MeanNpeFiller.cc
Go to the documentation of this file.
1 /*
2  For the simulation of threshold values. This module fills all the things FdElectronicsSimulator needs to run into an event.
3  \author Joachim Debatin
4 */
5 
6 #include "MeanNpeFiller.h"
7 
8 #include <utl/ErrorLogger.h>
9 #include <utl/Reader.h>
10 #include <utl/TimeStamp.h>
11 #include <utl/UTCDateTime.h>
12 #include <utl/TabulatedFunction.h>
13 #include <utl/MathConstants.h>
14 #include <utl/String.h>
15 
16 #include <fwk/CentralConfig.h>
17 
18 #include <evt/Event.h>
19 
20 #include <evt/DefaultShowerGeometryProducer.h>
21 
22 #include <fevt/FEvent.h>
23 #include <fevt/Eye.h>
24 #include <fevt/Telescope.h>
25 #include <fevt/TelescopeSimData.h>
26 #include <fevt/PixelSimData.h>
27 #include <fevt/Pixel.h>
28 
29 #include <det/Detector.h>
30 
31 #include <fdet/FDetector.h>
32 #include <fdet/Eye.h>
33 #include <fdet/Telescope.h>
34 #include <fdet/Pixel.h>
35 #include <fdet/Camera.h>
36 
37 using namespace MeanNpeFillerKG;
38 using namespace std;
39 using namespace utl;
40 using namespace fwk;
41 using namespace fevt;
42 using namespace det;
43 using namespace fdet;
44 
45 
48 {
49  Branch topB = CentralConfig::GetInstance()->GetTopBranch("MeanNpeFiller");
50 
51  fVerbosityLevel = 0;
52  if (topB.GetChild("verbosityLevel"))
53  topB.GetChild("verbosityLevel").GetData(fVerbosityLevel);
54 
55  if (topB.GetChild("Npe")) {
56  topB.GetChild("Npe").GetData(fNpe);
57  } else {
58  ostringstream info;
59  info <<"Npelevels must be set! Abort Simulation.";
60  ERROR(info);
61  return eFailure;
62  }
63 
64  if (topB.GetChild("NRuns"))
65  topB.GetChild("NRuns").GetData(fMaxRunNumber);
66  fRunNumber = 1;
67 
68  if (topB.GetChild("Eye"))
69  topB.GetChild("Eye").GetData(fEye);
70 
71  if (topB.GetChild("Tel"))
72  topB.GetChild("Tel").GetData(fTel);
73 
74  // the model config signature taken from TelescopeSimulatorKG
75  ostringstream configSS;
76  configSS << "TelescopeSimulatorKG";
77  if (false)//fDoNoShadow || fDoNoShadowSupport || fHasNoMercedes)
78  configSS << "(camera-shadow / support-shadow / mercedes) = ("
79  << (true ? "yes" : "no") << " / "
80  << (true ? "yes" : "no") << " / "
81  << (true ? "yes" : "no") << ")";
82  fGeneralConfigSignature = configSS.str();
83 
84  // info output
85  ostringstream info;
86  if (fVerbosityLevel) {
87  info << "verbosity level: " << fVerbosityLevel << "\n"
88  "Used Npe values: " << Join(" ", fNpe);
89  INFO(info);
90  }
91 
92  Detector::GetInstance().Update(UTCDateTime(2012,1,1,0,0,0).GetTimeStamp());
93 
94  return eSuccess;
95 }
96 
97 
100 {
101  if (fRunNumber > fMaxRunNumber){
102  ostringstream msg;
103  msg << "Reached maximum run number. Exit!";
104  INFO(msg);
105  return eBreakLoop;
106  }
107 
108  const double meanPe = fNpe[(fRunNumber-1) % fNpe.size()];
109 
110  if (fVerbosityLevel >= 1) {
111  ostringstream msg;
112  msg << "This is run number: " << fRunNumber << " meanPe = " << meanPe;
113  INFO(msg);
114  }
115 
116  ++fRunNumber;
117 
118  if (!event.HasSimShower())
119  event.MakeSimShower(evt::DefaultShowerGeometryProducer()); // ... pretty irrelevant
120 
121  if(!event.HasFEvent())
122  event.MakeFEvent();
123 
124  const Detector& detector = Detector::GetInstance();
125  const FDetector& detFD = detector.GetFDetector();
126 
127  FEvent& fEvent = event.GetFEvent();
128 
129  if (fVerbosityLevel >= 1) {
130  ostringstream msg;
131  msg << "Eye: "<< fEye <<" Tel: "<< fTel;
132  INFO(msg);
133  }
134 
135  fEvent.MakeEye(fEye);
136  fEvent.GetEye(fEye).MakeTelescope(fTel);
137  fevt::Telescope& telEvent = fEvent.GetEye(fEye).GetTelescope(fTel);
138 
139  // create configSignature see Init()
140  telEvent.MakeSimData();
141  fevt::TelescopeSimData& telSim = telEvent.GetSimData();
142  const fdet::Telescope& detTel = detFD.GetTelescope(telEvent);
143  telSim.SetConfigSignatureStr(detTel.GetConfigSignatureStr(fGeneralConfigSignature));
144 
145  //Needed to correct for scaling in ElectronicsSimulator
146  const double normWavelength = detFD.GetReferenceLambda();
147 
148  //create pixels and pixelSimData
149  for (unsigned int pixelId = 1; pixelId <= 440; ++pixelId) {
150  telEvent.MakePixel(pixelId);
151  telEvent.GetPixel(pixelId).MakeSimData();
152  fevt::Pixel& pix = telEvent.GetPixel(pixelId);
153  fevt::PixelSimData& pixSimData = pix.GetSimData();
154  const fdet::Pixel& detPixel = detFD.GetPixel(pix);
155  const TabulatedFunction& qEff = detPixel.GetQEfficiency();
156  const double qEffAtNormWavelength = qEff.Y(normWavelength);
157 
158  // Correct for scaling in ElectronicsSimulator
159  const double backphotons = meanPe / qEffAtNormWavelength;
160  pixSimData.SetMeanBgPhotonFlux(backphotons);
161  }
162 
163  return eSuccess;
164 }
Telescope & GetTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Telescope by Id, throw exception if not existent.
Definition: FEvent/Eye.cc:57
Branch GetTopBranch() const
Definition: Branch.cc:63
bool HasFEvent() const
const Pixel & GetPixel(const fevt::Pixel &eventPixel) const
Get fdet::Pixel from fevt::Channel.
Definition: FDetector.cc:198
Class to hold collection (x,y) points and provide interpolation between them.
bool HasSimShower() const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
PixelSimData & GetSimData()
Definition: FEvent/Pixel.h:35
void MakeEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Definition: FEvent.cc:115
const std::string & GetConfigSignatureStr(const std::string &module) const
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
void MakeTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Make Telescope telescopeId.
Definition: FEvent/Eye.cc:102
void MakeSimData()
Definition: FEvent/Pixel.cc:10
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
fwk::VModule::ResultFlag Init() override
Initialize: invoked at beginning of run (NOT beginning of event)
void SetMeanBgPhotonFlux(const double mean)
Set mean bg photon flux.
Definition: PixelSimData.h:135
void SetConfigSignatureStr(const std::string &configSignatureStr)
oss<< "0b";oss<< ((x >> i)&1);return oss.str();}template< class S, class V > std::string Join(const S &sep, const V &v)
Definition: String.h:60
void MakePixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Make Pixel telescopeId.
fevt::TelescopeSimData & GetSimData()
Description of simulated data for one Telescope.
Class representing a document branch.
Definition: Branch.h:107
fwk::VModule::ResultFlag Run(evt::Event &event) override
Run: invoked once per event.
Fluorescence Detector Pixel event.
Definition: FEvent/Pixel.h:28
const utl::TabulatedFunction & GetQEfficiency() const
Average quantum efficiency as a function of the wavelength.
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
const fdet::FDetector & GetFDetector() const
Definition: Detector.cc:131
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
Top of Fluorescence Detector event hierarchy.
Definition: FEvent.h:33
Eye & GetEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
return Eye by id
Definition: FEvent.cc:70
double GetReferenceLambda() const
Definition: FDetector.cc:332
Pixel & GetPixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Pixel by Id, throw exception if not existent.
Detector description interface for Telescope-related data.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
const Telescope & GetTelescope(const fevt::Telescope &eventTel) const
Get fdet::Telescope from fevt::Telescope.
Definition: FDetector.cc:150
Description of a pixel.
void MakeSimShower(const evt::VShowerGeometryProducer &p)
Fluorescence Detector Telescope Event.
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
Fluorescence Detector Pixel Simulated Data.
Definition: PixelSimData.h:28

, generated on Tue Sep 26 2023.