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  if(myCfg_.existsAs<double>("noise_fC")) {
56  noise_fC_.resize(1);
57  noise_fC_[0] = myCfg_.getParameter<double>("noise_fC");
58  } else if ( myCfg_.existsAs<std::vector<double> >("noise_fC") ) {
59  const auto& noises = myCfg_.getParameter<std::vector<double> >("noise_fC");
60  noise_fC_.resize(0);
61  noise_fC_.reserve(noises.size());
62  for( auto noise : noises ) { noise_fC_.push_back( noise ); }
63  } else {
64  noise_fC_.resize(1);
65  noise_fC_[0] = 1.f;
66  }
67  edm::ParameterSet feCfg = myCfg_.getParameter<edm::ParameterSet>("feCfg");
68  myFEelectronics_ = std::unique_ptr<HGCFEElectronics<DFr> >( new HGCFEElectronics<DFr>(feCfg) );
69 }
70 
71 template<class DFr>
72 void HGCDigitizerBase<DFr>::run( std::unique_ptr<HGCDigitizerBase::DColl> &digiColl,
73  HGCSimHitDataAccumulator &simData,
74  const CaloSubdetectorGeometry* theGeom,
75  const std::unordered_set<DetId>& validIds,
76  uint32_t digitizationType,
77  CLHEP::HepRandomEngine* engine) {
78  if(digitizationType==0) runSimple(digiColl,simData,theGeom,validIds,engine);
79  else runDigitizer(digiColl,simData,theGeom,validIds,digitizationType,engine);
80 }
81 
82 template<class DFr>
83 void HGCDigitizerBase<DFr>::runSimple(std::unique_ptr<HGCDigitizerBase::DColl> &coll,
84  HGCSimHitDataAccumulator &simData,
85  const CaloSubdetectorGeometry* theGeom,
86  const std::unordered_set<DetId>& validIds,
87  CLHEP::HepRandomEngine* engine) {
88  HGCSimHitData chargeColl,toa;
89 
90  // this represents a cell with no signal charge
91  HGCCellInfo zeroData;
92  zeroData.hit_info[0].fill(0.f); //accumulated energy
93  zeroData.hit_info[1].fill(0.f); //time-of-flight
94 
95  for( const auto& id : validIds ) {
96  chargeColl.fill(0.f);
97  toa.fill(0.f);
98  HGCSimHitDataAccumulator::iterator it = simData.find(id);
99  HGCCellInfo& cell = ( simData.end() == it ? zeroData : it->second );
100  addCellMetadata(cell,theGeom,id);
101 
102  for(size_t i=0; i<cell.hit_info[0].size(); i++) {
103  double rawCharge(cell.hit_info[0][i]);
104 
105  //time of arrival
106  toa[i]=cell.hit_info[1][i];
107  if(myFEelectronics_->toaMode()==HGCFEElectronics<DFr>::WEIGHTEDBYE && rawCharge>0)
108  toa[i]=cell.hit_info[1][i]/rawCharge;
109 
110  //convert total energy in GeV to charge (fC)
111  //double totalEn=rawEn*1e6*keV2fC_;
112  float totalCharge=rawCharge;
113 
114  //add noise (in fC)
115  //we assume it's randomly distributed and won't impact ToA measurement
116  totalCharge += std::max( (float)CLHEP::RandGaussQ::shoot(engine,0.0,cell.size*noise_fC_[cell.thickness-1]) , 0.f );
117  if(totalCharge<0.f) totalCharge=0.f;
118 
119  chargeColl[i]= totalCharge;
120  }
121 
122  //run the shaper to create a new data frame
123  DFr rawDataFrame( id );
124  myFEelectronics_->runShaper(rawDataFrame, chargeColl, toa, cell.thickness, engine);
125 
126  //update the output according to the final shape
127  updateOutput(coll,rawDataFrame);
128  }
129 }
130 
131 template<class DFr>
132 void HGCDigitizerBase<DFr>::updateOutput(std::unique_ptr<HGCDigitizerBase::DColl> &coll,
133  const DFr& rawDataFrame) {
134  int itIdx(9);
135  if(rawDataFrame.size()<=itIdx+2) return;
136 
137  DFr dataFrame( rawDataFrame.id() );
138  dataFrame.resize(5);
139  bool putInEvent(false);
140  for(int it=0;it<5; it++) {
141  dataFrame.setSample(it, rawDataFrame[itIdx-2+it]);
142  if(it==2) putInEvent = rawDataFrame[itIdx-2+it].threshold();
143  }
144 
145  if(putInEvent) {
146  coll->push_back(dataFrame);
147  }
148 }
149 
150 // cause the compiler to generate the appropriate code
152 template class HGCDigitizerBase<HGCEEDataFrame>;
153 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
std::array< HGCSimData_t, nSamples > HGCSimHitData
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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:96
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:35