ROOT logo
// This macro converts the networks that were saved by the AliTRDpidRefMaker to a root file (NN.root)
// which is readable by the AliTRDpidCDB.C macro to create the pid reference data bases.

#ifndef __CINT__
#include "TFile.h"
#include "TMultiLayerPerceptron.h"
#include "TEventList.h"
#include "TTree.h"
#include "TObject.h"

#include "AliTRDgeometry.h"
#include "AliTRDpidUtil.h"
#include "Cal/AliTRDCalPID.h"
#endif

Int_t ConvertMLPs(Int_t iDate = 20090129){

  const Int_t nCha = AliTRDgeometry::kNlayer;

  TFile *fOut = new TFile("NN.root","RECREATE");
    
  Float_t fv0pid[AliPID::kSPECIES], fdEdx[AliTRDpidUtil::kNNslices];

  for(Int_t iMomBin = 0; iMomBin <AliTRDCalPID::kNMom; iMomBin++){

// Load the TFile and the TTree to load the weights of the TMultiLayerPerceptron
    TFile *fIn = new TFile(Form("./%3.1fGeV/TRD.TaskPidRefMakerNN.root",AliTRDCalPID::GetMomentum(iMomBin)),"READ");
    TTree *tIn = (TTree *) fIn -> Get("NN");

// Create dummy TEventLists to load the weights of the TMultiLayerPerceptron
    TEventList* lTrainData = new TEventList();
    TEventList* lTestData = new TEventList();
    lTrainData -> Enter(1);
    lTestData -> Enter(1);
  
    tIn -> SetEventList(lTrainData);
    tIn -> SetEventList(lTestData);
    
    Char_t structure[1024];

    TMultiLayerPerceptron *mNet[nCha];
    
    for(Int_t iCha = 0; iCha < nCha; iCha++){
      sprintf(structure,"fdEdx[0],fdEdx[1],fdEdx[2],fdEdx[3],fdEdx[4],fdEdx[5],fdEdx[6],fdEdx[7]:15:7:fv0pid[0],fv0pid[1],fv0pid[2],fv0pid[3],fv0pid[4]!");      
      mNet[iCha] = new TMultiLayerPerceptron(structure,tIn,lTrainData,lTestData);

      printf("Network[%d] is ./%3.1fGeV/Network_%d/MomBin_%d/Net%d_49\n", iCha, AliTRDCalPID::GetMomentum(iMomBin), iDate, iMomBin, iCha);
      mNet[iCha] -> LoadWeights(Form("./%3.1fGeV/Network_%d/MomBin_%d/Net%d_49", AliTRDCalPID::GetMomentum(iMomBin), iDate, iMomBin, iCha));
    }
    
    fOut -> cd();
    for(Int_t iCha = 0; iCha < AliTRDgeometry::kNlayer; iCha++){
      mNet[iCha] -> Write(Form("NN_Mom%d_Plane%d",iMomBin,iCha));
    }
  }

  fOut -> Close();

  return 1;
    
}

 ConvertMLPs.C:1
 ConvertMLPs.C:2
 ConvertMLPs.C:3
 ConvertMLPs.C:4
 ConvertMLPs.C:5
 ConvertMLPs.C:6
 ConvertMLPs.C:7
 ConvertMLPs.C:8
 ConvertMLPs.C:9
 ConvertMLPs.C:10
 ConvertMLPs.C:11
 ConvertMLPs.C:12
 ConvertMLPs.C:13
 ConvertMLPs.C:14
 ConvertMLPs.C:15
 ConvertMLPs.C:16
 ConvertMLPs.C:17
 ConvertMLPs.C:18
 ConvertMLPs.C:19
 ConvertMLPs.C:20
 ConvertMLPs.C:21
 ConvertMLPs.C:22
 ConvertMLPs.C:23
 ConvertMLPs.C:24
 ConvertMLPs.C:25
 ConvertMLPs.C:26
 ConvertMLPs.C:27
 ConvertMLPs.C:28
 ConvertMLPs.C:29
 ConvertMLPs.C:30
 ConvertMLPs.C:31
 ConvertMLPs.C:32
 ConvertMLPs.C:33
 ConvertMLPs.C:34
 ConvertMLPs.C:35
 ConvertMLPs.C:36
 ConvertMLPs.C:37
 ConvertMLPs.C:38
 ConvertMLPs.C:39
 ConvertMLPs.C:40
 ConvertMLPs.C:41
 ConvertMLPs.C:42
 ConvertMLPs.C:43
 ConvertMLPs.C:44
 ConvertMLPs.C:45
 ConvertMLPs.C:46
 ConvertMLPs.C:47
 ConvertMLPs.C:48
 ConvertMLPs.C:49
 ConvertMLPs.C:50
 ConvertMLPs.C:51
 ConvertMLPs.C:52
 ConvertMLPs.C:53
 ConvertMLPs.C:54
 ConvertMLPs.C:55
 ConvertMLPs.C:56
 ConvertMLPs.C:57
 ConvertMLPs.C:58
 ConvertMLPs.C:59
 ConvertMLPs.C:60
 ConvertMLPs.C:61
 ConvertMLPs.C:62
 ConvertMLPs.C:63