CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
BeamMonitorBx Class Reference

#include <BeamMonitorBx.h>

Inheritance diagram for BeamMonitorBx:
edm::EDAnalyzer

Public Types

typedef std::map< BxNum,
reco::BeamSpot
BeamSpotMapBx
 
typedef int BxNum
 
- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 

Public Member Functions

 BeamMonitorBx (const edm::ParameterSet &)
 
 ~BeamMonitorBx ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Protected Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c)
 
void beginJob ()
 
void beginLuminosityBlock (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
 
void beginRun (const edm::Run &r, const edm::EventSetup &c)
 
void endJob (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
 
void endLuminosityBlock (const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
 
void endRun (const edm::Run &r, const edm::EventSetup &c)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Private Member Functions

void BookTables (int, std::map< std::string, std::string > &, std::string)
 
void BookTrendHistos (bool, int, std::map< std::string, std::string > &, std::string, TString, TString)
 
void FillTables (int, int, std::map< std::string, std::string > &, reco::BeamSpot &, std::string)
 
void FillTrendHistos (int, int, std::map< std::string, std::string > &, reco::BeamSpot &, TString)
 
void FitAndFill (const edm::LuminosityBlock &lumiSeg, int &, int &, int &)
 
const char * formatFitTime (const std::time_t &)
 
void weight (BeamSpotMapBx &, const BeamSpotMapBx &)
 
void weight (double &mean, double &meanError, const double &val, const double &valError)
 

Private Attributes

int beginLumiOfBSFit_
 
edm::InputTag bsSrc_
 
unsigned int countBx_
 
int countEvt_
 
int countGoodFit_
 
int countLumi_
 
DQMStoredbe_
 
bool debug_
 
int endLumiOfBSFit_
 
BeamSpotMapBx fbspotMap
 
int firstlumi_
 
int fitNLumi_
 
edm::TimeValue_t ftimestamp
 
std::map< TString,
MonitorElement * > 
hs
 
std::map< TString,
MonitorElement * > 
hst
 
int lastlumi_
 
std::string monitorName_
 
int nextlumi_
 
edm::ParameterSet parameters_
 
bool processed_
 
std::time_t refBStime [2]
 
std::time_t refTime
 
int resetFitNLumi_
 
bool resetHistos_
 
std::time_t startTime
 
BeamFittertheBeamFitter
 
std::time_t tmpTime
 
std::map< std::string,
std::string > 
varMap
 
std::map< std::string,
std::string > 
varMap1
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 

Detailed Description

Definition at line 29 of file BeamMonitorBx.h.

Member Typedef Documentation

Definition at line 35 of file BeamMonitorBx.h.

typedef int BeamMonitorBx::BxNum

Definition at line 34 of file BeamMonitorBx.h.

Constructor & Destructor Documentation

BeamMonitorBx::BeamMonitorBx ( const edm::ParameterSet ps)

Definition at line 49 of file BeamMonitorBx.cc.

References beginLumiOfBSFit_, bsSrc_, countGoodFit_, dbe_, endLumiOfBSFit_, firstlumi_, fitNLumi_, edm::ParameterSet::getUntrackedParameter(), lastlumi_, monitorName_, nextlumi_, cppFunctionSkipper::operator, parameters_, processed_, refBStime, resetFitNLumi_, BeamFitter::resetLSRange(), BeamFitter::resetPVFitter(), BeamFitter::resetRefTime(), BeamFitter::resetTrkVector(), and theBeamFitter.

49  :
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 }
edm::ParameterSet parameters_
Definition: BeamMonitorBx.h:71
T getUntrackedParameter(std::string const &, T const &) const
void resetTrkVector()
Definition: BeamFitter.h:48
unsigned int countBx_
Definition: BeamMonitorBx.h:82
std::string monitorName_
Definition: BeamMonitorBx.h:72
void resetLSRange()
Definition: BeamFitter.h:50
BeamFitter * theBeamFitter
Definition: BeamMonitorBx.h:80
std::time_t refBStime[2]
Definition: BeamMonitorBx.h:91
edm::InputTag bsSrc_
Definition: BeamMonitorBx.h:73
void resetPVFitter()
Definition: BeamFitter.h:64
DQMStore * dbe_
Definition: BeamMonitorBx.h:79
void resetRefTime()
Definition: BeamFitter.h:51
BeamMonitorBx::~BeamMonitorBx ( )

Definition at line 79 of file BeamMonitorBx.cc.

References theBeamFitter.

79  {
80  delete theBeamFitter;
81 }
BeamFitter * theBeamFitter
Definition: BeamMonitorBx.h:80

Member Function Documentation

void BeamMonitorBx::analyze ( const edm::Event e,
const edm::EventSetup c 
)
protectedvirtual

Implements edm::EDAnalyzer.

Definition at line 156 of file BeamMonitorBx.cc.

References countEvt_, edm::EventBase::luminosityBlock(), nextlumi_, processed_, BeamFitter::readEvent(), and theBeamFitter.

157  {
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_++;
172  processed_ = true;
173  }
174 
175 }
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:223
int iEvent
Definition: GenABIO.cc:243
BeamFitter * theBeamFitter
Definition: BeamMonitorBx.h:80
void BeamMonitorBx::beginJob ( void  )
protectedvirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 85 of file BeamMonitorBx.cc.

References BookTables(), dbe_, monitorName_, DQMStore::setCurrentFolder(), varMap, and varMap1.

85  {
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 }
std::string monitorName_
Definition: BeamMonitorBx.h:72
void BookTables(int, std::map< std::string, std::string > &, std::string)
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
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
void BeamMonitorBx::beginLuminosityBlock ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup context 
)
protectedvirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 128 of file BeamMonitorBx.cc.

References beginLumiOfBSFit_, edm::LuminosityBlockBase::beginTime(), countLumi_, FitAndFill(), lastlumi_, edm::LuminosityBlockBase::luminosityBlock(), nextlumi_, processed_, refBStime, and edm::Timestamp::value().

129  {
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 }
void FitAndFill(const edm::LuminosityBlock &lumiSeg, int &, int &, int &)
Timestamp const & beginTime() const
LuminosityBlockNumber_t luminosityBlock() const
unsigned long long TimeValue_t
Definition: Timestamp.h:27
std::time_t refBStime[2]
Definition: BeamMonitorBx.h:91
TimeValue_t value() const
Definition: Timestamp.cc:72
void BeamMonitorBx::beginRun ( const edm::Run r,
const edm::EventSetup c 
)
protectedvirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 119 of file BeamMonitorBx.cc.

References edm::RunBase::beginTime(), ftimestamp, refTime, startTime, tmpTime, and edm::Timestamp::value().

119  {
120 
121  ftimestamp = r.beginTime().value();
122  tmpTime = ftimestamp >> 32;
124 
125 }
std::time_t startTime
edm::TimeValue_t ftimestamp
TimeValue_t value() const
Definition: Timestamp.cc:72
std::time_t tmpTime
std::time_t refTime
Timestamp const & beginTime() const
Definition: RunBase.h:43
void BeamMonitorBx::BookTables ( int  ,
std::map< std::string, std::string > &  ,
std::string   
)
private

Definition at line 192 of file BeamMonitorBx.cc.

References DQMStore::book2D(), DQMStore::cd(), dbe_, DQMStore::get(), hs, i, monitorName_, and DQMStore::removeElement().

Referenced by beginJob(), and FitAndFill().

192  {
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 }
int i
Definition: DBlmapReader.cc:9
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:406
std::map< TString, MonitorElement * > hs
std::string monitorName_
Definition: BeamMonitorBx.h:72
void removeElement(const std::string &name)
Definition: DQMStore.cc:2572
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
DQMStore * dbe_
Definition: BeamMonitorBx.h:79
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
void BeamMonitorBx::BookTrendHistos ( bool  ,
int  ,
std::map< std::string, std::string > &  ,
std::string  ,
TString  ,
TString   
)
private

Definition at line 221 of file BeamMonitorBx.cc.

References DQMStore::book1D(), DQMStore::cd(), pyrootRender::da, dbe_, debug_, formatFitTime(), DQMStore::get(), hst, i, monitorName_, AlCaHLTBitMon_ParallelJobs::options, and startTime.

Referenced by FitAndFill().

222  {
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 }
const char * formatFitTime(const std::time_t &)
int i
Definition: DBlmapReader.cc:9
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:406
std::time_t startTime
std::string monitorName_
Definition: BeamMonitorBx.h:72
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
DQMStore * dbe_
Definition: BeamMonitorBx.h:79
std::map< TString, MonitorElement * > hst
void BeamMonitorBx::endJob ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup c 
)
protected

Definition at line 568 of file BeamMonitorBx.cc.

569  {
570 }
void BeamMonitorBx::endLuminosityBlock ( const edm::LuminosityBlock lumiSeg,
const edm::EventSetup c 
)
protectedvirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 179 of file BeamMonitorBx.cc.

References edm::LuminosityBlockBase::endTime(), edm::LuminosityBlockBase::id(), edm::LuminosityBlockID::luminosityBlock(), nextlumi_, refBStime, tmpTime, and edm::Timestamp::value().

180  {
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 }
LuminosityBlockID id() const
Timestamp const & endTime() const
unsigned long long TimeValue_t
Definition: Timestamp.h:27
std::time_t refBStime[2]
Definition: BeamMonitorBx.h:91
TimeValue_t value() const
Definition: Timestamp.cc:72
std::time_t tmpTime
LuminosityBlockNumber_t luminosityBlock() const
void BeamMonitorBx::endRun ( const edm::Run r,
const edm::EventSetup c 
)
protectedvirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 563 of file BeamMonitorBx.cc.

563  {
564 
565 }
void BeamMonitorBx::FillTables ( int  ,
int  ,
std::map< std::string, std::string > &  ,
reco::BeamSpot ,
std::string   
)
private

Definition at line 447 of file BeamMonitorBx.cc.

References reco::BeamSpot::BeamWidthX(), reco::BeamSpot::BeamWidthXError(), reco::BeamSpot::BeamWidthY(), reco::BeamSpot::BeamWidthYError(), hs, reco::BeamSpot::sigmaZ(), reco::BeamSpot::sigmaZ0Error(), reco::BeamSpot::x0(), reco::BeamSpot::x0Error(), reco::BeamSpot::y0(), reco::BeamSpot::y0Error(), reco::BeamSpot::z0(), and reco::BeamSpot::z0Error().

Referenced by FitAndFill().

449  {
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 }
std::map< TString, MonitorElement * > hs
void BeamMonitorBx::FillTrendHistos ( int  ,
int  ,
std::map< std::string, std::string > &  ,
reco::BeamSpot ,
TString   
)
private

Definition at line 469 of file BeamMonitorBx.cc.

References reco::BeamSpot::BeamWidthX(), reco::BeamSpot::BeamWidthXError(), reco::BeamSpot::BeamWidthY(), reco::BeamSpot::BeamWidthYError(), endLumiOfBSFit_, hst, reco::BeamSpot::sigmaZ(), reco::BeamSpot::sigmaZ0Error(), startTime, tmpTime, reco::BeamSpot::x0(), reco::BeamSpot::x0Error(), reco::BeamSpot::y0(), reco::BeamSpot::y0Error(), reco::BeamSpot::z0(), and reco::BeamSpot::z0Error().

Referenced by FitAndFill().

470  {
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 }
std::time_t startTime
std::time_t tmpTime
std::map< TString, MonitorElement * > hst
void BeamMonitorBx::FitAndFill ( const edm::LuminosityBlock lumiSeg,
int &  lastlumi,
int &  nextlumi,
int &  nthlumi 
)
private

Definition at line 331 of file BeamMonitorBx.cc.

References beginLumiOfBSFit_, BookTables(), BookTrendHistos(), countBx_, countGoodFit_, endLumiOfBSFit_, fbspotMap, FillTables(), FillTrendHistos(), firstlumi_, fitNLumi_, BeamFitter::getBeamSpotMap(), BeamFitter::getFitLSRange(), BeamFitter::getNPVsperBX(), hs, refBStime, refTime, BeamFitter::resetCutFlow(), resetFitNLumi_, resetHistos_, BeamFitter::resetLSRange(), BeamFitter::resetPVFitter(), BeamFitter::resetRefTime(), BeamFitter::resetTrkVector(), BeamFitter::runPVandTrkFitter(), theBeamFitter, tmpTime, varMap, varMap1, and weight().

Referenced by beginLuminosityBlock().

332  {
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 }
const std::map< int, int > & getNPVsperBX()
Definition: BeamFitter.h:127
void FillTables(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, std::string)
bool runPVandTrkFitter()
Definition: BeamFitter.cc:409
void resetTrkVector()
Definition: BeamFitter.h:48
void FillTrendHistos(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, TString)
void BookTrendHistos(bool, int, std::map< std::string, std::string > &, std::string, TString, TString)
std::map< TString, MonitorElement * > hs
BeamSpotMapBx fbspotMap
Definition: BeamMonitorBx.h:96
std::map< int, reco::BeamSpot > getBeamSpotMap()
Definition: BeamFitter.h:90
unsigned int countBx_
Definition: BeamMonitorBx.h:82
void resetLSRange()
Definition: BeamFitter.h:50
BeamFitter * theBeamFitter
Definition: BeamMonitorBx.h:80
std::time_t refBStime[2]
Definition: BeamMonitorBx.h:91
std::time_t tmpTime
void weight(BeamSpotMapBx &, const BeamSpotMapBx &)
std::time_t refTime
void BookTables(int, std::map< std::string, std::string > &, std::string)
void resetPVFitter()
Definition: BeamFitter.h:64
void resetCutFlow()
Definition: BeamFitter.h:100
std::map< std::string, std::string > varMap
Definition: BeamMonitorBx.h:97
std::map< std::string, std::string > varMap1
Definition: BeamMonitorBx.h:98
std::pair< int, int > getFitLSRange()
Definition: BeamFitter.h:112
std::map< BxNum, reco::BeamSpot > BeamSpotMapBx
Definition: BeamMonitorBx.h:35
void resetRefTime()
Definition: BeamFitter.h:51
const char * BeamMonitorBx::formatFitTime ( const std::time_t &  )
private

Definition at line 29 of file BeamMonitorBx.cc.

References b, CEST, and plotBeamSpotDB::ptm.

Referenced by BookTrendHistos().

29  {
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 }
#define CEST
double b
Definition: hdecay.h:120
void BeamMonitorBx::weight ( BeamSpotMapBx weightedMap_,
const BeamSpotMapBx newMap_ 
)
private

Definition at line 504 of file BeamMonitorBx.cc.

References reco::BeamSpot::BeamWidthX(), reco::BeamSpot::BeamWidthXError(), reco::BeamSpot::BeamWidthY(), reco::BeamSpot::BeamWidthYError(), reco::BeamSpot::dxdz(), reco::BeamSpot::dxdzError(), reco::BeamSpot::dydz(), reco::BeamSpot::dydzError(), error, i, reco::BeamSpot::setBeamWidthY(), reco::BeamSpot::sigmaZ(), reco::BeamSpot::sigmaZ0Error(), reco::BeamSpot::Tracker, reco::BeamSpot::Unknown, reco::BeamSpot::x0(), reco::BeamSpot::x0Error(), reco::BeamSpot::y0(), reco::BeamSpot::y0Error(), reco::BeamSpot::z0(), and reco::BeamSpot::z0Error().

Referenced by FitAndFill().

504  {
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 }
type
Definition: HCALResponse.h:22
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:32
double z0() const
z coordinate
Definition: BeamSpot.h:69
BeamType
beam spot flags
Definition: BeamSpot.h:27
int i
Definition: DBlmapReader.cc:9
double sigmaZ0Error() const
error on sigma z
Definition: BeamSpot.h:97
double dydzError() const
error on dydz
Definition: BeamSpot.h:101
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:30
double dydz() const
dydz slope
Definition: BeamSpot.h:85
double dxdzError() const
error on dxdz
Definition: BeamSpot.h:99
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:87
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
Definition: BeamSpot.h:106
double BeamWidthXError() const
error on beam width X, assume error in X = Y
Definition: BeamSpot.h:104
double z0Error() const
error on z
Definition: BeamSpot.h:95
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
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 y0() const
y coordinate
Definition: BeamSpot.h:67
double x0() const
x coordinate
Definition: BeamSpot.h:65
void BeamMonitorBx::weight ( double &  mean,
double &  meanError,
const double &  val,
const double &  valError 
)
private

Definition at line 548 of file BeamMonitorBx.cc.

References alignCSCRings::e, and mathSSE::sqrt().

548  {
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 }
T sqrt(T t)
Definition: SSEVec.h:46

Member Data Documentation

int BeamMonitorBx::beginLumiOfBSFit_
private

Definition at line 85 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), beginLuminosityBlock(), and FitAndFill().

edm::InputTag BeamMonitorBx::bsSrc_
private

Definition at line 73 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx().

unsigned int BeamMonitorBx::countBx_
private

Definition at line 82 of file BeamMonitorBx.h.

Referenced by FitAndFill().

int BeamMonitorBx::countEvt_
private

Definition at line 83 of file BeamMonitorBx.h.

Referenced by analyze().

int BeamMonitorBx::countGoodFit_
private

Definition at line 90 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), and FitAndFill().

int BeamMonitorBx::countLumi_
private

Definition at line 84 of file BeamMonitorBx.h.

Referenced by beginLuminosityBlock().

DQMStore* BeamMonitorBx::dbe_
private

Definition at line 79 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), beginJob(), BookTables(), and BookTrendHistos().

bool BeamMonitorBx::debug_
private

Definition at line 77 of file BeamMonitorBx.h.

Referenced by BookTrendHistos().

int BeamMonitorBx::endLumiOfBSFit_
private

Definition at line 86 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), FillTrendHistos(), and FitAndFill().

BeamSpotMapBx BeamMonitorBx::fbspotMap
private

Definition at line 96 of file BeamMonitorBx.h.

Referenced by FitAndFill().

int BeamMonitorBx::firstlumi_
private

Definition at line 89 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), and FitAndFill().

int BeamMonitorBx::fitNLumi_
private

Definition at line 75 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), and FitAndFill().

edm::TimeValue_t BeamMonitorBx::ftimestamp
private

Definition at line 110 of file BeamMonitorBx.h.

Referenced by beginRun().

std::map<TString, MonitorElement*> BeamMonitorBx::hs
private

Definition at line 100 of file BeamMonitorBx.h.

Referenced by BookTables(), FillTables(), and FitAndFill().

std::map<TString, MonitorElement*> BeamMonitorBx::hst
private

Definition at line 101 of file BeamMonitorBx.h.

Referenced by BookTrendHistos(), and FillTrendHistos().

int BeamMonitorBx::lastlumi_
private

Definition at line 87 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), and beginLuminosityBlock().

std::string BeamMonitorBx::monitorName_
private

Definition at line 72 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), beginJob(), BookTables(), and BookTrendHistos().

int BeamMonitorBx::nextlumi_
private

Definition at line 88 of file BeamMonitorBx.h.

Referenced by analyze(), BeamMonitorBx(), beginLuminosityBlock(), and endLuminosityBlock().

edm::ParameterSet BeamMonitorBx::parameters_
private
bool BeamMonitorBx::processed_
private

Definition at line 94 of file BeamMonitorBx.h.

Referenced by analyze(), BeamMonitorBx(), and beginLuminosityBlock().

std::time_t BeamMonitorBx::refBStime[2]
private
std::time_t BeamMonitorBx::refTime
private

Definition at line 108 of file BeamMonitorBx.h.

Referenced by beginRun(), and FitAndFill().

int BeamMonitorBx::resetFitNLumi_
private

Definition at line 76 of file BeamMonitorBx.h.

Referenced by BeamMonitorBx(), and FitAndFill().

bool BeamMonitorBx::resetHistos_
private

Definition at line 93 of file BeamMonitorBx.h.

Referenced by FitAndFill().

std::time_t BeamMonitorBx::startTime
private

Definition at line 109 of file BeamMonitorBx.h.

Referenced by beginRun(), BookTrendHistos(), and FillTrendHistos().

BeamFitter* BeamMonitorBx::theBeamFitter
private

Definition at line 80 of file BeamMonitorBx.h.

Referenced by analyze(), BeamMonitorBx(), FitAndFill(), and ~BeamMonitorBx().

std::time_t BeamMonitorBx::tmpTime
private

Definition at line 107 of file BeamMonitorBx.h.

Referenced by beginRun(), endLuminosityBlock(), FillTrendHistos(), and FitAndFill().

std::map<std::string, std::string> BeamMonitorBx::varMap
private

Definition at line 97 of file BeamMonitorBx.h.

Referenced by beginJob(), and FitAndFill().

std::map<std::string, std::string> BeamMonitorBx::varMap1
private

Definition at line 98 of file BeamMonitorBx.h.

Referenced by beginJob(), and FitAndFill().