]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/MakeFlow.C
Fixed references from PWG2 -> PWGLF - very efficiently done using ETags.
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / MakeFlow.C
1 /**
2  * @file   MakeFlow.C
3  * @author Alexander Hansen 
4  * @date   Wed Mar 23 12:11:33 2011
5  * 
6  * @brief  
7  * 
8  * @ingroup pwglf_forward_scripts_makers
9  * 
10  */
11 /**
12  * Script to analyse AOD input for flow
13  * 
14  * Takes either a single (AOD) .root file as input or a .txt
15  * The .txt file is expected to contain the path to the files 
16  * from the current directory or the absolute path.
17  * 
18  * @par Inputs: 
19  *  
20  * 
21  * @par Outputs: 
22  * - 
23  *
24  * @ingroup pwglf_forward_flow
25  */
26 void MakeFlow(TString data      = "", 
27               Int_t   nevents   = 0, 
28               TString type      = "", 
29               Int_t   etabins   = 48,
30               Bool_t  mc        = kFALSE,
31               TString addFlow   = "",
32               Int_t   addFType  = 0,
33               Int_t   addFOrder = 0,
34               Bool_t  proof     = kFALSE)
35 {
36   Bool_t proof = kFALSE;
37
38   // --- Load libs ---------------------------------------------------
39   gROOT->Macro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C");
40
41   // --- Check for proof mode, and possibly upload pars --------------
42   if (proof> 0) { 
43     gROOT->LoadMacro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/LoadPars.C");
44     if (!LoadPars(proof)) { 
45       AliError("MakeFlow", "Failed to load PARs");
46       return;
47     }
48   }
49
50   // --- Set the macro path ------------------------------------------
51   gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWGLF/FORWARD/analysis2:"
52                            "$ALICE_ROOT/ANALYSIS/macros",
53                            gROOT->GetMacroPath()));
54
55   // --- Add to chain either AOD ------------------------------------
56   if (data.IsNull()) {
57     AliError("You didn't add a data file");
58     return;
59   }
60   TChain* chain = new TChain("aodTree");
61
62   if (data.Contains(".txt")) MakeChain(data, chain);
63
64   if (data.Contains(".root")) {
65     TFile* test = TFile::Open(data.Data());
66     if (!test) {
67       AliError(Form("AOD file %s not found", data.Data()));
68       return;
69     }
70     test->Close(); // Remember to close!
71     chain->Add(data.Data());
72   }
73
74   // --- Initiate the event handlers --------------------------------
75   AliAnalysisManager *mgr  = new AliAnalysisManager("Forward Flow", 
76                                                     "Flow in the forward region");
77
78   // --- AOD input handler -------------------------------------------
79   AliAODInputHandler *aodInputHandler = new AliAODInputHandler();
80   mgr->SetInputEventHandler(aodInputHandler); 
81
82   // --- Add the tasks ---------------------------------------------
83   gROOT->LoadMacro("AddTaskForwardFlow.C");
84   AddTaskForwardFlow(type, etabins, mc, addFlow, addFType, addFOrder);
85
86   // --- Run the analysis --------------------------------------------
87   TStopwatch t;
88   if (!mgr->InitAnalysis()) {
89     Error("MakeFlow", "Failed to initialize analysis train!");
90     return;
91   }
92   mgr->PrintStatus();
93   Printf("****************************************");
94   Printf("Doing flow analysis on %d Events", nevents == 0 ? chain->GetEntries() : nevents);
95   Printf("****************************************");
96   // 
97   if (proof) mgr->SetDebugLevel(3);
98   if (mgr->GetDebugLevel() < 1 && !proof) 
99     mgr->SetUseProgressBar(kTRUE,chain->GetEntries() < 10000 ? 100 : 1000);
100
101 //  mgr->SetSkipTerminate(true);
102
103   t.Start();
104   if (nevents == 0) mgr->StartAnalysis("local", chain);
105   if (nevents != 0) mgr->StartAnalysis("local", chain, nevents);
106   t.Stop();
107   t.Print();
108 }
109 //----------------------------------------------------------------
110 void MakeChain(TString data = "", TChain* chain = 0)
111 {
112   // creates chain of files in a given directory or file containing a list.
113   
114   // Open the input stream
115   ifstream in;
116   in.open(data.Data());
117
118   // Read the input list of files and add them to the chain
119   TString line;
120   TFile* file;
121   while(in.good()) 
122   {
123     in >> line;
124       
125     if (line.Length() == 0)
126       continue;      
127     if (!(file = TFile::Open(line))) 
128       gROOT->ProcessLine(Form(".!rm %s", line.Data()));
129     else {
130       chain->Add(line);
131       file->Close();
132     }
133   }
134
135   in.close();
136
137   return;
138 }
139 //
140 // EOF
141 //