Split: fix refs to AddTaskPhysicsSelection.C
[u/mrichter/AliRoot.git] / PWGUD / multVScentPbPb / AnalysisMacroGlob.C
1 void AnalysisMacroGlob(TString dataset="/alice/sim/LHC10f8f_130844",
2                        TString outFName="glovar.root",
3                        Int_t  nEvents     = 5000,
4                        Int_t  nEventsSkip = 0) 
5 {
6   //  
7   TString format = GetFormatFromDataSet(dataset);
8   //
9   // ALICE stuff
10   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
11   if (!mgr) mgr = new AliAnalysisManager("Test train");
12   //
13   Bool_t isMC = dataset.Contains("sim");
14   InputHandlerSetup(format,kFALSE,isMC);
15   gProof->Load("AliTaskGlobVar.cxx++g");
16   //
17   /*
18   gROOT->LoadMacro("AddTaskGlobVar.C");
19   AliTaskGlobVar *task = AddTaskGlobVar(outFName.Data());
20   */
21   AliTaskGlobVar *task = new AliTaskGlobVar("AliTaskGlobVar");
22   // create output container
23   AliAnalysisDataContainer *coutput1 = 
24     mgr->CreateContainer("clist", TList::Class(),AliAnalysisManager::kOutputContainer,outFName.Data());
25   // add our task to the manager
26   mgr->AddTask(task);
27   //
28   // finaly connect input and output
29   mgr->ConnectInput(task, 0,  mgr->GetCommonInputContainer());
30   mgr->ConnectOutput(task,1,coutput1);
31   //
32   if (!isMC) {
33     AddPhysicsSelection();
34     task->SelectCollisionCandidates( AliVEvent::kUserDefined );
35     task->SetUseMC(kFALSE);
36   }
37   else task->SetUseMC(kTRUE);
38   //  else task->SelectCollisionCandidates( AliVEvent::kMB);
39   //
40   // Run analysis
41   mgr->InitAnalysis();
42   // process dataset  
43   mgr->StartAnalysis("proof", dataset.Data(), nEvents, nEventsSkip); 
44   //
45   TString evstCmd = "if [ -e event_stat.root ]; then \nmv event_stat.root evstat_"; 
46   evstCmd += outFName;  evstCmd += " \nfi";
47   gSystem->Exec( evstCmd.Data() );
48   
49 }
50
51
52 TString GetFormatFromDataSet(TString dataset) {
53   
54 //   Info("runAAF.C","Detecting format from dataset (may take while, depends on network connection)...");
55   TString dsTreeName;
56   if (dataset.Contains("#")) {
57     Info("runAAF.C",Form("Detecting format from dataset name '%s' ...",dataset.Data()));
58     dsTreeName=dataset(dataset.Last('#'),dataset.Length());
59   } else {
60     Info("runAAF.C",Form("Detecting format from dataset '%s' (may take while, depends on network connection) ...",dataset.Data()));
61     TFileCollection *ds = gProof->GetDataSet(dataset.Data());
62     if (!ds) {
63       Error(Form("Dataset %s doesn't exist on proof cluster!!!!",dataset.Data()));
64       return "";
65     }
66     dsTreeName = ds->GetDefaultTreeName();
67   }
68
69   if (dsTreeName.Contains("esdTree")) {
70     Info("runAAF.C","ESD input format detected ...");
71     return "ESD";
72   } else if (dsTreeName.Contains("aodTree"))  {
73     Info("runAAF.C","AOD input format detected ...");
74     return "AOD";
75   } else {
76     Error("runAAF.C",Form("Tree %s is not supported !!!",dsTreeName.Data()));
77     Error("runAAF.C",Form("Maybe set your DS to %s#esdTree or %s#aodTree",dataset.Data(),dataset.Data()));
78   }
79   
80   return "";
81 }
82
83 Bool_t InputHandlerSetup(TString format = "esd", Bool_t useRP=kFALSE, Bool_t useKine = kFALSE)
84 {
85   format.ToLower();
86
87   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
88
89   AliAnalysisDataContainer *cin = mgr->GetCommonInputContainer();
90
91   if (cin) return;
92
93   if (!format.CompareTo("esd"))
94   {
95     AliESDInputHandler *esdInputHandler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
96
97     if (!esdInputHandler)
98     {
99       Info("CustomAnalysisTaskInputSetup", "Creating esdInputHandler ...");
100       if (useRP) esdInputHandler = new AliESDInputHandlerRP();
101       else       esdInputHandler = new AliESDInputHandler();
102       mgr->SetInputEventHandler(esdInputHandler);
103     }
104     
105     if (useKine)
106     {
107       AliMCEventHandler* mcInputHandler = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
108
109       if (!mcInputHandler)
110       {
111         Info("CustomAnalysisTaskInputSetup", "Creating mcInputHandler ...");
112         AliMCEventHandler* mcInputHandler = new AliMCEventHandler();
113         mgr->SetMCtruthEventHandler(mcInputHandler);
114       }
115     }
116
117   }
118   else if (!format.CompareTo("aod"))
119   {
120     AliAODInputHandler *aodInputHandler = dynamic_cast<AliAODInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
121
122     if (!aodInputHandler)
123     {
124       Info("CustomAnalysisTaskInputSetup", "Creating aodInputHandler ...");
125       aodInputHandler = new AliAODInputHandler();
126       mgr->SetInputEventHandler(aodInputHandler);
127     }
128   }
129   else
130   {
131     Info("Wrong input format!!! Only ESD and AOD are supported. Skipping Task ...");
132     return kFALSE;
133   }
134
135   return kTRUE;
136 }
137
138 void AddPhysicsSelection(Bool_t isMC=kFALSE)
139 {
140   // physics selection a la Michele
141   printf("Requesting physics selection in %s mode\n",isMC ? "MC":"Data");
142   gROOT->ProcessLine(".L $ALICE_ROOT/OADB/macros/AddTaskPhysicsSelection.C");
143   //isMC is true when processing monte carlo, the second 0 disables the cluster vs tracklets
144   AliPhysicsSelectionTask* physicsSelectionTask = AddTaskPhysicsSelection(isMC,0);
145   if(!isMC) {
146     AliPhysicsSelection * physSel = physicsSelectionTask->GetPhysicsSelection();
147     physSel->AddCollisionTriggerClass("+CMBAC-B-NOPF-ALL");
148     /*
149     physSel->AddCollisionTriggerClass("+CMBS1C-B-NOPF-ALL");
150     physSel->AddCollisionTriggerClass("+CMBS1A-B-NOPF-ALL");
151     */
152     //
153     physSel->AddCollisionTriggerClass("+CMBS2C-B-NOPF-ALL");
154     physSel->AddCollisionTriggerClass("+CMBS2A-B-NOPF-ALL");
155     //
156     // This are needed only to fill the statistics tables
157     physSel->AddBGTriggerClass("+CMBAC-C-NOPF-ALL");
158     physSel->AddBGTriggerClass("+CMBAC-A-NOPF-ALL");
159     physSel->AddBGTriggerClass("+CMBAC-E-NOPF-ALL");
160     //
161     /*
162     physSel->AddBGTriggerClass("+CMBS1C-C-NOPF-ALL");
163     physSel->AddBGTriggerClass("+CMBS1C-A-NOPF-ALL");
164     physSel->AddBGTriggerClass("+CMBS1C-E-NOPF-ALL");
165     //
166     physSel->AddBGTriggerClass("+CMBS1A-C-NOPF-ALL");
167     physSel->AddBGTriggerClass("+CMBS1A-A-NOPF-ALL");
168     physSel->AddBGTriggerClass("+CMBS1A-E-NOPF-ALL");
169     //
170     */
171     /*
172     //
173     physSel->AddBGTriggerClass("+CMBS2C-C-NOPF-ALL");
174     physSel->AddBGTriggerClass("+CMBS2C-A-NOPF-ALL");
175     physSel->AddBGTriggerClass("+CMBS2C-E-NOPF-ALL");
176     //
177     physSel->AddBGTriggerClass("+CMBS2A-C-NOPF-ALL");
178     physSel->AddBGTriggerClass("+CMBS2A-A-NOPF-ALL");
179     physSel->AddBGTriggerClass("+CMBS2A-E-NOPF-ALL");
180     */
181   } 
182   // if you use the following line, your task only gets the selected events
183   //  task->SelectCollisionCandidates(AliVEvent::kUserDefined);
184   //
185   //Alternatively, in the UserExec of your task:
186   //Bool_t isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kUserDefined);
187   //
188 }