CMS 3D CMS Logo

HGCHEbackDigitizer.cc
Go to the documentation of this file.
2 
3 #include "CLHEP/Random/RandPoissonQ.h"
4 #include "CLHEP/Random/RandGaussQ.h"
5 
8 
9 #include "vdt/vdtMath.h"
10 
11 using namespace hgc_digi;
12 using namespace hgc_digi_utils;
13 
14 //
16 {
18  keV2MIP_ = cfg.getParameter<double>("keV2MIP");
19  this->keV2fC_ = 1.0; //keV2MIP_; // hack for HEB
20  noise_MIP_ = cfg.getParameter<edm::ParameterSet>("noise_MIP").getParameter<double>("value");
21  nPEperMIP_ = cfg.getParameter<double>("nPEperMIP");
22  nTotalPE_ = cfg.getParameter<double>("nTotalPE");
23  xTalk_ = cfg.getParameter<double>("xTalk");
24  sdPixels_ = cfg.getParameter<double>("sdPixels");
25 }
26 
27 //
28 void HGCHEbackDigitizer::runDigitizer(std::unique_ptr<HGCalDigiCollection> &digiColl,HGCSimHitDataAccumulator &simData,
29  const CaloSubdetectorGeometry* theGeom, const std::unordered_set<DetId>& validIds,
30  uint32_t digitizationType, CLHEP::HepRandomEngine* engine)
31 {
32  runCaliceLikeDigitizer(digiColl,simData,theGeom,validIds,engine);
33 }
34 
35 //
36 void HGCHEbackDigitizer::runCaliceLikeDigitizer(std::unique_ptr<HGCalDigiCollection> &digiColl,HGCSimHitDataAccumulator &simData,
37  const CaloSubdetectorGeometry* theGeom, const std::unordered_set<DetId>& validIds,
38  CLHEP::HepRandomEngine* engine)
39 {
40  //switch to true if you want to print some details
41  constexpr bool debug(false);
42 
43  HGCSimHitData chargeColl;
44 
45  // this represents a cell with no signal charge
46  HGCCellInfo zeroData;
47  zeroData.hit_info[0].fill(0.f); //accumulated energy
48  zeroData.hit_info[1].fill(0.f); //time-of-flight
49 
50  for( const auto& id : validIds ) {
51  chargeColl.fill(0.f);
52  HGCSimHitDataAccumulator::iterator it = simData.find(id);
53  HGCCellInfo& cell = ( simData.end() == it ? zeroData : it->second );
54  addCellMetadata(cell,theGeom,id);
55 
56  for(size_t i=0; i<cell.hit_info[0].size(); ++i)
57  {
58  //convert total energy keV->MIP, since converted to keV in accumulator
59  const float totalIniMIPs( cell.hit_info[0][i]*keV2MIP_ );
60  //std::cout << "energy in MIP: " << std::scientific << totalIniMIPs << std::endl;
61 
62  //generate random number of photon electrons
63  const uint32_t npe = std::floor(CLHEP::RandPoissonQ::shoot(engine,totalIniMIPs*nPEperMIP_));
64 
65  //number of pixels
66  const float x = vdt::fast_expf( -((float)npe)/nTotalPE_ );
67  uint32_t nPixel(0);
68  if(xTalk_*x!=1) nPixel=(uint32_t) std::max( nTotalPE_*(1.f-x)/(1.f-xTalk_*x), 0.f );
69 
70  //update signal
71  if(sdPixels_ != 0) nPixel = (uint32_t)std::max( CLHEP::RandGaussQ::shoot(engine,(double)nPixel,sdPixels_), 0. );
72 
73  //convert to MIP again and saturate
74  float totalMIPs(0.f), xtalk = 0.f;
75  const float peDiff = nTotalPE_ - (float) nPixel;
76  if (peDiff != 0.f) {
77  xtalk = (nTotalPE_-xTalk_*((float)nPixel)) / peDiff;
78  if( xtalk > 0.f && nPEperMIP_ != 0.f)
79  totalMIPs = (nTotalPE_/nPEperMIP_)*vdt::fast_logf(xtalk);
80  }
81 
82  //add noise (in MIPs)
83  chargeColl[i] = totalMIPs;
84  if(noise_MIP_ != 0) chargeColl[i] += std::max( CLHEP::RandGaussQ::shoot(engine,0.,noise_MIP_), 0. );
85  if(debug && cell.hit_info[0][i]>0)
86  std::cout << "[runCaliceLikeDigitizer] xtalk=" << xtalk << " En=" << cell.hit_info[0][i] << " keV -> " << totalIniMIPs << " raw-MIPs -> " << chargeColl[i] << " digi-MIPs" << std::endl;
87  }
88 
89  //init a new data frame and run shaper
90  HGCalDataFrame newDataFrame( id );
91  this->myFEelectronics_->runTrivialShaper( newDataFrame, chargeColl, 1 );
92 
93  //prepare the output
94  this->updateOutput(digiColl,newDataFrame);
95  }
96 }
97 
98 //
100 {
101 }
T getParameter(std::string const &) const
~HGCHEbackDigitizer() override
void updateOutput(std::unique_ptr< DColl > &coll, const HGCalDataFrame &rawDataFrame)
prepares the output according to the number of time samples to produce
void addCellMetadata(HGCCellInfo &info, const HcalGeometry *geom, const DetId &detid)
std::array< HGCSimHitData, 2 > hit_info
#define constexpr
std::array< HGCSimData_t, nSamples > HGCSimHitData
HGCHEbackDigitizer(const edm::ParameterSet &ps)
std::unordered_map< uint32_t, HGCCellInfo > HGCSimHitDataAccumulator
std::unique_ptr< HGCFEElectronics< HGCalDataFrame > > myFEelectronics_
double f[11][100]
#define debug
Definition: HDRShower.cc:19
void runCaliceLikeDigitizer(std::unique_ptr< HGCalDigiCollection > &digiColl, hgc::HGCSimHitDataAccumulator &simData, const CaloSubdetectorGeometry *theGeom, const std::unordered_set< DetId > &validIds, CLHEP::HepRandomEngine *engine)
float fast_expf(float x)
void runDigitizer(std::unique_ptr< HGCalDigiCollection > &digiColl, hgc::HGCSimHitDataAccumulator &simData, const CaloSubdetectorGeometry *theGeom, const std::unordered_set< DetId > &validIds, uint32_t digitizationType, CLHEP::HepRandomEngine *engine) override
to be specialized by top class
float fast_logf(float x)