Skip to content

Commit

Permalink
Moved beamline tracker to own files and inject into pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
simonge committed Sep 13, 2024
1 parent c4e13d6 commit 16cf707
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 13 deletions.
56 changes: 56 additions & 0 deletions compact/far_backward/beamline_tracking.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

<lccdd>



<detectors>

<detector
id="BackwardsBeamline_ID"
type="BeamPipeTracking"
name="Pipe_tracker"
readout="BackwardsBeamlineHits">

<slice
pipe_id="0"
grandmother="Pipe_Q1eR_to_B2BeR"
mother="Pipe_to_Q1eR_vacuum"
name="Pipe_to_Q1eR_tracker"/>

<slice
pipe_id="1"
grandmother="Pipe_Q1eR_to_B2BeR"
mother="Pipe_in_Q1eR_vacuum"
name="Pipe_in_Q1eR_tracker"/>

<slice
pipe_id="2"
grandmother="Pipe_Q1eR_to_B2BeR"
mother="Pipe_in_Q2eR_vacuum"
name="Pipe_in_Q2eR_tracker"/>

<slice
pipe_id="3"
grandmother="Pipe_Q1eR_to_B2BeR"
mother="Pipe_in_B2BeR_vacuum"
name="Pipe_in_B2BeR_tracker"/>

<slice
pipe_id="4"
grandmother="Pipe_Q3eR_to_B7eR"
mother="Pipe_in_Q3eR_vacuum"
name="Pipe_in_Q3eR_tracker"/>

</detector>
</detectors>

<readouts>

<readout name="BackwardsBeamlineHits">
<segmentation type="NoSegmentation"/>
<id>system:8,pipe:8,end:2</id>
</readout>

</readouts>

</lccdd>
4 changes: 3 additions & 1 deletion compact/far_backward/extended.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Copyright (C) 2023 Wouter Deconinck, Simon Gardner -->

<lccdd>

<include ref="magnets.xml"/>
<include ref="beamline_extension_hadron.xml"/>
<include ref="beamline_extension_electron.xml"/>
Expand All @@ -13,4 +13,6 @@
<!-- Luminosity detector -->
<include ref="lumi.xml"/>

<include ref="beamline_tracking.xml"/>

</lccdd>
13 changes: 1 addition & 12 deletions compact/far_backward/magnets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@

<!-- Beam pipe going from Q1eR to B2BeR -->
<detector
id="BackwardsBeamline_ID"
name="Pipe_Q1eR_to_B2BeR"
type="BeamPipeChain"
wall_thickness="2*mm"
vis="BeamPipeVis"
readout="BackwardsBeamlineHits"
sensitive="false">
vis="BeamPipeVis">
<pipe id="0" name="Pipe_to_Q1eR"
xcenter="0" zcenter="(Center_Beampipe_End + Q1eR_CenterPosition+Q1eR_Length/2)/2"
length="Center_Beampipe_End - (Q1eR_CenterPosition+Q1eR_Length/2)" theta="0"
Expand Down Expand Up @@ -127,13 +124,5 @@

</fields>

<readouts>

<readout name="BackwardsBeamlineHits">
<segmentation type="NoSegmentation"/>
<id>system:8,pipe:8,end:2</id>
</readout>

</readouts>

</lccdd>
87 changes: 87 additions & 0 deletions src/BeamPipeTracking_geo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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");

sens.setType("tracker");

DetElement sdet(det_name, det_id);
Assembly assembly(det_name + "_assembly");

// Grab info for beamline magnets
for (xml_coll_t slice_coll(x_det, _Unicode(slice)); slice_coll; slice_coll++) { // pipes

string grandmotherName = slice_coll.attr<string>(_Unicode(grandmother));
string motherName = slice_coll.attr<string>(_Unicode(mother));
bool detStart = getAttrOrDefault<bool>(slice_coll, _Unicode(end), true);
int pipe_id = getAttrOrDefault<int> (slice_coll, _Unicode(pipe_id), 0);
string slice_name = slice_coll.attr<string>(_Unicode(name));
DetElement mother = description.detector(grandmotherName).child(motherName);

// 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 = 0.1 * 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("v_start_disk_" + motherName, s_start_disk, m_Vacuum);
v_start_disk.setSensitiveDetector(sens);

auto disk_placement = mother_vol.placeVolume(v_start_disk, Position(0.0, 0.0, zPos));
disk_placement.addPhysVolID("end", detStart );
disk_placement.addPhysVolID("pipe", pipe_id );
disk_placement.addPhysVolID("system", det_id );

DetElement slice_element(sdet, slice_name, pipe_id);

slice_element.setPlacement(disk_placement);
description.declareParent(slice_name, mother);

}

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

return sdet;
}

DECLARE_DETELEMENT(BeamPipeTracking, create_detector)

0 comments on commit 16cf707

Please sign in to comment.