/* Description: This macro train the ANN for fake rejection algorithm. Author : Semen Lebedev E-mail : S.Lebedev@gsi.de */ void run_train_ANN_Select(){ gROOT->LoadMacro("$VMCWORKDIR/macro/rich/setstyle.C"); setphdStyle(); Int_t i; std::ifstream finFakeAndTrue("ann_fake_and_true.txt"); if(!gROOT->GetClass("TMultiLayerPerceptron")) gSystem->Load("libMLP"); TTree *simu = new TTree ("MonteCarlo","MontecarloData"); Float_t x1,x2,x3,x4,x5,x6,x11; simu->Branch("x1", &x1,"x1/F"); simu->Branch("x2", &x2,"x2/F"); simu->Branch("x3", &x3,"x3/F"); simu->Branch("x4", &x4,"x4/F"); simu->Branch("x5", &x5,"x5/F"); simu->Branch("x6", &x6,"x6/F"); simu->Branch("x11", &x11,"x11/F"); Int_t maxNofFake = 3000; Int_t maxNofTrue = 3000; Int_t inputCountTrue = 0; Int_t inputCountFake = 0; while ( !finFakeAndTrue.eof() ){ finFakeAndTrue >> x1 >> x2 >> x3 >> x4 >> x5 >> x6 >> x11; cout << " "<< x1 << " "<< x2 << " " << x3 << " "<< x4 << " "<< x5 << " " << x6 <<" "<< x11 << endl; if ( x11 == -1 && inputCountFake < maxNofFake){ inputCountFake++; simu->Fill(); } if (x11 == 1 && inputCountTrue < maxNofTrue){ inputCountTrue++; simu->Fill(); } if (inputCountFake >= maxNofFake&& inputCountTrue >= maxNofTrue){ break; } } TMultiLayerPerceptron network("x1,x2,x3,x4,x5,x6:5:x11",simu,"Entry$+1"); network.LoadWeights("/u/slebedev/JUL09/trunk/parameters/rich/NeuralNet_RingSelection_Weights_Compact.txt"); // network.Train(500,"text,update=1"); // network.DumpWeights("NeuralNet_RingSelection_Weights1.txt"); network.Export(); Double_t minEval = -1.3; Double_t maxEval = 1.3; TH1F *hANNOutputFake = new TH1F("hANNOutputFake","ANN output;ANN output;Entries",100, minEval, maxEval); TH1F *hANNOutputTrue = new TH1F("hANNOutputTrue","ANN optput;ANN output;Entries",100, minEval, maxEval); TH1F *hCumProbFake = new TH1F("hCumProbFake","ANN output;ANN output;Cumulative probability",100, minEval, maxEval); TH1F *hCumProbTrue = new TH1F("hCumProbTrue","ANN optput;ANN output;Cumulative probability",100, minEval, maxEval); //hANNOutputTrue->SetLogx(); Double_t ANNCut = -.5; Double_t params[10]; std::ifstream finTest("ann_fake_and_true.txt"); Int_t NofFakeLikeTrue = 0; Int_t NofTrueLikeFake = 0; Int_t NofTrueTest = 0; Int_t NofFakeTest = 0; while ( !finTest.eof() ){ finTest >> x1 >> x2 >> x3 >> x4 >> x5 >> x6 >> x11; if (x11 == -1)NofFakeTest++; if (x11 == 1 )NofTrueTest++; params[0] = x1; params[1] = x2; params[2] = x3; params[3] = x4; params[4] = x5; params[5] = x6; Double_t netEval = network.Evaluate(0,params); if (netEval > maxEval) netEval = maxEval - 0.01; if (netEval < minEval) netEval = minEval + 0.01; if (x11 == -1) hANNOutputFake->Fill(netEval); if (x11 == 1) hANNOutputTrue->Fill(netEval); if (netEval > ANNCut && x11 == -1) NofFakeLikeTrue++; if (netEval < ANNCut && x11 == 1) NofTrueLikeFake++; } cout <<"NofTrue = " <SetLogy(); TCanvas* c2 = new TCanvas(); hCumProbFake->SetLineWidth(3); hCumProbFake->SetLineStyle(2); hCumProbFake->Draw(); hCumProbTrue->SetLineWidth(3); hCumProbTrue->Draw("same"); gPad->SetLogy(); }