]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/ShowSPDConfiguration.C
Coverity warnings 23063, 23151, 23152, 23851
[u/mrichter/AliRoot.git] / ITS / ShowSPDConfiguration.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <TStyle.h>
3 #include <TGrid.h>
4 #include <TCanvas.h>
5 #include <TH2D.h>
6 #include <TLine.h>
7 #include <TView.h>
8 #include <TMath.h>
9 #include <TGeoManager.h>
10 #include "AliITSOnlineCalibrationSPDhandler.h"
11 #include "AliCDBManager.h"
12 #include "AliGeomManager.h"
13 #include "AliITSAlignMille2Module.h"
14 #endif
15
16 void Draw3D(AliITSOnlineCalibrationSPDhandler *h);
17
18 void ShowSPDConfiguration(Int_t runNb=0, const char *ocdblocation="local://$ALICE_ROOT/OCDB", bool grid=kFALSE,bool threed=kFALSE){
19
20
21   gStyle->SetOptStat(0);
22
23   if(grid){
24     TGrid::Connect("alien://");
25     if(!gGrid){
26       printf("no grid connection is available, exiting.\n");
27       return;
28     }
29   }
30   AliITSOnlineCalibrationSPDhandler *h = new AliITSOnlineCalibrationSPDhandler();
31   h->ReadDeadFromDB(runNb,ocdblocation);
32   AliCDBManager::Instance();
33   AliCDBManager::Instance()->SetRun(runNb);
34   AliCDBManager::Instance()->SetDefaultStorage(ocdblocation);
35   AliGeomManager::LoadGeometry();
36
37   if(threed) {
38     Draw3D(h);  
39     return;
40   }
41
42   Double_t nact[2]={0.,0.};
43
44   TCanvas *c = new TCanvas("c","Active Modules ",500,700);
45   c->Divide(1,2);
46   c->cd(1);
47   TH2D *hPhiZInner = new TH2D("hPhiZInner","Inner layer Active Modules ",200,-20,20,3,0,2*TMath::Pi());
48   hPhiZInner->SetXTitle("Z (cm)");
49   hPhiZInner->SetYTitle("#varphi (rad)");
50   hPhiZInner->Draw();
51
52   for(Int_t i=0; i<80; i++){
53     if((h->GetNrBad(i))<1) {
54       TGeoHMatrix matrix;
55       int vid = AliITSAlignMille2Module::GetVolumeIDFromIndex(i);
56       AliITSAlignMille2Module::SensVolMatrix(vid,&matrix);
57       Double_t local0[3],local1[3],local2[3],local3[3]; // local position of the four angles
58       local0[0]=-0.6375; local0[1]=0; local0[2]= 3.48; 
59       local1[0]=-0.6375; local1[1]=0; local1[2]= -3.48; 
60       local2[0]=0.6375; local2[1]=0; local2[2]= -3.48; 
61       local2[0]=0.6375; local3[1]=0; local3[2]= 3.48; 
62       Double_t global0[3],global1[3],global2[3],global3[3];
63       matrix.LocalToMaster(local0,global0);
64       matrix.LocalToMaster(local1,global1);
65       matrix.LocalToMaster(local2,global2);
66       matrix.LocalToMaster(local3,global3);
67       Double_t phiUp = atan2(global0[1],global0[0]);
68       if(phiUp<0) phiUp+=2*TMath::Pi();
69       Double_t phiDown = atan2(global2[1],global2[0]);
70       if(phiDown<0) phiDown+=2*TMath::Pi();
71       TLine *lhor1 = new TLine(global0[2],phiDown,global1[2],phiDown); lhor1->Draw("same");
72       lhor1->SetLineColor(kBlue);
73       lhor1->SetLineWidth(3); 
74       TLine *lver1 = new TLine(global1[2],phiDown,global2[2],phiUp); lver1->Draw("same");
75       lver1->SetLineColor(kBlue);
76       lver1->SetLineWidth(3); 
77       TLine *lhor2 = new TLine(global2[2],phiUp,global3[2],phiUp); lhor2->Draw("same");
78       lhor2->SetLineColor(kBlue);
79       lhor2->SetLineWidth(3); 
80       TLine *lver2 = new TLine(global3[2],phiUp,global0[2],phiDown); lver2->Draw("same");
81       lver2->SetLineColor(kBlue);
82       lver2->SetLineWidth(3); 
83       nact[0]++;
84     } 
85   }
86   c->cd(2);
87
88   TH2D *hPhiZOuter = new TH2D("hPhiZOuter","Outer layer Active Modules ",200,-20,20,3,0,2*TMath::Pi());
89   hPhiZOuter->SetXTitle("Z (cm)");
90   hPhiZOuter->SetYTitle("#varphi (rad)");
91   hPhiZOuter->Draw();
92   for(Int_t i=80; i<240; i++){
93     TGeoHMatrix matrix;
94     int vid = AliITSAlignMille2Module::GetVolumeIDFromIndex(i);
95     AliITSAlignMille2Module::SensVolMatrix(vid,&matrix);
96     Double_t local[4][3]; // local position of the four angles
97     local[0][0]=0.6375; local[0][1]=0; local[0][2]= -3.48;
98     local[1][0]=0.6375; local[1][1]=0; local[1][2]= 3.48;
99     local[2][0]=-0.6375; local[2][1]=0; local[2][2]= 3.48;
100     local[2][0]=-0.6375; local[3][1]=0; local[3][2]= -3.48;
101     Double_t global[4][3];
102     for(Int_t j=0; j<4; j++){
103       matrix.LocalToMaster(local[j],global[j]);
104     }
105     Double_t phiUp = atan2(global[0][1],global[0][0]);
106     if(phiUp<0) phiUp+=2*TMath::Pi();
107     Double_t phiDown = atan2(global[2][1],global[2][0]);
108     if(phiDown<0) phiDown+=2*TMath::Pi();
109     if(i>235) if(phiUp < 0.1) phiUp = TMath::Pi()*2;
110     //  printf("module %i  -   phiDown %f   phiUp %f \n",i,phiDown,phiUp); 
111     if((h->GetNrBad(i))<1) {
112       TLine *lhor1 = new TLine(global[0][2],phiUp,global[1][2],phiUp); lhor1->Draw("same");
113       lhor1->SetLineColor(kBlue);
114       lhor1->SetLineWidth(2); 
115       TLine *lver1 = new TLine(global[1][2],phiUp,global[2][2],phiDown); lver1->Draw("same");
116       lver1->SetLineColor(kBlue);
117       lver1->SetLineWidth(2); 
118       TLine *lhor2 = new TLine(global[2][2],phiDown,global[3][2],phiDown); lhor2->Draw("same");
119       lhor2->SetLineColor(kBlue);
120       lhor2->SetLineWidth(2); 
121       TLine *lver2 = new TLine(global[3][2],phiDown,global[0][2],phiUp); lver2->Draw("same");
122       lver2->SetLineColor(kBlue);
123       lver2->SetLineWidth(2); 
124       nact[1]++; 
125     } 
126   }
127   printf("  \n   Number of Active SPD modules (->Total)  : inner %3.0f (80) %f   -  outer %3.0f (160)  %f \n",nact[0],nact[0]/80.,nact[1],nact[1]/160.);
128   c->SaveAs(Form("active%i.png",runNb));
129 }
130
131
132 void Draw3D(AliITSOnlineCalibrationSPDhandler *h){
133
134   TGeoHMatrix m2t[240];
135   for(Int_t imod=0; imod<240; imod++){
136     int vid = AliITSAlignMille2Module::GetVolumeIDFromIndex(imod);
137     AliITSAlignMille2Module::SensVolMatrix(vid,&m2t[imod]);
138   }
139
140   delete gGeoManager;
141
142   new TGeoManager("SPD","active");
143
144   TGeoMaterial *vacuum = new TGeoMaterial("vacuum",0,0,0);
145   TGeoMedium *none = new TGeoMedium("Vacuum",0,vacuum);
146   TGeoVolume *top = gGeoManager->MakeBox("TOP",none,500,500,500);
147   gGeoManager->SetTopVolume(top);
148
149   TGeoVolume *ladder = gGeoManager->MakeBox("ladder",none,0.6375,0.001/2,3.48);
150
151   Int_t nActive[2]={0,0};
152   for(Int_t imod=0; imod<240; imod++){
153     TGeoRotation *rot  = new TGeoRotation();
154     rot->SetMatrix(m2t[imod].GetRotationMatrix());
155     TGeoCombiTrans *matrix = new TGeoCombiTrans(m2t[imod].GetTranslation()[0],m2t[imod].GetTranslation()[1],m2t[imod].GetTranslation()[2],rot);
156     if((40960-h->GetNrBad(imod))>0) {
157       top->AddNode(ladder,imod,matrix);
158       if(imod<80) nActive[0]++;
159       else nActive[1]++;
160     }
161   }
162
163   printf("  \n\n   Number of Active SPD modules (->Total)  : inner %i (80) outer %i (160) \n\n\n",nActive[0],nActive[1]);
164   gGeoManager->CloseGeometry();
165   top->Draw("ogl");
166   gPad->GetView()->ShowAxis();
167
168 }
169