Skip to content

Commit c6ab334

Browse files
authored
Beamline - Allow detector volumes which are not cone segments for tracking (#221)
1 parent 934a6f0 commit c6ab334

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

benchmarks/beamline/acceptanceAnalysis.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
using RVecS = ROOT::VecOps::RVec<string>;
2020
using RNode = ROOT::RDF::RNode;
2121

22-
int acceptanceAnalysis( TString inFile = "/scratch/EIC/G4out/beamline/acceptanceTest.edm4hep.root",
22+
int acceptanceAnalysis( TString inFile = "/home/simong/EIC/detector_benchmarks_anl/sim_output/beamline/acceptanceTestXS2.edm4hep.root",
2323
TString outFile = "output.root",
2424
std::string compactName = "/home/simong/EIC/epic/install/share/epic/epic_ip6_extended.xml",
2525
TString beampipeCanvasName = "acceptance_in_beampipe.png",

benchmarks/beamline/beamlineAnalysis.C

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
using RVecS = ROOT::VecOps::RVec<string>;
2020
using RNode = ROOT::RDF::RNode;
2121

22-
int beamlineAnalysis( TString inFile = "/scratch/EIC/G4out/beamline/beamlineTest.edm4hep.root",
22+
int beamlineAnalysis( TString inFile = "/home/simong/EIC/detector_benchmarks_anl/sim_output/beamline/acceptanceTestXS3.edm4hep.root",
2323
TString outFile = "output.root",
2424
std::string compactName = "/home/simong/EIC/epic/install/share/epic/epic_ip6_extended.xml",
2525
TString beamspotCanvasName = "beamspot_canvas.png",
@@ -79,6 +79,13 @@ int beamlineAnalysis( TString inFile = "/scratch/EIC/G4out/beamline/b
7979
}
8080
return radii;
8181
}, {"pipeParameters"})
82+
.Define("isConeSegment",[](const ROOT::VecOps::RVec<volParams>& params) {
83+
ROOT::VecOps::RVec<bool> cones;
84+
for (const auto& param : params) {
85+
cones.push_back(param.isConeSegment);
86+
}
87+
return cones;
88+
}, {"pipeParameters"})
8289
.Define("xdet",[](const ROOT::VecOps::RVec<volParams>& params) {
8390
ROOT::VecOps::RVec<double> xPos;
8491
for (const auto& param : params) {
@@ -170,6 +177,7 @@ int beamlineAnalysis( TString inFile = "/scratch/EIC/G4out/beamline/b
170177
std::map<TString,double> pipeXPos;
171178
std::map<TString,double> pipeZPos;
172179
std::map<TString,double> pipeRotation;
180+
std::map<TString,bool> pipeIsConeSegment;
173181

174182
// Queue up all actions
175183
auto xmin_ptr = d1.Min("xpos");
@@ -201,6 +209,7 @@ int beamlineAnalysis( TString inFile = "/scratch/EIC/G4out/beamline/b
201209
.Define("xmomf","xmom[pipeID=="+std::to_string(i)+"]")
202210
.Define("ymomf","ymom[pipeID=="+std::to_string(i)+"]")
203211
.Define("pipeRadiusf","pipeRadius[pipeID=="+std::to_string(i)+"]")
212+
.Define("isConeSegmentf","isConeSegment[pipeID=="+std::to_string(i)+"]")
204213
.Define("xdetf","xdet[pipeID=="+std::to_string(i)+"]")
205214
.Define("zdetf","zdet[pipeID=="+std::to_string(i)+"]")
206215
.Define("rotationf","rotation[pipeID=="+std::to_string(i)+"]");
@@ -273,6 +282,7 @@ int beamlineAnalysis( TString inFile = "/scratch/EIC/G4out/beamline/b
273282
pipeXPos[name] = filterDF.Max("xdetf").GetValue();
274283
pipeZPos[name] = filterDF.Max("zdetf").GetValue();
275284
pipeRotation[name] = filterDF.Max("rotationf").GetValue();
285+
pipeIsConeSegment[name] = filterDF.Max("isConeSegmentf").GetValue();
276286

277287
//Fit gaussian to the x, y, px and py distributions
278288
auto xhist = hHistsxy[name]->ProjectionX();
@@ -325,12 +335,15 @@ int beamlineAnalysis( TString inFile = "/scratch/EIC/G4out/beamline/b
325335
cXY->cd(i++);
326336

327337
h->Draw("col");
328-
//Draw cicle
329-
TEllipse *circle = new TEllipse(0,0,pipeRadius);
330-
circle->SetLineColor(kRed);
331-
circle->SetLineWidth(2);
332-
circle->SetFillStyle(0);
333-
circle->Draw("same");
338+
339+
// Only draw circle overlay if the shape is a cone segment
340+
if (pipeIsConeSegment[name] && pipeRadius > 0) {
341+
TEllipse *circle = new TEllipse(0,0,pipeRadius);
342+
circle->SetLineColor(kRed);
343+
circle->SetLineWidth(2);
344+
circle->SetFillStyle(0);
345+
circle->Draw("same");
346+
}
334347

335348
// Add zoomed version in the top-right corner
336349
TPad *pad = new TPad("zoomPad", "Zoomed View", 0.65, 0.65, 1.0, 1.0);

benchmarks/beamline/shared_functions.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#include "edm4hep/SimTrackerHitCollection.h"
55
#include "edm4hep/SimCalorimeterHitCollection.h"
66
#include "DD4hep/VolumeManager.h"
7+
#include "DD4hep/DetElement.h"
78
#include "TFile.h"
89

910
using RVecHits = ROOT::VecOps::RVec<edm4hep::SimTrackerHitData>;
11+
using namespace dd4hep;
1012

1113
//-----------------------------------------------------------------------------------------
1214
// Grab Component functor
@@ -108,6 +110,7 @@ struct volParams{
108110
double yPos;
109111
double zPos;
110112
double rotation;
113+
bool isConeSegment;
111114
};
112115

113116
// Functor to get the volume element parameters from the CellID
@@ -127,13 +130,20 @@ struct getVolumeParametersFromCellID {
127130
const Double_t* rotationMatrix = transform.GetRotationMatrix(); // Compute rotation angle around the Y-axis
128131
double rotationAngleY = std::atan2(rotationMatrix[2], rotationMatrix[8]); // atan2(r13, r33)
129132
auto volume = detelement.volume();
130-
dd4hep::ConeSegment cone = volume.solid();
133+
dd4hep::Solid solid = volume.solid();
134+
bool isCone = solid.isValid() && std::string(solid->IsA()->GetName()) == "TGeoConeSeg";
135+
double radius = 0.0;
136+
if (isCone) {
137+
dd4hep::ConeSegment cone = solid;
138+
radius = cone.rMax1();
139+
}
131140
volParams params{
132-
cone.rMax1(),
141+
radius,
133142
translation[0],
134143
translation[1],
135144
translation[2],
136-
rotationAngleY
145+
rotationAngleY,
146+
isCone
137147
};
138148
result.push_back(params);
139149
}
@@ -175,4 +185,13 @@ TH1F* CreateFittedHistogram(const std::string& histName,
175185
hist->SetMarkerColor(kRed);
176186

177187
return hist;
188+
}
189+
190+
void printHierarchy(const DetElement& de, int level = 0) {
191+
std::string indent(level * 2, ' ');
192+
std::cout << indent << "- " << de.name() << " (ID: " << de.id() << ")\n";
193+
194+
for (const auto& [childName, child] : de.children()) {
195+
printHierarchy(child, level + 1);
196+
}
178197
}

0 commit comments

Comments
 (0)