From 57abf466ad277dd9edeb1255b6f0ac3c7bc746f1 Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Fri, 14 Nov 2025 16:55:25 +0100 Subject: [PATCH 1/8] some messing --- UpstreamTagger/UpstreamTagger.cxx | 531 +++++++++++++++++++++++------- UpstreamTagger/UpstreamTagger.h | 158 ++++----- 2 files changed, 499 insertions(+), 190 deletions(-) diff --git a/UpstreamTagger/UpstreamTagger.cxx b/UpstreamTagger/UpstreamTagger.cxx index a7890fbd1f..a81715f5a8 100644 --- a/UpstreamTagger/UpstreamTagger.cxx +++ b/UpstreamTagger/UpstreamTagger.cxx @@ -1,68 +1,70 @@ -// RPC Timing Detector -// 17/12/2019 -// celso.franco@cern.ch +// Construction of SST tracker stations +// Last update: 15 Aug 2025 +// Contact: W.-C. Marty Lee #include "UpstreamTagger.h" -#include "UpstreamTaggerPoint.h" -#include "UpstreamTaggerHit.h" -#include "FairVolume.h" -#include "FairGeoVolume.h" -#include "FairGeoNode.h" -#include "FairRootManager.h" -#include "FairGeoLoader.h" +#include "FairGeoBuilder.h" #include "FairGeoInterface.h" +#include "FairGeoLoader.h" #include "FairGeoMedia.h" -#include "FairGeoBuilder.h" +#include "FairGeoNode.h" +#include "FairGeoVolume.h" +#include "FairLogger.h" +#include "FairRootManager.h" #include "FairRun.h" #include "FairRuntimeDb.h" +#include "FairVolume.h" #include "ShipDetectorList.h" #include "ShipStack.h" - #include "TClonesArray.h" -#include "TVirtualMC.h" -#include "TGeoManager.h" #include "TGeoBBox.h" #include "TGeoCompositeShape.h" -#include "TGeoTube.h" +#include "TGeoManager.h" #include "TGeoMaterial.h" #include "TGeoMedium.h" +#include "TGeoTube.h" #include "TMath.h" #include "TParticle.h" #include "TVector3.h" +#include "TVirtualMC.h" +#include "UpstreamTaggerPoint.h" -#include #include #include +#include using std::cout; using std::endl; -using ROOT::TSeq; -using ShipUnit::m; -using ShipUnit::cm; - UpstreamTagger::UpstreamTagger() - : FairDetector("UpstreamTagger", kTRUE, kUpstreamTagger), - fTrackID(-1), - fVolumeID(-1), - fPos(), - fMom(), - fTime(-1.), - fLength(-1.), - fELoss(-1), - // - det_zPos(0), - - // - UpstreamTagger_fulldet(0), - scoringPlaneUBText(0), - // - fUpstreamTaggerPointCollection(new TClonesArray("UpstreamTaggerPoint")) + : FairDetector("UpstreamTagger", kTRUE, kStraw) + , fTrackID(-1) + , fVolumeID(-1) + , fPos() + , fMom() + , fTime(-1.) + , fLength(-1.) + , fELoss(-1) + , fMedium("air") + , fUpstreamTaggerPointCollection(new TClonesArray("UpstreamTaggerPoint")) +{} + +UpstreamTagger::UpstreamTagger(std::string medium) + : FairDetector("UpstreamTagger", kTRUE, kStraw) + , fTrackID(-1) + , fVolumeID(-1) + , fPos() + , fMom() + , fTime(-1.) + , fLength(-1.) + , fELoss(-1) + , fMedium(medium) + , fUpstreamTaggerPointCollection(new TClonesArray("UpstreamTaggerPoint")) { } UpstreamTagger::UpstreamTagger(const char* name, Bool_t active) - : FairDetector(name, active, kUpstreamTagger), + : FairDetector(name, active, kStraw), fTrackID(-1), fVolumeID(-1), fPos(), @@ -70,24 +72,10 @@ UpstreamTagger::UpstreamTagger(const char* name, Bool_t active) fTime(-1.), fLength(-1.), fELoss(-1), - // - det_zPos(0), - - // - UpstreamTagger_fulldet(0), - scoringPlaneUBText(0), // Initialize new scoring plane to nullptr - // fUpstreamTaggerPointCollection(new TClonesArray("UpstreamTaggerPoint")) { } - -void UpstreamTagger::Initialize() -{ - FairDetector::Initialize(); -} - - UpstreamTagger::~UpstreamTagger() { if (fUpstreamTaggerPointCollection) { @@ -96,11 +84,16 @@ UpstreamTagger::~UpstreamTagger() } } +void UpstreamTagger::Initialize() +{ + FairDetector::Initialize(); +// FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb(); +// vetoGeoPar* par=(vetoGeoPar*)(rtdb->getContainer("vetoGeoPar")); +} - +// ----- Private method InitMedium Int_t UpstreamTagger::InitMedium(const char* name) { - static FairGeoLoader *geoLoad=FairGeoLoader::Instance(); static FairGeoInterface *geoFace=geoLoad->getGeoInterface(); static FairGeoMedia *media=geoFace->getMedia(); @@ -118,12 +111,8 @@ Int_t UpstreamTagger::InitMedium(const char* name) return ShipMedium->getMediumIndex(); return geoBuild->createMedium(ShipMedium); - - return 0; } - - Bool_t UpstreamTagger::ProcessHits(FairVolume* vol) { /** This method is called from the MC stepping */ @@ -135,52 +124,60 @@ Bool_t UpstreamTagger::ProcessHits(FairVolume* vol) gMC->TrackPosition(fPos); gMC->TrackMomentum(fMom); } - // Sum energy loss for all steps in the active volume fELoss += gMC->Edep(); - // Create vetoPoint at exit of active volume + // Create UpstreamTaggerPoint at exit of active volume if ( gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { if (fELoss == 0. ) { return kFALSE; } - - fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); - - Int_t uniqueId; - gMC->CurrentVolID(uniqueId); - if (uniqueId>1000000) //Solid scintillator case - { - Int_t vcpy; - gMC->CurrentVolOffID(1, vcpy); - if (vcpy==5) uniqueId+=4; //Copy of half - } - - TParticle* p = gMC->GetStack()->GetCurrentTrack(); + TParticle* p=gMC->GetStack()->GetCurrentTrack(); Int_t pdgCode = p->GetPdgCode(); + fTrackID = gMC->GetStack()->GetCurrentTrackNumber(); + Int_t straw_uniqueId; + gMC->CurrentVolID(straw_uniqueId); + if (fVolumeID == straw_uniqueId) { + //std::cout << pdgCode<< " same volume again ? "<< straw_uniqueId << " exit:" << gMC->IsTrackExiting() << " stop:" << gMC->IsTrackStop() << " disappeared:" << gMC->IsTrackDisappeared()<< std::endl; + return kTRUE; } + fVolumeID = straw_uniqueId; + // # d = |pq . u x v|/|u x v| + TVector3 bot,top; + StrawEndPoints(straw_uniqueId,bot,top); TLorentzVector Pos; gMC->TrackPosition(Pos); - TLorentzVector Mom; - gMC->TrackMomentum(Mom); Double_t xmean = (fPos.X()+Pos.X())/2. ; Double_t ymean = (fPos.Y()+Pos.Y())/2. ; Double_t zmean = (fPos.Z()+Pos.Z())/2. ; - - AddHit(fTrackID, uniqueId, TVector3(xmean, ymean, zmean), - TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, - fELoss,pdgCode,TVector3(Pos.X(), Pos.Y(), Pos.Z()), - TVector3(Mom.Px(), Mom.Py(), Mom.Pz()) ); - - // Increment number of veto det points in TParticle + TVector3 pq = TVector3(top.x()-xmean,top.y()-ymean,top.z()-zmean ); + TVector3 u = TVector3(bot.x()-top.x(),bot.y()-top.y(),bot.z()-top.z() ); + TVector3 v = TVector3(fPos.X()-Pos.X(),fPos.Y()-Pos.Y(),fPos.Z()-Pos.Z()); + TVector3 uCrossv = u.Cross(v); + Double_t dist2Wire = fabs(pq.Dot(uCrossv))/(uCrossv.Mag()+1E-8); + Double_t deltaTrackLength = gMC->TrackLength() - fLength; + AddHit(fTrackID, straw_uniqueId, TVector3(xmean, ymean, zmean), + TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, deltaTrackLength, + fELoss,pdgCode,dist2Wire); + if (dist2Wire > f_inner_straw_diameter / 2){ + std::cout << "addhit " << dist2Wire<< " straw id " << straw_uniqueId << " pdgcode " << pdgCode<< " dot prod " << pq.Dot(uCrossv)<< std::endl; + std::cout << " exit:" << gMC->IsTrackExiting() << " stop:" << gMC->IsTrackStop() << " disappeared:" << gMC->IsTrackDisappeared()<< std::endl; + std::cout << " entry:" << fPos.X()<< " " << fPos.Y()<< " " << fPos.Z() << std::endl; + std::cout << " exit:" << Pos.X()<< " " << Pos.Y()<< " " << Pos.Z() << std::endl; + std::cout << " mean:" << xmean<< " " << ymean << " " << zmean << std::endl; + std::cout << " bot:" << bot.x()<< " " << bot.y() << " " << bot.z() << std::endl; + std::cout << " top:" << top.x()<< " " << top.y() << " " << top.z() << std::endl; + pq.Print(); + u.Print(); + v.Print(); + uCrossv.Print(); + } + // Increment number of UpstreamTagger det points in TParticle ShipStack* stack = dynamic_cast(gMC->GetStack()); - stack->AddPoint(kUpstreamTagger); + stack->AddPoint(kStraw); } - return kTRUE; } - - void UpstreamTagger::EndOfEvent() { fUpstreamTaggerPointCollection->Clear(); @@ -202,62 +199,364 @@ void UpstreamTagger::Register() } - TClonesArray* UpstreamTagger::GetCollection(Int_t iColl) const { if (iColl == 0) { return fUpstreamTaggerPointCollection; } else { return NULL; } } - - void UpstreamTagger::Reset() { fUpstreamTaggerPointCollection->Clear(); } - - - -void UpstreamTagger::ConstructGeometry() +void UpstreamTagger::SetzPositions(Double_t z1, Double_t z2, Double_t z3, Double_t z4) { - TGeoVolume *top = gGeoManager->GetTopVolume(); - - ////////////////////////////////////////////////////// + f_T1_z = z1; //! z-position of tracking station 1 + f_T2_z = z2; //! z-position of tracking station 2 + f_T3_z = z3; //! z-position of tracking station 3 + f_T4_z = z4; //! z-position of tracking station 4 +} - /////////////////////////////////////////////////////// +void UpstreamTagger::SetApertureArea(Double_t width, Double_t height) +{ + f_aperture_width = width; //! Aperture width (x) + f_aperture_height = height; //! Aperture height (y) +} - /////////////////////////////////////////////////////// +void UpstreamTagger::SetStrawDiameter(Double_t outer_straw_diameter, Double_t wall_thickness) +{ + f_outer_straw_diameter = outer_straw_diameter; //! Outer straw diameter + f_inner_straw_diameter = + outer_straw_diameter - 2 * wall_thickness; //! Inner straw diameter +} - InitMedium("vacuum"); - TGeoMedium *Vacuum_box =gGeoManager->GetMedium("vacuum"); - /////////////////////////////////////////////////////////////////// +void UpstreamTagger::SetStrawPitch(Double_t straw_pitch, Double_t layer_offset) +{ + f_straw_pitch = straw_pitch; //! Distance (y) between straws in a layer + f_offset_layer = layer_offset; //! Offset (y) of straws between layers +} - // Adding UBT Extension - if (!Vacuum_box) { - Fatal("ConstructGeometry", "Medium 'vacuum' not found."); - } +void UpstreamTagger::SetDeltazLayer(Double_t delta_z_layer) +{ + f_delta_z_layer = delta_z_layer; //! Distance (z) between layers +} - UpstreamTagger_fulldet = gGeoManager->MakeBox("Upstream_Tagger", Vacuum_box, xbox_fulldet/2.0, ybox_fulldet/2.0, zbox_fulldet/2.0); - UpstreamTagger_fulldet->SetLineColor(kGreen); +void UpstreamTagger::SetStereoAngle(Double_t stereo_angle) +{ + f_view_angle = stereo_angle; //! Stereo view angle +} - top->AddNode(UpstreamTagger_fulldet, 1, new TGeoTranslation(0.0, 0.0, det_zPos)); - AddSensitiveVolume(UpstreamTagger_fulldet); - cout << " Z Position (Upstream Tagger1) " << det_zPos << endl; - ////////////////////////////////////////////////////////////////// +void UpstreamTagger::SetWireThickness(Double_t wire_thickness) +{ + f_wire_thickness = wire_thickness; //! Sense wire thickness +} - return; +void UpstreamTagger::SetDeltazView(Double_t delta_z_view) +{ + f_delta_z_view = delta_z_view; //! Distance (z) between stereo views } +void UpstreamTagger::SetFrameMaterial(TString frame_material) +{ + f_frame_material = frame_material; //! Structure frame material +} +void UpstreamTagger::SetStationEnvelope(Double_t x, Double_t y, Double_t z) +{ + f_station_width = x; //! Station envelope width (x) + f_station_height = y; //! Station envelope height (y) + f_station_length = z; //! Station envelope length (z) +} +void UpstreamTagger::ConstructGeometry() +{ + /** If you are using the standard ASCII input for the geometry + just copy this and use it for your detector, otherwise you can + implement here you own way of constructing the geometry. */ + + TGeoVolume *top = gGeoManager->GetTopVolume(); + InitMedium("air"); + TGeoMedium *air = gGeoManager->GetMedium("air"); + InitMedium("ShipSens"); + TGeoMedium *Se = gGeoManager->GetMedium("ShipSens"); + InitMedium("aluminium"); + TGeoMedium *Al = gGeoManager->GetMedium("aluminium"); + InitMedium("mylar"); + TGeoMedium *mylar = gGeoManager->GetMedium("mylar"); + InitMedium("STTmix8020_1bar"); + TGeoMedium *sttmix8020_1bar = gGeoManager->GetMedium("STTmix8020_1bar"); + InitMedium("tungsten"); + TGeoMedium *tungsten = gGeoManager->GetMedium("tungsten"); + InitMedium(f_frame_material); + TGeoMedium *FrameMatPtr = gGeoManager->GetMedium(f_frame_material); + InitMedium(fMedium.c_str()); + TGeoMedium* med = gGeoManager->GetMedium(fMedium.c_str()); + + gGeoManager->SetVisLevel(4); + gGeoManager->SetTopVisible(); + + // Epsilon to avoid overlapping volumes + Double_t eps = 0.0001; + // Straw (half) length + Double_t straw_length = f_aperture_width + 2. * eps; + // Width of frame: standard HEA 500 I-beam width + Double_t frame_width = 49.; + // Offset due to floor space limitation + Double_t floor_offset = 14.; + + Double_t rmin, rmax, T_station_z; + + // Arguments of boxes are half-lengths + TGeoBBox* detbox1 = new TGeoBBox( + "detbox1", f_aperture_width + frame_width, f_aperture_height + frame_width - floor_offset / 2., f_station_length); + TGeoBBox* detbox2 = new TGeoBBox( + "detbox2", + straw_length + eps, + f_aperture_height + TMath::Tan(f_view_angle * TMath::Pi() / 180.0) * straw_length * 2 + f_offset_layer / TMath::Cos(f_view_angle * TMath::Pi() / 180.0) + eps, + f_station_length + eps); + TGeoTranslation* move_up = new TGeoTranslation("move_up", 0, floor_offset / 2., 0); + move_up->RegisterYourself(); + + // Composite shape to create frame + TGeoCompositeShape* detcomp1 = new TGeoCompositeShape("detcomp1", "(detbox1:move_up)-detbox2"); + + // Volume: straw + rmin = f_inner_straw_diameter / 2.; + rmax = f_outer_straw_diameter / 2.; + // Third argument is half-length of tube + TGeoTube *straw_tube = new TGeoTube("straw", rmin, rmax, straw_length); + TGeoVolume *straw = new TGeoVolume("straw", straw_tube, mylar); + straw->SetLineColor(4); + straw->SetVisibility(kTRUE); + + // Volume: gas + rmin = f_wire_thickness / 2. + eps; + rmax = f_inner_straw_diameter / 2. - eps; + TGeoTube *gas_tube = new TGeoTube("gas", rmin, rmax, straw_length - 2. * eps); + TGeoVolume *gas = new TGeoVolume("gas", gas_tube, sttmix8020_1bar); + gas->SetLineColor(5); + // Only the gas is sensitive + AddSensitiveVolume(gas); + + // Volume: wire + rmin = 0.; + rmax = f_wire_thickness / 2.; + TGeoTube *wire_tube = new TGeoTube("wire", rmin, rmax, straw_length - 4. * eps); + TGeoVolume *wire = new TGeoVolume("wire", wire_tube, tungsten); + wire->SetLineColor(6); + + // Tracking stations + // statnb = station number; vnb = view number; lnb = layer number; snb = straw number + + // Station box to contain all components + TGeoBBox* statbox = new TGeoBBox("statbox", f_station_width, f_station_height - floor_offset / 2., f_station_length); + + f_frame_material.ToLower(); + + for (Int_t statnb = 1; statnb < 5; statnb++) { + // Tracking station loop + TString nmstation = "Tr"; + std::stringstream ss; + ss << statnb; + nmstation = nmstation + ss.str(); + switch (statnb) { + case 1: + T_station_z = f_T1_z; + break; + case 2: + T_station_z = f_T2_z; + break; + case 3: + T_station_z = f_T3_z; + break; + case 4: + T_station_z = f_T4_z; + break; + default: + T_station_z = f_T1_z; + } + + TGeoVolume* vol = new TGeoVolume(nmstation, statbox, med); + // z-translate the station to its (absolute) position + top->AddNode(vol, statnb, new TGeoTranslation(0, floor_offset / 2., T_station_z)); + + TGeoVolume* statframe = new TGeoVolume(nmstation + "_frame", detcomp1, FrameMatPtr); + vol->AddNode(statframe, statnb * 1e6, new TGeoTranslation(0, -floor_offset / 2., 0)); + statframe->SetLineColor(kRed); + + for (Int_t vnb = 0; vnb < 4; vnb++) { + // View loop + TString nmview; + Double_t angle; + Double_t stereo_growth; + Double_t stereo_pitch; + Double_t offset_layer; + Int_t straws_per_layer; + + switch (vnb) { + case 0: + angle = 0.; + nmview = nmstation + "_y1"; + break; + case 1: + angle = f_view_angle; + nmview = nmstation + "_u"; + break; + case 2: + angle = -f_view_angle; + nmview = nmstation + "_v"; + break; + case 3: + angle = 0.; + nmview = nmstation + "_y2"; + break; + default: + angle = 0.; + nmview = nmstation + "_y1"; + } + + // Adjustments in the stereo views + // stereo_growth: extension of stereo views beyond aperture + // stereo_pitch: straw pitch in stereo views + // offset_layer: layer offset in stereo views + // straws_per_layer: number of straws in one layer with stereo extension + // If angle == 0., all numbers return the case of non-stereo views. + stereo_growth = TMath::Tan(TMath::Abs(angle) * TMath::Pi() / 180.0) * straw_length; + stereo_pitch = f_straw_pitch / TMath::Cos(TMath::Abs(angle) * TMath::Pi() / 180.0); + offset_layer = f_offset_layer / TMath::Cos(TMath::Abs(angle) * TMath::Pi() / 180.0); + straws_per_layer = std::ceil(2 * (f_aperture_height + stereo_growth) / stereo_pitch); + + for (Int_t lnb = 0; lnb < 2; lnb++) { + // Layer loop + TString nmlayer = nmview + "_layer_"; + nmlayer += lnb; + TGeoBBox* layer = new TGeoBBox( + "layer box", straw_length + eps / 4, f_aperture_height + stereo_growth * 2 + offset_layer + eps / 4, f_outer_straw_diameter / 2. + eps / 4); + TGeoVolume* layerbox = new TGeoVolume(nmlayer, layer, med); + + // The layer box sits in the viewframe. + // Hence, z-translate the layer w.r.t. the view + vol->AddNode(layerbox, statnb * 1e6 + vnb * 1e5 + lnb * 1e4, new TGeoTranslation(0, -floor_offset / 2., (vnb - 3. / 2.) * f_delta_z_view + (lnb - 1. / 2.) * f_delta_z_layer)); + + TGeoRotation r6s; + TGeoTranslation t6s; + for (Int_t snb = 1; snb <= straws_per_layer; snb++) { + // Straw loop + // y-translate the straw to its position + t6s.SetTranslation(0, f_aperture_height + stereo_growth - (snb - 1. / 2.) * stereo_pitch + lnb * offset_layer, 0); + // Rotate the straw with stereo angle + r6s.SetAngles(90 + angle, 90, 0); + TGeoCombiTrans c6s(t6s, r6s); + TGeoHMatrix* h6s = new TGeoHMatrix(c6s); + layerbox->AddNode(straw, statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 1e3 + snb, h6s); + layerbox->AddNode(gas, statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 2e3 + snb, h6s); + layerbox->AddNode(wire, statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 3e3 + snb, h6s); + // End of straw loop + } + + if (lnb == 1) { + // Add one more straw at the bottom of the second layer to cover aperture entirely + t6s.SetTranslation(0, f_aperture_height + stereo_growth - (straws_per_layer - 1. / 2.) * stereo_pitch - lnb * offset_layer, 0); + r6s.SetAngles(90 + angle, 90, 0); + TGeoCombiTrans c6s(t6s, r6s); + TGeoHMatrix* h6s = new TGeoHMatrix(c6s); + layerbox->AddNode(straw, statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 1e3 + straws_per_layer + 1, h6s); + layerbox->AddNode(gas, statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 2e3 + straws_per_layer + 1, h6s); + layerbox->AddNode(wire, statnb * 1e6 + vnb * 1e5 + lnb * 1e4 + 3e3 + straws_per_layer + 1, h6s); + } + // End of layer loop + } + // End of view loop + } + // End of tracking station loop + } +} +// ----- Public method StrawDecode ------------------------------------------- +// ----- returns station, view, layer, straw number in a tuple ----------------------------------- +std::tuple UpstreamTagger::StrawDecode(Int_t detID) +{ + Int_t statnb, vnb, lnb, snb; + statnb = detID / 1e6; + vnb = (detID - statnb * 1e6) / 1e5; + lnb = (detID - statnb * 1e6 - vnb * 1e5) / 1e4; + snb = detID - statnb * 1e6 - vnb * 1e5 - lnb * 1e4 - 2e3; + + if (statnb < 1 || statnb > 4 || vnb < 0 || vnb > 3 || lnb < 0 || lnb > 1 || snb < 1 || snb > 317) { + LOG(warning) << "Invalid UpstreamTagger detID:"; + LOG(warning) << detID << " -> station: " << statnb << ", view: " << vnb << ", layer: " << lnb + << ", straw: " << snb; + LOG(warning) << "UpstreamTagger detID is 7-digit!"; + return std::make_tuple(0, -1, -1, 0); + } else { + return std::make_tuple(statnb, vnb, lnb, snb); + } +} +// ----- Public method StrawEndPoints ------------------------------------------- +// ----- returns top (left) and bottom (right) coordinates of straw ----------------------------------- +void UpstreamTagger::StrawEndPoints(Int_t fDetectorID, TVector3 &vbot, TVector3 &vtop) +// method to get end points from TGeoNavigator +{ + const auto [statnb, vnb, lnb, snb] = StrawDecode(fDetectorID); + TString stat = "Tr"; stat += statnb; stat += "_"; stat += statnb; + TString view; + switch (vnb) { + case 0: + view = "_y1"; + break; + case 1: + view = "_u"; + break; + case 2: + view = "_v"; + break; + case 3: + view = "_y2"; + break; + default: + view = "_y1"; + } + TGeoNavigator* nav = gGeoManager->GetCurrentNavigator(); + TString prefix = "Tr"; + prefix += statnb; + prefix += view; + prefix += "_"; + TString layer = prefix + "layer_"; + layer += lnb; + layer += "_"; + layer += statnb; + layer += vnb; + layer += lnb; + layer += "0000"; + TString wire = "wire_"; + wire += fDetectorID + 1e3; + TString path = "/"; + path += stat; + path += "/"; + path += layer; + path += "/"; + path += wire; + Bool_t rc = nav->cd(path); + if (!rc) { + LOG(warning) << "UpstreamTagger::StrawDecode, TGeoNavigator failed" << path; + return; + } + TGeoNode* W = nav->GetCurrentNode(); + TGeoTube* S = dynamic_cast(W->GetVolume()->GetShape()); + Double_t top[3] = {0, 0, S->GetDZ()}; + Double_t bot[3] = {0, 0, -S->GetDZ()}; + Double_t Gtop[3], Gbot[3]; + nav->LocalToMaster(top, Gtop); nav->LocalToMaster(bot, Gbot); + vtop.SetXYZ(Gtop[0], Gtop[1], Gtop[2]); + vbot.SetXYZ(Gbot[0], Gbot[1], Gbot[2]); +} UpstreamTaggerPoint* UpstreamTagger::AddHit(Int_t trackID, Int_t detID, - TVector3 pos, TVector3 mom, - Double_t time, Double_t length, - Double_t eLoss, Int_t pdgCode,TVector3 Lpos, TVector3 Lmom) + TVector3 pos, TVector3 mom, + Double_t time, Double_t length, + Double_t eLoss, Int_t pdgCode, Double_t dist2Wire) { TClonesArray& clref = *fUpstreamTaggerPointCollection; Int_t size = clref.GetEntriesFast(); - + //std::cout << "adding hit detid " < StrawDecode(Int_t detID); + static void StrawEndPoints(Int_t detID, TVector3& top, TVector3& bot); +// for the digitizing step + void SetStrawResolution(Double_t a, Double_t b) + { + v_drift = a; + sigma_spatial = b; } + Double_t StrawVdrift() {return v_drift;} + Double_t StrawSigmaSpatial() {return sigma_spatial;} - /** Create the detector geometry */ + /** Create the detector geometry */ void ConstructGeometry(); + + /** This method is an example of how to add your own point - * of type TimeRpcPoint to the clones array + * of type UpstreamTaggerPoint to the clones array */ UpstreamTaggerPoint* AddHit(Int_t trackID, Int_t detID, - TVector3 pos, TVector3 mom, - Double_t time, Double_t length, - Double_t eLoss, Int_t pdgCode,TVector3 Lpos, TVector3 Lmom); + TVector3 pos, TVector3 mom, + Double_t time, Double_t length, + Double_t eLoss, Int_t pdgCode, Double_t dist2Wire); + + /** The following methods can be implemented if you need to make + * any optional action in your detector during the transport. + */ + virtual void CopyClones( TClonesArray* cl1, TClonesArray* cl2 , + Int_t offset) {;} + virtual void SetSpecialPhysicsCuts() {;} virtual void EndOfEvent(); virtual void FinishPrimary() {;} virtual void FinishRun() {;} @@ -94,39 +96,47 @@ class UpstreamTagger: public FairDetector virtual void PreTrack() {;} virtual void BeginEvent() {;} - Double_t module[11][3]; // x,y,z centre positions for each module - // TODO Avoid 1-indexed array! - - /** Track information to be stored until the track leaves the active volume.*/ - Int_t fTrackID; //! track index - Int_t fVolumeID; //! volume id - TLorentzVector fPos; //! position at entrance - TLorentzVector fMom; //! momentum at entrance - Double_t fTime; //! time - Double_t fLength; //! length - Double_t fELoss; //! energy loss - - /** Detector parameters.*/ - - Double_t det_zPos; //! z-position of detector (set via SetZposition) - // Detector box dimensions (set via SetBoxDimensions, defaults provided below) - Double_t xbox_fulldet = 4.4 * m; //! X dimension (default: 4.4 m) - Double_t ybox_fulldet = 6.4 * m; //! Y dimension (default: 6.4 m) - Double_t zbox_fulldet = 16.0 * cm; //! Z dimension/thickness (default: 16 cm) - private: - TGeoVolume* UpstreamTagger_fulldet; // Timing_detector_1 object - TGeoVolume* scoringPlaneUBText; // new scoring plane + /** Track information to be stored until the track leaves the + active volume. + */ + Int_t fTrackID; //! track index + Int_t fVolumeID; //! volume id + TLorentzVector fPos; //! position at entrance + TLorentzVector fMom; //! momentum at entrance + Double_t fTime; //! time + Double_t fLength; //! length + Double_t fELoss; //! energy loss + Double_t f_T1_z; //! z-position of tracking station 1 + Double_t f_T2_z; //! z-position of tracking station 2 + Double_t f_T3_z; //! z-position of tracking station 3 + Double_t f_T4_z; //! z-position of tracking station 4 + Double_t f_aperture_width; //! Aperture width (x) + Double_t f_aperture_height; //! Aperture height (y) + Double_t f_inner_straw_diameter; //! Inner Straw diameter + Double_t f_outer_straw_diameter; //! Outer Straw diameter + Double_t f_straw_pitch; //! Distance (y) between straws in a layer + Double_t f_offset_layer; //! Offset (y) of straws between layers + Double_t f_delta_z_layer; //! Distance (z) between layers + Double_t f_view_angle; //! Stereo view angle + Double_t f_wire_thickness; //! Sense wire thickness + TString f_frame_material; //! Structure frame material + Double_t f_delta_z_view; //! Distance (z) between stereo views + Double_t f_station_width; //! Station envelope width (x) + Double_t f_station_height; //! Station envelope height (y) + Double_t f_station_length; //! Station envelope length (z) + Double_t v_drift; //! drift velocity + Double_t sigma_spatial; //! spatial resolution + std::string fMedium; //! vacuum box medium /** container for data points */ + TClonesArray* fUpstreamTaggerPointCollection; UpstreamTagger(const UpstreamTagger&); UpstreamTagger& operator=(const UpstreamTagger&); Int_t InitMedium(const char* name); - - - ClassDef(UpstreamTagger,1) + ClassDef(UpstreamTagger, 6) }; -#endif // UPSTREAMTAGGER_UPSTREAMTAGGER_H_ +#endif // UpstreamTagger_UpstreamTagger_H_ From 34493b483dad2cb07d512f752db2da5f8aee9347 Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Thu, 25 Dec 2025 00:40:25 +0100 Subject: [PATCH 2/8] alterations --- UpstreamTagger/UpstreamTagger.cxx | 362 ++++++++++++++---------------- UpstreamTagger/UpstreamTagger.h | 165 ++++++++------ macro/run_simScript.py | 17 +- python/ShipGeo.py | 8 +- python/geometry_config.py | 7 +- python/shipDet_conf.py | 69 +++++- 6 files changed, 351 insertions(+), 277 deletions(-) diff --git a/UpstreamTagger/UpstreamTagger.cxx b/UpstreamTagger/UpstreamTagger.cxx index 7402a29248..850a721399 100644 --- a/UpstreamTagger/UpstreamTagger.cxx +++ b/UpstreamTagger/UpstreamTagger.cxx @@ -6,68 +6,68 @@ // celso.franco@cern.ch #include "UpstreamTagger.h" +#include "UpstreamTaggerPoint.h" +#include "UpstreamTaggerHit.h" -#include "FairGeoBuilder.h" -#include "FairGeoInterface.h" -#include "FairGeoLoader.h" -#include "FairGeoMedia.h" -#include "FairGeoNode.h" +#include "FairVolume.h" #include "FairGeoVolume.h" -#include "FairLogger.h" +#include "FairGeoNode.h" #include "FairRootManager.h" +#include "FairGeoLoader.h" +#include "FairGeoInterface.h" +#include "FairGeoMedia.h" +#include "FairGeoBuilder.h" #include "FairRun.h" #include "FairRuntimeDb.h" -#include "FairVolume.h" #include "ShipDetectorList.h" #include "ShipStack.h" + #include "TClonesArray.h" +#include "TVirtualMC.h" +#include "TGeoManager.h" #include "TGeoBBox.h" #include "TGeoCompositeShape.h" -#include "TGeoManager.h" +#include "TGeoTube.h" #include "TGeoMaterial.h" #include "TGeoMedium.h" -#include "TGeoTube.h" #include "TMath.h" #include "TParticle.h" #include "TVector3.h" -#include "TVirtualMC.h" -#include "UpstreamTaggerPoint.h" +#include #include #include -#include using std::cout; using std::endl; +using ROOT::TSeq; +using ShipUnit::m; +using ShipUnit::cm; + UpstreamTagger::UpstreamTagger() - : FairDetector("UpstreamTagger", kTRUE, kStraw) - , fTrackID(-1) - , fVolumeID(-1) - , fPos() - , fMom() - , fTime(-1.) - , fLength(-1.) - , fELoss(-1) - , fMedium("air") - , fUpstreamTaggerPointCollection(new TClonesArray("UpstreamTaggerPoint")) -{} + : FairDetector("UpstreamTagger", kTRUE, kUpstreamTagger), + fTrackID(-1), + fVolumeID(-1), + fPos(), + fMom(), + fTime(-1.), + fLength(-1.), + fELoss(-1), + // + det_zPos(0), -UpstreamTagger::UpstreamTagger(std::string medium) - : FairDetector("UpstreamTagger", kTRUE, kStraw) - , fTrackID(-1) - , fVolumeID(-1) - , fPos() - , fMom() - , fTime(-1.) - , fLength(-1.) - , fELoss(-1) - , fMedium(medium) - , fUpstreamTaggerPointCollection(new TClonesArray("UpstreamTaggerPoint")) + // + UpstreamTagger_fulldet(0), + scoringPlaneUBText(0), + // + fUpstreamTaggerPointCollection(new TClonesArray("UpstreamTaggerPoint")) { } -UpstreamTagger::UpstreamTagger(const char* name, Bool_t active) - : FairDetector(name, active, kStraw), +//UpstreamTagger::UpstreamTagger(const char* name, Bool_t active) +UpstreamTagger::UpstreamTagger(std::string medium) + : FairDetector("UpstreamTagger", kTRUE, kUpstreamTagger), + fMedium(medium), fTrackID(-1), fVolumeID(-1), fPos(), @@ -75,28 +75,38 @@ UpstreamTagger::UpstreamTagger(const char* name, Bool_t active) fTime(-1.), fLength(-1.), fELoss(-1), + // + det_zPos(0), + + // + UpstreamTagger_fulldet(0), + scoringPlaneUBText(0), // Initialize new scoring plane to nullptr + // fUpstreamTaggerPointCollection(new TClonesArray("UpstreamTaggerPoint")) { } + +void UpstreamTagger::Initialize() +{ + FairDetector::Initialize(); +} + + UpstreamTagger::~UpstreamTagger() { + std::cout<<"destroyer droid"<Delete(); delete fUpstreamTaggerPointCollection; } } -void UpstreamTagger::Initialize() -{ - FairDetector::Initialize(); -// FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb(); -// vetoGeoPar* par=(vetoGeoPar*)(rtdb->getContainer("vetoGeoPar")); -} -// ----- Private method InitMedium + Int_t UpstreamTagger::InitMedium(const char* name) { + static FairGeoLoader *geoLoad=FairGeoLoader::Instance(); static FairGeoInterface *geoFace=geoLoad->getGeoInterface(); static FairGeoMedia *media=geoFace->getMedia(); @@ -114,10 +124,15 @@ Int_t UpstreamTagger::InitMedium(const char* name) return ShipMedium->getMediumIndex(); return geoBuild->createMedium(ShipMedium); + + return 0; } + + Bool_t UpstreamTagger::ProcessHits(FairVolume* vol) { + std::cout<<"processing a hit"<IsTrackEntering() ) { @@ -127,60 +142,54 @@ Bool_t UpstreamTagger::ProcessHits(FairVolume* vol) gMC->TrackPosition(fPos); gMC->TrackMomentum(fMom); } + std::cout<<"gello"<Edep(); + std::cout<<"eLoss: "<IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared() ) { if (fELoss == 0. ) { return kFALSE; } - TParticle* p=gMC->GetStack()->GetCurrentTrack(); - Int_t pdgCode = p->GetPdgCode(); + std::cout<<"going well"<GetStack()->GetCurrentTrackNumber(); - Int_t straw_uniqueId; - gMC->CurrentVolID(straw_uniqueId); - if (fVolumeID == straw_uniqueId) { - //std::cout << pdgCode<< " same volume again ? "<< straw_uniqueId << " exit:" << gMC->IsTrackExiting() << " stop:" << gMC->IsTrackStop() << " disappeared:" << gMC->IsTrackDisappeared()<< std::endl; - return kTRUE; } - fVolumeID = straw_uniqueId; - // # d = |pq . u x v|/|u x v| - TVector3 bot,top; - StrawEndPoints(straw_uniqueId,bot,top); + + Int_t uniqueId; + gMC->CurrentVolID(uniqueId); + if (uniqueId>1000000) //Solid scintillator case + { + Int_t vcpy; + gMC->CurrentVolOffID(1, vcpy); + if (vcpy==5) uniqueId+=4; //Copy of half + } + + TParticle* p = gMC->GetStack()->GetCurrentTrack(); + Int_t pdgCode = p->GetPdgCode(); TLorentzVector Pos; gMC->TrackPosition(Pos); + TLorentzVector Mom; + gMC->TrackMomentum(Mom); Double_t xmean = (fPos.X()+Pos.X())/2. ; Double_t ymean = (fPos.Y()+Pos.Y())/2. ; Double_t zmean = (fPos.Z()+Pos.Z())/2. ; - TVector3 pq = TVector3(top.x()-xmean,top.y()-ymean,top.z()-zmean ); - TVector3 u = TVector3(bot.x()-top.x(),bot.y()-top.y(),bot.z()-top.z() ); - TVector3 v = TVector3(fPos.X()-Pos.X(),fPos.Y()-Pos.Y(),fPos.Z()-Pos.Z()); - TVector3 uCrossv = u.Cross(v); - Double_t dist2Wire = fabs(pq.Dot(uCrossv))/(uCrossv.Mag()+1E-8); - Double_t deltaTrackLength = gMC->TrackLength() - fLength; - AddHit(fTrackID, straw_uniqueId, TVector3(xmean, ymean, zmean), - TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, deltaTrackLength, - fELoss,pdgCode,dist2Wire); - if (dist2Wire > f_inner_straw_diameter / 2){ - std::cout << "addhit " << dist2Wire<< " straw id " << straw_uniqueId << " pdgcode " << pdgCode<< " dot prod " << pq.Dot(uCrossv)<< std::endl; - std::cout << " exit:" << gMC->IsTrackExiting() << " stop:" << gMC->IsTrackStop() << " disappeared:" << gMC->IsTrackDisappeared()<< std::endl; - std::cout << " entry:" << fPos.X()<< " " << fPos.Y()<< " " << fPos.Z() << std::endl; - std::cout << " exit:" << Pos.X()<< " " << Pos.Y()<< " " << Pos.Z() << std::endl; - std::cout << " mean:" << xmean<< " " << ymean << " " << zmean << std::endl; - std::cout << " bot:" << bot.x()<< " " << bot.y() << " " << bot.z() << std::endl; - std::cout << " top:" << top.x()<< " " << top.y() << " " << top.z() << std::endl; - pq.Print(); - u.Print(); - v.Print(); - uCrossv.Print(); - } - // Increment number of UpstreamTagger det points in TParticle + + AddHit(fTrackID, uniqueId, TVector3(xmean, ymean, zmean), + TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, + fELoss,pdgCode,TVector3(Pos.X(), Pos.Y(), Pos.Z()), + TVector3(Mom.Px(), Mom.Py(), Mom.Pz()) ); + + // Increment number of veto det points in TParticle ShipStack* stack = dynamic_cast(gMC->GetStack()); - stack->AddPoint(kStraw); + stack->AddPoint(kUpstreamTagger); } + return kTRUE; } + + void UpstreamTagger::EndOfEvent() { fUpstreamTaggerPointCollection->Clear(); @@ -202,16 +211,21 @@ void UpstreamTagger::Register() } + TClonesArray* UpstreamTagger::GetCollection(Int_t iColl) const { if (iColl == 0) { return fUpstreamTaggerPointCollection; } else { return NULL; } } + + void UpstreamTagger::Reset() { fUpstreamTaggerPointCollection->Clear(); } + + void UpstreamTagger::SetzPositions(Double_t z1, Double_t z2, Double_t z3, Double_t z4) { f_T1_z = z1; //! z-position of tracking station 1 @@ -273,10 +287,13 @@ void UpstreamTagger::SetStationEnvelope(Double_t x, Double_t y, Double_t z) void UpstreamTagger::ConstructGeometry() { - /** If you are using the standard ASCII input for the geometry + + /** If you are using the standard ASCII input for the geometry just copy this and use it for your detector, otherwise you can implement here you own way of constructing the geometry. */ + std::cout<<"Making a geometry"<GetTopVolume(); InitMedium("air"); TGeoMedium *air = gGeoManager->GetMedium("air"); @@ -299,11 +316,11 @@ void UpstreamTagger::ConstructGeometry() gGeoManager->SetTopVisible(); // Epsilon to avoid overlapping volumes - Double_t eps = 0.0001; + Double_t eps = 0.01; // Straw (half) length Double_t straw_length = f_aperture_width + 2. * eps; // Width of frame: standard HEA 500 I-beam width - Double_t frame_width = 49.; + Double_t frame_width = 49.; // Offset due to floor space limitation Double_t floor_offset = 14.; @@ -311,24 +328,27 @@ void UpstreamTagger::ConstructGeometry() // Arguments of boxes are half-lengths TGeoBBox* detbox1 = new TGeoBBox( - "detbox1", f_aperture_width + frame_width, f_aperture_height + frame_width - floor_offset / 2., f_station_length); + "ubt_detbox1", (f_station_width + frame_width), (f_station_height + frame_width - floor_offset / 2.), f_station_length); TGeoBBox* detbox2 = new TGeoBBox( - "detbox2", - straw_length + eps, - f_aperture_height + TMath::Tan(f_view_angle * TMath::Pi() / 180.0) * straw_length * 2 + f_offset_layer / TMath::Cos(f_view_angle * TMath::Pi() / 180.0) + eps, + "ubt_detbox2", + (straw_length + eps), + (f_station_height + TMath::Tan(f_view_angle * TMath::Pi() / 180.0) * straw_length * 2 + f_offset_layer / TMath::Cos(f_view_angle * TMath::Pi() / 180.0) + eps), f_station_length + eps); + + std::cout<<"frame height: "<RegisterYourself(); // Composite shape to create frame - TGeoCompositeShape* detcomp1 = new TGeoCompositeShape("detcomp1", "(detbox1:move_up)-detbox2"); + TGeoCompositeShape* detcomp1 = new TGeoCompositeShape("ubt_detcomp1", "ubt_detbox1:move_up - ubt_detbox2"); // Volume: straw rmin = f_inner_straw_diameter / 2.; rmax = f_outer_straw_diameter / 2.; // Third argument is half-length of tube - TGeoTube *straw_tube = new TGeoTube("straw", rmin, rmax, straw_length); - TGeoVolume *straw = new TGeoVolume("straw", straw_tube, mylar); + TGeoTube *straw_tube = new TGeoTube("ubt_straw", rmin, rmax, straw_length); + TGeoVolume *straw = new TGeoVolume("ubt_straw", straw_tube, mylar); straw->SetLineColor(4); straw->SetVisibility(kTRUE); @@ -352,13 +372,13 @@ void UpstreamTagger::ConstructGeometry() // statnb = station number; vnb = view number; lnb = layer number; snb = straw number // Station box to contain all components - TGeoBBox* statbox = new TGeoBBox("statbox", f_station_width, f_station_height - floor_offset / 2., f_station_length); + TGeoBBox* statbox = new TGeoBBox("ubt_statbox", 0.01*f_station_width, 0.01*f_station_height - floor_offset / 2., 0.01*f_station_length); f_frame_material.ToLower(); - for (Int_t statnb = 1; statnb < 5; statnb++) { + for (Int_t statnb = 1; statnb < 2; statnb++) { // Tracking station loop - TString nmstation = "Tr"; + TString nmstation = "UBT"; std::stringstream ss; ss << statnb; nmstation = nmstation + ss.str(); @@ -366,15 +386,6 @@ void UpstreamTagger::ConstructGeometry() case 1: T_station_z = f_T1_z; break; - case 2: - T_station_z = f_T2_z; - break; - case 3: - T_station_z = f_T3_z; - break; - case 4: - T_station_z = f_T4_z; - break; default: T_station_z = f_T1_z; } @@ -385,16 +396,16 @@ void UpstreamTagger::ConstructGeometry() TGeoVolume* statframe = new TGeoVolume(nmstation + "_frame", detcomp1, FrameMatPtr); vol->AddNode(statframe, statnb * 1e6, new TGeoTranslation(0, -floor_offset / 2., 0)); - statframe->SetLineColor(kRed); + statframe->SetLineColor(kOrange); for (Int_t vnb = 0; vnb < 4; vnb++) { // View loop TString nmview; Double_t angle; - Double_t stereo_growth; - Double_t stereo_pitch; - Double_t offset_layer; - Int_t straws_per_layer; + Double_t stereo_growth; + Double_t stereo_pitch; + Double_t offset_layer; + Int_t straws_per_layer; switch (vnb) { case 0: @@ -471,95 +482,66 @@ void UpstreamTagger::ConstructGeometry() } // End of view loop } - // End of tracking station loop + // A layer of plastic scintillator detector + InitMedium("polyvinyltoluene"); + TGeoMedium *Vacuum_box =gGeoManager->GetMedium("polyvinyltoluene"); + UpstreamTagger_plastic = gGeoManager->MakeBox("Upstream_Tagger_Plastic", Vacuum_box, 150, 150, 1); + UpstreamTagger_plastic->SetLineColor(kGreen); + vol->AddNode(UpstreamTagger_plastic, 1, new TGeoTranslation(0.0, 0.0, -50)); + std::cout<<"geometry constructed"<GetTopVolume(); + + ////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////// + + InitMedium("STTmix8020_1bar"); + TGeoMedium *Vacuum_box =gGeoManager->GetMedium("STTmix8020_1bar"); + /////////////////////////////////////////////////////////////////// + + // Adding UBT Extension + if (!Vacuum_box) { + Fatal("ConstructGeometry", "Medium 'vacuum' not found."); + } + + UpstreamTagger_fulldet = gGeoManager->MakeBox("Upstream_Tagger", Vacuum_box, xbox_fulldet/2.0, ybox_fulldet/2.0, zbox_fulldet/2.0); + UpstreamTagger_fulldet->SetLineColor(kGreen); + + UpstreamTagger_fulldet_1 = gGeoManager->MakeBox("Upstream_Tagger_firstLayer", Vacuum_box, xbox_fulldet/2.0, ybox_fulldet/2.0, zbox_fulldet/2.0); + UpstreamTagger_fulldet_1->SetLineColor(kGreen); + UpstreamTagger_fulldet_3 = gGeoManager->MakeBox("Upstream_Tagger_lastLayer", Vacuum_box, xbox_fulldet/2.0, ybox_fulldet/2.0, zbox_fulldet/2.0); + UpstreamTagger_fulldet_3->SetLineColor(kGreen); + + top->AddNode(UpstreamTagger_fulldet, 1, new TGeoTranslation(0.0, 0.0, det_zPos)); + top->AddNode(UpstreamTagger_fulldet_1, 1, new TGeoTranslation(0.0, 0.0, det_zPos-4.*cm)); + top->AddNode(UpstreamTagger_fulldet_3, 1, new TGeoTranslation(0.0, 0.0, det_zPos+4.*cm)); + + AddSensitiveVolume(UpstreamTagger_fulldet); + AddSensitiveVolume(UpstreamTagger_fulldet_1); + AddSensitiveVolume(UpstreamTagger_fulldet_3); + + cout << " Z Position (Upstream Tagger1) " << det_zPos << endl; + ////////////////////////////////////////////////////////////////// + + return; +*/ } -// ----- Public method StrawDecode ------------------------------------------- -// ----- returns station, view, layer, straw number in a tuple ----------------------------------- -std::tuple UpstreamTagger::StrawDecode(Int_t detID) -{ - Int_t statnb, vnb, lnb, snb; - statnb = detID / 1e6; - vnb = (detID - statnb * 1e6) / 1e5; - lnb = (detID - statnb * 1e6 - vnb * 1e5) / 1e4; - snb = detID - statnb * 1e6 - vnb * 1e5 - lnb * 1e4 - 2e3; - - if (statnb < 1 || statnb > 4 || vnb < 0 || vnb > 3 || lnb < 0 || lnb > 1 || snb < 1 || snb > 317) { - LOG(warning) << "Invalid UpstreamTagger detID:"; - LOG(warning) << detID << " -> station: " << statnb << ", view: " << vnb << ", layer: " << lnb - << ", straw: " << snb; - LOG(warning) << "UpstreamTagger detID is 7-digit!"; - return std::make_tuple(0, -1, -1, 0); - } else { - return std::make_tuple(statnb, vnb, lnb, snb); - } -} -// ----- Public method StrawEndPoints ------------------------------------------- -// ----- returns top (left) and bottom (right) coordinates of straw ----------------------------------- -void UpstreamTagger::StrawEndPoints(Int_t fDetectorID, TVector3 &vbot, TVector3 &vtop) -// method to get end points from TGeoNavigator -{ - const auto [statnb, vnb, lnb, snb] = StrawDecode(fDetectorID); - TString stat = "Tr"; stat += statnb; stat += "_"; stat += statnb; - TString view; - switch (vnb) { - case 0: - view = "_y1"; - break; - case 1: - view = "_u"; - break; - case 2: - view = "_v"; - break; - case 3: - view = "_y2"; - break; - default: - view = "_y1"; - } - TGeoNavigator* nav = gGeoManager->GetCurrentNavigator(); - TString prefix = "Tr"; - prefix += statnb; - prefix += view; - prefix += "_"; - TString layer = prefix + "layer_"; - layer += lnb; - layer += "_"; - layer += statnb; - layer += vnb; - layer += lnb; - layer += "0000"; - TString wire = "wire_"; - wire += fDetectorID + 1e3; - TString path = "/"; - path += stat; - path += "/"; - path += layer; - path += "/"; - path += wire; - Bool_t rc = nav->cd(path); - if (!rc) { - LOG(warning) << "UpstreamTagger::StrawDecode, TGeoNavigator failed" << path; - return; - } - TGeoNode* W = nav->GetCurrentNode(); - TGeoTube* S = dynamic_cast(W->GetVolume()->GetShape()); - Double_t top[3] = {0, 0, S->GetDZ()}; - Double_t bot[3] = {0, 0, -S->GetDZ()}; - Double_t Gtop[3], Gbot[3]; - nav->LocalToMaster(top, Gtop); nav->LocalToMaster(bot, Gbot); - vtop.SetXYZ(Gtop[0], Gtop[1], Gtop[2]); - vbot.SetXYZ(Gbot[0], Gbot[1], Gbot[2]); -} + + + UpstreamTaggerPoint* UpstreamTagger::AddHit(Int_t trackID, Int_t detID, - TVector3 pos, TVector3 mom, - Double_t time, Double_t length, - Double_t eLoss, Int_t pdgCode, Double_t dist2Wire) + TVector3 pos, TVector3 mom, + Double_t time, Double_t length, + Double_t eLoss, Int_t pdgCode,TVector3 Lpos, TVector3 Lmom) { TClonesArray& clref = *fUpstreamTaggerPointCollection; Int_t size = clref.GetEntriesFast(); - //std::cout << "adding hit detid " < StrawDecode(Int_t detID); static void StrawEndPoints(Int_t detID, TVector3& top, TVector3& bot); -// for the digitizing step - void SetStrawResolution(Double_t a, Double_t b) - { - v_drift = a; - sigma_spatial = b; - } - Double_t StrawVdrift() {return v_drift;} - Double_t StrawSigmaSpatial() {return sigma_spatial;} - /** Create the detector geometry */ + /** Create the detector geometry */ void ConstructGeometry(); - - /** This method is an example of how to add your own point - * of type UpstreamTaggerPoint to the clones array + * of type TimeRpcPoint to the clones array */ UpstreamTaggerPoint* AddHit(Int_t trackID, Int_t detID, - TVector3 pos, TVector3 mom, - Double_t time, Double_t length, - Double_t eLoss, Int_t pdgCode, Double_t dist2Wire); + TVector3 pos, TVector3 mom, + Double_t time, Double_t length, + Double_t eLoss, Int_t pdgCode,TVector3 Lpos, TVector3 Lmom); - /** The following methods can be implemented if you need to make - * any optional action in your detector during the transport. - */ - - virtual void CopyClones( TClonesArray* cl1, TClonesArray* cl2 , - Int_t offset) {;} - virtual void SetSpecialPhysicsCuts() {;} virtual void EndOfEvent(); virtual void FinishPrimary() {;} virtual void FinishRun() {;} @@ -99,47 +110,59 @@ class UpstreamTagger: public FairDetector virtual void PreTrack() {;} virtual void BeginEvent() {;} + Double_t module[11][3]; // x,y,z centre positions for each module + // TODO Avoid 1-indexed array! + + /** Track information to be stored until the track leaves the active volume.*/ + Int_t fTrackID; //! track index + Int_t fVolumeID; //! volume id + TLorentzVector fPos; //! position at entrance + TLorentzVector fMom; //! momentum at entrance + Double_t fTime; //! time + Double_t fLength; //! length + Double_t fELoss; //! energy loss + + Double_t f_aperture_width; + Double_t f_aperture_height; + Double_t f_station_length; + Double_t f_station_width; + Double_t f_station_height; + Double_t f_straw_pitch; + Double_t f_view_angle; + Double_t f_offset_layer; + Double_t f_inner_straw_diameter; + Double_t f_outer_straw_diameter; + Double_t f_wire_thickness; + Double_t f_T1_z,f_T2_z,f_T3_z,f_T4_z; + Double_t f_delta_z_view; + Double_t f_delta_z_layer; + TString f_frame_material; + std::string fMedium; + /** Detector parameters.*/ + + Double_t det_zPos; //! z-position of detector (set via SetZposition) + // Detector box dimensions (set via SetBoxDimensions, defaults provided below) + Double_t xbox_fulldet;// = 4.4 * m; //! X dimension (default: 4.4 m) + Double_t ybox_fulldet;// = 6.4 * m; //! Y dimension (default: 6.4 m) + Double_t zbox_fulldet;// = 16.0 * cm; //! Z dimension/thickness (default: 16 cm) + private: - /** Track information to be stored until the track leaves the - active volume. - */ - Int_t fTrackID; //! track index - Int_t fVolumeID; //! volume id - TLorentzVector fPos; //! position at entrance - TLorentzVector fMom; //! momentum at entrance - Double_t fTime; //! time - Double_t fLength; //! length - Double_t fELoss; //! energy loss - Double_t f_T1_z; //! z-position of tracking station 1 - Double_t f_T2_z; //! z-position of tracking station 2 - Double_t f_T3_z; //! z-position of tracking station 3 - Double_t f_T4_z; //! z-position of tracking station 4 - Double_t f_aperture_width; //! Aperture width (x) - Double_t f_aperture_height; //! Aperture height (y) - Double_t f_inner_straw_diameter; //! Inner Straw diameter - Double_t f_outer_straw_diameter; //! Outer Straw diameter - Double_t f_straw_pitch; //! Distance (y) between straws in a layer - Double_t f_offset_layer; //! Offset (y) of straws between layers - Double_t f_delta_z_layer; //! Distance (z) between layers - Double_t f_view_angle; //! Stereo view angle - Double_t f_wire_thickness; //! Sense wire thickness - TString f_frame_material; //! Structure frame material - Double_t f_delta_z_view; //! Distance (z) between stereo views - Double_t f_station_width; //! Station envelope width (x) - Double_t f_station_height; //! Station envelope height (y) - Double_t f_station_length; //! Station envelope length (z) - Double_t v_drift; //! drift velocity - Double_t sigma_spatial; //! spatial resolution - std::string fMedium; //! vacuum box medium - /** container for data points */ + TGeoVolume* UpstreamTagger_plastic; + TGeoVolume* UpstreamTagger_fulldet; // Timing_detector_1 object + TGeoVolume* UpstreamTagger_fulldet_1; // Timing_detector_1 object + TGeoVolume* UpstreamTagger_fulldet_3; // Timing_detector_1 object + TGeoVolume* scoringPlaneUBText; // new scoring plane + /** container for data points */ TClonesArray* fUpstreamTaggerPointCollection; UpstreamTagger(const UpstreamTagger&); UpstreamTagger& operator=(const UpstreamTagger&); Int_t InitMedium(const char* name); - ClassDef(UpstreamTagger, 6) + + + ClassDef(UpstreamTagger,1) }; -#endif // UpstreamTagger_UpstreamTagger_H_ +#endif // UPSTREAMTAGGER_UPSTREAMTAGGER_H_ diff --git a/macro/run_simScript.py b/macro/run_simScript.py index 37ad2c276a..d231a3130f 100755 --- a/macro/run_simScript.py +++ b/macro/run_simScript.py @@ -591,17 +591,20 @@ # Plot the field example #fieldMaker.plotField(1, ROOT.TVector3(-9000.0, 6000.0, 50.0), ROOT.TVector3(-300.0, 300.0, 6.0), 'Bzx.png') #fieldMaker.plotField(2, ROOT.TVector3(-9000.0, 6000.0, 50.0), ROOT.TVector3(-400.0, 400.0, 6.0), 'Bzy.png') - +print("ABOUT TO RUN") # -----Start run---------------------------------------------------- run.Run(options.nEvents) +print("RUN OVER: KNACKERED") # -----Runtime database--------------------------------------------- -kParameterMerged = ROOT.kTRUE -parOut = ROOT.FairParRootFileIo(kParameterMerged) -parOut.open(parFile) -rtdb.setOutput(parOut) -rtdb.saveOutput() -rtdb.printParamContexts() +#kParameterMerged = ROOT.kTRUE +#parOut = ROOT.FairParRootFileIo(kParameterMerged) +#parOut.open(parFile) +#rtdb.setOutput(parOut) +#rtdb.saveOutput() +#rtdb.printParamContexts() getattr(rtdb,"print")() + +print("ABOUT TO GEMOFILE") # ------------------------------------------------------------------------ run.CreateGeometryFile(f"{options.outputDir}/geofile_full.{tag}.root") # save ShipGeo dictionary in geofile diff --git a/python/ShipGeo.py b/python/ShipGeo.py index e9d47c3df2..21dc4eb766 100644 --- a/python/ShipGeo.py +++ b/python/ShipGeo.py @@ -14,12 +14,18 @@ def zPositions(): for x in ShipGeo: if hasattr(eval('ShipGeo.'+x),'z'): print(x,'z=',eval('ShipGeo.'+x+'.z')) -vetoStation = ShipGeo(-2390.*u.cm) +#vetoStation = ShipGeo(-2390.*u.cm) TrackStation1 = ShipGeo(1510.*u.cm) TrackStation2 = ShipGeo(1710.*u.cm) TrackStation3 = ShipGeo(2150.*u.cm) TrackStation4 = ShipGeo(2370.*u.cm) +UBTStation1 = ShipGeo(2390.*u.cm) +UBTStation2 = ShipGeo(2395.*u.cm) +UBTStation3 = ShipGeo(2400.*u.cm) +UBTStation4 = ShipGeo(2405.*u.cm) + + z = TrackStation2.z + 0.5 * (TrackStation3.z - TrackStation2.z) Bfield = ShipGeo(z) Bfield.max = 1.5*u.kilogauss # was 1.15 in EOI diff --git a/python/geometry_config.py b/python/geometry_config.py index 9b375a11a9..e8b4e61bda 100644 --- a/python/geometry_config.py +++ b/python/geometry_config.py @@ -424,6 +424,11 @@ def create_config( c.Chamber1 = AttrDict(z=z4 - 4666.0 * u.cm - magnetIncrease - extraVesselLength) c.Chamber6 = AttrDict(z=z4 + 30.0 * u.cm + windowBulge / 2.0) + c.UBTStation1 = AttrDict(z = c.decayVolume.z0 - 25*u.cm) + c.UBTStation2 = AttrDict(z = c.decayVolume.z0 - 20*u.cm) + c.UBTStation3 = AttrDict(z = c.decayVolume.z0 - 15*u.cm) + c.UBTStation4 = AttrDict(z = c.decayVolume.z0 - 10*u.cm) + c.Bfield = AttrDict() c.Bfield.z = c.z c.Bfield.max = 0 # 1.4361*u.kilogauss # was 1.15 in EOI @@ -537,7 +542,7 @@ def create_config( c.UpstreamTagger = AttrDict() c.UpstreamTagger.BoxX = 4.4 * u.m # X dimension (width) c.UpstreamTagger.BoxY = 6.4 * u.m # Y dimension (height) - c.UpstreamTagger.BoxZ = 16.0 * u.cm # Z dimension (thickness) + c.UpstreamTagger.BoxZ = 2.0 * u.cm # Z dimension (thickness) c.UpstreamTagger.Z_Position = ( -25.400 * u.m + c.decayVolume.z ) # Relative position of UBT to decay vessel centre diff --git a/python/shipDet_conf.py b/python/shipDet_conf.py index 160c95d59a..beed6259fd 100644 --- a/python/shipDet_conf.py +++ b/python/shipDet_conf.py @@ -260,6 +260,56 @@ def configure_strawtubes(yaml_file, ship_geo): detectorList.append(strawtubes) +def configure_upstreamTagger(yaml_file, ship_geo): + with open(yaml_file) as file: + config = yaml.safe_load(file) + + ship_geo.ubt_geo = AttrDict(config['UBT']) + + # Straw tubes in decay vessel if vacuum, otherwise outside in air + ship_geo.ubt_geo.medium = "vacuums" if ship_geo.DecayVolumeMedium == "vacuums" else "air" + + ship_geo.ubt_geo.frame_material = "DIRCcarbonFiber" + + ubt = ROOT.UpstreamTagger(ship_geo.ubt_geo.medium) + ubt.SetzPositions( + ship_geo.UBTStation1.z, + ship_geo.UBTStation2.z, + ship_geo.UBTStation3.z, + ship_geo.UBTStation4.z, + ) + ubt.SetApertureArea( + ship_geo.ubt_geo.width, + ship_geo.ubt_geo.height, + ) + ubt.SetStrawDiameter( + ship_geo.ubt_geo.outer_straw_diameter, + ship_geo.ubt_geo.wall_thickness, + ) + ubt.SetStrawPitch( + ship_geo.ubt_geo.straw_pitch, + ship_geo.ubt_geo.y_layer_offset, + ) + ubt.SetDeltazLayer(ship_geo.ubt_geo.delta_z_layer) + ubt.SetStereoAngle(ship_geo.ubt_geo.view_angle) + ubt.SetWireThickness(ship_geo.ubt_geo.wire_thickness) + ubt.SetDeltazView(ship_geo.ubt_geo.delta_z_view) + ubt.SetFrameMaterial(ship_geo.ubt_geo.frame_material) + ubt.SetStationEnvelope( + ship_geo.ubt_geo.station_width, + ship_geo.ubt_geo.station_height, + ship_geo.ubt_geo.station_length, + ) + + + #For digitization +# strawtubes.SetStrawResolution( +# ship_geo.strawtubesDigi.v_drift, +# ship_geo.strawtubesDigi.sigma_spatial, +# ) + + detectorList.append(ubt) + def configure(run, ship_geo): # ---- for backward compatibility ---- @@ -444,14 +494,19 @@ def configure(run, ship_geo): Muon.SetFilterThickness(ship_geo.Muon.FilterThickness) detectorList.append(Muon) - upstreamTagger = ROOT.UpstreamTagger("UpstreamTagger", ROOT.kTRUE) - upstreamTagger.SetZposition(ship_geo.UpstreamTagger.Z_Position) - upstreamTagger.SetBoxDimensions( - ship_geo.UpstreamTagger.BoxX, - ship_geo.UpstreamTagger.BoxY, - ship_geo.UpstreamTagger.BoxZ +# upstreamTagger = ROOT.UpstreamTagger("UpstreamTagger", ROOT.kTRUE) +# upstreamTagger.SetZposition(ship_geo.UpstreamTagger.Z_Position) +# upstreamTagger.SetBoxDimensions( +# ship_geo.UpstreamTagger.BoxX, +# ship_geo.UpstreamTagger.BoxY, +# ship_geo.UpstreamTagger.BoxZ +# ) +# detectorList.append(upstreamTagger) + + configure_upstreamTagger( + os.path.join(os.environ["FAIRSHIP"], "geometry", "ubt_config.yaml"), + ship_geo, ) - detectorList.append(upstreamTagger) timeDet = ROOT.TimeDet("TimeDet", ROOT.kTRUE) timeDet.SetZposition(ship_geo.TimeDet.z) From 26af83910994d5c349c578ee3ba5daacd55b63ef Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Tue, 20 Jan 2026 14:15:08 +0100 Subject: [PATCH 3/8] UBT stuff --- python/geometry_config.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/python/geometry_config.py b/python/geometry_config.py index e8b4e61bda..1bee6de57a 100644 --- a/python/geometry_config.py +++ b/python/geometry_config.py @@ -424,10 +424,7 @@ def create_config( c.Chamber1 = AttrDict(z=z4 - 4666.0 * u.cm - magnetIncrease - extraVesselLength) c.Chamber6 = AttrDict(z=z4 + 30.0 * u.cm + windowBulge / 2.0) - c.UBTStation1 = AttrDict(z = c.decayVolume.z0 - 25*u.cm) - c.UBTStation2 = AttrDict(z = c.decayVolume.z0 - 20*u.cm) - c.UBTStation3 = AttrDict(z = c.decayVolume.z0 - 15*u.cm) - c.UBTStation4 = AttrDict(z = c.decayVolume.z0 - 10*u.cm) + c.UBTStation1 = AttrDict(z = c.decayVolume.z0 - 50*u.cm) c.Bfield = AttrDict() c.Bfield.z = c.z From 24e73f947d771156a60c42446e49006789103fcc Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Tue, 20 Jan 2026 14:18:59 +0100 Subject: [PATCH 4/8] UBT stuff --- geometry/ubt_config.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 geometry/ubt_config.yaml diff --git a/geometry/ubt_config.yaml b/geometry/ubt_config.yaml new file mode 100644 index 0000000000..e6e8d2d3cb --- /dev/null +++ b/geometry/ubt_config.yaml @@ -0,0 +1,14 @@ +# Geometry configuration of UBT (veto) in FairShip + +UBT: + width: 150 # Aperture width (x) in cm (half length) + height: 150 # Aperture height (y) in cm (half length) + wire_thickness: 0.003 # Sense wire thickness in cm + wall_thickness: 0.0036 # Straw wall thickness in cm + outer_straw_diameter: 2 # in cm + straw_pitch: 2 # Distance (y) between straws in a layer in cm + y_layer_offset: 1 # Offset (y) of straws between layers in cm + delta_z_layer: 1.732 # Distance (z) between layers in cm + delta_z_view: 12 # Distance (z) between stereo views in cm + view_angle: 4.57 # Stereo angle in degree + station_length: 40 # (z) in cm (half length) From aeaa050d7022e7fed514e3470ed36bb1feb29890 Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Wed, 21 Jan 2026 11:31:32 +0100 Subject: [PATCH 5/8] UBT stuff --- UpstreamTagger/UpstreamTagger.cxx | 36 ++++++++++++++++++++++++-- UpstreamTagger/UpstreamTagger.h | 2 +- UpstreamTagger/UpstreamTaggerPoint.cxx | 2 ++ UpstreamTagger/UpstreamTaggerPoint.h | 3 ++- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/UpstreamTagger/UpstreamTagger.cxx b/UpstreamTagger/UpstreamTagger.cxx index c1f127bf26..d26112b35c 100644 --- a/UpstreamTagger/UpstreamTagger.cxx +++ b/UpstreamTagger/UpstreamTagger.cxx @@ -43,6 +43,36 @@ using ShipUnit::m; using std::cout; using std::endl; +constexpr uint64_t hash(std::string_view str) { + uint64_t hash = 0; + for (char c : str) { + hash = (hash * 131) + c; + } + return hash; +} + +constexpr uint64_t operator"" _hash(const char* str, size_t len) { + return hash(std::string_view(str, len)); +} + + +constexpr const int detPieces(std::string_view pieceName) noexcept{ + switch(hash(pieceName)){ + case "Upstream_Tagger_Plastic"_hash: + return 0; + case "ubt_gas_UBT1_y2_layer"_hash: + return 1; + case "ubt_gas_UBT1_v_layer"_hash: + return 2; + case "ubt_gas_UBT1_u_layer"_hash: + return 3; + case "ubt_gas_UBT1_y1_layer"_hash: + return 4; + default: + return 10; + } +} + UpstreamTagger::UpstreamTagger() : FairDetector("UpstreamTagger", kTRUE, kUpstreamTagger), fTrackID(-1), @@ -141,6 +171,7 @@ Bool_t UpstreamTagger::ProcessHits(FairVolume* vol) gMC->CurrentVolID(uniqueId); const char* volName = gMC->CurrentVolName(); std::cout<<"volume id: "< 1000000) // Solid scintillator case { Int_t vcpy; @@ -158,7 +189,7 @@ Bool_t UpstreamTagger::ProcessHits(FairVolume* vol) Double_t ymean = (fPos.Y() + Pos.Y()) / 2.; Double_t zmean = (fPos.Z() + Pos.Z()) / 2.; - AddHit(fTrackID, uniqueId, TVector3(xmean, ymean, zmean), + AddHit(fTrackID, uniqueId, subDetID, TVector3(xmean, ymean, zmean), TVector3(fMom.Px(), fMom.Py(), fMom.Pz()), fTime, fLength, fELoss, pdgCode, TVector3(Pos.X(), Pos.Y(), Pos.Z()), TVector3(Mom.Px(), Mom.Py(), Mom.Pz())); @@ -448,11 +479,12 @@ void UpstreamTagger::ConstructGeometry() } UpstreamTaggerPoint* UpstreamTagger::AddHit(Int_t trackID, Int_t detID, + Int_t subDetID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss, Int_t pdgCode, TVector3 Lpos, TVector3 Lmom) { - fUpstreamTaggerPoints->emplace_back(trackID, detID, pos, mom, time, length, + fUpstreamTaggerPoints->emplace_back(trackID, detID, subDetID, pos, mom, time, length, eLoss, pdgCode, Lpos, Lmom); return &(fUpstreamTaggerPoints->back()); } diff --git a/UpstreamTagger/UpstreamTagger.h b/UpstreamTagger/UpstreamTagger.h index 7e86a882ba..b655e22815 100644 --- a/UpstreamTagger/UpstreamTagger.h +++ b/UpstreamTagger/UpstreamTagger.h @@ -101,7 +101,7 @@ class UpstreamTagger : public FairDetector, public ISTLPointContainer { /** This method is an example of how to add your own point * of type TimeRpcPoint to the clones array */ - UpstreamTaggerPoint* AddHit(Int_t trackID, Int_t detID, TVector3 pos, + UpstreamTaggerPoint* AddHit(Int_t trackID, Int_t detID, Int_t subDetID, TVector3 pos, TVector3 mom, Double_t time, Double_t length, Double_t eLoss, Int_t pdgCode, TVector3 Lpos, TVector3 Lmom); diff --git a/UpstreamTagger/UpstreamTaggerPoint.cxx b/UpstreamTagger/UpstreamTaggerPoint.cxx index d413f6dd2b..de2caff7d4 100644 --- a/UpstreamTagger/UpstreamTaggerPoint.cxx +++ b/UpstreamTagger/UpstreamTaggerPoint.cxx @@ -14,12 +14,14 @@ UpstreamTaggerPoint::UpstreamTaggerPoint() : FairMCPoint() {} // ----- Standard constructor ------------------------------------------ UpstreamTaggerPoint::UpstreamTaggerPoint(Int_t trackID, Int_t detID, + Int_t subDetID, TVector3 pos, TVector3 mom, Double_t tof, Double_t length, Double_t eLoss, Int_t pdgcode, TVector3 Lpos, TVector3 Lmom) : FairMCPoint(trackID, detID, pos, mom, tof, length, eLoss), fPdgCode(pdgcode), + fSubDetID(subDetID), fLpos{Lpos.X(), Lpos.Y(), Lpos.Z()}, fLmom{Lmom.X(), Lmom.Y(), Lmom.Z()} {} // ------------------------------------------------------------------------- diff --git a/UpstreamTagger/UpstreamTaggerPoint.h b/UpstreamTagger/UpstreamTaggerPoint.h index c6ff1f3a75..2a7cdbeb78 100644 --- a/UpstreamTagger/UpstreamTaggerPoint.h +++ b/UpstreamTagger/UpstreamTaggerPoint.h @@ -27,7 +27,7 @@ class UpstreamTaggerPoint : public FairMCPoint { *@param length Track length since creation [cm] *@param eLoss Energy deposit [GeV] **/ - UpstreamTaggerPoint(Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, + UpstreamTaggerPoint(Int_t trackID, Int_t detID, Int_t subDetID, TVector3 pos, TVector3 mom, Double_t tof, Double_t length, Double_t eLoss, Int_t pdgCode, TVector3 Lpos, TVector3 Lmom); @@ -47,6 +47,7 @@ class UpstreamTaggerPoint : public FairMCPoint { private: Int_t fPdgCode; + Int_t fSubDetID; std::array fLpos, fLmom; ClassDef(UpstreamTaggerPoint, 3) From f0cef424b72e4aa9d656fd527a54dd2420fc34e6 Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Wed, 21 Jan 2026 16:21:58 +0100 Subject: [PATCH 6/8] ubt stuff --- UpstreamTagger/UpstreamTaggerHit.cxx | 2 ++ UpstreamTagger/UpstreamTaggerHit.h | 1 + UpstreamTagger/UpstreamTaggerPoint.h | 2 ++ 3 files changed, 5 insertions(+) diff --git a/UpstreamTagger/UpstreamTaggerHit.cxx b/UpstreamTagger/UpstreamTaggerHit.cxx index 01d788fbf4..09a9e564c1 100644 --- a/UpstreamTagger/UpstreamTaggerHit.cxx +++ b/UpstreamTagger/UpstreamTaggerHit.cxx @@ -29,6 +29,8 @@ UpstreamTaggerHit::UpstreamTaggerHit(UpstreamTaggerPoint* p, Double_t t0, // Smear time with Gaussian resolution fTime = gRandom->Gaus(p->GetTime() + t0, time_res); + + fSubDetID = p->GetLayerID(); } // ----- Destructor ------------------------- diff --git a/UpstreamTagger/UpstreamTaggerHit.h b/UpstreamTagger/UpstreamTaggerHit.h index f9bce7a2d6..258f697785 100644 --- a/UpstreamTagger/UpstreamTaggerHit.h +++ b/UpstreamTagger/UpstreamTaggerHit.h @@ -56,6 +56,7 @@ class UpstreamTaggerHit : public ShipHit { Double_t fY; ///< Smeared y position (cm) Double_t fZ; ///< Smeared z position (cm) Double_t fTime; ///< Smeared time (ns) + Int_t fSubDetID; ///< Which layer of the UBT is this ClassDef(UpstreamTaggerHit, 2); }; diff --git a/UpstreamTagger/UpstreamTaggerPoint.h b/UpstreamTagger/UpstreamTaggerPoint.h index 2a7cdbeb78..39367b78d6 100644 --- a/UpstreamTagger/UpstreamTaggerPoint.h +++ b/UpstreamTagger/UpstreamTaggerPoint.h @@ -44,6 +44,8 @@ class UpstreamTaggerPoint : public FairMCPoint { Int_t PdgCode() const { return fPdgCode; } TVector3 LastPoint() const { return TVector3(fLpos[0], fLpos[1], fLpos[2]); } TVector3 LastMom() const { return TVector3(fLmom[0], fLmom[1], fLmom[2]); } + Int_t GetLayerID() const { return fSubDetID; }; + private: Int_t fPdgCode; From ea006b70b0b8a6ba3e3db74a7afccbb8e7d9bb8f Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Tue, 3 Feb 2026 17:57:42 +0100 Subject: [PATCH 7/8] thing --- macro/run_simScript.py | 17 +++++++---------- python/shipDet_conf.py | 25 ------------------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/macro/run_simScript.py b/macro/run_simScript.py index 235abda41a..60e9c4ad5a 100755 --- a/macro/run_simScript.py +++ b/macro/run_simScript.py @@ -581,20 +581,17 @@ # Plot the field example #fieldMaker.plotField(1, ROOT.TVector3(-9000.0, 6000.0, 50.0), ROOT.TVector3(-300.0, 300.0, 6.0), 'Bzx.png') #fieldMaker.plotField(2, ROOT.TVector3(-9000.0, 6000.0, 50.0), ROOT.TVector3(-400.0, 400.0, 6.0), 'Bzy.png') -print("ABOUT TO RUN") + # -----Start run---------------------------------------------------- run.Run(options.nEvents) -print("RUN OVER: KNACKERED") # -----Runtime database--------------------------------------------- -#kParameterMerged = ROOT.kTRUE -#parOut = ROOT.FairParRootFileIo(kParameterMerged) -#parOut.open(parFile) -#rtdb.setOutput(parOut) -#rtdb.saveOutput() -#rtdb.printParamContexts() +kParameterMerged = ROOT.kTRUE +parOut = ROOT.FairParRootFileIo(kParameterMerged) +parOut.open(parFile) +rtdb.setOutput(parOut) +rtdb.saveOutput() +rtdb.printParamContexts() getattr(rtdb,"print")() - -print("ABOUT TO GEMOFILE") # ------------------------------------------------------------------------ geofile_name = f"{options.outputDir}/geo_{run_identifier}.root" run.CreateGeometryFile(geofile_name) diff --git a/python/shipDet_conf.py b/python/shipDet_conf.py index 811d8b10af..6fbdaee834 100644 --- a/python/shipDet_conf.py +++ b/python/shipDet_conf.py @@ -471,31 +471,6 @@ def configure(run, ship_geo): SplitCal.SetStripSize(x.StripHalfWidth, x.StripHalfLength) detectorList.append(SplitCal) - Muon = ROOT.muon("Muon", ROOT.kTRUE) - Muon.SetZStationPositions( - ship_geo.MuonStation0.z, - ship_geo.MuonStation1.z, - ship_geo.MuonStation2.z, - ship_geo.MuonStation3.z, - ) - Muon.SetZFilterPositions( - ship_geo.MuonFilter0.z, ship_geo.MuonFilter1.z, ship_geo.MuonFilter2.z - ) - Muon.SetXMax(ship_geo.Muon.XMax) - Muon.SetYMax(ship_geo.Muon.YMax) - Muon.SetActiveThickness(ship_geo.Muon.ActiveThickness) - Muon.SetFilterThickness(ship_geo.Muon.FilterThickness) - detectorList.append(Muon) - -# upstreamTagger = ROOT.UpstreamTagger("UpstreamTagger", ROOT.kTRUE) -# upstreamTagger.SetZposition(ship_geo.UpstreamTagger.Z_Position) -# upstreamTagger.SetBoxDimensions( -# ship_geo.UpstreamTagger.BoxX, -# ship_geo.UpstreamTagger.BoxY, -# ship_geo.UpstreamTagger.BoxZ -# ) -# detectorList.append(upstreamTagger) - configure_upstreamTagger( os.path.join(os.environ["FAIRSHIP"], "geometry", "ubt_config.yaml"), ship_geo, From 9eee80a1635f3fa8d4d21d563f6ca38706b5f862 Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Wed, 4 Feb 2026 17:09:44 +0100 Subject: [PATCH 8/8] fix test --- tests/test_rntuple_io.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_rntuple_io.cxx b/tests/test_rntuple_io.cxx index 82852c8b17..aa580161d7 100644 --- a/tests/test_rntuple_io.cxx +++ b/tests/test_rntuple_io.cxx @@ -349,9 +349,9 @@ int main(int argc, char** argv) { TVector3 mom(0.1, 0.2, 0.3); TVector3 lpos(1.1, 2.1, 3.1); TVector3 lmom(0.11, 0.21, 0.31); - objects.emplace_back(1, 1001, pos, mom, 123.45, 234.56, 0.001, 2212, lpos, + objects.emplace_back(1, 1001, 1, pos, mom, 123.45, 234.56, 0.001, 2212, lpos, lmom); - objects.emplace_back(2, 2002, pos, mom, 345.67, 456.78, 0.002, 211, lpos, + objects.emplace_back(2, 2002, 1, pos, mom, 345.67, 456.78, 0.002, 211, lpos, lmom); total++; if (test_rntuple_io("UpstreamTaggerPoint", objects)) passed++;