File indexing completed on 2024-04-06 12:30:33
0001
0002
0003
0004
0005
0006
0007 #include <functional>
0008 #include <iostream>
0009 #include <map>
0010 #include <memory>
0011
0012 #include "DataFormats/Common/interface/Handle.h"
0013 #include "FWCore/Framework/interface/ConsumesCollector.h"
0014 #include "FWCore/Framework/interface/ModuleContextSentry.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/ServiceRegistry/interface/InternalContext.h"
0017 #include "FWCore/ServiceRegistry/interface/ModuleCallingContext.h"
0018 #include "FWCore/ServiceRegistry/interface/ParentContext.h"
0019
0020
0021 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0022 #include "DataMixingModule.h"
0023 #include "SimDataFormats/CrossingFrame/interface/CrossingFramePlaybackInfoNew.h"
0024 #include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"
0025
0026 using namespace std;
0027
0028 namespace edm {
0029
0030
0031 DataMixingModule::DataMixingModule(const edm::ParameterSet &ps, MixingCache::Config const *globalConf)
0032 : BMixingModule(ps, globalConf),
0033 EBPileInputTag_(ps.getParameter<edm::InputTag>("EBPileInputTag")),
0034 EEPileInputTag_(ps.getParameter<edm::InputTag>("EEPileInputTag")),
0035 ESPileInputTag_(ps.getParameter<edm::InputTag>("ESPileInputTag")),
0036 HBHEPileInputTag_(ps.getParameter<edm::InputTag>("HBHEPileInputTag")),
0037 HOPileInputTag_(ps.getParameter<edm::InputTag>("HOPileInputTag")),
0038 HFPileInputTag_(ps.getParameter<edm::InputTag>("HFPileInputTag")),
0039 ZDCPileInputTag_(ps.getParameter<edm::InputTag>("ZDCPileInputTag")),
0040 QIE10PileInputTag_(ps.getParameter<edm::InputTag>("QIE10PileInputTag")),
0041 QIE11PileInputTag_(ps.getParameter<edm::InputTag>("QIE11PileInputTag")),
0042 tokDB_(esConsumes<HcalDbService, HcalDbRecord>()),
0043 label_(ps.getParameter<std::string>("Label")) {
0044
0045 tok_hbhe_ = consumes<HBHEDigitizerTraits::DigiCollection>(HBHEPileInputTag_);
0046 tok_ho_ = consumes<HODigitizerTraits::DigiCollection>(HOPileInputTag_);
0047 tok_hf_ = consumes<HFDigitizerTraits::DigiCollection>(HFPileInputTag_);
0048 tok_zdc_ = consumes<ZDCDigitizerTraits::DigiCollection>(ZDCPileInputTag_);
0049 tok_qie10_ = consumes<HcalQIE10DigitizerTraits::DigiCollection>(QIE10PileInputTag_);
0050 tok_qie11_ = consumes<HcalQIE11DigitizerTraits::DigiCollection>(QIE11PileInputTag_);
0051
0052
0053 this->getSubdetectorNames();
0054
0055
0056
0057
0058
0059
0060
0061
0062 MergeTrackerDigis_ = (ps.getParameter<std::string>("TrackerMergeType")) == "Digis";
0063 MergeEMDigis_ = (ps.getParameter<std::string>("EcalMergeType")) == "Digis";
0064 MergeHcalDigis_ = (ps.getParameter<std::string>("HcalMergeType")) == "Digis";
0065 if (MergeHcalDigis_)
0066 MergeHcalDigisProd_ = (ps.getParameter<std::string>("HcalDigiMerge") == "FullProd");
0067
0068
0069
0070 if (MergeEMDigis_) {
0071
0072
0073 EBDigiCollectionDM_ = ps.getParameter<std::string>("EBDigiCollectionDM");
0074 EEDigiCollectionDM_ = ps.getParameter<std::string>("EEDigiCollectionDM");
0075 ESDigiCollectionDM_ = ps.getParameter<std::string>("ESDigiCollectionDM");
0076
0077
0078
0079 produces<EBDigiCollection>(EBDigiCollectionDM_);
0080 produces<EEDigiCollection>(EEDigiCollectionDM_);
0081 produces<ESDigiCollection>(ESDigiCollectionDM_);
0082
0083 EMDigiWorker_ = new DataMixingEMDigiWorker(ps, consumesCollector());
0084 } else {
0085 EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
0086 EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
0087 ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
0088
0089
0090
0091 produces<EBRecHitCollection>(EBRecHitCollectionDM_);
0092 produces<EERecHitCollection>(EERecHitCollectionDM_);
0093 produces<ESRecHitCollection>(ESRecHitCollectionDM_);
0094
0095 EMWorker_ = new DataMixingEMWorker(ps, consumesCollector());
0096 }
0097
0098
0099 if (MergeHcalDigis_) {
0100 HBHEDigiCollectionDM_ = ps.getParameter<std::string>("HBHEDigiCollectionDM");
0101 HODigiCollectionDM_ = ps.getParameter<std::string>("HODigiCollectionDM");
0102 HFDigiCollectionDM_ = ps.getParameter<std::string>("HFDigiCollectionDM");
0103 ZDCDigiCollectionDM_ = ps.getParameter<std::string>("ZDCDigiCollectionDM");
0104 QIE10DigiCollectionDM_ = ps.getParameter<std::string>("QIE10DigiCollectionDM");
0105 QIE11DigiCollectionDM_ = ps.getParameter<std::string>("QIE11DigiCollectionDM");
0106
0107 produces<HBHEDigiCollection>();
0108 produces<HODigiCollection>();
0109 produces<HFDigiCollection>();
0110 produces<ZDCDigiCollection>();
0111
0112 produces<QIE10DigiCollection>("HFQIE10DigiCollection");
0113 produces<QIE11DigiCollection>("HBHEQIE11DigiCollection");
0114
0115 if (ps.getParameter<bool>("debugCaloSamples")) {
0116 produces<CaloSamplesCollection>("HcalSamples");
0117 }
0118 if (ps.getParameter<bool>("injectTestHits")) {
0119 produces<edm::PCaloHitContainer>("HcalHits");
0120 }
0121
0122 if (MergeHcalDigisProd_)
0123 HcalDigiWorkerProd_ = new DataMixingHcalDigiWorkerProd(ps, consumesCollector(), tokDB_);
0124 else
0125 HcalDigiWorker_ = new DataMixingHcalDigiWorker(ps, consumesCollector());
0126
0127 } else {
0128 HBHERecHitCollectionDM_ = ps.getParameter<std::string>("HBHERecHitCollectionDM");
0129 HORecHitCollectionDM_ = ps.getParameter<std::string>("HORecHitCollectionDM");
0130 HFRecHitCollectionDM_ = ps.getParameter<std::string>("HFRecHitCollectionDM");
0131 ZDCRecHitCollectionDM_ = ps.getParameter<std::string>("ZDCRecHitCollectionDM");
0132
0133 produces<HBHERecHitCollection>(HBHERecHitCollectionDM_);
0134 produces<HORecHitCollection>(HORecHitCollectionDM_);
0135 produces<HFRecHitCollection>(HFRecHitCollectionDM_);
0136 produces<ZDCRecHitCollection>(ZDCRecHitCollectionDM_);
0137
0138 HcalWorker_ = new DataMixingHcalWorker(ps, consumesCollector());
0139 }
0140
0141
0142
0143 DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
0144 RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
0145 CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
0146 CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
0147 CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
0148
0149 produces<DTDigiCollection>();
0150 produces<RPCDigiCollection>();
0151 produces<CSCStripDigiCollection>(CSCStripDigiCollectionDM_);
0152 produces<CSCWireDigiCollection>(CSCWireDigiCollectionDM_);
0153 produces<CSCComparatorDigiCollection>(CSCComparatorDigiCollectionDM_);
0154
0155 MuonWorker_ = new DataMixingMuonWorker(ps, consumesCollector());
0156
0157
0158
0159 useSiStripRawDigi_ = ps.exists("SiStripRawDigiSource")
0160 ? ps.getParameter<std::string>("SiStripRawDigiSource") == "PILEUP" ||
0161 ps.getParameter<std::string>("SiStripRawDigiSource") == "SIGNAL"
0162 : false;
0163
0164 SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
0165
0166 if (useSiStripRawDigi_) {
0167 produces<edm::DetSetVector<SiStripRawDigi>>(SiStripDigiCollectionDM_);
0168 SiStripRawWorker_ = new DataMixingSiStripRawWorker(ps, consumesCollector());
0169
0170 } else {
0171 produces<edm::DetSetVector<SiStripDigi>>(SiStripDigiCollectionDM_);
0172
0173 SiStripWorker_ = new DataMixingSiStripWorker(ps, consumesCollector());
0174 }
0175
0176
0177
0178 PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
0179
0180 produces<edm::DetSetVector<PixelDigi>>(PixelDigiCollectionDM_);
0181
0182 SiPixelWorker_ = new DataMixingSiPixelWorker(ps, consumesCollector());
0183
0184
0185
0186
0187 MergePileup_ = ps.getParameter<bool>("MergePileupInfo");
0188
0189 if (MergePileup_) {
0190 produces<std::vector<PileupSummaryInfo>>();
0191 produces<int>("bunchSpacing");
0192 produces<CrossingFramePlaybackInfoNew>();
0193
0194 std::vector<edm::InputTag> GenPUProtonsInputTags;
0195 GenPUProtonsInputTags = ps.getParameter<std::vector<edm::InputTag>>("GenPUProtonsInputTags");
0196 for (std::vector<edm::InputTag>::const_iterator it_InputTag = GenPUProtonsInputTags.begin();
0197 it_InputTag != GenPUProtonsInputTags.end();
0198 ++it_InputTag)
0199 produces<std::vector<reco::GenParticle>>(it_InputTag->label());
0200
0201 PUWorker_ = new DataMixingPileupCopy(ps, consumesCollector());
0202 }
0203 }
0204
0205 void DataMixingModule::getSubdetectorNames() {
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245 }
0246
0247 void DataMixingModule::initializeEvent(const edm::Event &e, const edm::EventSetup &ES) {}
0248
0249 void DataMixingModule::beginRun(edm::Run const &run, const edm::EventSetup &ES) { BMixingModule::beginRun(run, ES); }
0250
0251 void DataMixingModule::endRun(edm::Run const &run, const edm::EventSetup &ES) { BMixingModule::endRun(run, ES); }
0252
0253
0254 DataMixingModule::~DataMixingModule() {
0255 if (MergeEMDigis_) {
0256 delete EMDigiWorker_;
0257 } else {
0258 delete EMWorker_;
0259 }
0260 if (MergeHcalDigis_) {
0261 if (MergeHcalDigisProd_) {
0262 delete HcalDigiWorkerProd_;
0263 } else {
0264 delete HcalDigiWorker_;
0265 }
0266 } else {
0267 delete HcalWorker_;
0268 }
0269 if (MuonWorker_)
0270 delete MuonWorker_;
0271 if (useSiStripRawDigi_)
0272 delete SiStripRawWorker_;
0273 else
0274 delete SiStripWorker_;
0275 delete SiPixelWorker_;
0276 if (MergePileup_) {
0277 delete PUWorker_;
0278 }
0279 }
0280
0281 void DataMixingModule::addSignals(const edm::Event &e, const edm::EventSetup &ES) {
0282
0283
0284 LogDebug("DataMixingModule") << "===============> adding MC signals for " << e.id();
0285
0286
0287 if (MergeEMDigis_) {
0288 EMDigiWorker_->addEMSignals(e, ES);
0289 } else {
0290 EMWorker_->addEMSignals(e);
0291 }
0292
0293
0294 if (MergeHcalDigis_) {
0295 if (MergeHcalDigisProd_) {
0296 HcalDigiWorkerProd_->addHcalSignals(e, ES);
0297 } else {
0298 HcalDigiWorker_->addHcalSignals(e, ES);
0299 }
0300 } else {
0301 HcalWorker_->addHcalSignals(e);
0302 }
0303
0304
0305 MuonWorker_->addMuonSignals(e);
0306
0307
0308 if (useSiStripRawDigi_)
0309 SiStripRawWorker_->addSiStripSignals(e);
0310 else
0311 SiStripWorker_->addSiStripSignals(e);
0312
0313
0314 SiPixelWorker_->addSiPixelSignals(e);
0315 AddedPileup_ = false;
0316 }
0317
0318 bool DataMixingModule::pileWorker(
0319 const EventPrincipal &ep, int bcr, int eventNr, const edm::EventSetup &ES, edm::ModuleCallingContext const *mcc) {
0320 InternalContext internalContext(ep.id(), mcc);
0321 ParentContext parentContext(&internalContext);
0322 ModuleCallingContext moduleCallingContext(&moduleDescription());
0323 ModuleContextSentry moduleContextSentry(&moduleCallingContext, parentContext);
0324
0325 LogDebug("DataMixingModule") << "\n===============> adding pileups from event " << ep.id() << " for bunchcrossing "
0326 << bcr;
0327
0328
0329
0330 setupPileUpEvent(ES);
0331
0332
0333
0334
0335
0336
0337 if (MergePileup_ && !AddedPileup_) {
0338 PUWorker_->addPileupInfo(&ep, eventNr, &moduleCallingContext);
0339
0340 AddedPileup_ = true;
0341 }
0342
0343
0344
0345
0346
0347 if (MergeEMDigis_) {
0348 EMDigiWorker_->addEMPileups(bcr, &ep, eventNr, ES, &moduleCallingContext);
0349 } else {
0350 EMWorker_->addEMPileups(bcr, &ep, eventNr, &moduleCallingContext);
0351 }
0352
0353
0354 if (MergeHcalDigis_) {
0355 if (MergeHcalDigisProd_) {
0356 HcalDigiWorkerProd_->addHcalPileups(bcr, &ep, eventNr, ES, &moduleCallingContext);
0357 } else {
0358 HcalDigiWorker_->addHcalPileups(bcr, &ep, eventNr, ES, &moduleCallingContext);
0359 }
0360 } else {
0361 HcalWorker_->addHcalPileups(bcr, &ep, eventNr, &moduleCallingContext);
0362 }
0363
0364
0365 MuonWorker_->addMuonPileups(bcr, &ep, eventNr, &moduleCallingContext);
0366
0367
0368 if (useSiStripRawDigi_)
0369 SiStripRawWorker_->addSiStripPileups(bcr, &ep, eventNr, &moduleCallingContext);
0370 else
0371 SiStripWorker_->addSiStripPileups(bcr, &ep, eventNr, &moduleCallingContext);
0372
0373
0374
0375
0376 SiPixelWorker_->addSiPixelPileups(bcr, &ep, eventNr, &moduleCallingContext);
0377
0378 return true;
0379 }
0380
0381 void DataMixingModule::doPileUp(edm::Event &e, const edm::EventSetup &ES) {
0382 using namespace std::placeholders;
0383
0384 std::vector<edm::SecondaryEventIDAndFileInfo> recordEventID;
0385 std::vector<int> PileupList;
0386 PileupList.clear();
0387 TrueNumInteractions_.clear();
0388
0389 ModuleCallingContext const *mcc = e.moduleCallingContext();
0390
0391 for (int bunchCrossing = minBunch_; bunchCrossing <= maxBunch_; ++bunchCrossing) {
0392 for (unsigned int isource = 0; isource < maxNbSources_; ++isource) {
0393 std::shared_ptr<PileUp> source = inputSources_[isource];
0394 if (!source || !(source->doPileUp(bunchCrossing)))
0395 continue;
0396
0397 if (isource == 0)
0398 source->CalculatePileup(minBunch_, maxBunch_, PileupList, TrueNumInteractions_, e.streamID());
0399
0400 int NumPU_Events = 0;
0401 if (isource == 0) {
0402 NumPU_Events = PileupList[bunchCrossing - minBunch_];
0403 } else {
0404
0405 NumPU_Events = 1;
0406 }
0407
0408 source->readPileUp(
0409 e.id(),
0410 recordEventID,
0411 std::bind(&DataMixingModule::pileWorker, std::ref(*this), _1, bunchCrossing, _2, std::cref(ES), mcc),
0412 NumPU_Events,
0413 e.streamID());
0414 }
0415 }
0416 }
0417
0418 void DataMixingModule::put(edm::Event &e, const edm::EventSetup &ES) {
0419
0420
0421
0422
0423 std::vector<PileupSummaryInfo> ps;
0424 int bunchSpacing = 10000;
0425
0426 if (MergePileup_) {
0427 PUWorker_->getPileupInfo(ps, bunchSpacing);
0428 PUWorker_->putPileupInfo(e);
0429 }
0430
0431
0432 if (MergeEMDigis_) {
0433 EMDigiWorker_->putEM(e, ES);
0434 } else {
0435 EMWorker_->putEM(e);
0436 }
0437
0438
0439 if (MergeHcalDigis_) {
0440 if (MergeHcalDigisProd_) {
0441 HcalDigiWorkerProd_->putHcal(e, ES);
0442 } else {
0443 HcalDigiWorker_->putHcal(e, ES);
0444 }
0445 } else {
0446 HcalWorker_->putHcal(e);
0447 }
0448
0449
0450 MuonWorker_->putMuon(e);
0451
0452
0453 if (useSiStripRawDigi_)
0454 SiStripRawWorker_->putSiStrip(e);
0455 else
0456 SiStripWorker_->putSiStrip(e);
0457
0458
0459 SiPixelWorker_->putSiPixel(e);
0460 }
0461
0462 void DataMixingModule::beginLuminosityBlock(LuminosityBlock const &l1, EventSetup const &c) {
0463 BMixingModule::beginLuminosityBlock(l1, c);
0464 }
0465
0466 void DataMixingModule::endLuminosityBlock(LuminosityBlock const &l1, EventSetup const &c) {
0467 BMixingModule::endLuminosityBlock(l1, c);
0468 }
0469
0470 }