Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:13:29

0001 
0002 #ifndef MISALIGNMENT_H
0003 #define MISALIGNMENT_H
0004 
0005 #include <cmath>
0006 #include <map>
0007 #include <vector>
0008 
0009 #include <TMath.h>
0010 
0011 vector<float> misalignment(int c)
0012 {
0013     float shift_1 = 0.001, shift_2 = 0.005, shift_3 = 0.01;
0014 
0015     std::map<int, std::vector<float>> Map_MisliagnCase = {{0, {0, 0, 0}},
0016                                                           {1, {shift_1, 0, 0}}, // 10 micron
0017                                                           {2, {-1 * shift_1, 0, 0}},
0018                                                           {3, {shift_2, 0, 0}}, // 50 micron
0019                                                           {4, {-1 * shift_2, 0, 0}},
0020                                                           {5, {shift_3, 0, 0}}, // 100 micron
0021                                                           {6, {-1 * shift_3, 0, 0}},
0022                                                           {7, {0, shift_1, 0}},                 // angle = 0
0023                                                           {8, {0, shift_1, TMath::Pi() / 6.}},  // angle = 30
0024                                                           {9, {0, shift_1, TMath::PiOver4()}},  // angle = 45
0025                                                           {10, {0, shift_1, TMath::Pi() / 3.}}, // angle = 60
0026                                                           {11, {0, shift_1, TMath::Pi() / 2.}}, // angle = 90
0027                                                           {12, {0, shift_1, 3 * TMath::PiOver4()}},
0028                                                           {13, {0, shift_1, 5 * TMath::PiOver4()}},
0029                                                           {14, {0, shift_1, 7 * TMath::PiOver4()}},
0030                                                           {15, {0, shift_2, 0}},                // angle = 0
0031                                                           {16, {0, shift_2, TMath::Pi() / 6.}}, // angle = 30
0032                                                           {17, {0, shift_2, TMath::PiOver4()}}, // angle = 45
0033                                                           {18, {0, shift_2, TMath::Pi() / 3.}}, // angle = 60
0034                                                           {19, {0, shift_2, TMath::Pi() / 2.}}, // angle = 90
0035                                                           {20, {0, shift_2, 3 * TMath::PiOver4()}},
0036                                                           {21, {0, shift_2, 5 * TMath::PiOver4()}},
0037                                                           {22, {0, shift_2, 7 * TMath::PiOver4()}},
0038                                                           {23, {0, shift_3, 0}},                // angle = 0
0039                                                           {24, {0, shift_3, TMath::Pi() / 6.}}, // angle = 30
0040                                                           {25, {0, shift_3, TMath::PiOver4()}}, // angle = 45
0041                                                           {26, {0, shift_3, TMath::Pi() / 3.}}, // angle = 60
0042                                                           {27, {0, shift_3, TMath::Pi() / 2.}}, // angle = 90
0043                                                           {28, {0, shift_3, 3 * TMath::PiOver4()}},
0044                                                           {29, {0, shift_3, 5 * TMath::PiOver4()}},
0045                                                           {30, {0, shift_3, 7 * TMath::PiOver4()}},
0046                                                           {31, {shift_1, shift_1, TMath::PiOver4()}},
0047                                                           {32, {shift_1, shift_2, TMath::PiOver4()}},
0048                                                           {33, {shift_1, shift_3, TMath::PiOver4()}},
0049                                                           {34, {shift_2, shift_1, TMath::PiOver4()}},
0050                                                           {35, {shift_2, shift_2, TMath::PiOver4()}},
0051                                                           {36, {shift_2, shift_3, TMath::PiOver4()}},
0052                                                           {37, {shift_3, shift_1, TMath::PiOver4()}},
0053                                                           {38, {shift_3, shift_2, TMath::PiOver4()}},
0054                                                           {39, {shift_3, shift_3, TMath::PiOver4()}},
0055                                                           // misalignment case for the MVTX position as of April 21 2023: south end gap 1.5mm and north end gap 2.9mm, so the two halfs have an angle
0056                                                           {100, {float(TMath::ATan(0.7 / 604.59))}},
0057                                                           {101, {float(TMath::ATan(1.0 / 604.59))}}};
0058 
0059     return Map_MisliagnCase[c];
0060 }
0061 
0062 // For gap in the two halves of the MVTX
0063 // s is the distance from the center of the clip to the beamline
0064 // g1 is the asymmetric gap for the top half of the stave
0065 // See [TODO: add link to the presentation]
0066 // Rotate, then shift based on the asymmetric gap between the two halves
0067 void UpdatePos_GapTwoHalves(vector<float> &hitpos, float gap_northend, float s, float g1)
0068 {
0069     float NorthEnd_to_StaveMid = 177.5;                                        // mm
0070     float StaveSouthEnd_to_StaveMid = 154.;                                    // mm
0071     float Clips_to_StaveSouthEnd = 273.09;                                     // mm
0072     float zshift = (Clips_to_StaveSouthEnd + StaveSouthEnd_to_StaveMid) / 10.; // cm
0073     float gap_atClips = 1.5;                                                   // mm
0074     float g2 = gap_northend - g1;                                              // mm
0075     float dalpha1_num = g1 - (gap_atClips / 2.);                               // mm, for the top half (x0 > 0)
0076     float dalpha2_num = g2 - (gap_atClips / 2.);                               // mm, for the bottom half (x0 < 0)
0077 
0078     if (gap_northend != gap_atClips)
0079     {
0080         // Rotate
0081         float z0 = hitpos[2] + zshift;
0082         float x0 = hitpos[0];
0083         float l = z0;
0084         float alpha0 = TMath::ATan(x0 / z0);               // In radian
0085         float dalpha1 = TMath::ATan(dalpha1_num / 604.59); // upper half (x0 > 0), in radian
0086         float dalpha2 = TMath::ATan(dalpha2_num / 604.59); // lower half (x0 < 0), in radian
0087         // hitpos[2] = (x0 > 0) ? l * TMath::Cos(alpha0 + dalpha1) - zshift : l * TMath::Cos(alpha0 - dalpha2) - zshift;
0088         // hitpos[0] = (x0 > 0) ? l * TMath::Sin(alpha0 + dalpha1) : l * TMath::Sin(alpha0 - dalpha2);
0089         hitpos[2] = (x0 > 0) ? l * TMath::Cos(dalpha1) - zshift : l * TMath::Cos(dalpha2) - zshift;
0090         hitpos[0] = (x0 > 0) ? x0 + l * TMath::Sin(dalpha1) : x0 + l * TMath::Sin(-1 * dalpha2);
0091         // Shift
0092         hitpos[0] = hitpos[0] + s;
0093     }
0094 }
0095 
0096 #endif