-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakeStaggeredPadsTrk2.C
More file actions
181 lines (138 loc) · 6.19 KB
/
MakeStaggeredPadsTrk2.C
File metadata and controls
181 lines (138 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
void Arc(int n, double a0, double a, double r, double *px, double *py);
TH2Poly* MakeStaggeredPadsTrk2(){
Double_t OuterRadius = 150.00;//mm
Double_t InnerRadius = 50.00;
cout << endl << "Inner and Outer radii are " << InnerRadius
<< " and " << OuterRadius << " mm " << endl;
// Double_t RingWidth = 5.00;
// cout << endl << "We have input Inner Radius " << InnerRadius
// << "mm, outer radius " << OuterRadius << "mm, and RingWidth "
// << RingWidth << "mm" << endl;
// const Int_t nRings = ceil( (OuterRadius-InnerRadius) / RingWidth);
// RingWidth = (OuterRadius-InnerRadius)/nRings;
// cout << "The resulting number of rings is " << nRings <<
// " and the new ring width is " << RingWidth << endl;
const Int_t nRings = 21;
Double_t RingWidth = (OuterRadius-InnerRadius)/nRings;
cout << "The number of rings is " << nRings <<
" and the ring width is " << RingWidth << endl;
Int_t nPads = 122;//120;
cout << "We have input " << nPads << " pads per ring" << endl
<< endl;
const Int_t NP = 4000;
const Int_t nPforB = 2.0 * NP;
TH2Poly *hPolyBins = new TH2Poly();
TH2Poly *hPolyBinAreas = new TH2Poly();
for(Int_t rInc=0; rInc<nRings; rInc++){
// for(Int_t rInc=0; rInc<1; rInc++){
// cout << "We are on radius loop inc " << rInc << endl << endl;
Double_t RIn = InnerRadius + ((rInc*1.00)*RingWidth);
Double_t CircumIn = TMath::Pi() * 2.00 * RIn;
Double_t CPerPadIn = CircumIn/(nPads*1.000);
// nPads = (CircumIn/CPerPadIn);
// CPerPadIn = CircumIn/(nPads*1.00000);
Double_t AngleSubtendedIn = CPerPadIn / RIn;
// To get the angle for each rotation CPerPadIn = theta * RIn
// cout << "Inner radius is " << RIn << "mm, with circumference "
// << CircumIn << "mm, and " << CPerPadIn << "mm length per pad"
// << " and angle subtended per segment " << AngleSubtendedIn
// << endl;
Double_t ROut = InnerRadius + (((rInc+1)*1.00)*RingWidth);
Double_t CircumOut = TMath::Pi() * 2.0 * ROut;
Double_t CPerPadOut = CircumOut/(nPads*1.000);
// nPads = CircumOut/CPerPadOut;
// CPerPadOut = CircumOut/(nPads*1.00000);
Double_t AngleSubtendedOut = CPerPadOut / ROut;
// cout << "Outer radius is " << ROut << "mm, with circumference "
// << CircumOut << "mm, and " << CPerPadOut << "mm length per pad"
// << " and angle subtended per segment " << AngleSubtendedOut
// << endl << endl;
for(Int_t pInc=0; pInc<nPads; pInc++){
// for(Int_t pInc=0; pInc<2; pInc++){
// cout << "On pad " << pInc << endl << endl;
Double_t FirstAngleIn;
if(rInc%2==0)// even
FirstAngleIn = -1.0*AngleSubtendedIn/2.0 + (pInc*1.00)*AngleSubtendedIn;// + (rInc*1.0)*AngleSubtendedIn/2.0;
// cout << "First angle in " << FirstAngleIn << endl;
else
FirstAngleIn = -1.0*AngleSubtendedIn/2.0 + (pInc*1.00)*AngleSubtendedIn + (0.5*2.0*TMath::Pi()/nPads);
Double_t FirstXIn = 0.0 + RIn*TMath::Sin(AngleSubtendedIn);
Double_t FirstYIn = RIn - RIn*(1.0-TMath::Cos(AngleSubtendedIn));;
// cout << "FirstXIn " << FirstXIn << " FirstYIn " << FirstYIn << endl;
// FirstAngleIn = (pInc*1.00) * AngleSubtendedIn;
Double_t pxIn[NP];
Double_t pyIn[NP];
Arc(NP, FirstAngleIn, AngleSubtendedIn, RIn, pxIn, pyIn);
Double_t FirstAngleOut;
if(rInc%2==0)// even
FirstAngleOut = -1.0*AngleSubtendedOut/2.0 + (pInc*1.00)*AngleSubtendedOut;// + (rInc*1.0)*AngleSubtendedOut/2.0;
else
FirstAngleOut = -1.0*AngleSubtendedOut/2.0 + (pInc*1.00)*AngleSubtendedOut+ (0.5*2.0*TMath::Pi()/nPads);
Double_t FirstXOut = 0.0 + ROut*TMath::Sin(AngleSubtendedOut);
Double_t FirstYOut = ROut - ROut*(1.0-TMath::Cos(AngleSubtendedOut));
Double_t pxOut[NP];
Double_t pyOut[NP];
Arc(NP, FirstAngleOut, AngleSubtendedOut, ROut, pxOut, pyOut);
Double_t pxOutReverse[NP];
Double_t pyOutReverse[NP];
for(int pointInc=0; pointInc<NP; pointInc++){
pxOutReverse[pointInc] = pxOut[NP-1-pointInc];
pyOutReverse[pointInc] = pyOut[NP-1-pointInc];
}
Double_t AddPointX1 = pxIn[NP-1] + (pxOutReverse[0] - pxIn[NP-1])/2.0;
Double_t AddPointY1 = pyIn[NP-1] + (pyOutReverse[0] - pyIn[NP-1])/2.0;
Double_t AddPointX2 = pxIn[0] + (pxOutReverse[NP-1] - pxIn[0])/2.0;
Double_t AddPointY2 = pyIn[0] + (pyOutReverse[NP-1] - pyIn[0])/2.0;
Double_t pBinCoordsX[nPforB];//+2];
Double_t pBinCoordsY[nPforB];//+2];
for(int pointInc2=0; pointInc2<NP; pointInc2++){
pBinCoordsX[pointInc2] = pxIn[pointInc2];
pBinCoordsY[pointInc2] = pyIn[pointInc2];
}
for(int pointInc3=NP; pointInc3<2*NP; pointInc3++){
pBinCoordsX[pointInc3] = pxOutReverse[pointInc3-NP];
pBinCoordsY[pointInc3] = pyOutReverse[pointInc3-NP];
}
hPolyBins->AddBin(nPforB,pBinCoordsX,pBinCoordsY);
}//pad loop
}//ring loop
// gStyle->SetPalette(kGreyScale);
// TColor::InvertPalette();
TCanvas *cPolyBins = new TCanvas();
cPolyBins->cd();
hPolyBins->SetName("hPolyBins");
hPolyBins->SetTitle("hPolyBins");
hPolyBins->Draw();
cout << "Number of pads is " << hPolyBins->GetNumberOfBins() << endl;
// // draw bin areas
// TList *bin_list=hPolyBins->GetBins();
// TIter next(bin_list);
// TObject *obj;
// TH2PolyBin *bin;
// double area;
// vector<Double_t> vbinareas;
// while((obj=next())){
// bin = (TH2PolyBin*) obj;
// vbinareas.push_back(bin->GetArea());
// bin->Fill(bin->GetArea());
// }
// // TCanvas *cPolyBinAreas = new TCanvas();
// // cPolyBinAreas->cd();
// hPolyBins->Draw("COLZ");
return hPolyBins;
}//make pads
void Arc(int n, double a0, double a, double r, double *px, double *py) {
// cout << endl;
// cout << "n " << n << " a0 " << a0 << " a " << a << " r " << r << endl;
// cout << "px[0] " << px[0] << " py[0] " << py[0] << endl;
Double_t AngleStep = a/(1.00*n);
// cout << "AngleStep " << AngleStep << endl;
Double_t Angle = a0;
// cout << "Angle " << Angle << endl;
for (int i=0; i<n; i++) {//i started from 0
Angle = a0 + ((i*1.00)*AngleStep);
px[i] = r*TMath::Cos(Angle);//+ px[0];
py[i] = r*TMath::Sin(Angle);//+ py[0];
// cout << "i " << i << " Angle " << Angle << " px[i] " << px[i] << " py[i] " << py[i] << endl;
}
}