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  theHBHEHits.clear();
103  theHOHits.clear();
104  if (doPhaseShift) {
105 
106  edm::Handle<PEcalTBInfo> theEcalTBInfo;
107  e.getByLabel(ecalTBInfoLabel,theEcalTBInfo);
108  thisPhaseShift = theEcalTBInfo->phaseShift();
109 
110  DetId detIdHB(DetId::Hcal, 1);
111  setPhaseShift(detIdHB);
112  DetId detIdHO(DetId::Hcal, 3);
113  setPhaseShift(detIdHO);
114  }
115 
117  eventSetup.get<HcalTimeSlewRecord>().get("HBHE", delay);
118  hcalTimeSlew_delay_ = &*delay;
119 
121 
124 }
125 
126 void HcalTBDigiProducer::accumulateCaloHits(edm::Handle<std::vector<PCaloHit> > const& hcalHandle, int bunchCrossing, CLHEP::HepRandomEngine* engine) {
127 
128  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate trying to get SimHit";
129 
130  if(hcalHandle.isValid()) {
131  std::vector<PCaloHit> hits = *hcalHandle.product();
132  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate Hits corrected";
133  theHBHEDigitizer->add(hits, bunchCrossing, engine);
134  theHODigitizer->add(hits, bunchCrossing, engine);
135  }
136 }
137 
139  // Step A: Get Inputs, and accumulate digis
140 
141  edm::InputTag hcalTag("g4SimHits", "HcalHits");
143  e.getByLabel(hcalTag, hcalHandle);
144 
145  accumulateCaloHits(hcalHandle, 0, randomEngine(e.streamID()));
146 }
147 
149  // Step A: Get Inputs, and accumulate digis
150 
151  edm::InputTag hcalTag("g4SimHits", "HcalHits");
153  e.getByLabel(hcalTag, hcalHandle);
154 
155  accumulateCaloHits(hcalHandle, e.bunchCrossing(), randomEngine(streamID));
156 }
157 
159  // Step B: Create empty output
160  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
161  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
162  LogDebug("HcalSim") << "HcalTBDigiProducer::produce Empty collection created";
163  // Step C: Invoke the algorithm, getting back outputs.
164  theHBHEDigitizer->run(*hbheResult, randomEngine(e.streamID()));
165  edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HBHE digis : " << hbheResult->size();
166  theHODigitizer->run(*hoResult, randomEngine(e.streamID()));
167  edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HO digis : " << hoResult->size();
168 
169  // Step D: Put outputs into event
170  std::string const instance("simHcalDigis");
171  e.put(std::move(hbheResult), instance);
172  e.put(std::move(hoResult), instance);
173 
174 }
175 
177 
178  for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin();
179  hitItr != hits.end(); ++hitItr) {
180  HcalSubdetector subdet = HcalDetId(hitItr->id()).subdet();
181  if(subdet == HcalBarrel || subdet == HcalEndcap) {
182  theHBHEHits.push_back(*hitItr);
183  } else if(subdet == HcalOuter) {
184  theHOHits.push_back(*hitItr);
185  } else {
186  edm::LogError("HcalSim") << "Bad HcalHit subdetector " << subdet;
187  }
188  }
189 }
190 
192 
193  // TODO find a way to avoid doing this every event
195  eventSetup.get<CaloGeometryRecord>().get(geometry);
196 
197  const CaloGeometry * pGeometry = &*geometry;
198 
199  // see if we need to update
200  if(pGeometry != theGeometry) {
201  theGeometry = pGeometry;
202  updateGeometry();
203  }
204 }
205 
207 
210 
211  // Get cells for HB and HE
212  hbheCells.clear();
214  std::vector<DetId> heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
215  // combine HB & HE
216  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
217 
218  // Get cells for HO
219  hoCells.clear();
221 
222  edm::LogInfo("HcalSim") << "HcalTBDigiProducer update Geometry with "
223  << hbheCells.size() << " cells in HB/HE and "
224  << hoCells.size() << " cells in HO";
225 
227  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HB/HE";
229  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HO";
230 }
231 
233 
235  if ( !parameters.syncPhase() ) {
236  int myDet = detId.subdetId();
237  double passPhaseShift = thisPhaseShift + tunePhaseShift;
238  if (myDet <= 2) {
239  theHBHEResponse->setPhaseShift(passPhaseShift);
240  } else {
241  theHOResponse->setPhaseShift(passPhaseShift);
242  }
243  }
244 }
245 
246 CLHEP::HepRandomEngine* HcalTBDigiProducer::randomEngine(edm::StreamID const& streamID) {
247  unsigned int index = streamID.value();
248  if(index >= randomEngines_.size()) {
249  randomEngines_.resize(index + 1, nullptr);
250  }
251  CLHEP::HepRandomEngine* ptr = randomEngines_[index];
252  if(!ptr) {
254  ptr = &rng->getEngine(streamID);
255  randomEngines_[index] = ptr;
256  }
257  return ptr;
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:136
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
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.
void initializeHits()
HBHEDigitizer * theHBHEDigitizer
void setTimeSlew(const HcalTimeSlew *timeSlew)
Definition: HcalAmplifier.h:40
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:38
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:475
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
unsigned int value() const
Definition: StreamID.h:46
void setTimeSlewSim(HcalTimeSlewSim *timeSlewSim)
Definition: HcalAmplifier.h:35
~HcalTBDigiProducer() override
void setDbService(const HcalDbService *service)
const T & get() const
Definition: EventSetup.h:59
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.
Definition: CaloGeometry.cc:97
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
StreamID streamID() const
Definition: Event.h:95
T const * product() const
Definition: ESHandle.h:86
const HcalTimeSlew * hcalTimeSlew_delay_
def move(src, dest)
Definition: eostools.py:510
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
void accumulateCaloHits(edm::Handle< std::vector< PCaloHit > > const &hits, int bunchCrossing, CLHEP::HepRandomEngine *)