CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BxTiming.cc
Go to the documentation of this file.
2 #include <cstdio>
3 
5  verbose_ = iConfig.getUntrackedParameter<int>("VerboseFlag", 0);
6  if (verbose())
7  std::cout << "BxTiming::BxTiming()...\n" << std::flush;
8 
9  fedRef_ = iConfig.getUntrackedParameter<int>("ReferenceFedId", 813);
10  fedSource_ = iConfig.getUntrackedParameter<edm::InputTag>("FedSource", edm::InputTag("source"));
11  fedSource_token_ = consumes<FEDRawDataCollection>(
12  iConfig.getUntrackedParameter<edm::InputTag>("FedSource", edm::InputTag("source")));
13  gtSource_ = iConfig.getUntrackedParameter<edm::InputTag>("GtSource", edm::InputTag("gtUnpack"));
14  gtSource_token_ = consumes<L1GlobalTriggerReadoutRecord>(
15  iConfig.getUntrackedParameter<edm::InputTag>("GtSource", edm::InputTag("gtUnpack")));
16  histFile_ = iConfig.getUntrackedParameter<std::string>("HistFile", "");
17  histFolder_ = iConfig.getUntrackedParameter<std::string>("HistFolder", "L1T/BXSynch");
18 
19  runInFF_ = iConfig.getUntrackedParameter<bool>("RunInFilterFarm", true);
20  if (runInFF_)
21  histFolder_ = "L1T/BXSynch_EvF";
22  if (verbose())
23  std::cout << "Filter farm run setting?" << runInFF_ << "\n" << std::flush;
24 
25  listGtBits_ = iConfig.getUntrackedParameter<std::vector<int> >("GtBitList", std::vector<int>(1, 0));
26  if (listGtBits_.size() == 1 && listGtBits_.at(0) == -1) {
27  int ngtbits = 128;
28  listGtBits_.reserve(ngtbits);
29  for (int i = 0; i < ngtbits; i++)
30  listGtBits_[i] = i;
31  }
32 
33  if (verbose()) {
34  std::cout << "BxTiming: gt bits set for timing dqm:";
35  std::cout << "nbits:" << listGtBits_.size() << " list: ";
36  for (size_t i = 0; i != listGtBits_.size(); i++)
37  std::cout << listGtBits_.at(i) << " ";
38  std::cout << "\n" << std::flush;
39  }
40 
41  nEvt_ = 0;
42 
43  if (verbose())
44  std::cout << "BxTiming::BxTiming constructor...done.\n" << std::flush;
45 }
46 
48 
51 
53  for (int i = 0; i < nfed_; i++) {
54  nBxDiff[i][0] = 0;
55  nBxDiff[i][1] = nbig_;
56  nBxDiff[i][2] = -1 * nbig_;
57  nBxOccy[i][0] = 0;
58  nBxOccy[i][1] = nbig_;
59  nBxOccy[i][2] = -1 * nbig_;
60  }
61 
62  std::string lbl("");
63  std::string SysLabel[NSYS] = {"PreShower", "ECAL", "HCAL", "GCT", "CSCTPG", "CSCTF", "DTTPG", "DTTF", "RPC", "GT"};
64 
65  typedef std::pair<int, int> FEDRange;
66 
67  std::pair<int, int> fedRange[NSYS] = {
78  };
79  for (int i = 0; i < NSYS; i++)
80  fedRange_[i] = fedRange[i];
81 
82  int fedRefSys = -1;
83  for (int i = 0; i < NSYS; i++)
84  if (fedRef_ >= fedRange_[i].first && fedRef_ <= fedRange_[i].second) {
85  fedRefSys = i;
86  break;
87  }
88  std::string refName("");
89  std::string spreadLabel[nspr_] = {"Spread", "Min", "Max"};
90  if (fedRefSys >= 0)
91  refName += SysLabel[fedRefSys];
92  else
93  refName += fedRef_;
94 
96 
97  const int dbx = nbig_;
98 
100 
101  hBxDiffAllFed = ibooker.bookProfile(
102  "BxDiffAllFed", "BxDiffAllFed", nfed_ + 1, -0.5, nfed_ + 0.5, 2 * dbx + 1, -1 * dbx - 0.5, dbx + 0.5);
103 
104  for (int i = 0; i < nspr_; i++) {
105  lbl.clear();
106  lbl += "BxDiffAllFed";
107  lbl += spreadLabel[i];
108  hBxDiffAllFedSpread[i] = ibooker.book1D(lbl.data(), lbl.data(), nfed_ + 1, -0.5, nfed_ + 0.5);
109  lbl.clear();
110  lbl += "BxOccyAllFed";
111  lbl += spreadLabel[i];
112  hBxOccyAllFedSpread[i] = ibooker.book1D(lbl.data(), lbl.data(), nfed_ + 1, -0.5, nfed_ + 0.5);
113 
114  lbl.clear();
115  lbl += "BxOccyAllFed";
116  hBxOccyAllFed = ibooker.book1D(lbl.data(), lbl.data(), norb_ + 1, -0.5, norb_ + 0.5);
117  }
118 
119  // following histos defined only when not runing in the ff
120  if (!runInFF_) {
121  ibooker.setCurrentFolder(histFolder_);
122 
123  for (int i = 0; i < NSYS; i++) {
124  lbl.clear();
125  lbl += SysLabel[i];
126  lbl += "FedBxDiff";
127  int nfeds = fedRange_[i].second - fedRange_[i].first + 1;
128  nfeds = (nfeds > 0) ? nfeds : 1;
129  hBxDiffSysFed[i] = ibooker.bookProfile(lbl.data(),
130  lbl.data(),
131  nfeds,
132  fedRange_[i].first - 0.5,
133  fedRange_[i].second + 0.5,
134  2 * dbx + 1,
135  -1 * dbx - 0.5,
136  dbx + 0.5);
137  }
138 
139  lbl.clear();
140  lbl += "BxOccyAllFed";
142  ibooker.setCurrentFolder(histFolder_ + "/SingleFed");
143  for (int i = 0; i < nfed_; i++) {
144  lbl.clear();
145  lbl += "BxOccyOneFed";
146  lbl += std::to_string(i);
147  hBxOccyOneFed[i] = ibooker.book1D(lbl.data(), lbl.data(), norb_ + 1, -0.5, norb_ + 0.5);
148  }
149 
150  ibooker.setCurrentFolder(histFolder_);
151  for (int i = 0; i < nttype_; i++) {
152  lbl.clear();
153  lbl += "BxOccyGtTrigType";
154  lbl += std::to_string(i + 1);
155  hBxOccyGtTrigType[i] = ibooker.book1D(lbl.data(), lbl.data(), norb_ + 1, -0.5, norb_ + 0.5);
156  }
157 
158  ibooker.setCurrentFolder(histFolder_ + "/SingleBit");
159  for (int i = 0; i < NSYS; i++) {
160  hBxOccyTrigBit[i] = new MonitorElement *[listGtBits_.size()];
161  for (size_t j = 0; j < listGtBits_.size(); j++) {
162  lbl.clear();
163  lbl += SysLabel[i];
164  lbl += "BxOccyGtBit";
165  lbl += std::to_string(listGtBits_.at(j));
166  hBxOccyTrigBit[i][j] = ibooker.book1D(lbl.data(), lbl.data(), norb_ + 1, -0.5, norb_ + 0.5);
167  }
168  }
169  }
170 
172  hBxDiffAllFed->setAxisTitle("FED ID", 1);
173  lbl.clear();
174  lbl += "BX(fed)-BX(";
175  lbl += refName;
176  lbl += ")";
177  hBxDiffAllFed->setAxisTitle(lbl, 2);
178  for (int i = 0; i < nspr_; i++) {
179  lbl.clear();
180  lbl += "BX(fed)-BX(";
181  lbl += refName;
182  lbl += ") " + spreadLabel[i];
183  hBxDiffAllFedSpread[i]->setAxisTitle("FED ID", 1);
185  lbl.clear();
186  lbl += "Bx FED occupancy";
187  lbl += " ";
188  lbl += spreadLabel[i];
189  hBxOccyAllFedSpread[i]->setAxisTitle("FED ID", 1);
191  }
192 
193  hBxOccyAllFed->setAxisTitle("bx", 1);
194  lbl.clear();
195  lbl += "Combined FED occupancy";
196  hBxOccyAllFed->setAxisTitle(lbl, 2);
197 
198  // skip next if running in filter farm
199  if (runInFF_)
200  return;
201 
202  for (int i = 0; i < NSYS; i++) {
203  lbl.clear();
204  lbl += SysLabel[i];
205  lbl += " FED ID";
206  hBxDiffSysFed[i]->setAxisTitle(lbl, 1);
207  lbl.clear();
208  lbl += "BX(";
209  lbl += SysLabel[i];
210  lbl += ")-BX(";
211  lbl += refName;
212  lbl += ")";
213  hBxDiffSysFed[i]->setAxisTitle(lbl, 2);
214  }
215 
216  for (int i = 0; i < nfed_; i++) {
217  hBxOccyOneFed[i]->setAxisTitle("bx", 1);
218  lbl.clear();
219  lbl += " FED ";
220  lbl += std::to_string(i);
221  lbl += " occupancy";
222  hBxOccyOneFed[i]->setAxisTitle(lbl, 2);
223  }
224  for (int i = 0; i < nttype_; i++) {
225  hBxOccyGtTrigType[i]->setAxisTitle("bx", 1);
226  lbl.clear();
227  lbl += "GT occupancy for trigger type ";
228  lbl += std::to_string(i + 1);
229  hBxOccyGtTrigType[i]->setAxisTitle(lbl, 2);
230  }
231 
232  for (int i = 0; i < NSYS; i++) {
233  for (size_t j = 0; j < listGtBits_.size(); j++) {
234  hBxOccyTrigBit[i][j]->setAxisTitle("bx", 1);
235  lbl.clear();
236  lbl += SysLabel[i];
237  lbl += " Bx occupancy for Trigger bit ";
238  lbl += std::to_string(listGtBits_.at(j));
239  hBxOccyTrigBit[i][j]->setAxisTitle(lbl, 2);
240  }
241  }
242 }
243 
244 // ------------ method called to for each event ------------
245 void BxTiming::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
246  if (verbose())
247  std::cout << "BxTiming::analyze() start\n" << std::flush;
248 
249  nEvt_++;
250 
253  iEvent.getByToken(fedSource_token_, rawdata);
254 
255  if (!rawdata.isValid()) {
256  if (verbose())
257  std::cout << "BxTiming::analyze() | FEDRawDataCollection with input tag " << fedSource_ << " not found.";
258 
259  return;
260  }
261 
262  // get the GT bits
264  iEvent.getByToken(gtSource_token_, gtdata);
265  std::vector<bool> gtbits;
266  int ngtbits = 128;
267  gtbits.reserve(ngtbits);
268  for (int i = 0; i < ngtbits; i++)
269  gtbits[i] = false;
270  if (gtdata.isValid())
271  gtbits = gtdata->decisionWord();
272 
273  if (gtbits.empty()) {
274  gtbits.push_back(true); // gtdata->decision();
275  if (verbose())
276  std::cout << "BxTiming::analyze() | unexpected empty decision bits!";
277  }
278 
279  if (verbose()) {
280  std::cout << "BxTiming::analyze() gt data valid:" << (int)(gtdata.isValid() ? 0 : 1)
281  << " decision word size:" << (int)(gtbits.size()) << " bits: ";
282  for (size_t i = 0; i != gtbits.size(); i++) {
283  int ii = gtbits.at(i) ? 1 : 0;
284  std::cout << ii;
285  }
286  std::cout << ".\n" << std::flush;
287  }
288 
289  // get reference bx
290  int bxRef = FEDHeader(rawdata->FEDData(fedRef_).data()).bxID();
291 
292  // triggerType
293  // trigger types: physics (1), calibration (2), random (3), traced physics (5), test (6)
294  int ttype = static_cast<double>(iEvent.eventAuxiliary().experimentType());
295 
296  // loop over feds
297  for (int i = 0; i < FEDNumbering::MAXFEDID + 1; i++) {
298  const FEDRawData &data = rawdata->FEDData(i);
299  size_t size = data.size();
300 
301  if (!size)
302  continue;
303  FEDHeader header(data.data());
304  //int lvl1id = header.lvl1ID(); //Level-1 event number generated by the TTC system
305  int bx = header.bxID(); // The bunch crossing number
306 
307  int bxDiff = calcBxDiff(bx, bxRef); // deviation from reference bx
308 
309  //min
310  if (nBxDiff[i][1] > bxDiff)
311  nBxDiff[i][1] = bxDiff;
312  if (nBxOccy[i][1] > bx)
313  nBxOccy[i][1] = bx;
314  //max
315  if (nBxDiff[i][2] < bxDiff)
316  nBxDiff[i][2] = bxDiff;
317  if (nBxOccy[i][2] < bx)
318  nBxOccy[i][2] = bx;
319 
320  if (verbose())
321  std::cout << " fed:" << i << " bx:" << bx << " bxRef:" << bxRef << " diff:" << bxDiff << " nBxDiff"
322  << " del:" << nBxDiff[i][0] << " min:" << nBxDiff[i][1] << " max:" << nBxDiff[i][2] << " nBxOccy"
323  << " del:" << nBxOccy[i][0] << " min:" << nBxOccy[i][1] << " max:" << nBxOccy[i][2] << "\n"
324  << std::flush;
325 
326  hBxDiffAllFed->Fill(i, bxDiff);
327 
328  //if(ttype==1) //skip if not a physics trigger
329  hBxOccyAllFed->Fill(bx);
330 
331  // done if running in filter farm
332  if (runInFF_)
333  continue;
334 
335  for (int j = 0; j < NSYS; j++)
336  if (i >= fedRange_[j].first && i <= fedRange_[j].second)
337  hBxDiffSysFed[j]->Fill(i, bxDiff);
338 
339  for (size_t k = 0; k != listGtBits_.size(); k++) {
340  if ((int)gtbits.size() <= listGtBits_.at(k)) {
341  if (verbose())
342  std::cout << "BxTiming analyze | problem with vector size!\n" << std::endl;
343  continue;
344  } else if (!gtbits.at(listGtBits_.at(k)))
345  continue;
346  for (int j = 0; j < NSYS; j++) {
347  if (i >= fedRange_[j].first && i <= fedRange_[j].second) {
348  hBxOccyTrigBit[j][k]->Fill(bx);
349  }
350  }
351  }
352 
353  if (i >= fedRange_[GLT].first && i <= fedRange_[GLT].second) //GT fed
354  if (ttype < nttype_)
355  hBxOccyGtTrigType[ttype - 1]->Fill(bx);
356 
357  if (ttype != 1)
358  continue; //skip if not a physics trigger
359  //hBxOccyAllFed->Fill(bx);
360  hBxOccyOneFed[i]->Fill(bx);
361  }
362 
363  for (int i = 0; i < nfed_; i++) {
364  nBxDiff[i][0] = nBxDiff[i][2] - nBxDiff[i][1];
365  nBxOccy[i][0] = nBxOccy[i][2] - nBxOccy[i][1];
366  if (nBxDiff[i][0] < 0 || nBxOccy[i][0] < 0)
367  continue;
368  for (int j = 0; j < nspr_; j++) {
369  hBxDiffAllFedSpread[j]->setBinContent(i, nBxDiff[i][j]);
370  hBxOccyAllFedSpread[j]->setBinContent(i, nBxOccy[i][j]);
371  }
372  if (verbose())
373  std::cout << "BxTiming fed:" << i << " Bx-Bx(" << fedRef_ << ")::"
374  << " del:" << nBxDiff[i][0] << " min:" << nBxDiff[i][1] << " max:" << nBxDiff[i][2] << " Occy: "
375  << " del:" << nBxOccy[i][0] << " min:" << nBxOccy[i][1] << " max:" << nBxOccy[i][2] << "\n"
376  << std::flush;
377  }
378 
379  if (verbose())
380  std::cout << "BxTiming::analyze() end.\n" << std::flush;
381 }
382 
383 //----------------------------------------------------------------------
384 
385 int BxTiming::calcBxDiff(int bx1, int bx2) {
386  int diff = bx1 - bx2;
387 
388  while (diff < -half_norb_)
389  diff += norb_;
390 
391  while (diff > half_norb_)
392  diff -= norb_;
393 
394  return diff;
395 }
396 
397 //----------------------------------------------------------------------
~BxTiming() override
Definition: BxTiming.cc:47
static const int nttype_
Definition: BxTiming.h:77
T getUntrackedParameter(std::string const &, T const &) const
static const int norb_
Definition: BxTiming.h:73
MonitorElement * hBxDiffAllFed
histograms
Definition: BxTiming.h:92
int nBxOccy[FEDNumbering::MAXFEDID+1][nspr_]
Definition: BxTiming.h:89
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
MonitorElement * hBxDiffAllFedSpread[nspr_]
Definition: BxTiming.h:97
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::vector< int > listGtBits_
Definition: BxTiming.h:79
int verbose()
Definition: BxTiming.h:50
#define nfed_
Definition: BxTiming.h:30
std::string histFile_
Definition: BxTiming.h:64
std::string to_string(const V &value)
Definition: OMSAccess.h:71
EventAuxiliary const & eventAuxiliary() const override
Definition: Event.h:95
int ii
Definition: cuy.py:589
MonitorElement * hBxOccyAllFed
Definition: BxTiming.h:94
MonitorElement ** hBxOccyOneFed
Definition: BxTiming.h:95
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
static const int nbig_
Definition: BxTiming.h:76
edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > gtSource_token_
Definition: BxTiming.h:46
ExperimentType experimentType() const
void Fill(long long x)
U second(std::pair< T, U > const &p)
MonitorElement * hBxOccyGtTrigType[nttype_]
Definition: BxTiming.h:100
int iEvent
Definition: GenABIO.cc:224
int nEvt_
Definition: BxTiming.h:61
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
int verbose_
Definition: BxTiming.h:49
static const int half_norb_
Definition: BxTiming.h:74
edm::InputTag fedSource_
Definition: BxTiming.h:43
bool isValid() const
Definition: HandleBase.h:70
std::pair< int, int > fedRange_[NSYS]
Definition: BxTiming.h:83
bool runInFF_
Definition: BxTiming.h:70
std::string histFolder_
Definition: BxTiming.h:67
edm::InputTag gtSource_
Definition: BxTiming.h:45
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const &) override
Definition: BxTiming.cc:49
edm::EDGetTokenT< FEDRawDataCollection > fedSource_token_
Definition: BxTiming.h:44
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
int fedRef_
Definition: BxTiming.h:84
MonitorElement * hBxDiffSysFed[NSYS]
Definition: BxTiming.h:93
MonitorElement ** hBxOccyTrigBit[NSYS]
Definition: BxTiming.h:101
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
int calcBxDiff(int bx1, int bx2)
Definition: BxTiming.cc:385
int nBxDiff[FEDNumbering::MAXFEDID+1][nspr_]
Definition: BxTiming.h:88
tuple cout
Definition: gather_cfg.py:144
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: BxTiming.cc:245
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MonitorElement * hBxOccyAllFedSpread[nspr_]
Definition: BxTiming.h:98
BxTiming(const edm::ParameterSet &)
Definition: BxTiming.cc:4
tuple size
Write out results.
static const int nspr_
Definition: BxTiming.h:87
Definition: Run.h:45
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)