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