Skip to content

Commit 87fb1c3

Browse files
committed
style: Add ALICE O2 copyright header and remove trailing spaces from PIDFeatureExtractor.cxx
1 parent 0a560dd commit 87fb1c3

File tree

1 file changed

+18
-55
lines changed

1 file changed

+18
-55
lines changed

Tools/PIDFeatureExtractor/PIDFeatureExtractor.cxx

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ struct PIDFeatureExtractor {
4040
// ============================================================================
4141
// OUTPUT OBJECTS - File and data structures for feature storage
4242
// ============================================================================
43-
4443
/// Output ROOT file for storing the TTree with extracted features
4544
std::unique_ptr<TFile> outputFile;
4645

@@ -73,7 +72,6 @@ struct PIDFeatureExtractor {
7372
// ============================================================================
7473
// TPC VARIABLES - Time Projection Chamber PID information
7574
// ============================================================================
76-
7775
float tpc_signal; /// dE/dx energy loss in TPC (specific ionization)
7876

7977
// n-sigma values: standard deviations from expected energy loss for each particle
@@ -102,7 +100,6 @@ struct PIDFeatureExtractor {
102100
// ============================================================================
103101
// BAYESIAN PID VARIABLES - Combined PID probabilities
104102
// ============================================================================
105-
106103
/// Bayesian probability that track is a pion (probability sum = 1.0)
107104
float bayes_prob_pi;
108105
/// Bayesian probability that track is a kaon
@@ -136,14 +133,12 @@ struct PIDFeatureExtractor {
136133
// ============================================================================
137134
// HISTOGRAM REGISTRY - Quality control histograms
138135
// ============================================================================
139-
140136
/// Registry for quality control histograms
141137
HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject};
142138

143139
// ============================================================================
144140
// CONFIGURABLE PARAMETERS - User-adjustable settings
145141
// ============================================================================
146-
147142
/// Base path and filename for output files (without extension)
148143
Configurable<std::string> outputPath{"outputPath", "pid_features", "Output file base"};
149144

@@ -168,7 +163,6 @@ struct PIDFeatureExtractor {
168163
// ============================================================================
169164
// INITIALIZATION FUNCTION
170165
// ============================================================================
171-
172166
/**
173167
* @brief Initialize output files and histograms
174168
*
@@ -178,18 +172,12 @@ struct PIDFeatureExtractor {
178172
void init(InitContext const&)
179173
{
180174
std::string base = outputPath.value;
181-
182-
// ========================================================================
183175
// ROOT OUTPUT SETUP
184-
// ========================================================================
185176
if (exportROOT) {
186-
// Create ROOT file for storing the TTree
187177
outputFile = std::make_unique<TFile>((base + ".root").c_str(), "RECREATE");
188-
189-
// Create TTree with descriptive name and title
190178
featureTree = std::make_unique<TTree>("pid_features", "PID features");
191179

192-
// Create branches for KINEMATIC VARIABLES
180+
// KINEMATIC VARIABLES
193181
featureTree->Branch("event_id", &event_id);
194182
featureTree->Branch("track_id", &track_id);
195183
featureTree->Branch("px", &px);
@@ -203,7 +191,7 @@ struct PIDFeatureExtractor {
203191
featureTree->Branch("charge", &charge);
204192
featureTree->Branch("track_type", &track_type);
205193

206-
// Create branches for TPC VARIABLES
194+
// TPC VARIABLES
207195
featureTree->Branch("tpc_signal", &tpc_signal);
208196
featureTree->Branch("tpc_nsigma_pi", &tpc_nsigma_pi);
209197
featureTree->Branch("tpc_nsigma_ka", &tpc_nsigma_ka);
@@ -212,38 +200,36 @@ struct PIDFeatureExtractor {
212200
featureTree->Branch("tpc_nclusters", &tpc_nclusters);
213201
featureTree->Branch("tpc_chi2", &tpc_chi2);
214202

215-
// Create branches for TOF VARIABLES
203+
// TOF VARIABLES
216204
featureTree->Branch("tof_beta", &tof_beta);
217205
featureTree->Branch("tof_mass", &tof_mass);
218206
featureTree->Branch("tof_nsigma_pi", &tof_nsigma_pi);
219207
featureTree->Branch("tof_nsigma_ka", &tof_nsigma_ka);
220208
featureTree->Branch("tof_nsigma_pr", &tof_nsigma_pr);
221209
featureTree->Branch("tof_nsigma_el", &tof_nsigma_el);
222210

223-
// Create branches for BAYESIAN PID VARIABLES
211+
// BAYESIAN PID VARIABLES
224212
featureTree->Branch("bayes_prob_pi", &bayes_prob_pi);
225213
featureTree->Branch("bayes_prob_ka", &bayes_prob_ka);
226214
featureTree->Branch("bayes_prob_pr", &bayes_prob_pr);
227215
featureTree->Branch("bayes_prob_el", &bayes_prob_el);
228216

229-
// Create branches for MONTE CARLO TRUTH (simulated data only)
217+
// MONTE CARLO TRUTH (simulated data only)
230218
featureTree->Branch("mc_pdg", &mc_pdg);
231219
featureTree->Branch("mc_px", &mc_px);
232220
featureTree->Branch("mc_py", &mc_py);
233221
featureTree->Branch("mc_pz", &mc_pz);
234222

235-
// Create branches for DETECTOR FLAGS
223+
// DETECTOR FLAGS
236224
featureTree->Branch("has_tpc", &has_tpc);
237225
featureTree->Branch("has_tof", &has_tof);
238226

239-
// Create branches for IMPACT PARAMETERS
227+
// IMPACT PARAMETERS
240228
featureTree->Branch("dca_xy", &dca_xy);
241229
featureTree->Branch("dca_z", &dca_z);
242230
}
243231

244-
// ========================================================================
245232
// CSV OUTPUT SETUP
246-
// ========================================================================
247233
if (exportCSV) {
248234
csvFile.open((base + ".csv").c_str());
249235
// Write CSV header with all column names
@@ -267,6 +253,13 @@ struct PIDFeatureExtractor {
267253
const AxisSpec axisMass{100, -0.2, 2.0, "mass"}; // 100 bins, -0.2 to 2.0 GeV/c²
268254

269255
// Add histograms to registry
256+
// HISTOGRAM SETUP
257+
const AxisSpec axisPt{200, 0, 10, "pT"};
258+
const AxisSpec axisEta{60, -1.5, 1.5, "eta"};
259+
const AxisSpec axisdEdx{300, 0, 300, "dE/dx"};
260+
const AxisSpec axisBeta{120, 0, 1.2, "beta"};
261+
const AxisSpec axisMass{100, -0.2, 2.0, "mass"};
262+
270263
histos.add("QC/nTracks", "Tracks", kTH1F, {{10000, 0, 100000}});
271264
histos.add("QC/pt", "pT", kTH1F, {axisPt});
272265
histos.add("QC/eta", "eta", kTH1F, {axisEta});
@@ -278,7 +271,6 @@ struct PIDFeatureExtractor {
278271
// ============================================================================
279272
// BAYESIAN PID CALCULATION FUNCTION
280273
// ============================================================================
281-
282274
/**
283275
* @brief Compute Bayesian probabilities combining TPC and TOF information
284276
*
@@ -297,8 +289,6 @@ struct PIDFeatureExtractor {
297289
void computeBayesianPID(float nsTPC[4], float nsTOF[4], float pri[4], float out[4])
298290
{
299291
float sum = 0;
300-
301-
// Calculate likelihood for each particle species
302292
for (int i = 0; i < 4; i++) {
303293
// Gaussian likelihood: exp(-0.5 * chi²)
304294
// Handle invalid TOF values (NaN) by replacing with 0 contribution
@@ -309,8 +299,6 @@ struct PIDFeatureExtractor {
309299
out[i] = l * pri[i];
310300
sum += out[i];
311301
}
312-
313-
// Normalize probabilities so they sum to 1.0
314302
for (int i = 0; i < 4; i++) {
315303
out[i] = sum > 0 ? out[i] / sum : 0.f;
316304
}
@@ -319,7 +307,6 @@ struct PIDFeatureExtractor {
319307
// ============================================================================
320308
// MAIN PROCESSING FUNCTION
321309
// ============================================================================
322-
323310
/**
324311
* @brief Process collision and track data, extract PID features
325312
*
@@ -346,14 +333,10 @@ struct PIDFeatureExtractor {
346333
> const& tracks,
347334
aod::McParticles const& mcParticles)
348335
{
349-
// Use static counter to maintain event numbering across process calls
350336
static int eventCounter = 0;
351337
event_id = eventCounter++;
352338
int idx = 0;
353339

354-
// ======================================================================
355-
// TRACK LOOP - Process each track in the event
356-
// ======================================================================
357340
for (auto& t : tracks) {
358341

359342
// ====================================================================
@@ -366,24 +349,19 @@ struct PIDFeatureExtractor {
366349

367350
track_id = idx++;
368351

369-
// ====================================================================
370-
// EXTRACT KINEMATIC VARIABLES
371-
// ====================================================================
352+
// Kinematics
372353
px = t.px();
373354
py = t.py();
374355
pz = t.pz();
375356
pt = t.pt();
376357
p = t.p();
377358
eta = t.eta();
378359
phi = t.phi();
379-
// Calculate polar angle from pseudorapidity: θ = 2*arctan(exp(-η))
380360
theta = 2.f * atanf(expf(-eta));
381361
charge = t.sign(); // Track charge
382362
track_type = t.trackType(); // Track categorization
383363

384-
// ====================================================================
385-
// EXTRACT TPC INFORMATION
386-
// ====================================================================
364+
// TPC info
387365
has_tpc = t.hasTPC();
388366
if (has_tpc) {
389367
// TPC has valid measurement
@@ -395,15 +373,12 @@ struct PIDFeatureExtractor {
395373
tpc_nclusters = t.tpcNClsFound(); // Quality: number of clusters
396374
tpc_chi2 = t.tpcChi2NCl(); // Quality: fit chi-square
397375
} else {
398-
// TPC has no valid measurement - set sentinel values
399376
tpc_signal = tpc_nsigma_pi = tpc_nsigma_ka = tpc_nsigma_pr = tpc_nsigma_el = -999;
400377
tpc_nclusters = 0;
401378
tpc_chi2 = -999;
402379
}
403380

404-
// ====================================================================
405-
// EXTRACT TOF INFORMATION
406-
// ====================================================================
381+
// TOF info
407382
has_tof = t.hasTOF();
408383
if (has_tof) {
409384
// TOF has valid measurement
@@ -414,7 +389,6 @@ struct PIDFeatureExtractor {
414389
tof_nsigma_pr = t.tofNSigmaPr(); // Deviation from proton hypothesis
415390
tof_nsigma_el = t.tofNSigmaEl(); // Deviation from electron hypothesis
416391
} else {
417-
// TOF has no valid measurement - set sentinel values
418392
tof_beta = tof_mass = -999;
419393
tof_nsigma_pi = tof_nsigma_ka = tof_nsigma_pr = tof_nsigma_el = -999;
420394
}
@@ -432,26 +406,20 @@ struct PIDFeatureExtractor {
432406
float arrTOF[4] = {tof_nsigma_pi, tof_nsigma_ka, tof_nsigma_pr, tof_nsigma_el};
433407
float priors[4] = {1.f, 0.2f, 0.1f, 0.05f}; // Prior prob: π, K, p, e
434408
float probs[4];
435-
436-
// Compute combined PID probabilities
437409
computeBayesianPID(arrTPC, arrTOF, priors, probs);
438410
bayes_prob_pi = probs[0];
439411
bayes_prob_ka = probs[1];
440412
bayes_prob_pr = probs[2];
441413
bayes_prob_el = probs[3];
442414

443-
// ====================================================================
444-
// EXTRACT MONTE CARLO TRUTH (if available)
445-
// ====================================================================
446-
// Safely access MC particle information with existence check
415+
// MC truth
447416
if (t.has_mcParticle()) {
448417
auto mc = t.mcParticle();
449418
mc_pdg = mc.pdgCode(); // Particle identifier code
450419
mc_px = mc.px(); // True momentum components
451420
mc_py = mc.py();
452421
mc_pz = mc.pz();
453422
} else {
454-
// No MC match - set sentinel values
455423
mc_pdg = 0;
456424
mc_px = mc_py = mc_pz = 0;
457425
}
@@ -502,7 +470,6 @@ struct PIDFeatureExtractor {
502470
// ============================================================================
503471
// FINALIZATION FUNCTION
504472
// ============================================================================
505-
506473
/**
507474
* @brief Clean up and finalize output files
508475
*
@@ -511,13 +478,11 @@ struct PIDFeatureExtractor {
511478
void finalize()
512479
{
513480
if (exportROOT) {
514-
// Write TTree to ROOT file and close
515481
outputFile->cd();
516482
featureTree->Write();
517483
outputFile->Close();
518484
}
519485
if (exportCSV) {
520-
// Close CSV file
521486
csvFile.close();
522487
}
523488
}
@@ -526,7 +491,6 @@ struct PIDFeatureExtractor {
526491
// ============================================================================
527492
// WORKFLOW DEFINITION
528493
// ============================================================================
529-
530494
/**
531495
* @brief Define the O2Physics workflow
532496
*
@@ -537,4 +501,3 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
537501
{
538502
return WorkflowSpec{adaptAnalysisTask<PIDFeatureExtractor>(cfgc)};
539503
}
540-

0 commit comments

Comments
 (0)