PhotonSystRewriter_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 // \author Christopher Backhouse - bckhouse@caltech.edu
3 ////////////////////////////////////////////////////////////////////////
4 
7 #include "art_root_io/TFileService.h"
11 #include "fhiclcpp/ParameterSet.h"
14 
16 #include "Geometry/Geometry.h"
18 #include "Simulation/FLSHitList.h"
20 #include "Simulation/Simulation.h"
21 
22 #include <map>
23 
24 namespace photrans
25 {
26  /// Modify already-simulated photons to alter the balance of Cerenkov and
27  /// scintillation light.
29  {
30  public:
31  explicit PhotonSystRewriter(const fhicl::ParameterSet& pset);
32  virtual ~PhotonSystRewriter();
33 
34  void produce(art::Event& evt);
35 
36  protected:
41 
44 
46  };
47 
48  //............................................................
50  : EDProducer(pset),
51  fEngine(createEngine(pset.get<unsigned int>("Seed", sim::GetRandomNumberSeed()))),
52  fGeneratorProcessName(pset.get<std::string>("GeneratorProcessName")),
53  fGeantLabel(pset.get<std::string>("GeantLabel")),
54  fPhotonTransportLabel(pset.get<std::string>("PhotonTransportLabel")),
55  fPhotonsPerMeVShift (pset.get<double>("PhotonsPerMeVShift")),
56  fCerenkovEffShift (pset.get<double>("CerenkovEffShift")),
57  fXViewFactorShift (pset.get<double>("XViewFactorShift")),
58  fYViewFactorShift (pset.get<double>("YViewFactorShift"))
59  {
61 
62  produces<std::vector<sim::PhotonSignal>>();
63  }
64 
65  //............................................................
67  {
68  delete fPoisson;
69  }
70 
71  //............................................................
73  {
76  if(ps.is_empty()){
77  std::cout << "PhotonSystRewriter: Couldn't find original PhotonTransport parameter set under process name " << fGeneratorProcessName << std::endl;
78  abort();
79  }
80 
81  std::string detStr;
83  case novadaq::cnv::kNEARDET: detStr = "nd"; break;
84  case novadaq::cnv::kFARDET: detStr = "fd"; break;
85  default:
86  std::cout << "PhotonSystRewriter: Unknown detector." << std::endl;
87  abort();
88  }
89 
90  const fhicl::ParameterSet phot_pset =
91  ps.get<fhicl::ParameterSet>("physics")
92  .get<fhicl::ParameterSet>("producers")
94  .get<fhicl::ParameterSet>(detStr);
95 
96  const double photonsPerMeVOrig = phot_pset.get<double>("PhotonsPerMeV");
97  const double cerenkovEffOrig = phot_pset.get<double>("CerenkovEff");
98  const double xViewFactorOrig = phot_pset.get<double>("XViewFactor");
99  const double yViewFactorOrig = phot_pset.get<double>("YViewFactor");
100 
101  // The FLSHits that led to the original photons
103  evt.getByLabel(fGeantLabel, flslistHandle);
104 
105  // We want an accounting of how much of each deposit was cherenkov light
106  // and how much scintillation light.
107  struct DepositInfo
108  {
109  DepositInfo() : cherenkovPhots(0), birksGeV(0) {}
110  double cherenkovPhots, birksGeV;
111  };
112 
113  // As a function of cell in the detector and track ID
114  typedef std::pair<geo::OfflineChan, int> Key_t;
115 
116  std::map<Key_t, DepositInfo> deposits;
117 
118  for(const sim::FLSHitList& hitlist: *flslistHandle){
119  for(const sim::FLSHit& hit: hitlist.fHits){
120  const Key_t key(geo::OfflineChan(hit.GetPlaneID(), hit.GetCellID()),
121  hit.GetTrackID());
122 
123  DepositInfo& info = deposits[key];
124 
125  for(int step = 0; step < hit.GetNSteps(); ++step){
126  info.cherenkovPhots += hit.GetNCerenkov(step);
127  info.birksGeV += hit.GetEdepBirks(step);
128  } // end for step
129  } // end for ihit
130  } // end for ilist
131 
132  // The original photons that we'll modify
134  evt.getByLabel(fPhotonTransportLabel, phots);
135 
137 
138  // Our output photons
139  auto pscol = std::make_unique<std::vector<sim::PhotonSignal>>();
140 
141  for(const sim::PhotonSignal& phot: *phots){
142  const Key_t key(geo::OfflineChan(phot.Plane(), phot.Cell()),
143  phot.TrackId());
144 
145  auto it = deposits.find(key);
146  if(it == deposits.end()){
147  std::cout << "PhotonSystRewriter: Photon with no matching FLSHits!" << std::endl;
148  abort();
149  }
150 
151  const double nCherenkov = it->second.cherenkovPhots;
152  const double birksGeV = it->second.birksGeV;
153 
154  double ViewFactorOrig(0.0), ViewFactorNew(0.0);
155  if (fGeo->Plane(phot.Plane())->View() == geo::kX) {
156  ViewFactorOrig = xViewFactorOrig;
157  ViewFactorNew = ViewFactorOrig*(1.0 + fXViewFactorShift);
158  }
159  else {
160  ViewFactorOrig = yViewFactorOrig;
161  ViewFactorNew = ViewFactorOrig*(1.0 + fYViewFactorShift);
162  }
163 
164  double cerenkovEffNew = cerenkovEffOrig*(1.0 + fCerenkovEffShift);
165  double photonsPerMeVNew = photonsPerMeVOrig*(1.0 + fPhotonsPerMeVShift);
166 
167  // How many photons were made in the fiber originally
168  const double greenOrig = ViewFactorOrig*(cerenkovEffOrig*nCherenkov + 1000*photonsPerMeVOrig*birksGeV);
169 
170  // How many will be made by the new settings
171  const double greenNew = ViewFactorNew*(cerenkovEffNew*nCherenkov + 1000*photonsPerMeVNew*birksGeV);
172 
173  // Everything downstream of here is common between the two cases, so just
174  // scale the mean expected number of photons by the ratio.
175  const double newLambda = greenNew / greenOrig * phot.PoissonLambda();
176 
177  // Copy the old hit to the new hit but with new lambda and NPhoton
179  ps.SetTimeMean(phot.TimeMean());
180  ps.SetNPhoton(fPoisson->fire(newLambda));
181  ps.SetPlaneCell(phot.Plane(), phot.Cell());
182  ps.SetTrackId(phot.TrackId());
183  ps.SetPoissonLambda(newLambda);
184 
185  pscol->push_back(ps);
186  } // end for phot
187 
188  evt.put(std::move(pscol));
189  }
190 
192 } //namespace
void SetPoissonLambda(double l)
Definition: PhotonSignal.h:26
const XML_Char XML_Encoding * info
Definition: expat.h:530
void SetTrackId(int t)
Definition: PhotonSignal.h:25
set< int >::iterator it
int GetPlaneID() const
Plane ID.
Definition: FLSHit.h:37
int GetCellID() const
Cell ID.
Definition: FLSHit.h:39
bool is_empty() const
int GetNSteps() const
Number of steps in FLSHit. Should be equal to GetNPoints() - 1.
Definition: FLSHit.h:63
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
Vertical planes which measure X.
Definition: PlaneGeo.h:28
float GetNCerenkov() const
Get total N Cerenkov photons.
Definition: FLSHit.h:35
A single unit of energy deposition in the liquid scintillator.
Definition: FLSHit.h:19
const PlaneGeo * Plane(unsigned int i) const
This slightly less simple photon transport uses a template for photon collection in time and in dista...
DEFINE_ART_MODULE(TestTMapFile)
bool getProcessParameterSet(std::string const &process, fhicl::ParameterSet &) const
void SetPlaneCell(int plane, int cell)
Definition: PhotonSignal.h:24
Far Detector at Ash River, MN.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
base_engine_t & createEngine(seed_t seed)
T get(std::string const &key) const
Definition: ParameterSet.h:231
int evt
Near Detector in the NuMI cavern.
void SetNPhoton(int npe)
Definition: PhotonSignal.h:23
Example routine for calculating the "ultimate e-m mother" of a particle in a simulated event...
Definition: FillTruth.h:16
float GetEdepBirks() const
Get total Energy with Birks suppression deposited into the cell for the whole FLSHit.
Definition: FLSHit.h:33
OStream cout
Definition: OStream.cxx:6
unsigned int GetRandomNumberSeed()
Definition: Simulation.cxx:13
PhotonSystRewriter(const fhicl::ParameterSet &pset)
int GetTrackID() const
Track ID.
Definition: FLSHit.h:45
A vector of FLSHit from single neutrino interaction.
Definition: FLSHitList.h:13
Definition: structs.h:12
A (plane, cell) pair.
Definition: OfflineChan.h:17
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:730
void SetTimeMean(double t)
Definition: PhotonSignal.h:22
Simple object representing a (plane, cell) pair.
Encapsulate the geometry of one entire detector (near, far, ndos)
enum BeamMode string