CMS 3D CMS Logo

BeamMonitorBx.cc
Go to the documentation of this file.
1 /*
2  * \file BeamMonitorBx.cc
3  * \author Geng-yuan Jeng/UC Riverside
4  * Francisco Yumiceva/FNAL
5  *
6  */
7 
18 #include <numeric>
19 #include <cmath>
20 #include <TMath.h>
21 #include <iostream>
22 #include <TStyle.h>
23 
24 using namespace std;
25 using namespace edm;
26 using namespace reco;
27 
28 void BeamMonitorBx::formatFitTime(char* ts, const time_t& t) {
29 #define CET (+1)
30 #define CEST (+2)
31 
32  tm* ptm;
33  ptm = gmtime(&t);
34  sprintf(ts,
35  "%4d-%02d-%02d %02d:%02d:%02d",
36  ptm->tm_year,
37  ptm->tm_mon + 1,
38  ptm->tm_mday,
39  (ptm->tm_hour + CEST) % 24,
40  ptm->tm_min,
41  ptm->tm_sec);
42 
43 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE
44  unsigned int b = strlen(ts);
45  while (ts[--b] == ' ') {
46  ts[b] = 0;
47  }
48 #endif
49 }
50 
51 //
52 // constructors and destructor
53 //
54 BeamMonitorBx::BeamMonitorBx(const ParameterSet& ps) : countBx_(0), countEvt_(0), countLumi_(0), resetHistos_(false) {
55  parameters_ = ps;
56  monitorName_ = parameters_.getUntrackedParameter<string>("monitorName", "YourSubsystemName");
58  fitNLumi_ = parameters_.getUntrackedParameter<int>("fitEveryNLumi", -1);
59  resetFitNLumi_ = parameters_.getUntrackedParameter<int>("resetEveryNLumi", -1);
60 
61  usesResource("DQMStore");
63 
64  if (!monitorName_.empty())
65  monitorName_ = monitorName_ + "/";
66 
72 
73  if (fitNLumi_ <= 0)
74  fitNLumi_ = 1;
76  refBStime[0] = refBStime[1] = 0;
77  lastlumi_ = 0;
78  nextlumi_ = 0;
79  firstlumi_ = 0;
80  processed_ = false;
81  countGoodFit_ = 0;
82 }
83 
85 
86 //--------------------------------------------------------
88  varMap["x0_bx"] = "X_{0}";
89  varMap["y0_bx"] = "Y_{0}";
90  varMap["z0_bx"] = "Z_{0}";
91  varMap["sigmaX_bx"] = "#sigma_{X}";
92  varMap["sigmaY_bx"] = "#sigma_{Y}";
93  varMap["sigmaZ_bx"] = "#sigma_{Z}";
94 
95  varMap1["x"] = "X_{0} [cm]";
96  varMap1["y"] = "Y_{0} [cm]";
97  varMap1["z"] = "Z_{0} [cm]";
98  varMap1["sigmaX"] = "#sigma_{X} [cm]";
99  varMap1["sigmaY"] = "#sigma_{Y} [cm]";
100  varMap1["sigmaZ"] = "#sigma_{Z} [cm]";
101 
102  // create and cd into new folder
103  dbe_->setCurrentFolder(monitorName_ + "FitBx");
104  // Results of good fit:
105  BookTables(1, varMap, "");
106  //if (resetFitNLumi_ > 0) BookTables(1,varMap,"all");
107 
108  // create and cd into new folders
109  for (std::map<std::string, std::string>::const_iterator varName = varMap1.begin(); varName != varMap1.end();
110  ++varName) {
111  string subDir_ = "FitBx";
112  subDir_ += "/";
113  subDir_ += "All_";
114  subDir_ += varName->first;
115  dbe_->setCurrentFolder(monitorName_ + subDir_);
116  }
117  dbe_->setCurrentFolder(monitorName_ + "FitBx/All_nPVs");
118 }
119 
120 //--------------------------------------------------------
122  ftimestamp = r.beginTime().value();
123  tmpTime = ftimestamp >> 32;
125 }
126 
127 //--------------------------------------------------------
129  int nthlumi = lumiSeg.luminosityBlock();
130  const edm::TimeValue_t fbegintimestamp = lumiSeg.beginTime().value();
131  const std::time_t ftmptime = fbegintimestamp >> 32;
132 
133  if (countLumi_ == 0) {
134  beginLumiOfBSFit_ = nthlumi;
135  refBStime[0] = ftmptime;
136  }
137  if (beginLumiOfBSFit_ == 0)
139 
140  if (nthlumi < nextlumi_)
141  return;
142 
143  if (nthlumi > nextlumi_) {
144  if (countLumi_ != 0 && processed_) {
145  FitAndFill(lumiSeg, lastlumi_, nextlumi_, nthlumi);
146  }
147  nextlumi_ = nthlumi;
148  edm::LogInfo("LS|BX|BeamMonitorBx") << "Next Lumi to Fit: " << nextlumi_ << endl;
149  if (refBStime[0] == 0)
150  refBStime[0] = ftmptime;
151  }
152  countLumi_++;
153  if (processed_)
154  processed_ = false;
155  edm::LogInfo("LS|BX|BeamMonitorBx") << "Begin of Lumi: " << nthlumi << endl;
156 }
157 
158 // ----------------------------------------------------------
159 void BeamMonitorBx::analyze(const Event& iEvent, const EventSetup& iSetup) {
160  bool readEvent_ = true;
161  const int nthlumi = iEvent.luminosityBlock();
162  if (nthlumi < nextlumi_) {
163  readEvent_ = false;
164  edm::LogWarning("BX|BeamMonitorBx") << "Spilt event from previous lumi section!" << endl;
165  }
166  if (nthlumi > nextlumi_) {
167  readEvent_ = false;
168  edm::LogWarning("BX|BeamMonitorBx") << "Spilt event from next lumi section!!!" << endl;
169  }
170 
171  if (readEvent_) {
172  countEvt_++;
174  processed_ = true;
175  }
176 }
177 
178 //--------------------------------------------------------
179 void BeamMonitorBx::endLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& iSetup) {
180  int nthlumi = lumiSeg.id().luminosityBlock();
181  edm::LogInfo("LS|BX|BeamMonitorBx") << "Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
182 
183  if (nthlumi < nextlumi_)
184  return;
185  const edm::TimeValue_t fendtimestamp = lumiSeg.endTime().value();
186  const std::time_t fendtime = fendtimestamp >> 32;
187  tmpTime = refBStime[1] = fendtime;
188 }
189 
190 //--------------------------------------------------------
191 void BeamMonitorBx::BookTables(int nBx, map<string, string>& vMap, string suffix_) {
192  // to rebin histograms when number of bx increases
193  dbe_->cd(monitorName_ + "FitBx");
194 
195  for (std::map<std::string, std::string>::const_iterator varName = vMap.begin(); varName != vMap.end(); ++varName) {
196  string tmpName = varName->first;
197  if (!suffix_.empty()) {
198  tmpName += "_";
199  tmpName += suffix_;
200  }
201 
202  hs[tmpName] = dbe_->book2D(tmpName, varName->second, 3, 0, 3, nBx, 0, nBx);
203  hs[tmpName]->setBinLabel(1, "bx", 1);
204  hs[tmpName]->setBinLabel(2, varName->second, 1);
205  hs[tmpName]->setBinLabel(3, "#Delta " + varName->second, 1);
206  for (int i = 0; i < nBx; i++) {
207  hs[tmpName]->setBinLabel(i + 1, " ", 2);
208  }
209  hs[tmpName]->getTH1()->SetOption("text");
210  hs[tmpName]->Reset();
211  }
212 }
213 
214 //--------------------------------------------------------
216  bool plotPV, int nBx, map<string, string>& vMap, string subDir_, const TString& prefix_, const TString& suffix_) {
217  int nType_ = 2;
218  if (plotPV)
219  nType_ = 4;
220  std::ostringstream ss;
221  std::ostringstream ss1;
222  ss << setfill('0') << setw(5) << nBx;
223  ss1 << nBx;
224 
225  for (int i = 0; i < nType_; i++) {
226  for (std::map<std::string, std::string>::const_iterator varName = vMap.begin(); varName != vMap.end(); ++varName) {
227  string tmpDir_ = subDir_ + "/All_" + varName->first;
228  dbe_->cd(monitorName_ + tmpDir_);
229  TString histTitle(varName->first);
230  TString tmpName;
231  if (prefix_ != "")
232  tmpName = prefix_ + "_" + varName->first;
233  if (suffix_ != "")
234  tmpName = tmpName + "_" + suffix_;
235  tmpName = tmpName + "_" + ss.str();
236 
237  TString histName(tmpName);
238  string ytitle(varName->second);
239  string xtitle("");
240  string options("E1");
241  bool createHisto = true;
242  switch (i) {
243  case 1: // BS vs time
244  histName.Insert(histName.Index("_bx_", 4), "_time");
245  xtitle = "Time [UTC] [Bx# " + ss1.str() + "]";
246  if (ytitle.find("sigma") == string::npos)
247  histTitle += " coordinate of beam spot vs time (Fit)";
248  else
249  histTitle = histTitle.Insert(5, " ") + " of beam spot vs time (Fit)";
250  break;
251  case 2: // PV +/- sigmaPV vs lumi
252  if (ytitle.find("sigma") == string::npos) {
253  histName.Insert(0, "PV");
254  histName.Insert(histName.Index("_bx_", 4), "_lumi");
255  histTitle.Insert(0, "Avg. ");
256  histTitle += " position of primary vtx vs lumi";
257  xtitle = "Lumisection [Bx# " + ss1.str() + "]";
258  ytitle.insert(0, "PV");
259  ytitle += " #pm #sigma_{PV";
260  ytitle += varName->first;
261  ytitle += "} (cm)";
262  } else
263  createHisto = false;
264  break;
265  case 3: // PV +/- sigmaPV vs time
266  if (ytitle.find("sigma") == string::npos) {
267  histName.Insert(0, "PV");
268  histName.Insert(histName.Index("_bx_", 4), "_time");
269  histTitle.Insert(0, "Avg. ");
270  histTitle += " position of primary vtx vs time";
271  xtitle = "Time [UTC] [Bx# " + ss1.str() + "]";
272  ytitle.insert(0, "PV");
273  ytitle += " #pm #sigma_{PV";
274  ytitle += varName->first;
275  ytitle += "} (cm)";
276  } else
277  createHisto = false;
278  break;
279  default: // BS vs lumi
280  histName.Insert(histName.Index("_bx_", 4), "_lumi");
281  xtitle = "Lumisection [Bx# " + ss1.str() + "]";
282  if (ytitle.find("sigma") == string::npos)
283  histTitle += " coordinate of beam spot vs lumi (Fit)";
284  else
285  histTitle = histTitle.Insert(5, " ") + " of beam spot vs lumi (Fit)";
286  break;
287  }
288  // check if already exist
289  if (dbe_->get(monitorName_ + tmpDir_ + "/" + string(histName.Data())))
290  continue;
291 
292  if (createHisto) {
293  edm::LogInfo("BX|BeamMonitorBx") << "histName = " << histName << "; histTitle = " << histTitle << std::endl;
294  hst[histName] = dbe_->book1D(histName, histTitle, 40, 0.5, 40.5);
295  hst[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
296  hst[histName]->setAxisTitle(xtitle, 1);
297  hst[histName]->setAxisTitle(ytitle, 2);
298  hst[histName]->getTH1()->SetOption("E1");
299  if (histName.Contains("time")) {
300  hst[histName]->getTH1()->SetBins(3600, 0.5, 3600 + 0.5);
301  hst[histName]->setAxisTimeDisplay(1);
302  hst[histName]->setAxisTimeFormat("%H:%M:%S", 1);
303 
304  char eventTime[64];
305  formatFitTime(eventTime, startTime);
306  TDatime da(eventTime);
307  if (debug_) {
308  edm::LogInfo("BX|BeamMonitorBx") << "TimeOffset = ";
309  da.Print();
310  }
311  hst[histName]->getTH1()->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
312  }
313  }
314  } //End of variable loop
315  } // End of type loop (lumi, time)
316 
317  // num of PVs(#Bx) per LS
318  dbe_->cd(monitorName_ + subDir_ + "/All_nPVs");
319  TString histName = "Trending_nPVs_lumi_bx_" + ss.str();
320  string xtitle = "Lumisection [Bx# " + ss1.str() + "]";
321 
322  hst[histName] = dbe_->book1D(histName, "Number of Good Reconstructed Vertices", 40, 0.5, 40.5);
323  hst[histName]->setAxisTitle(xtitle, 1);
324  hst[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
325  hst[histName]->getTH1()->SetOption("E1");
326 }
327 
328 //--------------------------------------------------------
329 void BeamMonitorBx::FitAndFill(const LuminosityBlock& lumiSeg, int& lastlumi, int& nextlumi, int& nthlumi) {
330  if (nthlumi <= nextlumi)
331  return;
332 
333  int currentlumi = nextlumi;
334  edm::LogInfo("LS|BX|BeamMonitorBx") << "Lumi of the current fit: " << currentlumi << endl;
335  lastlumi = currentlumi;
336  endLumiOfBSFit_ = currentlumi;
337 
338  edm::LogInfo("BX|BeamMonitorBx") << "Time lapsed = " << tmpTime - refTime << std::endl;
339 
340  if (resetHistos_) {
341  edm::LogInfo("BX|BeamMonitorBx") << "Resetting Histograms" << endl;
343  resetHistos_ = false;
344  }
345 
346  if (fitNLumi_ > 0)
347  if (currentlumi % fitNLumi_ != 0)
348  return;
349 
350  std::pair<int, int> fitLS = theBeamFitter->getFitLSRange();
351  edm::LogInfo("LS|BX|BeamMonitorBx") << " [Fitter] Do BeamSpot Fit for LS = " << fitLS.first << " to " << fitLS.second
352  << endl;
353  edm::LogInfo("LS|BX|BeamMonitorBx") << " [BX] Do BeamSpot Fit for LS = " << beginLumiOfBSFit_ << " to "
354  << endLumiOfBSFit_ << endl;
355 
356  edm::LogInfo("BX|BeamMonitorBx") << " [BxDebugTime] refBStime[0] = " << refBStime[0]
357  << "; address = " << &refBStime[0] << std::endl;
358  edm::LogInfo("BX|BeamMonitorBx") << " [BxDebugTime] refBStime[1] = " << refBStime[1]
359  << "; address = " << &refBStime[1] << std::endl;
360 
362  countGoodFit_++;
363  edm::LogInfo("BX|BeamMonitorBx") << "Number of good fit = " << countGoodFit_ << endl;
365  std::map<int, int> npvsmap = theBeamFitter->getNPVsperBX();
366  edm::LogInfo("BX|BeamMonitorBx") << "Number of bx = " << bsmap.size() << endl;
367  if (bsmap.empty())
368  return;
369  if (countBx_ < bsmap.size()) {
370  countBx_ = bsmap.size();
371  BookTables(countBx_, varMap, "");
372  BookTables(countBx_, varMap, "all");
373  for (BeamSpotMapBx::const_iterator abspot = bsmap.begin(); abspot != bsmap.end(); ++abspot) {
374  int bx = abspot->first;
375  BookTrendHistos(false, bx, varMap1, "FitBx", "Trending", "bx");
376  }
377  }
378 
379  std::pair<int, int> LSRange = theBeamFitter->getFitLSRange();
380  char tmpTitle[50];
381  sprintf(tmpTitle, "%s %i %s %i %s", " [cm] (LS: ", LSRange.first, " to ", LSRange.second, ")");
382  for (std::map<std::string, std::string>::const_iterator varName = varMap.begin(); varName != varMap.end();
383  ++varName) {
384  hs[varName->first]->setTitle(varName->second + " " + tmpTitle);
385  hs[varName->first]->Reset();
386  }
387 
388  if (countGoodFit_ == 1)
389  firstlumi_ = LSRange.first;
390 
391  if (resetFitNLumi_ > 0) {
392  char tmpTitle1[60];
393  if (countGoodFit_ > 1)
394  snprintf(tmpTitle1,
395  sizeof(tmpTitle1),
396  "%s %i %s %i %s",
397  " [cm] (LS: ",
398  firstlumi_,
399  " to ",
400  LSRange.second,
401  ") [weighted average]");
402  else
403  snprintf(tmpTitle1, sizeof(tmpTitle1), "%s", "Need at least two fits to calculate weighted average");
404  for (std::map<std::string, std::string>::const_iterator varName = varMap.begin(); varName != varMap.end();
405  ++varName) {
406  TString tmpName = varName->first + "_all";
407  hs[tmpName]->setTitle(varName->second + " " + tmpTitle1);
408  hs[tmpName]->Reset();
409  }
410  }
411 
412  int nthBin = countBx_;
413  for (BeamSpotMapBx::const_iterator abspot = bsmap.begin(); abspot != bsmap.end(); ++abspot, nthBin--) {
414  reco::BeamSpot bs = abspot->second;
415  int bx = abspot->first;
416  int nPVs = npvsmap.find(bx)->second;
417  edm::LogInfo("BeamMonitorBx") << "Number of PVs of bx#[" << bx << "] = " << nPVs << endl;
418  // Tables
419  FillTables(bx, nthBin, varMap, bs, "");
420  // Histograms
421  FillTrendHistos(bx, nPVs, varMap1, bs, "Trending");
422  }
423  // Calculate weighted beam spots
424  weight(fbspotMap, bsmap);
425  // Fill the results
426  nthBin = countBx_;
427  if (resetFitNLumi_ > 0 && countGoodFit_ > 1) {
428  for (BeamSpotMapBx::const_iterator abspot = fbspotMap.begin(); abspot != fbspotMap.end(); ++abspot, nthBin--) {
429  reco::BeamSpot bs = abspot->second;
430  int bx = abspot->first;
431  FillTables(bx, nthBin, varMap, bs, "all");
432  }
433  }
434  }
435  // else
436  // edm::LogInfo("BeamMonitorBx") << "Bad Fit!!!" << endl;
437 
438  if (resetFitNLumi_ > 0 && currentlumi % resetFitNLumi_ == 0) {
439  edm::LogInfo("LS|BX|BeamMonitorBx") << "Reset track collection for beam fit!!!" << endl;
440  resetHistos_ = true;
445  beginLumiOfBSFit_ = 0;
446  refBStime[0] = 0;
447  }
448 }
449 
450 //--------------------------------------------------------
451 void BeamMonitorBx::FillTables(int nthbx, int nthbin_, map<string, string>& vMap, reco::BeamSpot& bs_, string suffix_) {
452  map<string, pair<double, double> > val_;
453  val_["x0_bx"] = pair<double, double>(bs_.x0(), bs_.x0Error());
454  val_["y0_bx"] = pair<double, double>(bs_.y0(), bs_.y0Error());
455  val_["z0_bx"] = pair<double, double>(bs_.z0(), bs_.z0Error());
456  val_["sigmaX_bx"] = pair<double, double>(bs_.BeamWidthX(), bs_.BeamWidthXError());
457  val_["sigmaY_bx"] = pair<double, double>(bs_.BeamWidthY(), bs_.BeamWidthYError());
458  val_["sigmaZ_bx"] = pair<double, double>(bs_.sigmaZ(), bs_.sigmaZ0Error());
459 
460  for (std::map<std::string, std::string>::const_iterator varName = vMap.begin(); varName != vMap.end(); ++varName) {
461  TString tmpName = varName->first;
462  if (!suffix_.empty())
463  tmpName += TString("_" + suffix_);
464  hs[tmpName]->setBinContent(1, nthbin_, nthbx);
465  hs[tmpName]->setBinContent(2, nthbin_, val_[varName->first].first);
466  hs[tmpName]->setBinContent(3, nthbin_, val_[varName->first].second);
467  }
468 }
469 
470 //--------------------------------------------------------
472  int nthBx, int nPVs_, map<string, string>& vMap, reco::BeamSpot& bs_, const TString& prefix_) {
473  map<TString, pair<double, double> > val_;
474  val_[TString(prefix_ + "_x")] = pair<double, double>(bs_.x0(), bs_.x0Error());
475  val_[TString(prefix_ + "_y")] = pair<double, double>(bs_.y0(), bs_.y0Error());
476  val_[TString(prefix_ + "_z")] = pair<double, double>(bs_.z0(), bs_.z0Error());
477  val_[TString(prefix_ + "_sigmaX")] = pair<double, double>(bs_.BeamWidthX(), bs_.BeamWidthXError());
478  val_[TString(prefix_ + "_sigmaY")] = pair<double, double>(bs_.BeamWidthY(), bs_.BeamWidthYError());
479  val_[TString(prefix_ + "_sigmaZ")] = pair<double, double>(bs_.sigmaZ(), bs_.sigmaZ0Error());
480 
481  std::ostringstream ss;
482  ss << setfill('0') << setw(5) << nthBx;
483  int ntbin_ = tmpTime - startTime;
484  for (map<TString, MonitorElement*>::iterator itHst = hst.begin(); itHst != hst.end(); ++itHst) {
485  if (!(itHst->first.Contains(ss.str())))
486  continue;
487  if (itHst->first.Contains("nPVs"))
488  continue;
489  edm::LogInfo("BX|BeamMonitorBx") << "Filling histogram: " << itHst->first << endl;
490  if (itHst->first.Contains("time")) {
491  int idx = itHst->first.Index("_time", 5);
492  itHst->second->setBinContent(ntbin_, val_[itHst->first(0, idx)].first);
493  itHst->second->setBinError(ntbin_, val_[itHst->first(0, idx)].second);
494  }
495  if (itHst->first.Contains("lumi")) {
496  int idx = itHst->first.Index("_lumi", 5);
497  itHst->second->setBinContent(endLumiOfBSFit_, val_[itHst->first(0, idx)].first);
498  itHst->second->setBinError(endLumiOfBSFit_, val_[itHst->first(0, idx)].second);
499  }
500  }
501  TString histName = "Trending_nPVs_lumi_bx_" + ss.str();
502  if (hst[histName])
503  hst[histName]->setBinContent(endLumiOfBSFit_, nPVs_);
504 }
505 
506 //--------------------------------------------------------------------------------------------------
507 void BeamMonitorBx::weight(BeamSpotMapBx& weightedMap_, const BeamSpotMapBx& newMap_) {
508  for (BeamSpotMapBx::const_iterator it = newMap_.begin(); it != newMap_.end(); ++it) {
509  if (weightedMap_.find(it->first) == weightedMap_.end() || (it->second.type() != 2)) {
510  weightedMap_[it->first] = it->second;
511  continue;
512  }
513 
514  BeamSpot obs = weightedMap_[it->first];
515  double val_[8] = {
516  obs.x0(), obs.y0(), obs.z0(), obs.sigmaZ(), obs.dxdz(), obs.dydz(), obs.BeamWidthX(), obs.BeamWidthY()};
517  double valErr_[8] = {obs.x0Error(),
518  obs.y0Error(),
519  obs.z0Error(),
520  obs.sigmaZ0Error(),
521  obs.dxdzError(),
522  obs.dydzError(),
523  obs.BeamWidthXError(),
524  obs.BeamWidthYError()};
525 
527  weight(val_[0], valErr_[0], it->second.x0(), it->second.x0Error());
528  weight(val_[1], valErr_[1], it->second.y0(), it->second.y0Error());
529  weight(val_[2], valErr_[2], it->second.z0(), it->second.z0Error());
530  weight(val_[3], valErr_[3], it->second.sigmaZ(), it->second.sigmaZ0Error());
531  weight(val_[4], valErr_[4], it->second.dxdz(), it->second.dxdzError());
532  weight(val_[5], valErr_[5], it->second.dydz(), it->second.dydzError());
533  weight(val_[6], valErr_[6], it->second.BeamWidthX(), it->second.BeamWidthXError());
534  weight(val_[7], valErr_[7], it->second.BeamWidthY(), it->second.BeamWidthYError());
535  if (it->second.type() == reco::BeamSpot::Tracker) {
537  }
538 
539  reco::BeamSpot::Point bsPosition(val_[0], val_[1], val_[2]);
541  for (int i = 0; i < 7; ++i) {
542  error(i, i) = valErr_[i] * valErr_[i];
543  }
544  reco::BeamSpot weightedBeamSpot(bsPosition, val_[3], val_[4], val_[5], val_[6], error, type);
545  weightedBeamSpot.setBeamWidthY(val_[7]);
546  LogInfo("BX|BeamMonitorBx") << weightedBeamSpot << endl;
547  weightedMap_.erase(it->first);
548  weightedMap_[it->first] = weightedBeamSpot;
549  }
550 }
551 
552 //--------------------------------------------------------------------------------------------------
553 void BeamMonitorBx::weight(double& mean, double& meanError, const double& val, const double& valError) {
554  double tmpError = 0;
555  if (meanError < 1e-8) {
556  tmpError = 1 / (valError * valError);
557  mean = val * tmpError;
558  } else {
559  tmpError = 1 / (meanError * meanError) + 1 / (valError * valError);
560  mean = mean / (meanError * meanError) + val / (valError * valError);
561  }
562  mean = mean / tmpError;
563  meanError = std::sqrt(1 / tmpError);
564 }
565 
566 //--------------------------------------------------------
568 
edm::ParameterSet parameters_
Definition: BeamMonitorBx.h:62
#define CEST
void beginJob() override
void FillTrendHistos(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, const TString &)
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:29
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:82
BeamType
beam spot flags
Definition: BeamSpot.h:24
const std::map< int, int > & getNPVsperBX()
Definition: BeamFitter.h:123
LuminosityBlockNumber_t luminosityBlock() const
void FillTables(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, std::string)
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
Definition: BeamSpot.h:101
BeamMonitorBx(const edm::ParameterSet &)
bool runPVandTrkFitter()
Definition: BeamFitter.cc:449
void FitAndFill(const edm::LuminosityBlock &lumiSeg, int &, int &, int &)
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:646
std::map< BxNum, reco::BeamSpot > BeamSpotMapBx
Definition: BeamMonitorBx.h:35
void resetTrkVector()
Definition: BeamFitter.h:58
double x0Error() const
error on x
Definition: BeamSpot.h:86
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:27
double dydz() const
dydz slope
Definition: BeamSpot.h:80
std::time_t startTime
std::map< TString, MonitorElement * > hs
Definition: BeamMonitorBx.h:91
double z0Error() const
error on z
Definition: BeamSpot.h:90
BeamSpotMapBx fbspotMap
Definition: BeamMonitorBx.h:87
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:261
void endRun(const edm::Run &r, const edm::EventSetup &c) override
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
double sigmaZ0Error() const
error on sigma z
Definition: BeamSpot.h:92
T getUntrackedParameter(std::string const &, T const &) const
std::map< int, reco::BeamSpot > getBeamSpotMap()
Definition: BeamFitter.h:94
double x0() const
x coordinate
Definition: BeamSpot.h:61
unsigned int countBx_
Definition: BeamMonitorBx.h:73
int iEvent
Definition: GenABIO.cc:224
void setBeamWidthY(double v)
Definition: BeamSpot.h:105
edm::TimeValue_t ftimestamp
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::string monitorName_
Definition: BeamMonitorBx.h:63
T sqrt(T t)
Definition: SSEVec.h:19
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:84
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void resetLSRange()
Definition: BeamFitter.h:60
double y0() const
y coordinate
Definition: BeamSpot.h:63
BeamFitter * theBeamFitter
Definition: BeamMonitorBx.h:71
unsigned long long TimeValue_t
Definition: Timestamp.h:21
std::time_t refBStime[2]
Definition: BeamMonitorBx.h:82
edm::InputTag bsSrc_
Definition: BeamMonitorBx.h:64
double BeamWidthXError() const
error on beam width X, assume error in X = Y
Definition: BeamSpot.h:99
Log< level::Info, false > LogInfo
void analyze(const edm::Event &e, const edm::EventSetup &c) override
std::time_t tmpTime
Definition: BeamMonitorBx.h:98
void weight(BeamSpotMapBx &, const BeamSpotMapBx &)
double sigmaZ() const
sigma z
Definition: BeamSpot.h:76
LuminosityBlockID id() const
TimeValue_t value() const
Definition: Timestamp.h:38
Timestamp const & beginTime() const
Timestamp const & endTime() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
double dxdz() const
dxdz slope
Definition: BeamSpot.h:78
double b
Definition: hdecay.h:120
std::time_t refTime
Definition: BeamMonitorBx.h:99
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
double z0() const
z coordinate
Definition: BeamSpot.h:65
void BookTables(int, std::map< std::string, std::string > &, std::string)
fixed size matrix
HLT enums.
void resetPVFitter()
Definition: BeamFitter.h:72
void resetCutFlow()
Definition: BeamFitter.h:104
double dydzError() const
error on dydz
Definition: BeamSpot.h:96
DQMStore * dbe_
Definition: BeamMonitorBx.h:70
std::pair< int, int > getFitLSRange()
Definition: BeamFitter.h:114
std::map< std::string, std::string > varMap
Definition: BeamMonitorBx.h:88
void BookTrendHistos(bool, int, std::map< std::string, std::string > &, std::string, const TString &, const TString &)
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
std::map< std::string, std::string > varMap1
Definition: BeamMonitorBx.h:89
std::map< TString, MonitorElement * > hst
Definition: BeamMonitorBx.h:92
void formatFitTime(char *, const std::time_t &)
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
LuminosityBlockNumber_t luminosityBlock() const
double dxdzError() const
error on dxdz
Definition: BeamSpot.h:94
~BeamMonitorBx() override
Definition: Run.h:45
double y0Error() const
error on y
Definition: BeamSpot.h:88
void resetRefTime()
Definition: BeamFitter.h:61