All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BeamFlashTrackMatchTaggerAlg.cxx
Go to the documentation of this file.
1 /*!
2  * Title: Beam Flash<-->Track Match Algorithim Class
3  * Author: Wes Ketchum (wketchum@lanl.gov), based on code from Ben Jones
4  *
5  * Description: Algorithm that compares all tracks to the flash during the
6  * beam gate, and determines if that track is consistent with
7  * having produced that flash.
8  * Input: recob::OpFlash, recob::Track
9  * Output: anab::CosmicTag (and Assn<anab::CosmicTag,recob::Track>)
10 */
11 
13 
14 #include "fhiclcpp/ParameterSet.h"
15 
22 
23 #include <limits>
24 #include <utility>
25 #include <vector>
26 
27 #include "TH1F.h"
28 #include "TTree.h"
29 #include "TVector3.h"
30 
32  : COSMIC_TYPE_FLASHMATCH(anab::CosmicTagID_t::kFlash_BeamIncompatible),
33  COSMIC_TYPE_OUTSIDEDRIFT(anab::CosmicTagID_t::kOutsideDrift_Partial),
34  DEBUG_FLAG(p.get<bool>("RunDebugMode",false)),
35  fMinTrackLength(p.get<float>("MinTrackLength")),
36  fMinOpHitPE(p.get<float>("MinOpHitPE",0.1)),
37  fMIPdQdx(p.get<float>("MIPdQdx",2.1)),
38  fOpDetSaturation(p.get<float>("OpDetSaturation",200.)),
39  fSingleChannelCut(p.get<float>("SingleChannelCut")),
40  fCumulativeChannelThreshold(p.get<float>("CumulativeChannelThreshold")),
41  fCumulativeChannelCut(p.get<unsigned int>("CumulativeChannelCut")),
42  fIntegralCut(p.get<float>("IntegralCut")),
43  fMakeOutsideDriftTags(p.get<bool>("MakeOutsideDriftTags",false)),
44  fNormalizeHypothesisToFlash(p.get<bool>("NormalizeHypothesisToFlash"))
45 {}
46 
48  TH1F* hist_flash, TH1F* hist_hyp){
49  cTree = tree;
50 
51  cOpDetHist_flash = hist_flash;
52  cOpDetHist_flash->SetNameTitle("opdet_hist_flash","Optical Detector Occupancy, Flash");
53 
54  cOpDetHist_hyp = hist_hyp;
55  cOpDetHist_hyp->SetNameTitle("opdet_hist_hyp","Optical Detector Occupancy, Hypothesis");
56 
57  cTree->Branch("fcp",&cFlashComparison_p,cFlashComparison_p.leaf_structure.c_str());
58  cTree->Branch("opdet_hyp",&cOpDetVector_hyp);
59  cTree->Branch("opdet_flash",&cOpDetVector_flash);
60  cTree->Branch("opdet_hist_flash","TH1F",cOpDetHist_flash);
61  cTree->Branch("opdet_hist_hyp","TH1F",cOpDetHist_hyp);
62 }
63 
64 void cosmic::BeamFlashTrackMatchTaggerAlg::RunCompatibilityCheck(std::vector<recob::OpFlash> const& flashVector,
65  std::vector<recob::Track> const& trackVector,
66  std::vector<anab::CosmicTag>& cosmicTagVector,
67  std::vector<size_t>& assnTrackTagVector,
68  Providers_t providers,
70  opdet::OpDigiProperties const& opdigip){
71 
72  auto const& geom = *(providers.get<geo::GeometryCore>());
73 
74  std::vector< const recob::OpFlash* > flashesOnBeamTime;
75  for(auto const& flash : flashVector){
76  if(!flash.OnBeamTime()) continue;
77  flashesOnBeamTime.push_back(&flash);
78  }
79 
80  //make sure this association vector is initialized properly
81  assnTrackTagVector.resize(trackVector.size(),std::numeric_limits<size_t>::max());
82  cosmicTagVector.reserve(trackVector.size());
83 
84  for(size_t track_i=0; track_i<trackVector.size(); track_i++){
85 
86  recob::Track const& track(trackVector[track_i]);
87 
88  if(track.Length() < fMinTrackLength) continue;
89 
90  //get the begin and end points of this track
91  TVector3 const& pt_begin = track.LocationAtPoint<TVector3>(0);
92  TVector3 const& pt_end = track.LocationAtPoint<TVector3>(track.NumberTrajectoryPoints()-1);
93  std::vector<float> xyz_begin = { (float)pt_begin.x(), (float)pt_begin.y(), (float)pt_begin.z()};
94  std::vector<float> xyz_end = {(float)pt_end.x(), (float)pt_end.y(), (float)pt_end.z()};
95 
96  //check if this track is outside the drift window, and if it is continue
97  if(!InDriftWindow(pt_begin.x(),pt_end.x(),geom)) {
98  if(fMakeOutsideDriftTags){
99  cosmicTagVector.emplace_back(xyz_begin,xyz_end,1.,COSMIC_TYPE_OUTSIDEDRIFT);
100  assnTrackTagVector[track_i] = cosmicTagVector.size()-1;
101  }
102  continue;
103  }
104 
105  //get light hypothesis for track
106  std::vector<float> lightHypothesis = GetMIPHypotheses(track,providers,pvs,opdigip);
107 
108  //check compatibility with beam flash
109  bool compatible=false;
110  for(const recob::OpFlash* flashPointer : flashesOnBeamTime){
111  CompatibilityResultType result = CheckCompatibility(lightHypothesis,flashPointer, geom);
112  if(result==CompatibilityResultType::kCompatible) compatible=true;
113  if(DEBUG_FLAG){
114  PrintTrackProperties(track);
115  PrintFlashProperties(*flashPointer);
116  PrintHypothesisFlashComparison(lightHypothesis,flashPointer,geom,result);
117  }
118  }
119 
120  //make tag
121  float cosmicScore=1.;
122  if(compatible) cosmicScore=0.;
123  cosmicTagVector.emplace_back(xyz_begin,xyz_end,cosmicScore,COSMIC_TYPE_FLASHMATCH);
124  assnTrackTagVector[track_i]=cosmicTagVector.size()-1;
125  }
126 
127 }
128 
129 //this compares the hypothesis to the flash itself.
131  unsigned int const event,
132  std::vector<recob::OpFlash> const& flashVector,
133  std::vector<recob::Track> const& trackVector,
134  Providers_t providers,
136  opdet::OpDigiProperties const& opdigip){
137 
138  auto const& geom = *(providers.get<geo::GeometryCore>());
139 
140  cFlashComparison_p.run = run;
141  cFlashComparison_p.event = event;
142 
143  std::vector< std::pair<unsigned int, const recob::OpFlash*> > flashesOnBeamTime;
144  for(unsigned int i=0; i<flashVector.size(); i++){
145  recob::OpFlash const& flash = flashVector[i];
146  if(!flash.OnBeamTime()) continue;
147  flashesOnBeamTime.push_back(std::make_pair(i,&flash));
148  }
149 
150  for(size_t track_i=0; track_i<trackVector.size(); track_i++){
151 
152  recob::Track const& track(trackVector[track_i]);
153 
154  if(track.Length() < fMinTrackLength) continue;
155 
156  //get the begin and end points of this track
157  TVector3 const& pt_begin = track.LocationAtPoint<TVector3>(0);
158  TVector3 const& pt_end = track.LocationAtPoint<TVector3>(track.NumberTrajectoryPoints()-1);
159  std::vector<float> xyz_begin = { (float)pt_begin.x(), (float)pt_begin.y(), (float)pt_begin.z()};
160  std::vector<float> xyz_end = {(float)pt_end.x(), (float)pt_end.y(), (float)pt_end.z()};
161 
162  //check if this track is outside the drift window, and if it is continue
163  if(!InDriftWindow(pt_begin.x(),pt_end.x(),geom)) continue;
164 
165  cFlashComparison_p.trk_startx = pt_begin.x();
166  cFlashComparison_p.trk_starty = pt_begin.y();
167  cFlashComparison_p.trk_startz = pt_begin.z();
168  cFlashComparison_p.trk_endx = pt_end.x();
169  cFlashComparison_p.trk_endy = pt_end.y();
170  cFlashComparison_p.trk_endz = pt_end.z();
171 
172  //get light hypothesis for track
173  cOpDetVector_hyp = GetMIPHypotheses(track,providers,pvs,opdigip);
174 
175  cFlashComparison_p.hyp_index = track_i;
176  FillFlashProperties(cOpDetVector_hyp,
177  cFlashComparison_p.hyp_totalPE,
178  cFlashComparison_p.hyp_y,cFlashComparison_p.hyp_sigmay,
179  cFlashComparison_p.hyp_z,cFlashComparison_p.hyp_sigmaz,
180  geom);
181 
182  for(auto flash : flashesOnBeamTime){
183  cOpDetVector_flash = std::vector<float>(geom.NOpDets(),0);
184  cFlashComparison_p.flash_nOpDet = 0;
185  for(size_t c=0; c<=geom.MaxOpChannel(); c++){
186  if ( geom.IsValidOpChannel( c ) ) {
187  unsigned int OpDet = geom.OpDetFromOpChannel(c);
188  cOpDetVector_flash[OpDet] += flash.second->PE(c);
189  }
190  }
191  for(size_t o=0; o<cOpDetVector_flash.size(); o++)
192  if(cOpDetVector_flash[o] < fMinOpHitPE) cFlashComparison_p.flash_nOpDet++;
193 
194  cFlashComparison_p.flash_index = flash.first;
195  cFlashComparison_p.flash_totalPE = flash.second->TotalPE();
196  cFlashComparison_p.flash_y = flash.second->YCenter();
197  cFlashComparison_p.flash_sigmay = flash.second->YWidth();
198  cFlashComparison_p.flash_z = flash.second->ZCenter();
199  cFlashComparison_p.flash_sigmaz = flash.second->ZWidth();
200 
201  cFlashComparison_p.chi2 = CalculateChi2(cOpDetVector_flash,cOpDetVector_hyp);
202 
203  cTree->Fill();
204  }//end loop over flashes
205 
206  }//end loop over tracks
207 
208 
209 }
210 
211 //this compares the hypothesis to the flash itself.
213  unsigned int const event,
214  std::vector<recob::OpFlash> const& flashVector,
215  std::vector<simb::MCParticle> const& mcParticleVector,
216  Providers_t providers,
218  opdet::OpDigiProperties const& opdigip){
219 
220  auto const& geom = *(providers.get<geo::GeometryCore>());
221 
222  cFlashComparison_p.run = run;
223  cFlashComparison_p.event = event;
224 
225  std::vector< std::pair<unsigned int, const recob::OpFlash*> > flashesOnBeamTime;
226  for(unsigned int i=0; i<flashVector.size(); i++){
227  recob::OpFlash const& flash = flashVector[i];
228  if(!flash.OnBeamTime()) continue;
229  flashesOnBeamTime.push_back(std::make_pair(i,&flash));
230  }
231 
232  for(size_t particle_i=0; particle_i<mcParticleVector.size(); particle_i++){
233 
234  simb::MCParticle const& particle(mcParticleVector[particle_i]);
235  if(particle.Process().compare("primary")!=0) continue;
236  if(particle.Trajectory().TotalLength() < fMinTrackLength) continue;
237 
238  //get the begin and end points of this track
239  size_t start_i=0, end_i=particle.NumberTrajectoryPoints()-1;
240  bool prev_inside=false;
241  for(size_t pt_i=0; pt_i < particle.NumberTrajectoryPoints(); pt_i++){
242  bool inside = InDetector(particle.Position(pt_i).Vect(),geom);
243  if(inside && !prev_inside) start_i = pt_i;
244  if(!inside && prev_inside) { end_i = pt_i-1; break; }
245  prev_inside = inside;
246  }
247  TVector3 const& pt_begin = particle.Position(start_i).Vect();
248  TVector3 const& pt_end = particle.Position(end_i).Vect();
249  std::vector<float> xyz_begin = { (float)pt_begin.x(), (float)pt_begin.y(), (float)pt_begin.z()};
250  std::vector<float> xyz_end = {(float)pt_end.x(), (float)pt_end.y(), (float)pt_end.z()};
251 
252  //check if this track is outside the drift window, and if it is continue
253  if(!InDriftWindow(pt_begin.x(),pt_end.x(),geom)) continue;
254 
255  cFlashComparison_p.trk_startx = pt_begin.x();
256  cFlashComparison_p.trk_starty = pt_begin.y();
257  cFlashComparison_p.trk_startz = pt_begin.z();
258  cFlashComparison_p.trk_endx = pt_end.x();
259  cFlashComparison_p.trk_endy = pt_end.y();
260  cFlashComparison_p.trk_endz = pt_end.z();
261 
262  //get light hypothesis for track
263  cOpDetVector_hyp = GetMIPHypotheses(particle,start_i,end_i,providers,pvs,opdigip);
264 
265  cFlashComparison_p.hyp_index = particle_i;
266  FillFlashProperties(cOpDetVector_hyp,
267  cFlashComparison_p.hyp_totalPE,
268  cFlashComparison_p.hyp_y,cFlashComparison_p.hyp_sigmay,
269  cFlashComparison_p.hyp_z,cFlashComparison_p.hyp_sigmaz,
270  geom);
271 
272  for(auto flash : flashesOnBeamTime){
273  cOpDetVector_flash = std::vector<float>(geom.NOpDets(),0);
274  cFlashComparison_p.flash_nOpDet = 0;
275  //for(size_t c=0; c<geom.NOpChannels(); c++){
276  for(size_t c=0; c<=geom.MaxOpChannel(); c++){
277  if ( geom.IsValidOpChannel(c) ) {
278  unsigned int OpDet = geom.OpDetFromOpChannel(c);
279  cOpDetVector_flash[OpDet] += flash.second->PE(c);
280  }
281  }
282  for(size_t o=0; o<cOpDetVector_flash.size(); o++)
283  if(cOpDetVector_flash[o] < fMinOpHitPE) cFlashComparison_p.flash_nOpDet++;
284  cFlashComparison_p.flash_index = flash.first;
285  cFlashComparison_p.flash_totalPE = flash.second->TotalPE();
286  cFlashComparison_p.flash_y = flash.second->YCenter();
287  cFlashComparison_p.flash_sigmay = flash.second->YWidth();
288  cFlashComparison_p.flash_z = flash.second->ZCenter();
289  cFlashComparison_p.flash_sigmaz = flash.second->ZWidth();
290 
291  cFlashComparison_p.chi2 = CalculateChi2(cOpDetVector_flash,cOpDetVector_hyp);
292 
293  //cOpDetHist_flash->SetBins(cOpDetVector_flash.size(),0,cOpDetVector_flash.size());
294  for(size_t i=0; i<cOpDetVector_flash.size(); i++)
295  cOpDetHist_flash->SetBinContent(i+1,cOpDetVector_flash[i]);
296 
297  //cOpDetHist_hyp->SetBins(cOpDetVector_hyp.size(),0,cOpDetVector_hyp.size());
298  for(size_t i=0; i<cOpDetVector_hyp.size(); i++)
299  cOpDetHist_hyp->SetBinContent(i+1,cOpDetVector_hyp[i]);
300 
301  for(size_t i=0; i<cOpDetVector_flash.size(); i++){
302  std::cout << "Flash/Hyp " << i << " : "
303  << cOpDetHist_flash->GetBinContent(i+1) << " "
304  << cOpDetHist_hyp->GetBinContent(i+1) << std::endl;
305  }
306 
307  cTree->Fill();
308  }//end loop over flashes
309 
310  }//end loop over tracks
311 
312 
313 }
314 
315 void cosmic::BeamFlashTrackMatchTaggerAlg::FillFlashProperties(std::vector<float> const& opdetVector,
316  float& sum,
317  float& y, float& sigmay,
318  float& z, float& sigmaz,
319  geo::GeometryCore const& geom){
320  y=0; sigmay=0; z=0; sigmaz=0; sum=0;
321  double xyz[3];
322  for(unsigned int opdet=0; opdet<opdetVector.size(); opdet++){
323  sum+=opdetVector[opdet];
324  geom.Cryostat(0).OpDet(opdet).GetCenter(xyz);
325  y += opdetVector[opdet]*xyz[1];
326  z += opdetVector[opdet]*xyz[2];
327  }
328 
329  y /= sum; z /= sum;
330 
331  for(unsigned int opdet=0; opdet<opdetVector.size(); opdet++){
332  geom.Cryostat(0).OpDet(opdet).GetCenter(xyz);
333  sigmay += (opdetVector[opdet]*xyz[1]-y)*(opdetVector[opdet]*xyz[1]-y);
334  sigmaz += (opdetVector[opdet]*xyz[2]-y)*(opdetVector[opdet]*xyz[2]-y);
335  }
336 
337  sigmay = std::sqrt(sigmay)/sum;
338  sigmaz = std::sqrt(sigmaz)/sum;
339 
340 }
341 
343  if(pt.x() < 0 || pt.x() > 2*geom.DetHalfWidth()) return false;
344  if(std::abs(pt.y()) > geom.DetHalfHeight()) return false;
345  if(pt.z() < 0 || pt.z() > geom.DetLength()) return false;
346  return true;
347 }
348 
349 bool cosmic::BeamFlashTrackMatchTaggerAlg::InDriftWindow(double start_x, double end_x, geo::GeometryCore const& geom){
350  if(start_x < 0. || end_x < 0.) return false;
351  if(start_x > 2*geom.DetHalfWidth() || end_x > 2*geom.DetHalfWidth()) return false;
352  return true;
353 }
354 
356  TVector3 const& pt2,
357  std::vector<float> & lightHypothesis,
358  float & totalHypothesisPE,
359  geo::GeometryCore const& geom,
361  float const& PromptMIPScintYield,
362  float XOffset){
363 
364  double xyz_segment[3];
365  xyz_segment[0] = 0.5*(pt2.x()+pt1.x()) + XOffset;
366  xyz_segment[1] = 0.5*(pt2.y()+pt1.y());
367  xyz_segment[2] = 0.5*(pt2.z()+pt1.z());
368 
369  //get the visibility vector
370  auto const& PointVisibility = pvs.GetAllVisibilities(xyz_segment);
371 
372  //check pointer, as it may be null if given a y/z outside some range
373  if(!PointVisibility) return;
374 
375  //get the amount of light
376  float LightAmount = PromptMIPScintYield*(pt2-pt1).Mag();
377 
378  for(size_t opdet_i=0; opdet_i<pvs.NOpChannels(); opdet_i++){
379  lightHypothesis[opdet_i] += PointVisibility[opdet_i]*LightAmount;
380  totalHypothesisPE += PointVisibility[opdet_i]*LightAmount;
381 
382  //apply saturation limit
383  if(lightHypothesis[opdet_i]>fOpDetSaturation){
384  totalHypothesisPE -= (lightHypothesis[opdet_i]-fOpDetSaturation);
385  lightHypothesis[opdet_i] = fOpDetSaturation;
386  }
387  }
388 
389 }//end AddLightFromSegment
390 
391 void cosmic::BeamFlashTrackMatchTaggerAlg::NormalizeLightHypothesis(std::vector<float> & lightHypothesis,
392  float const& totalHypothesisPE,
393  geo::GeometryCore const& geom){
394  for(size_t opdet_i=0; opdet_i<geom.NOpDets(); opdet_i++)
395  lightHypothesis[opdet_i] /= totalHypothesisPE;
396 }
397 
398 
399 // Get a hypothesis for the light collected for a track
401  Providers_t providers,
403  opdet::OpDigiProperties const& opdigip,
404  float XOffset)
405 {
406  auto const& geom = *(providers.get<geo::GeometryCore>());
407  auto const& larp = *(providers.get<detinfo::LArProperties>());
408  std::vector<float> lightHypothesis(geom.NOpDets(),0);
409  float totalHypothesisPE=0;
410  const float PromptMIPScintYield = larp.ScintYield()*larp.ScintYieldRatio()*opdigip.QE()*fMIPdQdx;
411 
412  //get QE from ubChannelConfig, which gives per tube, so goes in AddLightFromSegment
413  //VisibleEnergySeparation(step);
414 
415  for(size_t pt=1; pt<track.NumberTrajectoryPoints(); pt++)
416  AddLightFromSegment(track.LocationAtPoint<TVector3>(pt-1),track.LocationAtPoint<TVector3>(pt),
417  lightHypothesis,totalHypothesisPE,
418  geom,pvs,PromptMIPScintYield,
419  XOffset);
420 
421  if(fNormalizeHypothesisToFlash && totalHypothesisPE > std::numeric_limits<float>::epsilon())
422  NormalizeLightHypothesis(lightHypothesis,totalHypothesisPE,geom);
423 
424  return lightHypothesis;
425 
426 }//end GetMIPHypotheses
427 
428 
429 // Get a hypothesis for the light collected for a particle trajectory
430 std::vector<float> cosmic::BeamFlashTrackMatchTaggerAlg::GetMIPHypotheses(simb::MCParticle const& particle,
431  size_t start_i, size_t end_i,
432  Providers_t providers,
434  opdet::OpDigiProperties const& opdigip,
435  float XOffset)
436 {
437  auto const& geom = *(providers.get<geo::GeometryCore>());
438  auto const& larp = *(providers.get<detinfo::LArProperties>());
439  std::vector<float> lightHypothesis(geom.NOpDets(),0);
440  float totalHypothesisPE=0;
441  const float PromptMIPScintYield = larp.ScintYield()*larp.ScintYieldRatio()*opdigip.QE()*fMIPdQdx;
442 
443  for(size_t pt=start_i+1; pt<=end_i; pt++)
444  AddLightFromSegment(particle.Position(pt-1).Vect(),particle.Position(pt).Vect(),
445  lightHypothesis,totalHypothesisPE,
446  geom,pvs,PromptMIPScintYield,
447  XOffset);
448 
449  if(fNormalizeHypothesisToFlash && totalHypothesisPE > std::numeric_limits<float>::epsilon())
450  NormalizeLightHypothesis(lightHypothesis,totalHypothesisPE,geom);
451 
452  return lightHypothesis;
453 
454 }//end GetMIPHypotheses
455 
456 
457 //---------------------------------------
458 // Check whether a hypothesis can be accomodated in a flash
459 // Flashes fail if 1 bin is far in excess of the observed signal
460 // or if the whole flash intensity is much too large for the hypothesis.
461 // MIP dEdx is assumed for now. Accounting for real dQdx will
462 // improve performance of this algorithm.
463 //---------------------------------------
465 cosmic::BeamFlashTrackMatchTaggerAlg::CheckCompatibility(std::vector<float> const& lightHypothesis,
466  const recob::OpFlash* flashPointer,
467  geo::GeometryCore const& geom)
468 {
469  float hypothesis_integral=0;
470  float flash_integral=0;
471  unsigned int cumulativeChannels=0;
472 
473  std::vector<double> PEbyOpDet(geom.NOpDets(),0);
474  //for (unsigned int c = 0; c < geom.NOpChannels(); c++){
475  for (unsigned int c = 0; c <= geom.MaxOpChannel(); c++){
476  if ( geom.IsValidOpChannel(c) ) {
477  unsigned int o = geom.OpDetFromOpChannel(c);
478  PEbyOpDet[o] += flashPointer->PE(c);
479  }
480  }
481 
482  float hypothesis_scale=1.;
483  if(fNormalizeHypothesisToFlash) hypothesis_scale = flashPointer->TotalPE();
484 
485  for(size_t pmt_i=0; pmt_i<lightHypothesis.size(); pmt_i++){
486 
487  flash_integral += PEbyOpDet[pmt_i];
488 
489  if(lightHypothesis[pmt_i] < std::numeric_limits<float>::epsilon() ) continue;
490  hypothesis_integral += lightHypothesis[pmt_i]*hypothesis_scale;
491 
492  if(PEbyOpDet[pmt_i] < fMinOpHitPE) continue;
493 
494  float diff_scaled = (lightHypothesis[pmt_i]*hypothesis_scale - PEbyOpDet[pmt_i])/std::sqrt(lightHypothesis[pmt_i]*hypothesis_scale);
495 
496  if( diff_scaled > fSingleChannelCut ) return CompatibilityResultType::kSingleChannelCut;
497 
498  if( diff_scaled > fCumulativeChannelThreshold ) cumulativeChannels++;
499  if(cumulativeChannels >= fCumulativeChannelCut) return CompatibilityResultType::kCumulativeChannelCut;
500 
501  }
502 
503  if( (hypothesis_integral - flash_integral)/std::sqrt(hypothesis_integral)
504  > fIntegralCut) return CompatibilityResultType::kIntegralCut;
505 
506  return CompatibilityResultType::kCompatible;
507 }
508 
509 
510 float cosmic::BeamFlashTrackMatchTaggerAlg::CalculateChi2(std::vector<float> const& light_flash,
511  std::vector<float> const& light_track){
512 
513  float chi2=0;
514  for(size_t pmt_i=0; pmt_i<light_flash.size(); pmt_i++){
515 
516  if(light_flash[pmt_i] < fMinOpHitPE) continue;
517 
518  float err2 = 1;
519  if(light_track[pmt_i] > 1) err2 = light_track[pmt_i];
520 
521  chi2 += (light_flash[pmt_i]-light_track[pmt_i])*(light_flash[pmt_i]-light_track[pmt_i]) / err2;
522  }
523 
524  return chi2;
525 }
526 
527 
529 {
530  *output << "----------------------------------------------" << std::endl;
531  *output << "Track properties: ";
532  *output << "\n\tLength=" << track.Length();
533 
534  auto const& pt_begin = track.LocationAtPoint(0);
535  *output << "\n\tBegin Location (x,y,z)=(" << pt_begin.x() << "," << pt_begin.y() << "," << pt_begin.z() << ")";
536 
537  auto const& pt_end = track.LocationAtPoint(track.NumberTrajectoryPoints()-1);
538  *output << "\n\tEnd Location (x,y,z)=(" << pt_end.x() << "," << pt_end.y() << "," << pt_end.z() << ")";
539 
540  *output << "\n\tTrajectoryPoints=" << track.NumberTrajectoryPoints();
541  *output << std::endl;
542  *output << "----------------------------------------------" << std::endl;
543 }
544 
546 {
547  *output << "----------------------------------------------" << std::endl;
548  *output << "Flash properties: ";
549 
550  *output << "\n\tTime=" << flash.Time();
551  *output << "\n\tOnBeamTime=" << flash.OnBeamTime();
552  *output << "\n\ty position (center,width)=(" << flash.YCenter() << "," << flash.YWidth() << ")";
553  *output << "\n\tz position (center,width)=(" << flash.ZCenter() << "," << flash.ZWidth() << ")";
554  *output << "\n\tTotal PE=" << flash.TotalPE();
555 
556  *output << std::endl;
557  *output << "----------------------------------------------" << std::endl;
558 
559 }
560 
561 void cosmic::BeamFlashTrackMatchTaggerAlg::PrintHypothesisFlashComparison(std::vector<float> const& lightHypothesis,
562  const recob::OpFlash* flashPointer,
563  geo::GeometryCore const& geom,
565  std::ostream* output)
566 {
567 
568  *output << "----------------------------------------------" << std::endl;
569  *output << "Hypothesis-flash comparison: ";
570 
571  float hypothesis_integral=0;
572  float flash_integral=0;
573 
574  float hypothesis_scale=1.;
575  if(fNormalizeHypothesisToFlash) hypothesis_scale = flashPointer->TotalPE();
576 
577 
578  std::vector<double> PEbyOpDet(geom.NOpDets(),0);
579  //for (unsigned int c = 0; c < geom.NOpChannels(); c++){
580  for ( unsigned int c = 0; c <= geom.MaxOpChannel(); c++){
581  if ( geom.IsValidOpChannel(c) ) {
582  unsigned int o = geom.OpDetFromOpChannel(c);
583  PEbyOpDet[o] += flashPointer->PE(c);
584  }
585  }
586 
587  for(size_t pmt_i=0; pmt_i<lightHypothesis.size(); pmt_i++){
588 
589  flash_integral += PEbyOpDet[pmt_i];
590 
591  *output << "\n\t pmt_i=" << pmt_i << ", (hypothesis,flash)=("
592  << lightHypothesis[pmt_i]*hypothesis_scale << "," << PEbyOpDet[pmt_i] << ")";
593 
594  if(lightHypothesis[pmt_i] < std::numeric_limits<float>::epsilon() ) continue;
595 
596  *output << " difference="
597  << (lightHypothesis[pmt_i]*hypothesis_scale - PEbyOpDet[pmt_i])/std::sqrt(lightHypothesis[pmt_i]*hypothesis_scale);
598 
599  hypothesis_integral += lightHypothesis[pmt_i]*hypothesis_scale;
600  }
601 
602  *output << "\n\t TOTAL (hypothesis,flash)=("
603  << hypothesis_integral << "," << flash_integral << ")"
604  << " difference=" << (hypothesis_integral - flash_integral)/std::sqrt(hypothesis_integral);
605 
606  *output << std::endl;
607  *output << "End result=" << result << std::endl;
608  *output << "----------------------------------------------" << std::endl;
609 
610 }
process_name opflash particleana ie ie ie z
CompatibilityResultType CheckCompatibility(std::vector< float > const &lightHypothesis, const recob::OpFlash *flashPointer, geo::GeometryCore const &geom)
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
BeamFlashTrackMatchTaggerAlg(fhicl::ParameterSet const &p)
enum anab::cosmic_tag_id CosmicTagID_t
Point_t const & LocationAtPoint(size_t i) const
pdgs p
Definition: selectors.fcl:22
void RunHypothesisComparison(unsigned int const, unsigned int const, std::vector< recob::OpFlash > const &, std::vector< recob::Track > const &, Providers_t, phot::PhotonVisibilityService const &, opdet::OpDigiProperties const &)
float CalculateChi2(std::vector< float > const &, std::vector< float > const &)
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
double QE() const noexcept
Returns quantum efficiency.
static constexpr bool
Provider const * get() const
Returns the provider with the specified type.
Definition: ProviderPack.h:193
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:40
double PE(unsigned int i) const
Definition: OpFlash.h:110
process_name use argoneut_mc_hitfinder track
void RunCompatibilityCheck(std::vector< recob::OpFlash > const &, std::vector< recob::Track > const &, std::vector< anab::CosmicTag > &, std::vector< size_t > &, Providers_t, phot::PhotonVisibilityService const &, opdet::OpDigiProperties const &)
unsigned int OpDetFromOpChannel(int opChannel) const
Convert unique channel to detector number.
double ZCenter() const
Definition: OpFlash.h:117
Access the description of detector geometry.
std::vector< float > GetMIPHypotheses(recob::Track const &track, Providers_t providers, phot::PhotonVisibilityService const &pvs, opdet::OpDigiProperties const &, float XOffset=0)
T abs(T value)
double Time() const
Definition: OpFlash.h:106
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
double Length(size_t p=0) const
Access to various track properties.
process_name opflash particleana ie ie y
void NormalizeLightHypothesis(std::vector< float > &lightHypothesis, float const &totalHypothesisPE, geo::GeometryCore const &geom)
const OpDetGeo & OpDet(unsigned int iopdet) const
Return the iopdet&#39;th optical detector in the cryostat.
int OnBeamTime() const
Definition: OpFlash.h:123
void AddLightFromSegment(TVector3 const &pt1, TVector3 const &pt2, std::vector< float > &lightHypothesis, float &totalHypothesisPE, geo::GeometryCore const &geom, phot::PhotonVisibilityService const &pvs, float const &PromptMIPScintYield, float XOffset)
void PrintTrackProperties(recob::Track const &, std::ostream *output=&std::cout)
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
unsigned int MaxOpChannel() const
Largest optical channel number.
Description of geometry of one entire detector.
MappedCounts_t GetAllVisibilities(Point const &p, bool wantReflected=false) const
void SetHypothesisComparisonTree(TTree *, TH1F *, TH1F *)
unsigned int NOpDets() const
Number of OpDets in the whole detector.
Encapsulate the geometry of an optical detector.
double YWidth() const
Definition: OpFlash.h:116
void PrintHypothesisFlashComparison(std::vector< float > const &, const recob::OpFlash *, geo::GeometryCore const &geom, CompatibilityResultType, std::ostream *output=&std::cout)
Container for a list of pointers to providers.
Definition: ProviderPack.h:114
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG simSlidingORM6O6 effSlidingORW output
bool InDriftWindow(double, double, geo::GeometryCore const &)
void FillFlashProperties(std::vector< float > const &opdetVector, float &, float &, float &, float &, float &, geo::GeometryCore const &geom)
double TotalPE() const
Definition: OpFlash.cxx:68
bool InDetector(TVector3 const &, geo::GeometryCore const &)
double YCenter() const
Definition: OpFlash.h:115
bool IsValidOpChannel(int opChannel) const
Is this a valid OpChannel number?
art framework interface to geometry description
BEGIN_PROLOG could also be cout
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track:
double ZWidth() const
Definition: OpFlash.h:118
void PrintFlashProperties(recob::OpFlash const &, std::ostream *output=&std::cout)