From 5d3f77752e4a71397304680f055aee6a88a8aaeb Mon Sep 17 00:00:00 2001 From: Ray Culbertson Date: Tue, 12 Mar 2024 12:06:40 -0500 Subject: [PATCH] implement TFileService access --- Mu2eUtilities/inc/compressPdgId.hh | 7 +++++-- Mu2eUtilities/src/compressPdgId.cc | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Mu2eUtilities/inc/compressPdgId.hh b/Mu2eUtilities/inc/compressPdgId.hh index 3737d50a02..48b505f157 100644 --- a/Mu2eUtilities/inc/compressPdgId.hh +++ b/Mu2eUtilities/inc/compressPdgId.hh @@ -3,6 +3,8 @@ #include "Offline/DataProducts/inc/PDGCode.hh" #include "Offline/DataProducts/inc/CompressedPDGCode.hh" +#include "art/Framework/Services/Registry/ServiceHandle.h" +#include "art_root_io/TFileService.h" #include "TH1D.h" #include @@ -13,8 +15,9 @@ namespace mu2e { CompressedPDGCode::enum_type compressPDGCode(PDGCode::enum_type pdgId); // a histogram with text labels, ready for use with CompressedPDGCode - TH1D compressPDGCodeHisto(std::string name="compPdgId", - std::string title="Compressed PDG ID"); + TH1D* compressPDGCodeHisto(art::ServiceHandle& tfs, + std::string name="compPdgId", + std::string title="Compressed PDG ID"); // compress PDG e,mu,gamma, pions and kaons produced // in cosmic generators into a index 0-7 diff --git a/Mu2eUtilities/src/compressPdgId.cc b/Mu2eUtilities/src/compressPdgId.cc index 6bc78bc3ed..85748054b6 100644 --- a/Mu2eUtilities/src/compressPdgId.cc +++ b/Mu2eUtilities/src/compressPdgId.cc @@ -74,24 +74,24 @@ namespace mu2e { return code; } - TH1D compressPDGCodeHisto(std::string name, std::string title) { + TH1D* compressPDGCodeHisto(art::ServiceHandle& tfs, + std::string name, std::string title) { float low = float(CompressedPDGCode::minBin) - 0.5; float hgh = float(CompressedPDGCode::maxBin) + 0.5; int nbin = CompressedPDGCode::maxBin - CompressedPDGCode::minBin +1; - TH1D hh(name.c_str(),title.c_str(),nbin,low,hgh); + auto hp = tfs->make(name.c_str(),title.c_str(),nbin,low,hgh); int rootBin = 0; for(int ibin=CompressedPDGCode::minBin; ibin<=CompressedPDGCode::maxBin; ibin++) { rootBin++; std::string name = CompressedPDGCode(ibin,false).name(); - std::cout << rootBin << " " << name << "\n"; - hh.GetXaxis()->SetBinLabel(rootBin,name.c_str()); + hp->GetXaxis()->SetBinLabel(rootBin,name.c_str()); } - return hh; + return hp; }