AliPhysics  master (3d17d9d)
AddTaskLc2V0bachelor_TMVAApp.C
Go to the documentation of this file.
1 class AliAnalysisTaskSELc2V0bachelorTMVAAppMine;
2 
3 AliAnalysisTaskSELc2V0bachelorTMVAApp* AddTaskLc2V0bachelor_TMVAApp(Int_t nvars, TString library = "_6_12", TString finname="Lc2V0bachelorCuts.root",
5  Bool_t theMCon=kTRUE,
6  Bool_t fillTree=kFALSE,
7  Bool_t onTheFly=kFALSE,
8  Bool_t keepingOnlyHIJINGbkd=kFALSE,
9  TString suffixName="",
10  Bool_t debugFlag = kFALSE,
11  Bool_t useXmlWeightsFile = kTRUE,
12  Bool_t useWeightsLibrary = kFALSE,
13  TString xmlWeightsFile = "$ALICE_PHYSICS/PWGHF/vertexingHF/TMVA/LHC19c2a_TMVAClassification_BDT_2_4_noP.weights.xml",
14  Bool_t useMultCorrection = kFALSE,
15  TString estimatorFilename="", // Multicity estimator file
16  Double_t refMult=9.26, // refrence multiplcity (period b)
17  Int_t year = 16, // Production year
18  Int_t recoEstimator = AliAnalysisTaskSELc2V0bachelorTMVAApp::kNtrk10, // fMultiplicityEstimator
19  Bool_t useMultCut = kFALSE,
20  Float_t multMin = 0., // Minimum is included
21  Float_t multMax = 99999., // Maximum is excluded
22  Bool_t useXmlFileFromCVMFS = kFALSE,
23  TString xmlFileFromCVMFS = ""
24  ){
25 
26  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
27  if (!mgr) {
28  ::Error("AddTaskLc2V0bachelor", "No analysis manager to connect to.");
29  return NULL;
30  }
31 
32  /*
33  TString inputVariablesBDT = "massK0S,tImpParBach,tImpParV0,bachelorPt,combinedProtonProb,DecayLengthK0S*0.497/v0P,cosPAK0S,CosThetaStar,signd0";
34  TObjArray *tokens = inputVariablesBDT.Tokenize(",");
35  tokens->Print();
36  std::vector<std::string> inputNamesVec;
37  for(Int_t i=0; i<tokens->GetEntries(); i++){
38  TString variable = ((TObjString*)(tokens->At(i)))->String();
39  string tmpvar = variable.Data();
40  inputNamesVec.push_back(tmpvar);
41  }
42 
43  IClassifierReader* fBDTReader = new ReadBDT_Default(inputNamesVec);
44  */
45 
46  // cuts are stored in a TFile generated by makeTFile4CutsLc2V0bachelor.C in ./macros/
47  // set there the cuts!!!!!
48  Bool_t stdcuts=kFALSE;
49  TFile* filecuts;
50  if( finname.EqualTo("") ) {
51  stdcuts=kTRUE;
52  } else {
53  filecuts=TFile::Open(finname.Data());
54  if(!filecuts ||(filecuts&& !filecuts->IsOpen())){
55  Printf("Input file not found : check your cut object"); return NULL;
56  }
57  }
58 
59  AliRDHFCutsLctoV0* RDHFCutsLctoV0anal = new AliRDHFCutsLctoV0();
60  if (stdcuts) RDHFCutsLctoV0anal->SetStandardCutsPP2010();
61  else RDHFCutsLctoV0anal = (AliRDHFCutsLctoV0*)filecuts->Get("LctoV0AnalysisCuts");
62  RDHFCutsLctoV0anal->SetName("LctoV0AnalysisCuts");
63  RDHFCutsLctoV0anal->SetMinPtCandidate(ptMin);
64  RDHFCutsLctoV0anal->SetMaxPtCandidate(ptMax);
65  RDHFCutsLctoV0anal->SetUseCentrality(1);
66 
67  // mm let's see if everything is ok
68  if (!RDHFCutsLctoV0anal) {
69  cout << "Specific AliRDHFCutsLctoV0 not found\n";
70  return NULL;
71  }
72 
73  Int_t nvarsSpectators = 0;
74  TString namesTMVAvars, namesTMVAvarsSpectators;
75  if (nvars == 14) namesTMVAvars = "massK0S,tImpParBach,tImpParV0,bachelorPt,DecayLengthK0S*0.497/v0P,cosPAK0S,CosThetaStar,signd0,bachelorP,nSigmaTOFpr,nSigmaTPCpr,nSigmaTPCpi,nSigmaTPCka,bachTPCmom";
76  else if (nvars == 11) {
77  namesTMVAvars = "massK0S,tImpParBach,tImpParV0,DecayLengthK0S*0.497/v0P,cosPAK0S,CosThetaStar,signd0,nSigmaTOFpr,nSigmaTPCpr,nSigmaTPCpi,nSigmaTPCka";
78  nvarsSpectators = 12;
79  namesTMVAvarsSpectators = "massLc2K0Sp,LcPt,cosPAK0S,V0positivePt,V0negativePt,dcaV0pos,bachelorPt,v0Pt,dcaV0,V0positiveEta,bachelorEta,centrality";
80  }
81  else if (nvars == 10) namesTMVAvars = "massK0S,tImpParBach,tImpParV0,DecayLengthK0S*0.497/v0P,cosPAK0S,signd0,nSigmaTOFpr,nSigmaTPCpr,nSigmaTPCpi,nSigmaTPCka";
82  else if (nvars == 7) {
83  namesTMVAvars = "massK0S,tImpParBach,tImpParV0,DecayLengthK0S*0.497/v0P,cosPAK0S,CosThetaStar,signd0";
84  nvarsSpectators = 16;
85  namesTMVAvarsSpectators = "nSigmaTOFpr,nSigmaTPCpr,nSigmaTPCpi,nSigmaTPCka,massLc2K0Sp,LcPt,cosPAK0S,V0positivePt,V0negativePt,dcaV0pos,bachelorPt,v0Pt,dcaV0,V0positiveEta,bachelorEta,centrality";
86  }
87 
88  //CREATE THE TASK
89  printf("CREATE TASK\n");
90  AliAnalysisTaskSELc2V0bachelorTMVAApp *task = new AliAnalysisTaskSELc2V0bachelorTMVAApp("AliAnalysisTaskSELc2V0bachelorTMVAApp", RDHFCutsLctoV0anal, onTheFly);
91  // task->SetMVReader(fBDTReader);
92  task->SetNVars(nvars);
93  task->SetNamesTMVAVariables(namesTMVAvars);
94  task->SetTMVAlibName("libvertexingHFTMVA.so");
95  task->SetTMVAlibPtBin(library);
96  task->SetFillTree(fillTree);
97 
98  Printf("************* fillTree = %d", (Int_t)fillTree);
99  task->SetMC(theMCon);
100  task->SetKeepingOnlyHIJINGBkg(keepingOnlyHIJINGbkd);
101  task->SetK0sAnalysis(kTRUE);
102  task->SetDebugLevel(0);
103  task->SetDebugHistograms(debugFlag);
104  // TMVA reader
105  task->SetNVarsSpectators(nvarsSpectators);
106  task->SetNamesTMVAVariablesSpectators(namesTMVAvarsSpectators);
107  task->SetUseXmlWeightsFile(useXmlWeightsFile);
108  task->SetUseWeightsLibrary(useWeightsLibrary);
109  task->SetXmlWeightsFile(TString(gSystem->ExpandPathName(Form("%s", xmlWeightsFile.Data()))));
110 
111  task->SetUseXmlFileFromCVMFS(useXmlFileFromCVMFS);
112  task->SetXmlFileFromCVMFS(xmlFileFromCVMFS);
113 
114  if(useMultCorrection){
115 
116  task->SetUseMultiplicityCorrection(useMultCorrection);
117  task->SetMultiplicityEstimator(recoEstimator);
119 
120  if(estimatorFilename.EqualTo("") ) {
121  printf("Estimator file not provided, multiplcity corrected histograms will not be filled\n");
122  }
123  else{
124 
125  TFile* fileEstimator=TFile::Open(estimatorFilename.Data());
126  if(!fileEstimator) {
127  Printf("FATAL: File with multiplicity estimator not found\n");
128  return NULL;
129  }
130 
131  task->SetReferenceMultiplcity(refMult); // < FUNCTION NEEDS TO BE ADDED TO AliAnalysisTaskSELc2V0bachelorMultTMVAApp.h
132  const Char_t* profilebasename="SPDmult10";
133  if(recoEstimator==AliAnalysisTaskSELc2V0bachelorTMVAApp::kVZEROA || recoEstimator==AliAnalysisTaskSELc2V0bachelorTMVAApp::kVZEROAEq) profilebasename="VZEROAmult";
134  else if(recoEstimator==AliAnalysisTaskSELc2V0bachelorTMVAApp::kVZERO || recoEstimator==AliAnalysisTaskSELc2V0bachelorTMVAApp::kVZEROEq) profilebasename="VZEROMmult";
135  cout<<endl<<endl<<" profilebasename="<<profilebasename<<endl<<endl;
136 
137  // Only pp data is calibrated
138  if(year == 10){
139  const Char_t* periodNames[4] = {"LHC10b", "LHC10c", "LHC10d", "LHC10e"};
140  TProfile* multEstimatorAvg[4];
141  for(Int_t ip=0; ip<4; ip++) {
142  multEstimatorAvg[ip] = (TProfile*)(fileEstimator->Get(Form("%s_%s",profilebasename,periodNames[ip]))->Clone(Form("%s_%s_clone",profilebasename,periodNames[ip])));
143  if (!multEstimatorAvg[ip]) {
144  Printf("Multiplicity estimator for %s not found! Please check your estimator file",periodNames[ip]);
145  return NULL;
146  }
147  }
148  task->SetMultiplVsZProfileLHC10b(multEstimatorAvg[0]);
149  task->SetMultiplVsZProfileLHC10c(multEstimatorAvg[1]);
150  task->SetMultiplVsZProfileLHC10d(multEstimatorAvg[2]);
151  task->SetMultiplVsZProfileLHC10e(multEstimatorAvg[3]);
152  }
153  else if(year == 16){
154  const Char_t* periodNames[10]={"LHC16d","LHC16e","LHC16g","LHC16h_1", "LHC16h_2","LHC16j","LHC16k","LHC16l","LHC16o","LHC16p"};
155  TProfile *multEstimatorAvg[10];
156  for(Int_t ip=0;ip<10; ip++){
157  multEstimatorAvg[ip] = (TProfile*)(fileEstimator->Get(Form("%s_%s",profilebasename,periodNames[ip]))->Clone(Form("%s_%s_clone",profilebasename,periodNames[ip])));
158  if (!multEstimatorAvg[ip]) {
159  Printf("Multiplicity estimator for %s not found! Please check your estimator file",periodNames[ip]);
160  return NULL;
161  }
162  }
163  task->SetMultiplVsZProfileLHC16d(multEstimatorAvg[0]);
164  task->SetMultiplVsZProfileLHC16e(multEstimatorAvg[1]);
165  task->SetMultiplVsZProfileLHC16g(multEstimatorAvg[2]);
166  task->SetMultiplVsZProfileLHC16h1(multEstimatorAvg[3]);
167  task->SetMultiplVsZProfileLHC16h2(multEstimatorAvg[4]);
168  task->SetMultiplVsZProfileLHC16j(multEstimatorAvg[5]);
169  task->SetMultiplVsZProfileLHC16k(multEstimatorAvg[6]);
170  task->SetMultiplVsZProfileLHC16l(multEstimatorAvg[7]);
171  task->SetMultiplVsZProfileLHC16o(multEstimatorAvg[8]);
172  task->SetMultiplVsZProfileLHC16p(multEstimatorAvg[9]);
173  }
174  else if(year == 17){
175  const Char_t* periodNames[10]={"LHC17e","LHC17f","LHC17h","LHC17i", "LHC17j","LHC17k","LHC17l","LHC17m","LHC17o","LHC17r"};
176  TProfile *multEstimatorAvg[10];
177  for(Int_t ip=0;ip<10; ip++){
178  multEstimatorAvg[ip] = (TProfile*)(fileEstimator->Get(Form("%s_%s",profilebasename,periodNames[ip]))->Clone(Form("%s_%s_clone",profilebasename,periodNames[ip])));
179  if (!multEstimatorAvg[ip]) {
180  Printf("Multiplicity estimator for %s not found! Please check your estimator file",periodNames[ip]);
181  return NULL;
182  }
183  }
184  task->SetMultiplVsZProfileLHC17e(multEstimatorAvg[0]);
185  task->SetMultiplVsZProfileLHC17f(multEstimatorAvg[1]);
186  task->SetMultiplVsZProfileLHC17h(multEstimatorAvg[2]);
187  task->SetMultiplVsZProfileLHC17i(multEstimatorAvg[3]);
188  task->SetMultiplVsZProfileLHC17j(multEstimatorAvg[4]);
189  task->SetMultiplVsZProfileLHC17k(multEstimatorAvg[5]);
190  task->SetMultiplVsZProfileLHC17l(multEstimatorAvg[6]);
191  task->SetMultiplVsZProfileLHC17m(multEstimatorAvg[7]);
192  task->SetMultiplVsZProfileLHC17o(multEstimatorAvg[8]);
193  task->SetMultiplVsZProfileLHC17r(multEstimatorAvg[9]);
194  }
195  else if(year == 18){
196  const Char_t* periodNames[14]={"LHC18b","LHC18d","LHC18e","LHC18f", "LHC18g","LHC18h","LHC18i","LHC18j","LHC18k","LHC18l","LHC18m","LHC18n","LHC18o","LHC18p"};
197  TProfile *multEstimatorAvg[14];
198  for(Int_t ip=0;ip<14; ip++){
199  multEstimatorAvg[ip] = (TProfile*)(fileEstimator->Get(Form("%s_%s",profilebasename,periodNames[ip]))->Clone(Form("%s_%s_clone",profilebasename,periodNames[ip])));
200  if (!multEstimatorAvg[ip]) {
201  Printf("Multiplicity estimator for %s not found! Please check your estimator file",periodNames[ip]);
202  return NULL;
203  }
204  }
205  task->SetMultiplVsZProfileLHC18b(multEstimatorAvg[0]);
206  task->SetMultiplVsZProfileLHC18d(multEstimatorAvg[1]);
207  task->SetMultiplVsZProfileLHC18e(multEstimatorAvg[2]);
208  task->SetMultiplVsZProfileLHC18f(multEstimatorAvg[3]);
209  task->SetMultiplVsZProfileLHC18g(multEstimatorAvg[4]);
210  task->SetMultiplVsZProfileLHC18h(multEstimatorAvg[5]);
211  task->SetMultiplVsZProfileLHC18i(multEstimatorAvg[6]);
212  task->SetMultiplVsZProfileLHC18j(multEstimatorAvg[7]);
213  task->SetMultiplVsZProfileLHC18k(multEstimatorAvg[8]);
214  task->SetMultiplVsZProfileLHC18l(multEstimatorAvg[9]);
215  task->SetMultiplVsZProfileLHC18m(multEstimatorAvg[10]);
216  task->SetMultiplVsZProfileLHC18n(multEstimatorAvg[11]);
217  task->SetMultiplVsZProfileLHC18o(multEstimatorAvg[12]);
218  task->SetMultiplVsZProfileLHC18p(multEstimatorAvg[13]);
219  }
220  }
221  }
222 
223  if(useMultCut){
224  task->SetUseMultiplcityCut(useMultCut);
225  task->SetMinimumMultiplicity(multMin);
226  task->SetMaximumMultiplicity(multMax);
227  }
228 
229  mgr->AddTask(task);
230 
231  // Create and connect containers for input/output
232  //TString outputfile = AliAnalysisManager::GetCommonFileName();
233  //TString outputfile = Form("Lc2K0Sp_tree_pA%s.root", suffixName.Data());
234  //TString outputfile = Form("Lc2K0Sp_tree_pA%s%s.root", ptBin.Data(), suffixName.Data());
235  TString outputfile = "AnalysisResults.root";
236  TString output1name="", output2name="", output3name="", output4name="", output5name="", output6name="", output7name="";
237 
238  output1name = Form("treeList%s%s", suffixName.Data(), library.Data());
239  output2name = Form("Lc2pK0Scounter%s%s", suffixName.Data(), library.Data());
240  output3name = Form("Lc2pK0SCuts%s%s", suffixName.Data(), library.Data());
241  output4name = Form("treeSgn%s%s", suffixName.Data(), library.Data());
242  output5name = Form("treeBkg%s%s", suffixName.Data(), library.Data());
243  output6name = Form("listHistoKF%s%s", suffixName.Data(), library.Data());
244  output7name = Form("listWeights%s%s", suffixName.Data(), library.Data());
245 
246  mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
247  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer(output1name, TList::Class(), AliAnalysisManager::kOutputContainer, outputfile.Data()); // trees
248  mgr->ConnectOutput(task, 1, coutput1);
249 
250  AliAnalysisDataContainer *coutputLc2 = mgr->CreateContainer(output2name, TList::Class(), AliAnalysisManager::kOutputContainer, outputfile.Data()); //counter
251  mgr->ConnectOutput(task, 2, coutputLc2);
252 
253  AliAnalysisDataContainer *coutputLc3 = mgr->CreateContainer(output3name, TList::Class(), AliAnalysisManager::kOutputContainer, outputfile.Data()); // cuts
254  mgr->ConnectOutput(task, 3, coutputLc3);
255 
256  AliAnalysisDataContainer *coutput4 = mgr->CreateContainer(output4name, TTree::Class(), AliAnalysisManager::kOutputContainer, outputfile.Data()); // trees
257  mgr->ConnectOutput(task, 4, coutput4);
258 
259  AliAnalysisDataContainer *coutput5 = mgr->CreateContainer(output5name, TTree::Class(), AliAnalysisManager::kOutputContainer, outputfile.Data()); // trees
260  mgr->ConnectOutput(task, 5, coutput5);
261 
262  AliAnalysisDataContainer *coutput6 = mgr->CreateContainer(output6name, TList::Class(), AliAnalysisManager::kOutputContainer, outputfile.Data()); // trees
263  mgr->ConnectOutput(task, 6, coutput6);
264 
265  AliAnalysisDataContainer *coutput7 = mgr->CreateContainer(output7name, TList::Class(), AliAnalysisManager::kOutputContainer, outputfile.Data()); // trees
266  mgr->ConnectOutput(task, 7, coutput7);
267 
268  return task;
269 
270 }
double Double_t
Definition: External.C:58
virtual void SetStandardCutsPP2010()
void SetUseCentrality(Int_t flag=1)
TSystem * gSystem
char Char_t
Definition: External.C:18
Double_t ptMin
AliAnalysisTaskSELc2V0bachelorTMVAApp * AddTaskLc2V0bachelor_TMVAApp(Int_t nvars, TString library="_6_12", TString finname="Lc2V0bachelorCuts.root", Float_t ptMin=0, Float_t ptMax=24, Bool_t theMCon=kTRUE, Bool_t fillTree=kFALSE, Bool_t onTheFly=kFALSE, Bool_t keepingOnlyHIJINGbkd=kFALSE, TString suffixName="", Bool_t debugFlag=kFALSE, Bool_t useXmlWeightsFile=kTRUE, Bool_t useWeightsLibrary=kFALSE, TString xmlWeightsFile="$ALICE_PHYSICS/PWGHF/vertexingHF/TMVA/LHC19c2a_TMVAClassification_BDT_2_4_noP.weights.xml", Bool_t useMultCorrection=kFALSE, TString estimatorFilename="", Double_t refMult=9.26, Int_t year=16, Int_t recoEstimator=AliAnalysisTaskSELc2V0bachelorTMVAApp::kNtrk10, Bool_t useMultCut=kFALSE, Float_t multMin=0., Float_t multMax=99999., Bool_t useXmlFileFromCVMFS=kFALSE, TString xmlFileFromCVMFS="")
void SetMaxPtCandidate(Double_t ptCand=1000.)
Definition: AliRDHFCuts.h:233
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
void SetUseVZEROParameterizedVertexCorr(Int_t flag)
Flag to use the zvtx correction from ( 0= none, 1= usual d2h, 2=AliESDUtils for VZERO multiplicity) ...
void SetMinPtCandidate(Double_t ptCand=-1.)
Definition: AliRDHFCuts.h:232
bool Bool_t
Definition: External.C:53
Double_t ptMax