2727
2828#include < Rtypes.h>
2929
30+ #include < iostream>
3031#include < vector>
3132
3233double computeEfficiencyPerChamber (THnF* hnf, int iAxis, int iCh, double binLimits[2 ]);
@@ -46,8 +47,26 @@ void evalMchTrackingEfficiency(const char* inFile = "AnalysisResults.root", cons
4647{
4748 // read ouput from the taskComputeMchEfficiency
4849 TFile* file = TFile::Open (inFile, " read" );
49- TDirectoryFile* dir = reinterpret_cast <TDirectoryFile*>(file->Get (" task-muon-mch-trk-efficiency" ));
50- THnF* hHitsEtaPtPhi = reinterpret_cast <THnF*>(dir->Get (" hHitsEtaPtPhi" ));
50+ if (!file || file->IsZombie ()) {
51+ std::cerr << " Cannot open input file: " << inFile << std::endl;
52+ return ;
53+ }
54+
55+ TDirectoryFile* dir = nullptr ;
56+ file->GetObject (" task-muon-mch-trk-efficiency" , dir);
57+
58+ THnF* hHitsEtaPtPhi = nullptr ;
59+ if (dir) {
60+ dir->GetObject (" hHitsEtaPtPhi" , hHitsEtaPtPhi);
61+ } else {
62+ std::cerr << " Directory task-muon-mch-trk-efficiency not found in file " << inFile << std::endl;
63+ return ;
64+ }
65+
66+ if (!hHitsEtaPtPhi) {
67+ std::cerr << " Histogram hHitsEtaPtPhi not found in directory." << std::endl;
68+ return ;
69+ }
5170
5271 // retrieve the eta/pt/phi axis binning configuration
5372 const int etaAx = 1 , ptAx = 2 , phiAx = 3 ;
@@ -274,7 +293,7 @@ double computeEfficiencyPerChamber(THnF* hnf, int iAxis, int iCh, double binLimi
274293 hnf->GetAxis (iAxis)->SetRangeUser (binLimits[0 ], binLimits[1 ]);
275294
276295 // Project onto the Nhits axis
277- TH1F * htmp = reinterpret_cast < TH1F *>( hnf->Projection (0 ) );
296+ TH1D * htmp = hnf->Projection (0 );
278297 double NhitPairing[16 ];
279298 for (int i = 0 ; i < 16 ; i++) {
280299 NhitPairing[i] = 0 ;
@@ -322,7 +341,7 @@ double computeEfficiencyPerChamber(THnF* hnf, const int iAxis[3], int iCh, doubl
322341 }
323342
324343 // Project onto the Nhits axis
325- TH1F * htmp = reinterpret_cast < TH1F *>( hnf->Projection (0 ) );
344+ TH1D * htmp = hnf->Projection (0 );
326345 double NhitPairing[16 ];
327346 for (int i = 0 ; i < 16 ; i++) {
328347 NhitPairing[i] = 0 ;
0 commit comments