]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/MakeFlow.C
adding planes
[u/mrichter/AliRoot.git] / PWG2 / 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 pwg2_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 pwg2_forward_flow
25  */
26 void MakeFlow(TString data      = "", 
27               Int_t   nevents   = 0, 
28               TString type      = "", 
29               Int_t   etabins   = 40,
30               Int_t   zVertex   = 2,
31               TString addFlow   = "",
32               Int_t   addFType  = 0,
33               Int_t   addFOrder = 0,
34               Bool_t  proof     = false)
35 {
36   Bool_t proof = kFALSE;
37
38   // --- Load libs ---------------------------------------------------
39   gROOT->Macro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadLibs.C");
40
41   // --- Check for proof mode, and possibly upload pars --------------
42   if (proof> 0) { 
43     gROOT->LoadMacro("$ALICE_ROOT/PWG2/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)/PWG2/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   // --- Create output handler ---------------------------------------
83   AliAODHandler* aodOut = new AliAODHandler();
84   mgr->SetOutputEventHandler(aodOut);
85   aodOut->SetOutputFileName("AliAODs.Flow.root");
86
87   // --- Add the tasks ---------------------------------------------
88   gROOT->LoadMacro("AddTaskForwardFlow.C");
89   AddTaskForwardFlow(type, etabins, zVertex, addFlow, addFType, addFOrder);
90
91   // --- Run the analysis --------------------------------------------
92   TStopwatch t;
93   if (!mgr->InitAnalysis()) {
94     Error("MakeFlow", "Failed to initialize analysis train!");
95     return;
96   }
97   mgr->PrintStatus();
98   // 
99   if (proof) mgr->SetDebugLevel(3);
100   if (mgr->GetDebugLevel() < 1 && !proof) 
101     mgr->SetUseProgressBar(kTRUE,nEvents < 10000 ? 10 : 100);
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   while(in.good()) 
121   {
122     in >> line;
123       
124     if (line.Length() == 0)
125       continue;      
126     
127     if (TFile::Open(line))
128       chain->Add(line);
129   }
130
131   in.close();
132
133   return;
134 }
135 //
136 // EOF
137 //