35 "%4d-%02d-%02d %02d:%02d:%02d",
43 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE 44 unsigned int b = strlen(ts);
45 while (ts[--
b] ==
' ') {
61 usesResource(
"DQMStore");
91 varMap[
"sigmaX_bx"] =
"#sigma_{X}";
92 varMap[
"sigmaY_bx"] =
"#sigma_{Y}";
93 varMap[
"sigmaZ_bx"] =
"#sigma_{Z}";
98 varMap1[
"sigmaX"] =
"#sigma_{X} [cm]";
99 varMap1[
"sigmaY"] =
"#sigma_{Y} [cm]";
100 varMap1[
"sigmaZ"] =
"#sigma_{Z} [cm]";
109 for (std::map<std::string, std::string>::const_iterator varName =
varMap1.begin(); varName !=
varMap1.end();
111 string subDir_ =
"FitBx";
114 subDir_ += varName->first;
131 const std::time_t ftmptime = fbegintimestamp >> 32;
155 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Begin of Lumi: " << nthlumi << endl;
160 bool readEvent_ =
true;
161 const int nthlumi =
iEvent.luminosityBlock();
164 edm::LogWarning(
"BX|BeamMonitorBx") <<
"Spilt event from previous lumi section!" << endl;
168 edm::LogWarning(
"BX|BeamMonitorBx") <<
"Spilt event from next lumi section!!!" << endl;
181 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Lumi of the last event before endLuminosityBlock: " << nthlumi << endl;
186 const std::time_t fendtime = fendtimestamp >> 32;
195 for (std::map<std::string, std::string>::const_iterator varName = vMap.begin(); varName != vMap.end(); ++varName) {
196 string tmpName = varName->first;
197 if (!suffix_.empty()) {
202 hs[tmpName] =
dbe_->
book2D(tmpName, varName->second, 3, 0, 3, nBx, 0, nBx);
203 hs[tmpName]->setBinLabel(1,
"bx", 1);
204 hs[tmpName]->setBinLabel(2, varName->second, 1);
205 hs[tmpName]->setBinLabel(3,
"#Delta " + varName->second, 1);
206 for (
int i = 0;
i < nBx;
i++) {
207 hs[tmpName]->setBinLabel(
i + 1,
" ", 2);
209 hs[tmpName]->getTH1()->SetOption(
"text");
210 hs[tmpName]->Reset();
216 bool plotPV,
int nBx, map<string, string>& vMap,
string subDir_,
const TString& prefix_,
const TString& suffix_) {
220 std::ostringstream
ss;
221 std::ostringstream ss1;
222 ss << setfill(
'0') << setw(5) << nBx;
225 for (
int i = 0;
i < nType_;
i++) {
226 for (std::map<std::string, std::string>::const_iterator varName = vMap.begin(); varName != vMap.end(); ++varName) {
227 string tmpDir_ = subDir_ +
"/All_" + varName->first;
232 tmpName = prefix_ +
"_" + varName->first;
234 tmpName = tmpName +
"_" + suffix_;
235 tmpName = tmpName +
"_" +
ss.str();
237 TString histName(tmpName);
238 string ytitle(varName->second);
241 bool createHisto =
true;
244 histName.Insert(histName.Index(
"_bx_", 4),
"_time");
245 xtitle =
"Time [UTC] [Bx# " + ss1.str() +
"]";
246 if (
ytitle.find(
"sigma") == string::npos)
247 histTitle +=
" coordinate of beam spot vs time (Fit)";
252 if (
ytitle.find(
"sigma") == string::npos) {
253 histName.Insert(0,
"PV");
254 histName.Insert(histName.Index(
"_bx_", 4),
"_lumi");
256 histTitle +=
" position of primary vtx vs lumi";
257 xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
259 ytitle +=
" #pm #sigma_{PV";
266 if (
ytitle.find(
"sigma") == string::npos) {
267 histName.Insert(0,
"PV");
268 histName.Insert(histName.Index(
"_bx_", 4),
"_time");
270 histTitle +=
" position of primary vtx vs time";
271 xtitle =
"Time [UTC] [Bx# " + ss1.str() +
"]";
273 ytitle +=
" #pm #sigma_{PV";
280 histName.Insert(histName.Index(
"_bx_", 4),
"_lumi");
281 xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
282 if (
ytitle.find(
"sigma") == string::npos)
283 histTitle +=
" coordinate of beam spot vs lumi (Fit)";
293 edm::LogInfo(
"BX|BeamMonitorBx") <<
"histName = " << histName <<
"; histTitle = " <<
histTitle << std::endl;
295 hst[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
298 hst[histName]->getTH1()->SetOption(
"E1");
299 if (histName.Contains(
"time")) {
300 hst[histName]->getTH1()->SetBins(3600, 0.5, 3600 + 0.5);
301 hst[histName]->setAxisTimeDisplay(1);
302 hst[histName]->setAxisTimeFormat(
"%H:%M:%S", 1);
306 TDatime
da(eventTime);
311 hst[histName]->getTH1()->GetXaxis()->SetTimeOffset(
da.Convert(kTRUE));
319 TString histName =
"Trending_nPVs_lumi_bx_" +
ss.str();
320 string xtitle =
"Lumisection [Bx# " + ss1.str() +
"]";
322 hst[histName] =
dbe_->
book1D(histName,
"Number of Good Reconstructed Vertices", 40, 0.5, 40.5);
324 hst[histName]->getTH1()->SetCanExtend(TH1::kAllAxes);
325 hst[histName]->getTH1()->SetOption(
"E1");
330 if (nthlumi <= nextlumi)
333 int currentlumi = nextlumi;
334 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Lumi of the current fit: " << currentlumi << endl;
335 lastlumi = currentlumi;
341 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Resetting Histograms" << endl;
351 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
" [Fitter] Do BeamSpot Fit for LS = " << fitLS.first <<
" to " << fitLS.second
357 <<
"; address = " << &
refBStime[0] << std::endl;
359 <<
"; address = " << &
refBStime[1] << std::endl;
366 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Number of bx = " << bsmap.size() << endl;
373 for (BeamSpotMapBx::const_iterator abspot = bsmap.begin(); abspot != bsmap.end(); ++abspot) {
374 int bx = abspot->first;
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(); varName !=
varMap.end();
384 hs[varName->first]->setTitle(varName->second +
" " + tmpTitle);
385 hs[varName->first]->Reset();
401 ") [weighted average]");
403 snprintf(tmpTitle1,
sizeof(tmpTitle1),
"%s",
"Need at least two fits to calculate weighted average");
404 for (std::map<std::string, std::string>::const_iterator varName =
varMap.begin(); varName !=
varMap.end();
406 TString tmpName = varName->first +
"_all";
407 hs[tmpName]->setTitle(varName->second +
" " + tmpTitle1);
408 hs[tmpName]->Reset();
413 for (BeamSpotMapBx::const_iterator abspot = bsmap.begin(); abspot != bsmap.end(); ++abspot, nthBin--) {
415 int bx = abspot->first;
416 int nPVs = npvsmap.find(
bx)->second;
417 edm::LogInfo(
"BeamMonitorBx") <<
"Number of PVs of bx#[" <<
bx <<
"] = " <<
nPVs << endl;
428 for (BeamSpotMapBx::const_iterator abspot =
fbspotMap.begin(); abspot !=
fbspotMap.end(); ++abspot, nthBin--) {
430 int bx = abspot->first;
439 edm::LogInfo(
"LS|BX|BeamMonitorBx") <<
"Reset track collection for beam fit!!!" << endl;
452 map<string, pair<double, double> > val_;
453 val_[
"x0_bx"] = pair<double, double>(bs_.
x0(), bs_.
x0Error());
454 val_[
"y0_bx"] = pair<double, double>(bs_.
y0(), bs_.
y0Error());
455 val_[
"z0_bx"] = pair<double, double>(bs_.
z0(), bs_.
z0Error());
460 for (std::map<std::string, std::string>::const_iterator varName = vMap.begin(); varName != vMap.end(); ++varName) {
461 TString tmpName = varName->first;
462 if (!suffix_.empty())
463 tmpName += TString(
"_" + suffix_);
464 hs[tmpName]->setBinContent(1, nthbin_, nthbx);
465 hs[tmpName]->setBinContent(2, nthbin_, val_[varName->first].first);
466 hs[tmpName]->setBinContent(3, nthbin_, val_[varName->first].second);
472 int nthBx,
int nPVs_, map<string, string>& vMap,
reco::BeamSpot& bs_,
const TString& prefix_) {
473 map<TString, pair<double, double> > val_;
474 val_[TString(prefix_ +
"_x")] = pair<double, double>(bs_.
x0(), bs_.
x0Error());
475 val_[TString(prefix_ +
"_y")] = pair<double, double>(bs_.
y0(), bs_.
y0Error());
476 val_[TString(prefix_ +
"_z")] = pair<double, double>(bs_.
z0(), bs_.
z0Error());
479 val_[TString(prefix_ +
"_sigmaZ")] = pair<double, double>(bs_.
sigmaZ(), bs_.
sigmaZ0Error());
481 std::ostringstream
ss;
482 ss << setfill(
'0') << setw(5) << nthBx;
484 for (map<TString, MonitorElement*>::iterator itHst =
hst.begin(); itHst !=
hst.end(); ++itHst) {
485 if (!(itHst->first.Contains(
ss.str())))
487 if (itHst->first.Contains(
"nPVs"))
489 edm::LogInfo(
"BX|BeamMonitorBx") <<
"Filling histogram: " << itHst->first << endl;
490 if (itHst->first.Contains(
"time")) {
491 int idx = itHst->first.Index(
"_time", 5);
492 itHst->second->setBinContent(ntbin_, val_[itHst->first(0,
idx)].first);
493 itHst->second->setBinError(ntbin_, val_[itHst->first(0,
idx)].second);
495 if (itHst->first.Contains(
"lumi")) {
496 int idx = itHst->first.Index(
"_lumi", 5);
501 TString histName =
"Trending_nPVs_lumi_bx_" +
ss.str();
508 for (BeamSpotMapBx::const_iterator
it = newMap_.begin();
it != newMap_.end(); ++
it) {
509 if (weightedMap_.find(
it->first) == weightedMap_.end() || (
it->second.type() != 2)) {
510 weightedMap_[
it->first] =
it->second;
517 double valErr_[8] = {obs.
x0Error(),
527 weight(val_[0], valErr_[0],
it->second.x0(),
it->second.x0Error());
528 weight(val_[1], valErr_[1],
it->second.y0(),
it->second.y0Error());
529 weight(val_[2], valErr_[2],
it->second.z0(),
it->second.z0Error());
530 weight(val_[3], valErr_[3],
it->second.sigmaZ(),
it->second.sigmaZ0Error());
531 weight(val_[4], valErr_[4],
it->second.dxdz(),
it->second.dxdzError());
532 weight(val_[5], valErr_[5],
it->second.dydz(),
it->second.dydzError());
533 weight(val_[6], valErr_[6],
it->second.BeamWidthX(),
it->second.BeamWidthXError());
534 weight(val_[7], valErr_[7],
it->second.BeamWidthY(),
it->second.BeamWidthYError());
541 for (
int i = 0;
i < 7; ++
i) {
546 LogInfo(
"BX|BeamMonitorBx") << weightedBeamSpot << endl;
547 weightedMap_.erase(
it->first);
548 weightedMap_[
it->first] = weightedBeamSpot;
555 if (meanError < 1
e-8) {
556 tmpError = 1 / (valError * valError);
559 tmpError = 1 / (meanError * meanError) + 1 / (valError * valError);
560 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