All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HitDumper_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: Hitdumper
3 // Module Type: analyzer
4 // File: Hitdumper_module.cc
5 //
6 ////////////////////////////////////////////////////////////////////////
7 #ifndef Hitdumper_Module
8 #define Hitdumper_Module
9 
10 // Framework includes
11 #include "art/Framework/Core/EDAnalyzer.h"
12 #include "art/Framework/Core/ModuleMacros.h"
13 #include "art/Framework/Principal/Event.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "fhiclcpp/ParameterSet.h"
17 #include "art/Framework/Principal/Handle.h"
18 #include "canvas/Persistency/Common/Ptr.h"
19 #include "canvas/Persistency/Common/PtrVector.h"
20 #include "art/Framework/Services/Registry/ServiceHandle.h"
21 #include "art_root_io/TFileService.h"
22 #include "messagefacility/MessageLogger/MessageLogger.h"
23 #include "canvas/Persistency/Common/FindMany.h"
24 
25 // LArSoft includes
27 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
40 #include "lardataobj/RawData/raw.h"
42 
43 // SBN/SBND includes
54 
55 // Truth includes
56 //#include "larsim/MCCheater/BackTrackerService.h"
57 //#include "larsim/MCCheater/ParticleInventoryService.h"
58 #include "nusimdata/SimulationBase/GTruth.h"
59 #include "nusimdata/SimulationBase/MCTruth.h"
60 #include "nusimdata/SimulationBase/MCFlux.h"
63 
64 // ROOT includes
65 #include "TTree.h"
66 #include "TTimeStamp.h"
67 #include "TH1.h"
68 #include "TH2.h"
69 #include "TLorentzVector.h"
70 #include "TVector3.h"
71 #include "TGeoManager.h"
72 
73 // C++ Includes
74 #include <map>
75 #include <vector>
76 #include <algorithm>
77 #include <iostream>
78 #include <string>
79 #include <cmath>
80 
81 const int MAX_INT = std::numeric_limits<int>::max();
82 const long int TIME_CORRECTION = (long int) std::numeric_limits<int>::max() * 2;
83 const int DEFAULT_VALUE = -9999;
84 
86  kCRTNotDefined = -1, ///< Not defined
87  kCRTHorizontal = 0, ///< Horizontal Tagger
88  kCRTVertical = 1, ///< VertivalTagger
89 };
90 
92  kPDNotDefined = -1, ///< Not defined
93  kPMTCoated = 0, ///< Coated PMT
94  kPMTUnCoated = 1, ///< Uncoated PMT
95  kXArapucaVis, ///< Arapuca Vis
96  kXArapucaVuv, ///< Arapuca VUV
97 };
98 
99 class Hitdumper : public art::EDAnalyzer {
100 public:
101  explicit Hitdumper(fhicl::ParameterSet const & p);
102  virtual ~Hitdumper();
103 
104  // This method is called once, at the start of the job. In this
105  // example, it will define the histograms and n-tuples we'll write.
106  void beginJob() override;
107 
108  // This method is called once, at the start of each run. It's a
109  // good place to read databases or files that may have
110  // run-dependent information.
111  // void beginRun(const art::Run& run);
112 
113  // This method reads in any parameters from the .fcl files. This
114  // method is called 'reconfigure' because it might be called in the
115  // middle of a job; e.g., if the user changes parameter values in an
116  // interactive event display.
117  void reconfigure(fhicl::ParameterSet const& pset);
118 
119  // The analysis routine, called once per event.
120  void analyze (const art::Event& evt) override;
121 
122  // Called at the beginning of every subrun
123  virtual void beginSubRun(art::SubRun const& sr) override;
124 private:
125 
126  /// Resets the variables that are saved to the TTree
127  void ResetVars();
128  /// Resets wire hits tree variables
129  void ResetWireHitsVars(int n);
130  /// Resets crt strips tree variables
131  void ResetCRTStripsVars(int n);
132  /// Resets custom crt tracks tree variables
133  void ResetCRTCustomTracksVars(int n);
134  /// Resets crt tracks tree variables
135  void ResetCRTTracksVars(int n);
136  /// Resets crt hits tree variables
137  void ResetCRTHitsVars(int n);
138  /// Resets optical hits tree variables
139  void ResetOpHitsVars(int n);
140  /// Resets pmt hardware trigger variables
141  void ResetPmtTriggerVars(int n);
142  /// Rests pmt software trigger variables
144  /// Resets crt software trigger variables
146  /// Resets crossing muon tracks tree variables
147  void ResetMuonTracksVars(int n);
148  /// Resets crossing muon hit tree variables
149  void ResetMuonHitVars(int n);
150  /// Resize the data structure for MCNeutrino particles
151  void ResizeMCNeutrino(int nNeutrinos);
152  /// Resize the data structure for Genie primaries
153  void ResizeGenie(int nPrimaries);
154 
156 
157  TTree* fTree;
158  //run information
159  int _run; ///< The run number
160  int _subrun; ///< The subrun number
161  int _event; ///< The event number
162  double _evttime; ///< The event time
163  int _t0; ///< The t0
164 
165  // Wire hits variables
166  int _nhits; ///< Number of reco hits in the event
167  std::vector<int> _hit_cryostat; ///< Cryostat where the hit belongs to
168  std::vector<int> _hit_tpc; ///< TPC where the hit belongs to
169  std::vector<int> _hit_plane; ///< Plane where the hit belongs to
170  std::vector<int> _hit_wire; ///< Wire where the hit belongs to
171  std::vector<int> _hit_channel; ///< Channel where the hit belongs to
172  std::vector<double> _hit_peakT; ///< Hit peak time
173  std::vector<double> _hit_charge; ///< Hit charge
174  std::vector<double> _hit_ph; ///< Hit ph?
175  std::vector<double> _hit_width; ///< Hit width
176  std::vector<double> _hit_full_integral; ///< Hit charge integral
177  std::vector<int> _waveform_number; ///< Number for each waveform, to allow for searching
178  std::vector<double> _adc_on_wire; ///< ADC on wire to draw waveform
179  std::vector<int> _time_for_waveform; ///<Time for waveform to plot
180  int _adc_count; ///<Used for plotting waveforms
181  std::vector<int> _waveform_integral; ///<Used to see progression of the waveform integral
182  std::vector<int> _adc_count_in_waveform; ///<Used to view all waveforms on a hitplane together
183 
184 
185  // CRT strip variables
186  int _nstrips; ///< Number of CRT strips
187  std::vector<int> _crt_plane; ///< CRT plane
188  std::vector<int> _crt_module; ///< CRT module
189  std::vector<int> _crt_strip; ///< CRT strip
190  std::vector<int> _crt_orient; ///< CRT orientation (0 for y (horizontal) and 1 for x (vertical))
191  std::vector<double> _crt_time; ///< CRT time
192  std::vector<double> _crt_adc; ///< CRT adc
193  std::vector<double> _crt_pos_x; ///< CRT position X
194  std::vector<double> _crt_pos_y; ///< CRT position Y
195  std::vector<double> _crt_pos_z; ///< CRT position Z
196 
197  // CRT track variables
198  int _nctrks; ///< Number of created CRT tracks
199  std::vector<double> _ctrk_x1; ///< CRT track x1
200  std::vector<double> _ctrk_y1; ///< CRT track y1
201  std::vector<double> _ctrk_z1; ///< CRT track z1
202  std::vector<double> _ctrk_t1; ///< CRT track t1
203  std::vector<double> _ctrk_adc1; ///< CRT track adc1
204  std::vector<int> _ctrk_mod1x; ///< CRT track mod2x
205  std::vector<double> _ctrk_x2; ///< CRT track x2
206  std::vector<double> _ctrk_y2; ///< CRT track y2
207  std::vector<double> _ctrk_z2; ///< CRT track z2
208  std::vector<double> _ctrk_t2; ///< CRT track t2
209  std::vector<double> _ctrk_adc2; ///< CRT track adc2
210  std::vector<int> _ctrk_mod2x; ///< CRT track mod2x
211 
212  // CRT hits variables
213  int _nchits; ///< Number of CRT hits
214  std::vector<double> _chit_x; ///< CRT hit x
215  std::vector<double> _chit_y; ///< CRT hit y
216  std::vector<double> _chit_z; ///< CRT hit z
217  std::vector<double> _chit_time; ///< CRT hit time
218  // std::vector<double> _chit_adc; ///< CRT hit adc
219  std::vector<int> _chit_plane; ///< CRT hit plane
220 
221  // CRT track variables
222  int _ncts; ///< Number of CRT tracks
223  std::vector<double> _ct_time; ///< CRT track time
224  std::vector<double> _ct_pes; ///< CRT track PEs
225  std::vector<double> _ct_x1; ///< CRT track x1
226  std::vector<double> _ct_y1; ///< CRT track y1
227  std::vector<double> _ct_z1; ///< CRT track z1
228  std::vector<double> _ct_x2; ///< CRT track x2
229  std::vector<double> _ct_y2; ///< CRT track y2
230  std::vector<double> _ct_z2; ///< CRT track z2
231 
232  int _nophits; ///< Number of Optical Hits
233  std::vector<int> _ophit_opch; ///< OpChannel of the optical hit
234  std::vector<int> _ophit_opdet; ///< OpDet of the optical hit
235  std::vector<double> _ophit_peakT; ///< Peak time of the optical hit
236  std::vector<double> _ophit_width; ///< Width of the optical hit
237  std::vector<double> _ophit_area; ///< Area of the optical hit
238  std::vector<double> _ophit_amplitude; ///< Amplitude of the optical hit
239  std::vector<double> _ophit_pe; ///< PEs of the optical hit
240  std::vector<double> _ophit_opdet_x; ///< OpDet X coordinate of the optical hit
241  std::vector<double> _ophit_opdet_y; ///< OpDet Y coordinate of the optical hit
242  std::vector<double> _ophit_opdet_z; ///< OpDet Z coordinate of the optical hit
243  std::vector<int> _ophit_opdet_type; ///< OpDet tyoe of the optical hit
244 
245  //pmt hardware trigger variables
246  std::vector<int> _pmtTrigger_npmtshigh; ///< number of pmt pairs above threshold, index = time during trigger window (usually beam spill)
247  int _pmtTrigger_maxpassed; ///< maximum number of pmt pairs above threshold during trigger window (usually beam spill)
248 
249  // PMT software trigger variables
250  bool _pmtSoftTrigger_foundBeamTrigger; /// Whether the beam spill was found or not
251  int _pmtSoftTrigger_tts; /// Trigger Time Stamp (TTS), ns (relative to start of beam spill)
252  double _pmtSoftTrigger_promptPE; /// Total photoelectron count 100 ns after the TTS
253  double _pmtSoftTrigger_prelimPE; /// Total photoelectron count before the TTS, during the beam spill
254  int _pmtSoftTrigger_nAboveThreshold; /// number of individual PMTs above ADC threshold (fcl) during the beam spill
255  // std::vector<sbnd::trigger::pmtInfo> _pmtSoftTrigger_pmtInfoVec; /// vector of PMT information
256 
257  // CRT software trigger variables
258  int _crtSoftTrigger_hitsperplane[7]; ///< Number of (very low level) CRT hits per plane
259 
260  // Muon track variables
261  int _nmuontrks; ///< number of muon tracks
262  std::vector<double> _muontrk_t0; ///< t0 (time of interaction)
263  std::vector<float> _muontrk_x1; ///< x coordinate closer to anode
264  std::vector<float> _muontrk_y1; ///< y coordinate closer to anode
265  std::vector<float> _muontrk_z1; ///< z coordinate closer to anode
266  std::vector<float> _muontrk_x2; ///< x coordinate closer to cathode
267  std::vector<float> _muontrk_y2; ///< y coordinate closer to cathode
268  std::vector<float> _muontrk_z2; ///< z coordinate closer to cathode
269  std::vector<float> _muontrk_theta_xz; ///< theta_xz trajectory angle
270  std::vector<float> _muontrk_theta_yz; ///< theta_yz trajectory angle
271  std::vector<int> _muontrk_tpc; ///< tpc that muon is located in
272  std::vector<int> _muontrk_type; ///< type of muon track
273 
274  // Muon Hit variables
275  int _nmhits; ///< Number of muon collection hits per track
276  std::vector<int> _mhit_trk; ///< Track number that the hit belongs to
277  std::vector<int> _mhit_tpc; ///< TPC where the hit belongs to
278  std::vector<int> _mhit_wire; ///< Wire where the hit belongs to
279  std::vector<int> _mhit_channel; ///< Channel where the hit belongs to
280  std::vector<double> _mhit_peakT; ///< Hit peak time
281  std::vector<double> _mhit_charge; ///< Hit charge
282 
283  //mctruth information
284  size_t MaxMCNeutrinos; ///! The number of MCNeutrinos there is currently room for
285  Int_t mcevts_truth; ///< number of neutrino Int_teractions in the spill
286  std::vector<Int_t> nuScatterCode_truth; ///< Scattering code given by Genie for each neutrino
287  std::vector<Int_t> nuID_truth; ///< Unique ID of each true neutrino
288  std::vector<Int_t> nuPDG_truth; ///< neutrino PDG code
289  std::vector<Int_t> ccnc_truth; ///< 0=CC 1=NC
290  std::vector<Int_t> mode_truth; ///< 0=QE/El, 1=RES, 2=DIS, 3=Coherent production
291  std::vector<Float_t> enu_truth; ///< true neutrino energy
292  std::vector<Float_t> Q2_truth; ///< Momentum transfer squared
293  std::vector<Float_t> W_truth; ///< hadronic invariant mass
294  std::vector<Int_t> hitnuc_truth; ///< hit nucleon
295  std::vector<Float_t> nuvtxx_truth; ///< neutrino vertex x
296  std::vector<Float_t> nuvtxy_truth; ///< neutrino vertex y
297  std::vector<Float_t> nuvtxz_truth; ///< neutrino vertex z
298  std::vector<Float_t> nu_dcosx_truth; ///< neutrino dcos x
299  std::vector<Float_t> nu_dcosy_truth; ///< neutrino dcos y
300  std::vector<Float_t> nu_dcosz_truth; ///< neutrino dcos z
301  std::vector<Float_t> lep_mom_truth; ///< lepton momentum
302  std::vector<Float_t> lep_dcosx_truth; ///< lepton dcos x
303  std::vector<Float_t> lep_dcosy_truth; ///< lepton dcos y
304  std::vector<Float_t> lep_dcosz_truth; ///< lepton dcos z
305 
306  //flux information
307  std::vector<Float_t> tpx_flux; ///< Px of parent particle leaving BNB target
308  std::vector<Float_t> tpy_flux; ///< Py of parent particle leaving BNB target
309  std::vector<Float_t> tpz_flux; ///< Pz of parent particle leaving BNB target
310  std::vector<Int_t> tptype_flux; ///< Type of parent particle leaving BNB target
311 
312  //genie information
313  size_t MaxGeniePrimaries = 0;
315  std::vector<Int_t> genie_primaries_pdg;
316  std::vector<Float_t> genie_Eng;
317  std::vector<Float_t> genie_Px;
318  std::vector<Float_t> genie_Py;
319  std::vector<Float_t> genie_Pz;
320  std::vector<Float_t> genie_P;
321  std::vector<Int_t> genie_status_code;
322  std::vector<Float_t> genie_mass;
323  std::vector<Int_t> genie_trackID;
324  std::vector<Int_t> genie_ND;
325  std::vector<Int_t> genie_mother;
326 
327 
328  TTree* _sr_tree; ///< A tree filled per subrun (for POT accounting)
331  double _sr_pot; ///< POTs in each subrun
332 
333 
334  int _max_hits; ///< maximum number of hits (to be set via fcl)
335  int _max_ophits; ///< maximum number of hits (to be set via fcl)
336  int _max_samples; ///< maximum number of samples (to be set via fcl)
337  int _max_chits; ///< maximum number of CRT hits (to be set via fcl)
338  int _max_nctrks; ///< maximum number of CRT tracks (to be set via fcl)
339 
340  std::string fHitsModuleLabel; ///< Label for Hit dataproduct (to be set via fcl)
341  std::string fLArG4ModuleLabel; ///< Label for LArG4 dataproduct (to be set via fcl)
342  std::string fCRTStripModuleLabel; ///< Label for CRTStrip dataproduct (to be set via fcl)
343  std::string fCRTHitModuleLabel; ///< Label for CRTHit dataproduct (to be set via fcl)
344  std::string fCRTTrackModuleLabel; ///< Label for CRTTrack dataproduct (to be set via fcl)
345  std::string fpmtTriggerModuleLabel; ///< Label for pmtTrigger dataproduct (to be set vis fcl)
346  std::string fpmtSoftTriggerModuleLabel; ///< Label for pmt software trigger data product (to be set via fcl)
347  std::string fcrtSoftTriggerModuleLabel; ///< Label for crt software trigger data product (to be set via fcl)
348  std::string fMuonTrackModuleLabel; ///< Label for MuonTrack dataproduct (to be set via fcl)
349  std::string fDigitModuleLabel; ///< Label for digitizer (to be set via fcl)
350  std::string fGenieGenModuleLabel; ///< Label for Genie dataproduct (to be set via fcl)
351  std::vector<std::string> fOpHitsModuleLabels; ///< Labels for OpHit dataproducts (to be set via fcl)
352 
353  // double fSelectedPDG;
354 
355  bool fkeepCRThits; ///< Keep the CRT hits (to be set via fcl)
356  bool fkeepCRTstrips; ///< Keep the CRT strips (to be set via fcl)
357  bool fmakeCRTtracks; ///< Make the CRT tracks (to be set via fcl)
358  bool freadCRTtracks; ///< Keep the CRT tracks (to be set via fcl)
359  bool freadOpHits; ///< Add OpHits to output (to be set via fcl)
360  bool freadMuonTracks; ///< Add MuonTracks to output (to be set via fcl)
361  bool freadMuonHits; ///< Add MuonTrack hits to output(to be set via fcl)
362  bool freadTruth; ///< Add Truth info to output (to be set via fcl)
363  bool freadpmtTrigger; ///< Add pmt hardware trigger info to output (to be set via fcl)
364  bool freadpmtSoftTrigger;///< Add pmt software trigger info to output (to be set via fcl)
365  bool freadcrtSoftTrigger;///< Add crt software trigger info to output (to be set via fcl)
366  bool fsavePOTInfo; ///< Add POT info to output (to be set via fcl)
367  bool fcheckTransparency; ///< Checks for wire transprency (to be set via fcl)
368  bool fUncompressWithPed; ///< Uncompresses the waveforms if true (to be set via fcl)
369  int fWindow;
370  bool fSkipInd; ///< If true, induction planes are not saved (to be set via fcl)
371  // double fSelectedPDG;
372 
373  std::vector<int> fKeepTaggerTypes = {0, 1, 2, 3, 4, 5, 6}; ///< Taggers to keep (to be set via fcl)
374 
376 
378  // detinfo::ElecClock fTrigClock;
379  art::ServiceHandle<geo::AuxDetGeometry> fAuxDetGeoService;
382 };
383 
384 
385 Hitdumper::Hitdumper(fhicl::ParameterSet const& pset)
386 : EDAnalyzer(pset)
387 {
388 
389  fGeometryService = lar::providerFrom<geo::Geometry>();
390  // fDetectorClocks = lar::providerFrom<detinfo::DetectorClocksService>();
391  // fDetectorProperties = lar::providerFrom<detinfo::DetectorPropertiesService>();
392  // fTrigClock = fDetectorClocks->TriggerClock();
393  fAuxDetGeo = &(*fAuxDetGeoService);
394  fAuxDetGeoCore = fAuxDetGeo->GetProviderPtr();
395 
396  // Read in the parameters from the .fcl file.
397  this->reconfigure(pset);
398 }
399 
400 void Hitdumper::reconfigure(fhicl::ParameterSet const& p)
401 {
402 
403  _max_hits = p.get<int>("MaxHits", 50000);
404  _max_ophits = p.get<int>("MaxOpHits", 50000);
405  _max_samples = p.get<int>("MaxSamples", 5001);
406  _max_chits = p.get<int>("MaxCRTHits", 5000);
407  _max_nctrks = p.get<int>("MaxCRTTracks", 10);
408 
409  fHitsModuleLabel = p.get<std::string>("HitsModuleLabel");
410  fDigitModuleLabel = p.get<std::string>("DigitModuleLabel", "daq");
411  fLArG4ModuleLabel = p.get<std::string>("LArG4ModuleLabel", "largeant");
412  fCRTStripModuleLabel = p.get<std::string>("CRTStripModuleLabel", "crt");
413  fCRTHitModuleLabel = p.get<std::string>("CRTHitModuleLabel", "crthit");
414  fCRTTrackModuleLabel = p.get<std::string>("CRTTrackModuleLabel", "crttrack");
415  fOpHitsModuleLabels = p.get<std::vector<std::string>>("OpHitsModuleLabel");
416  fpmtTriggerModuleLabel = p.get<std::string>("pmtTriggerModuleLabel", "pmttriggerproducer");
417  fpmtSoftTriggerModuleLabel = p.get<std::string>("pmtSoftTriggerModuleLabel", "pmtSoftwareTrigger");
418  fcrtSoftTriggerModuleLabel = p.get<std::string>("crtSoftTriggerModuleLabel", "MetricProducer");
419  fMuonTrackModuleLabel = p.get<std::string>("MuonTrackModuleLabel", "MuonTrackProducer");
420  fGenieGenModuleLabel = p.get<std::string>("GenieGenModuleLabel", "generator");
421 
422  fkeepCRThits = p.get<bool>("keepCRThits",true);
423  fkeepCRTstrips = p.get<bool>("keepCRTstrips",false);
424  fmakeCRTtracks = p.get<bool>("makeCRTtracks",true);
425  freadCRTtracks = p.get<bool>("readCRTtracks",true);
426  freadOpHits = p.get<bool>("readOpHits",true);
427  freadpmtTrigger = p.get<bool>("readpmtTrigger",true);
428  freadpmtSoftTrigger= p.get<bool>("readpmtSoftTrigger",true);
429  freadcrtSoftTrigger= p.get<bool>("readcrtSoftTrigger",false);
430  freadMuonTracks = p.get<bool>("readMuonTracks",true);
431  freadMuonHits = p.get<bool>("readMuonHits",false);
432  fcheckTransparency = p.get<bool>("checkTransparency",false);
433  freadTruth = p.get<bool>("readTruth",true);
434  fsavePOTInfo = p.get<bool>("savePOTinfo",true);
435  fUncompressWithPed = p.get<bool>("UncompressWithPed",false);
436 
437  fWindow = p.get<int>("window",100);
438  fKeepTaggerTypes = p.get<std::vector<int>>("KeepTaggerTypes");
439 
440  fSkipInd = p.get<bool>("SkipInduction",false);
441 }
442 
443 
445 {
446  // Clean up dynamic memory and other resources here.
447 }
448 
449 
450 void Hitdumper::analyze(const art::Event& evt)
451 {
452  // Reset the TTree variables
453  ResetVars();
454 
455  _run = evt.run();
456  _subrun = evt.subRun();
457  _event = evt.id().event();
458 
459  _t0 = 0.;
460  // t0 = detprop->TriggerOffset(); // units of TPC ticks
461 
462  //
463  // Hits
464  //
465  art::Handle<std::vector<recob::Hit>> hitListHandle;
466  std::vector<art::Ptr<recob::Hit>> hitlist;
467  if (evt.getByLabel(fHitsModuleLabel,hitListHandle)) {
468  art::fill_ptr_vector(hitlist, hitListHandle);
469  _nhits = hitlist.size();
470 
471  // Calculate how many hits we will save if skipping the induction planes
472  if (fSkipInd) {
473  _nhits = 0;
474  for (auto h : hitlist) {
475  if (h->WireID().Plane == 2) {
476  _nhits++;
477  }
478  }
479  }
480  }
481  else {
482  std::cout << "Failed to get recob::Hit data product." << std::endl;
483  _nhits = 0;
484  }
485 
486  if (_nhits > _max_hits) {
487  std::cout << "Available hits are " << _nhits
488  << ", which is above the maximum number allowed to store." << std::endl;
489  std::cout << "Will only store " << _max_hits << "hits." << std::endl;
490  _nhits = _max_hits;
491  }
492 
494 
495  size_t counter = 0;
496  for (size_t i = 0; i < hitlist.size(); ++i) {
497  geo::WireID wireid = hitlist[i]->WireID();
498  if (fSkipInd && wireid.Plane != 2) {
499  continue;
500  }
501 
502  _hit_cryostat[counter] = wireid.Cryostat;
503  _hit_tpc[counter] = wireid.TPC;
504  _hit_plane[counter] = wireid.Plane;
505  _hit_wire[counter] = wireid.Wire;
506  _hit_channel[counter] = hitlist[i]->Channel();
507  // peak time needs plane dependent offset correction applied.
508  _hit_peakT[counter] = hitlist[i]->PeakTime();
509  _hit_charge[counter] = hitlist[i]->Integral();
510  _hit_ph[counter] = hitlist[i]->PeakAmplitude();
511  _hit_width[counter] = hitlist[i]->RMS();
512  counter ++;
513  }
514 
515  //
516  // CRT strips
517  //
518  int _nstr = 0;
519  art::Handle<std::vector<sbnd::crt::CRTData> > crtStripListHandle;
520  std::vector<art::Ptr<sbnd::crt::CRTData> > striplist;
521  // art::Handle< std::vector<sbnd::crt::CRTData> > crtStripListHandle;
522  // std::vector< art::Ptr<sbnd::crt::CRTData> > striplist;
523  if (evt.getByLabel(fCRTStripModuleLabel, crtStripListHandle)) {
524  art::fill_ptr_vector(striplist, crtStripListHandle);
525  _nstr = striplist.size();
526  } else {
527  std::cout << "Failed to get sbnd::crt::CRTData data product." << std::endl;
528  }
529 
530  int ns = 0;
531  if (_nstr > _max_chits) _nstr = _max_chits;
532  // strips are always in pairs, one entry for each sipm (2 sipms per strip)
533 
534  ResetCRTStripsVars(_nstr);
535 
536  for (int i = 0; i < _nstr; i += 2){
537  uint32_t chan = striplist[i]->Channel();
538 
539  // std::pair<std::string,unsigned> tagger = CRTHitRecoAlg::ChannelToTagger(chan);
540  std::pair<std::string,unsigned> tagger = hitAlg.ChannelToTagger(chan);
542 
543  bool keep_tagger = false;
544  for (auto t : fKeepTaggerTypes) {
545  if (ip == t) {
546  keep_tagger = true;
547  }
548  }
549  // std::cout << "Tagger name " << tagger.first << ", ip " << ip << ", kept? " << (keep_tagger ? "yes" : "no") << std::endl;
550 
551  if (ip != sbnd::kCRTNotDefined && keep_tagger) {
552 
553  uint32_t ttime = striplist[i]->T0();
554  float ctime = (int)ttime * 0.001; // convert form ns to us
555  // recover simulation bug where neg times are sotred as unsigned integers
556  // if (ttime > MAX_INT) ctime = 0.001 * (ttime - MAX_INT * 2);
557  if (ctime < 1600. && ctime > -1400.) {
558  uint32_t adc1 = striplist[i]->ADC();
559  uint32_t adc2 = striplist[i+1]->ADC();
560  if (adc1 > 4095) adc1 = 4095;
561  if (adc2 > 4095) adc2 = 4095;
562  // std::cout << tagger.first << " " << tagger.second << std::endl;
563  // int sipm = chan & 1; // 0 or 1
564  int strip = (chan >> 1) & 15;
565  int module = (chan>> 5);
566  //
567  std::string name = fGeometryService->AuxDet(module).TotalVolume()->GetName();
568  TVector3 center = fAuxDetGeoCore->AuxDetChannelToPosition(2*strip, name);
569  _crt_plane.push_back(ip);
570  _crt_module.push_back(module);
571  _crt_strip.push_back(strip);
572  _crt_orient.push_back(tagger.second);
573  _crt_time.push_back(ctime);
574  _crt_adc.push_back(adc1 + adc2 - 127.2); // -127.2/131.9 correct for gain and 2*ped to get pe
575  _crt_pos_x.push_back(center.X());
576  _crt_pos_y.push_back(center.Y());
577  _crt_pos_z.push_back(center.Z());
578  ns++;
579  }
580  }
581  }
582  _nstrips = ns;
583 
584 
585 
586  //
587  // CRT Custom Tracks
588  //
590  _nctrks = 0;
591  if (fmakeCRTtracks) {
592  int ntr = 0;
593  int iflag[1000] = {0};
594  for (int i = 0; i < (ns - 1); ++i) {
595  if (iflag[i] == 0) {
596  iflag[i] = 1;
597  float plane1x = 0, plane2x = 0;
598  float plane1y = 0, plane2y = 0;
599  float plane1tx = 0, plane2tx = 0;
600  float plane1ty = 0, plane2ty = 0;
601  float plane1xm = -1, plane2xm = -1;
602  float plane1ym = -1, plane2ym = -1;
603  int nh1x = 0, nh2x = 0;
604  int nh1y = 0, nh2y = 0;
605  float adc1x = 0, adc2x = 0;
606  float adc1y = 0, adc2y = 0;
607  if (_crt_plane[i] == sbnd::kCRTFaceSouth) { // 1
608  if (_crt_orient[i] == kCRTVertical && _crt_adc[i] > 500) { // < 500 hardcoded
609  if (nh1x == 0 || (_crt_module[i] == plane1xm)) {
610  nh1x++;
611  if (_crt_adc[i] > adc1x) {
612  plane1tx = _crt_time[i];
613  adc1x += _crt_adc[i];
614  plane1x = _crt_pos_x[i];
615  plane1xm = _crt_module[i];
616  }
617  }
618  }
619  else if (_crt_orient[i]==kCRTHorizontal && _crt_adc[i]>500) { // < 500 hardcoded
620  if (nh1y==0 || (_crt_module[i]==plane1ym)) {
621  nh1y++;
622  if (_crt_adc[i]>adc1y) {
623  plane1ty=_crt_time[i];
624  adc1y+=_crt_adc[i];
625  plane1y=_crt_pos_y[i];
626  plane1ym=_crt_module[i];
627  }
628  }
629  }
630  }
631  else {
632  if (_crt_orient[i]==kCRTVertical && _crt_adc[i]>500) { // < 500 hardcoded
633  if (nh2x==0 || (_crt_module[i]==plane2xm)) {
634  nh2x++;
635  if (_crt_adc[i]>adc2x) {
636  plane2tx=_crt_time[i];
637  adc2x+=_crt_adc[i];
638  plane2x=_crt_pos_x[i];
639  plane2xm=_crt_module[i];
640  }
641  }
642  }
643  else if (_crt_orient[i]==kCRTHorizontal && _crt_adc[i]>500) { // < 500 hardcoded
644  if (nh2y==0 || (_crt_module[i]==plane2ym)) {
645  nh2y++;
646  if (_crt_adc[i]>adc2y) {
647  plane2ty=_crt_time[i];
648  adc2y+=_crt_adc[i];
649  plane2y=_crt_pos_y[i];
650  plane2ym=_crt_module[i];
651  }
652  }
653  }
654  }
655  for (int j=i+1;j<ns;++j) {
656  float tdiff = fabs(_crt_time[i]-_crt_time[j]);
657  if (tdiff<0.1) {
658  iflag[j]=1;
660  if (_crt_orient[j]==kCRTVertical && _crt_adc[j]>1000) {
661  if (nh1x==0 || (_crt_module[j]==plane1xm)) {
662  nh1x++;
663  if (_crt_adc[j]>adc1x) {
664  plane1tx=_crt_time[j];
665  adc1x+=_crt_adc[j];
666  plane1x=_crt_pos_x[j];
667  plane1xm=_crt_module[j];
668  }
669  }
670  }
671  else if (_crt_orient[j]==kCRTHorizontal && _crt_adc[j]>1000) {
672  if (nh1y==0 || (_crt_module[j]==plane1ym)) {
673  nh1y++;
674  if (_crt_adc[j]>adc1y) {
675  plane1ty=_crt_time[j];
676  adc1y+=_crt_adc[j];
677  plane1y=_crt_pos_y[j];
678  plane1ym=_crt_module[j];
679  }
680  }
681  }
682  }
683  else {
684  if (_crt_orient[j]==kCRTVertical && _crt_adc[j]>1000) {
685  if (nh2x==0 || (_crt_module[j]==plane2xm)) {
686  nh2x++;
687  if (_crt_adc[j]>adc2x) {
688  plane2tx=_crt_time[j];
689  adc2x+=_crt_adc[j];
690  plane2x=_crt_pos_x[j];
691  plane2xm=_crt_module[j];
692  }
693  }
694  }
695  else if (_crt_orient[j]==kCRTHorizontal && _crt_adc[j]>1000) {
696  if (nh2y==0 || (_crt_module[j]==plane2ym)) {
697  nh2y++;
698  if (_crt_adc[j]>adc2y) {
699  plane2ty=_crt_time[j];
700  adc2y+=_crt_adc[j];
701  plane2y=_crt_pos_y[j];
702  plane2ym=_crt_module[j];
703  }
704  }
705  }
706  }
707  }
708  } // look for hits at the same time as hit i
709  if (nh1x>0 && nh1y>0 && nh2x>0 && nh2y>0 && adc1x<9000 && adc1y<9000 && adc2x<9000 && adc2y<9000) {
710  // make a track!
711  _ctrk_x1.push_back(plane1x);
712  _ctrk_y1.push_back(plane1y);
713  _ctrk_z1.push_back(-239.95);
714  _ctrk_t1.push_back(0.5*(plane1tx+plane1ty));
715  _ctrk_adc1.push_back(adc1x+adc1y);
716  _ctrk_mod1x.push_back(plane1xm);
717  _ctrk_x2.push_back(plane2x);
718  _ctrk_y2.push_back(plane2y);
719  _ctrk_z2.push_back(656.25);
720  _ctrk_t2.push_back(0.5*(plane2tx+plane2ty));
721  _ctrk_adc2.push_back(adc2x+adc2y);
722  _ctrk_mod2x.push_back(plane2xm);
723  ntr++;
724  // std::cout << "track " << ntr << std::endl;
725  // std::cout << "x y t adc: plane 1 " << plane1x << " " << plane1y << " " <<
726  // 0.5*(plane1tx+plane1ty) << " " << adc1x << " " << adc1y << std::endl;
727  // std::cout << " : plane 2 " << plane2x << " " << plane2y << " " <<
728  // 0.5*(plane2tx+plane2ty) << " " << adc2x << " " << adc2y << std::endl;
729  }
730  } // i is the first hit with this time
731  } // loop over hits
732  _nctrks = ntr;
733  } // end if make tracks
734 
735  //
736  // CRT hits
737  //
738  if (fkeepCRThits) {
739  art::Handle<std::vector<sbn::crt::CRTHit> > crtHitListHandle;
740  std::vector<art::Ptr<sbn::crt::CRTHit> > chitlist;
741  // art::Handle< std::vector<sbnd::crt::CRTData> > crtStripListHandle;
742  // std::vector< art::Ptr<sbnd::crt::CRTData> > striplist;
743  if (evt.getByLabel(fCRTHitModuleLabel, crtHitListHandle)) {
744  art::fill_ptr_vector(chitlist, crtHitListHandle);
745  _nchits = chitlist.size();
746  }
747  else {
748  std::cout << "Failed to get sbn::crt::CRTHit data product." << std::endl;
749  _nchits = 0;
750  }
751 
752  if (_nchits > _max_chits) {
753  std::cout << "Available CRT hits are " << _nchits
754  << ", which is above the maximum number allowed to store." << std::endl;
755  std::cout << "Will only store " << _max_chits << "CRT hits." << std::endl;
757  }
758 
760 
761  for (int i = 0; i < _nchits; ++i){
762  // int ip = kNotDefined;
764 
765  _chit_time[i]=chitlist[i]->ts1_ns*0.001;
766  if (chitlist[i]->ts1_ns > MAX_INT) {
767  _chit_time[i] = 0.001 * (chitlist[i]->ts1_ns - TIME_CORRECTION);
768  }
769 
770  _chit_x[i] = chitlist[i]->x_pos;
771  _chit_y[i] = chitlist[i]->y_pos;
772  _chit_z[i] = chitlist[i]->z_pos;
773  _chit_plane[i] = ip;
774  }
775  }
776 
777  //
778  // CRT tracks
779  //
780  _ncts = 0;
781  if (freadCRTtracks) {
782  art::Handle<std::vector<sbn::crt::CRTTrack> > crtTrackListHandle;
783  std::vector<art::Ptr<sbn::crt::CRTTrack> > ctrklist;
784  if (evt.getByLabel(fCRTTrackModuleLabel, crtTrackListHandle)) {
785  art::fill_ptr_vector(ctrklist, crtTrackListHandle);
786  _ncts = ctrklist.size();
788 
790 
791  for (int i = 0; i < _ncts; ++i){
792  _ct_pes[i] = ctrklist[i]->peshit;
793  _ct_time[i] = ctrklist[i]->ts1_ns*0.001;
794  if (ctrklist[i]->ts1_ns > MAX_INT) {
795  _ct_time[i] = 0.001 * (ctrklist[i]->ts1_ns - TIME_CORRECTION);
796  }
797  _ct_x1[i] = ctrklist[i]->x1_pos;
798  _ct_y1[i] = ctrklist[i]->y1_pos;
799  _ct_z1[i] = ctrklist[i]->z1_pos;
800  _ct_x2[i] = ctrklist[i]->x2_pos;
801  _ct_y2[i] = ctrklist[i]->y2_pos;
802  _ct_z2[i] = ctrklist[i]->z2_pos;
803  }
804  } else {
805  std::cout << "Failed to get sbn::crt::CRTTrack data product." << std::endl;
806  }
807  }
808 
809 
810  //
811  // Optical Hits
812  //
813  if (freadOpHits) {
814  _nophits = 0;
815  size_t previous_nophits = 0;
816 
817  // Loop over all the ophits labels
818  for (auto ophit_label : fOpHitsModuleLabels) {
819 
820  art::Handle<std::vector<recob::OpHit>> ophitListHandle;
821  std::vector<art::Ptr<recob::OpHit>> ophitlist;
822  if (evt.getByLabel(ophit_label, ophitListHandle)) {
823  art::fill_ptr_vector(ophitlist, ophitListHandle);
824  _nophits += ophitlist.size();
825  }
826  else {
827  std::cout << "Failed to get recob::OpHit data product." << std::endl;
828  }
829 
830  if (_nophits > _max_ophits) {
831  std::cout << "Available optical hits are " << _nophits << ", which is above the maximum number allowed to store." << std::endl;
832  std::cout << "Will only store " << _max_ophits << " optical hits." << std::endl;
834  }
835 
837 
838  for (size_t i = 0; i < ophitlist.size(); ++i) {
839  size_t index = previous_nophits + i;
840  _ophit_opch[index] = ophitlist.at(i)->OpChannel();
841  _ophit_opdet[index] = fGeometryService->OpDetFromOpChannel(ophitlist.at(i)->OpChannel());
842  _ophit_peakT[index] = ophitlist.at(i)->PeakTime();
843  _ophit_width[index] = ophitlist.at(i)->Width();
844  _ophit_area[index] = ophitlist.at(i)->Area();
845  _ophit_amplitude[index] = ophitlist.at(i)->Amplitude();
846  _ophit_pe[index] = ophitlist.at(i)->PE();
847  auto opdet_center = fGeometryService->OpDetGeoFromOpChannel(ophitlist.at(i)->OpChannel()).GetCenter();
848  _ophit_opdet_x[index] = opdet_center.X();
849  _ophit_opdet_y[index] = opdet_center.Y();
850  _ophit_opdet_z[index] = opdet_center.Z();
851  auto pd_type = _pd_map.pdType(ophitlist.at(i)->OpChannel());
852  if (pd_type == "pmt_coated") {_ophit_opdet_type[index] = kPMTCoated;}
853  else if (pd_type == "pmt_uncoated") {_ophit_opdet_type[index] = kPMTUnCoated;}
854  else if (pd_type == "xarapuca_vis") {_ophit_opdet_type[index] = kXArapucaVis;}
855  else if (pd_type == "xarapuca_vuv") {_ophit_opdet_type[index] = kXArapucaVuv;}
856  else {_ophit_opdet_type[index] = kPDNotDefined;}
857  }
858  previous_nophits = _nophits;
859  }
860  }
861 
862  //
863  // pmt hardware trigger
864  //
865 
866  if (freadpmtTrigger){
867  art::Handle<std::vector<sbnd::comm::pmtTrigger> > pmtTriggerListHandle;
868  std::vector<art::Ptr<sbnd::comm::pmtTrigger> > pmttriggerlist;
869 
870  if (evt.getByLabel(fpmtTriggerModuleLabel, pmtTriggerListHandle)){
871  art::fill_ptr_vector(pmttriggerlist, pmtTriggerListHandle);
872  ResetPmtTriggerVars( (int)pmttriggerlist[0]->numPassed.size());
873 
874  for (int i=0; i < (int)pmttriggerlist[0]->numPassed.size(); i++){
875  _pmtTrigger_npmtshigh[i] = pmttriggerlist[0]->numPassed[i];
876  }
877  _pmtTrigger_maxpassed = pmttriggerlist[0]->maxPMTs;
878 
879  }
880  else{
881  std::cout << "Failed to get sbnd::comm::pmtTrigger data product" << std::endl;
882  }
883  }
884 
885  //
886  // PMT Software Trigger
887  //
888  if (freadpmtSoftTrigger){
889  art::Handle<sbnd::trigger::pmtSoftwareTrigger> pmtSoftTriggerHandle;
890  if (evt.getByLabel(fpmtSoftTriggerModuleLabel, pmtSoftTriggerHandle)){
891  const sbnd::trigger::pmtSoftwareTrigger &pmtSoftTriggerMetrics = (*pmtSoftTriggerHandle);
893  _pmtSoftTrigger_foundBeamTrigger = pmtSoftTriggerMetrics.foundBeamTrigger;
894  _pmtSoftTrigger_tts = pmtSoftTriggerMetrics.triggerTimestamp;
895  _pmtSoftTrigger_promptPE = pmtSoftTriggerMetrics.promptPE;
896  _pmtSoftTrigger_prelimPE = pmtSoftTriggerMetrics.prelimPE;
897  _pmtSoftTrigger_nAboveThreshold = pmtSoftTriggerMetrics.nAboveThreshold;
898  // _pmtSoftTrigger_pmtInfoVec = pmtsofttriggerlist[0]->pmtInfoVec;
899  }
900  else{
901  std::cout << "Failed to get sbnd::trigger::pmtSoftwareTrigger data product" << std::endl;
902  }
903  }
904 
905  //
906  // CRT Software Trigger
907  //
908  if (freadcrtSoftTrigger){
909  art::Handle<sbndaq::CRTmetric> crtSoftTriggerHandle;
910  if (evt.getByLabel(fcrtSoftTriggerModuleLabel, crtSoftTriggerHandle)){
911  const sbndaq::CRTmetric &crtSoftTriggerMetrics = (*crtSoftTriggerHandle);
913  for (int i=0; i<7; i++){
914  _crtSoftTrigger_hitsperplane[i] = crtSoftTriggerMetrics.hitsperplane[i];
915  }
916  }
917  else{
918  std::cout << "Failed to get sbndaq::crtMetric data product" << std::endl;
919  }
920 
921  }
922 
923  //
924  // Muon tracks
925  //
926  _nmuontrks = 0;
927  if (freadMuonTracks){
928  art::Handle<std::vector<sbnd::comm::MuonTrack> > muonTrackListHandle;
929  std::vector<art::Ptr<sbnd::comm::MuonTrack> > muontrklist;
930 
931  if (evt.getByLabel(fMuonTrackModuleLabel, muonTrackListHandle)){
932  art::fill_ptr_vector(muontrklist, muonTrackListHandle);
933  _nmuontrks = muontrklist.size();
935 
936  for (int i=0; i < _nmuontrks; i++){
937  _muontrk_t0[i] = muontrklist[i]->t0_us;
938  _muontrk_x1[i] = muontrklist[i]->x1_pos;
939  _muontrk_y1[i] = muontrklist[i]->y1_pos;
940  _muontrk_z1[i] = muontrklist[i]->z1_pos;
941  _muontrk_x2[i] = muontrklist[i]->x2_pos;
942  _muontrk_y2[i] = muontrklist[i]->y2_pos;
943  _muontrk_z2[i] = muontrklist[i]->z2_pos;
944  _muontrk_theta_xz[i] = muontrklist[i]->theta_xz;
945  _muontrk_theta_yz[i] = muontrklist[i]->theta_yz;
946  _muontrk_tpc[i] = muontrklist[i]->tpc;
947  _muontrk_type[i] = muontrklist[i]->type;
948  }
949  if (freadMuonHits){
950  art::FindMany<recob::Hit> muontrkassn(muonTrackListHandle, evt, fMuonTrackModuleLabel);
951  ResetMuonHitVars(3000); //estimate of maximum collection hits
952  _nmhits = 0;
953  for (int i=0; i < _nmuontrks; i++){
954  std::vector< const recob::Hit*> muonhitsVec = muontrkassn.at(i);
955  _nmhits += (muonhitsVec.size());
956  for (size_t j=0; j<muonhitsVec.size(); j++){
957  auto muonhit = muonhitsVec.at(j);
958  geo::WireID wireid = muonhit->WireID();
959  _mhit_trk.push_back(i);
960  _mhit_tpc.push_back(wireid.TPC);
961  _mhit_wire.push_back(wireid.Wire);
962  _mhit_channel.push_back(muonhit->Channel());
963  _mhit_peakT.push_back(muonhit->PeakTime());
964  _mhit_charge.push_back(muonhit->Integral());
965  }
966  }
967  }
968  }
969  else{
970  std::cout << "Failed to get sbnd::comm::MuonTrack data product" << std::endl;
971  }
972  }
973 
974  if (fcheckTransparency) {
975 
976  _waveform_number.resize(_max_hits*_max_samples, -9999.);
977  _adc_on_wire.resize(_max_hits*_max_samples, -9999.);
978  _time_for_waveform.resize(_max_hits*_max_samples, -9999.);
979  _waveform_integral.resize(_max_hits*_max_samples, -9999.);
980  _adc_count_in_waveform.resize(_max_hits*_max_samples, -9999.);
981 
982  art::Handle<std::vector<raw::RawDigit>> digitVecHandle;
983 
984  bool retVal = evt.getByLabel(fDigitModuleLabel, digitVecHandle);
985  if(retVal == true) {
986  mf::LogInfo("HitDumper") << "I got fDigitModuleLabel: " << fDigitModuleLabel << std::endl;
987  } else {
988  mf::LogWarning("HitDumper") << "Could not get fDigitModuleLabel: " << fDigitModuleLabel << std::endl;
989  }
990 
991  int waveform_number_tracker = 0;
992  int adc_counter = 1;
993  _adc_count = _nhits * (fWindow * 2 + 1);
994 
995  // loop over waveforms
996  for(size_t rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter) {
997 
998  //GET THE REFERENCE TO THE CURRENT raw::RawDigit.
999  art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
1000  int channel = digitVec->Channel();
1001  auto fDataSize = digitVec->Samples();
1002  std::vector<short> rawadc; //UNCOMPRESSED ADC VALUES.
1003  rawadc.resize(fDataSize);
1004 
1005  // see if there is a hit on this channel
1006  for (int ihit = 0; ihit < _nhits; ++ihit) {
1007  if (_hit_channel[ihit] == channel) {
1008 
1009  int pedestal = (int)digitVec->GetPedestal();
1010  //UNCOMPRESS THE DATA.
1011  if (fUncompressWithPed) {
1012  raw::Uncompress(digitVec->ADCs(), rawadc, pedestal, digitVec->Compression());
1013  }
1014  else {
1015  raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->Compression());
1016  }
1017 
1018  unsigned int bin = _hit_peakT[ihit];
1019  unsigned int low_edge,high_edge;
1020  if((int)bin > fWindow and _hit_plane[ihit] == 0) {
1021  low_edge = bin - (2*fWindow);
1022  }
1023  else if ((int)bin>fWindow) {
1024  low_edge = bin-fWindow;
1025  }
1026  else {
1027  low_edge = 0;
1028  }
1029  high_edge = bin + fWindow;
1030  if (high_edge > (fDataSize-1)) {
1031  high_edge = fDataSize - 1;
1032  }
1033  double integral = 0.0;
1034  waveform_number_tracker++;
1035  int counter_for_adc_in_waveform = 0;
1036  for (size_t ibin = low_edge; ibin <= high_edge; ++ibin) {
1037  _adc_count_in_waveform[adc_counter] = counter_for_adc_in_waveform;
1038  counter_for_adc_in_waveform++;
1039  _waveform_number[adc_counter] = waveform_number_tracker;
1040  _adc_on_wire[adc_counter] = rawadc[ibin]-pedestal;
1041  _time_for_waveform[adc_counter] = ibin;
1042  //std::cout << "DUMP: " << _waveform_number[adc_counter] << " " << _adc_count << " " << _hit_plane[ihit] << " " << _hit_wire[ihit] << " " <<ibin << " " << (rawadc[ibin]-pedestal) << " " << _time_for_waveform[adc_counter] << " " << _adc_on_wire[adc_counter] << std::endl;
1043  integral+=_adc_on_wire[adc_counter];
1044  _waveform_integral[adc_counter] = integral;
1045  adc_counter++;
1046  }
1047  std::cout << "DUMP SUM: " << _hit_tpc[ihit] << " " << _hit_plane[ihit] << " " << _hit_wire[ihit] << " " << integral << " " << waveform_number_tracker << std::endl;
1048  _hit_full_integral[ihit] = integral;
1049  } // if hit channel matches waveform channel
1050  } //end loop over hits
1051  }// end loop over waveforms
1052  }// end if fCheckTrasparency
1053 
1054 
1055  if (freadTruth){
1056 
1057  int nGeniePrimaries = 0, nMCNeutrinos = 0;
1058  art::Handle< std::vector<simb::MCTruth> > mctruthListHandle;
1059  std::vector<art::Ptr<simb::MCTruth> > mclist;
1060  if (evt.getByLabel(fGenieGenModuleLabel,mctruthListHandle)){
1061  art::fill_ptr_vector(mclist, mctruthListHandle);
1062  }else {
1063  std::cout << "Failed to get Genie data product." << std::endl;
1064  }
1065 
1066  art::Ptr<simb::MCTruth> mctruth;
1067 
1068  if (!mclist.empty()) {//at least one mc record
1069 
1070  mctruth = mclist[0];
1071 
1072  if (mctruth->NeutrinoSet()) nGeniePrimaries = mctruth->NParticles();
1073 
1074  } // if have MC truth
1075  MF_LOG_DEBUG("HitDumper") << "Expected " << nGeniePrimaries << " GENIE particles";
1076 
1077  //Initially call the number of neutrinos to be stored the number of MCTruth objects. This is not strictly true i.e. BNB + cosmic overlay but we will count the number of neutrinos later
1078  nMCNeutrinos = mclist.size();
1079 
1080  ResizeGenie(nGeniePrimaries);
1081  ResizeMCNeutrino(nMCNeutrinos);
1082 
1083  mcevts_truth = mclist.size();
1084  //Brailsford 2017/10/16
1085  //Issue 17917
1086  //To keep a 1:1 between neutrinos and 'flux' we need the assns
1087  art::FindManyP<simb::MCFlux> fmFluxNeutrino(mctruthListHandle, evt, fGenieGenModuleLabel);
1088  // Get GTruth information for scattering code
1089  art::FindManyP< simb::GTruth > fmgt( mctruthListHandle, evt, fGenieGenModuleLabel );
1090 
1091  if (mcevts_truth > 0){//at least one mc record
1092 
1093  //Brailsford 2017/10/16
1094  //Issue 17917
1095  //Loop over every truth in the spill rather than just looking at the first one.
1096  //Because MCTruth could be a neutrino OR something else (e.g. cosmics) we are going to have to count up how many neutrinos there are
1097  mcevts_truth = 0;
1098  for (unsigned int i_mctruth = 0; i_mctruth < mclist.size(); i_mctruth++){
1099  //fetch an mctruth
1100  art::Ptr<simb::MCTruth> curr_mctruth = mclist[i_mctruth];
1101  //Check if it's a neutrino
1102  if (!curr_mctruth->NeutrinoSet()) continue;
1103 
1104  // Genie Truth association only for the neutrino
1105  if (fmgt.size()>i_mctruth) {
1106  std::vector< art::Ptr<simb::GTruth> > mcgtAssn = fmgt.at(i_mctruth);
1107 
1108  nuScatterCode_truth[i_mctruth] = mcgtAssn[0]->fGscatter;
1109  } else {
1110  nuScatterCode_truth[i_mctruth] = -1.;
1111  }
1112 
1113  nuPDG_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().PdgCode();
1114  ccnc_truth[i_mctruth] = curr_mctruth->GetNeutrino().CCNC();
1115  mode_truth[i_mctruth] = curr_mctruth->GetNeutrino().Mode();
1116  Q2_truth[i_mctruth] = curr_mctruth->GetNeutrino().QSqr();
1117  W_truth[i_mctruth] = curr_mctruth->GetNeutrino().W();
1118  hitnuc_truth[i_mctruth] = curr_mctruth->GetNeutrino().HitNuc();
1119  enu_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().E();
1120  nuvtxx_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Vx();
1121  nuvtxy_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Vy();
1122  nuvtxz_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Vz();
1123  if (curr_mctruth->GetNeutrino().Nu().P()){
1124  nu_dcosx_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Px()/curr_mctruth->GetNeutrino().Nu().P();
1125  nu_dcosy_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Py()/curr_mctruth->GetNeutrino().Nu().P();
1126  nu_dcosz_truth[i_mctruth] = curr_mctruth->GetNeutrino().Nu().Pz()/curr_mctruth->GetNeutrino().Nu().P();
1127  }
1128  lep_mom_truth[i_mctruth] = curr_mctruth->GetNeutrino().Lepton().P();
1129  if (curr_mctruth->GetNeutrino().Lepton().P()){
1130  lep_dcosx_truth[i_mctruth] = curr_mctruth->GetNeutrino().Lepton().Px()/curr_mctruth->GetNeutrino().Lepton().P();
1131  lep_dcosy_truth[i_mctruth] = curr_mctruth->GetNeutrino().Lepton().Py()/curr_mctruth->GetNeutrino().Lepton().P();
1132  lep_dcosz_truth[i_mctruth] = curr_mctruth->GetNeutrino().Lepton().Pz()/curr_mctruth->GetNeutrino().Lepton().P();
1133  }
1134  //Brailsford
1135  //2017/10/17
1136  //Issue 12918
1137  //Use the art::Ptr key as the neutrino's unique ID
1138  nuID_truth[i_mctruth] = curr_mctruth.key();
1139  //We need to also store N 'flux' neutrinos per event so now check that the FindOneP is valid and, if so, use it!
1140  if (fmFluxNeutrino.isValid()){
1141  if (fmFluxNeutrino.at(0).size()>i_mctruth){
1142  art::Ptr<simb::MCFlux> curr_mcflux = fmFluxNeutrino.at(0).at(i_mctruth);
1143  tpx_flux[i_mctruth] = curr_mcflux->ftpx;
1144  tpy_flux[i_mctruth] = curr_mcflux->ftpy;
1145  tpz_flux[i_mctruth] = curr_mcflux->ftpz;
1146  tptype_flux[i_mctruth] = curr_mcflux->ftptype;
1147  }
1148  }
1149 
1150  //Let's increase the neutrino count
1151  mcevts_truth++;
1152  }
1153 
1154  if (mctruth->NeutrinoSet()){
1155  //genie particles information
1156  genie_no_primaries = mctruth->NParticles();
1157 
1158  size_t StoreParticles = std::min((size_t) genie_no_primaries, MaxGeniePrimaries);
1159  if (genie_no_primaries > (int) StoreParticles) {
1160  // got this error? it might be a bug,
1161  // since the structure should have enough room for everything
1162  mf::LogError("HitDumper") << "event has "
1163  << genie_no_primaries << " MC particles, only "
1164  << StoreParticles << " stored in tree";
1165  }
1166  for(size_t iPart = 0; iPart < StoreParticles; ++iPart){
1167  const simb::MCParticle& part(mctruth->GetParticle(iPart));
1168  genie_primaries_pdg[iPart]=part.PdgCode();
1169  genie_Eng[iPart]=part.E();
1170  genie_Px[iPart]=part.Px();
1171  genie_Py[iPart]=part.Py();
1172  genie_Pz[iPart]=part.Pz();
1173  genie_P[iPart]=part.P();
1174  genie_status_code[iPart]=part.StatusCode();
1175  genie_mass[iPart]=part.Mass();
1176  genie_trackID[iPart]=part.TrackId();
1177  genie_ND[iPart]=part.NumberDaughters();
1178  genie_mother[iPart]=part.Mother();
1179  } // for particle
1180  } //if neutrino set
1181  }//if (mcevts_truth)
1182  }//if (fReadTruth){
1183 
1184 
1185 
1186  fTree->Fill();
1187 
1188 }
1189 
1191  {
1192  // Implementation of optional member function here.
1193  art::ServiceHandle<art::TFileService> tfs;
1194  fTree = tfs->make<TTree>("hitdumpertree","analysis tree");
1195  fTree->Branch("run",&_run,"run/I");
1196  fTree->Branch("subrun",&_subrun,"subrun/I");
1197  fTree->Branch("event",&_event,"event/I");
1198  fTree->Branch("evttime",&_evttime,"evttime/D");
1199  fTree->Branch("t0",&_t0,"t0/I");
1200 
1201  fTree->Branch("nhits", &_nhits, "nhits/I");
1202  fTree->Branch("hit_cryostat", &_hit_cryostat);
1203  fTree->Branch("hit_tpc", &_hit_tpc);
1204  fTree->Branch("hit_plane", &_hit_plane);
1205  fTree->Branch("hit_wire", &_hit_wire);
1206  fTree->Branch("hit_channel", &_hit_channel);
1207  fTree->Branch("hit_peakT", &_hit_peakT);
1208  fTree->Branch("hit_charge", &_hit_charge);
1209  fTree->Branch("hit_ph", &_hit_ph);
1210  fTree->Branch("hit_width", &_hit_width);
1211  fTree->Branch("hit_full_integral", &_hit_full_integral);
1212 
1213  if (fcheckTransparency) {
1214  fTree->Branch("adc_count", &_adc_count,"adc_count/I");
1215  fTree->Branch("waveform_number", &_waveform_number);
1216  fTree->Branch("time_for_waveform",&_time_for_waveform);
1217  fTree->Branch("adc_on_wire", &_adc_on_wire);
1218  fTree->Branch("waveform_integral", &_waveform_integral);
1219  fTree->Branch("adc_count_in_waveform", &_adc_count_in_waveform);
1220  }
1221 
1222  if (fkeepCRTstrips) {
1223  fTree->Branch("nstrips", &_nstrips, "nstrips/I");
1224  fTree->Branch("crt_plane", &_crt_plane);
1225  fTree->Branch("crt_module", &_crt_module);
1226  fTree->Branch("crt_strip", &_crt_strip);
1227  fTree->Branch("crt_orient", &_crt_orient);
1228  fTree->Branch("crt_time", &_crt_time);
1229  fTree->Branch("crt_adc", &_crt_adc);
1230  fTree->Branch("crt_pos_x", &_crt_pos_x);
1231  fTree->Branch("crt_pos_y", &_crt_pos_y);
1232  fTree->Branch("crt_pos_z", &_crt_pos_z);
1233  }
1234 
1235  if (fmakeCRTtracks) {
1236  fTree->Branch("nctrks", &_nctrks, "nctrks/I");
1237  fTree->Branch("ctrk_x1", &_ctrk_x1);
1238  fTree->Branch("ctrk_y1", &_ctrk_y1);
1239  fTree->Branch("ctrk_z1", &_ctrk_z1);
1240  fTree->Branch("ctrk_t1", &_ctrk_t1);
1241  fTree->Branch("ctrk_adc1", &_ctrk_adc1);
1242  fTree->Branch("ctrk_mod1x", &_ctrk_mod1x);
1243  fTree->Branch("ctrk_x2", &_ctrk_x2);
1244  fTree->Branch("ctrk_y2", &_ctrk_y2);
1245  fTree->Branch("ctrk_z2", &_ctrk_z2);
1246  fTree->Branch("ctrk_t2", &_ctrk_t2);
1247  fTree->Branch("ctrk_adc2", &_ctrk_adc2);
1248  fTree->Branch("ctrk_mod2x", &_ctrk_mod2x);
1249  }
1250  if (fkeepCRThits) {
1251  fTree->Branch("nchits", &_nchits, "nchits/I");
1252  fTree->Branch("chit_x", &_chit_x);
1253  fTree->Branch("chit_y", &_chit_y);
1254  fTree->Branch("chit_z", &_chit_z);
1255  fTree->Branch("chit_time", &_chit_time);
1256  fTree->Branch("chit_plane", &_chit_plane);
1257  }
1258  if (freadCRTtracks) {
1259  fTree->Branch("ncts", &_ncts, "ncts/I");
1260  fTree->Branch("ct_x1", &_ct_x1);
1261  fTree->Branch("ct_y1", &_ct_y1);
1262  fTree->Branch("ct_z1", &_ct_z1);
1263  fTree->Branch("ct_x2", &_ct_x2);
1264  fTree->Branch("ct_y2", &_ct_y2);
1265  fTree->Branch("ct_z2", &_ct_z2);
1266  fTree->Branch("ct_time", &_ct_time);
1267  fTree->Branch("ct_pes", &_ct_pes);
1268  }
1269 
1270  if (freadOpHits) {
1271  fTree->Branch("nophits", &_nophits, "nophits/I");
1272  fTree->Branch("ophit_opch", &_ophit_opch);
1273  fTree->Branch("ophit_opdet", &_ophit_opdet);
1274  fTree->Branch("ophit_peakT", &_ophit_peakT);
1275  fTree->Branch("ophit_width", &_ophit_width);
1276  fTree->Branch("ophit_area", &_ophit_area);
1277  fTree->Branch("ophit_amplitude", &_ophit_amplitude);
1278  fTree->Branch("ophit_pe", &_ophit_pe);
1279  fTree->Branch("ophit_opdet_x", &_ophit_opdet_x);
1280  fTree->Branch("ophit_opdet_y", &_ophit_opdet_y);
1281  fTree->Branch("ophit_opdet_z", &_ophit_opdet_z);
1282  fTree->Branch("ophit_opdet_type", &_ophit_opdet_type);
1283  }
1284 
1285  if (freadpmtTrigger){
1286  fTree->Branch("pmtTrigger_npmtshigh", &_pmtTrigger_npmtshigh);
1287  fTree->Branch("pmtTrigger_maxpassed", &_pmtTrigger_maxpassed, "pmtTrigger_maxpassed/I");
1288  }
1289 
1290  if (freadpmtSoftTrigger){
1291  fTree->Branch("pmtSoftTrigger_foundBeamTrigger", &_pmtSoftTrigger_foundBeamTrigger);
1292  fTree->Branch("pmtSoftTrigger_tts", &_pmtSoftTrigger_tts);
1293  fTree->Branch("pmtSoftTrigger_promptPE", &_pmtSoftTrigger_promptPE);
1294  fTree->Branch("pmtSoftTrigger_prelimPE", &_pmtSoftTrigger_prelimPE);
1295  fTree->Branch("pmtSoftTrigger_nAboveThreshold", &_pmtSoftTrigger_nAboveThreshold);
1296  // fTree->Branch("pmtSoftTrigger_", &_pmtSoftTigger_)
1297  }
1298 
1299  if (freadcrtSoftTrigger){
1300  fTree->Branch("crtSoftTrigger_hitsperplane", &_crtSoftTrigger_hitsperplane,"crtSoftTrigger_hitsperplane[7]/I");
1301  }
1302 
1303  if (freadMuonTracks) {
1304  fTree->Branch("nmuontrks", &_nmuontrks, "nmuontrks/I");
1305  fTree->Branch("muontrk_t0", &_muontrk_t0);
1306  fTree->Branch("muontrk_x1", &_muontrk_x1);
1307  fTree->Branch("muontrk_y1", &_muontrk_y1);
1308  fTree->Branch("muontrk_z1", &_muontrk_z1);
1309  fTree->Branch("muontrk_x2", &_muontrk_x2);
1310  fTree->Branch("muontrk_y2", &_muontrk_y2);
1311  fTree->Branch("muontrk_z2", &_muontrk_z2);
1312  fTree->Branch("muontrk_theta_xz", &_muontrk_theta_xz);
1313  fTree->Branch("muontrk_theta_yz", &_muontrk_theta_yz);
1314  fTree->Branch("muontrk_tpc", &_muontrk_tpc);
1315  fTree->Branch("muontrk_type", &_muontrk_type);
1316  }
1317 
1318  if (freadMuonHits) {
1319  fTree->Branch("nmhits", &_nmhits, "nmhits/I");
1320  fTree->Branch("mhit_trk", &_mhit_trk);
1321  fTree->Branch("mhit_tpc", &_mhit_tpc);
1322  fTree->Branch("mhit_wire", &_mhit_wire);
1323  fTree->Branch("mhit_channel", &_mhit_channel);
1324  fTree->Branch("mhit_peakT", &_mhit_peakT);
1325  fTree->Branch("mhit_charge", &_mhit_charge);
1326  }
1327 
1328  if (freadTruth) {
1329  fTree->Branch("mcevts_truth",&mcevts_truth,"mcevts_truth/I");
1330  fTree->Branch("nuScatterCode_truth",&nuScatterCode_truth);
1331  fTree->Branch("nuID_truth",&nuID_truth);
1332  fTree->Branch("nuPDG_truth",&nuPDG_truth);
1333  fTree->Branch("ccnc_truth",&ccnc_truth);
1334  fTree->Branch("mode_truth",&mode_truth);
1335  fTree->Branch("enu_truth",&enu_truth);
1336  fTree->Branch("Q2_truth",&Q2_truth);
1337  fTree->Branch("W_truth",&W_truth);
1338  fTree->Branch("hitnuc_truth",&hitnuc_truth);
1339  fTree->Branch("nuvtxx_truth",&nuvtxx_truth);
1340  fTree->Branch("nuvtxy_truth",&nuvtxy_truth);
1341  fTree->Branch("nuvtxz_truth",&nuvtxz_truth);
1342  fTree->Branch("nu_dcosx_truth",&nu_dcosx_truth);
1343  fTree->Branch("nu_dcosy_truth",&nu_dcosy_truth);
1344  fTree->Branch("nu_dcosz_truth",&nu_dcosz_truth);
1345  fTree->Branch("lep_mom_truth",&lep_mom_truth);
1346  fTree->Branch("lep_dcosx_truth",&lep_dcosx_truth);
1347  fTree->Branch("lep_dcosy_truth",&lep_dcosy_truth);
1348  fTree->Branch("lep_dcosz_truth",&lep_dcosz_truth);
1349 
1350  fTree->Branch("tpx_flux",&tpx_flux);
1351  fTree->Branch("tpy_flux",&tpy_flux);
1352  fTree->Branch("tpz_flux",&tpz_flux);
1353  fTree->Branch("tptype_flux",&tptype_flux);
1354 
1355  fTree->Branch("genie_no_primaries",&genie_no_primaries);
1356  fTree->Branch("genie_primaries_pdg",&genie_primaries_pdg);
1357  fTree->Branch("genie_Eng",&genie_Eng);
1358  fTree->Branch("genie_Px",&genie_Px);
1359  fTree->Branch("genie_Py",&genie_Py);
1360  fTree->Branch("genie_Pz",&genie_Pz);
1361  fTree->Branch("genie_P",&genie_P);
1362  fTree->Branch("genie_status_code",&genie_status_code);
1363  fTree->Branch("genie_mass",&genie_mass);
1364  fTree->Branch("genie_trackID",&genie_trackID);
1365  fTree->Branch("genie_ND",&genie_ND);
1366  fTree->Branch("genie_mother",&genie_mother);
1367  }
1368 
1369  if (fsavePOTInfo) {
1370  _sr_tree = tfs->make<TTree>("pottree","");
1371  _sr_tree->Branch("run", &_sr_run, "run/I");
1372  _sr_tree->Branch("subrun", &_sr_subrun, "subrun/I");
1373  _sr_tree->Branch("begintime", &_sr_begintime, "begintime/D");
1374  _sr_tree->Branch("endtime", &_sr_endtime, "endtime/D");
1375  _sr_tree->Branch("pot", &_sr_pot, "pot/D");
1376  }
1377 
1378 }
1379 
1380 
1382  _hit_cryostat.assign(n, DEFAULT_VALUE);
1383  _hit_tpc.assign(n, DEFAULT_VALUE);
1384  _hit_plane.assign(n, DEFAULT_VALUE);
1385  _hit_wire.assign(n, DEFAULT_VALUE);
1386  _hit_channel.assign(n, DEFAULT_VALUE);
1387  _hit_peakT.assign(n, DEFAULT_VALUE);
1388  _hit_charge.assign(n, DEFAULT_VALUE);
1389  _hit_ph.assign(n, DEFAULT_VALUE);
1390  _hit_width.assign(n, DEFAULT_VALUE);
1391  _hit_full_integral.assign(n, DEFAULT_VALUE);
1392 }
1393 
1395  _crt_plane.clear();
1396  _crt_module.clear();
1397  _crt_strip.clear();
1398  _crt_orient.clear();
1399  _crt_time.clear();
1400  _crt_adc.clear();
1401  _crt_pos_x.clear();
1402  _crt_pos_y.clear();
1403  _crt_pos_z.clear();
1404 
1405  _crt_plane.reserve(n);
1406  _crt_module.reserve(n);
1407  _crt_strip.reserve(n);
1408  _crt_orient.reserve(n);
1409  _crt_time.reserve(n);
1410  _crt_adc.reserve(n);
1411  _crt_pos_x.reserve(n);
1412  _crt_pos_y.reserve(n);
1413  _crt_pos_z.reserve(n);
1414 }
1415 
1417  _ctrk_x1.clear();
1418  _ctrk_y1.clear();
1419  _ctrk_z1.clear();
1420  _ctrk_t1.clear();
1421  _ctrk_adc1.clear();
1422  _ctrk_mod1x.clear();
1423  _ctrk_x2.clear();
1424  _ctrk_y2.clear();
1425  _ctrk_z2.clear();
1426  _ctrk_t2.clear();
1427  _ctrk_adc2.clear();
1428  _ctrk_mod2x.clear();
1429 
1430  _ctrk_x1.reserve(n);
1431  _ctrk_y1.reserve(n);
1432  _ctrk_z1.reserve(n);
1433  _ctrk_t1.reserve(n);
1434  _ctrk_adc1.reserve(n);
1435  _ctrk_mod1x.reserve(n);
1436  _ctrk_x2.reserve(n);
1437  _ctrk_y2.reserve(n);
1438  _ctrk_z2.reserve(n);
1439  _ctrk_t2.reserve(n);
1440  _ctrk_adc2.reserve(n);
1441  _ctrk_mod2x.reserve(n);
1442 }
1443 
1445  _ct_x1.assign(n, DEFAULT_VALUE);
1446  _ct_y1.assign(n, DEFAULT_VALUE);
1447  _ct_z1.assign(n, DEFAULT_VALUE);
1448  _ct_time.assign(n, DEFAULT_VALUE);
1449  _ct_pes.assign(n, DEFAULT_VALUE);
1450  _ct_x2.assign(n, DEFAULT_VALUE);
1451  _ct_y2.assign(n, DEFAULT_VALUE);
1452  _ct_z2.assign(n, DEFAULT_VALUE);
1453 }
1454 
1456  _chit_plane.assign(n, DEFAULT_VALUE);
1457  _chit_time.assign(n, DEFAULT_VALUE);
1458  _chit_x.assign(n, DEFAULT_VALUE);
1459  _chit_y.assign(n, DEFAULT_VALUE);
1460  _chit_z.assign(n, DEFAULT_VALUE);
1461 }
1462 
1464  _ophit_opch.resize(n, DEFAULT_VALUE);
1465  _ophit_opdet.resize(n, DEFAULT_VALUE);
1466  _ophit_peakT.resize(n, DEFAULT_VALUE);
1467  _ophit_width.resize(n, DEFAULT_VALUE);
1468  _ophit_area.resize(n, DEFAULT_VALUE);
1469  _ophit_amplitude.resize(n, DEFAULT_VALUE);
1470  _ophit_pe.resize(n, DEFAULT_VALUE);
1471  _ophit_opdet_x.resize(n, DEFAULT_VALUE);
1472  _ophit_opdet_y.resize(n, DEFAULT_VALUE);
1473  _ophit_opdet_z.resize(n, DEFAULT_VALUE);
1474  _ophit_opdet_type.resize(n, DEFAULT_VALUE);
1475 }
1476 
1478  _pmtTrigger_npmtshigh.assign(n, DEFAULT_VALUE);
1480 }
1481 
1484  _pmtSoftTrigger_tts = 0;
1488 }
1489 
1491  for (int i=0; i<7; i++){
1493  }
1494 }
1495 
1497  _muontrk_t0.assign(n, DEFAULT_VALUE);
1498  _muontrk_x1.assign(n, DEFAULT_VALUE);
1499  _muontrk_y1.assign(n, DEFAULT_VALUE);
1500  _muontrk_z1.assign(n, DEFAULT_VALUE);
1501  _muontrk_x2.assign(n, DEFAULT_VALUE);
1502  _muontrk_y2.assign(n, DEFAULT_VALUE);
1503  _muontrk_z2.assign(n, DEFAULT_VALUE);
1504  _muontrk_theta_xz.assign(n, DEFAULT_VALUE);
1505  _muontrk_theta_yz.assign(n, DEFAULT_VALUE);
1506  _muontrk_tpc.assign(n, DEFAULT_VALUE);
1507  _muontrk_type.assign(n, DEFAULT_VALUE);
1508 }
1509 
1511  _mhit_trk.clear();
1512  _mhit_tpc.clear();
1513  _mhit_wire.clear();
1514  _mhit_channel.clear();
1515  _mhit_peakT.clear();
1516  _mhit_charge.clear();
1517 
1518  _mhit_trk.reserve(n);
1519  _mhit_tpc.reserve(n);
1520  _mhit_wire.reserve(n);
1521  _mhit_channel.reserve(n);
1522  _mhit_peakT.reserve(n);
1523  _mhit_charge.reserve(n);
1524 }
1525 
1527 
1528 
1529  _run = -99999;
1530  _subrun = -99999;
1531  _event = -99999;
1532  _evttime = -99999;
1533  _t0 = -99999;
1534 
1535  mcevts_truth = 0;
1536  genie_no_primaries = 0;
1537 }
1538 
1539 void Hitdumper::ResizeMCNeutrino(int nNeutrinos) {
1540 
1541  //min size is 1, to guarantee an address
1542  MaxMCNeutrinos = (size_t) std::max(nNeutrinos, 1);
1543 
1544  nuScatterCode_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1545  nuID_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1546  nuPDG_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1547  ccnc_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1548  mode_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1549  enu_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1550  Q2_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1551  W_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1552  hitnuc_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1553  nuvtxx_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1554  nuvtxy_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1555  nuvtxz_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1556  nu_dcosx_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1557  nu_dcosy_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1558  nu_dcosz_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1559  lep_mom_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1560  lep_dcosx_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1561  lep_dcosy_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1562  lep_dcosz_truth.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1563  //Also resize the flux information here as it's a 1:1 with the MCNeutrino
1564  tpx_flux.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1565  tpy_flux.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1566  tpz_flux.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1567  tptype_flux.assign(MaxMCNeutrinos, DEFAULT_VALUE);
1568 
1569 }
1570 
1571 void Hitdumper::ResizeGenie(int nPrimaries) {
1572 
1573  // minimum size is 1, so that we always have an address
1574  MaxGeniePrimaries = (size_t) std::max(nPrimaries, 1);
1575 
1576  genie_primaries_pdg.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1577  genie_Eng.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1578  genie_Px.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1579  genie_Py.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1580  genie_Pz.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1581  genie_P.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1582  genie_status_code.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1583  genie_mass.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1584  genie_trackID.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1585  genie_ND.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1586  genie_mother.assign(MaxGeniePrimaries, DEFAULT_VALUE);
1587 
1588 }
1589 
1590 
1591 void Hitdumper::beginSubRun(art::SubRun const& sr) {
1592 
1593  if (!fsavePOTInfo) {
1594  return;
1595  }
1596 
1597  _sr_run = sr.run();
1598  _sr_subrun = sr.subRun();
1599  _sr_begintime = sr.beginTime().value();
1600  _sr_endtime = sr.endTime().value();
1601 
1602  art::Handle<sumdata::POTSummary> pot_handle;
1603  sr.getByLabel(fGenieGenModuleLabel, pot_handle);
1604 
1605  if (pot_handle.isValid()) {
1606  _sr_pot = pot_handle->totpot;
1607  } else {
1608  _sr_pot = 0.;
1609  }
1610 
1611  _sr_tree->Fill();
1612 
1613 }
1614 
1615 DEFINE_ART_MODULE(Hitdumper)
1616 
1617 #endif // Hitdumper_Module
bool fSkipInd
If true, induction planes are not saved (to be set via fcl)
int _pmtTrigger_maxpassed
maximum number of pmt pairs above threshold during trigger window (usually beam spill) ...
void ResetOpHitsVars(int n)
Resets optical hits tree variables.
std::vector< Int_t > genie_status_code
std::vector< double > _ophit_opdet_y
OpDet Y coordinate of the optical hit.
std::vector< int > _time_for_waveform
Time for waveform to plot.
std::vector< int > _hit_cryostat
Cryostat where the hit belongs to.
void ResetCRTStripsVars(int n)
Resets crt strips tree variables.
std::vector< int > _pmtTrigger_npmtshigh
number of pmt pairs above threshold, index = time during trigger window (usually beam spill) ...
std::vector< Int_t > mode_truth
0=QE/El, 1=RES, 2=DIS, 3=Coherent production
void ResizeGenie(int nPrimaries)
Resize the data structure for Genie primaries.
int _nctrks
Number of created CRT tracks.
std::vector< double > _ctrk_z2
CRT track z2.
bool fUncompressWithPed
Uncompresses the waveforms if true (to be set via fcl)
std::vector< double > _ophit_peakT
Peak time of the optical hit.
std::vector< float > _muontrk_x1
x coordinate closer to anode
std::vector< int > _hit_wire
Wire where the hit belongs to.
std::vector< Float_t > lep_dcosy_truth
lepton dcos y
std::vector< Float_t > tpx_flux
Px of parent particle leaving BNB target.
void ResetWireHitsVars(int n)
Resets wire hits tree variables.
int _nmuontrks
number of muon tracks
Utilities related to art service access.
std::vector< int > fKeepTaggerTypes
Taggers to keep (to be set via fcl)
std::vector< float > _muontrk_z1
z coordinate closer to anode
Hitdumper(fhicl::ParameterSet const &p)
int _max_chits
maximum number of CRT hits (to be set via fcl)
std::vector< int > _mhit_trk
Track number that the hit belongs to.
std::vector< int > _mhit_wire
Wire where the hit belongs to.
std::vector< int > _hit_channel
Channel where the hit belongs to.
std::vector< float > _muontrk_x2
x coordinate closer to cathode
virtual void beginSubRun(art::SubRun const &sr) override
size_t MaxGeniePrimaries
int _crtSoftTrigger_hitsperplane[7]
number of individual PMTs above ADC threshold (fcl) during the beam spill
int _nhits
Number of reco hits in the event.
opdet::sbndPDMapAlg _pd_map
std::vector< std::string > fOpHitsModuleLabels
Labels for OpHit dataproducts (to be set via fcl)
int _event
The event number.
std::vector< double > _chit_time
CRT hit time.
Int_t mcevts_truth
! The number of MCNeutrinos there is currently room for
size_t MaxMCNeutrinos
std::vector< int > _adc_count_in_waveform
Used to view all waveforms on a hitplane together.
std::vector< double > _crt_pos_y
CRT position Y.
void ResizeMCNeutrino(int nNeutrinos)
Resize the data structure for MCNeutrino particles.
std::vector< int > _muontrk_tpc
tpc that muon is located in
std::vector< double > _crt_time
CRT time.
bool fkeepCRTstrips
Keep the CRT strips (to be set via fcl)
std::string fCRTStripModuleLabel
Label for CRTStrip dataproduct (to be set via fcl)
std::string fGenieGenModuleLabel
Label for Genie dataproduct (to be set via fcl)
Declaration of signal hit object.
std::vector< double > _ophit_pe
PEs of the optical hit.
std::vector< double > _mhit_peakT
Hit peak time.
std::string fHitsModuleLabel
Label for Hit dataproduct (to be set via fcl)
std::vector< int > _hit_tpc
TPC where the hit belongs to.
pdgs p
Definition: selectors.fcl:22
void reconfigure(fhicl::ParameterSet const &pset)
std::vector< int > _waveform_number
Number for each waveform, to allow for searching.
Uncoated PMT.
std::vector< Float_t > nuvtxy_truth
neutrino vertex y
std::vector< double > _ct_z2
CRT track z2.
std::vector< Float_t > nu_dcosx_truth
neutrino dcos x
std::vector< Float_t > Q2_truth
Momentum transfer squared.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
const int MAX_INT
Definition of basic raw digits.
std::vector< Float_t > nu_dcosy_truth
neutrino dcos y
std::vector< double > _ophit_opdet_z
OpDet Z coordinate of the optical hit.
bool fkeepCRThits
Keep the CRT hits (to be set via fcl)
std::vector< Float_t > genie_P
double _sr_pot
POTs in each subrun.
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
const int DEFAULT_VALUE
std::vector< double > _crt_pos_z
CRT position Z.
void ResetCRTCustomTracksVars(int n)
Resets custom crt tracks tree variables.
double _sr_endtime
std::vector< Float_t > nuvtxz_truth
neutrino vertex z
bool freadCRTtracks
Keep the CRT tracks (to be set via fcl)
std::vector< int > _crt_module
CRT module.
int _nchits
Number of CRT hits.
std::string fpmtSoftTriggerModuleLabel
Label for pmt software trigger data product (to be set via fcl)
Description of geometry of one set of auxiliary detectors.
std::vector< Float_t > nu_dcosz_truth
neutrino dcos z
std::vector< Float_t > tpy_flux
Py of parent particle leaving BNB target.
std::string fLArG4ModuleLabel
Label for LArG4 dataproduct (to be set via fcl)
int _run
The run number.
std::vector< int > _mhit_tpc
TPC where the hit belongs to.
int _max_samples
maximum number of samples (to be set via fcl)
The geometry of one entire detector, as served by art.
unsigned int OpDetFromOpChannel(int opChannel) const
Convert unique channel to detector number.
std::vector< Int_t > tptype_flux
Type of parent particle leaving BNB target.
void ResetCRTHitsVars(int n)
Resets crt hits tree variables.
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::vector< double > _hit_width
Hit width.
int _nmhits
Number of muon collection hits per track.
std::vector< int > _ophit_opdet_type
OpDet tyoe of the optical hit.
bool fsavePOTInfo
Add POT info to output (to be set via fcl)
int hitsperplane[7]
Definition: CRTmetric.hh:13
std::vector< Float_t > genie_Eng
int _max_ophits
maximum number of hits (to be set via fcl)
Not defined.
while getopts h
std::vector< double > _crt_adc
CRT adc.
Arapuca VUV.
std::vector< Int_t > nuID_truth
Unique ID of each true neutrino.
Access the description of detector geometry.
std::vector< int > _crt_strip
CRT strip.
std::vector< int > _ctrk_mod2x
CRT track mod2x.
void analyze(const art::Event &evt) override
sbnd::CRTHitRecoAlg hitAlg
object containing MC truth information necessary for making RawDigits and doing back tracking ...
std::vector< Float_t > genie_Py
std::vector< double > _ctrk_x1
CRT track x1.
std::vector< double > _ct_y1
CRT track y1.
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
std::vector< Int_t > nuScatterCode_truth
Scattering code given by Genie for each neutrino.
std::vector< Float_t > genie_Pz
std::vector< Int_t > hitnuc_truth
hit nucleon
std::vector< Float_t > lep_dcosx_truth
lepton dcos x
std::vector< double > _ct_y2
CRT track y2.
bool freadMuonTracks
Add MuonTracks to output (to be set via fcl)
TTree * _sr_tree
A tree filled per subrun (for POT accounting)
std::vector< double > _hit_full_integral
Hit charge integral.
Arapuca Vis.
std::vector< double > _ctrk_y2
CRT track y2.
std::vector< double > _adc_on_wire
ADC on wire to draw waveform.
virtual ~Hitdumper()
double _sr_begintime
std::vector< int > _hit_plane
Plane where the hit belongs to.
int _nstrips
Number of CRT strips.
std::vector< double > _chit_y
CRT hit y.
void ResetPmtTriggerVars(int n)
Resets pmt hardware trigger variables.
Collect all the RawData header files together.
std::vector< double > _mhit_charge
Hit charge.
art framework interface to geometry description for auxiliary detectors
const geo::AuxDetGeometryCore * fAuxDetGeoCore
enum::sbnd::CRTPlane GetPlaneIndex(std::string tagger)
const long int TIME_CORRECTION
std::string fMuonTrackModuleLabel
Label for MuonTrack dataproduct (to be set via fcl)
std::vector< double > _ctrk_t1
CRT track t1.
Int_t genie_no_primaries
std::vector< double > _ophit_amplitude
Amplitude of the optical hit.
std::vector< Float_t > W_truth
hadronic invariant mass
std::vector< float > _muontrk_z2
z coordinate closer to cathode
std::string fpmtTriggerModuleLabel
Label for pmtTrigger dataproduct (to be set vis fcl)
std::vector< double > _ctrk_adc1
CRT track adc1.
void ResetCrtSoftTriggerVars()
Resets crt software trigger variables.
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
std::vector< float > _muontrk_theta_yz
theta_yz trajectory angle
std::vector< Int_t > ccnc_truth
0=CC 1=NC
CRTOrientation
double _pmtSoftTrigger_prelimPE
Total photoelectron count 100 ns after the TTS.
PhotoDetectorType
std::pair< std::string, unsigned > ChannelToTagger(uint32_t channel)
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
Description of geometry of one entire detector.
std::vector< int > _ctrk_mod1x
CRT track mod2x.
std::vector< Float_t > genie_Px
std::vector< double > _ctrk_z1
CRT track z1.
int _nophits
Number of Optical Hits.
std::vector< int > _waveform_integral
Used to see progression of the waveform integral.
int _adc_count
Used for plotting waveforms.
Definition of data types for geometry description.
bool freadpmtSoftTrigger
Add pmt software trigger info to output (to be set via fcl)
std::vector< Int_t > genie_trackID
std::vector< double > _hit_ph
Hit ph?
std::vector< Float_t > tpz_flux
Pz of parent particle leaving BNB target.
double _pmtSoftTrigger_promptPE
Trigger Time Stamp (TTS), ns (relative to start of beam spill)
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
bool fcheckTransparency
Checks for wire transprency (to be set via fcl)
std::vector< Float_t > enu_truth
true neutrino energy
std::vector< int > _crt_plane
CRT plane.
std::string fcrtSoftTriggerModuleLabel
Label for crt software trigger data product (to be set via fcl)
std::vector< double > _ophit_width
Width of the optical hit.
Encapsulate the geometry of a wire.
std::vector< Int_t > genie_primaries_pdg
std::vector< double > _ct_x1
CRT track x1.
void ResetMuonTracksVars(int n)
Resets crossing muon tracks tree variables.
std::vector< double > _ct_x2
CRT track x2.
Horizontal Tagger.
std::vector< double > _ctrk_t2
CRT track t2.
std::vector< double > _ct_z1
CRT track z1.
bool freadpmtTrigger
Add pmt hardware trigger info to output (to be set via fcl)
int _subrun
The subrun number.
bool _pmtSoftTrigger_foundBeamTrigger
const geo::AuxDetGeometry * fAuxDetGeo
std::vector< Float_t > genie_mass
int _max_nctrks
maximum number of CRT tracks (to be set via fcl)
std::string fCRTTrackModuleLabel
Label for CRTTrack dataproduct (to be set via fcl)
bool freadOpHits
Add OpHits to output (to be set via fcl)
std::vector< Int_t > nuPDG_truth
neutrino PDG code
Encapsulate the construction of a single detector plane.
bool fmakeCRTtracks
Make the CRT tracks (to be set via fcl)
std::vector< int > _chit_plane
CRT hit plane.
std::vector< Float_t > lep_dcosz_truth
lepton dcos z
std::vector< double > _crt_pos_x
CRT position X.
const TGeoVolume * TotalVolume() const
Definition: AuxDetGeo.h:106
std::vector< Int_t > genie_mother
int _ncts
Number of CRT tracks.
bool freadMuonHits
Add MuonTrack hits to output(to be set via fcl)
std::vector< double > _chit_x
CRT hit x.
Coated PMT.
VertivalTagger.
std::vector< double > _chit_z
CRT hit z.
std::vector< Float_t > lep_mom_truth
lepton momentum
std::vector< double > _muontrk_t0
t0 (time of interaction)
std::vector< float > _muontrk_y1
y coordinate closer to anode
std::string fDigitModuleLabel
Label for digitizer (to be set via fcl)
bool freadcrtSoftTrigger
Add crt software trigger info to output (to be set via fcl)
std::vector< double > _ctrk_x2
CRT track x2.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
double _evttime
The event time.
static double tdiff(const art::Timestamp &ts1, const art::Timestamp &ts2)
int _max_hits
maximum number of hits (to be set via fcl)
std::vector< double > _hit_peakT
Hit peak time.
std::vector< double > _hit_charge
Hit charge.
constexpr WireID()=default
Default constructor: an invalid TPC ID.
std::vector< int > _ophit_opch
OpChannel of the optical hit.
std::vector< Int_t > genie_ND
std::vector< double > _ctrk_y1
CRT track y1.
void ResetPmtSoftTriggerVars()
Rests pmt software trigger variables.
then echo fcl name
geo::GeometryCore const * fGeometryService
std::vector< double > _ctrk_adc2
CRT track adc2.
art::ServiceHandle< art::TFileService > tfs
std::vector< float > _muontrk_y2
y coordinate closer to cathode
int _pmtSoftTrigger_nAboveThreshold
Total photoelectron count before the TTS, during the beam spill.
void ResetMuonHitVars(int n)
Resets crossing muon hit tree variables.
TCEvent evt
Definition: DataStructs.cxx:8
std::vector< int > _mhit_channel
Channel where the hit belongs to.
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
Not defined.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
void ResetCRTTracksVars(int n)
Resets crt tracks tree variables.
std::vector< double > _ct_time
CRT track time.
std::string pdType(size_t ch) const override
std::string fCRTHitModuleLabel
Label for CRTHit dataproduct (to be set via fcl)
OpDetGeo const & OpDetGeoFromOpChannel(unsigned int OpChannel) const
Returns the geo::OpDetGeo object for the given channel number.
int _pmtSoftTrigger_tts
Whether the beam spill was found or not.
std::vector< float > _muontrk_theta_xz
theta_xz trajectory angle
art::ServiceHandle< geo::AuxDetGeometry > fAuxDetGeoService
std::vector< Float_t > nuvtxx_truth
neutrino vertex x
std::vector< int > _ophit_opdet
OpDet of the optical hit.
TVector3 AuxDetChannelToPosition(uint32_t const &channel, std::string const &auxDetName) const
std::vector< int > _muontrk_type
type of muon track
std::vector< int > _crt_orient
CRT orientation (0 for y (horizontal) and 1 for x (vertical))
art framework interface to geometry description
BEGIN_PROLOG could also be cout
int _t0
The t0.
std::vector< double > _ophit_area
Area of the optical hit.
void ResetVars()
Resets the variables that are saved to the TTree.
std::vector< double > _ct_pes
CRT track PEs.
bool freadTruth
Add Truth info to output (to be set via fcl)
std::vector< double > _ophit_opdet_x
OpDet X coordinate of the optical hit.
void beginJob() override