-
Notifications
You must be signed in to change notification settings - Fork 18
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 #10 from lcorcodilos/dev
Development of C++ module infrastructure, doc editing, and other re-organizing
- Loading branch information
Showing
224 changed files
with
5,819 additions
and
4,413 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,7 @@ | |
__pycache__ | ||
build | ||
*.egg-info | ||
dist | ||
dist | ||
experimental/ | ||
.vscode/ | ||
examples/*.root |
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,73 @@ | ||
#include <string> | ||
#include <sstream> | ||
#include <algorithm> | ||
#include <iterator> | ||
#include <vector> | ||
#include <stdexcept> | ||
|
||
//https://stackoverflow.com/questions/13152252/is-there-a-compact-equivalent-to-python-range-in-c-stl | ||
template <typename IntType> | ||
std::vector<IntType> range(IntType start, IntType stop, IntType step) | ||
{ | ||
if (step == IntType(0)) | ||
{ | ||
throw std::invalid_argument("step for range must be non-zero"); | ||
} | ||
|
||
std::vector<IntType> result; | ||
IntType i = start; | ||
while ((step > 0) ? (i < stop) : (i > stop)) | ||
{ | ||
result.push_back(i); | ||
i += step; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
template <typename IntType> | ||
std::vector<IntType> range(IntType start, IntType stop) | ||
{ | ||
return range(start, stop, IntType(1)); | ||
} | ||
|
||
template <typename IntType> | ||
std::vector<IntType> range(IntType stop) | ||
{ | ||
return range(IntType(0), stop, IntType(1)); | ||
} | ||
|
||
// Adapted from http://www.martinbroadhurst.com/how-to-split-a-string-in-c.html | ||
std::vector<std::string> split(const std::string& str, char delim = ' ') { | ||
std::vector<std::string> out {}; | ||
std::stringstream ss(str); | ||
std::string token; | ||
while (std::getline(ss, token, delim)) { | ||
out.push_back(token); | ||
} | ||
|
||
return out; | ||
} | ||
|
||
// Personal | ||
template<typename T> | ||
bool InList(T obj, std::vector<T> list) { | ||
auto pos = std::find(std::begin(list), std::end(list), obj); | ||
if (pos != std::end(list)){ | ||
return true; | ||
} else {return false;} | ||
} | ||
|
||
bool InString(std::string sub, std::string main) { | ||
auto found = main.find(sub); | ||
if (found != std::string::npos){ | ||
return true; | ||
} else {return false;} | ||
} | ||
|
||
template<typename T> | ||
void Extend(std::vector<T> base, std::vector<T> extension) { | ||
for (int i = 0; i < extension.size(); i++) { | ||
base.push_back(extension.at(i)); | ||
} | ||
} |
File renamed without changes.
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,18 @@ | ||
#include <map> | ||
#include <string> | ||
#include <ROOT/RVec.hxx> | ||
|
||
using namespace ROOT::VecOps; | ||
using namespace std; | ||
|
||
/** Structure to store maps of the various types of objects | ||
* in a collection. UChar not considered. | ||
* Use by building each map as <branchName, branchValue> and | ||
* then assigning to the correct struct member. */ | ||
struct Collection { | ||
map<string,int*> Int; | ||
map<string,bool*> Bool; | ||
map<string,RVec<float>*> RVecFloat; | ||
map<string,RVec<int>*> RVecInt; | ||
}; | ||
|
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,77 @@ | ||
#include <cmath> | ||
#include <vector> | ||
#include <numeric> | ||
#include <fstream> | ||
#include "ROOT/RVec.hxx" | ||
#include </home/lucas/Projects/RDFanalyzer/TIMBER/TIMBER/Framework/include/Pythonic.h> | ||
|
||
using namespace ROOT::VecOps; | ||
|
||
class PDFweight_uncert | ||
{ | ||
private: | ||
bool hessian; | ||
bool ignoreEmpty; | ||
int lhaid; | ||
public: | ||
PDFweight_uncert(int lhaID, bool ignoreEmptyBranch = false); | ||
~PDFweight_uncert(); | ||
std::vector<float> eval(RVec<float> LHEPdfWeight); | ||
}; | ||
|
||
PDFweight_uncert::PDFweight_uncert(int lhaID, bool ignoreEmptyBranch){ | ||
ignoreEmpty = ignoreEmptyBranch; | ||
lhaid = lhaID; | ||
// auto determine whether these are replicas or hessian eigenvectors | ||
// Search pdfsets.index, find matching lhaid, check if "hessian" is in the pdf set name | ||
std::fstream lhaid_file; | ||
lhaid_file.open(std::string(std::getenv("TIMBERPATH"))+"TIMBER/data/pdfsets.index",std::fstream::in); | ||
std::string line; | ||
std::vector<std::string> line_parts; | ||
int idx = 0; | ||
while (getline(lhaid_file, line)) { | ||
line_parts = split(line,' '); | ||
if (lhaid == (int)std::stoi(line_parts[0])) { | ||
std::cout << "Found matching PDF set: " << line_parts[1] << " (" << lhaid << ")" << std::endl; | ||
if (InString("hessian",line_parts[1])) { | ||
hessian = true; | ||
} else { hessian = false; } | ||
}; | ||
} | ||
}; | ||
|
||
PDFweight_uncert::~PDFweight_uncert(){}; | ||
|
||
std::vector<float> PDFweight_uncert::eval(RVec<float> LHEPdfWeight) { | ||
// [up,down] | ||
std::vector<float> v; | ||
float stddev; | ||
float sumsquares = 0.0; | ||
int size = LHEPdfWeight.size(); | ||
// check weights aren't empty (known bug that they all could) | ||
if (size == 0 && !ignoreEmpty) { | ||
throw "LHEPdfWeight vector empty. May be known bug in NanoAOD - see https://github.com/cms-nanoAOD/cmssw/issues/520. To ignore, set ignoreEmpty argument to true."; | ||
} | ||
|
||
if (hessian) { // Computes sqrt of sum of differences squared | ||
float base_eigenv = LHEPdfWeight[0]; | ||
for (int ipdf = 1; ipdf < size; ipdf++) { | ||
sumsquares = sumsquares + std::pow(LHEPdfWeight[ipdf] - base_eigenv,2); | ||
} | ||
stddev = sqrt(sumsquares); | ||
|
||
} else { // Computes the std dev of the pdf MC replicas | ||
float pdfavg = std::accumulate(LHEPdfWeight.begin(), LHEPdfWeight.end(), 0.0) / size; | ||
for (int ipdf = 0; ipdf < size; ipdf++) { | ||
sumsquares = sumsquares + std::pow(LHEPdfWeight[ipdf] - pdfavg,2); | ||
} | ||
stddev = sqrt(sumsquares/(size-1)); | ||
} | ||
|
||
v = { | ||
std::min((float)13.0,(float)1.0+stddev), | ||
std::max((float)-13.0,(float)1.0-stddev) | ||
}; | ||
|
||
return v; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Oops, something went wrong.