FairShip
Loading...
Searching...
No Matches
MTCDetector.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5// MTC detector specific headers
6#include "MTCDetector.h"
7
8#include "MTCDetPoint.h"
9#include "ShipDetectorList.h"
10#include "ShipGeoUtil.h"
11#include "ShipStack.h"
12#include "ShipUnit.h"
13
14// ROOT / TGeo headers
15#include "TGeoBBox.h"
16#include "TGeoCompositeShape.h"
17#include "TGeoManager.h"
18#include "TGeoMaterial.h"
19#include "TGeoMedium.h"
20#include "TGeoPara.h"
21#include "TGeoTrd1.h"
22#include "TGeoTrd2.h"
23#include "TGeoTube.h"
24#include "TGeoUniformMagField.h"
25#include "TGeoVolume.h"
26#include "TParticle.h"
27#include "TVector3.h"
28
29// FairROOT headers
30#include "FairGeoBuilder.h"
31#include "FairGeoInterface.h"
32#include "FairGeoLoader.h"
33#include "FairGeoMedia.h"
34#include "FairGeoNode.h"
35#include "FairGeoVolume.h"
36#include "FairRun.h"
37#include "FairRuntimeDb.h"
38#include "FairVolume.h"
39
40// Additional standard headers
41#include "TList.h" // for TListIter, TList (ptr only)
42#include "TObjArray.h" // for TObjArray
43#include "TString.h" // for TString
44#include "TVirtualMC.h"
45
46namespace {
47Double_t ycross(Double_t a, Double_t R, Double_t x) {
48 /*
49 * ycross:
50 * Compute the positive y-coordinate where the vertical line x intersects
51 * the circle of radius R centered at (a, 0). If the line does not intersect
52 * (i.e., (x-a)^2 > R^2), returns -1 as a flag.
53 */
54 Double_t y = -1;
55 Double_t A = R * R - (x - a) * (x - a);
56 if (!(A < 0)) {
57 y = TMath::Sqrt(A);
58 }
59 return y;
60}
61
62Double_t integralSqrt(Double_t ynorm) {
63 /*
64 * integralSqrt:
65 * Compute the analytic integral ∫₀^{ynorm} sqrt(1 - t^2) dt
66 * = ½ [ ynorm * sqrt(1 - ynorm^2) + arcsin(ynorm) ].
67 * This is used for normalizing the circular segment area.
68 */
69 Double_t y =
70 1. / 2. * (ynorm * TMath::Sqrt(1 - ynorm * ynorm) + TMath::ASin(ynorm));
71 return y;
72}
73
74Double_t fraction(Double_t R, Double_t x, Double_t y) {
75 /*
76 * fraction:
77 * Compute the fraction of the circle's total area that lies on one side
78 * of a vertical cut at horizontal distance x from the circle center,
79 * up to the intersection height y = sqrt(R^2 - x^2).
80 * Formula:
81 * F = 2 R^2 ∫₀^{y/R} sqrt(1 - t^2) dt - 2 x y
82 * result = F / (π R^2)
83 */
84 Double_t F = 2 * R * R * (integralSqrt(y / R));
85 F -= (2 * x * y);
86 Double_t result = F / (R * R * TMath::Pi());
87 return result;
88}
89
90Double_t area(Double_t a, Double_t R, Double_t xL, Double_t xR) {
91 /*
92 * area:
93 * Compute the fraction of the full circle (radius R, center at (a,0))
94 * that lies between the vertical boundaries x = xL and x = xR.
95 * Special cases:
96 * - If [xL, xR] fully covers the circle, returns 1.
97 * - If neither boundary intersects the circle, returns -1 (no overlap).
98 * Otherwise, uses ycross() to find intersection heights, fraction()
99 * to get segment areas, and combines them to yield the net fraction.
100 */
101 Double_t fracL = -1;
102 Double_t fracR = -1;
103 if (xL <= a - R && xR >= a + R) {
104 return 1;
105 }
106
107 Double_t leftC = ycross(a, R, xL);
108 Double_t rightC = ycross(a, R, xR);
109 if (leftC < 0 && rightC < 0) {
110 return -1;
111 }
112
113 if (!(rightC < 0)) {
114 fracR = fraction(R, TMath::Abs(xR - a), rightC);
115 }
116 if (!(leftC < 0)) {
117 fracL = fraction(R, TMath::Abs(xL - a), leftC);
118 }
119
120 Double_t theAnswer = 0;
121 if (!(leftC < 0)) {
122 if (xL < a) {
123 theAnswer += 1 - fracL;
124 } else {
125 theAnswer += fracL;
126 }
127 if (!(rightC < 0)) {
128 theAnswer -= 1;
129 }
130 }
131 if (!(rightC < 0)) {
132 if (xR > a) {
133 theAnswer += 1 - fracR;
134 } else {
135 theAnswer += fracR;
136 }
137 }
138 return theAnswer;
139}
140} // namespace
141
143
144MTCDetector::MTCDetector(const char* name, Bool_t Active, const char* /*Title*/,
145 Int_t /*DetId*/)
146 : Detector(name, Active, kMTC) {}
147
149 Double_t width, Double_t height, Double_t fiber_tilt_angle,
150 Double_t iron_thickness, Double_t scifi_thickness,
151 Int_t num_of_agg_channels, Double_t scint_cell_size,
152 Double_t scint_thickness, Int_t number_of_layers, Double_t z_position,
153 Double_t field_strength) {
154 fWidth = width;
155 fHeight = height;
156 fSciFiBendingAngle = fiber_tilt_angle;
157 fIronThick = iron_thickness;
158 fSciFiThick = scifi_thickness;
159 fChannelAggregated = num_of_agg_channels;
160 fScintCellSize = scint_cell_size;
161 fScintThick = scint_thickness;
162 fLayers = number_of_layers;
163 fZCenter = z_position;
164 fFieldY = field_strength;
165 fSciFiActiveX = fWidth - fWidth * tan(fSciFiBendingAngle * TMath::DegToRad());
167}
168
169// Updated SciFi module builder with fiber placements
170void MTCDetector::CreateScintModule(const char* name,
171 TGeoVolumeAssembly* modMotherVol,
172 Double_t z_shift, Double_t width,
173 Double_t height, Double_t thickness,
174 Double_t cellSizeX, Double_t cellSizeY,
175 TGeoMedium* material, Int_t color,
176 Double_t transparency, Int_t LayerId) {
177 modMotherVol->SetLineColor(color);
178 modMotherVol->SetTransparency(transparency);
179 auto scint_volume = new TGeoVolumeAssembly(Form("%s_scint", name));
180 modMotherVol->AddNode(scint_volume, 0, new TGeoTranslation(0, 0, z_shift));
181 auto scint_mat = new TGeoVolumeAssembly(Form("%s_scint_mat", name));
182 scint_volume->AddNode(scint_mat, 0, new TGeoTranslation(0, 0, 0));
183 auto cell = new TGeoBBox(Form("%s_cell", name), cellSizeX / 2, cellSizeY / 2,
184 thickness / 2);
185 auto cellVol = new TGeoVolume(Form("%s_cell", name), cell, material);
186 cellVol->SetLineColor(color);
187 cellVol->SetTransparency(transparency);
188 AddSensitiveVolume(cellVol);
189 Int_t nX = Int_t(width / cellSizeX);
190 Int_t nY = Int_t(height / cellSizeY);
191
192 for (Int_t i = 0; i < nX; i++) {
193 for (Int_t j = 0; j < nY; j++) {
194 Double_t x = -width / 2 + cellSizeX * (i + 0.5);
195 Double_t y = -height / 2 + cellSizeY * (j + 0.5);
196 scint_mat->AddNode(cellVol, 1e8 + 1e6 + 2e5 + 0e4 + i * nY + j,
197 new TGeoTranslation(x, y, 0));
198 }
199 }
200}
201
202void MTCDetector::CreateSciFiModule(const char* name,
203 TGeoVolumeAssembly* modMotherVol,
204 Double_t width, Double_t height,
205 Double_t thickness, Int_t LayerId) {
206 // --- Lower Internal Iron ---
207 TGeoBBox* lowerIronBox = new TGeoBBox(Form("%s_lowerIron", name), width / 2,
208 height / 2, lowerIronThick / 2);
209 TGeoVolume* lowerIronVol = new TGeoVolume(
210 Form("%s_lowerIron", name), lowerIronBox, gGeoManager->GetMedium("iron"));
211 lowerIronVol->SetLineColor(kGray + 1);
212 lowerIronVol->SetTransparency(20);
213 modMotherVol->AddNode(lowerIronVol, 0,
214 new TGeoTranslation(0, 0, zLowerIronInt));
215
216 // --- Lower Epoxy matrix (replaces SciFiMat layer) ---
217 TGeoVolumeAssembly* ScifiVolU =
218 new TGeoVolumeAssembly(Form("%s_scifi_U", name));
219 modMotherVol->AddNode(ScifiVolU, 0, new TGeoTranslation(0, 0, 0));
220 TGeoBBox* epoxyMatBoxU = new TGeoBBox(Form("%s_epoxyMat", name), width / 2,
221 height / 2, fiberMatThick / 2);
222 TGeoVolume* ScifiMatVolU = new TGeoVolume(
223 Form("%s_epoxyMat", name), epoxyMatBoxU, gGeoManager->GetMedium("Epoxy"));
224 ScifiMatVolU->SetLineColor(kYellow - 2);
225 ScifiMatVolU->SetTransparency(30);
226 ScifiMatVolU->SetVisibility(kFALSE);
227 ScifiMatVolU->SetVisDaughters(kFALSE);
228 ScifiVolU->AddNode(ScifiMatVolU, 0, new TGeoTranslation(0, 0, zFiberMat1));
229
230 // --- Upper Epoxy matrix (replaces SciFiMat layer) ---
231 TGeoVolumeAssembly* ScifiVolV =
232 new TGeoVolumeAssembly(Form("%s_scifi_V", name));
233 modMotherVol->AddNode(ScifiVolV, 0, new TGeoTranslation(0, 0, 0));
234 TGeoBBox* epoxyMatBoxV = new TGeoBBox(Form("%s_epoxyMat", name), width / 2,
235 height / 2, fiberMatThick / 2);
236 TGeoVolume* ScifiMatVolV = new TGeoVolume(
237 Form("%s_epoxyMat", name), epoxyMatBoxV, gGeoManager->GetMedium("Epoxy"));
238 ScifiMatVolV->SetLineColor(kYellow - 2);
239 ScifiMatVolV->SetTransparency(30);
240 ScifiMatVolV->SetVisibility(kFALSE);
241 ScifiMatVolV->SetVisDaughters(kFALSE);
242 ScifiVolV->AddNode(ScifiMatVolV, 0, new TGeoTranslation(0, 0, zFiberMat2));
243
244 // --- Upper Internal Iron ---
245 TGeoBBox* upperIronBox = new TGeoBBox(Form("%s_upperIron", name), width / 2,
246 height / 2, upperIronThick / 2);
247 TGeoVolume* upperIronVol = new TGeoVolume(
248 Form("%s_upperIron", name), upperIronBox, gGeoManager->GetMedium("iron"));
249 upperIronVol->SetLineColor(kGray + 1);
250 upperIronVol->SetTransparency(20);
251 modMotherVol->AddNode(upperIronVol, 0,
252 new TGeoTranslation(0, 0, zUpperIronInt));
253
254 // -----------------------------
255 // Now build the fibers inside each Epoxy block:
256 // Common fiber parameters (cm)
257 Double_t layerThick = fiberMatThick / numFiberLayers;
258 fFiberLength = fSciFiActiveY / cos(fSciFiBendingAngle * TMath::DegToRad()) -
259 2 * fFiberRadius * sin(fSciFiBendingAngle * TMath::DegToRad());
260 LOG(info) << "Fiber length set to " << fFiberLength << " cm";
261 Int_t fNumFibers = static_cast<Int_t>(fSciFiActiveX / fFiberPitch);
262
263 // --- Define the SciFi fiber volume ---
264 TGeoTube* fiberTube =
265 new TGeoTube("FiberTube", 0, fFiberRadius, fFiberLength / 2);
266 TGeoVolume* fiberVol =
267 new TGeoVolume("FiberVol", fiberTube, gGeoManager->GetMedium("SciFiMat"));
268 AddSensitiveVolume(fiberVol);
269 fiberVol->SetLineColor(kMagenta);
270 fiberVol->SetTransparency(15);
271 fiberVol->SetVisibility(kFALSE);
272
273 // --- Rotations for U/V fibers ---
274 TGeoRotation* rotU = new TGeoRotation();
275 rotU->RotateY(fSciFiBendingAngle);
276 rotU->RotateX(90.);
277 TGeoRotation* rotV = new TGeoRotation();
278 rotV->RotateY(-fSciFiBendingAngle);
279 rotV->RotateX(90.);
280
281 // --- Place U-fibers inside lower Epoxy ---
282 for (int layer = 0; layer < numFiberLayers; ++layer) {
283 Double_t z0 = -fiberMatThick / 2 + (layer + 0.5) * (layerThick);
284 for (int j = 0; j < fNumFibers; ++j) {
285 Double_t x0 = -fSciFiActiveX / 2 + (j + 0.5) * fFiberPitch;
286 if (layer % 2 == 1) {
287 if (j == fNumFibers - 1) {
288 continue; // Skip the last layer for odd layers
289 }
290 x0 += fFiberPitch / 2;
291 }
292 TGeoCombiTrans* ct = new TGeoCombiTrans("", x0, 0, z0, rotU);
293 Int_t copyNo = 100000000 + 1000000 + 0 * 100000 + layer * 10000 + j;
294 ScifiMatVolU->AddNode(fiberVol, copyNo, ct);
295 }
296 }
297
298 // --- Place V-fibers inside upper Epoxy ---
299 for (int layer = 0; layer < numFiberLayers; ++layer) {
300 Double_t z0 = -fiberMatThick / 2 + (layer + 0.5) * (layerThick);
301 for (int j = 0; j < fNumFibers; ++j) {
302 Double_t x0 = -fSciFiActiveX / 2 + (j + 0.5) * fFiberPitch;
303 if (layer % 2 == 1) {
304 if (j == fNumFibers - 1) {
305 continue; // Skip the last layer for odd layers
306 }
307 x0 += fFiberPitch / 2;
308 }
309 TGeoCombiTrans* ct = new TGeoCombiTrans("", x0, 0, z0, rotV);
310 Int_t copyNo = 100000000 + 1000000 + 1 * 100000 + layer * 10000 + j;
311 ScifiMatVolV->AddNode(fiberVol, copyNo, ct);
312 }
313 }
314}
315
317 // Initialize media (using FairROOT's interface)
318 ShipGeo::InitMedium("SciFiMat");
319 ShipGeo::InitMedium("Epoxy");
320 ShipGeo::InitMedium("air");
321 ShipGeo::InitMedium("iron");
322 TGeoMedium* air = gGeoManager->GetMedium("air");
323 TGeoMedium* ironMed = gGeoManager->GetMedium("iron");
324 // For the scintillator, you may use the same medium as SciFiMat or another if
325 // defined.
326 TGeoMedium* scintMed = gGeoManager->GetMedium("SciFiMat");
327 ShipGeo::InitMedium("silicon");
328
329 // Define the module spacing based on three sublayers:
330 // fIronThick (outer iron), fSciFiThick (SciFi module/fiber module),
331 // fScintThick (scintillator)
332 Double_t moduleSpacing = fIronThick + fSciFiThick + fScintThick;
333 Double_t totalLength = fLayers * moduleSpacing;
334
335 // --- Create an envelope volume for the detector (green, semi-transparent)
336 // ---
337 auto envBox =
338 new TGeoBBox("MTC_env", fWidth / 2, fHeight / 2, totalLength / 2);
339 auto envVol = new TGeoVolume("MTC", envBox, air);
340 envVol->SetLineColor(kGreen);
341 envVol->SetTransparency(50);
342
343 // --- Outer Iron Layer (gray) ---
344 auto ironBox =
345 new TGeoBBox("MTC_iron", fWidth / 2, fHeight / 2, fIronThick / 2);
346 auto ironVol = new TGeoVolume("MTC_iron", ironBox, ironMed);
347 ironVol->SetLineColor(kGray + 1);
348 ironVol->SetTransparency(20);
349 // Enable the field in the iron volume
350 if (fFieldY != 0) ironVol->SetField(new TGeoUniformMagField(0, fFieldY, 0));
351
352 // --- Assemble the layers into the envelope ---
353 TGeoVolumeAssembly* sensitiveModule = new TGeoVolumeAssembly("MTC_layer");
354 // Define a layer for the SciFi module
355 CreateSciFiModule("MTC", sensitiveModule, fWidth, fHeight, fSciFiThick, 1);
356 CreateScintModule("MTC", sensitiveModule, fSciFiThick / 2 + fScintThick / 2,
358 fScintCellSize, scintMed, kAzure + 7, 30, 1);
359
360 for (Int_t i = 0; i < fLayers; i++) {
361 // Compute the center position (z) for the current module
362 Double_t zPos = -totalLength / 2 + i * moduleSpacing;
363
364 // Place the Outer Iron layer (shifted down by half the SciFi+scint
365 // thickness)
366 envVol->AddNode(ironVol, i,
367 new TGeoTranslation(0, 0, zPos + fIronThick / 2));
368 // Place the sensitive module (SciFi + Scintillator) at the correct z
369 // position
370 envVol->AddNode(
371 sensitiveModule, i,
372 new TGeoTranslation(0, 0, zPos + fIronThick + fSciFiThick / 2));
373 }
374
375 // Finally, add the envelope to the top volume with the global z offset
376 // fZCenter
377 gGeoManager->GetTopVolume()->AddNode(envVol, 1,
378 new TGeoTranslation(0, 0, fZCenter));
379}
380
381Bool_t MTCDetector::ProcessHits(FairVolume* vol) {
383 // Set parameters at entrance of volume. Reset ELoss.
384 if (gMC->IsTrackEntering()) {
385 fELoss = 0.;
386 fTime = gMC->TrackTime() * 1.0e09;
387 fLength = gMC->TrackLength();
388 gMC->TrackPosition(fPos);
389 gMC->TrackMomentum(fMom);
390 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
391 Int_t vol_local_id = nav->GetCurrentNode()->GetNumber() %
392 1000000; // Local ID within the mat or scint.
393 Int_t layer_id = nav->GetMother(3)->GetNumber(); // Get layer ID.
394 fVolumeID = 100000000 + layer_id * 1000000 +
395 vol_local_id; // 1e8 + layer_id * 1e6 + fibre_local_id;
396 }
397 // Sum energy loss for all steps in the active volume
398 fELoss += gMC->Edep();
399
400 // Create vetoPoint when exiting active volume
401 if (gMC->IsTrackExiting() || gMC->IsTrackStop() ||
402 gMC->IsTrackDisappeared()) {
403 if (fELoss == 0.) {
404 return kFALSE;
405 } // if you do not want hits with zero eloss
406
407 TParticle* p = gMC->GetStack()->GetCurrentTrack();
408 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
409 Int_t pdgCode = p->GetPdgCode();
410 TLorentzVector Pos;
411 gMC->TrackPosition(Pos);
412 TLorentzVector Mom;
413 gMC->TrackMomentum(Mom);
414 Double_t x, y, z;
415 // 0 and 1 are for SciFi planes, 2 is for scintillating tiles
416 if ((fVolumeID / 100000) % 10 == 2) {
417 x = (fPos.X() + Pos.X()) / 2.;
418 y = (fPos.Y() + Pos.Y()) / 2.;
419 z = (fPos.Z() + Pos.Z()) / 2.;
420 } else {
421 x = fPos.X();
422 y = fPos.Y();
423 z = (fPos.Z() + Pos.Z()) / 2.;
424 }
425
426 AddHit(fTrackID, fVolumeID, TVector3(x, y, z),
427 TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), // entrance momentum
428 fTime, fLength, fELoss, pdgCode);
429 // hit->Print();
430 ShipStack* stack = dynamic_cast<ShipStack*>(gMC->GetStack());
431 stack->AddPoint(kMTC);
432 }
433 return kTRUE;
434}
435
437 if (gGeoManager->FindVolumeFast("SiPMmapVolU") ||
438 gGeoManager->FindVolumeFast("SiPMmapVolV")) {
439 return;
440 }
441 Double_t fLengthScifiMat = fSciFiActiveY;
442 Double_t fWidthChannel = fFiberPitch * fChannelAggregated;
443 fNSiPMChan = std::ceil(fWidth / fWidthChannel);
445 LOG(warn) << "Number of SiPM channels (" << fNSiPMChan
446 << ") exceeds maximum per SiPM (" << kMaxChannelsPerSiPM
447 << "), redistributing across multiple SiPMs";
448
449 fNSiPMs = static_cast<int>(
450 std::ceil(static_cast<double>(fNSiPMChan) / kMaxChannelsPerSiPM));
451
452 LOG(info) << "Increasing number of SiPMs up to " << fNSiPMs;
453
454 // define redistribution of channels among SiPMs
455 fNSiPMChan =
456 static_cast<int>(std::ceil(fNSiPMChan / static_cast<float>(fNSiPMs)));
457
458 LOG(info) << "New fNSiPMChan = " << fNSiPMChan;
459 }
460 Double_t fEdge = (fWidth - fNSiPMs * fNSiPMChan * fWidthChannel) / 2;
461 Double_t firstChannelX = -fWidth / 2;
462
463 LOG(info) << "SiPM Overlap parameters:\n"
464 << " fLengthScifiMat = " << fLengthScifiMat << " cm\n"
465 << " fWidthChannel = " << fWidthChannel << " cm\n"
466 << " fFiberPitch = " << fFiberPitch << " cm\n"
467 << " fChannelAggregated = " << fChannelAggregated << "\n"
468 << " fNSiPMChan = " << fNSiPMChan << "\n"
469 << " fNSiPMs = " << fNSiPMs << "\n"
470 << " fNMats = " << fNMats << "\n"
471 << " fEdge = " << fEdge << " cm\n"
472 << " firstChannelX = " << firstChannelX << " cm";
473 // Contains all plane SiPMs, defined for horizontal fiber plane
474 // To obtain SiPM map for vertical fiber plane rotate by 90 degrees around Z
475 TGeoVolumeAssembly* SiPMmapVolU = new TGeoVolumeAssembly("SiPMmapVolU");
476 TGeoVolumeAssembly* SiPMmapVolV = new TGeoVolumeAssembly("SiPMmapVolV");
477
478 TGeoBBox* ChannelVol_box = new TGeoBBox(
479 "ChannelVol", fWidthChannel / 2, fLengthScifiMat / 2, fiberMatThick / 2);
480 TGeoVolume* ChannelVol = new TGeoVolume("ChannelVol", ChannelVol_box,
481 gGeoManager->GetMedium("silicon"));
482 /*
483 Example of fiberID: 123051820, where:
484 - 1: MTC unique ID
485 - 23: layer number
486 - 0: station type (0 for +5 degrees, 1 for -5 degrees, 2 for scint plane)
487 - 5: z-layer number (0-5)
488 - 1820: local fibre ID within the station
489 Example of SiPM global channel (what is seen in the output file): 123001123,
490 where:
491 - 1: MTC unique ID
492 - 23: layer number
493 - 0: station type (0 for +5 degrees, 1 for -5 degrees)
494 - 0: mat number (only 0 by June 2025)
495 - 1: SiPM number (automatically assigned based on fibre aggregation
496 settings)
497 - 123: number of the SiPM channel (0-N). The channel number depends on the
498 fibre aggregation setting.
499 */
500
501 Double_t pos = fEdge + firstChannelX;
502 for (int imat = 0; imat < fNMats; imat++) {
503 for (int isipms = 0; isipms < fNSiPMs; isipms++) {
504 for (int ichannel = 0; ichannel < fNSiPMChan; ichannel++) {
505 // +5 degrees
506 SiPMmapVolU->AddNode(
507 ChannelVol, 100000 * 0 + imat * 10000 + isipms * 1000 + ichannel,
508 new TGeoTranslation(pos, 0, 0));
509 // -5 degrees
510 SiPMmapVolV->AddNode(
511 ChannelVol, 100000 * 1 + imat * 10000 + isipms * 1000 + ichannel,
512 new TGeoTranslation(-pos, 0, 0));
513 pos += fWidthChannel;
514 }
515 }
516 }
517}
518
519void MTCDetector::GetPosition(Int_t fDetectorID, TVector3& A, TVector3& B) {
520 /*
521 Example of fiberID: 123051820, where:
522 - 1: MTC unique ID
523 - 23: layer number
524 - 0: station type (0 for +5 degrees, 1 for -5 degrees, 2 for scint plane)
525 - 5: z-layer number (0-5)
526 - 1820: local fibre ID within the station
527 Example of SiPM global channel (what is seen in the output file): 123001123,
528 where:
529 - 1: MTC unique ID
530 - 23: layer number
531 - 0: station type (0 for +5 degrees, 1 for -5 degrees)
532 - 0: mat number (only 0 by June 2025)
533 - 1: SiPM number (automatically assigned based on fibre aggregation
534 settings)
535 - 123: number of the SiPM channel (0-N). The channel number depends on the
536 fibre aggregation setting.
537 */
538
539 Int_t station_number = static_cast<int>(fDetectorID / 1e6) % 100;
540 Int_t plane_type = static_cast<int>(fDetectorID / 1e5) %
541 10; // 0 for horizontal, 1 for vertical
542
543 TString sID, stationID;
544 sID.Form("%i", fDetectorID);
545 stationID.Form("%i", station_number);
546 // Basic hierarchy:
547 // /cave/MTC_1/MTC_layer_1/MTC_sciFi_mother_1/MTC_sciFi_epoxyMat_U_1/FiberVol_101010187
548 TString path =
549 "/cave/MTC_1/MTC_layer_" + stationID +
550 ((plane_type == 0) ? "/MTC_scifi_U_0/MTC_epoxyMat_0/FiberVol_1010"
551 : "/MTC_scifi_V_0/MTC_epoxyMat_0/FiberVol_1011");
552 path += sID(4, 5);
553 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
554 nav->cd(path);
555 TGeoNode* W = nav->GetCurrentNode();
556 TGeoBBox* S = dynamic_cast<TGeoBBox*>(W->GetVolume()->GetShape());
557
558 Double_t top[3] = {0, 0, (S->GetDZ())};
559 Double_t bot[3] = {0, 0, -(S->GetDZ())};
560 Double_t Gtop[3], Gbot[3];
561 nav->LocalToMaster(top, Gtop);
562 nav->LocalToMaster(bot, Gbot);
563 A.SetXYZ(Gtop[0], Gtop[1], Gtop[2]);
564 B.SetXYZ(Gbot[0], Gbot[1], Gbot[2]);
565}
566
567TVector3 MTCDetector::GetLocalPos(Int_t fDetectorID, TVector3* glob) {
568 Int_t station_number = static_cast<int>(fDetectorID / 1e6) % 100;
569 Int_t plane_type = static_cast<int>(fDetectorID / 1e5) %
570 10; // 0 for horizontal, 1 for vertical
571
572 TString sID, stationID;
573 sID.Form("%i", fDetectorID);
574 stationID.Form("%i", station_number);
575 // Basic hierarchy:
576 // /cave/MTC_1/MTC_layer_1/MTC_sciFi_mother_1/MTC_sciFi_epoxyMat_U_1/FiberVol_101010187
577 TString path = "/cave/MTC_1/MTC_layer_" + stationID +
578 ((plane_type == 0) ? "/MTC_scifi_U_0" : "/MTC_scifi_V_0");
579 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
580 nav->cd(path);
581 Double_t aglob[3];
582 Double_t aloc[3];
583 glob->GetXYZ(aglob);
584 nav->MasterToLocal(aglob, aloc);
585 return TVector3(aloc[0], aloc[1], aloc[2]);
586}
587
588void MTCDetector::GetSiPMPosition(Int_t SiPMChan, TVector3& A, TVector3& B) {
589 /* STMRFFF
590 Example of fiberID: 123051820, where:
591 - 1: MTC unique ID
592 - 23: layer number
593 - 0: station type (0 for +5 degrees, 1 for -5 degrees, 2 for scint
594 plane)
595 - 5: z-layer number (0-5)
596 - 1820: local fibre ID within the station
597 Example of SiPM global channel (what is seen in the output file):
598 123001123, where:
599 - 1: MTC unique ID
600 - 23: layer number
601 - 0: station type (0 for +5 degrees, 1 for -5 degrees)
602 - 0: mat number (only 0 by June 2025)
603 - 1: SiPM number (automatically assigned based on fibre aggregation
604 settings)
605 - 123: number of the SiPM channel (0-N). The channel number depends on
606 the fibre aggregation setting.
607 */
608 Int_t locNumber = SiPMChan % 1000000;
609 Int_t station_number = static_cast<int>(SiPMChan / 1e6) % 100;
610 Int_t plane_type = static_cast<int>(SiPMChan / 1e5) %
611 10; // 0 for horizontal, 1 for vertical
612 Float_t locPosition;
613 locPosition =
614 (plane_type == 0 ? SiPMPos_U
615 : SiPMPos_V)[locNumber]; // local position in U/V plane
616 TString stationID;
617 stationID.Form("%i", station_number);
618
619 Double_t loc[3] = {0, 0, 0};
620 TString path = "/cave/MTC_1/MTC_layer_" + stationID +
621 ((plane_type == 0) ? "/MTC_scifi_U_0/MTC_epoxyMat_0"
622 : "/MTC_scifi_V_0/MTC_epoxyMat_0");
623 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
624 Double_t glob[3] = {0, 0, 0};
625 loc[0] = locPosition;
626 loc[1] = -fFiberLength / 2;
627 loc[2] = 7.47;
628 nav->cd(path);
629 nav->LocalToMaster(loc, glob);
630 A.SetXYZ(glob[0], glob[1], glob[2]);
631 loc[0] = locPosition;
632 loc[1] = fFiberLength / 2;
633 loc[2] = 7.47; // hardcoded for now, for some reason required to get the
634 // correct local position
635 nav->LocalToMaster(loc, glob);
636 B.SetXYZ(glob[0], glob[1], glob[2]);
637}
638
640 // check if containers are already filled
641 if (!fibresSiPM_U.empty() || !fibresSiPM_V.empty() || !SiPMPos_U.empty() ||
642 !SiPMPos_V.empty()) {
643 LOG(warning) << "SiPM mapping already done, skipping.";
644 return;
645 }
646 Float_t fibresRadius = -1;
647 Float_t dSiPM = -1;
648 TGeoNode* vol;
649 TGeoNode* fibre;
650 SiPMOverlap();
651 // Loop over both U and V planes
652 std::vector<std::pair<const char*, const char*>> sipm_planes = {
653 {"SiPMmapVolU", "MTC_scifi_U"}, {"SiPMmapVolV", "MTC_scifi_V"}};
654 for (const auto& [sipm_vol, scifi_vol] : sipm_planes) {
655 auto sipm = gGeoManager->FindVolumeFast(sipm_vol);
656 if (!sipm) continue;
657 TObjArray* Nodes = sipm->GetNodes();
658 auto plane = gGeoManager->FindVolumeFast(scifi_vol);
659 if (!plane) continue;
660 for (int imat = 0; imat < plane->GetNodes()->GetEntries(); imat++) {
661 auto mat = static_cast<TGeoNode*>(plane->GetNodes()->At(imat));
662 auto vmat = mat->GetVolume();
663 for (int ifibre = 0; ifibre < vmat->GetNodes()->GetEntriesFast();
664 ifibre++) {
665 fibre = static_cast<TGeoNode*>(vmat->GetNodes()->At(ifibre));
666 if (fibresRadius < 0) {
667 auto tmp = fibre->GetVolume()->GetShape();
668 auto S = dynamic_cast<TGeoBBox*>(tmp);
669 fibresRadius = S->GetDX();
670 }
671 Int_t fID =
672 fibre->GetNumber() % 1000000 +
673 imat * 1e4; // local fibre number, global fibre number = SO+fID
674 TVector3 Atop, Bbot;
675 GetPosition(fibre->GetNumber(), Atop, Bbot);
676 Float_t a = Bbot[0];
677
678 // check for overlap with any of the SiPM channels in the same mat
679 for (Int_t nChan = 0; nChan < Nodes->GetEntriesFast();
680 nChan++) { // 7 SiPMs total times 128 channels
681 vol = static_cast<TGeoNode*>(Nodes->At(nChan));
682 Int_t N = vol->GetNumber();
683 Float_t xcentre = vol->GetMatrix()->GetTranslation()[0];
684 if (dSiPM < 0) {
685 TGeoBBox* B = dynamic_cast<TGeoBBox*>(vol->GetVolume()->GetShape());
686 dSiPM = B->GetDX();
687 }
688
689 if (TMath::Abs(xcentre - a) > 3 * dSiPM / 2) {
690 continue;
691 } // no need to check further
692 Float_t W = area(a, fibresRadius, xcentre - dSiPM, xcentre + dSiPM);
693 if (W < 0) {
694 continue;
695 }
696 std::array<float, 2> Wa;
697 Wa[0] = W;
698 Wa[1] = a;
699
700 if (sipm_vol == std::string("SiPMmapVolU")) {
701 fibresSiPM_U[N][fID] = Wa;
702 } else {
703 fibresSiPM_V[N][fID] = Wa;
704 }
705 }
706 }
707 }
708 // calculate also local SiPM positions based on fibre positions and their
709 // fraction probably an overkill, maximum difference between weighted
710 // average and central position < 6 micron.
711 if (sipm_vol == std::string("SiPMmapVolU")) {
712 for (auto [N, it] : fibresSiPM_U) {
713 Float_t m = 0;
714 Float_t w = 0;
715 for (auto [current_fibre, Wa] : it) {
716 m += Wa[0] * Wa[1];
717 w += Wa[0];
718 }
719 SiPMPos_U[N] = m / w;
720 }
721 // make inverse mapping, which fibre is associated to which SiPMs
722 for (auto [N, it] : fibresSiPM_U) {
723 for (auto [nfibre, Wa] : it) {
724 siPMFibres_U[nfibre][N] = Wa;
725 }
726 }
727 } else if (sipm_vol == std::string("SiPMmapVolV")) {
728 for (auto [N, it] : fibresSiPM_V) {
729 Float_t m = 0;
730 Float_t w = 0;
731 for (auto [current_fibre, Wa] : it) {
732 m += Wa[0] * Wa[1];
733 w += Wa[0];
734 }
735 SiPMPos_V[N] = m / w;
736 }
737 // make inverse mapping, which fibre is associated to which SiPMs
738 for (auto [N, it] : fibresSiPM_V) {
739 for (auto [nfibre, Wa] : it) {
740 siPMFibres_V[nfibre][N] = Wa;
741 }
742 }
743 }
744 }
745}
constexpr Double_t m
@ kMTC
Double_t fIronThick
Definition MTCDetector.h:78
std::map< Int_t, std::map< Int_t, std::array< float, 2 > > > siPMFibres_V
mapping of fibres to SiPM channels
std::map< Int_t, std::map< Int_t, std::array< float, 2 > > > fibresSiPM_V
inverse mapping
Double_t fSciFiBendingAngle
Definition MTCDetector.h:77
std::map< Int_t, std::map< Int_t, std::array< float, 2 > > > fibresSiPM_U
static constexpr Int_t kMaxChannelsPerSiPM
Double_t fFiberLength
Definition MTCDetector.h:87
void SiPMmapping()
Int_t fChannelAggregated
Double_t fWidth
Definition MTCDetector.h:73
void ConstructGeometry() override
Int_t numFiberLayers
Double_t fSciFiThick
Definition MTCDetector.h:79
Double_t fHeight
Definition MTCDetector.h:74
Double_t upperIronThick
Definition MTCDetector.h:93
TVector3 GetLocalPos(Int_t fDetectorID, TVector3 *glob)
Double_t fScintCellSize
Definition MTCDetector.h:81
void SetMTCParameters(Double_t width, Double_t height, Double_t fiber_tilt_angle, Double_t iron_thickness, Double_t scifi_thickness, Int_t num_of_agg_channels, Double_t scint_cell_size, Double_t scint_thickness, Int_t number_of_layers, Double_t z_position, Double_t field_strength)
Double_t zUpperIronInt
Definition MTCDetector.h:98
virtual void CreateScintModule(const char *name, TGeoVolumeAssembly *modMotherVol, Double_t z_shift, Double_t width, Double_t height, Double_t thickness, Double_t cellSizeX, Double_t cellSizeY, TGeoMedium *material, Int_t color, Double_t transparency, Int_t LayerId)
virtual void CreateSciFiModule(const char *name, TGeoVolumeAssembly *modMotherVol, Double_t width, Double_t height, Double_t thickness, Int_t LayerId)
Double_t lowerIronThick
Definition MTCDetector.h:91
Double_t fiberMatThick
Definition MTCDetector.h:86
Double_t fSciFiActiveY
Definition MTCDetector.h:76
Bool_t ProcessHits(FairVolume *vol=nullptr) override
Double_t fScintThick
Definition MTCDetector.h:80
Double_t zLowerIronInt
Definition MTCDetector.h:94
Double_t fZCenter
Definition MTCDetector.h:83
void GetSiPMPosition(Int_t SiPMChan, TVector3 &A, TVector3 &B)
Int_t fLayers
Definition MTCDetector.h:82
Double_t fFieldY
Definition MTCDetector.h:84
Double_t fFiberRadius
Definition MTCDetector.h:99
Double_t fSciFiActiveX
Definition MTCDetector.h:75
std::map< Int_t, float > SiPMPos_U
inverse mapping
Double_t zFiberMat2
Definition MTCDetector.h:97
Int_t fNSiPMChan
Double_t fFiberPitch
Definition MTCDetector.h:88
Double_t zFiberMat1
Definition MTCDetector.h:95
std::map< Int_t, float > SiPMPos_V
virtual void SiPMOverlap()
std::map< Int_t, std::map< Int_t, std::array< float, 2 > > > siPMFibres_U
mapping of fibres to SiPM channels
void GetPosition(Int_t fDetectorID, TVector3 &vLeft, TVector3 &vRight)
MTCDetPoint * AddHit(Args &&... args)
Definition Detector.h:38
Int_t InitMedium(const char *name)
Definition ShipGeoUtil.h:22