macro comparing exact and reconstructed clusters
[u/mrichter/AliRoot.git] / TPC / AliTPCCompareClusters.C
1 #ifndef __CINT__
2 #include "alles.h"
3 #include "AliComplexCluster.h"
4 #endif
5
6 Int_t AliTPCCompareClusters(Int_t eventn) {
7    cerr<<"Comparing clusters...\n";
8
9    TFile *file=TFile::Open("galice.root");
10    if (!file->IsOpen()) {cerr<<"Can't open galice.root !\n"; return 1;}
11
12    //   TFile *cf=TFile::Open("AliTPCclusters.root");
13    TFile *cf=TFile::Open("AliTPCclusters.root");
14    if (!cf->IsOpen()){cerr<<"Can't open AliTPCclusters.root !\n"; return 3;}
15
16    AliTPCParam *dig=(AliTPCParam *)cf->Get("75x40_100x60");
17    if (!dig) {cerr<<"TPC parameters have not been found !\n"; return 2;}
18    
19    TFile *fout=TFile::Open("AliTPCClustersDif.root","new"); 
20    if (!fout->IsOpen()) fout=TFile::Open("AliTPCClustersDif.root","recreate");  
21
22    //connect exact clusters
23    file->cd();
24    AliTPCClustersArray *ce=new AliTPCClustersArray;
25    ce->Setup(dig);
26    ce->SetClusterType("AliComplexCluster");
27    char  cname[100];
28    sprintf(cname,"TreeCExact_%d",eventn);
29    ce->ConnectTree(cname);
30    //connect reconstructed clusters
31    cf->cd();
32    AliTPCClustersArray *cr=new AliTPCClustersArray;
33    cr->Setup(dig);
34    cr->SetClusterType("AliTPCcluster");  
35    sprintf(cname,"TreeC_TPC_%d",eventn);
36    cr->ConnectTree(cname);
37    
38    //create differantial clusters
39    fout->cd();
40    AliTPCClustersArray carray;
41    carray.Setup(dig);
42    carray.SetClusterType("AliDifCluster");
43    carray.MakeTree();
44    
45    Int_t nrows=Int_t(cr->GetTree()->GetEntries());
46    for (Int_t n=0; n<nrows; n++) {
47        AliSegmentID *sr=cr->LoadEntry(n);
48        Int_t sec,row;
49        dig->AdjustSectorRow(sr->GetID(),sec,row);
50        ce->LoadRow(sec,row);
51        cr->LoadRow(sec,row);
52        AliTPCClustersRow* clrowe = ce->GetRow(sec,row);
53        AliTPCClustersRow* clrowr = cr->GetRow(sec,row);
54        AliTPCClustersRow* clrowdiff = carray.CreateRow(sec,row);
55
56        Int_t ncl=clrowe->GetArray()->GetEntriesFast();
57        const Int_t kNIS=dig->GetNInnerSector(), kNOS=dig->GetNOuterSector();
58        Int_t npads, sign;
59        if (sec < kNIS) {
60           npads = dig->GetNPadsLow(row);
61           sign = (sec < kNIS/2) ? 1 : -1;
62        } else {
63           npads = dig->GetNPadsUp(row);
64           sign = ((sec-kNIS) < kNOS/2) ? 1 : -1;
65        }
66
67        while (ncl--) {
68          //           AliTPCcluster *cl=(AliTPCcluster*)clrow[ncl];
69            AliComplexCluster *cl=(AliComplexCluster*)(clrowe->GetArray()->At(ncl));
70            AliDifCluster * cldif = new(clrowdiff->Append()) AliDifCluster;
71
72            Double_t x=dig->GetPadRowRadii(sec,row);
73            Double_t y=cl->fY;
74            y = ( y + 0.5 -  0.5*npads) *dig->GetPadPitchWidth(sec);
75            Double_t z=cl->fX*dig->GetZWidth();
76            z = sign*(dig->GetZLength() - z);
77            Float_t cs, sn, tmp;
78            dig->AdjustCosSin(sec,cs,sn);
79            Int_t ncr = clrowr->GetArray()->GetEntriesFast();
80            AliTPCcluster *clrec =0;
81            while (ncr--) {
82              clrec = (AliTPCcluster*)(clrowr->GetArray()->At(ncr));
83              if (clrec->GetLabel(0) == cl->fTracks[0]){
84                //cout<<cl->fTracks[0]<<"\n";
85                cldif->fTracks[0]= cl->fTracks[0];
86                cldif->fTracks[1]= clrec->GetLabel(1);
87                cldif->fTracks[2]= clrec->GetLabel(2);
88
89                cldif->fX = clrec->GetZ();
90                cldif->fY = clrec->GetY();
91                cldif->fQ = clrec->GetQ();
92                cldif->fOrigQ = cl->fQ;
93                cldif->fDx = cldif->fX - z;
94                cldif->fAngleX= cl->fSigmaX2;
95                cldif->fAngleY= cl->fSigmaY2;           
96                cldif->fDy = cldif->fY - y;                     
97              }
98              
99            }
100            //tmp = x*cs-y*sn; y= x*sn+y*cs; x=tmp;
101
102            // pm->SetPoint(ncl,x,y,z);
103        }
104        cr->ClearRow(sec,row);
105        ce->ClearRow(sec,row);
106        carray.StoreRow(sec,row);
107        carray.ClearRow(sec,row);
108    }
109    delete ce;
110    delete cr;
111    carray.GetTree()->Write("Diff");
112    cf->Close();
113    fout->Close();
114    file->Close();
115    return 0;
116 }