CbmRoot
Loading...
Searching...
No Matches
CbmRichElectronIdAnn.cxx
Go to the documentation of this file.
1/* Copyright (C) 2008-2019 UGiessen/JINR-LIT, Giessen/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Semen Lebedev [committer], Andrey Lebedev */
4
13
14#include "CbmGlobalTrack.h"
15#include "CbmRichGeoManager.h"
16#include "CbmRichRing.h"
17#include "CbmRichUtil.h"
18
19#include "FairRootManager.h"
20#include <Logger.h>
21
22#include "TClonesArray.h"
23#include "TMath.h"
24#include "TMultiLayerPerceptron.h"
25#include "TSystem.h"
26#include "TTree.h"
27
28#include <iostream>
29
30using std::cout;
31using std::endl;
32
33CbmRichElectronIdAnn::CbmRichElectronIdAnn() : fAnnWeights(""), fNN(NULL), fGlobalTracks(NULL), fRichRings(NULL)
34{
35 Init();
36}
37
39
41{
42 if (fNN != NULL) { delete fNN; }
43
45 fAnnWeights = string(gSystem->Getenv("VMCWORKDIR")) + "/parameters/rich/rich_v17a_elid_ann_weights.txt";
46 }
47 else if (CbmRichGeoManager::GetInstance().fGP->fGeometryType == CbmRichGeometryTypeTwoWings) {
48 fAnnWeights = string(gSystem->Getenv("VMCWORKDIR")) + "/parameters/rich/rich_v16a_elid_ann_weights.txt";
49 }
50 else {
51 fAnnWeights = string(gSystem->Getenv("VMCWORKDIR")) + "/parameters/rich/rich_v17a_elid_ann_weights.txt";
52 }
53
54 TTree* simu = new TTree("MonteCarlo", "MontecarloData");
55 Double_t x[9];
56 Double_t xOut;
57
58 simu->Branch("x0", &x[0], "x0/D");
59 simu->Branch("x1", &x[1], "x1/D");
60 simu->Branch("x2", &x[2], "x2/D");
61 simu->Branch("x3", &x[3], "x3/D");
62 simu->Branch("x4", &x[4], "x4/D");
63 simu->Branch("x5", &x[5], "x5/D");
64 simu->Branch("x6", &x[6], "x6/D");
65 simu->Branch("x7", &x[7], "x7/D");
66 simu->Branch("x8", &x[8], "x8/D");
67 simu->Branch("xOut", &xOut, "xOut/D");
68
69 fNN = new TMultiLayerPerceptron("x0,x1,x2,x3,x4,x5,x6,x7,x8:18:xOut", simu);
70 cout << "-I- CbmRichElIdAnn: get NeuralNet weight parameters from: " << fAnnWeights << endl;
71 fNN->LoadWeights(fAnnWeights.c_str());
72
73 FairRootManager* ioman = FairRootManager::Instance();
74 if (ioman != NULL) {
75 fRichRings = (TClonesArray*) ioman->GetObject("RichRing");
76 if (fRichRings == NULL) { LOG(error) << "CbmRichElectronIdAnn::Init() fRichRings == NULL"; }
77 fGlobalTracks = (TClonesArray*) ioman->GetObject("GlobalTrack");
78 if (fGlobalTracks == NULL) { LOG(error) << "CbmRichElectronIdAnn::Init() fGlobalTracks == NULL"; }
79 }
80 else {
81 LOG(error) << "FairRootManager::Instance() == NULL";
82 }
83}
84
85double CbmRichElectronIdAnn::CalculateAnnValue(int globalTrackIndex, double momentum)
86{
87 double errorValue = -1.;
88 if (globalTrackIndex < 0) return errorValue;
89
90 if (fGlobalTracks == NULL || fRichRings == NULL) return -1;
91
92 const CbmGlobalTrack* globalTrack = static_cast<const CbmGlobalTrack*>(fGlobalTracks->At(globalTrackIndex));
93 if (globalTrack == NULL) return errorValue;
94
95 Int_t richId = globalTrack->GetRichRingIndex();
96 if (richId == -1) return errorValue;
97 const CbmRichRing* richRing = static_cast<const CbmRichRing*>(fRichRings->At(richId));
98 if (richRing == NULL) return errorValue;
99
100 double rtDistance = CbmRichUtil::GetRingTrackDistance(globalTrackIndex);
101
102 if (richRing->GetAaxis() >= 10. || richRing->GetAaxis() <= 0. || richRing->GetBaxis() >= 10.
103 || richRing->GetBaxis() <= 0. || richRing->GetNofHits() <= 5. || rtDistance <= 0. || rtDistance >= 999.
104 || richRing->GetRadialPosition() <= 0. || richRing->GetRadialPosition() >= 999. || richRing->GetPhi() <= -6.5
105 || richRing->GetPhi() >= 6.5 || richRing->GetRadialAngle() <= -6.5 || richRing->GetRadialAngle() >= 6.5) {
106
107 return -1.;
108 }
109 double params[9];
110 params[0] = richRing->GetAaxis() / 10.;
111 params[1] = richRing->GetBaxis() / 10.;
112 params[2] = (richRing->GetPhi() + 1.57) / 3.14;
113 params[3] = richRing->GetRadialAngle() / 6.28;
114 params[4] = (richRing->GetChi2() / richRing->GetNDF()) / 1.2;
115 params[5] = richRing->GetRadialPosition() / 110.;
116 params[6] = richRing->GetNofHits() / 45.;
117 params[7] = rtDistance / 5.;
118 params[8] = momentum / 15.;
119
120 for (int k = 0; k < 9; k++) {
121 if (params[k] < 0.0) params[k] = 0.0;
122 if (params[k] > 1.0) params[k] = 1.0;
123 }
124
125 double nnEval = fNN->Evaluate(0, params);
126
127 if (TMath::IsNaN(nnEval) == 1) {
128 //cout << " -W- CbmRichElectronIdAnn: nnEval nan " << endl;
129 nnEval = -1.;
130 }
131
132 return nnEval;
133}
Implementation of the electron identification algorithm in the RICH detector using Artificial Neural ...
@ CbmRichGeometryTypeTwoWings
@ CbmRichGeometryTypeCylindrical
int32_t GetRichRingIndex() const
CbmRichElectronIdAnn()
Standard constructor.
double CalculateAnnValue(int globalTrackIndex, double momentum)
Calculate output value of the ANN.
string fAnnWeights
Set path to the file with ANN weights.
virtual ~CbmRichElectronIdAnn()
Destructor.
void Init()
Initialize ANN before use.
TMultiLayerPerceptron * fNN
static CbmRichGeoManager & GetInstance()
double GetRadialAngle() const
double GetAaxis() const
Definition CbmRichRing.h:80
int32_t GetNofHits() const
Definition CbmRichRing.h:37
double GetChi2() const
Definition CbmRichRing.h:92
double GetPhi() const
Definition CbmRichRing.h:84
double GetNDF() const
Definition CbmRichRing.h:93
float GetRadialPosition() const
double GetBaxis() const
Definition CbmRichRing.h:81
static double GetRingTrackDistance(int globalTrackId)