test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HGCHEbackDigitizer.cc
Go to the documentation of this file.
2 
3 #include "CLHEP/Random/RandPoissonQ.h"
4 #include "CLHEP/Random/RandGaussQ.h"
5 
6 #include "vdt/vdtMath.h"
7 
8 using namespace hgc_digi;
9 
10 //
12 {
14  keV2MIP_ = cfg.getParameter<double>("keV2MIP");
15  keV2fC_ = 1.0; //keV2MIP_; // hack for HEB
16  noise_MIP_ = cfg.getParameter<double>("noise_MIP");
17  nPEperMIP_ = cfg.getParameter<double>("nPEperMIP");
18  nTotalPE_ = cfg.getParameter<double>("nTotalPE");
19  xTalk_ = cfg.getParameter<double>("xTalk");
20  sdPixels_ = cfg.getParameter<double>("sdPixels");
21 }
22 
23 //
24 void HGCHEbackDigitizer::runDigitizer(std::auto_ptr<HGCHEDigiCollection> &digiColl,HGCSimHitDataAccumulator &simData,uint32_t digitizationType, CLHEP::HepRandomEngine* engine)
25 {
26  runCaliceLikeDigitizer(digiColl,simData,engine);
27 }
28 
29 //
30 void HGCHEbackDigitizer::runCaliceLikeDigitizer(std::auto_ptr<HGCHEDigiCollection> &digiColl,HGCSimHitDataAccumulator &simData, CLHEP::HepRandomEngine* engine)
31 {
32 
33  //switch to true if you want to print some details
34  constexpr bool debug(false);
35 
36  HGCSimHitData chargeColl;
37  for(HGCSimHitDataAccumulator::iterator it=simData.begin();
38  it!=simData.end();
39  it++)
40  {
41  chargeColl.fill(0.f);
42  for(size_t i=0; i<it->second[0].size(); ++i)
43  {
44  //convert total energy keV->MIP, since converted to keV in accumulator
45  float totalIniMIPs( (it->second)[0][i]*keV2MIP_ );
46  //std::cout << "energy in MIP: " << std::scientific << totalIniMIPs << std::endl;
47 
48  //generate random number of photon electrons
49  uint32_t npe = std::floor(CLHEP::RandPoissonQ::shoot(engine,totalIniMIPs*nPEperMIP_));
50 
51  //number of pixels
52  float x = vdt::fast_expf( -((float)npe)/nTotalPE_ );
53  uint32_t nPixel(0);
54  if(xTalk_*x!=1) nPixel=(uint32_t) std::max( nTotalPE_*(1.f-x)/(1.f-xTalk_*x), 0.f );
55 
56  //update signal
57  nPixel = (uint32_t)std::max( CLHEP::RandGaussQ::shoot(engine,(double)nPixel,sdPixels_), 0. );
58 
59  //convert to MIP again and saturate
60  float totalMIPs(totalIniMIPs);
61  const float xtalk = (nTotalPE_-xTalk_*((float)nPixel))/(nTotalPE_-((float)nPixel));
62  if( nTotalPE_ != nPixel && xtalk > 0. )
63  totalMIPs = (nTotalPE_/nPEperMIP_)*vdt::fast_logf(xtalk);
64  else
65  totalMIPs = 0.f;
66 
67  //add noise (in MIPs)
68  chargeColl[i] = totalMIPs+std::max( CLHEP::RandGaussQ::shoot(engine,0.,noise_MIP_), 0. );
69  if(debug && (it->second)[0][i]>0)
70  std::cout << "[runCaliceLikeDigitizer] xtalk=" << xtalk << " En=" << (it->second)[0][i] << " keV -> " << totalIniMIPs << " raw-MIPs -> " << chargeColl[i] << " digi-MIPs" << std::endl;
71  }
72 
73  //init a new data frame and run shaper
74  HGCHEDataFrame newDataFrame( it->first );
75  myFEelectronics_->runTrivialShaper( newDataFrame, chargeColl );
76 
77  //prepare the output
78  updateOutput(digiColl,newDataFrame);
79  }
80 }
81 
82 //
84 {
85 }
86 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:293
#define constexpr
std::array< HGCSimData_t, nSamples > HGCSimHitData
HGCHEbackDigitizer(const edm::ParameterSet &ps)
std::unique_ptr< HGCFEElectronics< HGCHEDataFrame > > myFEelectronics_
double f[11][100]
void updateOutput(std::auto_ptr< DColl > &coll, const HGCHEDataFrame &rawDataFrame)
prepares the output according to the number of time samples to produce
#define debug
Definition: HDRShower.cc:19
void runCaliceLikeDigitizer(std::auto_ptr< HGCHEDigiCollection > &digiColl, hgc::HGCSimHitDataAccumulator &simData, CLHEP::HepRandomEngine *engine)
float fast_expf(float x)
tuple cout
Definition: gather_cfg.py:145
void runDigitizer(std::auto_ptr< HGCHEDigiCollection > &digiColl, hgc::HGCSimHitDataAccumulator &simData, uint32_t digitizationType, CLHEP::HepRandomEngine *engine)
std::unordered_map< uint32_t, std::array< HGCSimHitData, 2 > > HGCSimHitDataAccumulator
float fast_logf(float x)