Skip to content

Commit

Permalink
Added beampipe stop instead of kiling in beamline volume
Browse files Browse the repository at this point in the history
  • Loading branch information
simonge committed Oct 11, 2024
1 parent da36ad7 commit 3f6cace
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
8 changes: 8 additions & 0 deletions compact/far_backward/beamline_tracking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
name="Pipe_in_Q4eR_tracker"/>

</detector>

<detector
type="BeamPipeStop"
name="Backwards_Pipe_Stop"
grandmother="Pipe_Q3eR_to_B7eR"
mother="Pipe_Q4eR_to_B3eR_vacuum"
/>

</detectors>

<readouts>
Expand Down
3 changes: 0 additions & 3 deletions src/BeamPipeChain_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector /
vector<double> thetas;
vector<double> rOuters1;
vector<double> rOuters2;
vector<string> limits;

// Grab info for beamline magnets
for (xml_coll_t pipe_coll(x_det, _Unicode(pipe)); pipe_coll; pipe_coll++) { // pipes
Expand All @@ -55,7 +54,6 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector /
thetas.push_back(getAttrOrDefault<double>(pipe, _Unicode(theta), 0));
rOuters1.push_back(getAttrOrDefault<double>(pipe, _Unicode(rout1), 0));
rOuters2.push_back(getAttrOrDefault<double>(pipe, _Unicode(rout2), 0));
limits.push_back(getAttrOrDefault<std::string>(pipe, _Unicode(limits), "world_limits"));
}

// Calculate parameters for connecting pipes in between magnets
Expand Down Expand Up @@ -109,7 +107,6 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector /
Volume v_vacuum("v_vacuum_" + names[pipeN], s_vacuum, m_Vacuum);

v_tube.setVisAttributes(description.visAttributes(vis_name));
v_vacuum.setLimitSet(description, limits[pipeN]);

assembly.placeVolume(v_tube, Transform3D(RotationY(thetas[pipeN]),
Position(xCenters[pipeN], 0, zCenters[pipeN])));
Expand Down
68 changes: 68 additions & 0 deletions src/BeamPipeStop_geo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2024 Simon Gardner

//==========================================================================
//
// Places a small sensitive disk of vacuum at the end of beam pipes
//
//==========================================================================

#include "DD4hep/DetFactoryHelper.h"
#include "DD4hep/Printout.h"
#include "TMath.h"
#include <XML/Helper.h>

using namespace std;
using namespace dd4hep;

static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector /* sens */) {

using namespace ROOT::Math;
xml_det_t x_det = e;
string det_name = x_det.nameStr();
int det_id = x_det.id();
Material m_Vacuum = description.material("Vacuum");
string vis_name = dd4hep::getAttrOrDefault<std::string>(x_det, _Unicode(vis), "BeamPipeVis");

string grandmotherName = x_det.attr<string>(_Unicode(grandmother));
string motherName = x_det.attr<string>(_Unicode(mother));
bool detStart = getAttrOrDefault<bool>(x_det, _Unicode(end), true);
DetElement mother = description.detector(grandmotherName).child(motherName);

DetElement sdet(det_name, det_id);

// Get the mother volume
Volume mother_vol = mother.volume();

// Get mother volume shape as cone segment
ConeSegment mother_shape = mother_vol.solid();

// Get the parameters of the mother volume
double rOuter1 = mother_shape.rMax1();
double rOuter2 = mother_shape.rMax2();
double length = 2 * mother_shape.dZ();

double sensitive_thickness = 100 * mm;

//Calculate R or cone after sensitive layer
double rEnd = rOuter2 - (rOuter2 - rOuter1) * sensitive_thickness / length;
double zPos = length / 2.0 - sensitive_thickness / 2.0;
if (detStart) {
rEnd = rOuter1 - (rOuter1 - rOuter2) * sensitive_thickness / length;
zPos = -length / 2.0 + sensitive_thickness / 2.0;
}

ConeSegment s_start_disk(sensitive_thickness / 2, 0.0, rOuter2, 0.0, rEnd);
Volume v_start_disk("stop_disk_" + motherName, s_start_disk, m_Vacuum);

v_start_disk.setLimitSet(description, "kill_limits");

auto disk_placement = mother_vol.placeVolume(v_start_disk, Position(0.0, 0.0, zPos));

sdet.setPlacement(disk_placement);
description.declareParent(det_name, mother);

return sdet;
}

DECLARE_DETELEMENT(BeamPipeStop, create_detector)
1 change: 1 addition & 0 deletions src/BeamPipeTracking_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
}

auto pv_assembly = description.worldVolume().placeVolume(assembly, Position(0.0, 0.0, 0.0));
pv_assembly.addPhysVolID("system", det_id);
sdet.setPlacement(pv_assembly);

return sdet;
Expand Down

0 comments on commit 3f6cace

Please sign in to comment.