-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsamples.h
More file actions
134 lines (113 loc) · 4.6 KB
/
samples.h
File metadata and controls
134 lines (113 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef ANASAMPLES_SAMPLES_H
#define ANASAMPLES_SAMPLES_H
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iostream>
namespace AnaSamples
{
enum COLORS{kRed = 632, kGreen = 416, kBlack = 1, kMagenta = 616, kBlue = 600, kYellow = 400, kTeal = 840, kPink = 900, kOrange = 800, kSpring = 820, kWhite = 0, kGray = 0, kCyan = 432, kAzure = 860, kViolet = 880};
class FileSummary
{
public:
std::string tag;
std::string filePath, treePath;
double xsec, lumi, kfactor, nEvts;
int color;
bool isData_;
bool isFastSim_;
FileSummary() {}
FileSummary(std::string tag, std::string filePath, std::string treePath, double xsec, double lumi, double nEvts, double kfactor, int color = kBlack, bool isFastSim = false) : tag(tag), filePath(filePath), treePath(treePath), xsec(xsec), lumi(lumi), kfactor(kfactor), nEvts(nEvts), color(color), isData_(false), isFastSim_(isFastSim)
{
weight_ = xsec * lumi * kfactor / nEvts;
}
//Constructor which doesn't make a xsec*lumi weighted sample, e.g. for use with data.
//Initialize xsec, lumi, nEvts to 1 so that the comparison operators still work
FileSummary(std::string tag, std::string filePath, std::string treePath, double lumi, double kfactor, int color = kBlack) : tag(tag), filePath(filePath), treePath(treePath), xsec(1), lumi(lumi), kfactor(kfactor), nEvts(1), color(color), isData_(true)
{
weight_ = kfactor;
}
double getWeight() const {return weight_;}
const std::vector<std::string>& getFilelist() const {return filelist_;}
template<class T> void addFilesToChain(T* chain, int startfile =0, int filerun= -1) const
{
if(filelist_.size() == 0) readFileList();
if(filerun<0)filerun=filelist_.size();
for(int fn = startfile; fn < startfile+filerun && fn<filelist_.size(); fn++)
{
chain->Add(filelist_[fn].c_str());
}
}
mutable std::vector<std::string> filelist_;
void addCollection(std::string);
const std::set<std::string>& getCollections() const
{
return collections_;
}
void readFileList() const;
private:
double weight_;
std::set<std::string> collections_;
};
bool operator< (const FileSummary& lhs, const FileSummary& rhs);
bool operator== (const FileSummary& lhs, const FileSummary& rhs);
bool operator!= (const FileSummary& lhs, const FileSummary& rhs);
static const double luminosity = 35866.210733056; // in pb-1
static const std::string fileDir = "/store/user/lpcsusyhad/StealthStop/TreeMaker_ntuples/";
static const std::string treeName = "TreeMaker2/PreSelection";
template<class T>
class SampleBase
{
public:
SampleBase() : nullT_() {};
const T& operator[](const std::string& key) const
{
auto iter = sampleSet_.find(key);
if(iter != sampleSet_.end()) return iter->second;
else return nullT_;
}
const T& null() const {return nullT_;}
protected:
std::map<std::string, T> sampleSet_;
const T nullT_;
public:
decltype(sampleSet_.cbegin()) begin() const { return sampleSet_.cbegin(); }
decltype(sampleSet_.cend()) end() const { return sampleSet_.cend(); }
decltype(sampleSet_.size()) size() const { return sampleSet_.size(); }
};
class SampleCollection;
class SampleSet : public SampleBase<FileSummary>
{
friend class SampleCollection;
public:
SampleSet(std::string fDir = fileDir, double lumi = luminosity);
void addSample(std::string tag, std::string filePath, std::string treePath, double xsec, double lumi, double nEvts, double kfactor, int color = kBlack, bool isFastSim = false)
{
sampleSet_[tag] = FileSummary(tag, filePath, treePath, xsec, lumi, nEvts, kfactor, color, isFastSim);
}
void addSample(std::string tag, std::string filePath, std::string treePath, double lumi, double kfactor, int color = kBlack)
{
sampleSet_[tag] = FileSummary(tag, filePath, treePath, lumi, kfactor, color);
}
private:
std::string fDir_;
double lumi_;
std::map<std::string, FileSummary>& getMap();
};
class SampleCollection : public SampleBase<std::vector<FileSummary>>
{
public:
SampleCollection(SampleSet& samples);
std::vector<std::string>& getSampleLabels(std::string name);
inline double getSampleLumi(std::string name)
{
return totalLumiMap_[name];
}
private:
std::map<std::string, double> totalLumiMap_;
std::map<std::string, std::vector<std::string>> nameVec_;
void addSampleSet(SampleSet& samples, std::string name, std::vector<std::string> vss);
};
}
#endif