#include <TAxis.h>
#include <TFile.h>
#include <TH1.h>
+#include <TKey.h>
#include <TObjArray.h>
#include <TString.h>
+#include <TROOT.h>
#include <TSystem.h>
+#include <TDirectory.h>
#include "AliLog.h"
AliTRDPIDResponse::AliTRDPIDResponse(const Char_t * filename):
TObject()
,fReferences(NULL)
+ ,fGainNormalisationFactor(1.)
,fPIDmethod(2)
{
//
// Default constructor
//
- memset(fMapRefHists, 0, sizeof(Int_t) * 10);
- Load(filename);
+ for(Int_t ispec = 0; ispec < AliPID::kSPECIES; ispec++)
+ for(Int_t ipbin = 0; ipbin < kNPBins; ipbin++)
+ fMapRefHists[ispec][ipbin] = -1;
+ Load(filename);
}
//____________________________________________________________
AliTRDPIDResponse::AliTRDPIDResponse(const AliTRDPIDResponse &ref):
TObject(ref)
,fReferences(ref.fReferences)
+ ,fGainNormalisationFactor(ref.fGainNormalisationFactor)
,fPIDmethod(ref.fPIDmethod)
{
//
// Flat copy of the reference histos
// For creating a deep copy call SetOwner
//
- memcpy(fMapRefHists, ref.fMapRefHists, sizeof(Double_t) * 10);
+ Int_t size = (AliPID::kSPECIES)*(kNPBins);
+ memcpy(fMapRefHists, ref.fMapRefHists, sizeof(Double_t) * size);
}
//____________________________________________________________
delete fReferences;
}
SetBit(kIsOwner, kFALSE);
- }
+ } else if(fReferences) delete fReferences;
fReferences = ref.fReferences;
- memcpy(fMapRefHists, ref.fMapRefHists, sizeof(Double_t) * 10);
+ Int_t size = (AliPID::kSPECIES)*(kNPBins);
+ memcpy(fMapRefHists, ref.fMapRefHists, sizeof(Double_t) * size);
fPIDmethod = ref.fPIDmethod;
return *this;
//
// Destructor
//
- if(fReferences && IsOwner()){
- fReferences->Delete();
- delete fReferences;
+ if(IsOwner()){
+ // Destroy histos
+ if(fReferences) fReferences->Delete();
}
+ if(fReferences) delete fReferences;
}
//____________________________________________________________
//
// Load References into the toolkit
//
+
+ TDirectory *owd = gDirectory;// store old working directory
+
if(!filename)
filename = Form("%s/STEER/LQ1dRef_v1.root",gSystem->ExpandPathName("$ALICE_ROOT"));
TFile *in = TFile::Open(filename);
return kFALSE;
}
+ gROOT->cd();
fReferences = new TObjArray();
fReferences->SetOwner();
TIter iter(in->GetListOfKeys());
+ TKey *histkey = NULL;
TObject *tmp = NULL;
Int_t arrayPos = 0, pbin = 0;
AliPID::EParticleType species;
TString histname;
- while((tmp = iter())){
+ while((histkey = dynamic_cast<TKey *>(iter()))){
+ tmp = histkey->ReadObj();
histname = tmp->GetName();
if(histname.BeginsWith("fHQel")){ // Electron histogram
histname.ReplaceAll("fHQel_p","");
histname.ReplaceAll("fHQpi_p","");
species = AliPID::kPion;
}
- pbin = histname.Atoi();
+ pbin = histname.Atoi() - 1;
+ AliDebug(1, Form("Species %d, Histname %s, Pbin %d, Position in container %d", species, histname.Data(), pbin, arrayPos));
fMapRefHists[species][pbin] = arrayPos;
- fReferences->AddAt(tmp->Clone(), arrayPos);
+ fReferences->AddAt(new TH1F(*dynamic_cast<TH1F *>(tmp)), arrayPos);
arrayPos++;
}
in->Close();
-
+ owd->cd();
AliDebug(2, Form("Successfully loaded %d Reference Histograms", arrayPos));
+ SetBit(kIsOwner, kTRUE);
delete in;
return kTRUE;
}
for(Int_t is(AliPID::kSPECIES); is--;) prob[is]=.2;
Double_t prLayer[AliPID::kSPECIES];
- memset(prLayer, 0, AliPID::kSPECIES*sizeof(Double_t));
Double_t DE[10], s(0.);
for(Int_t il(kNlayer); il--;){
+ memset(prLayer, 0, AliPID::kSPECIES*sizeof(Double_t));
if(!CookdEdx(&dedx[il*n], &DE[0])) continue;
s=0.;
for(Int_t is(AliPID::kSPECIES); is--;){
- prLayer[is] = GetProbabilitySingleLayer(is, p[il], DE[0]);
+ if((DE[0] > 0.) && (p[il] > 0.)) prLayer[is] = GetProbabilitySingleLayer(is, p[il], DE[0]);
+ AliDebug(3, Form("Probability for Species %d in Layer %d: %f", is, il, prLayer[is]));
s+=prLayer[is];
}
if(s<1.e-30){
// from the reference histogram
// Interpolation between momentum bins
//
- Int_t pbin = GetLowerMomentumBin(plocal);
+ AliDebug(1, Form("Make Probability for Species %d with Momentum %f", species, plocal));
+ Int_t pbin = GetLowerMomentumBin(plocal);
+ AliDebug(1, Form("Bin %d", pbin));
Double_t pLayer = 0.;
// Do Interpolation exept for underflow and overflow
if(pbin >= 0 && pbin < kNPBins-1){
TH1 *refHistUpper = NULL, *refHistLower = NULL;
- refHistLower = dynamic_cast<TH1 *>(fReferences->UncheckedAt(fMapRefHists[species][pbin]));
- refHistUpper = dynamic_cast<TH1 *>(fReferences->UncheckedAt(fMapRefHists[species][pbin+1]));
+ if(fMapRefHists[species][pbin] >= 0)
+ refHistLower = dynamic_cast<TH1 *>(fReferences->UncheckedAt(fMapRefHists[species][pbin]));
+ if(fMapRefHists[species][pbin+1] >= 0)
+ refHistUpper = dynamic_cast<TH1 *>(fReferences->UncheckedAt(fMapRefHists[species][pbin+1]));
+ AliDebug(1, Form("Reference Histos (Upper/Lower): [%p|%p]", refHistUpper, refHistLower));
- Double_t pLower = refHistLower->GetBinContent(refHistLower->GetXaxis()->FindBin(dEdx));
- Double_t pUpper = refHistUpper->GetBinContent(refHistUpper->GetXaxis()->FindBin(dEdx));
+ if (refHistLower && refHistUpper ) {
+ Double_t pLower = refHistLower->GetBinContent(refHistLower->GetXaxis()->FindBin(dEdx));
+ Double_t pUpper = refHistUpper->GetBinContent(refHistUpper->GetXaxis()->FindBin(dEdx));
- pLayer = pLower + (pUpper - pLower)/(fgkPBins[pbin+1]-fgkPBins[pbin]) * plocal;
+ pLayer = pLower + (pUpper - pLower)/(fgkPBins[pbin+1]-fgkPBins[pbin]) * (plocal - fgkPBins[pbin]);
+ }
}
else{
TH1 *refHist = NULL;
if(pbin < 0){
// underflow
- refHist = dynamic_cast<TH1 *>(fReferences->UncheckedAt(fMapRefHists[0][0]));
+ if(fMapRefHists[species][0] >= 0){
+ refHist = dynamic_cast<TH1 *>(fReferences->UncheckedAt(fMapRefHists[species][0]));
+ }
} else {
// overflow
- refHist = dynamic_cast<TH1 *>(fReferences->UncheckedAt(fMapRefHists[species][kNPBins]));
+ if(fMapRefHists[species][kNPBins-1] > 0)
+ refHist = dynamic_cast<TH1 *>(fReferences->UncheckedAt(fMapRefHists[species][kNPBins-1]));
}
- pLayer = refHist->GetBinContent(refHist->GetXaxis()->FindBin(dEdx));
+ if (refHist)
+ pLayer = refHist->GetBinContent(refHist->GetXaxis()->FindBin(dEdx));
}
+ AliDebug(1, Form("Probability %f", pLayer));
return pLayer;
}
TObjArray *ctmp = new TObjArray();
for(Int_t ien = 0; ien < fReferences->GetEntriesFast(); ien++)
ctmp->AddAt(fReferences->UncheckedAt(ien)->Clone(), ien);
+ delete fReferences;
fReferences = ctmp;
SetBit(kIsOwner, kTRUE);
}
break;
case 2: // 1D LQ
out[0]= 0.;
- for(Int_t islice = 0; islice < 8; islice++) out[0] += in[islice];
+ for(Int_t islice = 0; islice < 8; islice++) out[0] += in[islice] * fGainNormalisationFactor;
if(out[0] < 1e-6) return kFALSE;
break;
default: