FrontEndSiPM.cc
Go to the documentation of this file.
1 #include <mdet/FrontEndSiPM.h>
2 
3 #include <mdet/SiPM.h>
4 #include <mdet/MHierarchyInfo.h>
5 #include <fwk/RandomEngineRegistry.h>
6 #include <CLHEP/Random/RandGauss.h>
7 #include <CLHEP/Random/RandFlat.h>
8 
9 #include <sstream>
10 #include <iostream>
11 #include <bitset>
12 #include <iomanip>
13 
14 using std::endl;
15 using std::cout;
16 
17 namespace mdet {
18 
19  const char* const
21 
22  const char* const
24 
26  (int fId, const det::VManager::IndexMap& parentMap, const Module& parent) :
28  fChannels(*this),
29  fModule(parent)
30  {
31  Register(fMeanSampleRatePeriod);
32  Register(fPreT1BufferLength);
33  Register(fPostT1BufferLength);
34  Register(fTrueRangeLowThreshold);
35  Register(fFalseRangeHiThreshold);
36  Register(fSampleTimeADC);
37  Register(fStepADC);
38  Register(fBaseLineFluctuationLG);
39  Register(fBaseLineFluctuationHG);
40  Register(fDelayBinaryADCMean);
41  Register(fDelayBinaryADCSigma);
42  fChannels.Update(GetIdsMap());
43  }
44 
45  const Module&
47  const
48  {
49  return fModule;
50  }
51 
52  double
54  const
55  {
56  return GetData(fMeanSampleRatePeriod, "meanSampleRatePeriod");
57  }
58 
59 
60  unsigned int
62  const
63  {
64 
65  return GetData(fPreT1BufferLength, "preT1BufferLength");
66  }
67 
68  unsigned int
70  const
71  {
72  return GetData(fPostT1BufferLength, "postT1BufferLength");
73  }
74 
75  double
77  const
78  {
79  return GetData(fTrueRangeLowThreshold, "trueRangeLowThreshold");
80  }
81 
82  double
84  const
85  {
86  return GetData(fFalseRangeHiThreshold, "falseRangeHiThreshold");
87  }
88 
89  double
91  const
92  {
93  return GetData(fSampleTimeADC, "sampleTimeADC");
94  }
95 
96  double
98  const
99  {
100  return GetData(fStepADC, "stepADC");
101  }
102 
103  double
105  const
106  {
107  return GetData(fDelayBinaryADCMean, "delayBinaryADCMean");
108  }
109 
110  double
112  const
113  {
114  return GetData(fDelayBinaryADCSigma, "delayBinaryADCSigma");
115  }
116 
117  double
119  const
120  {
121  return GetData(fBaseLineFluctuationLG, "baseLineFluctuationLG");
122  }
123  double
125  const
126  {
127  return GetData(fBaseLineFluctuationHG, "baseLineFluctuationHG");
128  }
129  double
131  const
132  {
133  return GetData(fDigitalBackGroundProbability, "digitalBackGroundProbability");
134  }
135 
136  double
138  const
139  {
140  return GetData(fDigitalBackGroundWidthMean, "digitalBackGroundWidthMean");
141  }
142  double
144  const
145  {
146  return GetData(fDigitalBackGroundWidthStdDev, "digitalBackGroundWidthStdDev");
147  }
148 
151  const
152  {
153  // Note that's shared: so once initialized no further loading
154  // will be done.
155  return GetData<BrokenChannelContainer,utl::ThrowOnZeroDereference,utl::ShadowPtr>(fBrokenChannels, "channelsBroken");
156  }
157 
158  ULong64_t
160  const
161  {
162  std::ostringstream msg;
163 
164  ULong64_t mask = 0;
165 
166  std::bitset<64> bit_mask;
167  bit_mask.reset();//sets all bits to zero
168 
169  msg.str("");
170  const BrokenChannelContainer * channels = 0;
171  channels = & GetBrokenChannels();
172 
173  for ( BrokenChannelContainer::const_iterator chIt = channels->begin(), chIte = channels->end();
174  chIt != chIte; ++chIt ){
175  msg << *chIt << " " ;
176  bit_mask.set(*chIt);//set channel X to one
177  mask |= ULong64_t(1) << *chIt;
178  }
179  msg << std::endl;
180 
181  msg << "MD MASK -- " << std::setw( 10 ) << std::setfill(' ')
182  << bit_mask << " "
183  << " ==> (" << bit_mask.count() << ")\n";
184  msg << "mask in decimal: " << std::endl;
185  msg << mask << std::endl;
186 
187  return mask;
188  }
189 
190  double
192  const
193  {
194  utl::RandomEngine& rnd = fwk::RandomEngineRegistry::GetInstance().Get(fwk::RandomEngineRegistry::eDetector);
195 
196  return CLHEP::RandGauss::shoot(& rnd.GetEngine(), GetDelayBinaryADCMean(), GetDelayBinaryADCSigma());
197  }
198 
199 
200  unsigned short
202  const
203  {
204  unsigned short counts = (value/GetStepADC() + 0.5);
205  return counts;
206  }
207 
208  unsigned short
210  const
211  {
212  utl::RandomEngine& rnd = fwk::RandomEngineRegistry::GetInstance().Get(fwk::RandomEngineRegistry::eDetector);
213 
214  return CLHEP::RandGauss::shoot(& rnd.GetEngine(), 0.0, GetBaseLineFluctuationLG());
215  }
216 
217  unsigned short
219  const
220  {
221  utl::RandomEngine& rnd = fwk::RandomEngineRegistry::GetInstance().Get(fwk::RandomEngineRegistry::eDetector);
222 
223  return CLHEP::RandGauss::shoot(& rnd.GetEngine(), 0.0, GetBaseLineFluctuationHG());
224  }
225 
226  /*unsigned short FrontEndSiPM::GetADCBaseLineOffsetLG()
227  const
228  {
229  return (fModule.GetBackEnd().GetLowGainAmplifierOffset()/GetStepADC()+0.5);
230  }
231  unsigned short FrontEndSiPM::GetADCBaseLineOffsetHG()
232  const
233  {
234  return (fModule.GetBackEnd().GetHighGainAmplifierOffset()/GetStepADC()+0.5);
235  }*/
236 
237  short
239  const{
240 
241  utl::RandomEngine& rnd = fwk::RandomEngineRegistry::GetInstance().Get(fwk::RandomEngineRegistry::eDetector);
242  double chance = CLHEP::RandFlat::shoot(& rnd.GetEngine(), 0, 1.0);
243  short bin = -1;
244  if(chance <= GetDigitalBackGroundProbability()){
245  bin = CLHEP::RandFlat::shoot(& rnd.GetEngine(), 0, (GetPreT1BufferLength() + GetPostT1BufferLength())-1.0);
246  }
247  return bin;
248  }
249 
250  unsigned short
252  const{
253  utl::RandomEngine& rnd = fwk::RandomEngineRegistry::GetInstance().Get(fwk::RandomEngineRegistry::eDetector);
254  return CLHEP::RandGauss::shoot(& rnd.GetEngine(), GetDigitalBackGroundWidthMean(), GetDigitalBackGroundWidthStdDev());
255  }
256 
257  unsigned short
259  const{
260 
261  utl::RandomEngine& rnd = fwk::RandomEngineRegistry::GetInstance().Get(fwk::RandomEngineRegistry::eDetector);
262  return CLHEP::RandFlat::shoot(& rnd.GetEngine(), 0, fChannels.GetNumberOfComponents());
263  }
264 
265 
268  const
269  {
270  return Sampler(*this);
271  }
272 
274  fLastSample(false), // Take as false the non-existing previous sample
275  fFrontEndSiPM(fe)
276  {
277  }
278 
279  bool
281  {
282  // Note that we use both comps with =, tough, if both
283  // limits coincide, we are privileging one of them
284  // (the first we are comparing with).
285  bool ret;
286  if (v >= fFrontEndSiPM.GetTrueRangeLowThreshold())
287  ret = true;
288  else if (v <= fFrontEndSiPM.GetFalseRangeHiThreshold())
289  ret = false;
290  else
291  ret = fLastSample;
292  // Keep this as the new last sample.
293  fLastSample = ret;
294  return ret;
295  }
296 
297  void
298  FrontEndSiPM::Update(bool invalidateData, bool invalidateComponents)
299  {
300  MDetectorComponent<FrontEndSiPM>::Type::Update(invalidateData, invalidateComponents);
301  fChannels.Update(GetIdsMap(), invalidateData, invalidateComponents);
302  if ( invalidateData )
303  fBrokenChannels = 0;
304  }
305 
306 }
double GetDigitalBackGroundProbability() const
Noise in digital channel.
utl::Validated< double > fDigitalBackGroundWidthStdDev
Definition: FrontEndSiPM.h:330
std::vector< int > BrokenChannelContainer
Definition: FrontEndSiPM.h:77
double GetDelayBinaryADCMean() const
Delay between the binary trace and the ADC traces.
double GetSampleTimeADC() const
ADC Sample Time and delay.
Definition: FrontEndSiPM.cc:90
double GetDigitalBackGroundWidthMean() const
void Update(bool invalidateData, bool invalidateComponents)
Forward to channels and to base-class.
utl::Validated< double > fDigitalBackGroundProbability
Definition: FrontEndSiPM.h:328
RandomEngineType & GetEngine()
Definition: RandomEngine.h:32
double GetStepADC() const
ADC resolution.
Definition: FrontEndSiPM.cc:97
short GetInjectDigitalNoiseBin() const
unsigned short GetADCBaseLineFluctuationLG() const
Noise injection for binary and ADC channels.
static const char *const kComponentName
Definition: FrontEndSiPM.h:73
static const char *const kComponentsNames[13]
utl::Validated< double > fBaseLineFluctuationHG
Definition: FrontEndSiPM.h:326
double GetTrueRangeLowThreshold() const
Low end-point of the range where the voltage is taken as a true-value by the FPGA sampling proccess...
Definition: FrontEndSiPM.cc:76
det::DetectorComponent< C, MManagerProvider > Type
Type specializing det::DetectorComponent for Muon hierarchy.
utl::Validated< double > fDelayBinaryADCSigma
Definition: FrontEndSiPM.h:318
unsigned short GetInjectDigitalNoiseWidth() const
double GetBaseLineFluctuationHG() const
ChannelGroup fChannels
Definition: FrontEndSiPM.h:292
void Update(std::vector< double > &init, const std::vector< double > &res)
Definition: Util.h:100
utl::Validated< double > fFalseRangeHiThreshold
Definition: FrontEndSiPM.h:311
static const char *const kComponentsIds[13]
double GetDelayBinaryADC() const
Encapsulates the sampling logic.
Definition: FrontEndSiPM.h:53
Sampler MakeSampler() const
Create a new sampler object.
utl::Validated< double > fDelayBinaryADCMean
Definition: FrontEndSiPM.h:317
const VManager::IndexMap & GetIdsMap() const
The id identifying this component within its detector hierarhy.
T & GetData(P< T > &d, const std::string &p) const
Common utility function for configuration.
Electronic front-end for the modules.
Definition: FrontEndSiPM.h:35
double GetBaseLineFluctuationLG() const
utl::Validated< double > fStepADC
Definition: FrontEndSiPM.h:316
FrontEndSiPM(int fId, const det::VManager::IndexMap &parentMap, const Module &parent)
Constructs the electronic front-end.
Definition: FrontEndSiPM.cc:26
Sampler(const FrontEndSiPM &fe)
Construct with the associated FrontEndSiPM.
Wraps the random number engine used to generate distributions.
Definition: RandomEngine.h:27
utl::Validated< double > fBaseLineFluctuationLG
Definition: FrontEndSiPM.h:325
utl::Validated< double > fDigitalBackGroundWidthMean
Definition: FrontEndSiPM.h:329
Array of Scintillator.
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
Definition: FrontEndSiPM.cc:53
ULong64_t GetMask() const
Size of the (cyclic) external memory buffer associated to each module.
unsigned int GetPreT1BufferLength() const
Number of bins of the (cyclic) pre-T1 buffer.
Definition: FrontEndSiPM.cc:61
utl::ShadowPtr< BrokenChannelContainer > fBrokenChannels
Definition: FrontEndSiPM.h:313
unsigned int GetPostT1BufferLength() const
Number of bins of the post-T1 buffer.
Definition: FrontEndSiPM.cc:69
const Module & fModule
Definition: FrontEndSiPM.h:332
bool operator()(double v)
Digitally sample the voltage.
const BrokenChannelContainer & GetBrokenChannels() const
List of broken channels.
utl::Validated< double > fSampleTimeADC
Definition: FrontEndSiPM.h:315
double GetDelayBinaryADCSigma() const
double GetDigitalBackGroundWidthStdDev() const
unsigned short GetADCCounts(double value) const
utl::Validated< int > fPreT1BufferLength
Definition: FrontEndSiPM.h:303
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
static const char *const kComponentId
Definition: FrontEndSiPM.h:75
double GetFalseRangeHiThreshold() const
Hi end-point of the range where the voltage is taken as a false-value by the FPGA sampling process...
Definition: FrontEndSiPM.cc:83
unsigned short GetADCBaseLineFluctuationHG() const
const Module & GetModule() const
The module to which this FrontEndSiPM belongs.
Definition: FrontEndSiPM.cc:46
utl::Validated< double > fMeanSampleRatePeriod
Definition: FrontEndSiPM.h:294
utl::Validated< double > fTrueRangeLowThreshold
Definition: FrontEndSiPM.h:309
unsigned short GetInjectDigitalNoiseChannel() const
utl::Validated< int > fPostT1BufferLength
Definition: FrontEndSiPM.h:305

, generated on Tue Sep 26 2023.