00001
00002
00003
00004
00005
00006
00007 #include <map>
00008 #include <iostream>
00009 #include <boost/bind.hpp>
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/Utilities/interface/EDMException.h"
00012 #include "FWCore/Framework/interface/ConstProductRegistry.h"
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "DataFormats/Common/interface/Handle.h"
00015 #include "DataFormats/Provenance/interface/Provenance.h"
00016 #include "DataFormats/Provenance/interface/BranchDescription.h"
00017
00018
00019 #include "DataMixingModule.h"
00020
00021
00022 using namespace std;
00023
00024 namespace edm
00025 {
00026
00027
00028 DataMixingModule::DataMixingModule(const edm::ParameterSet& ps) : BMixingModule(ps),
00029 label_(ps.getParameter<std::string>("Label"))
00030
00031 {
00032
00033
00034 this->getSubdetectorNames();
00035
00036
00037
00038
00039
00040
00041 DoFastSim_ = (ps.getParameter<std::string>("IsThisFastSim")).compare("YES") == 0;
00042 MergeEMDigis_ = (ps.getParameter<std::string>("EcalMergeType")).compare("Digis") == 0;
00043 MergeHcalDigis_ = (ps.getParameter<std::string>("HcalMergeType")).compare("Digis") == 0;
00044 if(MergeHcalDigis_) MergeHcalDigisProd_ = (ps.getParameter<std::string>("HcalDigiMerge")=="FullProd");
00045
00046
00047
00048 if(DoFastSim_) {
00049
00050
00051
00052
00053
00054 EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
00055 EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
00056 ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
00057
00058 produces< EBRecHitCollection >(EBRecHitCollectionDM_);
00059 produces< EERecHitCollection >(EERecHitCollectionDM_);
00060 produces< ESRecHitCollection >(ESRecHitCollectionDM_);
00061
00062 EMWorker_ = new DataMixingEMWorker(ps);
00063
00064
00065
00066 HBHERecHitCollectionDM_ = ps.getParameter<std::string>("HBHERecHitCollectionDM");
00067 HORecHitCollectionDM_ = ps.getParameter<std::string>("HORecHitCollectionDM");
00068 HFRecHitCollectionDM_ = ps.getParameter<std::string>("HFRecHitCollectionDM");
00069 ZDCRecHitCollectionDM_ = ps.getParameter<std::string>("ZDCRecHitCollectionDM");
00070
00071 produces< HBHERecHitCollection >(HBHERecHitCollectionDM_);
00072 produces< HORecHitCollection >(HORecHitCollectionDM_);
00073 produces< HFRecHitCollection >(HFRecHitCollectionDM_);
00074 produces< ZDCRecHitCollection >(ZDCRecHitCollectionDM_);
00075
00076 HcalWorker_ = new DataMixingHcalWorker(ps);
00077
00078
00079
00080 DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
00081 RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
00082 CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
00083 CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
00084 CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
00085
00086 produces< DTDigiCollection >();
00087 produces< RPCDigiCollection >();
00088 produces< CSCStripDigiCollection >(CSCStripDigiCollectionDM_);
00089 produces< CSCWireDigiCollection >(CSCWireDigiCollectionDM_);
00090 produces< CSCComparatorDigiCollection >(CSCComparatorDigiCollectionDM_);
00091
00092 MuonWorker_ = new DataMixingMuonWorker(ps);
00093
00094
00095
00096 GeneralTrackCollectionDM_ = ps.getParameter<std::string>("GeneralTrackDigiCollectionDM");
00097 produces< reco::TrackCollection >(GeneralTrackCollectionDM_);
00098 GeneralTrackWorker_ = new DataMixingGeneralTrackWorker(ps);
00099
00100 }
00101 else{
00102
00103
00104
00105
00106
00107 if(MergeEMDigis_) {
00108
00109
00110
00111 EBDigiCollectionDM_ = ps.getParameter<std::string>("EBDigiCollectionDM");
00112 EEDigiCollectionDM_ = ps.getParameter<std::string>("EEDigiCollectionDM");
00113 ESDigiCollectionDM_ = ps.getParameter<std::string>("ESDigiCollectionDM");
00114
00115
00116 produces< EBDigiCollection >(EBDigiCollectionDM_);
00117 produces< EEDigiCollection >(EEDigiCollectionDM_);
00118 produces< ESDigiCollection >(ESDigiCollectionDM_);
00119
00120 EMDigiWorker_ = new DataMixingEMDigiWorker(ps);
00121 }
00122 else {
00123 EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
00124 EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
00125 ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
00126
00127
00128 produces< EBRecHitCollection >(EBRecHitCollectionDM_);
00129 produces< EERecHitCollection >(EERecHitCollectionDM_);
00130 produces< ESRecHitCollection >(ESRecHitCollectionDM_);
00131
00132 EMWorker_ = new DataMixingEMWorker(ps);
00133 }
00134
00135
00136 if(MergeHcalDigis_){
00137
00138
00139 HBHEDigiCollectionDM_ = ps.getParameter<std::string>("HBHEDigiCollectionDM");
00140 HODigiCollectionDM_ = ps.getParameter<std::string>("HODigiCollectionDM");
00141 HFDigiCollectionDM_ = ps.getParameter<std::string>("HFDigiCollectionDM");
00142 ZDCDigiCollectionDM_ = ps.getParameter<std::string>("ZDCDigiCollectionDM");
00143
00144 produces< HBHEDigiCollection >();
00145 produces< HODigiCollection >();
00146 produces< HFDigiCollection >();
00147 produces< ZDCDigiCollection >();
00148
00149 if(MergeHcalDigisProd_) {
00150 HcalDigiWorkerProd_ = new DataMixingHcalDigiWorkerProd(ps);
00151 }
00152 else {HcalDigiWorker_ = new DataMixingHcalDigiWorker(ps);
00153 }
00154
00155
00156 }
00157 else{
00158 HBHERecHitCollectionDM_ = ps.getParameter<std::string>("HBHERecHitCollectionDM");
00159 HORecHitCollectionDM_ = ps.getParameter<std::string>("HORecHitCollectionDM");
00160 HFRecHitCollectionDM_ = ps.getParameter<std::string>("HFRecHitCollectionDM");
00161 ZDCRecHitCollectionDM_ = ps.getParameter<std::string>("ZDCRecHitCollectionDM");
00162
00163 produces< HBHERecHitCollection >(HBHERecHitCollectionDM_);
00164 produces< HORecHitCollection >(HORecHitCollectionDM_);
00165 produces< HFRecHitCollection >(HFRecHitCollectionDM_);
00166 produces< ZDCRecHitCollection >(ZDCRecHitCollectionDM_);
00167
00168 HcalWorker_ = new DataMixingHcalWorker(ps);
00169 }
00170
00171
00172
00173 DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
00174 RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
00175 CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
00176 CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
00177 CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
00178
00179
00180 produces< DTDigiCollection >();
00181 produces< RPCDigiCollection >();
00182 produces< CSCStripDigiCollection >(CSCStripDigiCollectionDM_);
00183 produces< CSCWireDigiCollection >(CSCWireDigiCollectionDM_);
00184 produces< CSCComparatorDigiCollection >(CSCComparatorDigiCollectionDM_);
00185
00186 MuonWorker_ = new DataMixingMuonWorker(ps);
00187
00188
00189
00190 useSiStripRawDigi_ = ps.exists("SiStripRawDigiSource")?
00191 ps.getParameter<std::string>("SiStripRawDigiSource")=="PILEUP" ||
00192 ps.getParameter<std::string>("SiStripRawDigiSource")=="SIGNAL" : false;
00193
00194 SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
00195
00196 if(useSiStripRawDigi_) {
00197
00198 produces< edm::DetSetVector<SiStripRawDigi> > (SiStripDigiCollectionDM_);
00199 SiStripRawWorker_ = new DataMixingSiStripRawWorker(ps);
00200
00201 } else {
00202
00203 produces< edm::DetSetVector<SiStripDigi> > (SiStripDigiCollectionDM_);
00204 SiStripWorker_ = new DataMixingSiStripWorker(ps);
00205
00206 }
00207
00208
00209
00210 PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
00211
00212 produces< edm::DetSetVector<PixelDigi> > (PixelDigiCollectionDM_);
00213
00214 SiPixelWorker_ = new DataMixingSiPixelWorker(ps);
00215
00216 }
00217
00218
00219
00220 MergePileup_ = ps.getParameter<bool>("MergePileupInfo");
00221
00222 if(MergePileup_) {
00223 produces< std::vector<PileupSummaryInfo> >();
00224 produces<CrossingFramePlaybackInfoExtended>();
00225
00226 PUWorker_ = new DataMixingPileupCopy(ps);
00227 }
00228
00229 }
00230
00231 void DataMixingModule::getSubdetectorNames() {
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 }
00266
00267
00268
00269
00270
00271 DataMixingModule::~DataMixingModule() {
00272 if(MergeEMDigis_){ delete EMDigiWorker_;}
00273 else {delete EMWorker_;}
00274 if(MergeHcalDigis_) {
00275 if(MergeHcalDigisProd_) { delete HcalDigiWorkerProd_;}
00276 else { delete HcalDigiWorker_; }}
00277 else {delete HcalWorker_;}
00278 if(MuonWorker_) delete MuonWorker_;
00279 if(DoFastSim_){
00280 delete GeneralTrackWorker_;
00281 }else{
00282 if(useSiStripRawDigi_)
00283 delete SiStripRawWorker_;
00284 else
00285 delete SiStripWorker_;
00286 delete SiPixelWorker_;
00287 }
00288 if(MergePileup_) { delete PUWorker_;}
00289 }
00290
00291 void DataMixingModule::addSignals(const edm::Event &e, const edm::EventSetup& ES) {
00292
00293
00294 LogDebug("DataMixingModule")<<"===============> adding MC signals for "<<e.id();
00295
00296
00297 if(MergeEMDigis_) { EMDigiWorker_->addEMSignals(e, ES); }
00298 else{ EMWorker_->addEMSignals(e);}
00299
00300
00301 if(MergeHcalDigis_) {
00302 if(MergeHcalDigisProd_){
00303 HcalDigiWorkerProd_->addHcalSignals(e, ES);
00304 }
00305 else{
00306 HcalDigiWorker_->addHcalSignals(e, ES);
00307 }
00308 }
00309 else {HcalWorker_->addHcalSignals(e);}
00310
00311
00312 MuonWorker_->addMuonSignals(e);
00313
00314 if(DoFastSim_){
00315 GeneralTrackWorker_->addGeneralTrackSignals(e);
00316 }else{
00317
00318 if(useSiStripRawDigi_) SiStripRawWorker_->addSiStripSignals(e);
00319 else SiStripWorker_->addSiStripSignals(e);
00320
00321
00322 SiPixelWorker_->addSiPixelSignals(e);
00323 }
00324 AddedPileup_ = false;
00325
00326 }
00327
00328
00329
00330
00331 void DataMixingModule::pileWorker(const EventPrincipal &ep, int bcr, int eventNr, const edm::EventSetup& ES) {
00332
00333
00334 LogDebug("DataMixingModule") <<"\n===============> adding pileups from event "<<ep.id()<<" for bunchcrossing "<<bcr;
00335
00336
00337
00338
00339 if(MergeEMDigis_) { EMDigiWorker_->addEMPileups(bcr, &ep, eventNr, ES);}
00340 else {EMWorker_->addEMPileups(bcr, &ep, eventNr); }
00341
00342
00343 if(MergeHcalDigis_) {
00344 if(MergeHcalDigisProd_) {
00345 HcalDigiWorkerProd_->addHcalPileups(bcr, &ep, eventNr, ES);
00346 }
00347 else{
00348 HcalDigiWorker_->addHcalPileups(bcr, &ep, eventNr, ES);}
00349 }
00350 else {HcalWorker_->addHcalPileups(bcr, &ep, eventNr);}
00351
00352
00353 MuonWorker_->addMuonPileups(bcr, &ep, eventNr);
00354
00355 if(DoFastSim_){
00356 GeneralTrackWorker_->addGeneralTrackPileups(bcr, &ep, eventNr);
00357 }else{
00358
00359
00360 if(useSiStripRawDigi_) SiStripRawWorker_->addSiStripPileups(bcr, &ep, eventNr);
00361 else SiStripWorker_->addSiStripPileups(bcr, &ep, eventNr);
00362
00363
00364 SiPixelWorker_->addSiPixelPileups(bcr, &ep, eventNr);
00365 }
00366
00367
00368
00369
00370
00371 if(MergePileup_ && !AddedPileup_){
00372
00373 PUWorker_->addPileupInfo(&ep, eventNr);
00374
00375 AddedPileup_ = true;
00376 }
00377
00378 }
00379
00380
00381
00382 void DataMixingModule::doPileUp(edm::Event &e, const edm::EventSetup& ES)
00383 {
00384 std::vector<edm::EventID> recordEventID;
00385 std::vector<int> PileupList;
00386 PileupList.clear();
00387 TrueNumInteractions_.clear();
00388
00389 for (int bunchCrossing=minBunch_;bunchCrossing<=maxBunch_;++bunchCrossing) {
00390 for (unsigned int isource=0;isource<maxNbSources_;++isource) {
00391 boost::shared_ptr<PileUp> source = inputSources_[isource];
00392 if (not source or not source->doPileUp())
00393 continue;
00394
00395 if (isource==0)
00396 source->CalculatePileup(minBunch_, maxBunch_, PileupList, TrueNumInteractions_);
00397
00398 int NumPU_Events = 0;
00399 if (isource ==0) {
00400 NumPU_Events = PileupList[bunchCrossing - minBunch_];
00401 } else {
00402
00403 NumPU_Events = 1;
00404 }
00405
00406 source->readPileUp(
00407 e.id(),
00408 recordEventID,
00409 boost::bind(&DataMixingModule::pileWorker, boost::ref(*this),
00410 _1, bunchCrossing, _2, boost::cref(ES)),
00411 NumPU_Events
00412 );
00413 }
00414 }
00415
00416 }
00417
00418
00419 void DataMixingModule::put(edm::Event &e,const edm::EventSetup& ES) {
00420
00421
00422
00423
00424 if(MergeEMDigis_) {EMDigiWorker_->putEM(e,ES);}
00425 else {EMWorker_->putEM(e);}
00426
00427
00428 if(MergeHcalDigis_) {
00429 if(MergeHcalDigisProd_) {
00430 HcalDigiWorkerProd_->putHcal(e,ES);
00431 }
00432 else{
00433 HcalDigiWorker_->putHcal(e,ES);
00434 }
00435 }
00436 else {HcalWorker_->putHcal(e);}
00437
00438
00439 MuonWorker_->putMuon(e);
00440
00441 if(DoFastSim_){
00442 GeneralTrackWorker_->putGeneralTrack(e);
00443 }else{
00444
00445 if(useSiStripRawDigi_) SiStripRawWorker_->putSiStrip(e);
00446 else SiStripWorker_->putSiStrip(e);
00447
00448
00449 SiPixelWorker_->putSiPixel(e);
00450 }
00451
00452 if(MergePileup_) { PUWorker_->putPileupInfo(e);}
00453
00454
00455 }
00456
00457
00458 }