New directory for the VMC tests (Ivana, Eva)
[u/mrichter/AliRoot.git] / TRD / qaRec / AliTRDpidRefMakerNN.cxx
CommitLineData
e9987811 1/*************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercialf 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**************************************************************************/
15
16/* $Id: AliTRDpidRefMakerNN.cxx 27496 2008-07-22 08:35:45Z cblume $ */
17
18////////////////////////////////////////////////////////////////////////////
19// //
20// Builds the reference tree for the training of neural networks //
21// //
22////////////////////////////////////////////////////////////////////////////
23
72f5f463 24#include "TSystem.h"
25#include "TDatime.h"
398f8388 26#include "TPDGCode.h"
27#include "TH1F.h"
ee8fb199 28#include "TH2F.h"
398f8388 29#include "TFile.h"
72f5f463 30#include "TGraphErrors.h"
398f8388 31#include "TTree.h"
398f8388 32#include "TEventList.h"
72f5f463 33#include "TMultiLayerPerceptron.h"
34
72f5f463 35#include "AliPID.h"
e9987811 36#include "AliESDtrack.h"
398f8388 37#include "AliTrackReference.h"
38
398f8388 39#include "AliTRDtrackV1.h"
40#include "AliTRDReconstructor.h"
72f5f463 41#include "AliTRDpidUtil.h"
72f5f463 42#include "AliTRDpidRefMakerNN.h"
ee8fb199 43#include "AliTRDpidUtil.h"
e9987811 44
45#include "../Cal/AliTRDCalPID.h"
46#include "../Cal/AliTRDCalPIDNN.h"
72f5f463 47#include "info/AliTRDtrackInfo.h"
398f8388 48#include "info/AliTRDv0Info.h"
72f5f463 49
72f5f463 50ClassImp(AliTRDpidRefMakerNN)
51
52//________________________________________________________________________
53AliTRDpidRefMakerNN::AliTRDpidRefMakerNN()
ee8fb199 54 :AliTRDpidRefMaker("PidRefMakerNN", "PID(NN) Reference Maker")
55// :AliTRDrecoTask("PidRefMakerNN", "PID(NN) Reference Maker")
72f5f463 56 ,fTrainMomBin(kAll)
57 ,fEpochs(1000)
58 ,fMinTrain(100)
59 ,fDate(0)
60 ,fDoTraining(0)
61 ,fContinueTraining(0)
62 ,fTrainPath(0x0)
ee8fb199 63 ,fScale(0)
72f5f463 64{
65 //
66 // Default constructor
67 //
398f8388 68
ee8fb199 69 memset(fTrain, 0, AliTRDCalPID::kNMom*AliTRDgeometry::kNlayer*sizeof(TEventList*));
70 memset(fTest, 0, AliTRDCalPID::kNMom*AliTRDgeometry::kNlayer*sizeof(TEventList*));
398f8388 71 memset(fNet, 0, AliTRDgeometry::kNlayer*sizeof(TMultiLayerPerceptron*));
72
ee8fb199 73 SetAbundance(.67);
74 SetScaledEdx(Float_t(AliTRDCalPIDNN::kMLPscale));
72f5f463 75 TDatime datime;
76 fDate = datime.GetDate();
398f8388 77
78 DefineInput(1, TObjArray::Class());
79 DefineOutput(1, TTree::Class());
72f5f463 80}
81
82
83//________________________________________________________________________
84AliTRDpidRefMakerNN::~AliTRDpidRefMakerNN()
85{
86}
87
88
89//________________________________________________________________________
90void AliTRDpidRefMakerNN::CreateOutputObjects()
91{
92 // Create histograms
93 // Called once
398f8388 94
ee8fb199 95 AliTRDpidRefMaker::CreateOutputObjects();
72f5f463 96 TGraphErrors *gEffisTrain = new TGraphErrors(kMoniTrain);
97 gEffisTrain -> SetLineColor(4);
98 gEffisTrain -> SetMarkerColor(4);
99 gEffisTrain -> SetMarkerStyle(29);
100 gEffisTrain -> SetMarkerSize(1);
101
102 TGraphErrors *gEffisTest = new TGraphErrors(kMoniTrain);
103 gEffisTest -> SetLineColor(2);
104 gEffisTest -> SetMarkerColor(2);
105 gEffisTest -> SetMarkerStyle(29);
106 gEffisTest -> SetMarkerSize(1);
107
108 fContainer -> AddAt(gEffisTrain,kGraphTrain);
109 fContainer -> AddAt(gEffisTest,kGraphTest);
398f8388 110}
111
112
72f5f463 113
114//________________________________________________________________________
115Bool_t AliTRDpidRefMakerNN::PostProcess()
116{
117 // Draw result to the screen
118 // Called once at the end of the query
119
120 // build the training andthe test list for the neural networks
398f8388 121 MakeTrainingLists();
72f5f463 122 if(!fDoTraining) return kTRUE;
123
124 // train the neural networks and build the refrence histos for 2-dim LQ
125 gSystem->Exec(Form("mkdir ./Networks_%d/",fDate));
dad3aa6b 126 AliDebug(2, Form("TrainMomBin [%d] [%d]", fTrainMomBin, kAll));
72f5f463 127
128 // train single network for a single momentum (recommended)
129 if(!(fTrainMomBin == kAll)){
130 if(fTrain[fTrainMomBin][0] -> GetN() < fMinTrain){
dad3aa6b 131 AliDebug(2, Form("Warning in AliTRDpidRefMakerNN::PostProcess : Not enough events for training available! Please check Data sample!"));
72f5f463 132 return kFALSE;
133 }
ee8fb199 134 MakeRefs(fTrainMomBin);
135// TrainNetworks(fTrainMomBin);
72f5f463 136 MonitorTraining(fTrainMomBin);
137 }
138 // train all momenta
139 else{
140 for(Int_t iMomBin = 0; iMomBin < AliTRDCalPID::kNMom; iMomBin++){
141 if(fTrain[iMomBin][0] -> GetN() < fMinTrain){
dad3aa6b 142 AliDebug(2, Form("Warning in AliTRDpidRefMakerNN::PostProcess : Not enough events for training available for momentum bin [%d]! Please check Data sample!", iMomBin));
ee8fb199 143 continue;
72f5f463 144 }
ee8fb199 145 MakeRefs(fTrainMomBin);
146// TrainNetworks(iMomBin);
72f5f463 147 MonitorTraining(iMomBin);
148 }
149 }
150
151 return kTRUE; // testing protection
152}
153
154
398f8388 155//________________________________________________________________________
398f8388 156void AliTRDpidRefMakerNN::MakeTrainingLists()
157{
158 //
159 // build the training lists for the neural networks
160 //
161
ee8fb199 162 if (!fData) {
398f8388 163 LoadFile("TRD.CalibPidRefMakerNN.root");
164 }
165
ee8fb199 166 if (!fData) {
398f8388 167 Printf("ERROR tree for training list not available");
168 return;
169 }
170
dad3aa6b 171 AliDebug(2, " Making training lists! \n");
398f8388 172
173 Int_t nPart[AliPID::kSPECIES][AliTRDCalPID::kNMom];
174 memset(nPart, 0, AliPID::kSPECIES*AliTRDCalPID::kNMom*sizeof(Int_t));
175
176 // set needed branches
ee8fb199 177 LinkPIDdata();
398f8388 178
179 // start first loop to check total number of each particle type
ee8fb199 180 for(Int_t iEv=0; iEv < fData -> GetEntries(); iEv++){
181 fData -> GetEntry(iEv);
398f8388 182
183 // use only events with goes through 6 layers TRD
ee8fb199 184 if(fPIDdataArray->fNtracklets != AliTRDgeometry::kNlayer) continue;
398f8388 185
ee8fb199 186 for(Int_t ily=AliTRDgeometry::kNlayer; ily--;) nPart[fPIDbin][fPIDdataArray->fData[ily].fPLbin & 0xf]++;
398f8388 187 }
188
dad3aa6b 189 AliDebug(2, "Particle multiplicities:");
190 for(Int_t iMomBin = 0; iMomBin <AliTRDCalPID::kNMom; iMomBin++)
191 AliDebug(2, Form("Momentum[%d] Elecs[%d] Muons[%d] Pions[%d] Kaons[%d] Protons[%d]", iMomBin, nPart[AliPID::kElectron][iMomBin], nPart[AliPID::kMuon][iMomBin], nPart[AliPID::kPion][iMomBin], nPart[AliPID::kKaon][iMomBin], nPart[AliPID::kProton][iMomBin]));
398f8388 192
193 // implement counter of training and test sample size
194 Int_t iTrain[AliTRDCalPID::kNMom], iTest[AliTRDCalPID::kNMom];
195 memset(iTrain, 0, AliTRDCalPID::kNMom*sizeof(Int_t));
196 memset(iTest, 0, AliTRDCalPID::kNMom*sizeof(Int_t));
197
198 // set training sample size per momentum interval to 2/3
199 // of smallest particle counter and test sample to 1/3
200 for(Int_t iMomBin = 0; iMomBin < AliTRDCalPID::kNMom; iMomBin++){
201 iTrain[iMomBin] = nPart[0][iMomBin];
202 for(Int_t iPart = 1; iPart < AliPID::kSPECIES; iPart++){
203 if(iTrain[iMomBin] > nPart[iPart][iMomBin])
ee8fb199 204 iTrain[iMomBin] = nPart[iPart][iMomBin];
398f8388 205 }
206 iTrain[iMomBin] = Int_t(iTrain[iMomBin] * .66);
207 iTest[iMomBin] = Int_t( iTrain[iMomBin] * .5);
dad3aa6b 208 AliDebug(2, Form("Momentum[%d] Train[%d] Test[%d]", iMomBin, iTrain[iMomBin], iTest[iMomBin]));
398f8388 209 }
398f8388 210
211
212 // reset couters
213 memset(nPart, 0, AliPID::kSPECIES*AliTRDCalPID::kNMom*sizeof(Int_t));
214
215 // start second loop to set the event lists
ee8fb199 216 for(Int_t iEv = 0; iEv < fData -> GetEntries(); iEv++){
217 fData -> GetEntry(iEv);
398f8388 218
219 // use only events with goes through 6 layers TRD
ee8fb199 220 if(fPIDdataArray->fNtracklets != AliTRDgeometry::kNlayer) continue;
398f8388 221
ee8fb199 222 for(Int_t ily=AliTRDgeometry::kNlayer; ily--;){
223 Int_t iMomBin = fPIDdataArray->fData[ily].fPLbin & 0xf;
398f8388 224
ee8fb199 225 // set event list
226 if(nPart[fPIDbin][iMomBin] < iTrain[iMomBin]){
227 fTrain[iMomBin][ily] -> Enter(iEv + ily);
228 nPart[fPIDbin][iMomBin]++;
229 } else if(nPart[fPIDbin][iMomBin] < iTest[iMomBin]+iTrain[iMomBin]){
230 fTest[iMomBin][ily] -> Enter(iEv + ily);
231 nPart[fPIDbin][iMomBin]++;
232 } else continue;
398f8388 233 }
234 }
235
dad3aa6b 236 AliDebug(2, "Particle multiplicities in both lists:");
237 for(Int_t iMomBin = 0; iMomBin <AliTRDCalPID::kNMom; iMomBin++)
238 AliDebug(2, Form("Momentum[%d] Elecs[%d] Muons[%d] Pions[%d] Kaons[%d] Protons[%d]", iMomBin, nPart[AliPID::kElectron][iMomBin], nPart[AliPID::kMuon][iMomBin], nPart[AliPID::kPion][iMomBin], nPart[AliPID::kKaon][iMomBin], nPart[AliPID::kProton][iMomBin]));
398f8388 239}
240
241
242//________________________________________________________________________
ee8fb199 243void AliTRDpidRefMakerNN::MakeRefs(Int_t mombin)
72f5f463 244{
245 //
246 // train the neural networks
247 //
248
249
ee8fb199 250 if (!fData) LoadFile(Form("TRD.Calib%s.root", GetName()));
72f5f463 251
ee8fb199 252 if (!fData) {
253 AliError("Tree for training list not available");
72f5f463 254 return;
255 }
256
257 TDatime datime;
258 fDate = datime.GetDate();
259
ee8fb199 260 AliDebug(2, Form("Training momentum bin %d", mombin));
72f5f463 261
262 // set variable to monitor the training and to save the development of the networks
263 Int_t nEpochs = fEpochs/kMoniTrain;
ee8fb199 264 AliDebug(2, Form("Training %d times %d epochs", kMoniTrain, nEpochs));
72f5f463 265
266 // make directories to save the networks
267 gSystem->Exec(Form("rm -r ./Networks_%d/MomBin_%d",fDate, mombin));
268 gSystem->Exec(Form("mkdir ./Networks_%d/MomBin_%d",fDate, mombin));
269
270 // variable to check if network can load weights from previous training
271 Bool_t bFirstLoop[AliTRDgeometry::kNlayer];
272 memset(bFirstLoop, kTRUE, AliTRDgeometry::kNlayer*sizeof(Bool_t));
ee8fb199 273
72f5f463 274 // train networks over several loops and save them after each loop
275 for(Int_t iLoop = 0; iLoop < kMoniTrain; iLoop++){
276 // loop over chambers
277 for(Int_t iChamb = 0; iChamb < AliTRDgeometry::kNlayer; iChamb++){
278 // set the event lists
ee8fb199 279 fData -> SetEventList(fTrain[mombin][iChamb]);
280 fData -> SetEventList(fTest[mombin][iChamb]);
72f5f463 281
ee8fb199 282 AliDebug(2, Form("Trainingloop[%d] Chamber[%d]", iLoop, iChamb));
72f5f463 283
284 // check if network is already implemented
285 if(bFirstLoop[iChamb] == kTRUE){
ee8fb199 286 fNet[iChamb] = new TMultiLayerPerceptron("fdEdx[0],fdEdx[1],fdEdx[2],fdEdx[3],fdEdx[4],fdEdx[5],fdEdx[6],fdEdx[7]:15:7:fPID[0],fPID[1],fPID[2],fPID[3],fPID[4]!",fData,fTrain[mombin][iChamb],fTest[mombin][iChamb]);
287 fNet[iChamb] -> SetLearningMethod(TMultiLayerPerceptron::kStochastic); // set learning method
288 fNet[iChamb] -> TMultiLayerPerceptron::SetEta(0.001); // set learning speed
289 if(!fContinueTraining){
dad3aa6b 290 if(DebugLevel()>=2) fNet[iChamb] -> Train(nEpochs,"text update=10, graph");
ee8fb199 291 else fNet[iChamb] -> Train(nEpochs,"");
292 }
293 else{
294 fNet[iChamb] -> LoadWeights(Form("./Networks_%d/MomBin_%d/Net%d_%d",fTrainPath, mombin, iChamb, kMoniTrain - 1));
dad3aa6b 295 if(DebugLevel()>=2) fNet[iChamb] -> Train(nEpochs,"text update=10, graph+");
ee8fb199 296 else fNet[iChamb] -> Train(nEpochs,"+");
297 }
298 bFirstLoop[iChamb] = kFALSE;
72f5f463 299 }
300 else{
dad3aa6b 301 if(DebugLevel()>=2) fNet[iChamb] -> Train(nEpochs,"text update=10, graph+");
ee8fb199 302 else fNet[iChamb] -> Train(nEpochs,"+");
72f5f463 303 }
304
305 // save weights for monitoring of the training
306 fNet[iChamb] -> DumpWeights(Form("./Networks_%d/MomBin_%d/Net%d_%d",fDate, mombin, iChamb, iLoop));
307 } // end chamber loop
308 } // end training loop
309}
310
311
398f8388 312
72f5f463 313//________________________________________________________________________
314void AliTRDpidRefMakerNN::MonitorTraining(Int_t mombin)
315{
316 //
317 // train the neural networks
318 //
319
ee8fb199 320 if (!fData) LoadFile(Form("TRD.Calib%s.root", GetName()));
321 if (!fData) {
322 AliError("Tree for training list not available");
72f5f463 323 return;
324 }
325
326 // init networks and set event list
327 for(Int_t iChamb = 0; iChamb < AliTRDgeometry::kNlayer; iChamb++){
ee8fb199 328 fNet[iChamb] = new TMultiLayerPerceptron("fdEdx[0],fdEdx[1],fdEdx[2],fdEdx[3],fdEdx[4],fdEdx[5],fdEdx[6],fdEdx[7]:15:7:fPID[0],fPID[1],fPID[2],fPID[3],fPID[4]!",fData,fTrain[mombin][iChamb],fTest[mombin][iChamb]);
329 fData -> SetEventList(fTrain[mombin][iChamb]);
330 fData -> SetEventList(fTest[mombin][iChamb]);
72f5f463 331 }
332
333 // implement variables for likelihoods
e9987811 334 Float_t like[AliPID::kSPECIES][AliTRDgeometry::kNlayer];
335 memset(like, 0, AliPID::kSPECIES*AliTRDgeometry::kNlayer*sizeof(Float_t));
336 Float_t likeAll[AliPID::kSPECIES], totProb;
72f5f463 337
e9987811 338 Double_t pionEffiTrain[kMoniTrain], pionEffiErrTrain[kMoniTrain];
339 Double_t pionEffiTest[kMoniTrain], pionEffiErrTest[kMoniTrain];
340 memset(pionEffiTrain, 0, kMoniTrain*sizeof(Double_t));
341 memset(pionEffiErrTrain, 0, kMoniTrain*sizeof(Double_t));
342 memset(pionEffiTest, 0, kMoniTrain*sizeof(Double_t));
343 memset(pionEffiErrTest, 0, kMoniTrain*sizeof(Double_t));
72f5f463 344
345 // init histos
346 const Float_t epsilon = 1/(2*(AliTRDpidUtil::kBins-1)); // get nice histos with bin center at 0 and 1
347 TH1F *hElecs, *hPions;
348 hElecs = new TH1F("hElecs","Likelihood for electrons", AliTRDpidUtil::kBins, 0.-epsilon, 1.+epsilon);
349 hPions = new TH1F("hPions","Likelihood for pions", AliTRDpidUtil::kBins, 0.-epsilon, 1.+epsilon);
350
351 TGraphErrors *gEffisTrain=0x0, *gEffisTest=0x0;
352 gEffisTrain = (TGraphErrors*)fContainer->At(kGraphTrain);
353 gEffisTest = (TGraphErrors*)fContainer->At(kGraphTest);
354
355 AliTRDpidUtil *util = new AliTRDpidUtil();
356
357 // monitor training progress
358 for(Int_t iLoop = 0; iLoop < kMoniTrain; iLoop++){
359
360 // load weights
361 for(Int_t iChamb = 0; iChamb < AliTRDgeometry::kNlayer; iChamb++){
362 fNet[iChamb] -> LoadWeights(Form("./Networks_%d/MomBin_%d/Net%d_%d",fDate, mombin, iChamb, iLoop));
363 }
364
365 // event loop training list
366 for(Int_t iEvent = 0; iEvent < fTrain[mombin][0] -> GetN(); iEvent++ ){
367
368 // reset particle probabilities
369 for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
ee8fb199 370 likeAll[iPart] = 1./AliPID::kSPECIES;
72f5f463 371 }
e9987811 372 totProb = 0.;
72f5f463 373
ee8fb199 374 fData -> GetEntry(fTrain[mombin][0] -> GetEntry(iEvent));
72f5f463 375 // use event only if it is electron or pion
ee8fb199 376 if(!((fPID[AliPID::kElectron] == 1.0) || (fPID[AliPID::kPion] == 1.0))) continue;
72f5f463 377
378 // get the probabilities for each particle type in each chamber
379 for(Int_t iChamb = 0; iChamb < AliTRDgeometry::kNlayer; iChamb++){
ee8fb199 380 for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
381 like[iPart][iChamb] = fNet[iChamb] -> Result(fTrain[mombin][iChamb] -> GetEntry(iEvent), iPart);
382 likeAll[iPart] *= like[iPart][iChamb];
383 }
72f5f463 384 }
385
386 // get total probability and normalize it
387 for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
ee8fb199 388 totProb += likeAll[iPart];
72f5f463 389 }
390 for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
ee8fb199 391 likeAll[iPart] /= totProb;
72f5f463 392 }
393
394 // fill likelihood distributions
ee8fb199 395 if(fPID[AliPID::kElectron] == 1)
396 hElecs -> Fill(likeAll[AliPID::kElectron]);
397 if(fPID[AliPID::kPion] == 1)
398 hPions -> Fill(likeAll[AliPID::kElectron]);
72f5f463 399 } // end event loop
400
401
402 // calculate the pion efficiency and fill the graph
403 util -> CalculatePionEffi(hElecs, hPions);
e9987811 404 pionEffiTrain[iLoop] = util -> GetPionEfficiency();
405 pionEffiErrTrain[iLoop] = util -> GetError();
72f5f463 406
e9987811 407 gEffisTrain -> SetPoint(iLoop, iLoop+1, pionEffiTrain[iLoop]);
408 gEffisTrain -> SetPointError(iLoop, 0, pionEffiErrTrain[iLoop]);
72f5f463 409 hElecs -> Reset();
410 hPions -> Reset();
dad3aa6b 411 AliDebug(2, Form("TrainingLoop[%d] PionEfficiency[%f +/- %f]", iLoop, pionEffiTrain[iLoop], pionEffiErrTrain[iLoop]));
72f5f463 412 // end training loop
413
414
415
416 // event loop test list
417 for(Int_t iEvent = 0; iEvent < fTest[mombin][0] -> GetN(); iEvent++ ){
418
419 // reset particle probabilities
420 for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
ee8fb199 421 likeAll[iPart] = 1./AliTRDgeometry::kNlayer;
72f5f463 422 }
e9987811 423 totProb = 0.;
72f5f463 424
ee8fb199 425 fData -> GetEntry(fTest[mombin][0] -> GetEntry(iEvent));
72f5f463 426 // use event only if it is electron or pion
ee8fb199 427 if(!((fPID[AliPID::kElectron] == 1.0) || (fPID[AliPID::kPion] == 1.0))) continue;
72f5f463 428
429 // get the probabilities for each particle type in each chamber
430 for(Int_t iChamb = 0; iChamb < AliTRDgeometry::kNlayer; iChamb++){
ee8fb199 431 for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
432 like[iPart][iChamb] = fNet[iChamb] -> Result(fTest[mombin][iChamb] -> GetEntry(iEvent), iPart);
433 likeAll[iPart] *= like[iPart][iChamb];
434 }
72f5f463 435 }
436
437 // get total probability and normalize it
438 for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
ee8fb199 439 totProb += likeAll[iPart];
72f5f463 440 }
441 for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
ee8fb199 442 likeAll[iPart] /= totProb;
72f5f463 443 }
444
445 // fill likelihood distributions
ee8fb199 446 if(fPID[AliPID::kElectron] == 1)
447 hElecs -> Fill(likeAll[AliPID::kElectron]);
448 if(fPID[AliPID::kPion] == 1)
449 hPions -> Fill(likeAll[AliPID::kElectron]);
72f5f463 450 } // end event loop
451
452 // calculate the pion efficiency and fill the graph
453 util -> CalculatePionEffi(hElecs, hPions);
e9987811 454 pionEffiTest[iLoop] = util -> GetPionEfficiency();
455 pionEffiErrTest[iLoop] = util -> GetError();
72f5f463 456
e9987811 457 gEffisTest -> SetPoint(iLoop, iLoop+1, pionEffiTest[iLoop]);
458 gEffisTest -> SetPointError(iLoop, 0, pionEffiErrTest[iLoop]);
72f5f463 459 hElecs -> Reset();
460 hPions -> Reset();
dad3aa6b 461 AliDebug(2, Form("TestLoop[%d] PionEfficiency[%f +/- %f] \n", iLoop, pionEffiTest[iLoop], pionEffiErrTest[iLoop]));
72f5f463 462
463 } // end training loop
ee8fb199 464
72f5f463 465 util -> Delete();
466
467 gEffisTest -> Draw("PAL");
468 gEffisTrain -> Draw("PL");
469
470}
471
472
398f8388 473//________________________________________________________________________
474void AliTRDpidRefMakerNN::LoadFile(const Char_t *InFileNN)
475{
476 //
477 // Loads the files and sets the event list
478 // for neural network training and
479 // building of the 2-dim reference histograms.
480 // Useable for training outside of the makeResults.C macro
481 //
482
483 TFile *fInFileNN;
484 fInFileNN = new TFile(InFileNN, "READ");
ee8fb199 485 fData = (TTree*)fInFileNN -> Get("NN");
398f8388 486
487 for(Int_t iMom = 0; iMom < AliTRDCalPID::kNMom; iMom++){
488 for(Int_t ily = 0; ily < AliTRDgeometry::kNlayer; ily++){
489 fTrain[iMom][ily] = new TEventList(Form("fTrainMom%d_%d", iMom, ily), Form("Training list for momentum intervall %d and plane %d", iMom, ily));
490 fTest[iMom][ily] = new TEventList(Form("fTestMom%d_%d", iMom, ily), Form("Test list for momentum intervall %d and plane %d", iMom, ily));
491 }
492 }
493}
494
495
ee8fb199 496// //________________________________________________________________________
497// void AliTRDpidRefMakerNN::LoadContainer(const Char_t *InFileCont)
498// {
398f8388 499
ee8fb199 500// //
501// // Loads the container if no container is there.
502// // Useable for training outside of the makeResults.C macro
503// //
398f8388 504
ee8fb199 505// TFile *fInFileCont;
506// fInFileCont = new TFile(InFileCont, "READ");
507// fContainer = (TObjArray*)fInFileCont -> Get("PidRefMaker");
398f8388 508
ee8fb199 509// }
398f8388 510
511
512// //________________________________________________________________________
513// void AliTRDpidRefMakerNN::CreateGraphs()
514// {
515// // Create histograms
516// // Called once
517
518// OpenFile(0, "RECREATE");
519// fContainer = new TObjArray();
520// fContainer->AddAt(new TH1F("hPDG","hPDG",AliPID::kSPECIES,-0.5,5.5),0);
521
522// TGraphErrors *gEffisTrain = new TGraphErrors(kMoniTrain);
523// gEffisTrain -> SetLineColor(4);
524// gEffisTrain -> SetMarkerColor(4);
525// gEffisTrain -> SetMarkerStyle(29);
526// gEffisTrain -> SetMarkerSize(2);
527
528// TGraphErrors *gEffisTest = new TGraphErrors(kMoniTrain);
529// gEffisTest -> SetLineColor(2);
530// gEffisTest -> SetMarkerColor(2);
531// gEffisTest -> SetMarkerSize(2);
532
533// fContainer -> AddAt(gEffisTrain,kGraphTrain);
534// fContainer -> AddAt(gEffisTest,kGraphTest);
535// }
536