CMS 3D CMS Logo

L1TdeStage2CaloLayer1.cc
Go to the documentation of this file.
1 /*
2  * \file L1TdeStage2CaloLayer1.cc
3  *
4  * N. Smith <nick.smith@cern.ch>
5  */
6 //Modified by Bhawna Gomber <bhawna.gomber@cern.ch>
7 
9 
14 
17 
18 using namespace l1t;
19 
21  dataLabel_(ps.getParameter<edm::InputTag>("dataSource")),
22  dataSource_(consumes<CaloTowerBxCollection>(dataLabel_)),
23  emulLabel_(ps.getParameter<edm::InputTag>("emulSource")),
24  emulSource_(consumes<CaloTowerBxCollection>(emulLabel_)),
25  hcalTowers_(consumes<HcalTrigPrimDigiCollection>(edm::InputTag("l1tCaloLayer1Digis"))),
26  fedRawData_(consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("fedRawDataLabel"))),
27  histFolder_(ps.getParameter<std::string>("histFolder")),
28  tpFillThreshold_(ps.getUntrackedParameter<int>("etDistributionsFillThreshold", 0))
29 {
31  for(size_t i=0; i<NSummaryColumns; ++i) {
32  dataEmulNumerator_[i] = 0.;
33  }
34 }
35 
37 {
38 }
39 
41 {
42 }
43 
45 {
47  event.getByToken(dataSource_, dataTowers);
49  event.getByToken(emulSource_, emulTowers);
51  event.getByToken(hcalTowers_, hcalTowers);
52 
53  // Best way I know to check if FED in a run
54  edm::Handle<FEDRawDataCollection> fedRawDataCollection;
55  event.getByToken(fedRawData_, fedRawDataCollection);
56  bool caloLayer1OutOfRun{true};
57  bool caloLayer2OutOfRun{true};
58  if (fedRawDataCollection.isValid()) {
59  caloLayer1OutOfRun = false;
60  caloLayer2OutOfRun = false;
61  for(int iFed=1354; iFed<1360; iFed+=2) {
62  const FEDRawData& fedRawData = fedRawDataCollection->FEDData(iFed);
63  if ( fedRawData.size() == 0 ) {
64  caloLayer1OutOfRun = true;
65  continue; // In case one of 3 layer 1 FEDs not in
66  }
67  }
68  const FEDRawData& fedRawData = fedRawDataCollection->FEDData(1360);
69  if ( fedRawData.size() == 0 ) {
70  caloLayer2OutOfRun = true;
71  }
72  }
73 
74  if ( caloLayer1OutOfRun or caloLayer2OutOfRun ) {
75  // No point in comparing
76  return;
77  }
78 
79  // We'll fill sets, compare, and then dissect comparison failures after.
80  SimpleTowerSet dataTowerSet;
81  // BXVector::begin(int bx)
82  for ( auto iter = dataTowers->begin(0); iter != dataTowers->end(0); ++iter) {
83  const auto& tower = *iter;
84  int eta = tower.hwEta();
85  if ( eta == 29 ) eta = 30;
86  if ( eta == -29 ) eta = -30;
87  dataTowerSet.emplace(eta, tower.hwPhi(), tower.hwPt() + (tower.hwEtRatio()<<9) + (tower.hwQual()<<12), true);
88  if ( tower.hwPt() > tpFillThreshold_ ) {
89  dataOcc_->Fill(eta, tower.hwPhi());
90  dataEtDistribution_->Fill(tower.hwPt());
91  }
92  }
93  SimpleTowerSet emulTowerSet;
94  for ( auto iter = emulTowers->begin(0); iter != emulTowers->end(0); ++iter) {
95  const auto& tower = *iter;
96  emulTowerSet.emplace(tower.hwEta(), tower.hwPhi(), tower.hwPt() + (tower.hwEtRatio()<<9) + (tower.hwQual()<<12), false);
97  if ( tower.hwPt() > tpFillThreshold_ ) {
98  emulOcc_->Fill(tower.hwEta(), tower.hwPhi());
99  emulEtDistribution_->Fill(tower.hwPt());
100  }
101  }
102 
103  bool etMsmThisEvent{false};
104  bool erMsmThisEvent{false};
105  bool fbMsmThisEvent{false};
106  bool towerCountMsmThisEvent{false};
107 
108  if ( dataTowerSet.size() != emulTowerSet.size() ) {
109  // This will happen if either CaloLayer1 or CaloLayer2 are out of run (in which case we exit early)
110  // The problematic situation that we are monitoring is when we see both in, but one MP7 card is not sending fat events when it should
112  towerCountMsmThisEvent = true;
113  }
114  else {
115  auto dataIter = dataTowerSet.begin();
116  auto emulIter = emulTowerSet.begin();
117  while ( dataIter != dataTowerSet.end() && emulIter != emulTowerSet.end() ) {
118  auto dataTower = *(dataIter++);
119  auto emulTower = *(emulIter++);
120  assert(dataTower.ieta_==emulTower.ieta_ && dataTower.iphi_==emulTower.iphi_);
121 
122  etCorrelation_->Fill(dataTower.et(), emulTower.et());
123 
124  if ( abs(dataTower.ieta_) >= 30 ) {
125  fbCorrelationHF_->Fill(dataTower.fb(), emulTower.fb());
126  } else {
127  fbCorrelation_->Fill(dataTower.fb(), emulTower.fb());
128  }
129 
130  if ( dataTower.data_ == emulTower.data_ ) {
131  // Perfect match
132  if ( dataTower.et() > tpFillThreshold_ ) {
133  matchOcc_->Fill(dataTower.ieta_, dataTower.iphi_);
134  }
135  } else {
136  // Ok, now dissect the failure
137  if ( dataTower.et() != emulTower.et() ) {
138  if ( dataTower.et() == 0 ) failureOccEtDataZero_->Fill(dataTower.ieta_, dataTower.iphi_);
139  else if ( emulTower.et() == 0 ) failureOccEtEmulZero_->Fill(dataTower.ieta_, dataTower.iphi_);
140  else failureOccEtMismatch_->Fill(dataTower.ieta_, dataTower.iphi_);
141 
142  etMismatchDiff_->Fill(dataTower.et() - emulTower.et());
145  etMsmThisEvent = true;
146  updateMismatch(event, 0);
147  }
148  if ( dataTower.er() != emulTower.er() ) {
149  failureOccErMismatch_->Fill(dataTower.ieta_, dataTower.iphi_);
152  erMsmThisEvent = true;
153  updateMismatch(event, 1);
154  }
155  if ( dataTower.fb() != emulTower.fb() ) {
156  failureOccFbMismatch_->Fill(dataTower.ieta_, dataTower.iphi_);
159  dataEtDistributionFBMismatch_->Fill(dataTower.et());
160  fbMsmThisEvent = true;
161  updateMismatch(event, 2);
162  }
163  }
164  }
165  }
166 
168  if ( etMsmThisEvent ) dataEmulNumerator_[EtMismatch] += 1;
169  if ( erMsmThisEvent ) dataEmulNumerator_[ErMismatch] += 1;
170  if ( fbMsmThisEvent ) dataEmulNumerator_[FbMismatch] += 1;
171  if ( towerCountMsmThisEvent ) dataEmulNumerator_[TowerCountMismatch] += 1;
172 
173  for(size_t i=0; i<NSummaryColumns; ++i) {
175  }
176  // GetEntries() increments every SetBinContent() call
178 
179  // To see if problems correlate with TMT cycle (i.e. an MP7-side issue)
180  if ( etMsmThisEvent or erMsmThisEvent or fbMsmThisEvent or towerCountMsmThisEvent ) {
182  }
183 }
184 
185 void L1TdeStage2CaloLayer1::updateMismatch(const edm::Event& e, int mismatchType) {
186  auto id = e.id();
187  std::string eventString{std::to_string(id.run()) + ":" + std::to_string(id.luminosityBlock()) + ":" + std::to_string(id.event())};
188  if ( last20MismatchArray_.at(lastMismatchIndex_).first == eventString ) {
189  // same event
190  last20MismatchArray_.at(lastMismatchIndex_).second |= 1<<mismatchType;
191  }
192  else {
193  // New event, advance
195  last20MismatchArray_.at(lastMismatchIndex_) = {eventString, 1<<mismatchType};
196  }
197 }
198 
200  // Ugly way to loop backwards through the last 20 mismatches
201  for (size_t ibin=1, imatch=lastMismatchIndex_; ibin<=20; ibin++, imatch=(imatch+19)%20) {
202  last20Mismatches_->getTH2F()->GetYaxis()->SetBinLabel(ibin, last20MismatchArray_.at(imatch).first.c_str());
203  for(int itype=0; itype<4; ++itype) {
204  int binContent = (last20MismatchArray_.at(imatch).second>>itype) & 1;
205  last20Mismatches_->setBinContent(itype+1, ibin, binContent);
206  }
207  }
208 }
209 
211  auto id = static_cast<double>(lumi.id().luminosityBlock()); // uint64_t
212  // Simple way to embed current lumi to auto-scale axis limits in render plugin
213  etMismatchByLumi_->getTH1F()->SetBinContent(0, id);
214  erMismatchByLumi_->getTH1F()->SetBinContent(0, id);
215  fbMismatchByLumi_->getTH1F()->SetBinContent(0, id);
216 }
217 
219 {
220  auto bookEt = [&ibooker](std::string name, std::string title) {
221  title += ";Raw ET value";
222  return ibooker.book1D(name, title, 512, -0.5, 511.5);
223  };
224  auto bookEtDiff = [&ibooker](std::string name, std::string title) {
225  title += ";#Delta raw ET value";
226  return ibooker.book1D(name, title, 1023, -511.5, 511.5);
227  };
228  auto bookEtCorrelation = [&ibooker](std::string name, std::string title) {
229  return ibooker.book2D(name, title, 512, -0.5, 511.5, 512, -0.5, 511.5);
230  };
231  auto bookOccupancy = [&ibooker](std::string name, std::string title) {
232  title += ";i#eta;i#phi";
233  return ibooker.book2D(name, title, 83, -41.5, 41.5, 72, 0.5, 72.5);
234  };
235 
236  ibooker.setCurrentFolder(histFolder_+"/");
237  dataEmulSummary_ = ibooker.book1D("dataEmulSummary", "CaloLayer1 data-emul mismatch frac. (entries=evts processed)", NSummaryColumns, 0., double(NSummaryColumns));
238  dataEmulSummary_->getTH1F()->GetYaxis()->SetTitle("Fraction events with mismatch");
239  dataEmulSummary_->getTH1F()->GetXaxis()->SetBinLabel(1+EtMismatch, "Et");
240  dataEmulSummary_->getTH1F()->GetXaxis()->SetBinLabel(1+ErMismatch, "Et ratio");
241  dataEmulSummary_->getTH1F()->GetXaxis()->SetBinLabel(1+FbMismatch, "Feature bit");
242  dataEmulSummary_->getTH1F()->GetXaxis()->SetBinLabel(1+TowerCountMismatch, "CaloTower readout");
243  mismatchesPerBxMod9_ = ibooker.book1D("mismatchesPerBxMod9", "CaloLayer1 data-emulator mismatch per bx%9;Bunch crossing mod 9;Counts", 9, -0.5, 8.5);
244 
245  ibooker.setCurrentFolder(histFolder_+"/Occupancies");
246 
247  dataOcc_ = bookOccupancy("dataOcc", "Tower Occupancy for Data");
248  emulOcc_ = bookOccupancy("emulOcc", "Tower Occupancy for Emulator");
249  matchOcc_ = bookOccupancy("matchOcc", "Tower Occupancy for Data/Emulator Full Matches");
250  failureOccEtMismatch_ = bookOccupancy("failureOccEtMismatch", "Tower Occupancy for Data/Emulator ET Mismatch");
251  failureOccEtDataZero_ = bookOccupancy("failureOccEtDataZero", "Tower Occupancy for Data ET Zero, Emul Nonzero");
252  failureOccEtEmulZero_ = bookOccupancy("failureOccEtEmulZero", "Tower Occupancy for Data ET Nonzero, Emul Zero");
253  failureOccErMismatch_ = bookOccupancy("failureOccErMismatch", "Tower Occupancy for Data/Emulator ET Ratio Mismatch");
254  failureOccFbMismatch_ = bookOccupancy("failureOccFbMismatch", "Tower Occupancy for Data/Emulator Feature Bit Mismatch");
255 
256  ibooker.setCurrentFolder(histFolder_+"/EtDistributions");
257  dataEtDistribution_ = bookEt("dataEtDistribution", "ET distribution for towers in data");
258  dataEtDistributionFBMismatch_ = bookEt("dataEtDistributionFBMismatch", "ET distribution for towers in data when FB Mismatch");
259  emulEtDistribution_ = bookEt("emulEtDistribution", "ET distribution for towers in emulator");
260  etCorrelation_ = bookEtCorrelation("EtCorrelation", "Et correlation for all towers;Data tower Et;Emulator tower Et");
261  matchEtDistribution_ = bookEt("matchEtDistribution", "ET distribution for towers matched between data and emulator");
262  etMismatchDiff_ = bookEtDiff("etMismatchDiff", "ET difference (data-emulator) for ET mismatches");
263  fbCorrelation_ = ibooker.book2D("FbCorrelation", "Feature Bit correlation for BE;Data;Emulator", 16, -0.5, 15.5, 16, -0.5, 15.5);
264  fbCorrelationHF_ = ibooker.book2D("FbCorrelationHF", "Feature Bit correlation for HF;Data;Emulator", 16, -0.5, 15.5, 16, -0.5, 15.5);
265 
266  ibooker.setCurrentFolder(histFolder_+"/MismatchDetail");
267 
268  const int nLumis = 2000;
269  etMismatchByLumi_ = ibooker.book1D("etMismatchByLumi", "ET Mismatch counts per lumi section;LumiSection;Counts", nLumis, .5, nLumis+0.5);
270  erMismatchByLumi_ = ibooker.book1D("erMismatchByLumi", "ET Ratio Mismatch counts per lumi section;LumiSection;Counts", nLumis, .5, nLumis+0.5);
271  fbMismatchByLumi_ = ibooker.book1D("fbMismatchByLumi", "Feature Bit Mismatch counts per lumi section;LumiSection;Counts", nLumis, .5, nLumis+0.5);
272 
273  etMismatchesPerBx_ = ibooker.book1D("etMismatchesPerBx", "ET Mismatch counts per bunch crossing", 3564, -.5, 3563.5);
274  erMismatchesPerBx_ = ibooker.book1D("erMismatchesPerBx", "ET Ratio Mismatch counts per bunch crossing", 3564, -.5, 3563.5);
275  fbMismatchesPerBx_ = ibooker.book1D("fbMismatchesPerBx", "Feature Bit Mismatch counts per bunch crossing", 3564, -.5, 3563.5);
276  towerCountMismatchesPerBx_ = ibooker.book1D("towerCountMismatchesPerBx", "CaloTower size mismatch counts per bunch crossing", 3564, -.5, 3563.5);
277 
278  last20Mismatches_ = ibooker.book2D("last20Mismatches",
279  "Log of last 20 mismatches (use json tool to copy/paste)",
280  4, 0, 4, 20, 0, 20);
281  last20Mismatches_->getTH2F()->GetXaxis()->SetBinLabel(1, "Et Mismatch");
282  last20Mismatches_->getTH2F()->GetXaxis()->SetBinLabel(2, "Et ratio Mismatch");
283  last20Mismatches_->getTH2F()->GetXaxis()->SetBinLabel(3, "Feature bit Mismatch");
284  last20Mismatches_->getTH2F()->GetXaxis()->SetBinLabel(4, "-");
285  for (size_t i=0; i<last20MismatchArray_.size(); ++i) last20MismatchArray_[i] = {"-"+std::to_string(i), 0};
286  for (size_t i=1; i<=20; ++i) last20Mismatches_->getTH2F()->GetYaxis()->SetBinLabel(i, ("-"+std::to_string(i)).c_str());
287 }
288 
LuminosityBlockID id() const
const_iterator end(int bx) const
void setBinContent(int binx, double content)
set content of bin (1-D)
std::array< double, NSummaryColumns > dataEmulNumerator_
edm::EDGetTokenT< l1t::CaloTowerBxCollection > emulSource_
edm::EDGetTokenT< l1t::CaloTowerBxCollection > dataSource_
void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
MonitorElement * erMismatchesPerBx_
L1TdeStage2CaloLayer1(const edm::ParameterSet &ps)
TH1F * getTH1F() const
MonitorElement * fbCorrelationHF_
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
edm::EDGetTokenT< HcalTrigPrimDigiCollection > hcalTowers_
int bunchCrossing() const
Definition: EventBase.h:64
MonitorElement * fbMismatchesPerBx_
delete x;
Definition: CaloConfig.h:22
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
MonitorElement * dataEmulSummary_
MonitorElement * failureOccErMismatch_
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
MonitorElement * fbCorrelation_
void Fill(long long x)
void updateMismatch(const edm::Event &e, int mismatchType)
MonitorElement * dataEtDistributionFBMismatch_
std::set< SimpleTower > SimpleTowerSet
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
MonitorElement * failureOccEtDataZero_
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
MonitorElement * matchEtDistribution_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
MonitorElement * failureOccEtMismatch_
void analyze(const edm::Event &e, const edm::EventSetup &c) override
MonitorElement * dataEtDistribution_
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * emulEtDistribution_
MonitorElement * erMismatchByLumi_
MonitorElement * etMismatchDiff_
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
bool isValid() const
Definition: HandleBase.h:74
MonitorElement * etMismatchesPerBx_
TH2F * getTH2F() const
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
MonitorElement * etMismatchByLumi_
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
std::array< std::pair< std::string, int >, 20 > last20MismatchArray_
LuminosityBlockNumber_t luminosityBlock() const
edm::EventID id() const
Definition: EventBase.h:59
MonitorElement * last20Mismatches_
HLT enums.
MonitorElement * mismatchesPerBxMod9_
MonitorElement * failureOccFbMismatch_
MonitorElement * failureOccEtEmulZero_
MonitorElement * etCorrelation_
const_iterator begin(int bx) const
edm::EDGetTokenT< FEDRawDataCollection > fedRawData_
void bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &, const edm::EventSetup &) override
Definition: event.py:1
Definition: Run.h:45
MonitorElement * towerCountMismatchesPerBx_
MonitorElement * fbMismatchByLumi_