LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
HitAnaAlg.cxx
Go to the documentation of this file.
1 
13 #include "HitAnaAlg.h"
14 
15 #include <functional>
16 #include <unordered_map>
17 
20 }
21 
23  wireDataTree = wdt;
25 }
26 
27 void hit::HitAnaAlg::SetHitDataTree(std::vector<TTree*>& trees){
28 
29  hitDataTree.clear();
30  hitData.clear();
31 
32  hitDataTree.reserve (trees.size());
33  // This is particularly important: to establish the hitData memory -- all before
34  // individually making the tree->Branch() calls, specifying those addresses.
35  hitData.reserve (trees.size());
36 
37  // Construct the local attribute data container
38  for(auto const& t : trees) {
39  hitDataTree.push_back(t);
40  hitData.push_back(new recob::Hit);
41  }
42 
43  for(size_t i=0; i<hitData.size(); ++i)
44  hitDataTree[i]->Branch(hitDataTree[i]->GetName(),"recob::Hit",&(hitData[i]));
45 }
46 
48  wireDataTree->Branch("event", &wireData.event, "event/i");
49  wireDataTree->Branch("run", &wireData.run, "run/i");
50  wireDataTree->Branch("channel", &wireData.channel, "channel/i");
51  wireDataTree->Branch("plane", &wireData.plane, "plane/i");
52  wireDataTree->Branch("roi_index", &wireData.range_index, "roi_index/i");
53  wireDataTree->Branch("roi_start", &wireData.range_start, "roi_start/i");
54  wireDataTree->Branch("roi_size", &wireData.range_size, "roi_size/i");
55  wireDataTree->Branch("roi_charge", &wireData.integrated_charge, "roi_charge/F");
56  wireDataTree->Branch("roi_peak_charge", &wireData.peak_charge, "roi_peak_charge/F");
57  wireDataTree->Branch("roi_peak_time", &wireData.peak_time, "roi_peak_time/F");
58  wireDataTree->Branch("nHitModules", &wireData.NHitModules, "nHitModules/I");
59  wireDataTree->Branch("HitModuleLabels",&wireData.HitModuleLabels);
60  wireDataTree->Branch("NHits",&wireData.NHits);
61  wireDataTree->Branch("Hits_IntegratedCharge",&wireData.Hits_IntegratedCharge);
62  wireDataTree->Branch("Hits_AverageCharge",&wireData.Hits_AverageCharge);
63  wireDataTree->Branch("Hits_PeakCharge",&wireData.Hits_PeakCharge);
64  wireDataTree->Branch("Hits_Peak",&wireData.Hits_PeakTime);
65  wireDataTree->Branch("Hits_wAverageCharge",&wireData.Hits_wAverageCharge);
66  wireDataTree->Branch("Hits_wAverageTime",&wireData.Hits_wAverageTime);
67  wireDataTree->Branch("Hits_MeanMultiplicity",&wireData.Hits_MeanMultiplicity);
68 
69  wireDataTree->Branch("NMCHits",&wireData.NMCHits);
70  wireDataTree->Branch("MCHits_IntegratedCharge",&wireData.MCHits_IntegratedCharge);
71  wireDataTree->Branch("MCHits_AverageCharge",&wireData.MCHits_AverageCharge);
72  wireDataTree->Branch("MCHits_PeakCharge",&wireData.MCHits_PeakCharge);
73  wireDataTree->Branch("MCHits_Peak",&wireData.MCHits_PeakTime);
74  wireDataTree->Branch("MCHits_wAverageCharge",&wireData.MCHits_wAverageCharge);
75  wireDataTree->Branch("MCHits_wAverageTime",&wireData.MCHits_wAverageTime);
76 
77 }
78 
79 
81  HitModuleLabels.clear();
82  HitProcessingQueue.clear();
84 }
85 
86 void hit::HitAnaAlg::LoadHitAssocPair( std::vector<recob::Hit> const& HitVector,
87  std::vector< std::vector<int> > const& AssocVector,
88  std::string const& HitModuleLabel){
89 
90  HitProcessingQueue.push_back( std::make_pair( std::cref(HitVector), std::cref(AssocVector)) );
91  HitModuleLabels.push_back(HitModuleLabel);
92 
93  if(HitProcessingQueue.size()!=HitModuleLabels.size())
94  throw hitanaalgexception;
95 
96 }
97 
98 void hit::HitAnaAlg::AnalyzeWires(std::vector<recob::Wire> const& WireVector,
99  std::vector<sim::MCHitCollection> const& MCHitCollectionVector,
100  std::vector< std::vector<int> > const& AssocVector,
101  const detinfo::DetectorClocks *ts,
102  unsigned int event, unsigned int run){
103 
104  InitWireData(event,run);
105  for(size_t iwire=0 ; iwire < WireVector.size(); iwire++)
106  FillWireInfo(WireVector[iwire], iwire, MCHitCollectionVector, AssocVector[iwire], ts);
107 
108 }
109 
110 void hit::HitAnaAlg::InitWireData(unsigned int event, unsigned int run){
111 
112  wireData.event = event;
113  wireData.run = run;
116 
117 }
118 
120  wireData.NMCHits = 0;
127 
136  wireData.Hits.clear(); wireData.Hits.resize(wireData.NHitModules);
137 }
138 
140  int WireIndex,
141  std::vector<sim::MCHitCollection> const& MCHitCollectionVector,
142  std::vector<int> const& thisAssocVector,
143  const detinfo::DetectorClocks *ts){
144 
145  wireData.channel = wire.Channel();
146  wireData.plane = wire.View();
147  unsigned int range_index = 0;
148 
149  for( auto const& range : wire.SignalROI().get_ranges() ){
150 
151  wireData.range_index = range_index;
152  wireData.range_start = range.begin_index();
153  wireData.range_size = range.size();
154 
156 
157  ProcessROI(range, WireIndex, MCHitCollectionVector, thisAssocVector, ts);
158  range_index++;
159 
160  }//end loop over roi ranges
161 
162 }
163 
165  float& charge_sum,
166  float& charge_peak,
167  float& charge_peak_time){
168 
169  charge_sum=0;
170  charge_peak = -999;
171  unsigned int counter=range.begin_index();
172 
173  for(auto const& value : range){
174  charge_sum += value;
175  if(value > charge_peak){
176  charge_peak = value;
177  charge_peak_time = (float)counter;
178  }
179  counter++;
180  }
181 
182 }
183 
185  int WireIndex,
186  std::vector<sim::MCHitCollection> const& MCHitCollectionVector,
187  std::vector<int> const& thisAssocVector,
188  const detinfo::DetectorClocks *ts){
189 
191 
192  //std::cout << "----------------------------------------------------------------" << std::endl;
193  //std::cout << "WireIndex = " << WireIndex << std::endl;
194  //std::cout << "\tRange begin: " << range.begin_index() << std::endl;
195  //std::cout << "\tRange end: " << range.begin_index()+range.size() << std::endl;
196 
197  for(size_t iter = 0; iter < HitProcessingQueue.size(); iter++)
199  HitProcessingQueue[iter].second.at(WireIndex),
200  iter,
201  range.begin_index(),
202  range.begin_index()+range.size());
203 
204  FindAndStoreMCHitsInRange(MCHitCollectionVector,
205  thisAssocVector,
206  range.begin_index(),
207  range.begin_index()+range.size(),
208  ts);
209 
210  wireDataTree->Fill();
211 }
212 
213 void hit::HitAnaAlg::FindAndStoreHitsInRange( std::vector<recob::Hit> const& HitVector,
214  std::vector<int> const& HitsOnWire,
215  size_t hitmodule_iter,
216  size_t begin_wire_tdc,
217  size_t end_wire_tdc){
218 
219  wireData.Hits_PeakCharge[hitmodule_iter]=-999;
220 
221  for( auto const& hit_index : HitsOnWire){
222  recob::Hit const& thishit = HitVector.at(hit_index);
223 
224  //check if this hit is on this ROI
225  if( thishit.PeakTimeMinusRMS() < begin_wire_tdc ||
226  thishit.PeakTimePlusRMS() > end_wire_tdc)
227  continue;
228 
229  FillHitInfo(thishit,wireData.Hits[hitmodule_iter]);
230  wireData.NHits[hitmodule_iter]++;
231  wireData.Hits_IntegratedCharge[hitmodule_iter] += thishit.Integral();
232 
233  if(thishit.PeakAmplitude() > wireData.Hits_PeakCharge[hitmodule_iter]){
234  wireData.Hits_PeakCharge[hitmodule_iter] = thishit.PeakAmplitude();
235  wireData.Hits_PeakTime[hitmodule_iter] = thishit.PeakTime();
236  }
237 
238  wireData.Hits_wAverageCharge[hitmodule_iter] += thishit.Integral()*thishit.Integral();
239  wireData.Hits_wAverageTime[hitmodule_iter] += thishit.Integral()*thishit.PeakTime();
240  wireData.Hits_MeanMultiplicity[hitmodule_iter] += thishit.Multiplicity();
241 
242  *(hitData.at(hitmodule_iter)) = thishit;
243  (hitDataTree.at(hitmodule_iter))->Fill();
244  }
245 
246  wireData.Hits_AverageCharge[hitmodule_iter] =
247  wireData.Hits_IntegratedCharge[hitmodule_iter]/wireData.NHits[hitmodule_iter];
248  wireData.Hits_wAverageCharge[hitmodule_iter] =
249  wireData.Hits_wAverageCharge[hitmodule_iter]/wireData.Hits_IntegratedCharge[hitmodule_iter];
250  wireData.Hits_wAverageTime[hitmodule_iter] =
251  wireData.Hits_wAverageTime[hitmodule_iter]/wireData.Hits_IntegratedCharge[hitmodule_iter];
252 
253  wireData.Hits_MeanMultiplicity[hitmodule_iter] /=wireData.NHits[hitmodule_iter];
254 
255 }
256 
257 void hit::HitAnaAlg::FindAndStoreMCHitsInRange( std::vector<sim::MCHitCollection> const& MCHitCollectionVector,
258  std::vector<int> const& HitsOnWire,
259  size_t begin_wire_tdc,
260  size_t end_wire_tdc,
261  const detinfo::DetectorClocks *ts){
262 
264 
265  for( auto const& hit_index : HitsOnWire){
266  sim::MCHitCollection const& thismchitcol = MCHitCollectionVector.at(hit_index);
267 
268  //let's have a map to keep track of the number of total particles
269  std::unordered_map<int,unsigned int> nmchits_per_trackID_map;
270  for( auto const& thishit : thismchitcol){
271 
272  //std::cout << "\t************************************************************" << std::endl;
273  //std::cout << "\t\tMCHit begin: " << ts->TPCTDC2Tick( thishit.PeakTime()-thishit.PeakWidth() ) << std::endl;
274  //std::cout << "\t\tMCHit end: " << ts->TPCTDC2Tick( thishit.PeakTime()+thishit.PeakWidth() ) << std::endl;
275 
276  //check if this hit is on this ROI
277  if( ts->TPCTDC2Tick( thishit.PeakTime()-thishit.PeakWidth() ) < begin_wire_tdc ||
278  ts->TPCTDC2Tick( thishit.PeakTime()+thishit.PeakWidth() ) > end_wire_tdc )
279  continue;
280 
281  nmchits_per_trackID_map[thishit.PartTrackId()] += 1;
282  wireData.MCHits_IntegratedCharge += thishit.Charge();
283 
284  if(thishit.Charge(true) > wireData.MCHits_PeakCharge){
285  wireData.MCHits_PeakCharge = thishit.Charge(true);
286  wireData.MCHits_PeakTime = ts->TPCTDC2Tick(thishit.PeakTime());
287  }
288 
289  wireData.MCHits_wAverageCharge += thishit.Charge()*thishit.Charge();
290  wireData.MCHits_wAverageTime += thishit.Charge()*ts->TPCTDC2Tick(thishit.PeakTime());
291 
292  }
293 
294  wireData.NMCHits = nmchits_per_trackID_map.size();
295 
302 
303  }
304 
305 }
306 
307 void hit::HitAnaAlg::FillHitInfo(recob::Hit const& hit, std::vector<HitInfo>& HitInfoVector){
308  HitInfoVector.emplace_back(hit.PeakTime(),
309  hit.SigmaPeakTime(),
310  hit.RMS(),
311  hit.StartTick(),
312  hit.EndTick(),
313  hit.Integral(),
314  hit.SigmaIntegral(),
315  hit.PeakAmplitude(),
316  hit.SigmaPeakAmplitude(),
317  hit.GoodnessOfFit());
318 }
std::vector< std::string > HitModuleLabels
Definition: HitAnaAlg.h:159
virtual double TPCTDC2Tick(double tdc) const =0
Given electronics clock count [tdc] returns TPC time-tick.
TTree * wireDataTree
Definition: HitAnaAlg.h:164
void SetupWireDataTree()
Definition: HitAnaAlg.cxx:47
unsigned int range_index
Definition: HitAnaAlg.h:69
void FindAndStoreMCHitsInRange(std::vector< sim::MCHitCollection > const &, std::vector< int > const &, size_t, size_t, const detinfo::DetectorClocks *)
Definition: HitAnaAlg.cxx:257
void SetHitDataTree(std::vector< TTree * > &trees)
Definition: HitAnaAlg.cxx:27
unsigned int event
Definition: HitAnaAlg.h:65
std::vector< std::vector< HitInfo > > Hits
Definition: HitAnaAlg.h:85
WireROIInfo wireData
Definition: HitAnaAlg.h:156
void FillHitInfo(recob::Hit const &, std::vector< HitInfo > &)
Definition: HitAnaAlg.cxx:307
std::vector< float > Hits_wAverageCharge
Definition: HitAnaAlg.h:82
std::vector< float > Hits_MeanMultiplicity
Definition: HitAnaAlg.h:84
float RMS() const
RMS of the hit shape, in tick units.
Definition: Hit.h:221
hit::HitAnaAlgException hitanaalgexception
std::vector< recob::Hit * > hitData
Definition: HitAnaAlg.h:157
TNtupleSim Fill(f1, f2, f3, f4)
std::vector< HitAssocPair > HitProcessingQueue
Definition: HitAnaAlg.h:160
void ClearWireDataHitInfo()
Definition: HitAnaAlg.cxx:119
float SigmaPeakAmplitude() const
Uncertainty on estimated amplitude of the hit at its peak, in ADC units.
Definition: Hit.h:223
float SigmaIntegral() const
Initial tdc tick for hit.
Definition: Hit.h:226
std::vector< float > Hits_PeakTime
Definition: HitAnaAlg.h:81
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:225
size_type begin_index() const
Returns the first absolute index included in the range.
void LoadHitAssocPair(std::vector< recob::Hit > const &, std::vector< std::vector< int > > const &, std::string const &)
Definition: HitAnaAlg.cxx:86
float GoodnessOfFit() const
Degrees of freedom in the determination of the hit signal shape (-1 by default)
Definition: Hit.h:229
short int Multiplicity() const
How many hits could this one be shared with.
Definition: Hit.h:227
unsigned int range_start
Definition: HitAnaAlg.h:70
void SetWireDataTree(TTree *)
Definition: HitAnaAlg.cxx:22
float PeakAmplitude() const
The estimated amplitude of the hit at its peak, in ADC units.
Definition: Hit.h:222
std::vector< std::string > HitModuleLabels
Definition: HitAnaAlg.h:76
geo::View_t View() const
Returns the view the channel belongs to.
Definition: Wire.h:163
float MCHits_wAverageTime
Definition: HitAnaAlg.h:92
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
unsigned int run
Definition: HitAnaAlg.h:66
void ProcessROI(lar::sparse_vector< float >::datarange_t const &, int, std::vector< sim::MCHitCollection > const &, std::vector< int > const &, const detinfo::DetectorClocks *)
Definition: HitAnaAlg.cxx:184
std::vector< float > Hits_PeakCharge
Definition: HitAnaAlg.h:80
std::vector< int > NHits
Definition: HitAnaAlg.h:77
float MCHits_IntegratedCharge
Definition: HitAnaAlg.h:87
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:164
float MCHits_wAverageCharge
Definition: HitAnaAlg.h:91
std::vector< art::Ptr< recob::Wire > > WireVector
float peak_charge
Definition: HitAnaAlg.h:73
std::vector< float > Hits_AverageCharge
Definition: HitAnaAlg.h:79
const RegionsOfInterest_t & SignalROI() const
Returns the list of regions of interest.
Definition: Wire.h:161
std::vector< float > Hits_wAverageTime
Definition: HitAnaAlg.h:83
unsigned int channel
Definition: HitAnaAlg.h:67
raw::TDCtick_t StartTick() const
Initial tdc tick for hit.
Definition: Hit.h:217
float PeakTimeMinusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
Definition: Hit.h:240
float MCHits_PeakCharge
Definition: HitAnaAlg.h:89
std::vector< art::Ptr< recob::Hit > > HitVector
Detector simulation of raw signals on wires.
Conversion of times between different formats and references.
raw::TDCtick_t EndTick() const
Final tdc tick for hit.
Definition: Hit.h:218
size_t range_size
Definition: HitAnaAlg.h:71
float MCHits_PeakTime
Definition: HitAnaAlg.h:90
void FillWireInfo(recob::Wire const &, int, std::vector< sim::MCHitCollection > const &, std::vector< int > const &, const detinfo::DetectorClocks *)
Definition: HitAnaAlg.cxx:139
unsigned int plane
Definition: HitAnaAlg.h:68
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:219
size_type size() const
Returns the size of the range.
std::string value(boost::any const &)
void InitWireData(unsigned int, unsigned int)
Definition: HitAnaAlg.cxx:110
std::vector< float > Hits_IntegratedCharge
Definition: HitAnaAlg.h:78
std::vector< TTree * > hitDataTree
Definition: HitAnaAlg.h:166
Class holding the deconvoluted signals from a channel.
Definition: Wire.h:80
Range class, with range and data.
float integrated_charge
Definition: HitAnaAlg.h:72
float MCHits_AverageCharge
Definition: HitAnaAlg.h:88
float SigmaPeakTime() const
Uncertainty for the signal peak, in tick units.
Definition: Hit.h:220
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
float PeakTimePlusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
Definition: Hit.h:237
void FindAndStoreHitsInRange(std::vector< recob::Hit > const &, std::vector< int > const &, size_t, size_t, size_t)
Definition: HitAnaAlg.cxx:213
void ClearHitModules()
Definition: HitAnaAlg.cxx:80
void AnalyzeWires(std::vector< recob::Wire > const &, std::vector< sim::MCHitCollection > const &, std::vector< std::vector< int > > const &, const detinfo::DetectorClocks *, unsigned int, unsigned int)
Definition: HitAnaAlg.cxx:98
void ROIInfo(lar::sparse_vector< float >::datarange_t const &, float &, float &, float &)
Definition: HitAnaAlg.cxx:164
Event finding and building.