Skip to content

Commit 6b3abf8

Browse files
authored
Merge branch 'AliceO2Group:master' into master
2 parents 9f6d575 + 5b9c96d commit 6b3abf8

File tree

55 files changed

+4251
-877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4251
-877
lines changed

ALICE3/TableProducer/OTF/onTheFlyRichPid.cxx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,15 @@ struct OnTheFlyRichPid {
745745
}
746746

747747
for (const auto& track : tracks) {
748+
749+
float nSigmaBarrelRich[5] = {error_value, error_value, error_value, error_value, error_value};
750+
748751
// first step: find precise arrival time (if any)
749752
// --- convert track into perfect track
750-
if (!track.has_mcParticle()) // should always be OK but check please
753+
if (!track.has_mcParticle()) { // should always be OK but check please
754+
upgradeRich(nSigmaBarrelRich[0], nSigmaBarrelRich[1], nSigmaBarrelRich[2], nSigmaBarrelRich[3], nSigmaBarrelRich[4]);
751755
continue;
756+
}
752757

753758
auto mcParticle = track.mcParticle();
754759
o2::track::TrackParCov o2track = o2::upgrade::convertMCParticleToO2Track(mcParticle, pdg);
@@ -761,12 +766,14 @@ struct OnTheFlyRichPid {
761766
// get particle to calculate Cherenkov angle and resolution
762767
auto pdgInfo = pdg->GetParticle(mcParticle.pdgCode());
763768
if (pdgInfo == nullptr) {
769+
upgradeRich(nSigmaBarrelRich[0], nSigmaBarrelRich[1], nSigmaBarrelRich[2], nSigmaBarrelRich[3], nSigmaBarrelRich[4]);
764770
continue;
765771
}
766772

767773
// find track bRICH sector
768774
int i_sector = findSector(o2track.getEta());
769775
if (i_sector < 0) {
776+
upgradeRich(nSigmaBarrelRich[0], nSigmaBarrelRich[1], nSigmaBarrelRich[2], nSigmaBarrelRich[3], nSigmaBarrelRich[4]);
770777
continue;
771778
}
772779

@@ -794,12 +801,12 @@ struct OnTheFlyRichPid {
794801
}
795802

796803
// Straight to Nsigma
797-
float deltaThetaBarrelRich[5], nSigmaBarrelRich[5];
804+
float deltaThetaBarrelRich[5]; //, nSigmaBarrelRich[5];
798805
int lpdg_array[5] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
799806
float masses[5];
800807

801808
for (int ii = 0; ii < 5; ii++) {
802-
nSigmaBarrelRich[ii] = error_value;
809+
// nSigmaBarrelRich[ii] = error_value;
803810

804811
auto pdgInfoThis = pdg->GetParticle(lpdg_array[ii]);
805812
masses[ii] = pdgInfoThis->Mass();

Common/TableProducer/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ o2physics_add_dpl_workflow(trackselection
2525
o2physics_add_dpl_workflow(event-selection
2626
SOURCES eventSelection.cxx
2727
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCCDB
28+
O2::DataFormatsITSMFT
2829
COMPONENT_NAME Analysis)
2930

3031
o2physics_add_dpl_workflow(event-selection-service
3132
SOURCES eventSelectionService.cxx
3233
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCCDB
34+
O2::DataFormatsITSMFT
3335
COMPONENT_NAME Analysis)
3436

3537
o2physics_add_dpl_workflow(multiplicity-table

Common/TableProducer/PID/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ o2physics_add_dpl_workflow(pid-tof-full
4545

4646
o2physics_add_dpl_workflow(pid-tpc-base
4747
SOURCES pidTPCBase.cxx
48-
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
48+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2Physics::AnalysisCCDB
4949
COMPONENT_NAME Analysis)
5050

5151
o2physics_add_dpl_workflow(pid-tpc

Common/TableProducer/PID/pidTPC.cxx

Lines changed: 110 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,34 @@
1818
/// \brief Task to produce PID tables for TPC split for each particle.
1919
/// Only the tables for the mass hypotheses requested are filled, and only for the requested table size ("Full" or "Tiny"). The others are sent empty.
2020
///
21-
#include <utility>
2221
#include <map>
2322
#include <memory>
2423
#include <string>
24+
#include <utility>
2525
#include <vector>
2626
// ROOT includes
2727
#include "TFile.h"
2828
#include "TRandom.h"
2929
#include "TSystem.h"
3030

3131
// O2 includes
32+
#include "MetadataHelper.h"
33+
#include "TableHelper.h"
34+
#include "pidTPCBase.h"
35+
36+
#include "Common/Core/PID/TPCPIDResponse.h"
37+
#include "Common/DataModel/EventSelection.h"
38+
#include "Common/DataModel/Multiplicity.h"
39+
#include "Common/DataModel/PIDResponseTPC.h"
40+
#include "Tools/ML/model.h"
41+
3242
#include "CCDB/BasicCCDBManager.h"
43+
#include "CCDB/CcdbApi.h"
44+
#include "Framework/ASoAHelpers.h"
45+
#include "Framework/AnalysisDataModel.h"
3346
#include "Framework/AnalysisTask.h"
3447
#include "Framework/runDataProcessing.h"
35-
#include "Framework/ASoAHelpers.h"
3648
#include "ReconstructionDataFormats/Track.h"
37-
#include "CCDB/CcdbApi.h"
38-
#include "Common/DataModel/PIDResponseTPC.h"
39-
#include "Common/Core/PID/TPCPIDResponse.h"
40-
#include "Framework/AnalysisDataModel.h"
41-
#include "Common/DataModel/Multiplicity.h"
42-
#include "Common/DataModel/EventSelection.h"
43-
#include "TableHelper.h"
44-
#include "Tools/ML/model.h"
45-
#include "pidTPCBase.h"
46-
#include "MetadataHelper.h"
4749

4850
using namespace o2;
4951
using namespace o2::framework;
@@ -155,8 +157,10 @@ struct tpcPid {
155157
void init(o2::framework::InitContext& initContext)
156158
{
157159
// Protection for process flags
158-
if ((doprocessStandard && doprocessMcTuneOnData) || (!doprocessStandard && !doprocessMcTuneOnData)) {
159-
LOG(fatal) << "pid-tpc must have only one of the options 'processStandard' OR 'processMcTuneOnData' enabled. Please check your configuration.";
160+
if (!((doprocessStandard && !doprocessStandard2 && !doprocessMcTuneOnData) ||
161+
(!doprocessStandard && doprocessStandard2 && !doprocessMcTuneOnData) ||
162+
(!doprocessStandard && !doprocessStandard2 && doprocessMcTuneOnData))) {
163+
LOG(fatal) << "pid-tpc must have only one of the options 'processStandard', 'processStandard2', 'processMcTuneOnData' enabled. Please check your configuration.";
160164
}
161165
response = new o2::pid::tpc::Response();
162166
// Checking the tables are requested in the workflow and enabling them
@@ -552,6 +556,98 @@ struct tpcPid {
552556
Partition<TrksMC> mcnotTPCStandaloneTracks = (aod::track::tpcNClsFindable > static_cast<uint8_t>(0)) && ((aod::track::itsClusterSizes > static_cast<uint32_t>(0)) || (aod::track::trdPattern > static_cast<uint8_t>(0)) || (aod::track::tofExpMom > 0.f && aod::track::tofChi2 > 0.f)); // To count number of tracks for use in NN array
553557
Partition<TrksMC> mctracksWithTPC = (aod::track::tpcNClsFindable > (uint8_t)0);
554558

559+
void processStandard2(Coll const& collisions, Trks const& tracks, aod::DEdxsCorrected const& dedxscorrected, aod::BCsWithTimestamps const& bcs)
560+
{
561+
const uint64_t outTable_size = tracks.size();
562+
const uint64_t dedxscorrected_size = dedxscorrected.size();
563+
564+
if (dedxscorrected_size != outTable_size) {
565+
LOG(fatal) << "Size of dEdx corrected table does not match size of tracks! dEdx size: " << dedxscorrected_size << ", tracks size: " << outTable_size;
566+
}
567+
568+
auto reserveTable = [&outTable_size](const Configurable<int>& flag, auto& table) {
569+
if (flag.value != 1) {
570+
return;
571+
}
572+
table.reserve(outTable_size);
573+
};
574+
575+
// Prepare memory for enabled tables
576+
reserveTable(pidFullEl, tablePIDFullEl);
577+
reserveTable(pidFullMu, tablePIDFullMu);
578+
reserveTable(pidFullPi, tablePIDFullPi);
579+
reserveTable(pidFullKa, tablePIDFullKa);
580+
reserveTable(pidFullPr, tablePIDFullPr);
581+
reserveTable(pidFullDe, tablePIDFullDe);
582+
reserveTable(pidFullTr, tablePIDFullTr);
583+
reserveTable(pidFullHe, tablePIDFullHe);
584+
reserveTable(pidFullAl, tablePIDFullAl);
585+
586+
reserveTable(pidTinyEl, tablePIDTinyEl);
587+
reserveTable(pidTinyMu, tablePIDTinyMu);
588+
reserveTable(pidTinyPi, tablePIDTinyPi);
589+
reserveTable(pidTinyKa, tablePIDTinyKa);
590+
reserveTable(pidTinyPr, tablePIDTinyPr);
591+
reserveTable(pidTinyDe, tablePIDTinyDe);
592+
reserveTable(pidTinyTr, tablePIDTinyTr);
593+
reserveTable(pidTinyHe, tablePIDTinyHe);
594+
reserveTable(pidTinyAl, tablePIDTinyAl);
595+
596+
const uint64_t tracksForNet_size = (skipTPCOnly) ? notTPCStandaloneTracks.size() : tracksWithTPC.size();
597+
std::vector<float> network_prediction;
598+
599+
if (useNetworkCorrection) {
600+
network_prediction = createNetworkPrediction(collisions, tracks, bcs, tracksForNet_size);
601+
}
602+
603+
uint64_t count_tracks = 0;
604+
uint64_t count_tracks2 = 0;
605+
606+
for (auto const& trk : tracks) {
607+
// Loop on Tracks
608+
609+
const auto& bc = trk.has_collision() ? collisions.iteratorAt(trk.collisionId()).bc_as<aod::BCsWithTimestamps>() : bcs.begin();
610+
auto dedx_corr = dedxscorrected.iteratorAt(count_tracks2);
611+
count_tracks2++;
612+
if (useCCDBParam && ccdbTimestamp.value == 0 && !ccdb->isCachedObjectValid(ccdbPath.value, bc.timestamp())) { // Updating parametrisation only if the initial timestamp is 0
613+
if (recoPass.value == "") {
614+
LOGP(info, "Retrieving latest TPC response object for timestamp {}:", bc.timestamp());
615+
} else {
616+
LOGP(info, "Retrieving TPC Response for timestamp {} and recoPass {}:", bc.timestamp(), recoPass.value);
617+
}
618+
response = ccdb->getSpecific<o2::pid::tpc::Response>(ccdbPath.value, bc.timestamp(), metadata);
619+
headers = ccdbApi.retrieveHeaders(ccdbPath.value, metadata, bc.timestamp());
620+
if (!response) {
621+
LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", metadata["RecoPassName"]);
622+
response = ccdb->getForTimeStamp<o2::pid::tpc::Response>(ccdbPath.value, bc.timestamp());
623+
headers = ccdbApi.retrieveHeaders(ccdbPath.value, nullmetadata, bc.timestamp());
624+
if (!response) {
625+
LOGP(fatal, "Could not find ANY TPC response object for the timestamp {}!", bc.timestamp());
626+
}
627+
}
628+
LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << bc.timestamp() << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"];
629+
response->PrintAll();
630+
}
631+
auto makePidTablesDefault = [&trk, &dedx_corr, &collisions, &network_prediction, &count_tracks, &tracksForNet_size, this](const int flagFull, auto& tableFull, const int flagTiny, auto& tableTiny, const o2::track::PID::ID pid) {
632+
makePidTables(flagFull, tableFull, flagTiny, tableTiny, pid, dedx_corr.tpcSignalCorrected(), trk, collisions, network_prediction, count_tracks, tracksForNet_size);
633+
};
634+
635+
makePidTablesDefault(pidFullEl, tablePIDFullEl, pidTinyEl, tablePIDTinyEl, o2::track::PID::Electron);
636+
makePidTablesDefault(pidFullMu, tablePIDFullMu, pidTinyMu, tablePIDTinyMu, o2::track::PID::Muon);
637+
makePidTablesDefault(pidFullPi, tablePIDFullPi, pidTinyPi, tablePIDTinyPi, o2::track::PID::Pion);
638+
makePidTablesDefault(pidFullKa, tablePIDFullKa, pidTinyKa, tablePIDTinyKa, o2::track::PID::Kaon);
639+
makePidTablesDefault(pidFullPr, tablePIDFullPr, pidTinyPr, tablePIDTinyPr, o2::track::PID::Proton);
640+
makePidTablesDefault(pidFullDe, tablePIDFullDe, pidTinyDe, tablePIDTinyDe, o2::track::PID::Deuteron);
641+
makePidTablesDefault(pidFullTr, tablePIDFullTr, pidTinyTr, tablePIDTinyTr, o2::track::PID::Triton);
642+
makePidTablesDefault(pidFullHe, tablePIDFullHe, pidTinyHe, tablePIDTinyHe, o2::track::PID::Helium3);
643+
makePidTablesDefault(pidFullAl, tablePIDFullAl, pidTinyAl, tablePIDTinyAl, o2::track::PID::Alpha);
644+
645+
if (trk.hasTPC() && (!skipTPCOnly || trk.hasITS() || trk.hasTRD() || trk.hasTOF())) {
646+
count_tracks++; // Increment network track counter only if track has TPC, and (not skipping TPConly) or (is not TPConly)
647+
}
648+
}
649+
}
650+
PROCESS_SWITCH(tpcPid, processStandard2, "Creating PID tables with Corrected dEdx", false);
555651
void processMcTuneOnData(CollMC const& collisionsMc, TrksMC const& tracksMc, aod::BCsWithTimestamps const& bcs, aod::McParticles const&)
556652
{
557653
gRandom->SetSeed(0); // Ensure unique seed from UUID for each process call

Common/TableProducer/PID/pidTPCBase.cxx

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@
1515
/// \brief Base to build tasks for TPC PID tasks.
1616
///
1717

18+
#include <string>
1819
#include <utility>
1920
#include <vector>
20-
#include <string>
2121

2222
// O2 includes
23-
#include "CCDB/BasicCCDBManager.h"
24-
#include "Framework/AnalysisTask.h"
25-
#include "ReconstructionDataFormats/Track.h"
26-
#include "Common/DataModel/FT0Corrected.h"
2723
#include "TableHelper.h"
2824
#include "pidTPCBase.h"
25+
26+
#include "Common/CCDB/ctpRateFetcher.h"
27+
#include "Common/DataModel/FT0Corrected.h"
28+
29+
#include "CCDB/BasicCCDBManager.h"
30+
#include "Framework/AnalysisTask.h"
2931
#include "Framework/runDataProcessing.h"
32+
#include "ReconstructionDataFormats/Track.h"
3033

3134
using namespace o2;
3235
using namespace o2::framework;
@@ -76,7 +79,105 @@ struct PidMultiplicity {
7679
PROCESS_SWITCH(PidMultiplicity, processStandard, "Process with tracks, needs propagated tracks", true);
7780
};
7881

82+
struct DeDxCorrection {
83+
Produces<aod::DEdxsCorrected> dEdxCorrected;
84+
using BCsRun3 = soa::Join<aod::BCs, aod::Timestamps, aod::BcSels, aod::Run3MatchedToBCSparse>;
85+
using ColEvSels = soa::Join<aod::Collisions, aod::EvSels, aod::Mults>;
86+
using FullTracksIU = soa::Join<aod::TracksIU, aod::TracksExtra>;
87+
88+
uint64_t minGlobalBC = 0;
89+
Service<o2::ccdb::BasicCCDBManager> ccdb;
90+
ctpRateFetcher mRateFetcher;
91+
92+
Str_dEdx_correction str_dedx_correction;
93+
94+
// void init(InitContext& initContext)
95+
void init(o2::framework::InitContext&)
96+
{
97+
ccdb->setURL("http://alice-ccdb.cern.ch");
98+
ccdb->setCaching(true);
99+
ccdb->setLocalObjectValidityChecking();
100+
str_dedx_correction.init();
101+
}
102+
103+
void processRun3(
104+
ColEvSels const& cols,
105+
FullTracksIU const& tracks,
106+
aod::BCsWithTimestamps const& bcs)
107+
{
108+
const uint64_t outTable_size = tracks.size();
109+
dEdxCorrected.reserve(outTable_size);
110+
111+
for (auto const& trk : tracks) {
112+
double hadronicRate;
113+
int multTPC;
114+
int occupancy;
115+
if (trk.has_collision()) {
116+
auto collision = cols.iteratorAt(trk.collisionId());
117+
auto bc = collision.bc_as<aod::BCsWithTimestamps>();
118+
const int runnumber = bc.runNumber();
119+
hadronicRate = mRateFetcher.fetch(ccdb.service, bc.timestamp(), runnumber, "ZNC hadronic") * 1.e-3; // kHz
120+
multTPC = collision.multTPC();
121+
occupancy = collision.trackOccupancyInTimeRange();
122+
} else {
123+
auto bc = bcs.begin();
124+
const int runnumber = bc.runNumber();
125+
hadronicRate = mRateFetcher.fetch(ccdb.service, bc.timestamp(), runnumber, "ZNC hadronic") * 1.e-3; // kHz
126+
multTPC = 0;
127+
occupancy = 0;
128+
}
129+
130+
float fTPCSignal = trk.tpcSignal();
131+
float fNormMultTPC = multTPC / 11000.;
132+
133+
float fTrackOccN = occupancy / 1000.;
134+
float fOccTPCN = fNormMultTPC * 10; //(fNormMultTPC*10).clip(0,12)
135+
if (fOccTPCN > 12)
136+
fOccTPCN = 12;
137+
else if (fOccTPCN < 0)
138+
fOccTPCN = 0;
139+
140+
float fTrackOccMeanN = hadronicRate / 5;
141+
float side = trk.tgl() > 0 ? 1 : 0;
142+
float a1pt = std::abs(trk.signed1Pt());
143+
float a1pt2 = a1pt * a1pt;
144+
float atgl = std::abs(trk.tgl());
145+
float mbb0R = 50 / fTPCSignal;
146+
if (mbb0R > 1.05)
147+
mbb0R = 1.05;
148+
else if (mbb0R < 0.05)
149+
mbb0R = 0.05;
150+
// float mbb0R = max(0.05, min(50 / fTPCSignal, 1.05));
151+
float a1ptmbb0R = a1pt * mbb0R;
152+
float atglmbb0R = atgl * mbb0R;
153+
154+
std::vector<float> vec_occu = {fTrackOccN, fOccTPCN, fTrackOccMeanN};
155+
std::vector<float> vec_track = {mbb0R, a1pt, atgl, atglmbb0R, a1ptmbb0R, side, a1pt2};
156+
157+
float fTPCSignalN_CR0 = str_dedx_correction.fReal_fTPCSignalN(vec_occu, vec_track);
158+
159+
float mbb0R1 = 50 / (fTPCSignal / fTPCSignalN_CR0);
160+
if (mbb0R1 > 1.05)
161+
mbb0R1 = 1.05;
162+
else if (mbb0R1 < 0.05)
163+
mbb0R1 = 0.05;
164+
165+
std::vector<float> vec_track1 = {mbb0R1, a1pt, atgl, atgl * mbb0R1, a1pt * mbb0R1, side, a1pt2};
166+
float fTPCSignalN_CR1 = str_dedx_correction.fReal_fTPCSignalN(vec_occu, vec_track1);
167+
168+
float corrected_dEdx = fTPCSignal / fTPCSignalN_CR1;
169+
dEdxCorrected(corrected_dEdx);
170+
}
171+
}
172+
PROCESS_SWITCH(DeDxCorrection, processRun3, "dEdx correction process", false);
173+
174+
void processDummy(ColEvSels const&) {}
175+
176+
PROCESS_SWITCH(DeDxCorrection, processDummy, "Do nothing", true);
177+
};
178+
79179
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
80180
{
81-
return WorkflowSpec{adaptAnalysisTask<PidMultiplicity>(cfgc)};
181+
return WorkflowSpec{adaptAnalysisTask<PidMultiplicity>(cfgc),
182+
adaptAnalysisTask<DeDxCorrection>(cfgc)};
82183
}

0 commit comments

Comments
 (0)