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 
60  for(int i=0; i<nfed_;i++) {
61  nBxDiff[i][0]=0; nBxDiff[i][1]=nbig_; nBxDiff[i][2]=-1*nbig_;
62  nBxOccy[i][0]=0; nBxOccy[i][1]=nbig_; nBxOccy[i][2]=-1*nbig_;
63  }
64 
65  std::string lbl("");
66  std::string SysLabel[NSYS] = {
67  "PreShower", "ECAL", "HCAL", "GCT", "CSCTPG", "CSCTF", "DTTPG", "DTTF", "RPC", "GT"
68  };
69 
70  typedef std::pair<int, int> FEDRange;
71 
72  std::pair<int,int> fedRange[NSYS] = {
83  };
84  for(int i=0; i<NSYS; i++) fedRange_[i]=fedRange[i];
85 
86 
87  int fedRefSys=-1;
88  for(int i=0; i<NSYS; i++)
90  {fedRefSys=i; break;}
91  std::string refName("");
92  std::string spreadLabel[nspr_] = {"Spread","Min", "Max"};
93  if(fedRefSys>=0)
94  refName+=SysLabel[fedRefSys];
95  else
96  refName+=fedRef_;
97 
99 
100  const int dbx = nbig_;
101 
102  ibooker.setCurrentFolder(histFolder_);
103 
104  hBxDiffAllFed = ibooker.bookProfile("BxDiffAllFed", "BxDiffAllFed",
105  nfed_ + 1, -0.5, nfed_+0.5,
106  2*dbx+1, -1*dbx-0.5,dbx+0.5
107  );
108 
109  for(int i=0; i<nspr_; i++) {
110  lbl.clear();lbl+="BxDiffAllFed";lbl+=spreadLabel[i];
111  hBxDiffAllFedSpread[i] = ibooker.book1D(lbl.data(),lbl.data(), nfed_ + 1, -0.5, nfed_+0.5);
112  lbl.clear();lbl+="BxOccyAllFed";lbl+=spreadLabel[i];
113  hBxOccyAllFedSpread[i] = ibooker.book1D(lbl.data(),lbl.data(), nfed_ + 1, -0.5, nfed_+0.5);
114 
115  lbl.clear();lbl+="BxOccyAllFed";
116  hBxOccyAllFed = ibooker.book1D(lbl.data(),lbl.data(),norb_+1,-0.5,norb_+0.5);
117 
118  }
119 
120  // following histos defined only when not runing in the ff
121  if(!runInFF_) {
122 
123  ibooker.setCurrentFolder(histFolder_);
124 
125  for(int i=0; i<NSYS; i++) {
126  lbl.clear();lbl+=SysLabel[i];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(),lbl.data(), nfeds,
130  fedRange_[i].first-0.5, fedRange_[i].second+0.5,
131  2*dbx+1,-1*dbx-0.5,dbx+0.5);
132 
133  }
134 
135 
136  lbl.clear();lbl+="BxOccyAllFed";
138  ibooker.setCurrentFolder(histFolder_+"/SingleFed");
139  for(int i=0; i<nfed_; i++) {
140  lbl.clear(); lbl+="BxOccyOneFed";
141  char *ii = new char[1000]; std::sprintf(ii,"%d",i);lbl+=ii;
142  hBxOccyOneFed[i] = ibooker.book1D(lbl.data(),lbl.data(),norb_+1,-0.5,norb_+0.5);
143  delete [] ii;
144  }
145 
146  ibooker.setCurrentFolder(histFolder_);
147  for(int i=0; i<nttype_; i++) {
148  lbl.clear();lbl+="BxOccyGtTrigType";
149  char *ii = new char[10]; std::sprintf(ii,"%d",i+1);lbl+=ii;
150  hBxOccyGtTrigType[i] = ibooker.book1D(lbl.data(),lbl.data(),norb_+1,-0.5,norb_+0.5);
151  delete [] ii;
152  }
153 
154  ibooker.setCurrentFolder(histFolder_+"/SingleBit");
155  for(int i=0; i<NSYS; i++) {
156  hBxOccyTrigBit[i] = new MonitorElement*[listGtBits_.size()];
157  for(size_t j=0; j<listGtBits_.size(); j++) {
158  lbl.clear();lbl+=SysLabel[i];lbl+="BxOccyGtBit";
159  char *ii = new char[1000]; std::sprintf(ii,"%d",listGtBits_.at(j)); lbl+=ii;
160  hBxOccyTrigBit[i][j] = ibooker.book1D(lbl.data(),lbl.data(),norb_+1,-0.5,norb_+0.5);
161  delete [] ii;
162  }
163  }
164 
165  }
166 
168  hBxDiffAllFed->setAxisTitle("FED ID",1);
169  lbl.clear(); lbl+="BX(fed)-BX("; lbl+=refName; lbl+=")";
170  hBxDiffAllFed->setAxisTitle(lbl,2);
171  for(int i=0; i<nspr_; i++) {
172  lbl.clear(); lbl+="BX(fed)-BX("; lbl+=refName; lbl+=") "+spreadLabel[i];
173  hBxDiffAllFedSpread[i]->setAxisTitle("FED ID",1);
175  lbl.clear(); lbl+="Bx FED occupancy"; lbl+=" "; lbl+=spreadLabel[i];
176  hBxOccyAllFedSpread[i]->setAxisTitle("FED ID",1);
178  }
179 
180  hBxOccyAllFed->setAxisTitle("bx",1);
181  lbl.clear(); lbl+="Combined FED occupancy";
182  hBxOccyAllFed->setAxisTitle(lbl,2);
183 
184  // skip next if running in filter farm
185  if(runInFF_)
186  return;
187 
188  for(int i=0; i<NSYS; i++) {
189  lbl.clear(); lbl+=SysLabel[i]; lbl+=" FED ID";
190  hBxDiffSysFed[i]->setAxisTitle(lbl,1);
191  lbl.clear(); lbl+="BX("; lbl+=SysLabel[i]; lbl+=")-BX(";lbl+=refName; lbl+=")";
192  hBxDiffSysFed[i]->setAxisTitle(lbl,2);
193  }
194 
195  for(int i=0; i<nfed_; i++) {
196  hBxOccyOneFed[i] ->setAxisTitle("bx",1);
197  lbl.clear(); lbl+=" FED "; char *ii = new char[1000]; std::sprintf(ii,"%d",i);lbl+=ii; lbl+=" occupancy";
198  hBxOccyOneFed[i] ->setAxisTitle(lbl,2);
199  delete [] ii;
200  }
201  for(int i=0; i<nttype_; i++) {
202  hBxOccyGtTrigType[i]->setAxisTitle("bx",1);
203  lbl.clear(); lbl+="GT occupancy for trigger type "; char *ii = new char[10]; std::sprintf(ii,"%d",i+1);lbl+=ii;
205  delete [] ii;
206  }
207 
208  for(int i=0; i<NSYS; i++) {
209  for(size_t j=0; j<listGtBits_.size(); j++) {
210  hBxOccyTrigBit[i][j]->setAxisTitle("bx",1);
211  lbl.clear();lbl+=SysLabel[i];lbl+=" Bx occupancy for Trigger bit ";
212  char *ii = new char[10]; std::sprintf(ii,"%d",listGtBits_.at(j)); lbl+=ii;
213  hBxOccyTrigBit[i][j]->setAxisTitle(lbl,2);
214  delete [] ii;
215  }
216  }
217 }
218 
219 void
221 
222 }
223 
224 // ------------ method called to for each event ------------
225 void
227 
228  if(verbose())
229  std::cout << "BxTiming::analyze() start\n" << std::flush;
230 
231  nEvt_++;
232 
235  iEvent.getByToken(fedSource_token_, rawdata);
236 
237  if (!rawdata.isValid()) {
238 
239  if (verbose())
240  std::cout
241  << "BxTiming::analyze() | FEDRawDataCollection with input tag "
242  << fedSource_ << " not found.";
243 
244  return;
245  }
246 
247  // get the GT bits
249  iEvent.getByToken(gtSource_token_, gtdata);
250  std::vector<bool> gtbits;
251  int ngtbits = 128;
252  gtbits.reserve(ngtbits); for(int i=0; i<ngtbits; i++) gtbits[i]=false;
253  if(gtdata.isValid())
254  gtbits = gtdata->decisionWord();
255 
256  if(gtbits.size()==0) {
257  gtbits.push_back(true); // gtdata->decision();
258  if(verbose())
259  std::cout << "BxTiming::analyze() | unexpected empty decision bits!";
260  }
261 
262  if(verbose()) {
263  std::cout << "BxTiming::analyze() gt data valid:" << (int)(gtdata.isValid()?0:1)
264  << " decision word size:" << (int)(gtbits.size()) << " bits: ";
265  for(size_t i=0; i!=gtbits.size(); i++) {
266  int ii = gtbits.at(i)? 1:0;
267  std::cout << ii;
268  }
269  std::cout << ".\n" << std::flush;
270  }
271 
272 
273  // get reference bx
274  int bxRef = FEDHeader(rawdata->FEDData(fedRef_).data()).bxID();
275 
276  // triggerType
277  // trigger types: physics (1), calibration (2), random (3), traced physics (5), test (6)
278  int ttype = static_cast<double> (iEvent.eventAuxiliary().experimentType());
279 
280  // loop over feds
281  for (int i = 0; i<FEDNumbering::MAXFEDID+1; i++){
282  const FEDRawData& data = rawdata->FEDData(i);
283  size_t size=data.size();
284 
285  if(!size) continue;
286  FEDHeader header(data.data());
287  //int lvl1id = header.lvl1ID(); //Level-1 event number generated by the TTC system
288  int bx = header.bxID(); // The bunch crossing number
289 
290  int bxDiff = calcBxDiff(bx,bxRef); // deviation from reference bx
291 
292  //min
293  if(nBxDiff[i][1]>bxDiff) nBxDiff[i][1] = bxDiff;
294  if(nBxOccy[i][1]>bx ) nBxOccy[i][1] = bx;
295  //max
296  if(nBxDiff[i][2]<bxDiff) nBxDiff[i][2] = bxDiff;
297  if(nBxOccy[i][2]<bx ) nBxOccy[i][2] = bx;
298 
299  if(verbose())
300  std::cout << " fed:" << i
301  << " bx:" << bx
302  << " bxRef:" << bxRef
303  << " diff:" << bxDiff
304  << " nBxDiff"<<" del:"<<nBxDiff[i][0]<<" min:"<<nBxDiff[i][1]<<" max:"<<nBxDiff[i][2]
305  << " nBxOccy"<<" del:"<<nBxOccy[i][0]<<" min:"<<nBxOccy[i][1]<<" max:"<<nBxOccy[i][2]
306  << "\n" << std::flush;
307 
308  hBxDiffAllFed->Fill(i,bxDiff);
309 
310  //if(ttype==1) //skip if not a physics trigger
311  hBxOccyAllFed->Fill(bx);
312 
313 
314  // done if running in filter farm
315  if(runInFF_)
316  continue;
317 
318  for(int j=0; j<NSYS; j++)
319  if(i>=fedRange_[j].first && i<=fedRange_[j].second)
320  hBxDiffSysFed[j]->Fill(i,bxDiff);
321 
322  for(size_t k=0; k!=listGtBits_.size(); k++) {
323  if((int)gtbits.size() <= listGtBits_.at(k)) {
324  if(verbose())
325  std::cout << "BxTiming analyze | problem with vector size!\n" << std::endl;
326  continue;
327  }
328  else if(!gtbits.at(listGtBits_.at(k)))
329  continue;
330  for(int j=0; j<NSYS; j++) {
331  if(i>=fedRange_[j].first && i<=fedRange_[j].second) {
332  hBxOccyTrigBit[j][k]->Fill(bx);
333  }
334  }
335  }
336 
337  if(i>=fedRange_[GLT].first && i<=fedRange_[GLT].second) //GT fed
338  if(ttype<nttype_)
339  hBxOccyGtTrigType[ttype-1]->Fill(bx);
340 
341  if(ttype!=1) continue; //skip if not a physics trigger
342  //hBxOccyAllFed->Fill(bx);
343  hBxOccyOneFed[i]->Fill(bx);
344 
345  }
346 
347  for(int i=0; i<nfed_;i++) {
348  nBxDiff[i][0]=nBxDiff[i][2]-nBxDiff[i][1];
349  nBxOccy[i][0]=nBxOccy[i][2]-nBxOccy[i][1];
350  if(nBxDiff[i][0]<0 || nBxOccy[i][0]<0) continue;
351  for(int j=0; j<nspr_; j++) {
352  hBxDiffAllFedSpread[j]->setBinContent(i,nBxDiff[i][j]);
353  hBxOccyAllFedSpread[j]->setBinContent(i,nBxOccy[i][j]);
354  }
355  if(verbose())
356  std::cout << "BxTiming fed:" << i
357  << " Bx-Bx(" << fedRef_ << ")::"
358  << " del:" << nBxDiff[i][0]
359  << " min:" << nBxDiff[i][1]
360  << " max:" << nBxDiff[i][2]
361  << " Occy: "
362  << " del:" << nBxOccy[i][0]
363  << " min:" << nBxOccy[i][1]
364  << " max:" << nBxOccy[i][2]
365  <<"\n" << std::flush;
366 
367  }
368 
369 
370  if(verbose())
371  std::cout << "BxTiming::analyze() end.\n" << std::flush;
372 }
373 
374 //----------------------------------------------------------------------
375 
376 int
377 BxTiming::calcBxDiff(int bx1, int bx2)
378 {
379  int diff = bx1 - bx2;
380 
381  while (diff < -half_norb_)
382  diff += norb_;
383 
384  while (diff > half_norb_)
385  diff -= norb_;
386 
387  return diff;
388 }
389 
390 //----------------------------------------------------------------------
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:220
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:462
std::vector< int > listGtBits_
Definition: BxTiming.h:87
int verbose()
Definition: BxTiming.h:57
#define nfed_
Definition: BxTiming.h:32
std::string histFile_
Definition: BxTiming.h:71
int ii
Definition: cuy.py:588
list diff
Definition: mps_update.py:85
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:226
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:77
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:276
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:377
int nBxDiff[FEDNumbering::MAXFEDID+1][nspr_]
Definition: BxTiming.h:96
tuple cout
Definition: gather_cfg.py:145
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:43