LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
BeamFlashCompatibilityCheck_module.cc
Go to the documentation of this file.
1 // This module makes a set of hypotheses for track light profiles
2 // based on beizer tracks in the event.
3 //
4 // This module will likely be subsumed into the OpFlashFinder module
5 // eventually. But at present they are being developped in parallel.
6 //
7 //
8 // \file BeamFlashCompatabilityCheck.cxx
9 // \author Ben Jones and Christie Chiu, MIT 2010
10 // Heavily revised by Ben Jones and Wes Ketchum, 2013
11 //
12 
13 
14 
16 //#include "AnalysisBase/FlashMatch.h"
18 
19 
20 // ROOT includes.
21 #include <Rtypes.h>
22 #ifndef BeamFlashCompatabilityCheck_h
23 #define BeamFlashCompatabilityCheck_h 1
24 
25 
26 
27 namespace trkf{
28  class BezierTrack;
29 }
30 
31 namespace recob{
32  class OpFlash;
33  class Track;
34 
35 }
36 
37 
38 namespace opdet {
39 
41 
43  public:
44 
46  virtual ~BeamFlashCompatabilityCheck();
47 
48  void produce(art::Event&);
49  void reconfigure(fhicl::ParameterSet const& p);
50 
51  std::vector<double> GetMIPHypotheses(trkf::BezierTrack* BTrack, double XOffset=0);
52  bool CheckCompatibility(std::vector<double>& hypothesis, std::vector<double>& signal);
53 
54  void beginJob();
55 
56 
57  private:
58  std::string fTrackModuleLabel;
59  std::string fFlashModuleLabel;
62  double fIntegralCut;
63  };
64 
65 
66 
67 }
68 
69 #endif
70 
71 
72 
73 
79 // Framework includes
81 
82 namespace opdet{
83 
85 
86 }//end namespace opdet
88 
89 
90 
91 // This module makes a set of hypotheses for track light profiles
92 // based on beizer tracks in the event.
93 //
94 // This module will likely be subsumed into the OpFlashFinder module
95 // eventually. But at present they are being developped in parallel.
96 //
97 //
98 // \file BeamFlashCompatabilityCheck.cxx
99 // \author Ben Jones and Christie Chiu, MIT 2010
100 //
101 //
102 
103 // LArSoft includes
108 
109 // FMWK includes
112 #include "fhiclcpp/ParameterSet.h"
121 #include "TH2D.h"
122 
123 // C++ language includes
124 #include <iostream>
125 #include <sstream>
126 #include <cstring>
127 #include <vector>
128 
129 #include "CLHEP/Random/RandFlat.h"
130 #include "CLHEP/Random/RandGaussQ.h"
131 
132 // Debug flag; only used during code development.
133 // const bool debug = true;
134 
135 namespace opdet {
136 
137  //-------------------------------------------------
138 
139  BeamFlashCompatabilityCheck::BeamFlashCompatabilityCheck(fhicl::ParameterSet const& pset)
140  {
141 
142  produces< std::vector<anab::CosmicTag> >();
143  produces< art::Assns<recob::Track, anab::CosmicTag> >();
144 
145  this->reconfigure(pset);
146  }
147 
148 
149  //-------------------------------------------------
150 
151  void BeamFlashCompatabilityCheck::reconfigure(fhicl::ParameterSet const& pset)
152  {
153  fTrackModuleLabel = pset.get<std::string>("TrackModuleLabel");
154  fFlashModuleLabel = pset.get<std::string>("FlashModuleLabel");
155  fBezierResolution = pset.get<int>("BezierResolution");
156  fSingleChannelCut = pset.get<int>("SingleChannelCut");
157  fIntegralCut = pset.get<int>("IntegralCut");
158  }
159 
160 
161  //-------------------------------------------------
162 
164  {
165  }
166 
167 
168 
169  //-------------------------------------------------
170 
171  BeamFlashCompatabilityCheck::~BeamFlashCompatabilityCheck()
172  {
173  }
174 
175 
176 
177 
178 
179 
180 
181  // Get a hypothesis for the light collected for a bezier track
182  std::vector<double> BeamFlashCompatabilityCheck::GetMIPHypotheses(trkf::BezierTrack* Btrack, double XOffset)
183  {
185  std::vector<double> ReturnVector(geom->NOpDets(),0);
186 
188 
189  float TrackLength = Btrack->GetLength();
190 
191  double xyz[3];
192  for (int b=0; b!=fBezierResolution; b++)
193  {
194  float s = float(b) / float(fBezierResolution);
195 
196  double MIPYield = 24000;
197  double QE = 0.01;
198  double MIPdQdx = 2.1;
199  double PromptFrac = 0.25;
200  double PromptMIPScintYield = MIPYield * QE * MIPdQdx * PromptFrac;
201 
202 
203  Btrack->GetTrackPoint(s,xyz);
204  xyz[0]+=XOffset;
205  const float* PointVisibility = pvs->GetAllVisibilities(xyz);
206  if (!PointVisibility) continue; // point not covered by the service
207 
208  float LightAmount = PromptMIPScintYield*TrackLength/float(fBezierResolution);
209 
210  for(size_t OpDet =0; OpDet!=pvs->NOpChannels(); OpDet++)
211  {
212  ReturnVector.at(OpDet)+= PointVisibility[OpDet] * LightAmount;
213  }
214  }
215  return ReturnVector;
216  }
217 
218  //-------------------------------------------------
219 
220 
221  void BeamFlashCompatabilityCheck::produce(art::Event& evt)
222  {
223 
224  // int EventID = evt.id().event();
225 
226 
227  // Read in flashes from the event
229  evt.getByLabel(fFlashModuleLabel, flashh);
230  std::vector<art::Ptr<recob::OpFlash> > Flashes;
231  for(unsigned int i=0; i < flashh->size(); ++i)
232  {
233  art::Ptr<recob::OpFlash> flash(flashh,i);
234  Flashes.push_back(flash);
235  }
236 
237  // Read in tracks from the event
239  evt.getByLabel(fTrackModuleLabel, trackh);
240  std::vector<art::Ptr<recob::Track> > Tracks;
241  for(unsigned int i=0; i < trackh->size(); ++i)
242  {
243  art::Ptr<recob::Track> track(trackh,i);
244  Tracks.push_back(track);
245  }
246 
247 
248  // Use these to produce Bezier tracks
249  std::vector<trkf::BezierTrack*> BTracks;
250  BTracks.clear();
251  for(size_t i=0; i!=Tracks.size(); i++)
252  BTracks.push_back(new trkf::BezierTrack(*Tracks.at(i)));
253 
254 
255  std::vector<std::vector<double> > TrackHypotheses;
256  std::vector<std::vector<double> > FlashShapes;
257 
258 
259  // For each track
260  for (size_t i=0; i!=BTracks.size(); ++i)
261  {
262  TrackHypotheses.push_back(GetMIPHypotheses(BTracks.at(i)));
263  }
264 
266  size_t NOpDets = geom->NOpDets();
267  size_t NOpChannels = geom->NOpChannels();
268 
269  std::vector<bool> Compatible(TrackHypotheses.size(),false);
270 
271  for(size_t f=0; f!=Flashes.size(); ++f)
272  {
273  if(Flashes.at(f)->OnBeamTime())
274  {
275  std::vector<double> ThisFlashShape(NOpDets,0);
276  for(size_t i=0; i!=NOpDets; ++i)
277  ThisFlashShape[i] = 0;
278  for(size_t i=0; i < NOpChannels; ++i) {
279  int opdet = geom->OpDetFromOpChannel(i);
280  ThisFlashShape[opdet] += Flashes.at(f)->PE(i);
281  }
282  FlashShapes.push_back(ThisFlashShape);
283 
284  for(size_t i=0; i!=TrackHypotheses.size(); ++i)
285  {
286  if(CheckCompatibility(TrackHypotheses.at(i),ThisFlashShape))
287  {
288  Compatible[i]=true;
289  }
290  }
291  }
292  }
293 
294  std::unique_ptr< std::vector<anab::CosmicTag> > CosmicTagPtr ( new std::vector<anab::CosmicTag>);
295  std::vector<anab::CosmicTag> & CosmicTagVector(*CosmicTagPtr);
296 
297  std::unique_ptr< art::Assns<recob::Track, anab::CosmicTag > > assn_track( new art::Assns<recob::Track, anab::CosmicTag>);
298 
299  float cosmic_score;
300  double xyz_begin[3];
301  double xyz_end[3];
302  for(size_t itrack=0; itrack<BTracks.size(); itrack++){
303 
304 
305  if(Compatible.at(itrack)) cosmic_score = 0; //not a cosmic
306  else if(!Compatible.at(itrack)) cosmic_score = 1; //is a cosmic
307 
308  BTracks.at(itrack)->GetTrackPoint(0,xyz_begin); //load in beginning point
309  std::vector<float> endPt1 = { (float)xyz_begin[0], (float)xyz_begin[1], (float)xyz_begin[2] };
310  BTracks.at(itrack)->GetTrackPoint(1,xyz_end); //load in ending point
311  std::vector<float> endPt2 = { (float)xyz_end[0], (float)xyz_end[1], (float)xyz_end[2] };
312 
313  CosmicTagVector.emplace_back(endPt1,endPt2,cosmic_score,anab::CosmicTagID_t::kFlash_BeamIncompatible);
314  util::CreateAssn(*this, evt, *(CosmicTagPtr.get()), Tracks.at(itrack), *(assn_track.get()), itrack);
315 
316  }
317 
318 
319  evt.put(std::move(CosmicTagPtr));
320  evt.put(std::move(assn_track));
321 
322 
323  }
324 
325 
326  //---------------------------------------
327  // Check whether a hypothesis can be accomodated in a flash
328  // Flashes fail if 1 bin is far in excess of the observed signal
329  // or if the whole flash intensity is much too large for the hypothesis.
330  // MIP dEdx is assumed for now. Accounting for real dQdx will
331  // improve performance of this algorithm.
332  //
333  bool BeamFlashCompatabilityCheck::CheckCompatibility(std::vector<double>& hypothesis, std::vector<double>& signal)
334  {
335  double sigintegral=0, hypintegral=0;
336  for(size_t i=0; i!=hypothesis.size(); ++i)
337  {
338  sigintegral+=signal.at(i);
339  hypintegral+=hypothesis.at(i);
340  double HypErr = pow(hypothesis.at(i),0.5);
341  if(( (hypothesis.at(i) - signal.at(i)) / HypErr) > fSingleChannelCut) return false;
342  }
343  double HypIntErr= pow(hypintegral,0.5);
344 
345  if( ( (hypintegral - sigintegral)/HypIntErr) > fIntegralCut) return false;
346  return true;
347  }
348 
349 
350 }
351 
352 
Float_t s
Definition: plot.C:23
TTree * t1
Definition: plottest35.C:26
Reconstruction base classes.
unsigned int NOpChannels() const
Number of electronics channels for all the optical detectors.
void GetTrackPoint(double s, double *xyz) const
unsigned int OpDetFromOpChannel(int opChannel) const
Convert unique channel to detector number.
TFile f
Definition: plotHisto.C:6
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool BeamFlashCompatabilityCheck_tracksort(art::Ptr< recob::Track > t1, art::Ptr< recob::Track > t2)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void beginJob()
Definition: Breakpoints.cc:14
T get(std::string const &key) const
Definition: ParameterSet.h:231
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
unsigned int NOpDets() const
Number of OpDets in the whole detector.
TTree * t2
Definition: plottest35.C:36
Utility object to perform functions of association.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::vector< art::Ptr< anab::CosmicTag > > CosmicTagVector
double GetLength() const
Float_t track
Definition: plot.C:34
art framework interface to geometry description
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