Added two missing includes to allow macro compilation (thanks to Laurent for remarkin...
[u/mrichter/AliRoot.git] / ITS / MakeSDDGeoMap.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <TCanvas.h>
3 #include <TFile.h>
4 #include <TLine.h>
5 #include <TLatex.h>
6 #include <TClassTable.h>
7 #include <TInterpreter.h>
8 #include <TGeoManager.h>
9 #include <TNtuple.h>
10 #include "AliRun.h"
11 #include "AliGeomManager.h"
12 #include "AliITSgeomTGeo.h"
13 #include "AliRunLoader.h"
14 #include "AliITSLoader.h"
15 #endif
16
17 void MakeSDDGeoMap(){
18 ///////////////////////////////////////////////////////////////////////////
19 //                                                                       //
20 // Macro to Create SDD geometrical map starting from geometry.root file  //
21 //                                                                       //
22 ///////////////////////////////////////////////////////////////////////////
23
24   if (gClassTable->GetID("AliRun") < 0) {
25     gInterpreter->ExecuteMacro("loadlibs.C");
26   }
27   else { 
28     if(gAlice){
29       delete AliRunLoader::Instance();
30       delete gAlice;
31       gAlice=0;
32     }
33   }
34   // retrives geometry 
35   if(!gGeoManager){
36     AliGeomManager::LoadGeometry("geometry.root");
37   }
38   
39   TNtuple *ntsddgeo=new TNtuple("ntsddgeo","SDD module positions","iMod:lay:lad:det:x:y:z:r:theta:phi");
40   Float_t xnt[10];
41   FILE *outfil;
42   outfil=fopen("SDDgeomap.data","w");
43   
44   Int_t first = AliITSgeomTGeo::GetModuleIndex(3,1,1);
45   Int_t last = AliITSgeomTGeo::GetModuleIndex(5,1,1)-1;
46   Double_t pos[3];
47   Int_t lay,lad,det;
48   //  TPaveText **text=new TPaveText*[36];
49   TLatex **text=new TLatex*[36];
50   TLatex **ltext=new TLatex*[36];
51   TLine **linxy=new TLine*[36];
52   Char_t modtxt[3];
53   Char_t ladtxt[8];
54   Int_t it=0;
55   Float_t D=3.5; //SDD half length along drift
56   for (Int_t iMod=first; iMod<=last; iMod++){
57     fprintf(outfil,"=========================================================\n");
58     AliITSgeomTGeo::GetModuleId(iMod,lay,lad,det);
59     AliITSgeomTGeo::GetTranslation(iMod,pos);
60     Float_t rad=TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]);
61     Float_t theta=90.-TMath::ATan2(pos[2],rad)*TMath::RadToDeg();
62     Float_t phi=TMath::ATan2(pos[1],pos[0])*TMath::RadToDeg();
63     fprintf(outfil,"ModuleId=%d   --- Layer %d  Ladder %d  Det %d\n",iMod,lay,lad,det);
64     fprintf(outfil,"Global coordinates: x=%f \t y=%f \t z=%f\n",pos[0],pos[1],pos[2]);
65     fprintf(outfil,"                    r=%f \t theta=%f \t phi=%f\n",rad,theta,phi);
66     xnt[0]=(Float_t)iMod;
67     xnt[1]=(Float_t)lay;    
68     xnt[2]=(Float_t)lad;    
69     xnt[3]=(Float_t)det;
70     xnt[4]=pos[0];
71     xnt[5]=pos[1];
72     xnt[6]=pos[2];
73     xnt[7]=rad;
74     xnt[8]=theta;
75     xnt[9]=phi;
76     ntsddgeo->Fill(xnt);
77     sprintf(modtxt,"%d",iMod);
78     sprintf(ladtxt,"L%d",lad);
79     if(det==1){ 
80       text[it]=new TLatex(1.1*pos[0],1.1*pos[1],modtxt);
81       text[it]->SetTextAlign(22);
82       text[it]->SetTextColor(2);
83       text[it]->SetTextSize(0.03);      
84       ltext[it]=new TLatex(.9*pos[0],.9*pos[1],ladtxt);
85       ltext[it]->SetTextAlign(22);
86       ltext[it]->SetTextColor(4);
87       ltext[it]->SetTextSize(0.03);
88       Float_t deltax=D*TMath::Sin(phi*TMath::DegToRad());
89       Float_t deltay=D*TMath::Cos(phi*TMath::DegToRad());
90       linxy[it]=new TLine(pos[0]-deltax,pos[1]+deltay,pos[0]+deltax,pos[1]-deltay);
91       linxy[it]->SetLineWidth(2);
92       it++;
93     }
94   }
95   fclose(outfil);
96   TFile *f=new TFile("SDDgeomap.root","recreate");
97   f->cd();
98   ntsddgeo->Write();
99   f->Close();
100   
101   ntsddgeo->SetMarkerStyle(7);
102   TCanvas *c1;
103   c1=new TCanvas("c1","",800,800);
104   ntsddgeo->Draw("y:x");
105   for(Int_t i=0;i<36;i++){
106     linxy[i]->Draw();
107     text[i]->Draw();
108     ltext[i]->Draw();
109   }
110
111   TCanvas *c2=new TCanvas("c2","",1200,800);
112   c2->Divide(3,2);
113   c2->cd(1);
114   ntsddgeo->SetMarkerColor(1);
115   ntsddgeo->Draw("x:iMod");
116   ntsddgeo->SetMarkerColor(2);
117   ntsddgeo->Draw("x:iMod","lay==4","same");
118   c2->cd(2);
119   ntsddgeo->SetMarkerColor(1);
120   ntsddgeo->Draw("y:iMod");
121   ntsddgeo->SetMarkerColor(2);
122   ntsddgeo->Draw("y:iMod","lay==4","same");
123   c2->cd(3);
124   ntsddgeo->SetMarkerColor(1);
125   ntsddgeo->Draw("z:iMod");
126   ntsddgeo->SetMarkerColor(2);
127   ntsddgeo->Draw("z:iMod","lay==4","same");
128   c2->cd(4);
129   ntsddgeo->SetMarkerColor(1);
130   ntsddgeo->Draw("r:iMod");
131   ntsddgeo->SetMarkerColor(2);
132   ntsddgeo->Draw("r:iMod","lay==4","same");
133   TLatex *t3=new TLatex(0.68,0.45,"Layer 3");
134   t3->SetTextSize(0.05);
135   t3->SetNDC();
136   t3->Draw();
137   TLatex *t4=new TLatex(0.68,0.37,"Layer 4");
138   t4->SetTextSize(0.05);
139   t4->SetNDC();
140   t4->SetTextColor(2);
141   t4->Draw();
142   c2->cd(5);
143   ntsddgeo->SetMarkerColor(1);
144   ntsddgeo->Draw("phi:iMod");
145   ntsddgeo->SetMarkerColor(2);
146   ntsddgeo->Draw("phi:iMod","lay==4","same");
147   t3->Draw();
148   t4->Draw();
149   c2->cd(6);
150   ntsddgeo->SetMarkerColor(1);
151   ntsddgeo->Draw("theta:iMod");
152   ntsddgeo->SetMarkerColor(2);
153   ntsddgeo->Draw("theta:iMod","lay==4","same");
154   t3->Draw();
155   t4->Draw();
156   
157   
158 }
159
160