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