Skip to content

Commit

Permalink
Apply clang-format to DREndcapTubes code
Browse files Browse the repository at this point in the history
clang-format .cpp and .hh files for DREndcapTubes subdetector. I checked
that this formatting does not change physics results.
  • Loading branch information
lopezzot committed Dec 5, 2024
1 parent 11e82c7 commit caaafb7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
struct Plane
{
Vector3D P1, P2, P3, P4;
Plane(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D p4) : P1(p1), P2(p2), P3(p3), P4(p4){};
Plane(Vector3D p1, Vector3D p2, Vector3D p3, Vector3D p4) : P1(p1), P2(p2), P3(p3), P4(p4) {};
};

// This struct represents a line towards negatize Z
Expand All @@ -27,7 +27,7 @@ struct ZLine
{
Vector3D origin;
Vector3D fuZ = Vector3D(0, 0, -1);
ZLine(Vector3D P) : origin(P){};
ZLine(Vector3D P) : origin(P) {};
};

// Custom exception class for intersecting ZLines with Planes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ using namespace dd4hep::rec; // for dd4hep::rec::Vector3D
// It is used to create a G4 copynumber for volumes with two IDs
unsigned int CalcCpNo32bits(int id1, int id2)
{
if (id1 > 0xFFF || id2 > 0xFFF){
if (id1 > 0xFFF || id2 > 0xFFF) {
throw std::invalid_argument("row and col IDs should not take more than 16 bits");
}
unsigned int CpNo = (id1 << 16) | id2;
unsigned int CpNo = (id1 << 16) | id2;
return CpNo;
}

// This methods unifies in 32 bits two IDs of 1 bit only
unsigned int CalcCpNo2bits(int id1, int id2)
{
if (id1 > 1 || id2 > 1) {
throw std::invalid_argument("core and cherenkov ID must be 0 or 1");
}
throw std::invalid_argument("core and cherenkov ID must be 0 or 1");
}
unsigned int CpNo = (id1 << 1) | id2;
return CpNo;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
//
// Distance between z-axis and the starting point of the Air stave containing
// the towers, it is included to avoid overlaps with the compensating solenoid
const double DistancetoSolenoid = 22*cm;
const double DistancetoSolenoid = 22 * cm;
// The first two points of the inner face are defined by DistancetoSolenoid
// similarly to the second two points
// The second two points of the inner face are at (x=tan(0.5*phi_unit, y=innerR)
Expand Down Expand Up @@ -172,8 +172,9 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
RotationY rotyleft(0.);
Transform3D slice_trnsformleft(rotz1 * rotz2 * rotx * rotyleft,
Position(0, 0, -1. * ((innerR)*tan(thetaB) + length / 2.)));
PlacedVolume phiELPlaced = AssemblyEndcap.placeVolume(phiERLog, j+NbOfZRot, slice_trnsformleft);
phiELPlaced.addPhysVolID("stave", j+NbOfZRot);
PlacedVolume phiELPlaced =
AssemblyEndcap.placeVolume(phiERLog, j + NbOfZRot, slice_trnsformleft);
phiELPlaced.addPhysVolID("stave", j + NbOfZRot);
} // end of slice/stave placement

// Create an S tube with full tower length
Expand All @@ -193,7 +194,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
description.material(x_core_S.attr<std::string>(_U(material))));
core_SLog.setVisAttributes(description, x_core_S.visStr());
if (x_core_S_sens) core_SLog.setSensitiveDetector(sens);
PlacedVolume core_SPlaced = clad_SLog.placeVolume(core_SLog, CalcCpNo2bits(1,0));
PlacedVolume core_SPlaced = clad_SLog.placeVolume(core_SLog, CalcCpNo2bits(1, 0));
core_SPlaced.addPhysVolID("core", 1).addPhysVolID("cherenkov", 0);

// Create a C tube with full tower length
Expand All @@ -213,7 +214,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
description.material(x_core_C.attr<std::string>(_U(material))));
core_CLog.setVisAttributes(description, x_core_C.visStr());
if (x_core_C_sens) core_CLog.setSensitiveDetector(sens);
PlacedVolume core_CPlaced = clad_CLog.placeVolume(core_CLog, CalcCpNo2bits(1,1));
PlacedVolume core_CPlaced = clad_CLog.placeVolume(core_CLog, CalcCpNo2bits(1, 1));
core_CPlaced.addPhysVolID("core", 1).addPhysVolID("cherenkov", 1);

// Build the towers inside and endcap R slice
Expand Down Expand Up @@ -312,7 +313,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
towerPlaced.addPhysVolID("tower", i).addPhysVolID("air", 0);
}
// Or, to debug, place towers one next to each other in assembly volume
//if(i<35) {
// if(i<35) {
// double z = static_cast<int>(i/15)*(length+40*cm);
// double x = (i-static_cast<int>(i/15)*15)*100*cm - 5*m;
// AssemblyEndcap.placeVolume(towerLog,i,Position(-1.*x,0.,-1.*z));
Expand Down Expand Up @@ -355,8 +356,8 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
Vector3D capillaryPos(x_tube, y_tube, length / 2.); // locate tube on tower back face
auto capillaryLength = Helper.GetTubeLength(pt, capillaryPos); // calculate tube length
if (std::fabs(capillaryLength - length) < 0.0001 * mm) {
PlacedVolume capillaryPlaced =
towerLog.placeVolume(capillary_SLog, CalcCpNo32bits(j,k), Position(x_tube, y_tube, 0.));
PlacedVolume capillaryPlaced = towerLog.placeVolume(capillary_SLog, CalcCpNo32bits(j, k),
Position(x_tube, y_tube, 0.));
// ID this volume with row ID and column ID
capillaryPlaced.addPhysVolID("row", k).addPhysVolID("col", j);
#ifdef COUNTTUBES
Expand Down Expand Up @@ -391,11 +392,12 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
description.material(x_core_S.attr<std::string>(_U(material))));
coreShort_SLog.setVisAttributes(description, x_core_S.visStr());
if (x_core_S_sens) coreShort_SLog.setSensitiveDetector(sens);
PlacedVolume coreShort_SPlaced = cladShort_SLog.placeVolume(coreShort_SLog, CalcCpNo2bits(1,0));
PlacedVolume coreShort_SPlaced =
cladShort_SLog.placeVolume(coreShort_SLog, CalcCpNo2bits(1, 0));
coreShort_SPlaced.addPhysVolID("core", 1).addPhysVolID("cherenkov", 0);

PlacedVolume capillaryShortPlaced = towerLog.placeVolume(
capillaryShortLog, CalcCpNo32bits(j,k),
capillaryShortLog, CalcCpNo32bits(j, k),
Position(x_tube, y_tube, length / 2. - capillaryLength / 2. + TubeLengthOffset / 2.));
// ID this volume with row ID and column ID
capillaryShortPlaced.addPhysVolID("row", k).addPhysVolID("col", j);
Expand Down Expand Up @@ -426,8 +428,8 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
Vector3D capillaryPos_C(x_tube_C, y_tube_C, length / 2.);
auto capillaryLength_C = Helper.GetTubeLength(pt, capillaryPos_C);
if (std::fabs(capillaryLength_C - length) < 0.0001 * mm) {
PlacedVolume capillaryPlaced_C = towerLog.placeVolume(capillary_CLog, CalcCpNo32bits(j,k),
Position(x_tube_C, y_tube_C, 0.));
PlacedVolume capillaryPlaced_C = towerLog.placeVolume(
capillary_CLog, CalcCpNo32bits(j, k), Position(x_tube_C, y_tube_C, 0.));
capillaryPlaced_C.addPhysVolID("row", k).addPhysVolID("col", j);
#ifdef COUNTTUBES
tubeNo++;
Expand Down Expand Up @@ -458,11 +460,12 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
description.material(x_core_C.attr<std::string>(_U(material))));
coreShort_CLog.setVisAttributes(description, x_core_C.visStr());
if (x_core_C_sens) coreShort_CLog.setSensitiveDetector(sens);
PlacedVolume coreShort_CPlaced = cladShort_CLog.placeVolume(coreShort_CLog, CalcCpNo2bits(1,1));
PlacedVolume coreShort_CPlaced =
cladShort_CLog.placeVolume(coreShort_CLog, CalcCpNo2bits(1, 1));
coreShort_CPlaced.addPhysVolID("core", 1).addPhysVolID("cherenkov", 1);

PlacedVolume capillaryShortPlaced_C = towerLog.placeVolume(
capillaryShortLog_C, CalcCpNo32bits(j,k),
capillaryShortLog_C, CalcCpNo32bits(j, k),
Position(x_tube_C, y_tube_C,
length / 2. - capillaryLength_C / 2. + TubeLengthOffset / 2.));
capillaryShortPlaced_C.addPhysVolID("row", k).addPhysVolID("col", j);
Expand Down Expand Up @@ -511,7 +514,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
Volume motherVolume = description.pickMotherVolume(sdet);
// Place the assembly container inside the mother volume
PlacedVolume AssemblyEndcapPV = motherVolume.placeVolume(AssemblyEndcap);
AssemblyEndcapPV.addPhysVolID("system",x_det.id());
AssemblyEndcapPV.addPhysVolID("system", x_det.id());
sdet.setPlacement(AssemblyEndcapPV);

std::cout << "--> DREndcapTubes::create_detector() end" << std::endl;
Expand Down
25 changes: 14 additions & 11 deletions plugins/DRTubesSDAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void Geant4SensitiveAction<DRTubesSDData>::defineCollections()
// Method that accesses the G4Step object at each track step.
template<>
bool Geant4SensitiveAction<DRTubesSDData>::process(const G4Step* aStep,
G4TouchableHistory* /*history*/)
G4TouchableHistory* /*history*/)
{
// NOTE: Here we do manipulation of the signal in each fiber (Scintillating and Cherenkov)
// to compute the calorimeter signal and populate the corresponding hit.
Expand Down Expand Up @@ -126,8 +126,8 @@ bool Geant4SensitiveAction<DRTubesSDData>::process(const G4Step* aStep,
auto cpNo = aStep->GetPreStepPoint()->GetTouchable()->GetCopyNumber();
// The second bit of the CopyNumber corresponds to the "core" entry:
// 1 if the step is in the fiber core (S or C) and 0 if it is
// in the fiber cladding (C only)
unsigned int CoreID = (cpNo & 0b10) >> 1; // take CpNo 2nd bit
// in the fiber cladding (C only)
unsigned int CoreID = (cpNo & 0b10) >> 1; // take CpNo 2nd bit
bool IsCherClad = (CoreID == 0);
// The first bit of the CopyNumber corresponds to the "cherenkov" entry
// 1 for C fibers and 0 for S fibers
Expand All @@ -151,14 +151,16 @@ bool Geant4SensitiveAction<DRTubesSDData>::process(const G4Step* aStep,
auto TubeID = aStep->GetPreStepPoint()->GetTouchable()->GetCopyNumber(2);
unsigned int ColumnID = TubeID >> 16;
unsigned int RawID = TubeID & 0xFFFF;
auto TowerID = static_cast<unsigned int>(aStep->GetPreStepPoint()->GetTouchable()->GetCopyNumber(3));
auto StaveID = static_cast<unsigned int>(aStep->GetPreStepPoint()->GetTouchable()->GetCopyNumber(4));
auto TowerID =
static_cast<unsigned int>(aStep->GetPreStepPoint()->GetTouchable()->GetCopyNumber(3));
auto StaveID =
static_cast<unsigned int>(aStep->GetPreStepPoint()->GetTouchable()->GetCopyNumber(4));

VolumeID VolID = 0; // recreate the 64-bit VolumeID
VolumeID VolID = 0; // recreate the 64-bit VolumeID
BitFieldCoder bc("system:5,stave:10,tower:6,air:1,col:16,row:16,clad:1,core:1,cherenkov:1");
bc.set(VolID, "system", 25); // this number is set in DectDimensions_IDEA_o2_v01.xml
bc.set(VolID, "stave" , StaveID);
bc.set(VolID, "tower" , TowerID);
bc.set(VolID, "system", 25); // this number is set in DectDimensions_IDEA_o2_v01.xml
bc.set(VolID, "stave", StaveID);
bc.set(VolID, "tower", TowerID);
bc.set(VolID, "air", 0);
bc.set(VolID, "col", ColumnID);
bc.set(VolID, "row", RawID);
Expand All @@ -173,6 +175,7 @@ bool Geant4SensitiveAction<DRTubesSDData>::process(const G4Step* aStep,
* 2. associate DRTubesSDAction to DREncapTubes subdetector
* in the steering file (instead of using RegexSD)
* 3. Uncomment the code below */
// clang-format off
/*std::cout<<"Volume id, created "<<VolID<<" and DD4hep oroginal "<<volumeID(aStep)<<std::endl;
std::cout<<"system id, created "<<25<<" and DD4hep original "<<bc.get(volumeID(aStep),"system")<<std::endl;
std::cout<<"stave id, created "<<StaveID<<" and DD4hep original "<<bc.get(volumeID(aStep),"stave")<<std::endl;
Expand All @@ -183,6 +186,7 @@ bool Geant4SensitiveAction<DRTubesSDData>::process(const G4Step* aStep,
std::cout<<"clad id, created "<<1<<" and DD4hep original "<<bc.get(volumeID(aStep),"clad")<<std::endl;
std::cout<<"core id, created "<<CoreID<<" and DD4hep original "<<bc.get(volumeID(aStep),"core")<<std::endl;
std::cout<<"cherenkov id, created "<<CherenkovID<<" and DD4hep original "<<bc.get(volumeID(aStep),"cherenkov")<<std::endl;*/
// clang-format on

bool IsRight = (aStep->GetPreStepPoint()->GetPosition().z() > 0.);

Expand All @@ -201,8 +205,7 @@ bool Geant4SensitiveAction<DRTubesSDData>::process(const G4Step* aStep,
return true; // not ionizing particle
}
G4double distance_to_sipm = DRTubesSglHpr::GetDistanceToSiPM(aStep);
signalhit =
DRTubesSglHpr::SmearSSignal(DRTubesSglHpr::ApplyBirks(Edep, steplength));
signalhit = DRTubesSglHpr::SmearSSignal(DRTubesSglHpr::ApplyBirks(Edep, steplength));
signalhit = DRTubesSglHpr::AttenuateSSignal(signalhit, distance_to_sipm);
if (signalhit == 0) return true;
} // end of scintillating fibre sigal calculation
Expand Down
2 changes: 1 addition & 1 deletion plugins/DRTubesSglHpr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ inline G4double DRTubesSglHpr::GetDistanceToSiPM(const G4Step* step, bool preste
}

inline G4int DRTubesSglHpr::AttenuateHelper(const G4int& signal, const G4double& distance,
const G4double& attenuation_length)
const G4double& attenuation_length)
{
double probability_of_survival = exp(-distance / attenuation_length);

Expand Down

0 comments on commit caaafb7

Please sign in to comment.