CMS 3D CMS Logo

HGCDigitizerBase.cc
Go to the documentation of this file.
4 
5 using namespace hgc_digi;
6 
7 namespace {
8  void addCellMetadata(HGCCellInfo& info,
9  const HcalGeometry* geom,
10  const DetId& detid ) {
11  //base time samples for each DetId, initialized to 0
12  info.size = 1.0;
13  info.thickness = 1.0;
14  }
15 
16  void addCellMetadata(HGCCellInfo& info,
17  const HGCalGeometry* geom,
18  const DetId& detid ) {
19  const auto& topo = geom->topology();
20  const auto& dddConst = topo.dddConstants();
21  uint32_t id(detid.rawId());
22  int waferTypeL = 0;
23  bool isHalf = false;
24  HGCalDetId hid(id);
25  int wafer = HGCalDetId(id).wafer();
26  waferTypeL = dddConst.waferTypeL(wafer);
27  isHalf = dddConst.isHalfCell(wafer,hid.cell());
28  //base time samples for each DetId, initialized to 0
29  info.size = (isHalf ? 0.5 : 1.0);
30  info.thickness = waferTypeL;
31  }
32 
33  void addCellMetadata(HGCCellInfo& info,
34  const CaloSubdetectorGeometry* geom,
35  const DetId& detid ) {
36  if( DetId::Hcal == detid.det() ) {
37  const HcalGeometry* hc = static_cast<const HcalGeometry*>(geom);
38  addCellMetadata(info,hc,detid);
39  } else {
40  const HGCalGeometry* hg = static_cast<const HGCalGeometry*>(geom);
41  addCellMetadata(info,hg,detid);
42  }
43  }
44 
45 }
46 
47 
48 template<class DFr>
50  bxTime_ = ps.getParameter<double>("bxTime");
51  myCfg_ = ps.getParameter<edm::ParameterSet>("digiCfg");
52  doTimeSamples_ = myCfg_.getParameter< bool >("doTimeSamples");
53  if(myCfg_.exists("keV2fC")) keV2fC_ = myCfg_.getParameter<double>("keV2fC");
54  else keV2fC_ = 1.0;
55 
56  if( myCfg_.existsAs<std::vector<double> >( "chargeCollectionEfficiencies" ) ) {
57  cce_ = myCfg_.getParameter<std::vector<double> >("chargeCollectionEfficiencies");
58  } else {
59  std::vector<double>().swap(cce_);
60  }
61 
62  if(myCfg_.existsAs<double>("noise_fC")) {
63  noise_fC_.resize(1);
64  noise_fC_[0] = myCfg_.getParameter<double>("noise_fC");
65  } else if ( myCfg_.existsAs<std::vector<double> >("noise_fC") ) {
66  const auto& noises = myCfg_.getParameter<std::vector<double> >("noise_fC");
67  noise_fC_.resize(0);
68  noise_fC_.reserve(noises.size());
69  for( auto noise : noises ) { noise_fC_.push_back( noise ); }
70  } else {
71  noise_fC_.resize(1);
72  noise_fC_[0] = 1.f;
73  }
74  edm::ParameterSet feCfg = myCfg_.getParameter<edm::ParameterSet>("feCfg");
75  myFEelectronics_ = std::unique_ptr<HGCFEElectronics<DFr> >( new HGCFEElectronics<DFr>(feCfg) );
76  myFEelectronics_->SetNoiseValues(noise_fC_);
77 }
78 
79 template<class DFr>
80 void HGCDigitizerBase<DFr>::run( std::unique_ptr<HGCDigitizerBase::DColl> &digiColl,
81  HGCSimHitDataAccumulator &simData,
82  const CaloSubdetectorGeometry* theGeom,
83  const std::unordered_set<DetId>& validIds,
84  uint32_t digitizationType,
85  CLHEP::HepRandomEngine* engine) {
86  if(digitizationType==0) runSimple(digiColl,simData,theGeom,validIds,engine);
87  else runDigitizer(digiColl,simData,theGeom,validIds,digitizationType,engine);
88 }
89 
90 template<class DFr>
91 void HGCDigitizerBase<DFr>::runSimple(std::unique_ptr<HGCDigitizerBase::DColl> &coll,
92  HGCSimHitDataAccumulator &simData,
93  const CaloSubdetectorGeometry* theGeom,
94  const std::unordered_set<DetId>& validIds,
95  CLHEP::HepRandomEngine* engine) {
96  HGCSimHitData chargeColl,toa;
97 
98  // this represents a cell with no signal charge
99  HGCCellInfo zeroData;
100  zeroData.hit_info[0].fill(0.f); //accumulated energy
101  zeroData.hit_info[1].fill(0.f); //time-of-flight
102 
103  for( const auto& id : validIds ) {
104  chargeColl.fill(0.f);
105  toa.fill(0.f);
106  HGCSimHitDataAccumulator::iterator it = simData.find(id);
107  HGCCellInfo& cell = ( simData.end() == it ? zeroData : it->second );
108  addCellMetadata(cell,theGeom,id);
109 
110  for(size_t i=0; i<cell.hit_info[0].size(); i++) {
111  double rawCharge(cell.hit_info[0][i]);
112 
113  //time of arrival
114  toa[i]=cell.hit_info[1][i];
115  if(myFEelectronics_->toaMode()==HGCFEElectronics<DFr>::WEIGHTEDBYE && rawCharge>0)
116  toa[i]=cell.hit_info[1][i]/rawCharge;
117 
118  //convert total energy in GeV to charge (fC)
119  //double totalEn=rawEn*1e6*keV2fC_;
120  float totalCharge=rawCharge;
121 
122  //add noise (in fC)
123  //we assume it's randomly distributed and won't impact ToA measurement
124  //also assume that it is related to the charge path only and that noise fluctuation for ToA circuit be handled separately
125  totalCharge += std::max( (float)CLHEP::RandGaussQ::shoot(engine,0.0,cell.size*noise_fC_[cell.thickness-1]) , 0.f );
126  if(totalCharge<0.f) totalCharge=0.f;
127 
128  chargeColl[i]= totalCharge;
129  }
130 
131  //run the shaper to create a new data frame
132  DFr rawDataFrame( id );
133  if( !cce_.empty() )
134  myFEelectronics_->runShaper(rawDataFrame, chargeColl, toa, cell.thickness, engine, cce_[cell.thickness-1]);
135  else
136  myFEelectronics_->runShaper(rawDataFrame, chargeColl, toa, cell.thickness, engine);
137 
138  //update the output according to the final shape
139  updateOutput(coll,rawDataFrame);
140  }
141 }
142 
143 template<class DFr>
144 void HGCDigitizerBase<DFr>::updateOutput(std::unique_ptr<HGCDigitizerBase::DColl> &coll,
145  const DFr& rawDataFrame) {
146  int itIdx(9);
147  if(rawDataFrame.size()<=itIdx+2) return;
148 
149  DFr dataFrame( rawDataFrame.id() );
150  dataFrame.resize(5);
151  bool putInEvent(false);
152  for(int it=0;it<5; it++) {
153  dataFrame.setSample(it, rawDataFrame[itIdx-2+it]);
154  if(it==2) putInEvent = rawDataFrame[itIdx-2+it].threshold();
155  }
156 
157  if(putInEvent) {
158  coll->push_back(dataFrame);
159  }
160 }
161 
162 // cause the compiler to generate the appropriate code
164 template class HGCDigitizerBase<HGCEEDataFrame>;
165 template class HGCDigitizerBase<HGCBHDataFrame>;
T getParameter(std::string const &) const
static const TGPicture * info(bool iBackgroundIsBlack)
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
std::array< HGCSimHitData, 2 > hit_info
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
std::array< HGCSimData_t, nSamples > HGCSimHitData
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
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
const HGCalTopology & topology() const
Definition: HGCalGeometry.h:99
double f[11][100]
int wafer() const
get the wafer #
Definition: HGCalDetId.h:42
HGCDigitizerBase(const edm::ParameterSet &ps)
CTOR.
Definition: DetId.h:18
JetCorrectorParametersCollection coll
Definition: classes.h:10
const HGCalDDDConstants & dddConstants() const
susybsm::HSCParticleCollection hc
Definition: classes.h:25
models the behavior of the front-end electronics
Detector det() const
get the detector field from this detid
Definition: DetId.h:36