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 const char * BeamMonitorBx::formatFitTime( const time_t & t ) {
29 #define CET (+1)
30 #define CEST (+2)
31 
32  static char ts[] = "yyyy-Mm-dd hh:mm:ss";
33  tm * ptm;
34  ptm = gmtime ( &t );
35  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);
36 
37 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE
38  unsigned int b = strlen(ts);
39  while (ts[--b] == ' ') {ts[b] = 0;}
40 #endif
41  return ts;
42 
43 }
44 
45 //
46 // constructors and destructor
47 //
49  countBx_(0),countEvt_(0),countLumi_(0),resetHistos_(false) {
50 
51  parameters_ = ps;
52  monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","YourSubsystemName");
54  fitNLumi_ = parameters_.getUntrackedParameter<int>("fitEveryNLumi",-1);
55  resetFitNLumi_ = parameters_.getUntrackedParameter<int>("resetEveryNLumi",-1);
56 
58 
59  if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
60 
66 
67  if (fitNLumi_ <= 0) fitNLumi_ = 1;
69  refBStime[0] = refBStime[1] = 0;
70  lastlumi_ = 0;
71  nextlumi_ = 0;
72  firstlumi_ = 0;
73  processed_ = false;
74  countGoodFit_ = 0;
75 }
76 
77 
79  delete theBeamFitter;
80 }
81 
82 
83 //--------------------------------------------------------
85  varMap["x0_bx"] = "X_{0}";
86  varMap["y0_bx"] = "Y_{0}";
87  varMap["z0_bx"] = "Z_{0}";
88  varMap["sigmaX_bx"] = "#sigma_{X}";
89  varMap["sigmaY_bx"] = "#sigma_{Y}";
90  varMap["sigmaZ_bx"] = "#sigma_{Z}";
91 
92  varMap1["x"] = "X_{0} [cm]";
93  varMap1["y"] = "Y_{0} [cm]";
94  varMap1["z"] = "Z_{0} [cm]";
95  varMap1["sigmaX"] = "#sigma_{X} [cm]";
96  varMap1["sigmaY"] = "#sigma_{Y} [cm]";
97  varMap1["sigmaZ"] = "#sigma_{Z} [cm]";
98 
99  // create and cd into new folder
100  dbe_->setCurrentFolder(monitorName_+"FitBx");
101  // Results of good fit:
102  BookTables(1,varMap,"");
103  //if (resetFitNLumi_ > 0) BookTables(1,varMap,"all");
104 
105  // create and cd into new folders
106  for (std::map<std::string,std::string>::const_iterator varName = varMap1.begin();
107  varName != varMap1.end(); ++varName) {
108  string subDir_ = "FitBx";
109  subDir_ += "/";
110  subDir_ += "All_";
111  subDir_ += varName->first;
112  dbe_->setCurrentFolder(monitorName_+subDir_);
113  }
114  dbe_->setCurrentFolder(monitorName_+"FitBx/All_nPVs");
115 }
116 
117 //--------------------------------------------------------
118 void BeamMonitorBx::beginRun(const edm::Run& r, const EventSetup& context) {
119 
120  ftimestamp = r.beginTime().value();
121  tmpTime = ftimestamp >> 32;
123 
124 }
125 
126 //--------------------------------------------------------
128  const EventSetup& context) {
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  }
138 
139  if (nthlumi < nextlumi_) return;
140 
141  if (nthlumi > nextlumi_) {
142  if (countLumi_ != 0 && processed_) {
143  FitAndFill(lumiSeg,lastlumi_,nextlumi_,nthlumi);
144  }
145  nextlumi_ = nthlumi;
146  edm::LogInfo("LS|BX|BeamMonitorBx") << "Next Lumi to Fit: " << nextlumi_ << endl;
147  if (refBStime[0] == 0) refBStime[0] = ftmptime;
148  }
149  countLumi_++;
150  if (processed_) processed_ = false;
151  edm::LogInfo("LS|BX|BeamMonitorBx") << "Begin of Lumi: " << nthlumi << endl;
152 }
153 
154 // ----------------------------------------------------------
156  const EventSetup& iSetup ) {
157  bool readEvent_ = true;
158  const int nthlumi = iEvent.luminosityBlock();
159  if (nthlumi < nextlumi_) {
160  readEvent_ = false;
161  edm::LogWarning("BX|BeamMonitorBx") << "Spilt event from previous lumi section!" << endl;
162  }
163  if (nthlumi > nextlumi_) {
164  readEvent_ = false;
165  edm::LogWarning("BX|BeamMonitorBx") << "Spilt event from next lumi section!!!" << endl;
166  }
167 
168  if (readEvent_) {
169  countEvt_++;
170  theBeamFitter->readEvent(iEvent);
171  processed_ = true;
172  }
173 
174 }
175 
176 
177 //--------------------------------------------------------
179  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_) return;
184  const edm::TimeValue_t fendtimestamp = lumiSeg.endTime().value();
185  const std::time_t fendtime = fendtimestamp >> 32;
186  tmpTime = refBStime[1] = fendtime;
187 }
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();
196  varName != vMap.end(); ++varName) {
197  string tmpName = varName->first;
198  if (!suffix_.empty()) {
199  tmpName += "_";
200  tmpName += suffix_;
201  }
202  if (dbe_->get(monitorName_+"FitBx/"+tmpName)) {
203  edm::LogInfo("BX|BeamMonitorBx") << "Rebinning " << tmpName << endl;
204  dbe_->removeElement(tmpName);
205  }
206 
207  hs[tmpName]=dbe_->book2D(tmpName,varName->second,3,0,3,nBx,0,nBx);
208  hs[tmpName]->setBinLabel(1,"bx",1);
209  hs[tmpName]->setBinLabel(2,varName->second,1);
210  hs[tmpName]->setBinLabel(3,"#Delta "+varName->second,1);
211  for (int i=0;i<nBx;i++) {
212  hs[tmpName]->setBinLabel(i+1," ",2);
213  }
214  hs[tmpName]->getTH1()->SetOption("text");
215  hs[tmpName]->Reset();
216  }
217 }
218 
219 //--------------------------------------------------------
220 void BeamMonitorBx::BookTrendHistos(bool plotPV,int nBx,map<string,string> & vMap,
221  string subDir_, const TString& prefix_, const TString& suffix_) {
222  int nType_ = 2;
223  if (plotPV) nType_ = 4;
224  std::ostringstream ss;
225  std::ostringstream ss1;
226  ss << setfill ('0') << setw (5) << nBx;
227  ss1 << nBx;
228 
229  for (int i = 0; i < nType_; i++) {
230  for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
231  varName != vMap.end(); ++varName) {
232  string tmpDir_ = subDir_ + "/All_" + varName->first;
233  dbe_->cd(monitorName_+tmpDir_);
234  TString histTitle(varName->first);
235  string tmpName;
236  if (prefix_ != "") tmpName = prefix_ + "_" + varName->first;
237  if (suffix_ != "") tmpName = tmpName + "_" + suffix_;
238  tmpName = tmpName + "_" + ss.str();
239 
240  TString histName(tmpName);
241  string ytitle(varName->second);
242  string xtitle("");
243  string options("E1");
244  bool createHisto = true;
245  switch(i) {
246  case 1: // BS vs time
247  histName.Insert(histName.Index("_bx_",4),"_time");
248  xtitle = "Time [UTC] [Bx# " + ss1.str() + "]";
249  if (ytitle.find("sigma") == string::npos)
250  histTitle += " coordinate of beam spot vs time (Fit)";
251  else
252  histTitle = histTitle.Insert(5," ") + " of beam spot vs time (Fit)";
253  break;
254  case 2: // PV +/- sigmaPV vs lumi
255  if (ytitle.find("sigma") == string::npos) {
256  histName.Insert(0,"PV");
257  histName.Insert(histName.Index("_bx_",4),"_lumi");
258  histTitle.Insert(0,"Avg. ");
259  histTitle += " position of primary vtx vs lumi";
260  xtitle = "Lumisection [Bx# " + ss1.str() + "]";
261  ytitle.insert(0,"PV");
262  ytitle += " #pm #sigma_{PV";
263  ytitle += varName->first;
264  ytitle += "} (cm)";
265  }
266  else createHisto = false;
267  break;
268  case 3: // PV +/- sigmaPV vs time
269  if (ytitle.find("sigma") == string::npos) {
270  histName.Insert(0,"PV");
271  histName.Insert(histName.Index("_bx_",4),"_time");
272  histTitle.Insert(0,"Avg. ");
273  histTitle += " position of primary vtx vs time";
274  xtitle = "Time [UTC] [Bx# " + ss1.str() + "]";
275  ytitle.insert(0,"PV");
276  ytitle += " #pm #sigma_{PV";
277  ytitle += varName->first;
278  ytitle += "} (cm)";
279  }
280  else createHisto = false;
281  break;
282  default: // BS vs lumi
283  histName.Insert(histName.Index("_bx_",4),"_lumi");
284  xtitle = "Lumisection [Bx# " + ss1.str() + "]";
285  if (ytitle.find("sigma") == string::npos)
286  histTitle += " coordinate of beam spot vs lumi (Fit)";
287  else
288  histTitle = histTitle.Insert(5," ") + " of beam spot vs lumi (Fit)";
289  break;
290  }
291  // check if already exist
292  if (dbe_->get(monitorName_+tmpDir_+"/"+string(histName))) continue;
293 
294  if (createHisto) {
295  edm::LogInfo("BX|BeamMonitorBx") << "histName = " << histName << "; histTitle = " << histTitle << std::endl;
296  hst[histName] = dbe_->book1D(histName,histTitle,40,0.5,40.5);
297  hst[histName]->getTH1()->SetBit(TH1::kCanRebin);
298  hst[histName]->setAxisTitle(xtitle,1);
299  hst[histName]->setAxisTitle(ytitle,2);
300  hst[histName]->getTH1()->SetOption("E1");
301  if (histName.Contains("time")) {
302  hst[histName]->getTH1()->SetBins(3600,0.5,3600+0.5);
303  hst[histName]->setAxisTimeDisplay(1);
304  hst[histName]->setAxisTimeFormat("%H:%M:%S",1);
305  const char* eventTime = formatFitTime(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()->SetBit(TH1::kCanRebin);
325  hst[histName]->getTH1()->SetOption("E1");
326 
327 }
328 
329 //--------------------------------------------------------
331  int &lastlumi,int &nextlumi,int &nthlumi){
332  if (nthlumi <= nextlumi) return;
333 
334  int currentlumi = nextlumi;
335  edm::LogInfo("LS|BX|BeamMonitorBx") << "Lumi of the current fit: " << currentlumi << endl;
336  lastlumi = currentlumi;
337  endLumiOfBSFit_ = currentlumi;
338 
339  edm::LogInfo("BX|BeamMonitorBx") << "Time lapsed = " << tmpTime - refTime << std:: endl;
340 
341  if (resetHistos_) {
342  edm::LogInfo("BX|BeamMonitorBx") << "Resetting Histograms" << endl;
344  resetHistos_ = false;
345  }
346 
347  if (fitNLumi_ > 0)
348  if (currentlumi%fitNLumi_!=0) return;
349 
350  std::pair<int,int> fitLS = theBeamFitter->getFitLSRange();
351  edm::LogInfo("LS|BX|BeamMonitorBx") << " [Fitter] Do BeamSpot Fit for LS = " << fitLS.first
352  << " to " << fitLS.second << endl;
353  edm::LogInfo("LS|BX|BeamMonitorBx") << " [BX] Do BeamSpot Fit for LS = " << beginLumiOfBSFit_
354  << " to " << 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.size() == 0) return;
368  if (countBx_ < bsmap.size()) {
369  countBx_ = bsmap.size();
371  BookTables(countBx_,varMap,"all");
372  for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
373  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();
383  varName != varMap.end(); ++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[50];
393  if ( countGoodFit_ > 1)
394  sprintf(tmpTitle1,"%s %i %s %i %s"," [cm] (LS: ",firstlumi_," to ",LSRange.second,") [weighted average]");
395  else
396  sprintf(tmpTitle1,"%s","Need at least two fits to calculate weighted average");
397  for (std::map<std::string,std::string>::const_iterator varName = varMap.begin();
398  varName != varMap.end(); ++varName) {
399  TString tmpName = varName->first + "_all";
400  hs[tmpName]->setTitle(varName->second + " " + tmpTitle1);
401  hs[tmpName]->Reset();
402  }
403  }
404 
405  int nthBin = countBx_;
406  for (BeamSpotMapBx::const_iterator abspot = bsmap.begin();
407  abspot!= bsmap.end(); ++abspot,nthBin--) {
408  reco::BeamSpot bs = abspot->second;
409  int bx = abspot->first;
410  int nPVs = npvsmap.find(bx)->second;
411  edm::LogInfo("BeamMonitorBx") << "Number of PVs of bx#[" << bx << "] = " << nPVs << endl;
412  // Tables
413  FillTables(bx,nthBin,varMap,bs,"");
414  // Histograms
415  FillTrendHistos(bx,nPVs,varMap1,bs,"Trending");
416  }
417  // Calculate weighted beam spots
418  weight(fbspotMap,bsmap);
419  // Fill the results
420  nthBin = countBx_;
421  if (resetFitNLumi_ > 0 && countGoodFit_ > 1) {
422  for (BeamSpotMapBx::const_iterator abspot = fbspotMap.begin();
423  abspot!= fbspotMap.end(); ++abspot,nthBin--) {
424  reco::BeamSpot bs = abspot->second;
425  int bx = abspot->first;
426  FillTables(bx,nthBin,varMap,bs,"all");
427  }
428  }
429  }
430  // else
431  // edm::LogInfo("BeamMonitorBx") << "Bad Fit!!!" << endl;
432 
433  if (resetFitNLumi_ > 0 && currentlumi%resetFitNLumi_ == 0) {
434  edm::LogInfo("LS|BX|BeamMonitorBx") << "Reset track collection for beam fit!!!" <<endl;
435  resetHistos_ = true;
440  beginLumiOfBSFit_ = 0;
441  refBStime[0] = 0;
442  }
443 }
444 
445 //--------------------------------------------------------
446 void BeamMonitorBx::FillTables(int nthbx,int nthbin_,
447  map<string,string>&vMap,
448  reco::BeamSpot&bs_, string suffix_){
449  map<string,pair<double,double> > val_;
450  val_["x0_bx"] = pair<double,double>(bs_.x0(),bs_.x0Error());
451  val_["y0_bx"] = pair<double,double>(bs_.y0(),bs_.y0Error());
452  val_["z0_bx"] = pair<double,double>(bs_.z0(),bs_.z0Error());
453  val_["sigmaX_bx"] = pair<double,double>(bs_.BeamWidthX(),bs_.BeamWidthXError());
454  val_["sigmaY_bx"] = pair<double,double>(bs_.BeamWidthY(),bs_.BeamWidthYError());
455  val_["sigmaZ_bx"] = pair<double,double>(bs_.sigmaZ(),bs_.sigmaZ0Error());
456 
457  for (std::map<std::string,std::string>::const_iterator varName = vMap.begin();
458  varName != vMap.end(); ++varName) {
459  TString tmpName = varName->first;
460  if (suffix_ != "") tmpName += TString("_"+suffix_);
461  hs[tmpName]->setBinContent(1,nthbin_,nthbx);
462  hs[tmpName]->setBinContent(2,nthbin_,val_[varName->first].first);
463  hs[tmpName]->setBinContent(3,nthbin_,val_[varName->first].second);
464  }
465 }
466 
467 //--------------------------------------------------------
468 void BeamMonitorBx::FillTrendHistos(int nthBx, int nPVs_, map<string,string> & vMap,
469  reco::BeamSpot & bs_, const TString& prefix_) {
470  map<TString,pair<double,double> > val_;
471  val_[TString(prefix_+"_x")] = pair<double,double>(bs_.x0(),bs_.x0Error());
472  val_[TString(prefix_+"_y")] = pair<double,double>(bs_.y0(),bs_.y0Error());
473  val_[TString(prefix_+"_z")] = pair<double,double>(bs_.z0(),bs_.z0Error());
474  val_[TString(prefix_+"_sigmaX")] = pair<double,double>(bs_.BeamWidthX(),bs_.BeamWidthXError());
475  val_[TString(prefix_+"_sigmaY")] = pair<double,double>(bs_.BeamWidthY(),bs_.BeamWidthYError());
476  val_[TString(prefix_+"_sigmaZ")] = pair<double,double>(bs_.sigmaZ(),bs_.sigmaZ0Error());
477 
478  std::ostringstream ss;
479  ss << setfill ('0') << setw (5) << nthBx;
480  int ntbin_ = tmpTime - startTime;
481  for (map<TString,MonitorElement*>::iterator itHst = hst.begin();
482  itHst != hst.end(); ++itHst) {
483  if (!(itHst->first.Contains(ss.str()))) continue;
484  if (itHst->first.Contains("nPVs")) continue;
485  edm::LogInfo("BX|BeamMonitorBx") << "Filling histogram: " << itHst->first << endl;
486  if (itHst->first.Contains("time")) {
487  int idx = itHst->first.Index("_time",5);
488  itHst->second->setBinContent(ntbin_,val_[itHst->first(0,idx)].first);
489  itHst->second->setBinError(ntbin_,val_[itHst->first(0,idx)].second);
490  }
491  if (itHst->first.Contains("lumi")) {
492  int idx = itHst->first.Index("_lumi",5);
493  itHst->second->setBinContent(endLumiOfBSFit_,val_[itHst->first(0,idx)].first);
494  itHst->second->setBinError(endLumiOfBSFit_,val_[itHst->first(0,idx)].second);
495  }
496  }
497  TString histName = "Trending_nPVs_lumi_bx_" + ss.str();
498  if (hst[histName])
499  hst[histName]->setBinContent(endLumiOfBSFit_,nPVs_);
500 }
501 
502 //--------------------------------------------------------------------------------------------------
503 void BeamMonitorBx::weight(BeamSpotMapBx& weightedMap_, const BeamSpotMapBx& newMap_){
504  for (BeamSpotMapBx::const_iterator it = newMap_.begin();
505  it != newMap_.end(); ++it) {
506  if (weightedMap_.find(it->first) == weightedMap_.end() || (it->second.type() != 2)) {
507  weightedMap_[it->first] = it->second;
508  continue;
509  }
510 
511  BeamSpot obs = weightedMap_[it->first];
512  double val_[8] = { obs.x0(),obs.y0(),obs.z0(),obs.sigmaZ(),
513  obs.dxdz(),obs.dydz(),obs.BeamWidthX(),obs.BeamWidthY()};
514  double valErr_[8] = { obs.x0Error(),obs.y0Error(),obs.z0Error(),
515  obs.sigmaZ0Error(),obs.dxdzError(),obs.dydzError(),
516  obs.BeamWidthXError(),obs.BeamWidthYError()};
517 
519  weight(val_[0], valErr_[0], it->second.x0() , it->second.x0Error());
520  weight(val_[1], valErr_[1], it->second.y0() , it->second.y0Error());
521  weight(val_[2], valErr_[2], it->second.z0() , it->second.z0Error());
522  weight(val_[3], valErr_[3], it->second.sigmaZ() , it->second.sigmaZ0Error());
523  weight(val_[4], valErr_[4], it->second.dxdz() , it->second.dxdzError());
524  weight(val_[5], valErr_[5], it->second.dydz() , it->second.dydzError());
525  weight(val_[6], valErr_[6], it->second.BeamWidthX(), it->second.BeamWidthXError());
526  weight(val_[7], valErr_[7], it->second.BeamWidthY(), it->second.BeamWidthYError());
527  if(it->second.type() == reco::BeamSpot::Tracker){
529  }
530 
531  reco::BeamSpot::Point bsPosition(val_[0],val_[1],val_[2]);
533  for (int i=0;i<7;++i) {
534  error(i,i) = valErr_[i]*valErr_[i];
535  }
536  reco::BeamSpot weightedBeamSpot(bsPosition,val_[3],val_[4],val_[5],val_[6],error,type);
537  weightedBeamSpot.setBeamWidthY(val_[7]);
538  LogInfo("BX|BeamMonitorBx")
539  << weightedBeamSpot
540  << endl;
541  weightedMap_.erase(it->first);
542  weightedMap_[it->first] = weightedBeamSpot;
543  }
544 }
545 
546 //--------------------------------------------------------------------------------------------------
547 void BeamMonitorBx::weight(double& mean,double& meanError,const double& val,const double& valError){
548  double tmpError = 0;
549  if (meanError < 1e-8){
550  tmpError = 1/(valError*valError);
551  mean = val*tmpError;
552  }
553  else{
554  tmpError = 1/(meanError*meanError) + 1/(valError*valError);
555  mean = mean/(meanError*meanError) + val/(valError*valError);
556  }
557  mean = mean/tmpError;
558  meanError = std::sqrt(1/tmpError);
559 }
560 
561 //--------------------------------------------------------
562 void BeamMonitorBx::endRun(const Run& r, const EventSetup& context){
563 
564 }
565 
566 //--------------------------------------------------------
568  const EventSetup& iSetup){
569 }
570 
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
const char * formatFitTime(const std::time_t &)
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
tuple BeamFitter
Input track for PrimaryVertex reconstruction, uncomment the following line to use pixelLess tracks pr...
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:63
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:48
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:43
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
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:41
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