Skip to content

Commit

Permalink
add safety checks for KSelector dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kpedro88 committed Mar 30, 2015
1 parent 65ad640 commit 469a721
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 30 deletions.
7 changes: 4 additions & 3 deletions KCode/KSelection.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class KSkimmer;
class KSelector {
public:
//constructor
KSelector() : name(""), localOpt(0), sel(0), sk(0), tree(0), counter(0), dummy(0), canfail(1) {
KSelector() : name(""), localOpt(0), sel(0), sk(0), tree(0), counter(0), dummy(0), canfail(1), depfailed(0) {
//must always have local option map
if(localOpt==0) localOpt = new OptionMap();
}
KSelector(string name_, OptionMap* localOpt_) : name(name_), localOpt(localOpt_), sel(0), sk(0), tree(0), counter(0), dummy(0), canfail(1) {
KSelector(string name_, OptionMap* localOpt_) : name(name_), localOpt(localOpt_), sel(0), sk(0), tree(0), counter(0), dummy(0), canfail(1), depfailed(0) {
//must always have local option map
if(localOpt==0) localOpt = new OptionMap();
dummy = localOpt->Get("dummy",false);
Expand All @@ -45,6 +45,7 @@ class KSelector {
int GetCounter() { return counter; }
bool Dummy() { return dummy; }
bool CanFail() { return canfail; }
bool FailedDependency() { return depfailed; }
//selection function, checks dummy first
virtual bool Select(){
bool result = dummy || Cut();
Expand All @@ -62,7 +63,7 @@ class KSelector {
KSkimmer* sk;
TTree* tree;
int counter;
bool dummy, canfail;
bool dummy, canfail, depfailed;
};

//----------------------------------------------------------------
Expand Down
152 changes: 125 additions & 27 deletions KCode/KSelectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,20 @@ class KSecondMuonSelector : public KLeptonBaseSelector {
sel = sel_;
//set dependencies here
FirstMuon = sel->Get<KLeptonBaseSelector*>("Muon");
if(!FirstMuon){
cout << "Input error: dependency Muon failed in SecondMuon!" << endl;
depfailed = true;
}
else if(FirstMuon->Dummy()){
cout << "Input error: dependency Muon is dummy in SecondMuon!" << endl;
depfailed = true;
}
}

//used for non-dummy selectors
virtual bool Cut() {
//the first muon selector must be present for this to work
if(!FirstMuon) return false;
if(depfailed) return false;

theGoodLeptons.clear(); theGoodLepton = -1;
for(unsigned m = 0; m < sk->MuonPt->size(); m++){
Expand Down Expand Up @@ -325,12 +333,20 @@ class KSecondMuonVetoSelector : public KLeptonBaseSelector {
sel = sel_;
//set dependencies here
FirstMuon = sel->Get<KLeptonBaseSelector*>("Muon");
if(!FirstMuon){
cout << "Input error: dependency Muon failed in SecondMuonVeto!" << endl;
depfailed = true;
}
else if(FirstMuon->Dummy()){
cout << "Input error: dependency Muon is dummy in SecondMuonVeto!" << endl;
depfailed = true;
}
}

//used for non-dummy selectors
virtual bool Cut() {
//the first muon selector must be present for this to work
if(!FirstMuon) return false;
if(depfailed) return false;

for(unsigned m = 0; m < sk->MuonPt->size(); m++){
//boolean to check requirements
Expand Down Expand Up @@ -366,12 +382,20 @@ class KMuonVetoSelector : public KLeptonBaseSelector {
sel = sel_;
//set dependencies here
FirstElectron = sel->Get<KLeptonBaseSelector*>("Electron");
if(!FirstElectron){
cout << "Input error: dependency Electron failed in MuonVeto!" << endl;
depfailed = true;
}
else if(FirstElectron->Dummy()){
cout << "Input error: dependency Electron is dummy in MuonVeto!" << endl;
depfailed = true;
}
}

//used for non-dummy selectors
virtual bool Cut() {
//the first electron selector must be present for this to work
if(!FirstElectron) return false;
if(depfailed) return false;

for(unsigned m = 0; m < sk->MuonPt->size(); m++){
//boolean to check requirements
Expand Down Expand Up @@ -475,12 +499,20 @@ class KSecondElectronSelector : public KLeptonBaseSelector {
sel = sel_;
//set dependencies here
FirstElectron = sel->Get<KLeptonBaseSelector*>("Electron");
if(!FirstElectron){
cout << "Input error: dependency Electron failed in SecondElectron!" << endl;
depfailed = true;
}
else if(FirstElectron->Dummy()){
cout << "Input error: dependency Electron is dummy in SecondElectron!" << endl;
depfailed = true;
}
}

//used for non-dummy selectors
virtual bool Cut() {
//the first electron selector must be present for this to work
if(!FirstElectron) return false;
if(depfailed) return false;

theGoodLeptons.clear(); theGoodLepton = -1;
for(unsigned e = 0; e < sk->ElectronPt->size(); e++){
Expand Down Expand Up @@ -539,12 +571,20 @@ class KSecondElectronVetoSelector : public KLeptonBaseSelector {
sel = sel_;
//set dependencies here
FirstElectron = sel->Get<KLeptonBaseSelector*>("Electron");
if(!FirstElectron){
cout << "Input error: dependency Electron failed in SecondElectronVeto!" << endl;
depfailed = true;
}
else if(FirstElectron->Dummy()){
cout << "Input error: dependency Electron is dummy in SecondElectronVeto!" << endl;
depfailed = true;
}
}

//used for non-dummy selectors
virtual bool Cut() {
//the first electron selector must be present for this to work
if(!FirstElectron) return false;
if(depfailed) return false;

for(unsigned e = 0; e < sk->ElectronPt->size(); e++){
//boolean to check requirements
Expand Down Expand Up @@ -580,12 +620,20 @@ class KElectronVetoSelector : public KLeptonBaseSelector {
sel = sel_;
//set dependencies here
FirstMuon = sel->Get<KLeptonBaseSelector*>("Muon");
if(!FirstMuon){
cout << "Input error: dependency Muon failed in ElectronVeto!" << endl;
depfailed = true;
}
else if(FirstMuon->Dummy()){
cout << "Input error: dependency Muon is dummy in ElectronVeto!" << endl;
depfailed = true;
}
}

//used for non-dummy selectors
virtual bool Cut() {
//the first muon selector must be present for this to work
if(!FirstMuon) return false;
if(depfailed) return false;

for(unsigned e = 0; e < sk->ElectronPt->size(); e++){
//boolean to check requirements
Expand Down Expand Up @@ -628,12 +676,20 @@ class KVertexSelector : public KSelector {
//set dependencies here
FirstLepton = sel->Get<KLeptonBaseSelector*>("Muon");
if(!FirstLepton) FirstLepton = sel->Get<KLeptonBaseSelector*>("Electron");
if(!FirstLepton){
cout << "Input error: dependency Lepton failed in Vertex!" << endl;
depfailed = true;
}
else if(FirstLepton->Dummy()){
cout << "Input error: dependency Lepton is dummy in Vertex!" << endl;
depfailed = true;
}
}

//used for non-dummy selectors
virtual bool Cut() {
//some first lepton selector must be present for this to work
if(!FirstLepton) return false;
if(depfailed) return false;

unsigned assocVtxIndex = FirstLepton->VtxIndex;
bool goodVtx = false;
Expand Down Expand Up @@ -677,7 +733,7 @@ class KTauSelector : public KSelector {
}

//accessors
virtual void SetTree(TTree* tree_) {
virtual void SetTree(TTree* tree_) {
tree = tree_;
//set tree branches here
tree->Branch("HPSTauEt","std::vector<double>",&Et);
Expand All @@ -688,13 +744,15 @@ class KTauSelector : public KSelector {
tree->Branch("HPSTauCharge","std::vector<int>",&Charge);
tree->Branch("HPSTauDecayMode","std::vector<int>",&DecayMode);
tree->Branch("HPSTaubyLooseCombinedIsolationDeltaBetaCorr3Hits","std::vector<bool>",&byLooseCombinedIsolationDeltaBetaCorr3Hits);
if(FirstLepton->GetName()=="Muon") {
tree->Branch("MassMuonTau",&MassLepTau,"MassLepTau/D");
tree->Branch("PtMuonTau",&PtLepTau,"PtLepTau/D");
}
else {
tree->Branch("MassElectronTau",&MassLepTau,"MassLepTau/D");
tree->Branch("PtElectronTau",&PtLepTau,"PtLepTau/D");
if(!depfailed){
if(FirstLepton->GetName()=="Muon") {
tree->Branch("MassMuonTau",&MassLepTau,"MassLepTau/D");
tree->Branch("PtMuonTau",&PtLepTau,"PtLepTau/D");
}
else {
tree->Branch("MassElectronTau",&MassLepTau,"MassLepTau/D");
tree->Branch("PtElectronTau",&PtLepTau,"PtLepTau/D");
}
}
//default values for variables
Et = Eta = Phi = Pt = NULL;
Expand All @@ -709,14 +767,24 @@ class KTauSelector : public KSelector {
FirstLeptonIsMuon = true;
FirstLepton = sel->Get<KLeptonBaseSelector*>("Muon");
if(!FirstLepton) { FirstLepton = sel->Get<KLeptonBaseSelector*>("Electron"); FirstLeptonIsMuon = false; }

if(!FirstLepton){
cout << "Input error: dependency Lepton failed in Tau!" << endl;
depfailed = true;
}
else if(FirstLepton->Dummy()){
cout << "Input error: dependency Lepton is dummy in Tau!" << endl;
depfailed = true;
}

SecondLepton = sel->Get<KLeptonBaseSelector*>("SecondMuon");
if(!SecondLepton) SecondLepton = sel->Get<KLeptonBaseSelector*>("SecondElectron");
}

//used for non-dummy selectors
virtual bool Cut() {
//some first lepton selector must be present for this to work
if(!FirstLepton) return false;
if(depfailed) return false;

theGoodTaus.clear();
for(unsigned t = 0; t < sk->HPSTauPt->size(); t++){
Expand Down Expand Up @@ -814,6 +882,14 @@ class KGenTauSelector : public KSelector {
sel = sel_;
//set dependencies here
TheTau = sel->Get<KTauSelector*>("Tau");
if(!TheTau){
cout << "Input error: dependency Tau failed in GenTau!" << endl;
depfailed = true;
}
else if(TheTau->Dummy()){
cout << "Input error: dependency Tau is dummy in GenTau!" << endl;
depfailed = true;
}
}
virtual void SetSkimmer(KSkimmer* sk_) {
sk = sk_;
Expand All @@ -824,7 +900,7 @@ class KGenTauSelector : public KSelector {
//used for non-dummy selectors
virtual bool Cut() {
//the tau selector must be present for this to work
if(!TheTau) return false;
if(depfailed) return false;

//reset variables
delete FakeJet; FakeJet = new vector<bool>(); FakeJet->resize(TheTau->theGoodTaus.size());
Expand Down Expand Up @@ -1004,15 +1080,17 @@ class KJetSelector : public KSelector {
tree->Branch("IndexTauJet",&IndexTauJet,"IndexTauJet/I");
tree->Branch("MassTauJet",&MassTauJet,"MassTauJet/D");
tree->Branch("PtTauJet",&PtTauJet,"PtTauJet/D");
if(FirstLepton->GetName()=="Muon") {
tree->Branch("IndexMuonJet",&IndexLepJet,"IndexLepJet/I");
tree->Branch("MassMuonJet",&MassLepJet,"MassLepJet/D");
tree->Branch("PtMuonJet",&PtLepJet,"PtLepJet/D");
}
else {
tree->Branch("IndexElectronJet",&IndexLepJet,"IndexLepJet/I");
tree->Branch("MassElectronJet",&MassLepJet,"MassLepJet/D");
tree->Branch("PtElectronJet",&PtLepJet,"PtLepJet/D");
if(!depfailed){
if(FirstLepton->GetName()=="Muon") {
tree->Branch("IndexMuonJet",&IndexLepJet,"IndexLepJet/I");
tree->Branch("MassMuonJet",&MassLepJet,"MassLepJet/D");
tree->Branch("PtMuonJet",&PtLepJet,"PtLepJet/D");
}
else {
tree->Branch("IndexElectronJet",&IndexLepJet,"IndexLepJet/I");
tree->Branch("MassElectronJet",&MassLepJet,"MassLepJet/D");
tree->Branch("PtElectronJet",&PtLepJet,"PtLepJet/D");
}
}
//default values for variables
Energy = Eta = Phi = Pt = CSVBTag = PartonFlavour = NULL;
Expand All @@ -1027,15 +1105,35 @@ class KJetSelector : public KSelector {
//set dependencies here
FirstLepton = sel->Get<KLeptonBaseSelector*>("Muon");
if(!FirstLepton) FirstLepton = sel->Get<KLeptonBaseSelector*>("Electron");

if(!FirstLepton){
cout << "Input error: dependency Lepton failed in Jet!" << endl;
depfailed = true;
}
else if(FirstLepton->Dummy()){
cout << "Input error: dependency Lepton is dummy in Jet!" << endl;
depfailed = true;
}

SecondLepton = sel->Get<KLeptonBaseSelector*>("SecondMuon");
if(!SecondLepton) SecondLepton = sel->Get<KLeptonBaseSelector*>("SecondElectron");

TheTau = sel->Get<KTauSelector*>("Tau");

if(!TheTau){
cout << "Input error: dependency Tau failed in Jet!" << endl;
depfailed = true;
}
else if(TheTau->Dummy()){
cout << "Input error: dependency Tau is dummy in Jet!" << endl;
depfailed = true;
}
}

//used for non-dummy selectors
virtual bool Cut() {
//first lepton and tau selectors must be present for this to work
if(!FirstLepton || !TheTau) return false;
if(depfailed) return false;

theGoodJets.clear();
theMainJet = -1;
Expand Down

0 comments on commit 469a721

Please sign in to comment.