CMS 3D CMS Logo

L1RCTProducer.cc
Go to the documentation of this file.
2 
3 // RunInfo stuff
8 
9 #include <vector>
10 using std::vector;
11 #include <iostream>
12 
13 using std::cout;
14 using std::endl;
15 namespace {
16  constexpr int crateFED[18][6] = {{613, 614, 603, 702, 718, 1118},
17  {611, 612, 602, 700, 718, 1118},
18  {627, 610, 601, 716, 722, 1122},
19  {625, 626, 609, 714, 722, 1122},
20  {623, 624, 608, 712, 722, 1122},
21  {621, 622, 607, 710, 720, 1120},
22  {619, 620, 606, 708, 720, 1120},
23  {617, 618, 605, 706, 720, 1120},
24  {615, 616, 604, 704, 718, 1118},
25  {631, 632, 648, 703, 719, 1118},
26  {629, 630, 647, 701, 719, 1118},
27  {645, 628, 646, 717, 723, 1122},
28  {643, 644, 654, 715, 723, 1122},
29  {641, 642, 653, 713, 723, 1122},
30  {639, 640, 652, 711, 721, 1120},
31  {637, 638, 651, 709, 721, 1120},
32  {635, 636, 650, 707, 721, 1120},
33  {633, 634, 649, 705, 719, 1118}};
34 }
36  : rctLookupTables(new L1RCTLookupTables),
37  rct(new L1RCT(rctLookupTables.get())),
38  useEcal(conf.getParameter<bool>("useEcal")),
39  useHcal(conf.getParameter<bool>("useHcal")),
40  ecalDigis(conf.getParameter<std::vector<edm::InputTag>>("ecalDigis")),
41  hcalDigis(conf.getParameter<std::vector<edm::InputTag>>("hcalDigis")),
42  bunchCrossings(conf.getParameter<std::vector<int>>("BunchCrossings")),
43  getFedsFromOmds(conf.getParameter<bool>("getFedsFromOmds")),
44  queryDelayInLS(conf.getParameter<unsigned int>("queryDelayInLS")),
45  queryIntervalInLS(conf.getParameter<unsigned int>("queryIntervalInLS")),
46  conditionsLabel(conf.getParameter<std::string>("conditionsLabel")),
47  fedUpdatedMask(nullptr),
48 
49  rctParamsToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", conditionsLabel))),
50  emScaleToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", conditionsLabel))),
51  ecalScaleToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", conditionsLabel))),
52  hcalScaleToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", conditionsLabel))),
53 
54  beginRunRunInfoToken_(esConsumes<edm::Transition::BeginRun>()),
55 
56  beginRunChannelMaskToken_(esConsumes<edm::Transition::BeginRun>()),
57  beginRunHotChannelMaskToken_(esConsumes<edm::Transition::BeginRun>()) {
58  produces<L1CaloEmCollection>();
59  produces<L1CaloRegionCollection>();
60 
61  if (getFedsFromOmds) {
62  beginLumiChannelMaskToken_ = esConsumes<edm::Transition::BeginLuminosityBlock>();
63  beginLumiHotChannelMaskToken_ = esConsumes<edm::Transition::BeginLuminosityBlock>();
64  beginLumiRunInfoToken_ = esConsumes<edm::Transition::BeginLuminosityBlock>();
65  omdsRunInfoToken_ = esConsumes<edm::Transition::BeginLuminosityBlock>(edm::ESInputTag("", "OmdsFedVector"));
66  }
67 
68  for (unsigned int ihc = 0; ihc < hcalDigis.size(); ihc++) {
69  consumes<edm::SortedCollection<HcalTriggerPrimitiveDigi, edm::StrictWeakOrdering<HcalTriggerPrimitiveDigi>>>(
70  hcalDigis[ihc]);
71  }
72 
73  for (unsigned int iec = 0; iec < ecalDigis.size(); iec++) {
74  consumes<edm::SortedCollection<EcalTriggerPrimitiveDigi, edm::StrictWeakOrdering<EcalTriggerPrimitiveDigi>>>(
75  ecalDigis[iec]);
76  }
77 }
78 
80  // std::cout << "getFedsFromOmds is " << getFedsFromOmds << std::endl;
81 
83 
84  // list of RCT channels to mask
85  L1RCTChannelMask const &channelMask = eventSetup.getData(beginRunChannelMaskToken_);
86 
87  // list of Noisy RCT channels to mask
88  L1RCTNoisyChannelMask const &hotChannelMask = eventSetup.getData(beginRunHotChannelMaskToken_);
89 
91 }
92 
94  // check LS number every LS, if the checkOMDS flag is set AND it's the right
95  // LS, update the FED vector from OMDS can pass the flag as the bool?? but
96  // only check LS number if flag is true anyhow
97  if (getFedsFromOmds) {
98  throw cms::Exception("L1RCTProducer Configuration")
99  << "L1RCTProducer is being run with the configuration parameter getFedsFromOmds set true. "
100  << "Underlying Framework changes have broken the implementation of that option. "
101  << "It was not fixed because we believe this option is no longer used or needed. "
102  << "If you actually need this option, please report this failure to the Framework. "
103  << "For more details see GitHub Issue 43697.";
104  /*
105  unsigned int nLumi = lumiSeg.luminosityBlock(); // doesn't even need the (unsigned int) cast
106  // because LuminosityBlockNumber_t is already
107  // an unsigned int
108  // LS count starts at 1, want to be able to delay 0 LS's intuitively
109  if (((nLumi - 1) == queryDelayInLS) ||
110  (queryIntervalInLS > 0 &&
111  nLumi % queryIntervalInLS == 0)) // to guard against problems if online DQM crashes; every 100
112  // LS is ~20-30 minutes, not too big a load, hopefully not too
113  // long between
114  {
115  // std::cout << "Lumi section for this FED vector update is " <<
116  // nLumi << std::endl;
117 
118  // list of RCT channels to mask
119  L1RCTChannelMask const &channelMask = context.getData(beginLumiChannelMaskToken_);
120 
121  // list of Noisy RCT channels to mask
122  L1RCTNoisyChannelMask const &hotChannelMask = context.getData(beginLumiHotChannelMaskToken_);
123 
124  updateFedVector(channelMask, hotChannelMask, getFedVectorFromOmds(context));
125  } else if (queryIntervalInLS <= 0) {
126  // don't do interval checking... cout message??
127  }
128  */
129  }
130 }
131 
133  // Refresh configuration information every event
134  // Hopefully, this does not take too much time
135  // There should be a call back function in future to
136  // handle changes in configuration
137  // parameters to configure RCT (thresholds, etc)
138  const L1RCTParameters *r = &eventSetup.getData(rctParamsToken_);
139 
140  // SCALES
141 
142  // energy scale to convert eGamma output
143  const L1CaloEtScale *s = &eventSetup.getData(emScaleToken_);
144 
145  // get energy scale to convert input from ECAL
146  const L1CaloEcalScale *e = &eventSetup.getData(ecalScaleToken_);
147 
148  // get energy scale to convert input from HCAL
149  const L1CaloHcalScale *h = &eventSetup.getData(hcalScaleToken_);
150 
151  // set scales
152  rctLookupTables->setEcalScale(e);
153  rctLookupTables->setHcalScale(h);
154 
155  rctLookupTables->setRCTParameters(r);
156  rctLookupTables->setL1CaloEtScale(s);
157 }
158 
160  const L1RCTNoisyChannelMask &hotChannelMask,
161  const std::vector<int> &Feds)
162 // http://cmslxr.fnal.gov/lxr/source/FWCore/Framework/interface/EventSetup.h
163 {
164  rctLookupTables->setNoisyChannelMask(&hotChannelMask);
165 
166  // Update the channel mask according to the FED VECTOR
167  // This is the beginning of run. We delete the old
168  // create the new and set it in the LUTs
169 
170  fedUpdatedMask = std::make_unique<L1RCTChannelMask>();
171  // copy a constant object
172  for (int i = 0; i < 18; i++) {
173  for (int j = 0; j < 2; j++) {
174  for (int k = 0; k < 28; k++) {
175  fedUpdatedMask->ecalMask[i][j][k] = channelMask.ecalMask[i][j][k];
176  fedUpdatedMask->hcalMask[i][j][k] = channelMask.hcalMask[i][j][k];
177  }
178  for (int k = 0; k < 4; k++) {
179  fedUpdatedMask->hfMask[i][j][k] = channelMask.hfMask[i][j][k];
180  }
181  }
182  }
183 
184  // so can create/initialize/assign const quantity in one line accounting for
185  // if statement wikipedia says this is exactly what it's for:
186  // http://en.wikipedia.org/wiki/%3F:#C.2B.2B
187 
188  // std::cout << "Contents of ";
189  // std::cout << (getFromOmds ? "OMDS RunInfo" : "standard RunInfo");
190  // std::cout << " FED vector" << std::endl;
191  // printFedVector(Feds);
192 
193  bool useUpgradedHF = false;
194 
195  std::vector<int> caloFeds; // pare down the feds to the interesting ones
196  // is this unneccesary?
197  // Mike B : This will decrease the find speed so better do it
198  for (std::vector<int>::const_iterator cf = Feds.begin(); cf != Feds.end(); ++cf) {
199  int fedNum = *cf;
200  if ((fedNum > 600 && fedNum < 724) || fedNum == 1118 || fedNum == 1120 || fedNum == 1122)
201  caloFeds.push_back(fedNum);
202 
203  if (fedNum == 1118 || fedNum == 1120 || fedNum == 1122)
204  useUpgradedHF = true;
205  }
206 
207  for (int cr = 0; cr < 18; ++cr) {
208  for (crateSection cs = c_min; cs <= c_max; cs = crateSection(cs + 1)) {
209  bool fedFound = false;
210 
211  // Try to find the FED
212  std::vector<int>::iterator fv = std::find(caloFeds.begin(), caloFeds.end(), crateFED[cr][cs]);
213  if (fv != caloFeds.end())
214  fedFound = true;
215 
216  if (!fedFound) {
217  int eta_min = 0;
218  int eta_max = 0;
219  bool phi_even[2] = {false}; //, phi_odd = false;
220  bool ecal = false;
221 
222  switch (cs) {
223  case ebEvenFed:
224  eta_min = minBarrel;
225  eta_max = maxBarrel;
226  phi_even[0] = true;
227  ecal = true;
228  break;
229 
230  case ebOddFed:
231  eta_min = minBarrel;
232  eta_max = maxBarrel;
233  phi_even[1] = true;
234  ecal = true;
235  break;
236 
237  case eeFed:
238  eta_min = minEndcap;
239  eta_max = maxEndcap;
240  phi_even[0] = true;
241  phi_even[1] = true;
242  ecal = true;
243  break;
244 
245  case hbheFed:
246  eta_min = minBarrel;
247  eta_max = maxEndcap;
248  phi_even[0] = true;
249  phi_even[1] = true;
250  ecal = false;
251  break;
252 
253  case hfFed:
254  if (useUpgradedHF)
255  break;
256 
257  eta_min = minHF;
258  eta_max = maxHF;
259 
260  phi_even[0] = true;
261  phi_even[1] = true;
262  ecal = false;
263  break;
264 
265  case hfFedUp:
266  if (!useUpgradedHF)
267  break;
268 
269  eta_min = minHF;
270  eta_max = maxHF;
271 
272  phi_even[0] = true;
273  phi_even[1] = true;
274  ecal = false;
275  break;
276 
277  default:
278  break;
279  }
280  for (int ieta = eta_min; ieta <= eta_max; ++ieta) {
281  if (ieta <= 28) // barrel and endcap
282  for (int even = 0; even <= 1; even++) {
283  if (phi_even[even]) {
284  if (ecal)
285  fedUpdatedMask->ecalMask[cr][even][ieta - 1] = true;
286  else
287  fedUpdatedMask->hcalMask[cr][even][ieta - 1] = true;
288  }
289  }
290  else
291  for (int even = 0; even <= 1; even++)
292  if (phi_even[even])
293  fedUpdatedMask->hfMask[cr][even][ieta - 29] = true;
294  }
295  }
296  }
297  }
298 
299  rctLookupTables->setChannelMask(fedUpdatedMask.get());
300 }
301 
303  const edm::EventSetup &eventSetup) const {
304  // std::cout << "Getting FED vector from standard RunInfo object" <<
305  // std::endl;
306  // get FULL FED vector from RUNINFO
307  return eventSetup.getData(token).m_fed_in;
308 }
309 
310 const std::vector<int> L1RCTProducer::getFedVectorFromOmds(const edm::EventSetup &eventSetup) const {
311  // std::cout << "Getting FED vector from my specific ES RunInfo object" <<
312  // std::endl;
313 
314  // get FULL FED vector from RunInfo object specifically created to have OMDS
315  // fed vector
317  if (sum.isValid()) {
318  return sum->m_fed_in;
319  } else {
321  }
322 }
323 
325  std::unique_ptr<L1CaloEmCollection> rctEmCands(new L1CaloEmCollection);
326  std::unique_ptr<L1CaloRegionCollection> rctRegions(new L1CaloRegionCollection);
327 
328  if (!(ecalDigis.size() == hcalDigis.size() && hcalDigis.size() == bunchCrossings.size()))
329  throw cms::Exception("BadInput") << "From what I see the number of your your ECAL input digi "
330  "collections.\n"
331  << "is different from the size of your HCAL digi input collections\n"
332  << "or the size of your BX factor collection"
333  << "They must be the same to correspond to the same Bxs\n"
334  << "It does not matter if one of them is empty\n";
335 
336  // loop through and process each bx
337  for (unsigned short sample = 0; sample < bunchCrossings.size(); sample++) {
340 
343 
344  if (useHcal && event.getByLabel(hcalDigis[sample], hcal))
345  hcalIn = *hcal;
346 
347  if (useEcal && event.getByLabel(ecalDigis[sample], ecal))
348  ecalIn = *ecal;
349 
350  rct->digiInput(ecalIn, hcalIn);
351  rct->processEvent();
352 
353  // Stuff to create
354  for (int j = 0; j < 18; j++) {
355  L1CaloEmCollection isolatedEGObjects = rct->getIsolatedEGObjects(j);
356  L1CaloEmCollection nonisolatedEGObjects = rct->getNonisolatedEGObjects(j);
357  for (int i = 0; i < 4; i++) {
358  isolatedEGObjects.at(i).setBx(bunchCrossings[sample]);
359  nonisolatedEGObjects.at(i).setBx(bunchCrossings[sample]);
360  rctEmCands->push_back(isolatedEGObjects.at(i));
361  rctEmCands->push_back(nonisolatedEGObjects.at(i));
362  }
363  }
364 
365  for (int i = 0; i < 18; i++) {
366  std::vector<L1CaloRegion> regions = rct->getRegions(i);
367  for (int j = 0; j < 22; j++) {
368  regions.at(j).setBx(bunchCrossings[sample]);
369  rctRegions->push_back(regions.at(j));
370  }
371  }
372  }
373 
374  // putting stuff back into event
375  event.put(std::move(rctEmCands));
376  event.put(std::move(rctRegions));
377 }
378 
379 // print contents of (FULL) FED vector
380 void L1RCTProducer::printFedVector(const std::vector<int> &fedVector) {
381  std::cout << "Contents of given fedVector: ";
382  std::copy(fedVector.begin(), fedVector.end(), std::ostream_iterator<int>(std::cout, ", "));
383  std::cout << std::endl;
384 }
385 
386 // print contents of RCT channel mask fedUpdatedMask
388  if (fedUpdatedMask != nullptr) {
389  fedUpdatedMask->print(std::cout);
390  } else {
391  std::cout << "Trying to print contents of fedUpdatedMask, but it doesn't exist!" << std::endl;
392  }
393 }
394 
395 // print contents of RCT channel mask fedUpdatedMask
397  if (fedUpdatedMask != nullptr) {
398  // print contents of fedvector
399  std::cout << "Contents of fedUpdatedMask: ";
400  // std::copy(fedUpdatedMask.begin(), fedUpdatedMask.end(),
401  // std::ostream_iterator<int>(std::cout, ", "));
402  std::cout << "--> ECAL mask: " << std::endl;
403  for (int i = 0; i < 18; i++) {
404  for (int j = 0; j < 2; j++) {
405  for (int k = 0; k < 28; k++) {
406  std::cout << fedUpdatedMask->ecalMask[i][j][k] << ", ";
407  }
408  }
409  }
410  std::cout << "--> HCAL mask: " << std::endl;
411  for (int i = 0; i < 18; i++) {
412  for (int j = 0; j < 2; j++) {
413  for (int k = 0; k < 28; k++) {
414  std::cout << fedUpdatedMask->hcalMask[i][j][k] << ", ";
415  }
416  }
417  }
418  std::cout << "--> HF mask: " << std::endl;
419  for (int i = 0; i < 18; i++) {
420  for (int j = 0; j < 2; j++) {
421  for (int k = 0; k < 4; k++) {
422  std::cout << fedUpdatedMask->hfMask[i][j][k] << ", ";
423  }
424  }
425  }
426 
427  std::cout << std::endl;
428  } else {
429  // print error message
430  std::cout << "Trying to print contents of fedUpdatedMask, but it doesn't exist!" << std::endl;
431  }
432 }
edm::ESGetToken< RunInfo, RunInfoRcd > beginLumiRunInfoToken_
Definition: L1RCTProducer.h:88
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::unique_ptr< L1RCT > rct
Definition: L1RCTProducer.h:66
std::vector< L1CaloEmCand > L1CaloEmCollection
const edm::ESGetToken< RunInfo, RunInfoRcd > beginRunRunInfoToken_
Definition: L1RCTProducer.h:87
const edm::ESGetToken< L1CaloEcalScale, L1CaloEcalScaleRcd > ecalScaleToken_
Definition: L1RCTProducer.h:83
void produce(edm::Event &e, const edm::EventSetup &c) final
void updateFedVector(const L1RCTChannelMask &, const L1RCTNoisyChannelMask &, const std::vector< int > &Feds)
const std::vector< int > getFedVectorFromRunInfo(const edm::ESGetToken< RunInfo, RunInfoRcd > &, const edm::EventSetup &) const
void updateConfiguration(const edm::EventSetup &)
void printFedVector(const std::vector< int > &)
edm::ESGetToken< L1RCTNoisyChannelMask, L1RCTNoisyChannelMaskRcd > beginLumiHotChannelMaskToken_
Definition: L1RCTProducer.h:97
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &context) final
bool ecalMask[18][2][28]
void printUpdatedFedMaskVerbose()
L1RCTProducer(const edm::ParameterSet &ps)
std::unique_ptr< L1RCTLookupTables > rctLookupTables
Definition: L1RCTProducer.h:65
static constexpr int minEndcap
std::unique_ptr< L1RCTChannelMask > fedUpdatedMask
Definition: L1RCTProducer.h:78
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const edm::ESGetToken< L1CaloHcalScale, L1CaloHcalScaleRcd > hcalScaleToken_
Definition: L1RCTProducer.h:84
const edm::ESGetToken< L1RCTChannelMask, L1RCTChannelMaskRcd > beginRunChannelMaskToken_
Definition: L1RCTProducer.h:92
bool getFedsFromOmds
Definition: L1RCTProducer.h:72
std::vector< edm::InputTag > hcalDigis
Definition: L1RCTProducer.h:70
std::vector< edm::InputTag > ecalDigis
Definition: L1RCTProducer.h:69
std::vector< int > bunchCrossings
Definition: L1RCTProducer.h:71
std::vector< int > m_fed_in
Definition: RunInfo.h:25
void printUpdatedFedMask()
Transition
Definition: Transition.h:12
static constexpr int maxBarrel
bool isValid() const
Definition: ESHandle.h:44
static constexpr int minBarrel
void beginRun(edm::Run const &r, const edm::EventSetup &c) final
const edm::ESGetToken< L1CaloEtScale, L1EmEtScaleRcd > emScaleToken_
Definition: L1RCTProducer.h:82
static constexpr int maxHF
const edm::ESGetToken< L1RCTNoisyChannelMask, L1RCTNoisyChannelMaskRcd > beginRunHotChannelMaskToken_
Definition: L1RCTProducer.h:93
const edm::ESGetToken< L1RCTParameters, L1RCTParametersRcd > rctParamsToken_
Definition: L1RCTProducer.h:81
const std::vector< int > getFedVectorFromOmds(const edm::EventSetup &) const
HLT enums.
edm::ESGetToken< RunInfo, RunInfoRcd > omdsRunInfoToken_
Definition: L1RCTProducer.h:89
bool hcalMask[18][2][28]
std::vector< L1CaloRegion > L1CaloRegionCollection
edm::ESGetToken< L1RCTChannelMask, L1RCTChannelMaskRcd > beginLumiChannelMaskToken_
Definition: L1RCTProducer.h:96
Definition: L1RCT.h:20
#define get
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static constexpr int minHF
bool hfMask[18][2][4]
static constexpr int maxEndcap
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
Definition: Run.h:45