]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/muon/AnalysisTrainFromStandardToMuonAODLocal.C
Warning fixed
[u/mrichter/AliRoot.git] / PWG3 / muon / AnalysisTrainFromStandardToMuonAODLocal.C
1 void AnalysisTrainFromStandardToMuonAODLocal(char* filein= "AliAODs.root", 
2                                              char* fileout= "AliMuonAOD.root", 
3                                              char* dirChain= ".",
4                                              char* dirData= "."){
5      
6 // Macro to produce a MUON-AOD, i.e. a replica of the standard AOD, containing only events
7 // where at least one muon is present
8 // 
9 // - The input files are the ESD (used only for tag creation) and the standard AOD.
10 //   Tags files are created from all the ESD/AOD files placed in the directory dirData 
11 //   and in its subdirectories.
12 // - The selection of the muon events is based on the AOD tags.
13 // - The content of the MUON-AOD can be defined by the user with some settings as
14 //   SetNeedsTracksBranchReplication(), SetNeedsVerticesBranchReplication() 
15 //   (defined in STEER/AliAODHandler.h)...
16
17
18     gSystem->Load("libTree.so");
19     gSystem->Load("libGeom.so");
20     gSystem->Load("libVMC.so");
21     gSystem->Load("libPhysics.so");
22
23     // Load par files  
24     SetupPar("STEERBase");
25     SetupPar("ESD");
26     SetupPar("AOD");
27     SetupPar("ANALYSIS");
28     SetupPar("ANALYSISalice");
29     SetupPar("PWG3base");      
30     SetupPar("PWG3muon");   
31         
32     // Create ESD tag files   
33     printf("Creating ESD Tags\n");
34     AliESDTagCreator *tesd = new AliESDTagCreator();
35     tesd->SetStorage(0);     
36     tesd->ReadLocalCollection(dirData);  
37  
38     // Create AOD tag files   
39     printf("Creating AOD Tags\n");
40     AliAODTagCreator *t = new AliAODTagCreator();
41     t->SetStorage(0);
42     t->ReadLocalCollection(dirData);    
43     
44     AliTagAnalysis *TagAna = new AliTagAnalysis("AOD"); 
45     
46     // Define tag cuts to select only events with muons
47     printf("Defining Tags cuts to select events containing at least one muon\n");
48     AliRunTagCuts *runCuts = new AliRunTagCuts();
49     AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
50     AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
51     AliEventTagCuts *evCuts = new AliEventTagCuts();
52     evCuts->SetNMuonRange(1,10);
53     
54     // Create the chain of interesting events
55     TChain* chain = 0x0;
56     TagAna->ChainLocalTags(dirChain);
57     chain = TagAna->QueryTags(runCuts,lhcCuts,detCuts,evCuts);
58
59     // Define aod input handler
60     AliAODInputHandler* aodInputHandler = new AliAODInputHandler();
61     
62     // Define aod output handler
63     AliAODHandler* aodOutputHandler = new AliAODHandler();
64
65     // Create non standard AOD
66     aodOutputHandler->SetCreateNonStandardAOD(); 
67     
68     // Select the branches to be written in the MUON-AOD
69     aodOutputHandler->SetNeedsHeaderReplication();
70     aodOutputHandler->SetNeedsTracksBranchReplication();
71     aodOutputHandler->SetNeedsVerticesBranchReplication();
72     //aodOutputHandler->SetNeedsV0sBranchReplication();
73     //aodOutputHandler->SetNeedsTrackletsBranchReplication(); 
74     //aodOutputHandler->SetNeedsPMDClustersBranchReplication();
75     //aodOutputHandler->SetNeedsJetsBranchReplication();
76     //aodOutputHandler->SetNeedsFMDClustersBranchReplication();
77     //aodOutputHandler->SetNeedsCaloClustersBranchReplication();
78     
79     aodOutputHandler->SetOutputFileName(fileout);
80
81      // Define the analysis manager
82     AliAnalysisManager *mgr  = new AliAnalysisManager("AOD Manager", "AOD Manager");
83     mgr->SetInputEventHandler(aodInputHandler);
84     mgr->SetOutputEventHandler(aodOutputHandler);
85     //mgr->SetDebugLevel(10);
86     
87     AliAnalysisTaskFromStandardToMuonAOD *aodfilter = new AliAnalysisTaskFromStandardToMuonAOD("AOD Filter");
88     mgr->AddTask(aodfilter);
89   
90     // Create containers for input/output
91     AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain",TChain::Class(), 
92                                                              AliAnalysisManager::kInputContainer);
93     AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("tree", TTree::Class(),
94                                                               AliAnalysisManager::kOutputContainer, "default");
95
96     mgr->ConnectInput(aodfilter,0,cinput1);
97     mgr->ConnectOutput(aodfilter,0,coutput1);
98     
99     // Run the analysis    
100     printf("CHAIN HAS %d ENTRIES\n",(Int_t)chain->GetEntries());
101     mgr->InitAnalysis();
102     mgr->PrintStatus();
103     mgr->StartAnalysis("local",chain);
104 }
105
106
107 Int_t setupPar(const char* pararchivename) {
108   ///////////////////
109   // Setup PAR File//
110   ///////////////////
111   if (pararchivename) {
112     char processline[1024];
113     sprintf(processline,".! tar xvzf %s.par",pararchivename);
114     gROOT->ProcessLine(processline);
115     const char* ocwd = gSystem->WorkingDirectory();
116     gSystem->ChangeDirectory(pararchivename);
117
118     // check for BUILD.sh and execute
119     if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
120       printf("*******************************\n");
121       printf("*** Building PAR archive    ***\n");
122       printf("*******************************\n");
123
124       if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
125         Error("runAnalysis","Cannot Build the PAR Archive! - Abort!");
126         return -1;
127       }
128     }
129     // check for SETUP.C and execute
130     if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
131       printf("*******************************\n");
132       printf("*** Setup PAR archive       ***\n");
133       printf("*******************************\n");
134       gROOT->Macro("PROOF-INF/SETUP.C");
135     }
136
137     gSystem->ChangeDirectory("../");
138   }
139
140   return 1;
141 }
142
143 //______________________________________________________________________________
144 void SetupPar(char* pararchivename)
145 {
146     if (pararchivename) {
147         char processline[1024];
148         sprintf(processline,".! tar xvzf %s.par",pararchivename);
149         gROOT->ProcessLine(processline);
150         TString ocwd = gSystem->WorkingDirectory();
151         gSystem->ChangeDirectory(pararchivename);
152         
153         // check for BUILD.sh and execute
154         if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
155             printf("*******************************\n");
156             printf("*** Building PAR archive    ***\n");
157             printf("*******************************\n");
158             
159             if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
160                 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
161                 return -1;
162             }
163         }
164         // check for SETUP.C and execute
165         if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
166             printf("*******************************\n");
167             printf("*** Setup PAR archive       ***\n");
168             printf("*******************************\n");
169             gROOT->Macro("PROOF-INF/SETUP.C");
170         }
171         
172         gSystem->ChangeDirectory(ocwd.Data());
173    printf("Current dir: %s\n", ocwd.Data());
174     } 
175 }