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,
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);
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));
203 TGeoVolumeAssembly* modMotherVol,
204 Double_t width, Double_t height,
205 Double_t thickness, Int_t LayerId) {
207 TGeoBBox* lowerIronBox =
new TGeoBBox(Form(
"%s_lowerIron", name), width / 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,
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,
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));
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,
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));
245 TGeoBBox* upperIronBox =
new TGeoBBox(Form(
"%s_upperIron", name), width / 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,
260 LOG(info) <<
"Fiber length set to " <<
fFiberLength <<
" cm";
264 TGeoTube* fiberTube =
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);
274 TGeoRotation* rotU =
new TGeoRotation();
277 TGeoRotation* rotV =
new TGeoRotation();
283 Double_t z0 = -
fiberMatThick / 2 + (layer + 0.5) * (layerThick);
284 for (
int j = 0; j < fNumFibers; ++j) {
286 if (layer % 2 == 1) {
287 if (j == fNumFibers - 1) {
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);
300 Double_t z0 = -
fiberMatThick / 2 + (layer + 0.5) * (layerThick);
301 for (
int j = 0; j < fNumFibers; ++j) {
303 if (layer % 2 == 1) {
304 if (j == fNumFibers - 1) {
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);
322 TGeoMedium* air = gGeoManager->GetMedium(
"air");
323 TGeoMedium* ironMed = gGeoManager->GetMedium(
"iron");
326 TGeoMedium* scintMed = gGeoManager->GetMedium(
"SciFiMat");
333 Double_t totalLength =
fLayers * moduleSpacing;
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);
346 auto ironVol =
new TGeoVolume(
"MTC_iron", ironBox, ironMed);
347 ironVol->SetLineColor(kGray + 1);
348 ironVol->SetTransparency(20);
350 if (
fFieldY != 0) ironVol->SetField(
new TGeoUniformMagField(0,
fFieldY, 0));
353 TGeoVolumeAssembly* sensitiveModule =
new TGeoVolumeAssembly(
"MTC_layer");
360 for (Int_t i = 0; i <
fLayers; i++) {
362 Double_t zPos = -totalLength / 2 + i * moduleSpacing;
366 envVol->AddNode(ironVol, i,
367 new TGeoTranslation(0, 0, zPos +
fIronThick / 2));
377 gGeoManager->GetTopVolume()->AddNode(envVol, 1,
378 new TGeoTranslation(0, 0,
fZCenter));
384 if (gMC->IsTrackEntering()) {
386 fTime = gMC->TrackTime() * 1.0e09;
388 gMC->TrackPosition(
fPos);
389 gMC->TrackMomentum(
fMom);
390 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
391 Int_t vol_local_id = nav->GetCurrentNode()->GetNumber() %
393 Int_t layer_id = nav->GetMother(3)->GetNumber();
394 fVolumeID = 100000000 + layer_id * 1000000 +
401 if (gMC->IsTrackExiting() || gMC->IsTrackStop() ||
402 gMC->IsTrackDisappeared()) {
407 TParticle* p = gMC->GetStack()->GetCurrentTrack();
408 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
409 Int_t pdgCode = p->GetPdgCode();
411 gMC->TrackPosition(Pos);
413 gMC->TrackMomentum(Mom);
417 x = (
fPos.X() + Pos.X()) / 2.;
418 y = (
fPos.Y() + Pos.Y()) / 2.;
419 z = (
fPos.Z() + Pos.Z()) / 2.;
423 z = (
fPos.Z() + Pos.Z()) / 2.;
431 stack->AddPoint(
kMTC);
437 if (gGeoManager->FindVolumeFast(
"SiPMmapVolU") ||
438 gGeoManager->FindVolumeFast(
"SiPMmapVolV")) {
445 LOG(warn) <<
"Number of SiPM channels (" <<
fNSiPMChan
447 <<
"), redistributing across multiple SiPMs";
452 LOG(info) <<
"Increasing number of SiPMs up to " <<
fNSiPMs;
458 LOG(info) <<
"New fNSiPMChan = " <<
fNSiPMChan;
461 Double_t firstChannelX = -
fWidth / 2;
463 LOG(info) <<
"SiPM Overlap parameters:\n"
464 <<
" fLengthScifiMat = " << fLengthScifiMat <<
" cm\n"
465 <<
" fWidthChannel = " << fWidthChannel <<
" cm\n"
469 <<
" fNSiPMs = " <<
fNSiPMs <<
"\n"
470 <<
" fNMats = " <<
fNMats <<
"\n"
471 <<
" fEdge = " << fEdge <<
" cm\n"
472 <<
" firstChannelX = " << firstChannelX <<
" cm";
475 TGeoVolumeAssembly* SiPMmapVolU =
new TGeoVolumeAssembly(
"SiPMmapVolU");
476 TGeoVolumeAssembly* SiPMmapVolV =
new TGeoVolumeAssembly(
"SiPMmapVolV");
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"));
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++) {
506 SiPMmapVolU->AddNode(
507 ChannelVol, 100000 * 0 + imat * 10000 + isipms * 1000 + ichannel,
508 new TGeoTranslation(pos, 0, 0));
510 SiPMmapVolV->AddNode(
511 ChannelVol, 100000 * 1 + imat * 10000 + isipms * 1000 + ichannel,
512 new TGeoTranslation(-pos, 0, 0));
513 pos += fWidthChannel;
539 Int_t station_number =
static_cast<int>(fDetectorID / 1e6) % 100;
540 Int_t plane_type =
static_cast<int>(fDetectorID / 1e5) %
543 TString sID, stationID;
544 sID.Form(
"%i", fDetectorID);
545 stationID.Form(
"%i", station_number);
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");
553 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
555 TGeoNode* W = nav->GetCurrentNode();
556 TGeoBBox* S =
dynamic_cast<TGeoBBox*
>(W->GetVolume()->GetShape());
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]);
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) %
617 stationID.Form(
"%i", station_number);
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;
629 nav->LocalToMaster(loc, glob);
630 A.SetXYZ(glob[0], glob[1], glob[2]);
631 loc[0] = locPosition;
635 nav->LocalToMaster(loc, glob);
636 B.SetXYZ(glob[0], glob[1], glob[2]);
643 LOG(warning) <<
"SiPM mapping already done, skipping.";
646 Float_t fibresRadius = -1;
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);
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();
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();
672 fibre->GetNumber() % 1000000 +
679 for (Int_t nChan = 0; nChan < Nodes->GetEntriesFast();
681 vol =
static_cast<TGeoNode*
>(Nodes->At(nChan));
682 Int_t N = vol->GetNumber();
683 Float_t xcentre = vol->GetMatrix()->GetTranslation()[0];
685 TGeoBBox* B =
dynamic_cast<TGeoBBox*
>(vol->GetVolume()->GetShape());
689 if (TMath::Abs(xcentre - a) > 3 * dSiPM / 2) {
692 Float_t W = area(a, fibresRadius, xcentre - dSiPM, xcentre + dSiPM);
696 std::array<float, 2> Wa;
700 if (sipm_vol == std::string(
"SiPMmapVolU")) {
711 if (sipm_vol == std::string(
"SiPMmapVolU")) {
715 for (
auto [current_fibre, Wa] : it) {
723 for (
auto [nfibre, Wa] : it) {
727 }
else if (sipm_vol == std::string(
"SiPMmapVolV")) {
731 for (
auto [current_fibre, Wa] : it) {
739 for (
auto [nfibre, Wa] : it) {
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)
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)