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 }
55 
57 {
58  if(rct != 0) delete rct;
59  if(rctLookupTables != 0) delete rctLookupTables;
60  if(fedUpdatedMask != 0) delete fedUpdatedMask;
61 }
62 
63 
64 void L1RCTProducer::beginRun(edm::Run const& run, const edm::EventSetup& eventSetup)
65 {
66  // std::cout << "getFedsFromOmds is " << getFedsFromOmds << std::endl;
67 
68  updateConfiguration(eventSetup);
69 
70  int runNumber = run.run();
71  updateFedVector(eventSetup,false,runNumber); // RUNINFO ONLY at beginning of run
72 
73 }
74 
75 
77 {
78  // check LS number every LS, if the checkOMDS flag is set AND it's the right LS, update the FED vector from OMDS
79  // can pass the flag as the bool?? but only check LS number if flag is true anyhow
80  if (getFedsFromOmds)
81  {
82  unsigned int nLumi = lumiSeg.luminosityBlock(); // doesn't even need the (unsigned int) cast because LuminosityBlockNumber_t is already 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 && 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
86  {
87  int runNumber = lumiSeg.run();
88  // std::cout << "Lumi section for this FED vector update is " << nLumi << std::endl;
89  updateFedVector(context,true,runNumber); // OMDS
90  }
91  else if (queryIntervalInLS <= 0)
92  {
93  // don't do interval checking... cout message??
94  }
95  }
96 }
97 
98 
99 
101 {
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(rctParameters);
109  const L1RCTParameters* r = rctParameters.product();
110 
111  //SCALES
112 
113  // energy scale to convert eGamma output
115  eventSetup.get<L1EmEtScaleRcd>().get(emScale);
116  const L1CaloEtScale* s = emScale.product();
117 
118  // get energy scale to convert input from ECAL
120  eventSetup.get<L1CaloEcalScaleRcd>().get(ecalScale);
121  const L1CaloEcalScale* e = ecalScale.product();
122 
123  // get energy scale to convert input from HCAL
125  eventSetup.get<L1CaloHcalScaleRcd>().get(hcalScale);
126  const L1CaloHcalScale* h = hcalScale.product();
127 
128  // set scales
131 
134 }
135 
136 
137 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
138 {
139  // list of RCT channels to mask
141  eventSetup.get<L1RCTChannelMaskRcd>().get(channelMask);
142  const L1RCTChannelMask* cEs = channelMask.product();
143 
144 
145  // list of Noisy RCT channels to mask
147  eventSetup.get<L1RCTNoisyChannelMaskRcd>().get(hotChannelMask);
148  const L1RCTNoisyChannelMask* cEsNoise = hotChannelMask.product();
150 
151 
152 
153  //Update the channel mask according to the FED VECTOR
154  //This is the beginning of run. We delete the old
155  //create the new and set it in the LUTs
156 
157  if(fedUpdatedMask!=0) delete fedUpdatedMask;
158 
160  // copy a constant object
161  for (int i = 0; i < 18; i++)
162  {
163  for (int j = 0; j < 2; j++)
164  {
165  for (int k = 0; k < 28; k++)
166  {
167  fedUpdatedMask->ecalMask[i][j][k] = cEs->ecalMask[i][j][k];
168  fedUpdatedMask->hcalMask[i][j][k] = cEs->hcalMask[i][j][k] ;
169  }
170  for (int k = 0; k < 4; k++)
171  {
172  fedUpdatedMask->hfMask[i][j][k] = cEs->hfMask[i][j][k];
173  }
174  }
175  }
176 
177 
178 // // adding fed mask into channel mask
179 
180  const std::vector<int> Feds = getFromOmds ? getFedVectorFromOmds(eventSetup) : getFedVectorFromRunInfo(eventSetup); // so can create/initialize/assign const quantity in one line accounting for if statement
181  // wikipedia says this is exactly what it's for: http://en.wikipedia.org/wiki/%3F:#C.2B.2B
182 
183 // std::cout << "Contents of ";
184 // std::cout << (getFromOmds ? "OMDS RunInfo" : "standard RunInfo");
185 // std::cout << " FED vector" << std::endl;
186 // printFedVector(Feds);
187 
188  std::vector<int> caloFeds; // pare down the feds to the interesting ones
189  // is this unneccesary?
190  // Mike B : This will decrease the find speed so better do it
191  for(std::vector<int>::const_iterator cf = Feds.begin(); cf != Feds.end(); ++cf)
192  {
193  int fedNum = *cf;
194  if(fedNum > 600 && fedNum <724)
195  caloFeds.push_back(fedNum);
196  }
197 
198  for(int cr = 0; cr < 18; ++cr)
199  {
200 
201  for(crateSection cs = c_min; cs <= c_max; cs = crateSection(cs +1))
202  {
203  bool fedFound = false;
204 
205 
206  //Try to find the FED
207  std::vector<int>::iterator fv = std::find(caloFeds.begin(),caloFeds.end(),crateFED[cr][cs]);
208  if(fv!=caloFeds.end())
209  fedFound = true;
210 
211  if(!fedFound) {
212  int eta_min=0;
213  int eta_max=0;
214  bool phi_even[2] = {false};//, phi_odd = false;
215  bool ecal=false;
216 
217  switch (cs) {
218  case ebEvenFed :
219  eta_min = minBarrel;
220  eta_max = maxBarrel;
221  phi_even[0] = true;
222  ecal = true;
223  break;
224 
225  case ebOddFed:
226  eta_min = minBarrel;
227  eta_max = maxBarrel;
228  phi_even[1] = true;
229  ecal = true;
230  break;
231 
232  case eeFed:
233  eta_min = minEndcap;
234  eta_max = maxEndcap;
235  phi_even[0] = true;
236  phi_even[1] = true;
237  ecal = true;
238  break;
239 
240  case hbheFed:
241  eta_min = minBarrel;
242  eta_max = maxEndcap;
243  phi_even[0] = true;
244  phi_even[1] = true;
245  ecal = false;
246  break;
247 
248  case hfFed:
249  eta_min = minHF;
250  eta_max = maxHF;
251 
252  phi_even[0] = true;
253  phi_even[1] = true;
254  ecal = false;
255  break;
256  default:
257  break;
258 
259  }
260  for(int ieta = eta_min; ieta <= eta_max; ++ieta)
261  {
262  if(ieta<=28) // barrel and endcap
263  for(int even = 0; even<=1 ; even++)
264  {
265  if(phi_even[even])
266  {
267  if(ecal)
268  fedUpdatedMask->ecalMask[cr][even][ieta-1] = true;
269  else
270  fedUpdatedMask->hcalMask[cr][even][ieta-1] = true;
271  }
272  }
273  else
274  for(int even = 0; even<=1 ; even++)
275  if(phi_even[even])
276  fedUpdatedMask->hfMask[cr][even][ieta-29] = true;
277 
278  }
279  }
280  }
281  }
282 
284 
285 }
286 
287 const std::vector<int> L1RCTProducer::getFedVectorFromRunInfo(const edm::EventSetup& eventSetup)
288 {
289  // std::cout << "Getting FED vector from standard RunInfo object" << std::endl;
290  // get FULL FED vector from RUNINFO
292  eventSetup.get<RunInfoRcd>().get(sum);
293  const RunInfo* summary=sum.product();
294  const std::vector<int> fedvector = summary->m_fed_in;
295 
296  return fedvector;
297 }
298 
299 
300 const std::vector<int> L1RCTProducer::getFedVectorFromOmds(const edm::EventSetup& eventSetup)
301 {
302 
303  // std::cout << "Getting FED vector from my specific ES RunInfo object" << std::endl;
304 
305  // get FULL FED vector from RunInfo object specifically created to have OMDS fed vector
307  eventSetup.get<RunInfoRcd>().get("OmdsFedVector",sum); // using label to get my specific instance of RunInfo
308  if (sum.isValid())
309  {
310  const RunInfo* summary=sum.product();
311  const std::vector<int> fedvector = summary->m_fed_in;
312 
313  return fedvector;
314  }
315  else
316  {
317  return getFedVectorFromRunInfo(eventSetup);
318  }
319 
320 }
321 
322 
323 
325 {
326 
327 
328  std::auto_ptr<L1CaloEmCollection> rctEmCands (new L1CaloEmCollection);
329  std::auto_ptr<L1CaloRegionCollection> rctRegions (new L1CaloRegionCollection);
330 
331 
332  if(!(ecalDigis.size()==hcalDigis.size()&&hcalDigis.size()==bunchCrossings.size()))
333  throw cms::Exception("BadInput")
334  << "From what I see the number of your your ECAL input digi collections.\n"
335  <<"is different from the size of your HCAL digi input collections\n"
336  <<"or the size of your BX factor collection"
337  <<"They must be the same to correspond to the same Bxs\n"
338  << "It does not matter if one of them is empty\n";
339 
340 
341 
342 
343  // loop through and process each bx
344  for (unsigned short sample = 0; sample < bunchCrossings.size(); sample++)
345  {
348 
351 
352 
353  if(useHcal&&event.getByLabel(hcalDigis[sample], hcal))
354  hcalIn = *hcal;
355 
356  if(useEcal&&event.getByLabel(ecalDigis[sample],ecal))
357  ecalIn = *ecal;
358 
359  rct->digiInput(ecalIn,hcalIn);
360  rct->processEvent();
361 
362  // Stuff to create
363  for (int j = 0; j<18; j++)
364  {
365  L1CaloEmCollection isolatedEGObjects = rct->getIsolatedEGObjects(j);
366  L1CaloEmCollection nonisolatedEGObjects = rct->getNonisolatedEGObjects(j);
367  for (int i = 0; i<4; i++)
368  {
369  isolatedEGObjects.at(i).setBx(bunchCrossings[sample]);
370  nonisolatedEGObjects.at(i).setBx(bunchCrossings[sample]);
371  rctEmCands->push_back(isolatedEGObjects.at(i));
372  rctEmCands->push_back(nonisolatedEGObjects.at(i));
373  }
374  }
375 
376 
377  for (int i = 0; i < 18; i++)
378  {
379  std::vector<L1CaloRegion> regions = rct->getRegions(i);
380  for (int j = 0; j < 22; j++)
381  {
382  regions.at(j).setBx(bunchCrossings[sample]);
383  rctRegions->push_back(regions.at(j));
384  }
385  }
386 
387  }
388 
389 
390  //putting stuff back into event
391  event.put(rctEmCands);
392  event.put(rctRegions);
393 
394 }
395 
396 // print contents of (FULL) FED vector
397 void L1RCTProducer::printFedVector(const std::vector<int>& fedVector)
398 {
399  std::cout << "Contents of given fedVector: ";
400  std::copy(fedVector.begin(), fedVector.end(), std::ostream_iterator<int>(std::cout, ", "));
401  std::cout << std::endl;
402 }
403 
404 // print contents of RCT channel mask fedUpdatedMask
406 {
407  if (fedUpdatedMask != 0)
408  {
410  }
411  else
412  {
413  std::cout << "Trying to print contents of fedUpdatedMask, but it doesn't exist!" << std::endl;
414  }
415 }
416 
417 // print contents of RCT channel mask fedUpdatedMask
419 {
420  if (fedUpdatedMask != 0)
421  {
422  // print contents of fedvector
423  std::cout << "Contents of fedUpdatedMask: ";
424 // std::copy(fedUpdatedMask.begin(), fedUpdatedMask.end(), std::ostream_iterator<int>(std::cout, ", "));
425  std::cout << "--> ECAL mask: " << std::endl;
426  for (int i = 0; i < 18; i++)
427  {
428  for (int j = 0; j < 2; j++)
429  {
430  for (int k = 0; k < 28; k++)
431  {
432  std::cout << fedUpdatedMask->ecalMask[i][j][k] << ", ";
433  }
434  }
435  }
436  std::cout << "--> HCAL mask: " << std::endl;
437  for (int i = 0; i < 18; i++)
438  {
439  for (int j = 0; j < 2; j++)
440  {
441  for (int k = 0; k < 28; k++)
442  {
443  std::cout << fedUpdatedMask->hcalMask[i][j][k] << ", ";
444  }
445  }
446  }
447  std::cout << "--> HF mask: " << std::endl;
448  for (int i = 0; i < 18; i++)
449  {
450  for (int j = 0; j < 2; j++)
451  {
452  for (int k = 0; k < 4; k++)
453  {
454  std::cout << fedUpdatedMask->hfMask[i][j][k] << ", ";
455  }
456  }
457  }
458 
459  std::cout << std::endl;
460  }
461  else
462  {
463  //print error message
464  std::cout << "Trying to print contents of fedUpdatedMask, but it doesn't exist!" << std::endl;
465  }
466 }
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:24
L1CaloEmCollection getIsolatedEGObjects(unsigned crate)
Definition: L1RCT.cc:332
void printUpdatedFedMask()
int j
Definition: DBlmapReader.cc:9
RunNumber_t run() const
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
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
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