|
| 1 | +#include "differential.h" |
| 2 | +#include <iostream> |
| 3 | +#include <memory> |
| 4 | + |
| 5 | +#include "TFile.h" |
| 6 | +#include "TKey.h" |
| 7 | +#include "TROOT.h" |
| 8 | + |
| 9 | +k4GeneratorsConfig::differential::differential() |
| 10 | + : m_sqrts(0.), m_generator(""), m_process(""), m_file(""), m_isValid(false) {} |
| 11 | +k4GeneratorsConfig::differential::differential(const differential& theOriginal) { |
| 12 | + if (this != &theOriginal) { |
| 13 | + m_sqrts = theOriginal.m_sqrts; |
| 14 | + m_generator = theOriginal.m_generator; |
| 15 | + m_process = theOriginal.m_process; |
| 16 | + m_file = theOriginal.m_file; |
| 17 | + m_isValid = theOriginal.m_isValid; |
| 18 | + for (auto histo : theOriginal.m_listOfHists) { |
| 19 | + m_listOfHists.push_back(new TH1D(*histo)); |
| 20 | + } |
| 21 | + } |
| 22 | +} |
| 23 | +k4GeneratorsConfig::differential& k4GeneratorsConfig::differential::operator=(const differential& theOriginal) { |
| 24 | + if (this != &theOriginal) { |
| 25 | + m_sqrts = theOriginal.m_sqrts; |
| 26 | + m_generator = theOriginal.m_generator; |
| 27 | + m_process = theOriginal.m_process; |
| 28 | + m_file = theOriginal.m_file; |
| 29 | + m_isValid = theOriginal.m_isValid; |
| 30 | + for (auto hist : m_listOfHists) { |
| 31 | + delete hist; |
| 32 | + } |
| 33 | + m_listOfHists.clear(); |
| 34 | + for (auto hist : theOriginal.m_listOfHists) { |
| 35 | + m_listOfHists.push_back(new TH1D(*hist)); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + return *this; |
| 40 | +} |
| 41 | +k4GeneratorsConfig::differential::~differential() {} |
| 42 | +bool k4GeneratorsConfig::differential::processFile() { |
| 43 | + |
| 44 | + // open the root file |
| 45 | + std::unique_ptr<TFile> theFile(TFile::Open(m_file.c_str())); |
| 46 | + if (!theFile || theFile->IsZombie()) |
| 47 | + return false; |
| 48 | + |
| 49 | + // retrieve the RunInfo for the weight names, there should only be 1 entry per Run |
| 50 | + TIter keyList(theFile->GetListOfKeys()); |
| 51 | + TKey* key; |
| 52 | + while ((key = (TKey*)keyList())) { |
| 53 | + TClass* cl = gROOT->GetClass(key->GetClassName()); |
| 54 | + if (cl->InheritsFrom("TH1")) { |
| 55 | + m_listOfHists.push_back(new TH1D(*(TH1D*)key->ReadObj())); |
| 56 | + // turn ownership over to differential: |
| 57 | + m_listOfHists[m_listOfHists.size() - 1]->SetDirectory(0); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + return true; |
| 62 | +} |
| 63 | +void k4GeneratorsConfig::differential::setSQRTS(double sqrts) { m_sqrts = sqrts; } |
| 64 | +void k4GeneratorsConfig::differential::setGenerator(std::string gen) { m_generator = gen; } |
| 65 | +void k4GeneratorsConfig::differential::setProcess(std::string proc) { m_process = proc; } |
| 66 | +void k4GeneratorsConfig::differential::setFile(std::string file) { |
| 67 | + m_file = file; |
| 68 | + m_isValid = processFile(); |
| 69 | +} |
| 70 | +double k4GeneratorsConfig::differential::SQRTS() { return m_sqrts; } |
| 71 | +std::string k4GeneratorsConfig::differential::Generator() { return m_generator; } |
| 72 | +std::string k4GeneratorsConfig::differential::Process() { return m_process; } |
| 73 | +std::string k4GeneratorsConfig::differential::File() { return m_file; } |
| 74 | +bool k4GeneratorsConfig::differential::isValid() { return m_isValid; } |
| 75 | +TH1D* k4GeneratorsConfig::differential::TH1DHisto(unsigned int iHisto) { |
| 76 | + return m_listOfHists.size() > 0 ? m_listOfHists[iHisto] : 0; |
| 77 | +} |
| 78 | +unsigned int k4GeneratorsConfig::differential::NbOf1DHistos() { return m_listOfHists.size(); } |
| 79 | +void k4GeneratorsConfig::differential::Print() { |
| 80 | + std::cout << std::endl; |
| 81 | + std::cout << "Differential object summary:" << std::endl; |
| 82 | + std::cout << "File : " << m_file << std::endl; |
| 83 | + std::cout << "Process : " << m_process << std::endl; |
| 84 | + std::cout << "SQRTS : " << m_sqrts << std::endl; |
| 85 | + std::cout << "Generator : " << m_generator << std::endl; |
| 86 | + std::cout << "differential valid: " << m_isValid << std::endl; |
| 87 | + std::cout << std::endl; |
| 88 | +} |
0 commit comments