test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HGCDigitizer.cc
Go to the documentation of this file.
16 
17 #include <boost/foreach.hpp>
18 
19 //
21  checkValidDetIds_(true),
22  simHitAccumulator_( new HGCSimHitDataAccumulator ),
23  mySubDet_(ForwardSubdetector::ForwardEmpty),
24  refSpeed_(0.1*CLHEP::c_light) { //[CLHEP::c_light]=mm/ns convert to cm/ns
25 
26  //configure from cfg
27  hitCollection_ = ps.getParameter< std::string >("hitCollection");
28  digiCollection_ = ps.getParameter< std::string >("digiCollection");
29  maxSimHitsAccTime_ = ps.getParameter< uint32_t >("maxSimHitsAccTime");
30  bxTime_ = ps.getParameter< int32_t >("bxTime");
31  digitizationType_ = ps.getParameter< uint32_t >("digitizationType");
32  useAllChannels_ = ps.getParameter< bool >("useAllChannels");
33  verbosity_ = ps.getUntrackedParameter< int32_t >("verbosity",0);
34  tofDelay_ = ps.getParameter< double >("tofDelay");
35 
36  iC.consumes<std::vector<PCaloHit> >(edm::InputTag("g4SimHits",hitCollection_));
37 
38  if(hitCollection_.find("HitsEE")!=std::string::npos) {
40  theHGCEEDigitizer_=std::unique_ptr<HGCEEDigitizer>(new HGCEEDigitizer(ps) );
41  }
42  if(hitCollection_.find("HitsHEfront")!=std::string::npos) {
44  theHGCHEfrontDigitizer_=std::unique_ptr<HGCHEfrontDigitizer>(new HGCHEfrontDigitizer(ps) );
45  }
46  if(hitCollection_.find("HitsHEback")!=std::string::npos) {
48  theHGCHEbackDigitizer_=std::unique_ptr<HGCHEbackDigitizer>(new HGCHEbackDigitizer(ps) );
49  }
50 }
51 
52 //
55 }
56 
57 //
58 void HGCDigitizer::finalizeEvent(edm::Event& e, edm::EventSetup const& es, CLHEP::HepRandomEngine* engine) {
59  if( producesEEDigis() ) {
60  std::auto_ptr<HGCEEDigiCollection> digiResult(new HGCEEDigiCollection() );
62  edm::LogInfo("HGCDigitizer") << " @ finalize event - produced " << digiResult->size() << " EE hits";
63  e.put(digiResult,digiCollection());
64  }
65  if( producesHEfrontDigis()) {
66  std::auto_ptr<HGCHEDigiCollection> digiResult(new HGCHEDigiCollection() );
68  edm::LogInfo("HGCDigitizer") << " @ finalize event - produced " << digiResult->size() << " HE front hits";
69  e.put(digiResult,digiCollection());
70  }
71  if( producesHEbackDigis() ) {
72  std::auto_ptr<HGCHEDigiCollection> digiResult(new HGCHEDigiCollection() );
74  edm::LogInfo("HGCDigitizer") << " @ finalize event - produced " << digiResult->size() << " HE back hits";
75  e.put(digiResult,digiCollection());
76  }
77 }
78 
79 //
80 void HGCDigitizer::accumulate(edm::Event const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
81 
82  //get inputs
84  e.getByLabel(edm::InputTag("g4SimHits",hitCollection_),hits);
85  if( !hits.isValid() ){
86  edm::LogError("HGCDigitizer") << " @ accumulate : can't find " << hitCollection_ << " collection of g4SimHits";
87  return;
88  }
89 
90  //get geometry
92  if( producesEEDigis() ) eventSetup.get<IdealGeometryRecord>().get("HGCalEESensitive" , geom);
93  if( producesHEfrontDigis() ) eventSetup.get<IdealGeometryRecord>().get("HGCalHESiliconSensitive" , geom);
94  if( producesHEbackDigis() ) eventSetup.get<IdealGeometryRecord>().get("HGCalHEScintillatorSensitive", geom);
95 
96  //accumulate in-time the main event
97  accumulate(hits, 0, geom, engine);
98 }
99 
100 //
101 void HGCDigitizer::accumulate(PileUpEventPrincipal const& e, edm::EventSetup const& eventSetup, CLHEP::HepRandomEngine* engine) {
102 
103  //get inputs
105  e.getByLabel(edm::InputTag("g4SimHits",hitCollection_),hits);
106  if( !hits.isValid() ){
107  edm::LogError("HGCDigitizer") << " @ accumulate : can't find " << hitCollection_ << " collection of g4SimHits";
108  return;
109  }
110 
111  //get geometry
113  if( producesEEDigis() ) eventSetup.get<IdealGeometryRecord>().get("HGCalEESensitive" , geom);
114  if( producesHEfrontDigis() ) eventSetup.get<IdealGeometryRecord>().get("HGCalHESiliconSensitive" , geom);
115  if( producesHEbackDigis() ) eventSetup.get<IdealGeometryRecord>().get("HGCalHEScintillatorSensitive", geom);
116 
117  //accumulate for the simulated bunch crossing
118  accumulate(hits, e.bunchCrossing(), geom, engine);
119 }
120 
121 //
122 void HGCDigitizer::accumulate(edm::Handle<edm::PCaloHitContainer> const &hits, int bxCrossing,const edm::ESHandle<HGCalGeometry> &geom, CLHEP::HepRandomEngine* engine) {
123  if(!geom.isValid()) return;
124  const HGCalTopology &topo=geom->topology();
125  const HGCalDDDConstants &dddConst=topo.dddConstants();
126 
127  for(edm::PCaloHitContainer::const_iterator hit_it = hits->begin(); hit_it != hits->end(); ++hit_it) {
128  HGCalDetId simId( hit_it->id() );
129 
130  //skip this hit if after ganging it is not valid
131  int layer(simId.layer()), cell(simId.cell());
132  std::pair<int,int> recoLayerCell=dddConst.simToReco(cell,layer,topo.detectorType());
133  cell = recoLayerCell.first;
134  layer = recoLayerCell.second;
135  if(layer<0 || cell<0) continue;
136 
137  //assign the RECO DetId
138  DetId id( producesEEDigis() ?
139  (uint32_t)HGCEEDetId(mySubDet_,simId.zside(),layer,simId.sector(),simId.subsector(),cell):
140  (uint32_t)HGCHEDetId(mySubDet_,simId.zside(),layer,simId.sector(),simId.subsector(),cell) );
141 
142  if (verbosity_>0) {
143  if (producesEEDigis())
144  std::cout << "HGCDigitizer: i/p " << simId << " o/p " << HGCEEDetId(id) << std::endl;
145  else
146  std::cout << "HGCDigitizer: i/p " << simId << " o/p " << HGCHEDetId(id) << std::endl;
147  }
148 
149  //distance to the center of the detector
150  float dist2center( geom->getPosition(id).mag() );
151 
152  //hit time: [time()]=ns [centerDist]=cm [refSpeed_]=cm/ns + delay by 1ns
153  //accumulate in 6 buckets of 25ns (4 pre-samples, 1 in-time, 1 post-sample)
154  float tof(hit_it->time()-dist2center/refSpeed_+tofDelay_);
155  int itime=floor( tof/bxTime_ ) ;
156 
157  //no need to add bx crossing - tof comes already corrected from the mixing module
158  //itime += bxCrossing;
159  itime += 4;
160 
161  if(itime<0 || itime>5) continue;
162 
163  //energy deposited
164  HGCSimEn_t ien( hit_it->energy() );
165 
166  //check if already existing (perhaps could remove this in the future - 2nd event should have all defined)
167  HGCSimHitDataAccumulator::iterator simHitIt=simHitAccumulator_->find(id);
168  if(simHitIt==simHitAccumulator_->end()) {
169  HGCSimHitData baseData;
170  baseData.fill(0.);
171  simHitAccumulator_->insert( std::make_pair(id,baseData) );
172  simHitIt=simHitAccumulator_->find(id);
173  }
174 
175  //check if time index is ok and store energy
176  if(itime >= (int)simHitIt->second.size() ) continue;
177  (simHitIt->second)[itime] += ien;
178  }
179 
180  //add base data for noise simulation
181  if(!checkValidDetIds_) return;
182  if(!geom.isValid()) return;
183  HGCSimHitData baseData;
184  baseData.fill(0.);
185  const std::vector<DetId> &validIds=geom->getValidDetIds();
186  int nadded(0);
187  if (useAllChannels_) {
188  for(std::vector<DetId>::const_iterator it=validIds.begin(); it!=validIds.end(); it++) {
189  uint32_t id(it->rawId());
190  if(simHitAccumulator_->find(id)!=simHitAccumulator_->end()) continue;
191  simHitAccumulator_->insert( std::make_pair(id,baseData) );
192  nadded++;
193  }
194  }
195  if (verbosity_ > 0)
196  std::cout << "HGCDigitizer:Added " << nadded << ":" << validIds.size()
197  << " detIds without " << hitCollection_
198  << " in first event processed" << std::endl;
199  checkValidDetIds_=false;
200 }
201 
202 //
204 
205 //
207 
208 //
210  for( HGCSimHitDataAccumulator::iterator it = simHitAccumulator_->begin(); it!=simHitAccumulator_->end(); it++) it->second.fill(0.);
211 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::SortedCollection< HGCEEDataFrame > HGCEEDigiCollection
ForwardSubdetector mySubDet_
Definition: HGCDigitizer.h:90
int digitizationType_
Definition: HGCDigitizer.h:76
std::string hitCollection_
Definition: HGCDigitizer.h:73
void resetSimHitDataAccumulator()
bool useAllChannels_
Definition: HGCDigitizer.h:93
bool checkValidDetIds_
Definition: HGCDigitizer.h:70
void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
actions at the start/end of event
Definition: HGCDigitizer.cc:53
bool detectorType() const
ForwardSubdetector
std::array< HGCSimEn_t, 6 > HGCSimHitData
bool producesEEDigis()
Definition: HGCDigitizer.h:56
std::string digiCollection_
Definition: HGCDigitizer.h:73
void finalizeEvent(edm::Event &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *)
Definition: HGCDigitizer.cc:58
void beginRun(const edm::EventSetup &es)
actions at the start/end of run
float refSpeed_
Definition: HGCDigitizer.h:97
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
bool isValid() const
Definition: HandleBase.h:75
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
std::pair< int, int > simToReco(int cell, int layer, bool half) const
bool producesHEfrontDigis()
Definition: HGCDigitizer.h:57
std::unique_ptr< HGCHEbackDigitizer > theHGCHEbackDigitizer_
Definition: HGCDigitizer.h:86
Definition: DetId.h:18
void accumulate(edm::Event const &e, edm::EventSetup const &c, CLHEP::HepRandomEngine *)
handle SimHit accumulation
Definition: HGCDigitizer.cc:80
bool producesHEbackDigis()
Definition: HGCDigitizer.h:58
const HGCalDDDConstants & dddConstants() const
Definition: HGCalTopology.h:97
const T & get() const
Definition: EventSetup.h:56
int maxSimHitsAccTime_
Definition: HGCDigitizer.h:79
std::unique_ptr< HGCHEfrontDigitizer > theHGCHEfrontDigitizer_
Definition: HGCDigitizer.h:87
std::unique_ptr< HGCEEDigitizer > theHGCEEDigitizer_
Definition: HGCDigitizer.h:85
std::unordered_map< uint32_t, HGCSimHitData > HGCSimHitDataAccumulator
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
std::unique_ptr< HGCSimHitDataAccumulator > simHitAccumulator_
Definition: HGCDigitizer.h:81
float HGCSimEn_t
HGCDigitizer(const edm::ParameterSet &ps, edm::ConsumesCollector &iC)
Definition: HGCDigitizer.cc:20
tuple cout
Definition: gather_cfg.py:121
bool isValid() const
Definition: ESHandle.h:47
std::string digiCollection()
Definition: HGCDigitizer.h:59
edm::SortedCollection< HGCHEDataFrame > HGCHEDigiCollection