RockMuonStopperSelection_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file RockMuonStopperSelection.cxx
3 // \brief Selects stopping rock muons
4 // \author mcolo@email.wm.edu (based on StopperSelection by C. Backhouse)
5 ////////////////////////////////////////////////////////////////////////
6 
13 
14 // NOvASoft includes
15 #include "MCCheater/BackTracker.h"
16 #include "MEFinder/MEClusters.h"
17 #include "RecoBase/CellHit.h"
18 #include "RecoBase/Track.h"
19 #include "Geometry/Geometry.h"
20 #include "NovaDAQConventions/DAQConventions.h"
21 #include "Utilities/AssociationUtil.h"
22 
23 namespace calib
24 {
25  /// Selects stopping cosmics
27  {
28  public:
29  explicit RockMuonStopperSelection(const fhicl::ParameterSet& pset);
31 
32  virtual bool filter(art::Event& evt);
33 
34  void reconfigure(const fhicl::ParameterSet& pset);
35 
36  void beginJob();
37  void endJob();
38 
39  protected:
40  bool IsContainedStopper(const rb::Track* trk);
41  bool IsTrulyContainedStopper(const rb::Track* trk) const;
42  bool IsTrulyInFiducial(const rb::Track* trk) const;
43 
44  std::string fTrackLabel; ///< Where to find Tracks to reconstruct
45 
47 
48  bool fVerbose;
49 
51 
52  int fTable[2][2];
53  int fFidTable[2][2];
54 
55  int x2Fiducial = 0;
56  int z1Fiducial = 0;
57  int z2Fiducial = 0;
58  int y1Fiducial = 0;
59  int y2Fiducial = 0;
60  int cpL = 0;
61  int ppL = 0;
62  int earlyCells = 0;
63  int numTot = 0;
64  };
65 
66  //......................................................................
68  {
69  produces< std::vector<rb::Track> >();
70  produces< art::Assns<rb::Track, rb::Cluster> >();
71 
72  reconfigure(pset);
73 
74  for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j) fTable[i][j] = 0;
75  for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j) fFidTable[i][j] = 0;
76 
77  }
78 
79  //......................................................................
81  {
82  }
83 
84  //......................................................................
86  {
87  fApplyFilter = pset.get<bool>("ApplyFilter");
88  fTrackLabel = pset.get<std::string>("TrackLabel");
89  fVerbose = pset.get<bool>("Verbose");
90 
91  }
92 
93  //......................................................................
95  {
96 
97  }
98 
99  //......................................................................
101  {
102 
103  std::unique_ptr<std::vector<rb::Track> > outTracks(new std::vector<rb::Track>);
104  std::unique_ptr<art::Assns<rb::Track, rb::Cluster> > assns(new art::Assns<rb::Track, rb::Cluster>);
106 
107  evt.getByLabel(fTrackLabel, tracks);
108  art::FindManyP<rb::Cluster> fmpslc(tracks, evt, fTrackLabel);
109 
110 
111  for(size_t trIdx = 0; trIdx < tracks->size(); ++trIdx){
112  const rb::Track* trk = &(tracks->at(trIdx));
113 
114  if (fVerbose) std::cout<<"In event "<<evt.event()<<":"<<std::endl;
115  const bool stopper = IsContainedStopper(trk);
116 
117  if(stopper){
118  outTracks->push_back(*trk);
119 
120  // Find the slice the original track was associated to
121  const std::vector<art::Ptr<rb::Cluster> > slices = fmpslc.at(trIdx);
122  assert(slices.size() == 1);
123  util::CreateAssn(*this, evt, *outTracks, slices[0], *assns);
124  }
125 
126 
127  if(!evt.isRealData()){
128  //printf("This is Montecarlo \n");
129  const bool trueStopper = IsTrulyContainedStopper(trk);
130  const bool inFidStopper = IsTrulyInFiducial(trk);
131  ++fTable[stopper][trueStopper];
132  ++fFidTable[stopper][inFidStopper];
133  }
134  } // end for meIdx
135 
136  const bool ret = !outTracks->empty();
137  evt.put(std::move(outTracks));
138  evt.put(std::move(assns));
139  if(fApplyFilter) return ret; else return true;
140  }
141 
142  //......................................................................
144  {
145  std::cout << "There were "<<numTot<<" reasonable tracks in this file"<<std::endl;
146  std::cout << earlyCells << " (" << .1*(1000*earlyCells/numTot) << " %) did not have enough hits in the first 4 planes. " << (numTot - earlyCells) << " remain."<<std::endl;
147  std::cout << y1Fiducial << " (" << .1*(1000*y1Fiducial/numTot) << " %) failed the y1 fiducial cut. " << (numTot - earlyCells - y1Fiducial) << " remain."<<std::endl;
148  std::cout << z2Fiducial << " (" << .1*(1000*z2Fiducial/numTot) << " %) failed the z2 fiducial cut. " << (numTot - earlyCells - y1Fiducial - z2Fiducial) << " remain."<<std::endl;
149  std::cout << x2Fiducial << " (" << .1*(1000*x2Fiducial/numTot) << " %) failed the x2 fiducial cut. " << (numTot - earlyCells - y1Fiducial - z2Fiducial - x2Fiducial) << " remain."<<std::endl;
150  std::cout << y2Fiducial << " (" << .1*(1000*y2Fiducial/numTot) << " %) failed the y2 fiducial cut. " << (numTot - earlyCells - y1Fiducial - z2Fiducial - x2Fiducial - y2Fiducial) << " remain."<<std::endl;
151  std::cout << (ppL + cpL) << " (" << .1*(1000*(ppL+cpL)/numTot) << " %) failed the y2 fiducial cut. " << (numTot - earlyCells - y1Fiducial - z2Fiducial - x2Fiducial - y2Fiducial - ppL - cpL) << " remain."<<std::endl;
152 
153  if(fTable[0][0]+fTable[1][0] == 0 || fTable[0][1]+fTable[1][1] == 0) return;
154  std::cout << "Stopper efficiency table. x-axis selection, y-axis truth:" << std::endl;
155  std::cout << fTable[0][0] << "\t" << fTable[1][0] << "\t" << .1*(1000*fTable[0][0]/(fTable[0][0]+fTable[1][0])) << "%" << std::endl;
156  std::cout << fTable[0][1] << "\t" << fTable[1][1] << "\t" << .1*(1000*fTable[1][1]/(fTable[0][1]+fTable[1][1])) << "%" << std::endl;
157  std::cout << .1*(1000*fTable[0][0]/(fTable[0][0]+fTable[0][1])) << "%\t" << .1*(1000*fTable[1][1]/(fTable[1][0]+fTable[1][1])) << "%" << std::endl;
158  std::cout << "Purity = " << .1*(1000*fTable[1][1]/(fTable[1][0]+fTable[1][1])) << "%" << std::endl;
159  std::cout << "Efficiency = " << .1*(1000*fTable[1][1]/(fTable[0][1]+fTable[1][1])) << "%" << std::endl;
160 
161  if(fFidTable[0][0]+fFidTable[1][0] == 0 || fFidTable[0][1]+fFidTable[1][1] == 0) return;
162  std::cout << "Stopper efficiency table (considering tracks stopping in the fiducial volume). x-axis selection, y-axis truth:" << std::endl;
163  std::cout << fFidTable[0][0] << "\t" << fFidTable[1][0] << "\t" << .1*(1000*fFidTable[0][0]/(fFidTable[0][0]+fFidTable[1][0])) << "%" << std::endl;
164  std::cout << fFidTable[0][1] << "\t" << fFidTable[1][1] << "\t" << .1*(1000*fFidTable[1][1]/(fFidTable[0][1]+fFidTable[1][1])) << "%" << std::endl;
165  std::cout << .1*(1000*fFidTable[0][0]/(fFidTable[0][0]+fFidTable[0][1])) << "%\t" << .1*(1000*fFidTable[1][1]/(fFidTable[1][0]+fFidTable[1][1])) << "%" << std::endl;
166  std::cout << "Purity = " << .1*(1000*fFidTable[1][1]/(fFidTable[1][0]+fFidTable[1][1])) << "%" << std::endl;
167  std::cout << "Efficiency = " << .1*(1000*fFidTable[1][1]/(fFidTable[0][1]+fFidTable[1][1])) << "%" << std::endl;
168 
169  }
170 
171  //......................................................................
174  {
175  // Start and end don't mean much, pick whichever is lowest in y.
176  const TVector3 v1 = trk->Start();
177  const TVector3 v2 = trk->Stop();
178  const TVector3 stop = (v1.Y() < v2.Y()) ? v1 : v2;
179 
180  //const double x1 = v1.X();
181  const double y1 = v1.Y();
182  const double z1 = v1.Z();
183  const double x2 = v2.X();
184  const double y2 = v2.Y();
185  const double z2 = v2.Z();
186 
187  const double len = trk->TotalLength();
188 
190 
191  int hitsperplane [geom->NPlanes()];
192  for (unsigned int k=0; k<geom->NPlanes(); k++) hitsperplane[k]=0;
193 
194  for(size_t i = 0; i < trk->NCell(); ++i){
195  art::Ptr<rb::CellHit> chit = trk->Cell(i);
196  hitsperplane[chit->Plane()]++;
197  }
198 
199  double planesperlength = 0;
200  int earlyhits = 0;
201 
202  for (unsigned int k=0; k<geom->NPlanes(); k++) if(hitsperplane[k]!=0) {
203  planesperlength += 1/len;
204  if (k<4) earlyhits ++;
205  }
206  double cellsperlength = trk->NCell() / len;
207 
208 
209  switch(geom->DetId()){
210  case novadaq::cnv::kNDOS:
211  // Fall through
213  if(len<225) {
214  if(fVerbose) std::cout<<"Track rejected (Track too short)"<<std::endl;
215  return false;
216  }
217  if(z1 > 25) {
218  if(fVerbose) std::cout<<"Track rejected (did not start in the first 25 cm of the detector)"<<std::endl;
219  return false;
220  }
221  numTot++;
222  if(earlyhits<3) {
223  if(fVerbose) std::cout<<"Track rejected (Two or less of the first 4 planes were hit)"<<std::endl;
224  earlyCells++;
225  return false;
226  }
227  if(y1 > geom->DetHalfHeight() - 30) {
228  if(fVerbose) std::cout<<"Track rejected (Ystart Fiducial)"<<std::endl;
229  y1Fiducial++;
230  return false;
231  }
232  if( (z2 < 25) || (z2 > 1250) ) {
233  if(fVerbose) std::cout<<"Track rejected (Zend Fiducial)"<<std::endl;
234  z2Fiducial++;
235  return false;
236  }
237  if(fabs(x2) > geom->DetHalfWidth() - 20) {
238  if(fVerbose) std::cout<<"Track rejected (Xend Fiducial)"<<std::endl;
239  x2Fiducial++;
240  return false; // Fiducial X
241  }
242  if(y2 < -geom->DetHalfHeight() + 30) {
243  if(fVerbose) std::cout<<"Track rejected (Yend Fiducial)"<<std::endl;
244  y2Fiducial++;
245  return false; // Fiducial Y
246  }
247 
248  if( (planesperlength < 0.12) || (planesperlength > 0.16) ) {
249  if(fVerbose) std::cout<<"Track rejected (Planes per unit length is "<<planesperlength<<")"<<std::endl;
250  ppL++;
251  return false;
252  }
253  if( (cellsperlength < 0.12) || (cellsperlength > 0.2) ) {
254  if(fVerbose) std::cout<<"Track rejected (Cells per unit length is "<<cellsperlength<<" )"<<std::endl;
255  cpL++;
256  return false;
257  }
258 
259  if(fVerbose) std::cout<<"Track passed cut"<<std::endl;
260  break;
261 
262  //the script allows the user to run it on the far detector
263  //however, users should be wary that these cuts were not tested on any FarDet data at all, and just mimick the neardet ones.
264  //furthermore, we expect close to no rock event to be present in FarDet at all.
266  if(len<225) {
267  if(fVerbose) std::cout<<"Track rejected (Track too short)"<<std::endl;
268  return false;
269  }
270  if(z1 > 25) {
271  if(fVerbose) std::cout<<"Track rejected (did not start in the first 25 cm of the detector)"<<std::endl;
272  return false;
273  }
274  numTot++;
275  if(earlyhits<3) {
276  if(fVerbose) std::cout<<"Track rejected (Two or less of the first 4 planes were hit)"<<std::endl;
277  earlyCells++;
278  return false;
279  }
280  if(y1 > geom->DetHalfHeight() - 30) {
281  if(fVerbose) std::cout<<"Track rejected (Ystart Fiducial)"<<std::endl;
282  y1Fiducial++;
283  return false;
284  }
285  if( (z2 < 25) || (z2 > geom->DetLength() - 25 ) ) {
286  if(fVerbose) std::cout<<"Track rejected (Zend Fiducial)"<<std::endl;
287  z2Fiducial++;
288  return false;
289  }
290  if(fabs(x2) > geom->DetHalfWidth() - 20) {
291  if(fVerbose) std::cout<<"Track rejected (Xend Fiducial)"<<std::endl;
292  x2Fiducial++;
293  return false; // Fiducial X
294  }
295  if(y2 < -geom->DetHalfHeight() + 30) {
296  if(fVerbose) std::cout<<"Track rejected (Yend Fiducial)"<<std::endl;
297  y2Fiducial++;
298  return false; // Fiducial Y
299  }
300 
301  if( (planesperlength < 0.12) || (planesperlength > 0.16) ) {
302  if(fVerbose) std::cout<<"Track rejected (Planes per unit length is "<<planesperlength<<")"<<std::endl;
303  ppL++;
304  return false;
305  }
306  if( (cellsperlength < 0.12) || (cellsperlength > 0.2) ) {
307  if(fVerbose) std::cout<<"Track rejected (Cells per unit length is "<<cellsperlength<<" )"<<std::endl;
308  cpL++;
309  return false;
310  }
311 
312  if(fVerbose) std::cout<<"Track passed cut"<<std::endl;
313  break;
314  default:
315  assert(0 && "Unknown detector");
316  }
317 
318  return true;
319  }
320 
321  //......................................................................
324  {
326 
327  std::vector<const sim::Particle*> parts = bt->HitsToParticle(trk->AllCells());
328  if(parts.empty()) return false;
329 
330  const sim::Particle* part = parts.front();
331 
332  const TVector3 stop = part->EndPosition().Vect();
333  const TVector3 start= part->Position().Vect();
335 
336  //x0 and y0 are the intercept of the start-stop trajectory with the front plane
337  //(i.e. the z=0 plane)
338 
339  double x0=(start.X()*stop.Z()-stop.X()*start.Z())/(stop.Z()-start.Z());
340  double y0=(start.Y()*stop.Z()-stop.Y()*start.Z())/(stop.Z()-start.Z());
341 
342  if(start.Z() > 0) return false;
343  if(fabs(x0) > geom->DetHalfWidth()) return false;
344  if(fabs(y0) > geom->DetHalfHeight()) return false;
345  if(fabs(stop.X()) > geom->DetHalfWidth()) return false;
346  if(fabs(stop.Y()) > geom->DetHalfHeight()) return false;
347  if(stop.Z() < 0) return false;
348  if(stop.Z() > geom->DetLength()) return false;
349  if(abs(part->PdgCode())!=13) return false;
350 
351  return true;
352  }
353  //......................................................................
356  {
358 
359  std::vector<const sim::Particle*> parts = bt->HitsToParticle(trk->AllCells());
360  if(parts.empty()) return false;
361 
362  const sim::Particle* part = parts.front();
363 
364  const TVector3 stop = part->EndPosition().Vect();
365  const TVector3 start= part->Position().Vect();
367 
368  //x0 and y0 are the intercept of the start-stop trajectory with the front plane
369  //(i.e. the z=0 plane)
370 
371  double x0=(start.X()*stop.Z()-stop.X()*start.Z())/(stop.Z()-start.Z());
372  double y0=(start.Y()*stop.Z()-stop.Y()*start.Z())/(stop.Z()-start.Z());
373 
374  if(start.Z() > 25) return false;
375  if(fabs(x0) > geom->DetHalfWidth()) return false;
376  if(fabs(y0) > geom->DetHalfHeight()) return false;
377  if(fabs(stop.X()) > geom->DetHalfWidth()-20) return false;
378  if(fabs(stop.Y()-15) > geom->DetHalfHeight()-15) return false;
379  if(fabs(y0 + 15) > geom->DetHalfHeight()-15) return false;
380  if(stop.Z() < 0) return false;
381  if(stop.Z() > 1250) return false;
382  if(abs(part->PdgCode())!=13) return false;
383 
384  return true;
385  }
386 
388 
389 } // end namespace
390 ////////////////////////////////////////////////////////////////////////
const XML_Char int len
Definition: expat.h:262
back track the reconstruction to the simulation
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:218
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
int PdgCode() const
Definition: MCParticle.h:211
unsigned int NCell(geo::View_t view) const
Number of cells in view view.
Definition: Cluster.cxx:134
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
const TLorentzVector & EndPosition() const
Definition: MCParticle.h:224
RockMuonStopperSelection(const fhicl::ParameterSet &pset)
Float_t y1[n_points_granero]
Definition: compare.C:5
unsigned short Plane() const
Definition: CellHit.h:39
bool IsTrulyInFiducial(const rb::Track *trk) const
double DetLength() const
void abs(TH1 *hist)
A rb::Prong with full reconstructed trajectory.
Definition: Track.h:20
bool isRealData() const
Definition: Event.h:83
DEFINE_ART_MODULE(TestTMapFile)
virtual TVector3 Start() const
Definition: Prong.h:73
art::PtrVector< rb::CellHit > AllCells() const
Get all cells from both views.
Definition: Cluster.cxx:180
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
virtual double TotalLength() const
Length (cm) of all the track segments.
Definition: Track.cxx:213
Track finder for cosmic rays.
TString part[npart]
Definition: Style.C:32
Far Detector at Ash River, MN.
CDPStorage service.
Prototype Near Detector on the surface at FNAL.
T get(std::string const &key) const
Definition: ParameterSet.h:231
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Near Detector in the NuMI cavern.
const double j
Definition: BetheBloch.cxx:29
EventNumber_t event() const
Definition: Event.h:67
double DetHalfHeight() const
OStream cout
Definition: OStream.cxx:6
art::Ptr< rb::CellHit > Cell(geo::View_t view, unsigned int viewIdx) const
Get the ith cell from view view.
Definition: Cluster.cxx:145
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
double DetHalfWidth() const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void geom(int which=0)
Definition: geom.C:163
void reconfigure(const fhicl::ParameterSet &pset)
bool IsTrulyContainedStopper(const rb::Track *trk) const
assert(nhit_max >=nhit_nbins)
unsigned int NPlanes() const
TVector3 Stop() const
Position of the final trajectory point.
Definition: Track.cxx:186
Encapsulate the geometry of one entire detector (near, far, ndos)
std::string fTrackLabel
Where to find Tracks to reconstruct.
std::vector< const sim::Particle * > HitsToParticle(const std::vector< const rb::CellHit * > &hits) const
Returns vector of sim::Particle objects contributing to the given collection of hits.