LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
TrackCalorimetryAlg.cxx
Go to the documentation of this file.
1 
10 #include "TrackCalorimetryAlg.h"
11 
12 #include "lardata/ArtDataHelper/TrackUtils.h" // lar::util::TrackPitchInView()
13 
14 #include <limits>
15 
17  caloAlg(p.get<fhicl::ParameterSet>("CalorimetryAlg"))
18 {
19  this->reconfigure(p);
20 }
21 
23  caloAlg.reconfigure(p.get<fhicl::ParameterSet>("CalorimetryAlg"));
24  fNHitsToDetermineStart = p.get<unsigned int>("NHitsToDetermineStart",3);
25 }
26 
27 void calo::TrackCalorimetryAlg::ExtractCalorimetry(std::vector<recob::Track> const& trackVector,
28  std::vector<recob::Hit> const& hitVector,
29  std::vector< std::vector<size_t> > const& hit_indices_per_track,
30  std::vector<anab::Calorimetry>& caloVector,
31  std::vector<size_t>& assnTrackCaloVector,
32  Providers_t providers)
33 {
34  auto const& geom = *(providers.get<geo::GeometryCore>());
35 // auto const& larp = *(providers.get<detinfo::LArProperties>());
36  auto const& detprop = *(providers.get<detinfo::DetectorProperties>());
37 
38  //loop over the track list
39  for(size_t i_track=0; i_track<trackVector.size(); i_track++){
40 
41  recob::Track const& track = trackVector[i_track];
42  std::vector<float> path_length_fraction_vec(CreatePathLengthFractionVector(track));
43 
44  //sort hits into each plane
45  std::vector< std::vector<size_t> > hit_indices_per_plane(geom.Nplanes());
46  for(auto const& i_hit : hit_indices_per_track[i_track])
47  hit_indices_per_plane[hitVector[i_hit].WireID().Plane].push_back(i_hit);
48 
49  //loop over the planes
50  for(size_t i_plane=0; i_plane<geom.Nplanes(); i_plane++){
51 
53  ReserveInternalVectors(hit_indices_per_plane[i_plane].size());
54 
55  //project down the track into wire/tick space for this plane
56  std::vector< std::pair<geo::WireID,float> > traj_points_in_plane(track.NumberTrajectoryPoints());
57  for(size_t i_trjpt=0; i_trjpt<track.NumberTrajectoryPoints(); i_trjpt++){
58  double x_pos = track.LocationAtPoint(i_trjpt).X();
59  float tick = detprop.ConvertXToTicks(x_pos,(int)i_plane,0,0);
60  traj_points_in_plane[i_trjpt] = std::make_pair(geom.NearestWireID(track.LocationAtPoint(i_trjpt),i_plane),
61  tick);
62  }
63 
64  HitPropertiesMultiset_t HitPropertiesMultiset;
65  //now loop through hits
66  for(auto const& i_hit : hit_indices_per_plane[i_plane])
67  AnalyzeHit(hitVector[i_hit],
68  track,
69  traj_points_in_plane,
70  path_length_fraction_vec,
71  HitPropertiesMultiset,
72  geom);
73 
74 
75  //PrintHitPropertiesMultiset(HitPropertiesMultiset);
76  geo::PlaneID planeID(0,0,i_plane);
77  MakeCalorimetryObject(HitPropertiesMultiset, track, i_track, caloVector, assnTrackCaloVector, planeID);
78 
79  }//end loop over planes
80 
81  }//end loop over tracks
82 
83 }//end ExtractCalorimetry
84 
85 
87 public:
89  hit(h), geom(g){}
90  bool operator() (std::pair<geo::WireID,float> i, std::pair<geo::WireID,float> j)
91  {
92  float dw_i = ((int)(i.first.Wire) - (int)(hit.WireID().Wire))*geom.WirePitch(i.first.Plane);
93  float dw_j = ((int)(j.first.Wire) - (int)(hit.WireID().Wire))*geom.WirePitch(j.first.Plane);
94  float dt_i = i.second - hit.PeakTime();
95  float dt_j = j.second - hit.PeakTime();
96 
97  return (std::sqrt(dw_i*dw_i + dt_i*dt_i) < std::sqrt(dw_j*dw_j + dt_j*dt_j));
98  }
99 private:
100  recob::Hit const& hit;
102 
103 };
104 
106 
107  std::vector<float> trk_path_length_frac_vec(track.NumberTrajectoryPoints());
108 
109  float cumulative_path_length=0;
110  const float total_path_length = track.Length();
111  for(size_t i_trj=1; i_trj<track.NumberTrajectoryPoints(); i_trj++){
112  cumulative_path_length+=(track.LocationAtPoint(i_trj)-track.LocationAtPoint(i_trj-1)).Mag();
113  trk_path_length_frac_vec[i_trj]=cumulative_path_length/total_path_length;
114  }
115 
116  return trk_path_length_frac_vec;
117 }
118 
120  recob::Track const& track,
121  std::vector< std::pair<geo::WireID,float> > const& traj_points_in_plane,
122  std::vector<float> const& path_length_fraction_vec,
123  HitPropertiesMultiset_t & HitPropertiesMultiset,
124  geo::GeometryCore const& geom){
125 
126  size_t traj_iter = std::distance(traj_points_in_plane.begin(),
127  std::min_element(traj_points_in_plane.begin(),
128  traj_points_in_plane.end(),
129  dist_projected(hit,geom)));
130  float pitch = lar::util::TrackPitchInView(track, geom.View(hit.WireID().Plane),traj_iter);
131 
132  HitPropertiesMultiset.emplace(hit.Integral(),
133  hit.Integral()/pitch,
134  caloAlg.dEdx_AREA(hit,pitch),
135  pitch,
136  track.LocationAtPoint(traj_iter),
137  path_length_fraction_vec[traj_iter]);
138 }
139 
141 
142  if(hpm.size() <= fNHitsToDetermineStart) return false;
143 
144  float charge_start=0,charge_end=0;
145  unsigned int counter=0;
146  for(HitPropertiesMultiset_t::iterator it_hpm=hpm.begin();
147  it_hpm!=hpm.end();
148  it_hpm++)
149  {
150  charge_start += (*it_hpm).charge;
151  counter++;
152  if(counter==fNHitsToDetermineStart) break;
153  }
154 
155  counter=0;
156  for(HitPropertiesMultiset_t::reverse_iterator it_hpm=hpm.rbegin();
157  it_hpm!=hpm.rend();
158  it_hpm++)
159  {
160  charge_end += (*it_hpm).charge;
161  counter++;
162  if(counter==fNHitsToDetermineStart) break;
163  }
164 
165  return (charge_start > charge_end);
166 }
167 
169  recob::Track const& track,
170  size_t const& i_track,
171  std::vector<anab::Calorimetry>& caloVector,
172  std::vector<size_t>& assnTrackCaloVector,
173  geo::PlaneID const& planeID){
174  size_t n_hits = hpm.size();
175  std::vector<double> dEdxVector,dQdxVector,resRangeVector,deadWireVector,pitchVector;
176  std::vector<TVector3> XYZVector;
177 
178  dEdxVector.reserve(n_hits);
179  dQdxVector.reserve(n_hits);
180  resRangeVector.reserve(n_hits);
181  deadWireVector.reserve(n_hits);
182  pitchVector.reserve(n_hits);
183  XYZVector.reserve(n_hits);
184 
185  double kinetic_energy=0,track_length=track.Length();
186  if(IsInvertedTrack(hpm)){
187 
188  for(HitPropertiesMultiset_t::iterator it_hpm=hpm.begin();
189  it_hpm!=hpm.end();
190  it_hpm++)
191  {
192  dEdxVector.push_back((*it_hpm).dEdx);
193  dQdxVector.push_back((*it_hpm).dQdx);
194  resRangeVector.push_back((*it_hpm).path_fraction*track_length);
195  pitchVector.push_back((*it_hpm).pitch);
196  XYZVector.push_back((*it_hpm).xyz);
197  kinetic_energy += dEdxVector.back()*pitchVector.back();
198  }
199 
200  }
201  else{
202 
203  for(HitPropertiesMultiset_t::reverse_iterator it_hpm=hpm.rbegin();
204  it_hpm!=hpm.rend();
205  it_hpm++)
206  {
207  dEdxVector.push_back((*it_hpm).dEdx);
208  dQdxVector.push_back((*it_hpm).dQdx);
209  resRangeVector.push_back((1-(*it_hpm).path_fraction)*track_length);
210  pitchVector.push_back((*it_hpm).pitch);
211  XYZVector.push_back((*it_hpm).xyz);
212  kinetic_energy += dEdxVector.back()*pitchVector.back();
213  }
214 
215  }
216 
217  caloVector.emplace_back(kinetic_energy,
218  dEdxVector,
219  dQdxVector,
220  resRangeVector,
221  deadWireVector,
222  track_length,
223  pitchVector,
224  XYZVector,
225  planeID);
226  assnTrackCaloVector.emplace_back(i_track);
227 }
228 
230 
231  for(auto const& hit : hpm)
232  hit.Print();
233 
234  std::cout << "Inverted? " << IsInvertedTrack(hpm) << std::endl;
235 
236 }
geo::GeometryCore const & geom
TVector3 LocationAtPoint(unsigned int p) const
Covariance matrices are either set or not.
Definition: Track.h:241
double dEdx_AREA(art::Ptr< recob::Hit > hit, double pitch, double T0=0) const
intermediate_table::iterator iterator
geo::WireID WireID() const
Initial tdc tick for hit.
Definition: Hit.h:234
bool IsInvertedTrack(HitPropertiesMultiset_t const &)
void MakeCalorimetryObject(HitPropertiesMultiset_t const &hpm, recob::Track const &track, size_t const &i_track, std::vector< anab::Calorimetry > &caloVector, std::vector< size_t > &assnTrackCaloVector, geo::PlaneID const &planeID)
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:109
void reconfigure(const Config &config)
Provider const * get() const
Returns the provider with the specified type.
Definition: ProviderPack.h:193
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:225
dist_projected(recob::Hit const &h, geo::GeometryCore const &g)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< float > CreatePathLengthFractionVector(recob::Track const &track)
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:174
parameter set interface
void PrintHitPropertiesMultiset(HitPropertiesMultiset_t const &hpm)
T get(std::string const &key) const
Definition: ParameterSet.h:231
void ReserveInternalVectors(size_t s)
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
Description of geometry of one entire detector.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Detector simulation of raw signals on wires.
TrackCalorimetryAlg(fhicl::ParameterSet const &p)
Container for a list of pointers to providers.
Definition: ProviderPack.h:114
std::multiset< HitProperties, HitPropertySorter > HitPropertiesMultiset_t
void reconfigure(fhicl::ParameterSet const &p)
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
double TrackPitchInView(recob::Track const &track, geo::View_t view, size_t trajectory_point=0)
Provides projected wire pitch for the view.
Definition: TrackUtils.cxx:76
recob::Hit const & hit
void ExtractCalorimetry(std::vector< recob::Track > const &, std::vector< recob::Hit > const &, std::vector< std::vector< size_t > > const &, std::vector< anab::Calorimetry > &, std::vector< size_t > &, Providers_t providers)
Float_t track
Definition: plot.C:34
Utility functions to extract information from recob::Track.
void AnalyzeHit(recob::Hit const &, recob::Track const &, std::vector< std::pair< geo::WireID, float > > const &, std::vector< float > const &, HitPropertiesMultiset_t &, geo::GeometryCore const &)
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:51