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