Skip to content

Commit e53183a

Browse files
committed
Add scanning codes and plotting scripts
1 parent aff82c0 commit e53183a

27 files changed

+3690
-0
lines changed

scan/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# METScanning
2+
3+
This framework aims to centralize the MET scanners analysis in a more efficient framework.
4+
For more details see the [Wiki page](https://gitlab.cern.ch/mmahdavi/metscanning/-/wikis/home).
5+
6+
7+
# Mannual
8+
9+
1. Set the environment and bBuild the executable file if needed.
10+
```
11+
cmsenv
12+
scram b -j $(nproc)
13+
```
14+
<br/>
15+
16+
2. Run the analysis
17+
```
18+
runAnalysis INPUT_FILE1 [INPUT_FILE2 [...]] --output output.root --dataset DATASET --year YYYY --pass-rec [ON/off] --cross-check [on/OFF]
19+
```
20+
***`--cross-check ON` option will allow you to have cross-check histograms in NFR***
21+
22+
- One can also run ```runAnalysis --help``` or ```runAnalysis -h``` for more detailed help message.
23+
- One may need to modify the configuration files stored in [`config`](https://github.com/cms-met/MetScanning/tree/master/scan/config) directory based on her/his analysis, such as different years, scenarios and etc.
24+
- If one is interested in old-analysis strategy i.e. without BER and NFR control region, it is possible by passing the `--old-analysis` option to the program. Hence the obtained efficencies are with out any cut or ID applied.
25+
<br/>
26+
27+
# Plotting Mannual
28+
For running plot scripts, you need to logout and login again if you have set `CMSSW` environment i.e. `cmsenv`. Then you need to set the proper environment,
29+
```
30+
cd plot
31+
. ./env
32+
cd -
33+
```
34+
There are two different python scripts which provide `efficiencies` and `occupancy maps` plots such as [plot_efficencies](https://github.com/cms-met/MetScanning/tree/master/scan/plot/plot_efficiencies) and [plot_occupancy_maps](https://github.com/cms-met/MetScanning/tree/master/scan/plot/plot_occupancy_maps) respectively. They are mentioned below separately.
35+
36+
Before using the scripts, please make sure that the environment has been set up as mention above.
37+
38+
- **Occupancy maps:**
39+
```
40+
plot_occupancy_maps [list of output root-files separated by space] --dataset [list of datasets w.r.t provided output root-files separated by space] --year YYYY
41+
```
42+
<br/>
43+
44+
- **Efficiency plots:**
45+
46+
For full plots, i.e all filters plots individually and merged plots for each provided dataset, `--all` option is needed like below.
47+
```
48+
plot_efficencies [list of output root-files separated by space] --dataset [list of datasets w.r.t provided output root-files separated by space] --year 2018 --all
49+
```
50+
51+
If one needs also to obtain the actual final merged plot, all datasets must be provided. In this case the `--all` option is optional, for example, below command will plot all kind of plots and the actual final merged plot as well.
52+
```
53+
plot_efficencies jetht_output.root singlemuon_output.root egamma_output.root --dataset jetht singlemuon egamma --year 2018 --all
54+
```
55+
<br/>
56+
57+
- **Plots Configurations:**
58+
59+
The `plot_efficencies` script uses `yaml` configuration files which contain `binning` settings according to regions (`BER` and `NFR`) variables and/or datasets, for each filter separately.
60+
61+
The configuration files are provided in the [config](https://github.com/cms-met/MetScanning/tree/master/scan/config) directory. One may need to modify theses configuration files to obtian the proper plots.
62+
<br/>
63+
<br/>
64+
65+
- *One can also run* ```plot_efficencies [--help, -h]``` or ```plot_occupancy_maps [--help, -h]``` for more detailed help messages.

scan/bin/BERegion.cc

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#include "BERegion.h"
2+
3+
#include <TVector2.h>
4+
5+
6+
BERegion::BERegion(TTreeReader &reader, const std::string berCat)
7+
: Tree(reader),
8+
berCat_{berCat} {
9+
cfg_ = YAML::LoadFile("config/BER.yaml");
10+
minPfMet_ = Get<float>("min_pfmet");
11+
12+
if (berCat == "BadChCand") {
13+
isBER = &BERegion::isBadChCandBER;
14+
minDPhi_ = Get<float>("min_dphi");
15+
pfCanMinPt_ = Get<float>("min_pfcandid_pt");
16+
pfCanPdgId_ = Get<int>("abs_pfcand_pdgid");
17+
}
18+
19+
else if (berCat == "GlbSTightHalo") {
20+
isBER = &BERegion::isGlbSTHaloBER;
21+
maxPfMetPhi_ = Get<float>("max_abs_pfmet_phi");
22+
minPfMetPhi_ = Get<float>("min_abs_pfmet_phi");
23+
minJetPt_ = Get<float>("min_jet_pt");
24+
maxJetEta_ = Get<float>("max_abs_jet_eta");
25+
maxJetChef_ = Get<float>("max_jet_chef");
26+
jetPtGt25Num_ = Get<int>("num_jets_ptgt25");
27+
jetPtGt200Num_ = Get<int>("num_jets_ptgt200");
28+
}
29+
30+
else if (berCat == "BadPFMuon") {
31+
isBER = &BERegion::isBadPFMuonBER;
32+
minDPhi_ = Get<float>("min_dphi");
33+
minMuPt_ = Get<float>("min_muon_pt");
34+
maxAddMuPt_ = Get<float>("max_additional_muon_pt");
35+
minDeltaR_ = Get<float>("min_delta_r");
36+
jetPtGt25Num_ = Get<int>("num_jets_ptgt25");
37+
jetPtGt200Num_ = Get<int>("num_jets_ptgt200");
38+
minMuNum_ = Get<int>("min_num_muon");
39+
}
40+
41+
else if (berCat == "EcalBadCal_U") {
42+
isBER = &BERegion::isEcalBadCalBER;
43+
minDPhi_ = Get<float>("min_dphi");
44+
minJetPt_ = Get<float>("min_jet_pt");
45+
maxJetEta_ = Get<float>("max_abs_jet_eta");
46+
minJetEta_ = Get<float>("min_abs_jet_eta");
47+
minJetNeef_ = Get<float>("min_jet_neef");
48+
jetPtGt25Num_ = Get<int>("num_jets_ptgt25");
49+
jetPtGt200Num_ = Get<int>("num_jets_ptgt200");
50+
}
51+
52+
else if (berCat == "HBHENoise") {
53+
isBER = &BERegion::isHBHENoiseBER;
54+
minDPhi_ = Get<float>("min_dphi");
55+
minJetPt_ = Get<float>("min_jet_pt");
56+
maxJetEta_ = Get<float>("max_abs_jet_eta");
57+
minJetNhef_ = Get<float>("min_jet_nhef");
58+
jetPtGt25Num_ = Get<int>("num_jets_ptgt25");
59+
jetPtGt200Num_ = Get<int>("num_jets_ptgt200");
60+
}
61+
62+
else
63+
isBER = &BERegion::isOthersBER;
64+
65+
}
66+
67+
68+
bool BERegion::operator()() {
69+
return (this->*isBER)();
70+
}
71+
72+
73+
bool BERegion::isBadChCandBER() {
74+
int i = 0;
75+
if (*pfmet > minPfMet_) {
76+
for (long unsigned int j = 0; j < (*pfCandPt).size(); j++)
77+
if ((*pfCandPt)[j] > pfCanMinPt_ and
78+
std::abs((*pfCandPdgId)[j]) == pfCanPdgId_ and
79+
std::fabs(
80+
TVector2::Phi_mpi_pi(*pfmetPhi-(*pfCandPhi)[j])) > minDPhi_)
81+
i++;
82+
}
83+
84+
return (i >= 1);
85+
}
86+
87+
88+
bool BERegion::isGlbSTHaloBER() {
89+
if (*pfmet > minPfMet_ and
90+
(*jetPt).size() == 1 and
91+
(*numJetsPt25) == 1 and
92+
(std::fabs(TVector2::Phi_mpi_pi(*pfmetPhi)) < maxPfMetPhi_ or
93+
std::fabs(TVector2::Phi_mpi_pi(*pfmetPhi)) > minPfMetPhi_) and
94+
(*jetPt)[0] > minJetPt_ and
95+
std::fabs((*jetEta)[0]) < maxJetEta_ and
96+
(*jetCHEF)[0] < maxJetChef_)
97+
return true;
98+
99+
return false;
100+
}
101+
102+
103+
bool BERegion::isBadPFMuonBER() {
104+
if (*pfmet > minPfMet_ and
105+
(*jetPt).size() == jetPtGt200Num_ and
106+
(*numJetsPt25) == jetPtGt25Num_ and
107+
(*muonPt).size() >= minMuNum_ and
108+
(*muonPt)[0] > minMuPt_ and
109+
std::fabs(
110+
TVector2::Phi_mpi_pi(*pfmetPhi - (*muonPhi)[0])) >= minDPhi_ and
111+
(((*muonPt).size() > minMuNum_) ? ((*muonPt)[1] < maxAddMuPt_) : true)
112+
) {
113+
int k = 0;
114+
for (long unsigned int j = 0; j < (*jetPt).size(); j++) {
115+
// To be sure that the jets are not comming from muon jet cone
116+
// by requiring DR < 0.4
117+
float const deltaR = std::sqrt(
118+
std::pow((*muonEta)[0] - (*jetEta)[j], 2) +
119+
std::pow((*muonPhi)[0] - (*jetPhi)[j], 2));
120+
if (deltaR < minDeltaR_)
121+
continue;
122+
k++;
123+
break;
124+
}
125+
126+
return (k == 0);
127+
}
128+
129+
return false;
130+
}
131+
132+
133+
bool BERegion::isEcalBadCalBER() {
134+
if (*pfmet > minPfMet_ and
135+
(*jetPt).size() == jetPtGt200Num_ and
136+
(*numJetsPt25) == jetPtGt25Num_ and
137+
(*jetPt)[0] > minJetPt_ and
138+
std::fabs((*jetEta)[0]) > minJetEta_ and
139+
std::fabs((*jetEta)[0]) < maxJetEta_ and
140+
(*jetNEEF)[0] > minJetNeef_ and
141+
std::fabs(TVector2::Phi_mpi_pi(*pfmetPhi - (*jetPhi)[0])) > minDPhi_)
142+
return true;
143+
144+
return false;
145+
}
146+
147+
148+
bool BERegion::isHBHENoiseBER() {
149+
if (*pfmet > minPfMet_ and
150+
(*jetPt).size() == jetPtGt200Num_ and
151+
(*numJetsPt25) == jetPtGt25Num_ and
152+
(*jetPt)[0] > minJetPt_ and
153+
std::fabs((*jetEta)[0]) < maxJetEta_ and
154+
(*jetNHEF)[0] > minJetNhef_ and
155+
std::fabs(TVector2::Phi_mpi_pi(*pfmetPhi - (*jetPhi)[0])) > minDPhi_)
156+
return true;
157+
158+
return false;
159+
}
160+
161+
162+
bool BERegion::isOthersBER() {
163+
return (*pfmet > minPfMet_);
164+
}
165+
166+
167+
template <typename T>
168+
T BERegion::Get(std::string const field) {
169+
if (cfg_[berCat_][field])
170+
return cfg_[berCat_][field].as<T>();
171+
else {
172+
std::ostringstream message;
173+
message << "BER configuration of " << berCat_
174+
<< " doesn't contain [" << field << "] field.";
175+
throw std::runtime_error(message.str());
176+
}
177+
}
178+

scan/bin/BERegion.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef BEREGION_H
2+
#define BEREGION_H
3+
4+
#include <yaml-cpp/yaml.h>
5+
6+
#include "Tree.h"
7+
8+
9+
class BERegion final : private Tree {
10+
public:
11+
// Constructor
12+
BERegion(TTreeReader &reader, const std::string="Others");
13+
bool operator()();
14+
15+
private:
16+
std::string berCat_;
17+
18+
// BER configuration.
19+
YAML::Node cfg_;
20+
21+
// All BER parameters
22+
float minPfMet_, minDPhi_, maxPfMetPhi_, minPfMetPhi_, minJetPt_, maxJetEta_,
23+
minJetEta_, maxJetChef_, minJetNeef_, minJetNhef_, minMuPt_,
24+
maxAddMuPt_, minDeltaR_, pfCanMinPt_;
25+
26+
int pfCanPdgId_, jetPtGt25Num_;
27+
28+
long unsigned int jetPtGt200Num_, minMuNum_;
29+
30+
// Check whether the event is in BER of BadChCand filters.
31+
bool isBadChCandBER();
32+
33+
// Check whether the event is in BER of GlbSTHalo and GlbTHalo filters.
34+
bool isGlbSTHaloBER();
35+
36+
// Check whether the event is in BER of BadPFMuon filters.
37+
bool isBadPFMuonBER();
38+
39+
// Check whether the event is in BER of EcalBadCal filters.
40+
bool isEcalBadCalBER();
41+
42+
// Check whether the event is in BER of HBHENoise and HBHEIsoNoise filters.
43+
bool isHBHENoiseBER();
44+
45+
// Check whether the event is in BER of other filters.
46+
bool isOthersBER();
47+
48+
// A pointer to one of functions checking whether the event is in BER or not.
49+
bool (BERegion::*isBER)();
50+
51+
// Return the value of given field from configuration file.
52+
template <typename T>
53+
T Get(std::string const field);
54+
};
55+
56+
#endif

scan/bin/BuildFile.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<flags CXXFLAGS="-std=c++17 -Wall -Wextra -O3" />
2+
3+
<bin name="runAnalysis" file="*.cc">
4+
<use name="boost_filesystem" />
5+
<use name="boost_program_options" />
6+
<use name="root" />
7+
<use name="rootgraphics" />
8+
<use name="yaml-cpp" />
9+
</bin>
10+

0 commit comments

Comments
 (0)