Updated directory names on LDC in SDD calibration plotting macro (Mario Sitta)
[u/mrichter/AliRoot.git] / ITS / macrosSDD / 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   ntsddgeo->SetMarkerStyle(7);
97   TCanvas *c1;
98   c1=new TCanvas("c1","",800,800);
99   ntsddgeo->Draw("y:x");
100   for(Int_t i=0;i<36;i++){
101     linxy[i]->Draw();
102     text[i]->Draw();
103     ltext[i]->Draw();
104   }
105   
106
107   TCanvas *c2=new TCanvas("c2","",1200,800);
108   c2->Divide(3,2);
109   c2->cd(1);
110   ntsddgeo->SetMarkerColor(1);
111   ntsddgeo->Draw("x:iMod");
112   ntsddgeo->SetMarkerColor(2);
113   ntsddgeo->Draw("x:iMod","lay==4","same");
114   c2->cd(2);
115   ntsddgeo->SetMarkerColor(1);
116   ntsddgeo->Draw("y:iMod");
117   ntsddgeo->SetMarkerColor(2);
118   ntsddgeo->Draw("y:iMod","lay==4","same");
119   c2->cd(3);
120   ntsddgeo->SetMarkerColor(1);
121   ntsddgeo->Draw("z:iMod");
122   ntsddgeo->SetMarkerColor(2);
123   ntsddgeo->Draw("z:iMod","lay==4","same");
124   c2->cd(4);
125   ntsddgeo->SetMarkerColor(1);
126   ntsddgeo->Draw("r:iMod");
127   ntsddgeo->SetMarkerColor(2);
128   ntsddgeo->Draw("r:iMod","lay==4","same");
129   TLatex *t3=new TLatex(0.68,0.45,"Layer 3");
130   t3->SetTextSize(0.05);
131   t3->SetNDC();
132   t3->Draw();
133   TLatex *t4=new TLatex(0.68,0.37,"Layer 4");
134   t4->SetTextSize(0.05);
135   t4->SetNDC();
136   t4->SetTextColor(2);
137   t4->Draw();
138   c2->cd(5);
139   ntsddgeo->SetMarkerColor(1);
140   ntsddgeo->Draw("phi:iMod");
141   ntsddgeo->SetMarkerColor(2);
142   ntsddgeo->Draw("phi:iMod","lay==4","same");
143   t3->Draw();
144   t4->Draw();
145   c2->cd(6);
146   ntsddgeo->SetMarkerColor(1);
147   ntsddgeo->Draw("theta:iMod");
148   ntsddgeo->SetMarkerColor(2);
149   ntsddgeo->Draw("theta:iMod","lay==4","same");
150   t3->Draw();
151   t4->Draw();
152   
153   TFile *f=new TFile("SDDgeomap.root","recreate");
154   f->cd();
155   ntsddgeo->Write();
156   f->Close();
157   
158 }
159
160