CMS 3D CMS Logo

HGCDigitizerBase.cc
Go to the documentation of this file.
4 
5 using namespace hgc_digi;
6 using namespace hgc_digi_utils;
7 
8 template<class DFr>
10  bxTime_ = ps.getParameter<double>("bxTime");
11  myCfg_ = ps.getParameter<edm::ParameterSet>("digiCfg");
12  doTimeSamples_ = myCfg_.getParameter< bool >("doTimeSamples");
13  if(myCfg_.exists("keV2fC")) keV2fC_ = myCfg_.getParameter<double>("keV2fC");
14  else keV2fC_ = 1.0;
15 
16  if( myCfg_.existsAs<edm::ParameterSet>( "chargeCollectionEfficiencies" ) ) {
17  cce_ = myCfg_.getParameter<edm::ParameterSet>("chargeCollectionEfficiencies").template getParameter<std::vector<double>>("values");
18  }
19 
20  if(myCfg_.existsAs<double>("noise_fC")) {
21  noise_fC_.reserve(1);
22  noise_fC_.push_back(myCfg_.getParameter<double>("noise_fC"));
23  } else if ( myCfg_.existsAs<std::vector<double> >("noise_fC") ) {
24  const auto& noises = myCfg_.getParameter<std::vector<double> >("noise_fC");
25  noise_fC_ = std::vector<float>(noises.begin(),noises.end());
26  } else if(myCfg_.existsAs<edm::ParameterSet>("noise_fC")) {
27  const auto& noises = myCfg_.getParameter<edm::ParameterSet>("noise_fC").template getParameter<std::vector<double> >("values");
28  noise_fC_ = std::vector<float>(noises.begin(),noises.end());
29  } else {
30  noise_fC_.resize(1,1.f);
31  }
32  edm::ParameterSet feCfg = myCfg_.getParameter<edm::ParameterSet>("feCfg");
33  myFEelectronics_ = std::unique_ptr<HGCFEElectronics<DFr> >( new HGCFEElectronics<DFr>(feCfg) );
34  myFEelectronics_->SetNoiseValues(noise_fC_);
35 }
36 
37 template<class DFr>
38 void HGCDigitizerBase<DFr>::run( std::unique_ptr<HGCDigitizerBase::DColl> &digiColl,
39  HGCSimHitDataAccumulator &simData,
40  const CaloSubdetectorGeometry* theGeom,
41  const std::unordered_set<DetId>& validIds,
42  uint32_t digitizationType,
43  CLHEP::HepRandomEngine* engine) {
44  if(digitizationType==0) runSimple(digiColl,simData,theGeom,validIds,engine);
45  else runDigitizer(digiColl,simData,theGeom,validIds,digitizationType,engine);
46 }
47 
48 template<class DFr>
49 void HGCDigitizerBase<DFr>::runSimple(std::unique_ptr<HGCDigitizerBase::DColl> &coll,
50  HGCSimHitDataAccumulator &simData,
51  const CaloSubdetectorGeometry* theGeom,
52  const std::unordered_set<DetId>& validIds,
53  CLHEP::HepRandomEngine* engine) {
54  HGCSimHitData chargeColl,toa;
55 
56  // this represents a cell with no signal charge
57  HGCCellInfo zeroData;
58  zeroData.hit_info[0].fill(0.f); //accumulated energy
59  zeroData.hit_info[1].fill(0.f); //time-of-flight
60 
61  for( const auto& id : validIds ) {
62  chargeColl.fill(0.f);
63  toa.fill(0.f);
64  HGCSimHitDataAccumulator::iterator it = simData.find(id);
65  HGCCellInfo& cell = ( simData.end() == it ? zeroData : it->second );
66  addCellMetadata(cell,theGeom,id);
67 
68  for(size_t i=0; i<cell.hit_info[0].size(); i++) {
69  double rawCharge(cell.hit_info[0][i]);
70 
71  //time of arrival
72  toa[i]=cell.hit_info[1][i];
73  if(myFEelectronics_->toaMode()==HGCFEElectronics<DFr>::WEIGHTEDBYE && rawCharge>0)
74  toa[i]=cell.hit_info[1][i]/rawCharge;
75 
76  //convert total energy in GeV to charge (fC)
77  //double totalEn=rawEn*1e6*keV2fC_;
78  float totalCharge=rawCharge;
79 
80  //add noise (in fC)
81  //we assume it's randomly distributed and won't impact ToA measurement
82  //also assume that it is related to the charge path only and that noise fluctuation for ToA circuit be handled separately
83  if (noise_fC_[cell.thickness-1] != 0)
84  totalCharge += std::max( (float)CLHEP::RandGaussQ::shoot(engine,0.0,cell.size*noise_fC_[cell.thickness-1]) , 0.f );
85  if(totalCharge<0.f) totalCharge=0.f;
86 
87  chargeColl[i]= totalCharge;
88  }
89 
90  //run the shaper to create a new data frame
91  DFr rawDataFrame( id );
92  if( !cce_.empty() )
93  myFEelectronics_->runShaper(rawDataFrame, chargeColl, toa, cell.thickness, engine, cce_[cell.thickness-1]);
94  else
95  myFEelectronics_->runShaper(rawDataFrame, chargeColl, toa, cell.thickness, engine);
96 
97  //update the output according to the final shape
98  updateOutput(coll,rawDataFrame);
99  }
100 }
101 
102 template<class DFr>
103 void HGCDigitizerBase<DFr>::updateOutput(std::unique_ptr<HGCDigitizerBase::DColl> &coll,
104  const DFr& rawDataFrame) {
105  int itIdx(9);
106  if(rawDataFrame.size()<=itIdx+2) return;
107 
108  DFr dataFrame( rawDataFrame.id() );
109  dataFrame.resize(5);
110  bool putInEvent(false);
111  for(int it=0;it<5; it++) {
112  dataFrame.setSample(it, rawDataFrame[itIdx-2+it]);
113  if(it==2) putInEvent = rawDataFrame[itIdx-2+it].threshold();
114  }
115 
116  if(putInEvent) {
117  coll->push_back(dataFrame);
118  }
119 }
120 
121 // cause the compiler to generate the appropriate code
123 template class HGCDigitizerBase<HGCEEDataFrame>;
124 template class HGCDigitizerBase<HGCBHDataFrame>;
125 template class HGCDigitizerBase<HGCalDataFrame>;
T getParameter(std::string const &) const
void runSimple(std::unique_ptr< DColl > &coll, hgc::HGCSimHitDataAccumulator &simData, const CaloSubdetectorGeometry *theGeom, const std::unordered_set< DetId > &validIds, CLHEP::HepRandomEngine *engine)
a trivial digitization: sum energies and digitize without noise
void updateOutput(std::unique_ptr< DColl > &coll, const DFr &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
std::array< HGCSimData_t, nSamples > HGCSimHitData
std::unordered_map< uint32_t, HGCCellInfo > HGCSimHitDataAccumulator
void run(std::unique_ptr< DColl > &digiColl, hgc::HGCSimHitDataAccumulator &simData, const CaloSubdetectorGeometry *theGeom, const std::unordered_set< DetId > &validIds, uint32_t digitizationType, CLHEP::HepRandomEngine *engine)
steer digitization mode
double f[11][100]
HGCDigitizerBase(const edm::ParameterSet &ps)
CTOR.
JetCorrectorParametersCollection coll
Definition: classes.h:10
models the behavior of the front-end electronics