CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
13 
14 using std::cout;
15 using std::endl;
16 const int L1RCTProducer::crateFED[18][5]=
17  {{613, 614, 603, 702, 718},
18  {611, 612, 602, 700, 718},
19  {627, 610, 601, 716, 722},
20  {625, 626, 609, 714, 722},
21  {623, 624, 608, 712, 722},
22  {621, 622, 607, 710, 720},
23  {619, 620, 606, 708, 720},
24  {617, 618, 605, 706, 720},
25  {615, 616, 604, 704, 718},
26  {631, 632, 648, 703, 719},
27  {629, 630, 647, 701, 719},
28  {645, 628, 646, 717, 723},
29  {643, 644, 654, 715, 723},
30  {641, 642, 653, 713, 723},
31  {639, 640, 652, 711, 721},
32  {637, 638, 651, 709, 721},
33  {635, 636, 650, 707, 721},
34  {633, 634, 649, 705, 719}};
35 
36 
37 
39  rctLookupTables(new L1RCTLookupTables),
40  rct(new L1RCT(rctLookupTables)),
41  useEcal(conf.getParameter<bool>("useEcal")),
42  useHcal(conf.getParameter<bool>("useHcal")),
43  ecalDigis(conf.getParameter<std::vector<edm::InputTag> >("ecalDigis")),
44  hcalDigis(conf.getParameter<std::vector<edm::InputTag> >("hcalDigis")),
45  bunchCrossings(conf.getParameter<std::vector<int> >("BunchCrossings")),
46  getFedsFromOmds(conf.getParameter<bool>("getFedsFromOmds")),
47  queryDelayInLS(conf.getParameter<unsigned int>("queryDelayInLS")),
48  queryIntervalInLS(conf.getParameter<unsigned int>("queryIntervalInLS")),
49  fedUpdatedMask(0)
50 {
51  produces<L1CaloEmCollection>();
52  produces<L1CaloRegionCollection>();
53 
54  for(unsigned int ihc=0;ihc<hcalDigis.size();ihc++){
55  consumes<edm::SortedCollection<HcalTriggerPrimitiveDigi,edm::StrictWeakOrdering<HcalTriggerPrimitiveDigi> > >(hcalDigis[ihc]);
56  }
57 
58  for(unsigned int iec=0;iec<ecalDigis.size();iec++){
59  consumes<edm::SortedCollection<EcalTriggerPrimitiveDigi,edm::StrictWeakOrdering<EcalTriggerPrimitiveDigi> > >(ecalDigis[iec]);
60  }
61 }
62 
64 {
65  if(rct != 0) delete rct;
66  if(rctLookupTables != 0) delete rctLookupTables;
67  if(fedUpdatedMask != 0) delete fedUpdatedMask;
68 }
69 
70 
71 void L1RCTProducer::beginRun(edm::Run const& run, const edm::EventSetup& eventSetup)
72 {
73  // std::cout << "getFedsFromOmds is " << getFedsFromOmds << std::endl;
74 
75  updateConfiguration(eventSetup);
76 
77  int runNumber = run.run();
78  updateFedVector(eventSetup,false,runNumber); // RUNINFO ONLY at beginning of run
79 
80 }
81 
82 
84 {
85  // check LS number every LS, if the checkOMDS flag is set AND it's the right LS, update the FED vector from OMDS
86  // can pass the flag as the bool?? but only check LS number if flag is true anyhow
87  if (getFedsFromOmds)
88  {
89  unsigned int nLumi = lumiSeg.luminosityBlock(); // doesn't even need the (unsigned int) cast because LuminosityBlockNumber_t is already an unsigned int
90  // LS count starts at 1, want to be able to delay 0 LS's intuitively
91  if ( ( (nLumi - 1) == queryDelayInLS)
92  || (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
93  {
94  int runNumber = lumiSeg.run();
95  // std::cout << "Lumi section for this FED vector update is " << nLumi << std::endl;
96  updateFedVector(context,true,runNumber); // OMDS
97  }
98  else if (queryIntervalInLS <= 0)
99  {
100  // don't do interval checking... cout message??
101  }
102  }
103 }
104 
105 
106 
108 {
109  // Refresh configuration information every event
110  // Hopefully, this does not take too much time
111  // There should be a call back function in future to
112  // handle changes in configuration
113  // parameters to configure RCT (thresholds, etc)
114  edm::ESHandle<L1RCTParameters> rctParameters;
115  eventSetup.get<L1RCTParametersRcd>().get(rctParameters);
116  const L1RCTParameters* r = rctParameters.product();
117 
118  //SCALES
119 
120  // energy scale to convert eGamma output
122  eventSetup.get<L1EmEtScaleRcd>().get(emScale);
123  const L1CaloEtScale* s = emScale.product();
124 
125  // get energy scale to convert input from ECAL
127  eventSetup.get<L1CaloEcalScaleRcd>().get(ecalScale);
128  const L1CaloEcalScale* e = ecalScale.product();
129 
130  // get energy scale to convert input from HCAL
132  eventSetup.get<L1CaloHcalScaleRcd>().get(hcalScale);
133  const L1CaloHcalScale* h = hcalScale.product();
134 
135  // set scales
138 
141 }
142 
143 
144 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
145 {
146  // list of RCT channels to mask
148  eventSetup.get<L1RCTChannelMaskRcd>().get(channelMask);
149  const L1RCTChannelMask* cEs = channelMask.product();
150 
151 
152  // list of Noisy RCT channels to mask
154  eventSetup.get<L1RCTNoisyChannelMaskRcd>().get(hotChannelMask);
155  const L1RCTNoisyChannelMask* cEsNoise = hotChannelMask.product();
157 
158 
159 
160  //Update the channel mask according to the FED VECTOR
161  //This is the beginning of run. We delete the old
162  //create the new and set it in the LUTs
163 
164  if(fedUpdatedMask!=0) delete fedUpdatedMask;
165 
167  // copy a constant object
168  for (int i = 0; i < 18; i++)
169  {
170  for (int j = 0; j < 2; j++)
171  {
172  for (int k = 0; k < 28; k++)
173  {
174  fedUpdatedMask->ecalMask[i][j][k] = cEs->ecalMask[i][j][k];
175  fedUpdatedMask->hcalMask[i][j][k] = cEs->hcalMask[i][j][k] ;
176  }
177  for (int k = 0; k < 4; k++)
178  {
179  fedUpdatedMask->hfMask[i][j][k] = cEs->hfMask[i][j][k];
180  }
181  }
182  }
183 
184 
185 // // adding fed mask into channel mask
186 
187  const std::vector<int> Feds = getFromOmds ? getFedVectorFromOmds(eventSetup) : getFedVectorFromRunInfo(eventSetup); // 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  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  {
200  int fedNum = *cf;
201  if(fedNum > 600 && fedNum <724)
202  caloFeds.push_back(fedNum);
203  }
204 
205  for(int cr = 0; cr < 18; ++cr)
206  {
207 
208  for(crateSection cs = c_min; cs <= c_max; cs = crateSection(cs +1))
209  {
210  bool fedFound = false;
211 
212 
213  //Try to find the FED
214  std::vector<int>::iterator fv = std::find(caloFeds.begin(),caloFeds.end(),crateFED[cr][cs]);
215  if(fv!=caloFeds.end())
216  fedFound = true;
217 
218  if(!fedFound) {
219  int eta_min=0;
220  int eta_max=0;
221  bool phi_even[2] = {false};//, phi_odd = false;
222  bool ecal=false;
223 
224  switch (cs) {
225  case ebEvenFed :
226  eta_min = minBarrel;
227  eta_max = maxBarrel;
228  phi_even[0] = true;
229  ecal = true;
230  break;
231 
232  case ebOddFed:
233  eta_min = minBarrel;
234  eta_max = maxBarrel;
235  phi_even[1] = true;
236  ecal = true;
237  break;
238 
239  case eeFed:
240  eta_min = minEndcap;
241  eta_max = maxEndcap;
242  phi_even[0] = true;
243  phi_even[1] = true;
244  ecal = true;
245  break;
246 
247  case hbheFed:
248  eta_min = minBarrel;
249  eta_max = maxEndcap;
250  phi_even[0] = true;
251  phi_even[1] = true;
252  ecal = false;
253  break;
254 
255  case hfFed:
256  eta_min = minHF;
257  eta_max = maxHF;
258 
259  phi_even[0] = true;
260  phi_even[1] = true;
261  ecal = false;
262  break;
263  default:
264  break;
265 
266  }
267  for(int ieta = eta_min; ieta <= eta_max; ++ieta)
268  {
269  if(ieta<=28) // barrel and endcap
270  for(int even = 0; even<=1 ; even++)
271  {
272  if(phi_even[even])
273  {
274  if(ecal)
275  fedUpdatedMask->ecalMask[cr][even][ieta-1] = true;
276  else
277  fedUpdatedMask->hcalMask[cr][even][ieta-1] = true;
278  }
279  }
280  else
281  for(int even = 0; even<=1 ; even++)
282  if(phi_even[even])
283  fedUpdatedMask->hfMask[cr][even][ieta-29] = true;
284 
285  }
286  }
287  }
288  }
289 
291 
292 }
293 
294 const std::vector<int> L1RCTProducer::getFedVectorFromRunInfo(const edm::EventSetup& eventSetup)
295 {
296  // std::cout << "Getting FED vector from standard RunInfo object" << std::endl;
297  // get FULL FED vector from RUNINFO
299  eventSetup.get<RunInfoRcd>().get(sum);
300  const RunInfo* summary=sum.product();
301  const std::vector<int> fedvector = summary->m_fed_in;
302 
303  return fedvector;
304 }
305 
306 
307 const std::vector<int> L1RCTProducer::getFedVectorFromOmds(const edm::EventSetup& eventSetup)
308 {
309 
310  // std::cout << "Getting FED vector from my specific ES RunInfo object" << std::endl;
311 
312  // get FULL FED vector from RunInfo object specifically created to have OMDS fed vector
314  eventSetup.get<RunInfoRcd>().get("OmdsFedVector",sum); // using label to get my specific instance of RunInfo
315  if (sum.isValid())
316  {
317  const RunInfo* summary=sum.product();
318  const std::vector<int> fedvector = summary->m_fed_in;
319 
320  return fedvector;
321  }
322  else
323  {
324  return getFedVectorFromRunInfo(eventSetup);
325  }
326 
327 }
328 
329 
330 
332 {
333 
334 
335  std::auto_ptr<L1CaloEmCollection> rctEmCands (new L1CaloEmCollection);
336  std::auto_ptr<L1CaloRegionCollection> rctRegions (new L1CaloRegionCollection);
337 
338 
339  if(!(ecalDigis.size()==hcalDigis.size()&&hcalDigis.size()==bunchCrossings.size()))
340  throw cms::Exception("BadInput")
341  << "From what I see the number of your your ECAL input digi collections.\n"
342  <<"is different from the size of your HCAL digi input collections\n"
343  <<"or the size of your BX factor collection"
344  <<"They must be the same to correspond to the same Bxs\n"
345  << "It does not matter if one of them is empty\n";
346 
347 
348 
349 
350  // loop through and process each bx
351  for (unsigned short sample = 0; sample < bunchCrossings.size(); sample++)
352  {
355 
358 
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  {
372  L1CaloEmCollection isolatedEGObjects = rct->getIsolatedEGObjects(j);
373  L1CaloEmCollection nonisolatedEGObjects = rct->getNonisolatedEGObjects(j);
374  for (int i = 0; i<4; i++)
375  {
376  isolatedEGObjects.at(i).setBx(bunchCrossings[sample]);
377  nonisolatedEGObjects.at(i).setBx(bunchCrossings[sample]);
378  rctEmCands->push_back(isolatedEGObjects.at(i));
379  rctEmCands->push_back(nonisolatedEGObjects.at(i));
380  }
381  }
382 
383 
384  for (int i = 0; i < 18; i++)
385  {
386  std::vector<L1CaloRegion> regions = rct->getRegions(i);
387  for (int j = 0; j < 22; j++)
388  {
389  regions.at(j).setBx(bunchCrossings[sample]);
390  rctRegions->push_back(regions.at(j));
391  }
392  }
393 
394  }
395 
396 
397  //putting stuff back into event
398  event.put(rctEmCands);
399  event.put(rctRegions);
400 
401 }
402 
403 // print contents of (FULL) FED vector
404 void L1RCTProducer::printFedVector(const std::vector<int>& fedVector)
405 {
406  std::cout << "Contents of given fedVector: ";
407  std::copy(fedVector.begin(), fedVector.end(), std::ostream_iterator<int>(std::cout, ", "));
408  std::cout << std::endl;
409 }
410 
411 // print contents of RCT channel mask fedUpdatedMask
413 {
414  if (fedUpdatedMask != 0)
415  {
417  }
418  else
419  {
420  std::cout << "Trying to print contents of fedUpdatedMask, but it doesn't exist!" << std::endl;
421  }
422 }
423 
424 // print contents of RCT channel mask fedUpdatedMask
426 {
427  if (fedUpdatedMask != 0)
428  {
429  // print contents of fedvector
430  std::cout << "Contents of fedUpdatedMask: ";
431 // std::copy(fedUpdatedMask.begin(), fedUpdatedMask.end(), std::ostream_iterator<int>(std::cout, ", "));
432  std::cout << "--> ECAL mask: " << std::endl;
433  for (int i = 0; i < 18; i++)
434  {
435  for (int j = 0; j < 2; j++)
436  {
437  for (int k = 0; k < 28; k++)
438  {
439  std::cout << fedUpdatedMask->ecalMask[i][j][k] << ", ";
440  }
441  }
442  }
443  std::cout << "--> HCAL mask: " << std::endl;
444  for (int i = 0; i < 18; i++)
445  {
446  for (int j = 0; j < 2; j++)
447  {
448  for (int k = 0; k < 28; k++)
449  {
450  std::cout << fedUpdatedMask->hcalMask[i][j][k] << ", ";
451  }
452  }
453  }
454  std::cout << "--> HF mask: " << std::endl;
455  for (int i = 0; i < 18; i++)
456  {
457  for (int j = 0; j < 2; j++)
458  {
459  for (int k = 0; k < 4; k++)
460  {
461  std::cout << fedUpdatedMask->hfMask[i][j][k] << ", ";
462  }
463  }
464  }
465 
466  std::cout << std::endl;
467  }
468  else
469  {
470  //print error message
471  std::cout << "Trying to print contents of fedUpdatedMask, but it doesn't exist!" << std::endl;
472  }
473 }
int i
Definition: DBlmapReader.cc:9
static const int minHF
std::vector< L1CaloEmCand > L1CaloEmCollection
auto_ptr< ClusterSequence > cs
RunNumber_t run() const
Definition: RunBase.h:42
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:363
void printFedVector(const std::vector< int > &)
virtual ~L1RCTProducer()
bool ecalMask[18][2][28]
void printUpdatedFedMaskVerbose()
L1RCTProducer(const edm::ParameterSet &ps)
static const int crateFED[18][5]
Definition: L1RCTProducer.h:95
unsigned int queryDelayInLS
Definition: L1RCTProducer.h:76
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &context) overridefinal
L1CaloEmCollection getNonisolatedEGObjects(unsigned crate)
Definition: L1RCT.cc:349
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
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
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
virtual void produce(edm::Event &e, const edm::EventSetup &c) overridefinal
std::vector< int > m_fed_in
Definition: RunInfo.h:26
L1CaloEmCollection getIsolatedEGObjects(unsigned crate)
Definition: L1RCT.cc:332
void printUpdatedFedMask()
int j
Definition: DBlmapReader.cc:9
RunNumber_t run() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void updateFedVector(const edm::EventSetup &, bool getFromOmds, int)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void setL1CaloEtScale(const L1CaloEtScale *etScale)
static const int minBarrel
Definition: L1RCTProducer.h:96
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
tuple conf
Definition: dbtoconf.py:185
int k[5][pyjets_maxn]
static const int minEndcap
Definition: L1RCTProducer.h:98
L1RCTChannelMask * fedUpdatedMask
Definition: L1RCTProducer.h:80
const T & get() const
Definition: EventSetup.h:55
static const int maxBarrel
Definition: L1RCTProducer.h:97
T const * product() const
Definition: ESHandle.h:62
void setEcalScale(const L1CaloEcalScale *ecalScale)
void processEvent()
Definition: L1RCT.cc:36
unsigned int queryIntervalInLS
Definition: L1RCTProducer.h:77
virtual void beginRun(edm::Run const &r, const edm::EventSetup &c) overridefinal
void setRCTParameters(const L1RCTParameters *rctParameters)
static const int maxEndcap
Definition: L1RCTProducer.h:99
void digiInput(const EcalTrigPrimDigiCollection &ecalCollection, const HcalTrigPrimDigiCollection &hcalCollection)
Definition: L1RCT.cc:116
void setNoisyChannelMask(const L1RCTNoisyChannelMask *channelMask)
bool hcalMask[18][2][28]
tuple cout
Definition: gather_cfg.py:121
std::vector< L1CaloRegion > L1CaloRegionCollection
Definition: L1RCT.h:20
bool isValid() const
Definition: ESHandle.h:37
bool hfMask[18][2][4]
void setChannelMask(const L1RCTChannelMask *channelMask)
Definition: Run.h:41