3232#include < Framework/OutputObjHeader.h>
3333#include < Framework/runDataProcessing.h>
3434
35- #include < TFile.h>
3635#include < TH1.h>
3736#include < TH2.h>
3837#include < THn.h>
3938#include < TList.h>
4039#include < TMath.h>
4140#include < TProfile3D.h>
4241
42+ #include < Rtypes.h>
43+
4344#include < memory>
4445#include < string>
4546#include < unordered_map>
@@ -247,9 +248,9 @@ struct ZdcExtraTableReader {
247248
248249 Configurable<bool > ifBeamSpotCorrection{" ifBeamSpotCorrection" , true , " Beam spot correction" };
249250
250- Configurable<bool > ifSel8{" ifSel8" , true , " Event selection: sel8 " };
251- Configurable<bool > ifVtxZle10{ " ifVtxZle10 " , true , " Event selection: zVtx < 10 cm" };
252- Configurable<bool > ifOccupancyCut{" ifOccupancyCut" , false , " Event selection: occupancy cut" };
251+ Configurable<bool > ifSel8{" ifSel8" , true , " Event selection: Sel8 " };
252+ Configurable<bool > ifZVtxCut{ " ifZVtxCut " , true , " Event selection: zVtx cut set in producer (tipically < 10 cm) " };
253+ Configurable<bool > ifOccupancyCut{" ifOccupancyCut" , false , " Event selection: occupancy cut set in producer " };
253254 Configurable<bool > ifNoSameBunchPileup{" ifNoSameBunchPileup" , false , " Event selection: no same bunch pileup" };
254255 Configurable<bool > ifIsGoodZvtxFT0vsPV{" ifIsGoodZvtxFT0vsPV" , false , " Event selection: good Zvtx FT0 vs PV" };
255256 Configurable<bool > ifNoCollInTimeRangeStandard{" ifNoCollInTimeRangeStandard" , false , " Event selection: no collision in time range standard" };
@@ -293,6 +294,34 @@ struct ZdcExtraTableReader {
293294 TH1 * hMeanQyVyZNA{nullptr };
294295 TH1 * hMeanQxVyZNC{nullptr };
295296 TH1 * hMeanQyVyZNC{nullptr };
297+
298+ // Destructor to handle cleanup automatically
299+ ~CalibStepData () {
300+ delete hMeanQxZNA;
301+ delete hMeanQyZNA;
302+ delete hMeanQxZNC;
303+ delete hMeanQyZNC;
304+
305+ delete hMeanQxCentZNA;
306+ delete hMeanQyCentZNA;
307+ delete hMeanQxCentZNC;
308+ delete hMeanQyCentZNC;
309+
310+ delete hMeanQxVzZNA;
311+ delete hMeanQyVzZNA;
312+ delete hMeanQxVzZNC;
313+ delete hMeanQyVzZNC;
314+
315+ delete hMeanQxVxZNA;
316+ delete hMeanQyVxZNA;
317+ delete hMeanQxVxZNC;
318+ delete hMeanQyVxZNC;
319+
320+ delete hMeanQxVyZNA;
321+ delete hMeanQyVyZNA;
322+ delete hMeanQxVyZNC;
323+ delete hMeanQyVyZNC;
324+ }
296325 };
297326
298327 // Cache container: Vector index = Step index (0-based, so step 1 is at index 0)
@@ -306,22 +335,19 @@ struct ZdcExtraTableReader {
306335 TProfile3D* mShiftProfileZNA {nullptr };
307336 TProfile3D* mShiftProfileZNC {nullptr };
308337
309- HistogramRegistry histos{
310- " histos" ,
311- {},
312- OutputObjHandlingPolicy::AnalysisObject};
313-
314- enum EvSelBits { // TO DO: move to a common header file
315- evSel_zvtx,
316- evSel_sel8,
317- evSel_occupancy,
318- evSel_kNoSameBunchPileup,
319- evSel_kIsGoodZvtxFT0vsPV,
320- evSel_kNoCollInTimeRangeStandard,
321- evSel_kIsVertexITSTPC,
322- evSel_kIsGoodITSLayersAll,
323- evSel_allEvents,
324- nEventSelections
338+ HistogramRegistry histos{" histos" };
339+
340+ enum EvSelBits { // same bits as in zdcExtraTableProducer.cxx
341+ ZVtxCut,
342+ Sel8,
343+ OccupancyCut,
344+ NoSameBunchPileup,
345+ IsGoodZvtxFT0vsPV,
346+ NoCollInTimeRangeStandard,
347+ IsVertexITSTPC,
348+ IsGoodITSLayersAll,
349+ AllEvents,
350+ NEventSelections
325351 };
326352
327353 int mCurrentRunNumber {-1 };
@@ -344,50 +370,18 @@ struct ZdcExtraTableReader {
344370
345371 void clearCache ()
346372 {
347- if (hMeanVx) {
348- delete hMeanVx;
349- hMeanVx = nullptr ;
350- }
351- if (hMeanVy) {
352- delete hMeanVy;
353- hMeanVy = nullptr ;
354- }
355-
356- for (const auto & step : mCalibCache ) {
357- delete step.hMeanQxZNA ;
358- delete step.hMeanQyZNA ;
359- delete step.hMeanQxZNC ;
360- delete step.hMeanQyZNC ;
361-
362- delete step.hMeanQxCentZNA ;
363- delete step.hMeanQyCentZNA ;
364- delete step.hMeanQxCentZNC ;
365- delete step.hMeanQyCentZNC ;
366-
367- delete step.hMeanQxVzZNA ;
368- delete step.hMeanQyVzZNA ;
369- delete step.hMeanQxVzZNC ;
370- delete step.hMeanQyVzZNC ;
371-
372- delete step.hMeanQxVxZNA ;
373- delete step.hMeanQyVxZNA ;
374- delete step.hMeanQxVxZNC ;
375- delete step.hMeanQyVxZNC ;
376-
377- delete step.hMeanQxVyZNA ;
378- delete step.hMeanQyVyZNA ;
379- delete step.hMeanQxVyZNC ;
380- delete step.hMeanQyVyZNC ;
381-
382- if (mShiftProfileZNA ) {
383- delete mShiftProfileZNA ;
384- mShiftProfileZNA = nullptr ;
385- }
386- if (mShiftProfileZNC ) {
387- delete mShiftProfileZNC ;
388- mShiftProfileZNC = nullptr ;
389- }
390- }
373+ delete hMeanVx;
374+ hMeanVx = nullptr ;
375+
376+ delete hMeanVy;
377+ hMeanVy = nullptr ;
378+
379+ delete mShiftProfileZNA ;
380+ mShiftProfileZNA = nullptr ;
381+
382+ delete mShiftProfileZNC ;
383+ mShiftProfileZNC = nullptr ;
384+
391385 mCalibCache .clear ();
392386 }
393387
@@ -398,7 +392,7 @@ struct ZdcExtraTableReader {
398392 }
399393 mCurrentRunNumber = mRunNumber ;
400394
401- if (gEventCounter .find (mRunNumber ) == gEventCounter . end ( )) {
395+ if (! gEventCounter .contains (mRunNumber )) {
402396 // if new run, initialize histograms
403397
404398 const AxisSpec axisCounter{1 , 0 , +1 , " " };
@@ -421,16 +415,16 @@ struct ZdcExtraTableReader {
421415
422416 const AxisSpec axisTime = {90 , 0 , 90 , " Time (minutes)" }; // 90 minutes
423417
424- gEventCounter [mRunNumber ] = histos.add <TH1 >(Form (" %i/eventCounter" , mRunNumber ), " Number of Event; ; #Events Passed Cut" , kTH1D , {{nEventSelections , 0 , nEventSelections }}).get ();
425- gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (evSel_allEvents + 1 , " All events " );
426- gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (evSel_zvtx + 1 , " vtxZ " );
427- gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (evSel_sel8 + 1 , " Sel8" );
428- gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (evSel_occupancy + 1 , " kOccupancy " );
429- gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (evSel_kNoSameBunchPileup + 1 , " kNoSameBunchPileup " );
430- gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (evSel_kIsGoodZvtxFT0vsPV + 1 , " kIsGoodZvtxFT0vsPV " );
431- gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (evSel_kNoCollInTimeRangeStandard + 1 , " kNoCollInTimeRangeStandard " );
432- gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (evSel_kIsVertexITSTPC + 1 , " kIsVertexITSTPC " );
433- gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (evSel_kIsGoodITSLayersAll + 1 , " kIsGoodITSLayersAll " );
418+ gEventCounter [mRunNumber ] = histos.add <TH1 >(Form (" %i/eventCounter" , mRunNumber ), " Number of Event; ; #Events Passed Cut" , kTH1D , {{NEventSelections , 0 , NEventSelections }}).get ();
419+ gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (AllEvents + 1 , " allEvents " );
420+ gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (ZVtxCut + 1 , " zVtxCut " );
421+ gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (Sel8 + 1 , " Sel8" );
422+ gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (OccupancyCut + 1 , " occupancyCut " );
423+ gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (NoSameBunchPileup + 1 , " NoSameBunchPileup " );
424+ gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (IsGoodZvtxFT0vsPV + 1 , " isGoodZvtxFT0vsPV " );
425+ gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (NoCollInTimeRangeStandard + 1 , " noCollInTimeRangeStandard " );
426+ gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (IsVertexITSTPC + 1 , " isVertexITSTPC " );
427+ gEventCounter [mRunNumber ]->GetXaxis ()->SetBinLabel (IsGoodITSLayersAll + 1 , " isGoodITSLayersAll " );
434428
435429 gCentroidZNA [mRunNumber ] = histos.add <TH2 >(Form (" %i/CentroidZNA" , mRunNumber ), " ZNA Centroid; Q_{X}; Q_{Y}" , kTH2F , {{50 , -1.5 , 1.5 }, {50 , -1.5 , 1.5 }}).get ();
436430 gCentroidZNC [mRunNumber ] = histos.add <TH2 >(Form (" %i/CentroidZNC" , mRunNumber ), " ZNC Centroid; Q_{X}; Q_{Y}" , kTH2F , {{50 , -1.5 , 1.5 }, {50 , -1.5 , 1.5 }}).get ();
@@ -551,7 +545,7 @@ struct ZdcExtraTableReader {
551545 // Vertex Calibration
552546 if (ifBeamSpotCorrection) {
553547 std::string folder = Form (" %s/step0" , qRecenteringCcdb.value .c_str ());
554- TList * lst = ccdb->getForRun <TList>(folder, run);
548+ auto * lst = ccdb->getForRun <TList>(folder, run);
555549 if (lst) {
556550 hMeanVx = safeClone<TH1 >(lst->FindObject (" hMeanVx" ));
557551 hMeanVy = safeClone<TH1 >(lst->FindObject (" hMeanVy" ));
@@ -567,7 +561,7 @@ struct ZdcExtraTableReader {
567561
568562 // Load 5D (Base)
569563 std::string folderBase = Form (" %s/step%d_base" , qRecenteringCcdb.value .c_str (), step);
570- TList * lstBase = ccdb->getForRun <TList>(folderBase, run);
564+ auto * lstBase = ccdb->getForRun <TList>(folderBase, run);
571565 if (lstBase) {
572566 mCalibCache [stepIdx].hMeanQxZNA = safeClone<THn>(lstBase->FindObject (" hMeanQxZNA" ));
573567 mCalibCache [stepIdx].hMeanQyZNA = safeClone<THn>(lstBase->FindObject (" hMeanQyZNA" ));
@@ -578,7 +572,7 @@ struct ZdcExtraTableReader {
578572 // Load 1D (Refine)
579573 if ((step != calibrationStep) || ifFineCalibration) {
580574 std::string folderRefine = Form (" %s/step%d_refine" , qRecenteringCcdb.value .c_str (), step);
581- TList * lstRefine = ccdb->getForRun <TList>(folderRefine, run);
575+ auto * lstRefine = ccdb->getForRun <TList>(folderRefine, run);
582576 if (lstRefine) {
583577 mCalibCache [stepIdx].hMeanQxCentZNA = safeClone<TH1 >(lstRefine->FindObject (" hMeanQxCentZNA" ));
584578 mCalibCache [stepIdx].hMeanQyCentZNA = safeClone<TH1 >(lstRefine->FindObject (" hMeanQyCentZNA" ));
@@ -611,30 +605,30 @@ struct ZdcExtraTableReader {
611605 // Attempt to fetch TList from CCDB
612606 auto * lst = ccdb->getForRun <TList>(folder, run);
613607
614- if (lst) {
608+ if (!lst) {
609+ LOGF (error, " >> CCDB TList is NULL for path: %s. Check object type (TList vs TFile)." , folder.c_str ());
610+ return ;
611+ }
612+
615613 // Important: Object names must match exactly what was saved
616614 mShiftProfileZNA = safeClone<TProfile3D>(lst->FindObject (" ShiftProfileZNA" ));
617615 mShiftProfileZNC = safeClone<TProfile3D>(lst->FindObject (" ShiftProfileZNC" ));
618616
619617 if (mShiftProfileZNA ) {
620618 mShiftProfileZNA ->SetDirectory (nullptr ); // Detach from file
621- LOGF (info, " >> ShiftProfileZNA found! Entries: %.0f, Mean: %f" ,
622- mShiftProfileZNA ->GetEntries (), mShiftProfileZNA ->GetMean ());
619+ // LOGF(info, " >> ShiftProfileZNA found! Entries: %.0f, Mean: %f", mShiftProfileZNA->GetEntries(), mShiftProfileZNA->GetMean());
623620 } else {
624621 LOGF (error, " >> ShiftProfileZNA NOT found in TList! Content follows:" );
625622 lst->Print ();
626623 }
627624
628625 if (mShiftProfileZNC ) {
629626 mShiftProfileZNC ->SetDirectory (nullptr );
630- LOGF (info, " >> ShiftProfileZNC found! Entries: %.0f" , mShiftProfileZNC ->GetEntries ());
627+ // LOGF(info, " >> ShiftProfileZNC found! Entries: %.0f", mShiftProfileZNC->GetEntries());
631628 } else {
632629 LOGF (error, " >> ShiftProfileZNC NOT found in TList!" );
633630 }
634631
635- } else {
636- LOGF (error, " >> CCDB TList is NULL for path: %s. Check object type (TList vs TFile)." , folder.c_str ());
637- }
638632 }
639633 } // end of loadCalibrations()
640634
@@ -659,39 +653,39 @@ struct ZdcExtraTableReader {
659653
660654 // Apply event selection
661655
662- if (ifSel8 && !(zdc.selectionBits () & ( 1 << evSel_sel8) )) {
656+ if (ifSel8 && !TESTBIT (zdc.selectionBits (), Sel8 )) {
663657 return ;
664658 }
665- if (ifVtxZle10 && !(zdc.selectionBits () & ( 1 << evSel_zvtx) )) {
659+ if (ifZVtxCut && !TESTBIT (zdc.selectionBits (), ZVtxCut )) {
666660 return ;
667661 }
668- if (ifOccupancyCut && !(zdc.selectionBits () & ( 1 << evSel_occupancy) )) {
662+ if (ifOccupancyCut && !TESTBIT (zdc.selectionBits (), OccupancyCut )) {
669663 return ;
670664 }
671- if (ifNoSameBunchPileup && !(zdc.selectionBits () & ( 1 << evSel_kNoSameBunchPileup) )) {
665+ if (ifNoSameBunchPileup && !TESTBIT (zdc.selectionBits (), NoSameBunchPileup )) {
672666 return ;
673667 }
674- if (ifIsGoodZvtxFT0vsPV && !(zdc.selectionBits () & ( 1 << evSel_kIsGoodZvtxFT0vsPV) )) {
668+ if (ifIsGoodZvtxFT0vsPV && !TESTBIT (zdc.selectionBits (), IsGoodZvtxFT0vsPV )) {
675669 return ;
676670 }
677- if (ifNoCollInTimeRangeStandard && !(zdc.selectionBits () & ( 1 << evSel_kNoCollInTimeRangeStandard) )) {
671+ if (ifNoCollInTimeRangeStandard && !TESTBIT (zdc.selectionBits (), NoCollInTimeRangeStandard )) {
678672 return ;
679673 }
680- if (ifIsVertexITSTPC && !(zdc.selectionBits () & ( 1 << evSel_kIsVertexITSTPC) )) {
674+ if (ifIsVertexITSTPC && !TESTBIT (zdc.selectionBits (), IsVertexITSTPC )) {
681675 return ;
682676 }
683- if (ifIsGoodITSLayersAll && !(zdc.selectionBits () & ( 1 << evSel_kIsGoodITSLayersAll) )) {
677+ if (ifIsGoodITSLayersAll && !TESTBIT (zdc.selectionBits (), IsGoodITSLayersAll )) {
684678 return ;
685679 }
686680
687- // LOGF(info, "zvtx = %d", (zdc.selectionBits() & (1 << evSel_zvtx)) > 0 );
688- // LOGF(info, "sel8 = %d", (zdc.selectionBits() & (1 << evSel_sel8)) > 0 );
689- // LOGF(info, "occupancy = %d", (zdc.selectionBits() & (1 << evSel_occupancy)) > 0 );
690- // LOGF(info, "noSameBC = %d", (zdc.selectionBits() & (1 << evSel_kNoSameBunchPileup)) > 0 );
691- // LOGF(info, "FT0vsPV = %d", (zdc.selectionBits() & (1 << evSel_kIsGoodZvtxFT0vsPV)) > 0 );
692- // LOGF(info, "noCollTR = %d", (zdc.selectionBits() & (1 << evSel_kNoCollInTimeRangeStandard)) > 0 );
693- // LOGF(info, "vtxITSTPC = %d", (zdc.selectionBits() & (1 << evSel_kIsVertexITSTPC)) > 0 );
694- // LOGF(info, "ITS layers = %d", (zdc.selectionBits() & (1 << evSel_kIsGoodITSLayersAll)) > 0 );
681+ // LOGF(info, "zvtx = %d", TESTBIT (zdc.selectionBits(), ZVtxCut) );
682+ // LOGF(info, "Sel8 = %d", TESTBIT (zdc.selectionBits(), Sel8) );
683+ // LOGF(info, "occupancy = %d", TESTBIT (zdc.selectionBits(), OccupancyCut) );
684+ // LOGF(info, "noSameBC = %d", TESTBIT (zdc.selectionBits(), NoSameBunchPileup) );
685+ // LOGF(info, "FT0vsPV = %d", TESTBIT (zdc.selectionBits(), IsGoodZvtxFT0vsPV) );
686+ // LOGF(info, "noCollTR = %d", TESTBIT (zdc.selectionBits(), NoCollInTimeRangeStandard) );
687+ // LOGF(info, "vtxITSTPC = %d", TESTBIT (zdc.selectionBits(), IsVertexITSTPC) );
688+ // LOGF(info, "ITS layers = %d", TESTBIT (zdc.selectionBits(), IsGoodITSLayersAll) );
695689
696690 const int mRunNumber = zdc.runNumber ();
697691
@@ -700,7 +694,7 @@ struct ZdcExtraTableReader {
700694 // Convert timestamp to hours from run start (approximate)
701695 // Store first timestamp of run to calculate relative time
702696 static std::unordered_map<int , uint64_t > runStartTime;
703- if (runStartTime.find (mRunNumber ) == runStartTime. end ( )) {
697+ if (! runStartTime.contains (mRunNumber )) {
704698 runStartTime[mRunNumber ] = timestamp;
705699 }
706700
@@ -715,11 +709,11 @@ struct ZdcExtraTableReader {
715709
716710 histos.fill (HIST (" eventCounter" ), 0.5 );
717711
718- gCurrentEventCounter ->Fill (evSel_allEvents );
712+ gCurrentEventCounter ->Fill (AllEvents );
719713
720714 // Fill histogram for all bits that passed
721- for (int bit = 0 ; bit < nEventSelections + 1 ; bit++) {
722- if (zdc.selectionBits () & ( 1 << bit)) {
715+ for (int bit = 0 ; bit < NEventSelections + 1 ; bit++) {
716+ if (TESTBIT ( zdc.selectionBits (), bit)) {
723717 gCurrentEventCounter ->Fill (bit);
724718 }
725719 }
0 commit comments