Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new tuple structure along with new methods of computing Tau Trigger SFs #5

Open
wants to merge 79 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
5187c68
Working on a new tag-and-prob root-tuple.
kandrosov Sep 2, 2019
dc3a8bd
Fixed met filters in SelectionFilter.
kandrosov Sep 2, 2019
c2eb956
TupleProducer produces ntuple with minimal set of vars.
kandrosov Sep 3, 2019
e92420b
Reviewed CollectTaus
kandrosov Sep 3, 2019
efda5da
Reviewed gen matching strategy and implementation.
kandrosov Sep 5, 2019
4566a99
Working on new tuple definition.
kandrosov Sep 15, 2019
e1bf8bf
Added HLT and L1 branches and cleaned up old files.
kandrosov Sep 15, 2019
c0bad1e
Added 2016 and 2018 triggers, and implemented a pure MC mode.
kandrosov Sep 20, 2019
9f3ce98
Added support of CRAB and updated instructions.
kandrosov Sep 21, 2019
d2c87e3
Removed dependency on additional packages for pureGen mode.
kandrosov Sep 21, 2019
3666cad
Bugfixes in crab_cmd.py.
kandrosov Sep 21, 2019
b9a0b8f
compareTurnOn - simple script to compare two turn-on curves.
kandrosov Sep 21, 2019
767e1f7
First functional version of compareTurnOn.py.
kandrosov Nov 1, 2019
5a7556f
Storing all filters for the matched HLT objects.
kandrosov Nov 17, 2019
f6b0bcc
Updated eventTuple and crab_submit.
kandrosov Nov 28, 2019
431bc28
Bugfixes in crab scripts.
kandrosov Dec 5, 2019
99b3858
Implemented first version of a GP-based fit.
kandrosov Dec 17, 2019
fe7a849
Merge branch 'new-tuple-update' of github.com:kandrosov/TauTriggerToo…
kandrosov Dec 17, 2019
ddd221f
Fixed fitTurnOn to correctly treat turn-ons with low stat.
kandrosov Dec 19, 2019
7c7f201
added first version of python script for background estimation
May 11, 2020
e09b53d
- minor python syntax fixes
May 11, 2020
9b4bf7a
Added changes to skimTuple.py for sideband studies and data-driven QC…
rdewanje May 12, 2020
d16809b
Merge branch 'new-tuple' of https://github.com/HEP-KBFI/TauTriggerToo…
rdewanje May 12, 2020
d102008
switch to integer (from string) type for "type" and "selection" columns
May 13, 2020
aadcb71
Merge branch 'new-tuple' of https://github.com/HEP-KBFI/TauTriggerToo…
May 13, 2020
aaa6da3
switch to ROOT batch mode
May 13, 2020
2453051
Fixed the pyhton path problem
rdewanje May 13, 2020
822b960
fix problem with RDataFrame constructors, reported by Ram
May 13, 2020
7787e3b
Merge branch 'new-tuple' of https://github.com/HEP-KBFI/TauTriggerToo…
May 13, 2020
dcfcd33
improved whitespace
May 13, 2020
ec9c15a
moved final_weight_data and final_weight_dy_mc functions from python …
May 13, 2020
52463ae
added unweighted event counts to print-out
May 14, 2020
4ee0ad0
improved print-out
May 14, 2020
07d2cf2
Added the sign-only method of computing genEventWeight
rdewanje May 16, 2020
1e62ef2
fixed lumiScale
May 17, 2020
cfa55a0
added debug print-out
May 17, 2020
5f320fd
fixed python syntax error
May 17, 2020
5b6875a
Bug fix in the estimateBackgrounds.py code
rdewanje May 17, 2020
b22ae0e
use separate configuration parameters to specify branchnames for even…
May 17, 2020
8bdef6d
Merge branch 'new-tuple' of https://github.com/HEP-KBFI/TauTriggerToo…
May 17, 2020
2c8fc85
Added logic in createTrunOn.py script for the case when data and mc w…
rdewanje May 17, 2020
b448f8a
Added logic in createTrunOn.py script for the case when data and mc w…
rdewanje May 17, 2020
3a143d3
Removed the RuntimeError in FixEfficiencyBins function inside Analysi…
rdewanje May 17, 2020
a48f964
added tau pT control plot
May 20, 2020
341c6f7
Merge branch 'new-tuple' of https://github.com/HEP-KBFI/TauTriggerToo…
May 20, 2020
f754012
make separate control plots for each tau ID WP
May 20, 2020
38031d0
added protection to CreateEfficiencyRatioGraph that throws an excepti…
May 22, 2020
ce574d6
fixed typo in error message
May 25, 2020
a21d9ab
fixed bug that was causing too manye xceptions of the type "Histogram…
May 25, 2020
abe6fe4
add ".root" to output filename (as it is done by all the other python…
May 25, 2020
5f0f957
- use the same binning for data and MC
May 25, 2020
3787e4d
added some debug print-out
May 26, 2020
0a4a78c
- improved error handling
May 26, 2020
099af82
- "polished" some default parameters
May 26, 2020
5deb1f7
fixed bug with fit function in case one uses non-equidistant binning
May 26, 2020
8bb93cb
fixed minor bug in normalization of histogram in case histogram has b…
May 26, 2020
e078194
fixed bug in print-out of bin errors
Jun 5, 2020
3dc172b
disabled debug output
Jun 5, 2020
199498f
- fixed branchnames for event weights
Jun 5, 2020
f3f94bf
improved handling of negative bins
Jun 5, 2020
c1b2062
clean-up
Jun 5, 2020
946922b
added protection against the number of events in the rightmost bin be…
Jun 5, 2020
585301a
- use binning that is better adapted to event statistics as function …
Jun 8, 2020
1a99a7c
extended debug output (disabled by default)
Jun 8, 2020
cd5da66
start plateau region at 80 GeV (unless a lower pT treshold is favored…
Jun 8, 2020
3dcf0d9
Uploading fixes for pathological cases
rdewanje Jun 9, 2020
ad5cd30
fixed bug in handling of bins with negative bin-content in AutoRebinA…
Jun 9, 2020
a8eea90
Loosened the error band criteria to 3 sigma and max_rel_shift to 0.65
rdewanje Jun 9, 2020
54c9594
bug-fix to AutoRebinAndEfficiency function, concerning the case where…
Jun 9, 2020
7224c64
enabled debug output for Konstantin
Jun 12, 2020
3721a58
require that relative uncertainty (= bin-error/bin-content) is below …
Jun 15, 2020
34e3d09
- use TEfficiency class from ROOT to compute uncertainties on efficie…
Jun 15, 2020
e20b8ab
- added data/MC ratio point in bottom part of fit plot
Jun 15, 2020
c203ea1
Added the New Trigger SF (sep. for true and fake taus) logic alongsid…
rdewanje Jul 20, 2020
b4bb514
Uploaded final version of computeTriggerSFs.py
rdewanje Aug 9, 2020
40d6771
Added the TTbar samples for all the 3 eras used in the study
rdewanje Aug 11, 2020
8138399
Added the pileUp info for the 3 eras
rdewanje Aug 11, 2020
2f9e10c
Added the full python script which runs the workflow post crab job co…
rdewanje Aug 12, 2020
093a677
Create README.md
rdewanje Aug 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
*.so
*.pdf
*.zip
fit.exe
*~
*#*
*.d
__init__.py
output
*.code-workspace
/.python
/.vscode
.DS_Store
3 changes: 3 additions & 0 deletions Common/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<use name="root"/>
<use name="boost"/>
<use name="CLHEP"/>
<use name="DataFormats/HepMCCandidate"/>
<use name="DataFormats/PatCandidates"/>
<use name="FWCore/ParameterSet"/>
<export> <lib name="1"/> </export>
22 changes: 14 additions & 8 deletions Common/interface/AnalysisTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,23 @@ ENUM_NAMES(GenQcdMatch) = {
{ GenQcdMatch::Gluon, "gen_gluon" }
};

enum class TauType { e = 0, mu = 1, tau = 2, jet = 3 };
ENUM_NAMES(TauType) = {
{ TauType::e, "e" }, { TauType::mu, "mu" }, { TauType::tau, "tau" }, { TauType::jet, "jet" }
enum class LegType { e = 1, mu = 2, tau = 4, jet = 8 };
ENUM_NAMES(LegType) = {
{ LegType::e, "e" }, { LegType::mu, "mu" }, { LegType::tau, "tau" }, { LegType::jet, "jet" }
};

inline constexpr TauType GenMatchToTauType(GenLeptonMatch gen_match)
inline constexpr LegType GenMatchToLegType(GenLeptonMatch gen_match)
{
if(gen_match == GenLeptonMatch::Electron || gen_match == GenLeptonMatch::TauElectron) return TauType::e;
if(gen_match == GenLeptonMatch::Muon || gen_match == GenLeptonMatch::TauMuon) return TauType::mu;
if(gen_match == GenLeptonMatch::Tau) return TauType::tau;
return TauType::jet;
if(gen_match == GenLeptonMatch::Electron || gen_match == GenLeptonMatch::TauElectron) return LegType::e;
if(gen_match == GenLeptonMatch::Muon || gen_match == GenLeptonMatch::TauMuon) return LegType::mu;
if(gen_match == GenLeptonMatch::Tau) return LegType::tau;
return LegType::jet;
}

enum class TauSelection { gen = 1, pt = 2, MVA = 4, DeepTau = 8 };
ENUM_NAMES(TauSelection) = {
{ TauSelection::gen, "gen" }, { TauSelection::pt, "pt" }, { TauSelection::MVA, "MVA"},
{ TauSelection::DeepTau, "DeepTau" }
};

} // namespace analysis
204 changes: 204 additions & 0 deletions Common/interface/CutTools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/*! Common tools and definitions to apply cuts.
This file is part of https://github.com/cms-tau-pog/TauTriggerTools. */

#pragma once

#include <exception>
#include <stdexcept>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <iostream>

#include <TH1D.h>
#include <Rtypes.h>

#include "SmartHistogram.h"

namespace cuts {

class cut_failed : public std::exception {
public:
cut_failed(size_t parameter_id) noexcept
: _param_id(parameter_id)
{
std::ostringstream ss;
ss << "Cut requirements are not fulfilled for parameter id = " << _param_id << ".";
message = ss.str();
}

~cut_failed() noexcept {}

virtual const char* what() const noexcept { return message.c_str(); }
size_t param_id() const noexcept { return _param_id; }

private:
size_t _param_id;
std::string message;
};

template<typename ValueType, typename Histogram>
ValueType fill_histogram(ValueType value, Histogram& histogram, double weight)
{
histogram.Fill(value,weight);
return value;
}


class ObjectSelector{
public:

virtual ~ObjectSelector(){}

void incrementCounter(size_t param_id, const std::string& param_label)
{
if (counters.size() < param_id)
throw std::runtime_error("counters out of range");
if (counters.size() == param_id){ //counters and selections filled at least once
counters.push_back(0);
selections.push_back(0);
selectionsSquaredErros.push_back(0);
const std::string label = make_unique_label(param_label);
labels.push_back(label);
label_set.insert(label);
}
counters.at(param_id)++;
}

void fill_selection(double weight = 1.0){
for (unsigned n = 0; n < counters.size(); ++n){
if(counters.at(n) > 0) {
selections.at(n) += weight;
selectionsSquaredErros.at(n) += weight * weight;
}
counters.at(n) = 0;
}
}

template<typename ObjectType, typename Selector, typename Comparitor>
std::vector<ObjectType> collect_objects(double weight, size_t n_objects, const Selector& selector,
const Comparitor& comparitor)
{
std::vector<ObjectType> selected;
for (size_t n = 0; n < n_objects; ++n) {
try {
const ObjectType selectedCandidate = selector(n);
selected.push_back(selectedCandidate);
} catch(cuts::cut_failed&) {}
}

fill_selection(weight);
std::sort(selected.begin(), selected.end(), comparitor);

return selected;
}

private:
std::string make_unique_label(const std::string& label)
{
if(!label_set.count(label)) return label;
for(size_t n = 2; ; ++n) {
std::ostringstream ss;
ss << label << "_" << n;
if(!label_set.count(ss.str())) return ss.str();
}
}

protected:
std::vector<unsigned> counters;
std::vector<double> selections;
std::vector<double> selectionsSquaredErros;
std::vector<std::string> labels;
std::set<std::string> label_set;
};

namespace detail {
struct DefaultSelectionManager{
template<typename ValueType>
void FillHistogram(ValueType value, const std::string& histogram_name) {}
};
} // namespace detail

template<typename SelectionManager = detail::DefaultSelectionManager>
class Cutter {
public:
explicit Cutter(ObjectSelector* _objectSelector, SelectionManager* _selectionManager = nullptr)
: objectSelector(_objectSelector), selectionManager(_selectionManager), param_id(0) {}

bool Enabled() const { return objectSelector != nullptr; }
int CurrentParamId() const { return param_id; }

void operator()(bool expected, const std::string& label)
{
(*this)(expected, label, expected);
}

template<typename ValueType>
void operator()(bool expected, const std::string& label, const ValueType& value)
{
if(selectionManager) {
try {
selectionManager->FillHistogram(value, label);
}catch(std::exception& e) {
std::cout << "ERROR: " << e.what() << std::endl;
}
}
if(Enabled()) {
++param_id;
if(!expected)
throw cut_failed(param_id -1);
objectSelector->incrementCounter(param_id - 1, label);
}
}

bool test(bool expected, const std::string& label)
{
try {
(*this)(expected, label);
return true;
} catch(cut_failed&) {}
return false;
}

private:
ObjectSelector* objectSelector;
SelectionManager* selectionManager;
size_t param_id;
};

} // cuts

namespace root_ext {

template<>
class SmartHistogram<cuts::ObjectSelector> : public cuts::ObjectSelector, public AbstractHistogram {
public:
using RootContainer = TH1D;

SmartHistogram(const std::string& name) : AbstractHistogram(name) {}

void SetSave(bool _save)
{
save = _save;
}

virtual void WriteRootObject()
{
if(!save || !selections.size() || !GetOutputDirectory() )
return;
std::unique_ptr<TH1D> selection_histogram(
new TH1D(Name().c_str(), Name().c_str(),selections.size(),-0.5,-0.5+selections.size()));
for (unsigned n = 0; n < selections.size(); ++n){
const std::string label = labels.at(n);
selection_histogram->GetXaxis()->SetBinLabel(n+1, label.c_str());
selection_histogram->SetBinContent(n+1,selections.at(n));
selection_histogram->SetBinError(n+1,std::sqrt(selectionsSquaredErros.at(n)));
}
root_ext::WriteObject(*selection_histogram, GetOutputDirectory());
}

private:
bool save{true};
};
}
44 changes: 31 additions & 13 deletions Common/interface/GenTruthTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,42 @@ namespace analysis {

namespace gen_truth {

struct FinalState {
public:
enum class ParticleType { visible, light_lepton, neutrino, gamma, charged_hadron, neutral_hadron };

explicit FinalState(const reco::GenParticle& particle, const std::set<int>& pdg_to_exclude = {},
const std::set<const reco::GenParticle*>& particles_to_exclude = {});

const std::set<const reco::GenParticle*>& getParticles(ParticleType type) { return particles[type]; }
const LorentzVectorXYZ& getMomentum(ParticleType type) { return momentum[type]; }
size_t count(ParticleType type) { return getParticles(type).size(); }

private:
void findFinalStateParticles(const reco::GenParticle& particle, const std::set<int>& pdg_to_exclude,
const std::set<const reco::GenParticle*>& particles_to_exclude);
void addParticle(const reco::GenParticle& particle);

private:
std::map<ParticleType, std::set<const reco::GenParticle*>> particles;
std::map<ParticleType, LorentzVectorXYZ> momentum;
};

struct LeptonMatchResult {
GenLeptonMatch match{GenLeptonMatch::NoMatch};
const reco::GenParticle* gen_particle{nullptr};
std::vector<const reco::GenParticle*> visible_daughters;
LorentzVectorXYZ visible_daughters_p4;
int n_chargedParticles;
int n_neutralParticles;
const reco::GenParticle *gen_particle_firstCopy{nullptr}, *gen_particle_lastCopy{nullptr};
std::set<const reco::GenParticle*> visible_daughters, visible_rad;
LorentzVectorXYZ visible_p4, visible_rad_p4;
unsigned n_charged_hadrons{0}, n_neutral_hadrons{0}, n_gammas{0}, n_gammas_rad{0};
};

void FindFinalStateDaughters(const reco::GenParticle& particle, std::set<const reco::GenParticle*>& daughters,
const std::set<int>& pdg_to_exclude);

LorentzVectorXYZ GetFinalStateMomentum(const reco::GenParticle& particle, std::vector<const reco::GenParticle*>& visible_daughters,
bool excludeInvisible, bool excludeLightLeptons);

LeptonMatchResult LeptonGenMatch(const LorentzVectorM& p4,
const reco::GenParticleCollection& genParticles);
const reco::GenParticle* FindTerminalCopy(const reco::GenParticle& genParticle, bool first);
bool FindLeptonGenMatch(const reco::GenParticle& particle, LeptonMatchResult& result,
const LorentzVectorM* ref_p4 = nullptr, double* best_match_dr2 = nullptr);

std::vector<LeptonMatchResult> CollectGenLeptons(const reco::GenParticleCollection& genParticles);
LeptonMatchResult LeptonGenMatch(const LorentzVectorM& p4, const reco::GenParticleCollection& genParticles);
LeptonMatchResult LeptonGenMatch(const LorentzVectorM& p4, const std::vector<LeptonMatchResult>& genLeptons);

float GetNumberOfPileUpInteractions(edm::Handle<std::vector<PileupSummaryInfo>>& pu_infos);

Expand Down
Loading