Go to the documentation of this file.
15 #include "FairMCPoint.h"
16 #include "FairRootManager.h"
17 #include "FairTrackParam.h"
19 #include "CbmRichUtil.h"
21 #include "TClonesArray.h"
24 #include "TMultiLayerPerceptron.h"
30 #include <boost/assign/list_of.hpp>
39 using boost::assign::list_of;
54 , fRichRingMatches(NULL)
56 , fStsTrackMatches(NULL)
59 , fMinNofHitsInRichRing(7)
61 , fMaxNofTrainSamples(5000)
69 , fOutputDir(
"results_images_ann/")
100 for (
int i = 0;
i < 2;
i++) {
101 if (
i == 0) ss =
"Electron";
102 if (
i == 1) ss =
"Pion";
104 fhAaxis[
i] =
new TH1D(
string(
"fhAaxis" + ss).c_str(),
105 "fhAaxis;A axis [cm];Counter",
110 fhBaxis[
i] =
new TH1D(
string(
"fhBAxis" + ss).c_str(),
111 "fhBAxis;B axis [cm];Counter",
121 new TH1D(
string(
"fhDistTrueMatch" + ss).c_str(),
122 "fhDistTrueMatch;Ring-track distance [cm];Counter",
128 new TH1D(
string(
"fhDistMisMatch" + ss).c_str(),
129 "fhDistMisMatch;Ring-track distance [cm];Counter",
134 fhNofHits[
i] =
new TH1D(
string(
"fhNofHits" + ss).c_str(),
135 "fhNofHits;Number of hits;Counter",
141 string(
"fhChi2" + ss).c_str(),
"fhChi2;#Chi^{2};Counter", 100, 0., 1.);
143 fhRadPos[
i] =
new TH1D(
string(
"fhRadPos" + ss).c_str(),
144 "fhRadPos;Radial position [cm];Counter",
149 fhAaxisVsMom[
i] =
new TH2D(
string(
"fhAaxisVsMom" + ss).c_str(),
150 "fhAaxisVsMom;P [GeV/c];A axis [cm]",
158 fhBaxisVsMom[
i] =
new TH2D(
string(
"fhBAxisVsMom" + ss).c_str(),
159 "fhBAxisVsMom;P [GeV/c];B axis [cm]",
168 "fhPhiVsRadAng;Phi [rad];Radial angle [rad]",
177 fhAnnOutput[
i] =
new TH1D(
string(
"fhAnnOutput" + ss).c_str(),
178 "ANN output;ANN output;Counter",
183 fhCumProb[
i] =
new TH1D(
string(
"fhCumProb" + ss).c_str(),
184 "ANN output;ANN output;Cumulative probability",
195 cout <<
"InitStatus CbmRichTrainAnnElectrons::Init()" << endl;
197 FairRootManager* ioman = FairRootManager::Instance();
199 Fatal(
"CbmRichTrainAnnElectrons::Init",
"RootManager not instantised!");
205 fRichRings = (TClonesArray*) ioman->GetObject(
"RichRing");
207 Fatal(
"CbmRichTrainAnnElectrons::Init",
"No RichRing array!");
213 fMCTracks = (TClonesArray*) ioman->GetObject(
"MCTrack");
215 Fatal(
"CbmRichTrainAnnElectrons::Init",
"No MCTrack array!");
220 Fatal(
"CbmRichTrainAnnElectrons::Init",
"No RichRingMatch array!");
228 Fatal(
"CbmRichTrainAnnElectrons::Init",
"No track match array!");
231 fGlobalTracks = (TClonesArray*) ioman->GetObject(
"GlobalTrack");
233 Fatal(
"CbmRichTrainAnnElectrons::Init",
"No global track array!");
236 fStsTracks = (TClonesArray*) ioman->GetObject(
"StsTrack");
238 Fatal(
"CbmRichTrainAnnElectrons::Init",
"No STSTrack array!");
245 cout << endl <<
"-I- CbmRichTrainAnnElectrons, event " <<
fEventNum << endl;
248 cout <<
"Nof Electrons = " <<
fRElIdParams[0].size() << endl;
249 cout <<
"Nof Pions = " <<
fRElIdParams[1].size() << endl;
255 for (Int_t iTrack = 0; iTrack < nGlTracks; iTrack++) {
257 if (NULL == gTrack)
continue;
259 if (stsIndex == -1)
continue;
261 if (NULL == stsTrack)
continue;
264 if (NULL == stsTrackMatch)
continue;
268 if (richIndex == -1)
continue;
270 if (NULL == ring)
continue;
273 if (NULL == richRingMatch)
continue;
277 if (NULL == track)
continue;
280 Double_t momentum = track->
GetP();
287 Double_t lPercTrue = 0;
288 if (lFoundHits >= 3) {
290 (Double_t) richRingMatch->
GetNofTrueHits() / (Double_t) lFoundHits;
292 Bool_t isTrueFound = (lPercTrue >
fQuota);
308 if (pdg == 11 && motherId == -1 && isTrueFound && mcIdSts == mcIdRich
324 if (pdg == 11 && motherId == -1 && isTrueFound && mcIdSts != mcIdRich
331 if (pdg == 211 && mcIdRich != -1) {
336 if (mcIdRich == mcIdSts) {
354 TTree* simu =
new TTree(
"MonteCarlo",
"MontecarloData");
358 simu->Branch(
"x0", &
x[0],
"x0/D");
359 simu->Branch(
"x1", &
x[1],
"x1/D");
360 simu->Branch(
"x2", &
x[2],
"x2/D");
361 simu->Branch(
"x3", &
x[3],
"x3/D");
362 simu->Branch(
"x4", &
x[4],
"x4/D");
363 simu->Branch(
"x5", &
x[5],
"x5/D");
364 simu->Branch(
"x6", &
x[6],
"x6/D");
365 simu->Branch(
"x7", &
x[7],
"x7/D");
366 simu->Branch(
"x8", &
x[8],
"x8/D");
367 simu->Branch(
"xOut", &xOut,
"xOut/D");
369 for (
int j = 0; j < 2; j++) {
381 for (
int k = 0; k < 9; k++) {
382 if (
x[k] < 0.0)
x[k] = 0.0;
383 if (
x[k] > 1.0)
x[k] = 1.0;
386 if (j == 0) xOut = 1.;
387 if (j == 1) xOut = -1.;
393 TMultiLayerPerceptron network(
394 "x0,x1,x2,x3,x4,x5,x6,x7,x8:18:xOut", simu,
"Entry$+1");
396 network.Train(300,
"text,update=10");
397 network.DumpWeights(
"rich_v17a_elid_ann_weights.txt");
405 for (
int j = 0; j < 2; j++) {
417 for (
int k = 0; k < 9; k++) {
418 if (params[k] < 0.0) params[k] = 0.0;
419 if (params[k] > 1.0) params[k] = 1.0;
422 Double_t netEval = network.Evaluate(0, params);
435 cout <<
"nof electrons = " <<
fRElIdParams[0].size() << endl;
436 cout <<
"nof pions = " <<
fRElIdParams[1].size() << endl;
440 cout <<
"Electrons like pions = " <<
fNofElLikePi <<
", el lost eff = "
442 cout <<
"ANN cut = " <<
fAnnCut << endl;
444 Double_t cumProbFake = 0.;
445 Double_t cumProbTrue = 0.;
446 Int_t nofFake = (Int_t)
fhAnnOutput[1]->GetEntries();
447 Int_t nofTrue = (Int_t)
fhAnnOutput[0]->GetEntries();
450 fhCumProb[1]->SetBinContent(
i, (Double_t) cumProbFake / nofFake);
453 fhCumProb[0]->SetBinContent(
i, 1. - (Double_t) cumProbTrue / nofTrue);
460 "ann_electrons_ann_output",
"ann_electrons_ann_output", 500, 500);
462 list_of(
"e^{#pm}")(
"#pi^{#pm}"),
474 CreateCanvas(
"ann_electrons_cum_prob",
"ann_electrons_cum_prob", 500, 500);
476 list_of(
"e^{#pm}")(
"#pi^{#pm}"),
489 "ann_electrons_params_ab",
"ann_electrons_params_ab", 1200, 600);
493 list_of(
"e^{#pm}")(
"#pi^{#pm}"),
503 list_of(
"e^{#pm}")(
"#pi^{#pm}"),
520 "ann_electrons_params_1",
"ann_electrons_params_1", 1500, 600);
536 list_of(
"e^{#pm} true match")(
"e^{#pm} mis match")(
537 "#pi^{#pm} true match")(
"#pi^{#pm} mis match"),
550 "ann_electrons_params_2",
"ann_electrons_params_2", 1500, 600);
554 list_of(
"e^{#pm}")(
"#pi^{#pm}"),
564 list_of(
"e^{#pm}")(
"#pi^{#pm}"),
574 list_of(
"e^{#pm}")(
"#pi^{#pm}"),
587 "ann_electrons_params_2d",
"ann_electrons_params_2d", 600, 900);
616 for (
unsigned int i = 0;
i <
fHists.size();
i++) {
628 TCanvas* c =
new TCanvas(name.c_str(), title.c_str(), width, height);
634 for (
unsigned int i = 0;
i <
fCanvas.size();
i++) {
Int_t GetMotherId() const
const CbmLink & GetMatchedLink() const
virtual ~CbmRichTrainAnnElectrons()
Destructor.
Int_t GetNofWrongHits() const
virtual void Exec(Option_t *option)
Inherited from FairTask.
vector< TH1D * > fhCumProb
vector< TH2D * > fhPhiVsRadAng
Int_t GetRichRingIndex() const
Helper functions for drawing 1D and 2D histograms and graphs.
Float_t GetRadialPosition() const
vector< TH1D * > fhDistMisMatch
virtual InitStatus Init()
Inherited from FairTask.
UInt_t fMaxNofTrainSamples
CbmRichTrainAnnElectrons()
Default constructor.
static Double_t GetRingTrackDistance(Int_t globalTrackId)
Double_t GetRadialAngle() const
vector< TH1D * > fhDistTrueMatch
void DrawH1(TH1 *hist, HistScale logx, HistScale logy, const string &drawOpt, Int_t color, Int_t lineWidth, Int_t lineStyle, Int_t markerSize, Int_t markerStyle)
Input Parameters for ANN for electron identification in RICH.
Int_t GetStsTrackIndex() const
void DiffElandPi()
Fill input parameters for ANN in array and histograms.
vector< TH1D * > fhNofHits
TClonesArray * fRichRings
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Double_t GetAaxis() const
TCanvas * CreateCanvas(const string &name, const string &title, int width, int height)
void TrainAndTestAnn()
Train and test ANN.
void Draw(Option_t *="")
Draw results.
Double_t GetBaxis() const
virtual void FinishTask()
Inherited from FairTask.
vector< TH2D * > fhAaxisVsMom
Int_t GetNofTrueHits() const
friend F32vec4 fabs(const F32vec4 &a)
TClonesArray * fRichRingMatches
Train ANN for electron identification in RICH.
vector< vector< RingElectronParam > > fRElIdParams
vector< TH1D * > fhAnnOutput
void DrawH2(TH2 *hist, HistScale logx, HistScale logy, HistScale logz, const string &drawOpt)
void SetDefaultDrawStyle()
void SaveCanvasAsImage(TCanvas *c, const std::string &dir, const std::string &option)
vector< TH1D * > fhRadPos
TClonesArray * fStsTracks
Train ANN for electron identification in RICH.
TClonesArray * fGlobalTracks
vector< TCanvas * > fCanvas
TClonesArray * fStsTrackMatches
vector< TH2D * > fhBaxisVsMom