CMS 3D CMS Logo

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