LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PhotonInf_module.cc
Go to the documentation of this file.
1 // Plugin Type: analyzer
3 // File: PhotonInf_module.cc
4 // Description:
5 // takes the SimPhotonsCollection generated by LArG4's sensitive detectors
6 // and gives: x, y, z, num of det_ph on each OpDet
7 // Oct. 20, 2020 by Mu Wei wmu@fnal.gov
9 
10 // FMWK includes
16 #include "art_root_io/TFileService.h"
17 #include "fhiclcpp/ParameterSet.h"
19 
20 // LArSoft includes
28 
31 
32 // ROOT includes
33 #include "RtypesCore.h"
34 #include "TLorentzVector.h"
35 #include "TTree.h"
36 #include "TVector3.h"
37 
38 // C++ language includes
39 #include <cstring>
40 #include <iostream>
41 
42 namespace opdet {
43 
44  class PhotonInf : public art::EDAnalyzer {
45  public:
47  void analyze(art::Event const&);
48  void beginJob();
49  void endJob();
50 
51  std::ofstream logFile;
52 
53  private:
54  bool FillTree;
55  std::string LogFileName; // Input tag for name of log file
56  std::vector<std::string> InputModules; // Input tag for OpDet collection
57 
58  std::vector<int> num_detph; // number of directly detected photons
59  std::vector<int> num_refph; // number of reflected photons
60  std::vector<int> num_totph; // number of total detected photons
61  double pos[3];
62 
63  TTree* PhInf;
64 
65  int OpChannel;
67  int EventID;
68  float Energy;
69  //float Time;
70  };
71 
73  : EDAnalyzer(pset)
74  , FillTree{pset.get<bool>("FillTree")}
75  , LogFileName{pset.get<std::string>("LogFileName")}
76  {
77  InputModules = pset.get<std::vector<std::string>>("InputModules", {"largeant"});
78 
80  nOpChannels = int(geo->Cryostat().NOpDet());
81 
82  num_detph.resize(nOpChannels, 0);
83  num_refph.resize(nOpChannels, 0);
84  num_totph.resize(nOpChannels, 0);
85 
86  if (FillTree) {
88  PhInf = tfs->make<TTree>("PhInf", "PhInf");
89  PhInf->Branch("X", &(pos[0]), "X/D");
90  PhInf->Branch("Y", &(pos[1]), "Y/D");
91  PhInf->Branch("Z", &(pos[2]), "Z/D");
92 
93  for (int channel = 0; channel < nOpChannels; ++channel) {
94  PhInf->Branch(Form("Channel_%03d_det", channel),
95  &(num_detph[channel]),
96  Form("Channel_%03d_det/I", channel));
97  PhInf->Branch(Form("Channel_%03d_ref", channel),
98  &(num_refph[channel]),
99  Form("Channel_%03d_ref/I", channel));
100  PhInf->Branch(Form("Channel_%03d_tot", channel),
101  &(num_totph[channel]),
102  Form("Channel_%03d_tot/I", channel));
103  }
104  }
105  }
106 
108  {
109  logFile.open(LogFileName);
110 
111  return;
112  }
113 
115  {
116  logFile.close();
117 
118  return;
119  }
120 
122  {
123  art::EventNumber_t event = evt.id().event();
124  EventID = int(event);
125 
126  num_detph.resize(nOpChannels, 0);
127  num_refph.resize(nOpChannels, 0);
128  num_totph.resize(nOpChannels, 0);
129 
130  pos[0] = 0.0;
131  pos[1] = 0.0;
132  pos[2] = 0.0;
133 
134  bool rec = false;
135  float vuv = 6e-6;
136 
137  auto photon_handles = evt.getMany<std::vector<sim::SimPhotons>>();
138  if (photon_handles.empty()) {
140  << "sim SimPhotons retrieved and you requested them.";
141  }
142 
143  for (auto const& mod : InputModules) {
144  for (auto const& ph_handle : photon_handles) {
145  if (!ph_handle.isValid()) { continue; }
146  if (ph_handle.provenance()->moduleLabel() != mod) { continue; }
147 
148  if (!ph_handle->empty()) {
149  for (auto const& itOpDet : (*ph_handle)) {
150  OpChannel = int(itOpDet.OpChannel());
151  const sim::SimPhotons& TheHit = itOpDet;
152  for (const sim::OnePhoton& Phot : TheHit) {
153  Energy = Phot.Energy;
154 
155  num_totph[OpChannel] += 1;
156 
157  if (Energy < vuv) // reflected photons
158  {
159  num_refph[OpChannel] += 1;
160  }
161  else {
162  num_detph[OpChannel] += 1;
163 
164  if (rec == false) {
165  pos[0] = Phot.InitialPosition.X() / 10.0; // cm
166  pos[1] = Phot.InitialPosition.Y() / 10.0;
167  pos[2] = Phot.InitialPosition.Z() / 10.0;
168 
169  rec = true;
170  }
171  }
172  }
173  }
174  }
175  }
176  }
177 
178  if (rec == true) {
179  if (FillTree) { PhInf->Fill(); }
180 
181  logFile << pos[0] << ", " << pos[1] << ", " << pos[2];
182  for (int channel = 0; channel < nOpChannels; channel++) {
183  logFile << ", " << num_detph[channel] << ", " << num_refph[channel] << ", "
184  << num_totph[channel];
185 
186  num_detph[channel] = 0;
187  num_refph[channel] = 0;
188  num_totph[channel] = 0;
189  }
190  logFile << std::endl;
191  pos[0] = 0.0;
192  pos[1] = 0.0;
193  pos[2] = 0.0;
194  }
195  else {
196  std::cout << "Warning: No record for event " << EventID << std::endl;
197  }
198 
199  rec = false;
200  return;
201  }
202 }
203 
PhotonInf(const fhicl::ParameterSet &)
std::vector< int > num_totph
Encapsulate the construction of a single cyostat.
All information of a photon entering the sensitive optical detector volume.
Definition: SimPhotons.h:60
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
Particle class.
Simulation objects for optical detectors.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
T get(std::string const &key) const
Definition: ParameterSet.h:314
void analyze(art::Event const &)
std::ofstream logFile
std::string LogFileName
Encapsulate the geometry of an optical detector.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< int > num_detph
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:127
std::vector< std::string > InputModules
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:8
Particle list in DetSim contains Monte Carlo particle information.
Float_t e
Definition: plot.C:35
Namespace collecting geometry-related classes utilities.
Tools and modules for checking out the basics of the Monte Carlo.
EventID id() const
Definition: Event.cc:23
art framework interface to geometry description
std::vector< int > num_refph
Event finding and building.
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const