1+ // //////////////////////////////////////////////////////////////////////
2+ // Class: SBNDOpT0FinderAna
3+ // Plugin Type: analyzer (art v3_05_01)
4+ // File: SBNDOpT0FinderAna_module.cc
5+ //
6+ // Generated at Mon Oct 12 13:52:37 2020 by Marco Del Tutto using cetskelgen
7+ // from cetlib version v3_10_00.
8+ // //////////////////////////////////////////////////////////////////////
9+
10+ #include " art/Framework/Core/EDAnalyzer.h"
11+ #include " art/Framework/Core/ModuleMacros.h"
12+ #include " art/Framework/Principal/Event.h"
13+ #include " art/Framework/Principal/Handle.h"
14+ #include " art/Framework/Principal/Run.h"
15+ #include " art/Framework/Principal/SubRun.h"
16+ #include " canvas/Utilities/InputTag.h"
17+ #include " canvas/Persistency/Common/FindManyP.h"
18+ #include " fhiclcpp/ParameterSet.h"
19+ #include " messagefacility/MessageLogger/MessageLogger.h"
20+
21+ #include " lardataobj/RecoBase/Slice.h"
22+ #include " lardataobj/RecoBase/OpFlash.h"
23+ #include " sbnobj/Common/Reco/CorrectedOpFlashTiming.h"
24+
25+ #include " art_root_io/TFileService.h"
26+
27+ #include " TTree.h"
28+
29+ #include < numeric>
30+
31+ class LightPropagationCorrectionAna ;
32+
33+
34+ class LightPropagationCorrectionAna : public art ::EDAnalyzer {
35+ public:
36+ explicit LightPropagationCorrectionAna (fhicl::ParameterSet const & p);
37+ // The compiler-generated destructor is fine for non-base
38+ // classes without bare pointers or other resource use.
39+
40+ // Plugins should not be copied or assigned.
41+ LightPropagationCorrectionAna (LightPropagationCorrectionAna const &) = delete ;
42+ LightPropagationCorrectionAna (LightPropagationCorrectionAna&&) = delete ;
43+ LightPropagationCorrectionAna& operator =(LightPropagationCorrectionAna const &) = delete ;
44+ LightPropagationCorrectionAna& operator =(LightPropagationCorrectionAna&&) = delete ;
45+
46+ // Required functions.
47+ void analyze (art::Event const & e) override ;
48+ void beginJob () override ;
49+ private:
50+
51+ std::string fLightPropCorrectionLabel ; // /< The light propagation correction label producer
52+
53+ TTree* fTree ; // /< The TTree for storing event information
54+
55+ double fOpFlashT0 ;
56+ double fUpstreamTime_lightonly ;
57+ double fUpstreamTime_tpczcorr ;
58+ double fUpstreamTime_propcorr_tpczcorr ;
59+
60+ unsigned int _eventID;
61+ unsigned int _runID;
62+ unsigned int _subrunID;
63+
64+ };
65+
66+
67+ LightPropagationCorrectionAna::LightPropagationCorrectionAna (fhicl::ParameterSet const & p)
68+ : EDAnalyzer{p}
69+ {
70+ fLightPropCorrectionLabel = p.get <std::string>(" LightPropCorrectionLabel" );
71+ }
72+
73+ void LightPropagationCorrectionAna::analyze (art::Event const & e)
74+ {
75+ fOpFlashT0 =-99999 .;
76+ fUpstreamTime_lightonly =-99999 .;
77+ fUpstreamTime_tpczcorr =-99999 .;
78+ fUpstreamTime_propcorr_tpczcorr =-99999 .;
79+
80+ _eventID = -1 ;
81+ _runID = -1 ;
82+ _subrunID = -1 ;
83+
84+ std::cout << " Run: " << e.id ().run () << " Sub: " << e.id ().subRun () << " Evt: " << e.id ().event () << std::endl;
85+
86+ _eventID = e.id ().event ();
87+ _runID = e.id ().run ();
88+ _subrunID = e.id ().subRun ();
89+
90+ // Get all the T0 objects
91+ ::art::Handle<std::vector<sbn::CorrectedOpFlashTiming>> correctedopflash_h;
92+ e.getByLabel (fLightPropCorrectionLabel , correctedopflash_h);
93+ if (!correctedopflash_h.isValid () || correctedopflash_h->empty ()) {
94+ mf::LogWarning (" fLightPropCorrectionLabel" ) << " No LightPropCorrectionLabel objects with label " << fLightPropCorrectionLabel << std::endl;
95+ return ;
96+ }
97+
98+
99+ std::vector<art::Ptr<sbn::CorrectedOpFlashTiming>> correctedopflash_v;
100+ art::fill_ptr_vector (correctedopflash_v, correctedopflash_h);
101+
102+ // Get the T0->Slice association
103+ art::FindManyP<recob::Slice> correctedflash_to_slices (correctedopflash_h, e, fLightPropCorrectionLabel );
104+ art::FindManyP<recob::OpFlash> correctedflash_to_flashes (correctedopflash_h, e, fLightPropCorrectionLabel );
105+
106+ for (size_t i = 0 ; i < correctedopflash_v.size (); i++) {
107+
108+ // The T0 object
109+ auto const correctedopflash = correctedopflash_v[i];
110+
111+ // The associations from T0 to both slices and flashes
112+ std::vector<art::Ptr<recob::Slice>> slice_v = correctedflash_to_slices.at (correctedopflash.key ());
113+ std::vector<art::Ptr<recob::OpFlash>> flash_v = correctedflash_to_flashes.at (correctedopflash.key ());
114+
115+ // One T0 object is always associated to one and only one Slice and Flash
116+ assert (slice_v.size () == 1 );
117+ assert (flash_v.size () == 1 );
118+
119+ std::cout << " Corrected flash time is " << correctedopflash->OpFlashT0 << std::endl;
120+ std::cout << " Associated with slice id " << slice_v[0 ]->ID () << std::endl;
121+ std::cout << " Corrected flash time light only " << correctedopflash->UpstreamTime_lightonly << std::endl;
122+ std::cout << " Corrected flash time tpc z corr " << correctedopflash->UpstreamTime_tpczcorr << std::endl;
123+ std::cout << " Corrected flash time prop corr tpc z corr " << correctedopflash->UpstreamTime_propcorr_tpczcorr << std::endl;
124+
125+ fOpFlashT0 = correctedopflash->OpFlashT0 ;
126+ fUpstreamTime_lightonly = correctedopflash->UpstreamTime_lightonly ;
127+ fUpstreamTime_tpczcorr = correctedopflash->UpstreamTime_tpczcorr ;
128+ fUpstreamTime_propcorr_tpczcorr = correctedopflash->UpstreamTime_propcorr_tpczcorr ;
129+ fTree ->Fill ();
130+ }
131+ }
132+
133+ void LightPropagationCorrectionAna::beginJob ()
134+ {
135+ // Implementation of optional member function here.
136+ art::ServiceHandle<art::TFileService> tfs;
137+ fTree = tfs->make <TTree>(" LightPropagationCorrection" , " Light Propagation Correction Tree" );
138+
139+ fTree ->Branch (" eventID" , &_eventID, " eventID/i" );
140+ fTree ->Branch (" runID" , &_runID, " runID/i" );
141+ fTree ->Branch (" subrunID" , &_subrunID, " subrunID/i" );
142+
143+ fTree ->Branch (" fOpFlashT0" , &fOpFlashT0 , " OpFlashT0/d" );
144+ fTree ->Branch (" fUpstreamTime_lightonly" , &fUpstreamTime_lightonly , " UpstreamTime_lightonly/d" );
145+ fTree ->Branch (" fUpstreamTime_tpczcorr" , &fUpstreamTime_tpczcorr , " UpstreamTime_tpczcorr/d" );
146+ fTree ->Branch (" fUpstreamTime_propcorr_tpczcorr" , &fUpstreamTime_propcorr_tpczcorr , " UpstreamTime_propcorr_tpczcorr/d" );
147+
148+ }
149+
150+ DEFINE_ART_MODULE (LightPropagationCorrectionAna)
0 commit comments