|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +#include <TCanvas.h> |
| 13 | +#include <TGraph.h> |
| 14 | +#include <TArc.h> |
| 15 | +#include <TH2F.h> |
| 16 | +#include <TMath.h> |
| 17 | +#include <TLatex.h> |
| 18 | +#include <TStyle.h> |
| 19 | +#include <algorithm> |
| 20 | +#include <cmath> |
| 21 | + |
| 22 | +void defineIOTOFGeo(const double rAvg = 21, // cm, average radius of the layer (used for stave size calculations) |
| 23 | + const int nStaves = 24, // Number of staves |
| 24 | + const double staveWidth = 5.42, // cm, Stave width (arc length at avg radius at 0 degrees) |
| 25 | + const double staveHeightX2X0 = 0.02, // Stave height (radial at 0 degrees) |
| 26 | + const double staveTilt = 10 // Stave tilt angle in degrees |
| 27 | +) |
| 28 | +{ |
| 29 | + const double Si_X0 = 9.5f; // cm, radiation length of silicon |
| 30 | + const double staveHeight = staveHeightX2X0 * Si_X0; |
| 31 | + |
| 32 | + // 1. Define inner and outer radii for the disk. |
| 33 | + // The radius corresponds to the distance of the center of the stave to the origin |
| 34 | + const double rInner = rAvg - staveHeight / 2.0; |
| 35 | + const double rOuter = rAvg + staveHeight / 2.0; |
| 36 | + |
| 37 | + const double alpha = staveTilt * TMath::DegToRad(); // Tilt angle in radians |
| 38 | + const double H = staveHeight; |
| 39 | + const double W = staveWidth; |
| 40 | + |
| 41 | + // 2. Analytical calculation of Inscribed and Outscribed Radii |
| 42 | + // We project the global origin (0,0) into the local, unrotated coordinate |
| 43 | + // system of a single stave centered at (0,0). |
| 44 | + const double u0 = -rAvg * TMath::Cos(alpha); |
| 45 | + const double v0 = rAvg * TMath::Sin(alpha); |
| 46 | + |
| 47 | + // Inscribed Radius: Distance to the closest point on the stave rectangle |
| 48 | + const double uc = std::max(-H / 2.0, std::min(H / 2.0, u0)); |
| 49 | + const double vc = std::max(-W / 2.0, std::min(W / 2.0, v0)); |
| 50 | + const double rInscribed = TMath::Sqrt((uc - u0) * (uc - u0) + (vc - v0) * (vc - v0)); |
| 51 | + |
| 52 | + // Outscribed Radius: Maximum distance to one of the 4 corners |
| 53 | + double rOutscribed = 0; |
| 54 | + const double uCorners[4] = {-H / 2.0, H / 2.0, H / 2.0, -H / 2.0}; |
| 55 | + const double vCorners[4] = {-W / 2.0, -W / 2.0, W / 2.0, W / 2.0}; |
| 56 | + for (int i = 0; i < 4; ++i) { |
| 57 | + const double dist = std::hypot(uCorners[i] - u0, vCorners[i] - v0); |
| 58 | + if (dist > rOutscribed) { |
| 59 | + rOutscribed = dist; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + // 3. Visualization |
| 64 | + new TCanvas("DiskWithStaves", "Disk with Staves", 800, 800); |
| 65 | + gPad->SetGrid(); |
| 66 | + gPad->SetLeftMargin(0.15); |
| 67 | + gPad->SetBottomMargin(0.15); |
| 68 | + gPad->SetRightMargin(0.05); |
| 69 | + gPad->SetTopMargin(0.05); |
| 70 | + |
| 71 | + const double maxR = std::max(rOuter, rOutscribed) * 1.5; |
| 72 | + gPad->DrawFrame(-maxR, -maxR, maxR, maxR, ";X (cm);Y (cm)"); |
| 73 | + |
| 74 | + // Draw Inner and Outer Disk Radii (Reference) |
| 75 | + TArc* arcInner = new TArc(0, 0, rInner); |
| 76 | + arcInner->SetLineStyle(2); |
| 77 | + arcInner->SetLineColor(kGray + 1); |
| 78 | + arcInner->SetFillStyle(0); |
| 79 | + arcInner->Draw("same"); |
| 80 | + |
| 81 | + TArc* arcOuter = new TArc(0, 0, rOuter); |
| 82 | + arcOuter->SetLineStyle(2); |
| 83 | + arcOuter->SetLineColor(kGray + 1); |
| 84 | + arcOuter->SetFillStyle(0); |
| 85 | + arcOuter->Draw("same"); |
| 86 | + |
| 87 | + // Draw Inscribed and Outscribed circles |
| 88 | + TArc* arcInscribed = new TArc(0, 0, rInscribed); |
| 89 | + arcInscribed->SetLineColor(kBlue); |
| 90 | + arcInscribed->SetLineWidth(2); |
| 91 | + arcInscribed->SetFillStyle(0); |
| 92 | + arcInscribed->Draw("same"); |
| 93 | + |
| 94 | + TArc* arcOutscribed = new TArc(0, 0, rOutscribed); |
| 95 | + arcOutscribed->SetLineColor(kRed); |
| 96 | + arcOutscribed->SetLineWidth(2); |
| 97 | + arcOutscribed->SetFillStyle(0); |
| 98 | + arcOutscribed->Draw("same"); |
| 99 | + |
| 100 | + // Generate and Draw Staves |
| 101 | + for (int i = 0; i < nStaves; ++i) { |
| 102 | + double phi = i * TMath::TwoPi() / nStaves; |
| 103 | + double xPts[5], yPts[5]; |
| 104 | + for (int j = 0; j < 4; ++j) { |
| 105 | + double u = uCorners[j]; |
| 106 | + double v = vCorners[j]; |
| 107 | + // Apply stave tilt (alpha) around its own center |
| 108 | + double uRot = u * TMath::Cos(alpha) - v * TMath::Sin(alpha); |
| 109 | + double vRot = u * TMath::Sin(alpha) + v * TMath::Cos(alpha); |
| 110 | + // Move stave to rAvg and apply azimuthal rotation (phi) |
| 111 | + double x_phi0 = rAvg + uRot; |
| 112 | + double y_phi0 = vRot; |
| 113 | + xPts[j] = x_phi0 * TMath::Cos(phi) - y_phi0 * TMath::Sin(phi); |
| 114 | + yPts[j] = x_phi0 * TMath::Sin(phi) + y_phi0 * TMath::Cos(phi); |
| 115 | + } |
| 116 | + // Close the geometric polygon |
| 117 | + xPts[4] = xPts[0]; |
| 118 | + yPts[4] = yPts[0]; |
| 119 | + TGraph* gStave = new TGraph(5, xPts, yPts); |
| 120 | + gStave->SetFillColorAlpha(kGreen + 2, 0.4); |
| 121 | + gStave->SetLineColor(kBlack); |
| 122 | + gStave->SetLineWidth(1); |
| 123 | + gStave->Draw("f same"); // Fill |
| 124 | + gStave->Draw("l same"); // Outline |
| 125 | + } |
| 126 | + |
| 127 | + // 7. Add Legend / Parameter Text |
| 128 | + TLatex* tex = new TLatex(); |
| 129 | + tex->SetNDC(); |
| 130 | + tex->SetTextSize(0.028); |
| 131 | + tex->SetTextFont(42); |
| 132 | + tex->SetTextColor(kBlack); |
| 133 | + tex->DrawLatex(0.12, 0.88, Form("R_{inner} = %.1f, R_{outer} = %.1f", rInner, rOuter)); |
| 134 | + tex->DrawLatex(0.12, 0.84, Form("Staves: %d, Tilt: %.1f#circ", nStaves, staveTilt)); |
| 135 | + tex->SetTextColor(kBlue); |
| 136 | + tex->DrawLatex(0.12, 0.80, Form("Inscribed Radius = %.2f", rInscribed)); |
| 137 | + tex->SetTextColor(kRed); |
| 138 | + tex->DrawLatex(0.12, 0.76, Form("Outscribed Radius = %.2f", rOutscribed)); |
| 139 | +} |
0 commit comments