CMS 3D CMS Logo

EcalDigiProducer_Ph2.cc
Go to the documentation of this file.
35 
36 //*****************************************//
37 //Ecal Digi Producer for PhaseII data format
38 //Removed EE and ES
39 //Moved to EBDigiCollectionPh2
40 //Moved to 2 Gains instead of 3, and from 10 to 16 ecal digi samples
41 //This producer calls the EcalLiteDTUCoder, the PhaseII noise matrices and the EcalLiteDTUPedestals
42 //*****************************************//
44  edm::ProducesCollector producesCollector,
48  producesCollector.produces<EBDigiCollectionPh2>(m_apdDigiTag);
49 
51 }
52 
53 // version for Pre-Mixing, for use outside of MixingModule
56  m_APDShape(iC),
57  m_EBShape(iC),
58 
59  m_EBdigiCollection(params.getParameter<std::string>("EBdigiCollectionPh2")),
60 
61  m_hitsProducerTag(params.getParameter<std::string>("hitsProducer")),
62  m_useLCcorrection(params.getUntrackedParameter<bool>("UseLCcorrection")),
63  m_apdSeparateDigi(params.getParameter<bool>("apdSeparateDigi")),
64 
65  m_EBs25notCont(params.getParameter<double>("EBs25notContainment")),
66 
67  m_readoutFrameSize(ecalPh2::sampleSize),
68 
69  m_ParameterMap(std::make_unique<EcalSimParameterMap>(params.getParameter<double>("simHitToPhotoelectronsBarrel"),
70  0, // endcap parameters not needed
71  params.getParameter<double>("photoelectronsToAnalogBarrel"),
72  0,
73  params.getParameter<double>("samplingFactor"),
74  params.getParameter<double>("timePhase"),
75  m_readoutFrameSize,
76  params.getParameter<int>("binOfMaximum"),
77  params.getParameter<bool>("doPhotostatistics"),
78  params.getParameter<bool>("syncPhase"))),
79 
80  m_apdDigiTag(params.getParameter<std::string>("apdDigiTag")),
81  m_apdParameters(std::make_unique<APDSimParameters>(params.getParameter<bool>("apdAddToBarrel"),
82  m_apdSeparateDigi,
83  params.getParameter<double>("apdSimToPELow"),
84  params.getParameter<double>("apdSimToPEHigh"),
85  params.getParameter<double>("apdTimeOffset"),
86  params.getParameter<double>("apdTimeOffWidth"),
87  params.getParameter<bool>("apdDoPEStats"),
88  m_apdDigiTag,
89  params.getParameter<std::vector<double>>("apdNonlParms"))),
90 
91  m_APDResponse(!m_apdSeparateDigi
92  ? nullptr
93  : std::make_unique<EBHitResponse_Ph2>(
94  m_ParameterMap.get(), &m_EBShape, true, m_apdParameters.get(), &m_APDShape)),
95 
96  m_EBResponse(std::make_unique<EBHitResponse_Ph2>(m_ParameterMap.get(),
97  &m_EBShape,
98  false, // barrel
99  m_apdParameters.get(),
100  &m_APDShape)),
101 
102  m_PreMix1(params.getParameter<bool>("EcalPreMixStage1")),
103  m_PreMix2(params.getParameter<bool>("EcalPreMixStage2")),
104  m_HitsEBToken(iC.consumes<std::vector<PCaloHit>>(edm::InputTag(m_hitsProducerTag, "EcalHitsEB"))),
105 
106  m_APDDigitizer(nullptr),
107  m_BarrelDigitizer(nullptr),
108  m_ElectronicsSim(nullptr),
109  m_Coder(nullptr),
110  m_APDElectronicsSim(nullptr),
111  m_APDCoder(nullptr),
112  m_Geometry(nullptr),
113  m_EBCorrNoise({{nullptr, nullptr}})
114 
115 {
116  iC.consumes<std::vector<PCaloHit>>(edm::InputTag(m_hitsProducerTag, "EcalHitsEB"));
117  pedestalToken_ = iC.esConsumes();
118  laserToken_ = iC.esConsumes<EcalLaserDbService, EcalLaserDbRecord>();
119  agcToken_ = iC.esConsumes<EcalADCToGeVConstant, EcalADCToGeVConstantRcd>();
120  icalToken_ = iC.esConsumes<EcalIntercalibConstants, EcalIntercalibConstantsRcd>();
121  geom_token_ = iC.esConsumes<CaloGeometry, CaloGeometryRecord>();
122 
123  const std::vector<double> ebCorMatG10Ph2 = params.getParameter<std::vector<double>>("EBCorrNoiseMatrixG10Ph2");
124  const std::vector<double> ebCorMatG01Ph2 = params.getParameter<std::vector<double>>("EBCorrNoiseMatrixG01Ph2");
125 
126  const bool applyConstantTerm = params.getParameter<bool>("applyConstantTerm");
127  const double rmsConstantTerm = params.getParameter<double>("ConstantTerm");
128 
129  const bool addNoise = params.getParameter<bool>("doENoise");
130  const bool cosmicsPhase = params.getParameter<bool>("cosmicsPhase");
131  const double cosmicsShift = params.getParameter<double>("cosmicsShift");
132 
133  // further phase for cosmics studies
134  if (cosmicsPhase) {
135  m_EBResponse->setPhaseShift(1. + cosmicsShift);
136  }
137 
138  EcalCorrMatrix_Ph2 ebMatrix[2];
139  const double errorCorrelation = 1.e-7;
140  assert(ebCorMatG10Ph2.size() == m_readoutFrameSize);
141  assert(ebCorMatG01Ph2.size() == m_readoutFrameSize);
142 
143  assert(errorCorrelation > std::abs(ebCorMatG10Ph2[0] - 1.0));
144  assert(errorCorrelation > std::abs(ebCorMatG01Ph2[0] - 1.0));
145 
146  for (unsigned int row(0); row != m_readoutFrameSize; ++row) {
147  assert(0 == row || 1. >= ebCorMatG10Ph2[row]);
148  assert(0 == row || 1. >= ebCorMatG01Ph2[row]);
149 
150  for (unsigned int column(0); column <= row; ++column) {
151  const unsigned int index(row - column);
152  ebMatrix[0](row, column) = ebCorMatG10Ph2[index];
153  ebMatrix[1](row, column) = ebCorMatG01Ph2[index];
154  }
155  }
156  m_EBCorrNoise[0] = std::make_unique<CorrelatedNoisifier<EcalCorrMatrix_Ph2>>(ebMatrix[0]);
157  m_EBCorrNoise[1] = std::make_unique<CorrelatedNoisifier<EcalCorrMatrix_Ph2>>(ebMatrix[1]);
158  m_Coder = std::make_unique<EcalLiteDTUCoder>(addNoise, m_PreMix1, m_EBCorrNoise[0].get(), m_EBCorrNoise[1].get());
159  m_ElectronicsSim =
160  std::make_unique<EcalElectronicsSim_Ph2>(m_ParameterMap.get(), m_Coder.get(), applyConstantTerm, rmsConstantTerm);
161 
162  if (m_apdSeparateDigi) {
163  m_APDCoder = std::make_unique<EcalLiteDTUCoder>(false, m_PreMix1, m_EBCorrNoise[0].get(), m_EBCorrNoise[1].get());
164 
165  m_APDElectronicsSim = std::make_unique<EcalElectronicsSim_Ph2>(
166  m_ParameterMap.get(), m_APDCoder.get(), applyConstantTerm, rmsConstantTerm);
167 
168  m_APDDigitizer = std::make_unique<EBDigitizer_Ph2>(m_APDResponse.get(), m_APDElectronicsSim.get(), false);
169  }
170 
171  m_BarrelDigitizer = std::make_unique<EBDigitizer_Ph2>(m_EBResponse.get(), m_ElectronicsSim.get(), addNoise);
172 }
173 
175 
178  randomEngine_ = &rng->getEngine(event.streamID());
179 
182 
183  m_BarrelDigitizer->initializeHits();
184  if (m_apdSeparateDigi) {
185  m_APDDigitizer->initializeHits();
186  }
187 }
188 
189 void EcalDigiProducer_Ph2::accumulateCaloHits(HitsHandle const& ebHandle, int bunchCrossing) {
190  if (ebHandle.isValid()) {
191  m_BarrelDigitizer->add(*ebHandle.product(), bunchCrossing, randomEngine_);
192 
193  if (m_apdSeparateDigi) {
194  m_APDDigitizer->add(*ebHandle.product(), bunchCrossing, randomEngine_);
195  }
196  }
197 }
198 
200  // Step A: Get Inputs
201 
204  const edm::Handle<std::vector<PCaloHit>>& ebHandle = e.getHandle(m_HitsEBToken);
205 
206  accumulateCaloHits(ebHandle, 0);
207 }
208 
211  edm::StreamID const& streamID) {
212  // Step A: Get Inputs
214 
215  edm::InputTag ebTag(m_hitsProducerTag, "EcalHitsEB");
216  e.getByLabel(ebTag, ebHandle);
217 
218  accumulateCaloHits(ebHandle, e.bunchCrossing());
219 }
220 
222  // Step B: Create empty output
223  std::unique_ptr<EBDigiCollectionPh2> apdResult(nullptr);
224  std::unique_ptr<EBDigiCollectionPh2> barrelResult = std::make_unique<EBDigiCollectionPh2>();
225  if (m_apdSeparateDigi) {
226  apdResult = std::make_unique<EBDigiCollectionPh2>();
227  }
228  // run the algorithm
229 
230  m_BarrelDigitizer->run(*barrelResult, randomEngine_);
231  cacheEBDigis(&*barrelResult);
232 
233  edm::LogInfo("DigiInfo") << "EB Digis: " << barrelResult->size();
234 
235  if (m_apdSeparateDigi) {
236  m_APDDigitizer->run(*apdResult, randomEngine_);
237  edm::LogInfo("DigiInfo") << "APD Digis: " << apdResult->size();
238  }
239 
240  // Step D: Put outputs into event
241 
242  event.put(std::move(barrelResult), m_EBdigiCollection);
243 
244  randomEngine_ = nullptr; // to prevent access outside event
245 }
246 
249  if (!rng.isAvailable()) {
250  throw cms::Exception("Configuration") << "RandomNumberGenerator service is not available.\n"
251  "You must add the service in the configuration file\n"
252  "or remove the module that requires it.";
253  }
254  CLHEP::HepRandomEngine* engine = &rng->getEngine(lumi.index());
255 
256  if (nullptr != m_APDResponse)
257  m_APDResponse->initialize(engine);
258  m_EBResponse->initialize(engine);
259 }
260 
262  // Pedestals from event setup
263  auto pedestals = &eventSetup.getData(pedestalToken_);
264 
265  m_Coder->setPedestals(pedestals);
266  if (nullptr != m_APDCoder)
267  m_APDCoder->setPedestals(pedestals);
268 
269  // Ecal Intercalibration Constants
270  auto ical = &eventSetup.getData(icalToken_);
271 
272  m_Coder->setIntercalibConstants(ical);
273  if (nullptr != m_APDCoder)
274  m_APDCoder->setIntercalibConstants(ical);
275 
276  m_EBResponse->setIntercal(ical);
277  if (nullptr != m_APDResponse)
278  m_APDResponse->setIntercal(ical);
279 
280  // Ecal LaserCorrection Constants
281  auto laser = &eventSetup.getData(laserToken_);
282 
283  const edm::TimeValue_t eventTimeValue = event.time().value();
284 
285  m_EBResponse->setEventTime(eventTimeValue);
286  m_EBResponse->setLaserConstants(laser, m_useLCcorrection);
287 
288  // ADC -> GeV Scale
289  auto agc = &eventSetup.getData(agcToken_);
290 
291  m_Coder->setGainRatios(ecalPh2::gains[0] / ecalPh2::gains[1]);
292  if (nullptr != m_APDCoder)
293  m_APDCoder->setGainRatios(ecalPh2::gains[0] / ecalPh2::gains[1]);
294 
295  const double EBscale((agc->getEBValue()) * ecalPh2::gains[1] * (ecalPh2::MAXADC)*m_EBs25notCont);
296 
297  LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEBValue() << "\n"
298  << " notCont = " << m_EBs25notCont << "\n"
299  << " saturation for EB = " << EBscale << ", " << m_EBs25notCont;
300 
301  m_Coder->setFullScaleEnergy(EBscale);
302  if (nullptr != m_APDCoder)
303  m_APDCoder->setFullScaleEnergy(EBscale);
304 }
305 
307  // TODO find a way to avoid doing this every event
308  edm::ESHandle<CaloGeometry> hGeometry = eventSetup.getHandle(geom_token_);
309  const CaloGeometry* pGeometry = &*hGeometry;
310 
311  if (pGeometry != m_Geometry) {
312  m_Geometry = pGeometry;
313  updateGeometry();
314  }
315 }
316 
318  if (nullptr != m_APDResponse)
321 }
322 
324  m_BarrelDigitizer->setNoiseSignalGenerator(noiseGenerator);
325 }
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_
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)
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
static constexpr const float * gains
Definition: EcalConstants.h:24
virtual void cacheEBDigis(const EBDigiCollectionPh2 *ebDigiPtr) const
const CaloGeometry * m_Geometry
unsigned long long TimeValue_t
Definition: Timestamp.h:28
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 setEventSetup(const edm::EventSetup &evtSetup)
void setEBNoiseSignalGenerator(EcalBaseSignalGenerator *noiseGenerator)
bool isAvailable() const
Definition: Service.h:40
#define get
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:29
Definition: event.py:1
#define LogDebug(id)