1 /****************************************************************************
2 * This macro is supposed to do reconstruction in the barrel ALICE trackers *
3 * (Make sure you have TPC digits and ITS hits before using this macro !!!) *
4 * It does the following steps (July 9, 2002,Dubna) *
5 * 1) TPC cluster finding *
6 * 2) TPC track finding *
7 * 3) ITS cluster finding V2 *
8 * 4) ITS track finding V2 *
9 * 5) ITS back track propagation V2 *
10 * 6) TPC back track propagation *
11 * (Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch) *
12 ****************************************************************************/
17 #include "AliTPCtracker.h"
20 #include "AliITSgeom.h"
21 #include "AliITSRecPoint.h"
22 #include "AliITSclusterV2.h"
23 #include "AliITSsimulationFastPoints.h"
24 #include "AliITStrackerV2.h"
28 Int_t TPCFindClusters(const Char_t *inname, const Char_t *outname, Int_t n);
29 Int_t TPCFindTracks(const Char_t *inname, const Char_t *outname, Int_t n);
30 Int_t TPCSortTracks(const Char_t *inname, const Char_t *inname2, const Char_t *outname, Int_t n);
31 Int_t TPCPropagateBack(const Char_t *inname, const Char_t *outname);
33 Int_t ITSFindClusters(const Char_t *inname, const Char_t *outname, Int_t n);
34 Int_t ITSFindTracks(const Char_t *inname, const Char_t *inname2, const Char_t *outname, Int_t n);
35 Int_t ITSPropagateBack(const Char_t *inname, const Char_t *outname);
38 Int_t AliBarrelReconstructionV2(Int_t n=1) {
39 //const Char_t *TPCdigName="rfio:galice.root";
40 const Char_t *TPCdigName="galice.root";
41 const Char_t *TPCclsName="AliTPCclusters.root";
42 const Char_t *TPCtrkName="AliTPCtracks.root";
43 const Char_t *TPCtrkNameS="AliTPCtracksSorted.root";
46 //const Char_t *ITSdigName="rfio:galice.root";
47 const Char_t *ITSdigName="galice.root";
48 const Char_t *ITSclsName="AliITSclustersV2.root";
49 const Char_t *ITStrkName="AliITStracksV2.root";
51 AliKalmanTrack::SetConvConst(100/0.299792458/0.2/gAlice->Field()->Factor());
54 // ********** Find TPC clusters *********** //
55 if (TPCFindClusters(TPCdigName,TPCclsName, n)) {
56 cerr<<"Failed to get TPC clusters !\n";
60 // ********** Find TPC tracks *********** //
61 if (TPCFindTracks(TPCclsName,TPCtrkName,n)) {
62 cerr<<"Failed to get TPC tracks !\n";
66 // ********** Sort and label TPC tracks *********** //
67 if (TPCSortTracks(TPCclsName,TPCtrkName,TPCtrkNameS,n)) {
68 cerr<<"Failed to sort TPC tracks !\n";
72 // ********** Find ITS clusters *********** //
73 if (ITSFindClusters(ITSdigName,ITSclsName,n)) {
74 cerr<<"Failed to get ITS clusters !\n";
78 // ********** Find ITS tracks *********** //
80 //TFile *clsFile=TFile::Open(ITSclsName);
81 if (ITSFindTracks(TPCtrkNameS,ITSclsName,ITStrkName,n)) {
82 cerr<<"Failed to get ITS tracks !\n";
88 // ********** Back propagation of the ITS tracks *********** //
89 {TFile *clsFile=TFile::Open(ITSclsName);
90 if (ITSPropagateBack(ITStrkName,TPCtrkNameS)) {
91 cerr<<"Failed to propagate back the ITS tracks !\n";
97 // ********** Back propagation of the TPC tracks *********** //
98 {TFile *clsFile=TFile::Open(TPCclsName);
99 if (TPCPropagateBack(TPCtrkName,TPCtrkName)) {
100 cerr<<"Failed to propagate back the TPC tracks !\n";
109 Int_t TPCFindClusters(const Char_t *inname, const Char_t *outname, Int_t n) {
111 const Char_t *name="TPCFindClusters";
112 cerr<<'\n'<<name<<"...\n";
113 gBenchmark->Start(name);
115 TFile *out=TFile::Open(outname,"recreate");
116 TFile *in =TFile::Open(inname);
118 AliTPCParam *param=(AliTPCParam *)in->Get("75x40_100x60_150x60");
119 if (!param) {cerr<<"TPC parameters have not been found !\n"; return 1;}
123 //tpc.Digits2Clusters(out); //MI change
124 cout<<"TPCFindClusters: nev ="<<n<<endl;
125 for (Int_t i=0;i<n;i++){
126 printf("Processing event %d\n",i);
127 tpc.Digits2Clusters(out,i);
128 // AliTPCclusterer::Digits2Clusters(dig, out, i);
132 gBenchmark->Stop(name);
133 gBenchmark->Show(name);
138 Int_t TPCFindTracks(const Char_t *inname, const Char_t *outname, Int_t n) {
140 const Char_t *name="TPCFindTracks";
141 cerr<<'\n'<<name<<"...\n";
142 gBenchmark->Start(name);
143 TFile *out=TFile::Open(outname,"recreate");
144 TFile *in =TFile::Open(inname);
145 AliTPCParam *param=(AliTPCParam *)in->Get("75x40_100x60_150x60");
146 if (!param) {cerr<<"TPC parameters have not been found !\n"; return 1;}
148 //AliTPCtracker *tracker=new AliTPCtracker(param);
149 //rc=tracker->Clusters2Tracks(0,out);
151 cout<<"TPCFindTracks: nev ="<<n<<endl;
153 for (Int_t i=0;i<n;i++){
154 printf("Processing event %d\n",i);
155 AliTPCtracker *tracker = new AliTPCtracker(param,i);
157 tracker->Clusters2Tracks(0,out);
163 gBenchmark->Stop(name);
164 gBenchmark->Show(name);
168 Int_t TPCSortTracks(const Char_t *inname, const Char_t *inname2, const Char_t * outname, Int_t eventn){
170 const Char_t *name="TPCSortTracks";
171 cerr<<'\n'<<name<<"...\n";
172 gBenchmark->Start(name);
174 TFile *out =TFile::Open(outname,"recreate");
175 TFile *in1 =TFile::Open(inname);
176 TFile *in2 =TFile::Open(inname2);
179 AliTPCParam *param=(AliTPCParam *)in1->Get("75x40_100x60_150x60");
180 if (!param) {cerr<<"TPC parameters have not been found !\n"; return 1;}
182 cout<<"TPCSortedtracks: nev ="<<eventn<<endl;
186 for (Int_t event=0;event<eventn; event++){
187 TObjArray tarray(10000);
188 AliTPCtrack *iotrack=0;
194 sprintf(tname,"TreeT_TPC_%d",event);
196 TTree *tracktree=(TTree*)in2->Get(tname);
197 TBranch *tbranch=tracktree->GetBranch("tracks");
198 Int_t nentr=(Int_t)tracktree->GetEntries();
199 for (i=0; i<nentr; i++) {
200 iotrack=new AliTPCtrack;
201 tbranch->SetAddress(&iotrack);
202 tracktree->GetEvent(i);
203 tarray.AddLast(iotrack);
208 //assign thacks GEANT labels
210 AliTPCtracker *tracker = new AliTPCtracker(param,event);
211 tracker->LoadInnerSectors();
212 tracker->LoadOuterSectors();
213 for (i=0; i<nentr; i++) {
214 iotrack=(AliTPCtrack*)tarray.UncheckedAt(i);
215 tracker->CookLabel(iotrack,0.1);
219 //end of GEANT label assignment
221 tracktree=new TTree(tname,"Tree with TPC tracks");
222 tracktree->Branch("tracks","AliTPCtrack",&iotrack,32000,0);
223 for (i=0; i<nentr; i++) {
224 iotrack=(AliTPCtrack*)tarray.UncheckedAt(i);
235 gBenchmark->Stop(name);
236 gBenchmark->Show(name);
241 Int_t ITSFindClusters(const Char_t *inname, const Char_t *outname, Int_t n) {
243 const Char_t *name="ITSFindClusters";
244 cerr<<'\n'<<name<<"...\n";
245 gBenchmark->Start(name);
246 TFile *out=TFile::Open(outname,"recreate");
247 TFile *in =TFile::Open(inname,"update");
249 if (!(gAlice=(AliRun*)in->Get("gAlice"))) {
250 cerr<<"Can't get gAlice !\n";
254 AliITS *ITS = (AliITS*)gAlice->GetModule("ITS");
255 if (!ITS) { cerr<<"Can't get the ITS !\n"; return 1;}
256 AliITSgeom *geom=ITS->GetITSgeom();
260 cout<<"ITSFindClusters: nev ="<<n<<endl;
262 for (ev = 0; ev<n; ev++){
263 in->cd(); // !!!! MI directory must point to galice. - othervise problem with Tree -connection
264 gAlice->GetEvent(ev);
265 //gAlice->TreeR()->Reset(); //reset reconstructed tree
268 TTree *pTree=gAlice->TreeR();
270 gAlice->MakeTree("R");
271 pTree = gAlice->TreeR();
273 TBranch *branch=pTree->GetBranch("ITSRecPoints");
276 //if not reconstructed ITS branch do reconstruction
277 ITS->MakeBranch("R",0);
279 //////////////// Taken from ITSHitsToFastPoints.C ///////////////////////
280 AliITSsimulationFastPoints *sim = new AliITSsimulationFastPoints();
281 for (Int_t i=0;i<3;i++) { ITS->SetSimulationModel(i,sim); }
284 Int_t bgr_ev=Int_t(ev/nsignal);
285 ITS->HitsToFastRecPoints(ev,bgr_ev,size," ","All"," ");
286 //////////////////////////////////////////////////////////////////////////
287 gAlice->GetEvent(ev); //MI comment - in HitsToFast... they reset treeR to 0
288 //they overwrite full reconstructed event ???? ... so lets connect TreeR one more
295 TClonesArray *clusters=new TClonesArray("AliITSclusterV2",10000);
297 sprintf(cname,"TreeC_ITS_%d",ev);
299 TTree *cTree=new TTree(cname,"ITS clusters");
300 cTree->Branch("Clusters",&clusters);
302 pTree=gAlice->TreeR();
303 if (!pTree) { cerr<<"Can't get TreeR !\n"; return 1; }
304 branch=pTree->GetBranch("ITSRecPoints");
305 if (!branch) { cerr<<"Can't get ITSRecPoints branch !\n"; return 1;}
306 TClonesArray *points=new TClonesArray("AliITSRecPoint",10000);
307 branch->SetAddress(&points);
309 TClonesArray &cl=*clusters;
311 Int_t nentr=(Int_t)pTree->GetEntries();
314 AliITSgeom *geom=ITS->GetITSgeom();
316 cout<<"!!!! nentr ="<<nentr<<endl;
317 for (Int_t i=0; i<nentr; i++) {
318 if (!pTree->GetEvent(i)) {cTree->Fill(); continue;}
319 Int_t lay,lad,det; geom->GetModuleId(i,lay,lad,det);
320 Float_t x,y,zshift; geom->GetTrans(lay,lad,det,x,y,zshift);
321 Double_t rot[9]; geom->GetRotMatrix(lay,lad,det,rot);
322 Double_t yshift = x*rot[0] + y*rot[1];
323 Int_t ndet=(lad-1)*geom->GetNdetectors(lay) + (det-1);
324 Int_t ncl=points->GetEntriesFast();
328 if(lay<5&&lay>2){kmip=280.;}; // b.b.
329 if(lay<7&&lay>4){kmip=38.;};
332 for (Int_t j=0; j<ncl; j++) {
333 AliITSRecPoint *p=(AliITSRecPoint*)points->UncheckedAt(j);
334 lp[0]=-p->GetX()-yshift; if (lay==1) lp[0]=-lp[0];
335 lp[1]=p->GetZ()+zshift;
336 lp[2]=p->GetSigmaX2();
337 lp[3]=p->GetSigmaZ2();
338 lp[4]=p->GetQ(); lp[4]/=kmip; // b.b.
339 if(ncl==11)cout<<"mod,cl,Q ="<<i<<","<<j<<","<<lp[4]<<endl;
340 lab[0]=p->GetLabel(0);lab[1]=p->GetLabel(1);lab[2]=p->GetLabel(2);
344 if(label>=0) { // b.b.
345 TParticle *part=(TParticle*)gAlice->Particle(label);
347 while (part->P() < 0.005) {
348 Int_t m=part->GetFirstMother();
349 if (m<0) {cerr<<"Primary momentum: "<<part->P()<<endl; break;}
351 part=(TParticle*)gAlice->Particle(label);
354 if (lab[1]<0) lab[1]=label;
355 else if (lab[2]<0) lab[2]=label;
356 else cerr<<"No empty labels !\n";
358 new(cl[j]) AliITSclusterV2(lab,lp);
360 cTree->Fill(); clusters->Delete();
364 cerr<<"Number of clusters: "<<nclusters<<endl;
365 delete cTree; delete clusters; delete points;
369 delete gAlice; gAlice=0;
372 gBenchmark->Stop(name);
373 gBenchmark->Show(name);
378 Int_t ITSFindTracks(const Char_t * inname, const Char_t *inname2, const Char_t *outname, Int_t n) {
380 const Char_t *name="ITSFindTracks";
381 cerr<<'\n'<<name<<"...\n";
382 gBenchmark->Start(name);
385 TFile *out=TFile::Open(outname,"recreate");
386 TFile *in =TFile::Open(inname);
387 TFile *in2 =TFile::Open(inname2);
389 AliITSgeom *geom=(AliITSgeom*)gFile->Get("AliITSgeom");
390 if (!geom) { cerr<<"can't get ITS geometry !\n"; return 1;}
392 cout<<"ITSFindtracks: nev ="<<n<<endl;
394 for (Int_t i=0;i<n;i++){
395 AliITStrackerV2 tracker(geom,i);
396 rc=tracker.Clusters2Tracks(in,out);
403 gBenchmark->Stop(name);
404 gBenchmark->Show(name);
409 Int_t ITSPropagateBack(const Char_t *inname, const Char_t *outname) {
413 const Char_t *name="ITSPropagateBack";
414 cerr<<'\n'<<name<<"...\n";
415 gBenchmark->Start(name);
417 AliITSgeom *geom=(AliITSgeom*)gFile->Get("AliITSgeom");
418 if (!geom) { cerr<<"can't get ITS geometry !\n"; return 1;}
419 AliITStrackerV2 tracker(geom);
421 TFile *out=TFile::Open(outname,"update");
422 TFile *in =TFile::Open(inname);
423 rc=tracker.PropagateBack(in,out);
427 gBenchmark->Stop(name);
428 gBenchmark->Show(name);
433 Int_t TPCPropagateBack(const Char_t *inname, const Char_t *outname) {
435 const Char_t *name="TPCPropagateBack";
436 cerr<<'\n'<<name<<"...\n";
437 gBenchmark->Start(name);
439 AliTPCParam *param=(AliTPCParam *)gFile->Get("75x40_100x60_150x60");
440 if (!param) {cerr<<"TPC parameters have not been found !\n"; return 1;}
441 AliTPCtracker *tracker=new AliTPCtracker(param);
443 TFile *out=TFile::Open(outname,"update");
444 TFile *in =TFile::Open(inname);
445 rc=tracker->PropagateBack(in,out);
450 gBenchmark->Stop(name);
451 gBenchmark->Show(name);