CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataMixingMuonWorker.cc
Go to the documentation of this file.
1 // File: DataMixingMuonWorker.cc
2 // Description: see DataMixingMuonWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
7 #include <map>
15 //
16 //
17 #include "DataMixingMuonWorker.h"
18 
19 
20 using namespace std;
21 
22 namespace edm
23 {
24 
25  // Virtual constructor
26 
27  DataMixingMuonWorker::DataMixingMuonWorker() { }
28 
29  // Constructor
30  DataMixingMuonWorker::DataMixingMuonWorker(const edm::ParameterSet& ps, edm::ConsumesCollector && iC) :
31  label_(ps.getParameter<std::string>("Label"))
32 
33  {
34 
35  // get the subdetector names
36  // this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
37 
38  // Declare the products to produce
39 
40  DTDigiTagSig_ = ps.getParameter<edm::InputTag>("DTDigiTagSig");
41  RPCDigiTagSig_ = ps.getParameter<edm::InputTag>("RPCDigiTagSig");
42 
43  CSCstripdigi_collectionSig_ = ps.getParameter<edm::InputTag>("CSCstripdigiCollectionSig");
44  CSCwiredigi_collectionSig_ = ps.getParameter<edm::InputTag>("CSCwiredigiCollectionSig");
45  CSCCompdigi_collectionSig_ = ps.getParameter<edm::InputTag>("CSCCompdigiCollectionSig");
46 
52 
53  DTPileInputTag_ = ps.getParameter<edm::InputTag>("DTPileInputTag");
54  RPCPileInputTag_ = ps.getParameter<edm::InputTag>("RPCPileInputTag");
55  CSCWirePileInputTag_ = ps.getParameter<edm::InputTag>("CSCWirePileInputTag");
56  CSCStripPileInputTag_ = ps.getParameter<edm::InputTag>("CSCStripPileInputTag");
57  CSCCompPileInputTag_ = ps.getParameter<edm::InputTag>("CSCCompPileInputTag");
58 
64 
65 
66  // outputs:
67 
68  DTDigiCollectionDM_ = ps.getParameter<std::string>("DTDigiCollectionDM");
69  RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
70  CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
71  CSCWireDigiCollectionDM_ = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
72  CSCComparatorDigiCollectionDM_ = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
73 
74 
75  }
76 
77 
78  // Virtual destructor needed.
80  }
81 
83  // fill in maps of hits
84 
85  LogDebug("DataMixingMuonWorker")<<"===============> adding MC signals for "<<e.id();
86 
87  // DT
88  //
89 
91  Handle<DTDigiCollection> pDTdigis;
92 
93  // Get the digis from the event
94  if( e.getByToken(DTDigiToken_, pDTdigis) ) {
95 
96  // LogInfo("DataMixingMuonWorker") << "total # DT Digis: " << DTdigis->size();
97 
98  // Loop over digis, copying them to our own local storage
99  const DTDigiCollection* DTdigis = pDTdigis.product();
101  for (DLayerIt = DTdigis->begin(); DLayerIt != DTdigis->end(); ++DLayerIt) {
102  // The layerId
103  const DTLayerId& layerId = (*DLayerIt).first;
104 
105  // Get the iterators over the digis associated with this LayerId
106  const DTDigiCollection::Range& range = (*DLayerIt).second;
107 
108  OurDTDigis_->put(range, layerId);
109  }
110  }
111  // RPC
112  //
113 
115 
116  // Get the digis from the event
117  Handle<RPCDigiCollection> pRPCdigis;
118 
119  if( e.getByToken(RPCDigiToken_, pRPCdigis) ) {
120 
121  // Loop over digis, copying them to our own local storage
122 
123  const RPCDigiCollection* RPCdigis = pRPCdigis.product();
125  for (RLayerIt = RPCdigis->begin(); RLayerIt != RPCdigis->end(); ++RLayerIt) {
126  // The layerId
127  const RPCDetId& layerId = (*RLayerIt).first;
128 
129  // Get the iterators over the digis associated with this LayerId
130  const RPCDigiCollection::Range& range = (*RLayerIt).second;
131 
132  OurRPCDigis_->put(range, layerId);
133 
134  }
135  }
136  // CSCStrip
137  //
138 
140 
141  // Get the digis from the event
142  Handle<CSCStripDigiCollection> pCSCStripdigis;
143 
144  if( e.getByToken(CSCStripDigiToken_, pCSCStripdigis) ) {
145 
146  //if(pCSCStripdigis.isValid() ) { std::cout << "Signal: have CSCStripDigis" << std::endl;}
147  //else { std::cout << "Signal: NO CSCStripDigis" << std::endl;}
148 
149 
150  // Loop over digis, copying them to our own local storage
151 
152  const CSCStripDigiCollection* CSCStripdigis = pCSCStripdigis.product();
154  for (CSLayerIt = CSCStripdigis->begin(); CSLayerIt != CSCStripdigis->end(); ++CSLayerIt) {
155  // The layerId
156  const CSCDetId& layerId = (*CSLayerIt).first;
157 
158  // Get the iterators over the digis associated with this LayerId
159  const CSCStripDigiCollection::Range& range = (*CSLayerIt).second;
160 
161  //std::cout << " Signal CSC layer " << (*CSLayerIt).first << std::endl;
162 
163  //for(CSCStripDigiCollection::const_iterator dtdigi=range.first; dtdigi!=range.second; dtdigi++){
164  // std::cout << "Digi " << (*dtdigi) << std::endl;
165  //}
166 
167 
168  OurCSCStripDigis_->put(range, layerId);
169  }
170  }
171  // CSCWire
172  //
173 
175 
176  // Get the digis from the event
177  Handle<CSCWireDigiCollection> pCSCWiredigis;
178 
179  if( e.getByToken(CSCWireDigiToken_, pCSCWiredigis) ) {
180 
181 
182  //if(pCSCWiredigis.isValid() ) { std::cout << "Signal: have CSCWireDigis" << std::endl;}
183  //else { std::cout << "Signal: NO CSCWireDigis" << std::endl;}
184 
185  // Loop over digis, copying them to our own local storage
186 
187  const CSCWireDigiCollection* CSCWiredigis = pCSCWiredigis.product();
189  for (CWLayerIt = CSCWiredigis->begin(); CWLayerIt != CSCWiredigis->end(); ++CWLayerIt) {
190  // The layerId
191  const CSCDetId& layerId = (*CWLayerIt).first;
192 
193  // Get the iterators over the digis associated with this LayerId
194  const CSCWireDigiCollection::Range& range = (*CWLayerIt).second;
195 
196  OurCSCWireDigis_->put(range, layerId);
197 
198  }
199  }
200 
201  // CSCComparators
202  //
203 
205 
206  // Get the digis from the event
207  Handle<CSCComparatorDigiCollection> pCSCComparatordigis;
208 
209  //std::cout << "CSCComp label: " << CSCDigiTagSig_.label() << " " << CSCCompdigi_collectionSig_.label() << std::endl;
210 
211  if( e.getByToken(CSCCompDigiToken_, pCSCComparatordigis) ) {
212 
213 
214  //if(pCSCComparatordigis.isValid() ) { std::cout << "Signal: have CSCComparatorDigis" << std::endl;}
215  //else { std::cout << "Signal: NO CSCComparatorDigis" << std::endl;}
216 
217  // Loop over digis, copying them to our own local storage
218 
219  const CSCComparatorDigiCollection* CSCComparatordigis = pCSCComparatordigis.product();
221  for (CWLayerIt = CSCComparatordigis->begin(); CWLayerIt != CSCComparatordigis->end(); ++CWLayerIt) {
222  // The layerId
223  const CSCDetId& layerId = (*CWLayerIt).first;
224 
225  // Get the iterators over the digis associated with this LayerId
226  const CSCComparatorDigiCollection::Range& range = (*CWLayerIt).second;
227 
228  OurCSCComparatorDigis_->put(range, layerId);
229 
230  }
231  }
232 
233 
234  } // end of addMuonSignals
235 
236  void DataMixingMuonWorker::addMuonPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr,
237  ModuleCallingContext const* mcc) {
238 
239  LogDebug("DataMixingMuonWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
240 
241  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
242 
243  // DT
244  //
245  // Get the digis from the event
246 
247  boost::shared_ptr<Wrapper<DTDigiCollection> const> DTDigisPTR =
248  getProductByTag<DTDigiCollection>(*ep, DTPileInputTag_, mcc);
249 
250  if(DTDigisPTR ) {
251 
252  const DTDigiCollection* DTDigis = const_cast< DTDigiCollection * >(DTDigisPTR->product());
253 
255  for (DTLayerIt = DTDigis->begin(); DTLayerIt != DTDigis->end(); ++DTLayerIt) {
256  // The layerId
257  const DTLayerId& layerId = (*DTLayerIt).first;
258 
259  // Get the iterators over the Digis associated with this LayerId
260  const DTDigiCollection::Range& range = (*DTLayerIt).second;
261 
262 
263  OurDTDigis_->put(range, layerId);
264 
265  }
266  }
267  // RPC
268  //
269 
270  // Get the digis from the event
271 
272 
273  boost::shared_ptr<Wrapper<RPCDigiCollection> const> RPCDigisPTR =
274  getProductByTag<RPCDigiCollection>(*ep, RPCPileInputTag_, mcc);
275 
276  if(RPCDigisPTR ) {
277 
278  const RPCDigiCollection* RPCDigis = const_cast< RPCDigiCollection * >(RPCDigisPTR->product());
279 
281  for (RPCLayerIt = RPCDigis->begin(); RPCLayerIt != RPCDigis->end(); ++RPCLayerIt) {
282  // The layerId
283  const RPCDetId& layerId = (*RPCLayerIt).first;
284 
285  // Get the iterators over the digis associated with this LayerId
286  const RPCDigiCollection::Range& range = (*RPCLayerIt).second;
287 
288  OurRPCDigis_->put(range, layerId);
289 
290  }
291  }
292 
293  // CSCStrip
294  //
295 
296  // Get the digis from the event
297 
298  boost::shared_ptr<Wrapper<CSCStripDigiCollection> const> CSCStripDigisPTR =
299  getProductByTag<CSCStripDigiCollection>(*ep, CSCStripPileInputTag_, mcc);
300 
301  if(CSCStripDigisPTR ) {
302 
303  const CSCStripDigiCollection* CSCStripDigis = const_cast< CSCStripDigiCollection * >(CSCStripDigisPTR->product());
304 
306  for (CSCStripLayerIt = CSCStripDigis->begin(); CSCStripLayerIt != CSCStripDigis->end(); ++CSCStripLayerIt) {
307  // The layerId
308  const CSCDetId& layerId = (*CSCStripLayerIt).first;
309 
310  // Get the iterators over the digis associated with this LayerId
311  const CSCStripDigiCollection::Range& range = (*CSCStripLayerIt).second;
312 
313  //std::cout << " Pileup CSC layer " << (*CSCStripLayerIt).first << std::endl;
314 
315  //for(CSCStripDigiCollection::const_iterator dtdigi=range.first; dtdigi!=range.second; dtdigi++){
316  // std::cout << "Digi " << (*dtdigi) << std::endl;
317  // }
318 
319  OurCSCStripDigis_->put(range, layerId);
320 
321  }
322  }
323 
324  // CSCWire
325  //
326 
327  // Get the digis from the event
328 
329  boost::shared_ptr<Wrapper<CSCWireDigiCollection> const> CSCWireDigisPTR =
330  getProductByTag<CSCWireDigiCollection>(*ep, CSCWirePileInputTag_, mcc);
331 
332  if(CSCWireDigisPTR ) {
333 
334  const CSCWireDigiCollection* CSCWireDigis = const_cast< CSCWireDigiCollection * >(CSCWireDigisPTR->product());
335 
337  for (CSCWireLayerIt = CSCWireDigis->begin(); CSCWireLayerIt != CSCWireDigis->end(); ++CSCWireLayerIt) {
338  // The layerId
339  const CSCDetId& layerId = (*CSCWireLayerIt).first;
340 
341  // Get the iterators over the digis associated with this LayerId
342  const CSCWireDigiCollection::Range& range = (*CSCWireLayerIt).second;
343 
344  OurCSCWireDigis_->put(range, layerId);
345 
346  }
347  }
348 
349  // CSCComparators
350  //
351 
352  // Get the digis from the event
353 
354  boost::shared_ptr<Wrapper<CSCComparatorDigiCollection> const> CSCComparatorDigisPTR =
355  getProductByTag<CSCComparatorDigiCollection>(*ep, CSCCompPileInputTag_, mcc);
356 
357  if(CSCComparatorDigisPTR ) {
358 
359  const CSCComparatorDigiCollection* CSCComparatorDigis = const_cast< CSCComparatorDigiCollection * >(CSCComparatorDigisPTR->product());
360 
362  for (CSCComparatorLayerIt = CSCComparatorDigis->begin(); CSCComparatorLayerIt != CSCComparatorDigis->end(); ++CSCComparatorLayerIt) {
363  // The layerId
364  const CSCDetId& layerId = (*CSCComparatorLayerIt).first;
365 
366  // Get the iterators over the digis associated with this LayerId
367  const CSCComparatorDigiCollection::Range& range = (*CSCComparatorLayerIt).second;
368 
369  OurCSCComparatorDigis_->put(range, layerId);
370 
371  }
372  }
373 
374 
375  }
376 
378 
379  // collections of digis to put in the event
380  std::auto_ptr< DTDigiCollection > DTDigiMerge( new DTDigiCollection );
381  std::auto_ptr< RPCDigiCollection > RPCDigiMerge( new RPCDigiCollection );
382  std::auto_ptr< CSCStripDigiCollection > CSCStripDigiMerge( new CSCStripDigiCollection );
383  std::auto_ptr< CSCWireDigiCollection > CSCWireDigiMerge( new CSCWireDigiCollection );
384  std::auto_ptr< CSCComparatorDigiCollection > CSCComparatorDigiMerge( new CSCComparatorDigiCollection );
385 
386  // Loop over DT digis, copying them from our own local storage
387 
389  for (DLayerIt = OurDTDigis_->begin(); DLayerIt != OurDTDigis_->end(); ++DLayerIt) {
390  // The layerId
391  const DTLayerId& layerId = (*DLayerIt).first;
392 
393  // Get the iterators over the digis associated with this LayerId
394  const DTDigiCollection::Range& range = (*DLayerIt).second;
395 
396 
397  DTDigiMerge->put(range, layerId);
398 
399  }
400 
401  // Loop over RPC digis, copying them from our own local storage
402 
404  for (RLayerIt = OurRPCDigis_->begin(); RLayerIt != OurRPCDigis_->end(); ++RLayerIt) {
405  // The layerId
406  const RPCDetId& layerId = (*RLayerIt).first;
407 
408  // Get the iterators over the digis associated with this LayerId
409  const RPCDigiCollection::Range& range = (*RLayerIt).second;
410 
411  RPCDigiMerge->put(range, layerId);
412 
413  }
414  // Loop over CSCStrip digis, copying them from our own local storage
415 
417  for (CSLayerIt = OurCSCStripDigis_->begin(); CSLayerIt != OurCSCStripDigis_->end(); ++CSLayerIt) {
418  // The layerId
419  const CSCDetId& layerId = (*CSLayerIt).first;
420 
421  // Get the iterators over the digis associated with this LayerId
422  const CSCStripDigiCollection::Range& range = (*CSLayerIt).second;
423 
424  std::vector<CSCStripDigi> NewDigiList;
425 
426  std::vector<int> StripList;
427  std::vector<CSCStripDigiCollection::const_iterator> StripPointer;
428 
429  for(CSCStripDigiCollection::const_iterator dtdigi=range.first; dtdigi!=range.second; ++dtdigi){
430  //std::cout << "Digi " << (*dtdigi).getStrip() << std::endl;
431  StripList.push_back( (*dtdigi).getStrip() );
432  StripPointer.push_back( dtdigi );
433  }
434 
435  int PrevStrip = -1;
436  std::vector<int> DuplicateList;
437 
438  std::vector<CSCStripDigiCollection::const_iterator>::const_iterator StripPtr = StripPointer.begin();
439 
440  for( std::vector<int>::const_iterator istrip = StripList.begin(); istrip !=StripList.end(); ++istrip) {
441 
442  const int CurrentStrip = *(istrip);
443 
444  if(CurrentStrip > PrevStrip) {
445  PrevStrip = CurrentStrip;
446 
447  int dupl_count;
448  dupl_count = std::count(StripList.begin(), StripList.end(), CurrentStrip);
449  if(dupl_count > 1) {
450  std::vector<int>::const_iterator duplicate = istrip;
451  ++duplicate;
452  std::vector<CSCStripDigiCollection::const_iterator>::const_iterator DuplPointer = StripPtr;
453  ++DuplPointer;
454  for( ; duplicate!=StripList.end(); ++duplicate) {
455  if( (*duplicate) == CurrentStrip ) {
456 
457  // std::cout << " Duplicate of current " << CurrentStrip << " found at " << (duplicate - StripList.begin()) << std::endl;
458 
459  DuplicateList.push_back(CurrentStrip);
460 
461  std::vector<int> pileup_adc = (**DuplPointer).getADCCounts();
462  std::vector<int> signal_adc = (**StripPtr).getADCCounts();
463 
464  std::vector<int>::const_iterator minplace;
465 
466  minplace = std::min_element(pileup_adc.begin(), pileup_adc.end());
467 
468  int minvalue = (*minplace);
469 
470  std::vector<int> new_adc;
471 
472  std::vector<int>::const_iterator newsig = signal_adc.begin();
473 
474  for(std::vector<int>::const_iterator ibin = pileup_adc.begin(); ibin!=pileup_adc.end(); ++ibin) {
475  new_adc.push_back((*newsig)+(*ibin)-minvalue);
476 
477  ++newsig;
478  }
479 
480  CSCStripDigi newDigi(CurrentStrip, new_adc);
481  NewDigiList.push_back(newDigi);
482  }
483  ++DuplPointer;
484  }
485  }
486  else { NewDigiList.push_back(**StripPtr); }
487  } // if strips monotonically increasing... Haven't hit duplicates yet
488  else { // reached end of signal digis, or there was no overlap
489  PrevStrip = 1000; // now into pileup signals, stop looking forward for duplicates
490 
491  // check if this digi was in the duplicate list
492  int check;
493  check = std::count(DuplicateList.begin(), DuplicateList.end(), CurrentStrip);
494  if(check == 0) NewDigiList.push_back(**StripPtr);
495  }
496  ++StripPtr;
497  }
498 
499  CSCStripDigiCollection::Range stripRange(NewDigiList.begin(), NewDigiList.end());
500 
501  CSCStripDigiMerge->put(stripRange, layerId);
502 
503  }
504  // Loop over CSCStrip digis, copying them from our own local storage
505 
507  for (CWLayerIt = OurCSCWireDigis_->begin(); CWLayerIt != OurCSCWireDigis_->end(); ++CWLayerIt) {
508  // The layerId
509  const CSCDetId& layerId = (*CWLayerIt).first;
510 
511  // Get the iterators over the digis associated with this LayerId
512  const CSCWireDigiCollection::Range& range = (*CWLayerIt).second;
513 
514  CSCWireDigiMerge->put(range, layerId);
515 
516  }
517 
518  // Loop over CSCComparator digis, copying them from our own local storage
519 
521  for (CCLayerIt = OurCSCComparatorDigis_->begin(); CCLayerIt != OurCSCComparatorDigis_->end(); ++CCLayerIt) {
522  // The layerId
523  const CSCDetId& layerId = (*CCLayerIt).first;
524 
525  // Get the iterators over the digis associated with this LayerId
526  const CSCComparatorDigiCollection::Range& range = (*CCLayerIt).second;
527 
528  CSCComparatorDigiMerge->put(range, layerId);
529 
530  }
531 
532 
533  // put the collection of recunstructed hits in the event
534  // LogDebug("DataMixingMuonWorker") << "total # DT Merged Digis: " << DTDigiMerge->size() ;
535  // LogDebug("DataMixingMuonWorker") << "total # RPC Merged Digis: " << RPCDigiMerge->size() ;
536  // LogDebug("DataMixingMuonWorker") << "total # CSCStrip Merged Digis: " << CSCStripDigiMerge->size() ;
537  // LogDebug("DataMixingMuonWorker") << "total # CSCWire Merged Digis: " << CSCWireDigiMerge->size() ;
538 
539  e.put( DTDigiMerge );
540  e.put( RPCDigiMerge );
541  e.put( CSCStripDigiMerge, CSCStripDigiCollectionDM_ );
542  e.put( CSCWireDigiMerge, CSCWireDigiCollectionDM_ );
543  e.put( CSCComparatorDigiMerge, CSCComparatorDigiCollectionDM_ );
544 
545  // clear local storage for this event
546  delete OurDTDigis_;
547  delete OurRPCDigis_;
548  delete OurCSCStripDigis_;
549  delete OurCSCWireDigis_;
550  delete OurCSCComparatorDigis_;
551 
552  }
553 
554 } //edm
#define LogDebug(id)
T getParameter(std::string const &) const
void addMuonSignals(const edm::Event &e)
void addMuonPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
EventID const & id() const
edm::InputTag CSCwiredigi_collectionSig_
MuonDigiCollection< CSCDetId, CSCStripDigi > CSCStripDigiCollection
edm::EDGetTokenT< RPCDigiCollection > RPCDigiPToken_
edm::EDGetTokenT< CSCStripDigiCollection > CSCStripDigiPToken_
CSCStripDigiCollection * OurCSCStripDigis_
DTDigiCollection * OurDTDigis_
MuonDigiCollection< CSCDetId, CSCComparatorDigi > CSCComparatorDigiCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
MuonDigiCollection< RPCDetId, RPCDigi > RPCDigiCollection
edm::EDGetTokenT< DTDigiCollection > DTDigiPToken_
edm::EDGetTokenT< RPCDigiCollection > RPCDigiToken_
edm::EDGetTokenT< DTDigiCollection > DTDigiToken_
RPCDigiCollection * OurRPCDigis_
CSCWireDigiCollection * OurCSCWireDigis_
MuonDigiCollection< CSCDetId, CSCWireDigi > CSCWireDigiCollection
static void check(Principal const &p, std::string const &id, edm::ModuleCallingContext const *mcc)
edm::EDGetTokenT< CSCStripDigiCollection > CSCStripDigiToken_
edm::EDGetTokenT< CSCComparatorDigiCollection > CSCCompDigiToken_
edm::EDGetTokenT< CSCWireDigiCollection > CSCWireDigiToken_
CSCComparatorDigiCollection * OurCSCComparatorDigis_
std::vector< CSCStripDigi >::const_iterator const_iterator
T const * product() const
Definition: Handle.h:81
edm::EventID id() const
Definition: EventBase.h:56
MuonDigiCollection< DTLayerId, DTDigi > DTDigiCollection
edm::InputTag CSCCompdigi_collectionSig_
std::pair< const_iterator, const_iterator > Range
edm::EDGetTokenT< CSCComparatorDigiCollection > CSCCompDigiPToken_
edm::EDGetTokenT< CSCWireDigiCollection > CSCWireDigiPToken_
edm::InputTag CSCstripdigi_collectionSig_