CMS 3D CMS Logo

HcalTBDigiProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 
10 
18 
20 
22  edm::ProducesCollector producesCollector,
24  : tunePhaseShift(ps.getUntrackedParameter<double>("tunePhaseShiftTB", 1.)),
25  ecalTBInfoLabel(ps.getUntrackedParameter<std::string>("EcalTBInfoLabel", "SimEcalTBG4Object")),
26  theParameterMap(new HcalTBSimParameterMap(ps)),
27  paraMap(new HcalSimParameterMap(ps)),
28  theHcalShape(new HcalShape()),
29  theHcalIntegratedShape(new CaloShapeIntegrator(theHcalShape)),
30  theHBHEResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)),
31  theHOResponse(new CaloHitResponse(theParameterMap, theHcalIntegratedShape)),
32  theAmplifier(nullptr),
33  theCoderFactory(nullptr),
34  theElectronicsSim(nullptr),
35  theTimeSlewSim(nullptr),
36  geometryToken_(iC.esConsumes()),
37  conditionsToken_(iC.esConsumes()),
38  hcalTimeSlew_delay_token_(iC.esConsumes(edm::ESInputTag("", "HBHE"))),
39  hcalToken_(iC.consumes<std::vector<PCaloHit>>(edm::InputTag("g4SimHits", "HcalHits"))),
40  theHBHEHits(),
41  theHOHits(),
42  thisPhaseShift(0) {
43  std::string const instance("simHcalDigis");
44  producesCollector.produces<HBHEDigiCollection>(instance);
45  producesCollector.produces<HODigiCollection>(instance);
46 
50 
53 
54  bool doNoise = ps.getParameter<bool>("doNoise");
55  bool dummy1 = false;
56  bool dummy2 = false; // extra arguments for premixing
57  theAmplifier = new HcalAmplifier(theParameterMap, doNoise, dummy1, dummy2);
60 
61  double minFCToDelay = ps.getParameter<double>("minFCToDelay");
62  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
63 
64  hcalTimeSlew_delay_ = nullptr;
65  if (doTimeSlew) {
66  // no time slewing for HF
69  }
70 
71  theHBHEDigitizer = std::make_unique<HBHEDigitizer>(theHBHEResponse, theElectronicsSim, doNoise);
72  theHODigitizer = std::make_unique<HODigitizer>(theHOResponse, theElectronicsSim, doNoise);
73 
74  edm::LogVerbatim("HcalSim") << "HcalTBDigiProducer initialized with doNoise = " << doNoise
75  << ", doTimeSlew = " << doTimeSlew << " and doPhaseShift = " << doPhaseShift
76  << " tunePhasShift = " << tunePhaseShift;
77 
78  if (doPhaseShift)
80 }
81 
83  if (theParameterMap)
84  delete theParameterMap;
85  if (paraMap)
86  delete paraMap;
87  if (theHcalShape)
88  delete theHcalShape;
91  if (theHBHEResponse)
92  delete theHBHEResponse;
93  if (theHOResponse)
94  delete theHOResponse;
96  delete theElectronicsSim;
97  if (theAmplifier)
98  delete theAmplifier;
99  if (theCoderFactory)
100  delete theCoderFactory;
101  if (theTimeSlewSim)
102  delete theTimeSlewSim;
103 }
104 
106  // get the appropriate gains, noises, & widths for this event
110 
111  // get the correct geometry
113 
114  // Cache random number engine
116  randomEngine_ = &rng->getEngine(e.streamID());
117 
118  theHBHEHits.clear();
119  theHOHits.clear();
120  if (doPhaseShift) {
121  const edm::Handle<PEcalTBInfo> &theEcalTBInfo = e.getHandle(theEcalTBToken_);
122  thisPhaseShift = theEcalTBInfo->phaseShift();
123 
124  DetId detIdHB(DetId::Hcal, 1);
125  setPhaseShift(detIdHB);
126  DetId detIdHO(DetId::Hcal, 3);
127  setPhaseShift(detIdHO);
128  }
129 
131 
133 
134  theHBHEDigitizer->initializeHits();
135  theHODigitizer->initializeHits();
136 }
137 
138 void HcalTBDigiProducer::accumulateCaloHits(edm::Handle<std::vector<PCaloHit>> const &hcalHandle, int bunchCrossing) {
139  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate trying to get SimHit";
140 
141  if (hcalHandle.isValid()) {
142  std::vector<PCaloHit> hits = *hcalHandle.product();
143  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate Hits corrected";
144  theHBHEDigitizer->add(hits, bunchCrossing, randomEngine_);
145  theHODigitizer->add(hits, bunchCrossing, randomEngine_);
146  }
147 }
148 
150  // Step A: Get Inputs, and accumulate digis
151 
152  edm::InputTag hcalTag("g4SimHits", "HcalHits");
153  const edm::Handle<std::vector<PCaloHit>> &hcalHandle = e.getHandle(hcalToken_);
154 
155  accumulateCaloHits(hcalHandle, 0);
156 }
157 
159  edm::EventSetup const &,
160  edm::StreamID const &streamID) {
161  // Step A: Get Inputs, and accumulate digis
162 
163  edm::InputTag hcalTag("g4SimHits", "HcalHits");
165  e.getByLabel(hcalTag, hcalHandle);
166 
167  accumulateCaloHits(hcalHandle, e.bunchCrossing());
168 }
169 
171  // Step B: Create empty output
172  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
173  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
174  LogDebug("HcalSim") << "HcalTBDigiProducer::produce Empty collection created";
175  // Step C: Invoke the algorithm, getting back outputs.
176  theHBHEDigitizer->run(*hbheResult, randomEngine_);
177  edm::LogVerbatim("HcalSim") << "HcalTBDigiProducer: HBHE digis : " << hbheResult->size();
178  theHODigitizer->run(*hoResult, randomEngine_);
179  edm::LogVerbatim("HcalSim") << "HcalTBDigiProducer: HO digis : " << hoResult->size();
180 
181  // Step D: Put outputs into event
182  std::string const instance("simHcalDigis");
183  e.put(std::move(hbheResult), instance);
184  e.put(std::move(hoResult), instance);
185 
186  randomEngine_ = nullptr; // to prevent access outside event
187 }
188 
190  for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin(); hitItr != hits.end(); ++hitItr) {
191  HcalSubdetector subdet = HcalDetId(hitItr->id()).subdet();
192  if (subdet == HcalBarrel || subdet == HcalEndcap) {
193  theHBHEHits.push_back(*hitItr);
194  } else if (subdet == HcalOuter) {
195  theHOHits.push_back(*hitItr);
196  } else {
197  edm::LogError("HcalSim") << "Bad HcalHit subdetector " << subdet;
198  }
199  }
200 }
201 
203  // see if we need to update
206  updateGeometry();
207  }
208 }
209 
213 
214  // Get cells for HB and HE
215  hbheCells.clear();
217  std::vector<DetId> heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
218  // combine HB & HE
219  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
220 
221  // Get cells for HO
222  hoCells.clear();
224 
225  edm::LogVerbatim("HcalSim") << "HcalTBDigiProducer update Geometry with " << hbheCells.size()
226  << " cells in HB/HE and " << hoCells.size() << " cells in HO";
227 
228  theHBHEDigitizer->setDetIds(hbheCells);
229  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HB/HE";
230  theHODigitizer->setDetIds(hoCells);
231  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HO";
232 }
233 
236  if (!parameters.syncPhase()) {
237  int myDet = detId.subdetId();
238  double passPhaseShift = thisPhaseShift + tunePhaseShift;
239  if (myDet <= 2) {
240  theHBHEResponse->setPhaseShift(passPhaseShift);
241  } else {
242  theHOResponse->setPhaseShift(passPhaseShift);
243  }
244  }
245 }
void setPhaseShift(const DetId &detId)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Log< level::Info, true > LogVerbatim
void setGeometry(const CaloGeometry *geometry)
geometry needed for time-of-flight
void setDbService(const HcalDbService *service)
the Producer will probably update this every event
void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void sortHits(const edm::PCaloHitContainer &hits)
fills the vectors for each subdetector
std::vector< PCaloHit > PCaloHitContainer
std::vector< DetId > hoCells
CaloHitResponse * theHBHEResponse
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
static PFTauRenderPlugin instance
HBHEHitFilter theHBHEHitFilter
double phaseShift() const
Definition: PEcalTBInfo.h:37
const CaloSimParameters & simParameters(const DetId &id) const override
HcalSimParameterMap * paraMap
HcalElectronicsSim * theElectronicsSim
const edm::ESGetToken< HcalTimeSlew, HcalTimeSlewRecord > hcalTimeSlew_delay_token_
HOHitFilter theHOHitFilter
Log< level::Error, false > LogError
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)
const edm::ESGetToken< HcalDbService, HcalDbRecord > conditionsToken_
std::vector< PCaloHit > theHBHEHits
edm::SortedCollection< HODataFrame > HODigiCollection
const edm::EDGetTokenT< std::vector< PCaloHit > > hcalToken_
CaloVShape * theHcalIntegratedShape
void setHitFilter(const CaloVHitFilter *filter)
Creates electronics signals from hits.
void setTimeSlew(const HcalTimeSlew *timeSlew)
Definition: HcalAmplifier.h:38
HcalSubdetector
Definition: HcalAssistant.h:31
void checkGeometry(const edm::EventSetup &eventSetup)
shaper for Hcal (not for HF)
Definition: HcalShape.h:15
HcalTBDigiProducer(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &iC)
std::vector< DetId > hbheCells
void accumulate(edm::Event const &e, edm::EventSetup const &c) override
std::vector< PCaloHit > theHOHits
edm::ESWatcher< CaloGeometryRecord > geometryWatcher_
Definition: DetId.h:17
const std::string ecalTBInfoLabel
CaloHitResponse * theHOResponse
void setTimeSlewSim(HcalTimeSlewSim *timeSlewSim)
Definition: HcalAmplifier.h:35
~HcalTBDigiProducer() override
void setDbService(const HcalDbService *service)
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:75
HcalAmplifier * theAmplifier
std::unique_ptr< HBHEDigitizer > theHBHEDigitizer
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::EDGetTokenT< PEcalTBInfo > theEcalTBToken_
CLHEP::HepRandomEngine * randomEngine_
HcalCoderFactory * theCoderFactory
CaloVShape * theHcalShape
HLT enums.
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
const double tunePhaseShift
std::unique_ptr< HODigitizer > theHODigitizer
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometryToken_
const HcalTimeSlew * hcalTimeSlew_delay_
void accumulateCaloHits(edm::Handle< std::vector< PCaloHit >> const &hits, int bunchCrossing)
def move(src, dest)
Definition: eostools.py:511
edm::SortedCollection< HBHEDataFrame > HBHEDigiCollection
HcalTimeSlewSim * theTimeSlewSim
#define LogDebug(id)