CTree35t_module.cc
Go to the documentation of this file.
1 // Read data from MC raw files and convert it into ROOT tree
2 // Chao Zhang (chao@bnl.gov) 2/24/2014
3 
4 #ifndef CTree35t_Module
5 #define CTree35t_Module
6 // test
7 
8 // LArSoft includes
9 //#include "lardata/Utilities/DetectorProperties.h"
11 // #include "Utilities/LArProperties.h"
28 #include "lardataobj/RawData/raw.h"
35 // Framework includes
42 #include "art_root_io/TFileService.h"
45 #include "canvas/Persistency/Common/FindManyP.h"
48 #include "fhiclcpp/ParameterSet.h"
49 // lbne-artdaq includes
50 #include "lbne-raw-data/Overlays/TpcMilliSliceFragment.hh"
51 #include "lbne-raw-data/Overlays/SSPFragment.hh"
52 #include "lbne-raw-data/Overlays/anlTypes.hh"
53 #include "artdaq-core/Data/Fragment.hh"
54 #include "../daqinput35t/tpcFragmentToRawDigits.h"
55 #include "../daqinput35t/PennToOffline.h"
56 #include "../daqinput35t/SSPReformatterAlgs.h"
57 #include "../daqinput35t/utilities/UnpackFragment.h"
58 // ROOT includes.
59 #include "TFile.h"
60 #include "TTree.h"
61 #include "TDirectory.h"
62 #include "TObjArray.h"
63 #include "TList.h"
64 #include "TClonesArray.h"
65 #include "TLorentzVector.h"
66 #include "TGeoTube.h"
67 #include "TGeoNode.h"
68 #include "TH1D.h"
69 // C++ Includes
70 #include <map>
71 #include <vector>
72 // #include <algorithm>
73 #include <fstream>
74 #include <iostream>
75 #include <iomanip>
76 // #include <string>
77 // #include <sstream>
78 // #include <cmath>
79 
80 // #ifdef __MAKECINT__
81 // #pragma link C++ class vector<vector<int> >+;
82 // #pragma link C++ class vector<vector<float> >+;
83 // #endif
84 
85 #define MAX_TPC 8
86 #define MAX_PLANE 3
87 // #define MAX_CHANNEL 1992
88 #define MAX_CHANNEL 2048
89 #define MAX_TRACKS 2000
90 #define MAX_HITS 20000
91 #define MAX_OPDET 8
92 #define MAX_CLUSTER 10
93 #define MAX_OPWAVEFORMS 1000
94 
95 using namespace std;
96 
97 namespace DUNE{
98 
99 class CTree35t : public art::EDAnalyzer {
100 public:
101 
102  explicit CTree35t(fhicl::ParameterSet const& pset);
103  virtual ~CTree35t();
104 
105  void beginJob();
106  void endJob();
107  void beginRun(const art::Run& run);
108  void analyze(const art::Event& evt);
109 
110  void reconfigure(fhicl::ParameterSet const& pset);
111  void initOutput();
112  void saveChannelWireMap();
113  void saveWireGeometry(int plane, int tpc);
114  void printGeometry();
115  void processRaw(const art::Event& evt);
116  void processCalib(const art::Event& evt);
117  void processMC(const art::Event& evt);
118  void processHits(const art::Event& evt);
119  void processRecoTracks(const art::Event& event);
120  void processOpDet(const art::Event& event);
121  void processTiming(const art::Event& event);
122  void printEvent();
123  void reset();
124 
125 private:
126 
127  // the parameters we'll read from the .fcl
139 
141  // art::ServiceHandle<util::LArProperties> larp;
142 
143  // art::ServiceHandle<art::TFileService> fTfs;
144  TFile *fOutFile;
145  TTree *fGeoTree;
146  TTree *fEventTree;
147 
148  // Geometry Tree Leafs
150  int fNTPC;
151  float fTPC_x[MAX_TPC]; // TPC length in x
152  float fTPC_y[MAX_TPC]; // TPC length in y
153  float fTPC_z[MAX_TPC]; // TPC length in z
154  int fNplanes;
155  int fPlane_type[MAX_PLANE]; // plane type: 0 == induction, 1 == collection
156  int fPlane_view[MAX_PLANE]; // wire orientation: 0 == U, 1 == V, 2 == X
157  double fPlane_wirepitch[MAX_PLANE]; // wire pitch of each plane
158  double fPlane_wireangle[MAX_PLANE]; // wire angle (to vertical) of each plane
159  int fPlane_wires[MAX_PLANE]; // number of wires in each plane
161  int fNOpDets;
162  float fOpDetPositions_Y[MAX_OPDET];
163  float fOpDetPositions_Z[MAX_OPDET];
164  float fOpDetHalfWidths[MAX_OPDET];
165  float fOpDetHalfHeights[MAX_OPDET];
166 
167  // Event Tree Leafs
168  int fEvent;
169  int fRun;
170  int fSubRun;
171 
173  int fRaw_channelId[MAX_CHANNEL]; // hit channel id; size == raw_Nhit
174  int fRaw_charge[MAX_CHANNEL]; // hit channel charge (simple alg); size == raw_Nhit
175  int fRaw_time[MAX_CHANNEL]; // hit channel time (simple alg); size == raw_Nhit
176  std::vector<std::vector<int> > fRaw_wfADC;
177  std::vector<std::vector<int> > fRaw_wfTDC;
178 
180  int fCalib_channelId[MAX_CHANNEL]; // hit channel id; size == fCalib_Nhit
181  // FIXEME:: cannot save e.g std::vector<std::vector<float> > in ttree
182  std::vector<std::vector<int> > fCalib_wfADC;
183  std::vector<std::vector<int> > fCalib_wfTDC;
184 
185  int fMC_Ntrack; // number of tracks in MC
186  int fMC_id[MAX_TRACKS]; // track id; size == mc_Ntrack
187  int fMC_pdg[MAX_TRACKS]; // track particle pdg; size == mc_Ntrack
188  int fMC_mother[MAX_TRACKS]; // mother id of this track; size == mc_Ntrack
189  float fMC_startXYZT[MAX_TRACKS][4]; // start position of this track; size == mc_Ntrack
190  float fMC_endXYZT[MAX_TRACKS][4]; // end position of this track; size == mc_Ntrack
191  float fMC_startMomentum[MAX_TRACKS][4]; // start momentum of this track; size == mc_Ntrack
192  float fMC_endMomentum[MAX_TRACKS][4]; // end momentum of this track; size == mc_Ntrack
193  std::vector<std::vector<int> > fMC_daughters; // daughters id of this track; vector
194  TObjArray *fMC_trackMomentum;
195  TObjArray *fMC_trackPosition;
196 
197  int no_hits; //number of hits
198  int hit_channel[MAX_HITS]; //channel ID
199  float hit_peakT[MAX_HITS]; //peak time
200  float hit_charge[MAX_HITS]; //charge (area)
201  float hit_wireID[MAX_HITS];
202  float hit_plane[MAX_HITS];
203  float hit_tpc[MAX_HITS];
204 
205  int nthits;
206  int thit_channel[MAX_HITS];
207  float thit_peakT[MAX_HITS];
208  float thit_charge[MAX_HITS];
209  int thit_wireID[MAX_HITS];
210  int thit_plane[MAX_HITS];
211  int thit_tpc[MAX_HITS];
212 
213  int nclhits;
214  int chit_cryostat[MAX_HITS];
215  int chit_tpc[MAX_HITS];
216  int chit_plane[MAX_HITS];
217  int chit_charge[MAX_HITS];
218  float chit_peakT[MAX_HITS];
219  int chit_wire[MAX_HITS];
220  int chit_channel[MAX_HITS];
221  int chit_cluster[MAX_HITS];
222 
223  int reco_nTrack; // number of reco tracks
225 
226  // unsigned int UVPlane[4]={3,2,1,0};
227  // unsigned int ZPlane[8]={7,6,5,4,3,2,1,0};
228 
229  //Photon detector related
232  TTree * fTheOpDetTree;
233  TTree * fTheEventTree;
245  //float fQE; // unused
246  //float fWavelengthCutLow; // unused
247  //float fWavelengthCutHigh; // unused
248  Float_t fWavelength;
249  Float_t fTime;
250  Int_t fCount;
251  Int_t fCountOpDetAll[MAX_OPDET];
252  Int_t fCountOpDetDetected[MAX_OPDET];
255  Int_t fOpChannel;
256  // new photon detector display
257  TObjArray *averageWaveforms;
258  std::map<int, int> waveformCount;
259  std::vector<std::vector<int> > OpChannelToOpDet;
260  std::vector<std::vector<int> > timestamp;
261  //std::map< int, int > OpHitCount;
262  //std::map< int, double > FirstHitTimePerChannel;
263  /*
264  TH1D* fPedestalMeanPerChannel;
265  TH1D* fPedestalSigmaPerChannel;
266  TH1D* fIntegratedSignalMeanPerChannel;
267  TH1D* fFractionSamplesNearMaximumPerChannel;
268  TH1D* fNumberOfWaveformsProcessedPerChannel;
269  TH1D* fFirstOpHitTimeMean;
270  //TH1D* fFirstOpHitTimeSigma;
271  TH1D* fSecondOpHitTimeMean;
272  //TH1D* fSecondOpHitTimeSigma;
273  TH1D* fFirstSecondDiffOpHitTimeMean;
274  //TH1D* fFirstSecondDiffOpHitTimeSigma;
275  TH1D* fNumberOfOpHitsPerChannelPerEvent;
276  */
277 
278  // timing
281  double fSampleFreq;
282  double RCETimeBegin;
283  double RCETimeEnd;
284  double SSPTimeBegin;
285  double SSPTimeEnd;
286 
287  }; // class CTree35t
288 
289 
290 //-----------------------------------------------------------------------
291 CTree35t::CTree35t(fhicl::ParameterSet const& parameterSet)
292  : EDAnalyzer(parameterSet)
293 {
294  reconfigure(parameterSet);
295  initOutput();
296 }
297 
298 
299 //-----------------------------------------------------------------------
301 {
302 }
303 
304 
305 //-----------------------------------------------------------------------
307  fRawDigitLabel = p.get< std::string >("RawDigitLabel");
308  fCalibLabel = p.get< std::string >("CalibLabel");
309  fHitsModuleLabel = p.get< std::string >("HitsModuleLabel");
310  fClusterModuleLabel = p.get< std::string >("ClusterModuleLabel");
311  fTrackModuleLabel = p.get< std::string >("TrackModuleLabel");
312  fOutFileName = p.get< std::string >("outFile");
313  fSaveChannelWireMap = p.get< bool >("saveChannelWireMap");
314  fSaveChannelWireGeo = p.get< bool >("saveChannelWireGeo");
315  fInputModule = p.get<std::string>("InputModule");
316  fMakeAllPhotonsTree = p.get<bool>("MakeAllPhotonsTree");
317  fMakeDetectedPhotonsTree = p.get<bool>("MakeDetectedPhotonsTree");
318  fMakeOpDetsTree = p.get<bool>("MakeOpDetsTree");
319  fMakeOpDetEventsTree = p.get<bool>("MakeOpDetEventsTree");
320  fUncompressWithPed = p.get< bool >("UncompressWithPed", true);
321  fProcessMCtruth = p.get< bool >("ProcessMCtruth", true);
322  fProcessCalib = p.get< bool >("ProcessCalib", true);
323  fProcessHits = p.get< bool >("ProcessHits", true);
324  fProcessReco = p.get< bool >("ProcessReco", true);
325  fProcessOpDet = p.get< bool >("ProcessOpDet", true);
326  fOpDetInputModule = p.get<std::string >("OpDetInputModule");
327  fInstanceName = p.get<std::string >("InstanceName");
328  fOpHitModule = p.get<std::string >("OpHitModule");
329  fRCEFragType = p.get<std::string >("RCEFragType");
330  fRCERawDataLabel = p.get<std::string >("RCERawDataLabel");
331  fSSPFragType = p.get<std::string >("SSPFragType");
332  fSSPRawDataLabel = p.get<std::string >("SSPRawDataLabel");
333 }
334 
335 
336 //-----------------------------------------------------------------------
338 {
339  TDirectory* tmpDir = gDirectory;
340 
341  fOutFile = new TFile(fOutFileName.c_str(), "recreate");
342 
343  // init Detector Geometry TTree
344  TDirectory* subDir = fOutFile->mkdir("Detector");
345  subDir->cd();
346  fGeoTree = new TTree("Geometry", "Detector Geometry");
347  fGeoTree->Branch("Ncryostats", &fNcryostats, "Ncryostats/I"); // number of cryostats, == 1
348 
349  fGeoTree->Branch("NTPC" , &fNTPC); // number of (virtual) Time Projection Chambers, == 8, NAPA = NTPC/2
350  fGeoTree->Branch("TPC_x" , &fTPC_x, "TPC_x[NTPC]/F"); // TPC length in x
351  fGeoTree->Branch("TPC_y" , &fTPC_y, "TPC_y[NTPC]/F"); // TPC length in y
352  fGeoTree->Branch("TPC_z" , &fTPC_z, "TPC_z[NTPC]/F"); // TPC length in z
353 
354  fGeoTree->Branch("Nplanes" , &fNplanes); // number of wire planes in each TPC, == 3
355  fGeoTree->Branch("plane_type" , &fPlane_type, "plane_type[Nplanes]/I"); // plane type: 0 == induction, 1 == collection
356  fGeoTree->Branch("plane_view" , &fPlane_view, "plane_view[Nplanes]/I"); // wire orientation: 0 == U, 1 == V, 2 == X
357  fGeoTree->Branch("plane_wirepitch" , &fPlane_wirepitch, "plane_wirepitch[Nplanes]/D"); // wire pitch of each plane
358  fGeoTree->Branch("plane_wireangle" , &fPlane_wireangle, "plane_wireangle[Nplanes]/D"); // wire pitch of each plane
359  fGeoTree->Branch("plane_wires" , &fPlane_wires, "Plane_wires[Nplanes]/I"); // number of wires in each plane
360 
361  fGeoTree->Branch("Nchannels" , &fNchannels); // number of total channels
362 
363  fGeoTree->Branch("NOpDets", &fNOpDets, "NOpDets/I");
364  fGeoTree->Branch("OpDetPositions_Y", &fOpDetPositions_Y, "OpDetPositions_Y[NOpDets]/F");
365  fGeoTree->Branch("OpDetPositions_Z", &fOpDetPositions_Z, "OpDetPositions_Z[NOpDets]/F");
366  fGeoTree->Branch("OpDetHalfWidths", &fOpDetHalfWidths, "OpDetHalfWidths[NOpDets]/F");
367  fGeoTree->Branch("OpDetHalfHeights", &fOpDetHalfHeights, "OpDetHalfHeights[NOpDets]/F");
368 
369  // init Event TTree
370  TDirectory* subDir2 = fOutFile->mkdir("Event");
371  subDir2->cd();
372  fEventTree = new TTree("Sim", "Event Tree from Simulation");
373  fEventTree->Branch("eventNo", &fEvent);
374  fEventTree->Branch("runNo", &fRun);
375  fEventTree->Branch("subRunNo", &fSubRun);
376 
377  fEventTree->Branch("raw_Nhit", &fRaw_Nhit); // number of hit channels above threshold
378  fEventTree->Branch("raw_channelId" , &fRaw_channelId, "raw_channelId[raw_Nhit]/I"); // hit channel id; size == raw_Nhit
379  fEventTree->Branch("raw_charge" , &fRaw_charge, "raw_charge[raw_Nhit]/I"); // hit channel id; size == raw_Nhit
380  fEventTree->Branch("raw_time" , &fRaw_time, "raw_time[raw_Nhit]/I"); // hit channel id; size == raw_Nhit
381  fEventTree->Branch("raw_wfADC", &fRaw_wfADC); // raw waveform adc of each channel
382  fEventTree->Branch("raw_wfTDC", &fRaw_wfTDC); // raw waveform tdc of each channel
383 
384  fEventTree->Branch("calib_Nhit", &fCalib_Nhit); // number of hit channels above threshold
385  fEventTree->Branch("calib_channelId" , &fCalib_channelId, "calib_channelId[calib_Nhit]/I"); // hit channel id; size == calib_Nhit
386  fEventTree->Branch("calib_wfADC", &fCalib_wfADC); // calib waveform adc of each channel
387  fEventTree->Branch("calib_wfTDC", &fCalib_wfTDC); // calib waveform tdc of each channel
388 
389 
390  fEventTree->Branch("mc_Ntrack", &fMC_Ntrack); // number of tracks in MC
391  fEventTree->Branch("mc_id", &fMC_id, "mc_id[mc_Ntrack]/I"); // track id; size == mc_Ntrack
392  fEventTree->Branch("mc_pdg", &fMC_pdg, "mc_id[mc_Ntrack]/I"); // track particle pdg; size == mc_Ntrack
393  fEventTree->Branch("mc_mother", &fMC_mother, "mc_mother[mc_Ntrack]/I"); // mother id of this track; size == mc_Ntrack
394  fEventTree->Branch("mc_daughters", &fMC_daughters); // daughters id of this track; vector
395  fEventTree->Branch("mc_startXYZT", &fMC_startXYZT, "mc_startXYZT[mc_Ntrack][4]/F"); // start position of this track; size == mc_Ntrack
396  fEventTree->Branch("mc_endXYZT", &fMC_endXYZT, "mc_endXYZT[mc_Ntrack][4]/F"); // start position of this track; size == mc_Ntrack
397  fEventTree->Branch("mc_startMomentum", &fMC_startMomentum, "mc_startMomentum[mc_Ntrack][4]/F"); // start momentum of this track; size == mc_Ntrack
398  fEventTree->Branch("mc_endMomentum", &fMC_endMomentum, "mc_endMomentum[mc_Ntrack][4]/F"); // start momentum of this track; size == mc_Ntrack
399 
400  fMC_trackPosition = new TObjArray();
401  fMC_trackMomentum= new TObjArray();
402  fMC_trackPosition->SetOwner(kTRUE);
403  fMC_trackMomentum->SetOwner(kTRUE);
404 
405  fEventTree->Branch("mc_trackPosition", &fMC_trackPosition);
406  fEventTree->Branch("mc_trackMomentum", &fMC_trackMomentum);
407 
408  fEventTree->Branch("no_hits", &no_hits); //number of hits
409  fEventTree->Branch("hit_channel", &hit_channel, "hit_channel[no_hits]/I"); // channel ID
410  fEventTree->Branch("hit_peakT", &hit_peakT, "hit_peakT[no_hits]/F"); // peak time
411  fEventTree->Branch("hit_charge", &hit_charge, "hit_charge[no_hits]/F"); // charge (area)
412  fEventTree->Branch("hit_wireID", &hit_wireID, "hit_wireID[no_hits]/F");
413  fEventTree->Branch("hit_plane", &hit_plane, "hit_plane[no_hits]/F");
414  fEventTree->Branch("hit_tpc", &hit_tpc, "hit_tpc[no_hits]/F");
415 
416  fEventTree->Branch("nthits", &nthits);
417  fEventTree->Branch("thit_channel", &thit_channel, "thit_channel[nthits]/I");
418  fEventTree->Branch("thit_peakT", &thit_peakT, "thit_peakT[nthits]/F");
419  fEventTree->Branch("thit_charge", &thit_charge, "thit_charge[nthits]/F");
420  fEventTree->Branch("thit_wireID", &thit_wireID, "thit_wireID[nthits]/I");
421  fEventTree->Branch("thit_plane", &thit_plane, "thit_plane[nthits]/I");
422  fEventTree->Branch("thit_tpc", &thit_tpc, "thit_tpc[nthits]/I");
423 
424  fEventTree->Branch("nclhits", &nclhits, "nclhits/I");
425  fEventTree->Branch("chit_cryostat", &chit_cryostat, "chit_cryostat[nclhits]/I");
426  fEventTree->Branch("chit_tpc", &chit_tpc, "chit_tpc[nclhits]/I");
427  fEventTree->Branch("chit_plane", &chit_plane, "chit_plane[nclhits]/I");
428  fEventTree->Branch("chit_charge", &chit_charge, "chit_charge[nclhits]/I");
429  fEventTree->Branch("chit_peakT", &chit_peakT, "chit_peakT[nclhits]/F");
430  fEventTree->Branch("chit_wire", &chit_wire, "chit_wire[nclhits]/I");
431  fEventTree->Branch("chit_channel", &chit_channel, "chit_channel[nclhits]/I");
432  fEventTree->Branch("chit_cluster", &chit_cluster, "chit_cluster[nclhits]/I");
433 
434  fEventTree->Branch("reco_nTrack", &reco_nTrack);
435  fReco_trackPosition = new TObjArray();
436  fReco_trackPosition->SetOwner(kTRUE);
437  fEventTree->Branch("reco_trackPosition", &fReco_trackPosition);
438 
439  averageWaveforms = new TObjArray();
440  averageWaveforms->SetOwner(kTRUE);
441  fEventTree->Branch("averageWaveforms", &averageWaveforms);
442  fEventTree->Branch("waveformCount", &waveformCount);
443  fEventTree->Branch("OpChannelToOpDet", &OpChannelToOpDet);
444  fEventTree->Branch("timestamp", &timestamp);
445 
446  fEventTree->Branch("sampleFreq", &fSampleFreq, "sampleFreq/D");
447  fEventTree->Branch("RCETimeBegin", &RCETimeBegin, "RCETimeBegin/D");
448  fEventTree->Branch("RCETimeEnd", &RCETimeEnd, "RCETimeEnd/D");
449  fEventTree->Branch("SSPTimeBegin", &SSPTimeBegin, "SSPTimeBegin[1000]/D");
450  fEventTree->Branch("SSPTimeEnd", &SSPTimeEnd, "SSPTimeEnd[1000]/D");
451  gDirectory = tmpDir;
452 
453  // init Photon TTree
454  TDirectory *subDir3 = fOutFile->mkdir("OpDet");
455  subDir3->cd();
457  fThePhotonTreeAll = new TTree("AllPhotons","AllPhotons");
458  fThePhotonTreeAll->Branch("eventNo", &fEvent);
459  fThePhotonTreeAll->Branch("runNo", &fRun);
460  fThePhotonTreeAll->Branch("subRunNo", &fSubRun);
461  fThePhotonTreeAll->Branch("Wavelength", &fWavelength, "Wavelength/F");
462  fThePhotonTreeAll->Branch("OpChannel", &fOpChannel, "OpChannel/I");
463  fThePhotonTreeAll->Branch("Time", &fTime, "Time/F");
464  }
466  fThePhotonTreeDetected = new TTree("DetectedPhotons", "DetectedPhotons");
467  fThePhotonTreeDetected->Branch("eventNo", &fEvent);
468  fThePhotonTreeDetected->Branch("runNo", &fRun);
469  fThePhotonTreeDetected->Branch("subRunNo", &fSubRun);
470  fThePhotonTreeDetected->Branch("Wavelength", &fWavelength, "Wavelength/F");
471  fThePhotonTreeDetected->Branch("OpChannel", &fOpChannel, "OpChannel/I");
472  fThePhotonTreeDetected->Branch("Time", &fTime, "Time/F");
473  }
474  if(fMakeOpDetsTree){
475  fTheOpDetTree = new TTree("OpDets", "OpDets");
476  fTheOpDetTree->Branch("eventNo", &fEvent);
477  fTheOpDetTree->Branch("runNo", &fRun);
478  fTheOpDetTree->Branch("subRunNo", &fSubRun);
479  fTheOpDetTree->Branch("NOpDets", &fNOpDets, "NOpDets/I");
480  fTheOpDetTree->Branch("OpChannel", &fOpChannel, "OpChannel/I");
481  fTheOpDetTree->Branch("CountOpDetAll", &fCountOpDetAll, "CountOpDetAll[NOpDets]/I");
482  fTheOpDetTree->Branch("CountOpDetDetected", &fCountOpDetDetected, "CountOpDetDetected[NOpDets]/I");
483  }
485  fTheEventTree = new TTree("OpDetEvents", "OpDetEvents");
486  fTheEventTree->Branch("eventNo", &fEvent);
487  fTheEventTree->Branch("runNo", &fRun);
488  fTheEventTree->Branch("subRunNo", &fSubRun);
489  fTheEventTree->Branch("CountAll", &fCountEventAll, "CountAll/I");
490  fTheEventTree->Branch("CountDetected", &fCountEventDetected, "CountDetected/I");
491  }
492 
493 
494 }
495 
496 //-----------------------------------------------------------------------
498 {
499  //art::ServiceHandle< util::TimeService> timeService;
500  auto const* timeService = lar::providerFrom<detinfo::DetectorClocksService>();
501  fSampleFreq = timeService->OpticalClock().Frequency();
502 
503  fNcryostats = fGeom->Ncryostats(); // 1 for 35t
504  // 8 TPC for 35t
505  // TPC (0,1), (6,7): large APA
506  // TPC (2,3), (4,5): small APA
507  // 0,2,4,6: short drift; 1,3,5,7: long drift
508  fNTPC = fGeom->NTPC();
509  for (int i=0; i<fNTPC; i++) {
510  fTPC_x[i] = fGeom->DetHalfWidth(i)*2;
511  fTPC_y[i] = fGeom->DetHalfHeight(i)*2;
512  fTPC_z[i] = fGeom->DetLength(i);
513  }
514 
515  // 3 planes for 35t. geo::kCollection plane: 1; induction plane: 0
516  // plane 0( type: 0, Nwires: 357)
517  // plane 1( type: 0, Nwires: 343)
518  // plane 2( type: 1, Nwires: 111)
519  fNplanes = fGeom->Nplanes();
520  for (int i=0; i<fNplanes; i++) {
521  fPlane_type[i] = fGeom->SignalType(geo::PlaneID(0, 0, i));
522  fPlane_view[i] = fGeom->Plane(i).View();
523  // fPlane_wirepitch[i] = fGeom->WirePitch(fPlane_view[i]); // this doesn't seem to return the correct value!
524  fPlane_wirepitch[i] = fGeom->WirePitch(fPlane_view[i], 1, 0); // this doesn't seem to return the correct value!
526  fPlane_wires[i] = fGeom->Nwires(i);
527  }
528 
530 
531  // photon detector
532  fNOpDets = fGeom->NOpDets();
533  OpChannelToOpDet.resize(MAX_OPDET);
534  timestamp.resize(MAX_OPDET);
535  double xyz[3];
536  double tmp;
537  for (int i=0; i<fNOpDets; i++) {
538  const geo::OpDetGeo& fOpDetNode = fGeom->Cryostat(0).OpDet(i);
539  fOpDetNode.GetCenter(xyz,0.);
540  fOpDetPositions_Y[i] = (float)xyz[1];
541  fOpDetPositions_Z[i] = (float)xyz[2];
542  TGeoNode *fOpNode = (TGeoNode*)fOpDetNode.Node();
543  TGeoTube *fOpTube = (TGeoTube*)fOpNode->GetVolume()->GetShape();
544  tmp = fOpTube->GetDZ();//GetRmax();//fOpDetNode.RMax();
545  fOpDetHalfWidths[i] = (float)tmp;
546  tmp = fOpTube->GetDY();//fOpDetNode.HalfL();
547  fOpDetHalfHeights[i] = (float)tmp;
548  }
549 
550  printGeometry();
551 
552  // Write fGeoTree to Disk (once)
553  fGeoTree->Fill();
554  TDirectory* tmpDir = gDirectory;
555  fOutFile->cd("/Detector");
556  fGeoTree->Write();
557  gDirectory = tmpDir;
558 
559  // Save Channel Map to text file.
560  if (fSaveChannelWireMap) {
562  }
563  // saveWireGeometry(1, 1);
564  // saveWireGeometry(1, 3);
565  // saveWireGeometry(1, 5);
566  // saveWireGeometry(1, 7);
567 
568  /*
569  std::ofstream wireGeoFile;
570  wireGeoFile.open("WireGeometry.txt");
571  for (unsigned int plane=0; plane<(unsigned int)fNplanes; plane++) {
572  wireGeoFile << "***************** PLANE " << plane <<" ********************\n";
573  for(unsigned int tpc=0; tpc<(unsigned int)fNTPC; tpc++) {
574  wireGeoFile << "----------- TPC "<< tpc << " ------------\n";
575  wireGeoFile << "Wire# WireID ChannelID Start End\n";
576  int Nwires = fGeom->Nwires(plane, tpc);
577  double xyzStart[3];
578  double xyzEnd[3];
579  for(int wire=0; wire<Nwires; wire++) {
580  fGeom->WireEndPoints(0, tpc, plane, wire, xyzStart, xyzEnd);
581  uint32_t channelid = fGeom->PlaneWireToChannel(plane, wire, tpc, 0);
582  int wireid = wire;
583  wireGeoFile << " " << xyzStart[0] << " " << xyzEnd[0] <<"\n";
584  wireGeoFile << wire << " " << wireid << " ";
585  wireGeoFile << channelid << " " << xyzStart[1] << " " << xyzEnd[1] << "\n";
586  wireGeoFile << " " << xyzStart[2] << " " << xyzEnd[2] <<"\n";
587  }
588  wireGeoFile << "------------------------------------------\n\n";
589  }
590  wireGeoFile << "\n***********************************************\n\n";
591  }
592  wireGeoFile << "\n" << endl;
593  wireGeoFile.close();
594  */
595 }
596 
597 
598 //-----------------------------------------------------------------------
600 {
601  std::ofstream mapfile;
602  mapfile.open("ChannelWireMap.txt");
603  mapfile << "# total channels: " << fNchannels << "\n\n";
604  for (int i=0; i<fNchannels; i++) {
605  std::vector<geo::WireID> wireids = fGeom->ChannelToWire(i);
606  mapfile << "Channel " << i << "\n";
607  mapfile << "Nwires " << wireids.size() << "\n";
608 
609  mapfile << "TPC ";
610  for (auto const& wid : wireids) {
611  mapfile << wid.TPC << " ";
612  }
613  mapfile << "\n";
614 
615  mapfile << "Plane ";
616  for (auto const& wid : wireids) {
617  mapfile << wid.Plane << " ";
618  }
619  mapfile << "\n";
620 
621  // redundant: Plane defines View
622  // mapfile << "View ";
623  // for (auto const& wid : wireids) {
624  // mapfile << fGeom->Plane(wid.Plane, wid.TPC).View() << " ";
625  // }
626  // mapfile << "\n";
627 
628  mapfile << "Wire ";
629  for (auto const& wid : wireids) {
630  mapfile << wid.Wire << " ";
631  }
632  mapfile << "\n" << endl;
633  }
634 
635  mapfile.close();
636 }
637 
638 
639 //-----------------------------------------------------------------------
640 void CTree35t::saveWireGeometry(int plane, int tpc)
641 {
642  int cstat = 0;
643  int Nwires = fGeom->Nwires(plane, tpc);
644  double xyzStart[3];
645  double xyzEnd[3];
646  for (int wire=0; wire<Nwires; wire++) {
647  fGeom->WireEndPoints(cstat, tpc, plane, wire, xyzStart, xyzEnd);
648  cout << plane << "\t" << wire << "\t";
649  for (int i=0; i<3; i++) {
650  cout << xyzStart[i] << "\t";
651  }
652  for (int i=0; i<3; i++) {
653  cout << xyzEnd[i] << "\t";
654  }
655  cout << endl;
656  }
657 
658  // cout << " Temperature: " << larp->Temperature() << endl;
659  // cout << " E field: " << larp->Efield() << endl;
660  // cout << " Drift Velocity: " << larp->DriftVelocity(larp->Efield(), larp->Temperature()) << endl;
661 
662 }
663 
664 //-----------------------------------------------------------------------
666 {
667  // Write fGeoTree to fEventTree
668  TDirectory* tmpDir = gDirectory;
669  fOutFile->cd("/Event");
670  fEventTree->Write();
671  fOutFile->cd("/OpDet");
674  if(fMakeOpDetsTree) fTheOpDetTree->Write();
675  if(fMakeOpDetEventsTree) fTheEventTree->Write();
676  gDirectory = tmpDir;
677  fOutFile->Close();
678 }
679 
680 
681 //-----------------------------------------------------------------------
683 {
684 
685  cout << "fNcryostats: " << fNcryostats << endl;
686  cout << "fNTPC: " << fNTPC << endl;
687  for (int i=0; i<fNTPC; i++) {
688  cout << "\tTPC " << i << ": " << fTPC_x[i] << ", " << fTPC_y[i] << ", " << fTPC_z[i] << endl;
689  }
690  cout << "fNplanes: " << fNplanes << endl;
691  for (int i=0; i<fNplanes; i++) {
692  cout
693  << "\tplane " << i
694  << "( type: " << fPlane_type[i]
695  << ", view: " << fPlane_view[i]
696  << ", wirepitch: " << fPlane_wirepitch[i]
697  << ", wire angle: " << fPlane_wireangle[i]
698  << ", wires: " << fPlane_wires[i]
699  << ")" << endl;
700  }
701  cout << "fNchannels: " << fNchannels << endl;
702  cout << "fNOpDet: " << fGeom->NOpDets() << endl;
703  cout << "fAuxDetectors: " << fGeom->NAuxDets() << endl;
704  cout << endl;
705 }
706 
707 
708 //-----------------------------------------------------------------------
709 void CTree35t::beginRun(const art::Run& /*run*/)
710 {
711  mf::LogInfo("CTree35t") << "begin run";
712 }
713 
714 
715 //-----------------------------------------------------------------------
717 {
718  reset();
719 
720  fEvent = event.id().event();
721  fRun = event.run();
722  fSubRun = event.subRun();
723 
724  if (fProcessMCtruth) processMC(event);
725  processRaw(event);
726  if (fProcessCalib) processCalib(event);
727  if (fProcessHits) processHits(event);
728  if (fProcessReco) processRecoTracks(event);
729  if (fProcessOpDet) processOpDet(event);
730  processTiming(event);
731  fEventTree->Fill();
732  printEvent();
733 
734 }
735 
736 
737 //-----------------------------------------------------------------------
739 {
740  fRaw_wfADC.clear();
741  fRaw_wfTDC.clear();
742  fCalib_wfADC.clear();
743  fCalib_wfTDC.clear();
744  for (int i=0; i<MAX_CHANNEL; i++) {
745  fRaw_channelId[i] = 0;
746  fRaw_charge[i] = 0;
747  fRaw_time[i] = 0;
748  fCalib_channelId[i] = 0;
749  }
750 
751  for (int i=0; i<MAX_TRACKS; i++) {
752  fMC_id[i] = 0;
753  fMC_pdg[i] = 0;
754  fMC_mother[i] = 0;
755  for (int j=0; j<4; j++) {
756  fMC_startXYZT[i][j] = 0;
757  fMC_endXYZT[i][j] = 0;
758  fMC_startMomentum[i][j] = 0;
759  fMC_endMomentum[i][j] = 0;
760  }
761  }
762  fMC_daughters.clear();
763 
764  fMC_trackPosition->Clear();
765  fMC_trackMomentum->Clear();
766 
767  for (int i=0; i<MAX_HITS; i++) {
768  hit_channel[i] = 0;
769  hit_peakT[i] = 0;
770  hit_charge[i] = 0;
771  hit_wireID[i] = 0;
772  hit_plane[i] = 0;
773  hit_tpc[i] = 0;
774  }
775 
776  fReco_trackPosition->Clear();
777 
778  averageWaveforms->Clear();
779  waveformCount.clear();
780  for (size_t i = 0; i < MAX_OPDET; ++i) {
781  OpChannelToOpDet.at(i).clear();
782  timestamp.at(i).clear();
783  }
784 
785  fCount=0;
786  fCountEventAll=0;
788  fOpChannel=0;
789  for (int i=0; i<MAX_OPDET; i++) {
790  fCountOpDetAll[i]=0;
791  fCountOpDetDetected[i]=0;
792  }
793 }
794 
795 
796 //-----------------------------------------------------------------------
798 {
799 
800  // unsigned int tpcNo, cryoNo;
801  // get the objects holding all of the raw data information
803  event.getByLabel(fRawDigitLabel, rawdigit);
804  std::cout << "raw digit label check: " << fRawDigitLabel << std::endl;
805 
806  // put it in a more easily usable form
807  std::vector< art::Ptr<raw::RawDigit> > rawhits;
808  art::fill_ptr_vector(rawhits, rawdigit);
809 
810  // rawhits size should == Nchannels == 2048; (no hit channel has a flat 0-waveform)
811  cout << "\n Raw Hits size: " << rawhits.size() << endl;
812 
813  //loop through all RawDigits (over entire channels)
814  fRaw_Nhit = 0;
815  for (auto const& hit : rawhits) {
816  int chanId = hit->Channel();
817  int nSamples = hit->Samples();
818  std::vector<short> uncompressed(nSamples);
819  int pedestal = (int)hit->GetPedestal();
820  // std::cout << " channel " << chanId << " pedestal " << pedestal << std::endl;
821  // uncompress the data
822  if (fUncompressWithPed){
823  raw::Uncompress(hit->ADCs(), uncompressed, pedestal, hit->Compression());
824  }
825  else{
826  raw::Uncompress(hit->ADCs(), uncompressed, hit->Compression());
827  }
828 
829  // short thresh = pedestal + 1; // threshold set to 1 adc;
830  short thresh = 1; // threshold set to 1 adc;
831  bool isHit = false;
832  for (auto const& adc : uncompressed) {
833  short ladc = adc-pedestal;
834  if (ladc > thresh) {
835  isHit = true;
836  break;
837  }
838  }
839  if (!isHit) continue; // skip empty channels
840 
841  int id = fRaw_Nhit;
842  fRaw_channelId[id] = chanId;
843 
844  vector<int> wfADC;
845  vector<int> wfTDC;
846  int nSavedSamples = 0;
847  // std::cout << " channel " << chanId << std::endl;
848  bool hasTime = false;
849  for (int i=0; i<nSamples; i++) {
850  short adc = uncompressed[i]-pedestal;
851  if (adc != 0) {
852  nSavedSamples++;
853  wfADC.push_back(int(adc));
854  wfTDC.push_back(i);
855  fRaw_charge[id] += adc;
856  if (!hasTime) {
857  fRaw_time[id] = i;
858  hasTime = true;
859  }
860  }
861  }
862 
863  fRaw_wfADC.push_back(wfADC);
864  fRaw_wfTDC.push_back(wfTDC);
865  fRaw_Nhit++;
866  // std::vector<geo::WireID> wireids = fGeom->ChannelToWire(chanNo);
867  // cout
868  // << "\n channelID: " << fRaw_channelId[id]
869  // << "\n charge: " << fRaw_charge[id]
870  // << "\n time: " << fRaw_time[id]
871  // << "\n nSamples: " << nSamples
872  // << "\n pedestal: " << pedstal
873  // << "\n nSavedSamples: " << nSavedSamples
874  // << endl;
875 
876  }
877 
878 }
879 
881 {
882 
884  if (! event.getByLabel(fCalibLabel, wires_handle)) return;
885 
886  // put it in a more easily usable form
887  std::vector< art::Ptr<recob::Wire> > wires;
888  art::fill_ptr_vector(wires, wires_handle);
889 
890  // wires size should == Nchannels == 1992; (no hit channel has a flat 0-waveform)
891  // cout << "\n wires size: " << wires.size() << endl;
892 
893  fCalib_Nhit = 0;
894  for (auto const& wire : wires) {
895  std::vector<float> calibwf = wire->Signal();
896  int chanId = wire->Channel();
897  int nSamples = calibwf.size();
898  int pedstal = 0;
899 
900  short thresh = pedstal + 1; // threshold set to 1 adc;
901  bool isHit = false;
902  for (auto const& adc : calibwf) {
903  if (adc > thresh) {
904  isHit = true;
905  break;
906  }
907  }
908  if (!isHit) continue; // skip empty channels
909 
910  int id = fCalib_Nhit;
911  fCalib_channelId[id] = chanId;
912 
913  vector<int> wfADC;
914  vector<int> wfTDC;
915  int nSavedSamples = 0;
916  for (int i=0; i<nSamples; i++) {
917  int adc = int(calibwf[i]);
918  if (adc != pedstal) {
919  // cout << i << "," << adc << " | ";
920  nSavedSamples++;
921  wfADC.push_back(adc);
922  wfTDC.push_back(i);
923  }
924  }
925  // cout << endl;
926 
927  fCalib_wfADC.push_back(wfADC);
928  fCalib_wfTDC.push_back(wfTDC);
929  fCalib_Nhit++;
930  }
931 
932 }
933 
935 {
937  event.getByLabel("largeant", particleHandle);
938 
939  // put it in a more easily usable form
940  std::vector< art::Ptr<simb::MCParticle> > particles;
941  art::fill_ptr_vector(particles, particleHandle);
942 
944  event.getByLabel("largeant", simChannelHandle);
945 
946  fMC_Ntrack = particles.size();
947 
948  int i=0; // track index
949  for (auto const& particle: particles ) {
950  fMC_id[i] = particle->TrackId();
951  fMC_pdg[i] = particle->PdgCode();
952  fMC_mother[i] = particle->Mother();
953  std::cout<<"i = "<<i
954  <<"\nfMC_id[i] = "<<fMC_id[i]
955  <<"\nfMC_pdg[i] = "<<fMC_pdg[i]
956  <<"\nfMC_mother[i] = "<<fMC_mother[i]<<std::endl;
957  int Ndaughters = particle->NumberDaughters();
958  vector<int> daughters;
959  for (int i=0; i<Ndaughters; i++) {
960  daughters.push_back(particle->Daughter(i));
961  }
962  fMC_daughters.push_back(daughters);
963  size_t numberTrajectoryPoints = particle->NumberTrajectoryPoints();
964  int last = numberTrajectoryPoints - 1;
965  const TLorentzVector& positionStart = particle->Position(0);
966  const TLorentzVector& positionEnd = particle->Position(last);
967  const TLorentzVector& momentumStart = particle->Momentum(0);
968  const TLorentzVector& momentumEnd = particle->Momentum(last);
969  positionStart.GetXYZT(fMC_startXYZT[i]);
970  positionEnd.GetXYZT(fMC_endXYZT[i]);
971  momentumStart.GetXYZT(fMC_startMomentum[i]);
972  momentumEnd.GetXYZT(fMC_endMomentum[i]);
973 
974  TClonesArray *Lposition = new TClonesArray("TLorentzVector", numberTrajectoryPoints);
975  TClonesArray *Lmomentum = new TClonesArray("TLorentzVector", numberTrajectoryPoints);
976  // Read the position and momentum along this particle track
977  for(unsigned int j=0; j<numberTrajectoryPoints; j++) {
978  new ((*Lposition)[j]) TLorentzVector(particle->Position(j));
979  new ((*Lmomentum)[j]) TLorentzVector(particle->Momentum(j));
980  // TLorentzVector *pos = new ((*Lposition)[j]) TLorentzVector(/*particle->Position(j)*/);
981  // TLorentzVector *mom = new ((*Lmomentum)[j]) TLorentzVector(/*particle->Momentum(j)*/);
982  // const TLorentzVector& tmp_pos = particle->Position(j);
983  // const TLorentzVector& tmp_mom = particle->Momentum(j);
984  // *pos = tmp_pos;
985  // *mom = tmp_mom;
986  }
987  fMC_trackPosition->Add(Lposition);
988  fMC_trackMomentum->Add(Lmomentum);
989 
990 
991  i++;
992  } // particle loop done
993 }
994 
995 
997 {
998  art::Handle< std::vector<recob::Hit> > hitListHandle;
999  if (! event.getByLabel(fHitsModuleLabel, hitListHandle)) return;
1000  std::vector<art::Ptr<recob::Hit> > hitlist;
1001  art::fill_ptr_vector(hitlist, hitListHandle);
1002 
1003  no_hits = hitlist.size();
1004  if (no_hits>MAX_HITS) {
1005  mf::LogError("CTree35t") << "Event has " << no_hits
1006  << " hits, MAX ALLOWED: " << MAX_HITS;
1007  }
1008  for (int i=0; i<no_hits; i++) {
1009  art::Ptr<recob::Hit> hit = hitlist[i];
1010  hit_channel[i] = hit->Channel();
1011  hit_charge[i] = hit->Integral();
1012  hit_peakT[i] = hit->PeakTime();
1013  hit_wireID[i] = hit->WireID().Wire;
1014  hit_tpc[i] = hit->WireID().TPC;
1015  hit_plane[i] = hit->WireID().Plane;
1016  }
1017 
1018  art::Handle< std::vector<recob::Hit> > tHitListHandle;
1019  if(! event.getByLabel("dcheat", tHitListHandle)) return;
1020  std::vector< art::Ptr<recob::Hit> > tHitlist;
1021  art::fill_ptr_vector(tHitlist, tHitListHandle);
1022  nthits = tHitlist.size();
1023  if (nthits>MAX_HITS) {
1024  mf::LogError("CTree35t") << "Event has " << nthits
1025  << " hits, MAX ALLOWED: " << MAX_HITS;
1026  }
1027  for (int i=0; i<nthits; i++) {
1028  art::Ptr<recob::Hit> hit = tHitlist[i];
1029  thit_channel[i] = hit->Channel();
1030  thit_charge[i] = hit->Integral();
1031  thit_peakT[i] = hit->PeakTime();
1032  thit_wireID[i] = hit->WireID().Wire;
1033  thit_tpc[i] = hit->WireID().TPC;
1034  thit_plane[i] = hit->WireID().Plane;
1035  }
1036 
1037 
1038  art::Handle< std::vector<recob::Cluster> > clusterListHandle;
1039  if (! event.getByLabel(fClusterModuleLabel, clusterListHandle)) return;
1040  std::vector<art::Ptr<recob::Cluster> > clusterlist;
1041  art::fill_ptr_vector(clusterlist, clusterListHandle);
1042  art::FindManyP<recob::Hit> fm(clusterListHandle, event, fClusterModuleLabel);
1043  //if (fm.empty()) {cout<<"can't associate cluters with hits. aborting..."<<endl; return;}
1044  int nclusters = clusterlist.size();
1045  cout<<"# of clusters is "<<nclusters<<endl;
1046  nclhits=0;
1047  for(size_t i=0; i<clusterlist.size(); ++i){
1048  geo::PlaneID planeid = clusterlist[i]->Plane();
1049  std::vector< art::Ptr<recob::Hit> > hitslist = fm.at(i);
1050  size_t n_hits = hitslist.size();
1051  //for (auto theHit=hitslist.begin();theHit!=hitslist.end();theHit++){
1052  for(size_t j=0; j<n_hits; j++) {
1053  art::Ptr<recob::Hit> hit = hitslist[j];
1054  chit_channel[nclhits] = hit->Channel();
1055  chit_wire[nclhits] = hit->WireID().Wire;
1056  chit_peakT[nclhits] = hit->PeakTime();
1057  chit_plane[nclhits] = planeid.Plane;
1058  chit_tpc[nclhits] = planeid.TPC;
1059  chit_cryostat[nclhits] = planeid.Cryostat;
1060  chit_charge[nclhits] = clusterlist[i]->Charge(0);
1061  chit_cluster[nclhits] = i;
1062  nclhits++;
1063  }
1064  //cout<<"nclhits = "<<nclhits<<endl;
1065  }
1066 }
1067 
1069 {
1070  art::Handle< std::vector<recob::Track> > trackListHandle;
1071  if (! event.getByLabel(fTrackModuleLabel, trackListHandle)) return;
1072  std::vector<art::Ptr<recob::Track> > tracklist;
1073  art::fill_ptr_vector(tracklist, trackListHandle);
1074 
1075  reco_nTrack = tracklist.size();
1076  for (int i=0; i<reco_nTrack; i++) {
1077  art::Ptr<recob::Track> track = tracklist[i];
1078  if (track->NumberTrajectoryPoints() > 0) {
1079  // cout << "track momentum: " << track->VertexMomentum() << endl;
1080  }
1081  size_t numberTrajectoryPoints = track->NumberTrajectoryPoints();
1082  // cout << numberTrajectoryPoints << ", " << track->NumberTrajectoryPoints() << endl;
1083 
1084  TClonesArray *Lposition = new TClonesArray("TLorentzVector", numberTrajectoryPoints);
1085  // Read the position and momentum along this particle track
1086  for(unsigned int j=0; j<numberTrajectoryPoints; j++) {
1087  new ((*Lposition)[j]) TLorentzVector(track->LocationAtPoint<TVector3>(j), 0);
1088  }
1089  fReco_trackPosition->Add(Lposition);
1090  }
1091 }
1092 
1094 {
1096  event.getByLabel(fOpDetInputModule, fInstanceName, waveformHandle);
1098  event.getByLabel(fOpHitModule, OpHitHandle);
1099  std::cout << "OpHitHandle->size() = " << OpHitHandle->size() << std::endl;
1100  std::cout<<"waveformHandle->size() = "<<waveformHandle->size()<<std::endl;
1101  for (size_t i = 0; i < waveformHandle->size(); ++i) {
1102  art::Ptr<raw::OpDetWaveform> waveformPtr(waveformHandle, i);
1103  raw::OpDetWaveform pulse = *waveformPtr;
1104  double extractedTimestamp = pulse.TimeStamp();
1105  int channel = pulse.ChannelNumber();
1106  int OpDetNumber = fGeom->GeometryCore::OpDetFromOpChannel(channel);
1107  std::cout<<i<<": channel = "<<channel<<", timestamp = "<<std::setprecision(15)<<extractedTimestamp<<", OpDetNumber = "<<OpDetNumber<<", #Ticks = "<<pulse.size()<<", fSampleFreq = "<<fSampleFreq<<std::endl;
1108  //auto findchannel = find(OpChannelToOpDet.at(OpDetNumber).begin(), OpChannelToOpDet.at(OpDetNumber).end(), channel);
1109  //if (findchannel == OpChannelToOpDet.at(OpDetNumber).end()) {
1110  OpChannelToOpDet.at(OpDetNumber).push_back(channel);
1111  timestamp.at(OpDetNumber).push_back((int)extractedTimestamp);
1112  //}
1113  TH1D *hwaveform = new TH1D(Form("avgwaveform_channel_%i_%i", channel, waveformCount[channel]), Form("average waveform channel %i %i-waveform", channel, waveformCount[channel]), pulse.size(), extractedTimestamp, double(pulse.size())/fSampleFreq+extractedTimestamp);
1114  for (size_t tick = 0; tick < pulse.size(); ++tick) {
1115  hwaveform->Fill(extractedTimestamp+double(tick)/fSampleFreq, pulse[tick]);
1116  }
1118  averageWaveforms->Add(hwaveform);
1119 
1120  }
1121  /*
1122  for (size_t i = 0; i != OpHitHandle->size(); ++i) {
1123  int channel = OpHitHandle->at(i).OpChannel();
1124  OpHitCount[channel]++;
1125  OpHitCountPerEvent[channel]++;
1126  }*/
1127 
1128  /*
1129  art::ServiceHandle<sim::LArG4Parameters> lgp;
1130  bool fUseLitePhotons = lgp->UseLitePhotons();
1131 
1132  // Service for determining opdet responses
1133  art::ServiceHandle<opdet::OpDetResponseInterface> odresponse;
1134 
1135  if (!fUseLitePhotons) {
1136  std::cout<<"Cannot get SimPhotonsLite. Aborting..."<<std::endl;
1137  return;
1138  }
1139 
1140  art::Handle< std::vector<sim::SimPhotonsLite> > photonHandle;
1141  event.getByLabel("largeant", photonHandle);
1142  std::vector<art::Ptr<sim::SimPhotonsLite> > photonlite;
1143  art::fill_ptr_vector(photonlite, photonHandle);
1144 
1145  // reset counters
1146  fCountEventAll=0;
1147  fCountEventDetected=0;
1148  //std::cout<<"Found OpDet hit collection of size "<< photonlite.size()<<std::endl;
1149 
1150  if (photonlite.size()>0) {
1151  int size = photonlite.size();
1152  //std::cout<<"photonlite.size() = "<<size<<std::endl;
1153  for (int k=0; k<size; k++) {
1154  //Get data from HitCollection entry
1155  art::Ptr<sim::SimPhotonsLite> photon = photonlite[k];
1156  fOpChannel=photon->OpChannel;
1157  std::map<int, int> PhotonsMap = photon->DetectedPhotons;
1158 
1159  for (auto it = PhotonsMap.begin(); it!= PhotonsMap.end(); it++){
1160  // Calculate wavelength in nm
1161  fWavelength= 128;
1162  //Get arrival time from phot
1163  fTime= it->first*2;
1164  //std::cout<<"Arrival time: " << fTime<<std::endl;
1165  for (int i = 0; i < it->second ; i++) { // second: number of photons
1166  // Increment per OpDet counters and fill per phot trees
1167  fCountOpDetAll[fOpChannel]++;
1168  if (fMakeAllPhotonsTree) fThePhotonTreeAll->Fill();
1169  if (odresponse->detectedLite(fOpChannel)) {
1170  if (fMakeDetectedPhotonsTree) fThePhotonTreeDetected->Fill();
1171  fCountOpDetDetected[fOpChannel]++;
1172  //std::cout<<"OpDetResponseInterface PerPhoton : Event "<<fEvent<<" OpChannel " <<fOpChannel << " Wavelength " << fWavelength << " Detected 1 "<<std::endl;
1173  } else {
1174  //std::cout<<"OpDetResponseInterface PerPhoton : Event "<<fEvent<<" OpChannel " <<fOpChannel << " Wavelength " << fWavelength << " Detected 0 "<<std::endl;
1175  }
1176  }
1177  }
1178  // Incremenent per event and fill Per OpDet trees
1179  fCountEventAll+=fCountOpDetAll[fOpChannel];
1180  fCountEventDetected+=fCountOpDetDetected[fOpChannel];
1181  //std::cout<<"OpDetResponseInterface PerOpDet : Event "<<fEvent<<" OpDet " << fOpChannel << " All " << fCountOpDetAll << " Det " <<fCountOpDetDetected<<std::endl;
1182  }
1183  if(fMakeOpDetsTree) fTheOpDetTree->Fill();
1184  if (fMakeOpDetEventsTree) fTheEventTree->Fill();
1185  //std::cout<<"OpDetResponseInterface PerEvent : Event "<<fEvent<<" All " << fCountEventAll << " Det " <<fCountEventDetected<<std::endl;
1186  } else {
1187  // if empty OpDet hit collection,
1188  // add an empty record to the per event tree
1189  if(fMakeOpDetsTree) fTheOpDetTree->Fill();
1190  if(fMakeOpDetEventsTree) fTheEventTree->Fill();
1191  }
1192  */
1193 }
1194 
1195 // -------------------------------------------------------------------
1197 {
1198  // RCE
1199  art::Handle<artdaq::Fragments> RCErawFragments;
1200  event.getByLabel(fRCERawDataLabel, fRCEFragType, RCErawFragments);
1201  bool RCEPresent = true;
1202  try { RCErawFragments->size(); }
1203  catch(std::exception const&) {
1204  std::cout << "WARNING: Raw RCE data not found in event " << event.event() << std::endl;
1205  RCEPresent = false;
1206  }
1207 
1208  if (RCEPresent) {
1209  if(!RCErawFragments.isValid()){
1210  std::cerr << "Run: " << event.run() << ", SubRun: " << event.subRun() << ", Event: " << event.event() << " is NOT VALID" << std::endl;
1211  throw cet::exception("RCErawFragments NOT VALID");
1212  return;
1213  }
1214 
1215  artdaq::Fragments const& rawFragmentsRCE = *RCErawFragments;
1216  std::cout<<"rawFragmentsRCE.size() = "<<rawFragmentsRCE.size()<<std::endl;
1217  for ( size_t fragIndex=0; fragIndex < rawFragmentsRCE.size(); ++fragIndex ) {
1218  int ThisADCcount = 0;
1219  const artdaq::Fragment &singleFragment = rawFragmentsRCE[fragIndex];
1220  lbne::TpcMilliSliceFragment millisliceFragment(singleFragment);
1221  auto numMicroSlices = millisliceFragment.microSliceCount();
1222  for (unsigned int i_micro=0;i_micro<numMicroSlices;i_micro++) { // Loop through all MicroSlices
1223  std::unique_ptr <const lbne::TpcMicroSlice> microSlice = millisliceFragment.microSlice(i_micro);
1224  auto numNanoSlices = microSlice->nanoSliceCount();
1225  if (numNanoSlices) {
1226  //ConsistRCE = 1;
1227  ThisADCcount += numNanoSlices;
1228  std::cout<<fragIndex<<": "<<numNanoSlices<<", "<<ThisADCcount<<std::endl;
1229  } // If numNanoSlices.
1230  if ( fragIndex==0 && i_micro==0 ) {
1231  std::cout << "Getting RCE time for event " << event.event();
1232  if ( microSlice->nanoSliceCount() ) { // If this MicroSlice has any NanoSlices
1233  RCETimeBegin = microSlice->nanoSlice(0)->nova_timestamp();
1234  std::cout << ", taking RCETime from first nanoslice " << RCETimeBegin << std::endl;
1235  } // NanoSlice
1236  else {
1237  RCETimeBegin = microSlice->software_message();
1238  std::cout << ", taking RCETime from header " << RCETimeBegin << std::endl;
1239  }
1240  } // Looking at first MicroSlice of first Fragment
1241  if ( fragIndex==rawFragmentsRCE.size()-1 && i_micro==numMicroSlices-1) { // last microslice of last fragment
1242  RCETimeEnd = microSlice->nanoSlice(numNanoSlices-1)->nova_timestamp();
1243  } else {
1244  std::unique_ptr <const lbne::TpcMicroSlice> prevMicroSlice = millisliceFragment.microSlice(i_micro-1);
1245  RCETimeEnd = 2.*microSlice->software_message() - prevMicroSlice->software_message();
1246  }
1247  } // MicroSlice
1248  }
1249  }
1250 
1251  // SSP Section ------------------------
1252  bool SSPPresent = true;
1253  art::Handle<artdaq::Fragments> SSPrawFragments;
1254  event.getByLabel(fSSPRawDataLabel, fSSPFragType, SSPrawFragments);
1255  try { SSPrawFragments->size(); }
1256  catch(std::exception const&) {
1257  mf::LogWarning("SSPToOffline") << "WARNING: Raw SSP data not found in event " << event.event();
1258  SSPPresent = false;
1259  }
1260 
1261  if (SSPPresent) {
1262  if(!SSPrawFragments.isValid()){
1263  mf::LogError("SSPToOffline") << "Run: " << event.run() << ", SubRun: " << event.subRun() << ", Event: " << event.event() << " is NOT VALID";
1264  throw cet::exception("raw NOT VALID");
1265  return;
1266  }
1267 
1268  artdaq::Fragments const& rawFragmentsSSP = *SSPrawFragments;
1269  std::cout<<"rawFragmentsSSP.size() = "<<rawFragmentsSSP.size()<<std::endl;
1270 
1271  if ( rawFragmentsSSP.size() ) {
1272  const auto& frag(rawFragmentsSSP[0]);
1273  const SSPDAQ::MillisliceHeader* meta=0;
1274  if(frag.hasMetadata())
1275  {
1276  meta = &(frag.metadata<lbne::SSPFragment::Metadata>()->sliceHeader);
1277  std::cout << "=== SSP Metadata, Start time " << meta->startTime << ", End time " << meta->endTime << " Packet length " << meta->length << " Number of triggers " << meta->nTriggers << "===" << std::endl;
1278  SSPTimeBegin = meta->startTime;
1279  }
1280  }
1281  std::cout << "Got SSP start time, it is " << SSPTimeBegin << std::endl;
1282 
1283  for (size_t fragIndex = 0; fragIndex < rawFragmentsSSP.size(); ++fragIndex) {
1284  const auto& frag(rawFragmentsSSP.at(fragIndex));
1285  const SSPDAQ::MillisliceHeader *meta = 0;
1286  if (frag.hasMetadata()) {
1287  meta = &(frag.metadata<lbne::SSPFragment::Metadata>()->sliceHeader);
1288  std::cout<<fragIndex<<", "<<meta->endTime<<std::endl;
1289  if (fragIndex == rawFragmentsSSP.size()-1) SSPTimeEnd = meta->endTime;
1290  }
1291  }
1292  } // SSP Present
1293 }
1294 
1295 // -------------------------------------------------------------------
1297 {
1298  cout << " Event: " << fEvent << endl;
1299  cout << " Run: " << fRun << endl;
1300  cout << "SubRun: " << fSubRun << endl;
1301 
1302  cout << " Hit Channels: " << fRaw_Nhit << endl;
1303  cout << " MC Ntracks:" << fMC_Ntrack;
1304  for (int i=0; i<fMC_Ntrack; i++) {
1305  cout << "\n id: " << fMC_id[i];
1306  cout << "\n pdg: " << fMC_pdg[i];
1307  cout << "\n mother: " << fMC_mother[i];
1308  cout << "\n Ndaughters: " << fMC_daughters.at(i).size();
1309  cout << "\n start XYZT: (" << fMC_startXYZT[i][0] << ", " << fMC_startXYZT[i][1] << ", " << fMC_startXYZT[i][2] << ", " << fMC_startXYZT[i][3] << ")";
1310  cout << "\n end XYZT: (" << fMC_endXYZT[i][0] << ", " << fMC_endXYZT[i][1] << ", " << fMC_endXYZT[i][2] << ", " << fMC_endXYZT[i][3] << ")";
1311  cout << "\n start momentum: (" << fMC_startMomentum[i][0] << ", " << fMC_startMomentum[i][1] << ", " << fMC_startMomentum[i][2] << ", " << fMC_startMomentum[i][3] << ")";
1312  cout << "\n end momentum: (" << fMC_endMomentum[i][0] << ", " << fMC_endMomentum[i][1] << ", " << fMC_endMomentum[i][2] << ", " << fMC_endMomentum[i][3] << ")";
1313 
1314  cout << endl;
1315  }
1316 
1317  cout << "Number of Hits Found: " << no_hits << endl;
1318  cout << "Number of reco tracks: " << reco_nTrack << endl;
1319  cout << "Number of all photons: "<< fCountEventAll << endl;
1320  cout << "Number of photons detected: "<< fCountEventDetected << endl;
1321 
1322  // for (int i=0; i<no_hits; i++) {
1323  // cout << hit_channel[i] << ", ";
1324  // cout << hit_charge[i] << ", ";
1325  // cout << hit_peakT[i] << ", ";
1326  // cout << endl;
1327  // }
1328 
1329 }
1330 
1332 
1333 } // namespace RawDataReader
1334 
1335 #endif // CTree35t_Module
float fOpDetPositions_Y[MAX_OPDET]
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:67
const TGeoNode * Node() const
Returns the ROOT object describing the detector geometry.
Definition: OpDetGeo.h:142
void processHits(const art::Event &evt)
std::string fInputModule
float fOpDetHalfWidths[MAX_OPDET]
Store parameters for running LArG4.
void processCalib(const art::Event &evt)
int fMC_pdg[MAX_TRACKS]
std::string fOutFileName
std::string fHitsModuleLabel
void analyze(const art::Event &evt)
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
Encapsulate the construction of a single cyostat.
Channel_t ChannelNumber() const
Definition: OpDetWaveform.h:69
#define MAX_TRACKS
float fTPC_x[MAX_TPC]
TimeStamp_t TimeStamp() const
Definition: OpDetWaveform.h:70
TObjArray * fReco_trackPosition
void processMC(const art::Event &evt)
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
geo::WireID WireID() const
Definition: Hit.h:233
Declaration of signal hit object.
std::vector< std::vector< int > > timestamp
Point_t const & LocationAtPoint(size_t i) const
Definition: Track.h:126
float hit_wireID[MAX_HITS]
The data type to uniquely identify a Plane.
Definition: geo_types.h:468
int fMC_id[MAX_TRACKS]
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:102
std::string fTrackModuleLabel
int hit_channel[MAX_HITS]
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:208
STL namespace.
Definition of basic raw digits.
int chit_plane[MAX_HITS]
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:47
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
TObjArray * averageWaveforms
int chit_cryostat[MAX_HITS]
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:576
int fRaw_time[MAX_CHANNEL]
int thit_wireID[MAX_HITS]
Int_t fCountOpDetDetected[MAX_OPDET]
int thit_tpc[MAX_HITS]
float fTPC_z[MAX_TPC]
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
Particle class.
float hit_peakT[MAX_HITS]
float fMC_endMomentum[MAX_TRACKS][4]
std::vector< std::vector< int > > fRaw_wfADC
TTree * fThePhotonTreeDetected
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
float fOpDetHalfHeights[MAX_OPDET]
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
int fPlane_wires[MAX_PLANE]
void processRaw(const art::Event &evt)
Definition: Run.h:21
float fOpDetPositions_Z[MAX_OPDET]
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
#define MAX_OPDET
std::string fClusterModuleLabel
#define MAX_CHANNEL
float fTPC_y[MAX_TPC]
bool isValid() const
Definition: Handle.h:183
#define MAX_PLANE
TTree * fThePhotonTreeAll
float thit_peakT[MAX_HITS]
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:184
std::string fCalibLabel
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
QTextStream & reset(QTextStream &s)
std::string fOpHitModule
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
void reconfigure(fhicl::ParameterSet const &pset)
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
void beginJob()
Definition: Breakpoints.cc:14
const OpDetGeo & OpDet(unsigned int iopdet) const
Return the iopdet&#39;th optical detector in the cryostat.
#define MAX_TPC
Collect all the RawData header files together.
T get(std::string const &key) const
Definition: ParameterSet.h:231
float fMC_startMomentum[MAX_TRACKS][4]
int chit_channel[MAX_HITS]
std::string fRCEFragType
TObjArray * fMC_trackMomentum
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:74
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
string tmp
Definition: languages.py:63
int fCalib_channelId[MAX_CHANNEL]
static const double fm
Definition: Units.h:83
Int_t fCountOpDetAll[MAX_OPDET]
int chit_charge[MAX_HITS]
void processRecoTracks(const art::Event &event)
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:489
Declaration of cluster object.
int fPlane_view[MAX_PLANE]
Definition of data types for geometry description.
art::ServiceHandle< geo::Geometry > fGeom
Provides recob::Track data product.
unsigned int NOpDets() const
Number of OpDets in the whole detector.
Detector simulation of raw signals on wires.
#define MAX_HITS
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
Encapsulate the geometry of an optical detector.
p
Definition: test.py:223
std::map< int, int > waveformCount
float hit_charge[MAX_HITS]
float thit_charge[MAX_HITS]
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
std::vector< std::vector< int > > OpChannelToOpDet
double fPlane_wireangle[MAX_PLANE]
std::vector< std::vector< int > > fCalib_wfADC
std::string fOpDetInputModule
std::vector< std::vector< int > > fRaw_wfTDC
std::string fRCERawDataLabel
Encapsulate the construction of a single detector plane.
float hit_tpc[MAX_HITS]
void processOpDet(const art::Event &event)
int chit_cluster[MAX_HITS]
TObjArray * fMC_trackPosition
double fPlane_wirepitch[MAX_PLANE]
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::vector< std::vector< int > > fMC_daughters
int chit_wire[MAX_HITS]
object containing MC truth information necessary for making RawDigits and doing back tracking ...
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
int chit_tpc[MAX_HITS]
std::string fSSPRawDataLabel
float fMC_endXYZT[MAX_TRACKS][4]
Declaration of basic channel signal object.
std::string fSSPFragType
float hit_plane[MAX_HITS]
float chit_peakT[MAX_HITS]
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:291
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:402
void beginRun(const art::Run &run)
std::string fInstanceName
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:755
int fRaw_channelId[MAX_CHANNEL]
void processTiming(const art::Event &event)
std::string fRawDigitLabel
int fRaw_charge[MAX_CHANNEL]
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
void saveWireGeometry(int plane, int tpc)
std::vector< std::vector< int > > fCalib_wfTDC
int thit_channel[MAX_HITS]
double WireAngleToVertical(geo::View_t view, geo::TPCID const &tpcid) const
Returns the angle of the wires in the specified view from vertical.
int thit_plane[MAX_HITS]
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int fPlane_type[MAX_PLANE]
QTextStream & endl(QTextStream &s)
unsigned int NAuxDets() const
Returns the number of auxiliary detectors.
int fMC_mother[MAX_TRACKS]
Event finding and building.
float fMC_startXYZT[MAX_TRACKS][4]
unsigned int run