CMS 3D CMS Logo

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