]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/muon/AnalysisTrainFromStandardToMuonAODLocal.C
Cleanup the code. Fix memory leak. Now inherit from AliAnalysisTaskSE (Antoine, Phili...
[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                                              Int_t nev=123456789){
6      
7 // Macro to produce a MUON-AOD, i.e. a replica of the standard AOD, containing only events
8 // where at least one muon is present
9 // 
10 // - The input files are the standard AOD and the AOD.tag.root files 
11 // - The AOD.tag file can be:
12 //      1) the one previously created together with the AOD file (i.e. from
13 //         AnalysisTrainMuonLocal.C)
14 //      2) created on the fly with this macro
15 // - The selection of the muon events is based on the AOD tags
16 // - The content of the MUON-AOD can be defined by the user with some settings as
17 //   SetNeedsTracksBranchReplication(), SetNeedsVerticesBranchReplication() 
18 //   (defined in STEER/AliAODHandler.h)...
19
20
21     gSystem->Load("libTree.so");
22     gSystem->Load("libGeom.so");
23     gSystem->Load("libVMC.so");
24     gSystem->Load("libPhysics.so");
25     gSystem->Load("libSTEER.so");              // for aliroot based analysis
26     gSystem->Load("libPWG3muon.so");  // for aliroot based analysis
27
28     // Load par files, if the analysis is par based
29     // SetupPar("STEERBase");
30     // SetupPar("ESD");
31     // SetupPar("AOD");
32     // SetupPar("ANALYSIS");
33     // SetupPar("ANALYSISalice");
34     // SetupPar("PWG3muon");   
35      
36     // Uncomment the following lines if the AOD tag file has to be created on the fly    
37     // printf("Creating AOD Tags on the fly\n");
38     // AliAODTagCreator *t = new AliAODTagCreator();
39     // t->SetStorage(0);
40     // t->ReadLocalCollection(dirData); 
41     
42     AliTagAnalysis *TagAna = new AliTagAnalysis("AOD"); 
43    
44     // Define tag cuts to select events containing at least one muon in the dimuon spectrometer
45     printf("Defining Tags cuts to select events containing at least one muon in the dimuon spectrometer\n");
46     AliRunTagCuts *runCuts = new AliRunTagCuts();
47     AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
48     AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
49     AliEventTagCuts *evCuts = new AliEventTagCuts();
50     evCuts->SetNFWMuonRange(1,10);
51    
52     // Create the chain of interesting events
53     TChain* chain = 0x0;
54     TagAna->ChainLocalTags(dirChain);
55     TagAna->SetType("AOD");
56     chain = TagAna->QueryTags(runCuts,lhcCuts,detCuts,evCuts);
57     Info("AnalysisTrainFromStandardToMuonAOD",Form("CHAIN HAS %d ENTRIES",(Int_t)chain->GetEntries()));
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 replicated 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->GetCommonInputContainer();
92     AliAnalysisDataContainer *coutput1 = mgr->GetCommonOutputContainer();
93                                                                
94     mgr->ConnectInput(aodfilter,0,cinput1);
95     mgr->ConnectOutput(aodfilter,0,coutput1);
96  
97     // Run the analysis    
98     printf("CHAIN HAS %d ENTRIES\n",(Int_t)chain->GetEntries());
99     mgr->InitAnalysis();
100     mgr->PrintStatus();
101     mgr->StartAnalysis("local",chain,nev);
102 }
103
104
105 Int_t setupPar(const char* pararchivename) {
106   ///////////////////
107   // Setup PAR File//
108   ///////////////////
109   if (pararchivename) {
110     char processline[1024];
111     sprintf(processline,".! tar xvzf %s.par",pararchivename);
112     gROOT->ProcessLine(processline);
113     const char* ocwd = gSystem->WorkingDirectory();
114     gSystem->ChangeDirectory(pararchivename);
115
116     // check for BUILD.sh and execute
117     if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
118       printf("*******************************\n");
119       printf("*** Building PAR archive    ***\n");
120       printf("*******************************\n");
121
122       if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
123         Error("runAnalysis","Cannot Build the PAR Archive! - Abort!");
124         return -1;
125       }
126     }
127     // check for SETUP.C and execute
128     if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
129       printf("*******************************\n");
130       printf("*** Setup PAR archive       ***\n");
131       printf("*******************************\n");
132       gROOT->Macro("PROOF-INF/SETUP.C");
133     }
134
135     gSystem->ChangeDirectory("../");
136   }
137
138   return 1;
139 }
140
141 //______________________________________________________________________________
142 void SetupPar(char* pararchivename)
143 {
144     if (pararchivename) {
145         char processline[1024];
146         sprintf(processline,".! tar xvzf %s.par",pararchivename);
147         gROOT->ProcessLine(processline);
148         TString ocwd = gSystem->WorkingDirectory();
149         gSystem->ChangeDirectory(pararchivename);
150         
151         // check for BUILD.sh and execute
152         if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
153             printf("*******************************\n");
154             printf("*** Building PAR archive    ***\n");
155             printf("*******************************\n");
156             
157             if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
158                 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
159                 return -1;
160             }
161         }
162         // check for SETUP.C and execute
163         if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
164             printf("*******************************\n");
165             printf("*** Setup PAR archive       ***\n");
166             printf("*******************************\n");
167             gROOT->Macro("PROOF-INF/SETUP.C");
168         }
169         
170         gSystem->ChangeDirectory(ocwd.Data());
171    printf("Current dir: %s\n", ocwd.Data());
172     } 
173 }