CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HGCDigitizerBase.h
Go to the documentation of this file.
1 #ifndef SimCalorimetry_HGCSimProducers_hgcdigitizerbase
2 #define SimCalorimetry_HGCSimProducers_hgcdigitizerbase
3 
4 #include <array>
5 #include <iostream>
6 #include <vector>
7 #include <memory>
8 #include <unordered_map>
9 
13 #include "CLHEP/Random/RandGaussQ.h"
14 
15 typedef float HGCSimEn_t;
16 typedef std::array<HGCSimEn_t,6> HGCSimHitData;
17 typedef std::unordered_map<uint32_t, HGCSimHitData> HGCSimHitDataAccumulator;
18 
19 template <class D>
21 
22 public:
23 
25 
30  myCfg_ = ps.getParameter<edm::ParameterSet>("digiCfg");
31  bxTime_ = ps.getParameter<int32_t>("bxTime");
32  doTimeSamples_ = myCfg_.getParameter< bool >("doTimeSamples");
33  mipInKeV_ = myCfg_.getParameter<double>("mipInKeV");
34  lsbInMIP_ = myCfg_.getParameter<double>("lsbInMIP");
35  mip2noise_ = myCfg_.getParameter<double>("mip2noise");
36  adcThreshold_ = myCfg_.getParameter< uint32_t >("adcThreshold");
37  shaperN_ = myCfg_.getParameter< double >("shaperN");
38  shaperTau_ = myCfg_.getParameter< double >("shaperTau");
39  }
40 
44  void run(std::auto_ptr<DColl> &digiColl,HGCSimHitDataAccumulator &simData,uint32_t digitizationType, CLHEP::HepRandomEngine* engine) {
45  if(digitizationType==0) runTrivial(digiColl,simData,engine);
46  else runDigitizer(digiColl,simData,digitizationType,engine);
47  }
48 
49 
53  void runTrivial(std::auto_ptr<DColl> &coll,HGCSimHitDataAccumulator &simData, CLHEP::HepRandomEngine* engine) {
54  for(HGCSimHitDataAccumulator::iterator it=simData.begin();
55  it!=simData.end(); it++) {
56 
57  //create a new data frame
58  D rawDataFrame( it->first );
59 
60  for(size_t i=0; i<it->second.size(); i++) {
61  //convert total energy GeV->keV->ADC counts
62  double totalEn=(it->second)[i]*1e6;
63 
64  //add noise (in keV)
65  double noiseEn=CLHEP::RandGaussQ::shoot(engine,0,mipInKeV_/mip2noise_);
66  totalEn += noiseEn;
67  if(totalEn<0) totalEn=0;
68 
69  //round to integer (sample will saturate the value according to available bits)
70  uint16_t totalEnInt = floor( (totalEn/mipInKeV_) / lsbInMIP_ );
71 
72  //0 gain for the moment
73  HGCSample singleSample;
74  singleSample.set(0, totalEnInt);
75 
76  rawDataFrame.setSample(i, singleSample);
77  }
78 
79  //run the shaper
80  runShaper(rawDataFrame);
81 
82  //update the output according to the final shape
83  updateOutput(coll,rawDataFrame);
84  }
85  }
86 
90  void updateOutput(std::auto_ptr<DColl> &coll,D rawDataFrame) {
91  size_t itIdx(4); //index to the in-time digi - this could be configurable in a future version
92 
93  //check if in-time sample is above threshold and put result into the event
94  if(doTimeSamples_) {
95  if(rawDataFrame[itIdx].adc() < adcThreshold_ ) return;
96  coll->push_back(rawDataFrame);
97  } else {
98  //create a new data frame containing only the in-time digi
99  D singleRawDataFrame( rawDataFrame.id() );
100  singleRawDataFrame.resize(1);
101 
102  HGCSample singleSample;
103  singleSample.set(rawDataFrame[itIdx].gain(),rawDataFrame[itIdx].adc());
104  singleRawDataFrame.setSample(0, singleSample);
105  if(singleRawDataFrame[0].adc() < adcThreshold_ ) return;
106  coll->push_back(singleRawDataFrame);
107  }
108  }
109 
113  void runShaper(D &dataFrame) {
114  std::vector<uint16_t> oldADC(dataFrame.size());
115  for(int it=0; it<dataFrame.size(); it++) {
116  uint16_t gain=dataFrame[it].gain();
117  oldADC[it]=dataFrame[it].adc();
118  uint16_t newADC(oldADC[it]);
119 
120  if(shaperN_*shaperTau_>0){
121  for(int jt=0; jt<it; jt++) {
122  float relTime(bxTime_*(it-jt)+shaperN_*shaperTau_);
123  newADC += uint16_t(oldADC[jt]*pow(relTime/(shaperN_*shaperTau_),shaperN_)*exp(-(relTime-shaperN_*shaperTau_)/shaperTau_));
124  }
125  }
126 
127  HGCSample newSample;
128  newSample.set(gain,newADC);
129  dataFrame.setSample(it,newSample);
130  }
131  }
132 
136  virtual void runDigitizer(std::auto_ptr<DColl> &coll,HGCSimHitDataAccumulator &simData,uint32_t digitizerType, CLHEP::HepRandomEngine* engine) {
137  throw cms::Exception("HGCDigitizerBaseException") << " Failed to find specialization of runDigitizer";
138  }
139 
144 
145  //baseline configuration
147 
148  //minimum ADC counts to produce DIGIs
149  uint32_t adcThreshold_;
150 
151  //parameters for the trivial digitization scheme
153 
154  //parameters for trivial shaping
156 
157  //bunch time
158  int bxTime_;
159 
160  //if true will put both in time and out-of-time samples in the event
162 
163 private:
164 
165 };
166 
167 #endif
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
edm::SortedCollection< D > DColl
void set(uint16_t gain, uint16_t adc)
Definition: HGCSample.h:30
std::array< HGCSimEn_t, 6 > HGCSimHitData
wrapper for a data word
Definition: HGCSample.h:12
virtual void runDigitizer(std::auto_ptr< DColl > &coll, HGCSimHitDataAccumulator &simData, uint32_t digitizerType, CLHEP::HepRandomEngine *engine)
to be specialized by top class
void runTrivial(std::auto_ptr< DColl > &coll, HGCSimHitDataAccumulator &simData, CLHEP::HepRandomEngine *engine)
a trivial digitization: sum energies and digitize without noise
HGCDigitizerBase(const edm::ParameterSet &ps)
CTOR.
JetCorrectorParametersCollection coll
Definition: classes.h:10
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
edm::ParameterSet myCfg_
void run(std::auto_ptr< DColl > &digiColl, HGCSimHitDataAccumulator &simData, uint32_t digitizationType, CLHEP::HepRandomEngine *engine)
steer digitization mode
std::unordered_map< uint32_t, HGCSimHitData > HGCSimHitDataAccumulator
float HGCSimEn_t
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void runShaper(D &dataFrame)
applies a shape to each time sample and propagates the tails to the subsequent time samples ...
void updateOutput(std::auto_ptr< DColl > &coll, D rawDataFrame)
prepares the output according to the number of time samples to produce