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