CheckCRT_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: CheckCRT
3 // Plugin Type: analyzer (art v3_00_00)
4 // File: CheckCRT_module.cc
5 //
6 // Generated at Mon Jan 7 12:31:13 2019 by Tingjun Yang using cetskelgen
7 // from cetlib version v3_04_00.
8 ////////////////////////////////////////////////////////////////////////
9 
16 #include "art_root_io/TFileService.h"
18 #include "canvas/Persistency/Common/FindManyP.h"
19 #include "fhiclcpp/ParameterSet.h"
24 #include "dune/Protodune/singlephase/CTB/data/pdspctb.h"
25 #include "dune/Protodune/singlephase/CRT/data/CRTTrigger.h"
27 #include "TTree.h"
28 
29 namespace pdsp {
30  class CheckCRT;
31 }
32 
33 
35 public:
36  explicit CheckCRT(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  CheckCRT(CheckCRT const&) = delete;
42  CheckCRT(CheckCRT&&) = delete;
43  CheckCRT& operator=(CheckCRT const&) = delete;
44  CheckCRT& operator=(CheckCRT&&) = delete;
45 
46  // Required functions.
47  void analyze(art::Event const& e) override;
48 
49  // Selected optional functions.
50  void beginJob() override;
51 
52 private:
53 
54  std::vector<unsigned short> GetModules(int pixel);
55 
56  TTree *fTree;
57  // Run information
58  int run;
59  int subrun;
60  int event;
61  std::vector<uint32_t> crtmask;
62  std::vector<ULong64_t> rdtime;
63  std::vector<unsigned int> crtmodule;
64  std::vector<unsigned long long> crttime;
65  std::vector<double> trkstartx_pandora;
66  std::vector<double> trkstarty_pandora;
67  std::vector<double> trkstartz_pandora;
68  std::vector<double> trkendx_pandora;
69  std::vector<double> trkendy_pandora;
70  std::vector<double> trkendz_pandora;
71  std::vector<double> t0_pandora;
72 
73  std::vector<double> trkstartx_pmtrack;
74  std::vector<double> trkstarty_pmtrack;
75  std::vector<double> trkstartz_pmtrack;
76  std::vector<double> trkendx_pmtrack;
77  std::vector<double> trkendy_pmtrack;
78  std::vector<double> trkendz_pmtrack;
79  std::vector<double> t0_pmtrack;
80 
81 };
82 
83 
85  : EDAnalyzer{p} // ,
86  // More initializers here.
87 {
88 }
89 std::vector<unsigned short> pdsp::CheckCRT::GetModules(int pixel){
90  std::vector<unsigned short> modules(2,-1);
91  if (pixel == 0){
92  modules[0] = 1;
93  modules[1] = 2;
94  }
95  else if (pixel == 1){
96  modules[0] = 0;
97  modules[1] = 2;
98  }
99  else if (pixel == 2){
100  modules[0] = 15;
101  modules[1] = 13;
102  }
103  else if (pixel == 3){
104  modules[0] = 14;
105  modules[1] = 13;
106  }
107  else if (pixel == 4){
108  modules[0] = 14;
109  modules[1] = 12;
110  }
111  else if (pixel == 5){
112  modules[0] = 9;
113  modules[1] = 11;
114  }
115  else if (pixel == 6){
116  modules[0] = 9;
117  modules[1] = 10;
118  }
119  else if (pixel == 7){
120  modules[0] = 8;
121  modules[1] = 10;
122  }
123  else if (pixel == 8){
124  modules[0] = 7;
125  modules[1] = 5;
126  }
127  else if (pixel == 9){
128  modules[0] = 6;
129  modules[1] = 5;
130  }
131  else if (pixel == 10){
132  modules[0] = 6;
133  modules[1] = 4;
134  }
135  else if (pixel == 11){
136  modules[0] = 1;
137  modules[1] = 3;
138  }
139  else if (pixel == 12){
140  modules[0] = 0;
141  modules[1] = 3;
142  }
143  else if (pixel == 13){
144  modules[0] = 15;
145  modules[1] = 12;
146  }
147  else if (pixel == 14){
148  modules[0] = 8;
149  modules[1] = 11;
150  }
151  else if (pixel == 15){
152  modules[0] = 7;
153  modules[1] = 4;
154  }
155  else if (pixel == 16){
156  modules[0] = 17;
157  modules[1] = 18;
158  }
159  else if (pixel == 17){
160  modules[0] = 16;
161  modules[1] = 18;
162  }
163  else if (pixel == 18){
164  modules[0] = 31;
165  modules[1] = 29;
166  }
167  else if (pixel == 19){
168  modules[0] = 30;
169  modules[1] = 29;
170  }
171  else if (pixel == 20){
172  modules[0] = 30;
173  modules[1] = 28;
174  }
175  else if (pixel == 21){
176  modules[0] = 25;
177  modules[1] = 27;
178  }
179  else if (pixel == 22){
180  modules[0] = 25;
181  modules[1] = 26;
182  }
183  else if (pixel == 23){
184  modules[0] = 24;
185  modules[1] = 26;
186  }
187  else if (pixel == 24){
188  modules[0] = 23;
189  modules[1] = 21;
190  }
191  else if (pixel == 25){
192  modules[0] = 22;
193  modules[1] = 21;
194  }
195  else if (pixel == 26){
196  modules[0] = 22;
197  modules[1] = 20;
198  }
199  else if (pixel == 27){
200  modules[0] = 17;
201  modules[1] = 19;
202  }
203  else if (pixel == 28){
204  modules[0] = 16;
205  modules[1] = 19;
206  }
207  else if (pixel == 29){
208  modules[0] = 31;
209  modules[1] = 28;
210  }
211  else if (pixel == 30){
212  modules[0] = 24;
213  modules[1] = 27;
214  }
215  else if (pixel == 31){
216  modules[0] = 23;
217  modules[1] = 20;
218  }
219  return modules;
220 }
221 
223 {
225  fTree = tfs->make<TTree>("crt","crt tree");
226  fTree->Branch("run",&run,"run/I");
227  fTree->Branch("subrun",&subrun,"subrun/I");
228  fTree->Branch("event",&event,"event/I");
229  fTree->Branch("crtmask", &crtmask);
230  fTree->Branch("rdtime", &rdtime);
231  fTree->Branch("crtmodule", &crtmodule);
232  fTree->Branch("crttime", &crttime);
233  fTree->Branch("trkstartx_pandora",&trkstartx_pandora);
234  fTree->Branch("trkstarty_pandora",&trkstarty_pandora);
235  fTree->Branch("trkstartz_pandora",&trkstartz_pandora);
236  fTree->Branch("trkendx_pandora",&trkendx_pandora);
237  fTree->Branch("trkendy_pandora",&trkendy_pandora);
238  fTree->Branch("trkendz_pandora",&trkendz_pandora);
239  fTree->Branch("t0_pandora",&t0_pandora);
240 
241  fTree->Branch("trkstartx_pmtrack",&trkstartx_pmtrack);
242  fTree->Branch("trkstarty_pmtrack",&trkstarty_pmtrack);
243  fTree->Branch("trkstartz_pmtrack",&trkstartz_pmtrack);
244  fTree->Branch("trkendx_pmtrack",&trkendx_pmtrack);
245  fTree->Branch("trkendy_pmtrack",&trkendy_pmtrack);
246  fTree->Branch("trkendz_pmtrack",&trkendz_pmtrack);
247  fTree->Branch("t0_pmtrack",&t0_pmtrack);
248 
249 }
250 
252 {
253 
254  run = e.run();
255  subrun = e.subRun();
256  event = e.id().event();
257 
258  crtmask.clear();
259  rdtime.clear();
260  crtmodule.clear();
261  crttime.clear();
262 
263  trkstartx_pandora.clear();
264  trkstarty_pandora.clear();
265  trkstartz_pandora.clear();
266  trkendx_pandora.clear();
267  trkendy_pandora.clear();
268  trkendz_pandora.clear();
269  t0_pandora.clear();
270 
271  trkstartx_pmtrack.clear();
272  trkstarty_pmtrack.clear();
273  trkstartz_pmtrack.clear();
274  trkendx_pmtrack.clear();
275  trkendy_pmtrack.clear();
276  trkendz_pmtrack.clear();
277  t0_pmtrack.clear();
278 
279  art::ValidHandle<std::vector<raw::RDTimeStamp>> timeStamps = e.getValidHandle<std::vector<raw::RDTimeStamp>>("timingrawdecoder:daq");
280 
281  int trigger = -1;
282  // Check that we have good information
283  if(timeStamps.isValid() && timeStamps->size() == 1){
284  // Access the trigger information. Beam trigger flag = 0xc
285  const raw::RDTimeStamp& timeStamp = timeStamps->at(0);
286  trigger = timeStamp.GetFlags();
287  }
288 
289  if (trigger!=13) return;
290 
291  auto const& pdspctbs = *e.getValidHandle<std::vector<raw::ctb::pdspctb>>("ctbrawdecoder:daq");
292  if (!pdspctbs.empty()){
293  const size_t npdspctbs = pdspctbs.size();
294  for (size_t i=0; i<npdspctbs; ++i){
295 // std::cout << "Number of triggers: " << pdspctbs[i].GetNTriggers() << std::endl;
296 // std::cout << "Number of chstatuses: " << pdspctbs[i].GetNChStatuses() << std::endl;
297 // std::cout << "Number of feedbacks: " << pdspctbs[i].GetNFeedbacks() << std::endl;
298 // std::cout << "Number of miscs: " << pdspctbs[i].GetNMiscs() << std::endl;
299 //
300 // const std::vector<raw::ctb::Trigger> HLTriggers = pdspctbs[i].GetHLTriggers();
301 // std::cout << "Number of HL Triggers: " << HLTriggers.size() << std::endl;
302 // for (size_t j=0; j<HLTriggers.size(); ++j){
303 // std::cout << "HL Trigger: " << j << " " << HLTriggers[j].word_type << " " << HLTriggers[j].trigger_word << " " << HLTriggers[j].timestamp << std::endl;
304 // }
305 
306  const std::vector<raw::ctb::ChStatus> chs = pdspctbs[i].GetChStatusAfterHLTs();
307  std::cout << "Number of CH Status after HLTs: " << chs.size() << std::endl;
308  for (size_t j=0; j<chs.size(); ++j){
309  //std::cout << " chs after HLT: " << j << " " << chs[j].word_type << " " << chs[j].pds << " " << chs[j].crt << " " << chs[j].beam_hi << " " << chs[j].beam_lo << std::endl;
310  crtmask.push_back(chs[j].crt);
311  }
312 //
313 //
314 // const std::vector<raw::ctb::Trigger> LLTriggers = pdspctbs[i].GetLLTriggers();
315 // std::cout << "Number of LL Triggers: " << LLTriggers.size() << std::endl;
316 // for (size_t j=0; j<LLTriggers.size(); ++j){
317 // std::cout << "LL Trigger: " << j << " " << LLTriggers[j].word_type << " " << LLTriggers[j].trigger_word << " " << LLTriggers[j].timestamp << std::endl;
318 // }
319 //
320 // const std::vector<raw::ctb::WordIndex> indexes = pdspctbs[i].GetIndexes();
321 // std::cout << "Number of Indexes: " << indexes.size() << std::endl;
322 // for (size_t j=0; j<indexes.size(); ++j){
323 // std::cout << "Index: " << j << " " << indexes[j].word_type << " " << indexes[j].index << std::endl;
324 // }
325 
326  }
327  }
328  //Save CRT trigger information
329  const auto & triggers = *e.getValidHandle < std::vector < CRT::Trigger >> ("crtrawdecoder");
330  for (const auto& trigger: triggers){
331  //std::cout<<"module: "<<trigger.Channel()<<" time: "<<trigger.Timestamp()<<std::endl;
332  crtmodule.push_back(trigger.Channel());
333  crttime.push_back(trigger.Timestamp());
334  }
335  for (const auto& time : *timeStamps){
336  rdtime.push_back(time.GetTimeStamp());
337  }
338  /*
339  for (auto const& crt_mask : crtmask){
340  int pixel[2] = {-1, -1};
341  for (size_t i = 0; i<32; ++i){
342  if (crt_mask & (1<<i)){
343  if (i<16){
344  pixel[0] = i;
345  }
346  else {
347  pixel[1] = i;
348  }
349  }
350  }
351  std::cout<<"Pixels "<<pixel[0]<<" "<<pixel[1]<<std::endl;
352  for (size_t i = 0; i<2; ++i){
353  if (pixel[i]!=-1){
354  std::vector<unsigned short> modules = GetModules(pixel[i]);
355  for (size_t j = 0; j<2; ++j){
356  for (const auto& trigger: triggers){
357  if (trigger.Channel() == modules[j]){
358  std::cout<<"Pixel: "<<pixel[i]<<" module: "<<trigger.Channel()<<" time: "<<trigger.Timestamp()<<" "<<timeStamps->at(0).GetTimeStamp()<<std::endl;
359  }
360  }
361  }
362  }
363  }
364  }
365  */
366 
367  std::vector< art::Ptr<recob::Track> > pandoratrks;
368  auto pandoratrkHandle = e.getHandle< std::vector<recob::Track> >("pandoraTrack");
369  if (pandoratrkHandle) art::fill_ptr_vector(pandoratrks, pandoratrkHandle);
370  else return;
371 
372  auto pfpListHandle = e.getHandle< std::vector<recob::PFParticle> >("pandora");
373  art::FindManyP<recob::PFParticle> fmpfp(pandoratrkHandle, e, "pandoraTrack");
374  art::FindManyP<anab::T0> fmt0pandora(pfpListHandle, e, "pandora");
375 
376  for (size_t i = 0; i<pandoratrks.size(); ++i){
377  auto & trk = pandoratrks[i];
378  trkstartx_pandora.push_back(trk->Vertex().X());
379  trkstarty_pandora.push_back(trk->Vertex().Y());
380  trkstartz_pandora.push_back(trk->Vertex().Z());
381  trkendx_pandora.push_back(trk->End().X());
382  trkendy_pandora.push_back(trk->End().Y());
383  trkendz_pandora.push_back(trk->End().Z());
384  double t0 = 0;
385  auto &pfps = fmpfp.at(trk.key());
386  if (!pfps.empty()){
387  auto &t0s = fmt0pandora.at(pfps[0].key());
388  if (!t0s.empty()){
389  t0 = t0s[0]->Time();
390  }
391  }
392  t0_pandora.push_back(t0);
393  }
394 
395  /*
396  std::vector< art::Ptr<recob::Track> > pmtracktrks;
397  auto pmtracktrkHandle = e.getHandle< std::vector<recob::Track> >("pmtrack");
398  if (pmtracktrkHandle) art::fill_ptr_vector(pmtracktrks, pmtracktrkHandle);
399 
400  art::FindManyP<anab::T0> fmt0pmtrack(pmtracktrkHandle, e, "pmtrack");
401 
402  for (size_t i = 0; i<pmtracktrks.size(); ++i){
403  auto & trk = pmtracktrks[i];
404  trkstartx_pmtrack.push_back(trk->Vertex().X());
405  trkstarty_pmtrack.push_back(trk->Vertex().Y());
406  trkstartz_pmtrack.push_back(trk->Vertex().Z());
407  trkendx_pmtrack.push_back(trk->End().X());
408  trkendy_pmtrack.push_back(trk->End().Y());
409  trkendz_pmtrack.push_back(trk->End().Z());
410  double t0 = 0;
411  auto &t0s = fmt0pmtrack.at(trk.key());
412  if (!t0s.empty()){
413  t0 = t0s[0]->Time();
414  }
415  t0_pmtrack.push_back(t0);
416  }
417  */
418  fTree->Fill();
419 }
420 
code to link reconstructed objects back to the MC truth information
std::vector< double > trkstartx_pandora
std::vector< double > trkendy_pandora
std::vector< unsigned short > GetModules(int pixel)
std::vector< unsigned int > crtmodule
uint16_t GetFlags() const
Definition: RDTimeStamp.h:46
void beginJob() override
CheckCRT(fhicl::ParameterSet const &p)
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
void analyze(art::Event const &e) override
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::vector< double > trkendy_pmtrack
std::vector< double > trkendz_pandora
std::vector< double > trkendx_pandora
const double e
std::vector< double > trkendx_pmtrack
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
def key(type, name=None)
Definition: graph.py:13
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
std::vector< double > trkstartz_pmtrack
p
Definition: test.py:223
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
std::vector< double > t0_pmtrack
RunNumber_t run() const
Definition: DataViewImpl.cc:71
std::vector< double > trkstarty_pmtrack
std::vector< double > trkstartx_pmtrack
std::vector< double > t0_pandora
std::vector< uint32_t > crtmask
std::vector< ULong64_t > rdtime
std::vector< double > trkstarty_pandora
std::vector< double > trkstartz_pandora
std::vector< unsigned long long > crttime
Provides recob::Track data product.
EventNumber_t event() const
Definition: EventID.h:116
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
std::vector< double > trkendz_pmtrack
EventID id() const
Definition: Event.cc:34
CheckCRT & operator=(CheckCRT const &)=delete
QTextStream & endl(QTextStream &s)
Event finding and building.
bool isValid() const
Definition: Handle.h:330