2 // Example macro to run a full resonance analysis task in a local machine
3 // using data taken from AliEn. This macro can be used as a template to create
4 // an AliEn job which runs this analysis on a collection of source data files (ESD/AOD/MC).
6 // This macro does the following:
7 // - loads all required PAR libraries
8 // - creates a TChain of events to be analyzed (from an XML collection)
9 // - creates the AnalysisTask macro which does the job
11 // Since it is possible that all required libraries/macroes are stored in different
12 // directories, for each one a variable must be initialized which gives the path,
13 // but, in order to allow to explode (if necessary) some environment variables,
14 // these variables are NOT arguments, but they are hard-coded in the macro at its
15 // beginning, to allow a user to customize them.
18 // - name of XM collection for source files
19 // - a flag to know it source data is ESD or AOD
20 // - maximum number of files to be analyzed
21 // - the number of files to be skipped starting from first one in collection.
23 Bool_t AliRsnTaskAlien
25 const char *collectionFile = "wn.xml",
26 Bool_t useESDsource = kTRUE,
31 // path for the "AliRsnLoad.C" macro which loads all libraries
32 TString strLoadPath(Form("%s/PWG2/RESONANCES/macros", getenv("ALICE_ROOT")));
33 strLoadPath.Append("/AliRsnLoad.C");
35 // path for the "CreateAnalysisManager.C" macro which creates the AnalysisManager
36 TString strTaskPath(Form("%s/PWG2/RESONANCES/macros", getenv("ALICE_ROOT")));
37 strTaskPath.Append("/CreateAnalysisManager.C");
40 TGrid::Connect("alien://");
42 // load the macro for uploading packages;
43 // the unique assumption which must be done here is that the PAR libraries
44 // are in the working directory, which is the case in all kinds of analysis
45 gROOT->LoadMacro(strLoadPath.Data());
48 // create the TChain of files to read
49 // its name depends on the kind of source to be read
52 sprintf(treeName, "esdTree");
53 Info("AliRsnSimpleTaskAlien", "Using ESD source data");
56 sprintf(treeName, "aodTree");
57 Info("AliRsnSimpleTaskAlien", "Using AOD source data");
59 TChain* analysisChain = new TChain(treeName);
60 TAlienCollection *myCollection = TAlienCollection::Open(collectionFile);
62 Error("AliRsnSimpleTaskAlien", Form("Cannot create an AliEn collection from %s", collectionFile));
65 // add files to the TChain, keeping trace of their number with a counter
68 myCollection->Reset();
69 while (myCollection->Next()) {
74 sprintf(fileName, "%s", myCollection->GetTURL(""));
75 Info("AliRsnSimpleTaskAlien", Form("Adding file '%s'", fileName));
76 analysisChain->Add(fileName);
78 if (maxFiles > 0 && nfiles >= maxFiles) break;
80 Info("AliRsnSimpleTaskAlien", Form("# processed events = %d", (Int_t)analysisChain->GetEntries()));
82 // load and execute the macro which creates the AnalysisManager
83 // this macro is expected to define a function with the standard name
84 // *** "CreateAnalysisManager()" *** [without arguments],
85 // irrespectively of the filename of the macro itself,
86 // which returns an AliAnalysisManager object
87 gROOT->LoadMacro(strTaskPath.Data());
88 AliAnalysisManager *mgr = CreateAnalysisManager(kFALSE);
90 // initialize analysis and run it in "local" mode
91 if (mgr->InitAnalysis()) {
93 return mgr->StartAnalysis("local", analysisChain);