Skip to content

Commit 0d5e205

Browse files
authored
Merge pull request #39 from key4hep/anaUpdate
update of analysis suite and implementation of corrections (pre-commit errors) of the -help branch merger
2 parents b24a593 + f7452e0 commit 0d5e205

File tree

12 files changed

+490
-104
lines changed

12 files changed

+490
-104
lines changed

k4GeneratorsConfig/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ set(xsection_sources
5858
${CMAKE_CURRENT_SOURCE_DIR}/src/xsection.cxx
5959
${CMAKE_CURRENT_SOURCE_DIR}/src/xsectionCollection.cxx
6060
${CMAKE_CURRENT_SOURCE_DIR}/src/xsection2Root.cxx
61+
${CMAKE_CURRENT_SOURCE_DIR}/src/differential.cxx
6162
)
6263

6364
add_executable(xsectionSummary ${xsection_sources})
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef K4GENERATORSCONFIG_DIFFERENTIAL_H
2+
#define K4GENERATORSCONFIG_DIFFERENTIAL_H
3+
4+
#include <string>
5+
6+
#include "TH1D.h"
7+
8+
namespace k4GeneratorsConfig {
9+
class differential {
10+
public:
11+
differential();
12+
differential(const differential&);
13+
differential& operator=(const differential&);
14+
~differential();
15+
16+
bool processFile();
17+
18+
void setSQRTS(double);
19+
void setGenerator(std::string);
20+
void setProcess(std::string);
21+
void setFile(std::string);
22+
23+
double SQRTS();
24+
std::string Generator();
25+
std::string Process();
26+
std::string File();
27+
bool isValid();
28+
TH1D* TH1DHisto(unsigned int);
29+
unsigned int NbOf1DHistos();
30+
31+
void Print();
32+
33+
private:
34+
double m_sqrts;
35+
std::string m_generator;
36+
std::string m_process;
37+
std::string m_file;
38+
bool m_isValid;
39+
std::vector<TH1D*> m_listOfHists;
40+
};
41+
} // namespace k4GeneratorsConfig
42+
43+
#endif

0 commit comments

Comments
 (0)