Fix for CMake
[u/mrichter/AliRoot.git] / PWG0 / multiplicity / run.C
1 void run(Char_t* data, Long64_t nRuns = -1, Long64_t offset = 0, Bool_t aDebug = kFALSE, Int_t aProof = 0, Bool_t mc = kTRUE, const char* option = "")
2 {
3   // aProof option: 0 no proof
4   //                1 proof with chain
5   //                2 proof with dataset
6
7   if (nRuns < 0)
8     nRuns = 1234567890;
9
10   if (aProof)
11   {
12     TProof::Open("alicecaf");
13     //gProof->SetParallel(1);
14
15     // Enable the needed package
16     if (1)
17     {
18       gProof->UploadPackage("$ALICE_ROOT/STEERBase");
19       gProof->EnablePackage("$ALICE_ROOT/STEERBase");
20       gProof->UploadPackage("$ALICE_ROOT/ESD");
21       gProof->EnablePackage("$ALICE_ROOT/ESD");
22       gProof->UploadPackage("$ALICE_ROOT/AOD");
23       gProof->EnablePackage("$ALICE_ROOT/AOD");
24       gProof->UploadPackage("$ALICE_ROOT/ANALYSIS");
25       gProof->EnablePackage("$ALICE_ROOT/ANALYSIS");
26       gProof->UploadPackage("$ALICE_ROOT/ANALYSISalice");
27       gProof->EnablePackage("$ALICE_ROOT/ANALYSISalice");
28     }
29     else
30     {
31       gProof->UploadPackage("$ALICE_ROOT/AF-v4-16");
32       gProof->EnablePackage("$ALICE_ROOT/AF-v4-16");
33     }
34
35     gProof->UploadPackage("$ALICE_ROOT/PWG0base");
36     gProof->EnablePackage("$ALICE_ROOT/PWG0base");
37   }
38   else
39   {
40     gSystem->Load("libVMC");
41     gSystem->Load("libTree");
42     gSystem->Load("libSTEERBase");
43     gSystem->Load("libESD");
44     gSystem->Load("libAOD");
45     gSystem->Load("libANALYSIS");
46     gSystem->Load("libANALYSISalice");
47     gSystem->Load("libPWG0base");
48   }
49
50   // Create the analysis manager
51   mgr = new AliAnalysisManager;
52
53   AliPWG0Helper::AnalysisMode analysisMode = AliPWG0Helper::kSPD;
54   AliPWG0Helper::Trigger      trigger      = AliPWG0Helper::kMB1;
55
56   AliPWG0Helper::PrintConf(analysisMode, trigger);
57
58   TString taskName("AliMultiplicityTask.cxx+");
59   if (aDebug)
60     taskName += "+g";
61
62   // Create, add task
63   if (aProof > 0) {
64     gProof->Load(taskName);
65   } else
66     gROOT->Macro(taskName);
67
68   task = new AliMultiplicityTask(option);
69
70   if (analysisMode != AliPWG0Helper::kSPD)
71   {
72     // selection of esd tracks
73     gROOT->ProcessLine(".L ../CreateStandardCuts.C");
74     AliESDtrackCuts* esdTrackCuts = CreateTrackCuts(analysisMode);
75     if (!esdTrackCuts)
76     {
77       printf("ERROR: esdTrackCuts could not be created\n");
78       return;
79     }
80
81     task->SetTrackCuts(esdTrackCuts);
82   }
83   else
84     task->SetDeltaPhiCut(0.05);
85
86   task->SetAnalysisMode(analysisMode);
87   task->SetTrigger(trigger);
88
89   if (mc)
90     task->SetReadMC();
91
92   //task->SetUseMCVertex();
93
94   mgr->AddTask(task);
95
96   TString optionStr(option);
97   
98   if (mc) {
99     // Enable MC event handler
100     AliMCEventHandler* handler = new AliMCEventHandler;
101     if (!optionStr.Contains("particle-efficiency"))
102       handler->SetReadTR(kFALSE);
103     mgr->SetMCtruthEventHandler(handler);
104   }
105
106   // pt study
107   if (optionStr.Contains("pt-spectrum-func"))
108   {
109     TF1* func = new TF1("func", "1", 0, 0.2);
110     //TF1* func = new TF1("func", "1.5 - x / 0.2 * 0.5", 0, 0.2);
111     //TF1* func = new TF1("func", "1.25 - x / 0.2 * 0.25", 0, 0.2);
112     //TF1* func = new TF1("func", "0.75 + x / 0.2 * 0.25", 0, 0.2);
113     hist = func->GetHistogram();
114     //new TCanvas; func->Draw();
115     //inputList.Add(func->GetHistogram()->Clone("pt-spectrum"));
116
117     new TCanvas; hist->Draw();
118     task->SetPtSpectrum((TH1D*) hist->Clone("pt-spectrum"));
119   }
120
121   // Add ESD handler
122   AliESDInputHandler* esdH = new AliESDInputHandler;
123   esdH->SetInactiveBranches("AliESDACORDE FMD ALIESDTZERO ALIESDZDC AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks AliESDTZERO ALIESDACORDE MuonTracks TrdTracks");
124   mgr->SetInputEventHandler(esdH);
125
126   // Attach input
127   cInput  = mgr->GetCommonInputContainer();
128   mgr->ConnectInput(task, 0, cInput);
129
130   // Attach output
131   cOutput = mgr->CreateContainer("cOutput", TList::Class(), AliAnalysisManager::kOutputContainer);
132   //cOutput->SetDataOwned(kTRUE);
133   mgr->ConnectOutput(task, 0, cOutput);
134
135   // Enable debug printouts
136   if (aDebug)
137     mgr->SetDebugLevel(2);
138
139   // Run analysis
140   mgr->InitAnalysis();
141   mgr->PrintStatus();
142
143   if (aProof == 2)
144   {
145     // process dataset
146
147     mgr->StartAnalysis("proof", data, nRuns, offset);
148   }
149   else if (aProof == 3)
150   {
151     gROOT->ProcessLine(".L CreateChainFromDataSet.C");
152     ds = gProof->GetDataSet(data)->GetStagedSubset();
153     chain = CreateChainFromDataSet(ds);
154     mgr->StartAnalysis("local", chain, nRuns, offset);
155   }
156   else
157   {
158     // Create chain of input files
159     gROOT->LoadMacro("../CreateESDChain.C");
160     chain = CreateESDChain(data, nRuns, offset);
161
162     mgr->StartAnalysis((aProof > 0) ? "proof" : "local", chain);
163   }
164 }