ROOT logo
//
// This is an example of steering macro for running RSN analysis task
// locally with a collection of files written in a text file
//
// Allowed inputs:
// - ESD + MC (MC is included automatically)
// - AOD
//
// All settings are specified as arguments in the main macro,
// which is at the end of this script.
//
void RunAnalysisPhi900GeV
(
  Int_t       nReadFiles   = 2,
  Int_t       nSkipFiles   = 0,
  const char *dataType     = "900GeV_pass4_sim",
  const char *inputSource  = "list.txt",
  const char *outName1     = "Phi900GeV_all.root",
  const char *outName2     = "Phi900GeV_true.root",
  const char *outName3     = "Phi900GeV_info.root"
)
{
  // convert the last argument into a BOOL variable
  Bool_t isMC = kTRUE;
  if (!strcmp(dataType, "900GeV_pass4_data")) isMC = kFALSE;
  if (!strcmp(dataType, "7TeV_pass1_data")) isMC = kFALSE;

  // message on aliroot version
  cout << "*** ALIROOT PATH = " << gSystem->Getenv("ALICE_ROOT") << " ***" << endl;
  cout << "*** MC " << (isMC ? "" : "NOT") << " INCLUDED ***" << endl;

  // check extension of input to distinguish between XML and TXT
  TString sInput(inputSource);
  sInput.ToLower();
  Bool_t isTXT = (!strcmp(sInput(sInput.Length() - 3, 3).Data(), "txt"));
  cout << "Input = " << (isTXT ? "TXT" : "XML") << endl;

  // load compiled libraries (for aliroot session)
  gSystem->Load("libANALYSIS.so");
  gSystem->Load("libANALYSISalice.so");
  gSystem->Load("libPWG2resonances.so");

  // if input is XML, connect to AliEn
  if (!isTXT) TGrid::Connect("alien://");

  // create analysis manager
  AliAnalysisManager *mgr = new AliAnalysisManager("MyTaskManager");

  // create handlers for input
  AliESDInputHandler *esdHandler = new AliESDInputHandler();
  mgr->SetInputEventHandler(esdHandler);
  // if required, create also MC handler
  if (isMC)
  {
    AliMCEventHandler *mcHandler  = new AliMCEventHandler();
    mgr->SetMCtruthEventHandler(mcHandler);
  }
  
  // add event selection for data
  gROOT->LoadMacro("AddTaskPhysicsSelection.C");
  AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(isMC);

  // add task macro
  AliRsnAnalysisPhi900GeV *task = new AliRsnAnalysisPhi900GeV("taskphi900gev");
  task->SelectCollisionCandidates();
  task->SetTPCparams(isMC);
  task->SetMaxChi2(4.0);
  task->SetMaxDCAr(0.5);
  task->SetMaxDCAz(3.0);
  task->SetMinNTPC(80);
  task->SetUseMC(kFALSE);
  if (!strcmp(dataType, "900GeV_pass4_data"))
  {
    task->SetTOFESD(kFALSE);
    task->SetTOFSigma(130.0);
    task->SetTOFSettings(AliTOFT0makerANA::kPass4);
  }
  if (!strcmp(dataType, "7TeV_pass1_data"))
  {
    task->SetTOFESD(kFALSE);
    task->SetTOFSigma(130.0);
    task->SetTOFSettings(AliTOFT0makerANA::kPass4);
  }
  else if (!strcmp(dataType, "900GeV_pass4_sim"))
  {
    task->SetTOFESD(kTRUE);
    task->SetTOFSigma(130.0);
    task->SetTOFSettings(AliTOFT0makerANA::kNone);
  }
  mgr->AddTask(task);
  
  // create containers for input/output
  AliAnalysisDataContainer *out1 = mgr->CreateContainer("tracks", TTree::Class(), AliAnalysisManager::kOutputContainer, outName1);
  AliAnalysisDataContainer *out2 = mgr->CreateContainer("rsn"   , TTree::Class(), AliAnalysisManager::kOutputContainer, outName2);
  AliAnalysisDataContainer *out3 = mgr->CreateContainer("info"  , TList::Class(), AliAnalysisManager::kOutputContainer, outName3);
  mgr->ConnectInput (task, 0, mgr->GetCommonInputContainer());
  mgr->ConnectOutput(task, 1, out1);
  mgr->ConnectOutput(task, 2, out2);
  mgr->ConnectOutput(task, 3, out3);

  // create TChain of input events
  TChain *analysisChain = 0x0;
  if (isTXT) analysisChain = CreateChainFromText(inputSource, "esdTree", nReadFiles, nSkipFiles);
  else       analysisChain = CreateChainFromXML (inputSource, "esdTree", nReadFiles, nSkipFiles);

  // start analysis
  if (!analysisChain)
  {
    Error("runLocal", "Analysis chain not properly initialized");
    return;
  }
  mgr->InitAnalysis();
  mgr->PrintStatus();
  if (isTXT) mgr->StartAnalysis("local", analysisChain);
  else       mgr->StartAnalysis("alien", analysisChain);
}

//_________________________________________________________________________________________________
TChain* CreateChainFromXML
(const char *xmlFileName, const char *treeName, Int_t nread, Int_t nskip)
{
//
// Create a TChain with all required files listed into an XML collection.
// Necessary to run analysis in AliEn jobs.
// ---
// Arguments:
//  - xmlFileName = input list
//  - treeName    = "esdTree" or "aodTree"
//  - nread       = how many files to read (0 = all)
//  - nskip       = how many files to skip from beginning
//

  // if nread argument is 0, it is disabled
  if (nread == 0) nread = 1000000000;

  // initialize output object
  TChain *chain = new TChain(treeName);

  // initialize the AliEn collection
  TAlienCollection *myCollection = TAlienCollection::Open(xmlFileName);
  if (!myCollection)
  {
    Error("CreateChainFromXML", "Cannot create an AliEn collection from %s", xmlFileName);
    return 0x0;
  }

  // loop on collection
  myCollection->Reset();
  while (myCollection->Next())
  {
    // skip until reached required number of offset
    if (nskip > 0) {--nskip; continue;}

    // stop if required number of read files is reached
    // otherwise update the counter
    if (nread <= 0) break;
    nread--;

    // recovery file and add it
    Info("CreateChainFromXML", Form("Adding: %s", myCollection->GetTURL("")));
    chain->Add(myCollection->GetTURL(""));
  }

  return chain;
}

//_________________________________________________________________________________________________
TChain* CreateChainFromText(const char *fileName, const char *treeName, Int_t nread, Int_t nskip)
{
//
// Create a TChain with all required files listed into a text file.
// Necessary to run analysis in local jobs.
// ---
// Arguments:
//  - xmlFileName = input file list
//  - treeName    = "esdTree" or "aodTree"
//  - nread       = how many files to read (0 = all)
//  - nskip       = how many files to skip from beginning
//

  // if third argument is 0, it is interpreted
  // as "read all lines"
  Bool_t readAll = (nread <= 0);
  
  // initialize output object
  TChain* target = new TChain(treeName);
  
  // open text file
  ifstream fileIn(fileName);
  
  // loop on collection
  TString line;
  while (fileIn.good())
  {
    fileIn >> line;
    if (line.IsNull()) continue;
    
    // skip until reached required number of offset
    if (nskip > 0) {--nskip; continue;}
    
    // stop if required number of read files is reached
    // otherwise update the counter
    if (!readAll && nread <= 0) break;
    nread--;
    
    // add file
    Info("CreateChainFromText", "Adding '%s'", line.Data());
    target->Add(line.Data());
  }
  
  return target;
}
 RunAnalysisPhi900GeV.C:1
 RunAnalysisPhi900GeV.C:2
 RunAnalysisPhi900GeV.C:3
 RunAnalysisPhi900GeV.C:4
 RunAnalysisPhi900GeV.C:5
 RunAnalysisPhi900GeV.C:6
 RunAnalysisPhi900GeV.C:7
 RunAnalysisPhi900GeV.C:8
 RunAnalysisPhi900GeV.C:9
 RunAnalysisPhi900GeV.C:10
 RunAnalysisPhi900GeV.C:11
 RunAnalysisPhi900GeV.C:12
 RunAnalysisPhi900GeV.C:13
 RunAnalysisPhi900GeV.C:14
 RunAnalysisPhi900GeV.C:15
 RunAnalysisPhi900GeV.C:16
 RunAnalysisPhi900GeV.C:17
 RunAnalysisPhi900GeV.C:18
 RunAnalysisPhi900GeV.C:19
 RunAnalysisPhi900GeV.C:20
 RunAnalysisPhi900GeV.C:21
 RunAnalysisPhi900GeV.C:22
 RunAnalysisPhi900GeV.C:23
 RunAnalysisPhi900GeV.C:24
 RunAnalysisPhi900GeV.C:25
 RunAnalysisPhi900GeV.C:26
 RunAnalysisPhi900GeV.C:27
 RunAnalysisPhi900GeV.C:28
 RunAnalysisPhi900GeV.C:29
 RunAnalysisPhi900GeV.C:30
 RunAnalysisPhi900GeV.C:31
 RunAnalysisPhi900GeV.C:32
 RunAnalysisPhi900GeV.C:33
 RunAnalysisPhi900GeV.C:34
 RunAnalysisPhi900GeV.C:35
 RunAnalysisPhi900GeV.C:36
 RunAnalysisPhi900GeV.C:37
 RunAnalysisPhi900GeV.C:38
 RunAnalysisPhi900GeV.C:39
 RunAnalysisPhi900GeV.C:40
 RunAnalysisPhi900GeV.C:41
 RunAnalysisPhi900GeV.C:42
 RunAnalysisPhi900GeV.C:43
 RunAnalysisPhi900GeV.C:44
 RunAnalysisPhi900GeV.C:45
 RunAnalysisPhi900GeV.C:46
 RunAnalysisPhi900GeV.C:47
 RunAnalysisPhi900GeV.C:48
 RunAnalysisPhi900GeV.C:49
 RunAnalysisPhi900GeV.C:50
 RunAnalysisPhi900GeV.C:51
 RunAnalysisPhi900GeV.C:52
 RunAnalysisPhi900GeV.C:53
 RunAnalysisPhi900GeV.C:54
 RunAnalysisPhi900GeV.C:55
 RunAnalysisPhi900GeV.C:56
 RunAnalysisPhi900GeV.C:57
 RunAnalysisPhi900GeV.C:58
 RunAnalysisPhi900GeV.C:59
 RunAnalysisPhi900GeV.C:60
 RunAnalysisPhi900GeV.C:61
 RunAnalysisPhi900GeV.C:62
 RunAnalysisPhi900GeV.C:63
 RunAnalysisPhi900GeV.C:64
 RunAnalysisPhi900GeV.C:65
 RunAnalysisPhi900GeV.C:66
 RunAnalysisPhi900GeV.C:67
 RunAnalysisPhi900GeV.C:68
 RunAnalysisPhi900GeV.C:69
 RunAnalysisPhi900GeV.C:70
 RunAnalysisPhi900GeV.C:71
 RunAnalysisPhi900GeV.C:72
 RunAnalysisPhi900GeV.C:73
 RunAnalysisPhi900GeV.C:74
 RunAnalysisPhi900GeV.C:75
 RunAnalysisPhi900GeV.C:76
 RunAnalysisPhi900GeV.C:77
 RunAnalysisPhi900GeV.C:78
 RunAnalysisPhi900GeV.C:79
 RunAnalysisPhi900GeV.C:80
 RunAnalysisPhi900GeV.C:81
 RunAnalysisPhi900GeV.C:82
 RunAnalysisPhi900GeV.C:83
 RunAnalysisPhi900GeV.C:84
 RunAnalysisPhi900GeV.C:85
 RunAnalysisPhi900GeV.C:86
 RunAnalysisPhi900GeV.C:87
 RunAnalysisPhi900GeV.C:88
 RunAnalysisPhi900GeV.C:89
 RunAnalysisPhi900GeV.C:90
 RunAnalysisPhi900GeV.C:91
 RunAnalysisPhi900GeV.C:92
 RunAnalysisPhi900GeV.C:93
 RunAnalysisPhi900GeV.C:94
 RunAnalysisPhi900GeV.C:95
 RunAnalysisPhi900GeV.C:96
 RunAnalysisPhi900GeV.C:97
 RunAnalysisPhi900GeV.C:98
 RunAnalysisPhi900GeV.C:99
 RunAnalysisPhi900GeV.C:100
 RunAnalysisPhi900GeV.C:101
 RunAnalysisPhi900GeV.C:102
 RunAnalysisPhi900GeV.C:103
 RunAnalysisPhi900GeV.C:104
 RunAnalysisPhi900GeV.C:105
 RunAnalysisPhi900GeV.C:106
 RunAnalysisPhi900GeV.C:107
 RunAnalysisPhi900GeV.C:108
 RunAnalysisPhi900GeV.C:109
 RunAnalysisPhi900GeV.C:110
 RunAnalysisPhi900GeV.C:111
 RunAnalysisPhi900GeV.C:112
 RunAnalysisPhi900GeV.C:113
 RunAnalysisPhi900GeV.C:114
 RunAnalysisPhi900GeV.C:115
 RunAnalysisPhi900GeV.C:116
 RunAnalysisPhi900GeV.C:117
 RunAnalysisPhi900GeV.C:118
 RunAnalysisPhi900GeV.C:119
 RunAnalysisPhi900GeV.C:120
 RunAnalysisPhi900GeV.C:121
 RunAnalysisPhi900GeV.C:122
 RunAnalysisPhi900GeV.C:123
 RunAnalysisPhi900GeV.C:124
 RunAnalysisPhi900GeV.C:125
 RunAnalysisPhi900GeV.C:126
 RunAnalysisPhi900GeV.C:127
 RunAnalysisPhi900GeV.C:128
 RunAnalysisPhi900GeV.C:129
 RunAnalysisPhi900GeV.C:130
 RunAnalysisPhi900GeV.C:131
 RunAnalysisPhi900GeV.C:132
 RunAnalysisPhi900GeV.C:133
 RunAnalysisPhi900GeV.C:134
 RunAnalysisPhi900GeV.C:135
 RunAnalysisPhi900GeV.C:136
 RunAnalysisPhi900GeV.C:137
 RunAnalysisPhi900GeV.C:138
 RunAnalysisPhi900GeV.C:139
 RunAnalysisPhi900GeV.C:140
 RunAnalysisPhi900GeV.C:141
 RunAnalysisPhi900GeV.C:142
 RunAnalysisPhi900GeV.C:143
 RunAnalysisPhi900GeV.C:144
 RunAnalysisPhi900GeV.C:145
 RunAnalysisPhi900GeV.C:146
 RunAnalysisPhi900GeV.C:147
 RunAnalysisPhi900GeV.C:148
 RunAnalysisPhi900GeV.C:149
 RunAnalysisPhi900GeV.C:150
 RunAnalysisPhi900GeV.C:151
 RunAnalysisPhi900GeV.C:152
 RunAnalysisPhi900GeV.C:153
 RunAnalysisPhi900GeV.C:154
 RunAnalysisPhi900GeV.C:155
 RunAnalysisPhi900GeV.C:156
 RunAnalysisPhi900GeV.C:157
 RunAnalysisPhi900GeV.C:158
 RunAnalysisPhi900GeV.C:159
 RunAnalysisPhi900GeV.C:160
 RunAnalysisPhi900GeV.C:161
 RunAnalysisPhi900GeV.C:162
 RunAnalysisPhi900GeV.C:163
 RunAnalysisPhi900GeV.C:164
 RunAnalysisPhi900GeV.C:165
 RunAnalysisPhi900GeV.C:166
 RunAnalysisPhi900GeV.C:167
 RunAnalysisPhi900GeV.C:168
 RunAnalysisPhi900GeV.C:169
 RunAnalysisPhi900GeV.C:170
 RunAnalysisPhi900GeV.C:171
 RunAnalysisPhi900GeV.C:172
 RunAnalysisPhi900GeV.C:173
 RunAnalysisPhi900GeV.C:174
 RunAnalysisPhi900GeV.C:175
 RunAnalysisPhi900GeV.C:176
 RunAnalysisPhi900GeV.C:177
 RunAnalysisPhi900GeV.C:178
 RunAnalysisPhi900GeV.C:179
 RunAnalysisPhi900GeV.C:180
 RunAnalysisPhi900GeV.C:181
 RunAnalysisPhi900GeV.C:182
 RunAnalysisPhi900GeV.C:183
 RunAnalysisPhi900GeV.C:184
 RunAnalysisPhi900GeV.C:185
 RunAnalysisPhi900GeV.C:186
 RunAnalysisPhi900GeV.C:187
 RunAnalysisPhi900GeV.C:188
 RunAnalysisPhi900GeV.C:189
 RunAnalysisPhi900GeV.C:190
 RunAnalysisPhi900GeV.C:191
 RunAnalysisPhi900GeV.C:192
 RunAnalysisPhi900GeV.C:193
 RunAnalysisPhi900GeV.C:194
 RunAnalysisPhi900GeV.C:195
 RunAnalysisPhi900GeV.C:196
 RunAnalysisPhi900GeV.C:197
 RunAnalysisPhi900GeV.C:198
 RunAnalysisPhi900GeV.C:199
 RunAnalysisPhi900GeV.C:200
 RunAnalysisPhi900GeV.C:201
 RunAnalysisPhi900GeV.C:202
 RunAnalysisPhi900GeV.C:203
 RunAnalysisPhi900GeV.C:204
 RunAnalysisPhi900GeV.C:205
 RunAnalysisPhi900GeV.C:206
 RunAnalysisPhi900GeV.C:207
 RunAnalysisPhi900GeV.C:208
 RunAnalysisPhi900GeV.C:209
 RunAnalysisPhi900GeV.C:210
 RunAnalysisPhi900GeV.C:211
 RunAnalysisPhi900GeV.C:212
 RunAnalysisPhi900GeV.C:213