PlotTrackT0_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // PlotTrackT0_module.cc
4 //
5 // Author: Leigh Whitehead (leigh.howard.whitehead@cern.ch)
6 //
7 // Make a histogram of the T0 of those tracks that have it measured
8 //
9 ////////////////////////////////////////////////////////////////////////
10 
18 #include "fhiclcpp/ParameterSet.h"
20 
29 #include "art_root_io/TFileService.h"
30 #include "art_root_io/TFileDirectory.h"
31 #include "canvas/Persistency/Common/FindManyP.h"
32 
33 #include <fstream>
34 
35 #include "TH1F.h"
36 
37 namespace nlana {
38  class PlotTrackT0;
39 }
40 
42 public:
43  explicit PlotTrackT0(fhicl::ParameterSet const & p);
44  // The compiler-generated destructor is fine for non-base
45  // classes without bare pointers or other resource use.
46 
47  // Plugins should not be copied or assigned.
48  PlotTrackT0(PlotTrackT0 const &) = delete;
49  PlotTrackT0(PlotTrackT0 &&) = delete;
50  PlotTrackT0 & operator = (PlotTrackT0 const &) = delete;
51  PlotTrackT0 & operator = (PlotTrackT0 &&) = delete;
52 
53  // Required functions.
54  void analyze(art::Event const & e) override;
55 
56  // Selected optional functions.
57  void beginJob() override;
58  void endJob() override;
59  void reconfigure(fhicl::ParameterSet const & p) ;
60 
61 private:
62 
64 
65  TH1F *fT0Hist;
66  TH1F *fT0HistHiRes;
69 
70 };
71 
72 
74  :
75  EDAnalyzer(pset) // ,
76  // More initializers here.
77 {
78  reconfigure(pset);
79 
80 }
81 
82 //--------------------------------------------------------------------
84 {
85  // Implementation of optional member function here.
86 
88  fT0Hist = tfs->make<TH1F>("TrackT0",";T0 (us)",100,-4000,4000);
89  fT0HistHiRes = tfs->make<TH1F>("TrackT0HiRes",";T0 (us)",1000,-4000,4000);
90  fCosmicT0Hist = tfs->make<TH1F>("CosmicTrackT0",";T0 (us)",100,-4000,4000);
91  fCosmicT0HistHiRes = tfs->make<TH1F>("CosmicTrackT0HiRes",";T0 (us)",1000,-4000,4000);
92 
93 } // beginJob
94 
95 //--------------------------------------------------------------------
97 {
98  // The name of the module that produced the tracks
99  fTrackProducerLabel = pset.get<std::string>("TrackProducerLabel");
100 } // reconfigure
101 
102 
103 //--------------------------------------------------------------------
105 {
106 
107 } // endJob
108 
109 //--------------------------------------------------------------------
111 {
112 
113  // Try finding some tracks
115  = evt.getValidHandle<std::vector<recob::Track> >(fTrackProducerLabel);
116 
117  // Find the associations between tracks and T0
118  const art::FindManyP<anab::T0> findTrackT0(trackHandle,evt,fTrackProducerLabel);
119 
120  // Also look for cosmic tags so we can make a T0 plot for cosmic tagged events only
121  const art::FindManyP<anab::CosmicTag> findCosmicTag(trackHandle,evt,fTrackProducerLabel);
122 
123  for ( size_t track_index = 0; track_index != trackHandle->size(); ++track_index )
124  {
125  const auto thisTrack = (*trackHandle)[track_index];
126 
127  // Did this track have an associated T0?
128  auto const& t0s = findTrackT0.at(track_index);
129  if(t0s.size() != 0){
130  fT0Hist->Fill(t0s[0]->Time());
131  fT0HistHiRes->Fill(t0s[0]->Time());
132  // Did this track also have a cosmic tag?
133  auto const& tag = findCosmicTag.at(track_index);
134  if(tag.size() != 0){
135  fCosmicT0Hist->Fill(t0s[0]->Time());
136  fCosmicT0HistHiRes->Fill(t0s[0]->Time());
137  }
138  }
139  }
140 
141 } // analyze
142 
143 
PlotTrackT0(fhicl::ParameterSet const &p)
std::string string
Definition: nybbler.cc:12
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
void endJob() override
art framework interface to geometry description
void beginJob() override
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
PlotTrackT0 & operator=(PlotTrackT0 const &)=delete
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
std::string fTrackProducerLabel
void analyze(art::Event const &e) override
Definition of data types for geometry description.
void reconfigure(fhicl::ParameterSet const &p)
Declaration of signal hit object.
Provides recob::Track data product.
TCEvent evt
Definition: DataStructs.cxx:7