CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BeamMonitor.cc
Go to the documentation of this file.
1 /*
2  * \file BeamMonitor.cc
3  * \author Geng-yuan Jeng/UC Riverside
4  * Francisco Yumiceva/FNAL
5  * $Date: 2011/03/13 20:33:36 $
6  * $Revision: 1.71 $
7  */
8 
9 
10 /*
11 The code has been modified for running average
12 mode, and it gives results for the last NLS which is
13 configurable.
14 Sushil S. Chauhan /UCDavis
15 Evan Friis /UCDavis
16 The last tag for working versions without this change is
17 V00-03-25
18 */
19 
20 
21 
41 #include <numeric>
42 #include <math.h>
43 #include <TMath.h>
44 #include <iostream>
45 #include <TStyle.h>
46 
47 using namespace std;
48 using namespace edm;
49 
50 const char * BeamMonitor::formatFitTime( const time_t & t ) {
51 #define CET (+1)
52 #define CEST (+2)
53 
54  static char ts[] = "yyyy-Mm-dd hh:mm:ss";
55  tm * ptm;
56  ptm = gmtime ( &t );
57  int year = ptm->tm_year;
58  if (year < 1995) {
59  edm::LogError("BadTimeStamp") << "year reported is " << year << "!! resetting to 2011..." << std::endl;
60  year = 2011;
61  }
62  sprintf( ts, "%4d-%02d-%02d %02d:%02d:%02d", year,ptm->tm_mon+1,ptm->tm_mday,(ptm->tm_hour+CEST)%24, ptm->tm_min, ptm->tm_sec);
63 
64 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE
65  unsigned int b = strlen(ts);
66  while (ts[--b] == ' ') {ts[b] = 0;}
67 #endif
68  return ts;
69 
70 }
71 
72 #define buffTime (23)
73 
74 //
75 // constructors and destructor
76 //
78  countEvt_(0),countLumi_(0),nthBSTrk_(0),nFitElements_(3),resetHistos_(false),StartAverage_(false),firstAverageFit_(0),countGapLumi_(0) {
79 
80  parameters_ = ps;
81  monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","YourSubsystemName");
84  hltSrc_ = parameters_.getParameter<InputTag>("hltResults");
85  intervalInSec_ = parameters_.getUntrackedParameter<int>("timeInterval",920);//40 LS X 23"
86  fitNLumi_ = parameters_.getUntrackedParameter<int>("fitEveryNLumi",-1);
87  resetFitNLumi_ = parameters_.getUntrackedParameter<int>("resetEveryNLumi",-1);
88  fitPVNLumi_ = parameters_.getUntrackedParameter<int>("fitPVEveryNLumi",-1);
89  resetPVNLumi_ = parameters_.getUntrackedParameter<int>("resetPVEveryNLumi",-1);
90  deltaSigCut_ = parameters_.getUntrackedParameter<double>("deltaSignificanceCut",15);
91  debug_ = parameters_.getUntrackedParameter<bool>("Debug");
92  onlineMode_ = parameters_.getUntrackedParameter<bool>("OnlineMode");
93  jetTrigger_ = parameters_.getUntrackedParameter<std::vector<std::string> >("jetTrigger");
94  tracksLabel_ = parameters_.getParameter<ParameterSet>("BeamFitter").getUntrackedParameter<InputTag>("TrackCollection");
95  min_Ntrks_ = parameters_.getParameter<ParameterSet>("BeamFitter").getUntrackedParameter<int>("MinimumInputTracks");
96  maxZ_ = parameters_.getParameter<ParameterSet>("BeamFitter").getUntrackedParameter<double>("MaximumZ");
97  minNrVertices_ = parameters_.getParameter<ParameterSet>("PVFitter").getUntrackedParameter<unsigned int>("minNrVerticesForFit");
98  minVtxNdf_ = parameters_.getParameter<ParameterSet>("PVFitter").getUntrackedParameter<double>("minVertexNdf");
99  minVtxWgt_ = parameters_.getParameter<ParameterSet>("PVFitter").getUntrackedParameter<double>("minVertexMeanWeight");
100 
102 
103  if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
104 
110 
111  if (fitNLumi_ <= 0) fitNLumi_ = 1;
113  refBStime[0] = refBStime[1] = refPVtime[0] = refPVtime[1] = 0;
114  maxZ_ = std::fabs(maxZ_);
115  lastlumi_ = 0;
116  nextlumi_ = 0;
117  processed_ = false;
118 }
119 
120 
122  delete theBeamFitter;
123 }
124 
125 
126 //--------------------------------------------------------
128 
129 
130  // book some histograms here
131  const int dxBin = parameters_.getParameter<int>("dxBin");
132  const double dxMin = parameters_.getParameter<double>("dxMin");
133  const double dxMax = parameters_.getParameter<double>("dxMax");
134 
135  const int vxBin = parameters_.getParameter<int>("vxBin");
136  const double vxMin = parameters_.getParameter<double>("vxMin");
137  const double vxMax = parameters_.getParameter<double>("vxMax");
138 
139  const int phiBin = parameters_.getParameter<int>("phiBin");
140  const double phiMin = parameters_.getParameter<double>("phiMin");
141  const double phiMax = parameters_.getParameter<double>("phiMax");
142 
143  const int dzBin = parameters_.getParameter<int>("dzBin");
144  const double dzMin = parameters_.getParameter<double>("dzMin");
145  const double dzMax = parameters_.getParameter<double>("dzMax");
146 
147  // create and cd into new folder
149 
150  h_nTrk_lumi=dbe_->book1D("nTrk_lumi","Num. of selected tracks vs lumi",20,0.5,20.5);
151  h_nTrk_lumi->setAxisTitle("Lumisection",1);
152  h_nTrk_lumi->setAxisTitle("Num of Tracks",2);
153 
154  h_d0_phi0 = dbe_->bookProfile("d0_phi0","d_{0} vs. #phi_{0} (Selected Tracks)",phiBin,phiMin,phiMax,dxBin,dxMin,dxMax,"");
155  h_d0_phi0->setAxisTitle("#phi_{0} (rad)",1);
156  h_d0_phi0->setAxisTitle("d_{0} (cm)",2);
157 
158  h_vx_vy = dbe_->book2D("trk_vx_vy","Vertex (PCA) position of selected tracks",vxBin,vxMin,vxMax,vxBin,vxMin,vxMax);
159  h_vx_vy->getTH2F()->SetOption("COLZ");
160  // h_vx_vy->getTH1()->SetBit(TH1::kCanRebin);
161  h_vx_vy->setAxisTitle("x coordinate of input track at PCA (cm)",1);
162  h_vx_vy->setAxisTitle("y coordinate of input track at PCA (cm)",2);
163 
164  TDatime *da = new TDatime();
165  gStyle->SetTimeOffset(da->Convert(kTRUE));
166 
167  const int nvar_ = 6;
168  string coord[nvar_] = {"x","y","z","sigmaX","sigmaY","sigmaZ"};
169  string label[nvar_] = {"x_{0} (cm)","y_{0} (cm)","z_{0} (cm)",
170  "#sigma_{X_{0}} (cm)","#sigma_{Y_{0}} (cm)","#sigma_{Z_{0}} (cm)"};
171  for (int i = 0; i < 4; i++) {
173  for (int ic=0; ic<nvar_; ++ic) {
174  TString histName(coord[ic]);
175  TString histTitle(coord[ic]);
176  string ytitle(label[ic]);
177  string xtitle("");
178  string options("E1");
179  bool createHisto = true;
180  switch(i) {
181  case 1: // BS vs time
182  histName += "0_time";
183  xtitle = "Time [UTC]";
184  if (ic < 3)
185  histTitle += " coordinate of beam spot vs time (Fit)";
186  else
187  histTitle = histTitle.Insert(5," ") + " of beam spot vs time (Fit)";
188  break;
189  case 2: // PV vs lumi
190  if (ic < 3) {
191  dbe_->setCurrentFolder(monitorName_+"PrimaryVertex");
192  histName.Insert(0,"PV");
193  histName += "_lumi";
194  histTitle.Insert(0,"Avg. ");
195  histTitle += " position of primary vtx vs lumi";
196  xtitle = "Lumisection";
197  ytitle.insert(0,"PV");
198  ytitle += " #pm #sigma_{PV";
199  ytitle += coord[ic];
200  ytitle += "} (cm)";
201  }
202  else createHisto = false;
203  break;
204  case 3: // PV vs time
205  if (ic < 3) {
206  dbe_->setCurrentFolder(monitorName_+"PrimaryVertex");
207  histName.Insert(0,"PV");
208  histName += "_time";
209  histTitle.Insert(0,"Avg. ");
210  histTitle += " position of primary vtx vs time";
211  xtitle = "Time [UTC]";
212  ytitle.insert(0,"PV");
213  ytitle += " #pm #sigma_{PV";
214  ytitle += coord[ic];
215  ytitle += "} (cm)";
216  }
217  else createHisto = false;
218  break;
219  default: // BS vs lumi
220  histName += "0_lumi";
221  xtitle = "Lumisection";
222  if (ic < 3)
223  histTitle += " coordinate of beam spot vs lumi (Fit)";
224  else
225  histTitle = histTitle.Insert(5," ") + " of beam spot vs lumi (Fit)";
226  break;
227  }
228  if (createHisto) {
229  edm::LogInfo("BeamMonitor") << "hitsName = " << histName << "; histTitle = " << histTitle << std::endl;
230  hs[histName] = dbe_->book1D(histName,histTitle,40,0.5,40.5);
231  hs[histName]->setAxisTitle(xtitle,1);
232  hs[histName]->setAxisTitle(ytitle,2);
233  hs[histName]->getTH1()->SetOption("E1");
234  if (histName.Contains("time")) {
235  //int nbins = (intervalInSec_/23 > 0 ? intervalInSec_/23 : 40);
236  hs[histName]->getTH1()->SetBins(intervalInSec_,0.5,intervalInSec_+0.5);
237  hs[histName]->setAxisTimeDisplay(1);
238  hs[histName]->setAxisTimeFormat("%H:%M:%S",1);
239  }
240  histName += "_all";
241  histTitle += " all";
242  hs[histName] = dbe_->book1D(histName,histTitle,40,0.5,40.5);
243  hs[histName]->getTH1()->SetBit(TH1::kCanRebin);
244  hs[histName]->setAxisTitle(xtitle,1);
245  hs[histName]->setAxisTitle(ytitle,2);
246  hs[histName]->getTH1()->SetOption("E1");
247  if (histName.Contains("time")) {
248  //int nbins = (intervalInSec_/23 > 0 ? intervalInSec_/23 : 40);
249  hs[histName]->getTH1()->SetBins(intervalInSec_,0.5,intervalInSec_+0.5);
250  hs[histName]->setAxisTimeDisplay(1);
251  hs[histName]->setAxisTimeFormat("%H:%M:%S",1);
252  }
253  }
254  }
255  }
257 
258  h_trk_z0 = dbe_->book1D("trk_z0","z_{0} of selected tracks",dzBin,dzMin,dzMax);
259  h_trk_z0->setAxisTitle("z_{0} of selected tracks (cm)",1);
260 
261  h_vx_dz = dbe_->bookProfile("vx_dz","v_{x} vs. dz of selected tracks",dzBin,dzMin,dzMax,dxBin,dxMin,dxMax,"");
262  h_vx_dz->setAxisTitle("dz (cm)",1);
263  h_vx_dz->setAxisTitle("x coordinate of input track at PCA (cm)",2);
264 
265  h_vy_dz = dbe_->bookProfile("vy_dz","v_{y} vs. dz of selected tracks",dzBin,dzMin,dzMax,dxBin,dxMin,dxMax,"");
266  h_vy_dz->setAxisTitle("dz (cm)",1);
267  h_vy_dz->setAxisTitle("x coordinate of input track at PCA (cm)",2);
268 
269  h_x0 = dbe_->book1D("BeamMonitorFeedBack_x0","x coordinate of beam spot (Fit)",100,-0.01,0.01);
270  h_x0->setAxisTitle("x_{0} (cm)",1);
271  h_x0->getTH1()->SetBit(TH1::kCanRebin);
272 
273  h_y0 = dbe_->book1D("BeamMonitorFeedBack_y0","y coordinate of beam spot (Fit)",100,-0.01,0.01);
274  h_y0->setAxisTitle("y_{0} (cm)",1);
275  h_y0->getTH1()->SetBit(TH1::kCanRebin);
276 
277  h_z0 = dbe_->book1D("BeamMonitorFeedBack_z0","z coordinate of beam spot (Fit)",dzBin,dzMin,dzMax);
278  h_z0->setAxisTitle("z_{0} (cm)",1);
279  h_z0->getTH1()->SetBit(TH1::kCanRebin);
280 
281  h_sigmaX0 = dbe_->book1D("BeamMonitorFeedBack_sigmaX0","sigma x0 of beam spot (Fit)",100,0,0.05);
282  h_sigmaX0->setAxisTitle("#sigma_{X_{0}} (cm)",1);
283  h_sigmaX0->getTH1()->SetBit(TH1::kCanRebin);
284 
285  h_sigmaY0 = dbe_->book1D("BeamMonitorFeedBack_sigmaY0","sigma y0 of beam spot (Fit)",100,0,0.05);
286  h_sigmaY0->setAxisTitle("#sigma_{Y_{0}} (cm)",1);
287  h_sigmaY0->getTH1()->SetBit(TH1::kCanRebin);
288 
289  h_sigmaZ0 = dbe_->book1D("BeamMonitorFeedBack_sigmaZ0","sigma z0 of beam spot (Fit)",100,0,10);
290  h_sigmaZ0->setAxisTitle("#sigma_{Z_{0}} (cm)",1);
291  h_sigmaZ0->getTH1()->SetBit(TH1::kCanRebin);
292 
293  // Histograms of all reco tracks (without cuts):
294  h_trkPt=dbe_->book1D("trkPt","p_{T} of all reco'd tracks (no selection)",200,0.,50.);
295  h_trkPt->setAxisTitle("p_{T} (GeV/c)",1);
296 
297  h_trkVz=dbe_->book1D("trkVz","Z coordinate of PCA of all reco'd tracks (no selection)",dzBin,dzMin,dzMax);
298  h_trkVz->setAxisTitle("V_{Z} (cm)",1);
299 
300  cutFlowTable = dbe_->book1D("cutFlowTable","Cut flow table of track selection", 9, 0, 9 );
301 
302  // Results of previous good fit:
303  fitResults=dbe_->book2D("fitResults","Results of previous good beam fit",2,0,2,8,0,8);
304  fitResults->setAxisTitle("Fitted Beam Spot (cm)",1);
305  fitResults->setBinLabel(8,"x_{0}",2);
306  fitResults->setBinLabel(7,"y_{0}",2);
307  fitResults->setBinLabel(6,"z_{0}",2);
308  fitResults->setBinLabel(5,"#sigma_{Z}",2);
309  fitResults->setBinLabel(4,"#frac{dx}{dz} (rad)",2);
310  fitResults->setBinLabel(3,"#frac{dy}{dz} (rad)",2);
311  fitResults->setBinLabel(2,"#sigma_{X}",2);
312  fitResults->setBinLabel(1,"#sigma_{Y}",2);
313  fitResults->setBinLabel(1,"Mean",1);
314  fitResults->setBinLabel(2,"Stat. Error",1);
315  fitResults->getTH1()->SetOption("text");
316 
317  // Histos of PrimaryVertices:
318  dbe_->setCurrentFolder(monitorName_+"PrimaryVertex");
319 
320  h_nVtx = dbe_->book1D("vtxNbr","Reconstructed Vertices(non-fake) in all Event",20,-0.5,19.5);
321  h_nVtx->setAxisTitle("Num. of reco. vertices",1);
322 
323  //For one Trigger only
324  h_nVtx_st = dbe_->book1D("vtxNbr_SelectedTriggers","Reconstructed Vertices(non-fake) in Events",20,-0.5,19.5);
325  //h_nVtx_st->setAxisTitle("Num. of reco. vertices for Un-Prescaled Jet Trigger",1);
326 
327  // Monitor only the PV with highest sum pt of assoc. trks:
328  h_PVx[0] = dbe_->book1D("PVX","x coordinate of Primary Vtx",50,-0.01,0.01);
329  h_PVx[0]->setAxisTitle("PVx (cm)",1);
330  h_PVx[0]->getTH1()->SetBit(TH1::kCanRebin);
331 
332  h_PVy[0] = dbe_->book1D("PVY","y coordinate of Primary Vtx",50,-0.01,0.01);
333  h_PVy[0]->setAxisTitle("PVy (cm)",1);
334  h_PVy[0]->getTH1()->SetBit(TH1::kCanRebin);
335 
336  h_PVz[0] = dbe_->book1D("PVZ","z coordinate of Primary Vtx",dzBin,dzMin,dzMax);
337  h_PVz[0]->setAxisTitle("PVz (cm)",1);
338 
339  h_PVx[1] = dbe_->book1D("PVXFit","x coordinate of Primary Vtx (Last Fit)",50,-0.01,0.01);
340  h_PVx[1]->setAxisTitle("PVx (cm)",1);
341  h_PVx[1]->getTH1()->SetBit(TH1::kCanRebin);
342 
343  h_PVy[1] = dbe_->book1D("PVYFit","y coordinate of Primary Vtx (Last Fit)",50,-0.01,0.01);
344  h_PVy[1]->setAxisTitle("PVy (cm)",1);
345  h_PVy[1]->getTH1()->SetBit(TH1::kCanRebin);
346 
347  h_PVz[1] = dbe_->book1D("PVZFit","z coordinate of Primary Vtx (Last Fit)",dzBin,dzMin,dzMax);
348  h_PVz[1]->setAxisTitle("PVz (cm)",1);
349 
350  h_PVxz = dbe_->bookProfile("PVxz","PVx vs. PVz",dzBin/2,dzMin,dzMax,dxBin/2,dxMin,dxMax,"");
351  h_PVxz->setAxisTitle("PVz (cm)",1);
352  h_PVxz->setAxisTitle("PVx (cm)",2);
353 
354  h_PVyz = dbe_->bookProfile("PVyz","PVy vs. PVz",dzBin/2,dzMin,dzMax,dxBin/2,dxMin,dxMax,"");
355  h_PVyz->setAxisTitle("PVz (cm)",1);
356  h_PVyz->setAxisTitle("PVy (cm)",2);
357 
358  // Results of previous good fit:
359  pvResults=dbe_->book2D("pvResults","Results of fitting Primary Vertices",2,0,2,6,0,6);
360  pvResults->setAxisTitle("Fitted Primary Vertex (cm)",1);
361  pvResults->setBinLabel(6,"PVx",2);
362  pvResults->setBinLabel(5,"PVy",2);
363  pvResults->setBinLabel(4,"PVz",2);
364  pvResults->setBinLabel(3,"#sigma_{X}",2);
365  pvResults->setBinLabel(2,"#sigma_{Y}",2);
366  pvResults->setBinLabel(1,"#sigma_{Z}",2);
367  pvResults->setBinLabel(1,"Mean",1);
368  pvResults->setBinLabel(2,"Stat. Error",1);
369  pvResults->getTH1()->SetOption("text");
370 
371  // Summary plots:
372  dbe_->setCurrentFolder(monitorName_+"EventInfo");
373  reportSummary = dbe_->get(monitorName_+"EventInfo/reportSummary");
375 
376  reportSummary = dbe_->bookFloat("reportSummary");
377  if(reportSummary) reportSummary->Fill(0./0.);
378 
379  char histo[20];
380  dbe_->setCurrentFolder(monitorName_+"EventInfo/reportSummaryContents");
381  for (int n = 0; n < nFitElements_; n++) {
382  switch(n){
383  case 0 : sprintf(histo,"x0_status"); break;
384  case 1 : sprintf(histo,"y0_status"); break;
385  case 2 : sprintf(histo,"z0_status"); break;
386  }
388  }
389 
390  for (int i = 0; i < nFitElements_; i++) {
391  summaryContent_[i] = 0.;
392  reportSummaryContents[i]->Fill(0./0.);
393  }
394 
395  dbe_->setCurrentFolder(monitorName_+"EventInfo");
396 
397  reportSummaryMap = dbe_->get(monitorName_+"EventInfo/reportSummaryMap");
399 
400  reportSummaryMap = dbe_->book2D("reportSummaryMap", "Beam Spot Summary Map", 1, 0, 1, 3, 0, 3);
402  reportSummaryMap->setAxisTitle("Fitted Beam Spot",2);
403  reportSummaryMap->setBinLabel(1," ",1);
404  reportSummaryMap->setBinLabel(1,"x_{0}",2);
405  reportSummaryMap->setBinLabel(2,"y_{0}",2);
406  reportSummaryMap->setBinLabel(3,"z_{0}",2);
407  for (int i = 0; i < nFitElements_; i++) {
408  reportSummaryMap->setBinContent(1,i+1,-1.);
409  }
410 }
411 
412 //--------------------------------------------------------
413 void BeamMonitor::beginRun(const edm::Run& r, const EventSetup& context) {
414 
415  frun = r.run();
416  ftimestamp = r.beginTime().value();
417  tmpTime = ftimestamp >> 32;
419  const char* eventTime = formatFitTime(tmpTime);
420  std::cout << "TimeOffset = " << eventTime << std::endl;
421  TDatime da(eventTime);
422  if (debug_) {
423  edm::LogInfo("BeamMonitor") << "TimeOffset = ";
424  da.Print();
425  }
426  for (std::map<TString,MonitorElement*>::iterator it = hs.begin();
427  it != hs.end(); ++it) {
428  if ((*it).first.Contains("time"))
429  (*it).second->getTH1()->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
430  }
431 }
432 
433 //--------------------------------------------------------
435  const EventSetup& context) {
436  int nthlumi = lumiSeg.luminosityBlock();
437  const edm::TimeValue_t fbegintimestamp = lumiSeg.beginTime().value();
438  const std::time_t ftmptime = fbegintimestamp >> 32;
439 
440 
441  if (countLumi_ == 0 && (!processed_)) {
443  refBStime[0] = refPVtime[0] = ftmptime;
444  mapBeginBSLS[countLumi_] = nthlumi;
445  mapBeginPVLS[countLumi_] = nthlumi;
446  mapBeginBSTime[countLumi_] = ftmptime;
447  mapBeginPVTime[countLumi_] = ftmptime;
448  }//for the first record
449 
450 if(nthlumi > nextlumi_){
451  if(processed_){ countLumi_++;
452  //store here them will need when we remove the first one of Last N LS
453  mapBeginBSLS[countLumi_] = nthlumi;
454  mapBeginPVLS[countLumi_] = nthlumi;
455  mapBeginBSTime[countLumi_] = ftmptime;
456  mapBeginPVTime[countLumi_] = ftmptime;
457  }//processed passed but not the first lumi
458  if((!processed_) && countLumi_ !=0){
459  mapBeginBSLS[countLumi_] = nthlumi;
460  mapBeginPVLS[countLumi_] = nthlumi;
461  mapBeginBSTime[countLumi_] = ftmptime;
462  mapBeginPVTime[countLumi_] = ftmptime;
463  }//processed fails for last lumi
464  }//nthLumi > nextlumi
465 
466 
467  if(StartAverage_ ){
468  //Just Make sure it get rest
469  refBStime[0] =0;
470  refPVtime[0] =0;
473 
474  if(debug_)edm::LogInfo("BeamMonitor") << " beginLuminosityBlock: Size of mapBeginBSLS before = "<< mapBeginBSLS.size()<<endl;
475  if(nthlumi> nextlumi_){ //this make sure that it does not take into account this lumi for fitting and only look forward for new lumi
476  //as countLumi also remains the same so map value get overwritten once return to normal running.
477  //even if few LS are misssing and DQM module do not sees them then it catchs up again
478  map<int, int>::iterator itbs=mapBeginBSLS.begin();
479  map<int, int>::iterator itpv=mapBeginPVLS.begin();
480  map<int, std::time_t>::iterator itbstime=mapBeginBSTime.begin();
481  map<int, std::time_t>::iterator itpvtime=mapBeginPVTime.begin();
482 
483  mapBeginBSLS.erase(itbs);
484  mapBeginPVLS.erase(itpv);
485  mapBeginBSTime.erase(itbstime);
486  mapBeginPVTime.erase(itpvtime);
487 
488  /*//not sure if want this or not ??
489  map<int, int>::iterator itgapb=mapBeginBSLS.begin();
490  map<int, int>::iterator itgape=mapBeginBSLS.end(); itgape--;
491  countGapLumi_ = ( (itgape->second) - (itgapb->second) );
492  //if we see Gap more than then 2*resetNFitLumi !!!!!!!
493  //for example if 10-15 is fitted and if 16-25 are missing then we next fit will be for range 11-26 but BS can change in between
494  // so better start as fresh and reset everything like starting in the begining!
495  if(countGapLumi_ >= 2*resetFitNLumi_){RestartFitting(); mapBeginBSLS[countLumi_] = nthlumi;}
496  */
497  }
498 
499  if(debug_) edm::LogInfo("BeamMonitor") << " beginLuminosityBlock:: Size of mapBeginBSLS After = "<< mapBeginBSLS.size()<<endl;
500 
501  map<int, int>::iterator bbs = mapBeginBSLS.begin();
502  map<int, int>::iterator bpv = mapBeginPVLS.begin();
503  map<int, std::time_t>::iterator bbst = mapBeginBSTime.begin();
504  map<int, std::time_t>::iterator bpvt = mapBeginPVTime.begin();
505 
506 
507  if (beginLumiOfPVFit_ == 0) beginLumiOfPVFit_ = bpv->second; //new begin time after removing the LS
508  if (beginLumiOfBSFit_ == 0) beginLumiOfBSFit_ = bbs->second;
509  if (refBStime[0] == 0) refBStime[0] = bbst->second;
510  if (refPVtime[0] == 0) refPVtime[0] = bpvt->second;
511 
512  }//same logic for average fit as above commented line
513 
514 
515  map<int, std::time_t>::iterator nbbst = mapBeginBSTime.begin();
516  map<int, std::time_t>::iterator nbpvt = mapBeginPVTime.begin();
517 
518 
519  if (onlineMode_ && (nthlumi < nextlumi_)) return;
520 
521  if (onlineMode_) {
522  if (nthlumi > nextlumi_) {
523  if (countLumi_ != 0 && processed_) FitAndFill(lumiSeg,lastlumi_,nextlumi_,nthlumi);
524  nextlumi_ = nthlumi;
525  edm::LogInfo("BeamMonitor") << "beginLuminosityBlock:: Next Lumi to Fit: " << nextlumi_ << endl;
526  if((StartAverage_) && refBStime[0] == 0) refBStime[0] = nbbst->second;
527  if((StartAverage_) && refPVtime[0] == 0) refPVtime[0] = nbpvt->second;
528  }
529  }
530  else{
531  if (processed_) FitAndFill(lumiSeg,lastlumi_,nextlumi_,nthlumi);
532  nextlumi_ = nthlumi;
533  edm::LogInfo("BeamMonitor") << " beginLuminosityBlock:: Next Lumi to Fit: " << nextlumi_ << endl;
534  if ((StartAverage_) && refBStime[0] == 0) refBStime[0] = nbbst->second;
535  if ((StartAverage_) && refPVtime[0] == 0) refPVtime[0] = nbpvt->second;
536  }
537 
538  //countLumi_++;
539  if (processed_) processed_ = false;
540  edm::LogInfo("BeamMonitor") << " beginLuminosityBlock:: Begin of Lumi: " << nthlumi << endl;
541 }
542 
543 // ----------------------------------------------------------
545  const EventSetup& iSetup ) {
546  const int nthlumi = iEvent.luminosityBlock();
547  if (onlineMode_ && (nthlumi < nextlumi_)) {
548  edm::LogInfo("BeamMonitor") << "analyze:: Spilt event from previous lumi section!" << std::endl;
549  return;
550  }
551  if (onlineMode_ && (nthlumi > nextlumi_)) {
552  edm::LogInfo("BeamMonitor") << "analyze:: Spilt event from next lumi section!!!" << std::endl;
553  return;
554  }
555 
556  countEvt_++;
557  theBeamFitter->readEvent(iEvent); //Remember when track fitter read the event in the same place the PVFitter read the events !!!!!!!!!
558 
559  Handle<reco::BeamSpot> recoBeamSpotHandle;
560  iEvent.getByLabel(bsSrc_,recoBeamSpotHandle);
561  refBS = *recoBeamSpotHandle;
562 
564 
565  //------Cut Flow Table filled every event!--------------------------------------
566  std::string cutFlowTableName = cutFlowTable->getName();
567  // Make a copy of the cut flow table from the beam fitter.
568  TH1F * tmphisto =
569  static_cast<TH1F*>((theBeamFitter->getCutFlow())->Clone("tmphisto"));
570  cutFlowTable->getTH1()->SetBins(
571  tmphisto->GetNbinsX(),
572  tmphisto->GetXaxis()->GetXmin(),
573  tmphisto->GetXaxis()->GetXmax());
574  // Update the bin labels
575  if (countEvt_ == 1) // SetLabel just once
576  for(int n=0; n < tmphisto->GetNbinsX(); n++)
577  cutFlowTable->setBinLabel(n+1,tmphisto->GetXaxis()->GetBinLabel(n+1),1);
578  cutFlowTable = dbe_->book1D(cutFlowTableName, tmphisto);
579 
580  //----Reco tracks -------------------------------------
582  iEvent.getByLabel(tracksLabel_, TrackCollection);
583  const reco::TrackCollection *tracks = TrackCollection.product();
584  for ( reco::TrackCollection::const_iterator track = tracks->begin();
585  track != tracks->end(); ++track ) {
586  h_trkPt->Fill(track->pt()); //no need to change here for average bs
587  h_trkVz->Fill(track->vz());
588  }
589 
590  //-------HLT Trigger --------------------------------
591  edm::Handle<TriggerResults> triggerResults;
592  bool JetTrigPass= false;
593  if(iEvent.getByLabel(hltSrc_, triggerResults)){
594  const edm::TriggerNames & trigNames = iEvent.triggerNames(*triggerResults);
595  for (unsigned int i=0; i< triggerResults->size(); i++){
596  std::string trigName = trigNames.triggerName(i);
597 
598  if(JetTrigPass) continue;
599 
600  for(size_t t=0; t <jetTrigger_.size(); ++t){
601 
602  if(JetTrigPass) continue;
603 
604  string string_search (jetTrigger_[t]);
605  size_t found = trigName.find(string_search);
606 
607  if(found != string::npos){
608  int thisTrigger_ = trigNames.triggerIndex(trigName);
609  if(triggerResults->accept(thisTrigger_))JetTrigPass = true;
610  }//if trigger found
611  }//for(t=0;..)
612  }//for(i=0; ..)
613  }//if trigger colleciton exist)
614 
615  //------ Primary Vertices-------
617 
618  if (iEvent.getByLabel(pvSrc_, PVCollection )) {
619  int nPVcount = 0;
620  int nPVcount_ST =0; //For Single Trigger(hence ST)
621 
622  for (reco::VertexCollection::const_iterator pv = PVCollection->begin(); pv != PVCollection->end(); ++pv) {
623  //--- vertex selection
624  if (pv->isFake() || pv->tracksSize()==0) continue;
625  nPVcount++; // count non fake pv:
626 
627  if(JetTrigPass)nPVcount_ST++; //non-fake pv with a specific trigger
628 
629  if (pv->ndof() < minVtxNdf_ || (pv->ndof()+3.)/pv->tracksSize() < 2*minVtxWgt_) continue;
630 
631  //Fill this map to store xyx for pv so that later we can remove the first one for run aver
632  mapPVx[countLumi_].push_back(pv->x());
633  mapPVy[countLumi_].push_back(pv->y());
634  mapPVz[countLumi_].push_back(pv->z());
635 
636  if(!StartAverage_){//for first N LS
637  h_PVx[0]->Fill(pv->x());
638  h_PVy[0]->Fill(pv->y());
639  h_PVz[0]->Fill(pv->z());
640  h_PVxz->Fill(pv->z(),pv->x());
641  h_PVyz->Fill(pv->z(),pv->y());
642  }//for first N LiS
643  else{
644  h_PVxz->Fill(pv->z(),pv->x());
645  h_PVyz->Fill(pv->z(),pv->y());}
646 
647  }//loop over pvs
648 
649 
650  if (nPVcount> 0 )h_nVtx->Fill(nPVcount*1.); //no need to change it for average BS
651 
652  mapNPV[countLumi_].push_back((nPVcount_ST));
653 
654  if(!StartAverage_){ if (nPVcount_ST>0 ) h_nVtx_st->Fill(nPVcount_ST*1.);}
655 
656  }//if pv collection is availaable
657 
658 
659  if(StartAverage_)
660  {
661  map<int, std::vector<float> >::iterator itpvx=mapPVx.begin();
662  map<int, std::vector<float> >::iterator itpvy=mapPVy.begin();
663  map<int, std::vector<float> >::iterator itpvz=mapPVz.begin();
664 
665  map<int, std::vector<int> >::iterator itbspvinfo=mapNPV.begin();
666 
667  if( (int)mapPVx.size() > resetFitNLumi_){ //sometimes the events is not there but LS is there!
668  mapPVx.erase(itpvx);
669  mapPVy.erase(itpvy);
670  mapPVz.erase(itpvz);
671  mapNPV.erase(itbspvinfo);
672  }//loop over Last N lumi collected
673 
674  }//StartAverage==true
675 
676  processed_ = true;
677 }
678 
679 
680 //--------------------------------------------------------
682  const EventSetup& iSetup) {
683  int nthlumi = lumiSeg.id().luminosityBlock();
684  edm::LogInfo("BeamMonitor") << "endLuminosityBlock:: Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
685 
686  if (onlineMode_ && nthlumi < nextlumi_) return;
687  const edm::TimeValue_t fendtimestamp = lumiSeg.endTime().value();
688  const std::time_t fendtime = fendtimestamp >> 32;
689  tmpTime = refBStime[1] = refPVtime[1] = fendtime;
690 }
691 
692 //--------------------------------------------------------
693 void BeamMonitor::FitAndFill(const LuminosityBlock& lumiSeg,int &lastlumi,int &nextlumi,int &nthlumi){
694  if (onlineMode_ && (nthlumi <= nextlumi)) return;
695 
696  //set the correct run number when no event in the LS for fake output
698 
699  int currentlumi = nextlumi;
700  edm::LogInfo("BeamMonitor") << "FitAndFill:: Lumi of the current fit: " << currentlumi << endl;
701  lastlumi = currentlumi;
702  endLumiOfBSFit_ = currentlumi;
703  endLumiOfPVFit_ = currentlumi;
704 
705 
706  //---------Fix for Runninv average-------------
708 
709  if(StartAverage_)
710  {
711  size_t SizeToRemovePV=0;
712  std::map<int, std::size_t>::iterator rmlspv = mapLSPVStoreSize.begin();
713  SizeToRemovePV= rmlspv->second;
714  int changedAfterThisPV=0;
715  for(std::map<int, std::size_t>::iterator rmLSPV = mapLSPVStoreSize.begin(); rmLSPV!=mapLSPVStoreSize.end(); ++rmLSPV, ++changedAfterThisPV){
716  if(changedAfterThisPV > 0 ){ (rmLSPV->second) = (rmLSPV->second)-SizeToRemovePV;}
717  }
718 
719  theBeamFitter->resizePVvector(SizeToRemovePV);
720 
721  map<int, std::size_t >::iterator tmpItpv=mapLSPVStoreSize.begin();
722  mapLSPVStoreSize.erase(tmpItpv);
723  }
724  if(debug_)edm::LogInfo("BeamMonitor") << "FitAndFill:: Size of thePVvector After removing the PVs = " << theBeamFitter->getPVvectorSize()<<endl;
725 
726 
727  //lets filt the PV for GUI here: It was in analyzer in preivous versiton but moved here due to absence of event in some lumis, works OK
728  bool resetHistoFlag_=false;
729  if((int)mapPVx.size() >= resetFitNLumi_ && (StartAverage_)){
730  h_PVx[0]->Reset();
731  h_PVy[0]->Reset();
732  h_PVz[0]->Reset();
733  h_nVtx_st->Reset();
734  resetHistoFlag_ = true;
735  }
736 
737  int MaxPVs = 0;
738  int countEvtLastNLS_=0;
739  int countTotPV_= 0;
740 
741  std::map< int, std::vector<int> >::iterator mnpv=mapNPV.begin();
742  std::map< int, std::vector<float> >::iterator mpv2=mapPVy.begin();
743  std::map< int, std::vector<float> >::iterator mpv3=mapPVz.begin();
744 
745  for(std::map< int, std::vector<float> >::iterator mpv1=mapPVx.begin(); mpv1 != mapPVx.end(); ++mpv1, ++mpv2, ++mpv3, ++mnpv)
746  {
747  std::vector<float>::iterator mpvs2 = (mpv2->second).begin();
748  std::vector<float>::iterator mpvs3 = (mpv3->second).begin();
749  for(std::vector<float>::iterator mpvs1=(mpv1->second).begin(); mpvs1 !=(mpv1->second).end(); ++mpvs1, ++mpvs2, ++mpvs3){
750  if(resetHistoFlag_)
751  {h_PVx[0]->Fill( *mpvs1 ); //these histogram are reset after StartAverage_ flag is ON
752  h_PVy[0]->Fill( *mpvs2 );
753  h_PVz[0]->Fill( *mpvs3 );
754  }
755  }//loop over second
756 
757  //Do the same here for nPV distr.
758  for(std::vector<int>::iterator mnpvs = (mnpv->second).begin(); mnpvs != (mnpv->second).end(); ++mnpvs){
759  if((*mnpvs > 0) && (resetHistoFlag_) )h_nVtx_st->Fill( (*mnpvs)*(1.0) );
760  countEvtLastNLS_++;
761  countTotPV_ += (*mnpvs);
762  if((*mnpvs) > MaxPVs) MaxPVs = (*mnpvs);
763  }//loop over second of mapNPV
764 
765  }//loop over last N lumis
766 
767  char tmpTitlePV[100];
768  sprintf(tmpTitlePV,"%s %i %s %i","Num. of reco. vertices for LS: ",beginLumiOfPVFit_," to ",endLumiOfPVFit_);
769  h_nVtx_st->setAxisTitle(tmpTitlePV,1);
770 
771  std::vector<float> DipPVInfo_;
772  DipPVInfo_.clear();
773 
774  if(countTotPV_ != 0 ){
775  DipPVInfo_.push_back((float)countEvtLastNLS_);
776  DipPVInfo_.push_back(h_nVtx_st->getMean());
777  DipPVInfo_.push_back(h_nVtx_st->getMeanError());
778  DipPVInfo_.push_back(h_nVtx_st->getRMS());
779  DipPVInfo_.push_back(h_nVtx_st->getRMSError());
780  DipPVInfo_.push_back((float)MaxPVs);
781  DipPVInfo_.push_back((float)countTotPV_);
782  MaxPVs =0;
783  }
784  else{ for(size_t i= 0; i < 7; i++){if(i>0)DipPVInfo_.push_back(0.);
785  else DipPVInfo_.push_back((float)countEvtLastNLS_);}
786  }
787  theBeamFitter->SetPVInfo(DipPVInfo_);
788  countEvtLastNLS_=0;
789 
790 
791 
792  if (onlineMode_) { // filling LS gap
793  // FIXME: need to add protection for the case if the gap is at the resetting LS!
794  const int countLS_bs = hs["x0_lumi"]->getTH1()->GetEntries();
795  const int countLS_pv = hs["PVx_lumi"]->getTH1()->GetEntries();
796  edm::LogInfo("BeamMonitor") << "FitAndFill:: countLS_bs = " << countLS_bs << " ; countLS_pv = " << countLS_pv << std::endl;
797  int LSgap_bs = currentlumi/fitNLumi_ - countLS_bs;
798  int LSgap_pv = currentlumi/fitPVNLumi_ - countLS_pv;
799  if (currentlumi%fitNLumi_ == 0)
800  LSgap_bs--;
801  if (currentlumi%fitPVNLumi_ == 0)
802  LSgap_pv--;
803  edm::LogInfo("BeamMonitor") << "FitAndFill:: LSgap_bs = " << LSgap_bs << " ; LSgap_pv = " << LSgap_pv << std::endl;
804  // filling previous fits if LS gap ever exists
805  for (int ig = 0; ig < LSgap_bs; ig++) {
806  hs["x0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );//x0 , x0err, fitNLumi_; see DQMCore....
807  hs["y0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
808  hs["z0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
809  hs["sigmaX0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
810  hs["sigmaY0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
811  hs["sigmaZ0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
812  }
813  for (int ig = 0; ig < LSgap_pv; ig++) {
814  hs["PVx_lumi"]->ShiftFillLast( 0., 0., fitPVNLumi_ );
815  hs["PVy_lumi"]->ShiftFillLast( 0., 0., fitPVNLumi_ );
816  hs["PVz_lumi"]->ShiftFillLast( 0., 0., fitPVNLumi_ );
817  }
818  const int previousLS = h_nTrk_lumi->getTH1()->GetEntries();
819  for (int i=1;i < (currentlumi - previousLS);i++)//if (current-previoius)= 1 then never go inside the for loop!!!!!!!!!!!
821  }
822 
823  edm::LogInfo("BeamMonitor") << "FitAndFill:: Time lapsed since last scroll = " << tmpTime - refTime << std:: endl;
824 
825  if (testScroll(tmpTime,refTime)) {
826  scrollTH1(hs["x0_time"]->getTH1(),refTime);
827  scrollTH1(hs["y0_time"]->getTH1(),refTime);
828  scrollTH1(hs["z0_time"]->getTH1(),refTime);
829  scrollTH1(hs["sigmaX0_time"]->getTH1(),refTime);
830  scrollTH1(hs["sigmaY0_time"]->getTH1(),refTime);
831  scrollTH1(hs["sigmaZ0_time"]->getTH1(),refTime);
832  scrollTH1(hs["PVx_time"]->getTH1(),refTime);
833  scrollTH1(hs["PVy_time"]->getTH1(),refTime);
834  scrollTH1(hs["PVz_time"]->getTH1(),refTime);
835  }
836 
837  bool doPVFit = false;
838 
839  if (fitPVNLumi_ > 0) {
840  if (onlineMode_) {
841  if (currentlumi%fitPVNLumi_ == 0)
842  doPVFit = true;
843  }
844  else
845  if (countLumi_%fitPVNLumi_ == 0)
846  doPVFit = true;
847  }
848  else
849  doPVFit = true;
850 
851 
852  if (doPVFit) {
853  edm::LogInfo("BeamMonitor") << "FitAndFill:: Do PV Fitting for LS = " << beginLumiOfPVFit_ << " to " << endLumiOfPVFit_ << std::endl;
854  // Primary Vertex Fit:
855  if (h_PVx[0]->getTH1()->GetEntries() > minNrVertices_) {
856 
857  pvResults->Reset();
858  char tmpTitle[50];
859  sprintf(tmpTitle,"%s %i %s %i","Fitted Primary Vertex (cm) of LS: ",beginLumiOfPVFit_," to ",endLumiOfPVFit_);
860  pvResults->setAxisTitle(tmpTitle,1);
861 
862  TF1 *fgaus = new TF1("fgaus","gaus");
863  double mean,width,meanErr,widthErr;
864  fgaus->SetLineColor(4);
865  h_PVx[0]->getTH1()->Fit("fgaus","QLM0");
866  mean = fgaus->GetParameter(1);
867  width = fgaus->GetParameter(2);
868  meanErr = fgaus->GetParError(1);
869  widthErr = fgaus->GetParError(2);
870 
871 
872  hs["PVx_lumi"]->ShiftFillLast(mean,width,fitPVNLumi_);
873  hs["PVx_lumi_all"]->setBinContent(currentlumi,mean);
874  hs["PVx_lumi_all"]->setBinError(currentlumi,width);
875  int nthBin = tmpTime - refTime;
876  if (nthBin < 0)
877  edm::LogInfo("BeamMonitor") << "FitAndFill:: Event time outside current range of time histograms!" << std::endl;
878  if (nthBin > 0) {
879  hs["PVx_time"]->setBinContent(nthBin,mean);
880  hs["PVx_time"]->setBinError(nthBin,width);
881  }
882  int jthBin = tmpTime - startTime;
883  if (jthBin > 0) {
884  hs["PVx_time_all"]->setBinContent(jthBin,mean);
885  hs["PVx_time_all"]->setBinError(jthBin,width);
886  }
887  pvResults->setBinContent(1,6,mean);
888  pvResults->setBinContent(1,3,width);
889  pvResults->setBinContent(2,6,meanErr);
890  pvResults->setBinContent(2,3,widthErr);
891 
892  dbe_->setCurrentFolder(monitorName_+"PrimaryVertex/");
893  const char* tmpfile;
894  TH1D * tmphisto;
895  // snap shot of the fit
896  tmpfile= (h_PVx[1]->getName()).c_str();
897  tmphisto = static_cast<TH1D *>((h_PVx[0]->getTH1())->Clone("tmphisto"));
898  h_PVx[1]->getTH1()->SetBins(tmphisto->GetNbinsX(),tmphisto->GetXaxis()->GetXmin(),tmphisto->GetXaxis()->GetXmax());
899  h_PVx[1] = dbe_->book1D(tmpfile,h_PVx[0]->getTH1F());
900  h_PVx[1]->getTH1()->Fit("fgaus","QLM");
901 
902 
903  h_PVy[0]->getTH1()->Fit("fgaus","QLM0");
904  mean = fgaus->GetParameter(1);
905  width = fgaus->GetParameter(2);
906  meanErr = fgaus->GetParError(1);
907  widthErr = fgaus->GetParError(2);
908  hs["PVy_lumi"]->ShiftFillLast(mean,width,fitPVNLumi_);
909  hs["PVy_lumi_all"]->setBinContent(currentlumi,mean);
910  hs["PVy_lumi_all"]->setBinError(currentlumi,width);
911  if (nthBin > 0) {
912  hs["PVy_time"]->setBinContent(nthBin,mean);
913  hs["PVy_time"]->setBinError(nthBin,width);
914  }
915  if (jthBin > 0) {
916  hs["PVy_time_all"]->setBinContent(jthBin,mean);
917  hs["PVy_time_all"]->setBinError(jthBin,width);
918  }
919  pvResults->setBinContent(1,5,mean);
920  pvResults->setBinContent(1,2,width);
921  pvResults->setBinContent(2,5,meanErr);
922  pvResults->setBinContent(2,2,widthErr);
923  // snap shot of the fit
924  tmpfile= (h_PVy[1]->getName()).c_str();
925  tmphisto = static_cast<TH1D *>((h_PVy[0]->getTH1())->Clone("tmphisto"));
926  h_PVy[1]->getTH1()->SetBins(tmphisto->GetNbinsX(),tmphisto->GetXaxis()->GetXmin(),tmphisto->GetXaxis()->GetXmax());
927  h_PVy[1]->update();
928  h_PVy[1] = dbe_->book1D(tmpfile,h_PVy[0]->getTH1F());
929  h_PVy[1]->getTH1()->Fit("fgaus","QLM");
930 
931 
932  h_PVz[0]->getTH1()->Fit("fgaus","QLM0");
933  mean = fgaus->GetParameter(1);
934  width = fgaus->GetParameter(2);
935  meanErr = fgaus->GetParError(1);
936  widthErr = fgaus->GetParError(2);
937  hs["PVz_lumi"]->ShiftFillLast(mean,width,fitPVNLumi_);
938  hs["PVz_lumi_all"]->setBinContent(currentlumi,mean);
939  hs["PVz_lumi_all"]->setBinError(currentlumi,width);
940  if (nthBin > 0) {
941  hs["PVz_time"]->setBinContent(nthBin,mean);
942  hs["PVz_time"]->setBinError(nthBin,width);
943  }
944  if (jthBin > 0) {
945  hs["PVz_time_all"]->setBinContent(jthBin,mean);
946  hs["PVz_time_all"]->setBinError(jthBin,width);
947  }
948  pvResults->setBinContent(1,4,mean);
949  pvResults->setBinContent(1,1,width);
950  pvResults->setBinContent(2,4,meanErr);
951  pvResults->setBinContent(2,1,widthErr);
952  // snap shot of the fit
953  tmpfile= (h_PVz[1]->getName()).c_str();
954  tmphisto = static_cast<TH1D *>((h_PVz[0]->getTH1())->Clone("tmphisto"));
955  h_PVz[1]->getTH1()->SetBins(tmphisto->GetNbinsX(),tmphisto->GetXaxis()->GetXmin(),tmphisto->GetXaxis()->GetXmax());
956  h_PVz[1]->update();
957  h_PVz[1] = dbe_->book1D(tmpfile,h_PVz[0]->getTH1F());
958  h_PVz[1]->getTH1()->Fit("fgaus","QLM");
959 
960  }//check if found min Vertices
961  }//do PVfit
962 
965  refPVtime[0] = 0;
966  }
967 
968 
969 
970 
971  //---------Readjustment of theBSvector, RefTime, beginLSofFit---------
972  vector<BSTrkParameters> theBSvector1 = theBeamFitter->getBSvector();
973  mapLSBSTrkSize[countLumi_]= (theBSvector1.size());
974  size_t PreviousRecords=0; //needed to fill nth record of tracks in GUI
975 
976  if(StartAverage_){
977  size_t SizeToRemove=0;
978  std::map<int, std::size_t>::iterator rmls=mapLSBSTrkSize.begin();
979  SizeToRemove = rmls->second;
980  if(debug_)edm::LogInfo("BeamMonitor")<< " The size to remove is = "<< SizeToRemove << endl;
981  int changedAfterThis=0;
982  for(std::map<int, std::size_t>::iterator rmLS = mapLSBSTrkSize.begin(); rmLS!=mapLSBSTrkSize.end(); ++rmLS, ++changedAfterThis){
983  if(changedAfterThis > 0 ){(rmLS->second) = (rmLS->second)-SizeToRemove;
984  if((mapLSBSTrkSize.size()- (size_t)changedAfterThis) == 2 )PreviousRecords = (rmLS->second);
985  } }
986 
987  theBeamFitter->resizeBSvector(SizeToRemove);
988 
989  map<int, std::size_t >::iterator tmpIt=mapLSBSTrkSize.begin();
990  mapLSBSTrkSize.erase(tmpIt);
991 
992  std::pair<int,int> checkfitLS = theBeamFitter->getFitLSRange();
993  std::pair<time_t,time_t> checkfitTime =theBeamFitter->getRefTime();
994  theBeamFitter->setFitLSRange(beginLumiOfBSFit_, checkfitLS.second);
995  theBeamFitter->setRefTime(refBStime[0], checkfitTime.second);
996  }
997 
998  //Fill the track for this fit
999  vector<BSTrkParameters> theBSvector = theBeamFitter->getBSvector();
1000  h_nTrk_lumi->ShiftFillLast( theBSvector.size() );
1001 
1002  if(debug_)edm::LogInfo("BeamMonitor")<< "FitAndFill:: Size of theBSViector.size() After =" << theBSvector.size() << endl;
1003 
1004 
1005 
1006  bool countFitting = false;
1007  if (theBSvector.size() >= PreviousRecords && theBSvector.size() >= min_Ntrks_) {
1008  countFitting = true;
1009  }
1010 
1011 
1012  //---Fix for Cut Flow Table for Running average in a same way//the previous code has problem for resetting!!!
1014  if(StartAverage_ && mapLSCF.size()){
1015  const TH1F& cutFlowToSubtract = mapLSCF.begin()->second;
1016  // Subtract the last cut flow from all of the others.
1017  std::map<int, TH1F>::iterator cf = mapLSCF.begin();
1018  // Start on second entry
1019  for(; cf != mapLSCF.end(); ++cf) {
1020  cf->second.Add(&cutFlowToSubtract, -1);
1021  }
1022  theBeamFitter->subtractFromCutFlow(&cutFlowToSubtract);
1023  // Remove the obsolete lumi section
1024  mapLSCF.erase(mapLSCF.begin());
1025  }
1026 
1027  if (resetHistos_) {
1028  h_d0_phi0->Reset();
1029  h_vx_vy->Reset();
1030  h_vx_dz->Reset();
1031  h_vy_dz->Reset();
1032  h_trk_z0->Reset();
1033  resetHistos_ = false;
1034  }
1035 
1036  if(StartAverage_) nthBSTrk_ = PreviousRecords; //after average proccess is ON//for 2-6 LS fit PreviousRecords is size from 2-5 LS
1037 
1038  edm::LogInfo("BeamMonitor")<<" The Previous Recored for this fit is ="<<nthBSTrk_<<endl;
1039 
1040  unsigned int itrk = 0;
1041  for (vector<BSTrkParameters>::const_iterator BSTrk = theBSvector.begin();
1042  BSTrk != theBSvector.end(); ++BSTrk, ++itrk){
1043  if (itrk >= nthBSTrk_){//fill for this record only !!
1044  h_d0_phi0->Fill( BSTrk->phi0(), BSTrk->d0() );
1045  double vx = BSTrk->vx();
1046  double vy = BSTrk->vy();
1047  double z0 = BSTrk->z0();
1048  h_vx_vy->Fill( vx, vy );
1049  h_vx_dz->Fill( z0, vx );
1050  h_vy_dz->Fill( z0, vy );
1051  h_trk_z0->Fill( z0 );
1052  }
1053  }
1054 
1055 
1056  nthBSTrk_ = theBSvector.size(); // keep track of num of tracks filled so far
1057 
1058  edm::LogInfo("BeamMonitor")<<" The Current Recored for this fit is ="<<nthBSTrk_<<endl;
1059 
1060  if (countFitting) edm::LogInfo("BeamMonitor") << "FitAndFill:: Num of tracks collected = " << nthBSTrk_ << endl;
1061 
1062 
1063  if (fitNLumi_ > 0) {
1064  if (onlineMode_){
1065  if (currentlumi%fitNLumi_!=0) {
1066 // for (std::map<TString,MonitorElement*>::iterator itAll = hs.begin();
1067 // itAll != hs.end(); ++itAll) {
1068 // if ((*itAll).first.Contains("all")) {
1069 // (*itAll).second->setBinContent(currentlumi,0.);
1070 // (*itAll).second->setBinError(currentlumi,0.);
1071 // }
1072 // }
1073  return;
1074  }
1075  }
1076  else
1077  if (countLumi_%fitNLumi_!=0) return;
1078  }
1079 
1080  edm::LogInfo("BeamMonitor") << "FitAndFill:: [DebugTime] refBStime[0] = " << refBStime[0]
1081  << "; address = " << &refBStime[0] << std::endl;
1082  edm::LogInfo("BeamMonitor") << "FitAndFill:: [DebugTime] refBStime[1] = " << refBStime[1]
1083  << "; address = " << &refBStime[1] << std::endl;
1084 
1085  if (countFitting) {
1086  nFits_++;
1087  std::pair<int,int> fitLS = theBeamFitter->getFitLSRange();
1088  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamFitter] Do BeamSpot Fit for LS = " << fitLS.first << " to " << fitLS.second << std::endl;
1089  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamMonitor] Do BeamSpot Fit for LS = " << beginLumiOfBSFit_ << " to " << endLumiOfBSFit_ << std::endl;
1090 
1091  //Now Run the PV and Track Fitter over the collected tracks and pvs
1094  if (bs.type() > 0) // with good beamwidth fit
1095  preBS = bs; // cache good fit results
1096 
1097  edm::LogInfo("BeamMonitor") << "\n RESULTS OF DEFAULT FIT:" << endl;
1098  edm::LogInfo("BeamMonitor") << bs << endl;
1099  edm::LogInfo("BeamMonitor") << "[BeamFitter] fitting done \n" << endl;
1100 
1101  hs["x0_lumi"]->ShiftFillLast( bs.x0(), bs.x0Error(), fitNLumi_ );
1102  hs["y0_lumi"]->ShiftFillLast( bs.y0(), bs.y0Error(), fitNLumi_ );
1103  hs["z0_lumi"]->ShiftFillLast( bs.z0(), bs.z0Error(), fitNLumi_ );
1104  hs["sigmaX0_lumi"]->ShiftFillLast( bs.BeamWidthX(), bs.BeamWidthXError(), fitNLumi_ );
1105  hs["sigmaY0_lumi"]->ShiftFillLast( bs.BeamWidthY(), bs.BeamWidthYError(), fitNLumi_ );
1106  hs["sigmaZ0_lumi"]->ShiftFillLast( bs.sigmaZ(), bs.sigmaZ0Error(), fitNLumi_ );
1107  hs["x0_lumi_all"]->setBinContent(currentlumi,bs.x0());
1108  hs["x0_lumi_all"]->setBinError(currentlumi,bs.x0Error());
1109  hs["y0_lumi_all"]->setBinContent(currentlumi,bs.y0());
1110  hs["y0_lumi_all"]->setBinError(currentlumi,bs.y0Error());
1111  hs["z0_lumi_all"]->setBinContent(currentlumi,bs.z0());
1112  hs["z0_lumi_all"]->setBinError(currentlumi,bs.z0Error());
1113  hs["sigmaX0_lumi_all"]->setBinContent(currentlumi, bs.BeamWidthX());
1114  hs["sigmaX0_lumi_all"]->setBinError(currentlumi, bs.BeamWidthXError());
1115  hs["sigmaY0_lumi_all"]->setBinContent(currentlumi, bs.BeamWidthY());
1116  hs["sigmaY0_lumi_all"]->setBinError(currentlumi, bs.BeamWidthYError());
1117  hs["sigmaZ0_lumi_all"]->setBinContent(currentlumi, bs.sigmaZ());
1118  hs["sigmaZ0_lumi_all"]->setBinError(currentlumi, bs.sigmaZ0Error());
1119 
1120  int nthBin = tmpTime - refTime;
1121  if (nthBin > 0) {
1122  hs["x0_time"]->setBinContent(nthBin, bs.x0());
1123  hs["y0_time"]->setBinContent(nthBin, bs.y0());
1124  hs["z0_time"]->setBinContent(nthBin, bs.z0());
1125  hs["sigmaX0_time"]->setBinContent(nthBin, bs.BeamWidthX());
1126  hs["sigmaY0_time"]->setBinContent(nthBin, bs.BeamWidthY());
1127  hs["sigmaZ0_time"]->setBinContent(nthBin, bs.sigmaZ());
1128  hs["x0_time"]->setBinError(nthBin, bs.x0Error());
1129  hs["y0_time"]->setBinError(nthBin, bs.y0Error());
1130  hs["z0_time"]->setBinError(nthBin, bs.z0Error());
1131  hs["sigmaX0_time"]->setBinError(nthBin, bs.BeamWidthXError());
1132  hs["sigmaY0_time"]->setBinError(nthBin, bs.BeamWidthYError());
1133  hs["sigmaZ0_time"]->setBinError(nthBin, bs.sigmaZ0Error());
1134  }
1135 
1136  int jthBin = tmpTime - startTime;
1137  if (jthBin > 0) {
1138  hs["x0_time_all"]->setBinContent(jthBin, bs.x0());
1139  hs["y0_time_all"]->setBinContent(jthBin, bs.y0());
1140  hs["z0_time_all"]->setBinContent(jthBin, bs.z0());
1141  hs["sigmaX0_time_all"]->setBinContent(jthBin, bs.BeamWidthX());
1142  hs["sigmaY0_time_all"]->setBinContent(jthBin, bs.BeamWidthY());
1143  hs["sigmaZ0_time_all"]->setBinContent(jthBin, bs.sigmaZ());
1144  hs["x0_time_all"]->setBinError(jthBin, bs.x0Error());
1145  hs["y0_time_all"]->setBinError(jthBin, bs.y0Error());
1146  hs["z0_time_all"]->setBinError(jthBin, bs.z0Error());
1147  hs["sigmaX0_time_all"]->setBinError(jthBin, bs.BeamWidthXError());
1148  hs["sigmaY0_time_all"]->setBinError(jthBin, bs.BeamWidthYError());
1149  hs["sigmaZ0_time_all"]->setBinError(jthBin, bs.sigmaZ0Error());
1150  }
1151 
1152  h_x0->Fill( bs.x0());
1153  h_y0->Fill( bs.y0());
1154  h_z0->Fill( bs.z0());
1155  if (bs.type() > 0) { // with good beamwidth fit
1156  h_sigmaX0->Fill( bs.BeamWidthX());
1157  h_sigmaY0->Fill( bs.BeamWidthY());
1158  }
1159  h_sigmaZ0->Fill( bs.sigmaZ());
1160 
1161  if (nthBSTrk_ >= 2*min_Ntrks_) {
1162  double amp = std::sqrt(bs.x0()*bs.x0()+bs.y0()*bs.y0());
1163  double alpha = std::atan2(bs.y0(),bs.x0());
1164  TF1 *f1 = new TF1("f1","[0]*sin(x-[1])",-3.14,3.14);
1165  f1->SetParameters(amp,alpha);
1166  f1->SetParLimits(0,amp-0.1,amp+0.1);
1167  f1->SetParLimits(1,alpha-0.577,alpha+0.577);
1168  f1->SetLineColor(4);
1169  h_d0_phi0->getTProfile()->Fit("f1","QR");
1170 
1171  double mean = bs.z0();
1172  double width = bs.sigmaZ();
1173  TF1 *fgaus = new TF1("fgaus","gaus");
1174  fgaus->SetParameters(mean,width);
1175  fgaus->SetLineColor(4);
1176  h_trk_z0->getTH1()->Fit("fgaus","QLRM","",mean-3*width,mean+3*width);
1177  }
1178 
1179  fitResults->Reset();
1180  std::pair<int,int> LSRange = theBeamFitter->getFitLSRange();
1181  char tmpTitle[50];
1182  sprintf(tmpTitle,"%s %i %s %i","Fitted Beam Spot (cm) of LS: ",LSRange.first," to ",LSRange.second);
1183  fitResults->setAxisTitle(tmpTitle,1);
1184  fitResults->setBinContent(1,8,bs.x0());
1185  fitResults->setBinContent(1,7,bs.y0());
1186  fitResults->setBinContent(1,6,bs.z0());
1187  fitResults->setBinContent(1,5,bs.sigmaZ());
1188  fitResults->setBinContent(1,4,bs.dxdz());
1189  fitResults->setBinContent(1,3,bs.dydz());
1190  if (bs.type() > 0) { // with good beamwidth fit
1191  fitResults->setBinContent(1,2,bs.BeamWidthX());
1192  fitResults->setBinContent(1,1,bs.BeamWidthY());
1193  }
1194  else { // fill cached widths
1197  }
1198 
1199  fitResults->setBinContent(2,8,bs.x0Error());
1200  fitResults->setBinContent(2,7,bs.y0Error());
1201  fitResults->setBinContent(2,6,bs.z0Error());
1203  fitResults->setBinContent(2,4,bs.dxdzError());
1204  fitResults->setBinContent(2,3,bs.dydzError());
1205  if (bs.type() > 0) { // with good beamwidth fit
1208  }
1209  else { // fill cached width errors
1212  }
1213 
1214  // count good fit
1215  // if (std::fabs(refBS.x0()-bs.x0())/bs.x0Error() < deltaSigCut_) { // disabled temporarily
1216  summaryContent_[0] += 1.;
1217  // }
1218  // if (std::fabs(refBS.y0()-bs.y0())/bs.y0Error() < deltaSigCut_) { // disabled temporarily
1219  summaryContent_[1] += 1.;
1220  // }
1221  // if (std::fabs(refBS.z0()-bs.z0())/bs.z0Error() < deltaSigCut_) { // disabled temporarily
1222  summaryContent_[2] += 1.;
1223  // }
1224 
1225  } //if (theBeamFitter->runPVandTrkFitter())
1226  else { // beam fit fails
1228  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamMonitor] Beam fit fails!!! \n" << endl;
1229  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamMonitor] Output beam spot for DIP \n" << endl;
1230  edm::LogInfo("BeamMonitor") << bs << endl;
1231 
1232  hs["sigmaX0_lumi"]->ShiftFillLast( bs.BeamWidthX(), bs.BeamWidthXError(), fitNLumi_ );
1233  hs["sigmaY0_lumi"]->ShiftFillLast( bs.BeamWidthY(), bs.BeamWidthYError(), fitNLumi_ );
1234  hs["sigmaZ0_lumi"]->ShiftFillLast( bs.sigmaZ(), bs.sigmaZ0Error(), fitNLumi_ );
1235  hs["x0_lumi"]->ShiftFillLast( bs.x0(), bs.x0Error(), fitNLumi_ );
1236  hs["y0_lumi"]->ShiftFillLast( bs.y0(), bs.y0Error(), fitNLumi_ );
1237  hs["z0_lumi"]->ShiftFillLast( bs.z0(), bs.z0Error(), fitNLumi_ );
1238  } // end of beam fit fails
1239 
1240 
1241  } //-------- end of countFitting------------------------------------------
1242  else { // no fit
1243  // Overwrite Fit LS and fit time when no event processed or no track selected
1246  if (theBeamFitter->runPVandTrkFitter()) {} // Dump fake beam spot for DIP
1248  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamMonitor] No fitting \n" << endl;
1249  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamMonitor] Output fake beam spot for DIP \n" << endl;
1250  edm::LogInfo("BeamMonitor") << bs << endl;
1251 
1252  hs["sigmaX0_lumi"]->ShiftFillLast( bs.BeamWidthX(), bs.BeamWidthXError(), fitNLumi_ );
1253  hs["sigmaY0_lumi"]->ShiftFillLast( bs.BeamWidthY(), bs.BeamWidthYError(), fitNLumi_ );
1254  hs["sigmaZ0_lumi"]->ShiftFillLast( bs.sigmaZ(), bs.sigmaZ0Error(), fitNLumi_ );
1255  hs["x0_lumi"]->ShiftFillLast( bs.x0(), bs.x0Error(), fitNLumi_ );
1256  hs["y0_lumi"]->ShiftFillLast( bs.y0(), bs.y0Error(), fitNLumi_ );
1257  hs["z0_lumi"]->ShiftFillLast( bs.z0(), bs.z0Error(), fitNLumi_ );
1258  }
1259 
1260 
1261 
1262  // Fill summary report
1263  if (countFitting) {
1264  for (int n = 0; n < nFitElements_; n++) {
1266  }
1267 
1268  summarySum_ = 0;
1269  for (int ii = 0; ii < nFitElements_; ii++) {
1271  }
1272  reportSummary_ = summarySum_ / (nFitElements_ * nFits_);
1274 
1275  for ( int bi = 0; bi < nFitElements_ ; bi++) {
1276  reportSummaryMap->setBinContent(1,bi+1,summaryContent_[bi] / (float)nFits_);
1277  }
1278  }
1279 
1280 
1281 
1282 
1283  if ( ( resetFitNLumi_ > 0 &&
1284  ((onlineMode_ && countLumi_==resetFitNLumi_ ) || //OR it should be currentLumi_ (if in sequence then does not mattar)
1286  ) || (StartAverage_) ){
1287 
1288  edm::LogInfo("BeamMonitor") << "FitAndFill:: The flag is ON for running average Beam Spot fit"<<endl;
1289  StartAverage_ = true;
1290  firstAverageFit_++;
1291  resetHistos_ = true;
1292  nthBSTrk_ = 0;
1293  beginLumiOfBSFit_= 0;
1294  refBStime[0] = 0;
1295 
1296  }
1297 
1298 
1299 
1300 }
1301 
1302 //--------------------------------------------------------
1304  if(debug_)edm::LogInfo("BeamMonitor") << " RestartingFitting:: Restart Beami everything to a fresh start !!! because Gap is > 10 LS" <<endl;
1305  //track based fit reset here
1306  resetHistos_ = true;
1307  nthBSTrk_ = 0;
1313  beginLumiOfBSFit_ = 0;
1314  refBStime[0] = 0;
1315  //pv based fit iis reset here
1316  h_PVx[0]->Reset();
1317  h_PVy[0]->Reset();
1318  h_PVz[0]->Reset();
1319  beginLumiOfPVFit_ = 0;
1320  refPVtime[0] = 0;
1321  //Clear all the Maps here
1322  mapPVx.clear();
1323  mapPVy.clear();
1324  mapPVz.clear();
1325  mapNPV.clear();
1326  mapBeginBSLS.clear();
1327  mapBeginPVLS.clear();
1328  mapBeginBSTime.clear();
1329  mapBeginPVTime.clear();
1330  mapLSBSTrkSize.clear();
1331  mapLSPVStoreSize.clear();
1332  mapLSCF.clear(); countGapLumi_=0; countLumi_=0; StartAverage_=false;
1333 
1334 }
1335 
1336 //-------------------------------------------------------
1337 void BeamMonitor::endRun(const Run& r, const EventSetup& context){
1338 
1339 if(debug_)edm::LogInfo("BeamMonitor") << "endRun:: Clearing all the Maps "<<endl;
1340 //Clear all the Maps here
1341 mapPVx.clear();
1342 mapPVy.clear();
1343 mapPVz.clear();
1344 mapNPV.clear();
1345 mapBeginBSLS.clear();
1346 mapBeginPVLS.clear();
1347 mapBeginBSTime.clear();
1348 mapBeginPVTime.clear();
1349 mapLSBSTrkSize.clear();
1350 mapLSPVStoreSize.clear();
1351 mapLSCF.clear();
1352 
1353 
1354 }
1355 
1356 //--------------------------------------------------------
1358  const EventSetup& iSetup){
1359  if (!onlineMode_) endLuminosityBlock(lumiSeg, iSetup);
1360 }
1361 
1362 //--------------------------------------------------------
1363 void BeamMonitor::scrollTH1(TH1 * h, time_t ref) {
1364  const char* offsetTime = formatFitTime(ref);
1365  TDatime da(offsetTime);
1366  if (lastNZbin > 0) {
1367  double val = h->GetBinContent(lastNZbin);
1368  double valErr = h->GetBinError(lastNZbin);
1369  h->Reset();
1370  h->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
1371  int bin = (lastNZbin > buffTime ? buffTime : 1);
1372  h->SetBinContent(bin,val);
1373  h->SetBinError(bin,valErr);
1374  }
1375  else {
1376  h->Reset();
1377  h->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
1378  }
1379 }
1380 
1381 //--------------------------------------------------------
1382 // Method to check whether to chane histogram time offset (forward only)
1383 bool BeamMonitor::testScroll(time_t & tmpTime_, time_t & refTime_){
1384  bool scroll_ = false;
1385  if (tmpTime_ - refTime_ >= intervalInSec_) {
1386  scroll_ = true;
1387  edm::LogInfo("BeamMonitor") << "testScroll:: Reset Time Offset" << std::endl;
1389  for (int bin = intervalInSec_; bin >= 1; bin--) {
1390  if (hs["x0_time"]->getBinContent(bin) > 0) {
1391  lastNZbin = bin;
1392  break;
1393  }
1394  }
1395  edm::LogInfo("BeamMonitor") << "testScroll:: Last non zero bin = " << lastNZbin << std::endl;
1396  if (tmpTime_ - refTime_ >= intervalInSec_ + lastNZbin) {
1397  edm::LogInfo("BeamMonitor") << "testScroll:: Time difference too large since last readout" << std::endl;
1398  lastNZbin = 0;
1399  refTime_ = tmpTime_ - buffTime;
1400  }
1401  else{
1402  edm::LogInfo("BeamMonitor") << "testScroll:: Offset to last record" << std::endl;
1403  int offset = ((lastNZbin > buffTime) ? (lastNZbin - buffTime) : (lastNZbin - 1));
1404  refTime_ += offset;
1405  }
1406  }
1407  return scroll_;
1408 }
1409 
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
Definition: BeamMonitor.cc:434
LuminosityBlockID id() const
const char * formatFitTime(const std::time_t &)
Definition: BeamMonitor.cc:50
T getParameter(std::string const &) const
BeamMonitor(const edm::ParameterSet &)
Definition: BeamMonitor.cc:77
double z0() const
z coordinate
Definition: BeamSpot.h:69
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
int i
Definition: DBlmapReader.cc:9
#define buffTime
Definition: BeamMonitor.cc:72
float alpha
Definition: AMPTWrapper.h:95
unsigned int minNrVertices_
Definition: BeamMonitor.h:98
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:208
void setBinContent(int binx, double content)
set content of bin (1-D)
double sigmaZ0Error() const
error on sigma z
Definition: BeamSpot.h:97
int nFitElements_
Definition: BeamMonitor.h:93
std::time_t refBStime[2]
Definition: BeamMonitor.h:90
MonitorElement * reportSummary
Definition: BeamMonitor.h:157
void analyze(const edm::Event &e, const edm::EventSetup &c)
Definition: BeamMonitor.cc:544
RunNumber_t run() const
Definition: RunBase.h:44
int endLumiOfPVFit_
Definition: BeamMonitor.h:87
const std::string & label
Definition: MVAComputer.cc:186
int resetFitNLumi_
Definition: BeamMonitor.h:72
bool runPVandTrkFitter()
Definition: BeamFitter.cc:409
MonitorElement * h_nVtx
Definition: BeamMonitor.h:131
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
double minVtxWgt_
Definition: BeamMonitor.h:100
MonitorElement * cutFlowTable
Definition: BeamMonitor.h:160
double dydzError() const
error on dydz
Definition: BeamSpot.h:101
void setRun(int run)
Definition: BeamFitter.h:119
MonitorElement * h_PVz[2]
Definition: BeamMonitor.h:135
#define CEST
bool testScroll(std::time_t &, std::time_t &)
std::vector< BSTrkParameters > getBSvector()
Definition: BeamFitter.h:91
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< int, std::vector< float > > mapPVx
Definition: BeamMonitor.h:142
void subtractFromCutFlow(const TH1F *toSubtract)
Definition: BeamFitter.h:93
MonitorElement * h_PVxz
Definition: BeamMonitor.h:136
double minVtxNdf_
Definition: BeamMonitor.h:99
bool processed_
Definition: BeamMonitor.h:107
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
std::size_t getPVvectorSize()
Definition: BeamFitter.h:67
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
edm::TimeValue_t ftimestamp
Definition: BeamMonitor.h:167
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
void resetTrkVector()
Definition: BeamFitter.h:48
void update(void)
Mark the object updated.
Timestamp const & beginTime() const
MonitorElement * h_sigmaZ0
Definition: BeamMonitor.h:130
MonitorElement * h_nTrk_lumi
Definition: BeamMonitor.h:116
std::map< int, std::size_t > mapLSBSTrkSize
Definition: BeamMonitor.h:148
tuple histo
Definition: trackerHits.py:12
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
MonitorElement * fitResults
Definition: BeamMonitor.h:124
std::vector< std::string > jetTrigger_
Definition: BeamMonitor.h:77
int fitPVNLumi_
Definition: BeamMonitor.h:71
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:223
MonitorElement * h_sigmaY0
Definition: BeamMonitor.h:129
double getMeanError(int axis=1) const
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:451
std::map< int, std::vector< float > > mapPVz
Definition: BeamMonitor.h:142
void Fill(long long x)
std::map< int, std::time_t > mapBeginPVTime
Definition: BeamMonitor.h:146
edm::InputTag bsSrc_
Definition: BeamMonitor.h:65
std::map< int, std::vector< int > > mapNPV
Definition: BeamMonitor.h:143
LuminosityBlockNumber_t luminosityBlock() const
std::map< int, std::time_t > mapBeginBSTime
Definition: BeamMonitor.h:146
double dydz() const
dydz slope
Definition: BeamSpot.h:85
MonitorElement * h_y0
Definition: BeamMonitor.h:126
void ShiftFillLast(double y, double ye=0., int32_t xscale=1)
int intervalInSec_
Definition: BeamMonitor.h:74
void beginJob()
Definition: BeamMonitor.cc:127
int iEvent
Definition: GenABIO.cc:243
double dxdzError() const
error on dxdz
Definition: BeamSpot.h:99
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
int countGapLumi_
Definition: BeamMonitor.h:105
MonitorElement * h_vy_dz
Definition: BeamMonitor.h:121
T sqrt(T t)
Definition: SSEVec.h:28
Float_t reportSummary_
Definition: BeamMonitor.h:154
Timestamp const & endTime() const
void removeElement(const std::string &name)
Definition: DQMStore.cc:2353
MonitorElement * h_PVyz
Definition: BeamMonitor.h:137
void beginRun(const edm::Run &r, const edm::EventSetup &c)
Definition: BeamMonitor.cc:413
std::time_t refTime
Definition: BeamMonitor.h:166
MonitorElement * pvResults
Definition: BeamMonitor.h:138
int endLumiOfBSFit_
Definition: BeamMonitor.h:85
virtual void endJob()
Definition: EDAnalyzer.h:56
std::time_t refPVtime[2]
Definition: BeamMonitor.h:91
void RestartFitting()
reco::BeamSpot refBS
Definition: BeamMonitor.h:112
TH1 * getTH1(void) const
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:87
void setFitLSRange(int ls0, int ls1)
Definition: BeamFitter.h:115
TH1F * getTH1F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
std::pair< time_t, time_t > getRefTime()
Definition: BeamFitter.h:60
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:828
#define end
Definition: vmac.h:38
void resetLSRange()
Definition: BeamFitter.h:50
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
Definition: BeamSpot.h:106
unsigned int offset(bool)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1265
double BeamWidthXError() const
error on beam width X, assume error in X = Y
Definition: BeamSpot.h:104
double z0Error() const
error on z
Definition: BeamSpot.h:95
unsigned long long TimeValue_t
Definition: Timestamp.h:27
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
double dxdz() const
dxdz slope
Definition: BeamSpot.h:83
std::map< int, TH1F > mapLSCF
Definition: BeamMonitor.h:151
double x0Error() const
error on x
Definition: BeamSpot.h:91
double y0Error() const
error on y
Definition: BeamSpot.h:93
DQMStore * dbe_
Definition: BeamMonitor.h:79
int getRunNumber()
Definition: BeamFitter.h:108
double maxZ_
Definition: BeamMonitor.h:97
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:75
std::time_t startTime
Definition: BeamMonitor.h:165
TimeValue_t value() const
Definition: Timestamp.cc:72
edm::InputTag hltSrc_
Definition: BeamMonitor.h:68
edm::InputTag pvSrc_
Definition: BeamMonitor.h:67
double getRMSError(int axis=1) const
get RMS uncertainty of histogram along x, y or z axis(axis=1,2,3 respectively)
void FitAndFill(const edm::LuminosityBlock &lumiSeg, int &, int &, int &)
Definition: BeamMonitor.cc:693
Float_t summaryContent_[3]
Definition: BeamMonitor.h:156
MonitorElement * h_sigmaX0
Definition: BeamMonitor.h:128
bool StartAverage_
Definition: BeamMonitor.h:103
reco::BeamSpot preBS
Definition: BeamMonitor.h:113
MonitorElement * h_nVtx_st
Definition: BeamMonitor.h:132
MonitorElement * h_PVy[2]
Definition: BeamMonitor.h:134
void resizeBSvector(unsigned int nsize)
Definition: BeamFitter.h:69
tuple tracks
Definition: testEve_cfg.py:39
int beginLumiOfPVFit_
Definition: BeamMonitor.h:86
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
MonitorElement * reportSummaryContents[3]
Definition: BeamMonitor.h:158
double sigmaZ() const
sigma z
Definition: BeamSpot.h:81
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:89
double b
Definition: hdecay.h:120
LuminosityBlockNumber_t luminosityBlock() const
MonitorElement * h_x0
Definition: BeamMonitor.h:125
MonitorElement * h_trk_z0
Definition: BeamMonitor.h:118
T const * product() const
Definition: Handle.h:74
int resetPVNLumi_
Definition: BeamMonitor.h:73
std::map< int, int > mapBeginBSLS
Definition: BeamMonitor.h:145
Timestamp const & beginTime() const
Definition: RunBase.h:45
Float_t summarySum_
Definition: BeamMonitor.h:155
TH1F * getCutFlow()
Definition: BeamFitter.h:92
edm::ParameterSet parameters_
Definition: BeamMonitor.h:63
MonitorElement * h_trkPt
Definition: BeamMonitor.h:122
#define begin
Definition: vmac.h:31
MonitorElement * h_vx_dz
Definition: BeamMonitor.h:120
double getRMS(int axis=1) const
get RMS of histogram along x, y or z axis (axis=1, 2, 3 respectively)
MonitorElement * h_z0
Definition: BeamMonitor.h:127
void resetPVFitter()
Definition: BeamFitter.h:64
void resizePVvector(unsigned int npvsize)
Definition: BeamFitter.h:74
TProfile * getTProfile(void) const
double y0() const
y coordinate
Definition: BeamSpot.h:67
void resetCutFlow()
Definition: BeamFitter.h:100
unsigned int nthBSTrk_
Definition: BeamMonitor.h:92
void SetPVInfo(std::vector< float > v1_)
Definition: BeamFitter.h:79
tuple cout
Definition: gather_cfg.py:41
unsigned int min_Ntrks_
Definition: BeamMonitor.h:96
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
Definition: BeamMonitor.cc:681
void setRefTime(time_t t0, time_t t1)
Definition: BeamFitter.h:52
bool resetHistos_
Definition: BeamMonitor.h:102
double deltaSigCut_
Definition: BeamMonitor.h:95
TH2F * getTH2F(void) const
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:642
std::time_t tmpTime
Definition: BeamMonitor.h:164
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
int firstAverageFit_
Definition: BeamMonitor.h:104
BeamFitter * theBeamFitter
Definition: BeamMonitor.h:80
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
MonitorElement * h_PVx[2]
Definition: BeamMonitor.h:133
std::pair< int, int > getFitLSRange()
Definition: BeamFitter.h:112
void Reset(void)
reset ME (ie. contents, errors, etc)
std::map< int, int > mapBeginPVLS
Definition: BeamMonitor.h:145
int beginLumiOfBSFit_
Definition: BeamMonitor.h:84
MonitorElement * h_trkVz
Definition: BeamMonitor.h:123
void endRun(const edm::Run &r, const edm::EventSetup &c)
std::string monitorName_
Definition: BeamMonitor.h:64
std::map< int, std::vector< float > > mapPVy
Definition: BeamMonitor.h:142
MonitorElement * h_d0_phi0
Definition: BeamMonitor.h:117
edm::InputTag tracksLabel_
Definition: BeamMonitor.h:66
reco::BeamSpot getBeamSpot()
Definition: BeamFitter.h:89
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
Definition: Run.h:32
MonitorElement * h_vx_vy
Definition: BeamMonitor.h:119
int countLumi_
Definition: BeamMonitor.h:83
void scrollTH1(TH1 *, std::time_t)
BeamType type() const
return beam type
Definition: BeamSpot.h:130
MonitorElement * reportSummaryMap
Definition: BeamMonitor.h:159
bool onlineMode_
Definition: BeamMonitor.h:76
double x0() const
x coordinate
Definition: BeamSpot.h:65
std::map< TString, MonitorElement * > hs
Definition: BeamMonitor.h:139
std::map< int, size_t > mapLSPVStoreSize
Definition: BeamMonitor.h:149
void resetRefTime()
Definition: BeamFitter.h:51