PlotTrackDetails_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // PlotTrackDetails_module.cc
4 //
5 // Author: Leigh Whitehead (leigh.howard.whitehead@cern.ch)
6 //
7 // Module to provide basic tracking information for protoDUNE
8 // Nearline Monitoring
9 //
10 ////////////////////////////////////////////////////////////////////////
11 
19 #include "fhiclcpp/ParameterSet.h"
21 
30 #include "art_root_io/TFileService.h"
31 #include "art_root_io/TFileDirectory.h"
32 #include "canvas/Persistency/Common/FindManyP.h"
33 
34 #include <fstream>
35 
36 #include "TH1F.h"
37 
38 namespace nlana {
39  class PlotTrackDetails;
40 }
41 
43 public:
44  explicit PlotTrackDetails(fhicl::ParameterSet const & p);
45  // The compiler-generated destructor is fine for non-base
46  // classes without bare pointers or other resource use.
47 
48  // Plugins should not be copied or assigned.
49  PlotTrackDetails(PlotTrackDetails const &) = delete;
51  PlotTrackDetails & operator = (PlotTrackDetails const &) = delete;
53 
54  // Required functions.
55  void analyze(art::Event const & e) override;
56 
57  // Selected optional functions.
58  void beginJob() override;
59  void endJob() override;
60  void reconfigure(fhicl::ParameterSet const & p) ;
61 
62 private:
63 
65 
66  // Number of tracks
67  TH1F *fNTracksHist;
68 
69  // Cosmic tagged tracks
71 
72  // Number of T0 tag plots
73  TH1F *fNT0Hist;
74 
75  // T0 plots
76  TH1F *fT0Hist;
77  TH1F *fT0HistHiRes;
80 
81 };
82 
83 
85  :
86  EDAnalyzer(pset) // ,
87  // More initializers here.
88 {
89  reconfigure(pset);
90 
91 }
92 
93 //--------------------------------------------------------------------
95 {
96  // Implementation of optional member function here.
97 
99 
100  fNTracksHist = tfs->make<TH1F>("NTracks",";Number of tracks",50,0,200);
101  fNCosmicTagHist = tfs->make<TH1F>("NCosmicTag",";Number of tracks tagged as cosmic",50,0,200);
102  fNT0Hist = tfs->make<TH1F>("NT0s",";Number of tracks with reconstructed T0",50,0,40);
103 
104  fT0Hist = tfs->make<TH1F>("TrackT0",";T0 (us)",100,-4000,4000);
105  fT0HistHiRes = tfs->make<TH1F>("TrackT0HiRes",";T0 (us)",1000,-4000,4000);
106  fCosmicT0Hist = tfs->make<TH1F>("CosmicTrackT0",";T0 (us)",100,-4000,4000);
107  fCosmicT0HistHiRes = tfs->make<TH1F>("CosmicTrackT0HiRes",";T0 (us)",1000,-4000,4000);
108 
109 } // beginJob
110 
111 //--------------------------------------------------------------------
113 {
114  // The name of the module that produced the tracks
115  fTrackProducerLabel = pset.get<std::string>("TrackProducerLabel");
116 } // reconfigure
117 
118 
119 //--------------------------------------------------------------------
121 {
122 
123 } // endJob
124 
125 //--------------------------------------------------------------------
127 {
128 
129  // Try finding some tracks
131  = evt.getValidHandle<std::vector<recob::Track> >(fTrackProducerLabel);
132 
133  // Find the associations between tracks and T0
134  const art::FindManyP<anab::T0> findTrackT0(trackHandle,evt,fTrackProducerLabel);
135 
136  // Also look for cosmic tags so we can make a T0 plot for cosmic tagged events only
137  const art::FindManyP<anab::CosmicTag> findCosmicTag(trackHandle,evt,fTrackProducerLabel);
138 
139  fNTracksHist->Fill(trackHandle->size());
140 
141  unsigned int nT0s = 0;
142  unsigned int nTags = 0;
143 
144  for ( size_t track_index = 0; track_index != trackHandle->size(); ++track_index )
145  {
146  const auto thisTrack = (*trackHandle)[track_index];
147 
148  // Did this track have an associated T0?
149  auto const& t0s = findTrackT0.at(track_index);
150  if(t0s.size() != 0){
151  ++nT0s;
152  fT0Hist->Fill(t0s[0]->Time());
153  fT0HistHiRes->Fill(t0s[0]->Time());
154  }
155  // Did this track have a cosmic tag?
156  auto const& tag = findCosmicTag.at(track_index);
157  if(tag.size() != 0){
158  ++nTags;
159  }
160 
161  if(t0s.size() && tag.size()){
162  fCosmicT0Hist->Fill(t0s[0]->Time());
163  fCosmicT0HistHiRes->Fill(t0s[0]->Time());
164  }
165 
166  }
167 
168  fNCosmicTagHist->Fill(nTags);
169  fNT0Hist->Fill(nT0s);
170 
171 } // analyze
172 
173 
PlotTrackDetails & operator=(PlotTrackDetails const &)=delete
std::string string
Definition: nybbler.cc:12
PlotTrackDetails(fhicl::ParameterSet const &p)
void analyze(art::Event const &e) override
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art framework interface to geometry description
void reconfigure(fhicl::ParameterSet const &p)
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
Definition of data types for geometry description.
Declaration of signal hit object.
Provides recob::Track data product.
TCEvent evt
Definition: DataStructs.cxx:7