Tests and example macros working with ESD (Yu.Belikov)
[u/mrichter/AliRoot.git] / TPC / AliTPCFindTracks.C
CommitLineData
88cb7938 1/****************************************************************************
2 * Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch *
3 ****************************************************************************/
4
c630aafd 5#if !defined(__CINT__) || defined(__MAKECINT__)
88cb7938 6 #include <iostream.h>
7f6ddf58 7 #include "AliTPCParam.h"
b9de75e1 8 #include "AliTPCtracker.h"
c630aafd 9 #include "AliRun.h"
10 #include "AliMagF.h"
11 #include "AliRunLoader.h"
12 #include "AliTPCLoader.h"
a62f4fcc 13 #include "AliESD.h"
b9de75e1 14
15 #include "TFile.h"
16 #include "TStopwatch.h"
17#endif
18
c630aafd 19extern AliRun *gAlice;
20
21Int_t AliTPCFindTracks(Int_t nev=5) {
88cb7938 22
73042f01 23 cerr<<"Looking for tracks...\n";
24
c630aafd 25 if (gAlice) {
88cb7938 26 delete gAlice->GetRunLoader();
27 delete gAlice;
28 gAlice = 0x0;
c630aafd 29 }
30
31 AliRunLoader *rl = AliRunLoader::Open("galice.root");
32 if (rl == 0x0) {
88cb7938 33 cerr<<"Can not open session"<<endl;
34 return 1;
c630aafd 35 }
36
37 AliTPCLoader *tpcl = (AliTPCLoader*)rl->GetLoader("TPCLoader");
38 if (tpcl == 0x0) {
88cb7938 39 cerr<<"Can not get TPC Loader"<<endl;
40 return 1;
c630aafd 41 }
88cb7938 42
c630aafd 43 if (rl->LoadgAlice()) {
44 cerr<<"Error occured while loading gAlice"<<endl;
88cb7938 45 return 1;
c630aafd 46 }
a62f4fcc 47
c630aafd 48 AliKalmanTrack::SetConvConst(
a62f4fcc 49 1000/0.299792458/rl->GetAliRun()->Field()->SolenoidField()
c630aafd 50 );
a62f4fcc 51
88cb7938 52 rl->CdGAFile();
53 AliTPCParam *dig=(AliTPCParam *)gDirectory->Get("75x40_100x60_150x60");
c630aafd 54 if (!dig) {
88cb7938 55 cerr<<"TPC parameters have not been found !\n";
56 return 1;
c630aafd 57 }
58
a62f4fcc 59 //rl->UnloadgAlice();
c630aafd 60
88cb7938 61 tpcl->LoadRecPoints("read");
73042f01 62
c630aafd 63 if (nev>rl->GetNumberOfEvents()) nev=rl->GetNumberOfEvents();
88cb7938 64
a62f4fcc 65 TFile *ef=TFile::Open("AliESDtpc.root","RECREATE");
66 if ((!ef)||(!ef->IsOpen())) {
67 cerr<<"Can't AliESDtpc.root !\n"; return 1;
68 }
73042f01 69 TStopwatch timer;
7f6ddf58 70 Int_t rc=0;
c630aafd 71 AliTPCtracker tracker(dig);
72 for (Int_t i=0;i<nev;i++){
afc42102 73 printf("Processing event %d\n",i);
a62f4fcc 74 AliESD *event=new AliESD();
c630aafd 75 rl->GetEvent(i);
76
77 TTree *in=tpcl->TreeR();
78 if (!in) {
79 cerr<<"Can't get clusters tree !\n";
80 return 4;
81 }
82
a62f4fcc 83 tracker.LoadClusters(in);
84 rc=tracker.Clusters2Tracks(event);
85 tracker.UnloadClusters();
86
87 if (rc==0) {
88 Char_t ename[100];
89 sprintf(ename,"%d",i);
90 ef->cd();
91 if (!event->Write(ename)) rc++;
92 }
93 if (rc) {
94 cerr<<"Something bad happened...\n";
c630aafd 95 }
a62f4fcc 96 delete event;
afc42102 97 }
c630aafd 98
73042f01 99 timer.Stop(); timer.Print();
b9de75e1 100
a62f4fcc 101 ef->Close();
102
88cb7938 103 delete dig; //Thanks to Mariana Bondila
c630aafd 104
88cb7938 105 delete rl;
c630aafd 106
7f6ddf58 107 return rc;
73042f01 108}