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  // create input selector
37  if (label_.size()>0){
39  }
40  else {
42  }
43 
44  // For now, list all of them here. Later, make this selectable with input parameters
45  //
46 
47  // Check to see if we are working in Full or Fast Simulation
48 
49  DoFastSim_ = (ps.getParameter<std::string>("IsThisFastSim")).compare("YES") == 0;
50  MergeEMDigis_ = (ps.getParameter<std::string>("EcalMergeType")).compare("Digis") == 0;
51  MergeHcalDigis_ = (ps.getParameter<std::string>("HcalMergeType")).compare("Digis") == 0;
52  if(MergeHcalDigis_) MergeHcalDigisProd_ = (ps.getParameter<std::string>("HcalDigiMerge")=="FullProd");
53 
54  // Put Fast Sim Sequences here for Simplification: Fewer options!
55 
56  if(DoFastSim_) {
57 
58  // declare the products to produce
59 
60  //Ecal:
61 
62  EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
63  EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
64  ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
65 
66  produces< EBRecHitCollection >(EBRecHitCollectionDM_);
67  produces< EERecHitCollection >(EERecHitCollectionDM_);
68  produces< ESRecHitCollection >(ESRecHitCollectionDM_);
69 
70  EMWorker_ = new DataMixingEMWorker(ps);
71 
72  //Hcal:
73 
74  HBHERecHitCollectionDM_ = ps.getParameter<std::string>("HBHERecHitCollectionDM");
75  HORecHitCollectionDM_ = ps.getParameter<std::string>("HORecHitCollectionDM");
76  HFRecHitCollectionDM_ = ps.getParameter<std::string>("HFRecHitCollectionDM");
77  ZDCRecHitCollectionDM_ = ps.getParameter<std::string>("ZDCRecHitCollectionDM");
78 
79  produces< HBHERecHitCollection >(HBHERecHitCollectionDM_);
80  produces< HORecHitCollection >(HORecHitCollectionDM_);
81  produces< HFRecHitCollection >(HFRecHitCollectionDM_);
82  produces< ZDCRecHitCollection >(ZDCRecHitCollectionDM_);
83 
85 
86  //Muons:
87 
88  DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
89  RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
90  CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
91  CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
92  CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
93 
94  produces< DTDigiCollection >();
95  produces< RPCDigiCollection >();
96  produces< CSCStripDigiCollection >(CSCStripDigiCollectionDM_);
97  produces< CSCWireDigiCollection >(CSCWireDigiCollectionDM_);
98  produces< CSCComparatorDigiCollection >(CSCComparatorDigiCollectionDM_);
99 
101 
102  //Tracks:
103 
104  GeneralTrackCollectionDM_ = ps.getParameter<std::string>("GeneralTrackDigiCollectionDM");
105  produces< reco::TrackCollection >(GeneralTrackCollectionDM_);
107 
108  }
109  else{ // Full Simulation options
110 
111  //cout<<"FastSim False!!!"<<endl;
112 
113  // declare the products to produce
114  // Start with EM
115  if(MergeEMDigis_) {
116 
117  // cout<<"EM Digis TRUE!!!"<<endl;
118 
119  EBDigiCollectionDM_ = ps.getParameter<std::string>("EBDigiCollectionDM");
120  EEDigiCollectionDM_ = ps.getParameter<std::string>("EEDigiCollectionDM");
121  ESDigiCollectionDM_ = ps.getParameter<std::string>("ESDigiCollectionDM");
122  // nMaxPrintout_ = ps.getUntrackedParameter<int>("nMaxPrintout",10);
123 
124  produces< EBDigiCollection >(EBDigiCollectionDM_);
125  produces< EEDigiCollection >(EEDigiCollectionDM_);
126  produces< ESDigiCollection >(ESDigiCollectionDM_);
127 
129  }
130  else { // merge RecHits
131  EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
132  EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
133  ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
134  // nMaxPrintout_ = ps.getUntrackedParameter<int>("nMaxPrintout",10);
135 
136  produces< EBRecHitCollection >(EBRecHitCollectionDM_);
137  produces< EERecHitCollection >(EERecHitCollectionDM_);
138  produces< ESRecHitCollection >(ESRecHitCollectionDM_);
139 
140  EMWorker_ = new DataMixingEMWorker(ps);
141  }
142  // Hcal next
143 
144  if(MergeHcalDigis_){
145  // cout<<"Hcal Digis TRUE!!!"<<endl;
146 
147  HBHEDigiCollectionDM_ = ps.getParameter<std::string>("HBHEDigiCollectionDM");
148  HODigiCollectionDM_ = ps.getParameter<std::string>("HODigiCollectionDM");
149  HFDigiCollectionDM_ = ps.getParameter<std::string>("HFDigiCollectionDM");
150  ZDCDigiCollectionDM_ = ps.getParameter<std::string>("ZDCDigiCollectionDM");
151 
152  produces< HBHEDigiCollection >();
153  produces< HODigiCollection >();
154  produces< HFDigiCollection >();
155  produces< ZDCDigiCollection >();
156 
157  if(MergeHcalDigisProd_) {
159  }
161  }
162 
163 
164  }
165  else{
166  HBHERecHitCollectionDM_ = ps.getParameter<std::string>("HBHERecHitCollectionDM");
167  HORecHitCollectionDM_ = ps.getParameter<std::string>("HORecHitCollectionDM");
168  HFRecHitCollectionDM_ = ps.getParameter<std::string>("HFRecHitCollectionDM");
169  ZDCRecHitCollectionDM_ = ps.getParameter<std::string>("ZDCRecHitCollectionDM");
170 
171  produces< HBHERecHitCollection >(HBHERecHitCollectionDM_);
172  produces< HORecHitCollection >(HORecHitCollectionDM_);
173  produces< HFRecHitCollection >(HFRecHitCollectionDM_);
174  produces< ZDCRecHitCollection >(ZDCRecHitCollectionDM_);
175 
177  }
178 
179  // Muons
180 
181  DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
182  RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
183  CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
184  CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
185  CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
186 
187 
188  produces< DTDigiCollection >();
189  produces< RPCDigiCollection >();
190  produces< CSCStripDigiCollection >(CSCStripDigiCollectionDM_);
191  produces< CSCWireDigiCollection >(CSCWireDigiCollectionDM_);
192  produces< CSCComparatorDigiCollection >(CSCComparatorDigiCollectionDM_);
193 
195 
196  // Si-Strips
197 
198  useSiStripRawDigi_ = ps.exists("SiStripRawDigiSource")?
199  ps.getParameter<std::string>("SiStripRawDigiSource")=="PILEUP" ||
200  ps.getParameter<std::string>("SiStripRawDigiSource")=="SIGNAL" : false;
201 
202  SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
203 
204  if(useSiStripRawDigi_) {
205 
206  produces< edm::DetSetVector<SiStripRawDigi> > (SiStripDigiCollectionDM_);
208 
209  } else {
210 
211  produces< edm::DetSetVector<SiStripDigi> > (SiStripDigiCollectionDM_);
213 
214  }
215 
216  // Pixels
217 
218  PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
219 
220  produces< edm::DetSetVector<PixelDigi> > (PixelDigiCollectionDM_);
221 
223 
224  }
225 
226  }
227 
229  // get subdetector names
230  // edm::Service<edm::ConstProductRegistry> reg;
231  // Loop over provenance of products in registry.
232  //for (edm::ProductRegistry::ProductList::const_iterator it = reg->productList().begin(); it != reg->productList().end(); ++it) {
233 
234  // **** Check this out.... ****
235 
236  // See FWCore/Framework/interface/BranchDescription.h
237  // BranchDescription contains all the information for the product.
238 
239  // This section not very backwards-compatible in terms of digi-merging. Need to be able to specify here which data format
240  // to look at...
241 
242  // edm::BranchDescription desc = it->second;
243  //if (!desc.friendlyClassName_.compare(0,9,"EBRecHitC")) {
244  // Subdetectors_.push_back(desc.productInstanceName_);
245  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
246  //}
247  //else if (!desc.friendlyClassName_.compare(0,9,"EERecHitC")) {
248  // else if (!desc.friendlyClassName_.compare(0,9,"EErechitC") && desc.productInstanceName_.compare(0,11,"TrackerHits")) {
249  // Subdetectors_.push_back(desc.productInstanceName_);
250  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
251  //}
252  //else if (!desc.friendlyClassName_.compare(0,9,"HBRecHitC")) {
253  // Subdetectors_.push_back(desc.productInstanceName_);
254  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
255  //}
256  //else if (!desc.friendlyClassName_.compare(0,9,"HERecHitC")) {
257  // Subdetectors_.push_back(desc.productInstanceName_);
258  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
259  // }
260  // and so on with other detector types...
261  // }
262  }
263 
264 
265 
266 
267  // Virtual destructor needed.
269  delete sel_;
270  if(MergeEMDigis_){ delete EMDigiWorker_;}
271  else {delete EMWorker_;}
272  if(MergeHcalDigis_) {
274  else { delete HcalDigiWorker_; }}
275  else {delete HcalWorker_;}
276  if(MuonWorker_) delete MuonWorker_;
277  if(DoFastSim_){
278  delete GeneralTrackWorker_;
279  }else{
281  delete SiStripRawWorker_;
282  else
283  delete SiStripWorker_;
284  delete SiPixelWorker_;
285  }
286  }
287 
289  // fill in maps of hits
290 
291  LogDebug("DataMixingModule")<<"===============> adding MC signals for "<<e.id();
292 
293  // Ecal
294  if(MergeEMDigis_) { EMDigiWorker_->addEMSignals(e, ES); }
295  else{ EMWorker_->addEMSignals(e);}
296 
297  // Hcal
298  if(MergeHcalDigis_) {
301  }
302  else{
304  }
305  }
306  else {HcalWorker_->addHcalSignals(e);}
307 
308  // Muon
310 
311  if(DoFastSim_){
313  }else{
314  // SiStrips
317 
318  // SiPixels
320  }
321  } // end of addSignals
322 
323 
324 
325 
326  void DataMixingModule::pileWorker(const EventPrincipal &ep, int bcr, int eventNr, const edm::EventSetup& ES) {
327 
328 
329  LogDebug("DataMixingModule") <<"\n===============> adding pileups from event "<<ep.id()<<" for bunchcrossing "<<bcr;
330 
331  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
332 
333  // Ecal
334  if(MergeEMDigis_) { EMDigiWorker_->addEMPileups(bcr, &ep, eventNr, ES);}
335  else {EMWorker_->addEMPileups(bcr, &ep, eventNr); }
336 
337  // Hcal
338  if(MergeHcalDigis_) {
339  if(MergeHcalDigisProd_) {
340  HcalDigiWorkerProd_->addHcalPileups(bcr, &ep, eventNr, ES);
341  }
342  else{
343  HcalDigiWorker_->addHcalPileups(bcr, &ep, eventNr, ES);}
344  }
345  else {HcalWorker_->addHcalPileups(bcr, &ep, eventNr);}
346 
347  // Muon
348  MuonWorker_->addMuonPileups(bcr, &ep, eventNr);
349 
350  if(DoFastSim_){
351  GeneralTrackWorker_->addGeneralTrackPileups(bcr, &ep, eventNr);
352  }else{
353 
354  // SiStrips
356  else SiStripWorker_->addSiStripPileups(bcr, &ep, eventNr);
357 
358  // SiPixels
359  SiPixelWorker_->addSiPixelPileups(bcr, &ep, eventNr);
360  }
361  }
362 
363 
364 
366  {
367  std::vector<edm::EventID> recordEventID;
368  std::vector<int> PileupList;
369  PileupList.clear();
370  TrueNumInteractions_.clear();
371 
372  for (int bunchCrossing=minBunch_;bunchCrossing<=maxBunch_;++bunchCrossing) {
373  for (unsigned int isource=0;isource<maxNbSources_;++isource) {
374  boost::shared_ptr<PileUp> source = inputSources_[isource];
375  if (not source or not source->doPileUp())
376  continue;
377 
378  if (isource==0)
379  source->CalculatePileup(minBunch_, maxBunch_, PileupList, TrueNumInteractions_);
380 
381  int NumPU_Events = 0;
382  if (isource ==0) {
383  NumPU_Events = PileupList[bunchCrossing - minBunch_];
384  } else {
385  // non-minbias pileup only gets one event for now. Fix later if desired.
386  NumPU_Events = 1;
387  }
388 
389  source->readPileUp(
390  e.id(),
391  recordEventID,
392  boost::bind(&DataMixingModule::pileWorker, boost::ref(*this),
393  _1, bunchCrossing, _2, boost::cref(ES)),
394  NumPU_Events
395  );
396  }
397  }
398  }
399 
400 
402 
403  // individual workers...
404 
405  // Ecal
406  if(MergeEMDigis_) {EMDigiWorker_->putEM(e,ES);}
407  else {EMWorker_->putEM(e);}
408 
409  // Hcal
410  if(MergeHcalDigis_) {
411  if(MergeHcalDigisProd_) {
413  }
414  else{
415  HcalDigiWorker_->putHcal(e,ES);
416  }
417  }
418  else {HcalWorker_->putHcal(e);}
419 
420  // Muon
421  MuonWorker_->putMuon(e);
422 
423  if(DoFastSim_){
425  }else{
426  // SiStrips
428  else SiStripWorker_->putSiStrip(e);
429 
430  // SiPixels
432  }
433  }
434 
435 
436 } //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_
std::vector< float > TrueNumInteractions_
Definition: BMixingModule.h:82
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:79
void addEMPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, const edm::EventSetup &ES)
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:87
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)