22#define MAX_NUM_EVENT_AUTODETECT 10000
28std::vector<int> Utils::mFillScheme;
30int Utils::mNautodet = 0;
32bool Utils::mIsInit =
false;
37int Utils::mNCalibTracks = 0;
39int Utils::mNsample = 0;
40int Utils::mIsample = 0;
41float Utils::mPhases[100];
42uint64_t Utils::mMaskBC[16] = {};
43uint64_t Utils::mMaskBCUsed[16] = {};
46TChain* Utils::mTreeFit =
nullptr;
47std::vector<o2::dataformats::CalibInfoTOF> Utils::mVectC;
48std::vector<o2::dataformats::CalibInfoTOF>* Utils::mPvectC = &mVectC;
50uint32_t Utils::mNOrbitInTF = 128;
54 if (fromCollisonCotext) {
63 mFillScheme.push_back(
bc);
78 if (mNCalibTracks >= NTRACKS_REQUESTED) {
86 static std::vector<o2::dataformats::CalibInfoTOF> tracks;
88 for (
int i = 0;
i < NTRACKS_REQUESTED;
i++) {
89 tracks.push_back(mCalibTracks[
i]);
92 auto evtime = evTimeMaker<std::vector<o2::dataformats::CalibInfoTOF>,
o2::dataformats::CalibInfoTOF, filterCalib<o2::dataformats::CalibInfoTOF>>(tracks, 6.0f,
true);
94 if (evtime.mEventTimeError < 100) {
95 mPhases[mIsample] = evtime.mEventTime;
96 mIsample = (mIsample + 1) % 100;
103 for (
int i = 0;
i < mNsample;
i++) {
111 printf(
"FILL SCHEME\n");
119 return mFillScheme.size();
140 int dbcSigned = 1000;
143 if (deltaCBC >= -8 && deltaCBC < 8) {
144 mask += (1 << (deltaCBC + 8));
146 if (std::abs(deltaCBC) < dbc) {
148 dbcSigned = deltaCBC;
149 dbc = std::abs(dbcSigned);
154 dbc = std::abs(dbcSigned);
159 dbc = std::abs(dbcSigned);
162 if (dbcSigned >= -8 && dbcSigned < 8) {
163 mask += (1 << (dbcSigned + 24));
189 int dbcSigned = 1000;
192 if (deltaCBC >= -8 && deltaCBC < 8) {
193 mask += (1 << (deltaCBC + 8));
195 if (std::abs(deltaCBC) < dbc) {
197 dbcSigned = deltaCBC;
198 dbc = std::abs(dbcSigned);
203 dbc = std::abs(dbcSigned);
208 dbc = std::abs(dbcSigned);
211 if (dbcSigned >= -8 && dbcSigned < 8) {
212 mask += (1 << (dbcSigned + 24));
229 int thres = mMaxBC / 2;
231 if (mBCmult[
i] > thres) {
255 if (mBCmult[
bc] > mMaxBC) {
256 mMaxBC = mBCmult[
bc];
272 int mask2 = (
mask >> 16);
277 for (
int ibit = 0; ibit < 16; ibit++) {
289 for (
int ibit = 0; ibit < 16; ibit++) {
291 mMaskBCchan[channel][ibit] +=
weight;
295 mMaskBCchanUsed[channel][ibit] +=
weight;
296 mMaskBCUsed[ibit] +=
weight;
308 for (
int ibit = 0; ibit < 16; ibit++) {
309 if (mMaskBC[ibit] >
val) {
321 for (
int ibit = 0; ibit < 16; ibit++) {
322 if (mMaskBCchan[channel][ibit] >
val) {
323 val = mMaskBCchan[channel][ibit];
332 if (!oldTS || !newTS) {
337 static auto fitFunc =
new TF1(
"fTOFfit",
"gaus", -5000, 5000);
339 fitFunc->SetParameter(0, 100);
340 fitFunc->SetParameter(1, 0);
341 fitFunc->SetParameter(2, 200);
347 mTreeFit =
new TChain(
"treeCollectedCalibInfo",
"treeCollectedCalibInfo");
349 auto retval = system(
"ls *collTOF*.root >listaCal");
351 FILE*
f = fopen(
"listaCal",
"r");
358 while (fscanf(
f,
"%s", namefile) == 1) {
359 mTreeFit->AddFile(namefile);
362 if (!mTreeFit->GetEntries()) {
366 mTreeFit->SetBranchAddress(
"TOFCollectedCalibInfo", &mPvectC);
368 for (
int isec = 0; isec < 18; isec++) {
378 for (
int i = sector * nchPerSect;
i < (sector + 1) * nchPerSect;
i += NCHPERBUNCH) {
386 TH2F*
h[NCHPERBUNCH];
389 int bcSel[NCHPERBUNCH];
391 for (
int ii = 0; ii < NCHPERBUNCH; ii++) {
392 h[ii] =
new TH2F(Form(
"h%d", chStart + ii),
"", 1000, 0, 100, 100, -5000, 5000);
396 for (
int i = chStart;
i + NCHPERBUNCH < mTreeFit->GetEntries();
i += 157248) {
397 for (
int ii = 0; ii < NCHPERBUNCH; ii++) {
398 int ch = chStart + ii;
399 mTreeFit->GetEvent(
i + ii);
402 for (
auto& obj : mVectC) {
403 if (obj.getTOFChIndex() != ch || skip) {
406 time = obj.getDeltaTimePi();
408 mask = obj.getMask();
410 if (time < -5000 || time > 20000) {
414 if (tscorr < -1000000 || tscorr > 1000000) {
420 if (bcSel[ii] > -9000) {
425 while (
time < -5000) {
429 while (
time > 20000) {
437 }
else if (
time < -12500) {
441 h[ii]->Fill(tot,
time);
446 for (
int ii = 0; ii < NCHPERBUNCH; ii++) {
458 int sec = ch / nchPerSect;
459 int chInSec = ch % nchPerSect;
462 int nbinPrev = istop - istart;
465 unsigned short oldtot[10000];
466 short oldcorr[10000];
467 unsigned short newtot[10000];
468 short newcorr[10000];
472 const std::vector<std::pair<unsigned short, short>>& vect = oldTS->
getVector(sec);
473 for (
int i = istart;
i < istop;
i++) {
474 oldtot[
count] = vect[
i].first;
475 oldcorr[
count] = vect[
i].second;
479 TH1D* hpro =
h->ProjectionX(
"hpro");
482 int nbin =
h->GetXaxis()->GetNbins();
483 float integralToEnd =
h->Integral();
501 if (integralToEnd < NMINTOFIT) {
512 float totHalfWidth =
h->GetXaxis()->GetBinWidth(1) * 0.5;
514 static TF1* fitFunc =
new TF1(
"fTOFfit",
"gaus", -5000, 5000);
517 float x[10000],
y[10000];
518 for (
int i = 1;
i <= nbin;
i++) {
519 integral += hpro->GetBinContent(
i);
520 integralToEnd -= hpro->GetBinContent(
i);
522 if (integral < NMINTOFIT || (integralToEnd < NMINTOFIT &&
i < nbin)) {
527 float xmin =
h->GetXaxis()->GetBinCenter(ibin) - totHalfWidth;
528 float xmax =
h->GetXaxis()->GetBinCenter(
i) + totHalfWidth;
529 TH1D* hfit =
h->ProjectionY(Form(
"mypro"), ibin,
i);
530 float xref = hfit->GetBinCenter(hfit->GetMaximumBin());
532 hfit->Fit(fitFunc,
"QN0",
"", xref - 500, xref + 500);
535 x[np] = (xmin + xmax) * 0.5;
536 y[np] = fitFunc->GetParameter(1);
537 if (
x[np] > 65.534) {
540 newtot[np] =
x[np] * 1000;
#define MAX_NUM_EVENT_AUTODETECT
Class for time synchronization of RawReader instances.
static constexpr Int_t NSECTORS
static constexpr Double_t BC_TIME_INPS
static constexpr Double_t BC_TIME_INPS_INV
static constexpr Int_t LATENCYWINDOW_IN_BC
static constexpr Int_t LATENCY_ADJ_LHC_IN_BC
static constexpr int NCHANNELS
static constexpr int BC_IN_ORBIT
static double subtractInteractionBC(double time, int &mask, bool subLatency=false)
static void fitTimeSlewing(int sector, const dataformats::CalibTimeSlewingParamTOF *oldTS, dataformats::CalibTimeSlewingParamTOF *newTS)
static void addBC(float toftime, bool subLatency=false)
static int extractNewTimeSlewing(const dataformats::CalibTimeSlewingParamTOF *oldTS, dataformats::CalibTimeSlewingParamTOF *newTS)
static void addCalibTrack(float time)
static int addMaskBC(int mask, int channel)
static void addInteractionBC(int bc, bool fromCollisonCotext=false)
static void fitChannelsTS(int chStart, const dataformats::CalibTimeSlewingParamTOF *oldTS, dataformats::CalibTimeSlewingParamTOF *newTS)
static void computeLHCphase()
static int getMaxUsedChannel(int channel)
static int getNinteractionBC()
static float mEventTimeSpread
static void printFillScheme()
static bool hasFillScheme()
static int getInteractionBC(int ibc)
static int fitSingleChannel(int ch, TH2F *h, const dataformats::CalibTimeSlewingParamTOF *oldTS, dataformats::CalibTimeSlewingParamTOF *newTS)
GLuint GLuint GLfloat weight
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
constexpr int LHCMaxBunches