MergeTruth_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file MergeTruth.cxx
3 /// \brief A module to produce truth information for Muon-Removed-Electron CC events.
4 ///
5 /// \version $Id: MergeTruth.cxx,v 1.2 2012-09-20 22:01:37 greenc Exp $
6 /// \author Kanika Sachdev (ksachdev@physics.umn.edu)
7 ////////////////////////////////////////////////////////////////////////
8 
9 // C/C++ includes
10 #include <iostream>
11 #include <vector>
12 
13 // Root includes
14 #include "TLorentzVector.h"
15 
16 // Framework includes
25 
26 // NOvASoft includes
27 
28 #include "Simulation/FLSHitList.h"
30 #include "Simulation/Particle.h"
32 #include "MCCheater/BackTracker.h"
33 
34 
35 namespace murem
36 {
37  namespace{
38  struct MergeTruthParams
39  {
40  template<class T> using Atom = fhicl::Atom<T>;
41  template<class T> using Table = fhicl::Table<T>;
42  using Comment = fhicl::Comment;
43  using Name = fhicl::Name;
44 
45  Atom<std::string> particleLabel
46  {
47  Name("ParticleLabel"),
48  Comment("module label of particle list")
49  };
50  Atom<std::string> photonLabel
51  {
52  Name("PhotonLabel"),
53  Comment("module label of photons")
54  };
55  Atom<std::string> mcTruthLabel
56  {
57  Name("MCTruthLabel"),
58  Comment("module label of mc truth")
59  };
60  Atom<std::string> mreTruthLabel
61  {
62  Name("MreTruthLabel"),
63  Comment("module label of mre truth")
64  };
65  Atom<std::string> mrePhotonLabel
66  {
67  Name("MrePhotonLabel"),
68  Comment("module label of mre photons")
69  };
70  Atom<std::string> mrccInfoLabel
71  {
72  Name("MrccInfoLabel"),
73  Comment("module label of mrcc info object")
74  };
75  };
76  }
77  class MergeTruth : public art::EDProducer
78  {
79  public:
80  // Allows 'nova --print-description' to work
82 
83  explicit MergeTruth(const Parameters& params);
84  ~MergeTruth();
85 
86  void produce(art::Event& evt);
87 
88  private:
89 
90  MergeTruthParams fParams;
91  };
92 }
93 
94 namespace murem
95 {
96 
97  /*********************************************************************************************/
98  ////////////////////////////////////////////////////////////////////////
99 
101  :fParams(params())
102  {
103  produces< std::vector <sim::FLSHitList> >();
104  produces< std::vector <sim::PhotonSignal> >();
105  produces< std::vector <sim::Particle> >();
106 
107  mf::LogInfo("MergeTruth") <<"MergeTruth::MergeTruth()\n";
108 
109  }
110 
111  /*********************************************************************************************/
112  ////////////////////////////////////////////////////////////////////////
113 
115  {
116 
117  }
118 
119  /*********************************************************************************************/
120  ////////////////////////////////////////////////////////////////////////
121 
123  {
124 
125  std::unique_ptr< std::vector<sim::FLSHitList> > flsHits(new std::vector<sim::FLSHitList>);
126  std::unique_ptr< std::vector<sim::Particle> > particleList(new std::vector<sim::Particle>);
127  std::unique_ptr< std::vector<sim::PhotonSignal> > photonSignal(new std::vector<sim::PhotonSignal>);
128  //std::unique_ptr< std::vector<simb::MCTruth> > mcTruth(new std::vector<simb::MCTruth>);
129 
131 
132  // The following handle has no use but to indicate if the muon
133  // was removed my truth. If not, there's not much sense in producing
134  // merged truth. Exit asap- don't waste time!
135 
137  evt.getByLabel(fParams.mrccInfoLabel(), mrccFlsHandle);
138  if( mrccFlsHandle.failedToGet() ) return;
139 
140  // Grab the Electron Truth Info saved to the
141  // file by the MRE modeule. They live under
142  // label "mregen". Photons live under "elecphotrans"
143 
144 
146  evt.getByLabel(fParams.mreTruthLabel(), elecTruthHandle);
147  if( elecTruthHandle.failedToGet() ) return;
148 
150  evt.getByLabel(fParams.mreTruthLabel(), elecFlsHandle);
151  if( elecFlsHandle.failedToGet() ) return;
152 
153  art::Handle< std::vector<sim::Particle> > elecPlistHandle;
154  evt.getByLabel(fParams.mreTruthLabel(), elecPlistHandle);
155  if( elecPlistHandle.failedToGet() ) return;
156 
158  evt.getByLabel(fParams.mrePhotonLabel(), elecSigHandle);
159  if( elecSigHandle.failedToGet() ) return;
160 
161  // Get the original truth information.
162 
164  evt.getByLabel(fParams.mcTruthLabel(), truthHandle);
165  if( truthHandle.failedToGet() ) return;
166 
168  evt.getByLabel(fParams.particleLabel(), flslistHandle);
169  if( flslistHandle.failedToGet() ) return;
170 
172  evt.getByLabel(fParams.particleLabel(), plistHandle);
173  if( plistHandle.failedToGet() ) return;
174 
176  evt.getByLabel(fParams.photonLabel(), photSigHandle);
177  if( photSigHandle.failedToGet() ) return;
178 
179 
180  ////////////////////////////////////////////////////////////////
181 
182  // Grab the removed muon info and map the muon trackID to electron
183 
185  evt.getByLabel(fParams.mrccInfoLabel(), muInfoHandle);
186 
187  std::map< unsigned int, unsigned int> muToElec;
188  std::set <int> muonID;
189 
190  int nMuInfoHandles = muInfoHandle->size();
191  for( int m = 0; m < nMuInfoHandles; m++){
192  simb::MCParticle muon = (*muInfoHandle)[m];
193  muonID.insert(muon.TrackId());
194 
195  int nElecHandles = elecTruthHandle->size();
196  for(int e = 0; e < nElecHandles; e++){
197  simb::MCParticle elec = (*elecTruthHandle)[e].GetParticle(0);
198 
199  if( (elec.Vx(0) == muon.Vx(0)) && (elec.Vy(0) == muon.Vy(0)) && (elec.Vz(0) == muon.Vz(0)) && (elec.P(0) && muon.P(0))){
200  muToElec[ muon.TrackId()] = elec.TrackId();
201  }
202  }// end loop over electron MCTruths
203  }// end loop over removed muons
204 
205 
206  ////////////////////////////////////////////////////////////////
207 
208  int nFlsHandles = flslistHandle->size();
209  for( int l = 0; l < nFlsHandles; ++l){
210  int matchedElecID = 0;
211  sim::FLSHitList newFLSList;
212 
213  const std::vector<sim::FLSHit> &hits = flslistHandle->at(l).fHits;
214 
215  for( int f = 0; f < (int)hits.size(); ++f){
216  bool hitIsFromMuon = false;
217  int hitID = hits[f].GetTrackID();
218  int motherID = bt->TrackIDToMotherParticle(hitID)->TrackId();
219 
220  if( (muonID.find(motherID) != muonID.end())){
221  matchedElecID = muToElec[ motherID ];
222  hitIsFromMuon = true;
223  }
224  else if (muonID.find(hitID) != muonID.end()){
225  matchedElecID = muToElec[ hitID ];
226  hitIsFromMuon = true;
227  }
228 
229  if(!hitIsFromMuon)
230  newFLSList.fHits.push_back(hits[f]);
231  }// end loop over flshits in this FLSHitList
232 
233 
234  int nElecFlsHandles = elecFlsHandle->size();
235  for( int e = 0; e < nElecFlsHandles; e++){
236  int matchedElecList = -1;
237  const std::vector<sim::FLSHit> &elechits = elecFlsHandle->at(e).fHits;
238  for(int f = 0; f < (int)elechits.size(); f++){
239  if( elechits[f].GetTrackID() == matchedElecID ){
240  matchedElecList = e;
241  break;
242  }
243  if(matchedElecList)
244  break;
245  }//end loop over elec fls hits
246 
247  if(matchedElecList != -1){
248  const std::vector<sim::FLSHit> &elechits = elecFlsHandle->at(matchedElecList).fHits;
249  int nElecFlsHits = elechits.size();
250  for(int el = 0; el < nElecFlsHits; el++)
251  newFLSList.fHits.push_back(elechits[el]);
252  }
253  }// end loop over elecflslists
254 
255  flsHits->push_back(newFLSList);
256 
257  }// end loop over flshit lists
258 
259 
260  ////////////////////////////////////////////////////////////////
261 
262  int nPhots = photSigHandle->size();
263  for( int l = 0; l < nPhots; ++l){
264  sim::PhotonSignal phot = (*photSigHandle)[l];
265  bool photIsFromMuon = false;
266  int photID = phot.TrackId();
267  int motherID = bt->TrackIDToMotherParticle( photID )->TrackId() ;
268 
269  if( (muonID.find(motherID) != muonID.end()) || (muonID.find(photID) != muonID.end()) )
270  photIsFromMuon = true;
271 
272  if(!photIsFromMuon)
273  photonSignal->push_back(phot);
274 
275  }// end loop over photons
276 
277  int nElecPhots = elecSigHandle->size();
278  for( int e = 0; e < nElecPhots; e++){
279  sim::PhotonSignal phot = (*elecSigHandle)[e];
280  photonSignal->push_back(phot);
281  }
282 
283 
284  ////////////////////////////////////////////////////////////////
285 
286 
287  for( size_t l = 0; l < plistHandle->size(); ++l){
288  sim::Particle part = (*plistHandle)[l];
289  bool partIsFromMuon = false;
290 
291  int partID = part.TrackId();
292  int motherID = part.Mother();
293 
294  if( (muonID.find(motherID) != muonID.end()) || (muonID.find(partID) != muonID.end()) ) {
295  partIsFromMuon = true;
296  }
297 
298  if(!partIsFromMuon)
299  particleList->push_back(part);
300  }// end loop over photons
301 
302  for( int e = 0; e < (int)elecPlistHandle->size(); e++){
303  sim::Particle elec = (*elecPlistHandle)[e];
304  particleList->push_back(elec);
305  }
306 
307 
308  ////////////////////////////////////////////////////////////////
309 
310  // Write the objects to the events
311 
312  evt.put(std::move(flsHits));
313  evt.put(std::move(photonSignal));
314  evt.put(std::move(particleList));
315 
316  return;
317 
318  } // End of producer
319 
320 
322 
323 
324 /*********************************************************************************************/
325 ////////////////////////////////////////////////////////////////////////
326 
327 }//end of namespace murem
MergeTruthParams fParams
back track the reconstruction to the simulation
Atom< std::string > mrePhotonLabel
std::vector< sim::FLSHit > fHits
Definition: FLSHitList.h:21
const sim::Particle * TrackIDToMotherParticle(int const &id) const
int TrackId() const
Definition: PhotonSignal.h:33
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
int Mother() const
Definition: MCParticle.h:212
DEFINE_ART_MODULE(TestTMapFile)
int TrackId() const
Definition: MCParticle.h:209
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
TString part[npart]
Definition: Style.C:32
void produce(art::Event &evt)
void hits()
Definition: readHits.C:15
Atom< std::string > photonLabel
double P(const int i=0) const
Definition: MCParticle.h:233
Atom< std::string > particleLabel
MergeTruth(const Parameters &params)
Atom< std::string > mcTruthLabel
Atom< std::string > mreTruthLabel
double Vx(const int i=0) const
Definition: MCParticle.h:220
A vector of FLSHit from single neutrino interaction.
Definition: FLSHitList.h:13
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
double Vz(const int i=0) const
Definition: MCParticle.h:222
particleList
Definition: demo.py:41
Float_t e
Definition: plot.C:35
double Vy(const int i=0) const
Definition: MCParticle.h:221
bool failedToGet() const
Definition: Handle.h:196
Atom< std::string > mrccInfoLabel