58 if (gMC->IsTrackEntering()) {
60 fTime = gMC->TrackTime() * 1.0e09;
62 gMC->TrackPosition(
fPos);
63 gMC->TrackMomentum(
fMom);
72 if (gMC->IsTrackExiting() || gMC->IsTrackStop() ||
73 gMC->IsTrackDisappeared()) {
77 TParticle* p = gMC->GetStack()->GetCurrentTrack();
78 Int_t pdgCode = p->GetPdgCode();
79 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
82 gMC->CurrentVolID(straw_uniqueId);
94 gMC->TrackPosition(Pos);
95 Double_t xmean = (
fPos.X() + Pos.X()) / 2.;
96 Double_t ymean = (
fPos.Y() + Pos.Y()) / 2.;
97 Double_t zmean = (
fPos.Z() + Pos.Z()) / 2.;
98 TVector3 pq = TVector3(top.x() - xmean, top.y() - ymean, top.z() - zmean);
100 TVector3(bot.x() - top.x(), bot.y() - top.y(), bot.z() - top.z());
102 TVector3(
fPos.X() - Pos.X(),
fPos.Y() - Pos.Y(),
fPos.Z() - Pos.Z());
103 TVector3 uCrossv = u.Cross(v);
104 Double_t dist2Wire = fabs(pq.Dot(uCrossv)) / (uCrossv.Mag() + 1E-8);
105 Double_t deltaTrackLength = gMC->TrackLength() -
fLength;
108 fELoss, pdgCode, dist2Wire);
110 std::cout <<
"addhit " << dist2Wire <<
" straw id " << straw_uniqueId
111 <<
" pdgcode " << pdgCode <<
" dot prod " << pq.Dot(uCrossv)
113 std::cout <<
" exit:" << gMC->IsTrackExiting()
114 <<
" stop:" << gMC->IsTrackStop()
115 <<
" disappeared:" << gMC->IsTrackDisappeared() << std::endl;
116 std::cout <<
" entry:" <<
fPos.X() <<
" " <<
fPos.Y() <<
" " <<
fPos.Z()
118 std::cout <<
" exit:" << Pos.X() <<
" " << Pos.Y() <<
" " << Pos.Z()
120 std::cout <<
" mean:" << xmean <<
" " << ymean <<
" " << zmean
122 std::cout <<
" bot:" << bot.x() <<
" " << bot.y() <<
" " << bot.z()
124 std::cout <<
" top:" << top.x() <<
" " << top.y() <<
" " << top.z()
194 TGeoVolume* top = gGeoManager->GetTopVolume();
196 TGeoMedium* mylar = gGeoManager->GetMedium(
"mylar");
198 TGeoMedium* sttmix8020_1bar = gGeoManager->GetMedium(
"STTmix8020_1bar");
200 TGeoMedium* tungsten = gGeoManager->GetMedium(
"tungsten");
204 TGeoMedium* med = gGeoManager->GetMedium(
fMedium.c_str());
206 gGeoManager->SetVisLevel(4);
207 gGeoManager->SetTopVisible();
210 Double_t eps = 0.0001;
214 Double_t frame_width = 49.;
216 Double_t floor_offset = 14.;
218 Double_t rmin, rmax, T_station_z;
221 [[maybe_unused]] TGeoBBox* detbox1 =
new TGeoBBox(
224 [[maybe_unused]] TGeoBBox* detbox2 =
new TGeoBBox(
225 "detbox2", straw_length + eps,
227 TMath::Tan(
f_view_angle * TMath::Pi() / 180.0) * straw_length * 2 +
230 TGeoTranslation* move_up =
231 new TGeoTranslation(
"move_up", 0, floor_offset / 2., 0);
232 move_up->RegisterYourself();
235 TGeoCompositeShape* detcomp1 =
236 new TGeoCompositeShape(
"detcomp1",
"(detbox1:move_up)-detbox2");
242 TGeoTube* straw_tube =
new TGeoTube(
"straw", rmin, rmax, straw_length);
243 TGeoVolume* straw =
new TGeoVolume(
"straw", straw_tube, mylar);
244 straw->SetLineColor(4);
245 straw->SetVisibility(kTRUE);
250 TGeoTube* gas_tube =
new TGeoTube(
"gas", rmin, rmax, straw_length - 2. * eps);
251 TGeoVolume* gas =
new TGeoVolume(
"gas", gas_tube, sttmix8020_1bar);
252 gas->SetLineColor(5);
254 AddSensitiveVolume(gas);
259 TGeoTube* wire_tube =
260 new TGeoTube(
"wire", rmin, rmax, straw_length - 4. * eps);
261 TGeoVolume* wire =
new TGeoVolume(
"wire", wire_tube, tungsten);
262 wire->SetLineColor(6);
275 for (Int_t statnb = 1; statnb < 5; statnb++) {
277 TString nmstation =
"Tr";
278 std::stringstream ss;
280 nmstation = nmstation + ss.str();
298 TGeoVolume* vol =
new TGeoVolume(nmstation, statbox, med);
300 top->AddNode(vol, statnb,
301 new TGeoTranslation(0, floor_offset / 2., T_station_z));
303 TGeoVolume* statframe =
304 new TGeoVolume(nmstation +
"_frame", detcomp1, FrameMatPtr);
305 vol->AddNode(statframe, statnb * 1e6,
306 new TGeoTranslation(0, -floor_offset / 2., 0));
307 statframe->SetLineColor(kRed);
309 for (Int_t vnb = 0; vnb < 4; vnb++) {
311 const Double_t angle = [&] {
321 const TString nmview = [&] {
324 return nmstation +
"_y1";
326 return nmstation +
"_u";
328 return nmstation +
"_v";
330 return nmstation +
"_y2";
332 return nmstation +
"_y1";
342 const Double_t stereo_growth =
343 TMath::Tan(TMath::Abs(angle) * TMath::Pi() / 180.0) * straw_length;
344 const Double_t stereo_pitch =
345 f_straw_pitch / TMath::Cos(TMath::Abs(angle) * TMath::Pi() / 180.0);
346 const Double_t offset_layer =
347 f_offset_layer / TMath::Cos(TMath::Abs(angle) * TMath::Pi() / 180.0);
348 const Int_t straws_per_layer =
351 for (Int_t lnb = 0; lnb < 2; lnb++) {
353 TString nmlayer = nmview +
"_layer_";
355 TGeoBBox* layer =
new TGeoBBox(
356 "layer box", straw_length + eps / 4,
359 TGeoVolume* layerbox =
new TGeoVolume(nmlayer, layer, med);
364 layerbox, statnb * 1e6 + vnb * 1e5 + lnb * 1e4,
365 new TGeoTranslation(0, -floor_offset / 2.,
371 for (Int_t snb = 1; snb <= straws_per_layer; snb++) {
374 t6s.SetTranslation(0,
376 (snb - 1. / 2.) * stereo_pitch +
380 r6s.SetAngles(90 + angle, 90, 0);
381 TGeoCombiTrans c6s(t6s, r6s);
382 TGeoHMatrix* h6s =
new TGeoHMatrix(c6s);
384 straw, statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 1e3 + snb, h6s);
386 gas, statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 2e3 + snb, h6s);
388 wire, statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 3e3 + snb, h6s);
395 t6s.SetTranslation(0,
397 (straws_per_layer - 1. / 2.) * stereo_pitch -
400 r6s.SetAngles(90 + angle, 90, 0);
401 TGeoCombiTrans c6s(t6s, r6s);
402 TGeoHMatrix* h6s =
new TGeoHMatrix(c6s);
405 statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 1e3 + straws_per_layer + 1,
409 statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 2e3 + straws_per_layer + 1,
413 statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 3e3 + straws_per_layer + 1,
454 static std::unordered_map<Int_t, std::pair<TVector3, TVector3>> endPointCache;
455 if (
auto it = endPointCache.find(fDetectorID); it != endPointCache.end()) {
456 vbot = it->second.first;
457 vtop = it->second.second;
460 const auto [statnb, vnb, lnb, snb] =
StrawDecode(fDetectorID);
465 const TString view = [&] {
468 return TString(
"_u");
470 return TString(
"_v");
472 return TString(
"_y2");
474 return TString(
"_y1");
477 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
478 TString prefix =
"Tr";
482 TString layer = prefix +
"layer_";
489 TString wire =
"wire_";
490 wire += fDetectorID + 1e3;
497 Bool_t rc = nav->cd(path);
499 LOG(warning) <<
"strawtubes::StrawDecode, TGeoNavigator failed" << path;
502 TGeoNode* W = nav->GetCurrentNode();
503 TGeoTube* S =
dynamic_cast<TGeoTube*
>(W->GetVolume()->GetShape());
504 Double_t top[3] = {0, 0, S->GetDZ()};
505 Double_t bot[3] = {0, 0, -S->GetDZ()};
506 Double_t Gtop[3], Gbot[3];
507 nav->LocalToMaster(top, Gtop);
508 nav->LocalToMaster(bot, Gbot);
509 vtop.SetXYZ(Gtop[0], Gtop[1], Gtop[2]);
510 vbot.SetXYZ(Gbot[0], Gbot[1], Gbot[2]);
511 endPointCache.emplace(fDetectorID, std::make_pair(vbot, vtop));