CMS 3D CMS Logo

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  // Output :The new manipulated TPGs
16  // make it smart - to name the collections
17  // correctly
18  char ecal_label[200];
19  char hcal_label[200];
20 
21  for (int i = preSamples; i > 0; --i) {
22  sprintf(ecal_label, "ECALBxminus%d", i);
23  sprintf(hcal_label, "HCALBxminus%d", i);
24  produces<EcalTrigPrimDigiCollection>(ecal_label);
25  produces<HcalTrigPrimDigiCollection>(hcal_label);
26  }
27 
28  produces<EcalTrigPrimDigiCollection>("ECALBx0");
29  produces<HcalTrigPrimDigiCollection>("HCALBx0");
30 
31  for (int i = 0; i < postSamples; ++i) {
32  sprintf(ecal_label, "ECALBxplus%d", i + 1);
33  sprintf(hcal_label, "HCALBxplus%d", i + 1);
34  produces<EcalTrigPrimDigiCollection>(ecal_label);
35  produces<HcalTrigPrimDigiCollection>(hcal_label);
36  }
37 }
38 
40  // do anything here that needs to be done at desctruction time
41  // (e.g. close files, deallocate resources etc.)
42 }
43 
44 //
45 // member functions
46 //
47 
48 // ------------ method called to produce the data ------------
50  const edm::EventSetup &iSetup) {
51  using namespace edm;
52  // Declare handles
55 
56  // Declare vector of collection to send for output !
57 
58  std::vector<EcalTrigPrimDigiCollection> ecalColl(preSamples + 1 +
59  postSamples);
60  std::vector<HcalTrigPrimDigiCollection> hcalColl(preSamples + 1 +
61  postSamples);
62 
63  unsigned nSamples = preSamples + postSamples + 1;
64 
65  if (iEvent.getByLabel(ecalTPG_, ecal))
66  if (ecal.isValid()) {
67  // loop through all ecal digis
69  ecal_it != ecal->end(); ecal_it++) {
70  short zside = ecal_it->id().zside();
71  unsigned short ietaAbs = ecal_it->id().ietaAbs();
72  short iphi = ecal_it->id().iphi();
73  unsigned short digiSize = ecal_it->size();
74  unsigned short nSOI = (unsigned short)(ecal_it->sampleOfInterest());
75  if (digiSize < nSamples || nSOI < preSamples ||
76  ((int)(digiSize - nSOI) < (int)(nSamples - preSamples))) {
77  unsigned short preLoopsZero = (unsigned short)(preSamples)-nSOI;
78 
79  // fill extra bx's at beginning with zeros
80  for (int sample = 0; sample < preLoopsZero; sample++) {
81  // fill first few with zeros
83  (int)zside, EcalTriggerTower, (int)ietaAbs, (int)iphi));
84  ecalDigi.setSize(1);
85  ecalDigi.setSample(0, EcalTriggerPrimitiveSample(0, false, 0));
86  ecalColl[sample].push_back(ecalDigi);
87  }
88 
89  // loop through existing data
90  for (int sample = preLoopsZero; sample < (preLoopsZero + digiSize);
91  sample++) {
92  // go through data
94  (int)zside, EcalTriggerTower, (int)ietaAbs, (int)iphi));
95  ecalDigi.setSize(1);
96  if (useEcalCosmicTiming && iphi >= 1 && iphi <= 36) {
97  if (nSOI < (preSamples + 1)) {
98  edm::LogWarning("TooLittleData")
99  << "ECAL data needs at least one presample "
100  << "more than the number requested "
101  << "to use ecal cosmic timing mod! "
102  << "reverting to useEcalCosmicTiming = false "
103  << "for rest of job.";
104  useEcalCosmicTiming = false;
105  } else {
106  ecalDigi.setSample(
107  0,
109  ecal_it->sample(nSOI + sample - preSamples - 1).raw()));
110  }
111  }
112  // else
113  if ((!useEcalCosmicTiming) || (iphi >= 37 && iphi <= 72)) {
114  ecalDigi.setSample(
116  ecal_it->sample(nSOI + sample - preSamples).raw()));
117  }
118  ecalColl[sample].push_back(ecalDigi);
119  }
120 
121  // fill extra bx's at end with zeros
122  for (unsigned int sample = (preLoopsZero + digiSize);
123  sample < nSamples; sample++) {
124  // fill zeros!
126  (int)zside, EcalTriggerTower, (int)ietaAbs, (int)iphi));
127  ecalDigi.setSize(1);
128  ecalDigi.setSample(0, EcalTriggerPrimitiveSample(0, false, 0));
129  ecalColl[sample].push_back(ecalDigi);
130  }
131  } else {
132  for (unsigned short sample = 0; sample < nSamples; sample++) {
133  // put each time sample into its own digi
134  short zside = ecal_it->id().zside();
135  unsigned short ietaAbs = ecal_it->id().ietaAbs();
136  short iphi = ecal_it->id().iphi();
138  (int)zside, EcalTriggerTower, (int)ietaAbs, (int)iphi));
139  ecalDigi.setSize(1);
140 
141  if (useEcalCosmicTiming && iphi >= 1 && iphi <= 36) {
142  if (nSOI < (preSamples + 1)) {
143  edm::LogWarning("TooLittleData")
144  << "ECAL data needs at least one presample "
145  << "more than the number requested "
146  << "to use ecal cosmic timing mod! "
147  << "reverting to useEcalCosmicTiming = false "
148  << "for rest of job.";
149  useEcalCosmicTiming = false;
150  } else {
151  ecalDigi.setSample(
153  ecal_it
154  ->sample(ecal_it->sampleOfInterest() + sample -
155  preSamples - 1)
156  .raw()));
157  }
158  }
159  // else
160  if ((!useEcalCosmicTiming) || (iphi >= 37 && iphi <= 72)) {
161  ecalDigi.setSample(0,
163  ecal_it
164  ->sample(ecal_it->sampleOfInterest() +
165  sample - preSamples)
166  .raw()));
167  }
168  // push back each digi into correct "time sample" of coll
169  ecalColl[sample].push_back(ecalDigi);
170  }
171  }
172  }
173  }
174 
175  if (iEvent.getByLabel(hcalTPG_, hcal))
176  if (hcal.isValid()) {
177  // loop through all hcal digis
178  for (HcalTrigPrimDigiCollection::const_iterator hcal_it = hcal->begin();
179  hcal_it != hcal->end(); hcal_it++) {
180  short ieta = hcal_it->id().ieta();
181  short iphi = hcal_it->id().iphi();
182  // loop through time samples for each digi
183  unsigned short digiSize = hcal_it->size();
184  // (size of each digi must be no less than nSamples)
185  unsigned short nSOI = (unsigned short)(hcal_it->presamples());
186  if (digiSize < nSamples || nSOI < preSamples ||
187  ((int)(digiSize - nSOI) < (int)(nSamples - preSamples))) {
188  unsigned short preLoopsZero = (unsigned short)(preSamples)-nSOI;
189  // fill extra bx's at beginning with zeros
190  for (int sample = 0; sample < preLoopsZero; sample++) {
191  // fill first few with zeros
192  HcalTriggerPrimitiveDigi hcalDigi(
193  HcalTrigTowerDetId((int)ieta, (int)iphi));
194  hcalDigi.setSize(1);
195  hcalDigi.setPresamples(0);
196  hcalDigi.setSample(0, HcalTriggerPrimitiveSample(0, false, 0, 0));
197  hcalColl[sample].push_back(hcalDigi);
198  }
199 
200  // loop through existing data
201  for (int sample = preLoopsZero; sample < (preLoopsZero + digiSize);
202  sample++) {
203  // go through data
204  HcalTriggerPrimitiveDigi hcalDigi(
205  HcalTrigTowerDetId((int)ieta, (int)iphi));
206  hcalDigi.setSize(1);
207  hcalDigi.setPresamples(0);
208 
209  if (useHcalCosmicTiming && iphi >= 1 && iphi <= 36) {
210  if (nSOI < (preSamples + 1)) {
211  edm::LogWarning("TooLittleData")
212  << "HCAL data needs at least one presample "
213  << "more than the number requested "
214  << "to use hcal cosmic timing mod! "
215  << "reverting to useHcalCosmicTiming = false "
216  << "for rest of job.";
217  useHcalCosmicTiming = false;
218  } else {
220  hcal_it
221  ->sample(hcal_it->presamples() +
222  sample - preSamples - 1)
223  .raw()));
224  }
225  }
226  // else
227  if ((!useHcalCosmicTiming) || (iphi >= 37 && iphi <= 72)) {
228 
230  hcal_it
231  ->sample(hcal_it->presamples() +
232  sample - preSamples)
233  .raw()));
234  }
235  hcalColl[sample].push_back(hcalDigi);
236  }
237 
238  // fill extra bx's at end with zeros
239  for (unsigned int sample = (preLoopsZero + digiSize);
240  sample < nSamples; sample++) {
241  // fill zeros!
242  HcalTriggerPrimitiveDigi hcalDigi(
243  HcalTrigTowerDetId((int)ieta, (int)iphi));
244  hcalDigi.setSize(1);
245  hcalDigi.setPresamples(0);
246  hcalDigi.setSample(0, HcalTriggerPrimitiveSample(0, false, 0, 0));
247  hcalColl[sample].push_back(hcalDigi);
248  }
249  } else {
250  for (unsigned short sample = 0; sample < nSamples; sample++) {
251  // put each (relevant) time sample into its own digi
252  HcalTriggerPrimitiveDigi hcalDigi(
253  HcalTrigTowerDetId((int)ieta, (int)iphi));
254  hcalDigi.setSize(1);
255  hcalDigi.setPresamples(0);
256 
257  if (useHcalCosmicTiming && iphi >= 1 && iphi <= 36) {
258  if (nSOI < (preSamples + 1)) {
259  edm::LogWarning("TooLittleData")
260  << "HCAL data needs at least one presample "
261  << "more than the number requested "
262  << "to use hcal cosmic timing mod! "
263  << "reverting to useHcalCosmicTiming = false "
264  << "for rest of job.";
265  useHcalCosmicTiming = false;
266  } else {
268  hcal_it
269  ->sample(hcal_it->presamples() +
270  sample - preSamples - 1)
271  .raw()));
272  }
273  }
274  // else
275  if ((!useHcalCosmicTiming) || (iphi >= 37 && iphi <= 72)) {
276  if (ieta > -29 && ieta < 29)
277  hcalDigi.setSample(
279  hcal_it
280  ->sample(hcal_it->presamples() + sample -
282  .raw()));
283  if (ieta <= -29 || ieta >= 29)
284  hcalDigi.setSample(
286  hcal_it
287  ->sample(hcal_it->presamples() + sample -
289  .raw()));
290  }
291  hcalColl[sample].push_back(hcalDigi);
292  }
293  }
294  }
295  }
296 
297  // Now put the events back to file
298 
299  for (int i = 0; i < preSamples; ++i) {
300  char ecal_label[200];
301  char hcal_label[200];
302 
303  sprintf(ecal_label, "ECALBxminus%d", preSamples - i);
304  sprintf(hcal_label, "HCALBxminus%d", preSamples - i);
305 
306  std::unique_ptr<EcalTrigPrimDigiCollection> ecalIn(
308  std::unique_ptr<HcalTrigPrimDigiCollection> hcalIn(
310  for (unsigned int j = 0; j < ecalColl[i].size(); ++j) {
311  ecalIn->push_back((ecalColl[i])[j]);
312  }
313  for (unsigned int j = 0; j < hcalColl[i].size(); ++j)
314  hcalIn->push_back((hcalColl[i])[j]);
315 
316  iEvent.put(std::move(ecalIn), ecal_label);
317  iEvent.put(std::move(hcalIn), hcal_label);
318  }
319 
320  std::unique_ptr<EcalTrigPrimDigiCollection> ecal0(
322  std::unique_ptr<HcalTrigPrimDigiCollection> hcal0(
324  for (unsigned int j = 0; j < ecalColl[preSamples].size(); ++j)
325  ecal0->push_back((ecalColl[preSamples])[j]);
326  for (unsigned int j = 0; j < hcalColl[preSamples].size(); ++j)
327  hcal0->push_back((hcalColl[preSamples])[j]);
328 
329  iEvent.put(std::move(ecal0), "ECALBx0");
330  iEvent.put(std::move(hcal0), "HCALBx0");
331 
332  for (int i = preSamples + 1; i < preSamples + postSamples + 1; ++i) {
333  char ecal_label[200];
334  char hcal_label[200];
335 
336  sprintf(ecal_label, "ECALBxplus%d", i - preSamples);
337  sprintf(hcal_label, "HCALBxplus%d", i - preSamples);
338 
339  std::unique_ptr<EcalTrigPrimDigiCollection> ecalIn2(
341  std::unique_ptr<HcalTrigPrimDigiCollection> hcalIn2(
343 
344  for (unsigned int j = 0; j < ecalColl[i].size(); ++j)
345  ecalIn2->push_back((ecalColl[i])[j]);
346 
347  for (unsigned int j = 0; j < hcalColl[i].size(); ++j)
348  hcalIn2->push_back((hcalColl[i])[j]);
349 
350  iEvent.put(std::move(ecalIn2), ecal_label);
351  iEvent.put(std::move(hcalIn2), hcal_label);
352  }
353 }
354 
355 // ------------ method called once each job just before starting event loop
356 // ------------
357 
358 // ------------ method called once each job just after ending the event loop
359 // ------------
void setSample(int i, const HcalTriggerPrimitiveSample &sam)
edm::InputTag ecalTPG_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
std::vector< T >::const_iterator const_iterator
L1RCTTPGProvider(const edm::ParameterSet &)
int zside(DetId const &)
int iEvent
Definition: GenABIO.cc:224
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
~L1RCTTPGProvider() override
bool isValid() const
Definition: HandleBase.h:74
constexpr size_t nSamples
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
edm::InputTag hcalTPG_
const_iterator end() const
void endJob() override
void produce(edm::Event &, const edm::EventSetup &) override
HLT enums.
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const