ROOT logo
TChain* loadChain(const char* inpData, const char* chName="esdTree");
const TObjArray* GetTrackingConditions(const char* recopar="ITS/Calib/RecoParam/Run0_999999999_v0_s0.root");

void runanLoc(const char* inpData="AliESDs.root", const char* outFile="tstPerfAn.root")
{
  // runs analysis task on local data
  //
  gROOT->ProcessLine(".x LoadLibs.C(1)");
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) mgr = new AliAnalysisManager("Test reco analysis");
  AliAnalysisDataContainer *cinp = (AliAnalysisDataContainer*)mgr->GetCommonInputContainer();
  //
  AliESDInputHandler *esdInputHandler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
  if (!esdInputHandler) esdInputHandler = new AliESDInputHandlerRP();
  mgr->SetInputEventHandler(esdInputHandler);
  //
  AliMCEventHandler* mcInputHandler = dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
  if (!mcInputHandler) mcInputHandler = new AliMCEventHandler();
  mgr->SetMCtruthEventHandler(mcInputHandler);
  mcInputHandler->SetPreReadMode(AliMCEventHandler::kLmPreRead);
  //
  gROOT->ProcessLine(".L AliTaskITSUPerf.cxx++");
  AliTaskITSUPerf* task = new AliTaskITSUPerf("tstAnalysis");
  TString outFString = outFile;
  if (outFString.IsNull()) outFString = "recAnOut.root";
  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("clist", TList::Class(),AliAnalysisManager::kOutputContainer,outFString.Data());
  mgr->AddTask(task);
  mgr->ConnectInput(task, 0,  mgr->GetCommonInputContainer());
  mgr->ConnectOutput(task,1,coutput1);
  task->SetUseMC(1);  // at the moment not irrelevant
  //
  // configure task
  task->SetEtaMin(-3);
  task->SetEtaMax(3);
  task->SetNPtBins(10);
  task->SetNResBins(200);
  task->SetPtMax(10);
  //
  // optionally set reconstructability condition
  task->SetTrackingConditions(GetTrackingConditions());
  //
  TChain *chain = loadChain(inpData);
  if (!chain) return;
  mgr->InitAnalysis();
  mgr->StartAnalysis("local",chain);
  //
}

const TObjArray* GetTrackingConditions(const char* recopar)
{
  // load tracking conditions used in reco
  TString rpfstr = recopar;
  Bool_t fail = kFALSE;
  const TObjArray* trCondArr = 0;
  while(1) {
    TFile* rpf = 0;
    if (rpfstr.IsNull() || !(rpf=TFile::Open(rpfstr.Data()))) {fail = kTRUE; break;}
    AliCDBEntry* cdbe = (AliCDBEntry*)rpf->Get("AliCDBEntry");
    if (!cdbe) {fail = kTRUE; break;}
    TObjArray* recoParArr = (TObjArray*)cdbe->GetObject();
    if (!recoParArr) {fail = kTRUE; break;}
    AliITSURecoParam* recoPar = (AliITSURecoParam*) recoParArr->At(1);
    if (!recoPar) {fail = kTRUE; break;}
    trCondArr = recoPar->GetTrackingConditions();
    if (!trCondArr) {fail = kTRUE; break;}
    break;
  }
  if (fail) {printf("Tracking conditions must be extracted from valid recoparams, path is %s\n",recopar); exit(1);}
  //
  return trCondArr;
}

//________________________________________________________________________________
TChain* loadChain(const char* inpData, const char* chName)
{
  TChain* chain = new TChain(chName);
  //
  TString inpDtStr = inpData;
  if (inpDtStr.EndsWith(".root")) {
    if (!inpDtStr.Contains("/")) inpDtStr = Form("%s/%s",gSystem->pwd(),inpDtStr.Data());
    printf("Setting %s as an input\n",inpDtStr.Data());
    chain->AddFile(inpDtStr.Data());
    if (!gGrid && inpDtStr.Contains("alien")) TGrid::Connect("alien://");
  }
  else {
    //
    ifstream inpf(inpData);
    if (!inpf.good()) {
      printf("Failed on input filename %s\n",inpData);
      return kFALSE;
    }
    //
    TString flName;
    flName.ReadLine(inpf);
    while ( !flName.IsNull() ) {
      flName = flName.Strip(TString::kBoth,' ');
      if (flName.BeginsWith("//") || flName.BeginsWith("#")) {flName.ReadLine(inpf); continue;}
      flName = flName.Strip(TString::kBoth,',');
      flName = flName.Strip(TString::kBoth,'"');
      if (!flName.Contains("/")) flName = Form("%s/%s",gSystem->pwd(),flName);
      printf("Adding %s\n",flName.Data());
      chain->AddFile(flName.Data());
      if (!gGrid && flName.Contains("alien")) TGrid::Connect("alien://");
      flName.ReadLine(inpf);
    }
  }
  //
  int n = chain->GetEntries();
  if (n<1) {
    printf("Obtained chain is empty\n");
    return 0;
  }
  else printf("Opened %s chain with %d entries\n",chName,n);
  return chain;
}
 runanLoc.C:1
 runanLoc.C:2
 runanLoc.C:3
 runanLoc.C:4
 runanLoc.C:5
 runanLoc.C:6
 runanLoc.C:7
 runanLoc.C:8
 runanLoc.C:9
 runanLoc.C:10
 runanLoc.C:11
 runanLoc.C:12
 runanLoc.C:13
 runanLoc.C:14
 runanLoc.C:15
 runanLoc.C:16
 runanLoc.C:17
 runanLoc.C:18
 runanLoc.C:19
 runanLoc.C:20
 runanLoc.C:21
 runanLoc.C:22
 runanLoc.C:23
 runanLoc.C:24
 runanLoc.C:25
 runanLoc.C:26
 runanLoc.C:27
 runanLoc.C:28
 runanLoc.C:29
 runanLoc.C:30
 runanLoc.C:31
 runanLoc.C:32
 runanLoc.C:33
 runanLoc.C:34
 runanLoc.C:35
 runanLoc.C:36
 runanLoc.C:37
 runanLoc.C:38
 runanLoc.C:39
 runanLoc.C:40
 runanLoc.C:41
 runanLoc.C:42
 runanLoc.C:43
 runanLoc.C:44
 runanLoc.C:45
 runanLoc.C:46
 runanLoc.C:47
 runanLoc.C:48
 runanLoc.C:49
 runanLoc.C:50
 runanLoc.C:51
 runanLoc.C:52
 runanLoc.C:53
 runanLoc.C:54
 runanLoc.C:55
 runanLoc.C:56
 runanLoc.C:57
 runanLoc.C:58
 runanLoc.C:59
 runanLoc.C:60
 runanLoc.C:61
 runanLoc.C:62
 runanLoc.C:63
 runanLoc.C:64
 runanLoc.C:65
 runanLoc.C:66
 runanLoc.C:67
 runanLoc.C:68
 runanLoc.C:69
 runanLoc.C:70
 runanLoc.C:71
 runanLoc.C:72
 runanLoc.C:73
 runanLoc.C:74
 runanLoc.C:75
 runanLoc.C:76
 runanLoc.C:77
 runanLoc.C:78
 runanLoc.C:79
 runanLoc.C:80
 runanLoc.C:81
 runanLoc.C:82
 runanLoc.C:83
 runanLoc.C:84
 runanLoc.C:85
 runanLoc.C:86
 runanLoc.C:87
 runanLoc.C:88
 runanLoc.C:89
 runanLoc.C:90
 runanLoc.C:91
 runanLoc.C:92
 runanLoc.C:93
 runanLoc.C:94
 runanLoc.C:95
 runanLoc.C:96
 runanLoc.C:97
 runanLoc.C:98
 runanLoc.C:99
 runanLoc.C:100
 runanLoc.C:101
 runanLoc.C:102
 runanLoc.C:103
 runanLoc.C:104
 runanLoc.C:105
 runanLoc.C:106
 runanLoc.C:107
 runanLoc.C:108
 runanLoc.C:109
 runanLoc.C:110
 runanLoc.C:111
 runanLoc.C:112
 runanLoc.C:113
 runanLoc.C:114
 runanLoc.C:115
 runanLoc.C:116