CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalTBDigiProducer.cc
Go to the documentation of this file.
9 
19 
21  theParameterMap(new HcalTBSimParameterMap(ps)),
22  theHcalShape(new HcalShape()),
23  theHcalIntegratedShape(new CaloShapeIntegrator(theHcalShape)),
24  theHBHEResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)),
25  theHOResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)),
26  theAmplifier(0), theCoderFactory(0), theElectronicsSim(0),
27  theHitCorrection(0), theHBHEDigitizer(0), theHODigitizer(0), theHBHEHits(),
28  theHOHits(), thisPhaseShift(0) {
29  std::string const instance("simHcalDigis");
30  mixMod.produces<HBHEDigiCollection>(instance);
31  mixMod.produces<HODigiCollection>(instance);
32  iC.consumes<std::vector<PCaloHit> >(edm::InputTag("g4SimHits", "HcalHits"));
33 
34  DetId detId(DetId::Hcal, 1);
35  bool syncPhase = (theParameterMap->simParameters(detId)).syncPhase();
36  doPhaseShift = !syncPhase;
37 
40 
41  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
42  if(doTimeSlew) {
43  // no time slewing for HF
47  }
48 
49  bool doNoise = ps.getParameter<bool>("doNoise");
50  bool dummy1 = false;
51  bool dummy2 = false; // extra arguments for premixing
52  theAmplifier = new HcalAmplifier(theParameterMap, doNoise, dummy1, dummy2);
55 
58 
59  tunePhaseShift = ps.getUntrackedParameter<double>("tunePhaseShiftTB", 1.);
60  ecalTBInfoLabel = ps.getUntrackedParameter<std::string>("EcalTBInfoLabel","SimEcalTBG4Object");
61  edm::LogInfo("HcalSim") << "HcalTBDigiProducer initialized with doNoise = "
62  << doNoise << ", doTimeSlew = " << doTimeSlew
63  << " and doPhaseShift = " << doPhaseShift
64  << " tunePhasShift = " << tunePhaseShift;
65 
66  if (doPhaseShift) {
68  }
69 }
70 
72 
74  if (theHODigitizer) delete theHODigitizer;
75  if (theParameterMap) delete theParameterMap;
76  if (theHcalShape) delete theHcalShape;
78  if (theHBHEResponse) delete theHBHEResponse;
79  if (theHOResponse) delete theHOResponse;
81  if (theAmplifier) delete theAmplifier;
82  if (theCoderFactory) delete theCoderFactory;
84 }
85 
86 
88  // get the appropriate gains, noises, & widths for this event
90  eventSetup.get<HcalDbRecord>().get(conditions);
91  theAmplifier->setDbService(conditions.product());
92  theCoderFactory->setDbService(conditions.product());
93 
94  // get the correct geometry
95  checkGeometry(eventSetup);
96 
97  theHBHEHits.clear();
98  theHOHits.clear();
99  if (doPhaseShift) {
100 
101  edm::Handle<PEcalTBInfo> theEcalTBInfo;
102  e.getByLabel(ecalTBInfoLabel,theEcalTBInfo);
103  thisPhaseShift = theEcalTBInfo->phaseShift();
104 
105  DetId detIdHB(DetId::Hcal, 1);
106  setPhaseShift(detIdHB);
107  DetId detIdHO(DetId::Hcal, 3);
108  setPhaseShift(detIdHO);
109  }
110 
113 }
114 
115 void HcalTBDigiProducer::accumulateCaloHits(edm::Handle<std::vector<PCaloHit> > const& hcalHandle, int bunchCrossing, CLHEP::HepRandomEngine* engine) {
116 
117  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate trying to get SimHit";
118 
119  if(hcalHandle.isValid()) {
120  std::vector<PCaloHit> hits = *hcalHandle.product();
121  if(theHitCorrection != 0) {
123  }
124  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate Hits corrected";
125  theHBHEDigitizer->add(hits, bunchCrossing, engine);
126  theHODigitizer->add(hits, bunchCrossing, engine);
127  }
128 }
129 
131  // Step A: Get Inputs, and accumulate digis
132 
133  edm::InputTag hcalTag("g4SimHits", "HcalHits");
135  e.getByLabel(hcalTag, hcalHandle);
136 
137  accumulateCaloHits(hcalHandle, 0, randomEngine(e.streamID()));
138 }
139 
141  // Step A: Get Inputs, and accumulate digis
142 
143  edm::InputTag hcalTag("g4SimHits", "HcalHits");
145  e.getByLabel(hcalTag, hcalHandle);
146 
147  accumulateCaloHits(hcalHandle, e.bunchCrossing(), randomEngine(streamID));
148 }
149 
151  // Step B: Create empty output
152  std::auto_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
153  std::auto_ptr<HODigiCollection> hoResult(new HODigiCollection());
154  LogDebug("HcalSim") << "HcalTBDigiProducer::produce Empty collection created";
155  // Step C: Invoke the algorithm, getting back outputs.
156  theHBHEDigitizer->run(*hbheResult, randomEngine(e.streamID()));
157  edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HBHE digis : " << hbheResult->size();
158  theHODigitizer->run(*hoResult, randomEngine(e.streamID()));
159  edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HO digis : " << hoResult->size();
160 
161  // Step D: Put outputs into event
162  std::string const instance("simHcalDigis");
163  e.put(hbheResult, instance);
164  e.put(hoResult, instance);
165 
166 }
167 
169 
170  for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin();
171  hitItr != hits.end(); ++hitItr) {
172  HcalSubdetector subdet = HcalDetId(hitItr->id()).subdet();
173  if(subdet == HcalBarrel || subdet == HcalEndcap) {
174  theHBHEHits.push_back(*hitItr);
175  } else if(subdet == HcalOuter) {
176  theHOHits.push_back(*hitItr);
177  } else {
178  edm::LogError("HcalSim") << "Bad HcalHit subdetector " << subdet;
179  }
180  }
181 }
182 
184 
185  // TODO find a way to avoid doing this every event
187  eventSetup.get<CaloGeometryRecord>().get(geometry);
188 
189  const CaloGeometry * pGeometry = &*geometry;
190 
191  // see if we need to update
192  if(pGeometry != theGeometry) {
193  theGeometry = pGeometry;
194  updateGeometry();
195  }
196 }
197 
199 
202 
203  // Get cells for HB and HE
204  hbheCells.clear();
206  std::vector<DetId> heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
207  // combine HB & HE
208  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
209 
210  // Get cells for HO
211  hoCells.clear();
213 
214  edm::LogInfo("HcalSim") << "HcalTBDigiProducer update Geometry with "
215  << hbheCells.size() << " cells in HB/HE and "
216  << hoCells.size() << " cells in HO";
217 
219  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HB/HE";
221  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HO";
222 }
223 
225 
227  if ( !parameters.syncPhase() ) {
228  int myDet = detId.subdetId();
229  double passPhaseShift = thisPhaseShift + tunePhaseShift;
230  if (myDet <= 2) {
231  theHBHEResponse->setPhaseShift(passPhaseShift);
232  } else {
233  theHOResponse->setPhaseShift(passPhaseShift);
234  }
235  }
236 }
237 
238 CLHEP::HepRandomEngine* HcalTBDigiProducer::randomEngine(edm::StreamID const& streamID) {
239  unsigned int index = streamID.value();
240  if(index >= randomEngines_.size()) {
241  randomEngines_.resize(index + 1, nullptr);
242  }
243  CLHEP::HepRandomEngine* ptr = randomEngines_[index];
244  if(!ptr) {
246  ptr = &rng->getEngine(streamID);
247  randomEngines_[index] = ptr;
248  }
249  return ptr;
250 }
#define LogDebug(id)
void setPhaseShift(const DetId &detId)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
void setGeometry(const CaloGeometry *geometry)
geometry needed for time-of-flight
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
T getUntrackedParameter(std::string const &, T const &) const
virtual void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
dictionary parameters
Definition: Parameters.py:2
void sortHits(const edm::PCaloHitContainer &hits)
fills the vectors for each subdetector
std::vector< PCaloHit > PCaloHitContainer
std::vector< DetId > hoCells
virtual const CaloSimParameters & simParameters(const DetId &id) const
CaloHitResponse * theHBHEResponse
HcalTBDigiProducer(const edm::ParameterSet &ps, edm::one::EDProducerBase &mixMod, edm::ConsumesCollector &iC)
void initializeHits()
static PFTauRenderPlugin instance
HBHEHitFilter theHBHEHitFilter
HODigitizer * theHODigitizer
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
HcalElectronicsSim * theElectronicsSim
HOHitFilter theHOHitFilter
HcalTBSimParameterMap * theParameterMap
std::vector< CLHEP::HepRandomEngine * > randomEngines_
Main class for Parameters in different subdetectors.
const CaloGeometry * theGeometry
void setPhaseShift(const double &thePhaseShift)
setting the phase shift for asynchronous trigger (e.g. test beams)
CaloTDigitizer< HBHEDigitizerTraits > HBHEDigitizer
std::vector< PCaloHit > theHBHEHits
CaloTDigitizer< HODigitizerTraits > HODigitizer
CLHEP::HepRandomEngine * randomEngine(edm::StreamID const &streamID)
edm::SortedCollection< HODataFrame > HODigiCollection
CaloVShape * theHcalIntegratedShape
void setHitFilter(const CaloVHitFilter *filter)
if you want to reject hits, for example, from a certain subdetector, set this
Creates electronics signals from hits.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
HBHEDigitizer * theHBHEDigitizer
void fillChargeSums(MixCollection< PCaloHit > &hits)
HcalSubdetector
Definition: HcalAssistant.h:31
void checkGeometry(const edm::EventSetup &eventSetup)
shaper for Hcal (not for HF)
Definition: HcalShape.h:15
std::vector< DetId > hbheCells
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual void accumulate(edm::Event const &e, edm::EventSetup const &c) override
std::vector< PCaloHit > theHOHits
Definition: DetId.h:18
CaloHitResponse * theHOResponse
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
HcalHitCorrection * theHitCorrection
unsigned int value() const
Definition: StreamID.h:46
void setDbService(const HcalDbService *service)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
HcalAmplifier * theAmplifier
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &) const =0
Use this engine in event methods.
std::string ecalTBInfoLabel
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:90
HcalCoderFactory * theCoderFactory
ESHandle< TrackerGeometry > geometry
CaloVShape * theHcalShape
virtual void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
void setHitCorrection(const CaloVHitCorrection *hitCorrection)
If you want to correct hits, for attenuation or delay, set this.
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
StreamID streamID() const
Definition: Event.h:75
void setDetIds(const std::vector< DetId > &detIds)
edm::SortedCollection< HBHEDataFrame > HBHEDigiCollection
bool syncPhase() const
choice of the ADC time alignment (synchronous for LHC, asynchronous for test beams) ...
void accumulateCaloHits(edm::Handle< std::vector< PCaloHit > > const &hits, int bunchCrossing, CLHEP::HepRandomEngine *)