CMS 3D CMS Logo

HcalTBDigiProducer.cc
Go to the documentation of this file.
9 
19 
21 
23  theParameterMap(new HcalTBSimParameterMap(ps)),
24  theHcalShape(new HcalShape()),
25  theHcalIntegratedShape(new CaloShapeIntegrator(theHcalShape)),
26  theHBHEResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)),
27  theHOResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)),
28  theAmplifier(nullptr), theCoderFactory(nullptr), theElectronicsSim(nullptr),
29  theTimeSlewSim(nullptr), theHBHEDigitizer(nullptr), theHODigitizer(nullptr),
30  theHBHEHits(), theHOHits(), thisPhaseShift(0)
31 {
32  std::string const instance("simHcalDigis");
35  iC.consumes<std::vector<PCaloHit> >(edm::InputTag("g4SimHits", "HcalHits"));
36 
37  DetId detId(DetId::Hcal, 1);
40 
43 
44  bool doNoise = ps.getParameter<bool>("doNoise");
45  bool dummy1 = false;
46  bool dummy2 = false; // extra arguments for premixing
47  theAmplifier = new HcalAmplifier(theParameterMap, doNoise, dummy1, dummy2);
50 
51  double minFCToDelay= ps.getParameter<double>("minFCToDelay");
52  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
53 
54  hcalTimeSlew_delay_ = nullptr;
55  if(doTimeSlew) {
56  // no time slewing for HF
59  }
60 
63 
64  tunePhaseShift = ps.getUntrackedParameter<double>("tunePhaseShiftTB", 1.);
65  ecalTBInfoLabel = ps.getUntrackedParameter<std::string>("EcalTBInfoLabel","SimEcalTBG4Object");
66  edm::LogInfo("HcalSim") << "HcalTBDigiProducer initialized with doNoise = "
67  << doNoise << ", doTimeSlew = " << doTimeSlew
68  << " and doPhaseShift = " << doPhaseShift
69  << " tunePhasShift = " << tunePhaseShift;
70 
71  if (doPhaseShift) {
73  }
74 }
75 
77 
79  if (theHODigitizer) delete theHODigitizer;
80  if (theParameterMap) delete theParameterMap;
81  if (theHcalShape) delete theHcalShape;
83  if (theHBHEResponse) delete theHBHEResponse;
84  if (theHOResponse) delete theHOResponse;
86  if (theAmplifier) delete theAmplifier;
87  if (theCoderFactory) delete theCoderFactory;
88  if (theTimeSlewSim) delete theTimeSlewSim;
89 }
90 
91 
93  // get the appropriate gains, noises, & widths for this event
95  eventSetup.get<HcalDbRecord>().get(conditions);
96  theAmplifier->setDbService(conditions.product());
97  theCoderFactory->setDbService(conditions.product());
98 
99  // get the correct geometry
100  checkGeometry(eventSetup);
101 
102  // Cache random number engine
104  randomEngine_ = &rng->getEngine(e.streamID());
105 
106  theHBHEHits.clear();
107  theHOHits.clear();
108  if (doPhaseShift) {
109 
110  edm::Handle<PEcalTBInfo> theEcalTBInfo;
111  e.getByLabel(ecalTBInfoLabel,theEcalTBInfo);
112  thisPhaseShift = theEcalTBInfo->phaseShift();
113 
114  DetId detIdHB(DetId::Hcal, 1);
115  setPhaseShift(detIdHB);
116  DetId detIdHO(DetId::Hcal, 3);
117  setPhaseShift(detIdHO);
118  }
119 
121  eventSetup.get<HcalTimeSlewRecord>().get("HBHE", delay);
122  hcalTimeSlew_delay_ = &*delay;
123 
125 
128 }
129 
130 void HcalTBDigiProducer::accumulateCaloHits(edm::Handle<std::vector<PCaloHit> > const& hcalHandle, int bunchCrossing) {
131 
132  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate trying to get SimHit";
133 
134  if(hcalHandle.isValid()) {
135  std::vector<PCaloHit> hits = *hcalHandle.product();
136  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate Hits corrected";
137  theHBHEDigitizer->add(hits, bunchCrossing, randomEngine_);
138  theHODigitizer->add(hits, bunchCrossing, randomEngine_);
139  }
140 }
141 
143  // Step A: Get Inputs, and accumulate digis
144 
145  edm::InputTag hcalTag("g4SimHits", "HcalHits");
147  e.getByLabel(hcalTag, hcalHandle);
148 
149  accumulateCaloHits(hcalHandle, 0);
150 }
151 
153  // Step A: Get Inputs, and accumulate digis
154 
155  edm::InputTag hcalTag("g4SimHits", "HcalHits");
157  e.getByLabel(hcalTag, hcalHandle);
158 
159  accumulateCaloHits(hcalHandle, e.bunchCrossing());
160 }
161 
163  // Step B: Create empty output
164  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
165  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
166  LogDebug("HcalSim") << "HcalTBDigiProducer::produce Empty collection created";
167  // Step C: Invoke the algorithm, getting back outputs.
168  theHBHEDigitizer->run(*hbheResult, randomEngine_);
169  edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HBHE digis : " << hbheResult->size();
170  theHODigitizer->run(*hoResult, randomEngine_);
171  edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HO digis : " << hoResult->size();
172 
173  // Step D: Put outputs into event
174  std::string const instance("simHcalDigis");
175  e.put(std::move(hbheResult), instance);
176  e.put(std::move(hoResult), instance);
177 
178  randomEngine_ = nullptr; // to prevent access outside event
179 }
180 
182 
183  for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin();
184  hitItr != hits.end(); ++hitItr) {
185  HcalSubdetector subdet = HcalDetId(hitItr->id()).subdet();
186  if(subdet == HcalBarrel || subdet == HcalEndcap) {
187  theHBHEHits.push_back(*hitItr);
188  } else if(subdet == HcalOuter) {
189  theHOHits.push_back(*hitItr);
190  } else {
191  edm::LogError("HcalSim") << "Bad HcalHit subdetector " << subdet;
192  }
193  }
194 }
195 
197 
198  // TODO find a way to avoid doing this every event
200  eventSetup.get<CaloGeometryRecord>().get(geometry);
201 
202  const CaloGeometry * pGeometry = &*geometry;
203 
204  // see if we need to update
205  if(pGeometry != theGeometry) {
206  theGeometry = pGeometry;
207  updateGeometry();
208  }
209 }
210 
212 
215 
216  // Get cells for HB and HE
217  hbheCells.clear();
219  std::vector<DetId> heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
220  // combine HB & HE
221  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
222 
223  // Get cells for HO
224  hoCells.clear();
226 
227  edm::LogInfo("HcalSim") << "HcalTBDigiProducer update Geometry with "
228  << hbheCells.size() << " cells in HB/HE and "
229  << hoCells.size() << " cells in HO";
230 
232  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HB/HE";
234  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HO";
235 }
236 
238 
240  if ( !parameters.syncPhase() ) {
241  int myDet = detId.subdetId();
242  double passPhaseShift = thisPhaseShift + tunePhaseShift;
243  if (myDet <= 2) {
244  theHBHEResponse->setPhaseShift(passPhaseShift);
245  } else {
246  theHOResponse->setPhaseShift(passPhaseShift);
247  }
248  }
249 }
#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:137
CaloHitResponse * theHBHEResponse
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
static PFTauRenderPlugin instance
HBHEHitFilter theHBHEHitFilter
HODigitizer * theHODigitizer
HcalElectronicsSim * theElectronicsSim
HOHitFilter theHOHitFilter
#define nullptr
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)
if you want to reject hits, for example, from a certain subdetector, set this
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 accumulateCaloHits(edm::Handle< std::vector< PCaloHit > > const &hits, int bunchCrossing)
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:535
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:38
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:62
StreamID streamID() const
Definition: Event.h:96
T const * product() const
Definition: ESHandle.h:86
const HcalTimeSlew * hcalTimeSlew_delay_
def move(src, dest)
Definition: eostools.py:511
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) ...
HcalTimeSlewSim * theTimeSlewSim