CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataMixingEMWorker.cc
Go to the documentation of this file.
1 // File: DataMixingEMWorker.cc
2 // Description: see DataMixingEMWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
7 #include <map>
15 //
16 //
17 #include "DataMixingEMWorker.h"
18 
19 
20 using namespace std;
21 
22 namespace edm
23 {
24 
25  // Virtual constructor
26 
27  DataMixingEMWorker::DataMixingEMWorker() { sel_=0;}
28 
29  // Constructor
30  DataMixingEMWorker::DataMixingEMWorker(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  // create input selector
39  if (label_.size()>0){
41  }
42  else {
44  }
45 
46  // declare the products to produce, retrieve
47 
48  EBProducerSig_ = ps.getParameter<edm::InputTag>("EBProducerSig");
49  EEProducerSig_ = ps.getParameter<edm::InputTag>("EEProducerSig");
50  ESProducerSig_ = ps.getParameter<edm::InputTag>("ESProducerSig");
51 
52 
53  EBrechitCollectionSig_ = ps.getParameter<edm::InputTag>("EBrechitCollectionSig");
54  EErechitCollectionSig_ = ps.getParameter<edm::InputTag>("EErechitCollectionSig");
55  ESrechitCollectionSig_ = ps.getParameter<edm::InputTag>("ESrechitCollectionSig");
56 
57  EBPileRecHitInputTag_ = ps.getParameter<edm::InputTag>("EBPileRecHitInputTag");
58  EEPileRecHitInputTag_ = ps.getParameter<edm::InputTag>("EEPileRecHitInputTag");
59  ESPileRecHitInputTag_ = ps.getParameter<edm::InputTag>("ESPileRecHitInputTag");
60 
61 
62  EBRecHitCollectionDM_ = ps.getParameter<std::string>("EBRecHitCollectionDM");
63  EERecHitCollectionDM_ = ps.getParameter<std::string>("EERecHitCollectionDM");
64  ESRecHitCollectionDM_ = ps.getParameter<std::string>("ESRecHitCollectionDM");
65  // nMaxPrintout_ = ps.getUntrackedParameter<int>("nMaxPrintout",10);
66 
67  //EBalgo_ = new EcalRecHitSimpleAlgo();
68  //EEalgo_ = new EcalRecHitSimpleAlgo();
69 
70  // don't think I can "produce" in a sub-class...
71 
72  //produces< EBRecHitCollection >(EBRecHitCollectionDM_);
73  //produces< EERecHitCollection >(EERecHitCollectionDM_);
74 
75  }
76 
77 
78  // Virtual destructor needed.
80  delete sel_;
81  sel_=0;
82  }
83 
85  // fill in maps of hits
86 
87  LogInfo("DataMixingEMWorker")<<"===============> adding MC signals for "<<e.id();
88 
89  // EB first
90 
92 
93  const EBRecHitCollection* EBRecHits = 0;
94 
95  if(e.getByLabel(EBProducerSig_, pEBRecHits) ){
96  EBRecHits = pEBRecHits.product(); // get a ptr to the product
97  LogDebug("DataMixingEMWorker") << "total # EB rechits: " << EBRecHits->size();
98  }
99 
100 
101  if (EBRecHits)
102  {
103  // loop over rechits, storing them in a map so we can add pileup later
104  for(EBRecHitCollection::const_iterator it = EBRecHits->begin();
105  it != EBRecHits->end(); ++it) {
106 
107  EBRecHitStorage_.insert(EBRecHitMap::value_type( ( it->id() ), *it ));
108 
109  LogDebug("DataMixingEMWorker") << "processed EBRecHit with rawId: "
110  << it->id().rawId() << "\n"
111  << " rechit energy: " << it->energy();
112 
113  }
114  }
115 
116  // EE next
117 
118  Handle< EERecHitCollection > pEERecHits;
119 
120  const EERecHitCollection* EERecHits = 0;
121 
122 
123  if(e.getByLabel(EEProducerSig_, pEERecHits) ){
124  EERecHits = pEERecHits.product(); // get a ptr to the product
125  LogDebug("DataMixingEMWorker") << "total # EE rechits: " << EERecHits->size();
126  }
127 
128 
129  if (EERecHits)
130  {
131  // loop over rechits, storing them in a map so we can add pileup later
132  for(EERecHitCollection::const_iterator it = EERecHits->begin();
133  it != EERecHits->end(); ++it) {
134 
135  EERecHitStorage_.insert(EERecHitMap::value_type( ( it->id() ), *it ));
136 #ifdef DEBUG
137  LogDebug("DataMixingEMWorker") << "processed EERecHit with rawId: "
138  << it->id().rawId() << "\n"
139  << " rechit energy: " << it->energy();
140 #endif
141 
142  }
143  }
144  // ES next
145 
146  Handle< ESRecHitCollection > pESRecHits;
147 
148  const ESRecHitCollection* ESRecHits = 0;
149 
150 
151  if(e.getByLabel( ESProducerSig_, pESRecHits) ){
152  ESRecHits = pESRecHits.product(); // get a ptr to the product
153 #ifdef DEBUG
154  LogDebug("DataMixingEMWorker") << "total # ES rechits: " << ESRecHits->size();
155 #endif
156  }
157 
158 
159  if (ESRecHits)
160  {
161  // loop over rechits, storing them in a map so we can add pileup later
162  for(ESRecHitCollection::const_iterator it = ESRecHits->begin();
163  it != ESRecHits->end(); ++it) {
164 
165  ESRecHitStorage_.insert(ESRecHitMap::value_type( ( it->id() ), *it ));
166 
167 #ifdef DEBUG
168  LogDebug("DataMixingEMWorker") << "processed ESRecHit with rawId: "
169  << it->id().rawId() << "\n"
170  << " rechit energy: " << it->energy();
171 #endif
172 
173  }
174  }
175 
176  } // end of addEMSignals
177 
178  void DataMixingEMWorker::addEMPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr) {
179 
180  LogInfo("DataMixingEMWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
181 
182  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
183 
184  // EB first
185 
186  boost::shared_ptr<Wrapper<EBRecHitCollection> const> EBRecHitsPTR =
187  getProductByTag<EBRecHitCollection>(*ep, EBPileRecHitInputTag_ );
188 
189  if(EBRecHitsPTR ) {
190 
191  const EBRecHitCollection* EBRecHits = const_cast< EBRecHitCollection * >(EBRecHitsPTR->product());
192 
193  LogDebug("DataMixingEMWorker") << "total # EB rechits: " << EBRecHits->size();
194 
195  // loop over digis, adding these to the existing maps
196  for(EBRecHitCollection::const_iterator it = EBRecHits->begin();
197  it != EBRecHits->end(); ++it) {
198 
199  EBRecHitStorage_.insert(EBRecHitMap::value_type( (it->id()), *it ));
200 
201 #ifdef DEBUG
202  LogDebug("DataMixingEMWorker") << "processed EBRecHit with rawId: "
203  << it->id().rawId() << "\n"
204  << " rechit energy: " << it->energy();
205 #endif
206  }
207  }
208 
209  // EE Next
210 
211  boost::shared_ptr<Wrapper<EERecHitCollection> const> EERecHitsPTR =
212  getProductByTag<EERecHitCollection>(*ep, EEPileRecHitInputTag_ );
213 
214  if(EERecHitsPTR ) {
215 
216  const EERecHitCollection* EERecHits = const_cast< EERecHitCollection * >(EERecHitsPTR->product());
217 
218  LogDebug("DataMixingEMWorker") << "total # EE rechits: " << EERecHits->size();
219 
220  // loop over digis, adding these to the existing maps
221  for(EERecHitCollection::const_iterator it = EERecHits->begin();
222  it != EERecHits->end(); ++it) {
223 
224  EERecHitStorage_.insert(EERecHitMap::value_type( (it->id()), *it ));
225 
226 #ifdef DEBUG
227  LogDebug("DataMixingEMWorker") << "processed EERecHit with rawId: "
228  << it->id().rawId() << "\n"
229  << " rechit energy: " << it->energy();
230 #endif
231  }
232  }
233 
234  // ES Next
235 
236  boost::shared_ptr<Wrapper<ESRecHitCollection> const> ESRecHitsPTR =
237  getProductByTag<ESRecHitCollection>(*ep, ESPileRecHitInputTag_ );
238 
239  if(ESRecHitsPTR ) {
240 
241  const ESRecHitCollection* ESRecHits = const_cast< ESRecHitCollection * >(ESRecHitsPTR->product());
242 
243  LogDebug("DataMixingEMWorker") << "total # ES rechits: " << ESRecHits->size();
244 
245  // loop over digis, adding these to the existing maps
246  for(ESRecHitCollection::const_iterator it = ESRecHits->begin();
247  it != ESRecHits->end(); ++it) {
248 
249  ESRecHitStorage_.insert(ESRecHitMap::value_type( (it->id()), *it ));
250 
251 #ifdef DEBUG
252  LogDebug("DataMixingEMWorker") << "processed ESRecHit with rawId: "
253  << it->id().rawId() << "\n"
254  << " rechit energy: " << it->energy();
255 #endif
256  }
257  }
258 
259 
260  }
261 
263 
264  // collection of rechits to put in the event
265  std::auto_ptr< EBRecHitCollection > EBrechits( new EBRecHitCollection );
266  std::auto_ptr< EERecHitCollection > EErechits( new EERecHitCollection );
267  std::auto_ptr< ESRecHitCollection > ESrechits( new ESRecHitCollection );
268 
269  // loop over the maps we have, re-making individual hits or digis if necessary.
270  DetId formerID = 0;
271  DetId currentID;
272  float ESum = 0.;
273  float EBTime = 0.;
274 
275  // EB first...
276 
277  EBRecHitMap::const_iterator iEBchk;
278 
279  for(EBRecHitMap::const_iterator iEB = EBRecHitStorage_.begin();
280  iEB != EBRecHitStorage_.end(); ++iEB) {
281 
282  currentID = iEB->first;
283 
284  if (currentID == formerID) { // we have to add these rechits together
285 
286  ESum+=(iEB->second).energy();
287  }
288  else {
289  if(formerID>0) {
290  // cutoff for ESum?
291  EcalRecHit aHit(formerID, ESum, EBTime);
292  EBrechits->push_back( aHit );
293  }
294  //save pointers for next iteration
295  formerID = currentID;
296  ESum = (iEB->second).energy();
297  EBTime = (iEB->second).time(); // take time of first hit in sequence - is this ok?
298  }
299 
300  iEBchk = iEB;
301  if((++iEBchk) == EBRecHitStorage_.end()) { //make sure not to lose the last one
302  EcalRecHit aHit(formerID, ESum, EBTime);
303  EBrechits->push_back( aHit );
304  }
305  }
306 
307  // EE next...
308 
309  // loop over the maps we have, re-making individual hits or digis if necessary.
310  formerID = 0;
311  ESum = 0.;
312  float EETime = 0.;
313 
314  EERecHitMap::const_iterator iEEchk;
315 
316  for(EERecHitMap::const_iterator iEE = EERecHitStorage_.begin();
317  iEE != EERecHitStorage_.end(); ++iEE) {
318 
319  currentID = iEE->first;
320 
321  if (currentID == formerID) { // we have to add these rechits together
322 
323  ESum+=(iEE->second).energy();
324  }
325  else {
326  if(formerID>0) {
327  // cutoff for ESum?
328  EcalRecHit aHit(formerID, ESum, EETime);
329  EErechits->push_back( aHit );
330  }
331  //save pointers for next iteration
332  formerID = currentID;
333  ESum = (iEE->second).energy();
334  EETime = (iEE->second).time(); // take time of first hit in sequence - is this ok?
335  }
336 
337  iEEchk = iEE;
338  if((++iEEchk) == EERecHitStorage_.end()) { //make sure not to lose the last one
339  EcalRecHit aHit(formerID, ESum, EETime);
340  EErechits->push_back( aHit );
341  }
342  }
343 
344  // ES next...
345 
346  // loop over the maps we have, re-making individual hits or digis if necessary.
347  formerID = 0;
348  ESum = 0.;
349  float ESTime = 0.;
350 
351  ESRecHitMap::const_iterator iESchk;
352 
353  for(ESRecHitMap::const_iterator iES = ESRecHitStorage_.begin();
354  iES != ESRecHitStorage_.end(); ++iES) {
355 
356  currentID = iES->first;
357 
358  if (currentID == formerID) { // we have to add these rechits together
359 
360  ESum+=(iES->second).energy();
361  }
362  else {
363  if(formerID>0) {
364  // cutoff for ESum?
365  EcalRecHit aHit(formerID, ESum, ESTime);
366  ESrechits->push_back( aHit );
367  }
368  //save pointers for next iteration
369  formerID = currentID;
370  ESum = (iES->second).energy();
371  ESTime = (iES->second).time(); // take time of first hit in sequence - is this ok?
372  }
373 
374  iESchk = iES;
375  if((++iESchk) == ESRecHitStorage_.end()) { //make sure not to lose the last one
376  EcalRecHit aHit(formerID, ESum, ESTime);
377  ESrechits->push_back( aHit );
378  }
379  }
380 
381  // done merging
382 
383  // put the collection of reconstructed hits in the event
384  LogInfo("DataMixingEMWorker") << "total # EB Merged rechits: " << EBrechits->size() ;
385  LogInfo("DataMixingEMWorker") << "total # EE Merged rechits: " << EErechits->size() ;
386  LogInfo("DataMixingEMWorker") << "total # ES Merged rechits: " << ESrechits->size() ;
387 
388  e.put( EBrechits, EBRecHitCollectionDM_ );
389  e.put( EErechits, EERecHitCollectionDM_ );
390  e.put( ESrechits, ESRecHitCollectionDM_ );
391 
392  // clear local storage after this event
393 
394  EBRecHitStorage_.clear();
395  EERecHitStorage_.clear();
396  ESRecHitStorage_.clear();
397 
398  }
399 
400 } //edm
#define LogDebug(id)
T getParameter(std::string const &) const
void putEM(edm::Event &e)
void addEMSignals(const edm::Event &e)
void addEMPileups(const int bcr, edm::EventPrincipal *, unsigned int EventId)
EventID const & id() const
std::vector< T >::const_iterator const_iterator
edm::InputTag EBrechitCollectionSig_
edm::InputTag ESPileRecHitInputTag_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
Container::value_type value_type
edm::InputTag EErechitCollectionSig_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
const_iterator end() const
Definition: DetId.h:20
edm::InputTag ESrechitCollectionSig_
T const * product() const
Definition: Handle.h:74
edm::InputTag EBPileRecHitInputTag_
edm::InputTag EEPileRecHitInputTag_
edm::EventID id() const
Definition: EventBase.h:56
size_type size() const
const_iterator begin() const