35 "%4d-%02d-%02d %02d:%02d:%02d",
43 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE 44 unsigned int b = strlen(ts);
45 while (ts[--
b] ==
' ') {
90 varMap[
"sigmaX_bx"] =
"#sigma_{X}";
91 varMap[
"sigmaY_bx"] =
"#sigma_{Y}";
92 varMap[
"sigmaZ_bx"] =
"#sigma_{Z}";
97 varMap1[
"sigmaX"] =
"#sigma_{X} [cm]";
98 varMap1[
"sigmaY"] =
"#sigma_{Y} [cm]";
99 varMap1[
"sigmaZ"] =
"#sigma_{Z} [cm]";
108 for (std::map<std::string, std::string>::const_iterator varName =
varMap1.begin(); varName !=
varMap1.end();
110 string subDir_ =
"FitBx";
113 subDir_ += varName->first;
130 const std::time_t ftmptime = fbegintimestamp >> 32;
154 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Begin of Lumi: " << nthlumi << endl;
159 bool readEvent_ =
true;
160 const int nthlumi =
iEvent.luminosityBlock();
163 edm::LogWarning(
"BX|BeamMonitorBx") <<
"Spilt event from previous lumi section!" << endl;
167 edm::LogWarning(
"BX|BeamMonitorBx") <<
"Spilt event from next lumi section!!!" << endl;
180 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
185 const std::time_t fendtime = fendtimestamp >> 32;
194 for (std::map<std::string, std::string>::const_iterator varName = vMap.begin(); varName != vMap.end(); ++varName) {
195 string tmpName = varName->first;
196 if (!suffix_.empty()) {
201 hs[tmpName] =
dbe_->
book2D(tmpName, varName->second, 3, 0, 3, nBx, 0, nBx);
202 hs[tmpName]->setBinLabel(1,
"bx", 1);
203 hs[tmpName]->setBinLabel(2, varName->second, 1);
204 hs[tmpName]->setBinLabel(3,
"#Delta " + varName->second, 1);
205 for (
int i = 0;
i < nBx;
i++) {
206 hs[tmpName]->setBinLabel(
i + 1,
" ", 2);
208 hs[tmpName]->getTH1()->SetOption(
"text");
209 hs[tmpName]->Reset();
215 bool plotPV,
int nBx, map<string, string>& vMap,
string subDir_,
const TString& prefix_,
const TString& suffix_) {
219 std::ostringstream
ss;
220 std::ostringstream ss1;
221 ss << setfill(
'0') << setw(5) << nBx;
224 for (
int i = 0;
i < nType_;
i++) {
225 for (std::map<std::string, std::string>::const_iterator varName = vMap.begin(); varName != vMap.end(); ++varName) {
226 string tmpDir_ = subDir_ +
"/All_" + varName->first;
231 tmpName = prefix_ +
"_" + varName->first;
233 tmpName = tmpName +
"_" + suffix_;
234 tmpName = tmpName +
"_" +
ss.str();
236 TString histName(tmpName);
237 string ytitle(varName->second);
240 bool createHisto =
true;
243 histName.Insert(histName.Index(
"_bx_", 4),
"_time");
244 xtitle =
"Time [UTC] [Bx# " + ss1.str() +
"]";
245 if (
ytitle.find(
"sigma") == string::npos)
246 histTitle +=
" coordinate of beam spot vs time (Fit)";
251 if (
ytitle.find(
"sigma") == string::npos) {
252 histName.Insert(0,
"PV");
253 histName.Insert(histName.Index(
"_bx_", 4),
"_lumi");
255 histTitle +=
" position of primary vtx vs lumi";
256 xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
258 ytitle +=
" #pm #sigma_{PV";
265 if (
ytitle.find(
"sigma") == string::npos) {
266 histName.Insert(0,
"PV");
267 histName.Insert(histName.Index(
"_bx_", 4),
"_time");
269 histTitle +=
" position of primary vtx vs time";
270 xtitle =
"Time [UTC] [Bx# " + ss1.str() +
"]";
272 ytitle +=
" #pm #sigma_{PV";
279 histName.Insert(histName.Index(
"_bx_", 4),
"_lumi");
280 xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
281 if (
ytitle.find(
"sigma") == string::npos)
282 histTitle +=
" coordinate of beam spot vs lumi (Fit)";
292 edm::LogInfo(
"BX|BeamMonitorBx") <<
"histName = " << histName <<
"; histTitle = " <<
histTitle << std::endl;
294 hst[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
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);
305 TDatime
da(eventTime);
310 hst[histName]->getTH1()->GetXaxis()->SetTimeOffset(
da.Convert(kTRUE));
318 TString histName =
"Trending_nPVs_lumi_bx_" +
ss.str();
319 string xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
321 hst[histName] =
dbe_->
book1D(histName,
"Number of Good Reconstructed Vertices", 40, 0.5, 40.5);
323 hst[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
324 hst[histName]->getTH1()->SetOption(
"E1");
329 if (nthlumi <= nextlumi)
332 int currentlumi = nextlumi;
333 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Lumi of the current fit: " << currentlumi << endl;
334 lastlumi = currentlumi;
340 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Resetting Histograms" << endl;
350 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
" [Fitter] Do BeamSpot Fit for LS = " << fitLS.first <<
" to " << fitLS.second
356 <<
"; address = " << &
refBStime[0] << std::endl;
358 <<
"; address = " << &
refBStime[1] << std::endl;
365 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Number of bx = " << bsmap.size() << endl;
372 for (BeamSpotMapBx::const_iterator abspot = bsmap.begin(); abspot != bsmap.end(); ++abspot) {
373 int bx = abspot->first;
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(); varName !=
varMap.end();
383 hs[varName->first]->setTitle(varName->second +
" " + tmpTitle);
384 hs[varName->first]->Reset();
400 ") [weighted average]");
402 snprintf(tmpTitle1,
sizeof(tmpTitle1),
"%s",
"Need at least two fits to calculate weighted average");
403 for (std::map<std::string, std::string>::const_iterator varName =
varMap.begin(); varName !=
varMap.end();
405 TString tmpName = varName->first +
"_all";
406 hs[tmpName]->setTitle(varName->second +
" " + tmpTitle1);
407 hs[tmpName]->Reset();
412 for (BeamSpotMapBx::const_iterator abspot = bsmap.begin(); abspot != bsmap.end(); ++abspot, nthBin--) {
414 int bx = abspot->first;
415 int nPVs = npvsmap.find(
bx)->second;
416 edm::LogInfo(
"BeamMonitorBx") <<
"Number of PVs of bx#[" <<
bx <<
"] = " <<
nPVs << endl;
427 for (BeamSpotMapBx::const_iterator abspot =
fbspotMap.begin(); abspot !=
fbspotMap.end(); ++abspot, nthBin--) {
429 int bx = abspot->first;
438 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Reset track collection for beam fit!!!" << endl;
451 map<string, pair<double, double> > val_;
452 val_[
"x0_bx"] = pair<double, double>(bs_.
x0(), bs_.
x0Error());
453 val_[
"y0_bx"] = pair<double, double>(bs_.
y0(), bs_.
y0Error());
454 val_[
"z0_bx"] = pair<double, double>(bs_.
z0(), bs_.
z0Error());
459 for (std::map<std::string, std::string>::const_iterator varName = vMap.begin(); varName != vMap.end(); ++varName) {
460 TString tmpName = varName->first;
461 if (!suffix_.empty())
462 tmpName += TString(
"_" + suffix_);
463 hs[tmpName]->setBinContent(1, nthbin_, nthbx);
464 hs[tmpName]->setBinContent(2, nthbin_, val_[varName->first].first);
465 hs[tmpName]->setBinContent(3, nthbin_, val_[varName->first].second);
471 int nthBx,
int nPVs_, map<string, string>& vMap,
reco::BeamSpot& bs_,
const TString& prefix_) {
472 map<TString, pair<double, double> > val_;
473 val_[TString(prefix_ +
"_x")] = pair<double, double>(bs_.
x0(), bs_.
x0Error());
474 val_[TString(prefix_ +
"_y")] = pair<double, double>(bs_.
y0(), bs_.
y0Error());
475 val_[TString(prefix_ +
"_z")] = pair<double, double>(bs_.
z0(), bs_.
z0Error());
478 val_[TString(prefix_ +
"_sigmaZ")] = pair<double, double>(bs_.
sigmaZ(), bs_.
sigmaZ0Error());
480 std::ostringstream
ss;
481 ss << setfill(
'0') << setw(5) << nthBx;
483 for (map<TString, MonitorElement*>::iterator itHst =
hst.begin(); itHst !=
hst.end(); ++itHst) {
484 if (!(itHst->first.Contains(
ss.str())))
486 if (itHst->first.Contains(
"nPVs"))
488 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Filling histogram: " << itHst->first << endl;
489 if (itHst->first.Contains(
"time")) {
490 int idx = itHst->first.Index(
"_time", 5);
491 itHst->second->setBinContent(ntbin_, val_[itHst->first(0,
idx)].first);
492 itHst->second->setBinError(ntbin_, val_[itHst->first(0,
idx)].second);
494 if (itHst->first.Contains(
"lumi")) {
495 int idx = itHst->first.Index(
"_lumi", 5);
500 TString histName =
"Trending_nPVs_lumi_bx_" +
ss.str();
507 for (BeamSpotMapBx::const_iterator it = newMap_.begin(); it != newMap_.end(); ++it) {
508 if (weightedMap_.find(it->first) == weightedMap_.end() || (it->second.type() != 2)) {
509 weightedMap_[it->first] = it->second;
513 BeamSpot obs = weightedMap_[it->first];
516 double valErr_[8] = {obs.
x0Error(),
526 weight(val_[0], valErr_[0], it->second.x0(), it->second.x0Error());
527 weight(val_[1], valErr_[1], it->second.y0(), it->second.y0Error());
528 weight(val_[2], valErr_[2], it->second.z0(), it->second.z0Error());
529 weight(val_[3], valErr_[3], it->second.sigmaZ(), it->second.sigmaZ0Error());
530 weight(val_[4], valErr_[4], it->second.dxdz(), it->second.dxdzError());
531 weight(val_[5], valErr_[5], it->second.dydz(), it->second.dydzError());
532 weight(val_[6], valErr_[6], it->second.BeamWidthX(), it->second.BeamWidthXError());
533 weight(val_[7], valErr_[7], it->second.BeamWidthY(), it->second.BeamWidthYError());
540 for (
int i = 0;
i < 7; ++
i) {
545 LogInfo(
"BX|BeamMonitorBx") << weightedBeamSpot << endl;
546 weightedMap_.erase(it->first);
547 weightedMap_[it->first] = weightedBeamSpot;
554 if (meanError < 1
e-8) {
555 tmpError = 1 / (valError * valError);
558 tmpError = 1 / (meanError * meanError) + 1 / (valError * valError);
559 mean =
mean / (meanError * meanError) +
val / (valError * valError);
edm::ParameterSet parameters_
void FillTrendHistos(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, const TString &)
math::Error< dimension >::type CovarianceMatrix
double BeamWidthX() const
beam width X
const std::map< int, int > & getNPVsperBX()
LuminosityBlockNumber_t luminosityBlock() const
void FillTables(int, int, std::map< std::string, std::string > &, reco::BeamSpot &, std::string)
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
BeamMonitorBx(const edm::ParameterSet &)
void FitAndFill(const edm::LuminosityBlock &lumiSeg, int &, int &, int &)
void setCurrentFolder(std::string const &fullpath) override
std::map< BxNum, reco::BeamSpot > BeamSpotMapBx
double x0Error() const
error on x
math::XYZPoint Point
point in the space
double dydz() const
dydz slope
std::map< TString, MonitorElement * > hs
double z0Error() const
error on z
void readEvent(const edm::Event &iEvent)
void endRun(const edm::Run &r, const edm::EventSetup &c) override
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
double sigmaZ0Error() const
error on sigma z
T getUntrackedParameter(std::string const &, T const &) const
std::map< int, reco::BeamSpot > getBeamSpotMap()
double x0() const
x coordinate
void setBeamWidthY(double v)
edm::TimeValue_t ftimestamp
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
double BeamWidthY() const
beam width Y
#define DEFINE_FWK_MODULE(type)
double y0() const
y coordinate
BeamFitter * theBeamFitter
unsigned long long TimeValue_t
double BeamWidthXError() const
error on beam width X, assume error in X = Y
Log< level::Info, false > LogInfo
void analyze(const edm::Event &e, const edm::EventSetup &c) override
void weight(BeamSpotMapBx &, const BeamSpotMapBx &)
double sigmaZ() const
sigma z
LuminosityBlockID id() const
TimeValue_t value() const
Timestamp const & beginTime() const
Timestamp const & endTime() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
double dxdz() const
dxdz slope
virtual MonitorElement * get(std::string const &fullpath) const
double z0() const
z coordinate
void BookTables(int, std::map< std::string, std::string > &, std::string)
double dydzError() const
error on dydz
std::pair< int, int > getFitLSRange()
std::map< std::string, std::string > varMap
void BookTrendHistos(bool, int, std::map< std::string, std::string > &, std::string, const TString &, const TString &)
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
std::map< std::string, std::string > varMap1
std::map< TString, MonitorElement * > hst
void formatFitTime(char *, const std::time_t &)
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
LuminosityBlockNumber_t luminosityBlock() const
double dxdzError() const
error on dxdz
~BeamMonitorBx() override
double y0Error() const
error on y