22#include "FairRootManager.h"
24#include "TClonesArray.h"
26#include "TMultiLayerPerceptron.h"
28#include <boost/assign/list_of.hpp>
34using boost::assign::list_of;
43 , fRichRingMatches(NULL)
48 , fMaxNofTrainSamples(5000)
84 for (
int i = 0; i < 2; i++) {
85 if (i == 0) ss =
"True";
86 if (i == 1) ss =
"Fake";
89 new TH1D(
string(
"fhNofHits" + ss).c_str(),
"Number of hits in ring;Nof hits in ring;Counter", 50, 0, 50);
91 fhAngle[i] =
new TH1D(
string(
"fhAngle" + ss).c_str(),
"Biggest angle in ring;Angle [rad];Counter", 50, 0, 6.5);
94 new TH1D(
string(
"fhNofHitsOnRing" + ss).c_str(),
"Number of hits on ring;Nof hits on ring;Counter", 50, 0, 50);
96 fhChi2[i] =
new TH1D(
string(
"fhFakeChi2" + ss).c_str(),
"Chi2;Chi2;Counter", 100, 0., 1.0);
99 new TH1D(
string(
"fhRadPos" + ss).c_str(),
"Radial position;Radial position [cm];Counter", 150, 0, 150);
101 fhRadius[i] =
new TH1D(
string(
"fhRadius" + ss).c_str(),
"Radius;Radius [cm];Counter", 80, 0., 9.);
104 fhAnnOutput[i] =
new TH1D(
string(
"fhAnnOutput" + ss).c_str(),
"ANN output;ANN output;Counter", 100, -1.2, 1.2);
107 new TH1D(
string(
"fhCumProb" + ss).c_str(),
"ANN output;ANN output;Cumulative probability", 100, -1.2, 1.2);
118 cout <<
"InitStatus CbmRichTrainAnnSelect::Init()" << endl;
119 FairRootManager* ioman = FairRootManager::Instance();
121 LOG(fatal) << GetName() <<
"::Init: CbmRootManager is not instantiated";
124 fRichRings = (TClonesArray*) ioman->GetObject(
"RichRing");
126 LOG(fatal) << GetName() <<
"::Init: No RichRing array!";
129 fMcTracks = (TClonesArray*) ioman->GetObject(
"MCTrack");
131 LOG(fatal) << GetName() <<
"::Init: No MCTrack array!";
136 LOG(fatal) << GetName() <<
"::Init: No RichRingMatch array!";
149 cout <<
"CbmRichRingQa Event No. " <<
fEventNumber << endl;
154 cout <<
"nof trues = " <<
fRSParams[0].size() << endl;
155 cout <<
"nof fakes = " <<
fRSParams[1].size() << endl;
164 for (Int_t iMatches = 0; iMatches < nMatches; iMatches++) {
166 if (NULL == match)
continue;
169 if (NULL == ring)
continue;
174 if (trackID >
fMcTracks->GetEntriesFast() || trackID < 0)
continue;
176 if (NULL == track)
continue;
178 Int_t gcode = TMath::Abs(track->
GetPdgCode());
188 if (gcode == 11 && motherId == -1) {
199 for (Int_t iMatches = 0; iMatches < nMatches; iMatches++) {
201 if (NULL == match)
continue;
204 if (NULL == ring)
continue;
250 TTree* simu =
new TTree(
"MonteCarlo",
"MontecarloData");
254 simu->Branch(
"x0", &
x[0],
"x0/D");
255 simu->Branch(
"x1", &
x[1],
"x1/D");
256 simu->Branch(
"x2", &
x[2],
"x2/D");
257 simu->Branch(
"x3", &
x[3],
"x3/D");
258 simu->Branch(
"x4", &
x[4],
"x4/D");
259 simu->Branch(
"x5", &
x[5],
"x5/D");
260 simu->Branch(
"xOut", &xOut,
"xOut/D");
262 for (
int j = 0; j < 2; j++) {
263 for (
unsigned int i = 0; i <
fRSParams[j].size(); i++) {
271 for (
int k = 0; k < 6; k++) {
272 if (
x[k] < 0.)
x[k] = 0.;
273 if (
x[k] > 1.)
x[k] = 1.;
276 if (j == 0) xOut = 1.;
277 if (j == 1) xOut = -1.;
283 TMultiLayerPerceptron network(
"x0,x1,x2,x3,x4,x5:10:xOut", simu,
"Entry$+1");
285 network.Train(300,
"text,update=10");
286 network.DumpWeights(
"rich_v17a_select_ann_weights.txt");
294 for (
int j = 0; j < 2; j++) {
295 for (
unsigned int i = 0; i <
fRSParams[j].size(); i++) {
296 params[0] =
fRSParams[j][i].fNofHits / 45.;
297 params[1] =
fRSParams[j][i].fAngle / 6.28;
298 params[2] =
fRSParams[j][i].fHitsOnRing / 45.;
299 params[3] =
fRSParams[j][i].fRadPos / 110.;
300 params[4] =
fRSParams[j][i].fRadius / 10.;
303 for (
int k = 0; k < 6; k++) {
304 if (params[k] < 0.) params[k] = 0.;
305 if (params[k] > 1.) params[k] = 1.;
308 Double_t netEval = network.Evaluate(0, params);
322 cout <<
"nof Trues = " <<
fRSParams[0].size() << endl;
323 cout <<
"nof Fakes = " <<
fRSParams[1].size() << endl;
328 cout <<
"ANN cut = " <<
fAnnCut << endl;
330 Double_t cumProbFake = 0.;
331 Double_t cumProbTrue = 0.;
332 Int_t nofFake = (Int_t)
fhAnnOutput[1]->GetEntries();
333 Int_t nofTrue = (Int_t)
fhAnnOutput[0]->GetEntries();
334 for (Int_t i = 1; i <=
fhAnnOutput[1]->GetNbinsX(); i++) {
336 fhCumProb[1]->SetBinContent(i, (Double_t) cumProbFake / nofFake);
339 fhCumProb[0]->SetBinContent(i, 1. - (Double_t) cumProbTrue / nofTrue);
343 new TCanvas(
"ann_select_ann_output",
"ann_select_ann_output", 500, 500);
349 new TCanvas(
"ann_select_cum_prob",
"ann_select_cum_prob", 500, 500);
352 TCanvas* c3 =
new TCanvas(
"ann_select_params",
"ann_select_params", 900, 600);
373 for (
unsigned int i = 0; i <
fHists.size(); i++) {
377 TDirectory* current = gDirectory;
378 TDirectory* rich = current->mkdir(
"CbmRichTrainAnnSelect");
381 for (
unsigned int i = 0; i <
fHists.size(); i++) {
ClassImp(CbmConverterManager)
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)
Helper functions for drawing 1D and 2D histograms and graphs.
Convert internal data classes to cbmroot common data classes.
Here the ring is fitted with the COP algorithm from A. Ayriyan/G. Ososkov.
Train ANN for fake rejection.
static constexpr size_t size()
int32_t GetMotherId() const
int32_t GetPdgCode() const
const CbmLink & GetMatchedLink() const
static void Init()
Initialize array of RICH hits.
static void CopyHitsToRingLight(const CbmRichRing *ring1, CbmRichRingLight *ring2)
Copy hits from CbmRichRing to CbmRichRingLight.
Here the ring is fitted with the COP algorithm from A. Ayriyan/G. Ososkov.
virtual void DoFit(CbmRichRingLight *ring)
Inherited from CbmRichRingFitterBase.
int GetNofHits() const
Return number of hits in ring.
float GetRadialPosition() const
Return radial position of the ring.
int GetNofHitsOnRingCircle(CbmRichRingLight *ring)
float GetAngle(CbmRichRingLight *ring)
int32_t GetRecFlag() const
void SetRecFlag(int32_t recflag)
Train ANN for fake rejection.
virtual void FinishTask()
Inherited from FairTask.
void TrainAndTestAnn()
Train and test ANN.
CbmRichRingFitterCOP * fFitCOP
vector< TH1D * > fhRadPos
UInt_t fMaxNofTrainSamples
vector< vector< RingSelectParam > > fRSParams
CbmRichTrainAnnSelect()
Default constructor.
CbmRichRingSelectImpl * fSelectImpl
void Draw(Option_t *="")
Draw results.
TClonesArray * fRichRings
void SetRecFlag()
Set recFlag weather ring was found correctly or not.
vector< TH1D * > fhNofHits
TClonesArray * fRichRingMatches
vector< TH1D * > fhAnnOutput
virtual void Exec(Option_t *option)
Inherited from FairTask.
void DiffFakeTrueCircle()
Fill ring selection parameters in array and histograms.
virtual InitStatus Init()
Inherited from FairTask.
vector< TH1D * > fhRadius
vector< TH1D * > fhNofHitsOnRing
virtual ~CbmRichTrainAnnSelect()
Destructor.
vector< TH1D * > fhCumProb
double GetTrueOverAllHitsRatio() const
Input Parameters for ANN.