test
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  theTimeSlewSim(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 doNoise = ps.getParameter<bool>("doNoise");
42  bool dummy1 = false;
43  bool dummy2 = false; // extra arguments for premixing
44  theAmplifier = new HcalAmplifier(theParameterMap, doNoise, dummy1, dummy2);
47 
48  double minFCToDelay= ps.getParameter<double>("minFCToDelay");
49  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
50  if(doTimeSlew) {
51  // no time slewing for HF
54  }
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;
83  if (theTimeSlewSim) delete theTimeSlewSim;
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  LogDebug("HcalSim") << "HcalTBDigiProducer::accumulate Hits corrected";
122  theHBHEDigitizer->add(hits, bunchCrossing, engine);
123  theHODigitizer->add(hits, bunchCrossing, engine);
124  }
125 }
126 
128  // Step A: Get Inputs, and accumulate digis
129 
130  edm::InputTag hcalTag("g4SimHits", "HcalHits");
132  e.getByLabel(hcalTag, hcalHandle);
133 
134  accumulateCaloHits(hcalHandle, 0, randomEngine(e.streamID()));
135 }
136 
138  // Step A: Get Inputs, and accumulate digis
139 
140  edm::InputTag hcalTag("g4SimHits", "HcalHits");
142  e.getByLabel(hcalTag, hcalHandle);
143 
144  accumulateCaloHits(hcalHandle, e.bunchCrossing(), randomEngine(streamID));
145 }
146 
148  // Step B: Create empty output
149  std::unique_ptr<HBHEDigiCollection> hbheResult(new HBHEDigiCollection());
150  std::unique_ptr<HODigiCollection> hoResult(new HODigiCollection());
151  LogDebug("HcalSim") << "HcalTBDigiProducer::produce Empty collection created";
152  // Step C: Invoke the algorithm, getting back outputs.
153  theHBHEDigitizer->run(*hbheResult, randomEngine(e.streamID()));
154  edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HBHE digis : " << hbheResult->size();
155  theHODigitizer->run(*hoResult, randomEngine(e.streamID()));
156  edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HO digis : " << hoResult->size();
157 
158  // Step D: Put outputs into event
159  std::string const instance("simHcalDigis");
160  e.put(std::move(hbheResult), instance);
161  e.put(std::move(hoResult), instance);
162 
163 }
164 
166 
167  for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin();
168  hitItr != hits.end(); ++hitItr) {
169  HcalSubdetector subdet = HcalDetId(hitItr->id()).subdet();
170  if(subdet == HcalBarrel || subdet == HcalEndcap) {
171  theHBHEHits.push_back(*hitItr);
172  } else if(subdet == HcalOuter) {
173  theHOHits.push_back(*hitItr);
174  } else {
175  edm::LogError("HcalSim") << "Bad HcalHit subdetector " << subdet;
176  }
177  }
178 }
179 
181 
182  // TODO find a way to avoid doing this every event
184  eventSetup.get<CaloGeometryRecord>().get(geometry);
185 
186  const CaloGeometry * pGeometry = &*geometry;
187 
188  // see if we need to update
189  if(pGeometry != theGeometry) {
190  theGeometry = pGeometry;
191  updateGeometry();
192  }
193 }
194 
196 
199 
200  // Get cells for HB and HE
201  hbheCells.clear();
203  std::vector<DetId> heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
204  // combine HB & HE
205  hbheCells.insert(hbheCells.end(), heCells.begin(), heCells.end());
206 
207  // Get cells for HO
208  hoCells.clear();
210 
211  edm::LogInfo("HcalSim") << "HcalTBDigiProducer update Geometry with "
212  << hbheCells.size() << " cells in HB/HE and "
213  << hoCells.size() << " cells in HO";
214 
216  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HB/HE";
218  LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HO";
219 }
220 
222 
224  if ( !parameters.syncPhase() ) {
225  int myDet = detId.subdetId();
226  double passPhaseShift = thisPhaseShift + tunePhaseShift;
227  if (myDet <= 2) {
228  theHBHEResponse->setPhaseShift(passPhaseShift);
229  } else {
230  theHOResponse->setPhaseShift(passPhaseShift);
231  }
232  }
233 }
234 
235 CLHEP::HepRandomEngine* HcalTBDigiProducer::randomEngine(edm::StreamID const& streamID) {
236  unsigned int index = streamID.value();
237  if(index >= randomEngines_.size()) {
238  randomEngines_.resize(index + 1, nullptr);
239  }
240  CLHEP::HepRandomEngine* ptr = randomEngines_[index];
241  if(!ptr) {
243  ptr = &rng->getEngine(streamID);
244  randomEngines_[index] = ptr;
245  }
246  return ptr;
247 }
#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
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:122
virtual const CaloSimParameters & simParameters(const DetId &id) const
CaloHitResponse * theHBHEResponse
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
edm::Service< edm::RandomNumberGenerator > rng
static PFTauRenderPlugin instance
HBHEHitFilter theHBHEHitFilter
HODigitizer * theHODigitizer
HcalElectronicsSim * theElectronicsSim
HOHitFilter theHOHitFilter
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.
HcalTBDigiProducer(const edm::ParameterSet &ps, edm::stream::EDProducerBase &mixMod, edm::ConsumesCollector &iC)
void initializeHits()
HBHEDigitizer * theHBHEDigitizer
def move
Definition: eostools.py:510
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:413
virtual void accumulate(edm::Event const &e, edm::EventSetup const &c) override
std::vector< PCaloHit > theHOHits
Definition: DetId.h:18
CaloHitResponse * theHOResponse
unsigned int value() const
Definition: StreamID.h:46
void setTimeSlewSim(HcalTimeSlewSim *timeSlewSim)
Definition: HcalAmplifier.h:34
void setDbService(const HcalDbService *service)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
HcalAmplifier * theAmplifier
std::string ecalTBInfoLabel
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:92
HcalCoderFactory * theCoderFactory
ESHandle< TrackerGeometry > geometry
CaloVShape * theHcalShape
virtual 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:81
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 *)