CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1Scalers.cc
Go to the documentation of this file.
1 #include <iostream>
2 
3 
4 // FW
6 
8 
10 
12 
13 // L1
15 
20 
21 
23 
24 
31 
32 // HACK START
36 // HACK END
37 
38 using namespace edm;
39 
40 
41 
43  dbe_(0), nev_(0),
44  verbose_(ps.getUntrackedParameter < bool > ("verbose", false)),
45  l1GtDataSource_( ps.getParameter< edm::InputTag >("l1GtData")),
46  denomIsTech_(ps.getUntrackedParameter <bool> ("denomIsTech", true)),
47  denomBit_(ps.getUntrackedParameter <unsigned int> ("denomBit", 40)),
48  tfIsTech_(ps.getUntrackedParameter <bool> ("tfIsTech", true)),
49  tfBit_(ps.getUntrackedParameter <unsigned int> ("tfBit", 41)),
50  algoSelected_(ps.getUntrackedParameter<std::vector<unsigned int> >("algoMonitorBits", std::vector<unsigned int>())),
51  techSelected_(ps.getUntrackedParameter<std::vector<unsigned int> >("techMonitorBits", std::vector<unsigned int>())),
52  folderName_( ps.getUntrackedParameter< std::string>("dqmFolder",
53  std::string("L1T/L1Scalers_EvF"))),
54  l1scalers_(0),
55  l1techScalers_(0),
56  l1Correlations_(0),
57  bxNum_(0),
58  l1scalersBx_(0),
59  l1techScalersBx_(0),
60 // pixFedSizeBx_(0),
61 // hfEnergyMaxTowerBx_(0),
62  nLumiBlock_(0),
63  l1AlgoCounter_(0),
64  l1TtCounter_(0),
65 // pixFedSize_(0),
66 // hfEnergy_(0),
67  fedStart_(ps.getUntrackedParameter<unsigned int>("firstFED", 0)),
68  fedStop_(ps.getUntrackedParameter<unsigned int>("lastFED", 931)),
69  rateAlgoCounter_(0),
70  rateTtCounter_(0),
71  fedRawCollection_(ps.getParameter<edm::InputTag>("fedRawData")),
72  maskedList_(ps.getUntrackedParameter<std::vector<int> >("maskedChannels", std::vector<int>())), //this is using the ashed index
73  HcalRecHitCollection_(ps.getParameter<edm::InputTag>("HFRecHitCollection"))
74 {
75  LogDebug("Status") << "constructor" ;
76 }
77 
78 
79 
80 
82 {
83  LogDebug("Status") << "L1Scalers::beginJob()...";
84 
86  if (dbe_ ) {
87  dbe_->setVerbose(0);
88  dbe_->setCurrentFolder(folderName_);
89 
90 
91  l1scalers_ = dbe_->book1D("l1AlgoBits", "L1 Algorithm Bits",
92  128, -0.5, 127.5);
93  l1scalersBx_ = dbe_->book2D("l1AlgoBits_Vs_Bx", "L1 Algorithm Bits vs "
94  "Bunch Number",
95  3600, -0.5, 3599.5,
96  128, -0.5, 127.5);
97  l1Correlations_ = dbe_->book2D("l1Correlations", "L1 Algorithm Bits "
98  "Correlations",
99  128, -0.5, 127.5,
100  128, -0.5, 127.5);
101  l1techScalers_ = dbe_->book1D("l1TechBits", "L1 Tech. Trigger Bits",
102  64, -0.5, 63.5);
103  l1techScalersBx_ = dbe_->book2D("l1TechBits_Vs_Bx", "L1 Technical "
104  "Trigger "
105  "Bits vs Bunch Number",
106  3600, -0.5, 3599.5, 64, -0.5, 63.5);
107 // pixFedSizeBx_ = dbe_->book2D("pixFedSize_Vs_Bx", "Size of Pixel FED data vs "
108 // "Bunch Number",
109 // 3600, -0.5, 3599.5,
110 // 200, 0., 20000.);
111 // hfEnergyMaxTowerBx_ = dbe_->book2D("hfEnergyMaxTower_Vs_Bx", "HF Energy Max Tower vs "
112 // "Bunch Number",
113 // 3600, -0.5, 3599.5,
114 // 100, 0., 500.);
115  bxNum_ = dbe_->book1D("bxNum", "Bunch number from GTFE",
116  3600, -0.5, 3599.5);
117 
118  nLumiBlock_ = dbe_->bookInt("nLumiBlock");
119 
120 // l1 total rate
121 
122  l1AlgoCounter_ = dbe_->bookInt("l1AlgoCounter");
123  l1TtCounter_ = dbe_->bookInt("l1TtCounter");
124 
125 
126  //int maxNbins = 200;
127  //int maxLumi = 2000;
128 
129  //timing plots
130  std::stringstream sdenom;
131  if(denomIsTech_) sdenom << "tech" ;
132  else sdenom << "algo" ;
133 
134  dbe_->setCurrentFolder(folderName_ + "/Synch");
135  algoBxDiff_.clear();
136  algoBxDiff_.clear();
137  algoBxDiffLumi_.clear();
138  techBxDiffLumi_.clear();
139  for(uint ibit = 0; ibit < algoSelected_.size(); ibit++){
140  std::stringstream ss;
141  ss << algoSelected_[ibit] << "_" << sdenom.str() << denomBit_;
142  algoBxDiff_.push_back(dbe_->book1D("BX_diff_algo"+ ss.str(),"BX_diff_algo"+ ss.str(),9,-4,5));
143  algoBxDiffLumi_.push_back(dbe_->book2D("BX_diffvslumi_algo"+ ss.str(),"BX_diff_algo"+ss.str(),MAX_LUMI_BIN,-0.5,double(MAX_LUMI_SEG)-0.5,9,-4,5));
144  //algoBxDiffLumi_[ibit]->setAxisTitle("Lumi Section", 1);
145  }
146  for(uint ibit = 0; ibit < techSelected_.size(); ibit++){
147  std::stringstream ss;
148  ss << techSelected_[ibit] << "_" << sdenom.str() << denomBit_;
149  techBxDiff_.push_back(dbe_->book1D("BX_diff_tech"+ ss.str(),"BX_diff_tech"+ ss.str(),9,-4,5));
150  techBxDiffLumi_.push_back(dbe_->book2D("BX_diffvslumi_tech"+ ss.str(),"BX_diff_tech"+ss.str(),MAX_LUMI_BIN,-0.5,double(MAX_LUMI_SEG)-0.5,9,-4,5));
151  //techBxDiffLumi_[ibit]->setAxisTitle("Lumi Section", 1);
152  }
153 
154  //GMT timing plots
155  std::stringstream ss1;
156  ss1 << "_" << sdenom.str() << denomBit_;
157  dtBxDiff_ = dbe_->book1D("BX_diff_DT" + ss1.str(),"BX_diff_DT" + ss1.str(),9,-4,5);
158  dtBxDiffLumi_ = dbe_->book2D("BX_diffvslumi_DT" + ss1.str(),"BX_diffvslumi_DT" + ss1.str(),MAX_LUMI_BIN,-0.5,double(MAX_LUMI_SEG)-0.5,9,-4,5);
159  cscBxDiff_ = dbe_->book1D("BX_diff_CSC" + ss1.str(),"BX_diff_CSC" + ss1.str(),9,-4,5);
160  cscBxDiffLumi_ = dbe_->book2D("BX_diffvslumi_CSC" + ss1.str(),"BX_diffvslumi_CSC" + ss1.str(),MAX_LUMI_BIN,-0.5,double(MAX_LUMI_SEG)-0.5,9,-4,5);
161  rpcbBxDiff_ = dbe_->book1D("BX_diff_RPCb" + ss1.str(),"BX_diff_RPCb" + ss1.str(),9,-4,5);
162  rpcbBxDiffLumi_ = dbe_->book2D("BX_diffvslumi_RPCb" + ss1.str(),"BX_diffvslumi_RPCb" + ss1.str(),MAX_LUMI_BIN,-0.5,double(MAX_LUMI_SEG)-0.5,9,-4,5);
163  rpcfBxDiff_ = dbe_->book1D("BX_diff_RPCf" + ss1.str(),"BX_diff_RPCf" + ss1.str(),9,-4,5);
164  rpcfBxDiffLumi_ = dbe_->book2D("BX_diffvslumi_RPCf" + ss1.str(),"BX_diffvslumi_RPCf" + ss1.str(),MAX_LUMI_BIN,-0.5,double(MAX_LUMI_SEG)-0.5,9,-4,5);
165 
166 
167  // early triggers
168 // pixFedSize_ = dbe_->book1D("pixFedSize", "Size of Pixel FED data",
169 // 200, 0., 20000.);
170 // hfEnergy_ = dbe_->book1D("hfEnergy", "HF energy",
171 // 100, 0., 500.);
172 
173  }
174 
175 
176  return;
177 }
178 
180 {
181 }
182 
183 void L1Scalers::analyze(const edm::Event &e, const edm::EventSetup &iSetup)
184 {
185  nev_++;
186 
187  LogDebug("Status") << "L1Scalers::analyze event " << nev_ ;
188 
189  // int myGTFEbx = -1;
190  // get Global Trigger decision and the decision word
191  // these are locally derived
193  bool t = e.getByLabel(l1GtDataSource_,gtRecord);
194 
195  if ( ! t ) {
196  LogDebug("Product") << "can't find L1GlobalTriggerReadoutRecord "
197  << "with label " << l1GtDataSource_.label() ;
198  }
199  else {
200 
201  // DEBUG
202  //gtRecord->print(std::cout);
203  // DEBUG
204 
205  L1GtfeWord gtfeWord = gtRecord->gtfeWord();
206  int gtfeBx = gtfeWord.bxNr();
207  bxNum_->Fill(gtfeBx);
208  // myGTFEbx = gtfeBx;
209 
210  bool tfBitGood = false;
211 
212  // First, the default
213  // vector of bool
214  for(int iebx=0; iebx<=4; iebx++) {
215 
216  //Algorithm Bits
217  DecisionWord gtDecisionWord = gtRecord->decisionWord(iebx-2);
218  // DecisionWord gtDecisionWord = gtRecord->decisionWord();
219  if ( ! gtDecisionWord.empty() ) { // if board not there this is zero
220  // loop over dec. bit to get total rate (no overlap)
221  for ( uint i = 0; i < gtDecisionWord.size(); ++i ) {
222  if ( gtDecisionWord[i] ) {
225  break;
226  }
227  }
228  // loop over decision bits
229  for ( uint i = 0; i < gtDecisionWord.size(); ++i ) {
230  if ( gtDecisionWord[i] ) {
231  l1scalers_->Fill(i);
232  l1scalersBx_->Fill(gtfeBx-2+iebx,i);
233  for ( uint j = i + 1; j < gtDecisionWord.size(); ++j ) {
234  if ( gtDecisionWord[j] ) {
235  l1Correlations_->Fill(i,j);
236  l1Correlations_->Fill(j,i);
237  }
238  }
239  }
240  }
241  }
242 
243 
244  // loop over technical triggers
245  // vector of bool again.
246  TechnicalTriggerWord tw = gtRecord->technicalTriggerWord(iebx-2);
247  // TechnicalTriggerWord tw = gtRecord->technicalTriggerWord();
248  if ( ! tw.empty() ) {
249  // loop over dec. bit to get total rate (no overlap)
250  for ( uint i = 0; i < tw.size(); ++i ) {
251  if ( tw[i] ) {
252  rateTtCounter_++;
254  break;
255  }
256  }
257  for ( uint i = 0; i < tw.size(); ++i ) {
258  if ( tw[i] ) {
259  l1techScalers_->Fill(i);
260  l1techScalersBx_->Fill(gtfeBx-2+iebx, i);
261  }
262  }
263 
264  // check if bit used to filter timing plots fired in this event
265  // (anywhere in the bx window)
266  if(tfIsTech_){
267  if(tfBit_ < tw.size()){
268  if( tw[tfBit_] ) tfBitGood = true;
269  }
270  }
271  } // ! tw.empty
272 
273  }//bx
274 
275 
276  //timing plots
277  earliestDenom_ = 9;
278  earliestAlgo_.clear();
279  earliestTech_.clear();
280  for(uint i=0; i < techSelected_.size(); i++) earliestTech_.push_back(9);
281  for(uint i=0; i < algoSelected_.size(); i++) earliestAlgo_.push_back(9);
282 
283  //GMT information
285  e.getByLabel(l1GtDataSource_,gmtCollection);
286 
287 
288  if (!gmtCollection.isValid()) {
289  edm::LogInfo("DataNotFound") << "can't find L1MuGMTReadoutCollection with label "
290  << l1GtDataSource_.label() ;
291  }
292 
293  // remember the bx of 1st candidate of each system (9=none)
294  int bx1st[4] = {9, 9, 9, 9};
295 
296  if(tfBitGood){//to avoid single BSC hits
297 
298  for(int iebx=0; iebx<=4; iebx++) {
299  TechnicalTriggerWord tw = gtRecord->technicalTriggerWord(iebx-2);
300  DecisionWord gtDecisionWord = gtRecord->decisionWord(iebx-2);
301 
302  bool denomBitGood = false;
303 
304  //check if reference bit is valid
305  if(denomIsTech_){
306  if ( ! tw.empty() ) {
307  if( denomBit_ < tw.size() ){
308  denomBitGood = true;
309  if( tw[denomBit_] && earliestDenom_==9 ) earliestDenom_ = iebx;
310  }
311  }
312  }
313  else{
314  if ( ! gtDecisionWord.empty() ) {
315  if( denomBit_ < gtDecisionWord.size() ){
316  denomBitGood = true;
317  if( gtDecisionWord[denomBit_] && earliestDenom_==9 ) earliestDenom_ = iebx;
318  }
319  }
320  }
321 
322  if(denomBitGood){
323 
324  //get earliest tech bx's
325  if ( ! tw.empty() ) {
326  for(uint ibit = 0; ibit < techSelected_.size(); ibit++){
327  if(techSelected_[ibit] < tw.size()){
328  if(tw[techSelected_[ibit]] && earliestTech_[ibit] == 9) earliestTech_[ibit] = iebx;
329  }
330  }
331  }
332 
333  //get earliest algo bx's
334  if(!gtDecisionWord.empty()){
335  for(uint ibit = 0; ibit < algoSelected_.size(); ibit++){
336  if(algoSelected_[ibit] < gtDecisionWord.size()){
337  if(gtDecisionWord[algoSelected_[ibit]] && earliestAlgo_[ibit] == 9) earliestAlgo_[ibit] = iebx;
338  }
339  }
340  }
341 
342  }//denomBitGood
343 
344  }//bx
345 
346 
347  //get earliest single muon trigger system bx's
348  if (gmtCollection.isValid()) {
349 
350  // get GMT readout collection
351  L1MuGMTReadoutCollection const* gmtrc = gmtCollection.product();
352  // get record vector
353  std::vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
354  // loop over records of individual bx's
355  std::vector<L1MuGMTReadoutRecord>::const_iterator RRItr;
356 
357  for( RRItr = gmt_records.begin(); RRItr != gmt_records.end(); RRItr++ ) {//loop from BX=-2 to BX=2
358  std::vector<L1MuRegionalCand> INPCands[4] = {
359  RRItr->getDTBXCands(),
360  RRItr->getBrlRPCCands(),
361  RRItr->getCSCCands(),
362  RRItr->getFwdRPCCands()
363  };
364  std::vector<L1MuRegionalCand>::const_iterator INPItr;
365  int BxInEvent = RRItr->getBxInEvent();
366 
367  // find the first non-empty candidate in this bx
368  for(int i=0; i<4; i++) {//for each single muon trigger system
369  for( INPItr = INPCands[i].begin(); INPItr != INPCands[i].end(); ++INPItr ) {
370  if(!INPItr->empty()) {
371  if(bx1st[i]==9) bx1st[i]=BxInEvent+2;//must go from 0 to 4 (consistent with above)
372  }
373  }
374  }
375  //for(int i=0; i<4; i++)
376  // std::cout << "bx1st[" << i << "] = " << bx1st[i];
377  //std::cout << std::endl;
378  }
379 
380  }//gmtCollection.isValid
381 
382 
383  //calculated bx difference
384  if(earliestDenom_ != 9){
385  for(uint ibit = 0; ibit < techSelected_.size(); ibit++){
386  if(earliestTech_[ibit] != 9){
387  int diff = earliestTech_[ibit] - earliestDenom_ ;
388  techBxDiff_[ibit]->Fill(diff);
389  techBxDiffLumi_[ibit]->Fill(e.luminosityBlock(), diff);
390  }
391  }
392  for(uint ibit = 0; ibit < algoSelected_.size(); ibit++){
393  if(earliestAlgo_[ibit] != 9){
394  int diff = earliestAlgo_[ibit] - earliestDenom_ ;
395  algoBxDiff_[ibit]->Fill(diff);
396  algoBxDiffLumi_[ibit]->Fill(e.luminosityBlock(), diff);
397  }
398  }
399 
400  if(bx1st[0] != 9){
401  int diff = bx1st[0] - earliestDenom_;
402  dtBxDiff_->Fill(diff);
404  }
405  if(bx1st[1] != 9){
406  int diff = bx1st[1] - earliestDenom_;
407  rpcbBxDiff_->Fill(diff);
409  }
410  if(bx1st[2] != 9){
411  int diff = bx1st[2] - earliestDenom_;
412  cscBxDiff_->Fill(diff);
414  }
415  if(bx1st[3] != 9){
416  int diff = bx1st[3] - earliestDenom_;
417  rpcfBxDiff_->Fill(diff);
419  }
420 
421  }
422 
423  }//tt41Good
424 
425  }
426 
427  return;
428 
429 }
430 
432  const edm::EventSetup& iSetup)
433 {
434  nLumiBlock_->Fill(lumiSeg.id().luminosityBlock());
435 
436 }
437 
438 
440 void L1Scalers::beginRun(const edm::Run& run, const edm::EventSetup& iSetup)
441 {
442 }
443 
445 void L1Scalers::endRun(const edm::Run& run, const edm::EventSetup& iSetup)
446 {
447 }
448 
449 
#define LogDebug(id)
LuminosityBlockID id() const
int i
Definition: DBlmapReader.cc:9
bool tfIsTech_
Definition: L1Scalers.h:56
MonitorElement * l1scalers_
Definition: L1Scalers.h:62
void endJob(void)
Definition: L1Scalers.cc:179
edm::InputTag l1GtDataSource_
Definition: L1Scalers.h:52
std::string folderName_
Definition: L1Scalers.h:61
MonitorElement * rpcfBxDiffLumi_
Definition: L1Scalers.h:91
L1Scalers(const edm::ParameterSet &ps)
Constructors.
Definition: L1Scalers.cc:42
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
void endRun(const edm::Run &run, const edm::EventSetup &c)
EndRun.
Definition: L1Scalers.cc:445
MonitorElement * rpcbBxDiffLumi_
Definition: L1Scalers.h:89
MonitorElement * dtBxDiffLumi_
Definition: L1Scalers.h:85
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
Definition: L1Scalers.cc:431
std::vector< int > earliestTech_
Definition: L1Scalers.h:111
void Fill(long long x)
bool denomIsTech_
Definition: L1Scalers.h:54
#define MAX_LUMI_SEG
Definition: L1Scalers.h:13
std::vector< MonitorElement * > algoBxDiff_
Definition: L1Scalers.h:80
void analyze(const edm::Event &e, const edm::EventSetup &c)
Definition: L1Scalers.cc:183
MonitorElement * cscBxDiff_
Definition: L1Scalers.h:86
MonitorElement * l1techScalers_
Definition: L1Scalers.h:63
std::vector< bool > DecisionWord
typedefs
MonitorElement * l1scalersBx_
Definition: L1Scalers.h:69
int nev_
Definition: L1Scalers.h:49
#define MAX_LUMI_BIN
Definition: L1Scalers.h:14
int j
Definition: DBlmapReader.cc:9
MonitorElement * l1TtCounter_
Definition: L1Scalers.h:77
std::vector< bool > TechnicalTriggerWord
technical trigger bits (64 bits)
std::vector< MonitorElement * > techBxDiff_
Definition: L1Scalers.h:81
bool isValid() const
Definition: HandleBase.h:76
std::vector< MonitorElement * > techBxDiffLumi_
Definition: L1Scalers.h:83
DQMStore * dbe_
Definition: L1Scalers.h:48
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
std::vector< unsigned int > algoSelected_
Definition: L1Scalers.h:58
DQMStore * dbe_
const cms_uint16_t bxNr() const
get/set bunch cross number as counted in the GTFE board
Definition: L1GtfeWord.h:122
MonitorElement * l1Correlations_
Definition: L1Scalers.h:64
std::vector< unsigned int > techSelected_
Definition: L1Scalers.h:59
MonitorElement * rpcbBxDiff_
Definition: L1Scalers.h:88
MonitorElement * dtBxDiff_
Definition: L1Scalers.h:84
T const * product() const
Definition: Handle.h:81
unsigned int rateAlgoCounter_
Definition: L1Scalers.h:100
std::vector< int > earliestAlgo_
Definition: L1Scalers.h:112
int earliestDenom_
Definition: L1Scalers.h:110
MonitorElement * nLumiBlock_
Definition: L1Scalers.h:75
void beginJob(void)
BeginJob.
Definition: L1Scalers.cc:81
unsigned int tfBit_
Definition: L1Scalers.h:57
LuminosityBlockNumber_t luminosityBlock() const
MonitorElement * bxNum_
Definition: L1Scalers.h:65
MonitorElement * l1techScalersBx_
Definition: L1Scalers.h:70
std::string const & label() const
Definition: InputTag.h:42
std::vector< MonitorElement * > algoBxDiffLumi_
Definition: L1Scalers.h:82
#define begin
Definition: vmac.h:30
std::vector< L1MuGMTReadoutRecord > const & getRecords() const
MonitorElement * l1AlgoCounter_
Definition: L1Scalers.h:76
unsigned int denomBit_
Definition: L1Scalers.h:55
volatile std::atomic< bool > shutdown_flag false
MonitorElement * rpcfBxDiff_
Definition: L1Scalers.h:90
Definition: Run.h:41
void beginRun(const edm::Run &run, const edm::EventSetup &c)
BeginRun.
Definition: L1Scalers.cc:440
unsigned int rateTtCounter_
Definition: L1Scalers.h:101
MonitorElement * cscBxDiffLumi_
Definition: L1Scalers.h:87