PhotonSystRewriter_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 // \author Christopher Backhouse - bckhouse@caltech.edu
3 ////////////////////////////////////////////////////////////////////////
4 
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:
40 
43 
45  };
46 
47  //............................................................
49  : fGeneratorProcessName(pset.get<std::string>("GeneratorProcessName")),
50  fGeantLabel(pset.get<std::string>("GeantLabel")),
51  fPhotonTransportLabel(pset.get<std::string>("PhotonTransportLabel")),
52  fPhotonsPerMeVShift (pset.get<double>("PhotonsPerMeVShift")),
53  fCerenkovEffShift (pset.get<double>("CerenkovEffShift")),
54  fXViewFactorShift (pset.get<double>("XViewFactorShift")),
55  fYViewFactorShift (pset.get<double>("YViewFactorShift"))
56  {
57  // Get the random number seed. Use a random default if not specified in the
58  // configuration file.
59  unsigned int seed = pset.get<unsigned int>("Seed", sim::GetRandomNumberSeed());
60  createEngine(seed);
61 
64 
65  produces<std::vector<sim::PhotonSignal>>();
66  }
67 
68  //............................................................
70  {
71  delete fPoisson;
72  }
73 
74  //............................................................
76  {
79  if(ps.is_empty()){
80  std::cout << "PhotonSystRewriter: Couldn't find original PhotonTransport parameter set under process name " << fGeneratorProcessName << std::endl;
81  abort();
82  }
83 
84  std::string detStr;
86  case novadaq::cnv::kNEARDET: detStr = "nd"; break;
87  case novadaq::cnv::kFARDET: detStr = "fd"; break;
88  default:
89  std::cout << "PhotonSystRewriter: Unknown detector." << std::endl;
90  abort();
91  }
92 
93  const fhicl::ParameterSet phot_pset =
94  ps.get<fhicl::ParameterSet>("physics")
95  .get<fhicl::ParameterSet>("producers")
97  .get<fhicl::ParameterSet>(detStr);
98 
99  const double photonsPerMeVOrig = phot_pset.get<double>("PhotonsPerMeV");
100  const double cerenkovEffOrig = phot_pset.get<double>("CerenkovEff");
101  const double xViewFactorOrig = phot_pset.get<double>("XViewFactor");
102  const double yViewFactorOrig = phot_pset.get<double>("YViewFactor");
103 
104  // The FLSHits that led to the original photons
106  evt.getByLabel(fGeantLabel, flslistHandle);
107 
108  // We want an accounting of how much of each deposit was cherenkov light
109  // and how much scintillation light.
110  struct DepositInfo
111  {
112  DepositInfo() : cherenkovPhots(0), birksGeV(0) {}
113  double cherenkovPhots, birksGeV;
114  };
115 
116  // As a function of cell in the detector and track ID
117  typedef std::pair<geo::OfflineChan, int> Key_t;
118 
119  std::map<Key_t, DepositInfo> deposits;
120 
121  for(const sim::FLSHitList& hitlist: *flslistHandle){
122  for(const sim::FLSHit& hit: hitlist.fHits){
123  const Key_t key(geo::OfflineChan(hit.GetPlaneID(), hit.GetCellID()),
124  hit.GetTrackID());
125 
126  DepositInfo& info = deposits[key];
127 
128  for(int step = 0; step < hit.GetNSteps(); ++step){
129  info.cherenkovPhots += hit.GetNCerenkov(step);
130  info.birksGeV += hit.GetEdepBirks(step);
131  } // end for step
132  } // end for ihit
133  } // end for ilist
134 
135  // The original photons that we'll modify
137  evt.getByLabel(fPhotonTransportLabel, phots);
138 
140 
141  // Our output photons
142  auto pscol = std::make_unique<std::vector<sim::PhotonSignal>>();
143 
144  for(const sim::PhotonSignal& phot: *phots){
145  const Key_t key(geo::OfflineChan(phot.Plane(), phot.Cell()),
146  phot.TrackId());
147 
148  auto it = deposits.find(key);
149  if(it == deposits.end()){
150  std::cout << "PhotonSystRewriter: Photon with no matching FLSHits!" << std::endl;
151  abort();
152  }
153 
154  const double nCherenkov = it->second.cherenkovPhots;
155  const double birksGeV = it->second.birksGeV;
156 
157  double ViewFactorOrig(0.0), ViewFactorNew(0.0);
158  if (fGeo->Plane(phot.Plane())->View() == geo::kX) {
159  ViewFactorOrig = xViewFactorOrig;
160  ViewFactorNew = ViewFactorOrig*(1.0 + fXViewFactorShift);
161  }
162  else {
163  ViewFactorOrig = yViewFactorOrig;
164  ViewFactorNew = ViewFactorOrig*(1.0 + fYViewFactorShift);
165  }
166 
167  double cerenkovEffNew = cerenkovEffOrig*(1.0 + fCerenkovEffShift);
168  double photonsPerMeVNew = photonsPerMeVOrig*(1.0 + fPhotonsPerMeVShift);
169 
170  // How many photons were made in the fiber originally
171  const double greenOrig = ViewFactorOrig*(cerenkovEffOrig*nCherenkov + 1000*photonsPerMeVOrig*birksGeV);
172 
173  // How many will be made by the new settings
174  const double greenNew = ViewFactorNew*(cerenkovEffNew*nCherenkov + 1000*photonsPerMeVNew*birksGeV);
175 
176  // Everything downstream of here is common between the two cases, so just
177  // scale the mean expected number of photons by the ratio.
178  const double newLambda = greenNew / greenOrig * phot.PoissonLambda();
179 
180  // Copy the old hit to the new hit but with new lambda and NPhoton
182  ps.SetTimeMean(phot.TimeMean());
183  ps.SetNPhoton(fPoisson->fire(newLambda));
184  ps.SetPlaneCell(phot.Plane(), phot.Cell());
185  ps.SetTrackId(phot.TrackId());
186  ps.SetPoissonLambda(newLambda);
187 
188  pscol->push_back(ps);
189  } // end for phot
190 
191  evt.put(std::move(pscol));
192  }
193 
195 } //namespace
void SetPoissonLambda(double l)
Definition: PhotonSignal.h:26
bool getProcessParameterSet(std::string const &processName, fhicl::ParameterSet &ps) const
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
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
int GetNSteps() const
Number of steps in FLSHit. Should be equal to GetNPoints() - 1.
Definition: FLSHit.h:63
Vertical planes which measure X.
Definition: PlaneGeo.h:28
base_engine_t & createEngine(seed_t seed)
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)
void SetPlaneCell(int plane, int cell)
Definition: PhotonSignal.h:24
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
base_engine_t & getEngine() const
Far Detector at Ash River, MN.
unsigned int seed
Definition: runWimpSim.h:102
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
Definition: View.py:1
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)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
int GetTrackID() const
Track ID.
Definition: FLSHit.h:45
A vector of FLSHit from single neutrino interaction.
Definition: FLSHitList.h:13
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Definition: structs.h:12
A (plane, cell) pair.
Definition: OfflineChan.h:17
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)