Skip to content

Commit 4af77ef

Browse files
TPC vdrift for 22c, d, e, f should be taken using a dedicated macro also in generalized script
1 parent dcdaf0b commit 4af77ef

2 files changed

Lines changed: 98 additions & 5 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <cmath>
2+
#include <fmt/format.h>
3+
#include <string_view>
4+
#include <fstream>
5+
6+
#include "TSystem.h"
7+
8+
#include "CCDB/CcdbApi.h"
9+
#include "DataFormatsTPC/LtrCalibData.h"
10+
#include "TPCBase/ParameterGas.h"
11+
#include <TJAlienCredentials.h>
12+
13+
float getTPCvdrift(int run, std::string_view ltrUrl = "http://alice-ccdb.cern.ch")
14+
{
15+
o2::ccdb::CcdbApi c;
16+
c.init("http://alice-ccdb.cern.ch");
17+
std::map<std::string, std::string> headers, metadataRCT, metadata, mm;
18+
headers = c.retrieveHeaders(fmt::format("RCT/Info/RunInformation/{}", run), metadataRCT, -1);
19+
printf("\nLooking for vdrift for run %d\n", run);
20+
const auto sor = std::stol(headers["SOR"].data());
21+
22+
const auto defaultDriftV = o2::tpc::ParameterGas::Instance().DriftV;
23+
24+
std::string_view calibType = "TPC/Calib/LaserTracks";
25+
//
26+
// query present run up to +-3days
27+
const auto queryInterval = 3l * 24l * 60l * 60l * 1000l;
28+
TJAlienCredentials* cred = new TJAlienCredentials();
29+
cred->loadCredentials();
30+
cred->selectPreferedCredentials();
31+
CredentialsKind cmk = cred->getPreferedCredentials();
32+
TJAlienCredentialsObject cmo = cred->get(cmk);
33+
34+
35+
const auto queryString = fmt::format("curl --cert {} --key {} --insecure -H \"If-Not-Before: {}\" -H \"If-Not-After: {}\" -H \"Accept: application/json\" {}/browse/{}", cmo.certpath.c_str(), cmo.keypath.c_str(), sor - queryInterval, sor + queryInterval, ltrUrl.data(), calibType.data());
36+
fmt::print("Query: {}\n", queryString);
37+
const auto queryResultTString = gSystem->GetFromPipe(queryString.data());
38+
std::string queryResult(queryResultTString);
39+
40+
// find closest entry in time
41+
long minDist = 9999999999999;
42+
long minTime = sor;
43+
size_t pos = 0;
44+
const std::string_view searchString("validFrom");
45+
while ((pos = queryResult.find(searchString.data(), pos)) < queryResult.size()) {
46+
const auto startPosTime = queryResult.find(":", pos) + 1;
47+
const auto endPosTime = queryResult.find(",", pos);
48+
const auto startValidity = std::atol(queryResult.substr(startPosTime, endPosTime - startPosTime).data());
49+
fmt::print("add object {}\n", startValidity);
50+
if (std::abs(startValidity - sor) < minDist) {
51+
minTime = startValidity;
52+
minDist = std::abs(startValidity - sor);
53+
}
54+
pos = endPosTime;
55+
}
56+
fmt::print("{} closest to {} is at {}\n", calibType, sor, minTime);
57+
58+
//
59+
// Get object closest to present run and return the drfit veloctiy calibration factor
60+
c.init(ltrUrl.data());
61+
const auto ltrCalib = c.retrieveFromTFileAny<o2::tpc::LtrCalibData>(calibType.data(), metadata, minTime); /// timestamp in the run of interest
62+
const auto corr = ltrCalib->getDriftVCorrection();
63+
float vcorr = defaultDriftV / corr;
64+
if (ltrCalib->refVDrift != 0) {
65+
printf("refVDrift different from zero: %f (default was %f)\n", ltrCalib->refVDrift, defaultDriftV);
66+
vcorr = ltrCalib->refVDrift / corr;
67+
}
68+
printf("vdrift = %f\n", vcorr);
69+
70+
ofstream fp("vdrift.txt");
71+
fp << vcorr << endl;
72+
fp.close();
73+
74+
return vcorr;
75+
}

DATA/production/configurations/asyncReco/setenv_extra.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ else
159159
echo "************************************************************"
160160
fi
161161

162+
# TPC vdrift
163+
PERIODLETTER=${PERIOD: -1}
164+
VDRIFTPARAMOPTION=
165+
if [[ $$ALIEN_JDL_LPMANCHORYEAR == "2022" ]] && [[ $PERIODLETTER < m ]]; then
166+
echo "In setenv_extra: time used so far = $timeUsed s"
167+
timeStart=`date +%s`
168+
time root -b -q "$O2DPG_ROOT/DATA/production/common/getTPCvdrift.C+($RUNNUMBER)"
169+
timeEnd=`date +%s`
170+
timeUsed=$(( $timeUsed+$timeEnd-$timeStart ))
171+
delta=$(( $timeEnd-$timeStart ))
172+
echo "Time spent to get VDrift for TPC = $delta s"
173+
export VDRIFT=`cat vdrift.txt`
174+
VDRIFTPARAMOPTION="TPCGasParam.DriftV=$VDRIFT"
175+
echo "Setting TPC vdrift to $VDRIFT"
176+
else
177+
echo "TPC vdrift will be taken from CCDB"
178+
fi
179+
162180
# IR
163181
if [[ -z $RUN_IR ]] || [[ -z $RUN_DURATION ]] || [[ -z $RUN_BFIELD ]]; then
164182
cp $O2DPG_ROOT/DATA/production/common/getIRandDuration.C ./
@@ -280,7 +298,7 @@ if [[ $ALIGNLEVEL != 0 ]]; then
280298
fi
281299

282300
# ad-hoc options for GPU reco workflow
283-
export CONFIG_EXTRA_PROCESS_o2_gpu_reco_workflow+=";GPU_global.dEdxDisableResidualGainMap=1;$TRACKTUNETPCINNER;"
301+
export CONFIG_EXTRA_PROCESS_o2_gpu_reco_workflow+=";GPU_global.dEdxDisableResidualGainMap=1;$TRACKTUNETPCINNER;$VDRIFTPARAMOPTION;"
284302
if [[ $ALIEN_JDL_LPMPRODUCTIONTYPE == "MC" ]]; then
285303
export CONFIG_EXTRA_PROCESS_o2_gpu_reco_workflow+=";GPU_global.dEdxDisableResidualGain=1"
286304
fi
@@ -315,10 +333,10 @@ fi
315333
# secondary vertexing
316334
export SVTX="svertexer.checkV0Hypothesis=false;svertexer.checkCascadeHypothesis=false"
317335

318-
export CONFIG_EXTRA_PROCESS_o2_primary_vertexing_workflow+=";$PVERTEXER;"
336+
export CONFIG_EXTRA_PROCESS_o2_primary_vertexing_workflow+=";$PVERTEXER;$VDRIFTPARAMOPTION;"
319337
export CONFIG_EXTRA_PROCESS_o2_secondary_vertexing_workflow+=";$SVTX"
320338

321-
export CONFIG_EXTRA_PROCESS_o2_tpcits_match_workflow+=";$ITSEXTRAERR;$ITSTPCMATCH;$TRACKTUNETPCINNER;"
339+
export CONFIG_EXTRA_PROCESS_o2_tpcits_match_workflow+=";$ITSEXTRAERR;$ITSTPCMATCH;$TRACKTUNETPCINNER;$VDRIFTPARAMOPTION;"
322340
[[ ! -z "${TPCITSTIMEBIAS}" ]] && export CONFIG_EXTRA_PROCESS_o2_tpcits_match_workflow+=";tpcitsMatch.globalTimeBiasMUS=$TPCITSTIMEBIAS;"
323341
[[ ! -z "${TPCITSTIMEERR}" ]] && export CONFIG_EXTRA_PROCESS_o2_tpcits_match_workflow+=";tpcitsMatch.globalTimeExtraErrorMUS=$TPCITSTIMEERR;"
324342

@@ -327,10 +345,10 @@ has_detector FT0 && export ARGS_EXTRA_PROCESS_o2_tpcits_match_workflow="$ARGS_EX
327345

328346
# ad-hoc settings for TOF matching
329347
export ARGS_EXTRA_PROCESS_o2_tof_matcher_workflow="$ARGS_EXTRA_PROCESS_o2_tof_matcher_workflow --output-type matching-info,calib-info --enable-dia"
330-
export CONFIG_EXTRA_PROCESS_o2_tof_matcher_workflow+=";$ITSEXTRAERR;$TRACKTUNETPCINNER;"
348+
export CONFIG_EXTRA_PROCESS_o2_tof_matcher_workflow+=";$ITSEXTRAERR;$TRACKTUNETPCINNER;$VDRIFTPARAMOPTION;"
331349

332350
# ad-hoc settings for TRD matching
333-
export CONFIG_EXTRA_PROCESS_o2_trd_global_tracking+=";$ITSEXTRAERR;$TRACKTUNETPCINNER;"
351+
export CONFIG_EXTRA_PROCESS_o2_trd_global_tracking+=";$ITSEXTRAERR;$TRACKTUNETPCINNER;$VDRIFTPARAMOPTION;"
334352

335353
# ad-hoc settings for FT0
336354
export ARGS_EXTRA_PROCESS_o2_ft0_reco_workflow="$ARGS_EXTRA_PROCESS_o2_ft0_reco_workflow --ft0-reconstructor"

0 commit comments

Comments
 (0)