2 // This is an example steering macro for running RSN analysis task
3 // locally with a collection of files specified in a text file:
6 // - nReadFiles = number of files to process from the list
7 // - nSkipFiles = how many lines to be skipped when reading the list
8 // - addTaskName = name of the macro to add the RSN analysis task
9 // (assumed to have inside it a function named like the file)
10 // - inputSource = name of the file containing all the inputs
11 // ---> to run on a local collection, the collection file
12 // must contain on each line the full path
13 // of one input file and it must have the ".txt" extension
14 // ---> to run on an AliEn collection, the collection file must be an XML
15 // file collection like those built from the "find -x" method in aliensh.
16 // - options = a label which is used to know what kind of data are being read
17 // (it is propagated to the 'addTask' macro for eventual setting up of something
18 // - outName = name for the file with RSN package outputs (without ROOT extension)
21 // - in case the source is an ESD, and if inputs are a MC production
22 // the MC input handler is created by default
25 // In principle, the user should never modify this macro.
32 const char *inputSource = "pbpb_data.txt",
33 const char *runOptions = "esd_data_phys_cent",
34 const char *analysisOptions = "tpcpid_tofpid_mult",
35 const char *outName = "test.root",
36 const char *taskList = "AddRsnAnalysisTask.C",
37 //const char *taskPath = "$(ALICE_ROOT)/PWG2/RESONANCES/macros/train"
38 const char *taskPath = "$(HOME)/code/resonances/alice-rsn-package/PWG2resonances/RESONANCES/macros/test/pulvir"
42 // === PREPARATION ==============================================================================
45 // this option is not needed when using plugin
46 // gEnv->SetValue("XSec.GSI.DelegProxy","2");
53 TString opt(runOptions);
55 Bool_t useTender = opt.Contains("TENDER");
56 Bool_t isMC = opt.Contains("MC") || (!opt.Contains("DATA"));
57 Bool_t isESD = opt.Contains("ESD");
58 ::Info("runPlugin.C", "useTender = %d", useTender);
59 ::Info("runPlugin.C", "isMC = %d", isMC );
60 ::Info("runPlugin.C", "runOpts = %s", runOptions);
61 ::Info("runPlugin.C", "anaOpts = %s", analysisOptions);
63 // basic configurations
64 gROOT->LoadMacro(Form("%s/AnalysisSetup.C", taskPath));
65 AnalysisSetup(isMC, nmix, runOptions, outName, taskPath);
69 if (isESD) sprintf(treeName, "esdTree"); else sprintf(treeName, "aodTree");
72 // === BUILD INPUT LIST =========================================================================
75 // check extension of input to distinguish between XML and TXT
76 TString sInput(inputSource);
78 Bool_t isTXT = (!strcmp(sInput(sInput.Length() - 3, 3).Data(), "txt"));
79 cout << "Input = " << (isTXT ? "TXT" : "XML") << endl;
81 // if input is XML, connect to AliEn
82 if (!isTXT) TGrid::Connect("alien://");
84 // create TChain of input events
85 TChain *analysisChain = 0x0;
86 if (isTXT) analysisChain = CreateChainFromText(inputSource, treeName, nReadFiles, nSkipFiles);
87 else analysisChain = CreateChainFromXML (inputSource, treeName, nReadFiles, nSkipFiles);
89 Error("runLocal", "Analysis chain not properly initialized");
94 // === CONFIGURATION ============================================================================
97 //AliLog::SetGlobalDebugLevel(AliLog::kDebug + 3);
98 //AliLog::SetClassDebugLevel("AliRsnCutESD2010", AliLog::kDebug+3);
99 //AliLog::SetClassDebugLevel("AliRsnCutValue", AliLog::kDebug+3);
100 //AliLog::SetClassDebugLevel("AliRsnCutESDCutMultiplicity", AliLog::kDebug+3);
101 //AliLog::SetClassDebugLevel("AliRsnValue", AliLog::kDebug+3);
102 //AliLog::SetClassDebugLevel("AliRsnCutTrackQuality", AliLog::kDebug+3);
103 //AliLog::SetGlobalDebugLevel(AliLog::kDebug+3);
106 // === ANALYSIS TASK CREATION AND INCLUSION =====================================================
109 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
112 gROOT->LoadMacro(Form("%s/AddRsnAnalysisTask.C", taskPath));
113 AddRsnAnalysisTask(isMC, (nmix > 0), runOptions, analysisOptions);
115 // initialize and start analysis
116 if (!mgr->InitAnalysis()) {
117 ::Error("runPlugin.C", "Failed to init analysis");
121 if (isTXT) mgr->StartAnalysis("local", analysisChain);
122 else mgr->StartAnalysis("alien", analysisChain);
125 // gObjectTable->Print();
130 //_________________________________________________________________________________________________
131 TChain* CreateChainFromXML
132 (const char *xmlFileName, const char *treeName, Int_t nread, Int_t nskip)
135 // Create a TChain with all required files listed into an XML collection.
136 // Necessary to run analysis in AliEn jobs.
139 // - xmlFileName = input list
140 // - treeName = "esdTree" or "aodTree"
141 // - nread = how many files to read (0 = all)
142 // - nskip = how many files to skip from beginning
145 // if nread argument is 0, it is disabled
146 if (nread == 0) nread = 1000000000;
148 // initialize output object
149 TChain *chain = new TChain(treeName);
151 // initialize the AliEn collection
152 TAlienCollection *myCollection = TAlienCollection::Open(xmlFileName);
154 Error("CreateChainFromXML", "Cannot create an AliEn collection from %s", xmlFileName);
158 // loop on collection
159 myCollection->Reset();
160 while (myCollection->Next()) {
161 // skip until reached required number of offset
162 if (nskip > 0) {--nskip; continue;}
164 // stop if required number of read files is reached
165 // otherwise update the counter
166 if (nread <= 0) break;
169 // recovery file and add it
170 Info("CreateChainFromXML", Form("Adding: %s", myCollection->GetTURL("")));
171 chain->Add(myCollection->GetTURL(""));
177 //_________________________________________________________________________________________________
178 TChain* CreateChainFromText(const char *fileName, const char *treeName, Int_t nread, Int_t nskip)
181 // Create a TChain with all required files listed into a text file.
182 // Necessary to run analysis in local jobs.
185 // - xmlFileName = input file list
186 // - treeName = "esdTree" or "aodTree"
187 // - nread = how many files to read (0 = all)
188 // - nskip = how many files to skip from beginning
191 // if third argument is 0, it is interpreted
192 // as "read all lines"
193 Bool_t readAll = (nread <= 0);
195 // initialize output object
196 TChain* target = new TChain(treeName);
199 ifstream fileIn(fileName);
201 // loop on collection
203 while (fileIn.good()) {
205 if (line.IsNull()) continue;
207 // skip until reached required number of offset
208 if (nskip > 0) {--nskip; continue;}
210 // stop if required number of read files is reached
211 // otherwise update the counter
212 if (!readAll && nread <= 0) break;
216 Info("CreateChainFromText", "Adding '%s'", line.Data());
217 target->Add(line.Data());