All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PhotonPropogationICARUS_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Class: PhotonPropogationICARUS
4 // Module Type: producer
5 // File: PhotonPropogationICARUS_module.cc
6 //
7 // The intent of this module is to modify the SimPhotons
8 // (e.g. to account for timing offsets)
9 //
10 // Configuration parameters:
11 //
12 // SimPhotonModuleLabel - the input source of the SimPhoton collection
13 //
14 //
15 // Created by Andrea Falcone (andrea.falcone@uta.edu) on June 19, 2018
16 //
17 ////////////////////////////////////////////////////////////////////////
18 
19 
20 // LArSoft libraries
24 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
26 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect::toPoint()
28 #include "nurandom/RandomUtils/NuRandomService.h"
29 
30 // framework libraries
31 #include "art/Framework/Services/Optional/RandomNumberGenerator.h"
32 #include "art/Framework/Core/EDProducer.h"
33 #include "art/Framework/Services/Registry/ServiceHandle.h"
34 #include "art_root_io/TFileService.h"
35 #include "art/Framework/Core/ModuleMacros.h"
36 #include "canvas/Utilities/InputTag.h"
37 // #include "art/Utilities/make_tool.h"
38 // #include "canvas/Persistency/Common/Ptr.h"
39 #include "messagefacility/MessageLogger/MessageLogger.h"
40 #include "fhiclcpp/ParameterSet.h"
41 
42 // CLHEP/ROOT libraries
43 // #include "CLHEP/Random/RandFlat.h"
44 // #include "CLHEP/Random/RandPoissonQ.h"
45 #include "CLHEP/Random/RandLandau.h"
46 
47 // C++ libraries
48 // #include <cmath>
49 // #include <algorithm>
50 #include <vector>
51 #include <memory> // std::make_unique()
52 
53 
54 class PhotonPropogationICARUS : public art::EDProducer
55 {
56 public:
57 
58  // Copnstructors, destructor.
59  explicit PhotonPropogationICARUS(fhicl::ParameterSet const & pset);
60 
61  // Overrides.
62  virtual void configure(fhicl::ParameterSet const & pset);
63  virtual void produce(art::Event & e) override;
64  virtual void beginJob() override;
65  virtual void endJob() override;
66 
67 private:
68 
69  // Fcl parameters.
70  art::InputTag fSimPhotonModuleLabel; ///< The full collection of SimPhotons
71 
72  // Statistics.
73  unsigned int fNumEvent = 0; ///< Number of events seen.
74 
75  // Useful services, keep copies for now (we can update during begin run periods)
76  geo::GeometryCore const* fGeometry = nullptr; ///< Pointer to Geometry service.
77  CLHEP::HepRandomEngine& fPhotonEngine;
78 
79  /// We don't keep more than this number of photons per `sim::SimPhoton`.
80  static constexpr unsigned int MaxPhotons = 10000000U;
81 
82 }; // class PhotonPropagationICARUS
83 
84 DEFINE_ART_MODULE(PhotonPropogationICARUS)
85 
86 //----------------------------------------------------------------------------
87 /// Constructor.
88 ///
89 /// Arguments:
90 ///
91 /// pset - Fcl parameters.
92 ///
94  : EDProducer{pset}, fGeometry(lar::providerFrom<geo::Geometry>())
95  , fPhotonEngine(art::ServiceHandle<rndm::NuRandomService>()->createEngine(*this, "HepJamesRandom", "icarusphoton", pset, "SeedPhoton"))
96 // , fDetectorProperties(lar::providerFrom<detinfo::DetectorPropertiesService>())
97 {
98  configure(pset);
99 
100  produces<std::vector<sim::SimPhotons>>();
101 
102  // Report.
103  mf::LogDebug("PhotonPropogationICARUS") << "PhotonPropogationICARUS configured";
104 } // PhotonPropagationICARUS::PhotonPropagationICARUS()
105 
106 //----------------------------------------------------------------------------
107 /// Reconfigure method.
108 ///
109 /// Arguments:
110 ///
111 /// pset - Fcl parameter set.
112 ///
113 void PhotonPropogationICARUS::configure(fhicl::ParameterSet const & pset)
114 {
115  fSimPhotonModuleLabel = pset.get<art::InputTag>("SimPhotonsModuleLabel");
116 }
117 
118 //----------------------------------------------------------------------------
119 /// Begin job method.
121 {
122  // Access ART's TFileService, which will handle creating and writing
123  // histograms and n-tuples for us.
124 // art::ServiceHandle<art::TFileService> tfs;
125 
126 // art::TFileDirectory dir = tfs->mkdir(Form("PhotonPropogation"));
127 
128  return;
129 }
130 
131 //----------------------------------------------------------------------------
132 /// Produce method.
133 ///
134 /// Arguments:
135 ///
136 /// evt - Art event.
137 ///
138 /// This is the primary method.
139 ///
140 void PhotonPropogationICARUS::produce(art::Event & event)
141 {
142  ++fNumEvent;
143 
144  /*
145  * In LArSoft, detected photons are organised optical channel by channel,
146  * each channel with its own sim::SimPhotons.
147  * Each channel contains individual information for each of the photons
148  * it has detected.
149  * Here we go through all detected photons from all the channels,
150  * and for each we assign a delay to the start time, parametrized by the
151  * distance between its generation point and the PMT.
152  *
153  */
154  // Agreed convention is to ALWAYS output to the event store so get a pointer to our collection
155  auto simPhotonVec = std::make_unique<std::vector<sim::SimPhotons>>();
156 
157  // Read in the digit List object(s).
158  auto const& srcSimPhotons
159  = *(event.getValidHandle< std::vector<sim::SimPhotons> >(fSimPhotonModuleLabel));
160 
161  if (srcSimPhotons.empty()) {
162  mf::LogWarning("PhotonPropagationICARUS") << "No photons! Nice event you have here.";
163  event.put(std::move(simPhotonVec));
164  return;
165  }
166 
167  // get hold of all needed services
168 // auto const& pvs = *(art::ServiceHandle<phot::PhotonVisibilityService>());
169  CLHEP::RandLandau landauGen(fPhotonEngine);
170 
171  // Loop through the input photons (this might need to be more complicated...)
172  for(const auto& simPhoton : srcSimPhotons)
173  {
174  auto const channel = simPhoton.OpChannel();
175  if (simPhoton.empty()) continue;
176 
177  auto const& PMTcenter = fGeometry->OpDetGeoFromOpChannel(channel).GetCenter();
178 
179  // TODO restore the "MF_LOG_TRACE" line for normal operations
180  // (MF_LOG_TRACE will print only in debug mode, with debug qualifiers and proper messagefacility settings)
181  // MF_LOG_TRACE("LightPropagationICARUS")
182 // mf::LogVerbatim("LightPropagationICARUS")
183 // << "Processing photon channel #" << channel << ", detector center: " << PMTcenter;
184  //
185  // fix the arrival time
186  //
187  sim::SimPhotons localPhoton = simPhoton; // modify a copy of the original photon
188  unsigned int photonNo = 0;
189  for (auto& onePhoton: localPhoton)
190  {
191  //
192  // sanity check: if there are too many photons we are in trouble
193  // (like in: not enough computing resources)
194  //
195  if (photonNo++ >= MaxPhotons) {
196  mf::LogError("LightPropagationICARUS")
197  << "Too many photons to handle! only " << (photonNo - 1) << " saved.";
198  break;
199  }
200 
201  geo::Point_t const position = geo::vect::toPoint(onePhoton.InitialPosition);
202  double const dis = (position - PMTcenter).R();
203 
204  double mean = 0.18*dis; // TODO
205  double sigma = 0.75*dis; // TODO
206 
207  //double time_plus = -1;
208 
209  //while (time_plus<dis/21.74){time_plus=mean + landauGen.fire() * sigma; }// TODO
210 
211  const double minPropTime = dis / 21.74; // d / (c/n) in [ns]
212  //const double maxPropTime = 2000 / 21.74; // dimension / (c/n) in [ns]
213  double time_plus;
214  do {
215  time_plus = mean + landauGen.fire() * sigma; // TODO
216  //time_plus = landauGen.fire(mean,sigma); // TODO
217  } while (time_plus < minPropTime);
218 
219  // TODO restore the "MF_LOG_TRACE" line for normal operations
220  MF_LOG_TRACE("LightPropagationICARUS");
221 // mf::LogVerbatim("LightPropagationICARUS")
222 // << "Photon #" << photonNo
223 // << " (at " << position << ", " << dis << " cm far from PMT) given offset "
224 // << time_plus;
225  //double time_plus = dis/21.74;
226  //TRandom r;
227 
228  onePhoton.Time += time_plus;
229  //onePhoton.Time = time_plus;
230 
231  } // for photons in simPhoton
232  // move the photon with the new arrival time into the new output collection
233  simPhotonVec->push_back(std::move(localPhoton));
234  } // for all simPhoton channels
235 
236  // Add tracks and associations to event.
237  event.put(std::move(simPhotonVec));
238 
239 } // LightPropagationICARUS::produce()
240 
241 //----------------------------------------------------------------------------
242 /// End job method.
244 {
245  mf::LogInfo("PhotonPropogationICARUS") << "Looked at " << fNumEvent << " events" << std::endl;
246 }
virtual void produce(art::Event &e) override
Utilities related to art service access.
static constexpr unsigned int MaxPhotons
We don&#39;t keep more than this number of photons per sim::SimPhoton.
virtual void endJob() override
End job method.
geo::GeometryCore const * fGeometry
Pointer to Geometry service.
::geo::Point_t toPoint(Point const &p)
Convert the specified point into a geo::Point_t.
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:40
PhotonPropogationICARUS(fhicl::ParameterSet const &pset)
Simulation objects for optical detectors.
unsigned int fNumEvent
Number of events seen.
CLHEP::HepRandomEngine & fPhotonEngine
art::InputTag fSimPhotonModuleLabel
The full collection of SimPhotons.
Utilities to extend the interface of geometry vectors.
Description of geometry of one entire detector.
Encapsulate the geometry of an optical detector.
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:136
do i e
virtual void configure(fhicl::ParameterSet const &pset)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
OpDetGeo const & OpDetGeoFromOpChannel(unsigned int OpChannel) const
Returns the geo::OpDetGeo object for the given channel number.
art framework interface to geometry description
virtual void beginJob() override
Begin job method.