CMS 3D CMS Logo

L1TdeStage2uGT.cc
Go to the documentation of this file.
1 /*
2  * \file L1TdeStage2uGT.cc
3  *
4  * L. Apanasevich <Leonard.Apanasevich@cern.ch>
5  */
6 
8 
10  dataLabel_(ps.getParameter<edm::InputTag>("dataSource")),
11  dataSource_(consumes<GlobalAlgBlkBxCollection>(dataLabel_)),
12  emulLabel_(ps.getParameter<edm::InputTag>("emulSource")),
13  emulSource_(consumes<GlobalAlgBlkBxCollection>(emulLabel_)),
14  triggerBlackList_(ps.getParameter<std::vector<std::string> >("triggerBlackList")),
15  numBx_(ps.getParameter<int>("numBxToMonitor")),
16  histFolder_(ps.getParameter<std::string>("histFolder")),
17  gtUtil_(new l1t::L1TGlobalUtil(ps, consumesCollector(), *this, ps.getParameter<edm::InputTag>("dataSource"), ps.getParameter<edm::InputTag>("dataSource"))),
18  numLS_(2000),
19  m_currentLumi(0)
20 {
21 
22  if (numBx_ >5 ) numBx_ = 5;
23  if ( ( numBx_ > 0 ) && ( ( numBx_ % 2 ) == 0 )) {
24  numBx_ = numBx_ - 1;
25 
26  edm::LogWarning("L1TdeStage2uGT")
27  << "\nWARNING: Number of bunch crossing to be emulated rounded to: "
28  << numBx_ << "\n The number must be an odd number!\n"
29  << std::endl;
30  }
31  firstBx = (numBx_ + 1)/2 - numBx_;
32  lastBx = (numBx_ + 1)/2 - 1;
33 
34  edm::LogInfo("L1TdeStage2uGT") << "Number of bunches crossings monitored: " << numBx_
35  << "\t" << "Min BX= " << firstBx << "\t" << "Max BX= " << lastBx << std::endl;
36 
37 }
38 
40 {
41 }
42 
43 void L1TdeStage2uGT::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& evtSetup)
44 {
45 }
46 
48 {
50  event.getByToken(dataSource_, dataCollection);
52  event.getByToken(emulSource_, emulCollection);
53 
54  if (!dataCollection.isValid()) {
55  edm::LogError("L1TdeStage2uGT") << "Cannot find unpacked uGT readout record.";
56  return;
57  }
58  if (!emulCollection.isValid()) {
59  edm::LogError("L1TdeStage2uGT") << "Cannot find emulated uGT readout record.";
60  return;
61  }
62 
63  // Only using gtUtil to find prescale factors and mapping of bits to names, so only call gtUtil_ at lumi boundaries.
64  if (m_currentLumi != event.luminosityBlock()){
65  m_currentLumi=event.luminosityBlock();
66  gtUtil_->retrieveL1(event,es,dataSource_);
67  }
68 
69  // Get standard event parameters
70  int lumi = event.luminosityBlock();
71  if (lumi > numLS_) lumi=numLS_;
72 
73  // int bx = event.bunchCrossing();
74 
75  // check that the requested range of BX's is consistent with the BX's in the emulated and unpacked collections
76  if (emulCollection->getFirstBX() > firstBx) firstBx = emulCollection->getFirstBX();
77  if (emulCollection->getLastBX() < lastBx) lastBx = emulCollection->getLastBX();
78 
79  if (dataCollection->getFirstBX() > firstBx) firstBx = dataCollection->getFirstBX();
80  if (dataCollection->getLastBX() < lastBx) lastBx = dataCollection->getLastBX();
81 
86 
87  for (int ibx = firstBx; ibx <= lastBx; ++ibx) {
88 
89  ostringstream bxt;
90  if (ibx==0){
91  bxt << "CentralBX";
92  }else{
93  bxt << "BX" << ibx;
94  }
95  std::string hname, hsummary;
96  float wt;
97 
98  hsummary="dataEmulSummary_" + bxt.str();
99 
100  std::vector<GlobalAlgBlk>::const_iterator it_data, it_emul;
101  for (it_data = dataCollection->begin(ibx), it_emul = emulCollection->begin(ibx);
102  it_data != dataCollection->end(ibx) && it_emul != emulCollection->end(ibx);
103  ++it_data, ++it_emul) {
104 
105 
106  // Fills algorithm bits histograms
107  int numAlgs= it_data->getAlgoDecisionInitial().size();
108  for(int algoBit = 0; algoBit < numAlgs; ++algoBit) {
109 
110  string algoName = "xxx";
111  bool found=gtUtil_->getAlgNameFromBit(algoBit,algoName);
112  if (not found) continue;
113 
114  // skip bits which emulator does not handle (only skiped for bx !=0)
115  bool isBlackListed(false);
116  for(auto const& pattern : triggerBlackList_) {
117  //std::cout << pattern << std::endl;
118  if (edm::is_glob(pattern)) {
119  std::regex regexp(edm::glob2reg(pattern));
120  if (regex_match (algoName.c_str(),regexp)) isBlackListed = true;
121  } else {
122  if (algoName == pattern) isBlackListed = true;
123  }
124  }
125  if (ibx !=0 && isBlackListed) continue;
126 
127  // Check initial decisions
128  if(it_data->getAlgoDecisionInitial(algoBit) != it_emul->getAlgoDecisionInitial(algoBit)) {
129 
130  if (it_data->getAlgoDecisionInitial(algoBit)){
131  hname = "DataNoEmul_" + bxt.str();
133  wt=1;
134  }else{
135  hname = "EmulatorNoData_" + bxt.str();
137  wt=-1;
138  }
139  fillHist(m_HistNamesInitial, hname, float(algoBit),1.);
140  initDecisionMismatches_vs_LS->Fill(float(lumi),wt);
141 
142  }
143 
144  // Check final decisions
145  if(it_data->getAlgoDecisionFinal(algoBit) != it_emul->getAlgoDecisionFinal(algoBit)) {
146  bool unprescaled=true;
147  // check the prescale factor
148  int prescale = -999;
149  bool dummy=gtUtil_->getPrescaleByBit(algoBit,prescale);
150  if (not dummy)
151  edm::LogWarning("L1TdeStage2uGT") << "Could not find prescale value for algobit: " << algoBit << std::endl;
152 
153  if (prescale != 1) unprescaled=false;
154 
155  if (unprescaled) {
156 
157  if (it_data->getAlgoDecisionFinal(algoBit)){
158  hname = "DataNoEmul_" + bxt.str();
160  wt=1;
161  }else{
162  hname = "EmulatorNoData_" + bxt.str();
164  wt=-1;
165  }
166  fillHist(m_HistNamesFinal, hname, float(algoBit),1.);
167  finalDecisionMismatches_vs_LS->Fill(float(lumi), wt);
168  }
169  }
170 
171  }// end loop over algoBits
172  }// end loop over globalalgblk vector
173  }// endof loop over BX collections
174 
175 }
176 
177 
178 
180 {
182 
183  auto const& prescales = gtUtil_->prescales();
184  int nbins = prescales.size(); // dummy values for now; update later when gtutils function is called
185  double xmin = -0.5;
186  double xmax = nbins-0.5;
187 
188  string hname, htitle;
189 
190  int ibx = (numBx_ + 1)/2 - numBx_;
191  for ( int i = 0; i < numBx_; i++) {
192 
193  ostringstream bxn,bxt;
194 
195  if (ibx==0){
196  bxt << "CentralBX";
197  bxn << " Central BX ";
198  }else{
199  bxt << "BX" << ibx;
200  bxn<< " BX " << ibx;
201  }
202  ibx++;
203 
204  ibooker.setCurrentFolder(histFolder_);
205  hname = "dataEmulSummary_" + bxt.str();
206  htitle = "uGT Data/Emulator Mismatches --" + bxn.str();
207  m_SummaryHistograms[hname] = ibooker.book1D(hname, htitle, NSummaryColumns, 0., double(NSummaryColumns));
208  m_SummaryHistograms[hname]->getTH1F()->GetYaxis()->SetTitle("Events");
209  m_SummaryHistograms[hname]->getTH1F()->GetXaxis()->SetBinLabel(1+NInitalMismatchDataNoEmul, "Data, NoEmul -- Initial Decisions");
210  m_SummaryHistograms[hname]->getTH1F()->GetXaxis()->SetBinLabel(1+NInitalMismatchEmulNoData, "Emulator, No Data -- Initial Decisions");
211  m_SummaryHistograms[hname]->getTH1F()->GetXaxis()->SetBinLabel(1+NFinalMismatchDataNoEmul, "Data, NoEmul -- Final Decisions");
212  m_SummaryHistograms[hname]->getTH1F()->GetXaxis()->SetBinLabel(1+NFinalMismatchEmulNoData, "Emulator, No Data -- Final Decisions");
213 
214  if (i == 0){
215  hname="normalizationHisto";
216  htitle="Normalization histogram for uGT Data/Emulator Mismatches ratios";
217  m_normalizationHisto = ibooker.book1D(hname, htitle, NSummaryColumns, 0., double(NSummaryColumns));
218  m_normalizationHisto->getTH1F()->GetYaxis()->SetTitle("Events");
219  m_normalizationHisto->getTH1F()->GetXaxis()->SetBinLabel(1+NInitalMismatchDataNoEmul, "Data, NoEmul -- Initial Decisions");
220  m_normalizationHisto->getTH1F()->GetXaxis()->SetBinLabel(1+NInitalMismatchEmulNoData, "Emulator, No Data -- Initial Decisions");
221  m_normalizationHisto->getTH1F()->GetXaxis()->SetBinLabel(1+NFinalMismatchDataNoEmul, "Data, NoEmul -- Final Decisions");
222  m_normalizationHisto->getTH1F()->GetXaxis()->SetBinLabel(1+NFinalMismatchEmulNoData, "Emulator, No Data -- Final Decisions");
223  }
224 
225  // book initial decisions histograms
226  ibooker.setCurrentFolder(histFolder_+"/InitialDecisionMismatches");
227  initDecisionMismatches_vs_LS = ibooker.book1D("initialDecisionMismatches_vs_LS", "uGT initial decision mismatches vs Luminosity Segment", numLS_, 0., double(numLS_));
228  initDecisionMismatches_vs_LS->getTH1F()->GetYaxis()->SetTitle("Events with Initial Decision Mismatch");
229  initDecisionMismatches_vs_LS->getTH1F()->GetXaxis()->SetTitle("Luminosity Segment");
230 
231  hname = "DataNoEmul_" + bxt.str();
232  htitle = "uGT data-emul mismatch -- Data fired but not Emulator --" + bxn.str();
233  m_HistNamesInitial[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
234 
235  hname = "EmulatorNoData_" + bxt.str();
236  htitle = "uGT data-emul mismatch -- Emulator fired but not Data --" + bxn.str();
237  m_HistNamesInitial[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
238 
239 
240  // book final decisions histograms
241  ibooker.setCurrentFolder(histFolder_+"/FinalDecisionMismatches");
242  finalDecisionMismatches_vs_LS = ibooker.book1D("finalDecisionMismatches_vs_LS", "uGT final decision mismatches vs Luminosity Segment", numLS_, 0., double(numLS_));
243  finalDecisionMismatches_vs_LS->getTH1F()->GetYaxis()->SetTitle("Events with Final Decision Mismatch");
244  finalDecisionMismatches_vs_LS->getTH1F()->GetXaxis()->SetTitle("Luminosity Segment");
245 
246  hname = "DataNoEmul_" + bxt.str();
247  htitle = "uGT data-emul mismatch -- Data fired but not Emulator --" + bxn.str();
248  m_HistNamesFinal[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
249 
250  hname = "EmulatorNoData_" + bxt.str();
251  htitle = "uGT data-emul mismatch -- Emulator fired but not Data --" + bxn.str();
252  m_HistNamesFinal[hname] = ibooker.book1D(hname, htitle, nbins, xmin, xmax);
253 
254  }
255 
256  // Set some histogram attributes
257  for (std::map<std::string,MonitorElement*>::iterator it = m_HistNamesInitial.begin(); it != m_HistNamesInitial.end(); ++it) {
258  // for (unsigned int i = 0; i < prescales.size(); i++) {
259  // auto const& name = prescales.at(i).first;
260  // if (name != "NULL")
261  // (*it).second->getTH1F()->GetXaxis()->SetBinLabel(1+i, name.c_str());
262  // }
263  (*it).second->getTH1F()->GetXaxis()->SetTitle("Trigger Bit");
264  (*it).second->getTH1F()->GetYaxis()->SetTitle("Events with Initial Decision Mismatch");
265  }
266 
267  for (std::map<std::string,MonitorElement*>::iterator it = m_HistNamesFinal.begin(); it != m_HistNamesFinal.end(); ++it) {
268  // for (unsigned int i = 0; i < prescales.size(); i++) {
269  // auto const& name = prescales.at(i).first;
270  // if (name != "NULL")
271  // (*it).second->getTH1F()->GetXaxis()->SetBinLabel(1+i, name.c_str());
272  // }
273  (*it).second->getTH1F()->GetXaxis()->SetTitle("Trigger Bit (Unprescaled)");
274  (*it).second->getTH1F()->GetYaxis()->SetTitle("Events with Final Decision Mismatch");
275  }
276 
277 
278 }
279 
280 void L1TdeStage2uGT::fillHist(const std::map<std::string, MonitorElement*>& m_HistNames, const std::string& histName, const Double_t& value, const Double_t& wt=1.){
281 
282  std::map<std::string, MonitorElement*>::const_iterator hid = m_HistNames.find(histName);
283 
284  if (hid==m_HistNames.end())
285  edm::LogWarning("L1TdeStage2uGT") << "%fillHist -- Could not find histogram with name: " << histName << std::endl;
286  else
287  hid->second->Fill(value,wt);
288 }
const_iterator end(int bx) const
const std::vector< std::pair< std::string, int > > & prescales()
TH1F * getTH1F() const
const bool getPrescaleByBit(int &bit, int &prescale) const
void fillHist(const std::map< std::string, MonitorElement * > &, const std::string &, const Double_t &, const Double_t &)
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:17
std::string glob2reg(std::string const &pattern)
Definition: RegexMatch.cc:19
std::string histFolder_
edm::EDGetTokenT< GlobalAlgBlkBxCollection > emulSource_
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
delete x;
Definition: CaloConfig.h:22
MonitorElement * m_normalizationHisto
void Fill(long long x)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
~L1TdeStage2uGT() override
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
void bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &, const edm::EventSetup &) override
Definition: value.py:1
l1t::L1TGlobalUtil * gtUtil_
bool isValid() const
Definition: HandleBase.h:74
const bool getAlgNameFromBit(int &bit, std::string &AlgName) const
int getFirstBX() const
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
std::map< std::string, MonitorElement * > m_SummaryHistograms
void analyze(const edm::Event &e, const edm::EventSetup &c) override
MonitorElement * finalDecisionMismatches_vs_LS
HLT enums.
int getLastBX() const
std::vector< std::string > triggerBlackList_
std::map< std::string, MonitorElement * > m_HistNamesFinal
MonitorElement * initDecisionMismatches_vs_LS
L1TdeStage2uGT(const edm::ParameterSet &ps)
const_iterator begin(int bx) const
void retrieveL1Setup(const edm::EventSetup &evSetup)
std::map< std::string, MonitorElement * > m_HistNamesInitial
edm::EDGetTokenT< GlobalAlgBlkBxCollection > dataSource_
void retrieveL1(const edm::Event &iEvent, const edm::EventSetup &evSetup)
initialize the class (mainly reserve)
Definition: event.py:1
Definition: Run.h:45