CMS 3D CMS Logo

HcalTBDigiProducer.cc
Go to the documentation of this file.
9 
19 
21 
23  edm::ProducerBase &mixMod,
25  : theParameterMap(new HcalTBSimParameterMap(ps)),
26  theHcalShape(new HcalShape()),
27  theHcalIntegratedShape(new CaloShapeIntegrator(theHcalShape)),
28  theHBHEResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)),
29  theHOResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)),
30  theAmplifier(nullptr),
31  theCoderFactory(nullptr),
32  theElectronicsSim(nullptr),
33  theTimeSlewSim(nullptr),
34  theHBHEDigitizer(nullptr),
35  theHODigitizer(nullptr),
36  theHBHEHits(),
37  theHOHits(),
38  thisPhaseShift(0) {
39  std::string const instance("simHcalDigis");
42  iC.consumes<std::vector<PCaloHit>>(edm::InputTag("g4SimHits", "HcalHits"));
43 
44  DetId detId(DetId::Hcal, 1);
47 
50 
51  bool doNoise = ps.getParameter<bool>("doNoise");
52  bool dummy1 = false;
53  bool dummy2 = false; // extra arguments for premixing
54  theAmplifier = new HcalAmplifier(theParameterMap, doNoise, dummy1, dummy2);
57 
58  double minFCToDelay = ps.getParameter<double>("minFCToDelay");
59  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
60 
61  hcalTimeSlew_delay_ = nullptr;
62  if (doTimeSlew) {
63  // no time slewing for HF
64  theTimeSlewSim = new HcalTimeSlewSim(theParameterMap, minFCToDelay);
66  }
67 
70 
71  tunePhaseShift = ps.getUntrackedParameter<double>("tunePhaseShiftTB", 1.);
72  ecalTBInfoLabel = ps.getUntrackedParameter<std::string>("EcalTBInfoLabel", "SimEcalTBG4Object");
73  edm::LogInfo("HcalSim") << "HcalTBDigiProducer initialized with doNoise = " << doNoise
74  << ", doTimeSlew = " << doTimeSlew << " and doPhaseShift = " << doPhaseShift
75  << " tunePhasShift = " << tunePhaseShift;
76 
77  if (doPhaseShift) {
79  }
80 }
81 
83  if (theHBHEDigitizer)
84  delete theHBHEDigitizer;
85  if (theHODigitizer)
86  delete theHODigitizer;
87  if (theParameterMap)
88  delete theParameterMap;
89  if (theHcalShape)
90  delete theHcalShape;
93  if (theHBHEResponse)
94  delete theHBHEResponse;
95  if (theHOResponse)
96  delete theHOResponse;
98  delete theElectronicsSim;
99  if (theAmplifier)
100  delete theAmplifier;
101  if (theCoderFactory)
102  delete theCoderFactory;
103  if (theTimeSlewSim)
104  delete theTimeSlewSim;
105 }
106 
108  // get the appropriate gains, noises, & widths for this event
109  edm::ESHandle<HcalDbService> conditions;
110  eventSetup.get<HcalDbRecord>().get(conditions);
111  theAmplifier->setDbService(conditions.product());
112  theCoderFactory->setDbService(conditions.product());
113 
114  // get the correct geometry
115  checkGeometry(eventSetup);
116 
117  // Cache random number engine
119  randomEngine_ = &rng->getEngine(e.streamID());
120 
121  theHBHEHits.clear();
122  theHOHits.clear();
123  if (doPhaseShift) {
124  edm::Handle<PEcalTBInfo> theEcalTBInfo;
125  e.getByLabel(ecalTBInfoLabel, theEcalTBInfo);
126  thisPhaseShift = theEcalTBInfo->phaseShift();
127 
128  DetId detIdHB(DetId::Hcal, 1);
129  setPhaseShift(detIdHB);
130  DetId detIdHO(DetId::Hcal, 3);
131  setPhaseShift(detIdHO);
132  }
133 
135  eventSetup.get<HcalTimeSlewRecord>().get("HBHE", delay);
136  hcalTimeSlew_delay_ = &*delay;
137 
139 
142 }
143 
144 void HcalTBDigiProducer::accumulateCaloHits(edm::Handle<std::vector<PCaloHit>> const &hcalHandle, int bunchCrossing) {
145  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate trying to get SimHit";
146 
147  if (hcalHandle.isValid()) {
148  std::vector<PCaloHit> hits = *hcalHandle.product();
149  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate Hits corrected";
150  theHBHEDigitizer->add(hits, bunchCrossing, randomEngine_);
151  theHODigitizer->add(hits, bunchCrossing, randomEngine_);
152  }
153 }
154 
156  // Step A: Get Inputs, and accumulate digis
157 
158  edm::InputTag hcalTag("g4SimHits", "HcalHits");
160  e.getByLabel(hcalTag, hcalHandle);
161 
162  accumulateCaloHits(hcalHandle, 0);
163 }
164 
166  edm::EventSetup const &,
167  edm::StreamID const &streamID) {
168  // Step A: Get Inputs, and accumulate digis
169 
170  edm::InputTag hcalTag("g4SimHits", "HcalHits");
172  e.getByLabel(hcalTag, hcalHandle);
173 
174  accumulateCaloHits(hcalHandle, e.bunchCrossing());
175 }
176 
178  // Step B: Create empty output
179  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
180  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
181  LogDebug("HcalSim") << "HcalTBDigiProducer::produce Empty collection created";
182  // Step C: Invoke the algorithm, getting back outputs.
183  theHBHEDigitizer->run(*hbheResult, randomEngine_);
184  edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HBHE digis : " << hbheResult->size();
185  theHODigitizer->run(*hoResult, randomEngine_);
186  edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HO digis : " << hoResult->size();
187 
188  // Step D: Put outputs into event
189  std::string const instance("simHcalDigis");
190  e.put(std::move(hbheResult), instance);
191  e.put(std::move(hoResult), instance);
192 
193  randomEngine_ = nullptr; // to prevent access outside event
194 }
195 
197  for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin(); hitItr != hits.end(); ++hitItr) {
198  HcalSubdetector subdet = HcalDetId(hitItr->id()).subdet();
199  if (subdet == HcalBarrel || subdet == HcalEndcap) {
200  theHBHEHits.push_back(*hitItr);
201  } else if (subdet == HcalOuter) {
202  theHOHits.push_back(*hitItr);
203  } else {
204  edm::LogError("HcalSim") << "Bad HcalHit subdetector " << subdet;
205  }
206  }
207 }
208 
210  // TODO find a way to avoid doing this every event
212  eventSetup.get<CaloGeometryRecord>().get(geometry);
213 
214  const CaloGeometry *pGeometry = &*geometry;
215 
216  // see if we need to update
217  if (pGeometry != theGeometry) {
218  theGeometry = pGeometry;
219  updateGeometry();
220  }
221 }
222 
226 
227  // Get cells for HB and HE
228  hbheCells.clear();
230  std::vector<DetId> heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
231  // combine HB & HE
232  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
233 
234  // Get cells for HO
235  hoCells.clear();
237 
238  edm::LogInfo("HcalSim") << "HcalTBDigiProducer update Geometry with " << hbheCells.size() << " cells in HB/HE and "
239  << hoCells.size() << " cells in HO";
240 
242  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HB/HE";
244  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HO";
245 }
246 
249  if (!parameters.syncPhase()) {
250  int myDet = detId.subdetId();
251  double passPhaseShift = thisPhaseShift + tunePhaseShift;
252  if (myDet <= 2) {
253  theHBHEResponse->setPhaseShift(passPhaseShift);
254  } else {
255  theHOResponse->setPhaseShift(passPhaseShift);
256  }
257  }
258 }
#define LogDebug(id)
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
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
void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
void sortHits(const edm::PCaloHitContainer &hits)
fills the vectors for each subdetector
std::vector< PCaloHit > PCaloHitContainer
std::vector< DetId > hoCells
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
CaloHitResponse * theHBHEResponse
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
static PFTauRenderPlugin instance
HBHEHitFilter theHBHEHitFilter
#define nullptr
HODigitizer * theHODigitizer
HcalElectronicsSim * theElectronicsSim
HOHitFilter theHOHitFilter
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
HcalTBSimParameterMap * theParameterMap
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
edm::SortedCollection< HODataFrame > HODigiCollection
CaloVShape * theHcalIntegratedShape
void setHitFilter(const CaloVHitFilter *filter)
Creates electronics signals from hits.
void initializeHits()
HBHEDigitizer * theHBHEDigitizer
void setTimeSlew(const HcalTimeSlew *timeSlew)
Definition: HcalAmplifier.h:40
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
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
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
void accumulate(edm::Event const &e, edm::EventSetup const &c) override
std::vector< PCaloHit > theHOHits
Definition: DetId.h:18
CaloHitResponse * theHOResponse
const CaloSimParameters & simParameters(const DetId &id) const override
void setTimeSlewSim(HcalTimeSlewSim *timeSlewSim)
Definition: HcalAmplifier.h:35
~HcalTBDigiProducer() override
void setDbService(const HcalDbService *service)
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
HcalTBDigiProducer(const edm::ParameterSet &ps, edm::ProducerBase &mixMod, edm::ConsumesCollector &iC)
HcalAmplifier * theAmplifier
std::string ecalTBInfoLabel
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
CLHEP::HepRandomEngine * randomEngine_
HcalCoderFactory * theCoderFactory
double phaseShift() const
Definition: PEcalTBInfo.h:37
ESHandle< TrackerGeometry > geometry
CaloVShape * theHcalShape
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
T get() const
Definition: EventSetup.h:71
StreamID streamID() const
Definition: Event.h:95
T const * product() const
Definition: ESHandle.h:86
const HcalTimeSlew * hcalTimeSlew_delay_
void accumulateCaloHits(edm::Handle< std::vector< PCaloHit >> const &hits, int bunchCrossing)
def move(src, dest)
Definition: eostools.py:511
void setDetIds(const std::vector< DetId > &detIds)
edm::SortedCollection< HBHEDataFrame > HBHEDigiCollection
bool syncPhase() const
HcalTimeSlewSim * theTimeSlewSim