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 ////////////////////////////////////////////////////////////////////////////
29 #include <TMultiLayerPerceptron.h>
34 #include "AliTRDgeometry.h"
35 #include "AliTRDCalPIDNN.h"
37 ClassImp(AliTRDCalPIDNN)
39 //_________________________________________________________________________
40 AliTRDCalPIDNN::AliTRDCalPIDNN()
41 :AliTRDCalPID("pid", "NN PID references for TRD")
44 // The Default constructor
51 //_________________________________________________________________________
52 AliTRDCalPIDNN::AliTRDCalPIDNN(const Text_t *name, const Text_t *title)
53 :AliTRDCalPID(name,title)
56 // The main constructor
63 // //_____________________________________________________________________________
64 // AliTRDCalPIDNN::AliTRDCalPIDNN(const AliTRDCalPIDNN &c)
66 // ,fMeanChargeRatio(c.fMeanChargeRatio)
70 // // Copy constructor
73 // if (this != &c) ((AliTRDCalPIDNN &) c).Copy(*this);
77 //_________________________________________________________________________
78 AliTRDCalPIDNN::~AliTRDCalPIDNN()
84 //if (fModel) delete fModel;
88 //_________________________________________________________________________
89 Bool_t AliTRDCalPIDNN::LoadReferences(Char_t *refFile)
92 // Read the TRD Neural Networks
96 TFile *nnFile = TFile::Open(refFile,"READ");
97 if (!nnFile || !nnFile->IsOpen()) {
98 AliError(Form("Opening TRD histgram file %s failed",refFile));
104 for (Int_t imom = 0; imom < kNMom; imom++) {
105 for (Int_t iplane = 0; iplane < AliTRDgeometry::kNlayer; iplane++) {
106 TMultiLayerPerceptron *nn = (TMultiLayerPerceptron *)
107 nnFile->Get(Form("NN_Mom%d_Plane%d",imom,iplane));
108 fModel->AddAt(nn,GetModelID(imom,0,iplane));
119 //_________________________________________________________________________
120 TObject *AliTRDCalPIDNN::GetModel(Int_t ip, Int_t, Int_t iplane) const
123 // Returns one selected TMultiLayerPerceptron. iType not used.
126 if (ip<0 || ip>= kNMom) return 0x0;
128 AliInfo(Form("Retrive MultiLayerPerceptron for %5.2f GeV/c for plane %d"
132 return fModel->At(GetModelID(ip, 0, iplane));
136 //_________________________________________________________________________
137 Double_t AliTRDCalPIDNN::GetProbability(Int_t spec, Float_t mom
138 , const Float_t * const dedx
139 , Float_t, Int_t iplane) const
142 // Core function of AliTRDCalPID class for calculating the
143 // likelihood for species "spec" (see AliTRDtrack::kNspecie) of a
144 // given momentum "mom", a given dE/dx (slice "dedx") yield per
145 // layer in a given layer (iplane)
148 if (spec < 0 || spec >= AliPID::kSPECIES) return 0.;
150 // find the interval in momentum and track segment length which applies for this data
153 while (imom<AliTRDCalPID::kNMom-1 && mom>fgTrackMomentum[imom]) imom++;
155 Double_t mom1 = fgTrackMomentum[imom-1], mom2 = fgTrackMomentum[imom];
157 TMultiLayerPerceptron *nn = 0x0;
158 if(!(nn = (TMultiLayerPerceptron *) fModel->At(GetModelID(imom-1, spec, iplane/*, ilength*/)))){
159 AliInfo(Form("Looking for mom(%f) plane(%d)", mom-1, iplane));
160 AliError(Form("NN id %d not found in DB.", GetModelID(imom-1, spec, iplane)));
164 Double_t ddedx[AliTRDCalPID::kNSlicesNN];
166 for (int inode=0; inode<AliTRDCalPID::kNSlicesNN; inode++) {
167 ddedx[inode] = (Double_t) dedx[inode]/kMLPscale;
170 lNN1 = nn->Evaluate(spec, ddedx);
172 if(!(nn = (TMultiLayerPerceptron*)fModel->At(GetModelID(imom, spec, iplane/*, ilength*/)))){
173 AliInfo(Form("Looking for mom(%f) plane(%d)", mom, iplane));
174 AliError(Form("NN id %d not found in DB.", GetModelID(imom, spec, iplane)));
177 lNN2 = nn->Evaluate(spec, ddedx);
179 // return interpolation over momentum binning
180 if (mom < fgTrackMomentum[0]) {
183 else if (mom > fgTrackMomentum[AliTRDCalPID::kNMom-1]) {
187 return lNN1 + (lNN2 - lNN1)*(mom - mom1)/(mom2 - mom1);
192 //_________________________________________________________________________
193 void AliTRDCalPIDNN::Init()
199 fModel = new TObjArray(AliTRDgeometry::kNlayer * AliTRDCalPID::kNMom);
204 //_________________________________________________________________________
205 Int_t AliTRDCalPIDNN::GetModelID(Int_t mom, Int_t /*ii*/, Int_t plane)
208 // returns the ID of the NN distribution (66 MLPs, ID from 56 to 121)
210 return /*AliPID::kSPECIES * AliTRDCalPID::kNMom + */
211 plane * AliTRDCalPID::kNMom + mom;