46 constexpr
int CEST(+2);
56 localTime = localtime(¤tTime);
57 int year = localTime->tm_year + 1900;
65 if (year >= 70 && year <= 137)
69 edm::LogError(
"BadTimeStamp") <<
"year reported is " << year <<
" !!" << std::endl;
74 "%4d-%02d-%02d %02d:%02d:%02d",
82 #ifdef STRIP_TRAILING_BLANKS_IN_TIMEZONE
83 unsigned int b = strlen(ts);
84 while (ts[--
b] ==
' ') {
98 : dxBin_(ps.getParameter<
int>(
"dxBin")),
99 dxMin_(ps.getParameter<double>(
"dxMin")),
100 dxMax_(ps.getParameter<double>(
"dxMax")),
102 vxBin_(ps.getParameter<
int>(
"vxBin")),
103 vxMin_(ps.getParameter<double>(
"vxMin")),
104 vxMax_(ps.getParameter<double>(
"vxMax")),
106 phiBin_(ps.getParameter<
int>(
"phiBin")),
107 phiMin_(ps.getParameter<double>(
"phiMin")),
108 phiMax_(ps.getParameter<double>(
"phiMax")),
110 dzBin_(ps.getParameter<
int>(
"dzBin")),
111 dzMin_(ps.getParameter<double>(
"dzMin")),
112 dzMax_(ps.getParameter<double>(
"dzMax")),
119 StartAverage_(
false),
151 rndm_ =
new TRandom3(0);
213 edm::LogInfo(
"FakeBeamMonitor") <<
"TimeOffset = " << eventTime << std::endl;
214 TDatime
da(eventTime);
219 auto daTime =
da.Convert(kTRUE);
226 h_nTrk_lumi = iBooker.
book1D(
"nTrk_lumi",
"Num. of selected tracks vs lumi (Fit)", 20, 0.5, 20.5);
231 h_nVtx_lumi = iBooker.
book1D(
"nVtx_lumi",
"Num. of selected Vtx vs lumi (Fit)", 20, 0.5, 20.5);
235 h_nVtx_lumi_all = iBooker.
book1D(
"nVtx_lumi_all",
"Num. of selected Vtx vs lumi (Fit) all", 20, 0.5, 20.5);
253 TDatime*
da =
new TDatime();
254 gStyle->SetTimeOffset(
da->Convert(kTRUE));
258 string coord[nvar_] = {
"x",
"y",
"z",
"sigmaX",
"sigmaY",
"sigmaZ"};
259 string label[nvar_] = {
260 "x_{0} (cm)",
"y_{0} (cm)",
"z_{0} (cm)",
"#sigma_{X_{0}} (cm)",
"#sigma_{Y_{0}} (cm)",
"#sigma_{Z_{0}} (cm)"};
263 hs.reserve(kNumHists);
264 for (
int i = 0;
i < 4;
i++) {
266 for (
int ic = 0; ic < nvar_; ++ic) {
267 TString histName(coord[ic]);
272 bool createHisto =
true;
275 histName +=
"0_time";
278 histTitle +=
" coordinate of beam spot vs time (Fit)";
285 histName.Insert(0,
"PV");
288 histTitle +=
" position of primary vtx vs lumi";
291 ytitle +=
" #pm #sigma_{PV";
300 histName.Insert(0,
"PV");
303 histTitle +=
" position of primary vtx vs time";
306 ytitle +=
" #pm #sigma_{PV";
313 histName +=
"0_lumi";
316 histTitle +=
" coordinate of beam spot vs lumi (Fit)";
322 edm::LogInfo(
"FakeBeamMonitor") <<
"hitsName = " << histName <<
"; histTitle = " <<
histTitle << std::endl;
325 tmpHs->setAxisTitle(
xtitle, 1);
326 tmpHs->setAxisTitle(
ytitle, 2);
327 tmpHs->getTH1()->SetOption(
"E1");
328 if (histName.Contains(
"time")) {
331 tmpHs->setAxisTimeDisplay(1);
332 tmpHs->setAxisTimeFormat(
"%H:%M:%S", 1);
333 tmpHs->getTH1()->GetXaxis()->SetTimeOffset(daTime);
339 tmpHs->getTH1()->SetCanExtend(TH1::kAllAxes);
340 tmpHs->setAxisTitle(
xtitle, 1);
341 tmpHs->setAxisTitle(
ytitle, 2);
342 tmpHs->getTH1()->SetOption(
"E1");
343 if (histName.Contains(
"time")) {
346 tmpHs->setAxisTimeDisplay(1);
347 tmpHs->setAxisTimeFormat(
"%H:%M:%S", 1);
348 tmpHs->getTH1()->GetXaxis()->SetTimeOffset(daTime);
354 assert(0 == strcmp(
hs[k_sigmaY0_time]->getTH1()->GetName(),
"sigmaY0_time"));
355 assert(0 == strcmp(
hs[k_PVz_lumi_all]->getTH1()->GetName(),
"PVz_lumi_all"));
372 h_x0 = iBooker.
book1D(
"BeamMonitorFeedBack_x0",
"x coordinate of beam spot (Fit)", 100, -0.01, 0.01);
376 h_y0 = iBooker.
book1D(
"BeamMonitorFeedBack_y0",
"y coordinate of beam spot (Fit)", 100, -0.01, 0.01);
384 h_sigmaX0 = iBooker.
book1D(
"BeamMonitorFeedBack_sigmaX0",
"sigma x0 of beam spot (Fit)", 100, 0, 0.05);
388 h_sigmaY0 = iBooker.
book1D(
"BeamMonitorFeedBack_sigmaY0",
"sigma y0 of beam spot (Fit)", 100, 0, 0.05);
392 h_sigmaZ0 = iBooker.
book1D(
"BeamMonitorFeedBack_sigmaZ0",
"sigma z0 of beam spot (Fit)", 100, 0, 10);
397 h_trkPt = iBooker.
book1D(
"trkPt",
"p_{T} of all reco'd tracks (no selection)", 200, 0., 50.);
403 cutFlowTable = iBooker.
book1D(
"cutFlowTable",
"Cut flow table of track selection", 9, 0, 9);
406 fitResults = iBooker.
book2D(
"fitResults",
"Results of previous good beam fit", 2, 0, 2, 8, 0, 8);
423 h_nVtx = iBooker.
book1D(
"vtxNbr",
"Reconstructed Vertices(non-fake) in all Event", 60, -0.5, 59.5);
427 h_nVtx_st = iBooker.
book1D(
"vtxNbr_SelectedTriggers",
"Reconstructed Vertices(non-fake) in Events", 60, -0.5, 59.5);
431 h_PVx[0] = iBooker.
book1D(
"PVX",
"x coordinate of Primary Vtx", 50, -0.01, 0.01);
435 h_PVy[0] = iBooker.
book1D(
"PVY",
"y coordinate of Primary Vtx", 50, -0.01, 0.01);
442 h_PVx[1] = iBooker.
book1D(
"PVXFit",
"x coordinate of Primary Vtx (Last Fit)", 50, -0.01, 0.01);
446 h_PVy[1] = iBooker.
book1D(
"PVYFit",
"y coordinate of Primary Vtx (Last Fit)", 50, -0.01, 0.01);
462 pvResults = iBooker.
book2D(
"pvResults",
"Results of fitting Primary Vertices", 2, 0, 2, 6, 0, 6);
486 sprintf(
histo,
"x0_status");
489 sprintf(
histo,
"y0_status");
492 sprintf(
histo,
"z0_status");
528 const std::time_t ftmptime = fbegintimestamp >> 32;
564 edm::LogInfo(
"FakeBeamMonitor") <<
" beginLuminosityBlock: Size of mapBeginBSLS before = "
572 map<int, std::time_t>::iterator itbstime =
mapBeginBSTime.begin();
573 map<int, std::time_t>::iterator itpvtime =
mapBeginPVTime.begin();
633 edm::LogInfo(
"FakeBeamMonitor") <<
" beginLuminosityBlock:: Next Lumi to Fit: " <<
nextlumi_ << endl;
643 edm::LogInfo(
"FakeBeamMonitor") <<
" beginLuminosityBlock:: Begin of Lumi: " << nthlumi << endl;
648 const int nthlumi =
iEvent.luminosityBlock();
651 edm::LogInfo(
"FakeBeamMonitor") <<
"analyze:: Spilt event from previous lumi section!" << std::endl;
655 edm::LogInfo(
"FakeBeamMonitor") <<
"analyze:: Spilt event from next lumi section!!!" << std::endl;
725 for (
int tmp_idx = 0; tmp_idx < 10; tmp_idx++) {
767 map<int, std::vector<float> >::iterator itpvx =
mapPVx.begin();
768 map<int, std::vector<float> >::iterator itpvy =
mapPVy.begin();
769 map<int, std::vector<float> >::iterator itpvz =
mapPVz.begin();
771 map<int, std::vector<int> >::iterator itbspvinfo =
mapNPV.begin();
788 edm::LogInfo(
"FakeBeamMonitor") <<
"endLuminosityBlock:: Lumi of the last event before endLuminosityBlock: "
794 const std::time_t fendtime = fendtimestamp >> 32;
813 int currentlumi = nextlumi;
814 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill:: Lumi of the current fit: " << currentlumi << endl;
815 lastlumi = currentlumi;
838 bool resetHistoFlag_ =
false;
844 resetHistoFlag_ =
true;
848 int countEvtLastNLS_ = 0;
851 std::map<int, std::vector<int> >::iterator mnpv =
mapNPV.begin();
852 std::map<int, std::vector<float> >::iterator mpv2 =
mapPVy.begin();
853 std::map<int, std::vector<float> >::iterator mpv3 =
mapPVz.begin();
856 ++mpv1, ++mpv2, ++mpv3, ++mnpv) {
857 std::vector<float>::iterator mpvs2 = (mpv2->second).begin();
858 std::vector<float>::iterator mpvs3 = (mpv3->second).begin();
859 for (std::vector<float>::iterator mpvs1 = (mpv1->second).begin(); mpvs1 != (mpv1->second).
end();
860 ++mpvs1, ++mpvs2, ++mpvs3) {
861 if (resetHistoFlag_) {
869 for (std::vector<int>::iterator mnpvs = (mnpv->second).begin(); mnpvs != (mnpv->second).
end(); ++mnpvs) {
870 if ((*mnpvs > 0) && (resetHistoFlag_))
873 countTotPV_ += (*mnpvs);
874 if ((*mnpvs) > MaxPVs)
880 char tmpTitlePV[100];
906 countEvtLastNLS_ = 0;
910 const int countLS_bs =
hs[k_x0_lumi]->getTH1()->GetEntries();
911 const int countLS_pv =
hs[k_PVx_lumi]->getTH1()->GetEntries();
912 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill:: countLS_bs = " << countLS_bs <<
" ; countLS_pv = " << countLS_pv
914 int LSgap_bs = currentlumi /
fitNLumi_ - countLS_bs;
915 int LSgap_pv = currentlumi /
fitPVNLumi_ - countLS_pv;
920 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill:: LSgap_bs = " << LSgap_bs <<
" ; LSgap_pv = " << LSgap_pv
923 for (
int ig = 0; ig < LSgap_bs; ig++) {
927 hs[k_sigmaX0_lumi]->ShiftFillLast(0., 0.,
fitNLumi_);
928 hs[k_sigmaY0_lumi]->ShiftFillLast(0., 0.,
fitNLumi_);
929 hs[k_sigmaZ0_lumi]->ShiftFillLast(0., 0.,
fitNLumi_);
932 for (
int ig = 0; ig < LSgap_pv; ig++) {
938 for (
int i = 1;
i < (currentlumi - previousLS);
978 std::unique_ptr<TF1> fgaus{
new TF1(
"fgaus",
"gaus")};
980 fgaus->SetLineColor(4);
982 mean = fgaus->GetParameter(1);
983 width = fgaus->GetParameter(2);
984 meanErr = fgaus->GetParError(1);
985 widthErr = fgaus->GetParError(2);
988 hs[k_PVx_lumi_all]->setBinContent(currentlumi,
mean);
989 hs[k_PVx_lumi_all]->setBinError(currentlumi,
width);
992 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill:: Event time outside current range of time histograms!"
995 hs[k_PVx_time]->setBinContent(nthBin,
mean);
996 hs[k_PVx_time]->setBinError(nthBin,
width);
1000 hs[k_PVx_time_all]->setBinContent(jthBin,
mean);
1001 hs[k_PVx_time_all]->setBinError(jthBin,
width);
1012 tmphisto->GetNbinsX(), tmphisto->GetXaxis()->GetXmin(), tmphisto->GetXaxis()->GetXmax());
1019 mean = fgaus->GetParameter(1);
1020 width = fgaus->GetParameter(2);
1021 meanErr = fgaus->GetParError(1);
1022 widthErr = fgaus->GetParError(2);
1024 hs[k_PVy_lumi_all]->setBinContent(currentlumi,
mean);
1025 hs[k_PVy_lumi_all]->setBinError(currentlumi,
width);
1027 hs[k_PVy_time]->setBinContent(nthBin,
mean);
1028 hs[k_PVy_time]->setBinError(nthBin,
width);
1031 hs[k_PVy_time_all]->setBinContent(jthBin,
mean);
1032 hs[k_PVy_time_all]->setBinError(jthBin,
width);
1042 tmphisto->GetNbinsX(), tmphisto->GetXaxis()->GetXmin(), tmphisto->GetXaxis()->GetXmax());
1049 mean = fgaus->GetParameter(1);
1050 width = fgaus->GetParameter(2);
1051 meanErr = fgaus->GetParError(1);
1052 widthErr = fgaus->GetParError(2);
1054 hs[k_PVz_lumi_all]->setBinContent(currentlumi,
mean);
1055 hs[k_PVz_lumi_all]->setBinError(currentlumi,
width);
1057 hs[k_PVz_time]->setBinContent(nthBin,
mean);
1058 hs[k_PVz_time]->setBinError(nthBin,
width);
1061 hs[k_PVz_time_all]->setBinContent(jthBin,
mean);
1062 hs[k_PVz_time_all]->setBinError(jthBin,
width);
1072 tmphisto->GetNbinsX(), tmphisto->GetXaxis()->GetXmin(), tmphisto->GetXaxis()->GetXmax());
1088 size_t PreviousRecords = 0;
1197 <<
"; address = " << &
refBStime[0] << std::endl;
1199 <<
"; address = " << &
refBStime[1] << std::endl;
1220 for (
int j = 0;
j < 7; ++
j) {
1221 for (
int k =
j;
k < 7; ++
k) {
1227 float tmp_BSx =
rndm_->Gaus(0.1, 0.1);
1228 float tmp_BSy =
rndm_->Gaus(0.1, 0.1);
1229 float tmp_BSz =
rndm_->Gaus(0.1, 0.1);
1230 float tmp_BSwidthX =
rndm_->Gaus(0.001, 0.0005);
1231 float tmp_BSwidthY =
rndm_->Gaus(0.001, 0.0005);
1232 float tmp_BSwidthZ =
rndm_->Gaus(3.5, 0.5);
1241 bs.setBeamWidthY(tmp_BSwidthY);
1246 edm::LogInfo(
"FakeBeamMonitor") <<
"\n RESULTS OF DEFAULT FIT:" << endl;
1248 edm::LogInfo(
"FakeBeamMonitor") <<
"[BeamFitter] fitting done \n" << endl;
1253 hs[k_sigmaX0_lumi]->ShiftFillLast(
bs.BeamWidthX(),
bs.BeamWidthXError(),
fitNLumi_);
1254 hs[k_sigmaY0_lumi]->ShiftFillLast(
bs.BeamWidthY(),
bs.BeamWidthYError(),
fitNLumi_);
1255 hs[k_sigmaZ0_lumi]->ShiftFillLast(
bs.sigmaZ(),
bs.sigmaZ0Error(),
fitNLumi_);
1256 hs[k_x0_lumi_all]->setBinContent(currentlumi,
bs.x0());
1257 hs[k_x0_lumi_all]->setBinError(currentlumi,
bs.x0Error());
1258 hs[k_y0_lumi_all]->setBinContent(currentlumi,
bs.y0());
1259 hs[k_y0_lumi_all]->setBinError(currentlumi,
bs.y0Error());
1260 hs[k_z0_lumi_all]->setBinContent(currentlumi,
bs.z0());
1261 hs[k_z0_lumi_all]->setBinError(currentlumi,
bs.z0Error());
1262 hs[k_sigmaX0_lumi_all]->setBinContent(currentlumi,
bs.BeamWidthX());
1263 hs[k_sigmaX0_lumi_all]->setBinError(currentlumi,
bs.BeamWidthXError());
1264 hs[k_sigmaY0_lumi_all]->setBinContent(currentlumi,
bs.BeamWidthY());
1265 hs[k_sigmaY0_lumi_all]->setBinError(currentlumi,
bs.BeamWidthYError());
1266 hs[k_sigmaZ0_lumi_all]->setBinContent(currentlumi,
bs.sigmaZ());
1267 hs[k_sigmaZ0_lumi_all]->setBinError(currentlumi,
bs.sigmaZ0Error());
1271 hs[k_x0_time]->setBinContent(nthBin,
bs.x0());
1272 hs[k_y0_time]->setBinContent(nthBin,
bs.y0());
1273 hs[k_z0_time]->setBinContent(nthBin,
bs.z0());
1274 hs[k_sigmaX0_time]->setBinContent(nthBin,
bs.BeamWidthX());
1275 hs[k_sigmaY0_time]->setBinContent(nthBin,
bs.BeamWidthY());
1276 hs[k_sigmaZ0_time]->setBinContent(nthBin,
bs.sigmaZ());
1277 hs[k_x0_time]->setBinError(nthBin,
bs.x0Error());
1278 hs[k_y0_time]->setBinError(nthBin,
bs.y0Error());
1279 hs[k_z0_time]->setBinError(nthBin,
bs.z0Error());
1280 hs[k_sigmaX0_time]->setBinError(nthBin,
bs.BeamWidthXError());
1281 hs[k_sigmaY0_time]->setBinError(nthBin,
bs.BeamWidthYError());
1282 hs[k_sigmaZ0_time]->setBinError(nthBin,
bs.sigmaZ0Error());
1287 hs[k_x0_time_all]->setBinContent(jthBin,
bs.x0());
1288 hs[k_y0_time_all]->setBinContent(jthBin,
bs.y0());
1289 hs[k_z0_time_all]->setBinContent(jthBin,
bs.z0());
1290 hs[k_sigmaX0_time_all]->setBinContent(jthBin,
bs.BeamWidthX());
1291 hs[k_sigmaY0_time_all]->setBinContent(jthBin,
bs.BeamWidthY());
1292 hs[k_sigmaZ0_time_all]->setBinContent(jthBin,
bs.sigmaZ());
1293 hs[k_x0_time_all]->setBinError(jthBin,
bs.x0Error());
1294 hs[k_y0_time_all]->setBinError(jthBin,
bs.y0Error());
1295 hs[k_z0_time_all]->setBinError(jthBin,
bs.z0Error());
1296 hs[k_sigmaX0_time_all]->setBinError(jthBin,
bs.BeamWidthXError());
1297 hs[k_sigmaY0_time_all]->setBinError(jthBin,
bs.BeamWidthYError());
1298 hs[k_sigmaZ0_time_all]->setBinError(jthBin,
bs.sigmaZ0Error());
1304 if (
bs.type() > 0) {
1312 double alpha = std::atan2(
bs.y0(),
bs.x0());
1313 std::unique_ptr<TF1>
f1{
new TF1(
"f1",
"[0]*sin(x-[1])", -3.14, 3.14)};
1314 f1->SetParameters(amp,
alpha);
1315 f1->SetParLimits(0, amp - 0.1, amp + 0.1);
1317 f1->SetLineColor(4);
1322 std::unique_ptr<TF1> fgaus{
new TF1(
"fgaus",
"gaus")};
1324 fgaus->SetLineColor(4);
1331 sprintf(tmpTitle,
"%s %i %s %i",
"Fitted Beam Spot (cm) of LS: ", LSRange.first,
" to ", LSRange.second);
1339 if (
bs.type() > 0) {
1353 if (
bs.type() > 0) {
1389 for (
int i = 0;
i < 7; ++
i) {
1390 for (
int j = 0;
j < 7; ++
j) {
1402 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill::[PayloadCreation] BeamSpotOnline object created: \n" << std::endl;
1403 edm::LogInfo(
"FakeBeamMonitor") << *BSOnline << std::endl;
1408 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill::[PayloadCreation] onlineDbService available \n" << std::endl;
1413 << fitLS.first <<
" to " << fitLS.second;
1419 <<
"FakeBeamMonitor::FitAndFill - [PayloadCreation] BeamSpotOnline object created:";
1427 <<
"FakeBeamMonitor::FitAndFill - [PayloadCreation] writeForNextLumisection executed correctly";
1430 <<
" for Run: " <<
frun <<
" - Lumi: " << fitLS.second;
1437 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill::[PayloadCreation] BeamSpotOnline payload created \n" << std::endl;
1498 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill:: The flag is ON for running average Beam Spot fit" << endl;
1512 <<
" RestartingFitting:: Restart Beami everything to a fresh start !!! because Gap is > 10 LS" << endl;
1549 edm::LogInfo(
"FakeBeamMonitor") <<
"dqmEndRun:: Clearing all the Maps " << endl;
1569 char offsetTime[64];
1571 TDatime
da(offsetTime);
1576 h->GetXaxis()->SetTimeOffset(
da.Convert(kTRUE));
1579 h->SetBinError(
bin, valErr);
1582 h->GetXaxis()->SetTimeOffset(
da.Convert(kTRUE));
1589 bool scroll_ =
false;
1592 edm::LogInfo(
"FakeBeamMonitor") <<
"testScroll:: Reset Time Offset" << std::endl;
1595 if (
hs[k_x0_time]->getBinContent(
bin) > 0) {
1602 edm::LogInfo(
"FakeBeamMonitor") <<
"testScroll:: Time difference too large since last readout" << std::endl;
1606 edm::LogInfo(
"FakeBeamMonitor") <<
"testScroll:: Offset to last record" << std::endl;