Skip to content

Commit

Permalink
Merge pull request #1222 from rlcee/pdg_240312
Browse files Browse the repository at this point in the history
implement TFileService access
  • Loading branch information
kutschke authored Mar 12, 2024
2 parents fd237c6 + 5d3f777 commit 558ec75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions Mu2eUtilities/inc/compressPdgId.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>

Expand All @@ -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<art::TFileService>& 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
Expand Down
10 changes: 5 additions & 5 deletions Mu2eUtilities/src/compressPdgId.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,24 @@ namespace mu2e {
return code;
}

TH1D compressPDGCodeHisto(std::string name, std::string title) {
TH1D* compressPDGCodeHisto(art::ServiceHandle<art::TFileService>& 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<TH1D>(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;
}


Expand Down

0 comments on commit 558ec75

Please sign in to comment.