Skip to content

Commit

Permalink
use new geometry functions from data extension, safer way of saving o…
Browse files Browse the repository at this point in the history
…utput histograms
  • Loading branch information
atolosadelgado committed Nov 22, 2024
1 parent 202faf9 commit dd80ac2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
8 changes: 7 additions & 1 deletion DCHdigi/include/DCHdigi_v01.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
#include "AlgData.h"

/// constant to convert from mm (EDM4hep) to DD4hep (cm)
constexpr double MM_TO_CM = 0.1;

struct DCHdigi_v01 final
: k4FWCore::MultiTransformer<
Expand All @@ -87,6 +86,9 @@ struct DCHdigi_v01 final
operator()(const edm4hep::SimTrackerHitCollection&, const edm4hep::EventHeaderCollection&) const override;

private:
/// conversion factor mm to cm, static to the class to avoid clash with DD4hep
static constexpr double MM_TO_CM = 0.1;

//------------------------------------------------------------------
// machinery for geometry

Expand Down Expand Up @@ -193,6 +195,10 @@ struct DCHdigi_v01 final

/// histogram to store smearing perpendicular the wire
TH1D* hSxy;

/// Create ROOT file for debug histograms
/// Does not change ROOT directory
void Create_outputROOTfile_for_debugHistograms();
};

DECLARE_COMPONENT(DCHdigi_v01);
Expand Down
39 changes: 33 additions & 6 deletions DCHdigi/src/DCHdigi_v01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ StatusCode DCHdigi_v01::initialize() {
/////////////////////////// retrieve data extension //////////////////////////
///////////////////////////////////////////////////////////////////////////////////
this->dch_data = DCH_DE.extension<dd4hep::rec::DCH_info>();
if (not dch_data->IsValid())
ThrowException("No valid data extension was found for detector <<" + DCH_name + ">>.");

///////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -115,13 +117,13 @@ DCHdigi_v01::operator()(const edm4hep::SimTrackerHitCollection& input_sim_hits,

// -------------------------------------------------------------------------
// calculate hit position projection into the wire
TVector3 hit_to_wire_vector = this->Calculate_hitpos_to_wire_vector(ilayer, nphi, hit_position);
TVector3 hit_to_wire_vector = this->dch_data->Calculate_hitpos_to_wire_vector(ilayer, nphi, hit_position);
TVector3 hit_projection_on_the_wire = hit_position + hit_to_wire_vector;
if (m_create_debug_histos.value()) {
double distance_hit_wire = hit_to_wire_vector.Mag();
hDpw->Fill(distance_hit_wire);
}
TVector3 wire_direction_ez = this->Calculate_wire_vector_ez(ilayer, nphi);
TVector3 wire_direction_ez = this->dch_data->Calculate_wire_vector_ez(ilayer, nphi);

// -------------------------------------------------------------------------
// smear the position
Expand All @@ -134,7 +136,7 @@ DCHdigi_v01::operator()(const edm4hep::SimTrackerHitCollection& input_sim_hits,
hit_projection_on_the_wire += smearing_z * (wire_direction_ez.Unit());
if (m_create_debug_histos.value()) {
// the distance from the hit projection and the wire should be zero
TVector3 dummy_vector = this->Calculate_hitpos_to_wire_vector(ilayer, nphi, hit_projection_on_the_wire);
TVector3 dummy_vector = this->dch_data->Calculate_hitpos_to_wire_vector(ilayer, nphi, hit_projection_on_the_wire);
hDww->Fill(dummy_vector.Mag());
}

Expand Down Expand Up @@ -193,16 +195,41 @@ DCHdigi_v01::operator()(const edm4hep::SimTrackerHitCollection& input_sim_hits,
///////////////////////////////////////////////////////////////////////////////////////
/////////////////////// finalize //////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
StatusCode DCHdigi_v01::finalize() {
if (m_create_debug_histos.value()) {
std::unique_ptr<TFile> ofile{TFile::Open(m_out_debug_filename.value().c_str(), "recreate")};

void DCHdigi_v01::Create_outputROOTfile_for_debugHistograms()
{
// save current ROOT directory
TDirectory* currentDir = gDirectory;

// save the debug histograms in a file
// file is saved and closed when going out of scope
{
auto filename = m_out_debug_filename.value().c_str();
std::unique_ptr<TFile> ofile{TFile::Open( filename, "recreate")};
if (!ofile || ofile->IsZombie())
{
error() << "Error: Could not open file " << filename << std::endl;
return;
}
ofile->cd();
hDpw->Write();
hDww->Write();
hSxy->Write();
hSz->Write();
}

// Restore previous ROOT directory
if(currentDir && ( not currentDir->IsDestructed() ) )
currentDir->cd();
return;
}

StatusCode DCHdigi_v01::finalize() {
if (m_create_debug_histos.value())
{
this->Create_outputROOTfile_for_debugHistograms();
}

return StatusCode::SUCCESS;
}

Expand Down

0 comments on commit dd80ac2

Please sign in to comment.