1+ // Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+ // See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+ // All rights not expressly granted are reserved.
4+ //
5+ // This software is distributed under the terms of the GNU General Public
6+ // License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+ //
8+ // In applying this license CERN does not waive the privileges and immunities
9+ // granted to it by virtue of its status as an Intergovernmental Organization
10+ // or submit itself to any jurisdiction.
11+ // /
12+ // / \file materialBudgetWeights.cxx
13+ // /
14+ // / \brief This code produces a table to retrieve material budget weights. The table is to be join with V0PhotonKF
15+ // /
16+ // / \author Youssef El Mard (youssef.el.mard.bouziani@cern.ch)
17+ // /
18+
19+ #ifndef PWGEM_PHOTONMESON_UTILS_MATERIALBUDGETWEIGHTS_H_
20+ #define PWGEM_PHOTONMESON_UTILS_MATERIALBUDGETWEIGHTS_H_
21+
22+ #include " PWGEM/PhotonMeson/DataModel/gammaTables.h"
23+
24+ #include " Framework/ASoAHelpers.h"
25+ #include " Framework/AnalysisDataModel.h"
26+ #include " Framework/AnalysisTask.h"
27+ #include " Framework/Logger.h"
28+ #include < CCDB/BasicCCDBManager.h>
29+ #include < Framework/Configurable.h>
30+ #include < Framework/InitContext.h>
31+
32+ #include < map>
33+ #include < string>
34+
35+ using namespace o2 ;
36+ using namespace o2 ::soa;
37+ using namespace o2 ::framework;
38+
39+ using MyV0PhotonsMB = o2::soa::Join<o2::aod::V0PhotonsKF, o2::aod::V0KFEMEventIds>;
40+ using MyV0PhotonMB = MyV0PhotonsMB::iterator;
41+
42+ struct MaterialBudgetWeights {
43+ Produces<aod::V0PhotonOmegaMBWeights> omegaMBWeight;
44+
45+ Configurable<std::string> ccdbUrl{" ccdbUrl" , " http://ccdb-test.cern.ch:8080" , " CCDB url" };
46+ Configurable<std::string> mbWeightsPath{" mbWeightsPath" , " Users/y/yelmard/MaterialBudget/OmegaMBWeights" , " Path of the mb weights" };
47+
48+ o2::ccdb::CcdbApi ccdbApi;
49+ TH1F* hOmegaMBFromCCDB = nullptr ;
50+
51+ void init (InitContext&)
52+ {
53+ // Load CCDB object only when the real process is enabled
54+ if (!doprocessMC) {
55+ LOG (info) << " MaterialBudgetWeights: dummy mode enabled -> no CCDB query, will write weight=1" ;
56+ return ;
57+ }
58+
59+ ccdbApi.init (ccdbUrl.value );
60+ std::map<std::string, std::string> metadata;
61+ LOG (info) << " MaterialBudgetWeights: loading Omega MB histogram from CCDB at path: " << mbWeightsPath.value ;
62+
63+ hOmegaMBFromCCDB = ccdbApi.retrieveFromTFileAny <TH1F>(mbWeightsPath, metadata, -1 );
64+
65+ if (!hOmegaMBFromCCDB) {
66+ LOG (fatal) << " MaterialBudgetWeights: CCDB object is missing. Path=" << mbWeightsPath.value ;
67+ }
68+ }
69+
70+ float computeMBWeight (float v0Rxy)
71+ {
72+ if (!hOmegaMBFromCCDB) {
73+ return 1 .f ;
74+ }
75+
76+ int binMBWeight = hOmegaMBFromCCDB->FindBin (v0Rxy);
77+ if (binMBWeight < 1 || binMBWeight > hOmegaMBFromCCDB->GetNbinsX ()) {
78+ LOG (debug) << " MaterialBudgetWeights: v0Rxy out of histogram range, returning 1" ;
79+ return 1 .f ;
80+ }
81+
82+ return hOmegaMBFromCCDB->GetBinContent (binMBWeight);
83+ }
84+
85+ // real process (weights from CCDB)
86+ void processMC (MyV0PhotonMB const & v0)
87+ {
88+ static bool once = false ;
89+ if (!once) {
90+ LOG (info) << " MaterialBudgetWeights: standard process running" ;
91+ once = true ;
92+ }
93+ if (!hOmegaMBFromCCDB) { // histogram not loaded => behave like dummy
94+ omegaMBWeight (1 .f );
95+ return ;
96+ }
97+ omegaMBWeight (computeMBWeight (v0.v0radius ()));
98+ }
99+
100+ // dummy process (always weight = 1)
101+ void processDummy (MyV0PhotonMB const &)
102+ {
103+ static bool once = false ;
104+ if (!once) {
105+ LOG (info) << " MaterialBudgetWeights: processDummy running" ;
106+ once = true ;
107+ }
108+ omegaMBWeight (1 .f );
109+ }
110+
111+ PROCESS_SWITCH (MaterialBudgetWeights, processMC, " Fill MB weights from CCDB" , false );
112+ PROCESS_SWITCH (MaterialBudgetWeights, processDummy, " Fill dummy MB weights (=1)" , true );
113+ };
114+
115+ #endif // PWGEM_PHOTONMESON_UTILS_MATERIALBUDGETWEIGHTS_H_
0 commit comments