All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SBNDFlashAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: SBNDFlashAna
3 // Plugin Type: analyzer (art v3_04_00)
4 // File: SBNDFlashAna_module.cc
5 //
6 // Generated at Sun Mar 1 15:08:24 2020 by Marco Del Tutto using cetskelgen
7 // from cetlib version v3_09_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 "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
19 #include "art_root_io/TFileService.h"
20 #include "canvas/Persistency/Common/FindManyP.h"
21 
25 
26 #include <TTree.h>
27 
28 class SBNDFlashAna;
29 
30 
31 class SBNDFlashAna : public art::EDAnalyzer {
32 public:
33  explicit SBNDFlashAna(fhicl::ParameterSet const& p);
34  // The compiler-generated destructor is fine for non-base
35  // classes without bare pointers or other resource use.
36 
37  // Plugins should not be copied or assigned.
38  SBNDFlashAna(SBNDFlashAna const&) = delete;
39  SBNDFlashAna(SBNDFlashAna&&) = delete;
40  SBNDFlashAna& operator=(SBNDFlashAna const&) = delete;
41  SBNDFlashAna& operator=(SBNDFlashAna&&) = delete;
42 
43  // Required functions.
44  void analyze(art::Event const& e) override;
45 
46 private:
47 
48  std::vector<std::string> _flash_label_v;
49  std::vector<std::string> _ophit_label_v;
50  std::vector<std::string> _mcflash_label_v;
51  std::vector<int> _tpc_v;
52 
54 
55  TTree *_flash_tree;
57  int _tpc;
58  double _flash_time;
60  std::vector<double> _flash_pe_v;
61  double _flash_y;
62  double _flash_yerr ;
63  double _flash_z;
64  double _flash_zerr;
65  std::vector<double> _flash_ophit_time;
66  std::vector<double> _flash_ophit_amp;
67  std::vector<double> _flash_ophit_area;
68  std::vector<double> _flash_ophit_width;
69  std::vector<double> _flash_ophit_pe;
70  std::vector<int> _flash_ophit_ch;
71  std::vector<std::string> _flash_ophit_chname;
72 
73  TTree *_mcflash_tree;
74 };
75 
76 
77 SBNDFlashAna::SBNDFlashAna(fhicl::ParameterSet const& p)
78  : EDAnalyzer{p}
79 {
80  _flash_label_v = p.get<std::vector<std::string>>("FlashProducer", _flash_label_v);
81  _mcflash_label_v = p.get<std::vector<std::string>>("MCFlashProducer", _mcflash_label_v);
82  _ophit_label_v = p.get<std::vector<std::string>>("OpHitProducer", _ophit_label_v);
83  _tpc_v = p.get<std::vector<int>>("TPC", _tpc_v);
84 
85  art::ServiceHandle<art::TFileService> fs;
86  _flash_tree = fs->make<TTree>("FlashTree","");
87  _flash_tree->Branch("run", &_run, "run/I");
88  _flash_tree->Branch("subrun", &_subrun, "subrun/I");
89  _flash_tree->Branch("event", &_event, "event/I");
90  _flash_tree->Branch("tpc", &_tpc, "tpc/I");
91  _flash_tree->Branch("flash_time", &_flash_time, "flash_time/D");
92  _flash_tree->Branch("flash_total_pe", &_flash_total_pe, "flash_total_pe/D");
93  _flash_tree->Branch("flash_y", &_flash_y, "flash_y/D");
94  _flash_tree->Branch("flash_yerr", &_flash_yerr, "flash_yerr/D");
95  _flash_tree->Branch("flash_z", &_flash_z, "flash_z/D");
96  _flash_tree->Branch("flash_zerr", &_flash_zerr, "flash_zerr/D");
97  _flash_tree->Branch("flash_pe_v", "std::vector<double>", &_flash_pe_v);
98  _flash_tree->Branch("flash_ophit_time", "std::vector<double>", &_flash_ophit_time);
99  _flash_tree->Branch("flash_ophit_amp", "std::vector<double>", &_flash_ophit_amp);
100  _flash_tree->Branch("flash_ophit_area", "std::vector<double>", &_flash_ophit_area);
101  _flash_tree->Branch("flash_ophit_width", "std::vector<double>", &_flash_ophit_width);
102  _flash_tree->Branch("flash_ophit_pe", "std::vector<double>", &_flash_ophit_pe);
103  _flash_tree->Branch("flash_ophit_ch", "std::vector<int>", &_flash_ophit_ch);
104  _flash_tree->Branch("flash_ophit_chname", "std::vector<std::string>", &_flash_ophit_chname);
105 
106  _mcflash_tree = fs->make<TTree>("MCFlashTree","");
107  _mcflash_tree->Branch("run", &_run, "run/I");
108  _mcflash_tree->Branch("subrun", &_subrun, "subrun/I");
109  _mcflash_tree->Branch("event", &_event, "event/I");
110  _mcflash_tree->Branch("tpc", &_tpc, "tpc/I");
111  _mcflash_tree->Branch("flash_time", &_flash_time, "flash_time/D");
112  _mcflash_tree->Branch("flash_total_pe", &_flash_total_pe, "flash_total_pe/D");
113  _mcflash_tree->Branch("flash_y", &_flash_y, "flash_y/D");
114  _mcflash_tree->Branch("flash_yerr", &_flash_yerr, "flash_yerr/D");
115  _mcflash_tree->Branch("flash_z", &_flash_z, "flash_z/D");
116  _mcflash_tree->Branch("flash_zerr", &_flash_zerr, "flash_zerr/D");
117  _mcflash_tree->Branch("flash_pe_v", "std::vector<double>", &_flash_pe_v);
118 }
119 
120 void SBNDFlashAna::analyze(art::Event const& e)
121 {
122  // if (_flash_label_v.size() != 2) {
123  // std::cout << "FlashProducer size has to be 2!" << std::endl;
124  // throw std::exception();
125  // }
126  // if (_mcflash_label_v.size() != 2) {
127  // std::cout << "MCFlashProducer size has to be 2!" << std::endl;
128  // throw std::exception();
129  // }
130 
131 
132  art::Handle<std::vector<recob::OpHit>> ophit_h;
133  e.getByLabel("ophitpmt", ophit_h);
134  if(!ophit_h.isValid()){
135  std::cout << "Invalid producer for recob::OpHit: " << "ophitpmt" << ". Ignoring." << std::endl;
136  }
137  std::vector<art::Ptr<recob::OpHit>> ophit_v;
138  art::fill_ptr_vector(ophit_v, ophit_h);
139  // for (auto oh : ophit_v) {
140  // std::cout << "ophit time " << oh->PeakTime() << std::endl;
141  // }
142 
143 
144 
145  _run = e.id().run();
146  _subrun = e.id().subRun();
147  _event = e.id().event();
148 
149  for (size_t l = 0; l < _flash_label_v.size(); l++) {
150  art::Handle<std::vector<recob::OpFlash>> flash_h;
151  e.getByLabel(_flash_label_v[l], flash_h);
152  if(!flash_h.isValid()){
153  std::cout << "Invalid producer for recob::OpFlash: " << _flash_label_v[l] << ". Ignoring." << std::endl;
154  }
155 
156  art::FindManyP<recob::OpHit> flashToOpHitAssns(flash_h, e, _ophit_label_v[l]);
157 
158  for (size_t i = 0; i < flash_h->size(); i++) {
159  auto const& f = (*flash_h)[i];
160  std::cout << "Flash " << i << ", time " << f.AbsTime() << std::endl;
161  _tpc = _tpc_v[l];
162  _flash_time = f.AbsTime();
163  _flash_total_pe = f.TotalPE();
164  _flash_pe_v = f.PEs();
165  _flash_y = f.YCenter();
166  _flash_yerr = f.YWidth();
167  _flash_z = f.ZCenter();
168  _flash_zerr = f.ZWidth();
169 
170  _flash_ophit_time.clear();
171  _flash_ophit_amp.clear();
172  _flash_ophit_area.clear();
173  _flash_ophit_width.clear();
174  _flash_ophit_pe.clear();
175  _flash_ophit_ch.clear();
176 
177  std::vector<art::Ptr<recob::OpHit>> ophit_v = flashToOpHitAssns.at(i);
178  for (auto ophit : ophit_v) {
179  _flash_ophit_time.push_back(ophit->PeakTimeAbs());
180  _flash_ophit_amp.push_back(ophit->Amplitude());
181  _flash_ophit_area.push_back(ophit->Area());
182  _flash_ophit_width.push_back(ophit->Width());
183  _flash_ophit_pe.push_back(ophit->PE());
184  _flash_ophit_ch.push_back(ophit->OpChannel());
185  _flash_ophit_chname.push_back(_pds_map.pdType(ophit->OpChannel()));
186 
187  }
188 
189  _flash_tree->Fill();
190  }
191  }
192 
193  for (size_t l = 0; l < _mcflash_label_v.size(); l++) {
194  art::Handle<std::vector<recob::OpFlash>> flash_h;
195  e.getByLabel(_mcflash_label_v[l], flash_h);
196  if(!flash_h.isValid()){
197  std::cout << "Invalid producer for MC recob::OpFlash: " << _mcflash_label_v[l] << ". Ignoring." << std::endl;
198  }
199  for (size_t i = 0; i < flash_h->size(); i++) {
200  auto const& f = (*flash_h)[i];
201  _tpc = _tpc_v[l];
202  _flash_time = f.Time();
203  _flash_total_pe = f.TotalPE();
204  _flash_pe_v = f.PEs();
205  _flash_y = f.YCenter();
206  _flash_yerr = f.YWidth();
207  _flash_z = f.ZCenter();
208  _flash_zerr = f.ZWidth();
209  _mcflash_tree->Fill();
210  }
211  }
212 
213 }
214 
215 
216 
217 
218 DEFINE_ART_MODULE(SBNDFlashAna)
219 
220 
221 
222 
223 
std::vector< double > _flash_ophit_amp
std::vector< std::string > _ophit_label_v
std::vector< std::string > _mcflash_label_v
std::vector< double > _flash_ophit_pe
pdgs p
Definition: selectors.fcl:22
void analyze(art::Event const &e) override
opdet::sbndPDMapAlg _pds_map
std::vector< std::string > _flash_label_v
SBNDFlashAna(fhicl::ParameterSet const &p)
std::vector< int > _tpc_v
BEGIN_PROLOG opflashCryoW opflashCryoW triggerfilterBNB triggerfilterNuMI triggerfilterOffbeamBNB triggerfilterOffbeamNuMI triggerfilterUnknown roifinder roifinder2d gaushitTPCEE gaushitTPCWE purityana1 ophit
std::vector< double > _flash_pe_v
std::vector< double > _flash_ophit_width
do i e
std::vector< double > _flash_ophit_area
SBNDFlashAna & operator=(SBNDFlashAna const &)=delete
std::vector< double > _flash_ophit_time
std::string pdType(size_t ch) const override
std::vector< std::string > _flash_ophit_chname
BEGIN_PROLOG could also be cout
std::vector< int > _flash_ophit_ch