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 "AliTRDgeometry.h"
39 #include "AliTRDCalPIDNN.h"
40 #include "AliTRDcalibDB.h"
42 ClassImp(AliTRDCalPIDNN)
44 //_________________________________________________________________________
45 AliTRDCalPIDNN::AliTRDCalPIDNN()
46 :AliTRDCalPID("pid", "NN PID references for TRD")
49 // The Default constructor
56 //_________________________________________________________________________
57 AliTRDCalPIDNN::AliTRDCalPIDNN(const Text_t *name, const Text_t *title)
58 :AliTRDCalPID(name,title)
61 // The main constructor
68 // //_____________________________________________________________________________
69 // AliTRDCalPIDNN::AliTRDCalPIDNN(const AliTRDCalPIDNN &c)
71 // ,fMeanChargeRatio(c.fMeanChargeRatio)
75 // // Copy constructor
78 // if (this != &c) ((AliTRDCalPIDNN &) c).Copy(*this);
82 //_________________________________________________________________________
83 AliTRDCalPIDNN::~AliTRDCalPIDNN()
89 //if (fModel) delete fModel;
93 //_________________________________________________________________________
94 Bool_t AliTRDCalPIDNN::LoadReferences(Char_t *refFile)
97 // Read the TRD Neural Networks
101 TFile *nnFile = TFile::Open(refFile,"READ");
102 if (!nnFile || !nnFile->IsOpen()) {
103 AliError(Form("Opening TRD histgram file %s failed",refFile));
109 for (Int_t imom = 0; imom < kNMom; imom++) {
110 for (Int_t iplane = 0; iplane < AliTRDgeometry::kNlayer; iplane++) {
111 TMultiLayerPerceptron *nn = (TMultiLayerPerceptron *)
112 nnFile->Get(Form("NN_Mom%d_Plane%d",imom,iplane));
113 fModel->AddAt(nn,GetModelID(imom,0,iplane));
124 //_________________________________________________________________________
125 TObject *AliTRDCalPIDNN::GetModel(Int_t ip, Int_t, Int_t iplane) const
128 // Returns one selected TMultiLayerPerceptron. iType not used.
131 if (ip<0 || ip>= kNMom) return 0x0;
133 AliInfo(Form("Retrive MultiLayerPerceptron for %5.2f GeV/c for plane %d"
137 return fModel->At(GetModelID(ip, 0, iplane));
141 //_________________________________________________________________________
142 Double_t AliTRDCalPIDNN::GetProbability(Int_t spec, Float_t mom, Float_t *dedx
143 , Float_t, Int_t iplane) const
146 // Core function of AliTRDCalPID class for calculating the
147 // likelihood for species "spec" (see AliTRDtrack::kNspecie) of a
148 // given momentum "mom", a given dE/dx (slice "dedx") yield per
149 // layer in a given layer (iplane)
152 if (spec < 0 || spec >= AliPID::kSPECIES) return 0.;
154 // find the interval in momentum and track segment length which applies for this data
157 while (imom<AliTRDCalPID::kNMom-1 && mom>fTrackMomentum[imom]) imom++;
159 Double_t mom1 = fTrackMomentum[imom-1], mom2 = fTrackMomentum[imom];
161 TMultiLayerPerceptron *nn = 0x0;
162 if(!(nn = (TMultiLayerPerceptron *) fModel->At(GetModelID(imom-1, spec, iplane/*, ilength*/)))){
163 AliInfo(Form("Looking for mom(%f) plane(%d)", mom-1, iplane));
164 AliError(Form("NN id %d not found in DB.", GetModelID(imom-1, spec, iplane)));
168 Double_t ddedx[AliTRDtrack::kNMLPslice];
170 for (int inode=0; inode<AliTRDtrack::kNMLPslice; inode++) {
171 ddedx[inode] = (((Double_t) dedx[inode]/kMLPscale)*3) // Bug fix! Needs new reference data or different calculation of dedx!!!!
172 / (AliTRDcalibDB::Instance()->GetNumberOfTimeBins()/AliTRDtrack::kNMLPslice);
175 lNN1 = nn->Evaluate(spec, ddedx);
177 if(!(nn = (TMultiLayerPerceptron*)fModel->At(GetModelID(imom, spec, iplane/*, ilength*/)))){
178 AliInfo(Form("Looking for mom(%f) plane(%d)", mom, iplane));
179 AliError(Form("NN id %d not found in DB.", GetModelID(imom, spec, iplane)));
182 lNN2 = nn->Evaluate(spec, ddedx);
184 // return interpolation over momentum binning
185 if (mom < fTrackMomentum[0]) {
188 else if (mom > fTrackMomentum[AliTRDCalPID::kNMom-1]) {
192 return lNN1 + (lNN2 - lNN1)*(mom - mom1)/(mom2 - mom1);
197 //_________________________________________________________________________
198 void AliTRDCalPIDNN::Init()
204 fModel = new TObjArray(AliTRDgeometry::kNlayer * AliTRDCalPID::kNMom);
209 //_________________________________________________________________________
210 Int_t AliTRDCalPIDNN::GetModelID(Int_t mom, Int_t, Int_t plane) const
213 // returns the ID of the NN distribution (66 MLPs, ID from 56 to 121)
215 return /*AliPID::kSPECIES * AliTRDCalPID::kNMom + */
216 plane * AliTRDCalPID::kNMom + mom;