CMS 3D CMS Logo

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