CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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,
47  : EcalDigiProducer_Ph2(params, iC) {
49  producesCollector.produces<EBDigiCollectionPh2>(m_apdDigiTag);
50 
52 }
53 
54 // version for Pre-Mixing, for use outside of MixingModule
57  m_APDShape(iC),
58  m_EBShape(iC),
59 
60  m_EBdigiCollection(params.getParameter<std::string>("EBdigiCollectionPh2")),
61 
62  m_hitsProducerTag(params.getParameter<std::string>("hitsProducer")),
63  m_useLCcorrection(params.getUntrackedParameter<bool>("UseLCcorrection")),
64  m_apdSeparateDigi(params.getParameter<bool>("apdSeparateDigi")),
65 
66  m_EBs25notCont(params.getParameter<double>("EBs25notContainment")),
67 
68  m_readoutFrameSize(ecalPh2::sampleSize),
69 
70  m_ParameterMap(std::make_unique<EcalSimParameterMap>(params.getParameter<double>("simHitToPhotoelectronsBarrel"),
71  0, // endcap parameters not needed
72  params.getParameter<double>("photoelectronsToAnalogBarrel"),
73  0,
74  params.getParameter<double>("samplingFactor"),
75  params.getParameter<double>("timePhase"),
76  m_readoutFrameSize,
77  params.getParameter<int>("binOfMaximum"),
78  params.getParameter<bool>("doPhotostatistics"),
79  params.getParameter<bool>("syncPhase"))),
80 
81  m_apdDigiTag(params.getParameter<std::string>("apdDigiTag")),
82  m_apdParameters(std::make_unique<APDSimParameters>(params.getParameter<bool>("apdAddToBarrel"),
83  m_apdSeparateDigi,
84  params.getParameter<double>("apdSimToPELow"),
85  params.getParameter<double>("apdSimToPEHigh"),
86  params.getParameter<double>("apdTimeOffset"),
87  params.getParameter<double>("apdTimeOffWidth"),
88  params.getParameter<bool>("apdDoPEStats"),
89  m_apdDigiTag,
90  params.getParameter<std::vector<double>>("apdNonlParms"))),
91 
92  m_APDResponse(!m_apdSeparateDigi
93  ? nullptr
94  : std::make_unique<EBHitResponse_Ph2>(
95  m_ParameterMap.get(), &m_EBShape, true, m_apdParameters.get(), &m_APDShape)),
96 
97  m_EBResponse(std::make_unique<EBHitResponse_Ph2>(m_ParameterMap.get(),
98  &m_EBShape,
99  false, // barrel
100  m_apdParameters.get(),
101  &m_APDShape)),
102 
103  m_PreMix1(params.getParameter<bool>("EcalPreMixStage1")),
104  m_PreMix2(params.getParameter<bool>("EcalPreMixStage2")),
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();
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 
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());
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 
180  checkGeometry(eventSetup);
181  checkCalibrations(event, eventSetup);
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
202 
203  m_EBShape.setEventSetup(eventSetup);
204  m_APDShape.setEventSetup(eventSetup);
205  edm::InputTag ebTag(m_hitsProducerTag, "EcalHitsEB");
206  e.getByLabel(ebTag, ebHandle);
207 
208  accumulateCaloHits(ebHandle, 0);
209 }
210 
212  edm::EventSetup const& eventSetup,
213  edm::StreamID const& streamID) {
214  // Step A: Get Inputs
216 
217  edm::InputTag ebTag(m_hitsProducerTag, "EcalHitsEB");
218  e.getByLabel(ebTag, ebHandle);
219 
220  accumulateCaloHits(ebHandle, e.bunchCrossing());
221 }
222 
224  // Step B: Create empty output
225  std::unique_ptr<EBDigiCollectionPh2> apdResult(nullptr);
226  std::unique_ptr<EBDigiCollectionPh2> barrelResult = std::make_unique<EBDigiCollectionPh2>();
227  if (m_apdSeparateDigi) {
228  apdResult = std::make_unique<EBDigiCollectionPh2>();
229  }
230  // run the algorithm
231 
232  m_BarrelDigitizer->run(*barrelResult, randomEngine_);
233  cacheEBDigis(&*barrelResult);
234 
235  edm::LogInfo("DigiInfo") << "EB Digis: " << barrelResult->size();
236 
237  if (m_apdSeparateDigi) {
238  m_APDDigitizer->run(*apdResult, randomEngine_);
239  edm::LogInfo("DigiInfo") << "APD Digis: " << apdResult->size();
240  }
241 
242  // Step D: Put outputs into event
243 
244  event.put(std::move(barrelResult), m_EBdigiCollection);
245 
246  randomEngine_ = nullptr; // to prevent access outside event
247 }
248 
251  if (!rng.isAvailable()) {
252  throw cms::Exception("Configuration") << "RandomNumberGenerator service is not available.\n"
253  "You must add the service in the configuration file\n"
254  "or remove the module that requires it.";
255  }
256  CLHEP::HepRandomEngine* engine = &rng->getEngine(lumi.index());
257 
258  if (nullptr != m_APDResponse)
259  m_APDResponse->initialize(engine);
260  m_EBResponse->initialize(engine);
261 }
262 
264  // Pedestals from event setup
265  auto pedestals = &eventSetup.getData(pedestalToken_);
266 
267  m_Coder->setPedestals(pedestals);
268  if (nullptr != m_APDCoder)
269  m_APDCoder->setPedestals(pedestals);
270 
271  // Ecal Intercalibration Constants
272  auto ical = &eventSetup.getData(icalToken_);
273 
274  m_Coder->setIntercalibConstants(ical);
275  if (nullptr != m_APDCoder)
276  m_APDCoder->setIntercalibConstants(ical);
277 
278  m_EBResponse->setIntercal(ical);
279  if (nullptr != m_APDResponse)
280  m_APDResponse->setIntercal(ical);
281 
282  // Ecal LaserCorrection Constants
283  auto laser = &eventSetup.getData(laserToken_);
284 
285  const edm::TimeValue_t eventTimeValue = event.time().value();
286 
287  m_EBResponse->setEventTime(eventTimeValue);
288  m_EBResponse->setLaserConstants(laser, m_useLCcorrection);
289 
290  // ADC -> GeV Scale
291  auto agc = &eventSetup.getData(agcToken_);
292 
293  m_Coder->setGainRatios(ecalPh2::gains[0] / ecalPh2::gains[1]);
294  if (nullptr != m_APDCoder)
295  m_APDCoder->setGainRatios(ecalPh2::gains[0] / ecalPh2::gains[1]);
296 
297  const double EBscale((agc->getEBValue()) * ecalPh2::gains[1] * (ecalPh2::MAXADC)*m_EBs25notCont);
298 
299  LogDebug("EcalDigi") << " GeV/ADC = " << agc->getEBValue() << "\n"
300  << " notCont = " << m_EBs25notCont << "\n"
301  << " saturation for EB = " << EBscale << ", " << m_EBs25notCont;
302 
303  m_Coder->setFullScaleEnergy(EBscale);
304  if (nullptr != m_APDCoder)
305  m_APDCoder->setFullScaleEnergy(EBscale);
306 }
307 
309  // TODO find a way to avoid doing this every event
310  edm::ESHandle<CaloGeometry> hGeometry = eventSetup.getHandle(geom_token_);
311  const CaloGeometry* pGeometry = &*hGeometry;
312 
313  if (pGeometry != m_Geometry) {
314  m_Geometry = pGeometry;
315  updateGeometry();
316  }
317 }
318 
320  if (nullptr != m_APDResponse)
323 }
324 
326  m_BarrelDigitizer->setNoiseSignalGenerator(noiseGenerator);
327 }
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
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_
const bool applyConstantTerm
LuminosityBlockIndex index() const
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
const std::string m_apdDigiTag
edm::ESGetToken< EcalLaserDbService, EcalLaserDbRecord > laserToken_
std::unique_ptr< EBDigitizer_Ph2 > m_APDDigitizer
const double errorCorrelation
EcalCorrMatrix_Ph2 ebMatrix[2]
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
static constexpr float gains[NGAINS]
Definition: EcalConstants.h:9
void checkCalibrations(const edm::Event &event, const edm::EventSetup &eventSetup)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
virtual void cacheEBDigis(const EBDigiCollectionPh2 *ebDigiPtr) const
const std::string m_hitsProducerTag
const bool cosmicsPhase
const double rmsConstantTerm
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geom_token_
def move
Definition: eostools.py:511
const std::string m_EBdigiCollection
bool isAvailable() const
Definition: Service.h:40
m_EBCorrNoise[0]
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
bool isValid() const
Definition: HandleBase.h:70
list lumi
Definition: dqmdumpme.py:53
const CaloGeometry * m_Geometry
unsigned long long TimeValue_t
Definition: Timestamp.h:28
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
void checkGeometry(const edm::EventSetup &eventSetup)
const double cosmicsShift
Log< level::Info, false > LogInfo
edm::ESGetToken< EcalIntercalibConstants, EcalIntercalibConstantsRcd > icalToken_
void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) override
T const * product() const
Definition: Handle.h:70
const std::vector< double > ebCorMatG01Ph2
edm::ESGetToken< EcalLiteDTUPedestalsMap, EcalLiteDTUPedestalsRcd > pedestalToken_
EcalIntercalibConstantMap EcalIntercalibConstants
EcalDigiProducer_Ph2(const edm::ParameterSet &params, edm::ProducesCollector producesCollector, edm::ConsumesCollector &iC)
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
StreamID streamID() const
Definition: Event.h:98
void setEventSetup(const edm::EventSetup &evtSetup)
const bool addNoise
const std::vector< double > ebCorMatG10Ph2
void setEBNoiseSignalGenerator(EcalBaseSignalGenerator *noiseGenerator)
#define get
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
void accumulateCaloHits(HitsHandle const &ebHandle, int bunchCrossing)
std::unique_ptr< EBDigitizer_Ph2 > m_BarrelDigitizer
math::ErrorD< ecalPh2::sampleSize >::type EcalCorrMatrix_Ph2
static constexpr unsigned int MAXADC
Definition: EcalConstants.h:14
#define LogDebug(id)