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  delete tmphisto;
579 
580  //----Reco tracks -------------------------------------
582  iEvent.getByToken(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 --------------------------------
592  bool JetTrigPass= false;
593  if(iEvent.getByToken(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.getByToken(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  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_){ 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  std::map<int, std::size_t>::iterator rmLSPVi = mapLSPVStoreSize.begin();
712  size_t SizeToRemovePV= rmLSPVi->second;
713  for(std::map<int, std::size_t>::iterator rmLSPVe = mapLSPVStoreSize.end(); ++rmLSPVi != rmLSPVe;)
714  rmLSPVi->second -= SizeToRemovePV;
715 
716  theBeamFitter->resizePVvector(SizeToRemovePV);
717 
718  map<int, std::size_t >::iterator tmpItpv=mapLSPVStoreSize.begin();
719  mapLSPVStoreSize.erase(tmpItpv);
720  }
721  if(debug_)edm::LogInfo("BeamMonitor") << "FitAndFill:: Size of thePVvector After removing the PVs = " << theBeamFitter->getPVvectorSize()<<endl;
722 
723 
724  //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
725  bool resetHistoFlag_=false;
726  if((int)mapPVx.size() >= resetFitNLumi_ && (StartAverage_)){
727  h_PVx[0]->Reset();
728  h_PVy[0]->Reset();
729  h_PVz[0]->Reset();
730  h_nVtx_st->Reset();
731  resetHistoFlag_ = true;
732  }
733 
734  int MaxPVs = 0;
735  int countEvtLastNLS_=0;
736  int countTotPV_= 0;
737 
738  std::map< int, std::vector<int> >::iterator mnpv=mapNPV.begin();
739  std::map< int, std::vector<float> >::iterator mpv2=mapPVy.begin();
740  std::map< int, std::vector<float> >::iterator mpv3=mapPVz.begin();
741 
742  for(std::map< int, std::vector<float> >::iterator mpv1=mapPVx.begin(); mpv1 != mapPVx.end(); ++mpv1, ++mpv2, ++mpv3, ++mnpv)
743  {
744  std::vector<float>::iterator mpvs2 = (mpv2->second).begin();
745  std::vector<float>::iterator mpvs3 = (mpv3->second).begin();
746  for(std::vector<float>::iterator mpvs1=(mpv1->second).begin(); mpvs1 !=(mpv1->second).end(); ++mpvs1, ++mpvs2, ++mpvs3){
747  if(resetHistoFlag_)
748  {h_PVx[0]->Fill( *mpvs1 ); //these histogram are reset after StartAverage_ flag is ON
749  h_PVy[0]->Fill( *mpvs2 );
750  h_PVz[0]->Fill( *mpvs3 );
751  }
752  }//loop over second
753 
754  //Do the same here for nPV distr.
755  for(std::vector<int>::iterator mnpvs = (mnpv->second).begin(); mnpvs != (mnpv->second).end(); ++mnpvs){
756  if((*mnpvs > 0) && (resetHistoFlag_) )h_nVtx_st->Fill( (*mnpvs)*(1.0) );
757  countEvtLastNLS_++;
758  countTotPV_ += (*mnpvs);
759  if((*mnpvs) > MaxPVs) MaxPVs = (*mnpvs);
760  }//loop over second of mapNPV
761 
762  }//loop over last N lumis
763 
764  char tmpTitlePV[100];
765  sprintf(tmpTitlePV,"%s %i %s %i","Num. of reco. vertices for LS: ",beginLumiOfPVFit_," to ",endLumiOfPVFit_);
766  h_nVtx_st->setAxisTitle(tmpTitlePV,1);
767 
768  std::vector<float> DipPVInfo_;
769  DipPVInfo_.clear();
770 
771  if(countTotPV_ != 0 ){
772  DipPVInfo_.push_back((float)countEvtLastNLS_);
773  DipPVInfo_.push_back(h_nVtx_st->getMean());
774  DipPVInfo_.push_back(h_nVtx_st->getMeanError());
775  DipPVInfo_.push_back(h_nVtx_st->getRMS());
776  DipPVInfo_.push_back(h_nVtx_st->getRMSError());
777  DipPVInfo_.push_back((float)MaxPVs);
778  DipPVInfo_.push_back((float)countTotPV_);
779  MaxPVs =0;
780  }
781  else{ for(size_t i= 0; i < 7; i++){if(i>0)DipPVInfo_.push_back(0.);
782  else DipPVInfo_.push_back((float)countEvtLastNLS_);}
783  }
784  theBeamFitter->SetPVInfo(DipPVInfo_);
785  countEvtLastNLS_=0;
786 
787 
788 
789  if (onlineMode_) { // filling LS gap
790  // FIXME: need to add protection for the case if the gap is at the resetting LS!
791  const int countLS_bs = hs["x0_lumi"]->getTH1()->GetEntries();
792  const int countLS_pv = hs["PVx_lumi"]->getTH1()->GetEntries();
793  edm::LogInfo("BeamMonitor") << "FitAndFill:: countLS_bs = " << countLS_bs << " ; countLS_pv = " << countLS_pv << std::endl;
794  int LSgap_bs = currentlumi/fitNLumi_ - countLS_bs;
795  int LSgap_pv = currentlumi/fitPVNLumi_ - countLS_pv;
796  if (currentlumi%fitNLumi_ == 0)
797  LSgap_bs--;
798  if (currentlumi%fitPVNLumi_ == 0)
799  LSgap_pv--;
800  edm::LogInfo("BeamMonitor") << "FitAndFill:: LSgap_bs = " << LSgap_bs << " ; LSgap_pv = " << LSgap_pv << std::endl;
801  // filling previous fits if LS gap ever exists
802  for (int ig = 0; ig < LSgap_bs; ig++) {
803  hs["x0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );//x0 , x0err, fitNLumi_; see DQMCore....
804  hs["y0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
805  hs["z0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
806  hs["sigmaX0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
807  hs["sigmaY0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
808  hs["sigmaZ0_lumi"]->ShiftFillLast( 0., 0., fitNLumi_ );
809  }
810  for (int ig = 0; ig < LSgap_pv; ig++) {
811  hs["PVx_lumi"]->ShiftFillLast( 0., 0., fitPVNLumi_ );
812  hs["PVy_lumi"]->ShiftFillLast( 0., 0., fitPVNLumi_ );
813  hs["PVz_lumi"]->ShiftFillLast( 0., 0., fitPVNLumi_ );
814  }
815  const int previousLS = h_nTrk_lumi->getTH1()->GetEntries();
816  for (int i=1;i < (currentlumi - previousLS);i++)//if (current-previoius)= 1 then never go inside the for loop!!!!!!!!!!!
818  }
819 
820  edm::LogInfo("BeamMonitor") << "FitAndFill:: Time lapsed since last scroll = " << tmpTime - refTime << std:: endl;
821 
822  if (testScroll(tmpTime,refTime)) {
823  scrollTH1(hs["x0_time"]->getTH1(),refTime);
824  scrollTH1(hs["y0_time"]->getTH1(),refTime);
825  scrollTH1(hs["z0_time"]->getTH1(),refTime);
826  scrollTH1(hs["sigmaX0_time"]->getTH1(),refTime);
827  scrollTH1(hs["sigmaY0_time"]->getTH1(),refTime);
828  scrollTH1(hs["sigmaZ0_time"]->getTH1(),refTime);
829  scrollTH1(hs["PVx_time"]->getTH1(),refTime);
830  scrollTH1(hs["PVy_time"]->getTH1(),refTime);
831  scrollTH1(hs["PVz_time"]->getTH1(),refTime);
832  }
833 
834  bool doPVFit = false;
835 
836  if (fitPVNLumi_ > 0) {
837  if (onlineMode_) {
838  if (currentlumi%fitPVNLumi_ == 0)
839  doPVFit = true;
840  }
841  else
842  if (countLumi_%fitPVNLumi_ == 0)
843  doPVFit = true;
844  }
845  else
846  doPVFit = true;
847 
848 
849  if (doPVFit) {
850  edm::LogInfo("BeamMonitor") << "FitAndFill:: Do PV Fitting for LS = " << beginLumiOfPVFit_ << " to " << endLumiOfPVFit_ << std::endl;
851  // Primary Vertex Fit:
852  if (h_PVx[0]->getTH1()->GetEntries() > minNrVertices_) {
853 
854  pvResults->Reset();
855  char tmpTitle[50];
856  sprintf(tmpTitle,"%s %i %s %i","Fitted Primary Vertex (cm) of LS: ",beginLumiOfPVFit_," to ",endLumiOfPVFit_);
857  pvResults->setAxisTitle(tmpTitle,1);
858 
859  std::unique_ptr<TF1> fgaus{ new TF1("fgaus","gaus") };
860  double mean,width,meanErr,widthErr;
861  fgaus->SetLineColor(4);
862  h_PVx[0]->getTH1()->Fit(fgaus.get(),"QLM0");
863  mean = fgaus->GetParameter(1);
864  width = fgaus->GetParameter(2);
865  meanErr = fgaus->GetParError(1);
866  widthErr = fgaus->GetParError(2);
867 
868 
869  hs["PVx_lumi"]->ShiftFillLast(mean,width,fitPVNLumi_);
870  hs["PVx_lumi_all"]->setBinContent(currentlumi,mean);
871  hs["PVx_lumi_all"]->setBinError(currentlumi,width);
872  int nthBin = tmpTime - refTime;
873  if (nthBin < 0)
874  edm::LogInfo("BeamMonitor") << "FitAndFill:: Event time outside current range of time histograms!" << std::endl;
875  if (nthBin > 0) {
876  hs["PVx_time"]->setBinContent(nthBin,mean);
877  hs["PVx_time"]->setBinError(nthBin,width);
878  }
879  int jthBin = tmpTime - startTime;
880  if (jthBin > 0) {
881  hs["PVx_time_all"]->setBinContent(jthBin,mean);
882  hs["PVx_time_all"]->setBinError(jthBin,width);
883  }
884  pvResults->setBinContent(1,6,mean);
885  pvResults->setBinContent(1,3,width);
886  pvResults->setBinContent(2,6,meanErr);
887  pvResults->setBinContent(2,3,widthErr);
888 
889  dbe_->setCurrentFolder(monitorName_+"PrimaryVertex/");
890  const char* tmpfile;
891  TH1D * tmphisto;
892  // snap shot of the fit
893  tmpfile= (h_PVx[1]->getName()).c_str();
894  tmphisto = static_cast<TH1D *>((h_PVx[0]->getTH1())->Clone("tmphisto"));
895  h_PVx[1]->getTH1()->SetBins(tmphisto->GetNbinsX(),tmphisto->GetXaxis()->GetXmin(),tmphisto->GetXaxis()->GetXmax());
896  h_PVx[1] = dbe_->book1D(tmpfile,h_PVx[0]->getTH1F());
897  h_PVx[1]->getTH1()->Fit(fgaus.get(),"QLM");
898 
899 
900  h_PVy[0]->getTH1()->Fit(fgaus.get(),"QLM0");
901  mean = fgaus->GetParameter(1);
902  width = fgaus->GetParameter(2);
903  meanErr = fgaus->GetParError(1);
904  widthErr = fgaus->GetParError(2);
905  hs["PVy_lumi"]->ShiftFillLast(mean,width,fitPVNLumi_);
906  hs["PVy_lumi_all"]->setBinContent(currentlumi,mean);
907  hs["PVy_lumi_all"]->setBinError(currentlumi,width);
908  if (nthBin > 0) {
909  hs["PVy_time"]->setBinContent(nthBin,mean);
910  hs["PVy_time"]->setBinError(nthBin,width);
911  }
912  if (jthBin > 0) {
913  hs["PVy_time_all"]->setBinContent(jthBin,mean);
914  hs["PVy_time_all"]->setBinError(jthBin,width);
915  }
916  pvResults->setBinContent(1,5,mean);
917  pvResults->setBinContent(1,2,width);
918  pvResults->setBinContent(2,5,meanErr);
919  pvResults->setBinContent(2,2,widthErr);
920  // snap shot of the fit
921  tmpfile= (h_PVy[1]->getName()).c_str();
922  tmphisto = static_cast<TH1D *>((h_PVy[0]->getTH1())->Clone("tmphisto"));
923  h_PVy[1]->getTH1()->SetBins(tmphisto->GetNbinsX(),tmphisto->GetXaxis()->GetXmin(),tmphisto->GetXaxis()->GetXmax());
924  h_PVy[1]->update();
925  h_PVy[1] = dbe_->book1D(tmpfile,h_PVy[0]->getTH1F());
926  h_PVy[1]->getTH1()->Fit(fgaus.get(),"QLM");
927 
928 
929  h_PVz[0]->getTH1()->Fit(fgaus.get(),"QLM0");
930  mean = fgaus->GetParameter(1);
931  width = fgaus->GetParameter(2);
932  meanErr = fgaus->GetParError(1);
933  widthErr = fgaus->GetParError(2);
934  hs["PVz_lumi"]->ShiftFillLast(mean,width,fitPVNLumi_);
935  hs["PVz_lumi_all"]->setBinContent(currentlumi,mean);
936  hs["PVz_lumi_all"]->setBinError(currentlumi,width);
937  if (nthBin > 0) {
938  hs["PVz_time"]->setBinContent(nthBin,mean);
939  hs["PVz_time"]->setBinError(nthBin,width);
940  }
941  if (jthBin > 0) {
942  hs["PVz_time_all"]->setBinContent(jthBin,mean);
943  hs["PVz_time_all"]->setBinError(jthBin,width);
944  }
945  pvResults->setBinContent(1,4,mean);
946  pvResults->setBinContent(1,1,width);
947  pvResults->setBinContent(2,4,meanErr);
948  pvResults->setBinContent(2,1,widthErr);
949  // snap shot of the fit
950  tmpfile= (h_PVz[1]->getName()).c_str();
951  tmphisto = static_cast<TH1D *>((h_PVz[0]->getTH1())->Clone("tmphisto"));
952  h_PVz[1]->getTH1()->SetBins(tmphisto->GetNbinsX(),tmphisto->GetXaxis()->GetXmin(),tmphisto->GetXaxis()->GetXmax());
953  h_PVz[1]->update();
954  h_PVz[1] = dbe_->book1D(tmpfile,h_PVz[0]->getTH1F());
955  h_PVz[1]->getTH1()->Fit(fgaus.get(),"QLM");
956  delete tmphisto;
957 
958  }//check if found min Vertices
959  }//do PVfit
960 
963  refPVtime[0] = 0;
964  }
965 
966 
967 
968 
969  //---------Readjustment of theBSvector, RefTime, beginLSofFit---------
970  vector<BSTrkParameters> theBSvector1 = theBeamFitter->getBSvector();
971  mapLSBSTrkSize[countLumi_]= (theBSvector1.size());
972  size_t PreviousRecords=0; //needed to fill nth record of tracks in GUI
973 
974  if(StartAverage_){
975  size_t SizeToRemove=0;
976  std::map<int, std::size_t>::iterator rmls=mapLSBSTrkSize.begin();
977  SizeToRemove = rmls->second;
978  if(debug_)edm::LogInfo("BeamMonitor")<< " The size to remove is = "<< SizeToRemove << endl;
979  int changedAfterThis=0;
980  for(std::map<int, std::size_t>::iterator rmLS = mapLSBSTrkSize.begin(); rmLS!=mapLSBSTrkSize.end(); ++rmLS, ++changedAfterThis){
981  if(changedAfterThis > 0 ){(rmLS->second) = (rmLS->second)-SizeToRemove;
982  if((mapLSBSTrkSize.size()- (size_t)changedAfterThis) == 2 )PreviousRecords = (rmLS->second);
983  } }
984 
985  theBeamFitter->resizeBSvector(SizeToRemove);
986 
987  map<int, std::size_t >::iterator tmpIt=mapLSBSTrkSize.begin();
988  mapLSBSTrkSize.erase(tmpIt);
989 
990  std::pair<int,int> checkfitLS = theBeamFitter->getFitLSRange();
991  std::pair<time_t,time_t> checkfitTime =theBeamFitter->getRefTime();
992  theBeamFitter->setFitLSRange(beginLumiOfBSFit_, checkfitLS.second);
993  theBeamFitter->setRefTime(refBStime[0], checkfitTime.second);
994  }
995 
996  //Fill the track for this fit
997  vector<BSTrkParameters> theBSvector = theBeamFitter->getBSvector();
998  h_nTrk_lumi->ShiftFillLast( theBSvector.size() );
999 
1000  if(debug_)edm::LogInfo("BeamMonitor")<< "FitAndFill:: Size of theBSViector.size() After =" << theBSvector.size() << endl;
1001 
1002 
1003 
1004  bool countFitting = false;
1005  if (theBSvector.size() >= PreviousRecords && theBSvector.size() >= min_Ntrks_) {
1006  countFitting = true;
1007  }
1008 
1009 
1010  //---Fix for Cut Flow Table for Running average in a same way//the previous code has problem for resetting!!!
1012  if(StartAverage_ && mapLSCF.size()){
1013  const TH1F& cutFlowToSubtract = mapLSCF.begin()->second;
1014  // Subtract the last cut flow from all of the others.
1015  std::map<int, TH1F>::iterator cf = mapLSCF.begin();
1016  // Start on second entry
1017  for(; cf != mapLSCF.end(); ++cf) {
1018  cf->second.Add(&cutFlowToSubtract, -1);
1019  }
1020  theBeamFitter->subtractFromCutFlow(&cutFlowToSubtract);
1021  // Remove the obsolete lumi section
1022  mapLSCF.erase(mapLSCF.begin());
1023  }
1024 
1025  if (resetHistos_) {
1026  h_d0_phi0->Reset();
1027  h_vx_vy->Reset();
1028  h_vx_dz->Reset();
1029  h_vy_dz->Reset();
1030  h_trk_z0->Reset();
1031  resetHistos_ = false;
1032  }
1033 
1034  if(StartAverage_) nthBSTrk_ = PreviousRecords; //after average proccess is ON//for 2-6 LS fit PreviousRecords is size from 2-5 LS
1035 
1036  edm::LogInfo("BeamMonitor")<<" The Previous Recored for this fit is ="<<nthBSTrk_<<endl;
1037 
1038  unsigned int itrk = 0;
1039  for (vector<BSTrkParameters>::const_iterator BSTrk = theBSvector.begin();
1040  BSTrk != theBSvector.end(); ++BSTrk, ++itrk){
1041  if (itrk >= nthBSTrk_){//fill for this record only !!
1042  h_d0_phi0->Fill( BSTrk->phi0(), BSTrk->d0() );
1043  double vx = BSTrk->vx();
1044  double vy = BSTrk->vy();
1045  double z0 = BSTrk->z0();
1046  h_vx_vy->Fill( vx, vy );
1047  h_vx_dz->Fill( z0, vx );
1048  h_vy_dz->Fill( z0, vy );
1049  h_trk_z0->Fill( z0 );
1050  }
1051  }
1052 
1053 
1054  nthBSTrk_ = theBSvector.size(); // keep track of num of tracks filled so far
1055 
1056  edm::LogInfo("BeamMonitor")<<" The Current Recored for this fit is ="<<nthBSTrk_<<endl;
1057 
1058  if (countFitting) edm::LogInfo("BeamMonitor") << "FitAndFill:: Num of tracks collected = " << nthBSTrk_ << endl;
1059 
1060 
1061  if (fitNLumi_ > 0) {
1062  if (onlineMode_){
1063  if (currentlumi%fitNLumi_!=0) {
1064 // for (std::map<TString,MonitorElement*>::iterator itAll = hs.begin();
1065 // itAll != hs.end(); ++itAll) {
1066 // if ((*itAll).first.Contains("all")) {
1067 // (*itAll).second->setBinContent(currentlumi,0.);
1068 // (*itAll).second->setBinError(currentlumi,0.);
1069 // }
1070 // }
1071  return;
1072  }
1073  }
1074  else
1075  if (countLumi_%fitNLumi_!=0) return;
1076  }
1077 
1078  edm::LogInfo("BeamMonitor") << "FitAndFill:: [DebugTime] refBStime[0] = " << refBStime[0]
1079  << "; address = " << &refBStime[0] << std::endl;
1080  edm::LogInfo("BeamMonitor") << "FitAndFill:: [DebugTime] refBStime[1] = " << refBStime[1]
1081  << "; address = " << &refBStime[1] << std::endl;
1082 
1083  if (countFitting) {
1084  nFits_++;
1085  std::pair<int,int> fitLS = theBeamFitter->getFitLSRange();
1086  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamFitter] Do BeamSpot Fit for LS = " << fitLS.first << " to " << fitLS.second << std::endl;
1087  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamMonitor] Do BeamSpot Fit for LS = " << beginLumiOfBSFit_ << " to " << endLumiOfBSFit_ << std::endl;
1088 
1089  //Now Run the PV and Track Fitter over the collected tracks and pvs
1092  if (bs.type() > 0) // with good beamwidth fit
1093  preBS = bs; // cache good fit results
1094 
1095  edm::LogInfo("BeamMonitor") << "\n RESULTS OF DEFAULT FIT:" << endl;
1096  edm::LogInfo("BeamMonitor") << bs << endl;
1097  edm::LogInfo("BeamMonitor") << "[BeamFitter] fitting done \n" << endl;
1098 
1099  hs["x0_lumi"]->ShiftFillLast( bs.x0(), bs.x0Error(), fitNLumi_ );
1100  hs["y0_lumi"]->ShiftFillLast( bs.y0(), bs.y0Error(), fitNLumi_ );
1101  hs["z0_lumi"]->ShiftFillLast( bs.z0(), bs.z0Error(), fitNLumi_ );
1102  hs["sigmaX0_lumi"]->ShiftFillLast( bs.BeamWidthX(), bs.BeamWidthXError(), fitNLumi_ );
1103  hs["sigmaY0_lumi"]->ShiftFillLast( bs.BeamWidthY(), bs.BeamWidthYError(), fitNLumi_ );
1104  hs["sigmaZ0_lumi"]->ShiftFillLast( bs.sigmaZ(), bs.sigmaZ0Error(), fitNLumi_ );
1105  hs["x0_lumi_all"]->setBinContent(currentlumi,bs.x0());
1106  hs["x0_lumi_all"]->setBinError(currentlumi,bs.x0Error());
1107  hs["y0_lumi_all"]->setBinContent(currentlumi,bs.y0());
1108  hs["y0_lumi_all"]->setBinError(currentlumi,bs.y0Error());
1109  hs["z0_lumi_all"]->setBinContent(currentlumi,bs.z0());
1110  hs["z0_lumi_all"]->setBinError(currentlumi,bs.z0Error());
1111  hs["sigmaX0_lumi_all"]->setBinContent(currentlumi, bs.BeamWidthX());
1112  hs["sigmaX0_lumi_all"]->setBinError(currentlumi, bs.BeamWidthXError());
1113  hs["sigmaY0_lumi_all"]->setBinContent(currentlumi, bs.BeamWidthY());
1114  hs["sigmaY0_lumi_all"]->setBinError(currentlumi, bs.BeamWidthYError());
1115  hs["sigmaZ0_lumi_all"]->setBinContent(currentlumi, bs.sigmaZ());
1116  hs["sigmaZ0_lumi_all"]->setBinError(currentlumi, bs.sigmaZ0Error());
1117 
1118  int nthBin = tmpTime - refTime;
1119  if (nthBin > 0) {
1120  hs["x0_time"]->setBinContent(nthBin, bs.x0());
1121  hs["y0_time"]->setBinContent(nthBin, bs.y0());
1122  hs["z0_time"]->setBinContent(nthBin, bs.z0());
1123  hs["sigmaX0_time"]->setBinContent(nthBin, bs.BeamWidthX());
1124  hs["sigmaY0_time"]->setBinContent(nthBin, bs.BeamWidthY());
1125  hs["sigmaZ0_time"]->setBinContent(nthBin, bs.sigmaZ());
1126  hs["x0_time"]->setBinError(nthBin, bs.x0Error());
1127  hs["y0_time"]->setBinError(nthBin, bs.y0Error());
1128  hs["z0_time"]->setBinError(nthBin, bs.z0Error());
1129  hs["sigmaX0_time"]->setBinError(nthBin, bs.BeamWidthXError());
1130  hs["sigmaY0_time"]->setBinError(nthBin, bs.BeamWidthYError());
1131  hs["sigmaZ0_time"]->setBinError(nthBin, bs.sigmaZ0Error());
1132  }
1133 
1134  int jthBin = tmpTime - startTime;
1135  if (jthBin > 0) {
1136  hs["x0_time_all"]->setBinContent(jthBin, bs.x0());
1137  hs["y0_time_all"]->setBinContent(jthBin, bs.y0());
1138  hs["z0_time_all"]->setBinContent(jthBin, bs.z0());
1139  hs["sigmaX0_time_all"]->setBinContent(jthBin, bs.BeamWidthX());
1140  hs["sigmaY0_time_all"]->setBinContent(jthBin, bs.BeamWidthY());
1141  hs["sigmaZ0_time_all"]->setBinContent(jthBin, bs.sigmaZ());
1142  hs["x0_time_all"]->setBinError(jthBin, bs.x0Error());
1143  hs["y0_time_all"]->setBinError(jthBin, bs.y0Error());
1144  hs["z0_time_all"]->setBinError(jthBin, bs.z0Error());
1145  hs["sigmaX0_time_all"]->setBinError(jthBin, bs.BeamWidthXError());
1146  hs["sigmaY0_time_all"]->setBinError(jthBin, bs.BeamWidthYError());
1147  hs["sigmaZ0_time_all"]->setBinError(jthBin, bs.sigmaZ0Error());
1148  }
1149 
1150  h_x0->Fill( bs.x0());
1151  h_y0->Fill( bs.y0());
1152  h_z0->Fill( bs.z0());
1153  if (bs.type() > 0) { // with good beamwidth fit
1154  h_sigmaX0->Fill( bs.BeamWidthX());
1155  h_sigmaY0->Fill( bs.BeamWidthY());
1156  }
1157  h_sigmaZ0->Fill( bs.sigmaZ());
1158 
1159  if (nthBSTrk_ >= 2*min_Ntrks_) {
1160  double amp = std::sqrt(bs.x0()*bs.x0()+bs.y0()*bs.y0());
1161  double alpha = std::atan2(bs.y0(),bs.x0());
1162  TF1 *f1 = new TF1("f1","[0]*sin(x-[1])",-3.14,3.14);
1163  f1->SetParameters(amp,alpha);
1164  f1->SetParLimits(0,amp-0.1,amp+0.1);
1165  f1->SetParLimits(1,alpha-0.577,alpha+0.577);
1166  f1->SetLineColor(4);
1167  h_d0_phi0->getTProfile()->Fit("f1","QR");
1168 
1169  double mean = bs.z0();
1170  double width = bs.sigmaZ();
1171  std::unique_ptr<TF1> fgaus{ new TF1("fgaus","gaus") };
1172  fgaus->SetParameters(mean,width);
1173  fgaus->SetLineColor(4);
1174  h_trk_z0->getTH1()->Fit(fgaus.get(),"QLRM","",mean-3*width,mean+3*width);
1175  }
1176 
1177  fitResults->Reset();
1178  std::pair<int,int> LSRange = theBeamFitter->getFitLSRange();
1179  char tmpTitle[50];
1180  sprintf(tmpTitle,"%s %i %s %i","Fitted Beam Spot (cm) of LS: ",LSRange.first," to ",LSRange.second);
1181  fitResults->setAxisTitle(tmpTitle,1);
1182  fitResults->setBinContent(1,8,bs.x0());
1183  fitResults->setBinContent(1,7,bs.y0());
1184  fitResults->setBinContent(1,6,bs.z0());
1185  fitResults->setBinContent(1,5,bs.sigmaZ());
1186  fitResults->setBinContent(1,4,bs.dxdz());
1187  fitResults->setBinContent(1,3,bs.dydz());
1188  if (bs.type() > 0) { // with good beamwidth fit
1189  fitResults->setBinContent(1,2,bs.BeamWidthX());
1190  fitResults->setBinContent(1,1,bs.BeamWidthY());
1191  }
1192  else { // fill cached widths
1195  }
1196 
1197  fitResults->setBinContent(2,8,bs.x0Error());
1198  fitResults->setBinContent(2,7,bs.y0Error());
1199  fitResults->setBinContent(2,6,bs.z0Error());
1201  fitResults->setBinContent(2,4,bs.dxdzError());
1202  fitResults->setBinContent(2,3,bs.dydzError());
1203  if (bs.type() > 0) { // with good beamwidth fit
1206  }
1207  else { // fill cached width errors
1210  }
1211 
1212  // count good fit
1213  // if (std::fabs(refBS.x0()-bs.x0())/bs.x0Error() < deltaSigCut_) { // disabled temporarily
1214  summaryContent_[0] += 1.;
1215  // }
1216  // if (std::fabs(refBS.y0()-bs.y0())/bs.y0Error() < deltaSigCut_) { // disabled temporarily
1217  summaryContent_[1] += 1.;
1218  // }
1219  // if (std::fabs(refBS.z0()-bs.z0())/bs.z0Error() < deltaSigCut_) { // disabled temporarily
1220  summaryContent_[2] += 1.;
1221  // }
1222 
1223  } //if (theBeamFitter->runPVandTrkFitter())
1224  else { // beam fit fails
1226  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamMonitor] Beam fit fails!!! \n" << endl;
1227  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamMonitor] Output beam spot for DIP \n" << endl;
1228  edm::LogInfo("BeamMonitor") << bs << endl;
1229 
1230  hs["sigmaX0_lumi"]->ShiftFillLast( bs.BeamWidthX(), bs.BeamWidthXError(), fitNLumi_ );
1231  hs["sigmaY0_lumi"]->ShiftFillLast( bs.BeamWidthY(), bs.BeamWidthYError(), fitNLumi_ );
1232  hs["sigmaZ0_lumi"]->ShiftFillLast( bs.sigmaZ(), bs.sigmaZ0Error(), fitNLumi_ );
1233  hs["x0_lumi"]->ShiftFillLast( bs.x0(), bs.x0Error(), fitNLumi_ );
1234  hs["y0_lumi"]->ShiftFillLast( bs.y0(), bs.y0Error(), fitNLumi_ );
1235  hs["z0_lumi"]->ShiftFillLast( bs.z0(), bs.z0Error(), fitNLumi_ );
1236  } // end of beam fit fails
1237 
1238 
1239  } //-------- end of countFitting------------------------------------------
1240  else { // no fit
1241  // Overwrite Fit LS and fit time when no event processed or no track selected
1244  if (theBeamFitter->runPVandTrkFitter()) {} // Dump fake beam spot for DIP
1246  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamMonitor] No fitting \n" << endl;
1247  edm::LogInfo("BeamMonitor") << "FitAndFill:: [BeamMonitor] Output fake beam spot for DIP \n" << endl;
1248  edm::LogInfo("BeamMonitor") << bs << endl;
1249 
1250  hs["sigmaX0_lumi"]->ShiftFillLast( bs.BeamWidthX(), bs.BeamWidthXError(), fitNLumi_ );
1251  hs["sigmaY0_lumi"]->ShiftFillLast( bs.BeamWidthY(), bs.BeamWidthYError(), fitNLumi_ );
1252  hs["sigmaZ0_lumi"]->ShiftFillLast( bs.sigmaZ(), bs.sigmaZ0Error(), fitNLumi_ );
1253  hs["x0_lumi"]->ShiftFillLast( bs.x0(), bs.x0Error(), fitNLumi_ );
1254  hs["y0_lumi"]->ShiftFillLast( bs.y0(), bs.y0Error(), fitNLumi_ );
1255  hs["z0_lumi"]->ShiftFillLast( bs.z0(), bs.z0Error(), fitNLumi_ );
1256  }
1257 
1258 
1259 
1260  // Fill summary report
1261  if (countFitting) {
1262  for (int n = 0; n < nFitElements_; n++) {
1264  }
1265 
1266  summarySum_ = 0;
1267  for (int ii = 0; ii < nFitElements_; ii++) {
1269  }
1270  reportSummary_ = summarySum_ / (nFitElements_ * nFits_);
1272 
1273  for ( int bi = 0; bi < nFitElements_ ; bi++) {
1274  reportSummaryMap->setBinContent(1,bi+1,summaryContent_[bi] / (float)nFits_);
1275  }
1276  }
1277 
1278 
1279 
1280 
1281  if ( ( resetFitNLumi_ > 0 &&
1282  ((onlineMode_ && countLumi_==resetFitNLumi_ ) || //OR it should be currentLumi_ (if in sequence then does not mattar)
1284  ) || (StartAverage_) ){
1285 
1286  edm::LogInfo("BeamMonitor") << "FitAndFill:: The flag is ON for running average Beam Spot fit"<<endl;
1287  StartAverage_ = true;
1288  firstAverageFit_++;
1289  resetHistos_ = true;
1290  nthBSTrk_ = 0;
1291  beginLumiOfBSFit_= 0;
1292  refBStime[0] = 0;
1293 
1294  }
1295 
1296 
1297 
1298 }
1299 
1300 //--------------------------------------------------------
1302  if(debug_)edm::LogInfo("BeamMonitor") << " RestartingFitting:: Restart Beami everything to a fresh start !!! because Gap is > 10 LS" <<endl;
1303  //track based fit reset here
1304  resetHistos_ = true;
1305  nthBSTrk_ = 0;
1311  beginLumiOfBSFit_ = 0;
1312  refBStime[0] = 0;
1313  //pv based fit iis reset here
1314  h_PVx[0]->Reset();
1315  h_PVy[0]->Reset();
1316  h_PVz[0]->Reset();
1317  beginLumiOfPVFit_ = 0;
1318  refPVtime[0] = 0;
1319  //Clear all the Maps here
1320  mapPVx.clear();
1321  mapPVy.clear();
1322  mapPVz.clear();
1323  mapNPV.clear();
1324  mapBeginBSLS.clear();
1325  mapBeginPVLS.clear();
1326  mapBeginBSTime.clear();
1327  mapBeginPVTime.clear();
1328  mapLSBSTrkSize.clear();
1329  mapLSPVStoreSize.clear();
1330  mapLSCF.clear(); countGapLumi_=0; countLumi_=0; StartAverage_=false;
1331 
1332 }
1333 
1334 //-------------------------------------------------------
1335 void BeamMonitor::endRun(const Run& r, const EventSetup& context){
1336 
1337 if(debug_)edm::LogInfo("BeamMonitor") << "endRun:: Clearing all the Maps "<<endl;
1338 //Clear all the Maps here
1339 mapPVx.clear();
1340 mapPVy.clear();
1341 mapPVz.clear();
1342 mapNPV.clear();
1343 mapBeginBSLS.clear();
1344 mapBeginPVLS.clear();
1345 mapBeginBSTime.clear();
1346 mapBeginPVTime.clear();
1347 mapLSBSTrkSize.clear();
1348 mapLSPVStoreSize.clear();
1349 mapLSCF.clear();
1350 
1351 
1352 }
1353 
1354 //--------------------------------------------------------
1356  const EventSetup& iSetup){
1357  if (!onlineMode_) endLuminosityBlock(lumiSeg, iSetup);
1358 }
1359 
1360 //--------------------------------------------------------
1361 void BeamMonitor::scrollTH1(TH1 * h, time_t ref) {
1362  const char* offsetTime = formatFitTime(ref);
1363  TDatime da(offsetTime);
1364  if (lastNZbin > 0) {
1365  double val = h->GetBinContent(lastNZbin);
1366  double valErr = h->GetBinError(lastNZbin);
1367  h->Reset();
1368  h->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
1369  int bin = (lastNZbin > buffTime ? buffTime : 1);
1370  h->SetBinContent(bin,val);
1371  h->SetBinError(bin,valErr);
1372  }
1373  else {
1374  h->Reset();
1375  h->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
1376  }
1377 }
1378 
1379 //--------------------------------------------------------
1380 // Method to check whether to chane histogram time offset (forward only)
1381 bool BeamMonitor::testScroll(time_t & tmpTime_, time_t & refTime_){
1382  bool scroll_ = false;
1383  if (tmpTime_ - refTime_ >= intervalInSec_) {
1384  scroll_ = true;
1385  edm::LogInfo("BeamMonitor") << "testScroll:: Reset Time Offset" << std::endl;
1387  for (int bin = intervalInSec_; bin >= 1; bin--) {
1388  if (hs["x0_time"]->getBinContent(bin) > 0) {
1389  lastNZbin = bin;
1390  break;
1391  }
1392  }
1393  edm::LogInfo("BeamMonitor") << "testScroll:: Last non zero bin = " << lastNZbin << std::endl;
1394  if (tmpTime_ - refTime_ >= intervalInSec_ + lastNZbin) {
1395  edm::LogInfo("BeamMonitor") << "testScroll:: Time difference too large since last readout" << std::endl;
1396  lastNZbin = 0;
1397  refTime_ = tmpTime_ - buffTime;
1398  }
1399  else{
1400  edm::LogInfo("BeamMonitor") << "testScroll:: Offset to last record" << std::endl;
1401  int offset = ((lastNZbin > buffTime) ? (lastNZbin - buffTime) : (lastNZbin - 1));
1402  refTime_ += offset;
1403  }
1404  }
1405  return scroll_;
1406 }
1407 
1409 
1410 // Local Variables:
1411 // show-trailing-whitespace: t
1412 // truncate-lines: t
1413 // 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:73
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:693
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:681
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