Some of the coding violations corrected
[u/mrichter/AliRoot.git] / TPC / AliTPCFindClusters.C
CommitLineData
c2b0eaa4 1/****************************************************************************
2 * Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch *
3 ****************************************************************************/
4
c630aafd 5#if !defined(__CINT__) || defined(__MAKECINT__)
ddae8318 6 #include <Riostream.h>
c630aafd 7
b9de75e1 8 #include "AliRun.h"
c630aafd 9 #include "AliRunLoader.h"
10 #include "AliTPCLoader.h"
b9de75e1 11 #include "AliTPCv1.h"
b9de75e1 12 #include "AliTPCParam.h"
c630aafd 13 #include "AliTPCclusterer.h"
b9de75e1 14
c630aafd 15 #include "TTree.h"
b9de75e1 16 #include "TStopwatch.h"
17#endif
18
c630aafd 19extern AliRun *gAlice;
20
21Int_t AliTPCFindClusters(Int_t nev=5) {
22
23 if (gAlice) {
33c3c91a 24 delete AliRunLoader::Instance();
88cb7938 25 delete gAlice;//if everything was OK here it is already NULL
26 gAlice = 0x0;
c630aafd 27 }
88cb7938 28
29 AliRunLoader* rl = AliRunLoader::Open("galice.root");
c630aafd 30 if (rl == 0x0) {
88cb7938 31 cerr<<"Can not open session"<<endl;
32 return 1;
c630aafd 33 }
88cb7938 34
c630aafd 35 if (rl->LoadgAlice()) {
88cb7938 36 cerr<<"Error occured while l"<<endl;
37 return 1;
c630aafd 38 }
88cb7938 39
c630aafd 40 AliTPCLoader *tpcl = (AliTPCLoader*)rl->GetLoader("TPCLoader");
41 if (tpcl == 0x0) {
88cb7938 42 cerr<<"Can not get TPC Loader"<<endl;
43 return 1;
c630aafd 44 }
73042f01 45
88cb7938 46 gAlice=rl->GetAliRun();
47 if (!gAlice) {
48 cerr<<"Can't get gAlice !\n";
49 return 1;
73042f01 50 }
51
73042f01 52 AliTPC *TPC = (AliTPC*)gAlice->GetDetector("TPC");
53 Int_t ver = TPC->IsVersion();
54 cerr<<"TPC version "<<ver<<" has been found !\n";
55
88cb7938 56 rl->CdGAFile();
57 AliTPCParam *dig=(AliTPCParam *)gDirectory->Get("75x40_100x60_150x60");
c630aafd 58 if (!dig) {
88cb7938 59 cerr<<"TPC parameters have not been found !\n";
60 return 1;
c630aafd 61 }
62
63 if (nev>rl->GetNumberOfEvents()) nev=rl->GetNumberOfEvents();
88cb7938 64
c630aafd 65 tpcl->LoadRecPoints("recreate");
66 if (ver==1) tpcl->LoadHits("read");
67 else tpcl->LoadDigits("read");
68
73042f01 69 TStopwatch timer;
70
c630aafd 71 if (ver==1) {
73042f01 72 cerr<<"Making clusters...\n";
c630aafd 73 AliTPCv1 &tpc=*((AliTPCv1*)TPC);
74 tpc.SetParam(dig);
75 tpc.SetLoader(tpcl);
76 rl->LoadKinematics();
77 timer.Start();
78 for(Int_t i=0;i<nev;i++) {
afc42102 79 printf("Processing event %d\n",i);
88cb7938 80 rl->GetEvent(i);
c630aafd 81 tpc.Hits2Clusters(i);
73042f01 82 }
c630aafd 83 } else if (ver==2) {
73042f01 84 cerr<<"Looking for clusters...\n";
c630aafd 85 AliTPCclusterer *dummy=new AliTPCclusterer(dig), &clusterer=*dummy;
86 timer.Start();
87 for (Int_t i=0;i<nev;i++) {
88cb7938 88 printf("Processing event %d\n",i);
c630aafd 89 rl->GetEvent(i);
90
91 TTree *out=tpcl->TreeR();
92 if (!out) {
93 tpcl->MakeTree("R");
94 out=tpcl->TreeR();
95 }
96 TTree *in=tpcl->TreeD();
97 if (!in) {
98 cerr<<"Can't get digits tree !\n";
99 return 4;
100 }
101
102 clusterer.Digits2Clusters(in,out);
103
104 tpcl->WriteRecPoints("OVERWRITE");
73042f01 105 }
c630aafd 106 delete dummy;
107 delete dig;
108 } else {
73042f01 109 cerr<<"Invalid TPC version !\n";
88cb7938 110 delete rl;
73042f01 111 return 5;
112 }
113
114 timer.Stop(); timer.Print();
115
88cb7938 116 delete rl;
c630aafd 117
73042f01 118 return 0;
119}