Go to the documentation of this file.
18 #include "FairRootManager.h"
21 #include "TClonesArray.h"
23 #include "TMultiLayerPerceptron.h"
25 #include <boost/assign/list_of.hpp>
31 using boost::assign::list_of;
40 , fRichRingMatches(NULL)
45 , fMaxNofTrainSamples(5000)
80 for (
int i = 0;
i < 2;
i++) {
81 if (
i == 0) ss =
"True";
82 if (
i == 1) ss =
"Fake";
84 fhNofHits[
i] =
new TH1D(
string(
"fhNofHits" + ss).c_str(),
85 "Number of hits in ring;Nof hits in ring;Counter",
90 fhAngle[
i] =
new TH1D(
string(
"fhAngle" + ss).c_str(),
91 "Biggest angle in ring;Angle [rad];Counter",
97 new TH1D(
string(
"fhNofHitsOnRing" + ss).c_str(),
98 "Number of hits on ring;Nof hits on ring;Counter",
104 string(
"fhFakeChi2" + ss).c_str(),
"Chi2;Chi2;Counter", 100, 0., 1.0);
106 fhRadPos[
i] =
new TH1D(
string(
"fhRadPos" + ss).c_str(),
107 "Radial position;Radial position [cm];Counter",
112 fhRadius[
i] =
new TH1D(
string(
"fhRadius" + ss).c_str(),
113 "Radius;Radius [cm];Counter",
119 fhAnnOutput[
i] =
new TH1D(
string(
"fhAnnOutput" + ss).c_str(),
120 "ANN output;ANN output;Counter",
125 fhCumProb[
i] =
new TH1D(
string(
"fhCumProb" + ss).c_str(),
126 "ANN output;ANN output;Cumulative probability",
139 cout <<
"InitStatus CbmRichTrainAnnSelect::Init()" << endl;
140 FairRootManager* ioman = FairRootManager::Instance();
142 Fatal(
"CbmRichRingQa::Init",
"CbmRootManager is not instantiated");
145 fRichRings = (TClonesArray*) ioman->GetObject(
"RichRing");
147 Fatal(
"CbmRichTrainAnnSelect::Init",
"No RichRing array!");
150 fMcTracks = (TClonesArray*) ioman->GetObject(
"MCTrack");
152 Fatal(
"CbmRichTrainAnnSelect::Init",
"No MCTrack array!");
157 Fatal(
"CbmRichTrainAnnSelect::Init",
"No RichRingMatch array!");
169 cout <<
"CbmRichRingQa Event No. " <<
fEventNumber << endl;
174 cout <<
"nof trues = " <<
fRSParams[0].size() << endl;
175 cout <<
"nof fakes = " <<
fRSParams[1].size() << endl;
183 for (Int_t iMatches = 0; iMatches < nMatches; iMatches++) {
186 if (NULL == match)
continue;
189 if (NULL == ring)
continue;
194 if (trackID >
fMcTracks->GetEntriesFast() || trackID < 0)
continue;
196 if (NULL == track)
continue;
198 Int_t gcode = TMath::Abs(track->
GetPdgCode());
207 if (gcode == 11 && motherId == -1) {
217 for (Int_t iMatches = 0; iMatches < nMatches; iMatches++) {
220 if (NULL == match)
continue;
223 if (NULL == ring)
continue;
268 TTree* simu =
new TTree(
"MonteCarlo",
"MontecarloData");
272 simu->Branch(
"x0", &
x[0],
"x0/D");
273 simu->Branch(
"x1", &
x[1],
"x1/D");
274 simu->Branch(
"x2", &
x[2],
"x2/D");
275 simu->Branch(
"x3", &
x[3],
"x3/D");
276 simu->Branch(
"x4", &
x[4],
"x4/D");
277 simu->Branch(
"x5", &
x[5],
"x5/D");
278 simu->Branch(
"xOut", &xOut,
"xOut/D");
280 for (
int j = 0; j < 2; j++) {
281 for (
unsigned int i = 0;
i <
fRSParams[j].size();
i++) {
289 for (
int k = 0; k < 6; k++) {
290 if (
x[k] < 0.)
x[k] = 0.;
291 if (
x[k] > 1.)
x[k] = 1.;
294 if (j == 0) xOut = 1.;
295 if (j == 1) xOut = -1.;
301 TMultiLayerPerceptron network(
"x0,x1,x2,x3,x4,x5:10:xOut", simu,
"Entry$+1");
303 network.Train(300,
"text,update=10");
304 network.DumpWeights(
"rich_v17a_select_ann_weights.txt");
312 for (
int j = 0; j < 2; j++) {
313 for (
unsigned int i = 0;
i <
fRSParams[j].size();
i++) {
316 params[2] =
fRSParams[j][
i].fHitsOnRing / 45.;
321 for (
int k = 0; k < 6; k++) {
322 if (params[k] < 0.) params[k] = 0.;
323 if (params[k] > 1.) params[k] = 1.;
326 Double_t netEval = network.Evaluate(0, params);
339 cout <<
"nof Trues = " <<
fRSParams[0].size() << endl;
340 cout <<
"nof Fakes = " <<
fRSParams[1].size() << endl;
347 cout <<
"ANN cut = " <<
fAnnCut << endl;
349 Double_t cumProbFake = 0.;
350 Double_t cumProbTrue = 0.;
351 Int_t nofFake = (Int_t)
fhAnnOutput[1]->GetEntries();
352 Int_t nofTrue = (Int_t)
fhAnnOutput[0]->GetEntries();
355 fhCumProb[1]->SetBinContent(
i, (Double_t) cumProbFake / nofFake);
358 fhCumProb[0]->SetBinContent(
i, 1. - (Double_t) cumProbTrue / nofTrue);
362 new TCanvas(
"ann_select_ann_output",
"ann_select_ann_output", 500, 500);
366 list_of(
"True")(
"Fake"),
376 new TCanvas(
"ann_select_cum_prob",
"ann_select_cum_prob", 500, 500);
378 list_of(
"True")(
"Fake"),
387 TCanvas* c3 =
new TCanvas(
"ann_select_params",
"ann_select_params", 900, 600);
391 list_of(
"True")(
"Fake"),
401 list_of(
"True")(
"Fake"),
411 list_of(
"True")(
"Fake"),
421 list_of(
"True")(
"Fake"),
431 list_of(
"True")(
"Fake"),
441 list_of(
"True")(
"Fake"),
454 for (
unsigned int i = 0;
i <
fHists.size();
i++) {
458 TDirectory* current = gDirectory;
459 TDirectory* rich = current->mkdir(
"CbmRichTrainAnnSelect");
462 for (
unsigned int i = 0;
i <
fHists.size();
i++) {
Int_t GetMotherId() const
const CbmLink & GetMatchedLink() const
vector< TH1D * > fhCumProb
Train ANN for fake rejection.
Double_t GetTrueOverAllHitsRatio() const
float GetAngle(CbmRichRingLight *ring)
virtual InitStatus Init()
Inherited from FairTask.
virtual void Exec(Option_t *option)
Inherited from FairTask.
vector< TH1D * > fhAnnOutput
Helper functions for drawing 1D and 2D histograms and graphs.
float GetRadialPosition() const
Return radial position of the ring.
Here the ring is fitted with the COP algorithm from A. Ayriyan/G. Ososkov.
UInt_t fMaxNofTrainSamples
void DiffFakeTrueCircle()
Fill ring selection parameters in array and histograms.
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)
int GetNofHits() const
Return number of hits in ring.
vector< TH1D * > fhNofHits
CbmRichTrainAnnSelect()
Default constructor.
Input Parameters for ANN.
TClonesArray * fRichRingMatches
Convert internal data classes to cbmroot common data classes.
virtual ~CbmRichTrainAnnSelect()
Destructor.
CbmRichRingSelectImpl * fSelectImpl
void SetRecFlag()
Set recFlag weather ring was found correctly or not.
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
TClonesArray * fRichRings
Here the ring is fitted with the COP algorithm from A. Ayriyan/G. Ososkov.
static void Init()
Initialize array of RICH hits.
vector< TH1D * > fhRadPos
virtual void DoFit(CbmRichRingLight *ring)
Inherited from CbmRichRingFitterBase.
virtual void FinishTask()
Inherited from FairTask.
void Draw(Option_t *="")
Draw results.
static void CopyHitsToRingLight(const CbmRichRing *ring1, CbmRichRingLight *ring2)
Copy hits from CbmRichRing to CbmRichRingLight.
vector< TH1D * > fhRadius
vector< TH1D * > fhNofHitsOnRing
CbmRichRingFitterCOP * fFitCOP
Train ANN for fake rejection.
int GetNofHitsOnRingCircle(CbmRichRingLight *ring)
vector< vector< RingSelectParam > > fRSParams
void SetRecFlag(Int_t recflag)
void TrainAndTestAnn()
Train and test ANN.