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