1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // Container of the distributions for the neural network //
23 // Alex Wilk <wilka@uni-muenster.de> //
25 ////////////////////////////////////////////////////////////////////////////
30 #include <TMultiLayerPerceptron.h>
35 #include "AliESDtrack.h"
36 #include "AliTRDtrack.h"
38 #include "AliTRDCalPIDNN.h"
39 #include "AliTRDcalibDB.h"
41 ClassImp(AliTRDCalPIDNN)
43 //_________________________________________________________________________
44 AliTRDCalPIDNN::AliTRDCalPIDNN()
45 :AliTRDCalPID("pid", "NN PID references for TRD")
48 // The Default constructor
55 //_________________________________________________________________________
56 AliTRDCalPIDNN::AliTRDCalPIDNN(const Text_t *name, const Text_t *title)
57 :AliTRDCalPID(name,title)
60 // The main constructor
67 // //_____________________________________________________________________________
68 // AliTRDCalPIDNN::AliTRDCalPIDNN(const AliTRDCalPIDNN &c)
70 // ,fMeanChargeRatio(c.fMeanChargeRatio)
74 // // Copy constructor
77 // if (this != &c) ((AliTRDCalPIDNN &) c).Copy(*this);
81 //_________________________________________________________________________
82 AliTRDCalPIDNN::~AliTRDCalPIDNN()
88 //if (fModel) delete fModel;
92 //_________________________________________________________________________
93 Bool_t AliTRDCalPIDNN::LoadReferences(Char_t *refFile)
96 // Read the TRD Neural Networks
100 TFile *nnFile = TFile::Open(refFile,"READ");
101 if (!nnFile || !nnFile->IsOpen()) {
102 AliError(Form("Opening TRD histgram file %s failed",refFile));
108 for (Int_t imom = 0; imom < kNMom; imom++) {
109 for (Int_t iplane = 0; iplane < kNPlane; iplane++) {
110 TMultiLayerPerceptron *nn = (TMultiLayerPerceptron *)
111 nnFile->Get(Form("NN_Mom%d_Plane%d",imom,iplane));
112 fModel->AddAt(nn,GetModelID(imom,0,iplane));
123 //_________________________________________________________________________
124 TObject *AliTRDCalPIDNN::GetModel(Int_t ip, Int_t, Int_t iplane) const
127 // Returns one selected TMultiLayerPerceptron. iType not used.
130 if (ip<0 || ip>= kNMom) return 0x0;
132 AliInfo(Form("Retrive MultiLayerPerceptron for %5.2f GeV/c for plane %d"
136 return fModel->At(GetModelID(ip, 0, iplane));
140 //_________________________________________________________________________
141 Double_t AliTRDCalPIDNN::GetProbability(Int_t spec, Float_t mom, Float_t *dedx
142 , Float_t, Int_t iplane) const
145 // Core function of AliTRDCalPID class for calculating the
146 // likelihood for species "spec" (see AliTRDtrack::kNspecie) of a
147 // given momentum "mom", a given dE/dx (slice "dedx") yield per
148 // layer in a given layer (iplane)
151 if (spec < 0 || spec >= AliPID::kSPECIES) return 0.;
153 // find the interval in momentum and track segment length which applies for this data
156 while (imom<AliTRDCalPID::kNMom-1 && mom>fTrackMomentum[imom]) imom++;
158 Double_t mom1 = fTrackMomentum[imom-1], mom2 = fTrackMomentum[imom];
160 TMultiLayerPerceptron *nn = 0x0;
161 if(!(nn = (TMultiLayerPerceptron *) fModel->At(GetModelID(imom-1, spec, iplane/*, ilength*/)))){
162 AliInfo(Form("Looking for mom(%f) plane(%d)", mom-1, iplane));
163 AliError(Form("NN id %d not found in DB.", GetModelID(imom-1, spec, iplane)));
167 Double_t ddedx[AliTRDtrack::kNMLPslice];
169 for (int inode=0; inode<AliTRDtrack::kNMLPslice; inode++) {
170 ddedx[inode] = (((Double_t) dedx[inode]/kMLPscale)*6) // Bug fix! Needs new reference data or different calculation of dedx!!!!
171 / (AliTRDcalibDB::Instance()->GetNumberOfTimeBins()/AliTRDtrack::kNMLPslice);
174 lNN1 = nn->Evaluate(spec, ddedx);
176 if(!(nn = (TMultiLayerPerceptron*)fModel->At(GetModelID(imom, spec, iplane/*, ilength*/)))){
177 AliInfo(Form("Looking for mom(%f) plane(%d)", mom, iplane));
178 AliError(Form("NN id %d not found in DB.", GetModelID(imom, spec, iplane)));
181 lNN2 = nn->Evaluate(spec, ddedx);
183 // return interpolation over momentum binning
184 if (mom < fTrackMomentum[0]) {
187 else if (mom > fTrackMomentum[AliTRDCalPID::kNMom-1]) {
191 return lNN1 + (lNN2 - lNN1)*(mom - mom1)/(mom2 - mom1);
196 //_________________________________________________________________________
197 void AliTRDCalPIDNN::Init()
203 fModel = new TObjArray(AliTRDCalPID::kNPlane * AliTRDCalPID::kNMom);
208 //_________________________________________________________________________
209 Int_t AliTRDCalPIDNN::GetModelID(Int_t mom, Int_t, Int_t plane) const
212 // returns the ID of the NN distribution (66 MLPs, ID from 56 to 121)
214 return /*AliPID::kSPECIES * AliTRDCalPID::kNMom + */
215 plane * AliTRDCalPID::kNMom + mom;