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