ROOT logo
// The following macro runs the HLT ITS tracker over the HLT
// tracks stored in the ESD and stores the output tracks in a
// separate ESD file AliESDits.root

#if !defined(__CINT__) || defined(__MAKECINT__)
  #include <TMath.h>
  #include <TError.h>
  #include <Riostream.h>
  #include <TH1F.h>
  #include <TH2F.h>
  #include <TNtuple.h>
  #include <TProfile2D.h>
  #include <TF1.h>
  #include <TGraphErrors.h>
  #include <TTree.h>
  #include <TParticle.h>
  #include <TCanvas.h>
  #include <TFile.h>
  #include <TROOT.h>
  #include <TStopwatch.h>
  #include <TSystem.h>

  #include "AliStack.h"
  #include "AliHeader.h"
  #include "AliTrackReference.h"
  #include "AliRunLoader.h"
  #include "AliITS.h"
  #include "AliITSLoader.h"
  #include "AliITSgeom.h"
  #include "AliITStrackerV2.h"
  #include "AliRun.h"
  #include "AliESD.h"
  #include "AliGenEventHeader.h"

  #include "AliHLTITStrack.h"
  #include "AliHLTITStracker.h"
  #include "AliHLTITSVertexerZ.h"
#endif

//extern TSystem *gSystem;

Int_t RunHLTITS(Int_t nev=1,Int_t run=0) {

  //  gSystem->Load("libAliHLTITS.so");

  TStopwatch timer;
  timer.Start();

   if (gAlice) {
      delete gAlice->GetRunLoader();
      delete gAlice; 
      gAlice=0;
   }

   AliRunLoader *rl = AliRunLoader::Open("galice.root");
   if (rl == 0x0) {
      cerr<<"Can not open session"<<endl;
      return 1;
   }
   Int_t retval = rl->LoadgAlice();
   if (retval) {
      cerr<<"AliESDtest.C : LoadgAlice returned error"<<endl;
      delete rl;
      return 1;
   }
   retval = rl->LoadHeader();
   if (retval) {
      cerr<<"AliESDtest.C : LoadHeader returned error"<<endl;
      delete rl;
      return 2;
   }
   gAlice=rl->GetAliRun();
       
   AliTracker::SetFieldMap(gAlice->Field());

   AliITSLoader* itsl = (AliITSLoader*)rl->GetLoader("ITSLoader");
   if (itsl == 0x0) {
      cerr<<"AliESDtest.C : Can not get the ITS loader"<<endl;
      return 3;
   }
   itsl->LoadRecPoints("read");

   AliITS *dITS = (AliITS*)gAlice->GetDetector("ITS");
   if (!dITS) {
      cerr<<"AliESDtest.C : Can not find the ITS detector !"<<endl;
      return 4;
   }
   //   AliITSgeom *geom = dITS->GetITSgeom();
   AliITSgeom *geom = new AliITSgeom();
   geom->ReadNewFile("$ALICE_ROOT/ITS/ITSgeometry_vPPRasymmFMD.det");

   //An instance of the HLT ITS tracker
   AliHLTITStracker itsTracker(geom);

   TFile *ef=TFile::Open("AliESDs.root");
   if (!ef || !ef->IsOpen()) {cerr<<"Can't AliESDs.root !\n"; return 1;}
   AliESD* event = new AliESD;
   TTree* tree = (TTree*) ef->Get("esdTree");
   if (!tree) {cerr<<"no ESD tree found\n"; return 1;};
   tree->SetBranchAddress("ESD", &event);

   TFile *itsf=TFile::Open("AliESDits.root","RECREATE");
   if ((!itsf)||(!itsf->IsOpen())) {
      cerr<<"Can't AliESDits.root !\n"; return 1;
   }

   Int_t rc=0;
   if (nev>rl->GetNumberOfEvents()) nev=rl->GetNumberOfEvents();
   //The loop over events
   for (Int_t i=0; i<nev; i++) {

     cerr<<"\n\nProcessing event number : "<<i<<endl;
     tree->GetEvent(i);
     rl->GetEvent(i);

     TArrayF v(3);     
     rl->GetHeader()->GenEventHeader()->PrimaryVertex(v);
     Double_t vtx[3]={v[0],v[1],v[2]};
     Double_t cvtx[3]={0.005,0.005,0.010};
     cout<<"MC vertex position: "<<v[2]<<endl;

     AliHLTITSVertexerZ vertexer("null");
     AliESDVertex* vertex = NULL;
     TStopwatch timer2;
     timer2.Start();
     TTree* treeClusters = itsl->TreeR();
     //     vertex = vertexer.FindVertexForCurrentEvent(i);
     //     AliESDVertex *vertex = vertexer.FindVertexForCurrentEvent(geom,treeClusters);
     vertex = new AliESDVertex(vtx,cvtx);
     timer2.Stop();
     timer2.Print();
     if(!vertex){
       cerr<<"Vertex not found"<<endl;
       vertex = new AliESDVertex(vtx,cvtx);
     }
     else {
       vertex->SetTruePos(vtx);  // store also the vertex from MC
     }

     event->SetVertex(vertex);

     Double_t vtxPos[3];
     Double_t vtxErr[3];
     vertex->GetXYZ(vtxPos);
     vertex->GetSigmaXYZ(vtxErr);
     itsTracker.SetVertex(vtxPos,vtxErr);

     TTree *itsTree=itsl->TreeR();
     if (!itsTree) {
       cerr<<"Can't get the ITS cluster tree !\n";
       return 4;
     }     
     itsTracker.LoadClusters(itsTree);
     rc+=itsTracker.Clusters2Tracks(event);
     //     rc+=itsTracker.PropagateBack(event);
     itsTracker.UnloadClusters();

     if (rc==0) {
       TTree* tree = new TTree("esdTree", "Tree with ESD objects");
       tree->Branch("ESD", "AliESD", &event);
       tree->Fill();
       itsf->cd();
       tree->Write();
     } 
     if (rc) {
       cerr<<"Something bad happened...\n";
     }

   }
   delete event;

   itsf->Close();
   ef->Close();

   //   delete rl;

   timer.Stop();
   timer.Print();

   return rc;
}
 RunHLTITS.C:1
 RunHLTITS.C:2
 RunHLTITS.C:3
 RunHLTITS.C:4
 RunHLTITS.C:5
 RunHLTITS.C:6
 RunHLTITS.C:7
 RunHLTITS.C:8
 RunHLTITS.C:9
 RunHLTITS.C:10
 RunHLTITS.C:11
 RunHLTITS.C:12
 RunHLTITS.C:13
 RunHLTITS.C:14
 RunHLTITS.C:15
 RunHLTITS.C:16
 RunHLTITS.C:17
 RunHLTITS.C:18
 RunHLTITS.C:19
 RunHLTITS.C:20
 RunHLTITS.C:21
 RunHLTITS.C:22
 RunHLTITS.C:23
 RunHLTITS.C:24
 RunHLTITS.C:25
 RunHLTITS.C:26
 RunHLTITS.C:27
 RunHLTITS.C:28
 RunHLTITS.C:29
 RunHLTITS.C:30
 RunHLTITS.C:31
 RunHLTITS.C:32
 RunHLTITS.C:33
 RunHLTITS.C:34
 RunHLTITS.C:35
 RunHLTITS.C:36
 RunHLTITS.C:37
 RunHLTITS.C:38
 RunHLTITS.C:39
 RunHLTITS.C:40
 RunHLTITS.C:41
 RunHLTITS.C:42
 RunHLTITS.C:43
 RunHLTITS.C:44
 RunHLTITS.C:45
 RunHLTITS.C:46
 RunHLTITS.C:47
 RunHLTITS.C:48
 RunHLTITS.C:49
 RunHLTITS.C:50
 RunHLTITS.C:51
 RunHLTITS.C:52
 RunHLTITS.C:53
 RunHLTITS.C:54
 RunHLTITS.C:55
 RunHLTITS.C:56
 RunHLTITS.C:57
 RunHLTITS.C:58
 RunHLTITS.C:59
 RunHLTITS.C:60
 RunHLTITS.C:61
 RunHLTITS.C:62
 RunHLTITS.C:63
 RunHLTITS.C:64
 RunHLTITS.C:65
 RunHLTITS.C:66
 RunHLTITS.C:67
 RunHLTITS.C:68
 RunHLTITS.C:69
 RunHLTITS.C:70
 RunHLTITS.C:71
 RunHLTITS.C:72
 RunHLTITS.C:73
 RunHLTITS.C:74
 RunHLTITS.C:75
 RunHLTITS.C:76
 RunHLTITS.C:77
 RunHLTITS.C:78
 RunHLTITS.C:79
 RunHLTITS.C:80
 RunHLTITS.C:81
 RunHLTITS.C:82
 RunHLTITS.C:83
 RunHLTITS.C:84
 RunHLTITS.C:85
 RunHLTITS.C:86
 RunHLTITS.C:87
 RunHLTITS.C:88
 RunHLTITS.C:89
 RunHLTITS.C:90
 RunHLTITS.C:91
 RunHLTITS.C:92
 RunHLTITS.C:93
 RunHLTITS.C:94
 RunHLTITS.C:95
 RunHLTITS.C:96
 RunHLTITS.C:97
 RunHLTITS.C:98
 RunHLTITS.C:99
 RunHLTITS.C:100
 RunHLTITS.C:101
 RunHLTITS.C:102
 RunHLTITS.C:103
 RunHLTITS.C:104
 RunHLTITS.C:105
 RunHLTITS.C:106
 RunHLTITS.C:107
 RunHLTITS.C:108
 RunHLTITS.C:109
 RunHLTITS.C:110
 RunHLTITS.C:111
 RunHLTITS.C:112
 RunHLTITS.C:113
 RunHLTITS.C:114
 RunHLTITS.C:115
 RunHLTITS.C:116
 RunHLTITS.C:117
 RunHLTITS.C:118
 RunHLTITS.C:119
 RunHLTITS.C:120
 RunHLTITS.C:121
 RunHLTITS.C:122
 RunHLTITS.C:123
 RunHLTITS.C:124
 RunHLTITS.C:125
 RunHLTITS.C:126
 RunHLTITS.C:127
 RunHLTITS.C:128
 RunHLTITS.C:129
 RunHLTITS.C:130
 RunHLTITS.C:131
 RunHLTITS.C:132
 RunHLTITS.C:133
 RunHLTITS.C:134
 RunHLTITS.C:135
 RunHLTITS.C:136
 RunHLTITS.C:137
 RunHLTITS.C:138
 RunHLTITS.C:139
 RunHLTITS.C:140
 RunHLTITS.C:141
 RunHLTITS.C:142
 RunHLTITS.C:143
 RunHLTITS.C:144
 RunHLTITS.C:145
 RunHLTITS.C:146
 RunHLTITS.C:147
 RunHLTITS.C:148
 RunHLTITS.C:149
 RunHLTITS.C:150
 RunHLTITS.C:151
 RunHLTITS.C:152
 RunHLTITS.C:153
 RunHLTITS.C:154
 RunHLTITS.C:155
 RunHLTITS.C:156
 RunHLTITS.C:157
 RunHLTITS.C:158
 RunHLTITS.C:159
 RunHLTITS.C:160
 RunHLTITS.C:161
 RunHLTITS.C:162
 RunHLTITS.C:163
 RunHLTITS.C:164
 RunHLTITS.C:165
 RunHLTITS.C:166
 RunHLTITS.C:167
 RunHLTITS.C:168
 RunHLTITS.C:169
 RunHLTITS.C:170
 RunHLTITS.C:171
 RunHLTITS.C:172
 RunHLTITS.C:173
 RunHLTITS.C:174
 RunHLTITS.C:175
 RunHLTITS.C:176
 RunHLTITS.C:177
 RunHLTITS.C:178
 RunHLTITS.C:179
 RunHLTITS.C:180
 RunHLTITS.C:181
 RunHLTITS.C:182