ROOT logo
/**************************************************************************
* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
*                                                                        *
* Author: The ALICE Off-line Project.                                    *
* Contributors are mentioned in the code where appropriate.              *
*                                                                        *
* Permission to use, copy, modify and distribute this software and its   *
* documentation strictly for non-commercial purposes is hereby granted   *
* without fee, provided that the above copyright notice appears in all   *
* copies and that both the copyright notice and this permission notice   *
* appear in the supporting documentation. The authors make no claims     *
* about the suitability of this software for any purpose. It is          *
* provided "as is" without express or implied warranty.                  *
**************************************************************************/

/* $Id$ */

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// Container for the distributions of dE/dx and the time bin of the     //
// max. cluster for electrons and pions                                 //
//                                                                      //
// Authors:                                                             //
//   Prashant Shukla <shukla@pi0.physi.uni-heidelberg.de>               //
//   Alex Bercuci <a.bercuci@gsi.de>                                    //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include <TFile.h>
#include <TROOT.h>
#include <TSystem.h>

#include "AliLog.h"
#include "AliPID.h"

#include "TKDPDF.h"

#include "AliTRDCalPIDLQ.h"
#include "AliTRDcalibDB.h"

ClassImp(AliTRDCalPIDLQ)

Float_t AliTRDCalPIDLQ::fgTrackSegLength[kNLength] = { 3.7, 3.9, 4.2, 5.0 };

//_________________________________________________________________________
AliTRDCalPIDLQ::AliTRDCalPIDLQ()
  :AliTRDCalPID("pid", "LQ PID references for TRD")
{
  //
  //  The Default constructor
  //

  //Init();

}

//_________________________________________________________________________
AliTRDCalPIDLQ::AliTRDCalPIDLQ(const Text_t *name, const Text_t *title)
  :AliTRDCalPID(name,title)
{
  //
  //  The main constructor
  //
  
  Init();

}

//_________________________________________________________________________
Bool_t AliTRDCalPIDLQ::LoadReferences(Char_t *refFile)
{
  //
  // Read the TRD dEdx histograms.
  //

  if(gSystem->AccessPathName(refFile, kReadPermission)){
    AliError(Form("File %s.root not readable", refFile));
    return kFALSE;
  }
  if(!TFile::Open(refFile)){
    AliError(Form("File %s corrupted", refFile));
    return kFALSE;
  }
  TObjArray *pdf(NULL);
  if (!( pdf = dynamic_cast<TObjArray*>(gFile->Get("PDF_LQ")))) {
    AliError("PID data not available");
    return kFALSE;
  }
  fModel=(TObjArray*)pdf->Clone("PDF");
  gFile->Close();
  return kTRUE;
}

//_________________________________________________________________________
TObject* AliTRDCalPIDLQ::GetModel(Int_t ip, Int_t is, Int_t slices) const
{
  //
  // Returns one selected dEdx histogram
  //

  if (is < 0 || is >= AliPID::kSPECIES) return NULL;
  if(ip<0 || ip>= kNMom ) return NULL;

  AliDebug(2, Form("Retrive dEdx distribution for %s @ p=%5.2f [GeV/c].", AliPID::ParticleShortName(is), fgTrackMomentum[ip]));
  return fModel->At(GetModelID(ip, is, slices));
}

//_________________________________________________________________________
Int_t AliTRDCalPIDLQ::GetNrefs()
{
// Returns the number of PDF distribution 
  return AliTRDCalPID::kNMom*AliPID::kSPECIES*2;
}

//_________________________________________________________________________
Double_t AliTRDCalPIDLQ::GetProbability(Int_t spec, Float_t mom
                                      , const Float_t * const dedx
                                      , Float_t length
                                      , Int_t slices) const
{
//
// Core function of AliTRDCalPID class for calculating the
// likelihood for species "spec" (see AliTRDtrack::kNspecie) of a
// given momentum "mom" and a given dE/dx (slice "dedx") yield per
// layer
//

  if (spec < 0 || spec >= AliPID::kSPECIES) return 0.;

  Bool_t k2D(slices==2);
  Double_t x[]={0., 0.};
  if(!CookdEdx(dedx, x, k2D)) return 0.;
    
  // find the interval in momentum and track segment length which applies for this data
/*  Int_t ilength = 1;
  while(ilength<kNLength-1 && length>fgTrackSegLength[ilength]){
    ilength++;
  }*/
  Int_t imom = 1;
  while(imom<kNMom-1 && mom>fgTrackMomentum[imom]) imom++;

  Double_t p[2], e[2], r;
  TKDPDF *pdf(NULL);

  AliDebug(2, Form("Looking %cD for %s@p=%6.4f[GeV/c] log(dEdx)={%7.2f %7.2f}[a.u.] l=%4.2f[cm].", k2D?'2':'1', AliPID::ParticleShortName(spec), mom, x[0], x[1], length));
  if(!(pdf = dynamic_cast<TKDPDF*>(fModel->At(GetModelID(imom-1, spec, slices))))) {
    AliError(Form("%cD Ref data @ idx[%d] not found in DB.", k2D?'2':'1', GetModelID(imom-1, spec, slices)));
    return 0.;
  }
  if(!pdf->GetSize()) pdf->Bootstrap();
  pdf->Eval(x, r, e[0], kFALSE);
  p[0]=TMath::Abs(r); // conversion from interpolation to PDF
  AliDebug(2, Form("LQ=%6.3f+-%5.2f%% @ %4.1f[GeV/c]", p[0], 1.E2*e[0]/p[0], fgTrackMomentum[imom-1]));

  if(!(pdf = dynamic_cast<TKDPDF*>(fModel->At(GetModelID(imom, spec, slices))))){
    AliError(Form("%cD Ref data @ idx[%d] not found in DB.", k2D?'2':'1', GetModelID(imom, spec, slices)));
    return p[0];
  }
  if(!pdf->GetSize()) pdf->Bootstrap();
  pdf->Eval(x, r, e[1], kFALSE);
  p[1]=TMath::Abs(r); // conversion from interpolation to PDF
  AliDebug(2, Form("LQ=%6.3f+-%5.2f%% @ %4.1f[GeV/c]", p[1], 1.E2*e[1]/p[1], fgTrackMomentum[imom]));
  
  // return interpolation over momentum binning
  if(mom < fgTrackMomentum[0]) return p[0];
  else if(mom > fgTrackMomentum[kNMom-1]) return p[1];
  else{ 
    Double_t lmom[2] = {fgTrackMomentum[imom-1],  fgTrackMomentum[imom]};
    return p[0] + (p[1] - p[0])*(mom - lmom[0])/(lmom[1] - lmom[0]);
  }
}

//_________________________________________________________________________
void AliTRDCalPIDLQ::Init()
{
//
// PID LQ list initialization
//
  fModel = new TObjArray(AliPID::kSPECIES  * kNMom * 2);
  fModel->SetOwner();
}
 AliTRDCalPIDLQ.cxx:1
 AliTRDCalPIDLQ.cxx:2
 AliTRDCalPIDLQ.cxx:3
 AliTRDCalPIDLQ.cxx:4
 AliTRDCalPIDLQ.cxx:5
 AliTRDCalPIDLQ.cxx:6
 AliTRDCalPIDLQ.cxx:7
 AliTRDCalPIDLQ.cxx:8
 AliTRDCalPIDLQ.cxx:9
 AliTRDCalPIDLQ.cxx:10
 AliTRD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AliTRDCalPIDLQ.cxx:60
 AliTRDCalPIDLQ.cxx:61
 AliTRDCalPIDLQ.cxx:62
 AliTRDCalPIDLQ.cxx:63
 AliTRDCalPIDLQ.cxx:64
 AliTRDCalPIDLQ.cxx:65
 AliTRDCalPIDLQ.cxx:66
 AliTRDCalPIDLQ.cxx:67
 AliTRDCalPIDLQ.cxx:68
 AliTRDCalPIDLQ.cxx:69
 AliTRDCalPIDLQ.cxx:70
 AliTRDCalPIDLQ.cxx:71
 AliTRDCalPIDLQ.cxx:72
 AliTRDCalPIDLQ.cxx:73
 AliTRDCalPIDLQ.cxx:74
 AliTRDCalPIDLQ.cxx:75
 AliTRDCalPIDLQ.cxx:76
 AliTRDCalPIDLQ.cxx:77
 AliTRDCalPIDLQ.cxx:78
 AliTRDCalPIDLQ.cxx:79
 AliTRDCalPIDLQ.cxx:80
 AliTRDCalPIDLQ.cxx:81
 AliTRDCalPIDLQ.cxx:82
 AliTRDCalPIDLQ.cxx:83
 AliTRDCalPIDLQ.cxx:84
 AliTRDCalPIDLQ.cxx:85
 AliTRDCalPIDLQ.cxx:86
 AliTRDCalPIDLQ.cxx:87
 AliTRDCalPIDLQ.cxx:88
 AliTRDCalPIDLQ.cxx:89
 AliTRDCalPIDLQ.cxx:90
 AliTRDCalPIDLQ.cxx:91
 AliTRDCalPIDLQ.cxx:92
 AliTRDCalPIDLQ.cxx:93
 AliTRDCalPIDLQ.cxx:94
 AliTRDCalPIDLQ.cxx:95
 AliTRDCalPIDLQ.cxx:96
 AliTRDCalPIDLQ.cxx:97
 AliTRDCalPIDLQ.cxx:98
 AliTRDCalPIDLQ.cxx:99
 AliTRDCalPIDLQ.cxx:100
 AliTRDCalPIDLQ.cxx:101
 AliTRDCalPIDLQ.cxx:102
 AliTRDCalPIDLQ.cxx:103
 AliTRDCalPIDLQ.cxx:104
 AliTRDCalPIDLQ.cxx:105
 AliTRDCalPIDLQ.cxx:106
 AliTRDCalPIDLQ.cxx:107
 AliTRDCalPIDLQ.cxx:108
 AliTRDCalPIDLQ.cxx:109
 AliTRDCalPIDLQ.cxx:110
 AliTRDCalPIDLQ.cxx:111
 AliTRDCalPIDLQ.cxx:112
 AliTRDCalPIDLQ.cxx:113
 AliTRDCalPIDLQ.cxx:114
 AliTRDCalPIDLQ.cxx:115
 AliTRDCalPIDLQ.cxx:116
 AliTRDCalPIDLQ.cxx:117
 AliTRDCalPIDLQ.cxx:118
 AliTRDCalPIDLQ.cxx:119
 AliTRDCalPIDLQ.cxx:120
 AliTRDCalPIDLQ.cxx:121
 AliTRDCalPIDLQ.cxx:122
 AliTRDCalPIDLQ.cxx:123
 AliTRDCalPIDLQ.cxx:124
 AliTRDCalPIDLQ.cxx:125
 AliTRDCalPIDLQ.cxx:126
 AliTRDCalPIDLQ.cxx:127
 AliTRDCalPIDLQ.cxx:128
 AliTRDCalPIDLQ.cxx:129
 AliTRDCalPIDLQ.cxx:130
 AliTRDCalPIDLQ.cxx:131
 AliTRDCalPIDLQ.cxx:132
 AliTRDCalPIDLQ.cxx:133
 AliTRDCalPIDLQ.cxx:134
 AliTRDCalPIDLQ.cxx:135
 AliTRDCalPIDLQ.cxx:136
 AliTRDCalPIDLQ.cxx:137
 AliTRDCalPIDLQ.cxx:138
 AliTRDCalPIDLQ.cxx:139
 AliTRDCalPIDLQ.cxx:140
 AliTRDCalPIDLQ.cxx:141
 AliTRDCalPIDLQ.cxx:142
 AliTRDCalPIDLQ.cxx:143
 AliTRDCalPIDLQ.cxx:144
 AliTRDCalPIDLQ.cxx:145
 AliTRDCalPIDLQ.cxx:146
 AliTRDCalPIDLQ.cxx:147
 AliTRDCalPIDLQ.cxx:148
 AliTRDCalPIDLQ.cxx:149
 AliTRDCalPIDLQ.cxx:150
 AliTRDCalPIDLQ.cxx:151
 AliTRDCalPIDLQ.cxx:152
 AliTRDCalPIDLQ.cxx:153
 AliTRDCalPIDLQ.cxx:154
 AliTRDCalPIDLQ.cxx:155
 AliTRDCalPIDLQ.cxx:156
 AliTRDCalPIDLQ.cxx:157
 AliTRDCalPIDLQ.cxx:158
 AliTRDCalPIDLQ.cxx:159
 AliTRDCalPIDLQ.cxx:160
 AliTRDCalPIDLQ.cxx:161
 AliTRDCalPIDLQ.cxx:162
 AliTRDCalPIDLQ.cxx:163
 AliTRDCalPIDLQ.cxx:164
 AliTRDCalPIDLQ.cxx:165
 AliTRDCalPIDLQ.cxx:166
 AliTRDCalPIDLQ.cxx:167
 AliTRDCalPIDLQ.cxx:168
 AliTRDCalPIDLQ.cxx:169
 AliTRDCalPIDLQ.cxx:170
 AliTRDCalPIDLQ.cxx:171
 AliTRDCalPIDLQ.cxx:172
 AliTRDCalPIDLQ.cxx:173
 AliTRDCalPIDLQ.cxx:174
 AliTRDCalPIDLQ.cxx:175
 AliTRDCalPIDLQ.cxx:176
 AliTRDCalPIDLQ.cxx:177
 AliTRDCalPIDLQ.cxx:178
 AliTRDCalPIDLQ.cxx:179
 AliTRDCalPIDLQ.cxx:180
 AliTRDCalPIDLQ.cxx:181