LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
FlashPurityCheckAna_module.cc
Go to the documentation of this file.
1 // This analyzer writes out a TTree containing the properties of
2 // each reconstructed flash
3 //
4 #ifndef FlashPurityCheckAna_H
5 #define FlashPurityCheckAna_H 1
6 
7 // ROOT includes
8 #include "TH1.h"
9 #include "TH2.h"
10 #include "TLorentzVector.h"
11 #include "TVector3.h"
12 #include "TTree.h"
13 
14 // C++ includes
15 #include <map>
16 #include <vector>
17 #include <iostream>
18 #include <cstring>
19 #include <sstream>
20 #include "math.h"
21 #include <climits>
22 
23 // LArSoft includes
29 
30 // ART includes.
34 #include "fhiclcpp/ParameterSet.h"
46 
47 
49 
50 namespace opdet {
51 
53  public:
54 
55  // Standard constructor and destructor for an ART module.
57  virtual ~FlashPurityCheckAna();
58 
59  // This method is called once, at the start of the job. In this
60  // example, it will define the histogram we'll write.
61  void beginJob();
62 
63  // The analyzer routine, called once per event.
64  void analyze (const art::Event&);
65 
66  private:
67 
68  // The stuff below is the part you'll most likely have to change to
69  // go from this custom example to your own task.
70 
71  // The parameters we'll read from the .fcl file.
72  std::string fOpFlashModuleLabel; // Input tag for OpFlash collection
73  std::string fTrackModuleLabel; // Input tag for OpFlash collection
74  std::string fMatchModuleLabel; // Input tag for OpFlash collection
75  std::string fGenieGenModuleLabel; // Input tag for OpFlash collection
76 
77 
78  TTree * fPerEventTree;
79 
80  Float_t fEventID;
81 
82  Float_t VertexX, VertexY, VertexZ;
83  Int_t fNVtxTracks;
91 
92 
93  };
94 
95 }
96 
97 #endif // FlashPurityCheckAna_H
98 
99 namespace opdet {
100 
101  //-----------------------------------------------------------------------
102  // Constructor
104  : EDAnalyzer(pset)
105  {
106 
107 
108  // Indicate that the Input Module comes from .fcl
109  fOpFlashModuleLabel = pset.get<std::string>("OpFlashModuleLabel");
110  fTrackModuleLabel = pset.get<std::string>("TrackModuleLabel");
111  fMatchModuleLabel = pset.get<std::string>("MatchModuleLabel");
112  fGenieGenModuleLabel = pset.get<std::string>("GenieGenModuleLabel");
113 
114 
116 
117 
118 
119  fPerEventTree = tfs->make<TTree>("PerEventTree","PerEventTree");
120  fPerEventTree->Branch("NVtxTracks", &fNVtxTracks, "NVtxTracks/I");
121  fPerEventTree->Branch("NVtxTracksRejected", &fNVtxTracksRejected, "NVtxTracksRejected/I");
122  fPerEventTree->Branch("NVtxTracks20cm", &fNVtxTracks20cm, "NVtxTracks20cm/I");
123  fPerEventTree->Branch("NVtxTracksRejected20cm", &fNVtxTracksRejected20cm, "NVtxTracksRejected20cm/I");
124  fPerEventTree->Branch("NNonVtxTracks", &fNNonVtxTracks, "NNonVtxTracks/I");
125  fPerEventTree->Branch("NNonVtxTracksRejected", &fNNonVtxTracksRejected, "NNonVtxTracksRejected/I");
126  fPerEventTree->Branch("NNonVtxTracks20cm", &fNNonVtxTracks20cm, "NNonVtxTracks20cm/I");
127  fPerEventTree->Branch("NNonVtxTracksRejected20cm", &fNNonVtxTracksRejected20cm, "NNonVtxTracksRejected20cm/I");
128 
129 
130 
131  }
132 
133  //-----------------------------------------------------------------------
134  // Destructor
136  {}
137 
138  //-----------------------------------------------------------------------
140  {
141  }
142 
143 
144  //-----------------------------------------------------------------------
146  {
147 
148  // Get flashes from event
150  evt.getByLabel(fOpFlashModuleLabel, FlashHandle);
151 
152  // Get matches
154  evt.getByLabel(fMatchModuleLabel, MatchHandle);
155 
156 
157  // Get tracks
158 
160  evt.getByLabel(fTrackModuleLabel, trackh);
161 
162  std::vector<art::Ptr<recob::Track> > Tracks;
163  for(unsigned int i=0; i < trackh->size(); ++i)
164  {
165  art::Ptr<recob::Track> track(trackh,i);
166  Tracks.push_back(track);
167  }
168  std::vector<trkf::BezierTrack*> BTracks;
169  BTracks.clear();
170  for(size_t i=0; i!=Tracks.size(); i++)
171  BTracks.push_back(new trkf::BezierTrack(*Tracks.at(i)));
172  std::cout<<"N Tracks : " << BTracks.size()<<std::endl;
173 
174 
175 
176 
177  // Get MC Truth
178  art::Handle< std::vector<simb::MCTruth> > mctruthListHandle;
179  std::vector<art::Ptr<simb::MCTruth> > mclist;
180  if (evt.getByLabel(fGenieGenModuleLabel,mctruthListHandle))
181  art::fill_ptr_vector(mclist, mctruthListHandle);
182 
183  if(mclist.size()==0)
184  std::cout<<"confused! MC list is zero length!"<<std::endl;
185  else
186  {
187  art::Ptr<simb::MCTruth> mctruth = mclist[0];
188 
189 
190  // art::FindManyP<recob::OpFlash> FlashesFMH(MatchHandle, evt, fMatchModuleLabel);
192 
193  std::cout<<"No of FMH entries : " << MatchFMH.size()<<std::endl;
194  std::vector<bool> Rejected(Tracks.size(), false);
195 
196  for(size_t i=0; i!=Tracks.size(); ++i)
197  {
198  std::cout<<"FMH at " << i << " is " << MatchFMH.at(i).size()<<std::endl;
199  for(size_t j=0; j!=MatchFMH.at(i).size(); ++j)
200  {
201  if(!MatchFMH.at(i).at(j)->InBeam())
202  Rejected[i]=true;
203  }
204  }
205 
206 
207 
208  fEventID=evt.id().event();
209 
210 
211  fNVtxTracks20cm =0 ;
213  fNVtxTracks =0 ;
215  fNNonVtxTracks =0;
219 
220 
221  // if (mctruth->NeutrinoSet())
222  // {
223  VertexX = mctruth->GetNeutrino().Nu().Vx();
224  VertexY = mctruth->GetNeutrino().Nu().Vy();
225  VertexZ = mctruth->GetNeutrino().Nu().Vz();
226 
227  TVector3 Vertex = TVector3(VertexX,VertexY, VertexZ);
228  //std::cout<<"Vertex is at " << vtxx_truth<<", " << vtxy_truth<<", " << vtxz_truth<<std::endl;
229  double s=0, d=0;
230  for(size_t i=0; i!=BTracks.size(); ++i)
231  {
232  BTracks.at(i)->GetClosestApproach(Vertex, s, d);
233  if(d<2)
234  {
235  fNVtxTracks++;
236  if(Rejected[i]) fNVtxTracksRejected++;
237  if(BTracks.at(i)->GetTrajectory().Length()>20)
238  {
239  fNVtxTracks20cm++;
240  if(Rejected[i]) fNVtxTracksRejected20cm++;
241  }
242  }
243  else
244  {
245  fNNonVtxTracks++;
246  if(Rejected[i]) fNNonVtxTracksRejected++;
247  if(BTracks.at(i)->GetTrajectory().Length()>20)
248  {
250  if(Rejected[i]) fNNonVtxTracksRejected20cm++;
251  }
252  }
253  }
254 
255  }
256  fPerEventTree->Fill();
257  // }
258  }
259 
260 } // namespace opdet
261 
262 namespace opdet {
264 }
265 
Float_t s
Definition: plot.C:23
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:74
const simb::MCParticle & Nu() const
Definition: MCNeutrino.h:150
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
Float_t d
Definition: plot.C:237
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
double Vx(const int i=0) const
Definition: MCParticle.h:225
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
double Vz(const int i=0) const
Definition: MCParticle.h:227
EventNumber_t event() const
Definition: EventID.h:117
FlashPurityCheckAna(const fhicl::ParameterSet &)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
Float_t track
Definition: plot.C:34
EventID id() const
Definition: Event.h:56
double Vy(const int i=0) const
Definition: MCParticle.h:226
art framework interface to geometry description