Skip to content

Commit 508938f

Browse files
committed
[PWGLF] temporary location for tutorial files, will restage them to the tutorial folder after O2AT
1 parent c2aed8a commit 508938f

File tree

6 files changed

+895
-0
lines changed

6 files changed

+895
-0
lines changed

PWGLF/Tasks/Resonances/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,23 @@ o2physics_add_dpl_workflow(phi-1020-spherocity-analysis
267267
SOURCES phi1020SpherocityAnalysis.cxx
268268
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
269269
COMPONENT_NAME Analysis)
270+
o2physics_add_dpl_workflow(phitutorial
271+
SOURCES phitutorial.cxx
272+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
273+
COMPONENT_NAME Analysis)
274+
o2physics_add_dpl_workflow(phitutorial-step0
275+
SOURCES phitutorial_step0.cxx
276+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
277+
COMPONENT_NAME Analysis)
278+
o2physics_add_dpl_workflow(phitutorial-step1
279+
SOURCES phitutorial_step1.cxx
280+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
281+
COMPONENT_NAME Analysis)
282+
o2physics_add_dpl_workflow(phitutorial-step2
283+
SOURCES phitutorial_step2.cxx
284+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
285+
COMPONENT_NAME Analysis)
286+
o2physics_add_dpl_workflow(phitutorial-step3
287+
SOURCES phitutorial_step3.cxx
288+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore
289+
COMPONENT_NAME Analysis)
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
// Copyright 2019-2025 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+
/// \file phitutorial.cxx
12+
/// \brief Phi meson analysis tutorial
13+
/// \author Adrian Fereydon Nassirpour <adrian.fereydon.nassirpour@cern.ch>
14+
15+
// IMPORTANT INCLUDES
16+
#include "Common/DataModel/Centrality.h"
17+
#include "Common/DataModel/EventSelection.h"
18+
#include "Common/DataModel/Multiplicity.h"
19+
#include "Common/DataModel/PIDResponse.h"
20+
#include "Common/DataModel/TrackSelectionTables.h"
21+
22+
#include "Framework/ASoA.h"
23+
#include "Framework/AnalysisDataModel.h"
24+
#include "Framework/AnalysisTask.h"
25+
#include "ReconstructionDataFormats/Track.h"
26+
#include <Framework/ASoAHelpers.h>
27+
#include <Framework/runDataProcessing.h>
28+
29+
// ROOT Includes (optional)
30+
#include <TLorentzVector.h>
31+
32+
// C++ includes
33+
#include <string>
34+
#include <vector>
35+
36+
using namespace o2;
37+
using namespace o2::framework;
38+
using namespace o2::framework::expressions;
39+
40+
// MAIN STRUCT
41+
struct phitutorial {
42+
43+
//*************************************//
44+
// SLICECACHE AND REGISTRY DEFS
45+
//*************************************//
46+
SliceCache cache;
47+
HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject};
48+
49+
//*************************************//
50+
// INIT FUNCTION AND HISTOGRAM BOOKING
51+
//*************************************//
52+
void init(o2::framework::InitContext&)
53+
{
54+
const AxisSpec ptAxis = {200, 0, 20.0};
55+
const AxisSpec MinvAxis = {200, 0.85, 1.25};
56+
57+
histos.add("Nch_pT", "Nch_pT", kTH1F, {ptAxis});
58+
histos.add("Nch_USS_Minv", "Nch_USS_Minv", kTH1F, {MinvAxis});
59+
histos.add("Nch_LSS_Minv", "Nch_LSS_Minv", kTH1F, {MinvAxis});
60+
61+
histos.add("Nch_ME_Minv", "Nch_ME_Minv", kTH1F, {MinvAxis});
62+
63+
}; // end of init
64+
65+
//*************************************//
66+
// TIME TO BUILD TRACK AND EVENT CANDIDATES
67+
//*************************************//
68+
using EventCandidates = soa::Join<aod::Collisions, aod::EvSels, aod::FT0Mults, aod::CentFT0Ms>;
69+
using TrackCandidates = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksDCA, aod::TrackSelection, aod::pidTPCFullKa, aod::pidTOFFullKa>;
70+
double massKa = o2::constants::physics::MassKPlus;
71+
72+
//***************************************//
73+
// PREAMBLE COMPLETE, NOW WE DO HELPER FCNS
74+
//**************************************//
75+
template <typename EventType>
76+
bool eventSelection(const EventType event)
77+
{
78+
if (!event.sel8())
79+
return false;
80+
if (std::abs(event.posZ()) > 10)
81+
return false;
82+
if (!event.selection_bit(aod::evsel::kIsGoodZvtxFT0vsPV))
83+
return false;
84+
if (!event.selection_bit(aod::evsel::kNoSameBunchPileup))
85+
return false;
86+
if (!event.selection_bit(aod::evsel::kNoCollInTimeRangeStandard))
87+
return false;
88+
89+
return true;
90+
};
91+
//********************************************//
92+
template <typename TracksType>
93+
bool trackSelection(const TracksType track)
94+
{
95+
if (!track.isGlobalTrack())
96+
return false;
97+
if (track.pt() < 0.15)
98+
return false;
99+
if (std::abs(track.eta()) > 1.0)
100+
return false;
101+
102+
return true;
103+
};
104+
//********************************************//
105+
template <typename TrackPID>
106+
bool trackPIDKaon(const TrackPID& candidate)
107+
{
108+
bool tpcPIDPassed{false}, tofPIDPassed{false};
109+
// TPC
110+
if (std::abs(candidate.tpcNSigmaKa()) < 3)
111+
tpcPIDPassed = true;
112+
// TOF
113+
if (candidate.hasTOF()) {
114+
if (std::abs(candidate.tofNSigmaKa()) < 3) {
115+
tofPIDPassed = true;
116+
}
117+
} else {
118+
tofPIDPassed = true;
119+
}
120+
// TPC & TOF
121+
if (tpcPIDPassed && tofPIDPassed) {
122+
return true;
123+
}
124+
return false;
125+
}
126+
127+
//********************************************//
128+
// HELPER FCNS COMPLETE, NOW WE DO PROCESS FCNS
129+
//********************************************//
130+
131+
// SAME EVENT
132+
int nEvents = 0;
133+
void processDataSameEvent(EventCandidates::iterator const& collision, TrackCandidates const& tracks)
134+
{
135+
nEvents++;
136+
if ((nEvents + 1) % 10000 == 0) {
137+
std::cout << "Processed Data Events: " << nEvents << std::endl;
138+
}
139+
140+
if (!eventSelection(collision))
141+
return;
142+
143+
for (const auto& track : tracks) {
144+
histos.fill(HIST("Nch_pT"), track.pt());
145+
}
146+
147+
for (const auto& [trk1, trk2] : combinations(o2::soa::CombinationsStrictlyUpperIndexPolicy(tracks, tracks))) {
148+
if (!trackSelection(trk1) || !trackSelection(trk2)) {
149+
continue;
150+
}
151+
if (!trackPIDKaon(trk1) || !trackPIDKaon(trk2)) {
152+
continue;
153+
}
154+
155+
ROOT::Math::PxPyPzMVector lDecayDaughter1, lDecayDaughter2, lResonance;
156+
lDecayDaughter1 = ROOT::Math::PxPyPzMVector(trk1.px(), trk1.py(), trk1.pz(), massKa);
157+
lDecayDaughter2 = ROOT::Math::PxPyPzMVector(trk2.px(), trk2.py(), trk2.pz(), massKa);
158+
159+
lResonance = lDecayDaughter1 + lDecayDaughter2;
160+
double conjugate = trk1.sign() * trk2.sign();
161+
if (conjugate < 0) {
162+
histos.fill(HIST("Nch_USS_Minv"), lResonance.M());
163+
} else {
164+
histos.fill(HIST("Nch_LSS_Minv"), lResonance.M());
165+
}
166+
} // Invariant mass combinations
167+
168+
} // proccessSameEvent
169+
PROCESS_SWITCH(phitutorial, processDataSameEvent, "process Data Same Event", false);
170+
171+
//**************************************************************************************************************************//
172+
173+
// MIXED EVENT
174+
175+
//*********************************************************//
176+
// DEFINITION OF SLICE CACHE, BINNING AND MIXING STRUCTURE
177+
//*********************************************************//
178+
Preslice<aod::Tracks> perCollision = aod::track::collisionId;
179+
std::vector<double> zBins{10, -10, 10};
180+
std::vector<double> multBins{VARIABLE_WIDTH, 0, 5, 10, 20, 30, 40, 50, 100.1};
181+
using BinningType = ColumnBinningPolicy<aod::collision::PosZ, aod::cent::CentFT0M>;
182+
BinningType binning{{zBins, multBins}, true};
183+
SameKindPair<EventCandidates, TrackCandidates, BinningType> pair{binning, 5, -1, &cache};
184+
185+
void processDataMixedEvent(EventCandidates const& collisions, TrackCandidates const& tracks)
186+
{
187+
LOGF(info, "Input data Collisions %d, Tracks %d ", collisions.size(), tracks.size());
188+
189+
for (const auto& [c1, tracks1, c2, tracks2] : pair) {
190+
191+
if (!eventSelection(c1) || !eventSelection(c2))
192+
continue;
193+
194+
for (const auto& [track1, track2] : combinations(o2::soa::CombinationsFullIndexPolicy(tracks1, tracks2))) {
195+
196+
if (track1.sign() * track2.sign() > 0)
197+
continue;
198+
199+
if (!trackSelection(track1) || !trackSelection(track2)) {
200+
continue;
201+
}
202+
if (!trackPIDKaon(track1) || !trackPIDKaon(track2)) {
203+
continue;
204+
}
205+
206+
ROOT::Math::PxPyPzMVector lDecayDaughter1, lDecayDaughter2, mother;
207+
lDecayDaughter1 = ROOT::Math::PxPyPzMVector(track1.px(), track1.py(), track1.pz(), massKa);
208+
lDecayDaughter2 = ROOT::Math::PxPyPzMVector(track2.px(), track2.py(), track2.pz(), massKa);
209+
210+
mother = lDecayDaughter1 + lDecayDaughter2;
211+
212+
histos.fill(HIST("Nch_ME_Minv"), mother.M());
213+
}
214+
}
215+
} // processMixedEvent
216+
PROCESS_SWITCH(phitutorial, processDataMixedEvent, "process Data Mixed Event", false);
217+
};
218+
219+
//***************************************//
220+
// TASK COMPLETE!
221+
//**************************************//
222+
223+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
224+
{
225+
return WorkflowSpec{adaptAnalysisTask<phitutorial>(cfgc)};
226+
};
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Copyright 2019-2025 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+
/// \file phitutorial.cxx
12+
/// \brief Phi meson analysis tutorial
13+
/// \author Adrian Fereydon Nassirpour <adrian.fereydon.nassirpour@cern.ch>
14+
15+
// IMPORTANT INCLUDES
16+
#include "Common/DataModel/Centrality.h"
17+
#include "Common/DataModel/EventSelection.h"
18+
#include "Common/DataModel/Multiplicity.h"
19+
#include "Common/DataModel/PIDResponse.h"
20+
#include "Common/DataModel/TrackSelectionTables.h"
21+
22+
#include "Framework/ASoA.h"
23+
#include "Framework/AnalysisDataModel.h"
24+
#include "Framework/AnalysisTask.h"
25+
#include "ReconstructionDataFormats/Track.h"
26+
#include <Framework/ASoAHelpers.h>
27+
#include <Framework/runDataProcessing.h>
28+
29+
// ROOT Includes (optional)
30+
#include <TLorentzVector.h>
31+
32+
// C++ includes
33+
#include <string>
34+
#include <vector>
35+
36+
using namespace o2;
37+
using namespace o2::framework;
38+
using namespace o2::framework::expressions;
39+
40+
// MAIN STRUCT
41+
struct phitutorial_step0 {
42+
43+
//*************************************//
44+
// SLICECACHE AND REGISTRY DEFS
45+
//*************************************//
46+
SliceCache cache;
47+
HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject};
48+
49+
//*************************************//
50+
// INIT FUNCTION AND HISTOGRAM BOOKING
51+
//*************************************//
52+
void init(o2::framework::InitContext&)
53+
{
54+
const AxisSpec ptAxis = {200, 0, 20.0};
55+
const AxisSpec MinvAxis = {200, 0.85, 1.25};
56+
57+
histos.add("Nch_pT", "Nch_pT", kTH1F, {ptAxis});
58+
59+
}; // end of init
60+
61+
//*************************************//
62+
// TIME TO BUILD TRACK AND EVENT CANDIDATES
63+
//*************************************//
64+
using EventCandidates = soa::Join<aod::Collisions, aod::EvSels, aod::FT0Mults, aod::CentFT0Ms>;
65+
using TrackCandidates = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksDCA, aod::TrackSelection, aod::pidTPCFullKa, aod::pidTOFFullKa>;
66+
double massKa = o2::constants::physics::MassKPlus;
67+
68+
//***************************************//
69+
// PREAMBLE COMPLETE, NOW WE DO HELPER FCNS
70+
//**************************************//
71+
template <typename EventType>
72+
bool eventSelection(const EventType event)
73+
{
74+
if (!event.sel8()) //This is required to extract good events
75+
return false;
76+
77+
return true;
78+
};
79+
//********************************************//
80+
//Space for more helper functions!
81+
82+
83+
//********************************************//
84+
// HELPER FCNS COMPLETE, NOW WE DO PROCESS FCNS
85+
//********************************************//
86+
87+
// SAME EVENT
88+
int nEvents = 0;
89+
void processDataSameEvent(EventCandidates::iterator const& collision, TrackCandidates const& tracks){
90+
nEvents++;
91+
if ((nEvents + 1) % 10000 == 0) {
92+
std::cout << "Processed Data Events: " << nEvents << std::endl;
93+
}
94+
95+
if (!eventSelection(collision))
96+
return;
97+
98+
// Now, time to start coding the task!
99+
// Keep in mind that:
100+
// M_inv = sqrt( (E1+E2)^2 - |P1 + P2|^2 )
101+
// Where you use the energies and momenta of the individual Kaons.
102+
103+
// You should fill: histos.fill(HIST("Minv"), M_inv), calculated as above.
104+
105+
//Usefull tips:
106+
// E = sqrt(p^2 + m^2). The Kaon mass is found above in the constant massKa
107+
// pz = pT*sinh(eta)
108+
// track.pt()
109+
// track.eta();
110+
// std::sinh(x)
111+
112+
// For more concise techinques, check out:
113+
// ROOT::Math::PxPyPzMVector //Check google
114+
// combinations(o2::soa::CombinationsStrictlyUpperIndexPolicy.... //check ALICE O2 documentation
115+
116+
for (const auto& track : tracks) {
117+
histos.fill(HIST("Nch_pT"), track.pt());
118+
//..
119+
//..
120+
//..
121+
}
122+
123+
124+
} // proccessSameEvent
125+
PROCESS_SWITCH(phitutorial_step0, processDataSameEvent, "process Data Same Event", false);
126+
127+
//***************************************//
128+
// TASK COMPLETE!
129+
//**************************************//
130+
131+
};
132+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
133+
{
134+
return WorkflowSpec{adaptAnalysisTask<phitutorial_step0>(cfgc)};
135+
};

0 commit comments

Comments
 (0)