Skip to content

Commit

Permalink
Fix the DDPlanarDigi algorithm to run like the processor
Browse files Browse the repository at this point in the history
Change the default value for the time resolution to -1, which will mean no time
smearing by default. Change also the directory of the histograms, since
currently only the histograms for the last collection are saved.
  • Loading branch information
jmcarcell committed Jul 3, 2024
1 parent 114d5d8 commit 251ee0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
28 changes: 15 additions & 13 deletions k4Reco/DDPlanarDigi/components/DDPlanarDigi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@
#include "Gaudi/Accumulators/RootHistogram.h"
#include "Gaudi/Histograming/Sink/Utils.h"

#include "DD4hep/BitFieldCoder.h"
#include "DD4hep/DD4hepUnits.h"
#include "DD4hep/Detector.h"
#include "DDSegmentation/BitFieldCoder.h"

#include "TFile.h"
#include "TMath.h"

#include <fmt/format.h>
#include <cmath>
#include <random>

DDPlanarDigi::DDPlanarDigi(const std::string& name, ISvcLocator* svcLoc)
: MultiTransformer(name, svcLoc,
Expand Down Expand Up @@ -156,7 +155,7 @@ std::tuple<edm4hep::TrackerHitPlaneCollection, edm4hep::MCRecoTrackerAssociation
// Smear time of the hit and apply the time window cut if needed
double hitT = hit.getTime();

if (m_resTLayer.size() and m_resTLayer[0] > 0) {
if (m_resTLayer.size() && m_resTLayer[0] > 0) {
float resT = m_resTLayer.size() > 1 ? m_resTLayer[layer] : m_resTLayer[0];

double tSmear = resT > 0 ? m_engine.Gaus(0, resT) : 0;
Expand Down Expand Up @@ -314,20 +313,23 @@ std::tuple<edm4hep::TrackerHitPlaneCollection, edm4hep::MCRecoTrackerAssociation
}

StatusCode DDPlanarDigi::finalize() {
auto file = TFile::Open(m_outputFileName.value().c_str(), "RECREATE");
auto file = TFile::Open(m_outputFileName.value().c_str(), "UPDATE");

std::vector<const char*> names = {"hu", "hv", "hT", "hitE", "hitsAccepted", "diffu", "diffv", "diffT", "hSize"};
auto it = names.begin();
for (auto& h : m_histograms) {
std::string name = "";
// Name that will appear in the stats table
std::string histName = *it;
nlohmann::json json = *h;

std::string directory = this->name();

for (size_t i = 0; i < m_histograms.size(); ++i) {
std::string histName = names[i];
const nlohmann::json& json = *m_histograms[i];

auto [histo, dir] =
Gaudi::Histograming::Sink::jsonToRootHistogram<Gaudi::Histograming::Sink::Traits<false, TH1D, 1>>(
name, histName, json);
histo.Write(*it);
++it;
directory, histName, json);

histo.Write(histName.c_str());
}

file->Close();
return StatusCode::SUCCESS;
}
3 changes: 1 addition & 2 deletions k4Reco/DDPlanarDigi/components/DDPlanarDigi.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

#include "TRandom2.h"

#include <random>
#include <string>
#include <vector>

Expand Down Expand Up @@ -94,7 +93,7 @@ struct DDPlanarDigi final
Gaudi::Property<std::vector<float>> m_resTLayer{
this,
"ResolutionT",
{0.004},
{-1},
"Resolution in the direction of t; either one per layer or one for all layers. If the single entry is negative, "
"disable time smearing. "};
Gaudi::Property<bool> m_forceHitsOntoSurface{this, "ForceHitsOntoSurface", false,
Expand Down

0 comments on commit 251ee0d

Please sign in to comment.