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 
8 #include <cstdio>
9 
11 
12  verbose_ = iConfig.getUntrackedParameter<int>("VerboseFlag",0);
13  if(verbose())
14  std::cout << "BxTiming::BxTiming()...\n" << std::flush;
15 
16  fedRef_ = iConfig.getUntrackedParameter<int>("ReferenceFedId",813);
18  ("FedSource",edm::InputTag("source"));
20  ("GtSource",edm::InputTag("gtUnpack"));
22  ("HistFile","");
24  ("HistFolder", "L1T/BXSynch");
25 
26  runInFF_ = iConfig.getUntrackedParameter<bool> ("RunInFilterFarm", true);
27  if(runInFF_) histFolder_ = "L1T/BXSynch_EvF";
28  if(verbose())
29  std::cout << "Filter farm run setting?" << runInFF_
30  << "\n" << std::flush;
31 
32  listGtBits_ = iConfig.getUntrackedParameter<std::vector<int> > ("GtBitList", std::vector<int>(1,0));
33  if(listGtBits_.size()==1 && listGtBits_.at(0)==-1) {
34  int ngtbits = 128;
35  listGtBits_.reserve(ngtbits);
36  for(int i=0; i<ngtbits; i++)
37  listGtBits_[i]=i;
38  }
39 
40  if(verbose()) {
41  std::cout << "BxTiming: gt bits set for timing dqm:";
42  std::cout << "nbits:" << listGtBits_.size() << " list: " ;
43  for(size_t i=0; i!=listGtBits_.size(); i++)
44  std::cout << listGtBits_.at(i) << " " ;
45  std::cout << "\n" << std::flush;
46  }
47 
49 
50  dbe = NULL;
51  if (iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
53  dbe->setVerbose(0);
54  }
55 
56  if(dbe!=NULL)
57  dbe->setCurrentFolder(histFolder_);
58 
59  nEvt_ = 0;
60 
61  if(verbose())
62  std::cout << "BxTiming::BxTiming constructor...done.\n" << std::flush;
63 }
64 
66 
67 void
69 
70  if(verbose())
71  std::cout << "BxTiming::beginJob() start\n" << std::flush;
72 
73  DQMStore* dbe = 0;
74  dbe = edm::Service<DQMStore>().operator->();
75  if(dbe) {
77  //dbe->rmdir(histFolder_);
78  }
79 
81  for(int i=0; i<nfed_;i++) {
82  nBxDiff[i][0]=0; nBxDiff[i][1]=nbig_; nBxDiff[i][2]=-1*nbig_;
83  nBxOccy[i][0]=0; nBxOccy[i][1]=nbig_; nBxOccy[i][2]=-1*nbig_;
84  }
85 
86  std::string lbl("");
87  std::string SysLabel[NSYS] = {
88  "PreShower", "ECAL", "HCAL", "GCT", "CSCTPG", "CSCTF", "DTTPG", "DTTF", "RPC", "GT"
89  };
90 
91  typedef std::pair<int, int> FEDRange;
92 
93  std::pair<int,int> fedRange[NSYS] = {
104  };
105  for(int i=0; i<NSYS; i++) fedRange_[i]=fedRange[i];
106 
107 
108  int fedRefSys=-1;
109  for(int i=0; i<NSYS; i++)
111  {fedRefSys=i; break;}
112  std::string refName("");
113  std::string spreadLabel[nspr_] = {"Spread","Min", "Max"};
114  if(fedRefSys>=0)
115  refName+=SysLabel[fedRefSys];
116  else
117  refName+=fedRef_;
118 
120 
121  const int dbx = nbig_;
122 
123  if(dbe) {
124 
126 
127  hBxDiffAllFed = dbe->bookProfile("BxDiffAllFed", "BxDiffAllFed",
128  nfed_ + 1, -0.5, nfed_+0.5,
129  2*dbx+1, -1*dbx-0.5,dbx+0.5
130  );
131 
132  for(int i=0; i<nspr_; i++) {
133  lbl.clear();lbl+="BxDiffAllFed";lbl+=spreadLabel[i];
134  hBxDiffAllFedSpread[i] = dbe->book1D(lbl.data(),lbl.data(), nfed_ + 1, -0.5, nfed_+0.5);
135  lbl.clear();lbl+="BxOccyAllFed";lbl+=spreadLabel[i];
136  hBxOccyAllFedSpread[i] = dbe->book1D(lbl.data(),lbl.data(), nfed_ + 1, -0.5, nfed_+0.5);
137  }
138 
139  lbl.clear();lbl+="BxOccyAllFed";
140  hBxOccyAllFed = dbe->book1D(lbl.data(),lbl.data(),norb_+1,-0.5,norb_+0.5);
141 
142  }
143 
144  // following histos defined only when not runing in the ff
145  if(dbe && !runInFF_) {
146 
148 
149  for(int i=0; i<NSYS; i++) {
150  lbl.clear();lbl+=SysLabel[i];lbl+="FedBxDiff";
151  int nfeds = fedRange_[i].second - fedRange_[i].first + 1;
152  nfeds = (nfeds>0)? nfeds:1;
153  hBxDiffSysFed[i] = dbe->bookProfile(lbl.data(),lbl.data(), nfeds,
154  fedRange_[i].first-0.5, fedRange_[i].second+0.5,
155  2*dbx+1,-1*dbx-0.5,dbx+0.5);
156 
157  }
158 
159 
160  lbl.clear();lbl+="BxOccyAllFed";
162  dbe->setCurrentFolder(histFolder_+"/SingleFed");
163  for(int i=0; i<nfed_; i++) {
164  lbl.clear(); lbl+="BxOccyOneFed";
165  char *ii = new char[1000]; std::sprintf(ii,"%d",i);lbl+=ii;
166  hBxOccyOneFed[i] = dbe->book1D(lbl.data(),lbl.data(),norb_+1,-0.5,norb_+0.5);
167  delete [] ii;
168  }
169 
171  for(int i=0; i<nttype_; i++) {
172  lbl.clear();lbl+="BxOccyGtTrigType";
173  char *ii = new char[10]; std::sprintf(ii,"%d",i+1);lbl+=ii;
174  hBxOccyGtTrigType[i] = dbe->book1D(lbl.data(),lbl.data(),norb_+1,-0.5,norb_+0.5);
175  delete [] ii;
176  }
177 
178  dbe->setCurrentFolder(histFolder_+"/SingleBit");
179  for(int i=0; i<NSYS; i++) {
180  hBxOccyTrigBit[i] = new MonitorElement*[listGtBits_.size()];
181  for(size_t j=0; j<listGtBits_.size(); j++) {
182  lbl.clear();lbl+=SysLabel[i];lbl+="BxOccyGtBit";
183  char *ii = new char[1000]; std::sprintf(ii,"%d",listGtBits_.at(j)); lbl+=ii;
184  hBxOccyTrigBit[i][j] = dbe->book1D(lbl.data(),lbl.data(),norb_+1,-0.5,norb_+0.5);
185  delete [] ii;
186  }
187  }
188 
189  }
190 
192  hBxDiffAllFed->setAxisTitle("FED ID",1);
193  lbl.clear(); lbl+="BX(fed)-BX("; lbl+=refName; lbl+=")";
194  hBxDiffAllFed->setAxisTitle(lbl,2);
195  for(int i=0; i<nspr_; i++) {
196  lbl.clear(); lbl+="BX(fed)-BX("; lbl+=refName; lbl+=") "+spreadLabel[i];
197  hBxDiffAllFedSpread[i]->setAxisTitle("FED ID",1);
199  lbl.clear(); lbl+="Bx FED occupancy"; lbl+=" "; lbl+=spreadLabel[i];
200  hBxOccyAllFedSpread[i]->setAxisTitle("FED ID",1);
202  }
203 
204  hBxOccyAllFed->setAxisTitle("bx",1);
205  lbl.clear(); lbl+="Combined FED occupancy";
206  hBxOccyAllFed->setAxisTitle(lbl,2);
207 
208  // skip next if running in filter farm
209  if(runInFF_)
210  return;
211 
212  for(int i=0; i<NSYS; i++) {
213  lbl.clear(); lbl+=SysLabel[i]; lbl+=" FED ID";
214  hBxDiffSysFed[i]->setAxisTitle(lbl,1);
215  lbl.clear(); lbl+="BX("; lbl+=SysLabel[i]; lbl+=")-BX(";lbl+=refName; lbl+=")";
216  hBxDiffSysFed[i]->setAxisTitle(lbl,2);
217  }
218 
219  for(int i=0; i<nfed_; i++) {
220  hBxOccyOneFed[i] ->setAxisTitle("bx",1);
221  lbl.clear(); lbl+=" FED "; char *ii = new char[1000]; std::sprintf(ii,"%d",i);lbl+=ii; lbl+=" occupancy";
222  hBxOccyOneFed[i] ->setAxisTitle(lbl,2);
223  delete [] ii;
224  }
225  for(int i=0; i<nttype_; i++) {
226  hBxOccyGtTrigType[i]->setAxisTitle("bx",1);
227  lbl.clear(); lbl+="GT occupancy for trigger type "; char *ii = new char[10]; std::sprintf(ii,"%d",i+1);lbl+=ii;
229  delete [] ii;
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();lbl+=SysLabel[i];lbl+=" Bx occupancy for Trigger bit ";
236  char *ii = new char[10]; std::sprintf(ii,"%d",listGtBits_.at(j)); lbl+=ii;
237  hBxOccyTrigBit[i][j]->setAxisTitle(lbl,2);
238  delete [] ii;
239  }
240  }
241 
242  if(verbose())
243  std::cout << "BxTiming::beginJob() end.\n" << std::flush;
244 }
245 
246 void
248 
249  if(verbose())
250  std::cout << "BxTiming::endJob Nevents: " << nEvt_ << "\n" << std::flush;
251 
252  if(histFile_.size()!=0 && dbe)
253  dbe->save(histFile_);
254 
255  if(verbose())
256  std::cout << "BxTiming::endJob() end.\n" << std::flush;
257 }
258 
259 
260 // ------------ method called to for each event ------------
261 void
263 
264  if(verbose())
265  std::cout << "BxTiming::analyze() start\n" << std::flush;
266 
267  nEvt_++;
268 
271  iEvent.getByLabel(fedSource_, rawdata);
272 
273  if (!rawdata.isValid()) {
274 
275  if (verbose())
276  std::cout
277  << "BxTiming::analyze() | FEDRawDataCollection with input tag "
278  << fedSource_ << " not found.";
279 
280  return;
281  }
282 
283  // get the GT bits
285  iEvent.getByLabel(gtSource_, gtdata);
286  std::vector<bool> gtbits;
287  int ngtbits = 128;
288  gtbits.reserve(ngtbits); for(int i=0; i<ngtbits; i++) gtbits[i]=false;
289  if(gtdata.isValid())
290  gtbits = gtdata->decisionWord();
291 
292  if(gtbits.size()==0) {
293  gtbits.push_back(true); // gtdata->decision();
294  if(verbose())
295  std::cout << "BxTiming::analyze() | unexpected empty decision bits!";
296  }
297 
298  if(verbose()) {
299  std::cout << "BxTiming::analyze() gt data valid:" << (int)(gtdata.isValid()?0:1)
300  << " decision word size:" << (int)(gtbits.size()) << " bits: ";
301  for(size_t i=0; i!=gtbits.size(); i++) {
302  int ii = gtbits.at(i)? 1:0;
303  std::cout << ii;
304  }
305  std::cout << ".\n" << std::flush;
306  }
307 
308 
309  // get reference bx
310  int bxRef = FEDHeader(rawdata->FEDData(fedRef_).data()).bxID();
311 
312  // triggerType
313  //trigger types: physics (1), calibration (2), random (3), traced physics (5), test (6)
314  int ttype = FEDHeader(rawdata->FEDData(812).data()).triggerType();
315 
316  // loop over feds
317  for (int i = 0; i<FEDNumbering::MAXFEDID+1; i++){
318  const FEDRawData& data = rawdata->FEDData(i);
319  size_t size=data.size();
320 
321  if(!size) continue;
322  FEDHeader header(data.data());
323  //int lvl1id = header.lvl1ID();//Level-1 event number generated by the TTC system
324  int bx = header.bxID(); // The bunch crossing number
325 
326  int bxDiff = calcBxDiff(bx,bxRef); // deviation from reference bx
327 
328  //min
329  if(nBxDiff[i][1]>bxDiff) nBxDiff[i][1] = bxDiff;
330  if(nBxOccy[i][1]>bx ) nBxOccy[i][1] = bx;
331  //max
332  if(nBxDiff[i][2]<bxDiff) nBxDiff[i][2] = bxDiff;
333  if(nBxOccy[i][2]<bx ) nBxOccy[i][2] = bx;
334 
335  if(verbose())
336  std::cout << " fed:" << i
337  << " bx:" << bx
338  << " bxRef:" << bxRef
339  << " diff:" << bxDiff
340  << " nBxDiff"<<" del:"<<nBxDiff[i][0]<<" min:"<<nBxDiff[i][1]<<" max:"<<nBxDiff[i][2]
341  << " nBxOccy"<<" del:"<<nBxOccy[i][0]<<" min:"<<nBxOccy[i][1]<<" max:"<<nBxOccy[i][2]
342  << "\n" << std::flush;
343 
344  hBxDiffAllFed->Fill(i,bxDiff);
345 
346  //if(ttype==1) //skip if not a physics trigger
347  hBxOccyAllFed->Fill(bx);
348 
349 
350  // done if running in filter farm
351  if(runInFF_)
352  continue;
353 
354  for(int j=0; j<NSYS; j++)
355  if(i>=fedRange_[j].first && i<=fedRange_[j].second)
356  hBxDiffSysFed[j]->Fill(i,bxDiff);
357 
358  for(size_t k=0; k!=listGtBits_.size(); k++) {
359  if((int)gtbits.size() <= listGtBits_.at(k)) {
360  if(verbose())
361  std::cout << "BxTiming analyze | problem with vector size!\n" << std::endl;
362  continue;
363  }
364  else if(!gtbits.at(listGtBits_.at(k)))
365  continue;
366  for(int j=0; j<NSYS; j++) {
367  if(i>=fedRange_[j].first && i<=fedRange_[j].second) {
368  hBxOccyTrigBit[j][k]->Fill(bx);
369  }
370  }
371  }
372 
373  if(i>=fedRange_[GLT].first && i<=fedRange_[GLT].second) //GT fed
374  if(ttype<nttype_)
375  hBxOccyGtTrigType[ttype-1]->Fill(bx);
376 
377  if(ttype!=1) continue; //skip if not a physics trigger
378  //hBxOccyAllFed->Fill(bx);
379  hBxOccyOneFed[i]->Fill(bx);
380 
381  }
382 
383  for(int i=0; i<nfed_;i++) {
384  nBxDiff[i][0]=nBxDiff[i][2]-nBxDiff[i][1];
385  nBxOccy[i][0]=nBxOccy[i][2]-nBxOccy[i][1];
386  if(nBxDiff[i][0]<0 || nBxOccy[i][0]<0) continue;
387  for(int j=0; j<nspr_; j++) {
388  hBxDiffAllFedSpread[j]->setBinContent(i,nBxDiff[i][j]);
389  hBxOccyAllFedSpread[j]->setBinContent(i,nBxOccy[i][j]);
390  }
391  if(verbose())
392  std::cout << "BxTiming fed:" << i
393  << " Bx-Bx(" << fedRef_ << ")::"
394  << " del:" << nBxDiff[i][0]
395  << " min:" << nBxDiff[i][1]
396  << " max:" << nBxDiff[i][2]
397  << " Occy: "
398  << " del:" << nBxOccy[i][0]
399  << " min:" << nBxOccy[i][1]
400  << " max:" << nBxOccy[i][2]
401  <<"\n" << std::flush;
402 
403  }
404 
405 
406  if(verbose())
407  std::cout << "BxTiming::analyze() end.\n" << std::flush;
408 }
409 
410 //----------------------------------------------------------------------
411 
412 int
413 BxTiming::calcBxDiff(int bx1, int bx2)
414 {
415  int diff = bx1 - bx2;
416 
417  while (diff < -half_norb_)
418  diff += norb_;
419 
420  while (diff > half_norb_)
421  diff -= norb_;
422 
423  return diff;
424 }
425 
426 //----------------------------------------------------------------------
static const int nttype_
Definition: BxTiming.h:76
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
static const int norb_
Definition: BxTiming.h:72
DQMStore * dbe
Definition: BxTiming.h:66
MonitorElement * hBxDiffAllFed
histograms
Definition: BxTiming.h:92
void setBinContent(int binx, double content)
set content of bin (1-D)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
MonitorElement * hBxDiffAllFedSpread[nspr_]
Definition: BxTiming.h:97
std::vector< int > listGtBits_
Definition: BxTiming.h:78
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2118
int verbose()
Definition: BxTiming.h:46
std::string histFile_
Definition: BxTiming.h:60
#define NULL
Definition: scimark2.h:8
int ii
Definition: cuy.py:588
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:49
static const int nbig_
Definition: BxTiming.h:75
void Fill(long long x)
int nBxOccy[1500][nspr_]
Definition: BxTiming.h:89
U second(std::pair< T, U > const &p)
virtual void beginJob(void)
Definition: BxTiming.cc:68
MonitorElement * hBxOccyGtTrigType[nttype_]
Definition: BxTiming.h:100
int iEvent
Definition: GenABIO.cc:243
int nEvt_
Definition: BxTiming.h:57
int verbose_
Definition: BxTiming.h:45
int nBxDiff[1500][nspr_]
Definition: BxTiming.h:88
int j
Definition: DBlmapReader.cc:9
static const int half_norb_
Definition: BxTiming.h:73
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1036
void setVerbose(unsigned level)
Definition: DQMStore.cc:398
edm::InputTag fedSource_
Definition: BxTiming.h:41
bool first
Definition: L1TdeRCT.cc:94
bool isValid() const
Definition: HandleBase.h:76
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: BxTiming.cc:262
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
int k[5][pyjets_maxn]
bool runInFF_
Definition: BxTiming.h:69
std::string histFolder_
Definition: BxTiming.h:63
edm::InputTag gtSource_
Definition: BxTiming.h:42
int bxID()
The bunch crossing number.
Definition: FEDHeader.cc:26
int fedRef_
Definition: BxTiming.h:84
MonitorElement * hBxDiffSysFed[NSYS]
Definition: BxTiming.h:93
MonitorElement ** hBxOccyTrigBit[NSYS]
Definition: BxTiming.h:101
int nfed_
Definition: BxTiming.h:83
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:29
int calcBxDiff(int bx1, int bx2)
Definition: BxTiming.cc:413
tuple cout
Definition: gather_cfg.py:121
virtual void endJob()
Definition: BxTiming.cc:247
dictionary rawdata
Definition: lumiPlot.py:393
std::pair< int, int > fedRange_[NSYS]
Definition: BxTiming.h:82
MonitorElement * hBxOccyAllFedSpread[nspr_]
Definition: BxTiming.h:98
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:65
BxTiming(const edm::ParameterSet &)
Definition: BxTiming.cc:10
tuple size
Write out results.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
static const int nspr_
Definition: BxTiming.h:87