2222#include < string>
2323
2424#include " Framework/Configurable.h"
25- #include " Framework/AnalysisHelpers.h"
2625#include " Framework/CallbackService.h"
2726#include " Framework/InitContext.h"
2827#include " CCDB/BasicCCDBManager.h"
@@ -37,20 +36,13 @@ concept isOneOrTwo = T == 1 || T == 2;
3736struct EfficiencyConfigurableGroup : ConfigurableGroup {
3837 Configurable<bool > confEfficiencyCalculate{" confEfficiencyCalculate" , false , " Should calculate efficiency" };
3938 Configurable<bool > confEfficiencyApplyCorrections{" confEfficiencyApplyCorrections" , false , " Should apply corrections from efficiency" };
39+ Configurable<std::vector<std::string>> confEfficiencyCCDBLabels{" confEfficiencyCCDBLabels" , {}, " Labels for efficiency objects in CCDB" };
40+ ConfigurableAxis confEfficiencyCCDBTimestamps{" confEfficiencyCCDBTimestamps" , {-1 , -1 }, " Timestamps from which to query CCDB objects (default: -1 for both)" };
4041
41- Configurable<std::vector<std::string>> confCCDBLabels{" confCCDBLabels" , std::vector<std::string>{" label1" , " label2" }, " Labels for efficiency objects in CCDB" };
42-
43- OutputObj<TH1F> hEfficiency1{" Efficiency part1" };
44- OutputObj<TH1F> hEfficiency2{" Efficiency part2" };
45-
46- // TODO: move to separate struct?
42+ // NOTE: in the future we might move the below configurables to a separate struct, eg. CCDBConfigurableGroup
4743 Configurable<std::string> confCCDBUrl{" confCCDBUrl" , " http://alice-ccdb.cern.ch" , " CCDB URL to be used" };
4844 Configurable<std::string> confCCDBPath{" confCCDBPath" , " " , " CCDB base path to where to upload objects" };
49- Configurable<int64_t > confCCDBTimestamp{" confCCDBTimestamp" , -1 , " Timestamp from which to query CCDB objects" };
50-
51- // TODO: declare this in task directly?
52- FemtoUniverseParticleHisto<aod::femtouniverseparticle::ParticleType::kMCTruthTrack , 1 > hMCTruth1;
53- FemtoUniverseParticleHisto<aod::femtouniverseparticle::ParticleType::kMCTruthTrack , 2 > hMCTruth2;
45+ Configurable<int64_t > confCCDBLifetime{" confCCDBLifetime" , 365LL * 24 * 60 * 60 * 1000 , " Lifetime of uploaded objects (default: 1 year)" };
5446};
5547
5648class EfficiencyCalculator
@@ -69,33 +61,31 @@ class EfficiencyCalculator
6961 ccdb.setLocalObjectValidityChecking ();
7062 ccdb.setFatalWhenNull (false );
7163
64+ int64_t now = duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now ().time_since_epoch ()).count ();
65+ ccdb.setCreatedNotAfter (now);
66+
7267 shouldCalculate = config->confEfficiencyCalculate ;
7368 shouldApplyCorrections = config->confEfficiencyApplyCorrections ;
7469
7570 ccdbFullPath = fmt::format (" {}/{}" , config->confCCDBPath .value , folderName);
7671
77- if (config->confEfficiencyCalculate ) {
78- hOutput = {config->hEfficiency1 .object , config->hEfficiency2 .object };
79- }
80-
8172 if (config->confEfficiencyApplyCorrections ) {
73+ if (config->confEfficiencyCCDBTimestamps ->size () != 2 ) {
74+ LOGF (fatal, notify (" CCDB timestamps configurable should be exactly of size 2" ));
75+ }
8276 hLoaded = {
83- loadEfficiencyFromCCDB<1 >(config->confCCDBTimestamp ),
84- loadEfficiencyFromCCDB<2 >(config->confCCDBTimestamp ) //
77+ loadEfficiencyFromCCDB<1 >(config->confEfficiencyCCDBTimestamps . value [ 0 ] ),
78+ loadEfficiencyFromCCDB<2 >(config->confEfficiencyCCDBTimestamps . value [ 1 ] ) //
8579 };
8680 }
8781 }
8882
8983 template <uint8_t N>
9084 requires isOneOrTwo<N>
91- auto doMCTruth (auto particles) const -> void
85+ auto doMCTruth (FemtoUniverseParticleHisto<aod::femtouniverseparticle::ParticleType:: kMCTruthTrack , N>& hMCTruth, const auto & particles) const -> void
9286 {
9387 for (const auto & particle : particles) {
94- if constexpr (N == 1 ) {
95- config->hMCTruth1 .fillQA <false , false >(particle);
96- } else if constexpr (N == 2 ) {
97- config->hMCTruth2 .fillQA <false , false >(particle);
98- }
88+ hMCTruth.template fillQA <false , false >(particle);
9989 }
10090 }
10191
@@ -120,9 +110,8 @@ class EfficiencyCalculator
120110 LOGF (debug, notify (" Found histogram %d: %s" ), i + 1 , output->GetTitle ());
121111
122112 int64_t now = duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now ().time_since_epoch ()).count ();
123- int64_t oneYear = 365LL * 24 * 60 * 60 * 1000 ;
124113
125- if (ccdbApi.storeAsTFileAny (output.get (), ccdbFullPath, createMetadata (i), now, now + oneYear ) == 0 ) {
114+ if (ccdbApi.storeAsTFileAny (output.get (), ccdbFullPath, createMetadata (i), now, now + config-> confCCDBLifetime ) == 0 ) {
126115 LOGF (info, notify (" Histogram %d saved successfully" ), i + 1 );
127116 } else {
128117 LOGF (fatal, notify (" Histogram %d save failed" ), i + 1 );
@@ -136,7 +125,7 @@ class EfficiencyCalculator
136125
137126 template <uint8_t N>
138127 requires isOneOrTwo<N>
139- auto getWeight (auto const & particle) const -> float
128+ auto getWeight (const auto & particle) const -> float
140129 {
141130 auto weight = 1 .0f ;
142131 auto hEff = hLoaded[N - 1 ];
@@ -152,27 +141,28 @@ class EfficiencyCalculator
152141
153142 template <uint8_t N>
154143 requires isOneOrTwo<N>
155- auto calculate (std::shared_ptr<TH1> truth , std::shared_ptr<TH1> reco) const
144+ auto calculate (std::shared_ptr<TH1> hEff , std::shared_ptr<TH1> hTruth, std::shared_ptr<TH1> hReco)
156145 {
157146 if (!shouldCalculate) {
158147 return ;
159148 }
160149
161- if (!truth || !reco ) {
150+ if (!hTruth || !hReco ) {
162151 LOGF (error, notify (" MC Truth & MC Reco histograms cannot be null" ));
163152 return ;
164153 }
165154
166- auto hEff = hOutput[N - 1 ];
167155 if (!hEff) {
168- LOGF (error, notify (" No OutputObj specified for particle %d histogram " ), N);
156+ LOGF (error, notify (" No target histogram to fill specified for particle %d" ), N);
169157 return ;
170158 }
171159
172160 for (auto bin = 0 ; bin < hEff->GetNbinsX (); bin++) {
173- auto denom = truth ->GetBinContent (bin);
174- hEff->SetBinContent (bin, denom == 0 ? 0 : reco ->GetBinContent (bin) / denom);
161+ auto denom = hTruth ->GetBinContent (bin);
162+ hEff->SetBinContent (bin, denom == 0 ? 0 : hReco ->GetBinContent (bin) / denom);
175163 }
164+
165+ hOutput[N - 1 ] = hEff;
176166 }
177167
178168 private:
@@ -197,19 +187,19 @@ class EfficiencyCalculator
197187 return true ;
198188 }
199189
200- auto createMetadata (uint8_t partNo) const -> std::map<std::string, std::string>
190+ auto createMetadata (const uint8_t partNo) const -> std::map<std::string, std::string>
201191 {
202- if (config->confCCDBLabels ->size () != 2 ) {
192+ if (config->confEfficiencyCCDBLabels ->size () != 2 ) {
203193 LOGF (fatal, notify (" CCDB labels configurable should be exactly of size 2" ));
204194 }
205195 return std::map<std::string, std::string>{
206- {" label" , config->confCCDBLabels .value [partNo]} //
196+ {" label" , config->confEfficiencyCCDBLabels .value [partNo]} //
207197 };
208198 }
209199
210200 template <uint8_t N>
211201 requires isOneOrTwo<N>
212- auto loadEfficiencyFromCCDB (int64_t timestamp) const -> TH1*
202+ auto loadEfficiencyFromCCDB (const int64_t timestamp) const -> TH1*
213203 {
214204 auto hEff = ccdb.getSpecific <TH1>(ccdbFullPath, timestamp, createMetadata (N - 1 ));
215205 if (!hEff || hEff->IsZombie ()) {
0 commit comments