LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
PhotonLibraryPropagation_module.cc
Go to the documentation of this file.
1 // Class: PhotonLibraryPropagation
3 // Plugin Type: producer (art v2_05_00)
4 // File: PhotonLibraryPropagation_module.cc
5 //
6 // Generated at Tue Mar 21 07:45:42 2017 by Wesley Ketchum using cetskelgen
7 // from cetlib version v1_21_00.
9 
17 #include "fhiclcpp/ParameterSet.h"
21 
22 #include <memory>
23 #include <iostream>
24 
28 
29 #include "CLHEP/Random/RandFlat.h"
30 #include "CLHEP/Random/RandPoissonQ.h"
31 
35 
40 
41 
42 namespace phot {
43  class PhotonLibraryPropagation;
44 }
45 
46 
48 public:
50  // The compiler-generated destructor is fine for non-base
51  // classes without bare pointers or other resource use.
52 
53  // Plugins should not be copied or assigned.
58 
59  // Required functions.
60  void produce(art::Event & e) override;
61 
62  // Selected optional functions.
63  void reconfigure(fhicl::ParameterSet const & p);
64  void beginJob() override;
65 
66 private:
67 
68  double fRiseTimeFast;
69  double fRiseTimeSlow;
71 
72  std::vector<art::InputTag> fEDepTags;
73 
75 
77 
78  double GetScintTime(double scint_time, double rise_time, double, double);
79 };
80 
81 
83 {
84  produces< std::vector<sim::SimPhotons> >();
85  art::ServiceHandle<rndm::NuRandomService>()->createEngine(*this, "HepJamesRandom", "photon", p, "SeedPhoton");
86  art::ServiceHandle<rndm::NuRandomService>()->createEngine(*this, "HepJamesRandom", "scinttime", p, "SeedScintTime");
87  this->reconfigure(p);
88 }
89 
91  detinfo::LArProperties const& larp)
92 {
93  double yieldRatio = larp.ScintYieldRatio();
94  if(larp.ScintByParticleType()){
95  switch(edep.PdgCode()) {
96  case 2212:
97  yieldRatio = larp.ProtonScintYieldRatio();
98  break;
99  case 13:
100  case -13:
101  yieldRatio = larp.MuonScintYieldRatio();
102  break;
103  case 211:
104  case -211:
105  yieldRatio = larp.PionScintYieldRatio();
106  break;
107  case 321:
108  case -321:
109  yieldRatio = larp.KaonScintYieldRatio();
110  break;
111  case 1000020040:
112  yieldRatio = larp.AlphaScintYieldRatio();
113  break;
114  case 11:
115  case -11:
116  case 22:
117  yieldRatio = larp.ElectronScintYieldRatio();
118  break;
119  default:
120  yieldRatio = larp.ElectronScintYieldRatio();
121  }
122  }
123  return yieldRatio;
124 }
125 
127 {
130  const detinfo::LArProperties* larp = lar::providerFrom<detinfo::LArPropertiesService>();
131 
133  CLHEP::HepRandomEngine &engine_photon = rng->getEngine("photon");
134  CLHEP::RandPoissonQ randpoisphot(engine_photon);
135  CLHEP::HepRandomEngine &engine_scinttime = rng->getEngine("scinttime");
136  CLHEP::RandFlat randflatscinttime(engine_scinttime);
137 
138  const size_t NOpChannels = pvs->NOpChannels();
139  double yieldRatio;
140  double nphot,nphot_fast,nphot_slow;
141 
142  //auto fSCE = lar::providerFrom<spacecharge::SpaceChargeService>();
143 
144  sim::OnePhoton photon;
145  photon.Energy = 9.7e-6;
146  photon.SetInSD = false;
147 
148  fISAlg.Initialize(larp,
149  lar::providerFrom<detinfo::DetectorPropertiesService>(),
150  &(*lgpHandle),
151  lar::providerFrom<spacecharge::SpaceChargeService>());
152 
153  std::unique_ptr< std::vector<sim::SimPhotons> > photCol ( new std::vector<sim::SimPhotons>);
154  auto & photonCollection(*photCol);
155 
156  //size_t edep_reserve_size=0;
157  std::vector< std::vector<sim::SimEnergyDeposit> const*> edep_vecs;
158  for(auto label : fEDepTags){
159  auto const& edep_handle = e.getValidHandle< std::vector<sim::SimEnergyDeposit> >(label);
160  edep_vecs.push_back(edep_handle);
161  //edep_reserve_size += edep_handle->size();
162  }
163 
164  for(size_t i_op=0; i_op<NOpChannels; ++i_op){
165  photonCollection.emplace_back(i_op);
166  }
167 
168  for(auto const& edeps : edep_vecs){
169 
170  for(auto const& edep : *edeps){
171  /*
172  std::cout << "Processing edep with trackID="
173  << edep.TrackID()
174  << " pdgCode="
175  << edep.PdgCode()
176  << " energy="
177  << edep.Energy()
178  << "(x,y,z)=("
179  << edep.X() << "," << edep.Y() << "," << edep.Z() << ")"
180  << std::endl;
181  */
182  double const xyz[3] = { edep.X(), edep.Y(), edep.Z() };
183 
184  photon.InitialPosition = TVector3(xyz[0],xyz[1],xyz[2]);
185 
186  float const* Visibilities = pvs->GetAllVisibilities(xyz);
187  if(!Visibilities)
188  continue;
189 
190  yieldRatio = GetScintYield(edep,*larp);
191  fISAlg.Reset();
194  nphot_fast = yieldRatio*nphot;
195 
196  photon.Time = edep.T() + GetScintTime(larp->ScintFastTimeConst(),fRiseTimeFast,
197  randflatscinttime(),randflatscinttime());
198  //std::cout << "\t\tPhoton fast time is " << photon.Time << " (" << edep.T() << " orig)" << std::endl;
199  for(size_t i_op=0; i_op<NOpChannels; ++i_op){
200  auto nph = randpoisphot.fire(nphot_fast*Visibilities[i_op]);
201  /*
202  std::cout << "\t\tHave " << nph << " fast photons ("
203  << Visibilities[i_op] << "*" << nphot_fast << " from " << nphot << ")"
204  << " for opdet " << i_op << std::endl;
205  //photonCollection[i_op].insert(photonCollection[i_op].end(),randpoisphot.fire(nphot_fast*Visibilities[i_op]),photon);
206  */
207  photonCollection[i_op].insert(photonCollection[i_op].end(),nph,photon);
208  }
209  if(fDoSlowComponent){
210  nphot_slow = nphot - nphot_fast;
211 
212  if(nphot_slow>0){
213  photon.Time = edep.T() + GetScintTime(larp->ScintSlowTimeConst(),fRiseTimeSlow,
214  randflatscinttime(),randflatscinttime());
215  //std::cout << "\t\tPhoton slow time is " << photon.Time << " (" << edep.T() << " orig)" << std::endl;
216  for(size_t i_op=0; i_op<NOpChannels; ++i_op){
217  auto nph = randpoisphot.fire(nphot_slow*Visibilities[i_op]);
218  //std::cout << "\t\tHave " << nph << " slow photons ("
219  // << Visibilities[i_op] << "*" << nphot_slow << " from " << nphot << ")"
220  // << " for opdet " << i_op << std::endl;
221  photonCollection[i_op].insert(photonCollection[i_op].end(),nph,photon);
222  }
223  }
224 
225  }//end doing slow component
226 
227  }//end loop over edeps
228  }//end loop over edep vectors
229 
230  e.put(std::move(photCol));
231 
232 }
233 
234 double phot::PhotonLibraryPropagation::GetScintTime(double scint_time, double rise_time,
235  double r1, double r2)
236 {
237  //no rise time
238  if(rise_time<0.0)
239  return -1 * scint_time * std::log(r1);
240 
241  while(1){
242  double t = -1.0*scint_time*std::log(1-r1);
243  //double g = (scint_time+rise_time)/scint_time * std::exp(-1.0*t/scint_time)/scint_time;
244  if ( r2 <= (std::exp(-1.0*t/rise_time)*(1-std::exp(-1.0*t/rise_time))/scint_time/scint_time*(scint_time+rise_time)) )
245  return -1 * t;
246  }
247 
248  return 1;
249 
250 }
251 
253 {
254  fRiseTimeFast = p.get<double>("RiseTimeFast",-1.0);
255  fRiseTimeSlow = p.get<double>("RiseTimeSlow",-1.0);
256  fDoSlowComponent = p.get<bool>("DoSlowComponent");
257 
258  fEDepTags = p.get< std::vector<art::InputTag> >("EDepModuleLabels");
259 }
260 
262 {
263 
264 }
265 
virtual double ElectronScintYieldRatio() const =0
Store parameters for running LArG4.
virtual double ScintYieldRatio() const =0
const std::string label
double GetScintTime(double scint_time, double rise_time, double, double)
virtual double AlphaScintYieldRatio() const =0
virtual double ScintSlowTimeConst() const =0
virtual double ScintFastTimeConst() const =0
virtual double ProtonScintYieldRatio() const =0
PhotonLibraryPropagation(fhicl::ParameterSet const &p)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
virtual double PionScintYieldRatio() const =0
contains objects relating to OpDet hits
void reconfigure(fhicl::ParameterSet const &p)
base_engine_t & createEngine(seed_t seed)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
void CalculateIonizationAndScintillation(sim::SimEnergyDeposit const &edep)
Double_t edep
Definition: macro.C:13
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
General LArSoft Utilities.
TVector3 InitialPosition
Definition: SimPhotons.h:49
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
contains information for a single step in the detector simulation
PhotonLibraryPropagation & operator=(PhotonLibraryPropagation const &)=delete
virtual double MuonScintYieldRatio() const =0
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
virtual double KaonScintYieldRatio() const =0
Float_t e
Definition: plot.C:34
virtual bool ScintByParticleType() const =0
double GetScintYield(sim::SimEnergyDeposit const &, detinfo::LArProperties const &)
art framework interface to geometry description
void Initialize(const detinfo::LArProperties *larp, const detinfo::DetectorProperties *detp, const sim::LArG4Parameters *lgp, const spacecharge::SpaceCharge *sce)