Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: +1 for L1 latency and trigger class check improved #13682

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 89 additions & 35 deletions Detectors/CTP/macro/PlotPbLumi.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,56 @@
#include "CCDB/BasicCCDBManager.h"
#include "DataFormatsCTP/Scalers.h"
#include "DataFormatsCTP/Configuration.h"
#include <DataFormatsParameters/GRPLHCIFData.h>
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TCanvas.h"
#include "TMath.h"
#include "TStyle.h"
#include "TF1.h"
#include <string>
#include <map>
#include <iostream>
#endif
using namespace o2::ctp;
void PlotPbLumi(int runNumber, int fillN, std::string ccdbHost = "http://ccdb-test.cern.ch:8080")
{ //
// what = 1: znc rate
// what = 2: (TCE+TSC)/ZNC
// what = 3: TCE/ZNC
using namespace std::chrono;
//
// if fillN = 0: pileup correction not done
// QCDB =1 : use for ongoing run
//
void PlotPbLumi(int runNumber, int fillN = 0, int QCDB = 0, std::string ccdbHost = "http://alice-ccdb.cern.ch")
{ // "http://ccdb-test.cern.ch:8080"
std::string mCCDBPathCTPScalers = "CTP/Calib/Scalers";
std::string mQCDBPathCTPScalers = "qc/CTP/Scalers";
std::string mCCDBPathCTPConfig = "CTP/Config/Config";
auto& ccdbMgr = o2::ccdb::BasicCCDBManager::instance();
ccdbMgr.setURL(ccdbHost);
// Timestamp
auto soreor = ccdbMgr.getRunDuration(runNumber);
uint64_t timeStamp = (soreor.second - soreor.first) / 2 + soreor.first;
std::cout << "Timestamp:" << timeStamp << std::endl;
// Filling
std::string sfill = std::to_string(fillN);
std::map<string, string> metadata;
metadata["fillNumber"] = sfill;
auto lhcifdata = ccdbMgr.getSpecific<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", timeStamp, metadata);
auto bfilling = lhcifdata->getBunchFilling();
std::vector<int> bcs = bfilling.getFilledBCs();
int nbc = bcs.size();
std::cout << "Number of interacting bc:" << nbc << std::endl;
int nbc = 0;
if (fillN) {
std::string sfill = std::to_string(fillN);
metadata["fillNumber"] = sfill;
auto lhcifdata = ccdbMgr.getSpecific<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", timeStamp, metadata);
auto bfilling = lhcifdata->getBunchFilling();
std::vector<int> bcs = bfilling.getFilledBCs();
nbc = bcs.size();
std::cout << "Number of interacting bc:" << nbc << std::endl;
}
if (QCDB) { // use this option for ongoing run
mCCDBPathCTPScalers = mQCDBPathCTPScalers;
ccdbMgr.setURL("http://ccdb-test.cern.ch:8080");
timeStamp = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
std::cout << "For scalers using Current time:" << timeStamp << std::endl;
}
// Scalers
std::string srun = std::to_string(runNumber);
metadata.clear(); // can be empty
metadata["runNumber"] = srun;
ccdbMgr.setURL("http://ccdb-test.cern.ch:8080");
auto scl = ccdbMgr.getSpecific<CTPRunScalers>(mCCDBPathCTPScalers, timeStamp, metadata);
if (scl == nullptr) {
LOG(info) << "CTPRunScalers not in database, timestamp:" << timeStamp;
Expand Down Expand Up @@ -105,48 +124,72 @@ void PlotPbLumi(int runNumber, int fillN, std::string ccdbHost = "http://ccdb-te
return;
}
//
// Anal
//
// Times
double_t frev = 11245;
double_t time0 = recs[0].epochTime;
double_t timeL = recs[recs.size() - 1].epochTime;
double_t Trun = timeL - time0;
double_t orbit0 = recs[0].intRecord.orbit;
int n = recs.size() - 1;
if (runNumber == 559143) {
n = 400;
}
if (runNumber == 559561) {
n = n - 3; // rate drops at the end
}
if (runNumber == 559575) {
n = n - 6;
}
if (runNumber == 559617) {
n = n - 5;
}
if (runNumber == 559632) {
n = n - 6;
}
std::cout << " Run duration:" << Trun << " Scalers size:" << n + 1 << std::endl;
Double_t x[n], znc[n], zncpp[n];
Double_t x[n], znc[n], zncpp[n], ex[n], eznc[n];
Double_t tcetsctoznc[n], tcetoznc[n], vchtoznc[n];
Double_t etcetsctoznc[n], etcetoznc[n], evchtoznc[n];

for (int i = 0; i < n; i++) {
ex[i] = 0;
x[i] = (double_t)(recs[i + 1].intRecord.orbit + recs[i].intRecord.orbit) / 2. - orbit0;
x[i] *= 88e-6;
// x[i] = (double_t)(recs[i+1].epochTime + recs[i].epochTime)/2.;
double_t tt = (double_t)(recs[i + 1].intRecord.orbit - recs[i].intRecord.orbit);
tt = tt * 88e-6;
//
// std::cout << recs[i+1].scalersInps[25] << std::endl;
double_t znci = (double_t)(recs[i + 1].scalersInps[25] - recs[i].scalersInps[25]);
double_t mu = -TMath::Log(1. - znci / tt / nbc / frev);
double_t zncipp = mu * nbc * frev;
double_t zncipp = znci;
double_t mu = 0;
if (fillN) {
mu = -TMath::Log(1. - znci / tt / nbc / frev);
zncipp = mu * nbc * frev * tt;
}
zncpp[i] = zncipp / 28.;
znc[i] = znci / 28. / tt;
//
auto had = recs[i + 1].scalers[tce].lmBefore - recs[i].scalers[tce].lmBefore;
// std::cout << recs[i+1].scalers[tce].lmBefore << std::endl;
had += recs[i + 1].scalers[tsc].lmBefore - recs[i].scalers[tsc].lmBefore;
// rat = (double_t)(had)/double_t(recs[i+1].scalersInps[25] - recs[i].scalersInps[25])*28;
tcetsctoznc[i] = (double_t)(had) / zncpp[i] / tt;
had = recs[i + 1].scalers[tce].lmBefore - recs[i].scalers[tce].lmBefore;
// rat = (double_t)(had)/double_t(recs[i+1].scalersInps[25] - recs[i].scalersInps[25])*28;
tcetoznc[i] = (double_t)(had) / zncpp[i] / tt;
had = recs[i + 1].scalers[vch].lmBefore - recs[i].scalers[vch].lmBefore;
// rat = (double_t)(had)/double_t(recs[i+1].scalersInps[25] - recs[i].scalersInps[25])*28;
vchtoznc[i] = (double_t)(had) / zncpp[i] / tt;
znc[i] = zncipp / 28. / tt;
eznc[i] = TMath::Sqrt(zncipp) / 28. / tt;
if (1) {
//
auto had = recs[i + 1].scalers[tsc].lmBefore - recs[i].scalers[tsc].lmBefore;
had += recs[i + 1].scalers[tce].lmBefore - recs[i].scalers[tce].lmBefore;
tcetsctoznc[i] = (double_t)(had) / zncpp[i];
etcetsctoznc[i] = TMath::Sqrt(tcetsctoznc[i] * (1 - tcetsctoznc[i]) / zncpp[i]);
had = recs[i + 1].scalers[tce].lmBefore - recs[i].scalers[tce].lmBefore;
double_t tcec = had;
tcetoznc[i] = (double_t)(had) / zncpp[i];
had = recs[i + 1].scalers[vch].lmBefore - recs[i].scalers[vch].lmBefore;
vchtoznc[i] = (double_t)(had) / zncpp[i];
// std::cout << "mu:" << mu << " zncpp corr:" << zncipp << " zncraw:" << znci << " tce:" << tcec << " tce/had" << tcec/zncpp[i] << std::endl;
}
}
//
TFile myfile("file.root", "RECREATE");
gStyle->SetMarkerSize(0.5);
TGraph* gr1 = new TGraph(n, x, znc);
// TGraph* gr1 = new TGraph(n, x, znc);
TGraphErrors* gr1 = new TGraphErrors(n, x, znc, ex, eznc);
TGraph* gr2 = new TGraph(n, x, tcetsctoznc);
// TGraphErrors* gr2 = new TGraphErrors(n, x, tcetsctoznc, ex, etcetsctoznc); // nom and denom are strongly correlated
TGraph* gr3 = new TGraph(n, x, tcetoznc);
TGraph* gr4 = new TGraph(n, x, vchtoznc);
gr1->SetMarkerStyle(20);
Expand All @@ -155,28 +198,39 @@ void PlotPbLumi(int runNumber, int fillN, std::string ccdbHost = "http://ccdb-te
gr4->SetMarkerStyle(23);
gr1->SetTitle("R=ZNC/28 rate [Hz]; time[sec]; R");
gr2->SetTitle("R=(TSC+TCE)*TVTX*B*28/ZNC; time[sec]; R");
// gr2->GetHistogram()->SetMaximum(1.1);
// gr2->GetHistogram()->SetMinimum(0.9);
// gr2->SetTitle("R=TSC*TVTX*B*28/ZNC; time[sec]; R");
// gr2->GetHistogram()->SetMaximum(1.1);
// gr2->GetHistogram()->SetMinimum(0.9);
gr3->SetTitle("R=(TCE)*TVTX*B*28/ZNC; time[sec]; R");
// gr3->GetHistogram()->SetMaximum(0.6);
// gr3->GetHistogram()->SetMinimum(0.4);
gr4->SetTitle("R=(VCH)*TVTX*B*28/ZNC; time[sec]; R");
// gr4->GetHistogram()->SetMaximum(0.6);
// gr4->GetHistogram()->SetMinimum(0.4);
TCanvas* c1 = new TCanvas("c1", srun.c_str(), 200, 10, 800, 500);
TF1* fun = new TF1("poly0", "[0]+x*[1]");
c1->Divide(2, 2);
c1->cd(1);
gr1->Draw("AP");
c1->cd(2);
fun->SetParameter(0, 1);
gr2->Fit("poly0", "FM");
gr2->Draw("AP");
c1->cd(3);
fun->SetParameter(0, 0.5);
gr3->Fit("poly0");
gr3->Draw("AP");
c1->cd(4);
gr4->Fit("poly0");
gr4->Draw("AP");
// getRate test:
double tt = timeStamp / 1000.;
std::pair<double, double> r1 = scl->getRateGivenT(tt, 25, 7);
std::cout << "ZDC input getRateGivetT:" << r1.first / 28. << " " << r1.second / 28. << std::endl;
std::pair<double, double> r2 = scl->getRateGivenT(tt, tce, 1);
std::cout << "LM before TCE class getRateGivetT:" << r2.first << " " << r2.second << std::endl;
gr1->Write();
gr2->Write();
gr3->Write();
gr4->Write();
}
19 changes: 12 additions & 7 deletions Detectors/CTP/macro/TestConfig.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
#include <CCDB/BasicCCDBManager.h>
#include <DataFormatsCTP/Configuration.h>
#include "CTPWorkflowScalers/ctpCCDBManager.h"
#include "Framework/Logger.h"
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lietava could you add

#include "Framework/Logger.h"

after(!) the the #endif to pass macro test in the interpreter mode?

using namespace o2::ctp;

void TestConfig(bool test = 0)
void TestConfig(bool test = 1)
{
if (test == 0) {
return;
}
uint64_t timestamp = 1660196771632;
std::string run = "523148";
uint64_t timestamp = 1660276134898 + 10000;
std::string run = "523186";
o2::ctp::ctpCCDBManager::setCCDBHost("https://alice-ccdb.cern.ch");
bool ok;
auto ctpcfg = o2::ctp::ctpCCDBManager::getConfigFromCCDB(timestamp, run, ok);
Expand All @@ -31,13 +32,17 @@ void TestConfig(bool test = 0)
}
CTPConfiguration ctpconfig;
ctpconfig.loadConfigurationRun3(ctpcfg.getConfigString());
// ctpconfig.printStream(std::cout);
// return;
// ctpconfig.assignDescriptors();
// ctpconfig.createInputsInDecriptorsFromNames();
ctpconfig.printStream(std::cout);
auto& triggerclasses = ctpconfig.getCTPClasses();
std::cout << "Found " << triggerclasses.size() << " trigger classes" << std::endl;
for (const auto& trg : triggerclasses) {
if (trg.cluster->maskCluster[o2::detectors::DetID::EMC]) {
// Class triggering EMCAL cluster
LOG(info) << "Found trigger class for EMCAL cluster: " << trg.name << " with input mask " << std::bitset<64>(trg.descriptor->getInputsMask());
trg.descriptor->getInputsMask();
}
}
return;
int indexInList = 0;
for (const auto& trgclass : triggerclasses) {
uint64_t inputmask = 0;
Expand Down
6 changes: 4 additions & 2 deletions Detectors/CTP/macro/TestFetcher.C
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#endif
using namespace o2::ctp;

void TestFetcher(int runNumber = 557251)
void TestFetcher(int runNumber = 559456)
{
auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
std::pair<int64_t, int64_t> pp = ccdb.getRunDuration(runNumber);
Expand All @@ -25,7 +25,9 @@ void TestFetcher(int runNumber = 557251)
// Opening run
CTPRateFetcher fetcher;
fetcher.setupRun(runNumber, &ccdb, ts, 0);
ccdb.setURL("http://ali-qcdb-gpn.cern.ch:8083/");
// ccdb.setURL("http://ali-qcdb-gpn.cern.ch:8083/");
ccdb.setURL("http://ccdb-test.cern.ch:8080/");

std::string QCDBPathCTPScalers = "qc/CTP/Scalers";
map<string, string> metadata; // can be empty
std::string run = std::to_string(runNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "DetectorsBase/CTFCoderBase.h"
#include "CTPReconstruction/CTFHelper.h"
#include "CTPReconstruction/RawDataDecoder.h"
#include "DataFormatsCTP/Configuration.h"

class TTree;

Expand Down Expand Up @@ -53,6 +54,8 @@ class CTFCoder : public o2::ctf::CTFCoderBase

void createCoders(const std::vector<char>& bufVec, o2::ctf::CTFCoderBase::OpType op) final;
void setDecodeInps(bool decodeinps) { mDecodeInps = decodeinps; }
void setCTPConfig(CTPConfiguration cfg) { mCTPConfig = std::move(cfg); }
bool getDecodeInps() { return mDecodeInps; }
bool canApplyBCShiftInputs(const o2::InteractionRecord& ir) const { return canApplyBCShift(ir, mBCShiftInputs); }

private:
Expand All @@ -62,6 +65,7 @@ class CTFCoder : public o2::ctf::CTFCoderBase
void appendToTree(TTree& tree, CTF& ec);
void readFromTree(TTree& tree, int entry, std::vector<CTPDigit>& data, LumiInfo& lumi);
std::vector<CTPDigit> mDataFilt;
CTPConfiguration mCTPConfig;
int mBCShiftInputs = 0;
bool mDecodeInps = false;
};
Expand Down Expand Up @@ -215,8 +219,13 @@ o2::ctf::CTFIOSize CTFCoder::decode(const CTF::base& ec, VTRG& data, LumiInfo& l
}
}
if (mDecodeInps) {
uint64_t trgclassmask = 0xffffffffffffffff;
if (mCTPConfig.getRunNumber() != 0) {
trgclassmask = mCTPConfig.getTriggerClassMask();
}
std::cout << "trgclassmask:" << std::hex << trgclassmask << std::dec << std::endl;
o2::pmr::vector<CTPDigit> digits;
o2::ctp::RawDataDecoder::shiftInputs(digitsMap, digits, mFirstTFOrbit);
o2::ctp::RawDataDecoder::shiftInputs(digitsMap, digits, mFirstTFOrbit, trgclassmask);
for (auto const& dig : digits) {
data.emplace_back(dig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Framework/InputRecord.h"
#include "DataFormatsCTP/Digits.h"
#include "DataFormatsCTP/LumiInfo.h"
#include "DataFormatsCTP/Configuration.h"

namespace o2
{
Expand All @@ -43,14 +44,15 @@ class RawDataDecoder
void setVerbose(bool v) { mVerbose = v; }
void setMAXErrors(int m) { mErrorMax = m; }
int setLumiInp(int lumiinp, std::string inp);
void setCTPConfig(CTPConfiguration cfg) { mCTPConfig = std::move(cfg); };
uint32_t getIRRejected() const { return mIRRejected; }
uint32_t getTCRRejected() const { return mTCRRejected; }
std::vector<uint32_t>& getTFOrbits() { return mTFOrbits; }
int getErrorIR() { return mErrorIR; }
int getErrorTCR() { return mErrorTCR; }
int init();
static int shiftNew(const o2::InteractionRecord& irin, uint32_t TFOrbit, std::bitset<48>& inpmask, int64_t shift, int level, std::map<o2::InteractionRecord, CTPDigit>& digmap);
static int shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit);
static int shiftInputs(std::map<o2::InteractionRecord, CTPDigit>& digitsMap, o2::pmr::vector<CTPDigit>& digits, uint32_t TFOrbit, uint64_t trgclassmask = 0xffffffffffffffff);

private:
static constexpr uint32_t TF_TRIGGERTYPE_MASK = 0x800;
Expand Down Expand Up @@ -79,6 +81,7 @@ class RawDataDecoder
int mErrorTCR = 0;
int mErrorMax = 3;
bool mStickyError = false;
CTPConfiguration mCTPConfig;
};
} // namespace ctp
} // namespace o2
Expand Down
Loading
Loading