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>
16 //
17 //
18 #include "DataMixingModule.h"
19 
20 
21 using namespace std;
22 
23 namespace edm
24 {
25 
26  // Constructor
27  DataMixingModule::DataMixingModule(const edm::ParameterSet& ps) : BMixingModule(ps),
28  label_(ps.getParameter<std::string>("Label"))
29 
30  { // what's "label_"?
31 
32  // get the subdetector names
33  this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
34 
35  // create input selector
36  if (label_.size()>0){
38  }
39  else {
41  }
42 
43  // For now, list all of them here. Later, make this selectable with input parameters
44  //
45 
46  // Check to see if we are working in Full or Fast Simulation
47 
48  DoFastSim_ = (ps.getParameter<std::string>("IsThisFastSim")).compare("YES") == 0;
49  MergeEMDigis_ = (ps.getParameter<std::string>("EcalMergeType")).compare("Digis") == 0;
50  MergeHcalDigis_ = (ps.getParameter<std::string>("HcalMergeType")).compare("Digis") == 0;
51  if(MergeHcalDigis_) MergeHcalDigisProd_ = (ps.getParameter<std::string>("HcalDigiMerge")=="FullProd");
52 
53  // Put Fast Sim Sequences here for Simplification: Fewer options!
54 
55  if(DoFastSim_) {
56 
57  // declare the products to produce
58 
59  //Ecal:
60 
61  EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
62  EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
63  ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
64 
65  produces< EBRecHitCollection >(EBRecHitCollectionDM_);
66  produces< EERecHitCollection >(EERecHitCollectionDM_);
67  produces< ESRecHitCollection >(ESRecHitCollectionDM_);
68 
69  EMWorker_ = new DataMixingEMWorker(ps);
70 
71  //Hcal:
72 
73  HBHERecHitCollectionDM_ = ps.getParameter<std::string>("HBHERecHitCollectionDM");
74  HORecHitCollectionDM_ = ps.getParameter<std::string>("HORecHitCollectionDM");
75  HFRecHitCollectionDM_ = ps.getParameter<std::string>("HFRecHitCollectionDM");
76  ZDCRecHitCollectionDM_ = ps.getParameter<std::string>("ZDCRecHitCollectionDM");
77 
78  produces< HBHERecHitCollection >(HBHERecHitCollectionDM_);
79  produces< HORecHitCollection >(HORecHitCollectionDM_);
80  produces< HFRecHitCollection >(HFRecHitCollectionDM_);
81  produces< ZDCRecHitCollection >(ZDCRecHitCollectionDM_);
82 
84 
85  //Muons:
86 
87  DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
88  RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
89  CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
90  CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
91  CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
92 
93  produces< DTDigiCollection >();
94  produces< RPCDigiCollection >();
95  produces< CSCStripDigiCollection >(CSCStripDigiCollectionDM_);
96  produces< CSCWireDigiCollection >(CSCWireDigiCollectionDM_);
97  produces< CSCComparatorDigiCollection >(CSCComparatorDigiCollectionDM_);
98 
100 
101  //Tracks:
102 
103  GeneralTrackCollectionDM_ = ps.getParameter<std::string>("GeneralTrackDigiCollectionDM");
104  produces< reco::TrackCollection >(GeneralTrackCollectionDM_);
106 
107  }
108  else{ // Full Simulation options
109 
110  //cout<<"FastSim False!!!"<<endl;
111 
112  // declare the products to produce
113  // Start with EM
114  if(MergeEMDigis_) {
115 
116  // cout<<"EM Digis TRUE!!!"<<endl;
117 
118  EBDigiCollectionDM_ = ps.getParameter<std::string>("EBDigiCollectionDM");
119  EEDigiCollectionDM_ = ps.getParameter<std::string>("EEDigiCollectionDM");
120  ESDigiCollectionDM_ = ps.getParameter<std::string>("ESDigiCollectionDM");
121  // nMaxPrintout_ = ps.getUntrackedParameter<int>("nMaxPrintout",10);
122 
123  produces< EBDigiCollection >(EBDigiCollectionDM_);
124  produces< EEDigiCollection >(EEDigiCollectionDM_);
125  produces< ESDigiCollection >(ESDigiCollectionDM_);
126 
128  }
129  else { // merge RecHits
130  EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
131  EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
132  ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
133  // nMaxPrintout_ = ps.getUntrackedParameter<int>("nMaxPrintout",10);
134 
135  produces< EBRecHitCollection >(EBRecHitCollectionDM_);
136  produces< EERecHitCollection >(EERecHitCollectionDM_);
137  produces< ESRecHitCollection >(ESRecHitCollectionDM_);
138 
139  EMWorker_ = new DataMixingEMWorker(ps);
140  }
141  // Hcal next
142 
143  if(MergeHcalDigis_){
144  // cout<<"Hcal Digis TRUE!!!"<<endl;
145 
146  HBHEDigiCollectionDM_ = ps.getParameter<std::string>("HBHEDigiCollectionDM");
147  HODigiCollectionDM_ = ps.getParameter<std::string>("HODigiCollectionDM");
148  HFDigiCollectionDM_ = ps.getParameter<std::string>("HFDigiCollectionDM");
149  ZDCDigiCollectionDM_ = ps.getParameter<std::string>("ZDCDigiCollectionDM");
150 
151  produces< HBHEDigiCollection >();
152  produces< HODigiCollection >();
153  produces< HFDigiCollection >();
154  produces< ZDCDigiCollection >();
155 
156  if(MergeHcalDigisProd_) {
158  }
160  }
161 
162 
163  }
164  else{
165  HBHERecHitCollectionDM_ = ps.getParameter<std::string>("HBHERecHitCollectionDM");
166  HORecHitCollectionDM_ = ps.getParameter<std::string>("HORecHitCollectionDM");
167  HFRecHitCollectionDM_ = ps.getParameter<std::string>("HFRecHitCollectionDM");
168  ZDCRecHitCollectionDM_ = ps.getParameter<std::string>("ZDCRecHitCollectionDM");
169 
170  produces< HBHERecHitCollection >(HBHERecHitCollectionDM_);
171  produces< HORecHitCollection >(HORecHitCollectionDM_);
172  produces< HFRecHitCollection >(HFRecHitCollectionDM_);
173  produces< ZDCRecHitCollection >(ZDCRecHitCollectionDM_);
174 
176  }
177 
178  // Muons
179 
180  DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
181  RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
182  CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
183  CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
184  CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
185 
186 
187  produces< DTDigiCollection >();
188  produces< RPCDigiCollection >();
189  produces< CSCStripDigiCollection >(CSCStripDigiCollectionDM_);
190  produces< CSCWireDigiCollection >(CSCWireDigiCollectionDM_);
191  produces< CSCComparatorDigiCollection >(CSCComparatorDigiCollectionDM_);
192 
194 
195  // Si-Strips
196 
197  useSiStripRawDigi_ = ps.exists("SiStripRawDigiSource")?
198  ps.getParameter<std::string>("SiStripRawDigiSource")=="PILEUP" ||
199  ps.getParameter<std::string>("SiStripRawDigiSource")=="SIGNAL" : false;
200 
201  SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
202 
203  if(useSiStripRawDigi_) {
204 
205  produces< edm::DetSetVector<SiStripRawDigi> > (SiStripDigiCollectionDM_);
207 
208  } else {
209 
210  produces< edm::DetSetVector<SiStripDigi> > (SiStripDigiCollectionDM_);
212 
213  }
214 
215  // Pixels
216 
217  PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
218 
219  produces< edm::DetSetVector<PixelDigi> > (PixelDigiCollectionDM_);
220 
222 
223  }
224 
225  }
226 
228  // get subdetector names
229  // edm::Service<edm::ConstProductRegistry> reg;
230  // Loop over provenance of products in registry.
231  //for (edm::ProductRegistry::ProductList::const_iterator it = reg->productList().begin(); it != reg->productList().end(); ++it) {
232 
233  // **** Check this out.... ****
234 
235  // See FWCore/Framework/interface/BranchDescription.h
236  // BranchDescription contains all the information for the product.
237 
238  // This section not very backwards-compatible in terms of digi-merging. Need to be able to specify here which data format
239  // to look at...
240 
241  // edm::BranchDescription desc = it->second;
242  //if (!desc.friendlyClassName_.compare(0,9,"EBRecHitC")) {
243  // Subdetectors_.push_back(desc.productInstanceName_);
244  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
245  //}
246  //else if (!desc.friendlyClassName_.compare(0,9,"EERecHitC")) {
247  // else if (!desc.friendlyClassName_.compare(0,9,"EErechitC") && desc.productInstanceName_.compare(0,11,"TrackerHits")) {
248  // Subdetectors_.push_back(desc.productInstanceName_);
249  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
250  //}
251  //else if (!desc.friendlyClassName_.compare(0,9,"HBRecHitC")) {
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,"HERecHitC")) {
256  // Subdetectors_.push_back(desc.productInstanceName_);
257  //LogInfo("DataMixingModule") <<"Adding container "<<desc.productInstanceName_ <<" for pileup treatment";
258  // }
259  // and so on with other detector types...
260  // }
261  }
262 
263 
265  }
266 
267 
268  // Virtual destructor needed.
270  delete sel_;
271  if(MergeEMDigis_){ delete EMDigiWorker_;}
272  else {delete EMWorker_;}
273  if(MergeHcalDigis_) {
275  else { delete HcalDigiWorker_; }}
276  else {delete HcalWorker_;}
277  if(MuonWorker_) delete MuonWorker_;
278  if(DoFastSim_){
279  delete GeneralTrackWorker_;
280  }else{
282  delete SiStripRawWorker_;
283  else
284  delete SiStripWorker_;
285  delete SiPixelWorker_;
286  }
287  }
288 
290  // fill in maps of hits
291 
292  LogDebug("DataMixingModule")<<"===============> adding MC signals for "<<e.id();
293 
294  // Ecal
295  if(MergeEMDigis_) { EMDigiWorker_->addEMSignals(e, ES); }
296  else{ EMWorker_->addEMSignals(e);}
297 
298  // Hcal
299  if(MergeHcalDigis_) {
302  }
303  else{
305  }
306  }
307  else {HcalWorker_->addHcalSignals(e);}
308 
309  // Muon
311 
312  if(DoFastSim_){
314  }else{
315  // SiStrips
318 
319  // SiPixels
321  }
322  } // end of addSignals
323 
324 
326 
327  void DataMixingModule::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr, unsigned int worker, const edm::EventSetup& ES) {
328 
329 
330  LogDebug("DataMixingModule") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
331 
332  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
333 
334  // Ecal
335  if(MergeEMDigis_) { EMDigiWorker_->addEMPileups(bcr, ep, eventNr, ES);}
336  else {EMWorker_->addEMPileups(bcr, ep, eventNr); }
337 
338  // Hcal
339  if(MergeHcalDigis_) {
340  if(MergeHcalDigisProd_) {
341  HcalDigiWorkerProd_->addHcalPileups(bcr, ep, eventNr, ES);
342  }
343  else{
344  HcalDigiWorker_->addHcalPileups(bcr, ep, eventNr, ES);}
345  }
346  else {HcalWorker_->addHcalPileups(bcr, ep, eventNr);}
347 
348  // Muon
349  MuonWorker_->addMuonPileups(bcr, ep, eventNr);
350 
351  if(DoFastSim_){
352  GeneralTrackWorker_->addGeneralTrackPileups(bcr, ep, eventNr);
353  }else{
354 
355  // SiStrips
357  else SiStripWorker_->addSiStripPileups(bcr, ep, eventNr);
358 
359  // SiPixels
360  SiPixelWorker_->addSiPixelPileups(bcr, ep, eventNr);
361  }
362  }
363 
365  {//
366 
367  for (int bunchCrossing=minBunch_;bunchCrossing<=maxBunch_;++bunchCrossing) {
368  setBcrOffset();
369  for (unsigned int isource=0;isource<maxNbSources_;++isource) {
370  setSourceOffset(isource);
371  if (doit_[isource]) {
372  merge(bunchCrossing, (pileup_[isource])[bunchCrossing-minBunch_],1, ES);
373  }
374  }
375  }
376  }
377 
378 
380 
381  // individual workers...
382 
383  // Ecal
384  if(MergeEMDigis_) {EMDigiWorker_->putEM(e,ES);}
385  else {EMWorker_->putEM(e);}
386 
387  // Hcal
388  if(MergeHcalDigis_) {
389  if(MergeHcalDigisProd_) {
391  }
392  else{
393  HcalDigiWorker_->putHcal(e,ES);
394  }
395  }
396  else {HcalWorker_->putHcal(e);}
397 
398  // Muon
399  MuonWorker_->putMuon(e);
400 
401  if(DoFastSim_){
403  }else{
404  // SiStrips
406  else SiStripWorker_->putSiStrip(e);
407 
408  // SiPixels
410  }
411  }
412 
414  }
415 
416  void DataMixingModule::setSourceOffset(const unsigned int is) {
417  }
418 
419 } //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 addGeneralTrackPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId)
void putEM(edm::Event &e)
virtual void setSourceOffset(const unsigned int is)
void addSiStripSignals(const edm::Event &e)
void addHcalSignals(const edm::Event &e)
std::string HBHERecHitCollectionDM_
std::string ZDCRecHitCollectionDM_
void addEMSignals(const edm::Event &e)
DataMixingGeneralTrackWorker * GeneralTrackWorker_
std::string CSCStripDigiCollectionDM_
std::vector< EventPrincipalVector > pileup_[4]
Definition: BMixingModule.h:81
void addEMPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId)
void addSiStripPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId)
EventID const & id() const
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string SiStripDigiCollectionDM_
void addHcalPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId, const edm::EventSetup &ES)
void merge(const int bcr, const EventPrincipalVector &vec, unsigned int worker, const edm::EventSetup &c)
virtual void createnewEDProduct()
std::string CSCWireDigiCollectionDM_
void putEM(edm::Event &e, const edm::EventSetup &ES)
DataMixingSiStripRawWorker * SiStripRawWorker_
DataMixingSiPixelWorker * SiPixelWorker_
void addEMPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId, const edm::EventSetup &ES)
std::string RPCDigiCollectionDM_
void putHcal(edm::Event &e, const edm::EventSetup &ES)
std::string ZDCDigiCollectionDM_
DataMixingHcalDigiWorker * HcalDigiWorker_
DataMixingEMWorker * EMWorker_
std::string GeneralTrackCollectionDM_
virtual void addSignals(const edm::Event &e, const edm::EventSetup &ES)
static const unsigned int maxNbSources_
Definition: BMixingModule.h:79
virtual void setBcrOffset()
virtual void doPileUp(edm::Event &e, const edm::EventSetup &ES)
std::string HORecHitCollectionDM_
void addSiPixelPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId)
DataMixingMuonWorker * MuonWorker_
virtual void getSubdetectorNames()
std::string EEDigiCollectionDM_
std::string HFRecHitCollectionDM_
std::string HBHEDigiCollectionDM_
std::string EBRecHitCollectionDM_
std::string CSCComparatorDigiCollectionDM_
void addSiStripPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId)
void putHcal(edm::Event &e, const edm::EventSetup &ES)
edm::EventID id() const
Definition: EventBase.h:56
DataMixingSiStripWorker * SiStripWorker_
std::string ESRecHitCollectionDM_
std::string EERecHitCollectionDM_
std::string ESDigiCollectionDM_
virtual void checkSignal(const edm::Event &e)
std::string DTDigiCollectionDM_
void addSiStripSignals(const edm::Event &e)
std::string EBDigiCollectionDM_
DataMixingHcalWorker * HcalWorker_
void addHcalPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId, const edm::EventSetup &ES)
std::string HODigiCollectionDM_
std::string PixelDigiCollectionDM_
DataMixingHcalDigiWorkerProd * HcalDigiWorkerProd_
void addMuonPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId)
void addHcalPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId)
void addEMSignals(const edm::Event &e, const edm::EventSetup &ES)
void addHcalSignals(const edm::Event &e, const edm::EventSetup &ES)
DataMixingEMDigiWorker * EMDigiWorker_
void addSiPixelSignals(const edm::Event &e)
virtual void addPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId, unsigned int worker, const edm::EventSetup &ES)
virtual void put(edm::Event &e, const edm::EventSetup &ES)