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"));
21  histFile_ = iConfig.getUntrackedParameter<std::string>
22  ("HistFile","");
23  histFolder_ = iConfig.getUntrackedParameter<std::string>
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  //iEvent.getByType(rawdata);
273 
274  // get the GT bits
276  iEvent.getByLabel(gtSource_, gtdata);
277  std::vector<bool> gtbits;
278  int ngtbits = 128;
279  gtbits.reserve(ngtbits); for(int i=0; i<ngtbits; i++) gtbits[i]=false;
280  if(gtdata.isValid())
281  gtbits = gtdata->decisionWord();
282 
283  if(gtbits.size()==0) {
284  gtbits.push_back(true); // gtdata->decision();
285  if(verbose())
286  std::cout << "BxTiming::analyze() | unexpected empty decision bits!";
287  }
288 
289  if(verbose()) {
290  std::cout << "BxTiming::analyze() gt data valid:" << (int)(gtdata.isValid()?0:1)
291  << " decision word size:" << (int)(gtbits.size()) << " bits: ";
292  for(size_t i=0; i!=gtbits.size(); i++) {
293  int ii = gtbits.at(i)? 1:0;
294  std::cout << ii;
295  }
296  std::cout << ".\n" << std::flush;
297  }
298 
299 
300  // get reference bx
301  int bxRef = FEDHeader(rawdata->FEDData(fedRef_).data()).bxID();
302 
303  // triggerType
304  //trigger types: physics (1), calibration (2), random (3), traced physics (5), test (6)
305  int ttype = FEDHeader(rawdata->FEDData(812).data()).triggerType();
306 
307  // loop over feds
308  for (int i = 0; i<FEDNumbering::MAXFEDID; i++){
309  const FEDRawData& data = rawdata->FEDData(i);
310  size_t size=data.size();
311 
312  if(!size) continue;
313  FEDHeader header(data.data());
314  //int lvl1id = header.lvl1ID();//Level-1 event number generated by the TTC system
315  int bx = header.bxID(); // The bunch crossing number
316 
317  int bxDiff = calcBxDiff(bx,bxRef); // deviation from reference bx
318 
319  //min
320  if(nBxDiff[i][1]>bxDiff) nBxDiff[i][1] = bxDiff;
321  if(nBxOccy[i][1]>bx ) nBxOccy[i][1] = bx;
322  //max
323  if(nBxDiff[i][2]<bxDiff) nBxDiff[i][2] = bxDiff;
324  if(nBxOccy[i][2]<bx ) nBxOccy[i][2] = bx;
325 
326  if(verbose())
327  std::cout << " fed:" << i
328  << " bx:" << bx
329  << " bxRef:" << bxRef
330  << " diff:" << bxDiff
331  << " nBxDiff"<<" del:"<<nBxDiff[i][0]<<" min:"<<nBxDiff[i][1]<<" max:"<<nBxDiff[i][2]
332  << " nBxOccy"<<" del:"<<nBxOccy[i][0]<<" min:"<<nBxOccy[i][1]<<" max:"<<nBxOccy[i][2]
333  << "\n" << std::flush;
334 
335  hBxDiffAllFed->Fill(i,bxDiff);
336 
337  //if(ttype==1) //skip if not a physics trigger
338  hBxOccyAllFed->Fill(bx);
339 
340 
341  // done if running in filter farm
342  if(runInFF_)
343  continue;
344 
345  for(int j=0; j<NSYS; j++)
346  if(i>=fedRange_[j].first && i<=fedRange_[j].second)
347  hBxDiffSysFed[j]->Fill(i,bxDiff);
348 
349  for(size_t k=0; k!=listGtBits_.size(); k++) {
350  if((int)gtbits.size() <= listGtBits_.at(k)) {
351  if(verbose())
352  std::cout << "BxTiming analyze | problem with vector size!\n" << std::endl;
353  continue;
354  }
355  else if(!gtbits.at(listGtBits_.at(k)))
356  continue;
357  for(int j=0; j<NSYS; j++) {
358  if(i>=fedRange_[j].first && i<=fedRange_[j].second) {
359  hBxOccyTrigBit[j][k]->Fill(bx);
360  }
361  }
362  }
363 
364  if(i>=fedRange_[GLT].first && i<=fedRange_[GLT].second) //GT fed
365  if(ttype<nttype_)
366  hBxOccyGtTrigType[ttype-1]->Fill(bx);
367 
368  if(ttype!=1) continue; //skip if not a physics trigger
369  //hBxOccyAllFed->Fill(bx);
370  hBxOccyOneFed[i]->Fill(bx);
371 
372  }
373 
374  for(int i=0; i<nfed_;i++) {
375  nBxDiff[i][0]=nBxDiff[i][2]-nBxDiff[i][1];
376  nBxOccy[i][0]=nBxOccy[i][2]-nBxOccy[i][1];
377  if(nBxDiff[i][0]<0 || nBxOccy[i][0]<0) continue;
378  for(int j=0; j<nspr_; j++) {
379  hBxDiffAllFedSpread[j]->setBinContent(i,nBxDiff[i][j]);
380  hBxOccyAllFedSpread[j]->setBinContent(i,nBxOccy[i][j]);
381  }
382  if(verbose())
383  std::cout << "BxTiming fed:" << i
384  << " Bx-Bx(" << fedRef_ << ")::"
385  << " del:" << nBxDiff[i][0]
386  << " min:" << nBxDiff[i][1]
387  << " max:" << nBxDiff[i][2]
388  << " Occy: "
389  << " del:" << nBxOccy[i][0]
390  << " min:" << nBxOccy[i][1]
391  << " max:" << nBxOccy[i][2]
392  <<"\n" << std::flush;
393 
394  }
395 
396 
397  if(verbose())
398  std::cout << "BxTiming::analyze() end.\n" << std::flush;
399 }
400 
401 //----------------------------------------------------------------------
402 
403 int
404 BxTiming::calcBxDiff(int bx1, int bx2)
405 {
406  int diff = bx1 - bx2;
407 
408  while (diff < -half_norb_)
409  diff += norb_;
410 
411  while (diff > half_norb_)
412  diff -= norb_;
413 
414  return diff;
415 }
416 
417 //----------------------------------------------------------------------
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:519
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:1883
int verbose()
Definition: BxTiming.h:46
std::string histFile_
Definition: BxTiming.h:60
#define NULL
Definition: scimark2.h:8
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:47
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:833
void setVerbose(unsigned level)
Definition: DQMStore.cc:201
edm::InputTag fedSource_
Definition: BxTiming.h:41
bool first
Definition: L1TdeRCT.cc:79
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:359
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
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:404
tuple cout
Definition: gather_cfg.py:41
virtual void endJob()
Definition: BxTiming.cc:247
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:237
static const int nspr_
Definition: BxTiming.h:87