]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
writing new LQ TRD-PID based on kdTree to the OCDB ENABLED.
authorabercuci <abercuci@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 2 Oct 2009 12:18:22 +0000 (12:18 +0000)
committerabercuci <abercuci@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 2 Oct 2009 12:18:22 +0000 (12:18 +0000)
- minimum statistics needed / momentum bin / species - 7.5k full tracks
- size on disk approx 500kb a factor 36 smaller ~ same order as NN

TRD/Cal/AliTRDCalPIDLQ.cxx
TRD/Cal/AliTRDCalPIDLQ.h
TRD/Macros/AliTRDpidCDB.C
TRD/qaRec/AliTRDpidRefMaker.cxx
TRD/qaRec/AliTRDpidRefMaker.h
TRD/qaRec/AliTRDpidRefMakerLQ.cxx
TRD/qaRec/AliTRDpidRefMakerLQ.h

index 49d3908445fc1577de27b81002b464d239ed45c9..85d970d8e700f8094a772ed6a550e06b739c30e2 100644 (file)
@@ -1,17 +1,17 @@
 /**************************************************************************
- * 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.                  *
- **************************************************************************/
+* 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$ */
 
@@ -33,6 +33,7 @@
 #include "AliLog.h"
 #include "AliPID.h"
 
+#include "../../STAT/TKDPDF.h"
 #include "AliTRDCalPIDLQ.h"
 #include "AliTRDcalibDB.h"
 
@@ -73,6 +74,22 @@ AliTRDCalPIDLQ::~AliTRDCalPIDLQ()
   
 }
 
+//_________________________________________________________________________
+Bool_t AliTRDCalPIDLQ::LoadPDF(TDirectoryFile *d)
+{
+  // Read histograms
+  TKDPDF *pdf = 0x0;
+  for (Int_t is=0; is < AliPID::kSPECIES; is++){
+    for (Int_t ip = 0; ip < kNMom; ip++){
+      if(!(pdf = (TKDPDF*)d->Get(Form("%s[%d]", AliPID::ParticleShortName(is), ip)))){ 
+        AliWarning(Form("Reference for %s[%d] missing.", AliPID::ParticleShortName(is), ip));
+        continue;
+      }
+      fModel->AddAt(pdf->Clone(), GetModelID(ip, is, 0));
+    }
+  }
+}
+  //
 //_________________________________________________________________________
 Bool_t AliTRDCalPIDLQ::LoadReferences(Char_t *refFile)
 {
@@ -80,17 +97,17 @@ Bool_t AliTRDCalPIDLQ::LoadReferences(Char_t *refFile)
   // Read the TRD dEdx histograms.
   //
 
-       Int_t nTimeBins = 22;
-       // Get number of time bins from CDB
-       AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
-       if(!calibration){
-               AliWarning(Form("No AliTRDcalibDB available. Using %d time bins.", nTimeBins));
-       }else{
-               if(calibration->GetRun() > -1) nTimeBins = calibration->GetNumberOfTimeBins();
-               else AliWarning(Form("Run number not set. Using %d time bins.", nTimeBins));
-       }
-
-       
+  Int_t nTimeBins = 22;
+  // Get number of time bins from CDB
+  AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
+  if(!calibration){
+    AliWarning(Form("No AliTRDcalibDB available. Using %d time bins.", nTimeBins));
+  }else{
+    if(calibration->GetRun() > -1) nTimeBins = calibration->GetNumberOfTimeBins();
+    else AliWarning(Form("Run number not set. Using %d time bins.", nTimeBins));
+  }
+
+  
   // Read histogram Root file  
   TFile *histFile = TFile::Open(refFile, "READ");
   if (!histFile || !histFile->IsOpen()) {
@@ -102,9 +119,9 @@ Bool_t AliTRDCalPIDLQ::LoadReferences(Char_t *refFile)
   // Read histograms
   for (Int_t iparticle = 0; iparticle < AliPID::kSPECIES; iparticle++){
     for (Int_t imom = 0; imom < kNMom; imom++){
-                       TH2D* hist = (TH2D*)histFile->Get(Form("h2dEdx%s%d", fPartSymb[iparticle], imom/*, ilength*/))->Clone();
-                       hist->Scale(1./hist->Integral());
-                       fModel->AddAt(hist, GetModelID(imom, iparticle, 0));
+      TH2D* hist = (TH2D*)histFile->Get(Form("h2dEdx%s%d", fPartSymb[iparticle], imom/*, ilength*/))->Clone();
+      hist->Scale(1./hist->Integral());
+      fModel->AddAt(hist, GetModelID(imom, iparticle, 0));
 
 //                     if (iparticle != AliPID::kElectron && iparticle != AliPID::kPion) continue;
 // 
@@ -112,7 +129,7 @@ Bool_t AliTRDCalPIDLQ::LoadReferences(Char_t *refFile)
 //                     if(ht->GetNbinsX() != nTimeBins) AliWarning(Form("The number of time bins %d defined in h1MaxTB%s%02d differs from calibration value of %d. This may lead to erroneous results.", ht->GetNbinsX(), fPartSymb[iparticle], imom, nTimeBins));
 //                     ht->Scale(1./ht->Integral());
 //                     fHistTimeBin->AddAt(ht, ((iparticle==AliPID::kElectron)?0:1)*kNMom + imom);
-               }
+    }
   }
   
   histFile->Close();
@@ -136,7 +153,7 @@ TObject* AliTRDCalPIDLQ::GetModel(Int_t ip, Int_t iType, Int_t iplane) const
   //
 
   if (iType < 0 || iType >= AliPID::kSPECIES) return 0x0;
-       if(ip<0 || ip>= kNMom ) return 0x0;
+  if(ip<0 || ip>= kNMom ) return 0x0;
 
   AliInfo(Form("Retrive dEdx histogram for %s of %5.2f GeV/c", fPartName[iType], fgTrackMomentum[ip]));
   
@@ -149,61 +166,61 @@ Double_t AliTRDCalPIDLQ::GetProbability(Int_t spec, Float_t mom
                                       , Float_t length, Int_t iplane) 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
+  // 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.;
-               
-       //Double_t dedx   = dedx1/fMeanChargeRatio;
-       
-       // find the interval in momentum and track segment length which applies for this data
-       Int_t ilength = 1;
+  if (spec < 0 || spec >= AliPID::kSPECIES) return 0.;
+    
+  //Double_t dedx   = dedx1/fMeanChargeRatio;
+  
+  // 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;
+    ilength++;
+  }
+  Int_t imom = 1;
   while(imom<kNMom-1 && mom>fgTrackMomentum[imom]) imom++;
 
-       Int_t nbinsx, nbinsy;
-       TAxis *ax = 0x0, *ay = 0x0;
-       Double_t lq1, lq2;
-       Double_t mom1 = fgTrackMomentum[imom-1], mom2 = fgTrackMomentum[imom];
-       TH2 *hist = 0x0;
-       if(!(hist = (TH2D*)fModel->At(GetModelID(imom-1, spec, iplane)))){
-               AliInfo(Form("Looking for spec(%d) mom(%f) Ex(%f) Ey(%f) length(%f)", spec, mom, dedx[0], dedx[1], length));
-               AliError(Form("EHistogram id %d not found in DB.", GetModelID(imom-1, spec, iplane)));
-               return 0.;
-       }
-       ax = hist->GetXaxis(); nbinsx = ax->GetNbins();
-       ay = hist->GetYaxis(); nbinsy = ay->GetNbins();
-       Float_t x = dedx[0]+dedx[1], y = dedx[2];
+  Int_t nbinsx, nbinsy;
+  TAxis *ax = 0x0, *ay = 0x0;
+  Double_t lq1, lq2;
+  Double_t mom1 = fgTrackMomentum[imom-1], mom2 = fgTrackMomentum[imom];
+  TH2 *hist = 0x0;
+  if(!(hist = (TH2D*)fModel->At(GetModelID(imom-1, spec, iplane)))){
+    AliInfo(Form("Looking for spec(%d) mom(%f) Ex(%f) Ey(%f) length(%f)", spec, mom, dedx[0], dedx[1], length));
+    AliError(Form("EHistogram id %d not found in DB.", GetModelID(imom-1, spec, iplane)));
+    return 0.;
+  }
+  ax = hist->GetXaxis(); nbinsx = ax->GetNbins();
+  ay = hist->GetYaxis(); nbinsy = ay->GetNbins();
+  Float_t x = dedx[0]+dedx[1], y = dedx[2];
         Bool_t kX = (x < ax->GetBinUpEdge(nbinsx));
-       Bool_t kY = (y < ay->GetBinUpEdge(nbinsy));
-       if(kX)
-               if(kY) lq1 = hist->GetBinContent( hist->FindBin(x, y)); 
+  Bool_t kY = (y < ay->GetBinUpEdge(nbinsy));
+  if(kX)
+    if(kY) lq1 = hist->GetBinContent( hist->FindBin(x, y)); 
     //fEstimator->Estimate2D2(hist, x, y);
-               else lq1 = hist->GetBinContent(ax->FindBin(x), nbinsy);
-       else
-               if(kY) lq1 = hist->GetBinContent(nbinsx, ay->FindBin(y));
-               else lq1 = hist->GetBinContent(nbinsx, nbinsy);
-
-
-       if(!(hist = (TH2D*)fModel->At(GetModelID(imom, spec, iplane)))){
-               AliInfo(Form("Looking for spec(%d) mom(%f) Ex(%f) Ey(%f) length(%f)", spec, mom, dedx[0], dedx[1], length));
-               AliError(Form("EHistogram id %d not found in DB.", GetModelID(imom, spec, iplane)));
-               return lq1;
-       }
-       if(kX)
-               if(kY) lq2 = hist->GetBinContent( hist->FindBin(x, y)); 
+    else lq1 = hist->GetBinContent(ax->FindBin(x), nbinsy);
+  else
+    if(kY) lq1 = hist->GetBinContent(nbinsx, ay->FindBin(y));
+    else lq1 = hist->GetBinContent(nbinsx, nbinsy);
+
+
+  if(!(hist = (TH2D*)fModel->At(GetModelID(imom, spec, iplane)))){
+    AliInfo(Form("Looking for spec(%d) mom(%f) Ex(%f) Ey(%f) length(%f)", spec, mom, dedx[0], dedx[1], length));
+    AliError(Form("EHistogram id %d not found in DB.", GetModelID(imom, spec, iplane)));
+    return lq1;
+  }
+  if(kX)
+    if(kY) lq2 = hist->GetBinContent( hist->FindBin(x, y)); 
     //fEstimator->Estimate2D2(hist, x, y);
-               else lq2 = hist->GetBinContent(ax->FindBin(x), nbinsy);
-       else
-               if(kY) lq2 = hist->GetBinContent(nbinsx, ay->FindBin(y));
-               else lq2 = hist->GetBinContent(nbinsx, nbinsy);
-       
+    else lq2 = hist->GetBinContent(ax->FindBin(x), nbinsy);
+  else
+    if(kY) lq2 = hist->GetBinContent(nbinsx, ay->FindBin(y));
+    else lq2 = hist->GetBinContent(nbinsx, nbinsy);
+  
         // return interpolation over momentum binning
         if(mom < fgTrackMomentum[0]) return lq1;
         else if(mom > fgTrackMomentum[kNMom-1]) return lq2;
@@ -228,5 +245,5 @@ Int_t AliTRDCalPIDLQ::GetModelID(Int_t mom, Int_t spec, Int_t /*ii*/) const
 {  
   // returns the ID of the LQ distribution (55 Histos, ID from 1 to 55)
 
-       return spec * AliTRDCalPID::kNMom + mom;
+  return spec * AliTRDCalPID::kNMom + mom;
 }
index 03c485ba0b046aa19dcf49f06bbbf9a377f27845..69304e6fa6af8ff36829d15e461b9cb406491fdc 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "AliTRDCalPID.h"
 
+class TDirectoryFile;
 class AliTRDCalPIDLQ : public AliTRDCalPID
 {
 
@@ -30,6 +31,7 @@ class AliTRDCalPIDLQ : public AliTRDCalPID
   AliTRDCalPIDLQ(const Text_t *name, const Text_t *title);
   virtual        ~AliTRDCalPIDLQ();
 
+  Bool_t          LoadPDF(TDirectoryFile *);
   Bool_t          LoadReferences(Char_t* refFile);
   TObject*        GetModel(Int_t ip, Int_t iType, Int_t iPlane) const;
   static Double_t GetLength(Int_t il) { return (il<0 || il>=kNLength) ? -1. : fgTrackSegLength[il]; }
index bd0c5e0492fca82ab1236106c19346afccc6a1b0..b4985af73b9e01c114c0c655722317c8b9b3ea5e 100644 (file)
@@ -15,47 +15,37 @@ void makePIDRefs(const char *dir = ".", const char *file="Refs.root")
 // 2. "file" - output file containing reference data saved in directory
 //             "dir" 
 
-       AliCDBManager *man = AliCDBManager::Instance();
-       man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
-       man->SetRun(0);
+  AliCDBManager *man = AliCDBManager::Instance();
+  man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  man->SetRun(0);
 
-       AliTRDCalPIDRefMaker maker;
-       maker.BuildLQReferences(file, dir);
+  AliTRDCalPIDRefMaker maker;
+  maker.BuildLQReferences(file, dir);
 }
 
 //___________________________________________________________________
-void generatePIDDB(const char *fileNN = "NN.root", const char *fileLQ = "LQ.root")
+void generatePIDDB()
 {
 // Write TRD PID DB using the reference data from file "file"
 
 
-       AliCDBManager *man = AliCDBManager::Instance();
-       man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
-       man->SetRun(0);
+  AliCDBManager *man = AliCDBManager::Instance();
+  man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  man->SetSpecificStorage("TRD/Calib/PIDLQ", "local://.");
+  man->SetRun(0);
 
-       AliCDBStorage *gStorLoc = man->GetStorage("local://$ALICE_ROOT/OCDB");
-       if (!gStorLoc) return;
+  AliCDBStorage *gStorLoc = man->GetStorage("local://$ALICE_ROOT/OCDB");
+  if (!gStorLoc) return;
 
-  
-       AliTRDCalPID *pidLQ = new AliTRDCalPIDLQ("pidLQ", "LQ TRD PID object");
-       pidLQ->LoadReferences(fileLQ);
-       AliCDBMetaData *md= new AliCDBMetaData();
-       md->SetObjectClassName("AliTRDCalPIDLQ");
-       md->SetResponsible("Alex Bercuci");
-       md->SetBeamPeriod(1);
-       md->SetAliRootVersion("v4-06-HEAD"); //root version
-       md->SetComment("2D PID for TRD");
-       gStorLoc->Put(pidLQ, AliCDBId("TRD/Calib/PIDLQ", 0, 999999999, 0, 1), md);
-       
-       AliTRDCalPID *pidNN = new AliTRDCalPIDNN("pidNN", "NN TRD PID object");
-       pidNN->LoadReferences(fileNN);
-       md->SetObjectClassName("AliTRDCalPIDNN");
-       md->SetResponsible("Alex Wilk");
-       md->SetBeamPeriod(1);
-       md->SetAliRootVersion("v4-06-HEAD"); //root version
-       md->SetComment("NN PID for TRD");
-       
-       gStorLoc->Put(pidNN, AliCDBId("TRD/Calib/PIDNN", 0, 999999999, 0, 1), md);
+  AliTRDpidRefMakerLQ pidMaker;
+  TObject *o = pidMaker.GetOCDBEntry("20091101");
+  AliCDBMetaData *md= new AliCDBMetaData();
+  md->SetObjectClassName("AliTRDCalPIDLQ");
+  md->SetResponsible("Alexandru Bercuci");
+  md->SetBeamPeriod(1);
+  md->SetAliRootVersion("v4-16-Release"); //root version
+  md->SetComment("2D PID for TRD");
+  gStorLoc->Put(o, AliCDBId("TRD/Calib/PIDLQ", 0, 999999999, 0, 1), md, AliCDBManager::kReference);
 }
 
 //___________________________________________________________________
@@ -66,20 +56,20 @@ AliTRDCalPID* getPIDObject(const char *method="NN")
 //   > AliTRDCalPID *pid = getPIDObject();
 //   > pid->GetHistogram(0, 3);
 
-       gStyle->SetOptStat(0);
-       
+  gStyle->SetOptStat(0);
+  
   AliCDBManager *CDBManager = AliCDBManager::Instance();
-       CDBManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
-       CDBManager->SetRun(0);
+  CDBManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  CDBManager->SetRun(0);
 
-       AliCDBEntry *wrap = CDBManager->Get(Form("TRD/Calib/PID%s", method), 0);
-       AliTRDCalPID *pid = dynamic_cast<const AliTRDCalPID *>wrap->GetObject();
-       AliCDBMetaData *meta = wrap->GetMetaData();
-       if(!pid){
-               printf("Error while retriving pid object from DB.\n");
-               return 0x0;
-       }
-       meta->PrintMetaData();
-       return pid;
+  AliCDBEntry *wrap = CDBManager->Get(Form("TRD/Calib/PID%s", method), 0);
+  AliTRDCalPID *pid = dynamic_cast<const AliTRDCalPID *>wrap->GetObject();
+  AliCDBMetaData *meta = wrap->GetMetaData();
+  if(!pid){
+    printf("Error while retriving pid object from DB.\n");
+    return 0x0;
+  }
+  meta->PrintMetaData();
+  return pid;
 }
 
index c7657ab0379c5da6cec4fd73e591bd9732173a3c..f68b87880bde81cb702ff366735c9e4f13227284 100644 (file)
@@ -53,9 +53,6 @@ AliTRDpidRefMaker::AliTRDpidRefMaker(const char *name, const char *title)
   memset(fdEdx, 0, 10*sizeof(Float_t));
   memset(fPID, 0, AliPID::kSPECIES*sizeof(Float_t));
 
-  memset(fTrain, 0, AliTRDCalPID::kNMom*AliTRDgeometry::kNlayer*sizeof(TEventList*));
-  memset(fTest, 0, AliTRDCalPID::kNMom*AliTRDgeometry::kNlayer*sizeof(TEventList*));
-
   DefineInput(1, TObjArray::Class());
   DefineOutput(1, TTree::Class());
 }
@@ -65,12 +62,6 @@ AliTRDpidRefMaker::AliTRDpidRefMaker(const char *name, const char *title)
 AliTRDpidRefMaker::~AliTRDpidRefMaker() 
 {
   if(fReconstructor) delete fReconstructor;
-  for(Int_t ip=AliTRDCalPID::kNMom; ip--;){
-    for(Int_t il=AliTRDgeometry::kNlayer; il--;){
-      if(fTrain[ip][il]) delete fTrain[ip][il];
-      if(fTest[ip][il]) delete fTest[ip][il];
-    }
-  }
 }
 
 
@@ -128,9 +119,6 @@ void AliTRDpidRefMaker::Exec(Option_t *)
   //AliExternalTrackParam *esd = 0x0;
   AliTRDseedV1 *TRDtracklet = 0x0;
   for(Int_t itrk=0, nTRD=0; itrk<fTracks->GetEntriesFast(); itrk++){
-    // reset the pid information
-    memset(fPID, 0, AliPID::kSPECIES*sizeof(Float_t));
-
     track = (AliTRDtrackInfo*)fTracks->UncheckedAt(itrk);
     if(!track->HasESDtrack()) continue;
     ULong_t status = track->GetStatus();
@@ -146,53 +134,20 @@ void AliTRDpidRefMaker::Exec(Option_t *)
      
 
     if(HasMCdata()) labelsacc[nTRD++] = track->GetLabel();
-      
-
-    switch(fRefPID){ 
-    case kV0:
-      SetRefPID(TRDtrack,fPID);
-      break;
-    case kMC:
-      if(!HasMCdata()){
-        AliError("Could not retrive reference PID from MC");
-        return;
-      }
-      switch(track -> GetPDG()){
-      case kElectron:
-      case kPositron:
-        fPID[AliPID::kElectron] = 1.;
-        break;
-      case kMuonPlus:
-      case kMuonMinus:
-        fPID[AliPID::kMuon] = 1.;
-        break;
-      case kPiPlus:
-      case kPiMinus:
-        fPID[AliPID::kPion] = 1.;
-        break;
-      case kKPlus:
-      case kKMinus:
-        fPID[AliPID::kKaon] = 1.;
-        break;
-      case kProton:
-      case kProtonBar:
-        fPID[AliPID::kProton] = 1.;
-        break;
-      }
-      break;
-    default:
-      AliWarning("PID reference source not implemented");
-      return;
-    }
 
-    // set reconstructor
-    //Float_t *dedx;
-    TRDtrack -> SetReconstructor(fReconstructor);
+    // fill the pid information
+    memset(fPID, 0, AliPID::kSPECIES*sizeof(Float_t));
+    switch(fRefPID){
+    case kV0: SetRefPID(kV0, 0x0/*v0*/, fPID); break;
+    case kMC: SetRefPID(kMC, track, fPID); break;
+    case kRec: SetRefPID(kRec, TRDtrack, fPID); break;
+    }
 
     // fill the momentum and dE/dx information
+    TRDtrack -> SetReconstructor(fReconstructor);
     for(Int_t ily = 0; ily < AliTRDgeometry::kNlayer; ily++){
       if(!(TRDtracklet = TRDtrack -> GetTracklet(ily))) continue;
-      if(!GetdEdx(TRDtracklet)) continue;
+      if(!CookdEdx(TRDtracklet)) continue;
       switch(fRefP){
       case kMC:
         if(!HasMCdata()){
@@ -244,58 +199,68 @@ void AliTRDpidRefMaker::Terminate(Option_t *)
 
 
 //________________________________________________________________________
-void AliTRDpidRefMaker::LoadFile(const Char_t *InFile
+void AliTRDpidRefMaker::SetRefPID(ETRDpidRefMakerSource select, void *source, Float_t *pid
 {
-  //
-  // Loads the files and sets the event list
-  // for neural network training and 
-  // building of the 2-dim reference histograms.
-  // Usable for training outside of the makeResults.C macro
-  //
-
-  TFile::Open(InFile, "READ");
-  fData = (TTree*)gFile->Get(GetName());
-
-  for(Int_t iMom = 0; iMom < AliTRDCalPID::kNMom; iMom++){
-    for(Int_t iLy = 0; iLy < AliTRDgeometry::kNlayer; iLy++){
-      fTrain[iMom][iLy] = new TEventList(Form("fTrain_P%d_L%d", iMom, iLy), Form("Training list for momentum bin %d layer %d", iMom, iLy));
-      fTest[iMom][iLy] = new TEventList(Form("fTest_P%d_L%d", iMom, iLy), Form("Test list for momentum bin %d layer %d", iMom, iLy));
+// !!!! PREMILMINARY FUNCTION !!!!
+//
+// this is the place for the V0 procedure
+// as long as there is no one implemented, 
+// just the probabilities
+// of the TRDtrack are used!
+
+  switch(select){ 
+  case kV0:
+    {
+      AliTRDv0Info *v0 = static_cast<AliTRDv0Info*>(source);
+      v0->Print(); // do something
     }
-  }
-}
-
-
-//________________________________________________________________________
-void AliTRDpidRefMaker::LoadContainer(const Char_t *InFileCont) 
-{
-
-  //
-  // Loads the container if no container is there.
-  // Useable for training outside of the makeResults.C macro
-  //
-
-  TFile::Open(InFileCont, "READ");
-  fContainer = (TObjArray*)gFile->Get(GetName());
-}
-
-
-//________________________________________________________________________
-void AliTRDpidRefMaker::SetRefPID(void *source, Float_t *pid) 
-{
-  // !!!! PREMILMINARY FUNCTION !!!!
-  //
-  // this is the place for the V0 procedure
-  // as long as there is no one implemented, 
-  // just the probabilities
-  // of the TRDtrack are used!
-
-  AliTRDtrackV1 *TRDtrack = static_cast<AliTRDtrackV1*>(source);
-  TRDtrack -> SetReconstructor(fReconstructor);
-  //fReconstructor -> SetOption("nn");
-  TRDtrack -> CookPID();
-  for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
-    pid[iPart] = TRDtrack -> GetPID(iPart);
-    AliDebug(4, Form("PDG is (in V0info) %d %f", iPart, pid[iPart]));
+    break;
+  case kMC:
+    if(!HasMCdata()){
+      AliError("Could not retrive reference PID from MC");
+      return;
+    }
+    {
+      AliTRDtrackInfo *track = static_cast<AliTRDtrackInfo*>(source);
+      switch(track->GetPDG()){
+      case kElectron:
+      case kPositron:
+        fPID[AliPID::kElectron] = 1.;
+        break;
+      case kMuonPlus:
+      case kMuonMinus:
+        fPID[AliPID::kMuon] = 1.;
+        break;
+      case kPiPlus:
+      case kPiMinus:
+        fPID[AliPID::kPion] = 1.;
+        break;
+      case kKPlus:
+      case kKMinus:
+        fPID[AliPID::kKaon] = 1.;
+        break;
+      case kProton:
+      case kProtonBar:
+        fPID[AliPID::kProton] = 1.;
+        break;
+      }
+    }
+    break;
+  case kRec:
+    { 
+      AliTRDtrackV1 *TRDtrack = static_cast<AliTRDtrackV1*>(source);
+      TRDtrack -> SetReconstructor(fReconstructor);
+      //fReconstructor -> SetOption("nn");
+      TRDtrack -> CookPID();
+      for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
+        pid[iPart] = TRDtrack -> GetPID(iPart);
+        AliDebug(4, Form("PDG is (in V0info) %d %f", iPart, pid[iPart]));
+      }
+    }
+    break;
+  default:
+    AliWarning("PID reference source not implemented");
+    return;
   }
 }
 
index f3d013be7beb8fcbf9440de244e7af5924ca2cd0..f962c6c16dabc8ac7fe0c04ef9419693cd3b71ac 100644 (file)
@@ -27,7 +27,6 @@
 
 class TTree;
 class TObjArray;
-class TEventList;
 class AliTRDReconstructor;
 class AliTRDseedV1;
 class AliTRDpidRefMaker : public AliTRDrecoTask
@@ -61,25 +60,20 @@ public:
   void    CreateOutputObjects();
   void    Exec(Option_t *option);
 
-  void    LoadContainer(const Char_t *InFileCont);
-  void    LoadFile(const Char_t *InFile);
-
   void    SetAbundance(Float_t train, Float_t test);
-  void    SetRefPID(void *source, Float_t *pid);
+  void    SetRefPID(ETRDpidRefMakerSource select, void *source, Float_t *pid);
   void    SetSource(ETRDpidRefMakerSource pid, ETRDpidRefMakerSource momentum) {fRefPID = pid; fRefP = momentum;}
 
   void    Terminate(Option_t *);
 
 protected:
-  virtual Float_t* GetdEdx(AliTRDseedV1*) = 0;
+  virtual Float_t* CookdEdx(AliTRDseedV1*) = 0;
   virtual Int_t    GetNslices() = 0;
   virtual void     Fill();
 
   AliTRDReconstructor *fReconstructor;  //! reconstructor needed for recalculation the PID
   TObjArray     *fV0s;                  //! v0 array
   TTree         *fData;                 //! dEdx-P data
-  TEventList *fTrain[AliTRDCalPID::kNMom][AliTRDgeometry::kNlayer];          // Training list for each momentum 
-  TEventList *fTest[AliTRDCalPID::kNMom][AliTRDgeometry::kNlayer];           // Test list for each momentum 
   ETRDpidRefMakerSource fRefPID;     // reference PID source
   ETRDpidRefMakerSource fRefP;       // reference momentum source
   Float_t       fTrainFreq;             //! training sample relative abundance
index d6f062d92f7e93b895a372f8d8762a907f730934..c22c77a705188087c19786eb3e914c86d190a84a 100644 (file)
@@ -107,7 +107,7 @@ void AliTRDpidRefMakerLQ::CreateOutputObjects()
 
 
 //________________________________________________________________________
-Float_t* AliTRDpidRefMakerLQ::GetdEdx(AliTRDseedV1 *trklt)
+Float_t* AliTRDpidRefMakerLQ::CookdEdx(AliTRDseedV1 *trklt)
 {
   trklt->CookdEdx(AliTRDpidUtil::kLQslices);
   const Float_t *dedx = trklt->GetdEdx();
@@ -119,11 +119,17 @@ Float_t* AliTRDpidRefMakerLQ::GetdEdx(AliTRDseedV1 *trklt)
   return fdEdx;
 }
 
+#include "../Cal/AliTRDCalPIDLQ.h"
 
 //__________________________________________________________________
-Bool_t AliTRDpidRefMakerLQ::GenerateOCDBEntry(Option_t *)
+TObject* AliTRDpidRefMakerLQ::GetOCDBEntry(Option_t *opt)
 {
-  return kTRUE;
+  TDirectoryFile *d = 0x0;
+  if(!TFile::Open(Form("TRD.Calib%s.root", GetName()))) return 0x0;
+  if(!(d=(TDirectoryFile*)gFile->Get(Form("PDF_%s", opt)))) return 0x0;
+  AliTRDCalPIDLQ *cal = new AliTRDCalPIDLQ("pidLQ", "LQ TRD PID object");
+  cal->LoadPDF(d);
+  return cal;
 }
 
 //__________________________________________________________________
@@ -147,7 +153,7 @@ Bool_t AliTRDpidRefMakerLQ::GetRefFigure(Int_t ifig)
   TList *l=gPad->GetListOfPrimitives(); 
   for(Int_t is=0; is<AliPID::kSPECIES; is++){
     ((TVirtualPad*)l->At(is))->cd();
-    ((TH2*)arr->At(is))->Draw("colz");
+    ((TH2*)arr->At(is))->Draw("cont4z");
   }
 
   return kTRUE;
@@ -167,28 +173,40 @@ void AliTRDpidRefMakerLQ::Fill()
   ((TH2*)fContainer->At(0))->Fill(fSbin, fPbin);
   TH2* h2 = (TH2*)((TObjArray*)fContainer->At(1+fPbin))->At(fSbin);
   h2->Fill(fdEdx[0], fdEdx[1]);
-  //printf("h[%s] : [%f] [%f]\n", h2->GetName(), fdEdx[0], fdEdx[1]);
 }
 
 //________________________________________________________________________
 Bool_t AliTRDpidRefMakerLQ::PostProcess()
 {
-  TFile::Open(Form("TRD.Calib%s.root", GetName()));
+// Analyse merged dedx = f(p) distributions.
+//   - select momentum - species bins
+//   - rotate to principal components
+//   - locally interpolate with TKDPDF
+//   - save interpolation to monitoring histograms
+//   - write pdf to file for loading to OCDB
+// 
+
+
+  TFile *fCalib = TFile::Open(Form("TRD.Calib%s.root", GetName()), "update");
   fData = dynamic_cast<TTree*>(gFile->Get(GetName()));
   if (!fData) {
     AliError("Tree not available");
     return kFALSE;
   }
+  TDatime d;
+  TDirectoryFile *pdfs = new TDirectoryFile(Form("PDF_%d", d.GetDate()), "PDFs for LQ TRD-PID", "", gFile);
+  pdfs->Write();
   AliDebug(2, Form("Data[%d]", fData->GetEntries()));
 
-  // save PDF representation
+  // save a volatile PDF representation
+  gROOT->cd();
   TH2 *h2 = 0x0;
   fResults = new TObjArray(AliTRDCalPID::kNMom);
   for(Int_t ip=AliTRDCalPID::kNMom; ip--;){ 
     TObjArray *arr = new TObjArray(AliPID::kSPECIES);
     arr->SetName(Form("Pbin%02d", ip));
     for(Int_t is=AliPID::kSPECIES; is--;) {
-      h2 = new TH2I(Form("h%s%d", AliPID::ParticleShortName(is), ip), Form("%s ref. dEdx @ Pbin[%d]", AliPID::ParticleName(is), ip), 50, -6., 6., 50, -6., 6.);
+      h2 = new TH2D(Form("i%s%d", AliPID::ParticleShortName(is), ip), Form("Interpolated %s dEdx @ Pbin[%d]", AliPID::ParticleName(is), ip), 50, -3., 3., 50, -3., 3.);
       h2->GetXaxis()->SetTitle("log(dE/dx^{*}_{am}) [au]");
       h2->GetYaxis()->SetTitle("log(dE/dx^{*}_{dr}) [au]");
       h2->GetZaxis()->SetTitle("#");
@@ -196,19 +214,27 @@ Bool_t AliTRDpidRefMakerLQ::PostProcess()
     }
     fResults->AddAt(arr, ip);
   }
-
+  pdfs->cd();
 
   TCanvas *cc = new TCanvas("cc", "", 500, 500);
 
   Float_t *data[] = {0x0, 0x0};
   TPrincipal principal(2, "ND");
-  for(Int_t ip=AliTRDCalPID::kNMom; ip--;){ 
+  for(Int_t ip=AliTRDCalPID::kNMom; ip--; ){ 
     for(Int_t is=AliPID::kSPECIES; is--;) {
       principal.Clear();
       Int_t n = fData->Draw("dEdx[0]:dEdx[1]", Form("p==%d&&s==%d", ip, is), "goff");
-      AliDebug(2, Form("pBin[%d] sBin[%d] n[%d]", ip, is, n));
-      if(n<1000/*Int_t(kMinStat)*Int_t(kMinBuckets)*/){
-        AliWarning(Form("Not enough entries [%d] for %s[%d].", n, AliPID::ParticleShortName(is), ip));
+
+      // estimate bucket statistics
+      Int_t nb(kMinBuckets), // number of buckets
+            ns(Int_t(Float_t(n)/nb));    //statistics/bucket
+            
+// if(Float_t(n)/nb < 220.) ns = 200; // 7% stat error
+//       else if(Float_t(n)/nb < 420.) ns = 400; // 5% stat error
+
+      AliDebug(2, Form("pBin[%d] sBin[%d] N[%d] n[%d] nb[%d]", ip, is, n, ns, nb));
+      if(ns<Int_t(kMinStat)){
+        AliWarning(Form("Not enough entries [%d] for %s[%d].", ns, AliPID::ParticleShortName(is), ip));
         continue;
       }
       // allocate storage
@@ -236,12 +262,6 @@ Bool_t AliTRDpidRefMakerLQ::PostProcess()
         data[0][n]=rxy[0]; data[1][n]=rxy[1];
       }
 
-      // estimate bucket statistics
-      Int_t ns(kMinStat),    //statistics/bucket
-            nb(kMinBuckets); // number of buckets
-      if(Float_t(n)/nb < 220.) ns = 200; // 7% stat error
-      else if(Float_t(n)/nb < 420.) ns = 400; // 5% stat error
-
       // build PDF
       TKDPDF pdf(n, 2, ns, data);
       pdf.SetStore();
@@ -253,10 +273,10 @@ Bool_t AliTRDpidRefMakerLQ::PostProcess()
         rxy[0] = (Double_t)c[0];rxy[1] = (Double_t)c[1];
         pdf.Eval(rxy, r, e, kTRUE);
       }
-      pdf.DrawBins(0,1,-6,6,-6,6);cc->Modified(); cc->Update();
+      // visual on-line monitoring
+      pdf.DrawBins(0,1,-5.,5.,-8.,8.);cc->Modified(); cc->Update(); cc->SaveAs(Form("pdf_%s%02d.gif", AliPID::ParticleShortName(is), ip));
 
-
-      // save a discretization of the PDF for monitoring
+      // save a discretization of the PDF for result monitoring
       TH2 *h2s = (TH2D*)((TObjArray*)fResults->At(ip))->At(is);
       TAxis *ax = h2s->GetXaxis(), *ay = h2s->GetYaxis();
       for(int ix=1; ix<=ax->GetNbins(); ix++){
@@ -272,13 +292,14 @@ Bool_t AliTRDpidRefMakerLQ::PostProcess()
         }
       }
 
-
-      //pdf.Write(Form("%s[%d]", AliPID::ParticleShortName(is), ip));
-      
+      // write results to output array
+      pdf.Write(Form("%s[%d]", AliPID::ParticleShortName(is), ip));
 
       delete [] data[0]; delete [] data[1];
     }
   }
+  pdfs->Write();
+  fCalib->Close(); delete fCalib;
 
   return kTRUE; // testing protection
 }
index a3f7f2d68e45a543e5facbda96eb33be486f176d..387f506a3678ca06c3c725ca713faf22581af733 100644 (file)
@@ -27,19 +27,19 @@ class TObjArray;
 class AliTRDpidRefMakerLQ : public AliTRDpidRefMaker {
 public:
   enum ETRDpidRefMakerLQsteer{
-    kMinStat = 100    // minimum statistics/bucket 10%
+    kMinStat = 50    // minimum statistics/bucket 14%
    ,kMinBuckets = 450 // minimum number of buckets [lambda(6)*alpha(1.5)*regions(50)]
   };
   AliTRDpidRefMakerLQ();
   ~AliTRDpidRefMakerLQ();
  
   void      CreateOutputObjects();
-  Bool_t    GenerateOCDBEntry(Option_t *);
+  TObject*  GetOCDBEntry(Option_t *);
   Bool_t    GetRefFigure(Int_t ifig);
   Bool_t    PostProcess();
 
 protected:
-  Float_t*  GetdEdx(AliTRDseedV1*);
+  Float_t*  CookdEdx(AliTRDseedV1*);
   Int_t     GetNslices() { return 2;}
   void      Fill();