Tests and example macros working with ESD (Yu.Belikov)
[u/mrichter/AliRoot.git] / ITS / AliITSFindTracksV2.C
CommitLineData
c630aafd 1/****************************************************************************
2 * Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch *
3 ****************************************************************************/
4
5#if !defined(__CINT__) || defined(__MAKECINT__)
c0dd5278 6 #include "Riostream.h"
a62f4fcc 7 #include "TKey.h"
03248e6d 8 #include "TStopwatch.h"
c0dd5278 9
c630aafd 10 #include "AliRun.h"
a62f4fcc 11 #include "AliMagF.h"
c630aafd 12 #include "AliRunLoader.h"
13 #include "AliTPCLoader.h"
14 #include "AliITSLoader.h"
15 #include "AliITS.h"
c0dd5278 16 #include "AliITSgeom.h"
17 #include "AliITStrackerV2.h"
a62f4fcc 18 #include "AliESD.h"
03248e6d 19#endif
20
c630aafd 21extern AliRun *gAlice;
22
23Int_t AliITSFindTracksV2(Int_t nev=5) { //number of events to process
03248e6d 24 cerr<<"Looking for tracks...\n";
88cb7938 25
c630aafd 26 if (gAlice) {
88cb7938 27 delete gAlice->GetRunLoader();
28 delete gAlice;
29 gAlice=0;
c630aafd 30 }
88cb7938 31
c630aafd 32 AliRunLoader* rl = AliRunLoader::Open("galice.root");
33 if (rl == 0x0) {
34 cerr<<"AliITSFindTracks.C : Can not open session RL=NULL"<< endl;
35 return 3;
36 }
88cb7938 37
c630aafd 38 AliITSLoader* itsl = (AliITSLoader*)rl->GetLoader("ITSLoader");
39 if (itsl == 0x0) {
40 cerr<<"AliITSFindTracksV2.C : Can not get ITS loader"<<endl;
88cb7938 41 return 4;
c630aafd 42 }
03248e6d 43
a62f4fcc 44 if (rl->LoadgAlice()) {
45 cerr<<"AliITSFindTracksV2.C : LoadgAlice returned error"<<endl;
46 delete rl;
47 return 3;
c630aafd 48 }
03248e6d 49
a62f4fcc 50 AliKalmanTrack::SetConvConst(
51 1000/0.299792458/rl->GetAliRun()->Field()->SolenoidField()
52 );
53
54 AliITS *dITS = (AliITS*)rl->GetAliRun()->GetDetector("ITS");
c630aafd 55 if (!dITS) {
56 cerr<<"AliITSFindClusters.C : Can not find the ITS detector !"<<endl;
88cb7938 57 return 6;
c630aafd 58 }
88cb7938 59 AliITSgeom *geom = dITS->GetITSgeom();
03248e6d 60
c630aafd 61 AliITStrackerV2 tracker(geom);
03248e6d 62
c630aafd 63 itsl->LoadRecPoints("read");
64
c630aafd 65 if (nev>rl->GetNumberOfEvents()) nev=rl->GetNumberOfEvents();
66 Int_t rc=0;
a62f4fcc 67
68 TFile *itsf=TFile::Open("AliESDits.root","RECREATE");
69 if ((!itsf)||(!itsf->IsOpen())) {
70 cerr<<"Can't AliESDits.root !\n"; return 1;
71 }
72 TFile *tpcf=TFile::Open("AliESDtpc.root");
73 if ((!tpcf)||(!tpcf->IsOpen())) {
74 cerr<<"Can't AliESDtpc.root !\n"; return 1;
75 }
76 TKey *key=0;
77 TIter next(tpcf->GetListOfKeys());
78 TStopwatch timer;
c630aafd 79 for (Int_t i=0; i<nev; i++) {
a62f4fcc 80 tpcf->cd();
81 if ((key=(TKey*)next())==0) break;
c630aafd 82 cerr<<"Processing event number: "<<i<<endl;
a62f4fcc 83 AliESD *event=(AliESD*)key->ReadObj();
84
c630aafd 85 rl->GetEvent(i);
86
87 TTree *cTree=itsl->TreeR();
88 if (!cTree) {
89 cerr<<"AliITSFindTracksV2.C : Can't get the clusters tree !"<<endl;
90 return 4;
91 }
c630aafd 92
93 tracker.LoadClusters(cTree);
a62f4fcc 94 rc=tracker.Clusters2Tracks(event);
c630aafd 95 tracker.UnloadClusters();
96
a62f4fcc 97 if (rc==0) {
98 Char_t ename[100];
99 sprintf(ename,"%d",i);
100 itsf->cd();
101 if (!event->Write(ename)) rc++;
102 }
103 if (rc) {
104 cerr<<"Something bad happened...\n";
105 }
106 delete event;
c630aafd 107 }
88cb7938 108 timer.Stop(); timer.Print();
c630aafd 109
a62f4fcc 110 tpcf->Close();
111 itsf->Close();
112
88cb7938 113 delete rl;
c630aafd 114
03248e6d 115 return rc;
116}