Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DCHdigi_v01 adapted to work with SenseWireHit #42

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DCHdigi/include/DCHdigi_v01.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Processor produces collection of Digitized hits of Drift Chamber v2<br>
* @param DCH_simhits The name of input collection, type edm4hep::SimTrackerHitCollection <br>
* (default name empty) <br>
* @param DCH_DigiCollection The name of out collection, type extension::DriftChamberDigiV2Collection <br>
* @param DCH_DigiCollection The name of out collection, type extension::SenseWireHitCollection <br>
* (default name DCH_DigiCollection) <br>
* @param DCH_name DCH subdetector name <br>
* (default value DCH_v2) <br>
Expand Down Expand Up @@ -50,8 +50,8 @@
#include "edm4hep/SimTrackerHitCollection.h"

// EDM4HEP extension
#include "extension/DriftChamberDigiV2Collection.h"
#include "extension/MCRecoDriftChamberDigiV2AssociationCollection.h"
#include "extension/SenseWireHitCollection.h"
#include "extension/SenseWireHitSimTrackerHitLinkCollection.h"

// DD4hep
#include "DD4hep/Detector.h" // for dd4hep::VolumeManager
Expand All @@ -77,14 +77,14 @@

struct DCHdigi_v01 final
: k4FWCore::MultiTransformer<
std::tuple<extension::DriftChamberDigiV2Collection, extension::MCRecoDriftChamberDigiV2AssociationCollection>(
std::tuple<extension::SenseWireHitCollection, extension::SenseWireHitSimTrackerHitLinkCollection>(
const edm4hep::SimTrackerHitCollection&, const edm4hep::EventHeaderCollection&)> {
DCHdigi_v01(const std::string& name, ISvcLocator* svcLoc);

StatusCode initialize() override;
StatusCode finalize() override;

std::tuple<extension::DriftChamberDigiV2Collection, extension::MCRecoDriftChamberDigiV2AssociationCollection>
std::tuple<extension::SenseWireHitCollection, extension::SenseWireHitSimTrackerHitLinkCollection>
operator()(const edm4hep::SimTrackerHitCollection&, const edm4hep::EventHeaderCollection&) const override;

private:
Expand Down
43 changes: 30 additions & 13 deletions DCHdigi/src/DCHdigi_v01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <iostream>
#include <sstream>

#include "extension/MutableDriftChamberDigiV2.h"
#include "extension/MutableSenseWireHit.h"

///////////////////////////////////////////////////////////////////////////////////////
////////////////////// DCHdigi_v01 constructor ////////////////////////////
Expand Down Expand Up @@ -96,7 +96,7 @@ StatusCode DCHdigi_v01::initialize() {
///////////////////////////////////////////////////////////////////////////////////////
/////////////////////// operator() ////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
std::tuple<extension::DriftChamberDigiV2Collection, extension::MCRecoDriftChamberDigiV2AssociationCollection>
std::tuple<extension::SenseWireHitCollection, extension::SenseWireHitSimTrackerHitLinkCollection>
DCHdigi_v01::operator()(const edm4hep::SimTrackerHitCollection& input_sim_hits,
const edm4hep::EventHeaderCollection& headers) const {
// initialize seed for random engine
Expand All @@ -105,8 +105,8 @@ DCHdigi_v01::operator()(const edm4hep::SimTrackerHitCollection& input_sim_hits,
debug() << "Input Sim Hit collection size: " << input_sim_hits.size() << endmsg;

// Create the collections we are going to return
extension::DriftChamberDigiV2Collection output_digi_hits;
extension::MCRecoDriftChamberDigiV2AssociationCollection output_digi_sim_association;
extension::SenseWireHitCollection output_digi_hits;
extension::SenseWireHitSimTrackerHitLinkCollection output_digi_sim_association;

//loop over hit collection
for (const auto& input_sim_hit : input_sim_hits) {
Expand Down Expand Up @@ -154,24 +154,41 @@ DCHdigi_v01::operator()(const edm4hep::SimTrackerHitCollection& input_sim_hits,
float eDepError = 0;
// length units back to mm
auto positionSW = Convert_TVector3_to_EDM4hepVector(hit_projection_on_the_wire, 1. / MM_TO_CM);
auto directionSW = Convert_TVector3_to_EDM4hepVector(wire_direction_ez, 1. / MM_TO_CM);
//auto directionSW = Convert_TVector3_to_EDM4hepVector(wire_direction_ez, 1. / MM_TO_CM);
float distanceToWire = distanceToWire_smeared / MM_TO_CM;

extension::MutableDriftChamberDigiV2 oDCHdigihit;
// The direction of the sense wires can be calculated as:
// RotationZ(WireAzimuthalAngle) * RotationX(stereoangle)
// One point of the wire is for example the following:
// RotationZ(WireAzimuthalAngle) * Position(cell_rave_z0, 0 , 0)
// variables aredefined below
auto WireAzimuthalAngle = this->dch_data->Get_cell_phi_angle(ilayer, nphi);
float WireStereoAngle = 0;
{
auto l = this->dch_data->database.at(ilayer);
// radial middle point of the cell at Z=0
auto cell_rave_z0 = 0.5*(l.radius_fdw_z0 + l.radius_fuw_z0);
// when building the twisted tube, the twist angle is defined as:
// cell_twistangle = l.StereoSign() * DCH_i->twist_angle
// which forces the stereoangle of the wire to have the oposite sign
WireStereoAngle = (-1.)*l.StereoSign()*dch_data->stereoangle_z0(cell_rave_z0);
}

extension::MutableSenseWireHit oDCHdigihit;
oDCHdigihit.setCellID(input_sim_hit.getCellID());
oDCHdigihit.setType(type);
oDCHdigihit.setQuality(quality);
oDCHdigihit.setTime(input_sim_hit.getTime());
oDCHdigihit.setEDep(input_sim_hit.getEDep());
oDCHdigihit.setEDepError(eDepError);
oDCHdigihit.setPosition(positionSW);
oDCHdigihit.setDirectionSW(directionSW);
oDCHdigihit.setWireAzimuthalAngle(WireAzimuthalAngle);
oDCHdigihit.setWireStereoAngle(WireStereoAngle);
oDCHdigihit.setDistanceToWire(distanceToWire);
// For the sake of speed, let the dNdx calculation be optional
if( m_calculate_dndx.value() )
{
auto [nCluster, nElectrons_v] = CalculateClusters(input_sim_hit);
oDCHdigihit.setNCluster(nCluster);
// to return the total number of electrons within the step, do the following:
// int nElectronsTotal = std::accumulate( nElectrons_v.begin(), nElectrons_v.end(), 0);
// oDCHdigihit.setNElectronsTotal(nElectronsTotal);
Expand All @@ -182,16 +199,16 @@ DCHdigi_v01::operator()(const edm4hep::SimTrackerHitCollection& input_sim_hits,

output_digi_hits.push_back(oDCHdigihit);

extension::MutableMCRecoDriftChamberDigiV2Association oDCHsimdigi_association;
oDCHsimdigi_association.setDigi(oDCHdigihit);
oDCHsimdigi_association.setSim(input_sim_hit);
extension::MutableSenseWireHitSimTrackerHitLink oDCHsimdigi_association;
oDCHsimdigi_association.setFrom(oDCHdigihit);
oDCHsimdigi_association.setTo(input_sim_hit);
output_digi_sim_association.push_back(oDCHsimdigi_association);

} // end loop over hit collection

/////////////////////////////////////////////////////////////////
return std::make_tuple<extension::DriftChamberDigiV2Collection,
extension::MCRecoDriftChamberDigiV2AssociationCollection>(
return std::make_tuple<extension::SenseWireHitCollection,
extension::SenseWireHitSimTrackerHitLinkCollection>(
std::move(output_digi_hits), std::move(output_digi_sim_association));
}

Expand Down
Loading