All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRTSimHitViewer.cc
Go to the documentation of this file.
1 /**
2  * \file CRTSimHitViewer.cc
3  *
4  *
5  * Author:
6  */
7 
8 #include <iostream>
9 #include <array>
10 
11 #include "canvas/Utilities/InputTag.h"
12 #include "core/SelectionBase.hh"
13 #include "core/Event.hh"
14 #include "core/Experiment.hh"
15 #include "core/ProviderManager.hh"
16 
17 #include "canvas/Persistency/Common/FindManyP.h"
20 #include "icaruscode/CRT/CRTProducts/CRTChannelData.h"
24 #include "fhiclcpp/ParameterSet.h"
25 
26 #include "TH2D.h"
27 #include "TGraph.h"
28 
29 namespace ana {
30  namespace SBNOsc {
31 
32 /**
33  * \class CRTSimHitViewer
34  * \brief Electron neutrino event selection
35  */
37 public:
38  /** Constructor. */
40 
41  /**
42  * Initialization.
43  *
44  * \param config A configuration, as a FHiCL ParameterSet object
45  */
46  void Initialize(fhicl::ParameterSet* config=NULL) {
47  fCRTHitTag = config ? config->get<std::string>("CRTHitTag", "crtsimhit") : "crtsimhit";
48  fIsICARUS = config ? config->get<bool>("IsICARUS", true) : true;
49  event_ind = 0;
50 
51  time_v_pe_all = new TH2D("in_time_hits_all", "in_time_hits_all", 200, -1000., 1000., 10, 0., 500000.);
52  }
53 
54  /** Finalize and write objects to the output file. */
55  void Finalize() {
56  fOutputFile->cd();
57  time_v_pe_all->Write();
58  }
59 
60  /**
61  * Process one event.
62  *
63  * \param ev A single event, as a gallery::Event
64  * \param Reconstructed interactions
65  * \return True to keep event
66  */
67  bool ProcessEvent(const gallery::Event& ev, const std::vector<event::Interaction> &truth, std::vector<event::RecoInteraction>& reco) {
68 
69  if (fIsICARUS) {
70  auto const &crt_hits_handle = ev.getValidHandle<std::vector<sbn::crt::CRTHit>>(fCRTHitTag);;
71  const std::vector<sbn::crt::CRTHit> &crt_hits = *crt_hits_handle;
72  const std::vector<sim::AuxDetSimChannel> &crt_sim_channels = *ev.getValidHandle<std::vector<sim::AuxDetSimChannel>>("largeant");
73  art::FindManyP<icarus::crt::CRTData, void> hits_to_data(crt_hits_handle, ev, fCRTHitTag);
74  std::cout << "Event: " << event_ind << std::endl;
75 
76  for (const sim::AuxDetSimChannel &sim_channel: crt_sim_channels) {
77  int channel = sim_channel.AuxDetID();
78  std::cout << "Channel: " << channel << std::endl;
79  for (const sim::AuxDetIDE &ide: sim_channel.AuxDetIDEs()) {
80  std::cout << "IDE\n";
81  std::cout << "entry T: " << ide.entryT << " exit T: " << ide.exitT << std::endl;
82  std::cout << "entry X: " << ide.entryX << " entry Y: " << ide.entryY << " entry Z: " << ide.entryZ << std::endl;
83  std::cout << "exit X: " << ide.exitX << " exit Y: " << ide.exitY << " exit Z: " << ide.exitZ << std::endl;
84  std::cout << "Track ID: " << ide.trackID << std::endl;
85  }
86  }
87 
88  std::string histo_name = "in_time_hits" + std::to_string(event_ind);
89  fOutputFile->cd();
90  TH2D *time_v_pe = new TH2D(histo_name.c_str(), "in_time_hits", 200, -1000., 1000., 10, 0., 500000.);
91  for (unsigned i = 0; i < crt_hits.size(); i++) {
92  const sbn::crt::CRTHit &crt_hit = crt_hits[i];
93  std::cout << "Hit index: " << i << std::endl;
94  std::cout << "TS0 NS: " << (int)crt_hit.ts0_ns << std::endl;
95  std::cout << "TS1 NS: " << crt_hit.ts1_ns << std::endl;
96  std::cout << "X: " << crt_hit.x_pos << " Y: " << crt_hit.y_pos << " Z: " << crt_hit.z_pos << std::endl;
97  std::cout << "Xerr: " << crt_hit.x_err << " Yerr: " << crt_hit.y_err << " Z: " << crt_hit.z_err << std::endl;
98  std::cout << "Plane: " << crt_hit.plane << std::endl;
99  std::cout << "PE's Hit: " << crt_hit.peshit << std::endl;
100  std::cout << "Tagger: " << crt_hit.tagger << std::endl;
101  time_v_pe->Fill(((int)crt_hit.ts0_ns) / 1000. + 1.1e3, crt_hit.peshit);
102  time_v_pe_all->Fill(((int)crt_hit.ts0_ns) / 1000. + 1.1e3, crt_hit.peshit);
103  const std::vector<art::Ptr<icarus::crt::CRTData>> &crt_datas = hits_to_data.at(i);
104  std::cout << "Track IDs: ";
105  for (auto const &crt_data: crt_datas) {
106  std::vector<icarus::crt::CRTChannelData> crt_channel_datas = crt_data->ChanData();
107  for (auto const &crt_chan: crt_channel_datas) {
108  for (int id: crt_chan.TrackID()) {
109  std::cout << id << " ";
110  }
111  }
112  }
113  std::cout << std::endl;
114  }
115  time_v_pe->Write();
116  delete time_v_pe;
117  }
118  else {
119  auto const &crt_hits_handle = ev.getValidHandle<std::vector<sbn::crt::CRTHit>>(fCRTHitTag);;
120  const std::vector<sbn::crt::CRTHit> &crt_hits = *crt_hits_handle;
121  const std::vector<sim::AuxDetSimChannel> &crt_sim_channels = *ev.getValidHandle<std::vector<sim::AuxDetSimChannel>>("largeant");
122  std::cout << "Event: " << event_ind << std::endl;
123 
124  for (const sim::AuxDetSimChannel &sim_channel: crt_sim_channels) {
125  int channel = sim_channel.AuxDetID();
126  std::cout << "Channel: " << channel << std::endl;
127  for (const sim::AuxDetIDE &ide: sim_channel.AuxDetIDEs()) {
128  std::cout << "IDE\n";
129  std::cout << "entry T: " << ide.entryT << " exit T: " << ide.exitT << std::endl;
130  std::cout << "entry X: " << ide.entryX << " entry Y: " << ide.entryY << " entry Z: " << ide.entryZ << std::endl;
131  std::cout << "exit X: " << ide.exitX << " exit Y: " << ide.exitY << " exit Z: " << ide.exitZ << std::endl;
132  }
133  }
134 
135  for (unsigned i = 0; i < crt_hits.size(); i++) {
136  const sbn::crt::CRTHit &crt_hit = crt_hits[i];
137  std::cout << "Hit index: " << i << std::endl;
138  std::cout << "TS0 NS: " << crt_hit.ts0_ns << std::endl;
139  std::cout << "TS1 NS: " << crt_hit.ts1_ns << std::endl;
140  std::cout << "X: " << crt_hit.x_pos << " Y: " << crt_hit.y_pos << " Z: " << crt_hit.z_pos << std::endl;
141  std::cout << "Xerr: " << crt_hit.x_err << " Yerr: " << crt_hit.y_err << " Z: " << crt_hit.z_err << std::endl;
142  std::cout << "Plane: " << crt_hit.plane << std::endl;
143  std::cout << "PE's Hit: " << crt_hit.peshit << std::endl;
144  }
145 
146  }
147  event_ind += 1;
148 
149  return false;
150  }
151 
152 protected:
153  std::string fCRTHitTag;
154  bool fIsICARUS;
155  unsigned event_ind;
157 };
158 
159  } // namespace SBNOsc
160 } // namespace ana
162 
float z_err
position uncertainty in z-direction (cm).
Definition: CRTHit.hh:43
float x_err
position uncertainty in x-direction (cm).
Definition: CRTHit.hh:39
double ts1_ns
Timestamp T1 ([signal time w.r.t. Trigger time]), in UTC absolute time scale in nanoseconds from the ...
Definition: CRTHit.hh:34
int plane
Name of the CRT wall (in the form of numbers).
Definition: CRTHit.hh:36
float peshit
Total photo-electron (PE) in a crt hit.
Definition: CRTHit.hh:27
float y_err
position uncertainty in y-direction (cm).
Definition: CRTHit.hh:41
TFile * fOutputFile
The output ROOT file.
process_name opflashCryoW ana
Collection of particles crossing one auxiliary detector cell.
float z_pos
position in z-direction (cm).
Definition: CRTHit.hh:42
double ts0_ns
Timestamp T0 (from White Rabbit), in UTC absolute time scale in nanoseconds from the Epoch...
Definition: CRTHit.hh:32
void Initialize(fhicl::ParameterSet *config=NULL)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
process_name standard_reco_uboone reco
Electron neutrino event selection.
#define DECLARE_SBN_PROCESSOR(classname)
Base class for event selections.
float y_pos
position in y-direction (cm).
Definition: CRTHit.hh:40
float x_pos
position in x-direction (cm).
Definition: CRTHit.hh:38
std::string to_string(WindowPattern const &pattern)
MC truth information to make RawDigits and do back tracking.
std::string tagger
Name of the CRT wall (in the form of strings).
Definition: CRTHit.hh:45
bool ProcessEvent(const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)
BEGIN_PROLOG could also be cout