CMS 3D CMS Logo

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