-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32019 from kpedro88/SLHATree_94X
Read SLHA from TTree [9_4_X]
- Loading branch information
Showing
7 changed files
with
123 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
GeneratorInterface/Pythia8Interface/interface/SLHAReaderBase.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef GeneratorInterface_Pythia8Interface_SLHAReaderBase | ||
#define GeneratorInterface_Pythia8Interface_SLHAReaderBase | ||
|
||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
class TFile; | ||
class TTree; | ||
|
||
class SLHAReaderBase { | ||
public: | ||
SLHAReaderBase(const edm::ParameterSet& conf); | ||
virtual ~SLHAReaderBase(); | ||
|
||
//this function should parse the config description (e.g. with splitline() below) | ||
//then use the information to get the SLHA info out of the tree and return it | ||
virtual std::string getSLHA(const std::string& configDesc) = 0; | ||
|
||
static std::vector<std::string> splitline(const std::string& line, char delim); | ||
|
||
protected: | ||
//members | ||
TFile* file_; | ||
TTree* tree_; | ||
}; | ||
|
||
#include "FWCore/PluginManager/interface/PluginFactory.h" | ||
typedef edmplugin::PluginFactory<SLHAReaderBase*(const edm::ParameterSet&)> SLHAReaderFactory; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
GeneratorInterface/Pythia8Interface/plugins/SLHAReaderpMSSM.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "GeneratorInterface/Pythia8Interface/interface/SLHAReaderBase.h" | ||
|
||
#include "TTree.h" | ||
#include "TString.h" | ||
|
||
#include <memory> | ||
|
||
class SLHAReaderpMSSM : public SLHAReaderBase { | ||
public: | ||
SLHAReaderpMSSM(const edm::ParameterSet& conf) : SLHAReaderBase(conf) {} | ||
~SLHAReaderpMSSM() override {} | ||
|
||
std::string getSLHA(const std::string& configDesc) override; | ||
}; | ||
|
||
DEFINE_EDM_PLUGIN(SLHAReaderFactory, SLHAReaderpMSSM, "SLHAReaderpMSSM"); | ||
|
||
std::string SLHAReaderpMSSM::getSLHA(const std::string& configDesc) { | ||
const auto& config_fields = splitline(configDesc, '_'); | ||
int chain = std::stoi(config_fields.at(2)); | ||
int iteration = std::stoi(config_fields.at(3)); | ||
|
||
auto slhabranch = std::make_unique<TString>(); | ||
auto slhabranch_ptr = slhabranch.get(); | ||
tree_->SetBranchAddress("slhacontent", &slhabranch_ptr); | ||
tree_->GetEntryWithIndex(chain, iteration); | ||
|
||
return std::string(*slhabranch); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "GeneratorInterface/Pythia8Interface/interface/SLHAReaderBase.h" | ||
#include "FWCore/Utilities/interface/Exception.h" | ||
|
||
#include <sstream> | ||
|
||
#include "TFile.h" | ||
#include "TTree.h" | ||
|
||
SLHAReaderBase::SLHAReaderBase(const edm::ParameterSet& conf) { | ||
auto filename = conf.getParameter<std::string>("file"); | ||
file_ = TFile::Open(filename.c_str()); | ||
if (!file_) | ||
throw cms::Exception("MissingFile") << "Could not open file " << filename; | ||
|
||
auto treename = conf.getParameter<std::string>("tree"); | ||
tree_ = (TTree*)file_->Get(treename.c_str()); | ||
if (!tree_) | ||
throw cms::Exception("MissingTree") << "Could not get tree " << treename << " from file " << filename; | ||
} | ||
|
||
SLHAReaderBase::~SLHAReaderBase() { file_->Close(); } | ||
|
||
std::vector<std::string> SLHAReaderBase::splitline(const std::string& line, char delim) { | ||
std::stringstream ss(line); | ||
std::string field; | ||
std::vector<std::string> fields; | ||
while (getline(ss, field, delim)) { | ||
fields.push_back(field); | ||
} | ||
return fields; | ||
} | ||
|
||
EDM_REGISTER_PLUGINFACTORY(SLHAReaderFactory, "SLHAReaderFactory"); |