CMS 3D CMS Logo

L1RCTTPGProvider.cc
Go to the documentation of this file.
4 
6  : ecalTPG_(consumes(iConfig.getParameter<edm::InputTag>("ecalTPGs"))),
7  hcalTPG_(consumes(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  // Output :The new manipulated TPGs
15  // make it smart - to name the collections
16  // correctly
17  char ecal_label[200];
18  char hcal_label[200];
19 
20  for (int i = preSamples; i > 0; --i) {
21  sprintf(ecal_label, "ECALBxminus%d", i);
22  sprintf(hcal_label, "HCALBxminus%d", i);
23  produces<EcalTrigPrimDigiCollection>(ecal_label);
24  produces<HcalTrigPrimDigiCollection>(hcal_label);
25  }
26 
27  produces<EcalTrigPrimDigiCollection>("ECALBx0");
28  produces<HcalTrigPrimDigiCollection>("HCALBx0");
29 
30  for (int i = 0; i < postSamples; ++i) {
31  sprintf(ecal_label, "ECALBxplus%d", i + 1);
32  sprintf(hcal_label, "HCALBxplus%d", i + 1);
33  produces<EcalTrigPrimDigiCollection>(ecal_label);
34  produces<HcalTrigPrimDigiCollection>(hcal_label);
35  }
36 }
37 
39  // do anything here that needs to be done at desctruction time
40  // (e.g. close files, deallocate resources etc.)
41 }
42 
43 //
44 // member functions
45 //
46 
47 // ------------ method called to produce the data ------------
49  using namespace edm;
50  // Declare handles
53 
54  // Declare vector of collection to send for output !
55 
56  std::vector<EcalTrigPrimDigiCollection> ecalColl(preSamples + 1 + postSamples);
57  std::vector<HcalTrigPrimDigiCollection> hcalColl(preSamples + 1 + postSamples);
58 
59  unsigned nSamples = preSamples + postSamples + 1;
60 
61  if ((ecal = iEvent.getHandle(ecalTPG_)))
62  if (ecal.isValid()) {
63  // loop through all ecal digis
64  for (EcalTrigPrimDigiCollection::const_iterator ecal_it = ecal->begin(); ecal_it != ecal->end(); ecal_it++) {
65  short zside = ecal_it->id().zside();
66  unsigned short ietaAbs = ecal_it->id().ietaAbs();
67  short iphi = ecal_it->id().iphi();
68  unsigned short digiSize = ecal_it->size();
69  unsigned short nSOI = (unsigned short)(ecal_it->sampleOfInterest());
70  if (digiSize < nSamples || nSOI < preSamples || ((int)(digiSize - nSOI) < (int)(nSamples - preSamples))) {
71  unsigned short preLoopsZero = (unsigned short)(preSamples)-nSOI;
72 
73  // fill extra bx's at beginning with zeros
74  for (int sample = 0; sample < preLoopsZero; sample++) {
75  // fill first few with zeros
76  EcalTriggerPrimitiveDigi ecalDigi(
78  ecalDigi.setSize(1);
79  ecalDigi.setSample(0, EcalTriggerPrimitiveSample(0, false, 0));
80  ecalColl[sample].push_back(ecalDigi);
81  }
82 
83  // loop through existing data
84  for (int sample = preLoopsZero; sample < (preLoopsZero + digiSize); sample++) {
85  // go through data
86  EcalTriggerPrimitiveDigi ecalDigi(
88  ecalDigi.setSize(1);
89  if (useEcalCosmicTiming && iphi >= 1 && iphi <= 36) {
90  if (nSOI < (preSamples + 1)) {
91  edm::LogWarning("TooLittleData") << "ECAL data needs at least one presample "
92  << "more than the number requested "
93  << "to use ecal cosmic timing mod! "
94  << "reverting to useEcalCosmicTiming = false "
95  << "for rest of job.";
96  useEcalCosmicTiming = false;
97  } else {
98  ecalDigi.setSample(0,
99  EcalTriggerPrimitiveSample(ecal_it->sample(nSOI + sample - preSamples - 1).raw()));
100  }
101  }
102  // else
103  if ((!useEcalCosmicTiming) || (iphi >= 37 && iphi <= 72)) {
104  ecalDigi.setSample(0, EcalTriggerPrimitiveSample(ecal_it->sample(nSOI + sample - preSamples).raw()));
105  }
106  ecalColl[sample].push_back(ecalDigi);
107  }
108 
109  // fill extra bx's at end with zeros
110  for (unsigned int sample = (preLoopsZero + digiSize); sample < nSamples; sample++) {
111  // fill zeros!
112  EcalTriggerPrimitiveDigi ecalDigi(
114  ecalDigi.setSize(1);
115  ecalDigi.setSample(0, EcalTriggerPrimitiveSample(0, false, 0));
116  ecalColl[sample].push_back(ecalDigi);
117  }
118  } else {
119  for (unsigned short sample = 0; sample < nSamples; sample++) {
120  // put each time sample into its own digi
121  short zside = ecal_it->id().zside();
122  unsigned short ietaAbs = ecal_it->id().ietaAbs();
123  short iphi = ecal_it->id().iphi();
124  EcalTriggerPrimitiveDigi ecalDigi(
126  ecalDigi.setSize(1);
127 
128  if (useEcalCosmicTiming && iphi >= 1 && iphi <= 36) {
129  if (nSOI < (preSamples + 1)) {
130  edm::LogWarning("TooLittleData") << "ECAL data needs at least one presample "
131  << "more than the number requested "
132  << "to use ecal cosmic timing mod! "
133  << "reverting to useEcalCosmicTiming = false "
134  << "for rest of job.";
135  useEcalCosmicTiming = false;
136  } else {
137  ecalDigi.setSample(0,
139  ecal_it->sample(ecal_it->sampleOfInterest() + sample - preSamples - 1).raw()));
140  }
141  }
142  // else
143  if ((!useEcalCosmicTiming) || (iphi >= 37 && iphi <= 72)) {
144  ecalDigi.setSample(
145  0,
146  EcalTriggerPrimitiveSample(ecal_it->sample(ecal_it->sampleOfInterest() + sample - preSamples).raw()));
147  }
148  // push back each digi into correct "time sample" of coll
149  ecalColl[sample].push_back(ecalDigi);
150  }
151  }
152  }
153  }
154 
155  if ((hcal = iEvent.getHandle(hcalTPG_)))
156  if (hcal.isValid()) {
157  // loop through all hcal digis
158  for (HcalTrigPrimDigiCollection::const_iterator hcal_it = hcal->begin(); hcal_it != hcal->end(); hcal_it++) {
159  short ieta = hcal_it->id().ieta();
160  short iphi = hcal_it->id().iphi();
161  // loop through time samples for each digi
162  unsigned short digiSize = hcal_it->size();
163  // (size of each digi must be no less than nSamples)
164  unsigned short nSOI = (unsigned short)(hcal_it->presamples());
165  if (digiSize < nSamples || nSOI < preSamples || ((int)(digiSize - nSOI) < (int)(nSamples - preSamples))) {
166  unsigned short preLoopsZero = (unsigned short)(preSamples)-nSOI;
167  // fill extra bx's at beginning with zeros
168  for (int sample = 0; sample < preLoopsZero; sample++) {
169  // fill first few with zeros
171  hcalDigi.setSize(1);
172  hcalDigi.setPresamples(0);
173  hcalDigi.setSample(0, HcalTriggerPrimitiveSample(0, false, 0, 0));
174  hcalColl[sample].push_back(hcalDigi);
175  }
176 
177  // loop through existing data
178  for (int sample = preLoopsZero; sample < (preLoopsZero + digiSize); sample++) {
179  // go through data
181  hcalDigi.setSize(1);
182  hcalDigi.setPresamples(0);
183 
184  if (useHcalCosmicTiming && iphi >= 1 && iphi <= 36) {
185  if (nSOI < (preSamples + 1)) {
186  edm::LogWarning("TooLittleData") << "HCAL data needs at least one presample "
187  << "more than the number requested "
188  << "to use hcal cosmic timing mod! "
189  << "reverting to useHcalCosmicTiming = false "
190  << "for rest of job.";
191  useHcalCosmicTiming = false;
192  } else {
193  hcalDigi.setSample(
194  0,
195  HcalTriggerPrimitiveSample(hcal_it->sample(hcal_it->presamples() + sample - preSamples - 1).raw()));
196  }
197  }
198  // else
199  if ((!useHcalCosmicTiming) || (iphi >= 37 && iphi <= 72)) {
200  hcalDigi.setSample(
201  0, HcalTriggerPrimitiveSample(hcal_it->sample(hcal_it->presamples() + sample - preSamples).raw()));
202  }
203  hcalColl[sample].push_back(hcalDigi);
204  }
205 
206  // fill extra bx's at end with zeros
207  for (unsigned int sample = (preLoopsZero + digiSize); sample < nSamples; sample++) {
208  // fill zeros!
210  hcalDigi.setSize(1);
211  hcalDigi.setPresamples(0);
212  hcalDigi.setSample(0, HcalTriggerPrimitiveSample(0, false, 0, 0));
213  hcalColl[sample].push_back(hcalDigi);
214  }
215  } else {
216  for (unsigned short sample = 0; sample < nSamples; sample++) {
217  // put each (relevant) time sample into its own digi
219  hcalDigi.setSize(1);
220  hcalDigi.setPresamples(0);
221 
222  if (useHcalCosmicTiming && iphi >= 1 && iphi <= 36) {
223  if (nSOI < (preSamples + 1)) {
224  edm::LogWarning("TooLittleData") << "HCAL data needs at least one presample "
225  << "more than the number requested "
226  << "to use hcal cosmic timing mod! "
227  << "reverting to useHcalCosmicTiming = false "
228  << "for rest of job.";
229  useHcalCosmicTiming = false;
230  } else {
231  hcalDigi.setSample(
232  0,
233  HcalTriggerPrimitiveSample(hcal_it->sample(hcal_it->presamples() + sample - preSamples - 1).raw()));
234  }
235  }
236  // else
237  if ((!useHcalCosmicTiming) || (iphi >= 37 && iphi <= 72)) {
238  if (ieta > -29 && ieta < 29)
239  hcalDigi.setSample(0,
241  hcal_it->sample(hcal_it->presamples() + sample - preSamples + hbShift).raw()));
242  if (ieta <= -29 || ieta >= 29)
243  hcalDigi.setSample(0,
245  hcal_it->sample(hcal_it->presamples() + sample - preSamples + hfShift).raw()));
246  }
247  hcalColl[sample].push_back(hcalDigi);
248  }
249  }
250  }
251  }
252 
253  // Now put the events back to file
254 
255  for (int i = 0; i < preSamples; ++i) {
256  char ecal_label[200];
257  char hcal_label[200];
258 
259  sprintf(ecal_label, "ECALBxminus%d", preSamples - i);
260  sprintf(hcal_label, "HCALBxminus%d", preSamples - i);
261 
262  std::unique_ptr<EcalTrigPrimDigiCollection> ecalIn(new EcalTrigPrimDigiCollection);
263  std::unique_ptr<HcalTrigPrimDigiCollection> hcalIn(new HcalTrigPrimDigiCollection);
264  for (unsigned int j = 0; j < ecalColl[i].size(); ++j) {
265  ecalIn->push_back((ecalColl[i])[j]);
266  }
267  for (unsigned int j = 0; j < hcalColl[i].size(); ++j)
268  hcalIn->push_back((hcalColl[i])[j]);
269 
270  iEvent.put(std::move(ecalIn), ecal_label);
271  iEvent.put(std::move(hcalIn), hcal_label);
272  }
273 
274  std::unique_ptr<EcalTrigPrimDigiCollection> ecal0(new EcalTrigPrimDigiCollection);
275  std::unique_ptr<HcalTrigPrimDigiCollection> hcal0(new HcalTrigPrimDigiCollection);
276  for (unsigned int j = 0; j < ecalColl[preSamples].size(); ++j)
277  ecal0->push_back((ecalColl[preSamples])[j]);
278  for (unsigned int j = 0; j < hcalColl[preSamples].size(); ++j)
279  hcal0->push_back((hcalColl[preSamples])[j]);
280 
281  iEvent.put(std::move(ecal0), "ECALBx0");
282  iEvent.put(std::move(hcal0), "HCALBx0");
283 
284  for (int i = preSamples + 1; i < preSamples + postSamples + 1; ++i) {
285  char ecal_label[200];
286  char hcal_label[200];
287 
288  sprintf(ecal_label, "ECALBxplus%d", i - preSamples);
289  sprintf(hcal_label, "HCALBxplus%d", i - preSamples);
290 
291  std::unique_ptr<EcalTrigPrimDigiCollection> ecalIn2(new EcalTrigPrimDigiCollection);
292  std::unique_ptr<HcalTrigPrimDigiCollection> hcalIn2(new HcalTrigPrimDigiCollection);
293 
294  for (unsigned int j = 0; j < ecalColl[i].size(); ++j)
295  ecalIn2->push_back((ecalColl[i])[j]);
296 
297  for (unsigned int j = 0; j < hcalColl[i].size(); ++j)
298  hcalIn2->push_back((hcalColl[i])[j]);
299 
300  iEvent.put(std::move(ecalIn2), ecal_label);
301  iEvent.put(std::move(hcalIn2), hcal_label);
302  }
303 }
void setSample(int i, const HcalTriggerPrimitiveSample &sam)
std::vector< T >::const_iterator const_iterator
L1RCTTPGProvider(const edm::ParameterSet &)
int zside(DetId const &)
edm::EDGetTokenT< HcalTrigPrimDigiCollection > hcalTPG_
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ietaAbs(uint32_t id)
int iEvent
Definition: GenABIO.cc:224
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
std::atomic< bool > useHcalCosmicTiming
~L1RCTTPGProvider() override
edm::EDGetTokenT< EcalTrigPrimDigiCollection > ecalTPG_
HLT enums.
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511
std::atomic< bool > useEcalCosmicTiming