CMS 3D CMS Logo

EcalDigiProducer_Ph2.cc
Go to the documentation of this file.
36 
37 //*****************************************//
38 //Ecal Digi Producer for PhaseII data format
39 //Removed EE and ES
40 //Moved to EBDigiCollectionPh2
41 //Moved to 2 Gains instead of 3, and from 10 to 16 ecal digi samples
42 //This producer calls the EcalLiteDTUCoder, the PhaseII noise matrices and the EcalLiteDTUPedestals
43 //*****************************************//
45  edm::ProducesCollector producesCollector,
49  producesCollector.produces<EBDigiCollectionPh2>(m_apdDigiTag);
50 
53 
55 }
56 
57 // version for Pre-Mixing, for use outside of MixingModule
60  m_APDShape(iC),
61  m_ComponentShapes(iC),
62  m_EBShape(iC),
63 
64  m_EBdigiCollection(params.getParameter<std::string>("EBdigiCollectionPh2")),
65 
66  m_hitsProducerTag(params.getParameter<std::string>("hitsProducer")),
67  m_useLCcorrection(params.getUntrackedParameter<bool>("UseLCcorrection")),
68  m_apdSeparateDigi(params.getParameter<bool>("apdSeparateDigi")),
69  m_componentSeparateDigi(params.getParameter<bool>("componentSeparateDigi")),
70 
71  m_EBs25notCont(params.getParameter<double>("EBs25notContainment")),
72 
73  m_readoutFrameSize(ecalPh2::sampleSize),
74 
75  m_ParameterMap(std::make_unique<EcalSimParameterMap>(params.getParameter<double>("simHitToPhotoelectronsBarrel"),
76  0, // endcap parameters not needed
77  params.getParameter<double>("photoelectronsToAnalogBarrel"),
78  0,
79  params.getParameter<double>("samplingFactor"),
80  params.getParameter<double>("timePhase"),
81  m_readoutFrameSize,
82  params.getParameter<int>("binOfMaximum"),
83  params.getParameter<bool>("doPhotostatistics"),
84  params.getParameter<bool>("syncPhase"))),
85 
86  m_apdDigiTag(params.getParameter<std::string>("apdDigiTag")),
87  m_apdParameters(std::make_unique<APDSimParameters>(params.getParameter<bool>("apdAddToBarrel"),
88  m_apdSeparateDigi,
89  params.getParameter<double>("apdSimToPELow"),
90  params.getParameter<double>("apdSimToPEHigh"),
91  params.getParameter<double>("apdTimeOffset"),
92  params.getParameter<double>("apdTimeOffWidth"),
93  params.getParameter<bool>("apdDoPEStats"),
94  m_apdDigiTag,
95  params.getParameter<std::vector<double>>("apdNonlParms"))),
96 
97  m_componentDigiTag(params.getParameter<std::string>("componentDigiTag")),
98  m_componentParameters(
99  std::make_unique<ComponentSimParameterMap>(params.getParameter<bool>("componentAddToBarrel"),
100  m_componentSeparateDigi,
101  params.getParameter<double>("simHitToPhotoelectronsBarrel"),
102  0, // endcap parameters not needed
103  params.getParameter<double>("photoelectronsToAnalogBarrel"),
104  0,
105  params.getParameter<double>("samplingFactor"),
106  params.getParameter<double>("componentTimePhase"),
107  m_readoutFrameSize,
108  params.getParameter<int>("binOfMaximum"),
109  params.getParameter<bool>("doPhotostatistics"),
110  params.getParameter<bool>("syncPhase"))),
111 
112  m_APDResponse(!m_apdSeparateDigi ? nullptr
113  : std::make_unique<EBHitResponse_Ph2>(m_ParameterMap.get(),
114  &m_EBShape,
115  true,
116  false,
117  m_apdParameters.get(),
118  &m_APDShape,
119  m_componentParameters.get(),
120  &m_ComponentShapes)),
121 
122  m_ComponentResponse(!m_componentSeparateDigi ? nullptr
123  : std::make_unique<EBHitResponse_Ph2>(m_ParameterMap.get(),
124  &m_EBShape,
125  false,
126  true,
127  m_apdParameters.get(),
128  &m_APDShape,
129  m_componentParameters.get(),
130  &m_ComponentShapes)),
131 
132  m_EBResponse(std::make_unique<EBHitResponse_Ph2>(m_ParameterMap.get(),
133  &m_EBShape,
134  false, // barrel
135  false, // not component-based
136  m_apdParameters.get(),
137  &m_APDShape,
138  m_componentParameters.get(),
139  &m_ComponentShapes)),
140 
141  m_PreMix1(params.getParameter<bool>("EcalPreMixStage1")),
142  m_PreMix2(params.getParameter<bool>("EcalPreMixStage2")),
143  m_HitsEBToken(iC.consumes<std::vector<PCaloHit>>(edm::InputTag(m_hitsProducerTag, "EcalHitsEB"))),
144 
145  m_APDDigitizer(nullptr),
146  m_ComponentDigitizer(nullptr),
147  m_BarrelDigitizer(nullptr),
148  m_ElectronicsSim(nullptr),
149  m_Coder(nullptr),
150  m_APDElectronicsSim(nullptr),
151  m_APDCoder(nullptr),
152  m_Geometry(nullptr),
153  m_EBCorrNoise({{nullptr, nullptr}})
154 
155 {
156  iC.consumes<std::vector<PCaloHit>>(edm::InputTag(m_hitsProducerTag, "EcalHitsEB"));
157  pedestalToken_ = iC.esConsumes();
158  laserToken_ = iC.esConsumes<EcalLaserDbService, EcalLaserDbRecord>();
159  agcToken_ = iC.esConsumes<EcalADCToGeVConstant, EcalADCToGeVConstantRcd>();
160  icalToken_ = iC.esConsumes<EcalIntercalibConstants, EcalIntercalibConstantsRcd>();
161  geom_token_ = iC.esConsumes<CaloGeometry, CaloGeometryRecord>();
162 
163  const std::vector<double> ebCorMatG10Ph2 = params.getParameter<std::vector<double>>("EBCorrNoiseMatrixG10Ph2");
164  const std::vector<double> ebCorMatG01Ph2 = params.getParameter<std::vector<double>>("EBCorrNoiseMatrixG01Ph2");
165 
166  const bool applyConstantTerm = params.getParameter<bool>("applyConstantTerm");
167  const double rmsConstantTerm = params.getParameter<double>("ConstantTerm");
168 
169  const bool addNoise = params.getParameter<bool>("doENoise");
170  const bool cosmicsPhase = params.getParameter<bool>("cosmicsPhase");
171  const double cosmicsShift = params.getParameter<double>("cosmicsShift");
172 
173  // further phase for cosmics studies
174  if (cosmicsPhase) {
175  m_EBResponse->setPhaseShift(1. + cosmicsShift);
176  }
177 
178  EcalCorrMatrix_Ph2 ebMatrix[2];
179  const double errorCorrelation = 1.e-7;
180  assert(ebCorMatG10Ph2.size() == m_readoutFrameSize);
181  assert(ebCorMatG01Ph2.size() == m_readoutFrameSize);
182 
183  assert(errorCorrelation > std::abs(ebCorMatG10Ph2[0] - 1.0));
184  assert(errorCorrelation > std::abs(ebCorMatG01Ph2[0] - 1.0));
185 
186  for (unsigned int row(0); row != m_readoutFrameSize; ++row) {
187  assert(0 == row || 1. >= ebCorMatG10Ph2[row]);
188  assert(0 == row || 1. >= ebCorMatG01Ph2[row]);
189 
190  for (unsigned int column(0); column <= row; ++column) {
191  const unsigned int index(row - column);
192  ebMatrix[0](row, column) = ebCorMatG10Ph2[index];
193  ebMatrix[1](row, column) = ebCorMatG01Ph2[index];
194  }
195  }
196  m_EBCorrNoise[0] = std::make_unique<CorrelatedNoisifier<EcalCorrMatrix_Ph2>>(ebMatrix[0]);
197  m_EBCorrNoise[1] = std::make_unique<CorrelatedNoisifier<EcalCorrMatrix_Ph2>>(ebMatrix[1]);
198  m_Coder = std::make_unique<EcalLiteDTUCoder>(addNoise, m_PreMix1, m_EBCorrNoise[0].get(), m_EBCorrNoise[1].get());
199  m_ElectronicsSim =
200  std::make_unique<EcalElectronicsSim_Ph2>(m_ParameterMap.get(), m_Coder.get(), applyConstantTerm, rmsConstantTerm);
201 
202  if (m_apdSeparateDigi) {
203  m_APDCoder = std::make_unique<EcalLiteDTUCoder>(false, m_PreMix1, m_EBCorrNoise[0].get(), m_EBCorrNoise[1].get());
204 
205  m_APDElectronicsSim = std::make_unique<EcalElectronicsSim_Ph2>(
206  m_ParameterMap.get(), m_APDCoder.get(), applyConstantTerm, rmsConstantTerm);
207 
208  m_APDDigitizer = std::make_unique<EBDigitizer_Ph2>(m_APDResponse.get(), m_APDElectronicsSim.get(), false);
209  }
210  if (m_componentSeparateDigi) {
211  m_ComponentCoder =
212  std::make_unique<EcalLiteDTUCoder>(addNoise, m_PreMix1, m_EBCorrNoise[0].get(), m_EBCorrNoise[1].get());
213  m_ComponentElectronicsSim = std::make_unique<EcalElectronicsSim_Ph2>(
214  m_ParameterMap.get(), m_ComponentCoder.get(), applyConstantTerm, rmsConstantTerm);
215  m_ComponentDigitizer =
216  std::make_unique<EBDigitizer_Ph2>(m_ComponentResponse.get(), m_ComponentElectronicsSim.get(), addNoise);
217  }
218 
219  m_BarrelDigitizer = std::make_unique<EBDigitizer_Ph2>(m_EBResponse.get(), m_ElectronicsSim.get(), addNoise);
220 }
221 
223 
226  randomEngine_ = &rng->getEngine(event.streamID());
227 
230 
231  m_BarrelDigitizer->initializeHits();
232  if (m_apdSeparateDigi) {
233  m_APDDigitizer->initializeHits();
234  }
236  m_ComponentDigitizer->initializeHits();
237  }
238 }
239 
240 void EcalDigiProducer_Ph2::accumulateCaloHits(HitsHandle const& ebHandle, int bunchCrossing) {
241  if (ebHandle.isValid()) {
242  m_BarrelDigitizer->add(*ebHandle.product(), bunchCrossing, randomEngine_);
243 
244  if (m_apdSeparateDigi) {
245  m_APDDigitizer->add(*ebHandle.product(), bunchCrossing, randomEngine_);
246  }
248  m_ComponentDigitizer->add(*ebHandle.product(), bunchCrossing, randomEngine_);
249  }
250  }
251 }
252 
254  // Step A: Get Inputs
255 
259  const edm::Handle<std::vector<PCaloHit>>& ebHandle = e.getHandle(m_HitsEBToken);
260 
261  accumulateCaloHits(ebHandle, 0);
262 }
263 
266  edm::StreamID const& streamID) {
267  // Step A: Get Inputs
269 
270  edm::InputTag ebTag(m_hitsProducerTag, "EcalHitsEB");
271  e.getByLabel(ebTag, ebHandle);
272 
273  accumulateCaloHits(ebHandle, e.bunchCrossing());
274 }
275 
277  // Step B: Create empty output
278  std::unique_ptr<EBDigiCollectionPh2> apdResult(nullptr);
279  std::unique_ptr<EBDigiCollectionPh2> componentResult(nullptr);
280  std::unique_ptr<EBDigiCollectionPh2> barrelResult = std::make_unique<EBDigiCollectionPh2>();
281  if (m_apdSeparateDigi) {
282  apdResult = std::make_unique<EBDigiCollectionPh2>();
283  }
285  componentResult = std::make_unique<EBDigiCollectionPh2>();
286  }
287  // run the algorithm
288 
289  m_BarrelDigitizer->run(*barrelResult, randomEngine_);
290  cacheEBDigis(&*barrelResult);
291 
292  edm::LogInfo("DigiInfo") << "EB Digis: " << barrelResult->size();
293 
294  if (m_apdSeparateDigi) {
295  m_APDDigitizer->run(*apdResult, randomEngine_);
296  edm::LogInfo("DigiInfo") << "APD Digis: " << apdResult->size();
297  }
299  m_ComponentDigitizer->run(*componentResult, randomEngine_);
300  edm::LogInfo("DigiInfo") << "Component Digis: " << componentResult->size();
301  }
302 
303  // Step D: Put outputs into event
304 
305  event.put(std::move(barrelResult), m_EBdigiCollection);
307  event.put(std::move(componentResult), m_componentDigiTag);
308  }
309 
310  randomEngine_ = nullptr; // to prevent access outside event
311 }
312 
315  if (!rng.isAvailable()) {
316  throw cms::Exception("Configuration") << "RandomNumberGenerator service is not available.\n"
317  "You must add the service in the configuration file\n"
318  "or remove the module that requires it.";
319  }
320  CLHEP::HepRandomEngine* engine = &rng->getEngine(lumi.index());
321 
322  if (nullptr != m_APDResponse)
323  m_APDResponse->initialize(engine);
324  if (nullptr != m_ComponentResponse)
325  m_ComponentResponse->initialize(engine);
326  m_EBResponse->initialize(engine);
327 }
328 
330  // Pedestals from event setup
331  auto pedestals = &eventSetup.getData(pedestalToken_);
332 
333  m_Coder->setPedestals(pedestals);
334  if (nullptr != m_APDCoder)
335  m_APDCoder->setPedestals(pedestals);
336  if (nullptr != m_ComponentCoder)
337  m_ComponentCoder->setPedestals(pedestals);
338 
339  // Ecal Intercalibration Constants
340  auto ical = &eventSetup.getData(icalToken_);
341 
342  m_Coder->setIntercalibConstants(ical);
343  if (nullptr != m_APDCoder)
344  m_APDCoder->setIntercalibConstants(ical);
345  if (nullptr != m_ComponentCoder)
346  m_ComponentCoder->setIntercalibConstants(ical);
347 
348  m_EBResponse->setIntercal(ical);
349  if (nullptr != m_APDResponse)
350  m_APDResponse->setIntercal(ical);
351  if (nullptr != m_ComponentResponse)
352  m_ComponentResponse->setIntercal(ical);
353 
354  // Ecal LaserCorrection Constants
355  auto laser = &eventSetup.getData(laserToken_);
356 
357  const edm::TimeValue_t eventTimeValue = event.time().value();
358 
359  m_EBResponse->setEventTime(eventTimeValue);
360  m_EBResponse->setLaserConstants(laser, m_useLCcorrection);
361 
362  // ADC -> GeV Scale
363  auto agc = &eventSetup.getData(agcToken_);
364 
365  m_Coder->setGainRatios(ecalPh2::gains[0] / ecalPh2::gains[1]);
366  if (nullptr != m_APDCoder)
367  m_APDCoder->setGainRatios(ecalPh2::gains[0] / ecalPh2::gains[1]);
368  if (nullptr != m_ComponentCoder)
369  m_ComponentCoder->setGainRatios(ecalPh2::gains[0] / ecalPh2::gains[1]);
370 
371  const double EBscale((agc->getEBValue()) * ecalPh2::gains[1] * (ecalPh2::MAXADC)*m_EBs25notCont);
372 
373  LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEBValue() << "\n"
374  << " notCont = " << m_EBs25notCont << "\n"
375  << " saturation for EB = " << EBscale << ", " << m_EBs25notCont;
376 
377  m_Coder->setFullScaleEnergy(EBscale);
378  if (nullptr != m_APDCoder)
379  m_APDCoder->setFullScaleEnergy(EBscale);
380  if (nullptr != m_ComponentCoder)
381  m_ComponentCoder->setFullScaleEnergy(EBscale);
382 }
383 
385  // TODO find a way to avoid doing this every event
386  edm::ESHandle<CaloGeometry> hGeometry = eventSetup.getHandle(geom_token_);
387  const CaloGeometry* pGeometry = &*hGeometry;
388 
389  if (pGeometry != m_Geometry) {
390  m_Geometry = pGeometry;
391  updateGeometry();
392  }
393 }
394 
396  if (nullptr != m_APDResponse)
398  if (nullptr != m_ComponentResponse)
401 }
402 
404  m_BarrelDigitizer->setNoiseSignalGenerator(noiseGenerator);
405 }
ComponentShapeCollection m_ComponentShapes
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
std::unique_ptr< EBHitResponse_Ph2 > m_EBResponse
void accumulate(edm::Event const &e, edm::EventSetup const &c) override
CLHEP::HepRandomEngine * randomEngine_
std::unique_ptr< EBDigitizer_Ph2 > m_ComponentDigitizer
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
const std::string m_apdDigiTag
edm::ESGetToken< EcalLaserDbService, EcalLaserDbRecord > laserToken_
T const * product() const
Definition: Handle.h:70
std::unique_ptr< EBDigitizer_Ph2 > m_APDDigitizer
std::unique_ptr< EBHitResponse_Ph2 > m_APDResponse
edm::ESGetToken< EcalADCToGeVConstant, EcalADCToGeVConstantRcd > agcToken_
std::unique_ptr< EcalLiteDTUCoder > m_APDCoder
assert(be >=bs)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
std::unique_ptr< EcalLiteDTUCoder > m_Coder
void checkCalibrations(const edm::Event &event, const edm::EventSetup &eventSetup)
std::unique_ptr< EBHitResponse_Ph2 > m_ComponentResponse
const std::string m_hitsProducerTag
const edm::EDGetTokenT< std::vector< PCaloHit > > m_HitsEBToken
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geom_token_
const std::string m_EBdigiCollection
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
void setEventSetup(const edm::EventSetup &evtSetup)
static constexpr const float * gains
Definition: EcalConstants.h:33
virtual void cacheEBDigis(const EBDigiCollectionPh2 *ebDigiPtr) const
const CaloGeometry * m_Geometry
unsigned long long TimeValue_t
Definition: Timestamp.h:21
void setEventSetup(const edm::EventSetup &evtSetup, bool normalize=true)
void checkGeometry(const edm::EventSetup &eventSetup)
Log< level::Info, false > LogInfo
edm::ESGetToken< EcalIntercalibConstants, EcalIntercalibConstantsRcd > icalToken_
void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) override
edm::ESGetToken< EcalLiteDTUPedestalsMap, EcalLiteDTUPedestalsRcd > pedestalToken_
bool isValid() const
Definition: HandleBase.h:70
EcalIntercalibConstantMap EcalIntercalibConstants
EcalDigiProducer_Ph2(const edm::ParameterSet &params, edm::ProducesCollector producesCollector, edm::ConsumesCollector &iC)
HLT enums.
void setEBNoiseSignalGenerator(EcalBaseSignalGenerator *noiseGenerator)
bool isAvailable() const
Definition: Service.h:40
#define get
const std::string m_componentDigiTag
void accumulateCaloHits(HitsHandle const &ebHandle, int bunchCrossing)
std::unique_ptr< EBDigitizer_Ph2 > m_BarrelDigitizer
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
math::ErrorD< ecalPh2::sampleSize >::type EcalCorrMatrix_Ph2
def move(src, dest)
Definition: eostools.py:511
static constexpr unsigned int MAXADC
Definition: EcalConstants.h:38
Definition: event.py:1
std::unique_ptr< EcalLiteDTUCoder > m_ComponentCoder
#define LogDebug(id)