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