CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataMixingModule.cc
Go to the documentation of this file.
1 // File: DataMixingModule.cc
2 // Description: see DataMixingModule.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
7 #include <map>
8 #include <iostream>
9 #include <boost/bind.hpp>
17 //
18 //
19 #include "DataMixingModule.h"
20 
21 
22 using namespace std;
23 
24 namespace edm
25 {
26 
27  // Constructor
28  DataMixingModule::DataMixingModule(const edm::ParameterSet& ps) : BMixingModule(ps),
29  label_(ps.getParameter<std::string>("Label"))
30 
31  { // what's "label_"?
32 
33  // get the subdetector names
34  this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
35 
36  // For now, list all of them here. Later, make this selectable with input parameters
37  //
38 
39  // Check to see if we are working in Full or Fast Simulation
40 
41  DoFastSim_ = (ps.getParameter<std::string>("IsThisFastSim")).compare("YES") == 0;
42  MergeEMDigis_ = (ps.getParameter<std::string>("EcalMergeType")).compare("Digis") == 0;
43  MergeHcalDigis_ = (ps.getParameter<std::string>("HcalMergeType")).compare("Digis") == 0;
44  if(MergeHcalDigis_) MergeHcalDigisProd_ = (ps.getParameter<std::string>("HcalDigiMerge")=="FullProd");
45 
46  // Put Fast Sim Sequences here for Simplification: Fewer options!
47 
48  if(DoFastSim_) {
49 
50  // declare the products to produce
51 
52  //Ecal:
53 
54  EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
55  EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
56  ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
57 
58  produces< EBRecHitCollection >(EBRecHitCollectionDM_);
59  produces< EERecHitCollection >(EERecHitCollectionDM_);
60  produces< ESRecHitCollection >(ESRecHitCollectionDM_);
61 
62  EMWorker_ = new DataMixingEMWorker(ps);
63 
64  //Hcal:
65 
66  HBHERecHitCollectionDM_ = ps.getParameter<std::string>("HBHERecHitCollectionDM");
67  HORecHitCollectionDM_ = ps.getParameter<std::string>("HORecHitCollectionDM");
68  HFRecHitCollectionDM_ = ps.getParameter<std::string>("HFRecHitCollectionDM");
69  ZDCRecHitCollectionDM_ = ps.getParameter<std::string>("ZDCRecHitCollectionDM");
70 
71  produces< HBHERecHitCollection >(HBHERecHitCollectionDM_);
72  produces< HORecHitCollection >(HORecHitCollectionDM_);
73  produces< HFRecHitCollection >(HFRecHitCollectionDM_);
74  produces< ZDCRecHitCollection >(ZDCRecHitCollectionDM_);
75 
77 
78  //Muons:
79 
80  DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
81  RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
82  CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
83  CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
84  CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
85 
86  produces< DTDigiCollection >();
87  produces< RPCDigiCollection >();
88  produces< CSCStripDigiCollection >(CSCStripDigiCollectionDM_);
89  produces< CSCWireDigiCollection >(CSCWireDigiCollectionDM_);
90  produces< CSCComparatorDigiCollection >(CSCComparatorDigiCollectionDM_);
91 
93 
94  //Tracks:
95 
96  GeneralTrackCollectionDM_ = ps.getParameter<std::string>("GeneralTrackDigiCollectionDM");
97  produces< reco::TrackCollection >(GeneralTrackCollectionDM_);
99 
100  }
101  else{ // Full Simulation options
102 
103  //cout<<"FastSim False!!!"<<endl;
104 
105  // declare the products to produce
106  // Start with EM
107  if(MergeEMDigis_) {
108 
109  // cout<<"EM Digis TRUE!!!"<<endl;
110 
111  EBDigiCollectionDM_ = ps.getParameter<std::string>("EBDigiCollectionDM");
112  EEDigiCollectionDM_ = ps.getParameter<std::string>("EEDigiCollectionDM");
113  ESDigiCollectionDM_ = ps.getParameter<std::string>("ESDigiCollectionDM");
114  // nMaxPrintout_ = ps.getUntrackedParameter<int>("nMaxPrintout",10);
115 
116  produces< EBDigiCollection >(EBDigiCollectionDM_);
117  produces< EEDigiCollection >(EEDigiCollectionDM_);
118  produces< ESDigiCollection >(ESDigiCollectionDM_);
119 
121  }
122  else { // merge RecHits
123  EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
124  EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
125  ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
126  // nMaxPrintout_ = ps.getUntrackedParameter<int>("nMaxPrintout",10);
127 
128  produces< EBRecHitCollection >(EBRecHitCollectionDM_);
129  produces< EERecHitCollection >(EERecHitCollectionDM_);
130  produces< ESRecHitCollection >(ESRecHitCollectionDM_);
131 
132  EMWorker_ = new DataMixingEMWorker(ps);
133  }
134  // Hcal next
135 
136  if(MergeHcalDigis_){
137  // cout<<"Hcal Digis TRUE!!!"<<endl;
138 
139  HBHEDigiCollectionDM_ = ps.getParameter<std::string>("HBHEDigiCollectionDM");
140  HODigiCollectionDM_ = ps.getParameter<std::string>("HODigiCollectionDM");
141  HFDigiCollectionDM_ = ps.getParameter<std::string>("HFDigiCollectionDM");
142  ZDCDigiCollectionDM_ = ps.getParameter<std::string>("ZDCDigiCollectionDM");
143 
144  produces< HBHEDigiCollection >();
145  produces< HODigiCollection >();
146  produces< HFDigiCollection >();
147  produces< ZDCDigiCollection >();
148 
149  if(MergeHcalDigisProd_) {
151  }
153  }
154 
155 
156  }
157  else{
158  HBHERecHitCollectionDM_ = ps.getParameter<std::string>("HBHERecHitCollectionDM");
159  HORecHitCollectionDM_ = ps.getParameter<std::string>("HORecHitCollectionDM");
160  HFRecHitCollectionDM_ = ps.getParameter<std::string>("HFRecHitCollectionDM");
161  ZDCRecHitCollectionDM_ = ps.getParameter<std::string>("ZDCRecHitCollectionDM");
162 
163  produces< HBHERecHitCollection >(HBHERecHitCollectionDM_);
164  produces< HORecHitCollection >(HORecHitCollectionDM_);
165  produces< HFRecHitCollection >(HFRecHitCollectionDM_);
166  produces< ZDCRecHitCollection >(ZDCRecHitCollectionDM_);
167 
169  }
170 
171  // Muons
172 
173  DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
174  RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
175  CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
176  CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
177  CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
178 
179 
180  produces< DTDigiCollection >();
181  produces< RPCDigiCollection >();
182  produces< CSCStripDigiCollection >(CSCStripDigiCollectionDM_);
183  produces< CSCWireDigiCollection >(CSCWireDigiCollectionDM_);
184  produces< CSCComparatorDigiCollection >(CSCComparatorDigiCollectionDM_);
185 
187 
188  // Si-Strips
189 
190  useSiStripRawDigi_ = ps.exists("SiStripRawDigiSource")?
191  ps.getParameter<std::string>("SiStripRawDigiSource")=="PILEUP" ||
192  ps.getParameter<std::string>("SiStripRawDigiSource")=="SIGNAL" : false;
193 
194  SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
195 
196  if(useSiStripRawDigi_) {
197 
198  produces< edm::DetSetVector<SiStripRawDigi> > (SiStripDigiCollectionDM_);
200 
201  } else {
202 
203  produces< edm::DetSetVector<SiStripDigi> > (SiStripDigiCollectionDM_);
205 
206  }
207 
208  // Pixels
209 
210  PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
211 
212  produces< edm::DetSetVector<PixelDigi> > (PixelDigiCollectionDM_);
213 
215 
216  }
217 
218  // Pileup Information: if doing pre-mixing, we have to save the pileup information from the Secondary stream
219 
220  MergePileup_ = ps.getParameter<bool>("MergePileupInfo");
221 
222  if(MergePileup_) {
223  produces< std::vector<PileupSummaryInfo> >();
224  produces<CrossingFramePlaybackInfoExtended>();
225 
227  }
228 
229  }
230 
232  // get subdetector names
233  // edm::Service<edm::ConstProductRegistry> reg;
234  // Loop over provenance of products in registry.
235  //for (edm::ProductRegistry::ProductList::const_iterator it = reg->productList().begin(); it != reg->productList().end(); ++it) {
236 
237  // **** Check this out.... ****
238 
239  // See FWCore/Framework/interface/BranchDescription.h
240  // BranchDescription contains all the information for the product.
241 
242  // This section not very backwards-compatible in terms of digi-merging. Need to be able to specify here which data format
243  // to look at...
244 
245  // edm::BranchDescription desc = it->second;
246  //if (!desc.friendlyClassName_.compare(0,9,"EBRecHitC")) {
247  // Subdetectors_.push_back(desc.productInstanceName_);
248  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
249  //}
250  //else if (!desc.friendlyClassName_.compare(0,9,"EERecHitC")) {
251  // else if (!desc.friendlyClassName_.compare(0,9,"EErechitC") && desc.productInstanceName_.compare(0,11,"TrackerHits")) {
252  // Subdetectors_.push_back(desc.productInstanceName_);
253  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
254  //}
255  //else if (!desc.friendlyClassName_.compare(0,9,"HBRecHitC")) {
256  // Subdetectors_.push_back(desc.productInstanceName_);
257  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
258  //}
259  //else if (!desc.friendlyClassName_.compare(0,9,"HERecHitC")) {
260  // Subdetectors_.push_back(desc.productInstanceName_);
261  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
262  // }
263  // and so on with other detector types...
264  // }
265  }
266 
267 
268 
269 
270  // Virtual destructor needed.
272  if(MergeEMDigis_){ delete EMDigiWorker_;}
273  else {delete EMWorker_;}
274  if(MergeHcalDigis_) {
276  else { delete HcalDigiWorker_; }}
277  else {delete HcalWorker_;}
278  if(MuonWorker_) delete MuonWorker_;
279  if(DoFastSim_){
280  delete GeneralTrackWorker_;
281  }else{
283  delete SiStripRawWorker_;
284  else
285  delete SiStripWorker_;
286  delete SiPixelWorker_;
287  }
288  if(MergePileup_) { delete PUWorker_;}
289  }
290 
292  // fill in maps of hits
293 
294  LogDebug("DataMixingModule")<<"===============> adding MC signals for "<<e.id();
295 
296  // Ecal
297  if(MergeEMDigis_) { EMDigiWorker_->addEMSignals(e, ES); }
298  else{ EMWorker_->addEMSignals(e);}
299 
300  // Hcal
301  if(MergeHcalDigis_) {
304  }
305  else{
307  }
308  }
309  else {HcalWorker_->addHcalSignals(e);}
310 
311  // Muon
313 
314  if(DoFastSim_){
316  }else{
317  // SiStrips
320 
321  // SiPixels
323  }
324  AddedPileup_ = false;
325 
326  } // end of addSignals
327 
328 
329 
330 
331  void DataMixingModule::pileWorker(const EventPrincipal &ep, int bcr, int eventNr, const edm::EventSetup& ES) {
332 
333 
334  LogDebug("DataMixingModule") <<"\n===============> adding pileups from event "<<ep.id()<<" for bunchcrossing "<<bcr;
335 
336  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
337 
338  // Ecal
339  if(MergeEMDigis_) { EMDigiWorker_->addEMPileups(bcr, &ep, eventNr, ES);}
340  else {EMWorker_->addEMPileups(bcr, &ep, eventNr); }
341 
342  // Hcal
343  if(MergeHcalDigis_) {
344  if(MergeHcalDigisProd_) {
345  HcalDigiWorkerProd_->addHcalPileups(bcr, &ep, eventNr, ES);
346  }
347  else{
348  HcalDigiWorker_->addHcalPileups(bcr, &ep, eventNr, ES);}
349  }
350  else {HcalWorker_->addHcalPileups(bcr, &ep, eventNr);}
351 
352  // Muon
353  MuonWorker_->addMuonPileups(bcr, &ep, eventNr);
354 
355  if(DoFastSim_){
356  GeneralTrackWorker_->addGeneralTrackPileups(bcr, &ep, eventNr);
357  }else{
358 
359  // SiStrips
361  else SiStripWorker_->addSiStripPileups(bcr, &ep, eventNr);
362 
363  // SiPixels
364  SiPixelWorker_->addSiPixelPileups(bcr, &ep, eventNr);
365  }
366 
367  // check and see if we need to copy the pileup information from
368  // secondary stream to the output stream
369  // We only have the pileup event here, so pick the first time and store the info
370 
371  if(MergePileup_ && !AddedPileup_){
372 
373  PUWorker_->addPileupInfo(&ep, eventNr);
374 
375  AddedPileup_ = true;
376  }
377 
378  }
379 
380 
381 
383  {
384  std::vector<edm::EventID> recordEventID;
385  std::vector<int> PileupList;
386  PileupList.clear();
387  TrueNumInteractions_.clear();
388 
389  for (int bunchCrossing=minBunch_;bunchCrossing<=maxBunch_;++bunchCrossing) {
390  for (unsigned int isource=0;isource<maxNbSources_;++isource) {
391  boost::shared_ptr<PileUp> source = inputSources_[isource];
392  if (not source or not source->doPileUp())
393  continue;
394 
395  if (isource==0)
396  source->CalculatePileup(minBunch_, maxBunch_, PileupList, TrueNumInteractions_);
397 
398  int NumPU_Events = 0;
399  if (isource ==0) {
400  NumPU_Events = PileupList[bunchCrossing - minBunch_];
401  } else {
402  // non-minbias pileup only gets one event for now. Fix later if desired.
403  NumPU_Events = 1;
404  }
405 
406  source->readPileUp(
407  e.id(),
408  recordEventID,
409  boost::bind(&DataMixingModule::pileWorker, boost::ref(*this),
410  _1, bunchCrossing, _2, boost::cref(ES)),
411  NumPU_Events
412  );
413  }
414  }
415 
416  }
417 
418 
420 
421  // individual workers...
422 
423  // Ecal
424  if(MergeEMDigis_) {EMDigiWorker_->putEM(e,ES);}
425  else {EMWorker_->putEM(e);}
426 
427  // Hcal
428  if(MergeHcalDigis_) {
429  if(MergeHcalDigisProd_) {
431  }
432  else{
433  HcalDigiWorker_->putHcal(e,ES);
434  }
435  }
436  else {HcalWorker_->putHcal(e);}
437 
438  // Muon
439  MuonWorker_->putMuon(e);
440 
441  if(DoFastSim_){
443  }else{
444  // SiStrips
446  else SiStripWorker_->putSiStrip(e);
447 
448  // SiPixels
450  }
451 
453 
454 
455  }
456 
457 
458 } //edm
#define LogDebug(id)
T getParameter(std::string const &) const
void addMuonSignals(const edm::Event &e)
std::string HFDigiCollectionDM_
void addHcalSignals(const edm::Event &e, const edm::EventSetup &ES)
void addHcalPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, const edm::EventSetup &ES)
void putEM(edm::Event &e)
void addSiStripSignals(const edm::Event &e)
void addHcalSignals(const edm::Event &e)
void addSiPixelPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId)
std::string HBHERecHitCollectionDM_
std::string ZDCRecHitCollectionDM_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void addEMSignals(const edm::Event &e)
void addHcalPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId)
DataMixingGeneralTrackWorker * GeneralTrackWorker_
std::string CSCStripDigiCollectionDM_
void putPileupInfo(edm::Event &e)
std::vector< float > TrueNumInteractions_
Definition: BMixingModule.h:90
EventID const & id() const
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string SiStripDigiCollectionDM_
std::string CSCWireDigiCollectionDM_
void putEM(edm::Event &e, const edm::EventSetup &ES)
DataMixingSiStripRawWorker * SiStripRawWorker_
DataMixingSiPixelWorker * SiPixelWorker_
std::string RPCDigiCollectionDM_
void addSiStripPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId)
void putHcal(edm::Event &e, const edm::EventSetup &ES)
std::string ZDCDigiCollectionDM_
void addGeneralTrackPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId)
DataMixingHcalDigiWorker * HcalDigiWorker_
DataMixingEMWorker * EMWorker_
std::string GeneralTrackCollectionDM_
virtual void addSignals(const edm::Event &e, const edm::EventSetup &ES)
void addHcalPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, const edm::EventSetup &ES)
static const unsigned int maxNbSources_
Definition: BMixingModule.h:87
void addEMPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, const edm::EventSetup &ES)
DataMixingPileupCopy * PUWorker_
void addEMPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId)
void addSiStripPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId)
virtual void doPileUp(edm::Event &e, const edm::EventSetup &ES)
std::string HORecHitCollectionDM_
DataMixingMuonWorker * MuonWorker_
virtual void getSubdetectorNames()
std::string EEDigiCollectionDM_
std::string HFRecHitCollectionDM_
std::string HBHEDigiCollectionDM_
std::string EBRecHitCollectionDM_
std::string CSCComparatorDigiCollectionDM_
void putHcal(edm::Event &e, const edm::EventSetup &ES)
void addMuonPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId)
std::vector< boost::shared_ptr< PileUp > > inputSources_
Definition: BMixingModule.h:95
edm::EventID id() const
Definition: EventBase.h:56
DataMixingSiStripWorker * SiStripWorker_
std::string ESRecHitCollectionDM_
std::string EERecHitCollectionDM_
std::string ESDigiCollectionDM_
std::string DTDigiCollectionDM_
void addSiStripSignals(const edm::Event &e)
std::string EBDigiCollectionDM_
DataMixingHcalWorker * HcalWorker_
std::string HODigiCollectionDM_
std::string PixelDigiCollectionDM_
DataMixingHcalDigiWorkerProd * HcalDigiWorkerProd_
void addEMSignals(const edm::Event &e, const edm::EventSetup &ES)
void addHcalSignals(const edm::Event &e, const edm::EventSetup &ES)
void pileWorker(const edm::EventPrincipal &, int bcr, int EventId, const edm::EventSetup &ES)
DataMixingEMDigiWorker * EMDigiWorker_
void addSiPixelSignals(const edm::Event &e)
virtual void put(edm::Event &e, const edm::EventSetup &ES)
void addPileupInfo(const edm::EventPrincipal *, unsigned int EventId)