TrackOverlapECalc_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // brief: Cacluate the overlapping energy on each track using the
3 // TrackCleanUpAlg class, and put that number in the event.
4 // Module Type: producer
5 // File: TrackOverlapECalc_module.cc
6 //
7 // Generated on Thu Aug 03 2017, at high noon by Michael Baird
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include <string>
11 #include "TMath.h"
12 
13 // Framework includes
19 
20 // NOvA includes
21 #include "Geometry/Geometry.h"
22 #include "RecoBase/Cluster.h"
23 #include "RecoBase/Track.h"
24 #include "RecoBase/Energy.h"
25 #include "RecoBase/FitSum.h"
26 #include "Utilities/AssociationUtil.h"
27 #include "Utilities/func/MathUtil.h"
29 
30 
31 
32 namespace numue {
33 
35  public:
36  explicit TrackOverlapECalc(fhicl::ParameterSet const & pset);
37  virtual ~TrackOverlapECalc();
38 
39  void produce(art::Event & evt);
40  void beginRun(art::Run& run);
41 
42  private:
43 
44  murem::TrackCleanUpAlg* fTrackCleanUpAlg; ///< Track Clean Up Algorithm Object
45  fhicl::ParameterSet fTrackCleanUpAlgPSet; ///< Parameter Set to configure the TrackCleanUpAlg object
46  std::string fSlicerModuleLabel; ///< Label for the slicing module
47  std::string fTrackModuleLabel_1; ///< Label for the first tracking module (and also the instance label for the energy objects)
48  std::string fTrackModuleLabel_2; ///< Label for the second tracking module (and also the instance label for the energy objects)
49 
50  double fMUmipHigh; ///< high mip value for muon tracks
51  double fMUmipLow; ///< low mip value for muon tracks
52  double fMUmip; ///< mip value for muon tracks
53  double fMUvertex; ///< dE/dx cut off value for determining the vertex region for muon tracks
54 
55  double fPImipHigh; ///< high mip value for pion tracks
56  double fPImipLow; ///< low mip value for pion tracks
57  double fPImip; ///< mip value for pion tracks
58  double fPIvertex; ///< dE/dx cut off value for determining the vertex region for pion tracks
59 
60  double fPRmipHigh; ///< high mip value for proton tracks
61  double fPRmipLow; ///< low mip value for proton tracks
62  double fPRmip; ///< mip value for proton tracks
63  double fPRvertex; ///< dE/dx cut off value for determining the vertex region for proton tracks
64 
65  };
66 
67  //----------------------------------------------------------------------
69  fTrackCleanUpAlg ( 0 ),
70  fTrackCleanUpAlgPSet ( pset.get< fhicl::ParameterSet > ("TrackCleanUpAlgPSet") ),
71  fSlicerModuleLabel ( pset.get< std::string > ("SlicerModuleLabel" ) ),
72  fTrackModuleLabel_1 ( pset.get< std::string > ("TrackModuleLabel_1" ) ),
73  fTrackModuleLabel_2 ( pset.get< std::string > ("TrackModuleLabel_2" ) ),
74  fMUmipHigh ( pset.get< double > ("MUmipHigh" ) ),
75  fMUmipLow ( pset.get< double > ("MUmipLow" ) ),
76  fMUmip ( pset.get< double > ("MUmip" ) ),
77  fMUvertex ( pset.get< double > ("MUvertexRegionCutOff" ) ),
78  fPImipHigh ( pset.get< double > ("PImipHigh" ) ),
79  fPImipLow ( pset.get< double > ("PImipLow" ) ),
80  fPImip ( pset.get< double > ("PImip" ) ),
81  fPIvertex ( pset.get< double > ("PIvertexRegionCutOff" ) ),
82  fPRmipHigh ( pset.get< double > ("PRmipHigh" ) ),
83  fPRmipLow ( pset.get< double > ("PRmipLow" ) ),
84  fPRmip ( pset.get< double > ("PRmip" ) ),
85  fPRvertex ( pset.get< double > ("PRvertexRegionCutOff" ) )
86  {
87  this->produces< std::vector<rb::Energy> > (fTrackModuleLabel_1); // using track label as instance label too...
88  this->produces< art::Assns<rb::Energy, rb::Track> > (fTrackModuleLabel_1); // using track label as instance label too...
89  this->produces< std::vector<rb::Energy> > (fTrackModuleLabel_2); // using track label as instance label too...
90  this->produces< art::Assns<rb::Energy, rb::Track> > (fTrackModuleLabel_2); // using track label as instance label too...
91  }
92 
93 
94  //----------------------------------------------------------------------
96  {
98  }
99 
100  //----------------------------------------------------------------------
102  {
103  // Have to recreate these because behavior can depend on run number
104  // (apparently...)
107  }
108 
109  //----------------------------------------------------------------------
111  {
112 
113  // Load slices list from the event.
115  evt.getByLabel(fSlicerModuleLabel, slicecol);
116 
117  // Get the first set of tracks associated with the slices.
118  art::FindManyP<rb::Track> sliceToTracks_1(slicecol, evt, fTrackModuleLabel_1);
119 
120  // Get the second set of tracks associated with the slices.
121  art::FindManyP<rb::Track> sliceToTracks_2(slicecol, evt, fTrackModuleLabel_2);
122 
123  // Declare containers for things to be stored in event.
124  std::unique_ptr< std::vector<rb::Energy> > trackECol_1 (new std::vector<rb::Energy>);
125  std::unique_ptr< art::Assns<rb::Energy, rb::Track> > trackAssoc_1(new art::Assns<rb::Energy, rb::Track>);
126  std::unique_ptr< std::vector<rb::Energy> > trackECol_2 (new std::vector<rb::Energy>);
127  std::unique_ptr< art::Assns<rb::Energy, rb::Track> > trackAssoc_2(new art::Assns<rb::Energy, rb::Track>);
128 
129 
130 
131  // Loop over the slices
132  for(size_t islice = 0; islice < slicecol->size(); ++islice){
133  const art::Ptr<rb::Cluster> slice(slicecol, islice);
134 
135  // As usual, skip the noise slice.
136  if(slice->IsNoise()) continue;
137 
138  // Get all of the tracks from the first tracker in the slice.
139  const std::vector< art::Ptr<rb::Track> > sliceTracks_1 = sliceToTracks_1.at(islice);
140 
141  // Get all of the tracks from the second tracker in the slice.
142  const std::vector< art::Ptr<rb::Track> > sliceTracks_2 = sliceToTracks_2.at(islice);
143 
144  // Create the FindMany object for getting FitSum objects created by the second tracker.
145  art::FindManyP<rb::FitSum> fitsumFMP(sliceTracks_2, evt, fTrackModuleLabel_2);
146 
147 
148 
149  // Loop over the first set of tracks:
150  //
151  // NOTE: These tracks are assumed to be the Kalman tracks, therefore
152  // we will use the muon assumption for all tracks.
153  if( !(sliceTracks_1.empty()) ) {
154  for(unsigned int itrack = 0; itrack < sliceTracks_1.size(); ++itrack) {
155 
156  // make the energy object
157  rb::Energy trackE;
158 
159  // call TrackCleanUpAlg and set the energy
160  trackE.SetE( (float)(fTrackCleanUpAlg->ExtraEOnTrackInGeV(*sliceTracks_1[itrack], *slice,
162  trackECol_1->push_back(trackE);
163 
164  // make the association
165  util::CreateAssn(*this, evt, *(trackECol_1.get()), sliceTracks_1[itrack], *(trackAssoc_1.get()),
166  UINT_MAX, fTrackModuleLabel_1); // using track label as instance label too...
167 
168  } // End loop over first set of tracks (itrack)
169  } // End if( !(sliceTracks_1.empty()) )
170 
171 
172 
173  // Loop over the second set of tracks:
174  //
175  // NOTE: These tracks are assumed to be the BPF tracks, therefore
176  // we will use the appropriate assumption for each track.
177  if( !(sliceTracks_2.empty()) ) {
178  for(unsigned int itrack = 0; itrack < sliceTracks_2.size(); ++itrack) {
179 
180  // Get the FitSum object associated with this track.
181  std::vector< art::Ptr< rb::FitSum > > fitsums;
182  if(fitsumFMP.isValid()) fitsums = fitsumFMP.at(itrack);
183  if(fitsums.size() == 0) continue; // this should never happen, but just in case...
184 
185  // make the energy object
186  rb::Energy trackE;
187 
188  // Determine the particle assumption and set the mip values:
189  double mipHigh = 0.0;
190  double mipLow = 0.0;
191  double mip = 0.0;
192  double vertex = 0.0;
193  if(fitsums[0]->PDG() == 13) { // muon...
194  mipHigh = fMUmipHigh;
195  mipLow = fMUmipLow;
196  mip = fMUmip;
197  vertex = fMUvertex;
198  }
199  else if(fitsums[0]->PDG() == 211) { // pion...
200  mipHigh = fPImipHigh;
201  mipLow = fPImipLow;
202  mip = fPImip;
203  vertex = fPIvertex;
204  }
205  else if(fitsums[0]->PDG() == 2212) { // proton...
206  mipHigh = fPRmipHigh;
207  mipLow = fPRmipLow;
208  mip = fPRmip;
209  vertex = fPRvertex;
210  }
211  else {
212  std::cout << "\n\n\nWARNING! PDG code: "
213  << fitsums[0]->PDG()
214  << " not currently supported!\n\n\n";
215  continue;
216  }
217 
218  // call TrackCleanUpAlg and set the energy
219  trackE.SetE( (float)(fTrackCleanUpAlg->ExtraEOnTrackInGeV(*sliceTracks_2[itrack], *slice,
220  &mipHigh, &mipLow, &mip, &vertex)));
221  trackECol_2->push_back(trackE);
222 
223  // make the association
224  util::CreateAssn(*this, evt, *(trackECol_2.get()), sliceTracks_2[itrack], *(trackAssoc_2.get()),
225  UINT_MAX, fTrackModuleLabel_2); // using track label as instance label too...
226 
227  } // End loop over second set of tracks (itrack)
228  } // End if( !(sliceTracks_2.empty()) )
229 
230  } // End of loop over slices (islice).
231 
232 
233 
234  // Put objects and associations into the file.
235  evt.put(std::move(trackECol_1), fTrackModuleLabel_1); // using track label as instance label too...
236  evt.put(std::move(trackAssoc_1), fTrackModuleLabel_1); // using track label as instance label too...
237  evt.put(std::move(trackECol_2), fTrackModuleLabel_2); // using track label as instance label too...
238  evt.put(std::move(trackAssoc_2), fTrackModuleLabel_2); // using track label as instance label too...
239 
240  return;
241 
242  } // End of produce function.
243 
244  //----------------------------------------------------------------------
246 
247 } // End of namespace
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.
Definition: event.h:34
void SetE(float energy)
Definition: Energy.cxx:21
Energy estimators for CC events.
Definition: FillEnergies.h:7
std::string fTrackModuleLabel_1
Label for the first tracking module (and also the instance label for the energy objects) ...
double fMUmipLow
low mip value for muon tracks
double fPImipLow
low mip value for pion tracks
DEFINE_ART_MODULE(TestTMapFile)
TrackOverlapECalc(fhicl::ParameterSet const &pset)
Definition: Run.h:31
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
murem::TrackCleanUpAlg * fTrackCleanUpAlg
Track Clean Up Algorithm Object.
int evt
double fPRmipLow
low mip value for proton tracks
double fPImipHigh
high mip value for pion tracks
Definition: run.py:1
double fMUmip
mip value for muon tracks
OStream cout
Definition: OStream.cxx:6
double fMUmipHigh
high mip value for muon tracks
double fPIvertex
dE/dx cut off value for determining the vertex region for pion tracks
double fPImip
mip value for pion tracks
A container for energy information.
Definition: Energy.h:20
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
double fMUvertex
dE/dx cut off value for determining the vertex region for muon tracks
double fPRmipHigh
high mip value for proton tracks
double fPRmip
mip value for proton tracks
bool IsNoise() const
Is the noise flag set?
Definition: Cluster.h:163
float ExtraEOnTrackInGeV(const rb::Track &track, const rb::Cluster &slice, double *mipRangeHigh=NULL, double *mipRangeLow=NULL, double *mipValue=NULL, double *vertexRegionDeDxCutOff=NULL)
double fPRvertex
dE/dx cut off value for determining the vertex region for proton tracks
std::string fSlicerModuleLabel
Label for the slicing module.
Encapsulate the geometry of one entire detector (near, far, ndos)
std::string fTrackModuleLabel_2
Label for the second tracking module (and also the instance label for the energy objects) ...
fhicl::ParameterSet fTrackCleanUpAlgPSet
Parameter Set to configure the TrackCleanUpAlg object.
enum BeamMode string