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),
150 rndm_ =
new TRandom3(0);
206 edm::LogInfo(
"FakeBeamMonitor") <<
"TimeOffset = " << eventTime << std::endl;
207 TDatime
da(eventTime);
212 auto daTime =
da.Convert(kTRUE);
219 h_nTrk_lumi = iBooker.book1D(
"nTrk_lumi",
"Num. of selected tracks vs lumi (Fit)", 20, 0.5, 20.5);
224 h_nVtx_lumi = iBooker.book1D(
"nVtx_lumi",
"Num. of selected Vtx vs lumi (Fit)", 20, 0.5, 20.5);
228 h_nVtx_lumi_all = iBooker.book1D(
"nVtx_lumi_all",
"Num. of selected Vtx vs lumi (Fit) all", 20, 0.5, 20.5);
246 TDatime*
da =
new TDatime();
247 gStyle->SetTimeOffset(
da->Convert(kTRUE));
251 string coord[nvar_] = {
"x",
"y",
"z",
"sigmaX",
"sigmaY",
"sigmaZ"};
252 string label[nvar_] = {
253 "x_{0} (cm)",
"y_{0} (cm)",
"z_{0} (cm)",
"#sigma_{X_{0}} (cm)",
"#sigma_{Y_{0}} (cm)",
"#sigma_{Z_{0}} (cm)"};
256 hs.reserve(kNumHists);
257 for (
int i = 0;
i < 4;
i++) {
259 for (
int ic = 0; ic < nvar_; ++ic) {
260 TString histName(coord[ic]);
265 bool createHisto =
true;
268 histName +=
"0_time";
271 histTitle +=
" coordinate of beam spot vs time (Fit)";
277 iBooker.setCurrentFolder(
monitorName_ +
"PrimaryVertex");
278 histName.Insert(0,
"PV");
281 histTitle +=
" position of primary vtx vs lumi";
284 ytitle +=
" #pm #sigma_{PV";
292 iBooker.setCurrentFolder(
monitorName_ +
"PrimaryVertex");
293 histName.Insert(0,
"PV");
296 histTitle +=
" position of primary vtx vs time";
299 ytitle +=
" #pm #sigma_{PV";
306 histName +=
"0_lumi";
309 histTitle +=
" coordinate of beam spot vs lumi (Fit)";
315 edm::LogInfo(
"FakeBeamMonitor") <<
"hitsName = " << histName <<
"; histTitle = " <<
histTitle << std::endl;
316 auto tmpHs = iBooker.book1D(histName,
histTitle, 40, 0.5, 40.5);
318 tmpHs->setAxisTitle(
xtitle, 1);
319 tmpHs->setAxisTitle(
ytitle, 2);
320 tmpHs->getTH1()->SetOption(
"E1");
321 if (histName.Contains(
"time")) {
324 tmpHs->setAxisTimeDisplay(1);
325 tmpHs->setAxisTimeFormat(
"%H:%M:%S", 1);
326 tmpHs->getTH1()->GetXaxis()->SetTimeOffset(daTime);
330 tmpHs = iBooker.book1D(histName,
histTitle, 40, 0.5, 40.5);
332 tmpHs->getTH1()->SetCanExtend(TH1::kAllAxes);
333 tmpHs->setAxisTitle(
xtitle, 1);
334 tmpHs->setAxisTitle(
ytitle, 2);
335 tmpHs->getTH1()->SetOption(
"E1");
336 if (histName.Contains(
"time")) {
339 tmpHs->setAxisTimeDisplay(1);
340 tmpHs->setAxisTimeFormat(
"%H:%M:%S", 1);
341 tmpHs->getTH1()->GetXaxis()->SetTimeOffset(daTime);
347 assert(0 == strcmp(
hs[k_sigmaY0_time]->getTH1()->GetName(),
"sigmaY0_time"));
348 assert(0 == strcmp(
hs[k_PVz_lumi_all]->getTH1()->GetName(),
"PVz_lumi_all"));
365 h_x0 = iBooker.book1D(
"BeamMonitorFeedBack_x0",
"x coordinate of beam spot (Fit)", 100, -0.01, 0.01);
369 h_y0 = iBooker.book1D(
"BeamMonitorFeedBack_y0",
"y coordinate of beam spot (Fit)", 100, -0.01, 0.01);
373 h_z0 = iBooker.book1D(
"BeamMonitorFeedBack_z0",
"z coordinate of beam spot (Fit)",
dzBin_,
dzMin_,
dzMax_);
377 h_sigmaX0 = iBooker.book1D(
"BeamMonitorFeedBack_sigmaX0",
"sigma x0 of beam spot (Fit)", 100, 0, 0.05);
381 h_sigmaY0 = iBooker.book1D(
"BeamMonitorFeedBack_sigmaY0",
"sigma y0 of beam spot (Fit)", 100, 0, 0.05);
385 h_sigmaZ0 = iBooker.book1D(
"BeamMonitorFeedBack_sigmaZ0",
"sigma z0 of beam spot (Fit)", 100, 0, 10);
390 h_trkPt = iBooker.book1D(
"trkPt",
"p_{T} of all reco'd tracks (no selection)", 200, 0., 50.);
396 cutFlowTable = iBooker.book1D(
"cutFlowTable",
"Cut flow table of track selection", 9, 0, 9);
399 fitResults = iBooker.book2D(
"fitResults",
"Results of previous good beam fit", 2, 0, 2, 8, 0, 8);
414 iBooker.setCurrentFolder(
monitorName_ +
"PrimaryVertex");
416 h_nVtx = iBooker.book1D(
"vtxNbr",
"Reconstructed Vertices(non-fake) in all Event", 60, -0.5, 59.5);
420 h_nVtx_st = iBooker.book1D(
"vtxNbr_SelectedTriggers",
"Reconstructed Vertices(non-fake) in Events", 60, -0.5, 59.5);
424 h_PVx[0] = iBooker.book1D(
"PVX",
"x coordinate of Primary Vtx", 50, -0.01, 0.01);
428 h_PVy[0] = iBooker.book1D(
"PVY",
"y coordinate of Primary Vtx", 50, -0.01, 0.01);
435 h_PVx[1] = iBooker.book1D(
"PVXFit",
"x coordinate of Primary Vtx (Last Fit)", 50, -0.01, 0.01);
439 h_PVy[1] = iBooker.book1D(
"PVYFit",
"y coordinate of Primary Vtx (Last Fit)", 50, -0.01, 0.01);
455 pvResults = iBooker.book2D(
"pvResults",
"Results of fitting Primary Vertices", 2, 0, 2, 6, 0, 6);
475 iBooker.setCurrentFolder(
monitorName_ +
"EventInfo/reportSummaryContents");
479 sprintf(
histo,
"x0_status");
482 sprintf(
histo,
"y0_status");
485 sprintf(
histo,
"z0_status");
498 reportSummaryMap = iBooker.book2D(
"reportSummaryMap",
"Beam Spot Summary Map", 1, 0, 1, 3, 0, 3);
514 const std::time_t ftmptime = fbegintimestamp >> 32;
550 edm::LogInfo(
"FakeBeamMonitor") <<
" beginLuminosityBlock: Size of mapBeginBSLS before = "
558 map<int, std::time_t>::iterator itbstime =
mapBeginBSTime.begin();
559 map<int, std::time_t>::iterator itpvtime =
mapBeginPVTime.begin();
619 edm::LogInfo(
"FakeBeamMonitor") <<
" beginLuminosityBlock:: Next Lumi to Fit: " <<
nextlumi_ << endl;
629 edm::LogInfo(
"FakeBeamMonitor") <<
" beginLuminosityBlock:: Begin of Lumi: " << nthlumi << endl;
634 const int nthlumi =
iEvent.luminosityBlock();
637 edm::LogInfo(
"FakeBeamMonitor") <<
"analyze:: Spilt event from previous lumi section!" << std::endl;
641 edm::LogInfo(
"FakeBeamMonitor") <<
"analyze:: Spilt event from next lumi section!!!" << std::endl;
711 for (
int tmp_idx = 0; tmp_idx < 10; tmp_idx++) {
753 map<int, std::vector<float> >::iterator itpvx =
mapPVx.begin();
754 map<int, std::vector<float> >::iterator itpvy =
mapPVy.begin();
755 map<int, std::vector<float> >::iterator itpvz =
mapPVz.begin();
757 map<int, std::vector<int> >::iterator itbspvinfo =
mapNPV.begin();
774 edm::LogInfo(
"FakeBeamMonitor") <<
"endLuminosityBlock:: Lumi of the last event before endLuminosityBlock: "
780 const std::time_t fendtime = fendtimestamp >> 32;
793 int currentlumi = nextlumi;
794 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill:: Lumi of the current fit: " << currentlumi << endl;
795 lastlumi = currentlumi;
818 bool resetHistoFlag_ =
false;
824 resetHistoFlag_ =
true;
828 int countEvtLastNLS_ = 0;
831 std::map<int, std::vector<int> >::iterator mnpv =
mapNPV.begin();
832 std::map<int, std::vector<float> >::iterator mpv2 =
mapPVy.begin();
833 std::map<int, std::vector<float> >::iterator mpv3 =
mapPVz.begin();
836 ++mpv1, ++mpv2, ++mpv3, ++mnpv) {
837 std::vector<float>::iterator mpvs2 = (mpv2->second).
begin();
838 std::vector<float>::iterator mpvs3 = (mpv3->second).
begin();
839 for (std::vector<float>::iterator mpvs1 = (mpv1->second).begin(); mpvs1 != (mpv1->second).
end();
840 ++mpvs1, ++mpvs2, ++mpvs3) {
841 if (resetHistoFlag_) {
849 for (std::vector<int>::iterator mnpvs = (mnpv->second).begin(); mnpvs != (mnpv->second).
end(); ++mnpvs) {
850 if ((*mnpvs > 0) && (resetHistoFlag_))
853 countTotPV_ += (*mnpvs);
854 if ((*mnpvs) > MaxPVs)
860 char tmpTitlePV[100];
886 countEvtLastNLS_ = 0;
890 const int countLS_bs =
hs[k_x0_lumi]->getTH1()->GetEntries();
891 const int countLS_pv =
hs[k_PVx_lumi]->getTH1()->GetEntries();
892 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill:: countLS_bs = " << countLS_bs <<
" ; countLS_pv = " << countLS_pv
894 int LSgap_bs = currentlumi /
fitNLumi_ - countLS_bs;
895 int LSgap_pv = currentlumi /
fitPVNLumi_ - countLS_pv;
900 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill:: LSgap_bs = " << LSgap_bs <<
" ; LSgap_pv = " << LSgap_pv
903 for (
int ig = 0; ig < LSgap_bs; ig++) {
907 hs[k_sigmaX0_lumi]->ShiftFillLast(0., 0.,
fitNLumi_);
908 hs[k_sigmaY0_lumi]->ShiftFillLast(0., 0.,
fitNLumi_);
909 hs[k_sigmaZ0_lumi]->ShiftFillLast(0., 0.,
fitNLumi_);
912 for (
int ig = 0; ig < LSgap_pv; ig++) {
918 for (
int i = 1;
i < (currentlumi - previousLS);
958 std::unique_ptr<TF1> fgaus{
new TF1(
"fgaus",
"gaus")};
960 fgaus->SetLineColor(4);
962 mean = fgaus->GetParameter(1);
963 width = fgaus->GetParameter(2);
964 meanErr = fgaus->GetParError(1);
965 widthErr = fgaus->GetParError(2);
968 hs[k_PVx_lumi_all]->setBinContent(currentlumi,
mean);
969 hs[k_PVx_lumi_all]->setBinError(currentlumi,
width);
972 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill:: Event time outside current range of time histograms!"
975 hs[k_PVx_time]->setBinContent(nthBin,
mean);
976 hs[k_PVx_time]->setBinError(nthBin,
width);
980 hs[k_PVx_time_all]->setBinContent(jthBin,
mean);
981 hs[k_PVx_time_all]->setBinError(jthBin,
width);
992 tmphisto->GetNbinsX(), tmphisto->GetXaxis()->GetXmin(), tmphisto->GetXaxis()->GetXmax());
999 mean = fgaus->GetParameter(1);
1000 width = fgaus->GetParameter(2);
1001 meanErr = fgaus->GetParError(1);
1002 widthErr = fgaus->GetParError(2);
1004 hs[k_PVy_lumi_all]->setBinContent(currentlumi,
mean);
1005 hs[k_PVy_lumi_all]->setBinError(currentlumi,
width);
1007 hs[k_PVy_time]->setBinContent(nthBin,
mean);
1008 hs[k_PVy_time]->setBinError(nthBin,
width);
1011 hs[k_PVy_time_all]->setBinContent(jthBin,
mean);
1012 hs[k_PVy_time_all]->setBinError(jthBin,
width);
1022 tmphisto->GetNbinsX(), tmphisto->GetXaxis()->GetXmin(), tmphisto->GetXaxis()->GetXmax());
1029 mean = fgaus->GetParameter(1);
1030 width = fgaus->GetParameter(2);
1031 meanErr = fgaus->GetParError(1);
1032 widthErr = fgaus->GetParError(2);
1034 hs[k_PVz_lumi_all]->setBinContent(currentlumi,
mean);
1035 hs[k_PVz_lumi_all]->setBinError(currentlumi,
width);
1037 hs[k_PVz_time]->setBinContent(nthBin,
mean);
1038 hs[k_PVz_time]->setBinError(nthBin,
width);
1041 hs[k_PVz_time_all]->setBinContent(jthBin,
mean);
1042 hs[k_PVz_time_all]->setBinError(jthBin,
width);
1052 tmphisto->GetNbinsX(), tmphisto->GetXaxis()->GetXmin(), tmphisto->GetXaxis()->GetXmax());
1068 size_t PreviousRecords = 0;
1177 <<
"; address = " << &
refBStime[0] << std::endl;
1179 <<
"; address = " << &
refBStime[1] << std::endl;
1200 for (
int j = 0;
j < 7; ++
j) {
1201 for (
int k =
j;
k < 7; ++
k) {
1207 float tmp_BSx =
rndm_->Gaus(0.1, 0.1);
1208 float tmp_BSy =
rndm_->Gaus(0.1, 0.1);
1209 float tmp_BSz =
rndm_->Gaus(0.1, 0.1);
1210 float tmp_BSwidthX =
rndm_->Gaus(0.001, 0.0005);
1211 float tmp_BSwidthY =
rndm_->Gaus(0.001, 0.0005);
1212 float tmp_BSwidthZ =
rndm_->Gaus(3.5, 0.5);
1221 bs.setBeamWidthY(tmp_BSwidthY);
1226 edm::LogInfo(
"FakeBeamMonitor") <<
"\n RESULTS OF DEFAULT FIT:" << endl;
1228 edm::LogInfo(
"FakeBeamMonitor") <<
"[BeamFitter] fitting done \n" << endl;
1233 hs[k_sigmaX0_lumi]->ShiftFillLast(
bs.BeamWidthX(),
bs.BeamWidthXError(),
fitNLumi_);
1234 hs[k_sigmaY0_lumi]->ShiftFillLast(
bs.BeamWidthY(),
bs.BeamWidthYError(),
fitNLumi_);
1235 hs[k_sigmaZ0_lumi]->ShiftFillLast(
bs.sigmaZ(),
bs.sigmaZ0Error(),
fitNLumi_);
1236 hs[k_x0_lumi_all]->setBinContent(currentlumi,
bs.x0());
1237 hs[k_x0_lumi_all]->setBinError(currentlumi,
bs.x0Error());
1238 hs[k_y0_lumi_all]->setBinContent(currentlumi,
bs.y0());
1239 hs[k_y0_lumi_all]->setBinError(currentlumi,
bs.y0Error());
1240 hs[k_z0_lumi_all]->setBinContent(currentlumi,
bs.z0());
1241 hs[k_z0_lumi_all]->setBinError(currentlumi,
bs.z0Error());
1242 hs[k_sigmaX0_lumi_all]->setBinContent(currentlumi,
bs.BeamWidthX());
1243 hs[k_sigmaX0_lumi_all]->setBinError(currentlumi,
bs.BeamWidthXError());
1244 hs[k_sigmaY0_lumi_all]->setBinContent(currentlumi,
bs.BeamWidthY());
1245 hs[k_sigmaY0_lumi_all]->setBinError(currentlumi,
bs.BeamWidthYError());
1246 hs[k_sigmaZ0_lumi_all]->setBinContent(currentlumi,
bs.sigmaZ());
1247 hs[k_sigmaZ0_lumi_all]->setBinError(currentlumi,
bs.sigmaZ0Error());
1251 hs[k_x0_time]->setBinContent(nthBin,
bs.x0());
1252 hs[k_y0_time]->setBinContent(nthBin,
bs.y0());
1253 hs[k_z0_time]->setBinContent(nthBin,
bs.z0());
1254 hs[k_sigmaX0_time]->setBinContent(nthBin,
bs.BeamWidthX());
1255 hs[k_sigmaY0_time]->setBinContent(nthBin,
bs.BeamWidthY());
1256 hs[k_sigmaZ0_time]->setBinContent(nthBin,
bs.sigmaZ());
1257 hs[k_x0_time]->setBinError(nthBin,
bs.x0Error());
1258 hs[k_y0_time]->setBinError(nthBin,
bs.y0Error());
1259 hs[k_z0_time]->setBinError(nthBin,
bs.z0Error());
1260 hs[k_sigmaX0_time]->setBinError(nthBin,
bs.BeamWidthXError());
1261 hs[k_sigmaY0_time]->setBinError(nthBin,
bs.BeamWidthYError());
1262 hs[k_sigmaZ0_time]->setBinError(nthBin,
bs.sigmaZ0Error());
1267 hs[k_x0_time_all]->setBinContent(jthBin,
bs.x0());
1268 hs[k_y0_time_all]->setBinContent(jthBin,
bs.y0());
1269 hs[k_z0_time_all]->setBinContent(jthBin,
bs.z0());
1270 hs[k_sigmaX0_time_all]->setBinContent(jthBin,
bs.BeamWidthX());
1271 hs[k_sigmaY0_time_all]->setBinContent(jthBin,
bs.BeamWidthY());
1272 hs[k_sigmaZ0_time_all]->setBinContent(jthBin,
bs.sigmaZ());
1273 hs[k_x0_time_all]->setBinError(jthBin,
bs.x0Error());
1274 hs[k_y0_time_all]->setBinError(jthBin,
bs.y0Error());
1275 hs[k_z0_time_all]->setBinError(jthBin,
bs.z0Error());
1276 hs[k_sigmaX0_time_all]->setBinError(jthBin,
bs.BeamWidthXError());
1277 hs[k_sigmaY0_time_all]->setBinError(jthBin,
bs.BeamWidthYError());
1278 hs[k_sigmaZ0_time_all]->setBinError(jthBin,
bs.sigmaZ0Error());
1284 if (
bs.type() > 0) {
1292 double alpha = std::atan2(
bs.y0(),
bs.x0());
1293 std::unique_ptr<TF1>
f1{
new TF1(
"f1",
"[0]*sin(x-[1])", -3.14, 3.14)};
1294 f1->SetParameters(amp,
alpha);
1295 f1->SetParLimits(0, amp - 0.1, amp + 0.1);
1297 f1->SetLineColor(4);
1302 std::unique_ptr<TF1> fgaus{
new TF1(
"fgaus",
"gaus")};
1304 fgaus->SetLineColor(4);
1311 sprintf(tmpTitle,
"%s %i %s %i",
"Fitted Beam Spot (cm) of LS: ", LSRange.first,
" to ", LSRange.second);
1319 if (
bs.type() > 0) {
1333 if (
bs.type() > 0) {
1369 for (
int i = 0;
i < 7; ++
i) {
1370 for (
int j = 0;
j < 7; ++
j) {
1379 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill::[PayloadCreation] BeamSpotOnline object created: \n" << std::endl;
1380 edm::LogInfo(
"FakeBeamMonitor") << *BSOnline << std::endl;
1386 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill::[PayloadCreation] onlineDbService available \n" << std::endl;
1390 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill::[PayloadCreation] BeamSpotOnline payload created \n" << std::endl;
1451 edm::LogInfo(
"FakeBeamMonitor") <<
"FitAndFill:: The flag is ON for running average Beam Spot fit" << endl;
1465 <<
" RestartingFitting:: Restart Beami everything to a fresh start !!! because Gap is > 10 LS" << endl;
1502 edm::LogInfo(
"FakeBeamMonitor") <<
"dqmEndRun:: Clearing all the Maps " << endl;
1519 char offsetTime[64];
1521 TDatime
da(offsetTime);
1526 h->GetXaxis()->SetTimeOffset(
da.Convert(kTRUE));
1529 h->SetBinError(
bin, valErr);
1532 h->GetXaxis()->SetTimeOffset(
da.Convert(kTRUE));
1539 bool scroll_ =
false;
1542 edm::LogInfo(
"FakeBeamMonitor") <<
"testScroll:: Reset Time Offset" << std::endl;
1545 if (
hs[k_x0_time]->getBinContent(
bin) > 0) {
1552 edm::LogInfo(
"FakeBeamMonitor") <<
"testScroll:: Time difference too large since last readout" << std::endl;
1556 edm::LogInfo(
"FakeBeamMonitor") <<
"testScroll:: Offset to last record" << std::endl;