-
Notifications
You must be signed in to change notification settings - Fork 652
Expand file tree
/
Copy pathpidTOFbeta.cxx
More file actions
154 lines (141 loc) · 6.78 KB
/
pidTOFbeta.cxx
File metadata and controls
154 lines (141 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file pidTOFbeta.cxx
/// \author Nicolò Jacazio nicolo.jacazio@cern.ch
/// \brief Task to produce TOF beta and TOF mass tables
///
// O2 includes
#include "CCDB/BasicCCDBManager.h"
#include "Framework/AnalysisTask.h"
#include "Common/DataModel/TrackSelectionTables.h"
#include "pidTOFBase.h"
#include "TableHelper.h"
// O2Physics includes
#include "PID/PIDTOF.h"
using namespace o2;
using namespace o2::pid;
using namespace o2::track;
using namespace o2::framework;
using namespace o2::framework::expressions;
void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
{
std::vector<ConfigParamSpec> options{{"add-qa", VariantType::Int, 0, {"Legacy. No effect."}}};
std::swap(workflowOptions, options);
}
#include "Framework/runDataProcessing.h"
struct tofPidBeta {
Produces<aod::pidTOFbeta> tablePIDBeta;
Produces<aod::pidTOFmass> tablePIDTOFMass;
Configurable<float> expreso{"tof-expreso", 80, "Expected resolution for the computation of the expected beta"};
// Detector response and input parameters
o2::pid::tof::TOFResoParamsV2 mRespParamsV2;
Service<o2::ccdb::BasicCCDBManager> ccdb;
Configurable<std::string> paramFileName{"paramFileName", "", "Path to the parametrization object. If empty the parametrization is not taken from file"};
Configurable<std::string> url{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<std::string> parametrizationPath{"parametrizationPath", "TOF/Calib/Params", "Path of the TOF parametrization on the CCDB or in the file, if the paramFileName is not empty"};
Configurable<std::string> passName{"passName", "", "Name of the pass inside of the CCDB parameter collection. If empty, the automatically deceted from metadata (to be implemented!!!)"};
Configurable<int64_t> timestamp{"ccdb-timestamp", -1, "timestamp of the object"};
Configurable<bool> fatalOnPassNotAvailable{"fatalOnPassNotAvailable", true, "Flag to throw a fatal if the pass is not available in the retrieved CCDB object"};
Configurable<bool> enableTOFParams{"enableTOFParams", false, "Flag to use TOF parameters"};
bool enableTableBeta = false;
bool enableTableMass = false;
void init(o2::framework::InitContext& initContext)
{
if (isTableRequiredInWorkflow(initContext, "pidTOFbeta")) {
enableTableBeta = true;
}
if (isTableRequiredInWorkflow(initContext, "pidTOFmass")) {
enableTableMass = true;
}
responseBeta.mExpectedResolution = expreso.value;
if (!enableTOFParams) {
return;
}
// Getting the parametrization parameters
ccdb->setURL(url.value);
ccdb->setTimestamp(timestamp.value);
ccdb->setCaching(true);
ccdb->setLocalObjectValidityChecking();
// Not later than now objects
ccdb->setCreatedNotAfter(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
//
// TODO: implement the automatic pass name detection from metadata
if (passName.value == "") {
passName.value = "unanchored"; // temporary default
LOG(warning) << "Passed autodetect mode for pass, not implemented yet, waiting for metadata. Taking '" << passName.value << "'";
}
LOG(info) << "Using parameter collection, starting from pass '" << passName.value << "'";
const std::string fname = paramFileName.value;
if (!fname.empty()) { // Loading the parametrization from file
LOG(info) << "Loading exp. sigma parametrization from file " << fname << ", using param: " << parametrizationPath.value;
if (1) {
o2::tof::ParameterCollection paramCollection;
paramCollection.loadParamFromFile(fname, parametrizationPath.value);
LOG(info) << "+++ Loaded parameter collection from file +++";
if (!paramCollection.retrieveParameters(mRespParamsV2, passName.value)) {
if (fatalOnPassNotAvailable) {
LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", passName.value.data());
} else {
LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", passName.value.data());
}
} else {
mRespParamsV2.setShiftParameters(paramCollection.getPars(passName.value));
mRespParamsV2.printShiftParameters();
}
} else {
mRespParamsV2.loadParamFromFile(fname.data(), parametrizationPath.value);
}
} else { // Loading it from CCDB
LOG(info) << "Loading exp. sigma parametrization from CCDB, using path: " << parametrizationPath.value << " for timestamp " << timestamp.value;
o2::tof::ParameterCollection* paramCollection = ccdb->getForTimeStamp<o2::tof::ParameterCollection>(parametrizationPath.value, timestamp.value);
paramCollection->print();
if (!paramCollection->retrieveParameters(mRespParamsV2, passName.value)) {
if (fatalOnPassNotAvailable) {
LOGF(fatal, "Pass '%s' not available in the retrieved CCDB object", passName.value.data());
} else {
LOGF(warning, "Pass '%s' not available in the retrieved CCDB object", passName.value.data());
}
} else {
mRespParamsV2.setShiftParameters(paramCollection->getPars(passName.value));
mRespParamsV2.printShiftParameters();
}
}
mRespParamsV2.print();
}
using Trks = soa::Join<aod::Tracks, aod::TracksExtra, aod::TOFSignal, aod::TOFEvTime, aod::pidEvTimeFlags>;
o2::pid::tof::Beta responseBeta;
template <o2::track::PID::ID pid>
using ResponseImplementation = o2::pid::tof::ExpTimes<Trks::iterator, pid>;
void process(Trks const& tracks)
{
if (!enableTableBeta && !enableTableMass) {
return;
}
float beta = 0.f;
tablePIDBeta.reserve(tracks.size());
for (auto const& trk : tracks) {
beta = responseBeta.GetBeta(trk);
if (enableTableBeta) {
tablePIDBeta(beta,
responseBeta.GetExpectedSigma(trk));
}
if (enableTableMass) {
if (enableTOFParams) {
tablePIDTOFMass(o2::pid::tof::TOFMass::GetTOFMass(trk.tofExpMom() / (1.f + trk.sign() * mRespParamsV2.getShift(trk.eta())), beta));
} else {
tablePIDTOFMass(o2::pid::tof::TOFMass::GetTOFMass(trk, beta));
}
}
}
}
};
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { return WorkflowSpec{adaptAnalysisTask<tofPidBeta>(cfgc)}; }