]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/muon/AnalysisTrigChEff.C
Connection to tree in Notify() seems to be safer.
[u/mrichter/AliRoot.git] / PWG3 / muon / AnalysisTrigChEff.C
1 //--------------------------------------------------------------------------
2 // Base macro for submitting trigger chamber efficiency determination.
3 // 
4 // In case it is not run with full aliroot, it needs to have in the working directory:
5 //  - STEERBase.par
6 //  - ESD.par
7 //  - AOD.par
8 //  - ANALYSIS.par
9 //  - ANALYSISalice.par
10 //  - PWG3muon.par
11 // 
12 // The macro reads ESDs and outputs file:
13 // - MUON.TriggerEfficiencyMap.root
14 //
15 // To display the trigger chamber efficiency:
16 // > aliroot
17 // > AliMUONTriggerEfficiencyCells effCells("MUON.TriggerEfficiencyMap.root")
18 // > effCells.DisplayEfficiency()
19 //--------------------------------------------------------------------------
20
21 enum anaModes {kMlocal, kMgridLocal, kMgrid};
22 TString modeName[3] = {"local", "local", "grid"};
23 const TString kDefaultLocalInputDir="$ALICE_ROOT/MUON/test_out.100";
24 const TString kDefaultXmlFile="wn.xml";
25
26 void AnalysisTrigChEff(Int_t mode=kMlocal)
27 {
28 // Example of running analysis train
29   TStopwatch timer;
30   timer.Start();
31
32   gSystem->Load("libTree.so");
33   gSystem->Load("libGeom.so");
34   gSystem->Load("libVMC.so");
35   gSystem->Load("libPhysics.so");
36
37   // if root setup Par
38   TString checkString=gSystem->Getenv("ALICE_ROOT");
39   checkString.Append("/lib/tgt_linux/libMUONbase.so");
40   TString foundLib=gSystem->GetLibraries(checkString.Data());
41
42   if(foundLib.Length()==0){
43     // Common packages
44     SetupPar("STEERBase");
45     SetupPar("ESD");
46     SetupPar("AOD");
47     SetupPar("ANALYSIS");
48     SetupPar("ANALYSISalice");
49   }
50   SetupPar("PWG3muon");
51
52   // Analysis using standard AliRoot libraries
53   gSystem->Load("libSTEERBase.so");
54   gSystem->Load("libESD.so");
55   gSystem->Load("libAOD.so");
56   gSystem->Load("libANALYSIS.so");
57   gSystem->Load("libANALYSISalice.so");
58   gSystem->Load("libANALYSISalice.so");
59   gSystem->Load("libPWG3muon.so");
60
61   //
62   // Connect to alien
63   //
64   if(mode==kMgridLocal || mode==kMgrid)
65     TGrid::Connect("alien://"); 
66
67   //
68   // Create the chain
69   //
70   TChain* chain = CreateChain(mode);
71
72   TString outFileName("MUON.TriggerEfficiencyMap.root");
73   //
74   //
75   // Make the analysis manager
76   AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train", "A test setup for the analysis train");
77   // ESD input handler
78   AliESDInputHandler *esdHandler = new AliESDInputHandler();
79   //esdHandler->SetInactiveBranches("FMD CaloCluster");
80   // Monte Carlo handler
81   //AliMCEventHandler* mcHandler = new AliMCEventHandler();
82
83   mgr->SetInputEventHandler(esdHandler);
84   //mgr->SetMCtruthEventHandler(mcHandler);
85   
86   // Trigger chamber efficiency analysis
87   AliAnalysisTaskTrigChEff* taskTrigChEff = new AliAnalysisTaskTrigChEff("TaskTrigChEff");
88   mgr->AddTask(taskTrigChEff);
89   
90   // Create containers for input/output
91   // Top container for ESD input 
92   AliAnalysisDataContainer *cin_esd = mgr->GetCommonInputContainer();
93
94   // Output histograms list for single muons analysis
95   AliAnalysisDataContainer *cout_trigChEff = mgr->CreateContainer("triggerChamberEff", TList::Class(),
96                                                                  AliAnalysisManager::kOutputContainer, outFileName.Data());
97
98   mgr->ConnectInput  (taskTrigChEff, 0, cin_esd);
99   mgr->ConnectOutput (taskTrigChEff, 0, cout_trigChEff);
100
101   //
102   // Run the analysis
103   //
104   if (mgr->InitAnalysis()) {
105     mgr->PrintStatus();
106     mgr->StartAnalysis(modeName[mode].Data(), chain);
107   }
108   timer.Stop();
109   timer.Print();
110 }
111
112 //______________________________________________________________________________
113 TChain* CreateChain(Int_t mode)
114 {
115   printf("*******************************\n");
116   printf("*** Getting the Chain       ***\n");
117   printf("*******************************\n");
118   TChain *chain = 0x0;
119   if(mode==kMgridLocal || mode==kMgrid){
120     AliTagAnalysis *analysis = new AliTagAnalysis();
121     chain = analysis->GetChainFromCollection(kDefaultXmlFile.Data(),"esdTree");
122   }
123   else{
124     chain = new TChain("esdTree");
125     TString inFileName("AliESDs.root");
126     inFileName.Prepend(Form("%s/",kDefaultLocalInputDir.Data()));
127     chain->Add(inFileName.Data());
128   }
129   if (chain) chain->ls();
130   return chain;
131 }
132
133 //______________________________________________________________________________
134 void SetupPar(char* pararchivename)
135 {
136   if (pararchivename) {
137     char processline[1024];
138     sprintf(processline,".! tar xvzf %s.par",pararchivename);
139     gROOT->ProcessLine(processline);
140     const char* ocwd = gSystem->WorkingDirectory();
141     gSystem->ChangeDirectory(pararchivename);
142     printf("Current directory = %s\n",gSystem->pwd());
143
144     // check for BUILD.sh and execute
145     if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
146       printf("*******************************\n");
147       printf("*** Building PAR archive    ***\n");
148       printf("*******************************\n");
149
150       if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
151         Error("runProcess","Cannot Build the PAR Archive! - Abort!");
152         return -1;
153       }
154     }
155     // check for SETUP.C and execute
156     if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
157       printf("*******************************\n");
158       printf("*** Setup PAR archive       ***\n");
159       printf("*******************************\n");
160       gROOT->Macro("PROOF-INF/SETUP.C");
161     }
162         
163     gSystem->ChangeDirectory("../");
164   } 
165 }