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