AliRoot Core  ee782a0 (ee782a0)
QAtrendingFitExample.C
Go to the documentation of this file.
1 
20 
21 
22 Bool_t useDNN=kFALSE;
23 TTree * tree = 0;
24 TTree * treeCache=0;
26 void loadTree() {
28  tree = info.GetChain("QA.TPC", "LHC17*", "cpass1_pass1", "QA.EVS;QA.rawTPC");
29  tree->SetAlias("interactionRate", "QA.EVS.interactionRate");
31  tree->SetAlias("qmaxQASum", "Sum$(qmaxQA.fElements*((abs(qmaxQA.fElements-40)<20)))/Sum$((abs(qmaxQA.fElements-40)<20))");
32  tree->SetAlias("qmaxQASumIn", "Sum$(qmaxQA.fElements*((Iteration$<36&&abs(qmaxQA.fElements-40)<20)))/Sum$((Iteration$<36&&abs(qmaxQA.fElements-40)<20))");
33  tree->SetAlias("qmaxQASumOut", "Sum$(qmaxQA.fElements*((Iteration$>=36&&abs(qmaxQA.fElements-40)<20)))/Sum$((Iteration$>=36&&abs(qmaxQA.fElements-40)<20))");
34  tree->SetAlias("qmaxQASumR", "qmaxQASumIn/qmaxQASum");
35  tree->SetAlias("meanMIPeleR", "meanMIPele/meanMIP");
36  tree->SetAlias("bz0", "bz+rndm*0.0001");
37  tree->SetMarkerStyle(21); tree->SetMarkerSize(0.5);
38 }
39 
45 void cacheTree(){
46  AliTreePlayer::MakeCacheTree(tree,"resolutionMIP:meanMIPeleR:tpcItsMatchA:bz0:interactionRate:qmaxQASum:qmaxQASumIn:qmaxQASumOut:qmaxQASumR:run:time","TMVAInput.root","MVAInput","meanMIP>30&&run==QA.EVS.run");
47 }
48 
57  TString layoutString("Layout=TANH|20,LINEAR");
58  TString training0("LearningRate=1e-5,Momentum=0.5,Repetitions=1,ConvergenceSteps=500,BatchSize=50,"
59  "TestRepetitions=7,WeightDecay=0.01,Regularization=L1,DropConfig=0.5+0.5+0.5+0.5,"
60  "DropRepetitions=2");
61  TString training1("LearningRate=1e-5,Momentum=0.9,Repetitions=1,ConvergenceSteps=170,BatchSize=30,"
62  "TestRepetitions=7,WeightDecay=0.01,Regularization=L1,DropConfig=0.1+0.1+0.1,DropRepetitions="
63  "1");
64  TString trainingStrategyString("TrainingStrategy=");
65  trainingStrategyString += training0 + "|" + training1;
66  TString dnnOptions("!H:V:ErrorStrategy=SUMOFSQUARES:VarTransform=G:WeightInitialization=XAVIERUNIFORM:Architecture=CPU");
67  dnnOptions.Append(":");
68  dnnOptions.Append(layoutString);
69  dnnOptions.Append(":");
70  dnnOptions.Append(trainingStrategyString);
72  AliNDFunctionInterface::registerMethod("BDTRF25_8","!H:!V:NTrees=25:Shrinkage=0.1:UseRandomisedTrees:nCuts=20:MaxDepth=8",TMVA::Types::kBDT);
73  AliNDFunctionInterface::registerMethod("BDTRF12_16", "!H:!V:NTrees=12:Shrinkage=0.1:UseRandomisedTrees:nCuts=20:MaxDepth=16", TMVA::Types::kBDT);
74  AliNDFunctionInterface::registerMethod("KNN","nkNN=20:ScaleFrac=0.8:SigmaFact=1.0:Kernel=Gaus:UseKernel=F:UseWeight=T:!Trim", TMVA::Types::kKNN);
75  AliNDFunctionInterface::registerMethod("MLP", "!H:!V:VarTransform=Norm:NeuronType=tanh:NCycles=20000:HiddenLayers=N+20:TestRate=6:TrainingMethod=BFGS:Sampling=0.3:SamplingEpoch=0.8:ConvergenceImprove=1e-6:ConvergenceTests=15:!UseRegulator",TMVA::Types::kMLP);
76  AliNDFunctionInterface::registerMethod("DNN_CPU",dnnOptions.Data(), TMVA::Types::kDNN);
77 }
78 
81 void makeMVAFits(){
82  TFile *f= TFile::Open("TMVAInput.root");
83  f->GetObject("MVAInput",treeCache);
84  AliNDFunctionInterface::FitMVA(treeCache, "resolutionMIP","interactionRate>0", "interactionRate:bz0:qmaxQASum:qmaxQASumR","BDTRF25_8:BDTRF12_16:MLP:KNN");
85  AliNDFunctionInterface::FitMVA(treeCache, "meanMIPeleR","interactionRate>0", "interactionRate:bz0:qmaxQASum:qmaxQASumR","BDTRF25_8:BDTRF12_16:MLP:KNN");
86  AliNDFunctionInterface::FitMVA(treeCache, "tpcItsMatchA","interactionRate>0", "interactionRate:bz0:qmaxQASum:qmaxQASumR","BDTRF25_8:BDTRF12_16:MLP:KNN");
87 }
88 
93 void makeMVABootstrapMI(Int_t nregression=10){
94  TFile *f= TFile::Open("TMVAInput.root");
95  f->GetObject("MVAInput",treeCache);
96  for (Int_t iBoot=0; iBoot<nRegression; iBoot++) {
97  AliNDFunctionInterface::FitMVA(treeCache, "resolutionMIP", "interactionRate>0", "interactionRate:bz0:qmaxQASum:qmaxQASumR", "BDTRF25_8:BDTRF12_16:KNN", 0, iBoot);
98  AliNDFunctionInterface::FitMVA(treeCache, "meanMIPeleR", "interactionRate>0", "interactionRate:bz0:qmaxQASum:qmaxQASumR", "BDTRF25_8:BDTRF12_16:KNN", 0, iBoot);
99  AliNDFunctionInterface::FitMVA(treeCache, "tpcItsMatchA", "interactionRate>0", "interactionRate:bz0:qmaxQASum:qmaxQASumR", "BDTRF25_8:BDTRF12_16:KNN", 0, iBoot);
100  if (useDNN){
101  AliNDFunctionInterface::FitMVA(treeCache, "resolutionMIP", "interactionRate>0", "interactionRate:bz0:qmaxQASum:qmaxQASumR", "DNN_CPU", 0, iBoot);
102  }
103  }
104 }
105 
108  AliNDFunctionInterface::LoadMVAReader(0,"TMVA_RegressionOutput.root","MLP","dir_resolutionMIP");
109  AliNDFunctionInterface::LoadMVAReader(1,"TMVA_RegressionOutput.root","KNN","dir_resolutionMIP");
110  AliNDFunctionInterface::LoadMVAReader(2,"TMVA_RegressionOutput.root","BDTRF25_8","dir_resolutionMIP");
111  AliNDFunctionInterface::LoadMVAReader(3,"TMVA_RegressionOutput.root","BDTRF12_16","dir_resolutionMIP");
112 }
113 
117  AliNDFunctionInterface::LoadMVAReaderArray(0,"TMVA_RegressionOutput.root","BDTRF12_16",".*resolutionMIP");
118  AliNDFunctionInterface::LoadMVAReaderArray(1,"TMVA_RegressionOutput.root","BDTRF25_8",".*resolutionMIP");
119  AliNDFunctionInterface::LoadMVAReaderArray(2,"TMVA_RegressionOutput.root","KNN",".*resolutionMIP");
120 }
125  gSystem->Unlink("TMVA_RegressionOutput.root");
127  loadTree();
129  cacheTree();
131  RegisterFitters();
133  makeMVABootstrapMI(10);
142  tree->Draw("AliNDFunctionInterface::EvalMVAStat(0,1,interactionRate, bz0,qmaxQASum,qmaxQASumR):resolutionMIP:run","run==QA.EVS.run","colz");
143  gPad->SaveAs("resolutionMIPvsfit.png");
147  tree->Draw("AliNDFunctionInterface::EvalMVAStat(0,1,interactionRate, bz0,qmaxQASum,qmaxQASumR)/resolutionMIP:run:interactionRate","run==QA.EVS.run","colz");
148  gPad->SaveAs("resolutionMIPFitRatiovsRun.png");
152  tree->Draw("AliNDFunctionInterface::EvalMVAStat(0,2,interactionRate, bz0,qmaxQASum,qmaxQASumR):AliNDFunctionInterface::EvalMVAStat(1,2,interactionRate, bz0,qmaxQASum,qmaxQASumR)","run==QA.EVS.run","colz");
153 }
TFile * Open(const char *filename, Long64_t &nevents)
TTree * treeCache
void RegisterFitters()
void loadTree()
Load tree and defining derived information (TTree aliases) and metadata.
void makeMVAFits()
AliExternalInfo info
void makeMVABootstrapMI(Int_t nregression=10)
TTree * tree
Int_t LoadMVAReaderArray(Int_t id, const char *inputFile, const char *methodMask, const char *dirMask)
void loadMVAreaders()
Bool_t useDNN
TF1 * f
Definition: interpolTest.C:21
TMVA::MethodBase * LoadMVAReader(Int_t id, const char *inputFile, const char *method, const char *dir)
MVA regression.
This class gives you an interface to different trees of information spread throughout ALICE...
TChain * GetChain(TString type, TString period, TString pass, Int_t buildIndex=1)
void registerMethod(std::string method, std::string content, TMVA::Types::EMVA id)
example registering default methods ()
static void MakeCacheTree(TTree *tree, TString varList, TString outFile, TString outTree, TCut selection, Int_t nEntries=-1, Int_t firstEntry=0)
Fill tree with information specified in varList of TTreeFormulas Used to cache CPU consuming formulas...
void cacheTree()
Int_t FitMVA(TTree *tree, const char *varFit, TCut cut, const char *variableList, const char *methodList, const char *weights=NULL, Int_t index=-1)
void QAtrendingFitExample()
void loadMVAreadersBootstrap()