20 #include "TMultiLayerPerceptron.h" 
   23 #include "TClonesArray.h" 
   25 #include <boost/assign/list_of.hpp> 
   34 using boost::assign::list_of;
 
   39    fRichRingMatches(NULL),
 
   43    fMaxNofTrainSamples(5000),
 
   74    for (
int i = 0; i < 2; i++){
 
   75       if (i == 0) ss = 
"True";
 
   76       if (i == 1) ss = 
"Fake";
 
   78       fhNofHits[i] = 
new TH1D(
string(
"fhNofHits"+ss).c_str(),
"Number of hits in ring;Nof hits in ring;Counter",50, 0, 50);
 
   80       fhAngle[i] = 
new TH1D(
string(
"fhAngle"+ss).c_str(),
"Biggest angle in ring;Angle [rad];Counter",50, 0, 6.5);
 
   82       fhNofHitsOnRing[i] = 
new TH1D(
string(
"fhNofHitsOnRing"+ss).c_str(),
"Number of hits on ring;Nof hits on ring;Counter",50, 0, 50);
 
   84       fhChi2[i] = 
new TH1D(
string(
"fhFakeChi2"+ss).c_str(),
"Chi2;Chi2;Counter", 100, 0., 1.0);
 
   86       fhRadPos[i] = 
new TH1D(
string(
"fhRadPos"+ss).c_str(),
"Radial position;Radial position [cm];Counter",150, 0, 150);
 
   88       fhRadius[i] = 
new TH1D(
string(
"fhRadius"+ss).c_str(),
"Radius;Radius [cm];Counter",80, 0., 9.);
 
   91       fhAnnOutput[i] = 
new TH1D(
string(
"fhAnnOutput"+ss).c_str(),
"ANN output;ANN output;Counter",100, -1.2, 1.2);
 
   93       fhCumProb[i] = 
new TH1D(
string(
"fhCumProb"+ss).c_str(),
"ANN output;ANN output;Cumulative probability",100, -1.2, 1.2);
 
  107    cout << 
"InitStatus CbmRichTrainAnnSelect::Init()" << endl;
 
  109   if (NULL == ioman) { Fatal(
"CbmRichRingQa::Init",
"CbmRootManager is not instantiated"); }
 
  112   if (NULL == 
fRichRings) { Fatal(
"CbmRichTrainAnnSelect::Init",
"No RichRing array!"); }
 
  115   if (NULL == 
fMcTracks) { Fatal(
"CbmRichTrainAnnSelect::Init",
"No MCTrack array!");}
 
  118   if (NULL == 
fRichRingMatches) { Fatal(
"CbmRichTrainAnnSelect::Init",
"No RichRingMatch array!");}
 
  131    cout<<
"CbmRichRingQa Event No. "<< 
fEventNumber << endl;
 
  136    cout << 
"nof trues = " << 
fRSParams[0].size() << endl;
 
  137    cout << 
"nof fakes = " << 
fRSParams[1].size() << endl;
 
  146    for (Int_t iMatches = 0; iMatches < nMatches; iMatches++){
 
  148       if (NULL == match) 
continue;
 
  151       if (NULL == ring) 
continue;
 
  157       Int_t lFoundHits = lTrueHits + lWrongHits + lFakeHits;
 
  158       Double_t lPercTrue = 0.;
 
  159       if (lFoundHits >= 1){
 
  160          lPercTrue = (Double_t)lTrueHits / (Double_t)lFoundHits;
 
  164       if (trackID > 
fMcTracks->GetEntriesFast() || trackID < 0) 
continue;
 
  166       if (NULL == track) 
continue;
 
  168       Int_t gcode = TMath::Abs(track->
GetPdgCode());
 
  177          if (gcode == 11 && motherId == -1){ 
 
  188    for (Int_t iMatches = 0; iMatches < nMatches; iMatches++) {
 
  190       if (NULL == match) 
continue;
 
  193       if (NULL == ring) 
continue;
 
  239    TTree *simu = 
new TTree (
"MonteCarlo",
"MontecarloData");
 
  243    simu->Branch(
"x0", &x[0],
"x0/D");
 
  244    simu->Branch(
"x1", &x[1],
"x1/D");
 
  245    simu->Branch(
"x2", &x[2],
"x2/D");
 
  246    simu->Branch(
"x3", &x[3],
"x3/D");
 
  247    simu->Branch(
"x4", &x[4],
"x4/D");
 
  248    simu->Branch(
"x5", &x[5],
"x5/D");
 
  249    simu->Branch(
"xOut", &xOut,
"xOut/D");
 
  251    for (
int j = 0; j < 2; j++){
 
  252       for (
int i = 0; i < 
fRSParams[j].size(); i++){
 
  255          x[2] = 
fRSParams[j][i].fHitsOnRing / 45.;
 
  260          for (
int k = 0; 
k < 6; 
k++){
 
  261             if (x[
k] < 0.) x[
k] = 0.;
 
  262             if (x[
k] > 1.) x[
k] = 1.;
 
  265          if (j == 0) xOut = 1.;
 
  266          if (j == 1) xOut = -1.;
 
  272    TMultiLayerPerceptron network(
"x0,x1,x2,x3,x4,x5:10:xOut",simu,
"Entry$+1");
 
  274    network.Train(300,
"text,update=10");
 
  275    network.DumpWeights(
"rich_select_ann_weights.txt");
 
  283    for (
int j = 0; j < 2; j++){
 
  284       for (
int i = 0; i < 
fRSParams[j].size(); i++){
 
  285          params[0] = 
fRSParams[j][i].fNofHits / 45.;
 
  286          params[1] = 
fRSParams[j][i].fAngle / 6.28;
 
  287          params[2] = 
fRSParams[j][i].fHitsOnRing / 45.;
 
  288          params[3] = 
fRSParams[j][i].fRadPos / 110.;
 
  289          params[4] = 
fRSParams[j][i].fRadius / 10.;
 
  292          for (
int k = 0; 
k < 6; 
k++){
 
  293             if (params[
k] < 0.) params[
k] = 0.;
 
  294             if (params[
k] > 1.) params[
k] = 1.;
 
  297          Double_t netEval = network.Evaluate(0, params);
 
  311    cout <<
"nof Trues = " << 
fRSParams[0].size() << endl;
 
  312    cout <<
"nof Fakes = " << 
fRSParams[1].size() << endl;
 
  315    cout << 
"ANN cut = " << 
fAnnCut << endl;
 
  317    Double_t cumProbFake = 0.;
 
  318    Double_t cumProbTrue = 0.;
 
  319    Int_t nofFake = (Int_t)
fhAnnOutput[1]->GetEntries();
 
  320    Int_t nofTrue = (Int_t)
fhAnnOutput[0]->GetEntries();
 
  321    for (Int_t i = 1; i <= 
fhAnnOutput[1]->GetNbinsX(); i++){
 
  323       fhCumProb[1]->SetBinContent(i, (Double_t)cumProbFake/nofFake);
 
  326       fhCumProb[0]->SetBinContent(i, 1. - (Double_t)cumProbTrue / nofTrue);
 
  329    TCanvas* 
c1 = 
new TCanvas(
"ann_select_ann_output", 
"ann_select_ann_output", 500, 500);
 
  334    TCanvas* 
c2 = 
new TCanvas(
"ann_select_cum_prob", 
"ann_select_cum_prob", 500, 500);
 
  337    TCanvas* 
c3 = 
new TCanvas(
"ann_select_params", 
"ann_select_params", 900, 600);
 
  358    TDirectory *current = gDirectory;
 
  359    TDirectory *
rich = current->mkdir(
"CbmRichTrainAnnSelect");
 
  362    for (
int i = 0; i < 
fHists.size(); i++ ){