CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1RCTTPGProvider.cc
Go to the documentation of this file.
4 
6  ecalTPG_(iConfig.getParameter<edm::InputTag>("ecalTPGs")),
7  hcalTPG_(iConfig.getParameter<edm::InputTag>("hcalTPGs")),
8  useHcalCosmicTiming(iConfig.getParameter<bool>("useHCALCosmicTiming")),
9  useEcalCosmicTiming(iConfig.getParameter<bool>("useECALCosmicTiming")),
10  preSamples(iConfig.getParameter<int>("preSamples")),
11  postSamples(iConfig.getParameter<int>("postSamples")),
12  hfShift(iConfig.getParameter<int>("HFShift")),
13  hbShift(iConfig.getParameter<int>("HBShift"))
14 {
15 
16  //Output :The new manipulated TPGs
17  //make it smart - to name the collections
18  //correctly
19  char ecal_label[200];
20  char hcal_label[200];
21 
22 
23 
24  for(int i=preSamples;i>0;--i)
25  {
26  sprintf(ecal_label,"ECALBxminus%d",i);
27  sprintf(hcal_label,"HCALBxminus%d",i);
28  produces<EcalTrigPrimDigiCollection>(ecal_label);
29  produces<HcalTrigPrimDigiCollection>(hcal_label);
30  }
31 
32  produces<EcalTrigPrimDigiCollection>("ECALBx0");
33  produces<HcalTrigPrimDigiCollection>("HCALBx0");
34 
35  for(int i=0;i<postSamples;++i)
36  {
37  sprintf(ecal_label,"ECALBxplus%d",i+1);
38  sprintf(hcal_label,"HCALBxplus%d",i+1);
39  produces<EcalTrigPrimDigiCollection>(ecal_label);
40  produces<HcalTrigPrimDigiCollection>(hcal_label);
41  }
42 }
43 
45 {
46  // do anything here that needs to be done at desctruction time
47  // (e.g. close files, deallocate resources etc.)
48 }
49 
50 
51 //
52 // member functions
53 //
54 
55 // ------------ method called to produce the data ------------
56 void
58 {
59  using namespace edm;
60  //Declare handles
63 
64  //Declare vector of collection to send for output !
65 
66  std::vector<EcalTrigPrimDigiCollection> ecalColl(preSamples+1+postSamples);
67  std::vector<HcalTrigPrimDigiCollection> hcalColl(preSamples+1+postSamples);
68 
69  unsigned nSamples = preSamples + postSamples + 1;
70 
71 
72  if(iEvent.getByLabel(ecalTPG_,ecal))
73  if (ecal.isValid())
74  {
75  // loop through all ecal digis
76  for (EcalTrigPrimDigiCollection::const_iterator ecal_it = ecal->begin(); ecal_it != ecal->end(); ecal_it++)
77  {
78  short zside = ecal_it->id().zside();
79  unsigned short ietaAbs = ecal_it->id().ietaAbs();
80  short iphi = ecal_it->id().iphi();
81  unsigned short digiSize = ecal_it->size();
82  unsigned short nSOI = (unsigned short) ( ecal_it->sampleOfInterest() );
83  if (digiSize < nSamples || nSOI < preSamples || ((int)(digiSize - nSOI) < (int)(nSamples - preSamples)))
84  {
85  unsigned short preLoopsZero = (unsigned short) (preSamples)- nSOI;
86 
87  // fill extra bx's at beginning with zeros
88  for (int sample = 0; sample < preLoopsZero; sample++)
89  {
90  // fill first few with zeros
92  ecalDigi(EcalTrigTowerDetId((int) zside, EcalTriggerTower,
93  (int) ietaAbs, (int) iphi));
94  ecalDigi.setSize(1);
95  ecalDigi.setSample(0, EcalTriggerPrimitiveSample(0,false,0));
96  ecalColl[sample].push_back(ecalDigi);
97  }
98 
99  // loop through existing data
100  for (int sample = preLoopsZero;sample < (preLoopsZero + digiSize); sample++)
101  {
102  // go through data
104  ecalDigi(EcalTrigTowerDetId((int) zside, EcalTriggerTower,
105  (int) ietaAbs, (int) iphi));
106  ecalDigi.setSize(1);
107  if (useEcalCosmicTiming && iphi >= 1 && iphi <= 36)
108  {
109  if (nSOI < (preSamples + 1))
110  {
111  edm::LogWarning ("TooLittleData")
112  << "ECAL data needs at least one presample "
113  << "more than the number requested "
114  << "to use ecal cosmic timing mod! "
115  << "reverting to useEcalCosmicTiming = false "
116  << "for rest of job.";
117  useEcalCosmicTiming = false;
118  }
119  else
120  {
122  (ecal_it->sample(nSOI + sample -
123  preSamples -
124  1).raw()));
125  }
126  }
127  //else
128  if ((!useEcalCosmicTiming) || (iphi >=37 && iphi <= 72))
129  {
131  (ecal_it->sample(nSOI + sample -
132  preSamples).raw()));
133  }
134  ecalColl[sample].push_back(ecalDigi);
135  }
136 
137  // fill extra bx's at end with zeros
138  for (unsigned int sample = (preLoopsZero + digiSize);
139  sample < nSamples; sample++)
140  {
141  // fill zeros!
143  ecalDigi(EcalTrigTowerDetId((int) zside, EcalTriggerTower,
144  (int) ietaAbs, (int) iphi));
145  ecalDigi.setSize(1);
146  ecalDigi.setSample(0, EcalTriggerPrimitiveSample(0,false,0));
147  ecalColl[sample].push_back(ecalDigi);
148  }
149  }
150  else
151  {
152  for (unsigned short sample = 0; sample < nSamples; sample++)
153  {
154  // put each time sample into its own digi
155  short zside = ecal_it->id().zside();
156  unsigned short ietaAbs = ecal_it->id().ietaAbs();
157  short iphi = ecal_it->id().iphi();
159  ecalDigi(EcalTrigTowerDetId((int) zside, EcalTriggerTower,
160  (int) ietaAbs, (int) iphi));
161  ecalDigi.setSize(1);
162 
163  if (useEcalCosmicTiming && iphi >= 1 && iphi <=36)
164  {
165  if (nSOI < (preSamples + 1))
166  {
167  edm::LogWarning ("TooLittleData")
168  << "ECAL data needs at least one presample "
169  << "more than the number requested "
170  << "to use ecal cosmic timing mod! "
171  << "reverting to useEcalCosmicTiming = false "
172  << "for rest of job.";
173  useEcalCosmicTiming = false;
174  }
175  else
176  {
178  (ecal_it->sample
179  (ecal_it->sampleOfInterest() +
180  sample - preSamples -
181  1).raw()));
182  }
183  }
184  //else
185  if ((!useEcalCosmicTiming) || (iphi >=37 && iphi <= 72))
186  {
188  (ecal_it->sample
189  (ecal_it->sampleOfInterest() +
190  sample - preSamples).raw()));
191  }
192  // push back each digi into correct "time sample" of coll
193  ecalColl[sample].push_back(ecalDigi);
194  }
195  }
196  }
197  }
198 
199  if(iEvent.getByLabel(hcalTPG_,hcal))
200  if (hcal.isValid())
201  {
202  // loop through all hcal digis
203  for (HcalTrigPrimDigiCollection::const_iterator hcal_it = hcal->begin(); hcal_it != hcal->end(); hcal_it++)
204  {
205  short ieta = hcal_it->id().ieta();
206  short iphi = hcal_it->id().iphi();
207  // loop through time samples for each digi
208  unsigned short digiSize = hcal_it->size();
209  // (size of each digi must be no less than nSamples)
210  unsigned short nSOI = (unsigned short) (hcal_it->presamples());
211  if (digiSize < nSamples || nSOI < preSamples
212  || ((int)(digiSize - nSOI) < (int)(nSamples - preSamples)))
213  {
214  unsigned short preLoopsZero = (unsigned short) (preSamples)
215  - nSOI;
216  // fill extra bx's at beginning with zeros
217  for (int sample = 0; sample < preLoopsZero; sample++)
218  {
219  // fill first few with zeros
220  HcalTriggerPrimitiveDigi hcalDigi(HcalTrigTowerDetId((int) ieta, (int) iphi));
221  hcalDigi.setSize(1);
222  hcalDigi.setPresamples(0);
223  hcalDigi.setSample(0, HcalTriggerPrimitiveSample(0,false,0,0));
224  hcalColl[sample].push_back(hcalDigi);
225  }
226 
227  // loop through existing data
228  for (int sample = preLoopsZero;
229  sample < (preLoopsZero + digiSize); sample++)
230  {
231  // go through data
232  HcalTriggerPrimitiveDigi hcalDigi(HcalTrigTowerDetId((int) ieta, (int) iphi));
233  hcalDigi.setSize(1);
234  hcalDigi.setPresamples(0);
235 
236  if (useHcalCosmicTiming && iphi >= 1 && iphi <= 36)
237  {
238  if (nSOI < (preSamples + 1))
239  {
240  edm::LogWarning ("TooLittleData")
241  << "HCAL data needs at least one presample "
242  << "more than the number requested "
243  << "to use hcal cosmic timing mod! "
244  << "reverting to useHcalCosmicTiming = false "
245  << "for rest of job.";
246  useHcalCosmicTiming = false;
247  }
248  else
249  {
251  (hcal_it->sample(hcal_it->
252  presamples() +
253  sample -
254  preSamples -
255  1).raw()));
256  }
257  }
258  //else
259  if ((!useHcalCosmicTiming) || (iphi >= 37 && iphi <= 72))
260  {
261 
263  (hcal_it->sample(hcal_it->
264  presamples() +
265  sample -
266  preSamples).raw()));
267 
268  }
269  hcalColl[sample].push_back(hcalDigi);
270  }
271 
272  // fill extra bx's at end with zeros
273  for (unsigned int sample = (preLoopsZero + digiSize);
274  sample < nSamples; sample++)
275  {
276  // fill zeros!
278  hcalDigi(HcalTrigTowerDetId((int) ieta, (int) iphi));
279  hcalDigi.setSize(1);
280  hcalDigi.setPresamples(0);
281  hcalDigi.setSample(0, HcalTriggerPrimitiveSample(0,false,0,0));
282  hcalColl[sample].push_back(hcalDigi);
283  }
284  }
285  else
286  {
287  for (unsigned short sample = 0; sample < nSamples; sample++)
288  {
289  // put each (relevant) time sample into its own digi
290  HcalTriggerPrimitiveDigi hcalDigi(HcalTrigTowerDetId((int) ieta, (int) iphi));
291  hcalDigi.setSize(1);
292  hcalDigi.setPresamples(0);
293 
294  if (useHcalCosmicTiming && iphi >= 1 && iphi <= 36)
295  {
296  if (nSOI < (preSamples + 1))
297  {
298  edm::LogWarning ("TooLittleData")
299  << "HCAL data needs at least one presample "
300  << "more than the number requested "
301  << "to use hcal cosmic timing mod! "
302  << "reverting to useHcalCosmicTiming = false "
303  << "for rest of job.";
304  useHcalCosmicTiming = false;
305  }
306  else
307  {
309  (hcal_it->sample(hcal_it->
310  presamples() +
311  sample -
312  preSamples -
313  1).raw()));
314  }
315  }
316  //else
317  if ((!useHcalCosmicTiming) || (iphi >= 37 && iphi <= 72))
318  {
319  if(ieta>-29 && ieta<29)
321  (hcal_it->sample(hcal_it->
322  presamples() +
323  sample -
324  preSamples+hbShift).raw()));
325  if(ieta<=-29 || ieta>=29)
327  (hcal_it->sample(hcal_it->
328  presamples() +
329  sample -
330  preSamples+hfShift).raw()));
331  }
332  hcalColl[sample].push_back(hcalDigi);
333  }
334  }
335  }
336  }
337 
338 
339  //Now put the events back to file
340 
341  for(int i=0;i<preSamples;++i)
342  {
343  char ecal_label[200];
344  char hcal_label[200];
345 
346 
347  sprintf(ecal_label,"ECALBxminus%d",preSamples-i);
348  sprintf(hcal_label,"HCALBxminus%d",preSamples-i);
349 
350  std::auto_ptr<EcalTrigPrimDigiCollection> ecalIn(new EcalTrigPrimDigiCollection);
351  std::auto_ptr<HcalTrigPrimDigiCollection> hcalIn(new HcalTrigPrimDigiCollection);
352  for(unsigned int j=0;j<ecalColl[i].size();++j)
353  {
354  ecalIn->push_back((ecalColl[i])[j]);
355  }
356  for(unsigned int j=0;j<hcalColl[i].size();++j)
357  hcalIn->push_back((hcalColl[i])[j]);
358 
359  iEvent.put(ecalIn,ecal_label);
360  iEvent.put(hcalIn,hcal_label);
361 
362  }
363 
364 
365  std::auto_ptr<EcalTrigPrimDigiCollection> ecal0(new EcalTrigPrimDigiCollection);
366  std::auto_ptr<HcalTrigPrimDigiCollection> hcal0(new HcalTrigPrimDigiCollection);
367  for(unsigned int j=0;j<ecalColl[preSamples].size();++j)
368  ecal0->push_back((ecalColl[preSamples])[j]);
369  for(unsigned int j=0;j<hcalColl[preSamples].size();++j)
370  hcal0->push_back((hcalColl[preSamples])[j]);
371 
372  iEvent.put(ecal0,"ECALBx0");
373  iEvent.put(hcal0,"HCALBx0");
374 
375 
376  for(int i=preSamples+1;i<preSamples+postSamples+1;++i)
377  {
378  char ecal_label[200];
379  char hcal_label[200];
380 
381  sprintf(ecal_label,"ECALBxplus%d",i-preSamples);
382  sprintf(hcal_label,"HCALBxplus%d",i-preSamples);
383 
384  std::auto_ptr<EcalTrigPrimDigiCollection> ecalIn2(new EcalTrigPrimDigiCollection);
385  std::auto_ptr<HcalTrigPrimDigiCollection> hcalIn2(new HcalTrigPrimDigiCollection);
386 
387  for(unsigned int j=0;j<ecalColl[i].size();++j)
388  ecalIn2->push_back((ecalColl[i])[j]);
389 
390  for(unsigned int j=0;j<hcalColl[i].size();++j)
391  hcalIn2->push_back((hcalColl[i])[j]);
392 
393 
394  iEvent.put(ecalIn2,ecal_label);
395  iEvent.put(hcalIn2,hcal_label);
396  }
397 }
398 
399 // ------------ method called once each job just before starting event loop ------------
400 
401 
402 // ------------ method called once each job just after ending the event loop ------------
403 void
405 }
int i
Definition: DBlmapReader.cc:9
void setSample(int i, const HcalTriggerPrimitiveSample &sam)
edm::InputTag ecalTPG_
std::vector< T >::const_iterator const_iterator
L1RCTTPGProvider(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:243
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
int j
Definition: DBlmapReader.cc:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
edm::InputTag hcalTPG_
virtual void endJob()
virtual void produce(edm::Event &, const edm::EventSetup &)