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