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 
13 namespace {
14  void addCellMetadata(HGCCellInfo& info,
15  const HcalGeometry* geom,
16  const DetId& detid ) {
17  //base time samples for each DetId, initialized to 0
18  info.size = 1.0;
19  info.thickness = 1.0;
20  }
21 
22  void addCellMetadata(HGCCellInfo& info,
23  const HGCalGeometry* geom,
24  const DetId& detid ) {
25  const auto& topo = geom->topology();
26  const auto& dddConst = topo.dddConstants();
27  uint32_t id(detid.rawId());
28  int waferTypeL = 0;
29  bool isHalf = false;
30  HGCalDetId hid(id);
31  int wafer = HGCalDetId(id).wafer();
32  waferTypeL = dddConst.waferTypeL(wafer);
33  isHalf = dddConst.isHalfCell(wafer,hid.cell());
34  //base time samples for each DetId, initialized to 0
35  info.size = (isHalf ? 0.5 : 1.0);
36  info.thickness = waferTypeL;
37  }
38 
39  void addCellMetadata(HGCCellInfo& info,
40  const CaloSubdetectorGeometry* geom,
41  const DetId& detid ) {
42  if( DetId::Hcal == detid.det() ) {
43  const HcalGeometry* hc = static_cast<const HcalGeometry*>(geom);
44  addCellMetadata(info,hc,detid);
45  } else {
46  const HGCalGeometry* hg = static_cast<const HGCalGeometry*>(geom);
47  addCellMetadata(info,hg,detid);
48  }
49  }
50 
51 }
52 
53 //
55 {
57  keV2MIP_ = cfg.getParameter<double>("keV2MIP");
58  keV2fC_ = 1.0; //keV2MIP_; // hack for HEB
59  noise_MIP_ = cfg.getParameter<double>("noise_MIP");
60  nPEperMIP_ = cfg.getParameter<double>("nPEperMIP");
61  nTotalPE_ = cfg.getParameter<double>("nTotalPE");
62  xTalk_ = cfg.getParameter<double>("xTalk");
63  sdPixels_ = cfg.getParameter<double>("sdPixels");
64 }
65 
66 //
67 void HGCHEbackDigitizer::runDigitizer(std::unique_ptr<HGCBHDigiCollection> &digiColl,HGCSimHitDataAccumulator &simData,
68  const CaloSubdetectorGeometry* theGeom, const std::unordered_set<DetId>& validIds,
69  uint32_t digitizationType, CLHEP::HepRandomEngine* engine)
70 {
71  runCaliceLikeDigitizer(digiColl,simData,theGeom,validIds,engine);
72 }
73 
74 //
75 void HGCHEbackDigitizer::runCaliceLikeDigitizer(std::unique_ptr<HGCBHDigiCollection> &digiColl,HGCSimHitDataAccumulator &simData,
76  const CaloSubdetectorGeometry* theGeom, const std::unordered_set<DetId>& validIds,
77  CLHEP::HepRandomEngine* engine)
78 {
79  //switch to true if you want to print some details
80  constexpr bool debug(false);
81 
82  HGCSimHitData chargeColl;
83 
84  // this represents a cell with no signal charge
85  HGCCellInfo zeroData;
86  zeroData.hit_info[0].fill(0.f); //accumulated energy
87  zeroData.hit_info[1].fill(0.f); //time-of-flight
88 
89  for( const auto& id : validIds ) {
90  chargeColl.fill(0.f);
91  HGCSimHitDataAccumulator::iterator it = simData.find(id);
92  HGCCellInfo& cell = ( simData.end() == it ? zeroData : it->second );
93  addCellMetadata(cell,theGeom,id);
94 
95  for(size_t i=0; i<cell.hit_info[0].size(); ++i)
96  {
97  //convert total energy keV->MIP, since converted to keV in accumulator
98  const float totalIniMIPs( cell.hit_info[0][i]*keV2MIP_ );
99  //std::cout << "energy in MIP: " << std::scientific << totalIniMIPs << std::endl;
100 
101  //generate random number of photon electrons
102  const uint32_t npe = std::floor(CLHEP::RandPoissonQ::shoot(engine,totalIniMIPs*nPEperMIP_));
103 
104  //number of pixels
105  const float x = vdt::fast_expf( -((float)npe)/nTotalPE_ );
106  uint32_t nPixel(0);
107  if(xTalk_*x!=1) nPixel=(uint32_t) std::max( nTotalPE_*(1.f-x)/(1.f-xTalk_*x), 0.f );
108 
109  //update signal
110  nPixel = (uint32_t)std::max( CLHEP::RandGaussQ::shoot(engine,(double)nPixel,sdPixels_), 0. );
111 
112  //convert to MIP again and saturate
113  float totalMIPs(0.f), xtalk = 0.f;
114  const float peDiff = nTotalPE_ - (float) nPixel;
115  if (peDiff != 0.f) {
116  xtalk = (nTotalPE_-xTalk_*((float)nPixel)) / peDiff;
117  if( xtalk > 0.f && nPEperMIP_ != 0.f)
118  totalMIPs = (nTotalPE_/nPEperMIP_)*vdt::fast_logf(xtalk);
119  }
120 
121  //add noise (in MIPs)
122  chargeColl[i] = totalMIPs+std::max( CLHEP::RandGaussQ::shoot(engine,0.,noise_MIP_), 0. );
123  if(debug && cell.hit_info[0][i]>0)
124  std::cout << "[runCaliceLikeDigitizer] xtalk=" << xtalk << " En=" << cell.hit_info[0][i] << " keV -> " << totalIniMIPs << " raw-MIPs -> " << chargeColl[i] << " digi-MIPs" << std::endl;
125  }
126 
127  //init a new data frame and run shaper
128  HGCBHDataFrame newDataFrame( id );
129  myFEelectronics_->runTrivialShaper( newDataFrame, chargeColl, 1 );
130 
131  //prepare the output
132  updateOutput(digiColl,newDataFrame);
133  }
134 }
135 
136 //
138 {
139 }
140 
T getParameter(std::string const &) const
static const TGPicture * info(bool iBackgroundIsBlack)
void updateOutput(std::unique_ptr< DColl > &coll, const HGCBHDataFrame &rawDataFrame)
prepares the output according to the number of time samples to produce
std::array< HGCSimHitData, 2 > hit_info
#define constexpr
std::array< HGCSimData_t, nSamples > HGCSimHitData
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
HGCHEbackDigitizer(const edm::ParameterSet &ps)
std::unordered_map< uint32_t, HGCCellInfo > HGCSimHitDataAccumulator
void runDigitizer(std::unique_ptr< HGCBHDigiCollection > &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
const HGCalTopology & topology() const
Definition: HGCalGeometry.h:99
std::unique_ptr< HGCFEElectronics< HGCBHDataFrame > > myFEelectronics_
double f[11][100]
int wafer() const
get the wafer #
Definition: HGCalDetId.h:42
Definition: DetId.h:18
#define debug
Definition: HDRShower.cc:19
const HGCalDDDConstants & dddConstants() const
susybsm::HSCParticleCollection hc
Definition: classes.h:25
void runCaliceLikeDigitizer(std::unique_ptr< HGCBHDigiCollection > &digiColl, hgc::HGCSimHitDataAccumulator &simData, const CaloSubdetectorGeometry *theGeom, const std::unordered_set< DetId > &validIds, CLHEP::HepRandomEngine *engine)
float fast_expf(float x)
Detector det() const
get the detector field from this detid
Definition: DetId.h:36
float fast_logf(float x)