]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/MakeFlow.C
f0757fc54ec780fadc9c4056525e13d558da47f1
[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 {
35   Bool_t proof = kFALSE;
36
37   // --- Load libs ---------------------------------------------------
38   gROOT->Macro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadLibs.C");
39
40   // --- Check for proof mode, and possibly upload pars --------------
41   if (proof> 0) { 
42     gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/scripts/LoadPars.C");
43     if (!LoadPars(proof)) { 
44       AliError("MakeFlow", "Failed to load PARs");
45       return;
46     }
47   }
48
49   // --- Add to chain either AOD ------------------------------------
50   if (data.Length() <= 1) {
51     AliError("You didn't add a data file");
52     return;
53   }
54   TChain* chain = new TChain("aodTree");
55
56   if (data.Contains(".txt"))
57     MakeChain(data, chain);
58
59   if (data.Contains(".root")) {
60     if (!TFile::Open(data.Data())) {
61       AliError(Form("AOD file %s not found", data.Data()));
62       return;
63     }
64     chain->Add(data.Data());
65   }
66
67   // --- Initiate the event handlers --------------------------------
68   AliAnalysisManager *mgr  = new AliAnalysisManager("Forward Flow", 
69                                                     "Flow in the forward region");
70   mgr->SetUseProgressBar(kTRUE, 10);
71
72   // --- AOD input handler -------------------------------------------
73   AliAODInputHandler *aodInputHandler = new AliAODInputHandler();
74   mgr->SetInputEventHandler(aodInputHandler);      
75
76   // --- Create output handler ---------------------------------------
77   AliAODHandler* aodOut = new AliAODHandler();
78   mgr->SetOutputEventHandler(aodOut);
79   aodOut->SetOutputFileName("AliAODs.Flow.root");
80
81   // --- Add the tasks ---------------------------------------------
82   gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis2/AddTaskForwardFlow.C");
83   AddTaskForwardFlow(type, etabins, zVertex, addFlow, addFType, addFOrder);
84
85   // --- Run the analysis --------------------------------------------
86   TStopwatch t;
87   if (!mgr->InitAnalysis()) {
88     Error("MakeFlow", "Failed to initialize analysis train!");
89     return;
90   }
91   mgr->PrintStatus();
92
93   t.Start();
94   if (nevents == 0) mgr->StartAnalysis("local", chain);
95   if (nevents != 0) mgr->StartAnalysis("local", chain, nevents);
96   t.Stop();
97   t.Print();
98 }
99 //----------------------------------------------------------------
100 void MakeChain(TString data = "", TChain* chain = 0)
101 {
102   // creates chain of files in a given directory or file containing a list.
103   
104   // Open the input stream
105   ifstream in;
106   in.open(data.Data());
107
108   // Read the input list of files and add them to the chain
109   TString line;
110   while(in.good()) 
111   {
112     in >> line;
113       
114     if (line.Length() == 0)
115       continue;      
116     
117     if (TFile::Open(line))
118       chain->Add(line);
119   }
120
121   in.close();
122
123   return;
124 }
125 //
126 // EOF
127 //