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 void DataMixingModule::getSubdetectorNames() {
00221
00222
00223
00224
00225
00226
00227
00228
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 DataMixingModule::~DataMixingModule() {
00261 if(MergeEMDigis_){ delete EMDigiWorker_;}
00262 else {delete EMWorker_;}
00263 if(MergeHcalDigis_) {
00264 if(MergeHcalDigisProd_) { delete HcalDigiWorkerProd_;}
00265 else { delete HcalDigiWorker_; }}
00266 else {delete HcalWorker_;}
00267 if(MuonWorker_) delete MuonWorker_;
00268 if(DoFastSim_){
00269 delete GeneralTrackWorker_;
00270 }else{
00271 if(useSiStripRawDigi_)
00272 delete SiStripRawWorker_;
00273 else
00274 delete SiStripWorker_;
00275 delete SiPixelWorker_;
00276 }
00277 }
00278
00279 void DataMixingModule::addSignals(const edm::Event &e, const edm::EventSetup& ES) {
00280
00281
00282 LogDebug("DataMixingModule")<<"===============> adding MC signals for "<<e.id();
00283
00284
00285 if(MergeEMDigis_) { EMDigiWorker_->addEMSignals(e, ES); }
00286 else{ EMWorker_->addEMSignals(e);}
00287
00288
00289 if(MergeHcalDigis_) {
00290 if(MergeHcalDigisProd_){
00291 HcalDigiWorkerProd_->addHcalSignals(e, ES);
00292 }
00293 else{
00294 HcalDigiWorker_->addHcalSignals(e, ES);
00295 }
00296 }
00297 else {HcalWorker_->addHcalSignals(e);}
00298
00299
00300 MuonWorker_->addMuonSignals(e);
00301
00302 if(DoFastSim_){
00303 GeneralTrackWorker_->addGeneralTrackSignals(e);
00304 }else{
00305
00306 if(useSiStripRawDigi_) SiStripRawWorker_->addSiStripSignals(e);
00307 else SiStripWorker_->addSiStripSignals(e);
00308
00309
00310 SiPixelWorker_->addSiPixelSignals(e);
00311 }
00312 }
00313
00314
00315
00316
00317 void DataMixingModule::pileWorker(const EventPrincipal &ep, int bcr, int eventNr, const edm::EventSetup& ES) {
00318
00319
00320 LogDebug("DataMixingModule") <<"\n===============> adding pileups from event "<<ep.id()<<" for bunchcrossing "<<bcr;
00321
00322
00323
00324
00325 if(MergeEMDigis_) { EMDigiWorker_->addEMPileups(bcr, &ep, eventNr, ES);}
00326 else {EMWorker_->addEMPileups(bcr, &ep, eventNr); }
00327
00328
00329 if(MergeHcalDigis_) {
00330 if(MergeHcalDigisProd_) {
00331 HcalDigiWorkerProd_->addHcalPileups(bcr, &ep, eventNr, ES);
00332 }
00333 else{
00334 HcalDigiWorker_->addHcalPileups(bcr, &ep, eventNr, ES);}
00335 }
00336 else {HcalWorker_->addHcalPileups(bcr, &ep, eventNr);}
00337
00338
00339 MuonWorker_->addMuonPileups(bcr, &ep, eventNr);
00340
00341 if(DoFastSim_){
00342 GeneralTrackWorker_->addGeneralTrackPileups(bcr, &ep, eventNr);
00343 }else{
00344
00345
00346 if(useSiStripRawDigi_) SiStripRawWorker_->addSiStripPileups(bcr, &ep, eventNr);
00347 else SiStripWorker_->addSiStripPileups(bcr, &ep, eventNr);
00348
00349
00350 SiPixelWorker_->addSiPixelPileups(bcr, &ep, eventNr);
00351 }
00352 }
00353
00354
00355
00356 void DataMixingModule::doPileUp(edm::Event &e, const edm::EventSetup& ES)
00357 {
00358 std::vector<edm::EventID> recordEventID;
00359 std::vector<int> PileupList;
00360 PileupList.clear();
00361 TrueNumInteractions_.clear();
00362
00363 for (int bunchCrossing=minBunch_;bunchCrossing<=maxBunch_;++bunchCrossing) {
00364 for (unsigned int isource=0;isource<maxNbSources_;++isource) {
00365 boost::shared_ptr<PileUp> source = inputSources_[isource];
00366 if (not source or not source->doPileUp())
00367 continue;
00368
00369 if (isource==0)
00370 source->CalculatePileup(minBunch_, maxBunch_, PileupList, TrueNumInteractions_);
00371
00372 int NumPU_Events = 0;
00373 if (isource ==0) {
00374 NumPU_Events = PileupList[bunchCrossing - minBunch_];
00375 } else {
00376
00377 NumPU_Events = 1;
00378 }
00379
00380 source->readPileUp(
00381 e.id(),
00382 recordEventID,
00383 boost::bind(&DataMixingModule::pileWorker, boost::ref(*this),
00384 _1, bunchCrossing, _2, boost::cref(ES)),
00385 NumPU_Events
00386 );
00387 }
00388 }
00389 }
00390
00391
00392 void DataMixingModule::put(edm::Event &e,const edm::EventSetup& ES) {
00393
00394
00395
00396
00397 if(MergeEMDigis_) {EMDigiWorker_->putEM(e,ES);}
00398 else {EMWorker_->putEM(e);}
00399
00400
00401 if(MergeHcalDigis_) {
00402 if(MergeHcalDigisProd_) {
00403 HcalDigiWorkerProd_->putHcal(e,ES);
00404 }
00405 else{
00406 HcalDigiWorker_->putHcal(e,ES);
00407 }
00408 }
00409 else {HcalWorker_->putHcal(e);}
00410
00411
00412 MuonWorker_->putMuon(e);
00413
00414 if(DoFastSim_){
00415 GeneralTrackWorker_->putGeneralTrack(e);
00416 }else{
00417
00418 if(useSiStripRawDigi_) SiStripRawWorker_->putSiStrip(e);
00419 else SiStripWorker_->putSiStrip(e);
00420
00421
00422 SiPixelWorker_->putSiPixel(e);
00423 }
00424 }
00425
00426
00427 }