CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <math.h>
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, "%4d-%02d-%02d %02d:%02d:%02d", ptm->tm_year,ptm->tm_mon+1,ptm->tm_mday,(ptm->tm_hour+CEST)%24, ptm->tm_min, ptm->tm_sec);
35 
36 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE
37  unsigned int b = strlen(ts);
38  while (ts[--b] == ' ') {ts[b] = 0;}
39 #endif
40 }
41 
42 //
43 // constructors and destructor
44 //
46  countBx_(0),countEvt_(0),countLumi_(0),resetHistos_(false) {
47 
48  parameters_ = ps;
49  monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","YourSubsystemName");
51  fitNLumi_ = parameters_.getUntrackedParameter<int>("fitEveryNLumi",-1);
52  resetFitNLumi_ = parameters_.getUntrackedParameter<int>("resetEveryNLumi",-1);
53 
55 
56  if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
57 
63 
64  if (fitNLumi_ <= 0) fitNLumi_ = 1;
66  refBStime[0] = refBStime[1] = 0;
67  lastlumi_ = 0;
68  nextlumi_ = 0;
69  firstlumi_ = 0;
70  processed_ = false;
71  countGoodFit_ = 0;
72 }
73 
74 
76  delete theBeamFitter;
77 }
78 
79 
80 //--------------------------------------------------------
82  varMap["x0_bx"] = "X_{0}";
83  varMap["y0_bx"] = "Y_{0}";
84  varMap["z0_bx"] = "Z_{0}";
85  varMap["sigmaX_bx"] = "#sigma_{X}";
86  varMap["sigmaY_bx"] = "#sigma_{Y}";
87  varMap["sigmaZ_bx"] = "#sigma_{Z}";
88 
89  varMap1["x"] = "X_{0} [cm]";
90  varMap1["y"] = "Y_{0} [cm]";
91  varMap1["z"] = "Z_{0} [cm]";
92  varMap1["sigmaX"] = "#sigma_{X} [cm]";
93  varMap1["sigmaY"] = "#sigma_{Y} [cm]";
94  varMap1["sigmaZ"] = "#sigma_{Z} [cm]";
95 
96  // create and cd into new folder
97  dbe_->setCurrentFolder(monitorName_+"FitBx");
98  // Results of good fit:
99  BookTables(1,varMap,"");
100  //if (resetFitNLumi_ > 0) BookTables(1,varMap,"all");
101 
102  // create and cd into new folders
103  for (std::map<std::string,std::string>::const_iterator varName = varMap1.begin();
104  varName != varMap1.end(); ++varName) {
105  string subDir_ = "FitBx";
106  subDir_ += "/";
107  subDir_ += "All_";
108  subDir_ += varName->first;
109  dbe_->setCurrentFolder(monitorName_+subDir_);
110  }
111  dbe_->setCurrentFolder(monitorName_+"FitBx/All_nPVs");
112 }
113 
114 //--------------------------------------------------------
115 void BeamMonitorBx::beginRun(const edm::Run& r, const EventSetup& context) {
116 
117  ftimestamp = r.beginTime().value();
118  tmpTime = ftimestamp >> 32;
120 
121 }
122 
123 //--------------------------------------------------------
125  const EventSetup& context) {
126  int nthlumi = lumiSeg.luminosityBlock();
127  const edm::TimeValue_t fbegintimestamp = lumiSeg.beginTime().value();
128  const std::time_t ftmptime = fbegintimestamp >> 32;
129 
130  if (countLumi_ == 0) {
131  beginLumiOfBSFit_ = nthlumi;
132  refBStime[0] = ftmptime;
133  }
135 
136  if (nthlumi < nextlumi_) return;
137 
138  if (nthlumi > nextlumi_) {
139  if (countLumi_ != 0 && processed_) {
140  FitAndFill(lumiSeg,lastlumi_,nextlumi_,nthlumi);
141  }
142  nextlumi_ = nthlumi;
143  edm::LogInfo("LS|BX|BeamMonitorBx") << "Next Lumi to Fit: " << nextlumi_ << endl;
144  if (refBStime[0] == 0) refBStime[0] = ftmptime;
145  }
146  countLumi_++;
147  if (processed_) processed_ = false;
148  edm::LogInfo("LS|BX|BeamMonitorBx") << "Begin of Lumi: " << nthlumi << endl;
149 }
150 
151 // ----------------------------------------------------------
153  const EventSetup& iSetup ) {
154  bool readEvent_ = true;
155  const int nthlumi = iEvent.luminosityBlock();
156  if (nthlumi < nextlumi_) {
157  readEvent_ = false;
158  edm::LogWarning("BX|BeamMonitorBx") << "Spilt event from previous lumi section!" << endl;
159  }
160  if (nthlumi > nextlumi_) {
161  readEvent_ = false;
162  edm::LogWarning("BX|BeamMonitorBx") << "Spilt event from next lumi section!!!" << endl;
163  }
164 
165  if (readEvent_) {
166  countEvt_++;
167  theBeamFitter->readEvent(iEvent);
168  processed_ = true;
169  }
170 
171 }
172 
173 
174 //--------------------------------------------------------
176  const EventSetup& iSetup) {
177  int nthlumi = lumiSeg.id().luminosityBlock();
178  edm::LogInfo("LS|BX|BeamMonitorBx") << "Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
179 
180  if (nthlumi < nextlumi_) return;
181  const edm::TimeValue_t fendtimestamp = lumiSeg.endTime().value();
182  const std::time_t fendtime = fendtimestamp >> 32;
183  tmpTime = refBStime[1] = fendtime;
184 }
185 
186 
187 //--------------------------------------------------------
188 void BeamMonitorBx::BookTables(int nBx, map<string,string> & vMap, string suffix_) {
189  // to rebin histograms when number of bx increases
190  dbe_->cd(monitorName_+"FitBx");
191 
192  for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
193  varName != vMap.end(); ++varName) {
194  string tmpName = varName->first;
195  if (!suffix_.empty()) {
196  tmpName += "_";
197  tmpName += suffix_;
198  }
199  if (dbe_->get(monitorName_+"FitBx/"+tmpName)) {
200  edm::LogInfo("BX|BeamMonitorBx") << "Rebinning " << tmpName << endl;
201  dbe_->removeElement(tmpName);
202  }
203 
204  hs[tmpName]=dbe_->book2D(tmpName,varName->second,3,0,3,nBx,0,nBx);
205  hs[tmpName]->setBinLabel(1,"bx",1);
206  hs[tmpName]->setBinLabel(2,varName->second,1);
207  hs[tmpName]->setBinLabel(3,"#Delta "+varName->second,1);
208  for (int i=0;i<nBx;i++) {
209  hs[tmpName]->setBinLabel(i+1," ",2);
210  }
211  hs[tmpName]->getTH1()->SetOption("text");
212  hs[tmpName]->Reset();
213  }
214 }
215 
216 //--------------------------------------------------------
217 void BeamMonitorBx::BookTrendHistos(bool plotPV,int nBx,map<string,string> & vMap,
218  string subDir_, const TString& prefix_, const TString& suffix_) {
219  int nType_ = 2;
220  if (plotPV) nType_ = 4;
221  std::ostringstream ss;
222  std::ostringstream ss1;
223  ss << setfill ('0') << setw (5) << nBx;
224  ss1 << nBx;
225 
226  for (int i = 0; i < nType_; i++) {
227  for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
228  varName != vMap.end(); ++varName) {
229  string tmpDir_ = subDir_ + "/All_" + varName->first;
230  dbe_->cd(monitorName_+tmpDir_);
231  TString histTitle(varName->first);
232  string tmpName;
233  if (prefix_ != "") tmpName = prefix_ + "_" + varName->first;
234  if (suffix_ != "") 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  }
263  else 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  }
277  else 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))) continue;
290 
291  if (createHisto) {
292  edm::LogInfo("BX|BeamMonitorBx") << "histName = " << histName << "; histTitle = " << histTitle << std::endl;
293  hst[histName] = dbe_->book1D(histName,histTitle,40,0.5,40.5);
294  hst[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
295  hst[histName]->setAxisTitle(xtitle,1);
296  hst[histName]->setAxisTitle(ytitle,2);
297  hst[histName]->getTH1()->SetOption("E1");
298  if (histName.Contains("time")) {
299  hst[histName]->getTH1()->SetBins(3600,0.5,3600+0.5);
300  hst[histName]->setAxisTimeDisplay(1);
301  hst[histName]->setAxisTimeFormat("%H:%M:%S",1);
302 
303  char eventTime[64];
304  formatFitTime(eventTime, startTime);
305  TDatime da(eventTime);
306  if (debug_) {
307  edm::LogInfo("BX|BeamMonitorBx") << "TimeOffset = ";
308  da.Print();
309  }
310  hst[histName]->getTH1()->GetXaxis()->SetTimeOffset(da.Convert(kTRUE));
311  }
312  }
313  }//End of variable loop
314  }// End of type loop (lumi, time)
315 
316  // num of PVs(#Bx) per LS
317  dbe_->cd(monitorName_+subDir_ + "/All_nPVs");
318  TString histName = "Trending_nPVs_lumi_bx_" + ss.str();
319  string xtitle = "Lumisection [Bx# " + ss1.str() + "]";
320 
321  hst[histName] = dbe_->book1D(histName,"Number of Good Reconstructed Vertices",40,0.5,40.5);
322  hst[histName]->setAxisTitle(xtitle,1);
323  hst[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
324  hst[histName]->getTH1()->SetOption("E1");
325 
326 }
327 
328 //--------------------------------------------------------
330  int &lastlumi,int &nextlumi,int &nthlumi){
331  if (nthlumi <= nextlumi) 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) return;
348 
349  std::pair<int,int> fitLS = theBeamFitter->getFitLSRange();
350  edm::LogInfo("LS|BX|BeamMonitorBx") << " [Fitter] Do BeamSpot Fit for LS = " << fitLS.first
351  << " to " << fitLS.second << endl;
352  edm::LogInfo("LS|BX|BeamMonitorBx") << " [BX] Do BeamSpot Fit for LS = " << beginLumiOfBSFit_
353  << " to " << endLumiOfBSFit_ << endl;
354 
355  edm::LogInfo("BX|BeamMonitorBx") << " [BxDebugTime] refBStime[0] = " << refBStime[0]
356  << "; address = " << &refBStime[0] << std::endl;
357  edm::LogInfo("BX|BeamMonitorBx") << " [BxDebugTime] refBStime[1] = " << refBStime[1]
358  << "; address = " << &refBStime[1] << std::endl;
359 
361  countGoodFit_++;
362  edm::LogInfo("BX|BeamMonitorBx") << "Number of good fit = " << countGoodFit_ << endl;
364  std::map<int,int> npvsmap = theBeamFitter->getNPVsperBX();
365  edm::LogInfo("BX|BeamMonitorBx") << "Number of bx = " << bsmap.size() << endl;
366  if (bsmap.size() == 0) return;
367  if (countBx_ < bsmap.size()) {
368  countBx_ = bsmap.size();
370  BookTables(countBx_,varMap,"all");
371  for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
372  abspot!= bsmap.end(); ++abspot) {
373  int bx = abspot->first;
374  BookTrendHistos(false,bx,varMap1,"FitBx","Trending","bx");
375  }
376  }
377 
378  std::pair<int,int> LSRange = theBeamFitter->getFitLSRange();
379  char tmpTitle[50];
380  sprintf(tmpTitle,"%s %i %s %i %s"," [cm] (LS: ",LSRange.first," to ",LSRange.second,")");
381  for (std::map<std::string,std::string>::const_iterator varName = varMap.begin();
382  varName != varMap.end(); ++varName) {
383  hs[varName->first]->setTitle(varName->second + " " + tmpTitle);
384  hs[varName->first]->Reset();
385  }
386 
387  if (countGoodFit_ == 1)
388  firstlumi_ = LSRange.first;
389 
390  if (resetFitNLumi_ > 0 ) {
391  char tmpTitle1[50];
392  if ( countGoodFit_ > 1)
393  sprintf(tmpTitle1,"%s %i %s %i %s"," [cm] (LS: ",firstlumi_," to ",LSRange.second,") [weighted average]");
394  else
395  sprintf(tmpTitle1,"%s","Need at least two fits to calculate weighted average");
396  for (std::map<std::string,std::string>::const_iterator varName = varMap.begin();
397  varName != varMap.end(); ++varName) {
398  TString tmpName = varName->first + "_all";
399  hs[tmpName]->setTitle(varName->second + " " + tmpTitle1);
400  hs[tmpName]->Reset();
401  }
402  }
403 
404  int nthBin = countBx_;
405  for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
406  abspot!= bsmap.end(); ++abspot,nthBin--) {
407  reco::BeamSpot bs = abspot->second;
408  int bx = abspot->first;
409  int nPVs = npvsmap.find(bx)->second;
410  edm::LogInfo("BeamMonitorBx") << "Number of PVs of bx#[" << bx << "] = " << nPVs << endl;
411  // Tables
412  FillTables(bx,nthBin,varMap,bs,"");
413  // Histograms
414  FillTrendHistos(bx,nPVs,varMap1,bs,"Trending");
415  }
416  // Calculate weighted beam spots
417  weight(fbspotMap,bsmap);
418  // Fill the results
419  nthBin = countBx_;
420  if (resetFitNLumi_ > 0 && countGoodFit_ > 1) {
421  for (BeamSpotMapBx::const_iterator abspot = fbspotMap.begin();
422  abspot!= fbspotMap.end(); ++abspot,nthBin--) {
423  reco::BeamSpot bs = abspot->second;
424  int bx = abspot->first;
425  FillTables(bx,nthBin,varMap,bs,"all");
426  }
427  }
428  }
429  // else
430  // edm::LogInfo("BeamMonitorBx") << "Bad Fit!!!" << endl;
431 
432  if (resetFitNLumi_ > 0 && currentlumi%resetFitNLumi_ == 0) {
433  edm::LogInfo("LS|BX|BeamMonitorBx") << "Reset track collection for beam fit!!!" <<endl;
434  resetHistos_ = true;
439  beginLumiOfBSFit_ = 0;
440  refBStime[0] = 0;
441  }
442 }
443 
444 //--------------------------------------------------------
445 void BeamMonitorBx::FillTables(int nthbx,int nthbin_,
446  map<string,string>&vMap,
447  reco::BeamSpot&bs_, string suffix_){
448  map<string,pair<double,double> > val_;
449  val_["x0_bx"] = pair<double,double>(bs_.x0(),bs_.x0Error());
450  val_["y0_bx"] = pair<double,double>(bs_.y0(),bs_.y0Error());
451  val_["z0_bx"] = pair<double,double>(bs_.z0(),bs_.z0Error());
452  val_["sigmaX_bx"] = pair<double,double>(bs_.BeamWidthX(),bs_.BeamWidthXError());
453  val_["sigmaY_bx"] = pair<double,double>(bs_.BeamWidthY(),bs_.BeamWidthYError());
454  val_["sigmaZ_bx"] = pair<double,double>(bs_.sigmaZ(),bs_.sigmaZ0Error());
455 
456  for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
457  varName != vMap.end(); ++varName) {
458  TString tmpName = varName->first;
459  if (suffix_ != "") tmpName += TString("_"+suffix_);
460  hs[tmpName]->setBinContent(1,nthbin_,nthbx);
461  hs[tmpName]->setBinContent(2,nthbin_,val_[varName->first].first);
462  hs[tmpName]->setBinContent(3,nthbin_,val_[varName->first].second);
463  }
464 }
465 
466 //--------------------------------------------------------
467 void BeamMonitorBx::FillTrendHistos(int nthBx, int nPVs_, map<string,string> & vMap,
468  reco::BeamSpot & bs_, const TString& prefix_) {
469  map<TString,pair<double,double> > val_;
470  val_[TString(prefix_+"_x")] = pair<double,double>(bs_.x0(),bs_.x0Error());
471  val_[TString(prefix_+"_y")] = pair<double,double>(bs_.y0(),bs_.y0Error());
472  val_[TString(prefix_+"_z")] = pair<double,double>(bs_.z0(),bs_.z0Error());
473  val_[TString(prefix_+"_sigmaX")] = pair<double,double>(bs_.BeamWidthX(),bs_.BeamWidthXError());
474  val_[TString(prefix_+"_sigmaY")] = pair<double,double>(bs_.BeamWidthY(),bs_.BeamWidthYError());
475  val_[TString(prefix_+"_sigmaZ")] = pair<double,double>(bs_.sigmaZ(),bs_.sigmaZ0Error());
476 
477  std::ostringstream ss;
478  ss << setfill ('0') << setw (5) << nthBx;
479  int ntbin_ = tmpTime - startTime;
480  for (map<TString,MonitorElement*>::iterator itHst = hst.begin();
481  itHst != hst.end(); ++itHst) {
482  if (!(itHst->first.Contains(ss.str()))) continue;
483  if (itHst->first.Contains("nPVs")) continue;
484  edm::LogInfo("BX|BeamMonitorBx") << "Filling histogram: " << itHst->first << endl;
485  if (itHst->first.Contains("time")) {
486  int idx = itHst->first.Index("_time",5);
487  itHst->second->setBinContent(ntbin_,val_[itHst->first(0,idx)].first);
488  itHst->second->setBinError(ntbin_,val_[itHst->first(0,idx)].second);
489  }
490  if (itHst->first.Contains("lumi")) {
491  int idx = itHst->first.Index("_lumi",5);
492  itHst->second->setBinContent(endLumiOfBSFit_,val_[itHst->first(0,idx)].first);
493  itHst->second->setBinError(endLumiOfBSFit_,val_[itHst->first(0,idx)].second);
494  }
495  }
496  TString histName = "Trending_nPVs_lumi_bx_" + ss.str();
497  if (hst[histName])
498  hst[histName]->setBinContent(endLumiOfBSFit_,nPVs_);
499 }
500 
501 //--------------------------------------------------------------------------------------------------
502 void BeamMonitorBx::weight(BeamSpotMapBx& weightedMap_, const BeamSpotMapBx& newMap_){
503  for (BeamSpotMapBx::const_iterator it = newMap_.begin();
504  it != newMap_.end(); ++it) {
505  if (weightedMap_.find(it->first) == weightedMap_.end() || (it->second.type() != 2)) {
506  weightedMap_[it->first] = it->second;
507  continue;
508  }
509 
510  BeamSpot obs = weightedMap_[it->first];
511  double val_[8] = { obs.x0(),obs.y0(),obs.z0(),obs.sigmaZ(),
512  obs.dxdz(),obs.dydz(),obs.BeamWidthX(),obs.BeamWidthY()};
513  double valErr_[8] = { obs.x0Error(),obs.y0Error(),obs.z0Error(),
514  obs.sigmaZ0Error(),obs.dxdzError(),obs.dydzError(),
515  obs.BeamWidthXError(),obs.BeamWidthYError()};
516 
518  weight(val_[0], valErr_[0], it->second.x0() , it->second.x0Error());
519  weight(val_[1], valErr_[1], it->second.y0() , it->second.y0Error());
520  weight(val_[2], valErr_[2], it->second.z0() , it->second.z0Error());
521  weight(val_[3], valErr_[3], it->second.sigmaZ() , it->second.sigmaZ0Error());
522  weight(val_[4], valErr_[4], it->second.dxdz() , it->second.dxdzError());
523  weight(val_[5], valErr_[5], it->second.dydz() , it->second.dydzError());
524  weight(val_[6], valErr_[6], it->second.BeamWidthX(), it->second.BeamWidthXError());
525  weight(val_[7], valErr_[7], it->second.BeamWidthY(), it->second.BeamWidthYError());
526  if(it->second.type() == reco::BeamSpot::Tracker){
528  }
529 
530  reco::BeamSpot::Point bsPosition(val_[0],val_[1],val_[2]);
532  for (int i=0;i<7;++i) {
533  error(i,i) = valErr_[i]*valErr_[i];
534  }
535  reco::BeamSpot weightedBeamSpot(bsPosition,val_[3],val_[4],val_[5],val_[6],error,type);
536  weightedBeamSpot.setBeamWidthY(val_[7]);
537  LogInfo("BX|BeamMonitorBx")
538  << weightedBeamSpot
539  << endl;
540  weightedMap_.erase(it->first);
541  weightedMap_[it->first] = weightedBeamSpot;
542  }
543 }
544 
545 //--------------------------------------------------------------------------------------------------
546 void BeamMonitorBx::weight(double& mean,double& meanError,const double& val,const double& valError){
547  double tmpError = 0;
548  if (meanError < 1e-8){
549  tmpError = 1/(valError*valError);
550  mean = val*tmpError;
551  }
552  else{
553  tmpError = 1/(meanError*meanError) + 1/(valError*valError);
554  mean = mean/(meanError*meanError) + val/(valError*valError);
555  }
556  mean = mean/tmpError;
557  meanError = std::sqrt(1/tmpError);
558 }
559 
560 //--------------------------------------------------------
561 void BeamMonitorBx::endRun(const Run& r, const EventSetup& context){
562 
563 }
564 
565 //--------------------------------------------------------
567  const EventSetup& iSetup){
568 }
569 
void beginRun(const edm::Run &r, const edm::EventSetup &c)
edm::ParameterSet parameters_
Definition: BeamMonitorBx.h:69
LuminosityBlockID id() const
#define CEST
void FillTrendHistos(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, const TString &)
type
Definition: HCALResponse.h:21
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:31
double z0() const
z coordinate
Definition: BeamSpot.h:68
BeamType
beam spot flags
Definition: BeamSpot.h:26
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
const std::map< int, int > & getNPVsperBX()
Definition: BeamFitter.h:132
void FillTables(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, std::string)
double sigmaZ0Error() const
error on sigma z
Definition: BeamSpot.h:96
BeamMonitorBx(const edm::ParameterSet &)
bool runPVandTrkFitter()
Definition: BeamFitter.cc:397
double dydzError() const
error on dydz
Definition: BeamSpot.h:100
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void FitAndFill(const edm::LuminosityBlock &lumiSeg, int &, int &, int &)
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:62
void resetTrkVector()
Definition: BeamFitter.h:53
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
std::time_t startTime
Timestamp const & beginTime() const
std::map< TString, MonitorElement * > hs
Definition: BeamMonitorBx.h:98
BeamSpotMapBx fbspotMap
Definition: BeamMonitorBx.h:94
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:215
LuminosityBlockNumber_t luminosityBlock() const
std::map< int, reco::BeamSpot > getBeamSpotMap()
Definition: BeamFitter.h:95
double dydz() const
dydz slope
Definition: BeamSpot.h:84
unsigned int countBx_
Definition: BeamMonitorBx.h:80
int iEvent
Definition: GenABIO.cc:230
void endRun(const edm::Run &r, const edm::EventSetup &c)
void setBeamWidthY(double v)
Definition: BeamSpot.h:109
double dxdzError() const
error on dxdz
Definition: BeamSpot.h:98
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
edm::TimeValue_t ftimestamp
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::string monitorName_
Definition: BeamMonitorBx.h:70
T sqrt(T t)
Definition: SSEVec.h:18
Timestamp const & endTime() const
virtual void endJob()
Definition: EDAnalyzer.h:73
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
void resetLSRange()
Definition: BeamFitter.h:55
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
Definition: BeamSpot.h:105
double BeamWidthXError() const
error on beam width X, assume error in X = Y
Definition: BeamSpot.h:103
BeamFitter * theBeamFitter
Definition: BeamMonitorBx.h:78
double z0Error() const
error on z
Definition: BeamSpot.h:94
unsigned long long TimeValue_t
Definition: Timestamp.h:28
std::time_t refBStime[2]
Definition: BeamMonitorBx.h:89
edm::InputTag bsSrc_
Definition: BeamMonitorBx.h:71
double dxdz() const
dxdz slope
Definition: BeamSpot.h:82
double x0Error() const
error on x
Definition: BeamSpot.h:90
double y0Error() const
error on y
Definition: BeamSpot.h:92
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
std::time_t tmpTime
void weight(BeamSpotMapBx &, const BeamSpotMapBx &)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
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
std::time_t refTime
Timestamp const & beginTime() const
Definition: RunBase.h:41
void BookTables(int, std::map< std::string, std::string > &, std::string)
void resetPVFitter()
Definition: BeamFitter.h:69
double y0() const
y coordinate
Definition: BeamSpot.h:66
void resetCutFlow()
Definition: BeamFitter.h:105
DQMStore * dbe_
Definition: BeamMonitorBx.h:77
std::map< std::string, std::string > varMap
Definition: BeamMonitorBx.h:95
void BookTrendHistos(bool, int, std::map< std::string, std::string > &, std::string, const TString &, const TString &)
std::map< std::string, std::string > varMap1
Definition: BeamMonitorBx.h:96
std::map< TString, MonitorElement * > hst
Definition: BeamMonitorBx.h:99
void formatFitTime(char *, const std::time_t &)
volatile std::atomic< bool > shutdown_flag false
std::pair< int, int > getFitLSRange()
Definition: BeamFitter.h:117
TimeValue_t value() const
Definition: Timestamp.h:56
void analyze(const edm::Event &e, const edm::EventSetup &c)
Definition: Run.h:43
std::map< BxNum, reco::BeamSpot > BeamSpotMapBx
Definition: BeamMonitorBx.h:33
double x0() const
x coordinate
Definition: BeamSpot.h:64
void resetRefTime()
Definition: BeamFitter.h:56