From 209a5fc3debf39baef2e3f78617334e02b4d9148 Mon Sep 17 00:00:00 2001 From: "Jack Y. Araz" Date: Mon, 6 Jun 2022 15:42:09 +0100 Subject: [PATCH 01/67] improve code efficiency --- .../Interfaces/fastjet/ClusterAlgoFastJet.cpp | 60 ++++++++++--------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp b/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp index 8f880447..1782601c 100644 --- a/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp +++ b/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp @@ -52,26 +52,6 @@ MAbool ClusterAlgoFastJet::Execute(SampleFormat& mySample, EventFormat& myEvent, if (Exclusive_) jets = clust_seq->exclusive_jets(0.); else jets = clust_seq->inclusive_jets(0.); - // Initialize output jet vector - std::vector output_jets; - - // Smearing if necessary - MAint32 jet_counter = 0; - if (smearer->isJetSmearerOn()) - { - for (auto &jet: jets) - { - // Smearer module returns a smeared MCParticleFormat object - // Default: NullSmearer, that does nothing - // Reminder: 21 is reserved for the reco-jets - MCParticleFormat current_jet(jet.px(),jet.py(),jet.pz(),jet.e()); - MCParticleFormat smeared = smearer->Execute(dynamic_cast(¤t_jet), 21); - jet.reset_momentum(smeared.px(),smeared.py(),smeared.pz(),smeared.e()); - if(jet.pt() >= Ptmin_) jet_counter++; - } - output_jets.reserve(jet_counter); - } - // Calculating the MET ParticleBaseFormat* MET = myEvent.rec()->GetNewMet(); ParticleBaseFormat* MHT = myEvent.rec()->GetNewMht(); @@ -82,9 +62,22 @@ MAbool ClusterAlgoFastJet::Execute(SampleFormat& mySample, EventFormat& myEvent, MAfloat64 & Meff= myEvent.rec()->Meff(); // Storing - for (auto &jet: fastjet::sorted_by_pt(jets)) + for (auto &jet: jets) { if (jet.pt() <= 1e-10) continue; + + if (smearer->isJetSmearerOn()) + { + // Smearer module returns a smeared MCParticleFormat object + // Default: NullSmearer, that does nothing + // Reminder: 21 is reserved for the reco-jets + MCParticleFormat current_jet(jet.px(),jet.py(),jet.pz(),jet.e()); + MCParticleFormat smeared = smearer->Execute( + dynamic_cast(¤t_jet), 21 + ); + jet.reset_momentum(smeared.px(),smeared.py(),smeared.pz(),smeared.e()); + } + MALorentzVector q(jet.px(),jet.py(),jet.pz(),jet.e()); (*MET) -= q; (*MHT) -= q; @@ -95,18 +88,31 @@ MAbool ClusterAlgoFastJet::Execute(SampleFormat& mySample, EventFormat& myEvent, if(jet.pt() < Ptmin_) continue; // Saving jet information - output_jets.emplace_back(jet); + RecJetFormat * RecJet = myEvent.rec()->GetNewJet(); + RecJet->pseudojet_=jet; + RecJet->setMomentum(MALorentzVector(jet.px(),jet.py(),jet.pz(),jet.e())); + std::vector constituents = clust_seq->constituents(jet); - output_jets.back().Constituents_.reserve(constituents.size()); - output_jets.back().ntracks_ = 0; + RecJet->Constituents_.reserve(constituents.size()); + RecJet->ntracks_ = 0; for (auto &constit: constituents) { - output_jets.back().Constituents_.emplace_back(constit.user_index()); + RecJet->Constituents_.emplace_back(constit.user_index()); if (PDG->IsCharged(myEvent.mc()->particles()[constit.user_index()].pdgid())) - output_jets.back().ntracks_++; + RecJet->ntracks_++; } } - myEvent.rec()->jetcollection_.insert(std::make_pair(myEvent.rec()->PrimaryJetID_, output_jets)); + + // Create an empty accessor if there are no jets. Jets are not sorted at this point!! + if (jets.size() == 0) myEvent.rec()->CreateEmptyJetAccesor(); + else { + std::sort( + myEvent.rec()->jetcollection_[myEvent.rec()->PrimaryJetID_].begin(), + myEvent.rec()->jetcollection_[myEvent.rec()->PrimaryJetID_].end(), + [](RecJetFormat const &j1, RecJetFormat const &j2) { return j1.pt() > j2.pt(); } + ); + } + Meff += MET->pt(); return true; } From 4b0ee80b62b3c0af4341e013aa914819eef44190 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Mon, 6 Jun 2022 16:12:36 +0100 Subject: [PATCH 02/67] deprecate old detector simulator --- .../configuration/beauty_identification.py | 78 ++++--------------- .../configuration/tau_identification.py | 69 ++++++++-------- 2 files changed, 51 insertions(+), 96 deletions(-) diff --git a/madanalysis/configuration/beauty_identification.py b/madanalysis/configuration/beauty_identification.py index 50911e45..400bb5be 100644 --- a/madanalysis/configuration/beauty_identification.py +++ b/madanalysis/configuration/beauty_identification.py @@ -33,12 +33,10 @@ class BeautyIdentification(): default_misid_ljet = 0. - userVariables = { "bjet_id.matching_dr" : [str(default_matching_dr)],\ - "bjet_id.exclusive" : [str(default_exclusive)],\ - "bjet_id.efficiency" : [str(default_efficiency)],\ - "bjet_id.misid_cjet" : [str(default_misid_cjet)],\ - "bjet_id.misid_ljet" : [str(default_misid_ljet)]\ - } + userVariables = { + "bjet_id.matching_dr" : [str(default_matching_dr)], + "bjet_id.exclusive" : [str(default_exclusive)], + } def __init__(self): self.matching_dr = BeautyIdentification.default_matching_dr @@ -52,9 +50,6 @@ def Display(self): logging.getLogger('MA5').info(" + b-jet identification:") self.user_DisplayParameter("bjet_id.matching_dr") self.user_DisplayParameter("bjet_id.exclusive") - self.user_DisplayParameter("bjet_id.efficiency") - self.user_DisplayParameter("bjet_id.misid_cjet") - self.user_DisplayParameter("bjet_id.misid_ljet") def user_DisplayParameter(self,parameter): @@ -123,64 +118,25 @@ def user_SetParameter(self,parameter,value): return False # efficiency - elif parameter=="bjet_id.efficiency": - try: - number = float(value) - except: - logging.getLogger('MA5').error("the efficiency must be a float value.") - return False - if number<0: - logging.getLogger('MA5').error("the efficiency cannot be negative.") - return False - if number>1: - logging.getLogger('MA5').error("the efficiency cannot not greater to 1.") - return False - self.efficiency=number - - # efficiency - elif parameter=="bjet_id.efficiency": - try: - number = float(value) - except: - logging.getLogger('MA5').error("the efficiency must be a float value.") - return False - if number<0: - logging.getLogger('MA5').error("the efficiency cannot be negative.") - return False - if number>1: - logging.getLogger('MA5').error("the efficiency cannot be greater to 1.") - return False - self.efficiency=number + elif parameter == "bjet_id.efficiency": + logging.getLogger('MA5').error("This function has been deprecated, please use SFS functionality instead.") + logging.getLogger('MA5').error("Same functionality can be captured via following command in SFS:") + logging.getLogger('MA5').error(f" -> define tagger b as b {value}") + return False # mis efficiency (cjet) elif parameter=="bjet_id.misid_cjet": - try: - number = float(value) - except: - logging.getLogger('MA5').error("the mis-id efficiency must be a float value.") - return False - if number<0: - logging.getLogger('MA5').error("the mis-id efficiency cannot be negative.") - return False - if number>1: - logging.getLogger('MA5').error("the mis-id efficiency cannot be greater to 1.") - return False - self.misid_cjet=number + logging.getLogger('MA5').error("This function has been deprecated, please use SFS functionality instead.") + logging.getLogger('MA5').error("Same functionality can be captured via following command in SFS:") + logging.getLogger('MA5').error(f" -> define tagger b as c {value}") + return False # mis efficiency (ljet) elif parameter=="bjet_id.misid_ljet": - try: - number = float(value) - except: - logging.getLogger('MA5').error("the mis-id efficiency must be a float value.") - return False - if number<0: - logging.getLogger('MA5').error("the mis-id efficiency cannot be negative.") - return False - if number>1: - logging.getLogger('MA5').error("the mis-id efficiency cannot be greater to 1.") - return False - self.misid_ljet=number + logging.getLogger('MA5').error("This function has been deprecated, please use SFS functionality instead.") + logging.getLogger('MA5').error("Same functionality can be captured via following command in SFS:") + logging.getLogger('MA5').error(f" -> define tagger b as j {value}") + return False # other else: diff --git a/madanalysis/configuration/tau_identification.py b/madanalysis/configuration/tau_identification.py index c7467f98..df539061 100644 --- a/madanalysis/configuration/tau_identification.py +++ b/madanalysis/configuration/tau_identification.py @@ -31,36 +31,39 @@ class TauIdentification(): default_efficiency = 1. default_misid_ljet = 0. - userVariables = { "tau_id.efficiency" : [str(default_efficiency)],\ - "tau_id.misid_ljet" : [str(default_misid_ljet)]\ - } + userVariables = {"tau_id.matching_dr": [str(default_misid_ljet)]} def __init__(self): self.efficiency = TauIdentification.default_efficiency self.misid_ljet = TauIdentification.default_misid_ljet + self.matching_dr = TauIdentification.default_matching_dr def Display(self): logging.getLogger('MA5').info(" + hadronic-tau identification:") - self.user_DisplayParameter("tau_id.efficiency") - self.user_DisplayParameter("tau_id.misid_ljet") + self.user_DisplayParameter("tau_id.matching_dr") + # self.user_DisplayParameter("tau_id.efficiency") + # self.user_DisplayParameter("tau_id.misid_ljet") def user_DisplayParameter(self,parameter): - if parameter=="tau_id.efficiency": - logging.getLogger('MA5').info(" + id efficiency = "+str(self.efficiency)) - elif parameter=="tau_id.misid_ljet": - logging.getLogger('MA5').info(" + mis-id efficiency (light quarks) = "+str(self.misid_ljet)) + if parameter=="tau_id.matching_dr": + logging.getLogger('MA5').info(" + DeltaR matching = "+str(self.matching_dr)) + # if parameter=="tau_id.efficiency": + # logging.getLogger('MA5').info(" + id efficiency = "+str(self.efficiency)) + # elif parameter=="tau_id.misid_ljet": + # logging.getLogger('MA5').info(" + mis-id efficiency (light quarks) = "+str(self.misid_ljet)) else: logging.getLogger('MA5').error("'clustering' has no parameter called '"+parameter+"'") def SampleAnalyzerConfigString(self): - mydict = {} - mydict['tau_id.efficiency'] = str(self.efficiency) - mydict['tau_id.misid_ljet'] = str(self.misid_ljet) - return mydict + return { + 'tau_id.efficiency': str(self.efficiency), + 'tau_id.misid_ljet': str(self.misid_ljet), + 'tau_id.matching_dr': str(self.matching_dr), + } def user_GetValues(self,variable): @@ -75,35 +78,31 @@ def user_GetParameters(self): def user_SetParameter(self,parameter,value): - # efficiency - if parameter=="tau_id.efficiency": + # matching deltar + if parameter == "tau_id.matching_dr": try: number = float(value) except: - logging.getLogger('MA5').error("the efficiency must be a float value.") - return False - if number<0: - logging.getLogger('MA5').error("the efficiency cannot be negative.") + logging.getLogger('MA5').error("the 'matching deltaR' must be a float value.") return False - if number>1: - logging.getLogger('MA5').error("the efficiency cannot not greater to 1.") + if number <= 0: + logging.getLogger('MA5').error("the 'matching deltaR' cannot be negative or null.") return False - self.efficiency=number + self.matching_dr = number + + # efficiency + elif parameter == "tau_id.efficiency": + logging.getLogger('MA5').error("This function has been deprecated, please use SFS functionality instead.") + logging.getLogger('MA5').error("Same functionality can be captured via following command in SFS:") + logging.getLogger('MA5').error(f" -> define tagger ta as ta {value}") + return False # mis efficiency (ljet) - elif parameter=="tau_id.misid_ljet": - try: - number = float(value) - except: - logging.getLogger('MA5').error("the mis-id efficiency must be a float value.") - return False - if number<0: - logging.getLogger('MA5').error("the mis-id efficiency cannot be negative.") - return False - if number>1: - logging.getLogger('MA5').error("the mis-id efficiency cannot be greater to 1.") - return False - self.misid_ljet=number + elif parameter == "tau_id.misid_ljet": + logging.getLogger('MA5').error("This function has been deprecated, please use SFS functionality instead.") + logging.getLogger('MA5').error("Same functionality can be captured via following command in SFS:") + logging.getLogger('MA5').error(f" -> define tagger ta as j {value}") + return False # other else: From 2bcc2ca2ddf0db88a3a74e97720b3aa484f61482 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Mon, 6 Jun 2022 16:21:06 +0100 Subject: [PATCH 03/67] change ancestor as RecJetFormat --- tools/SampleAnalyzer/Commons/DataFormat/RecTauFormat.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecTauFormat.h b/tools/SampleAnalyzer/Commons/DataFormat/RecTauFormat.h index 0defed5c..1189dd89 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecTauFormat.h +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecTauFormat.h @@ -33,7 +33,7 @@ #include // SampleAnalyzer headers -#include "SampleAnalyzer/Commons/DataFormat/RecParticleFormat.h" +#include "SampleAnalyzer/Commons/DataFormat/RecJetFormat.h" #include "SampleAnalyzer/Commons/Service/LogService.h" @@ -48,7 +48,7 @@ class DetectorDelphes; class DetectorDelphesMA5tune; class DelphesMemoryInterface; -class RecTauFormat : public RecParticleFormat +class RecTauFormat : public RecJetFormat { friend class LHCOReader; From 4c6ae3fa1d136d123b7aaff1b02a9a4769cdf980 Mon Sep 17 00:00:00 2001 From: "Jack Y. Araz" Date: Mon, 6 Jun 2022 17:47:14 +0100 Subject: [PATCH 04/67] add reconstruction method --- madanalysis/IOinterface/job_writer.py | 6 +- .../configuration/tau_identification.py | 115 +++++++++++------- 2 files changed, 72 insertions(+), 49 deletions(-) diff --git a/madanalysis/IOinterface/job_writer.py b/madanalysis/IOinterface/job_writer.py index ce308d44..25002aba 100644 --- a/madanalysis/IOinterface/job_writer.py +++ b/madanalysis/IOinterface/job_writer.py @@ -471,11 +471,11 @@ def CreateMainFct(self,file,analysisName,outputName): file.write(' std::map parametersC1;\n') parameters = self.main.fastsim.SampleAnalyzerConfigString() for k,v in sorted(six.iteritems(parameters),key=lambda k_v: (k_v[0],k_v[1])): - file.write(' parametersC1["'+k+'"]="'+v+'";\n') + file.write(' parametersC1["' + (k + '"').ljust(30, " ") + '] = "' + v + '";\n') for obj in ["electron","muon","track","photon"]: if len(getattr(self.main.superfastsim, obj+"_isocone_radius")) != 0: file.write( - ' parametersC1["isolation.'+obj+'.radius"]="'+ ','.join( + ' parametersC1[' + ('"isolation.' + obj + '.radius"').ljust(30, " ") + '] = "' + ','.join( [str(x) for x in getattr(self.main.superfastsim, obj+"_isocone_radius")] )+'";\n' ) @@ -491,7 +491,7 @@ def CreateMainFct(self,file,analysisName,outputName): file.write(' std::map '+map_name+';\n') for opt, val in item.__dict__.items(): if opt in ['JetID','algorithm']: - file.write(' '+map_name+'["'+(opt+'"').ljust(18,' ') + '] = "'+str(val)+'";\n') + file.write(' '+map_name+'["'+(opt+'"').ljust(20,' ') + '] = "'+str(val)+'";\n') else: # To follow old syntax add "cluster.". # This is not necessary but makes sense for unified syntax diff --git a/madanalysis/configuration/tau_identification.py b/madanalysis/configuration/tau_identification.py index df539061..3bbfce7d 100644 --- a/madanalysis/configuration/tau_identification.py +++ b/madanalysis/configuration/tau_identification.py @@ -1,109 +1,132 @@ ################################################################################ -# +# # Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks # The MadAnalysis development team, email: -# +# # This file is part of MadAnalysis 5. # Official website: -# +# # MadAnalysis 5 is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # MadAnalysis 5 is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with MadAnalysis 5. If not, see -# +# ################################################################################ from __future__ import absolute_import import logging -class TauIdentification(): - default_matching_dr = 0.5 - default_exclusive = True - default_efficiency = 1. - default_misid_ljet = 0. - userVariables = {"tau_id.matching_dr": [str(default_misid_ljet)]} +class TauIdentification: + + default_matching_dr = 0.5 + default_exclusive = True + default_efficiency = 1.0 + default_misid_ljet = 0.0 + default_reconstruction_method = "jet-based" + userVariables = { + "tau_id.matching_dr": [str(default_misid_ljet)], + "tau_id.reconstruction_method": ["jet-based", "hadron-based"], + } def __init__(self): - self.efficiency = TauIdentification.default_efficiency - self.misid_ljet = TauIdentification.default_misid_ljet + self.efficiency = TauIdentification.default_efficiency + self.misid_ljet = TauIdentification.default_misid_ljet self.matching_dr = TauIdentification.default_matching_dr + self.reconstruction_method = TauIdentification.default_reconstruction_method - def Display(self): - logging.getLogger('MA5').info(" + hadronic-tau identification:") + logging.getLogger("MA5").info(" + hadronic-tau identification:") self.user_DisplayParameter("tau_id.matching_dr") - # self.user_DisplayParameter("tau_id.efficiency") - # self.user_DisplayParameter("tau_id.misid_ljet") + self.user_DisplayParameter("tau_id.reconstruction_method") - - def user_DisplayParameter(self,parameter): - if parameter=="tau_id.matching_dr": - logging.getLogger('MA5').info(" + DeltaR matching = "+str(self.matching_dr)) - # if parameter=="tau_id.efficiency": - # logging.getLogger('MA5').info(" + id efficiency = "+str(self.efficiency)) - # elif parameter=="tau_id.misid_ljet": - # logging.getLogger('MA5').info(" + mis-id efficiency (light quarks) = "+str(self.misid_ljet)) + def user_DisplayParameter(self, parameter): + if parameter == "tau_id.matching_dr": + logging.getLogger("MA5").info(f" + DeltaR matching = {self.matching_dr:.2f}") + elif parameter == "tau_id.clustering_method": + logging.getLogger("MA5").info( + f" + Reconstruction method = {self.reconstruction_method}" + ) else: - logging.getLogger('MA5').error("'clustering' has no parameter called '"+parameter+"'") - + logging.getLogger("MA5").error( + "'clustering' has no parameter called '" + parameter + "'" + ) def SampleAnalyzerConfigString(self): return { - 'tau_id.efficiency': str(self.efficiency), - 'tau_id.misid_ljet': str(self.misid_ljet), - 'tau_id.matching_dr': str(self.matching_dr), + "tau_id.efficiency": str(self.efficiency), + "tau_id.misid_ljet": str(self.misid_ljet), + "tau_id.matching_dr": str(self.matching_dr), + "tau_id.reconstruction_method": self.reconstruction_method, } - - def user_GetValues(self,variable): + def user_GetValues(self, variable): try: return TauIdentification.userVariables[variable] except: return [] - def user_GetParameters(self): return list(TauIdentification.userVariables.keys()) - - def user_SetParameter(self,parameter,value): + def user_SetParameter(self, parameter, value): # matching deltar if parameter == "tau_id.matching_dr": try: number = float(value) except: - logging.getLogger('MA5').error("the 'matching deltaR' must be a float value.") + logging.getLogger("MA5").error("the 'matching deltaR' must be a float value.") return False if number <= 0: - logging.getLogger('MA5').error("the 'matching deltaR' cannot be negative or null.") + logging.getLogger("MA5").error("the 'matching deltaR' cannot be negative or null.") return False self.matching_dr = number + # reconstruction method + if parameter == "tau_id.reconstruction_method": + if value in TauIdentification.userVariables["tau_id.reconstruction_method"]: + self.reconstruction_method = value + else: + logging.getLogger("MA5").error( + "Available reconstruction methods are: " + + ", ".join(TauIdentification.userVariables["tau_id.reconstruction_method"]) + ) + return False + # efficiency elif parameter == "tau_id.efficiency": - logging.getLogger('MA5').error("This function has been deprecated, please use SFS functionality instead.") - logging.getLogger('MA5').error("Same functionality can be captured via following command in SFS:") - logging.getLogger('MA5').error(f" -> define tagger ta as ta {value}") + logging.getLogger("MA5").error( + "This function has been deprecated, please use SFS functionality instead." + ) + logging.getLogger("MA5").error( + "Same functionality can be captured via following command in SFS:" + ) + logging.getLogger("MA5").error(f" -> define tagger ta as ta {value}") return False # mis efficiency (ljet) elif parameter == "tau_id.misid_ljet": - logging.getLogger('MA5').error("This function has been deprecated, please use SFS functionality instead.") - logging.getLogger('MA5').error("Same functionality can be captured via following command in SFS:") - logging.getLogger('MA5').error(f" -> define tagger ta as j {value}") + logging.getLogger("MA5").error( + "This function has been deprecated, please use SFS functionality instead." + ) + logging.getLogger("MA5").error( + "Same functionality can be captured via following command in SFS:" + ) + logging.getLogger("MA5").error(f" -> define tagger ta as j {value}") return False - # other + # other else: - logging.getLogger('MA5').error("'clustering' has no parameter called '"+parameter+"'") + logging.getLogger("MA5").error( + "'clustering' has no parameter called '" + parameter + "'" + ) From e74b3713692fc1a8799849fbd963298708c3cbaa Mon Sep 17 00:00:00 2001 From: "Jack Y. Araz" Date: Mon, 6 Jun 2022 18:05:36 +0100 Subject: [PATCH 05/67] set default reco mode to hadron-based --- madanalysis/configuration/tau_identification.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/madanalysis/configuration/tau_identification.py b/madanalysis/configuration/tau_identification.py index 3bbfce7d..e554edcd 100644 --- a/madanalysis/configuration/tau_identification.py +++ b/madanalysis/configuration/tau_identification.py @@ -32,7 +32,7 @@ class TauIdentification: default_exclusive = True default_efficiency = 1.0 default_misid_ljet = 0.0 - default_reconstruction_method = "jet-based" + default_reconstruction_method = "hadron-based" userVariables = { "tau_id.matching_dr": [str(default_misid_ljet)], From df1fc5d72d2fd0721eec055e728f449e32889e32 Mon Sep 17 00:00:00 2001 From: "Jack Y. Araz" Date: Mon, 6 Jun 2022 23:05:33 +0100 Subject: [PATCH 06/67] initialize tagger base --- .../Commons/Base/SFSTaggerBase.h | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h new file mode 100644 index 00000000..d6c8463d --- /dev/null +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -0,0 +1,132 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks +// The MadAnalysis development team, email: +// +// This file is part of MadAnalysis 5. +// Official website: +// +// MadAnalysis 5 is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// MadAnalysis 5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have const Received a copy of the GNU General Public License +// along with MadAnalysis 5. If not, see +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef MADANALYSIS5_SFSTAGGERBASE_H +#define MADANALYSIS5_SFSTAGGERBASE_H + +// SampleAnalyser headers +#include "SampleAnalyzer/Commons/DataFormat/EventFormat.h" +#include "SampleAnalyzer/Commons/DataFormat/RecJetFormat.h" +#include "SampleAnalyzer/Commons/DataFormat/RecTauFormat.h" +#include "SampleAnalyzer/Commons/DataFormat/RecPhotonFormat.h" + +namespace MA5 { + class SFSTaggerBase { + public: + /// Constructor without argument + SFSTaggerBase() {} + + /// Destructor + virtual ~SFSTaggerBase() {} + + // Execution + void Execute(EventFormat& myEvent); + + //===============// + // B-Tagging // + //===============// + + // B-jet tagging efficiency + virtual MAfloat32 b_tagging_eff(const RecJetFormat *jet) { return 1.; } + + // B-jet mistagging as C-jet + virtual MAfloat32 b_mistag_c(const RecJetFormat *jet) { return 0.; } + + // B-jet mistagging as light jet + virtual MAfloat32 b_mistag_lightjet(const RecJetFormat *jet) { return 0.; } + + //===============// + // C-Tagging // + //===============// + + // C-jet tagging efficiency + virtual MAfloat32 c_tagging_eff(const RecJetFormat *jet) { return 1.; } + + // C-jet mistagging as C-jet + virtual MAfloat32 c_mistag_b(const RecJetFormat *jet) { return 0.; } + + // C-jet mistagging as light jet + virtual MAfloat32 c_mistag_lightjet(const RecJetFormat *jet) { return 0.; } + + //=======================// + // Light-Jet Tagging // + //=======================// + + // Light-Jet mistagging as b-jet + virtual MAfloat32 lightjet_mistag_b(const RecJetFormat *jet) { return 0.; } + + // Light-Jet mistagging as c jet + virtual MAfloat32 lightjet_mistag_c(const RecJetFormat *jet) { return 0.; } + + // Light-Jet mistagging as tau + virtual MAfloat32 lightjet_mistag_tau(const RecJetFormat *jet) { return 0.; } + + // Light-Jet mistagging as electron + virtual MAfloat32 lightjet_mistag_electron(const RecJetFormat *jet) { return 0.; } + + // Light-Jet mistagging as muon + virtual MAfloat32 lightjet_mistag_muon(const RecJetFormat *jet) { return 0.; } + + // Light-Jet mistagging as photon + virtual MAfloat32 lightjet_mistag_photon(const RecJetFormat *jet) { return 0.; } + + //=================// + // Tau Tagging // + //=================// + + // Electron mistagging as muon + virtual MAfloat32 tau_mistag_lightjet(const RecTauFormat *tau) { return 0.; } + + //=======================// + // Electron Tagging // + //======================// + + // Electron mistagging as muon + virtual MAfloat32 electron_mistag_muon(const RecLeptonFormat *electron) { return 0.; } + + // Electron mistagging as photon + virtual MAfloat32 electron_mistag_photon(const RecLeptonFormat *electron) { return 0.; } + + //==================// + // Muon Tagging // + //==================// + + // Electron mistagging as electron + virtual MAfloat32 muon_mistag_electron(const RecLeptonFormat *muon) { return 0.; } + + // Electron mistagging as photon + virtual MAfloat32 muon_mistag_photon(const RecLeptonFormat *muon) { return 0.; } + + //====================// + // Photon Tagging // + //====================// + + // Electron mistagging as electron + virtual MAfloat32 photon_mistag_electron(const RecPhotonFormat *photon) { return 0.; } + + // Electron mistagging as muon + virtual MAfloat32 photon_mistag_muon(const RecPhotonFormat *photon) { return 0.; } + }; +} + +#endif //MADANALYSIS5_SFSTAGGERBASE_H From bfcdbee01263f379a71cacabfb0d6751b7e9ce1d Mon Sep 17 00:00:00 2001 From: "Jack Y. Araz" Date: Tue, 7 Jun 2022 18:26:42 +0100 Subject: [PATCH 07/67] main routines for tagger base --- .../Commons/Base/SFSTaggerBase.cpp | 148 ++++++++++++++++++ .../Commons/Base/SFSTaggerBase.h | 96 +++++++++--- 2 files changed, 224 insertions(+), 20 deletions(-) create mode 100644 tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp new file mode 100644 index 00000000..4307cd68 --- /dev/null +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -0,0 +1,148 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks +// The MadAnalysis development team, email: +// +// This file is part of MadAnalysis 5. +// Official website: +// +// MadAnalysis 5 is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// MadAnalysis 5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have const Received a copy of the GNU General Public License +// along with MadAnalysis 5. If not, see +// +//////////////////////////////////////////////////////////////////////////////// + +// SampleAnalyser headers +#include "SampleAnalyzer/Commons/Base/SFSTaggerBase.h" +#include "SampleAnalyzer/Commons/Service/RandomService.h" +#include "SampleAnalyzer/Commons/Service/Physics.h" +#include "SampleAnalyzer/Commons/Service/PDGService.h" + +namespace MA5 { + + // Truth B-Jet tagging + void SFSTaggerBase::BJetTagging(EventFormat &myEvent) const + { + for (auto &bHadron: myEvent.rec()->MCBquarks_) + { + MAfloat32 DeltaRmax = _options.btag_matching_deltaR; + RecJetFormat* current_jet = 0; + for (auto &jet: myEvent.rec()->jets()) + { + MAfloat32 dR = jet.dr(bHadron); + if (dR <= DeltaRmax) + { + if (_options.btag_exclusive) + { + current_jet = &jet; DeltaRmax = dR; + } + else jet.setTrueBtag(true); + } + } + if (_options.btag_exclusive && current_jet != 0) current_jet->setTrueBtag(true); + } + } + + // Truth C-Jet tagging + void SFSTaggerBase::CJetTagging(EventFormat &myEvent) const + { + for (auto &cHadron: myEvent.rec()->MCCquarks_) + { + MAfloat32 DeltaRmax = _options.ctag_matching_deltaR; + RecJetFormat* current_jet = 0; + for (auto &jet: myEvent.rec()->jets()) + { + MAfloat32 dR = jet.dr(cHadron); + if (dR <= DeltaRmax) + { + if (_options.ctag_exclusive) + { + current_jet = &jet; DeltaRmax = dR; + } + else jet.setTrueCtag(true); + } + } + if (_options.ctag_exclusive && current_jet != 0) current_jet->setTrueCtag(true); + } + } + + // Truth Hadronic tau tagging (only exclusive) + void SFSTaggerBase::TauTagging(EventFormat &myEvent) const + { + if (_options.tautag_jetbased) + { + for (auto &hadronicTau: myEvent.rec()->MCHadronicTaus()) + { + if (RANDOM->flat() < tau_tagging_eff(*hadronicTau)) continue; + + MAfloat32 DeltaRmax = _options.tautag_matching_deltaR; + MAuint32 toRemove = -1; + for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) + { + if (myEvent.rec()->jets()[ijet].true_ctag() || myEvent.rec()->jets()[ijet].true_btag()) + continue; + + MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(hadronicTau); + if (dR <= DeltaRmax) { DeltaRmax = dR; toRemove = ijet; } + } + if (toRemove >= 0) + { + RecTauFormat* myTau; + Jet2Tau(&myEvent.rec()->jets()[toRemove], myTau, myEvent); + if (RANDOM->flat() < tau_tagging_eff(myTau)) + { + myEvent.rec()->jets().erase(myEvent.rec()->jets().begin() + toRemove); + myEvent.rec()->taus_.push_back(*myTau); + } + } + } + } + else + { + std::vector toRemove; + for (MAuint32 itau = 0; itau < myEvent.rec()->taus().size(); itau++) + { + if (RANDOM->flat() > tau_tagging_eff(*myEvent.rec()->taus()[itau].mc())) + } + } + } + + // Convert Jet object to tau object + void SFSTaggerBase::Jet2Tau(const RecJetFormat * myJet, RecTauFormat *myTau, EventFormat &myEvent) const + { + myTau->setMomentum(myJet->momentum()); + myTau->ntracks_ = myJet->ntracks(); + myTau->mc_ = myJet->mc_; + myTau->DecayMode_ = PHYSICS->GetTauDecayMode(myTau->mc_); + myTau->pseudojet_ = myJet->pseudojet_; + + MAint32 charge = 0; + myTau->Constituents_ = myJet->Constituents_; + for (auto &constit: myTau->Constituents_) + charge += PDG->GetCharge(myEvent.mc()->particles()[constit].pdgid()); + + myTau->charge_ = charge > 0 ? true : false; + } + + // Convert Tau object to Jet + void SFSTaggerBase::Tau2Jet(RecJetFormat *myJet, const RecTauFormat *myTau, EventFormat &myEvent) const + { + myJet->setMomentum(myTau->momentum()); + myJet->ntracks_ = myTau->ntracks(); + myJet->mc_ = myTau->mc_; + myJet->pseudojet_ = myTau->pseudojet_; + myJet->Constituents_ = myTau->Constituents_; + } + + + +} \ No newline at end of file diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index d6c8463d..55727dca 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -31,7 +31,29 @@ #include "SampleAnalyzer/Commons/DataFormat/RecPhotonFormat.h" namespace MA5 { + + struct SFSTaggerBaseOptions { + // btag includes bjet tagging options + // matching deltaR is the threshold for maximum dR distance between a jet and B-hadron + // exclusive algorithm is designed to dynamically find the jet that best matches to the B-hadron + // options starting with ctag and tautag are the ones corresponding to c-jet and tau-jet tagging + // taujtag_jetbased can be either hadron based or jet based. DR matching for tau tagging is + // only available on jet based method + MAfloat32 btag_matching_deltaR = 0.3; + MAbool btag_exclusive = true; + MAfloat32 ctag_matching_deltaR = 0.3; + MAbool ctag_exclusive = true; + MAfloat32 tautag_matching_deltaR = 0.3; + MAbool tautag_jetbased = false; + }; + + class SFSTaggerBase { + private: + MAbool _isTaggerOn; + MAbool _isJetTaggingOn; + SFSTaggerBaseOptions _options; + public: /// Constructor without argument SFSTaggerBase() {} @@ -39,93 +61,127 @@ namespace MA5 { /// Destructor virtual ~SFSTaggerBase() {} + virtual void Initialize() + { + _isTaggerOn = false; + _isJetTaggingOn = false; + } + // Execution void Execute(EventFormat& myEvent); + // Initialize options + void SetOptions(SFSTaggerBaseOptions &opt) { _options = opt; } + + // Accesor to options + SFSTaggerBaseOptions options() const { return _options; } + + void BJetTagging(EventFormat& myEvent) const; + void CJetTagging(EventFormat& myEvent) const; + void TauTagging(EventFormat& myEvent) const; + void Jet2Tau(const RecJetFormat * myJet, RecTauFormat *myTau, EventFormat &myEvent) const; + void Tau2Jet(RecJetFormat * myJet, const RecTauFormat *myTau, EventFormat &myEvent) const; + + //<><><><><><><><><><><><><><><><><><><><><>// + // // + // Tagging Efficiencies // + // // + //<><><><><><><><><><><><><><><><><><><><><>// + + // By default, all efficiencies are initialised as perfect detector + //===============// // B-Tagging // //===============// // B-jet tagging efficiency - virtual MAfloat32 b_tagging_eff(const RecJetFormat *jet) { return 1.; } + virtual MAfloat32 b_tagging_eff(const RecJetFormat jet) const { return 1.; } // B-jet mistagging as C-jet - virtual MAfloat32 b_mistag_c(const RecJetFormat *jet) { return 0.; } + virtual MAfloat32 b_mistag_c(const RecJetFormat jet) const { return 0.; } // B-jet mistagging as light jet - virtual MAfloat32 b_mistag_lightjet(const RecJetFormat *jet) { return 0.; } + virtual MAfloat32 b_mistag_lightjet(const RecJetFormat jet) const { return 0.; } //===============// // C-Tagging // //===============// // C-jet tagging efficiency - virtual MAfloat32 c_tagging_eff(const RecJetFormat *jet) { return 1.; } + virtual MAfloat32 c_tagging_eff(const RecJetFormat jet) const { return 1.; } // C-jet mistagging as C-jet - virtual MAfloat32 c_mistag_b(const RecJetFormat *jet) { return 0.; } + virtual MAfloat32 c_mistag_b(const RecJetFormat jet) const { return 0.; } // C-jet mistagging as light jet - virtual MAfloat32 c_mistag_lightjet(const RecJetFormat *jet) { return 0.; } + virtual MAfloat32 c_mistag_lightjet(const RecJetFormat jet) const { return 0.; } //=======================// // Light-Jet Tagging // //=======================// // Light-Jet mistagging as b-jet - virtual MAfloat32 lightjet_mistag_b(const RecJetFormat *jet) { return 0.; } + virtual MAfloat32 lightjet_mistag_b(const RecJetFormat jet) const { return 0.; } // Light-Jet mistagging as c jet - virtual MAfloat32 lightjet_mistag_c(const RecJetFormat *jet) { return 0.; } + virtual MAfloat32 lightjet_mistag_c(const RecJetFormat jet) const { return 0.; } // Light-Jet mistagging as tau - virtual MAfloat32 lightjet_mistag_tau(const RecJetFormat *jet) { return 0.; } + virtual MAfloat32 lightjet_mistag_tau(const RecJetFormat jet) const { return 0.; } // Light-Jet mistagging as electron - virtual MAfloat32 lightjet_mistag_electron(const RecJetFormat *jet) { return 0.; } + virtual MAfloat32 lightjet_mistag_electron(const RecJetFormat jet) const { return 0.; } // Light-Jet mistagging as muon - virtual MAfloat32 lightjet_mistag_muon(const RecJetFormat *jet) { return 0.; } + virtual MAfloat32 lightjet_mistag_muon(const RecJetFormat jet) const { return 0.; } // Light-Jet mistagging as photon - virtual MAfloat32 lightjet_mistag_photon(const RecJetFormat *jet) { return 0.; } + virtual MAfloat32 lightjet_mistag_photon(const RecJetFormat jet) const { return 0.; } //=================// // Tau Tagging // //=================// - // Electron mistagging as muon - virtual MAfloat32 tau_mistag_lightjet(const RecTauFormat *tau) { return 0.; } + // Tau tagging efficiency + virtual MAfloat32 tau_tagging_eff(const RecJetFormat* jet) const + { + RecTauFormat * myTau; + return tau_tagging_eff(Jet2Tau(jet, myTau)) + } + virtual MAfloat32 tau_tagging_eff(const RecTauFormat tau) const { return 1.; } + + // Tau mistagging as lightjet + virtual MAfloat32 tau_mistag_lightjet(const RecTauFormat tau) const { return 0.; } //=======================// // Electron Tagging // //======================// // Electron mistagging as muon - virtual MAfloat32 electron_mistag_muon(const RecLeptonFormat *electron) { return 0.; } + virtual MAfloat32 electron_mistag_muon(const RecLeptonFormat electron) const { return 0.; } // Electron mistagging as photon - virtual MAfloat32 electron_mistag_photon(const RecLeptonFormat *electron) { return 0.; } + virtual MAfloat32 electron_mistag_photon(const RecLeptonFormat electron) const { return 0.; } //==================// // Muon Tagging // //==================// // Electron mistagging as electron - virtual MAfloat32 muon_mistag_electron(const RecLeptonFormat *muon) { return 0.; } + virtual MAfloat32 muon_mistag_electron(const RecLeptonFormat muon) const { return 0.; } // Electron mistagging as photon - virtual MAfloat32 muon_mistag_photon(const RecLeptonFormat *muon) { return 0.; } + virtual MAfloat32 muon_mistag_photon(const RecLeptonFormat muon) const { return 0.; } //====================// // Photon Tagging // //====================// // Electron mistagging as electron - virtual MAfloat32 photon_mistag_electron(const RecPhotonFormat *photon) { return 0.; } + virtual MAfloat32 photon_mistag_electron(const RecPhotonFormat photon) const { return 0.; } // Electron mistagging as muon - virtual MAfloat32 photon_mistag_muon(const RecPhotonFormat *photon) { return 0.; } + virtual MAfloat32 photon_mistag_muon(const RecPhotonFormat photon) const { return 0.; } }; } From 0aaaa3b8ec009099e57daa691656eb1b14f59890 Mon Sep 17 00:00:00 2001 From: "Jack Y. Araz" Date: Tue, 7 Jun 2022 18:27:08 +0100 Subject: [PATCH 08/67] add tagger base --- tools/SampleAnalyzer/Commons/DataFormat/RecEventFormat.h | 2 ++ tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h | 2 ++ tools/SampleAnalyzer/Commons/DataFormat/RecTauFormat.h | 2 ++ tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecEventFormat.h b/tools/SampleAnalyzer/Commons/DataFormat/RecEventFormat.h index 9d5a28d0..35433a47 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecEventFormat.h +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecEventFormat.h @@ -59,6 +59,7 @@ namespace MA5 class ROOTReader; class TauTagger; class bTagger; + class SFSTaggerBase; class JetClusterer; class ClusterAlgoBase; class ClusterAlgoFastJet; @@ -73,6 +74,7 @@ namespace MA5 friend class ROOTReader; friend class TauTagger; friend class bTagger; + friend class SFSTaggerBase; friend class JetClusterer; friend class ClusterAlgoBase; friend class ClusterAlgoFastJet; diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h index 281075fa..3e9f678d 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h @@ -59,6 +59,7 @@ namespace MA5 class DetectorDelphes; class DetectorDelphesMA5tune; class DelphesMemoryInterface; + class SFSTaggerBase; class RecJetFormat : public RecParticleFormat { @@ -69,6 +70,7 @@ namespace MA5 friend class bTagger; friend class TauTagger; friend class cTagger; + friend class SFSTaggerBase; friend class DetectorDelphes; friend class DetectorDelphesMA5tune; friend class DelphesTreeReader; diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecTauFormat.h b/tools/SampleAnalyzer/Commons/DataFormat/RecTauFormat.h index 472476ba..84e76d6d 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecTauFormat.h +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecTauFormat.h @@ -47,6 +47,7 @@ class DelphesMA5tuneTreeReader; class DetectorDelphes; class DetectorDelphesMA5tune; class DelphesMemoryInterface; +class SFSTaggerBase; class RecTauFormat : public RecJetFormat { @@ -59,6 +60,7 @@ class RecTauFormat : public RecJetFormat friend class DetectorDelphes; friend class DetectorDelphesMA5tune; friend class DelphesMemoryInterface; + friend class SFSTaggerBase; // ------------------------------------------------------------- // data members diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index dce184bf..d107dc8e 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -305,7 +305,7 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) if (!found) myEvent.rec()->MCCquarks_.push_back(&(part)); } - // looking for taus + // looking for taus else if (absid==15) { // rejecting particle if coming from hadronization From cddb25f0e85090d82eab9f8f134c4ae4169d0b11 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Wed, 8 Jun 2022 18:50:10 +0100 Subject: [PATCH 09/67] construct main tagger structure (not complete) --- .../Commons/Base/SFSTaggerBase.cpp | 330 +++++++++++++++--- .../Commons/Base/SFSTaggerBase.h | 137 +++++--- .../Commons/DataFormat/RecJetFormat.h | 15 +- 3 files changed, 368 insertions(+), 114 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index 4307cd68..2e1c6dad 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -29,94 +29,319 @@ namespace MA5 { - // Truth B-Jet tagging + void SFSTaggerBase::Execute(EventFormat &myEvent) const + { + /// Shortcut for global event variables + MAfloat64 & THT = myEvent.rec()->THT(); + MAfloat64 & Meff = myEvent.rec()->Meff(); + + /// Truth level B/C tagging + BJetTagging(myEvent); + CJetTagging(myEvent); + + /// Run tau tagging + if (_options.tautag_jetbased) JetBasedTauTagging(myEvent); + + /// Get initial number of taus. + /// @attention if tau tagging is jet based Ntau will be zero + MAuint32 Ntau = myEvent.rec()->taus().size(); + + /// Jet tagging with detector effects + std::vector toRemove; + MAuint32 ijet = -1; + if (_isJetTaggingOn || _options.tautag_jetbased) { + for (auto &jet: myEvent.rec()->jets()) + { + ijet++; + if (jet.tautag()) + { + if (RANDOM->flat() < tau_tagging_eff(jet)) + { + RecTauFormat *newTau = myEvent.rec()->GetNewTau(); + Jet2Tau(&jet, newTau, myEvent); + toRemove.push_back(ijet); + continue; + } + /// @attention This is for consistency. Tau tag is created for this application only. + jet.setTautag(false); + } + if (!_isJetTaggingOn) continue; + + /// We have a true b-jet: is it b-tagged? + if (jet.true_btag()) + { + if (RANDOM->flat() > b_tagging_eff(jet)) jet.setBtag(false); + } + /// We have a true c-jet: is it b-tagged? + else if (jet.true_ctag()) + { + if (RANDOM->flat() < c_mistag_b(jet)) jet.setBtag(true); + } + /// We have a true light-jet: is it b-tagged? + else + { + if (RANDOM->flat() < lightjet_mistag_b(jet)) jet.setBtag(true); + } + + /// We have a b-tagged jet -> moving on with the next jet + if (jet.btag()) continue; + + /// We have a true b-jet: is it c-tagged? + if (jet.true_btag()) + { + if (RANDOM->flat() < b_mistag_c(jet)) { jet.setCtag(true); jet.setBtag(false); } + } + /// We have a true c-jet: is it c-tagged? + else if (jet.true_ctag()) + { + if (RANDOM->flat() > c_tagging_eff(jet)) jet.setCtag(false); + } + /// We have a true light-jet: is it c-tagged? + else + { + if (RANDOM->flat() < lightjet_mistag_c(jet)) jet.setCtag(true); + } + + /// We have a c-tagged jet -> moving on with the next jet + if (jet.ctag()) continue; + + /// We have a true b/c-jet -> cannot be mistagged + if (jet.ctag() || jet.btag()) continue; + /// if not, is it mis-tagged as anything? + else + { + { /// Scope for light jet mistagging as tau + /// if not, is it Tau-tagged? + if (RANDOM->flat() < lightjet_mistag_tau(jet)) { + RecTauFormat *newTau = myEvent.rec()->GetNewTau(); + Jet2Tau(&jet, newTau, myEvent); + toRemove.push_back(ijet); + continue; + } + } + { /// Scope for light jet mistagging for electron + /// if not, is it Electron-tagged? + if (RANDOM->flat() < lightjet_mistag_electron(jet)) + { + RecLeptonFormat* NewParticle = myEvent.rec()->GetNewElectron(); + NewParticle->setMomentum(jet.momentum()); + NewParticle->setMc(jet.mc()); + /// @attention charge can also be determined via total constituent charge + NewParticle->SetCharge(RANDOM->flat() > 0.5 ? 1. : -1.); + THT -= jet.pt(); + Meff -= jet.pt(); + MALorentzVector MissHT = myEvent.rec()->MHT().momentum() + jet.momentum(); + (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( + MissHT.Px(), MissHT.Py(), 0., MissHT.E() + ); + toRemove.push_back(ijet); + } + } + { /// Scope for light jet mistagging for photon + /// if not, is it Photon-tagged? + if (RANDOM->flat() < lightjet_mistag_photon(jet)) + { + RecPhotonFormat* NewParticle = myEvent.rec()->GetNewPhoton(); + NewParticle->setMomentum(jet.momentum()); + NewParticle->setMc(jet.mc()); + THT -= jet.pt(); + Meff -= jet.pt(); + MALorentzVector MissHT = myEvent.rec()->MHT().momentum() + jet.momentum(); + (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( + MissHT.Px(), MissHT.Py(), 0., MissHT.E() + ); + toRemove.push_back(ijet); + continue; + } + } + } + } + /// Remove jets from the collection + for (MAuint32 i = toRemove.size(); i > 0; i--) + myEvent.rec()->jets().erase(myEvent.rec()->jets().begin() + toRemove[i-1]); + toRemove.clear(); + } + + + if (_isTauTaggingEffOn) + { + /// In Jet based tau tagging this loop will not run + for (MAuint32 itau = 0; itau < Ntau; itau++) + { + if (RANDOM->flat() > tau_tagging_eff(myEvent.rec()->taus()[itau])) + { + RecJetFormat* NewParticle = myEvent.rec()->GetNewJet(); + NewParticle->setMomentum((&myEvent.rec()->taus()[itau])->momentum()); + NewParticle->setMc((&myEvent.rec()->taus()[itau])->mc()); + NewParticle->setNtracks((&myEvent.rec()->taus()[itau])->ntracks()); + toRemove.push_back(itau); + } + } + /// Remove taus from the collection + for (MAuint32 i=toRemove.size();i>0;i--) + myEvent.rec()->taus().erase(myEvent.rec()->taus().begin() + toRemove[i-1]); + toRemove.clear(); + } + + + /// Muon mistagging + if (_isMuonTaggingOn) + { + MAuint32 imu = -1; + for (auto &muon: myEvent.rec()->muons()) + { + imu++; + /// Muon mistagging as electron + if (RANDOM->flat() < muon_mistag_electron(muon)) + { + RecLeptonFormat* NewParticle = myEvent.rec()->GetNewElectron(); + NewParticle->setMomentum(muon.momentum()); + NewParticle->setMc(muon.mc()); + NewParticle->SetCharge(muon.charge()); + toRemove.push_back(imu); + continue; + } + /// Muon mistagging as photon + if (RANDOM->flat() < muon_mistag_photon(muon)) + { + RecPhotonFormat* NewParticle = myEvent.rec()->GetNewPhoton(); + NewParticle->setMomentum(muon.momentum()); + NewParticle->setMc(muon.mc()); + toRemove.push_back(imu); + continue; + } + /// Muon mistagging as light jet + /// @attention this will cause problems if executed in substructure tools + if (RANDOM->flat() < muon_mistag_lightjet(muon)) + { + RecJetFormat* NewParticle = myEvent.rec()->GetNewJet(); + NewParticle->setMomentum(muon.momentum()); + NewParticle->setMc(muon.mc()); + NewParticle->setNtracks(1); + THT += muon.pt(); + Meff += muon.pt(); + MALorentzVector MissHT = myEvent.rec()->MHT().momentum() - muon.momentum(); + (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( + MissHT.Px(), MissHT.Py(), 0., MissHT.E() + ); + toRemove.push_back(imu); + continue; + } + } + for (MAuint32 i=toRemove.size();i>0;i--) + myEvent.rec()->muons().erase(myEvent.rec()->muons().begin() + toRemove[i-1]); + toRemove.clear(); + } + + + /// Electron mistagging + if (_isElectronTaggingOn) + { + /// @todo complete this section + } + + + /// Photon mistaging + if (_isPhotonTaggingOn) + { + /// @todo complete this section + } + } + + /// @attention BJetTagging and CJetTagging methods do not include any detector effects + /// this is due to the construction of the for loop over jets. If one applies detector + /// efficiencies at this state an efficiency can be applied to a jet multiple times. + /// Since one jet can contains multiple B/C hadrons within its cone. + + /// Truth B-Jet tagging void SFSTaggerBase::BJetTagging(EventFormat &myEvent) const { for (auto &bHadron: myEvent.rec()->MCBquarks_) { MAfloat32 DeltaRmax = _options.btag_matching_deltaR; - RecJetFormat* current_jet = 0; - for (auto &jet: myEvent.rec()->jets()) + MAuint32 current_ijet = -1; + for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) { - MAfloat32 dR = jet.dr(bHadron); + MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(bHadron); if (dR <= DeltaRmax) { if (_options.btag_exclusive) { - current_jet = &jet; DeltaRmax = dR; + current_ijet = ijet; DeltaRmax = dR; + } + else + { + myEvent.rec()->jets()[ijet].setTrueBtag(true); + myEvent.rec()->jets()[ijet].setBtag(true); } - else jet.setTrueBtag(true); } } - if (_options.btag_exclusive && current_jet != 0) current_jet->setTrueBtag(true); + if (current_ijet >= 0) + { + myEvent.rec()->jets()[current_ijet].setTrueBtag(true); + myEvent.rec()->jets()[current_ijet].setBtag(true); + } } } - // Truth C-Jet tagging + /// Truth C-Jet tagging void SFSTaggerBase::CJetTagging(EventFormat &myEvent) const { for (auto &cHadron: myEvent.rec()->MCCquarks_) { MAfloat32 DeltaRmax = _options.ctag_matching_deltaR; - RecJetFormat* current_jet = 0; - for (auto &jet: myEvent.rec()->jets()) + MAuint32 current_ijet = -1; + for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) { - MAfloat32 dR = jet.dr(cHadron); + MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(cHadron); if (dR <= DeltaRmax) { if (_options.ctag_exclusive) { - current_jet = &jet; DeltaRmax = dR; + current_ijet = ijet; DeltaRmax = dR; + } + else + { + myEvent.rec()->jets()[ijet].setTrueCtag(true); + myEvent.rec()->jets()[ijet].setCtag(true); } - else jet.setTrueCtag(true); } } - if (_options.ctag_exclusive && current_jet != 0) current_jet->setTrueCtag(true); + if (current_ijet >= 0) + { + myEvent.rec()->jets()[current_ijet].setTrueCtag(true); + myEvent.rec()->jets()[current_ijet].setCtag(true); + } } } - // Truth Hadronic tau tagging (only exclusive) - void SFSTaggerBase::TauTagging(EventFormat &myEvent) const + /// This method implements tau matching for jets + void SFSTaggerBase::JetBasedTauTagging(EventFormat &myEvent) const { - if (_options.tautag_jetbased) + for (auto &hadronicTau: myEvent.rec()->MCHadronicTaus()) { - for (auto &hadronicTau: myEvent.rec()->MCHadronicTaus()) + MAfloat32 DeltaRmax = _options.tautag_matching_deltaR; + MAuint32 current_jet = -1; + for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) { - if (RANDOM->flat() < tau_tagging_eff(*hadronicTau)) continue; - - MAfloat32 DeltaRmax = _options.tautag_matching_deltaR; - MAuint32 toRemove = -1; - for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) - { - if (myEvent.rec()->jets()[ijet].true_ctag() || myEvent.rec()->jets()[ijet].true_btag()) - continue; + if (myEvent.rec()->jets()[ijet].true_ctag() || myEvent.rec()->jets()[ijet].true_btag()) + continue; - MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(hadronicTau); - if (dR <= DeltaRmax) { DeltaRmax = dR; toRemove = ijet; } - } - if (toRemove >= 0) + MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(hadronicTau); + if (dR <= DeltaRmax) { - RecTauFormat* myTau; - Jet2Tau(&myEvent.rec()->jets()[toRemove], myTau, myEvent); - if (RANDOM->flat() < tau_tagging_eff(myTau)) + if (_options.tautag_exclusive) { - myEvent.rec()->jets().erase(myEvent.rec()->jets().begin() + toRemove); - myEvent.rec()->taus_.push_back(*myTau); + DeltaRmax = dR; current_jet = ijet; } + else myEvent.rec()->jets()[current_jet].setTautag(true); } } - } - else - { - std::vector toRemove; - for (MAuint32 itau = 0; itau < myEvent.rec()->taus().size(); itau++) - { - if (RANDOM->flat() > tau_tagging_eff(*myEvent.rec()->taus()[itau].mc())) - } + if (current_jet >= 0) myEvent.rec()->jets()[current_jet].setTautag(true); } } - // Convert Jet object to tau object + /// Convert Jet object to tau object void SFSTaggerBase::Jet2Tau(const RecJetFormat * myJet, RecTauFormat *myTau, EventFormat &myEvent) const { myTau->setMomentum(myJet->momentum()); @@ -126,23 +351,14 @@ namespace MA5 { myTau->pseudojet_ = myJet->pseudojet_; MAint32 charge = 0; - myTau->Constituents_ = myJet->Constituents_; + myTau->Constituents_.reserve(myJet->Constituents_.size()); + myTau->Constituents_.insert( + myTau->Constituents_.end(), myJet->Constituents_.begin(), myJet->Constituents_.end() + ); for (auto &constit: myTau->Constituents_) charge += PDG->GetCharge(myEvent.mc()->particles()[constit].pdgid()); myTau->charge_ = charge > 0 ? true : false; } - // Convert Tau object to Jet - void SFSTaggerBase::Tau2Jet(RecJetFormat *myJet, const RecTauFormat *myTau, EventFormat &myEvent) const - { - myJet->setMomentum(myTau->momentum()); - myJet->ntracks_ = myTau->ntracks(); - myJet->mc_ = myTau->mc_; - myJet->pseudojet_ = myTau->pseudojet_; - myJet->Constituents_ = myTau->Constituents_; - } - - - } \ No newline at end of file diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index 55727dca..e93a0846 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -33,25 +33,34 @@ namespace MA5 { struct SFSTaggerBaseOptions { - // btag includes bjet tagging options - // matching deltaR is the threshold for maximum dR distance between a jet and B-hadron - // exclusive algorithm is designed to dynamically find the jet that best matches to the B-hadron - // options starting with ctag and tautag are the ones corresponding to c-jet and tau-jet tagging - // taujtag_jetbased can be either hadron based or jet based. DR matching for tau tagging is - // only available on jet based method + /// @brief Tagging options + /// + /// @code btag_matching_deltaR @endcode + /// matching deltaR is the threshold for maximum dR distance between a jet and B-hadron + /// @code btag_exclusive @endcode + /// exclusive algorithm is designed to dynamically find the jet that best matches to the B-hadron + /// + /// options starting with ctag and tautag are the ones corresponding to c-jet and tau-jet tagging + /// taujtag_jetbased can be either hadron based or jet based. + /// @warning DR matching for tau tagging is only available on jet based method MAfloat32 btag_matching_deltaR = 0.3; MAbool btag_exclusive = true; MAfloat32 ctag_matching_deltaR = 0.3; MAbool ctag_exclusive = true; MAfloat32 tautag_matching_deltaR = 0.3; + MAbool tautag_exclusive = true; /// not used at the moment. MAbool tautag_jetbased = false; }; + /// @brief Tagger base is designed to accommodate both truth and detector level B/C/Hadronic Tau tagging. + /// + /// Tagging efficiencies are designed to redefine in new_tagger.h/cpp files locally for the analysis + /// and used during tagging. If not defined, by default truth level tagging will be applied. class SFSTaggerBase { private: - MAbool _isTaggerOn; - MAbool _isJetTaggingOn; + /// Code efficiency booleans + MAbool _isJetTaggingOn, _isTauTaggingEffOn, _isMuonTaggingOn, _isElectronTaggingOn, _isPhotonTaggingOn; SFSTaggerBaseOptions _options; public: @@ -63,125 +72,143 @@ namespace MA5 { virtual void Initialize() { - _isTaggerOn = false; + /// @brief Booleans for code efficiency + /// Turn on the usage of tau tagging efficiency + _isTauTaggingEffOn = false; + /// Turn on the usage of jet (mis)tagging efficiency _isJetTaggingOn = false; + /// Turn on the usage of muon (mis)tagging efficiency + _isMuonTaggingOn = false; + /// Turn on the usage of electron (mis)tagging efficiency + _isElectronTaggingOn = false; + /// Turn on the usage of photon (mis)tagging efficiency + _isPhotonTaggingOn = false; } - // Execution - void Execute(EventFormat& myEvent); + /// @brief Execution: execute truth and detector level tagging algorithm + void Execute(EventFormat& myEvent) const; - // Initialize options + /// Initialize options void SetOptions(SFSTaggerBaseOptions &opt) { _options = opt; } - // Accesor to options + /// Accesor to options SFSTaggerBaseOptions options() const { return _options; } + /// Truth B-Jet tagging void BJetTagging(EventFormat& myEvent) const; + + /// Truth C-Jet tagging void CJetTagging(EventFormat& myEvent) const; - void TauTagging(EventFormat& myEvent) const; + + /// Hadronic tau tagging: this method implements both truth and detector level tagging simultaneously + void JetBasedTauTagging(EventFormat& myEvent) const; + + /// Convert Jet object to tau object void Jet2Tau(const RecJetFormat * myJet, RecTauFormat *myTau, EventFormat &myEvent) const; - void Tau2Jet(RecJetFormat * myJet, const RecTauFormat *myTau, EventFormat &myEvent) const; - //<><><><><><><><><><><><><><><><><><><><><>// - // // - // Tagging Efficiencies // - // // - //<><><><><><><><><><><><><><><><><><><><><>// + ///==========================================// + /// // + /// Tagging Efficiencies // + /// // + ///==========================================// - // By default, all efficiencies are initialised as perfect detector + /// @brief By default, all efficiencies are initialised as perfect detector - //===============// - // B-Tagging // - //===============// + ///===============// + /// B-Tagging // + ///===============// - // B-jet tagging efficiency + /// B-jet tagging efficiency (b as b) virtual MAfloat32 b_tagging_eff(const RecJetFormat jet) const { return 1.; } - // B-jet mistagging as C-jet + /// B-jet mistagging as C-jet (b as c) virtual MAfloat32 b_mistag_c(const RecJetFormat jet) const { return 0.; } - // B-jet mistagging as light jet - virtual MAfloat32 b_mistag_lightjet(const RecJetFormat jet) const { return 0.; } - //===============// // C-Tagging // //===============// - // C-jet tagging efficiency + /// C-jet tagging efficiency (c as c) virtual MAfloat32 c_tagging_eff(const RecJetFormat jet) const { return 1.; } - // C-jet mistagging as C-jet + /// C-jet mistagging as C-jet (c as b) virtual MAfloat32 c_mistag_b(const RecJetFormat jet) const { return 0.; } - // C-jet mistagging as light jet - virtual MAfloat32 c_mistag_lightjet(const RecJetFormat jet) const { return 0.; } - //=======================// // Light-Jet Tagging // //=======================// - // Light-Jet mistagging as b-jet + /// Light-Jet mistagging as b-jet (j as b) virtual MAfloat32 lightjet_mistag_b(const RecJetFormat jet) const { return 0.; } - // Light-Jet mistagging as c jet + /// Light-Jet mistagging as c jet (j as c) virtual MAfloat32 lightjet_mistag_c(const RecJetFormat jet) const { return 0.; } - // Light-Jet mistagging as tau + /// Light-Jet mistagging as tau (j as ta) virtual MAfloat32 lightjet_mistag_tau(const RecJetFormat jet) const { return 0.; } - // Light-Jet mistagging as electron + /// Light-Jet mistagging as electron (j as e) virtual MAfloat32 lightjet_mistag_electron(const RecJetFormat jet) const { return 0.; } - // Light-Jet mistagging as muon - virtual MAfloat32 lightjet_mistag_muon(const RecJetFormat jet) const { return 0.; } - - // Light-Jet mistagging as photon + /// Light-Jet mistagging as photon (j as photon) virtual MAfloat32 lightjet_mistag_photon(const RecJetFormat jet) const { return 0.; } //=================// // Tau Tagging // //=================// - // Tau tagging efficiency - virtual MAfloat32 tau_tagging_eff(const RecJetFormat* jet) const + /// Convert jet to tau + MAfloat32 tau_tagging_eff(const RecJetFormat jet) const { - RecTauFormat * myTau; - return tau_tagging_eff(Jet2Tau(jet, myTau)) + RecTauFormat myTau; + myTau.setMomentum(jet.momentum()); + myTau.ntracks_ = jet.ntracks(); + myTau.mc_ = jet.mc_; + + return tau_tagging_eff(myTau); } + + /// Tau tagging efficiency (ta as ta) virtual MAfloat32 tau_tagging_eff(const RecTauFormat tau) const { return 1.; } - // Tau mistagging as lightjet - virtual MAfloat32 tau_mistag_lightjet(const RecTauFormat tau) const { return 0.; } - //=======================// // Electron Tagging // //======================// - // Electron mistagging as muon + /// Electron mistagging as muon (e as mu) virtual MAfloat32 electron_mistag_muon(const RecLeptonFormat electron) const { return 0.; } - // Electron mistagging as photon + /// Electron mistagging as photon (e as a) virtual MAfloat32 electron_mistag_photon(const RecLeptonFormat electron) const { return 0.; } + /// Electron mistagging as light jet (e as j) + virtual MAfloat32 electron_mistag_lightjet(const RecLeptonFormat electron) const { return 0.; } + //==================// // Muon Tagging // //==================// - // Electron mistagging as electron + /// Electron mistagging as electron (mu as e) virtual MAfloat32 muon_mistag_electron(const RecLeptonFormat muon) const { return 0.; } - // Electron mistagging as photon + /// Electron mistagging as photon (mu as a) virtual MAfloat32 muon_mistag_photon(const RecLeptonFormat muon) const { return 0.; } + /// Electron mistagging as light jet (mu as j) + virtual MAfloat32 muon_mistag_lightjet(const RecLeptonFormat muon) const { return 0.; } + //====================// // Photon Tagging // //====================// - // Electron mistagging as electron + /// Electron mistagging as electron (a as e) virtual MAfloat32 photon_mistag_electron(const RecPhotonFormat photon) const { return 0.; } - // Electron mistagging as muon + /// Electron mistagging as muon (a as mu) virtual MAfloat32 photon_mistag_muon(const RecPhotonFormat photon) const { return 0.; } + + /// Electron mistagging as light jet (a as j) + virtual MAfloat32 photon_mistag_lightjet(const RecPhotonFormat photon) const { return 0.; } }; } diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h index 3e9f678d..40270b93 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h @@ -93,6 +93,7 @@ namespace MA5 MAuint16 ntracks_; /// number of tracks MAbool btag_; /// b-tag MAbool ctag_; /// c-tag + MAbool tautag_; /// tau-tag MAbool true_ctag_; /// c-tag (before id or misid) MAbool true_btag_; /// b-tag (before id or misid) std::vector Constituents_; /// indices of the MC particles @@ -150,9 +151,11 @@ namespace MA5 ntracks_ = 0; btag_ = false; ctag_ = false; + tautag_ = false; true_btag_ = false; true_ctag_ = false; isolCones_.clear(); + Constituents_.clear(); } /// Accessor to the number of tracks @@ -183,14 +186,22 @@ namespace MA5 void setBtag(const MAbool& tag) {btag_=tag;} - /// Setting a new true_ctag_ value + /// Setting a new ctag_ value void setCtag(const MAbool& tag) {ctag_=tag;} - /// Setting a new ctag_ value + /// Setting a new true_ctag_ value void setTrueCtag(const MAbool& tag) {true_ctag_=tag;} + /// Accessor to the tautag + const MAbool& tautag() const + { return tautag_; } + + /// Setting a new tautag_ value + void setTautag(const MAbool& tag) + {tautag_=tag;} + /// Setting ntracks void setNtracks(MAuint16 ntracks) { ntracks_=ntracks; } From b20caa9fabc1d45b5cc9ab5473d03b0bd09dbbab Mon Sep 17 00:00:00 2001 From: jackaraz Date: Wed, 8 Jun 2022 23:56:46 +0100 Subject: [PATCH 10/67] improve docstring --- .../Commons/Base/SFSTaggerBase.cpp | 2 +- .../Commons/Base/SFSTaggerBase.h | 54 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index 2e1c6dad..2b4d487a 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -165,7 +165,7 @@ namespace MA5 { if (_isTauTaggingEffOn) { - /// In Jet based tau tagging this loop will not run + /// @attention In Jet based tau tagging this loop will not run for (MAuint32 itau = 0; itau < Ntau; itau++) { if (RANDOM->flat() > tau_tagging_eff(myEvent.rec()->taus()[itau])) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index e93a0846..18bf316c 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -26,22 +26,24 @@ // SampleAnalyser headers #include "SampleAnalyzer/Commons/DataFormat/EventFormat.h" -#include "SampleAnalyzer/Commons/DataFormat/RecJetFormat.h" -#include "SampleAnalyzer/Commons/DataFormat/RecTauFormat.h" -#include "SampleAnalyzer/Commons/DataFormat/RecPhotonFormat.h" namespace MA5 { struct SFSTaggerBaseOptions { /// @brief Tagging options /// - /// @code btag_matching_deltaR @endcode + /// @code btag_matching_deltaR : double @endcode /// matching deltaR is the threshold for maximum dR distance between a jet and B-hadron - /// @code btag_exclusive @endcode + /// @code btag_exclusive : bool @endcode /// exclusive algorithm is designed to dynamically find the jet that best matches to the B-hadron /// /// options starting with ctag and tautag are the ones corresponding to c-jet and tau-jet tagging - /// taujtag_jetbased can be either hadron based or jet based. + /// + /// @code taujtag_jetbased : bool@endcode + /// States the nature of tau tagging proecedure. If false, the hadronic tau in the event history + /// will be found and used as hadronic tau object. if True, this hadronic tau will be matched with + /// a jet and the jet will be considered as tau jet. + /// /// @warning DR matching for tau tagging is only available on jet based method MAfloat32 btag_matching_deltaR = 0.3; MAbool btag_exclusive = true; @@ -119,46 +121,46 @@ namespace MA5 { ///===============// /// B-jet tagging efficiency (b as b) - virtual MAfloat32 b_tagging_eff(const RecJetFormat jet) const { return 1.; } + virtual MAfloat32 b_tagging_eff(const RecJetFormat &jet) const { return 1.; } /// B-jet mistagging as C-jet (b as c) - virtual MAfloat32 b_mistag_c(const RecJetFormat jet) const { return 0.; } + virtual MAfloat32 b_mistag_c(const RecJetFormat &jet) const { return 0.; } //===============// // C-Tagging // //===============// /// C-jet tagging efficiency (c as c) - virtual MAfloat32 c_tagging_eff(const RecJetFormat jet) const { return 1.; } + virtual MAfloat32 c_tagging_eff(const RecJetFormat &jet) const { return 1.; } /// C-jet mistagging as C-jet (c as b) - virtual MAfloat32 c_mistag_b(const RecJetFormat jet) const { return 0.; } + virtual MAfloat32 c_mistag_b(const RecJetFormat &jet) const { return 0.; } //=======================// // Light-Jet Tagging // //=======================// /// Light-Jet mistagging as b-jet (j as b) - virtual MAfloat32 lightjet_mistag_b(const RecJetFormat jet) const { return 0.; } + virtual MAfloat32 lightjet_mistag_b(const RecJetFormat &jet) const { return 0.; } /// Light-Jet mistagging as c jet (j as c) - virtual MAfloat32 lightjet_mistag_c(const RecJetFormat jet) const { return 0.; } + virtual MAfloat32 lightjet_mistag_c(const RecJetFormat &jet) const { return 0.; } /// Light-Jet mistagging as tau (j as ta) - virtual MAfloat32 lightjet_mistag_tau(const RecJetFormat jet) const { return 0.; } + virtual MAfloat32 lightjet_mistag_tau(const RecJetFormat &jet) const { return 0.; } /// Light-Jet mistagging as electron (j as e) - virtual MAfloat32 lightjet_mistag_electron(const RecJetFormat jet) const { return 0.; } + virtual MAfloat32 lightjet_mistag_electron(const RecJetFormat &jet) const { return 0.; } /// Light-Jet mistagging as photon (j as photon) - virtual MAfloat32 lightjet_mistag_photon(const RecJetFormat jet) const { return 0.; } + virtual MAfloat32 lightjet_mistag_photon(const RecJetFormat &jet) const { return 0.; } //=================// // Tau Tagging // //=================// /// Convert jet to tau - MAfloat32 tau_tagging_eff(const RecJetFormat jet) const + MAfloat32 tau_tagging_eff(const RecJetFormat &jet) const { RecTauFormat myTau; myTau.setMomentum(jet.momentum()); @@ -169,46 +171,46 @@ namespace MA5 { } /// Tau tagging efficiency (ta as ta) - virtual MAfloat32 tau_tagging_eff(const RecTauFormat tau) const { return 1.; } + virtual MAfloat32 tau_tagging_eff(const RecTauFormat &tau) const { return 1.; } //=======================// // Electron Tagging // //======================// /// Electron mistagging as muon (e as mu) - virtual MAfloat32 electron_mistag_muon(const RecLeptonFormat electron) const { return 0.; } + virtual MAfloat32 electron_mistag_muon(const RecLeptonFormat &electron) const { return 0.; } /// Electron mistagging as photon (e as a) - virtual MAfloat32 electron_mistag_photon(const RecLeptonFormat electron) const { return 0.; } + virtual MAfloat32 electron_mistag_photon(const RecLeptonFormat &electron) const { return 0.; } /// Electron mistagging as light jet (e as j) - virtual MAfloat32 electron_mistag_lightjet(const RecLeptonFormat electron) const { return 0.; } + virtual MAfloat32 electron_mistag_lightjet(const RecLeptonFormat &electron) const { return 0.; } //==================// // Muon Tagging // //==================// /// Electron mistagging as electron (mu as e) - virtual MAfloat32 muon_mistag_electron(const RecLeptonFormat muon) const { return 0.; } + virtual MAfloat32 muon_mistag_electron(const RecLeptonFormat &muon) const { return 0.; } /// Electron mistagging as photon (mu as a) - virtual MAfloat32 muon_mistag_photon(const RecLeptonFormat muon) const { return 0.; } + virtual MAfloat32 muon_mistag_photon(const RecLeptonFormat &muon) const { return 0.; } /// Electron mistagging as light jet (mu as j) - virtual MAfloat32 muon_mistag_lightjet(const RecLeptonFormat muon) const { return 0.; } + virtual MAfloat32 muon_mistag_lightjet(const RecLeptonFormat &muon) const { return 0.; } //====================// // Photon Tagging // //====================// /// Electron mistagging as electron (a as e) - virtual MAfloat32 photon_mistag_electron(const RecPhotonFormat photon) const { return 0.; } + virtual MAfloat32 photon_mistag_electron(const RecPhotonFormat &photon) const { return 0.; } /// Electron mistagging as muon (a as mu) - virtual MAfloat32 photon_mistag_muon(const RecPhotonFormat photon) const { return 0.; } + virtual MAfloat32 photon_mistag_muon(const RecPhotonFormat &photon) const { return 0.; } /// Electron mistagging as light jet (a as j) - virtual MAfloat32 photon_mistag_lightjet(const RecPhotonFormat photon) const { return 0.; } + virtual MAfloat32 photon_mistag_lightjet(const RecPhotonFormat &photon) const { return 0.; } }; } From b8ac3021311384a142a2eeb34c816b7538e8e9d7 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 09:29:40 +0100 Subject: [PATCH 11/67] complete tagger module --- .../Commons/Base/SFSTaggerBase.cpp | 115 ++++++++++++++++-- .../Commons/Base/SFSTaggerBase.h | 2 +- 2 files changed, 107 insertions(+), 10 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index 2b4d487a..f401542f 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -65,6 +65,7 @@ namespace MA5 { /// @attention This is for consistency. Tau tag is created for this application only. jet.setTautag(false); } + /// Do not continue if tagger is not on (for code efficiency) if (!_isJetTaggingOn) continue; /// We have a true b-jet: is it b-tagged? @@ -75,7 +76,9 @@ namespace MA5 { /// We have a true c-jet: is it b-tagged? else if (jet.true_ctag()) { - if (RANDOM->flat() < c_mistag_b(jet)) jet.setBtag(true); + if (RANDOM->flat() < c_mistag_b(jet)) { + jet.setBtag(true); jet.setCtag(false); + } } /// We have a true light-jet: is it b-tagged? else @@ -89,7 +92,9 @@ namespace MA5 { /// We have a true b-jet: is it c-tagged? if (jet.true_btag()) { - if (RANDOM->flat() < b_mistag_c(jet)) { jet.setCtag(true); jet.setBtag(false); } + if (RANDOM->flat() < b_mistag_c(jet)) { + jet.setCtag(true); jet.setBtag(false); + } } /// We have a true c-jet: is it c-tagged? else if (jet.true_ctag()) @@ -110,7 +115,8 @@ namespace MA5 { /// if not, is it mis-tagged as anything? else { - { /// Scope for light jet mistagging as tau + /// Scope for light jet mistagging as tau + { /// if not, is it Tau-tagged? if (RANDOM->flat() < lightjet_mistag_tau(jet)) { RecTauFormat *newTau = myEvent.rec()->GetNewTau(); @@ -119,7 +125,8 @@ namespace MA5 { continue; } } - { /// Scope for light jet mistagging for electron + /// Scope for light jet mistagging for electron + { /// if not, is it Electron-tagged? if (RANDOM->flat() < lightjet_mistag_electron(jet)) { @@ -137,7 +144,8 @@ namespace MA5 { toRemove.push_back(ijet); } } - { /// Scope for light jet mistagging for photon + /// Scope for light jet mistagging for photon + { /// if not, is it Photon-tagged? if (RANDOM->flat() < lightjet_mistag_photon(jet)) { @@ -165,7 +173,7 @@ namespace MA5 { if (_isTauTaggingEffOn) { - /// @attention In Jet based tau tagging this loop will not run + /// @attention In Jet based tau tagging this loop will not run. If its runnning thats a bug for (MAuint32 itau = 0; itau < Ntau; itau++) { if (RANDOM->flat() > tau_tagging_eff(myEvent.rec()->taus()[itau])) @@ -211,7 +219,7 @@ namespace MA5 { continue; } /// Muon mistagging as light jet - /// @attention this will cause problems if executed in substructure tools + /// @warning this will cause problems if executed in substructure tools if (RANDOM->flat() < muon_mistag_lightjet(muon)) { RecJetFormat* NewParticle = myEvent.rec()->GetNewJet(); @@ -237,14 +245,103 @@ namespace MA5 { /// Electron mistagging if (_isElectronTaggingOn) { - /// @todo complete this section + MAuint32 ielec = -1; + for (auto &electron: myEvent.rec()->electrons()) + { + ielec++; + /// Electron mistagging as muon + if (RANDOM->flat() < electron_mistag_muon(electron)) + { + RecLeptonFormat* NewParticle = myEvent.rec()->GetNewMuon(); + NewParticle->setMomentum(electron.momentum()); + NewParticle->setMc(electron.mc()); + NewParticle->SetCharge(electron.charge()); + toRemove.push_back(ielec); + continue; + } + /// Electron mistagging as photon + if (RANDOM->flat() < electron_mistag_photon(electron)) + { + RecPhotonFormat* NewParticle = myEvent.rec()->GetNewPhoton(); + NewParticle->setMomentum(electron.momentum()); + NewParticle->setMc(electron.mc()); + toRemove.push_back(ielec); + continue; + } + /// Electron mistagging as jet + /// @warning This will cause problems during execution with substructure module + if (RANDOM->flat() < electron_mistag_lightjet(electron)) + { + RecJetFormat* NewParticle = myEvent.rec()->GetNewJet(); + NewParticle->setMomentum(electron.momentum()); + NewParticle->setMc(electron.mc()); + NewParticle->setNtracks(1); + THT += electron.pt(); + Meff += electron.pt(); + MALorentzVector MissHT = myEvent.rec()->MHT().momentum() - electron.momentum(); + (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( + MissHT.Px(), MissHT.Py(), 0., MissHT.E() + ); + toRemove.push_back(ielec); + continue; + } + } + /// Remove mistagged electrons + for (MAuint32 i=toRemove.size();i>0;i--) + myEvent.rec()->electrons().erase(myEvent.rec()->electrons().begin() + toRemove[i-1]); + toRemove.clear(); } /// Photon mistaging if (_isPhotonTaggingOn) { - /// @todo complete this section + MAuint32 iph = -1; + for (auto &photon: myEvent.rec()->photons()) + { + iph++; + /// Photon mistagging as electron + if (RANDOM->flat() < photon_mistag_electron(photon)) + { + RecLeptonFormat* NewParticle = myEvent.rec()->GetNewElectron(); + NewParticle->setMomentum(photon.momentum()); + NewParticle->setMc(photon.mc()); + NewParticle->SetCharge(RANDOM->flat() > 0.5 ? 1. : -1.); + toRemove.push_back(iph); + continue; + } + /// Photon mistagging as muon + if (RANDOM->flat() < photon_mistag_muon(photon)) + { + RecLeptonFormat* NewParticle = myEvent.rec()->GetNewMuon(); + NewParticle->setMomentum(photon.momentum()); + NewParticle->setMc(photon.mc()); + NewParticle->SetCharge(RANDOM->flat() > 0.5 ? 1. : -1.); + toRemove.push_back(iph); + continue; + } + /// Photon mistagging as jet + /// @warning This will cause problems during execution with substructure module + if (RANDOM->flat() < photon_mistag_lightjet(photon)) + { + RecJetFormat* NewParticle = myEvent.rec()->GetNewJet(); + NewParticle->setMomentum(photon.momentum()); + NewParticle->setMc(photon.mc()); + NewParticle->setNtracks(1); + THT += photon.pt(); + Meff += photon.pt(); + MALorentzVector MissHT = myEvent.rec()->MHT().momentum() - photon.momentum(); + (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( + MissHT.Px(), MissHT.Py(), 0., MissHT.E() + ); + toRemove.push_back(iph); + continue; + } + } + /// Remove mistagged photons + for (MAuint32 i=toRemove.size();i>0;i--) + myEvent.rec()->photons().erase(myEvent.rec()->photons().begin() + toRemove[i-1]); + toRemove.clear(); } } diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index 18bf316c..a65f15fe 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -50,7 +50,7 @@ namespace MA5 { MAfloat32 ctag_matching_deltaR = 0.3; MAbool ctag_exclusive = true; MAfloat32 tautag_matching_deltaR = 0.3; - MAbool tautag_exclusive = true; /// not used at the moment. + MAbool tautag_exclusive = true; MAbool tautag_jetbased = false; }; From 50f1abf33fe8cea55e433bdc71ea2798551f5322 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 09:39:39 +0100 Subject: [PATCH 12/67] add tagger loader --- .../Process/JetClustering/JetClusterer.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index acbf1ebd..b72068a3 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -35,6 +35,7 @@ #include "SampleAnalyzer/Process/JetClustering/TauTagger.h" #include "SampleAnalyzer/Process/JetClustering/NullSmearer.h" #include "SampleAnalyzer/Commons/Base/SmearerBase.h" +#include "SampleAnalyzer/Commons/Base/SFSTaggerBase.h" #ifdef MA5_FASTJET_MODE #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoStandard.h" @@ -66,6 +67,9 @@ namespace MA5 cTagger* myCtagger_; TauTagger* myTautagger_; SmearerBase* mySmearer_; + SFSTaggerBase* myTagger_; + + SFSTaggerBaseOptions* myTaggerOptions_; /// Exclusive id for tau-elec-photon-jet MAbool ExclusiveId_; @@ -152,6 +156,14 @@ namespace MA5 mySmearer_->Initialize(); } + /// Generic Loader for tagger module + void LoadTagger(SFSTaggerBase* tagger) + { + myTagger_ = tagger; + myTagger_->Initialize(); + myTagger_->SetOptions(*myTaggerOptions_); + } + // Load additional Jets MAbool LoadJetConfiguration(std::map options); From bf3923a1dabba1301ca2c78135fecf290b775503 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 11:39:52 +0100 Subject: [PATCH 13/67] adapt python interface --- .../configuration/beauty_identification.py | 151 +++++++++--------- .../configuration/charm_identification.py | 99 ++++++++++++ .../configuration/tau_identification.py | 26 ++- 3 files changed, 193 insertions(+), 83 deletions(-) create mode 100644 madanalysis/configuration/charm_identification.py diff --git a/madanalysis/configuration/beauty_identification.py b/madanalysis/configuration/beauty_identification.py index 74271334..ae7f44d1 100644 --- a/madanalysis/configuration/beauty_identification.py +++ b/madanalysis/configuration/beauty_identification.py @@ -1,143 +1,138 @@ ################################################################################ -# +# # Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks # The MadAnalysis development team, email: -# +# # This file is part of MadAnalysis 5. # Official website: -# +# # MadAnalysis 5 is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # MadAnalysis 5 is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with MadAnalysis 5. If not, see -# +# ################################################################################ from __future__ import absolute_import import logging -class BeautyIdentification(): + + +class BeautyIdentification: default_matching_dr = 0.5 - default_exclusive = True - default_efficiency = 1. - default_misid_cjet = 0. - default_misid_ljet = 0. - + default_exclusive = True + default_efficiency = 1.0 + default_misid_cjet = 0.0 + default_misid_ljet = 0.0 userVariables = { - "bjet_id.matching_dr" : [str(default_matching_dr)], - "bjet_id.exclusive" : [str(default_exclusive)], + "bjet_id.matching_dr": [str(default_matching_dr)], + "bjet_id.exclusive": [str(default_exclusive)], } def __init__(self): self.matching_dr = BeautyIdentification.default_matching_dr - self.exclusive = BeautyIdentification.default_exclusive - self.efficiency = BeautyIdentification.default_efficiency - self.misid_cjet = BeautyIdentification.default_misid_cjet - self.misid_ljet = BeautyIdentification.default_misid_ljet + self.exclusive = BeautyIdentification.default_exclusive + self.efficiency = BeautyIdentification.default_efficiency + self.misid_cjet = BeautyIdentification.default_misid_cjet + self.misid_ljet = BeautyIdentification.default_misid_ljet - def Display(self): - logging.getLogger('MA5').info(" + b-jet identification:") + logging.getLogger("MA5").info(" + b-jet identification:") self.user_DisplayParameter("bjet_id.matching_dr") self.user_DisplayParameter("bjet_id.exclusive") - - def user_DisplayParameter(self,parameter): - if parameter=="bjet_id.matching_dr": - logging.getLogger('MA5').info(" + DeltaR matching = "+str(self.matching_dr)) - elif parameter=="bjet_id.exclusive": - msg="false" - if self.exclusive: - msg="true" - logging.getLogger('MA5').info(" + exclusive algo = "+msg) - elif parameter=="bjet_id.efficiency": - logging.getLogger('MA5').info(" + id efficiency = "+str(self.efficiency)) - elif parameter=="bjet_id.misid_cjet": - logging.getLogger('MA5').info(" + mis-id efficiency (c-quark) = "+str(self.misid_cjet)) - elif parameter=="bjet_id.misid_ljet": - logging.getLogger('MA5').info(" + mis-id efficiency (light quarks) = "+str(self.misid_ljet)) + def user_DisplayParameter(self, parameter): + if parameter == "bjet_id.matching_dr": + logging.getLogger("MA5").info(" + DeltaR matching = " + str(self.matching_dr)) + elif parameter == "bjet_id.exclusive": + logging.getLogger("MA5").info( + f" + exclusive algo = {'true' if self.exclusive else 'false'}" + ) else: - logging.getLogger('MA5').error("'clustering' has no parameter called '"+parameter+"'") - + logging.getLogger("MA5").error( + "'clustering' has no parameter called '" + parameter + "'" + ) def SampleAnalyzerConfigString(self): - mydict = {} - mydict['bjet_id.matching_dr'] = str(self.matching_dr) - mydict['bjet_id.efficiency'] = str(self.efficiency) - if self.exclusive: - mydict['bjet_id.exclusive'] = '1' - else: - mydict['bjet_id.exclusive'] = '0' - mydict['bjet_id.misid_cjet'] = str(self.misid_cjet) - mydict['bjet_id.misid_ljet'] = str(self.misid_ljet) - return mydict + return { + "bjet_id.matching_dr": str(self.matching_dr), + "bjet_id.exclusive": "1" if self.exclusive else "0", + } - - def user_GetValues(self,variable): + def user_GetValues(self, variable): try: return BeautyIdentification.userVariables[variable] except: return [] - def user_GetParameters(self): return list(BeautyIdentification.userVariables.keys()) - - def user_SetParameter(self,parameter,value): + def user_SetParameter(self, parameter, value): # matching deltar - if parameter=="bjet_id.matching_dr": + if parameter == "bjet_id.matching_dr": try: number = float(value) - except: - logging.getLogger('MA5').error("the 'matching deltaR' must be a float value.") + except Exception as err: + logging.getLogger("MA5").error("the 'matching deltaR' must be a float value.") return False - if number<=0: - logging.getLogger('MA5').error("the 'matching deltaR' cannot be negative or null.") + if number <= 0: + logging.getLogger("MA5").error("the 'matching deltaR' cannot be negative or null.") return False - self.matching_dr=number + self.matching_dr = number # exclusive - elif parameter=="bjet_id.exclusive": - if value == "true": - self.exclusive=True - elif value == "false": - self.exclusive=False - else: - logging.getLogger('MA5').error("'exclusive' possible values are : 'true', 'false'") + elif parameter == "bjet_id.exclusive": + if value not in ["true", "false"]: + logging.getLogger("MA5").error("'exclusive' possible values are : 'true', 'false'") return False + self.exclusive = value == "true" # efficiency elif parameter == "bjet_id.efficiency": - logging.getLogger('MA5').error("This function has been deprecated, please use SFS functionality instead.") - logging.getLogger('MA5').error("Same functionality can be captured via following command in SFS:") - logging.getLogger('MA5').error(f" -> define tagger b as b {value}") + logging.getLogger("MA5").error( + "This function has been deprecated, please use SFS functionality instead." + ) + logging.getLogger("MA5").error( + "Same functionality can be captured via following command in SFS:" + ) + logging.getLogger("MA5").error(f" -> define tagger b as b {value}") return False # mis efficiency (cjet) - elif parameter=="bjet_id.misid_cjet": - logging.getLogger('MA5').error("This function has been deprecated, please use SFS functionality instead.") - logging.getLogger('MA5').error("Same functionality can be captured via following command in SFS:") - logging.getLogger('MA5').error(f" -> define tagger b as c {value}") + elif parameter == "bjet_id.misid_cjet": + logging.getLogger("MA5").error( + "This function has been deprecated, please use SFS functionality instead." + ) + logging.getLogger("MA5").error( + "Same functionality can be captured via following command in SFS:" + ) + logging.getLogger("MA5").error(f" -> define tagger b as c {value}") return False # mis efficiency (ljet) - elif parameter=="bjet_id.misid_ljet": - logging.getLogger('MA5').error("This function has been deprecated, please use SFS functionality instead.") - logging.getLogger('MA5').error("Same functionality can be captured via following command in SFS:") - logging.getLogger('MA5').error(f" -> define tagger b as j {value}") + elif parameter == "bjet_id.misid_ljet": + logging.getLogger("MA5").error( + "This function has been deprecated, please use SFS functionality instead." + ) + logging.getLogger("MA5").error( + "Same functionality can be captured via following command in SFS:" + ) + logging.getLogger("MA5").error(f" -> define tagger b as j {value}") return False - # other + # other else: - logging.getLogger('MA5').error("'clustering' has no parameter called '"+parameter+"'") + logging.getLogger("MA5").error( + "'clustering' has no parameter called '" + parameter + "'" + ) diff --git a/madanalysis/configuration/charm_identification.py b/madanalysis/configuration/charm_identification.py new file mode 100644 index 00000000..a03862f0 --- /dev/null +++ b/madanalysis/configuration/charm_identification.py @@ -0,0 +1,99 @@ +################################################################################ +# +# Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks +# The MadAnalysis development team, email: +# +# This file is part of MadAnalysis 5. +# Official website: +# +# MadAnalysis 5 is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# MadAnalysis 5 is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with MadAnalysis 5. If not, see +# +################################################################################ + + +from __future__ import absolute_import +import logging + + +class CharmIdentification: + + default_matching_dr = 0.5 + default_exclusive = True + + userVariables = { + "cjet_id.matching_dr": [str(default_matching_dr)], + "cjet_id.exclusive": [str(default_exclusive)], + } + + def __init__(self): + self.matching_dr = CharmIdentification.default_matching_dr + self.exclusive = CharmIdentification.default_exclusive + + def Display(self): + logging.getLogger("MA5").info(" + b-jet identification:") + self.user_DisplayParameter("cjet_id.matching_dr") + self.user_DisplayParameter("cjet_id.exclusive") + + def user_DisplayParameter(self, parameter): + if parameter == "cjet_id.matching_dr": + logging.getLogger("MA5").info(" + DeltaR matching = " + str(self.matching_dr)) + elif parameter == "cjet_id.exclusive": + logging.getLogger("MA5").info( + f" + exclusive algo = {'true' if self.exclusive else 'false'}" + ) + else: + logging.getLogger("MA5").error( + "'clustering' has no parameter called '" + parameter + "'" + ) + + def SampleAnalyzerConfigString(self): + return { + "cjet_id.matching_dr": str(self.matching_dr), + "cjet_id.exclusive": "1" if self.exclusive else "0", + } + + def user_GetValues(self, variable): + try: + return CharmIdentification.userVariables[variable] + except: + return [] + + def user_GetParameters(self): + return list(CharmIdentification.userVariables.keys()) + + def user_SetParameter(self, parameter, value): + # matching deltar + if parameter == "cjet_id.matching_dr": + try: + number = float(value) + except Exception as err: + logging.getLogger("MA5").error("the 'matching deltaR' must be a float value.") + return False + if number <= 0: + logging.getLogger("MA5").error("the 'matching deltaR' cannot be negative or null.") + return False + self.matching_dr = number + + # exclusive + elif parameter == "cjet_id.exclusive": + if value not in ["true", "false"]: + logging.getLogger("MA5").error("'exclusive' possible values are : 'true', 'false'") + return False + self.exclusive = value == "true" + + # other + else: + logging.getLogger("MA5").error( + "'clustering' has no parameter called '" + parameter + "'" + ) diff --git a/madanalysis/configuration/tau_identification.py b/madanalysis/configuration/tau_identification.py index 15b9bd1d..8822a99f 100644 --- a/madanalysis/configuration/tau_identification.py +++ b/madanalysis/configuration/tau_identification.py @@ -28,8 +28,8 @@ class TauIdentification: - default_matching_dr = 0.5 - default_exclusive = True + default_matching_dr = 0.3 + default_exclusive = False default_efficiency = 1.0 default_misid_ljet = 0.0 default_reconstruction_method = "hadron-based" @@ -44,6 +44,7 @@ def __init__(self): self.misid_ljet = TauIdentification.default_misid_ljet self.matching_dr = TauIdentification.default_matching_dr self.reconstruction_method = TauIdentification.default_reconstruction_method + self.exclusive = TauIdentification.default_exclusive def Display(self): logging.getLogger("MA5").info(" + hadronic-tau identification:") @@ -64,10 +65,9 @@ def user_DisplayParameter(self, parameter): def SampleAnalyzerConfigString(self): return { - "tau_id.efficiency": str(self.efficiency), - "tau_id.misid_ljet": str(self.misid_ljet), "tau_id.matching_dr": str(self.matching_dr), - "tau_id.reconstruction_method": self.reconstruction_method, + "tau_id.reconstruction_method": "1" if self.reconstruction_method == "jet-based" else "0", + "tau_id.exclusive" : "1" if self.exclusive else "0", } def user_GetValues(self, variable): @@ -90,8 +90,24 @@ def user_SetParameter(self, parameter, value): if number <= 0: logging.getLogger("MA5").error("the 'matching deltaR' cannot be negative or null.") return False + if self.reconstruction_method == "hadron-based": + logging.getLogger("MA5").warning("Hadronic tau matching is only available in jet-based tagging mode.") + logging.getLogger("MA5").warning("To activate jet-based tagging type " + "`set main.fastsim.tau_id.reconstruction_method = jet-based`") self.matching_dr = number + # Exclusive algorithm + elif parameter == "tau_id.exclusive": + if value not in ["true", "false"]: + logging.getLogger('MA5').error("'exclusive' possible values are : 'true', 'false'") + return False + if self.reconstruction_method == "hadron-based": + logging.getLogger("MA5").warning("Exclusive Hadronic tau matching is only available " + "in jet-based tagging mode.") + logging.getLogger("MA5").warning("To activate jet-based tagging type " + "`set main.fastsim.tau_id.reconstruction_method = jet-based`") + self.exclusive = (value == "true") + # reconstruction method if parameter == "tau_id.reconstruction_method": if value in TauIdentification.userVariables["tau_id.reconstruction_method"]: From f46457b9ce2c46234c4f68260e5adb7df73e9be9 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 11:40:06 +0100 Subject: [PATCH 14/67] adap user-interface --- .../configuration/clustering_configuration.py | 296 ++++++++++-------- 1 file changed, 165 insertions(+), 131 deletions(-) diff --git a/madanalysis/configuration/clustering_configuration.py b/madanalysis/configuration/clustering_configuration.py index 57361eda..a8946311 100644 --- a/madanalysis/configuration/clustering_configuration.py +++ b/madanalysis/configuration/clustering_configuration.py @@ -1,254 +1,288 @@ ################################################################################ -# +# # Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks # The MadAnalysis development team, email: -# +# # This file is part of MadAnalysis 5. # Official website: -# +# # MadAnalysis 5 is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # MadAnalysis 5 is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with MadAnalysis 5. If not, see -# +# ################################################################################ from __future__ import absolute_import -from madanalysis.configuration.clustering_kt import ClusteringKt -from madanalysis.configuration.clustering_antikt import ClusteringAntiKt -from madanalysis.configuration.clustering_genkt import ClusteringGenKt -from madanalysis.configuration.clustering_cambridge import ClusteringCambridge -from madanalysis.configuration.clustering_gridjet import ClusteringGridJet +from madanalysis.configuration.clustering_kt import ClusteringKt +from madanalysis.configuration.clustering_antikt import ClusteringAntiKt +from madanalysis.configuration.clustering_genkt import ClusteringGenKt +from madanalysis.configuration.clustering_cambridge import ClusteringCambridge +from madanalysis.configuration.clustering_gridjet import ClusteringGridJet from madanalysis.configuration.clustering_cdfmidpoint import ClusteringCDFMidPoint -from madanalysis.configuration.clustering_cdfjetclu import ClusteringCDFJetClu -from madanalysis.configuration.clustering_siscone import ClusteringSisCone -from madanalysis.configuration.beauty_identification import BeautyIdentification -from madanalysis.configuration.tau_identification import TauIdentification -from madanalysis.enumeration.ma5_running_type import MA5RunningType +from madanalysis.configuration.clustering_cdfjetclu import ClusteringCDFJetClu +from madanalysis.configuration.clustering_siscone import ClusteringSisCone +from madanalysis.configuration.beauty_identification import BeautyIdentification +from madanalysis.configuration.charm_identification import CharmIdentification +from madanalysis.configuration.tau_identification import TauIdentification +from madanalysis.enumeration.ma5_running_type import MA5RunningType import logging + class ClusteringConfiguration: - userVariables = { "algorithm" : ["kt","antikt","genkt",\ - "cambridge","gridjet",\ - "siscone",\ - "cdfjetclu", "cdfmidpoint",\ - "none"], - "exclusive_id" : ["true","false"], - "jetrecomode" : ["jets","constituents"], - "magnetic_field" : ["3.8"], - # "tracker_radius" : ["1.29"], @JACK these are not available atm - # "half_length" : ["3.0"], - "particle_propagator" : ["on","off"], - "JetID" : ["Ma5Jet"], - "track_isocone_radius" : ["0.5"], - "electron_isocone_radius" : ["0.5"], - "muon_isocone_radius" : ["0.5"], - "photon_isocone_radius" : ["0.5"], - } + userVariables = { + "algorithm": [ + "kt", + "antikt", + "genkt", + "cambridge", + "gridjet", + "siscone", + "cdfjetclu", + "cdfmidpoint", + "none", + ], + "exclusive_id": ["true", "false"], + "jetrecomode": ["jets", "constituents"], + "magnetic_field": ["3.8"], + # "tracker_radius" : ["1.29"], @JACK these are not available atm + # "half_length" : ["3.0"], + "particle_propagator": ["on", "off"], + "JetID": ["Ma5Jet"], + "track_isocone_radius": ["0.5"], + "electron_isocone_radius": ["0.5"], + "muon_isocone_radius": ["0.5"], + "photon_isocone_radius": ["0.5"], + } def __init__(self): - self.algorithm = "antikt" - self.clustering = ClusteringAntiKt() - self.beauty = BeautyIdentification() - self.tau = TauIdentification() + self.algorithm = "antikt" + self.clustering = ClusteringAntiKt() + self.beauty = BeautyIdentification() + self.charm = CharmIdentification() + self.tau = TauIdentification() self.exclusive_id = True - self.JetID = "Ma5Jet" + self.JetID = "Ma5Jet" - def Display(self): self.user_DisplayParameter("algorithm") - if self.algorithm!="none": - logging.getLogger('MA5').info(' + Jet ID : '+self.JetID) + if self.algorithm != "none": + logging.getLogger("MA5").info(" + Jet ID : " + self.JetID) self.clustering.Display() self.user_DisplayParameter("exclusive_id") self.beauty.Display() + self.charm.Display() self.tau.Display() - - def user_DisplayParameter(self,parameter): - if parameter=="algorithm": - logging.getLogger('MA5').info(" clustering algorithm : "+self.algorithm) + def user_DisplayParameter(self, parameter): + if parameter == "algorithm": + logging.getLogger("MA5").info(" clustering algorithm : " + self.algorithm) return - if self.algorithm!="none": - if parameter=="exclusive_id": - word="" + if self.algorithm != "none": + if parameter == "exclusive_id": + word = "" if self.exclusive_id: - word="true" + word = "true" else: - word="false" - logging.getLogger('MA5').info(" + exclusive identification = "+word) - elif parameter.startswith('bjet_id.'): + word = "false" + logging.getLogger("MA5").info(" + exclusive identification = " + word) + elif parameter.startswith("bjet_id."): self.beauty.user_DisplayParameter(parameter) - elif parameter.startswith('tau_id.'): + elif parameter.startswith("cjet_id."): + self.charm.user_DisplayParameter(parameter) + elif parameter.startswith("tau_id."): self.tau.user_DisplayParameter(parameter) else: self.clustering.user_DisplayParameter(parameter) - def SampleAnalyzerConfigString(self): - if self.algorithm!="none": + if self.algorithm != "none": mydict = {} - mydict['JetID'] = self.JetID + mydict["JetID"] = self.JetID if self.exclusive_id: - mydict['exclusive_id'] = '1' + mydict["exclusive_id"] = "1" else: - mydict['exclusive_id'] = '0' + mydict["exclusive_id"] = "0" mydict.update(self.clustering.SampleAnalyzerConfigString()) mydict.update(self.beauty.SampleAnalyzerConfigString()) + mydict.update(self.charm.SampleAnalyzerConfigString()) mydict.update(self.tau.SampleAnalyzerConfigString()) return mydict else: return {} + def user_SetParameter(self, parameter, value, datasets, level): - def user_SetParameter(self,parameter,value,datasets,level): - # algorithm - if parameter=="algorithm": + if parameter == "algorithm": # Switch off the clustering - if value=="none": - test=True + if value == "none": + test = True for dataset in datasets: if not test: break for file in dataset.filenames: - if file.endswith('lhe') or \ - file.endswith('lhe.gz') or \ - file.endswith('hep') or \ - file.endswith('hep.gz') or \ - file.endswith('hepmc') or \ - file.endswith('hepmc.gz'): - test=False + if ( + file.endswith("lhe") + or file.endswith("lhe.gz") + or file.endswith("hep") + or file.endswith("hep.gz") + or file.endswith("hepmc") + or file.endswith("hepmc.gz") + ): + test = False break if not test: - logging.getLogger('MA5').error("some datasets contain partonic/hadronic file format. Clustering algorithm cannot be switched off.") + logging.getLogger("MA5").error( + "some datasets contain partonic/hadronic file format. Clustering algorithm cannot be switched off." + ) return # Switch on the clustering - elif value in ["kt","antikt","cambridge","genkt",\ - "gridjet","cdfmidpoint","cdfjetclu",\ - "siscone"]: + elif value in [ + "kt", + "antikt", + "cambridge", + "genkt", + "gridjet", + "cdfmidpoint", + "cdfjetclu", + "siscone", + ]: # Only in reco mode - if level!=MA5RunningType.RECO: - logging.getLogger('MA5').error("clustering algorithm is only available in RECO mode") + if level != MA5RunningType.RECO: + logging.getLogger("MA5").error( + "clustering algorithm is only available in RECO mode" + ) return - - test=True + + test = True for dataset in datasets: if not test: break for file in dataset.filenames: - if file.endswith('lhco') or \ - file.endswith('lhco.gz') or \ - file.endswith('root'): - test=False + if ( + file.endswith("lhco") + or file.endswith("lhco.gz") + or file.endswith("root") + ): + test = False break if not test: - logging.getLogger('MA5').error("some datasets contain reconstructed file format. Clustering algorithm cannot be switched on.") + logging.getLogger("MA5").error( + "some datasets contain reconstructed file format. Clustering algorithm cannot be switched on." + ) return - - if value=="kt": - self.algorithm="kt" + + if value == "kt": + self.algorithm = "kt" self.clustering = ClusteringKt() - elif value=="antikt": - self.algorithm="antikt" + elif value == "antikt": + self.algorithm = "antikt" self.clustering = ClusteringAntiKt() - elif value=="cambridge": - self.algorithm="cambridge" + elif value == "cambridge": + self.algorithm = "cambridge" self.clustering = ClusteringCambridge() - elif value=="genkt": - self.algorithm="genkt" + elif value == "genkt": + self.algorithm = "genkt" self.clustering = ClusteringGenKt() - elif value=="gridjet": - self.algorithm="gridjet" + elif value == "gridjet": + self.algorithm = "gridjet" self.clustering = ClusteringGridJet() - elif value=="cdfmidpoint": - self.algorithm="cdfmidpoint" + elif value == "cdfmidpoint": + self.algorithm = "cdfmidpoint" self.clustering = ClusteringCDFMidPoint() - elif value=="cdfjetclu": - self.algorithm="cdfjetclu" + elif value == "cdfjetclu": + self.algorithm = "cdfjetclu" self.clustering = ClusteringCDFJetClu() - elif value=="siscone": - self.algorithm="siscone" + elif value == "siscone": + self.algorithm = "siscone" self.clustering = ClusteringSisCone() - elif value=="none": - self.algorithm="none" + elif value == "none": + self.algorithm = "none" self.clustering = 0 else: - logging.getLogger('MA5').error("algorithm called '"+value+"' is not found.") - return + logging.getLogger("MA5").error("algorithm called '" + value + "' is not found.") + return # other rejection if no algo specified - if self.algorithm=="none": - logging.getLogger('MA5').error("'clustering' has no parameter called '"+parameter+"'") + if self.algorithm == "none": + logging.getLogger("MA5").error( + "'clustering' has no parameter called '" + parameter + "'" + ) return # exclusive_id - if parameter=="exclusive_id": - if value=="true": - self.exclusive_id=True - elif value=="false": - self.exclusive_id=False + if parameter == "exclusive_id": + if value == "true": + self.exclusive_id = True + elif value == "false": + self.exclusive_id = False else: - logging.getLogger('MA5').error("The allowed values for 'exclusive_id' " +\ - "parameter are 'true' or 'false'.") - return + logging.getLogger("MA5").error( + "The allowed values for 'exclusive_id' " + "parameter are 'true' or 'false'." + ) + return # other - elif parameter.startswith('bjet_id.'): - return self.beauty.user_SetParameter(parameter,value) - elif parameter.startswith('tau_id.'): - return self.tau.user_SetParameter(parameter,value) - elif parameter.lower() == 'jetid': + elif parameter.startswith("bjet_id."): + return self.beauty.user_SetParameter(parameter, value) + elif parameter.startswith("cjet_id."): + return self.charm.user_SetParameter(parameter, value) + elif parameter.startswith("tau_id."): + return self.tau.user_SetParameter(parameter, value) + elif parameter.lower() == "jetid": self.JetID = str(value) else: - return self.clustering.user_SetParameter(parameter,value) + return self.clustering.user_SetParameter(parameter, value) - def user_GetParameters(self): - if self.algorithm!="none": + if self.algorithm != "none": table = list(ClusteringConfiguration.userVariables.keys()) table.extend(self.clustering.user_GetParameters()) table.extend(self.beauty.user_GetParameters()) + table.extend(self.charm.user_GetParameters()) table.extend(self.tau.user_GetParameters()) else: table = ["algorithm"] return table - - def user_GetValues(self,variable): + def user_GetValues(self, variable): table = [] - if self.algorithm!="none": + if self.algorithm != "none": try: table.extend(ClusteringConfiguration.userVariables[variable]) - except: + except Exception as err: pass try: table.extend(self.clustering.user_GetValues(variable)) - except: + except Exception as err: pass try: table.extend(self.beauty.user_GetValues(variable)) - except: + except Exception as err: + pass + try: + table.extend(self.charm.user_GetValues(variable)) + except Exception as err: pass try: table.extend(self.tau.user_GetValues(variable)) - except: + except Exception as err: pass else: - if variable=="algorithm": + if variable == "algorithm": table.extend(ClusteringConfiguration.userVariables["algorithm"]) return table - From fdb5f285730d7dba5c0b50ce88f054adcb6cceb2 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 11:40:42 +0100 Subject: [PATCH 15/67] integrate new tagger to JetClusterer --- .../Commons/Base/SFSTaggerBase.h | 4 +- .../Process/JetClustering/JetClusterer.cpp | 330 +++++++++++------- .../Process/JetClustering/JetClusterer.h | 3 +- 3 files changed, 201 insertions(+), 136 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index a65f15fe..2355c7a4 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -72,7 +72,7 @@ namespace MA5 { /// Destructor virtual ~SFSTaggerBase() {} - virtual void Initialize() + virtual void Initialize(SFSTaggerBaseOptions &opt) { /// @brief Booleans for code efficiency /// Turn on the usage of tau tagging efficiency @@ -85,6 +85,8 @@ namespace MA5 { _isElectronTaggingOn = false; /// Turn on the usage of photon (mis)tagging efficiency _isPhotonTaggingOn = false; + /// Initialize options + SetOptions(opt); } /// @brief Execution: execute truth and detector level tagging algorithm diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index d107dc8e..1d3d20de 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -72,31 +72,36 @@ MAbool JetClusterer::Initialize(const std::map& options if (algo_==0) return false; // configure tagger - myBtagger_ = new bTagger(); - myCtagger_ = new cTagger(); - myTautagger_ = new TauTagger(); +// myBtagger_ = new bTagger(); +// myCtagger_ = new cTagger(); +// myTautagger_ = new TauTagger(); mySmearer_ = new NullSmearer(); + myTagger_ = new SFSTaggerBase(); + myTaggerOptions_ = new SFSTaggerBaseOptions(); mySmearer_->Initialize(true); - // Loop over options - for (std::map::const_iterator - it=options.begin();it!=options.end();it++) + + /// Loop ower options + for (const auto &opt: options) { - std::string key = ClusterAlgoBase::Lower(it->first); + std::string key = ClusterAlgoBase::Lower(opt.first); MAbool result=false; - // exclusive_id - if (key=="exclusive_id") + /// Initialize exclusive algorithm for jet clustering + if (key == "exclusive_id") { MAint32 tmp=0; std::stringstream str; - str << it->second; + str << opt.second; str >> tmp; try { if (tmp==1) ExclusiveId_=true; else if (tmp==0) ExclusiveId_=false; - else throw EXCEPTION_WARNING("'exclusive_id' must be equal to 0 or 1. Using default value 'exclusive_id' = "+CONVERT->ToString(ExclusiveId_),"",0); + else throw EXCEPTION_WARNING( + "'exclusive_id' must be equal to 0 or 1. Using default value 'exclusive_id' = " \ + + CONVERT->ToString(ExclusiveId_), "", 0 + ); } catch(const std::exception& e) { @@ -104,42 +109,103 @@ MAbool JetClusterer::Initialize(const std::map& options } result=true; } - - // b-tagging - else if (key.find("bjet_id.")==0) + /// B tagging options + else if (key.find("bjet_id.") == 0 || key.find("cjet_id.") == 0 || key.find("tau_id.") == 0) { - result=myBtagger_->SetParameter(key.substr(8),it->second,"bjet_id."); - } - - // c-tagging - // else if (key.find("cjet_id.")==0) - // { - // result=myCtagger_->SetParameter(key.substr(8),it->second,"cjet_id."); - // } - - // tau-tagging - else if (key.find("tau_id.")==0) - { - result=myTautagger_->SetParameter(key.substr(7),it->second,"tau_id."); - } + /// Turn the input value to float + MAfloat32 tmp = 0; + std::stringstream str; + str << opt.second; + str >> tmp; - // clustering algo - else if (key.find("cluster.")==0) - { - result=algo_->SetParameter(key.substr(8),it->second); + /// Is bjet run via exclusive algorithm + if (key == "bjet_id.exclusive") { + try { + if (tmp == 1.) myTaggerOptions_->btag_exclusive = true; + else if (tmp == 0.) myTaggerOptions_->btag_exclusive = false; + else + throw EXCEPTION_WARNING( + "'bjet_id.exclusive' must be equal to 0 or 1. Using default value 'bjet_id.exclusive' = " \ + + CONVERT->ToString(myTaggerOptions_->btag_exclusive), "", 0 + ); + } + catch (const std::exception &e) { + MANAGE_EXCEPTION(e); + } + } + /// What is the bjet matching DR + else if (key == "bjet_id.matching_dr") myTaggerOptions_->btag_matching_deltaR = tmp; + /// Is cjet run via exclusive algorithm + else if (key == "cjet_id.exclusive") + { + try { + if (tmp == 1.) myTaggerOptions_->ctag_exclusive = true; + else if (tmp == 0.) myTaggerOptions_->ctag_exclusive = false; + else + throw EXCEPTION_WARNING( + "'cjet_id.exclusive' must be equal to 0 or 1. Using default value 'cjet_id.exclusive' = " \ + + CONVERT->ToString(myTaggerOptions_->ctag_exclusive), "", 0 + ); + } + catch (const std::exception &e) { + MANAGE_EXCEPTION(e); + } + } + /// What is the cjet matching DR + else if (key == "cjet_id.matching_dr") myTaggerOptions_->ctag_matching_deltaR = tmp; + /// Is cjet run via exclusive algorithm + else if (key == "tau_id.exclusive") + { + try { + if (tmp == 1.) myTaggerOptions_->tautag_exclusive = true; + else if (tmp == 0.) myTaggerOptions_->tautag_exclusive = false; + else + throw EXCEPTION_WARNING( + "'cjet_id.exclusive' must be equal to 0 or 1. Using default value 'cjet_id.exclusive' = " \ + + CONVERT->ToString(myTaggerOptions_->ctag_exclusive), "", 0 + ); + } + catch (const std::exception &e) { + MANAGE_EXCEPTION(e); + } + } + else if (key == "tau_id.matching_dr") myTaggerOptions_->tautag_matching_deltaR = tmp; + else if (key == "tau_id.reconstruction_method") + { + try { + if (tmp == 1.) myTaggerOptions_->tautag_jetbased = true; + else if (tmp == 0.) myTaggerOptions_->tautag_jetbased = false; + else + throw EXCEPTION_WARNING( + "Hadronic tau tagging has only two options 0 corresponds to hadron-based tagging algorithm " + "and 1 corresponds to jet-based tagging algorithm. Default, hadron-based, " + "algorithm will be used", "", 0 + ); + } + catch (const std::exception &e) { + MANAGE_EXCEPTION(e); + myTaggerOptions_->tautag_jetbased = false; + } + } + else + { + try { throw EXCEPTION_WARNING("Parameter = "+key+" unknown. It will be skipped.","",0); } + catch(const std::exception& e) { MANAGE_EXCEPTION(e); } + } + result=true; } - - // Primary Jet ID + /// clustering algo + else if (key.find("cluster.")==0) result = algo_->SetParameter(key.substr(8),opt.second); + /// Primary Jet ID else if (key == "jetid") { - JetID_ = it->second; + JetID_ = opt.second; result = true; } - - // Isolation cone radius for tracker + /// Isolation cone radius for tracker else if (key.find("isolation")==0) { - std::stringstream str(it->second); + std::stringstream str(opt.second); for (MAfloat64 tmp; str >> tmp;) { if (tmp>0. && key.substr(10) == "track.radius") isocone_track_radius_.push_back(tmp); @@ -151,21 +217,14 @@ MAbool JetClusterer::Initialize(const std::map& options result = true; } - // Other - try - { - if (!result) throw EXCEPTION_WARNING("Parameter = "+key+" unknown. It will be skipped.","",0); - } - catch(const std::exception& e) - { - MANAGE_EXCEPTION(e); - } - + /// Other + try { if (!result) throw EXCEPTION_WARNING("Parameter = "+key+" unknown. It will be skipped.","",0); } + catch(const std::exception& e) { MANAGE_EXCEPTION(e); } } - - // configure algo + /// configure algo algo_->Initialize(); - + /// Configure Tagger + myTagger_->Initialize(*myTaggerOptions_); return true; } @@ -177,10 +236,12 @@ MAbool JetClusterer::Initialize(const std::map& options void JetClusterer::Finalize() { if (algo_!=0) delete algo_; - if (myBtagger_!=0) delete myBtagger_; - if (myCtagger_!=0) delete myCtagger_; - if (myTautagger_!=0) delete myTautagger_; +// if (myBtagger_!=0) delete myBtagger_; +// if (myCtagger_!=0) delete myCtagger_; +// if (myTautagger_!=0) delete myTautagger_; if (mySmearer_!=0) delete mySmearer_; + if (myTaggerOptions_!=0) delete myTaggerOptions_; + if (myTagger_!=0) delete myTagger_; } @@ -226,6 +287,12 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) std::vector vetos(myEvent.mc()->particles().size(),false); std::set vetos2; + // shortcut for TET & THT + MAfloat64 & TET = myEvent.rec()->TET(); + // MAfloat64 & THT = myEvent.rec()->THT(); + RecParticleFormat* MET = &(myEvent.rec()->MET()); + RecParticleFormat* MHT = &(myEvent.rec()->MHT()); + // Filling the dataformat with electron/muon for (MAuint32 i=0;iparticles().size();i++) { @@ -239,8 +306,8 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) if (mySmearer_->isPropagatorOn() && part.mothers().size()>0) mySmearer_->ParticlePropagator(const_cast(&part)); - // @JACK delphes based analyses already has tracks - // Set up tracks as charged FS particles OR charged interstate particles with nonzero ctau + /// @attention delphes based analyses already has tracks + /// Set up tracks as charged FS particles OR charged interstate particles with nonzero ctau if (PDG->IsCharged(part.pdgid()) && part.mothers().size()>0 && algo_!=0) { // Minimum tracking requirement is around 0.5 mm see ref. 1007.1988 @@ -365,37 +432,52 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) myEvent.rec()->MCHadronicTaus_.push_back(&(part)); // Applying efficiency - if (!myTautagger_->IsIdentified()) continue; +// if (!myTautagger_->IsIdentified()) continue; - // Smearing the hadronic taus - MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); - // If smeared pt is zero, no need to count the particle but it still needs - // to be vetoed for jet clustering. - if (smeared.pt() > 1e-10) + /// If tau tagging is jet based do not proceed + if (!myTaggerOptions_->tautag_jetbased) { - // Creating reco hadronic taus - RecTauFormat* myTau = myEvent.rec()->GetNewTau(); - if (part.pdgid()>0) myTau->setCharge(-1); - else myTau->setCharge(+1); - myTau->setMomentum(smeared.momentum()); - myTau->setD0(smeared.d0()); - myTau->setDZ(smeared.dz()); - myTau->setD0Approx(smeared.d0_approx()); - myTau->setDZApprox(smeared.dz_approx()); - myTau->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), - part.mothers()[0]->decay_vertex().Y(), - part.mothers()[0]->decay_vertex().Z(),0.0)); - myTau->setClosestApproach(smeared.closest_approach()); - myTau->setMc(&part); - myTau->setDecayMode(PHYSICS->GetTauDecayMode(myTau->mc())); - if (myTau->DecayMode()<=0) myTau->setNtracks(0); // ERROR case - else if (myTau->DecayMode()==7 || - myTau->DecayMode()==9) myTau->setNtracks(3); // 3-Prong - else myTau->setNtracks(1); // 1-Prong + // Smearing the hadronic taus + MCParticleFormat smeared = mySmearer_->Execute( + &part, static_cast(absid) + ); + // If smeared pt is zero, no need to count the particle but it still needs + // to be vetoed for jet clustering. + if (smeared.pt() > 1e-10) + { + // Creating reco hadronic taus + RecTauFormat* myTau = myEvent.rec()->GetNewTau(); + if (part.pdgid()>0) myTau->setCharge(-1); + else myTau->setCharge(+1); + myTau->setMomentum(smeared.momentum()); + myTau->setD0(smeared.d0()); + myTau->setDZ(smeared.dz()); + myTau->setD0Approx(smeared.d0_approx()); + myTau->setDZApprox(smeared.dz_approx()); + myTau->setProductionVertex( + MALorentzVector(part.mothers()[0]->decay_vertex().X(), + part.mothers()[0]->decay_vertex().Y(), + part.mothers()[0]->decay_vertex().Z(), + 0.0) + ); + myTau->setClosestApproach(smeared.closest_approach()); + myTau->setMc(&part); + myTau->setDecayMode(PHYSICS->GetTauDecayMode(myTau->mc())); + if (myTau->DecayMode()<=0) myTau->setNtracks(0); // ERROR case + else if (myTau->DecayMode()==7 || + myTau->DecayMode()==9) myTau->setNtracks(3); // 3-Prong + else myTau->setNtracks(1); // 1-Prong + + /// Set MET and TET + if (ExclusiveId_) { + (*MET) -= myTau->momentum(); + TET += myTau->pt(); + } + } + + // Searching final state + GetFinalState(&part,vetos2); } - - // Searching final state - GetFinalState(&part,vetos2); } } } @@ -433,6 +515,10 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) muon->setMc(&(part)); if (part.pdgid()==13) muon->SetCharge(-1); else muon->SetCharge(+1); + + /// Set MET and TET + (*MET) -= muon->momentum(); + TET += muon->pt(); } // Electrons @@ -457,6 +543,12 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) elec->setMc(&(part)); if (part.pdgid()==11) elec->SetCharge(-1); else elec->SetCharge(+1); + + /// Set MET and TET + if (ExclusiveId_) { + (*MET) -= elec->momentum(); + TET += elec->pt(); + } } // Photons @@ -481,6 +573,12 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) part.mothers()[0]->decay_vertex().Z(),0.0)); photon->setClosestApproach(smeared.closest_approach()); photon->setMc(&(part)); + + /// Set MET and TET + if (ExclusiveId_) { + (*MET) -= photon->momentum(); + TET += photon->pt(); + } } } } @@ -513,20 +611,6 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) } } - // Sorting the objecfts after smearing - if (mySmearer_->isElectronSmearerOn()) - std::sort(myEvent.rec()->electrons_.begin(), myEvent.rec()->electrons_.end(), - [](RecLeptonFormat const & lep1, RecLeptonFormat const & lep2){ return lep1.pt() > lep2.pt(); }); - if (mySmearer_->isMuonSmearerOn()) - std::sort(myEvent.rec()->muons_.begin(), myEvent.rec()->muons_.end(), - [](RecLeptonFormat const & lep1, RecLeptonFormat const & lep2){ return lep1.pt() > lep2.pt(); }); - if (mySmearer_->isTauSmearerOn()) - std::sort(myEvent.rec()->taus_.begin(), myEvent.rec()->taus_.end(), - [](RecTauFormat const & ta1, RecTauFormat const & ta2){ return ta1.pt() > ta2.pt(); }); - if (mySmearer_->isPhotonSmearerOn()) - std::sort(myEvent.rec()->photons_.begin(), myEvent.rec()->photons_.end(), - [](RecPhotonFormat const & ph1, RecPhotonFormat const & ph2){ return ph1.pt() > ph2.pt(); }); - // Set Primary Jet ID myEvent.rec()->SetPrimaryJetID(JetID_); // Launching the clustering @@ -543,46 +627,26 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) substructure.second->Execute(myEvent, substructure.first); #endif - - // shortcut for TET & THT - MAfloat64 & TET = myEvent.rec()->TET(); - // MAfloat64 & THT = myEvent.rec()->THT(); - RecParticleFormat* MET = &(myEvent.rec()->MET()); - RecParticleFormat* MHT = &(myEvent.rec()->MHT()); - - // End - if (ExclusiveId_) - { - for (MAuint32 i=0;ielectrons().size();i++) - { - (*MET) -= myEvent.rec()->electrons()[i].momentum(); - TET += myEvent.rec()->electrons()[i].pt(); - } - for (MAuint32 i=0;iphotons().size();i++) - { - (*MET) -= myEvent.rec()->photons()[i].momentum(); - TET += myEvent.rec()->photons()[i].pt(); - } - for (MAuint32 i=0;itaus().size();i++) - { - (*MET) -= myEvent.rec()->taus()[i].momentum(); - TET += myEvent.rec()->taus()[i].pt(); - } - } - - for (MAuint32 i=0;imuons().size();i++) - { - (*MET) -= myEvent.rec()->muons()[i].momentum(); - TET += myEvent.rec()->muons()[i].pt(); - } - MET->momentum().SetPz(0.); MET->momentum().SetE(MET->momentum().Pt()); MHT->momentum().SetPz(0.); MHT->momentum().SetE(MHT->momentum().Pt()); - myBtagger_->Execute(mySample,myEvent); - myTautagger_->Execute(mySample,myEvent); + /// Execute tagger + myTagger_->Execute(myEvent); + + // Sorting the objects + std::sort(myEvent.rec()->electrons_.begin(), myEvent.rec()->electrons_.end(), + [](RecLeptonFormat const & lep1, RecLeptonFormat const & lep2){ return lep1.pt() > lep2.pt(); }); + std::sort(myEvent.rec()->muons_.begin(), myEvent.rec()->muons_.end(), + [](RecLeptonFormat const & lep1, RecLeptonFormat const & lep2){ return lep1.pt() > lep2.pt(); }); + std::sort(myEvent.rec()->taus_.begin(), myEvent.rec()->taus_.end(), + [](RecTauFormat const & ta1, RecTauFormat const & ta2){ return ta1.pt() > ta2.pt(); }); + std::sort(myEvent.rec()->photons_.begin(), myEvent.rec()->photons_.end(), + [](RecPhotonFormat const & ph1, RecPhotonFormat const & ph2){ return ph1.pt() > ph2.pt(); }); + std::sort(myEvent.rec()->jets().begin(), myEvent.rec()->jets().end(), + [](RecJetFormat &j1, RecJetFormat &j2) { return j1.pt() > j2.pt();}); + #ifdef MA5_FASTJET_MODE // Setup isolation cones diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index b72068a3..bba14a57 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -160,8 +160,7 @@ namespace MA5 void LoadTagger(SFSTaggerBase* tagger) { myTagger_ = tagger; - myTagger_->Initialize(); - myTagger_->SetOptions(*myTaggerOptions_); + myTagger_->Initialize(*myTaggerOptions_); } // Load additional Jets From 8676021e564f889b904dfb4512977bbdce5ecfa1 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 11:48:58 +0100 Subject: [PATCH 16/67] remove null smearer. its not needed --- .../Process/JetClustering/JetClusterer.cpp | 3 +- .../Process/JetClustering/JetClusterer.h | 1 - .../Process/JetClustering/NullSmearer.h | 46 ------------------- 3 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 tools/SampleAnalyzer/Process/JetClustering/NullSmearer.h diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index 1d3d20de..d3080cfc 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -28,7 +28,6 @@ #include "SampleAnalyzer/Commons/Service/ExceptionService.h" #include "SampleAnalyzer/Commons/Service/ConvertService.h" #include "SampleAnalyzer/Commons/Service/PDGService.h" -#include "SampleAnalyzer/Process/JetClustering/NullSmearer.h" #ifdef MA5_FASTJET_MODE #include "SampleAnalyzer/Interfaces/substructure/VariableR.h" @@ -75,7 +74,7 @@ MAbool JetClusterer::Initialize(const std::map& options // myBtagger_ = new bTagger(); // myCtagger_ = new cTagger(); // myTautagger_ = new TauTagger(); - mySmearer_ = new NullSmearer(); + mySmearer_ = new SmearerBase(); myTagger_ = new SFSTaggerBase(); myTaggerOptions_ = new SFSTaggerBaseOptions(); mySmearer_->Initialize(true); diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index bba14a57..c9d12f3a 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -33,7 +33,6 @@ #include "SampleAnalyzer/Process/JetClustering/bTagger.h" #include "SampleAnalyzer/Process/JetClustering/cTagger.h" #include "SampleAnalyzer/Process/JetClustering/TauTagger.h" -#include "SampleAnalyzer/Process/JetClustering/NullSmearer.h" #include "SampleAnalyzer/Commons/Base/SmearerBase.h" #include "SampleAnalyzer/Commons/Base/SFSTaggerBase.h" diff --git a/tools/SampleAnalyzer/Process/JetClustering/NullSmearer.h b/tools/SampleAnalyzer/Process/JetClustering/NullSmearer.h deleted file mode 100644 index c73217eb..00000000 --- a/tools/SampleAnalyzer/Process/JetClustering/NullSmearer.h +++ /dev/null @@ -1,46 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks -// The MadAnalysis development team, email: -// -// This file is part of MadAnalysis 5. -// Official website: -// -// MadAnalysis 5 is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// MadAnalysis 5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with MadAnalysis 5. If not, see -// -//////////////////////////////////////////////////////////////////////////////// - - -#ifndef NULLSMEARER_H -#define NULLSMEARER_H - - -// SampleAnalyzer headers -#include "SampleAnalyzer/Commons/Base/SmearerBase.h" - - -namespace MA5 -{ - class NullSmearer: public SmearerBase { - public: - /// Constructor without argument - NullSmearer() { } - - /// Destructor - ~NullSmearer() {} - - }; -} - -#endif From d80a61ab35a7545de996cb8e43c026214f53400e Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 12:38:21 +0100 Subject: [PATCH 17/67] rule out old tagger interface --- .../Commons/Base/SFSTaggerBase.cpp | 18 ++ .../Commons/Base/SFSTaggerBase.h | 3 + .../Process/Core/SampleAnalyzer.cpp | 3 +- .../Process/JetClustering/JetClusterer.cpp | 6 - .../Process/JetClustering/JetClusterer.h | 254 +++++++++--------- 5 files changed, 145 insertions(+), 139 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index f401542f..e76120cd 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -29,6 +29,24 @@ namespace MA5 { + /// Print parameters + void SFSTaggerBase::PrintParam() const + { + std::string excl = _options.btag_exclusive ? "Exclusive" : "Inclusive"; + INFO << " with bjet: dR = " << _options.btag_matching_deltaR << " ; " << excl << endmsg; + excl = _options.ctag_exclusive ? "Exclusive" : "Inclusive"; + INFO << " with cjet: dR = " << _options.ctag_matching_deltaR << " ; " << excl << endmsg; + if (_options.tautag_jetbased) + { + excl = _options.ctag_exclusive ? "Exclusive" : "Inclusive"; + INFO << " with tau: dR = " << _options.tautag_matching_deltaR << " ; " << excl << endmsg; + } + else + { + INFO << " with tau: hadron-based tagging" << endmsg; + } + } + void SFSTaggerBase::Execute(EventFormat &myEvent) const { /// Shortcut for global event variables diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index 2355c7a4..7ae68778 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -95,6 +95,9 @@ namespace MA5 { /// Initialize options void SetOptions(SFSTaggerBaseOptions &opt) { _options = opt; } + /// Print parameters + void PrintParam() const; + /// Accesor to options SFSTaggerBaseOptions options() const { return _options; } diff --git a/tools/SampleAnalyzer/Process/Core/SampleAnalyzer.cpp b/tools/SampleAnalyzer/Process/Core/SampleAnalyzer.cpp index 8818fc20..19d05390 100644 --- a/tools/SampleAnalyzer/Process/Core/SampleAnalyzer.cpp +++ b/tools/SampleAnalyzer/Process/Core/SampleAnalyzer.cpp @@ -467,8 +467,7 @@ JetClusterer* SampleAnalyzer::InitializeJetClusterer( // Display INFO << " with algo: " << myClusterer->GetParameters() << endmsg; - INFO << " with bjet: " << myClusterer->bParameters() << endmsg; - INFO << " with tau: " << myClusterer->tauParameters() << endmsg; + myClusterer->TaggerParameters(); // Returning the clusterer return myClusterer; diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index d3080cfc..cf7f6e80 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -71,9 +71,6 @@ MAbool JetClusterer::Initialize(const std::map& options if (algo_==0) return false; // configure tagger -// myBtagger_ = new bTagger(); -// myCtagger_ = new cTagger(); -// myTautagger_ = new TauTagger(); mySmearer_ = new SmearerBase(); myTagger_ = new SFSTaggerBase(); myTaggerOptions_ = new SFSTaggerBaseOptions(); @@ -235,9 +232,6 @@ MAbool JetClusterer::Initialize(const std::map& options void JetClusterer::Finalize() { if (algo_!=0) delete algo_; -// if (myBtagger_!=0) delete myBtagger_; -// if (myCtagger_!=0) delete myCtagger_; -// if (myTautagger_!=0) delete myTautagger_; if (mySmearer_!=0) delete mySmearer_; if (myTaggerOptions_!=0) delete myTaggerOptions_; if (myTagger_!=0) delete myTagger_; diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index c9d12f3a..0610cc53 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -30,19 +30,16 @@ #include "SampleAnalyzer/Commons/DataFormat/SampleFormat.h" #include "SampleAnalyzer/Commons/Service/Physics.h" #include "SampleAnalyzer/Commons/Base/ClusterAlgoBase.h" -#include "SampleAnalyzer/Process/JetClustering/bTagger.h" -#include "SampleAnalyzer/Process/JetClustering/cTagger.h" -#include "SampleAnalyzer/Process/JetClustering/TauTagger.h" #include "SampleAnalyzer/Commons/Base/SmearerBase.h" #include "SampleAnalyzer/Commons/Base/SFSTaggerBase.h" #ifdef MA5_FASTJET_MODE - #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoStandard.h" - #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoSISCone.h" - #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFMidpoint.h" - #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFJetClu.h" - #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoGridJet.h" - #include "SampleAnalyzer/Interfaces/substructure/ClusterBase.h" +#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoStandard.h" +#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoSISCone.h" +#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFMidpoint.h" +#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFJetClu.h" +#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoGridJet.h" +#include "SampleAnalyzer/Interfaces/substructure/ClusterBase.h" #endif // STL headers @@ -54,145 +51,140 @@ namespace MA5 { - class JetClusterer - { - //-------------------------------------------------------------------------- - // data members - //-------------------------------------------------------------------------- - protected : + class JetClusterer + { + //-------------------------------------------------------------------------- + // data members + //-------------------------------------------------------------------------- + protected : - ClusterAlgoBase* algo_; - bTagger* myBtagger_; - cTagger* myCtagger_; - TauTagger* myTautagger_; - SmearerBase* mySmearer_; - SFSTaggerBase* myTagger_; + ClusterAlgoBase* algo_; + /// SFS smearer + SmearerBase* mySmearer_; + /// b/c/tau tagger + SFSTaggerBase* myTagger_; - SFSTaggerBaseOptions* myTaggerOptions_; + /// pointer to tagger options + SFSTaggerBaseOptions* myTaggerOptions_; - /// Exclusive id for tau-elec-photon-jet - MAbool ExclusiveId_; + /// Exclusive id for tau-elec-photon-jet + MAbool ExclusiveId_; - /// Primary Jet ID - std::string JetID_; + /// Primary Jet ID + std::string JetID_; #ifdef MA5_FASTJET_MODE - /// Jet collection configurations - std::map cluster_collection_; + /// Jet collection configurations + std::map cluster_collection_; - // Jet collection configuration with VariableR - std::map substructure_collection_; + // Jet collection configuration with VariableR + std::map substructure_collection_; #endif - MAuint32 muon; - MAuint32 electron; - MAuint32 tauH; - MAuint32 tauM; - MAuint32 tauE; - MAuint32 photon; + MAuint32 muon; + MAuint32 electron; + MAuint32 tauH; + MAuint32 tauM; + MAuint32 tauE; + MAuint32 photon; - // Track Isolation radius - std::vector isocone_track_radius_; + // Track Isolation radius + std::vector isocone_track_radius_; - // Electron Isolation radius - std::vector isocone_electron_radius_; + // Electron Isolation radius + std::vector isocone_electron_radius_; - // Muon Isolation radius - std::vector isocone_muon_radius_; + // Muon Isolation radius + std::vector isocone_muon_radius_; - // Photon Isolation radius - std::vector isocone_photon_radius_; + // Photon Isolation radius + std::vector isocone_photon_radius_; - //-------------------------------------------------------------------------- - // method members - //-------------------------------------------------------------------------- - public : + //-------------------------------------------------------------------------- + // method members + //-------------------------------------------------------------------------- + public : - /// Constructor without argument - JetClusterer (ClusterAlgoBase* algo) - { - // Initializing tagger - algo_ = algo; + /// Constructor without argument + JetClusterer (ClusterAlgoBase* algo) + { + // Initializing tagger + algo_ = algo; #ifdef MA5_FASTJET_MODE - cluster_collection_.clear(); - substructure_collection_.clear(); + cluster_collection_.clear(); + substructure_collection_.clear(); #endif - myBtagger_ = 0; - myCtagger_ = 0; - myTautagger_ = 0; - mySmearer_ = 0; - ExclusiveId_ = false; - JetID_ = "Ma5Jet"; - muon=0; - electron=0; - tauH=0; - tauM=0; - tauE=0; - photon=0; - isocone_track_radius_.clear(); - isocone_electron_radius_.clear(); - isocone_muon_radius_.clear(); - isocone_photon_radius_.clear(); - } - - /// Destructor - ~JetClusterer() - { } - - /// Initialization - MAbool Initialize(const std::map& options); - - /// Jet clustering - MAbool Execute(SampleFormat& mySample, EventFormat& myEvent); - - /// Finalization - void Finalize(); - - /// Generic loader for the smearer module - void LoadSmearer(SmearerBase* smearer) - { - mySmearer_ = smearer; - mySmearer_->Initialize(); - } - - /// Generic Loader for tagger module - void LoadTagger(SFSTaggerBase* tagger) - { - myTagger_ = tagger; - myTagger_->Initialize(*myTaggerOptions_); - } - - // Load additional Jets - MAbool LoadJetConfiguration(std::map options); - - /// Accessor to the jet clusterer name - std::string GetName() - { - if (algo_==0) return "NotDefined"; - else return algo_->GetName(); - } - - /// Accessor to the b tagger parameters - std::string bParameters() - { return myBtagger_->GetParameters(); } - - /// Accessor to the tau tagger parameters - std::string tauParameters() - { return myTautagger_->GetParameters(); } - - /// Print parameters - void PrintParam() - { algo_->PrintParam(); } - - /// Accessor to the jet clusterer parameters - std::string GetParameters() - { return algo_->GetParameters(); } - - private: - MAbool IsLast(const MCParticleFormat* part, EventFormat& myEvent); - void GetFinalState(const MCParticleFormat* part, std::set& finalstates); - - }; + mySmearer_ = 0; + myTagger_ = 0; + myTaggerOptions_ = 0; + ExclusiveId_ = false; + JetID_ = "Ma5Jet"; + muon=0; + electron=0; + tauH=0; + tauM=0; + tauE=0; + photon=0; + isocone_track_radius_.clear(); + isocone_electron_radius_.clear(); + isocone_muon_radius_.clear(); + isocone_photon_radius_.clear(); + } + + /// Destructor + ~JetClusterer() + { } + + /// Initialization + MAbool Initialize(const std::map& options); + + /// Jet clustering + MAbool Execute(SampleFormat& mySample, EventFormat& myEvent); + + /// Finalization + void Finalize(); + + /// Generic loader for the smearer module + void LoadSmearer(SmearerBase* smearer) + { + mySmearer_ = smearer; + mySmearer_->Initialize(); + } + + /// Generic Loader for tagger module + void LoadTagger(SFSTaggerBase* tagger) + { + myTagger_ = tagger; + myTagger_->Initialize(*myTaggerOptions_); + } + + // Load additional Jets + MAbool LoadJetConfiguration(std::map options); + + /// Accessor to the jet clusterer name + std::string GetName() + { + if (algo_==0) return "NotDefined"; + else return algo_->GetName(); + } + + /// Accessor to the tagger parameters + void TaggerParameters() + { myTagger_->PrintParam(); } + + /// Print parameters + void PrintParam() + { algo_->PrintParam(); } + + /// Accessor to the jet clusterer parameters + std::string GetParameters() + { return algo_->GetParameters(); } + + private: + MAbool IsLast(const MCParticleFormat* part, EventFormat& myEvent); + void GetFinalState(const MCParticleFormat* part, std::set& finalstates); + + }; } From dbb0eb616b2e2428b847bedabe1f51054984debb Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 12:50:47 +0100 Subject: [PATCH 18/67] bugfix in tagging interface --- tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp | 10 +++++----- .../Process/JetClustering/JetClusterer.cpp | 3 --- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index e76120cd..60fe5a96 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -39,11 +39,11 @@ namespace MA5 { if (_options.tautag_jetbased) { excl = _options.ctag_exclusive ? "Exclusive" : "Inclusive"; - INFO << " with tau: dR = " << _options.tautag_matching_deltaR << " ; " << excl << endmsg; + INFO << " with tau : dR = " << _options.tautag_matching_deltaR << " ; " << excl << endmsg; } else { - INFO << " with tau: hadron-based tagging" << endmsg; + INFO << " with tau : hadron-based tagging" << endmsg; } } @@ -374,7 +374,7 @@ namespace MA5 { for (auto &bHadron: myEvent.rec()->MCBquarks_) { MAfloat32 DeltaRmax = _options.btag_matching_deltaR; - MAuint32 current_ijet = -1; + MAint32 current_ijet = -1; for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) { MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(bHadron); @@ -405,7 +405,7 @@ namespace MA5 { for (auto &cHadron: myEvent.rec()->MCCquarks_) { MAfloat32 DeltaRmax = _options.ctag_matching_deltaR; - MAuint32 current_ijet = -1; + MAint32 current_ijet = -1; for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) { MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(cHadron); @@ -436,7 +436,7 @@ namespace MA5 { for (auto &hadronicTau: myEvent.rec()->MCHadronicTaus()) { MAfloat32 DeltaRmax = _options.tautag_matching_deltaR; - MAuint32 current_jet = -1; + MAint32 current_jet = -1; for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) { if (myEvent.rec()->jets()[ijet].true_ctag() || myEvent.rec()->jets()[ijet].true_btag()) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index cf7f6e80..0045f1be 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -424,9 +424,6 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) // Saving the hadrons in MC container myEvent.rec()->MCHadronicTaus_.push_back(&(part)); - // Applying efficiency -// if (!myTautagger_->IsIdentified()) continue; - /// If tau tagging is jet based do not proceed if (!myTaggerOptions_->tautag_jetbased) { From ad205e9d448236ceaf3f0da6847ec52a010c9516 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 13:47:49 +0100 Subject: [PATCH 19/67] move sfs banner to JetClusterer.h --- .../SampleAnalyzer/Commons/Base/SmearerBase.h | 20 --------------- .../Process/JetClustering/JetClusterer.h | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SmearerBase.h b/tools/SampleAnalyzer/Commons/Base/SmearerBase.h index 0338b6ee..d72ab156 100644 --- a/tools/SampleAnalyzer/Commons/Base/SmearerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SmearerBase.h @@ -95,7 +95,6 @@ namespace MA5 void Initialize(MAbool base=false) { SetParameters(); - if (!base) { PrintHeader(); } PrintDebug(); output_.Reset(); c_ = 2.99792458E+8; // [m/s] @@ -270,25 +269,6 @@ namespace MA5 module = JetSmearer_ ? "on" : "off"; DEBUG << " * Jet Smearer = " << module << endmsg; } - - - void PrintHeader() - { - INFO << " <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>" << endmsg; - INFO << " <> <>" << endmsg; - INFO << " <> Simplified Fast Detector Simulation in MadAnalysis 5 <>" << endmsg; - INFO << " <> Please cite arXiv:2006.09387 [hep-ph] <>" << endmsg; - if (isPropagatorOn()) // cite particle propagator module - { - INFO << " <> <>" << endmsg; - INFO << " <> Particle Propagation in MadAnalysis 5 <>" << endmsg; - INFO << " <> Please cite arXiv:2112.05163 [hep-ph] <>" << endmsg; - INFO << " <> <>" << endmsg; - } - INFO << " <> https://madanalysis.irmp.ucl.ac.be/wiki/SFS <>" << endmsg; - INFO << " <> <>" << endmsg; - INFO << " <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>" << endmsg; - } }; } diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index 0610cc53..493b7451 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -67,6 +67,9 @@ namespace MA5 /// pointer to tagger options SFSTaggerBaseOptions* myTaggerOptions_; + /// Print SFS banner + MAbool SFSbanner_; + /// Exclusive id for tau-elec-photon-jet MAbool ExclusiveId_; @@ -117,6 +120,7 @@ namespace MA5 mySmearer_ = 0; myTagger_ = 0; myTaggerOptions_ = 0; + SFSbanner_ = true; ExclusiveId_ = false; JetID_ = "Ma5Jet"; muon=0; @@ -149,6 +153,7 @@ namespace MA5 { mySmearer_ = smearer; mySmearer_->Initialize(); + if (SFSbanner_) {PrintSFSBanner(); SFSbanner_ = false;} } /// Generic Loader for tagger module @@ -156,6 +161,7 @@ namespace MA5 { myTagger_ = tagger; myTagger_->Initialize(*myTaggerOptions_); + if (SFSbanner_) {PrintSFSBanner(); SFSbanner_ = false;} } // Load additional Jets @@ -180,6 +186,25 @@ namespace MA5 std::string GetParameters() { return algo_->GetParameters(); } + /// SFS Banner + void PrintSFSBanner() + { + INFO << " <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>" << endmsg; + INFO << " <> <>" << endmsg; + INFO << " <> Simplified Fast Detector Simulation in MadAnalysis 5 <>" << endmsg; + INFO << " <> Please cite arXiv:2006.09387 [hep-ph] <>" << endmsg; + if (mySmearer_->isPropagatorOn()) // cite particle propagator module + { + INFO << " <> <>" << endmsg; + INFO << " <> Particle Propagation in MadAnalysis 5 <>" << endmsg; + INFO << " <> Please cite arXiv:2112.05163 [hep-ph] <>" << endmsg; + INFO << " <> <>" << endmsg; + } + INFO << " <> https://madanalysis.irmp.ucl.ac.be/wiki/SFS <>" << endmsg; + INFO << " <> <>" << endmsg; + INFO << " <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>" << endmsg; + } + private: MAbool IsLast(const MCParticleFormat* part, EventFormat& myEvent); void GetFinalState(const MCParticleFormat* part, std::set& finalstates); From 684b7b7c3f990aca9236d22f4866d15c59e2f047 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 15:38:15 +0100 Subject: [PATCH 20/67] full integration of SFSTaggerBase --- madanalysis/IOinterface/job_writer.py | 5 +- madanalysis/fastsim/ast.py | 4 +- madanalysis/job/job_tagger_header.py | 106 ++++++--- madanalysis/job/job_tagger_main.py | 223 ++++-------------- .../Commons/Base/SFSTaggerBase.h | 42 ++-- .../Process/JetClustering/JetClusterer.cpp | 3 +- .../Process/JetClustering/JetClusterer.h | 3 +- 7 files changed, 147 insertions(+), 239 deletions(-) diff --git a/madanalysis/IOinterface/job_writer.py b/madanalysis/IOinterface/job_writer.py index b83b165c..cd428bd9 100644 --- a/madanalysis/IOinterface/job_writer.py +++ b/madanalysis/IOinterface/job_writer.py @@ -507,7 +507,8 @@ def CreateMainFct(self,file,analysisName,outputName): file.write(' cluster1->LoadSmearer(mySmearer);\n\n') if self.main.superfastsim.isTaggerOn(): file.write(' // Declaration of a generic tagger\n') - file.write(' NewTagger* tagger = new NewTagger();\n\n') + file.write(' NewTagger* myTagger = new NewTagger();\n') + file.write(' cluster1->LoadTagger(myTagger);\n\n') # + Case Delphes @@ -593,8 +594,6 @@ def CreateMainFct(self,file,analysisName,outputName): file.write(' if (!analyzer2->Execute(mySample,myEvent)) continue;\n') if self.main.fastsim.package=="fastjet": file.write(' cluster1->Execute(mySample,myEvent);\n') - if self.main.superfastsim.isTaggerOn(): - file.write(' tagger->Execute(mySample,myEvent);\n') elif self.main.fastsim.package=="delphes": file.write(' fastsim1->Execute(mySample,myEvent);\n') elif self.main.fastsim.package=="delphesMA5tune": diff --git a/madanalysis/fastsim/ast.py b/madanalysis/fastsim/ast.py index 12aa69a3..7c1aa1ac 100644 --- a/madanalysis/fastsim/ast.py +++ b/madanalysis/fastsim/ast.py @@ -269,9 +269,9 @@ def tocpp(self,cpp_type,name): # Setting the c++ in text initialization - def tocpp_call(self,obj,name): + def tocpp_call(self,obj,name, pointer="->"): obs = list(set([x.name for x in self.leaves if x.type=='var'])) result = ' fct_' + name + '(' - result += ', '.join([obj+'->'+obs_list.__dict__[x].code_reco for x in obs]) + result += ', '.join([obj+pointer+obs_list.__dict__[x].code_reco for x in obs]) result += ') ' return result diff --git a/madanalysis/job/job_tagger_header.py b/madanalysis/job/job_tagger_header.py index 249190b9..d2cd85b4 100644 --- a/madanalysis/job/job_tagger_header.py +++ b/madanalysis/job/job_tagger_header.py @@ -1,67 +1,101 @@ ################################################################################ -# +# # Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks # The MadAnalysis development team, email: -# +# # This file is part of MadAnalysis 5. # Official website: -# +# # MadAnalysis 5 is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # MadAnalysis 5 is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with MadAnalysis 5. If not, see -# +# ################################################################################ class JobTaggerHeader: + + # structure: (true_id, reco_id) : "..." + base = { + (5, 5): "\t/// B-jet tagging efficiency (b as b)\n\tMAfloat32 b_tagging_eff(const RecJetFormat &object) const", + (5, 4): "\t/// B-jet mistagging as C-jet (b as c)\n\tMAfloat32 b_mistag_c(const RecJetFormat &object) const", + (4, 4): "\t/// C-jet tagging efficiency (c as c)\n\tMAfloat32 c_tagging_eff(const RecJetFormat &object) const", + (4, 5): "\t/// C-jet mistagging as C-jet (c as b)\n\tMAfloat32 c_mistag_b(const RecJetFormat &object) const", + (21, 5): "\t/// Light-Jet mistagging as b-jet (j as b)\n\tMAfloat32 lightjet_mistag_b(const RecJetFormat &object) const", + (21, 4): "\t/// Light-Jet mistagging as c jet (j as c)\n\tMAfloat32 lightjet_mistag_c(const RecJetFormat &object) const", + (21, 15): "\t/// Light-Jet mistagging as tau (j as ta)\n\tMAfloat32 lightjet_mistag_tau(const RecJetFormat &object) const", + (21, 11): "\t/// Light-Jet mistagging as electron (j as e)\n\tMAfloat32 lightjet_mistag_electron(const RecJetFormat &object) const", + (21, 22): "\t/// Light-Jet mistagging as photon (j as photon)\n\tMAfloat32 lightjet_mistag_photon(const RecJetFormat &object) const", + (15, 15): "\t/// Tau tagging efficiency (ta as ta)\n\tMAfloat32 tau_tagging_eff(const RecTauFormat &object) const", + (11, 13): "\t/// Electron mistagging as muon (e as mu)\n\tMAfloat32 electron_mistag_muon(const RecLeptonFormat &object) const", + (11, 22): "\t/// Electron mistagging as photon (e as a)\n\tMAfloat32 electron_mistag_photon(const RecLeptonFormat &object) const", + (11, 21): "\t/// Electron mistagging as light jet (e as j)\n\tMAfloat32 electron_mistag_lightjet(const RecLeptonFormat &object) const", + (13, 11): "\t/// Electron mistagging as electron (mu as e)\n\tMAfloat32 muon_mistag_electron(const RecLeptonFormat &object) const", + (13, 22): "\t/// Electron mistagging as photon (mu as a)\n\tMAfloat32 muon_mistag_photon(const RecLeptonFormat &object) const", + (13, 21): "\t/// Electron mistagging as light jet (mu as j)\n\tMAfloat32 muon_mistag_lightjet(const RecLeptonFormat &object) const", + (22, 11): "\t/// Electron mistagging as electron (a as e)\n\tMAfloat32 photon_mistag_electron(const RecPhotonFormat &object) const", + (22, 13): "\t/// Electron mistagging as muon (a as mu)\n\tMAfloat32 photon_mistag_muon(const RecPhotonFormat &object) const", + (22, 21): "\t/// Electron mistagging as light jet (a as j)\n\tMAfloat32 photon_mistag_lightjet(const RecPhotonFormat &object) const", + } + + ## Initialization def __init__(self, fastsim): self.fastsim = fastsim + self.unique_rules = [] + for key, rule in self.fastsim.tagger.rules.items(): + if (int(rule["id_true"]), int(rule["id_reco"])) not in self.unique_rules: + self.unique_rules.append((int(rule["id_true"]), int(rule["id_reco"]))) + ## Writing NewTagger.h def WriteNewTaggerHeader(self, file): - file.write('#ifndef NEW_TAGGER_H\n') - file.write('#define NEW_TAGGER_H\n') + file.write('#ifndef MADANALYSIS5_NEW_TAGGER_H\n') + file.write('#define MADANALYSIS5_NEW_TAGGER_H\n') file.write('// SampleAnalyzer headers\n') - file.write('#include "SampleAnalyzer/Commons/DataFormat/EventFormat.h"\n') - file.write('#include "SampleAnalyzer/Commons/DataFormat/SampleFormat.h"\n') - file.write('namespace MA5\n') - file.write('{\n') - file.write(' class NewTagger\n') - file.write(' {\n') + file.write('#include "SampleAnalyzer/Commons/Base/SFSTaggerBase.h"\n') + file.write('namespace MA5 {\n') + file.write(' class NewTagger: public SFSTaggerBase {\n') + file.write(' private:\n') + file.write(' /// Code efficiency booleans\n') + file.write(' MAbool _isJetTaggingOn, _isTauTaggingEffOn, _isMuonTaggingOn, _isElectronTaggingOn, _isPhotonTaggingOn;\n') + file.write(' SFSTaggerBaseOptions _options;\n') file.write(' public :\n') - file.write(' /// Constructor without argument\n') - file.write(' NewTagger() \n') - file.write(' {\n') - if not self.fastsim.isNewSmearerOn(): - # If tagger is on but SmearerBase wont be initialized, write SFS reference - # This way whenever SFS is used it will consistently show the ref. - file.write(' INFO <<" <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>" << endmsg;\n') - file.write(' INFO <<" <> <>" << endmsg;\n') - file.write(' INFO <<" <> Simplified Fast Detector Simulation in MadAnalysis 5 <>" << endmsg;\n') - file.write(' INFO <<" <> Please cite arXiv:2006.09387 [hep-ph] <>" << endmsg;\n') - file.write(' INFO <<" <> <>" << endmsg;\n') - file.write(' INFO <<" <> https://madanalysis.irmp.ucl.ac.be/wiki/SFS <>" << endmsg;\n') - file.write(' INFO <<" <> <>" << endmsg;\n') - file.write(' INFO <<" <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>" << endmsg;\n') - file.write(' }\n\n') - file.write(' /// Destructor\n') - file.write(' virtual ~NewTagger() {}\n\n') - file.write(' /// Tagger execution\n') - file.write(' void Execute(SampleFormat &mySample, EventFormat &myEvent);\n\n') - file.write(' };\n') - file.write('}\n') - file.write('#endif') + file.write(' /// Constructor without argument\n') + file.write(' NewTagger() {}\n\n') + file.write(' /// Destructor\n') + file.write(' virtual ~NewTagger() {}\n\n') + file.write(' void Initialize() {\n') + file.write(' /// @brief Booleans for code efficiency\n') + file.write(' /// Turn on the usage of tau tagging efficiency\n') + file.write(f" _isTauTaggingEffOn = {'true' if (5,5) in self.unique_rules else 'false'};\n") + file.write(' /// Turn on the usage of jet (mis)tagging efficiency\n') + file.write(f" _isJetTaggingOn = {'true' if any([x in self.unique_rules for x in [(5,5), (4,5), (21,5), (5,4), (4,4), (21,4), (21,15), (21,11), (21,22)]]) else 'false'};\n") + file.write(' /// Turn on the usage of muon (mis)tagging efficiency\n') + file.write(f" _isMuonTaggingOn = {'true' if 13 in [x[0] for x in self.unique_rules] else 'false'};\n") + file.write(' /// Turn on the usage of electron (mis)tagging efficiency\n') + file.write(f" _isElectronTaggingOn = {'true' if 11 in [x[0] for x in self.unique_rules] else 'false'};\n") + file.write(' /// Turn on the usage of photon (mis)tagging efficiency\n') + file.write(f" _isPhotonTaggingOn = {'true' if 22 in [x[0] for x in self.unique_rules] else 'false'};\n") + file.write(' }\n\n') + file.write(' ///==========================================//\n') + file.write(' /// //\n') + file.write(' /// Tagging Efficiencies //\n') + file.write(' /// //\n') + file.write(' ///==========================================//\n\n') + for rule in self.unique_rules: + file.write(JobTaggerHeader.base[rule] + ";\n") + file.write(' };\n}\n#endif //MADANALYSIS5_NEW_TAGGER_H') ## efficiencies and bounds diff --git a/madanalysis/job/job_tagger_main.py b/madanalysis/job/job_tagger_main.py index 2d93cb11..663fc6f8 100644 --- a/madanalysis/job/job_tagger_main.py +++ b/madanalysis/job/job_tagger_main.py @@ -23,6 +23,30 @@ class JobTaggerMain: + + # structure: (true_id, reco_id) : "..." + base = { + (5, 5): "/// B-jet tagging efficiency (b as b)\nMAfloat32 NewTagger::b_tagging_eff(const RecJetFormat &object) const", + (5, 4): "/// B-jet mistagging as C-jet (b as c)\nMAfloat32 NewTagger::b_mistag_c(const RecJetFormat &object) const", + (4, 4): "/// C-jet tagging efficiency (c as c)\nMAfloat32 NewTagger::c_tagging_eff(const RecJetFormat &object) const", + (4, 5): "/// C-jet mistagging as C-jet (c as b)\nMAfloat32 NewTagger::c_mistag_b(const RecJetFormat &object) const", + (21, 5): "/// Light-Jet mistagging as b-jet (j as b)\nMAfloat32 NewTagger::lightjet_mistag_b(const RecJetFormat &object) const", + (21, 4): "/// Light-Jet mistagging as c jet (j as c)\nMAfloat32 NewTagger::lightjet_mistag_c(const RecJetFormat &object) const", + (21, 15): "/// Light-Jet mistagging as tau (j as ta)\nMAfloat32 NewTagger::lightjet_mistag_tau(const RecJetFormat &object) const", + (21, 11): "/// Light-Jet mistagging as electron (j as e)\nMAfloat32 NewTagger::lightjet_mistag_electron(const RecJetFormat &object) const", + (21, 22): "/// Light-Jet mistagging as photon (j as photon)\nMAfloat32 NewTagger::lightjet_mistag_photon(const RecJetFormat &object) const", + (15, 15): "/// Tau tagging efficiency (ta as ta)\nMAfloat32 NewTagger::tau_tagging_eff(const RecTauFormat &object) const", + (11, 13): "/// Electron mistagging as muon (e as mu)\nMAfloat32 NewTagger::electron_mistag_muon(const RecLeptonFormat &object) const", + (11, 22): "/// Electron mistagging as photon (e as a)\nMAfloat32 NewTagger::electron_mistag_photon(const RecLeptonFormat &object) const", + (11, 21): "/// Electron mistagging as light jet (e as j)\nMAfloat32 NewTagger::electron_mistag_lightjet(const RecLeptonFormat &object) const", + (13, 11): "/// Electron mistagging as electron (mu as e)\nMAfloat32 NewTagger::muon_mistag_electron(const RecLeptonFormat &object) const", + (13, 22): "/// Electron mistagging as photon (mu as a)\nMAfloat32 NewTagger::muon_mistag_photon(const RecLeptonFormat &object) const", + (13, 21): "/// Electron mistagging as light jet (mu as j)\nMAfloat32 NewTagger::muon_mistag_lightjet(const RecLeptonFormat &object) const", + (22, 11): "/// Electron mistagging as electron (a as e)\nMAfloat32 NewTagger::photon_mistag_electron(const RecPhotonFormat &object) const", + (22, 13): "/// Electron mistagging as muon (a as mu)\nMAfloat32 NewTagger::photon_mistag_muon(const RecPhotonFormat &object) const", + (22, 21): "/// Electron mistagging as light jet (a as j)\nMAfloat32 NewTagger::photon_mistag_lightjet(const RecPhotonFormat &object) const", + } + ## Initialization def __init__(self, fastsim): self.fastsim = fastsim @@ -33,181 +57,32 @@ def WriteNewTaggerSource(self, file): # header file.write('#include "SampleAnalyzer/User/Analyzer/new_tagger.h"\n') file.write('#include "SampleAnalyzer/User/Analyzer/efficiencies.h"\n') - file.write('#include "SampleAnalyzer/Commons/Service/RandomService.h"\n') - file.write('#include "SampleAnalyzer/Commons/Service/PDGService.h"\n') - file.write('#include "SampleAnalyzer/Commons/Service/Physics.h"\n') file.write('using namespace MA5;\n') - file.write('\n') - file.write('void NewTagger::Execute(SampleFormat& sample, ' +\ - 'EventFormat& event)\n{\n') - - # Removal container - file.write(' // Storing the IDs of objects that need to leave a collection\n') - file.write(' std::vector toRemove;\n\n') - - # global event variables - file.write(' // Shortcut for global event variables\n') - file.write(' MAfloat64 & THT = event.rec()->THT();\n') - file.write(' MAfloat64 & Meff = event.rec()->Meff();\n\n') - - # b/c-tagging + jet mistagging as any other object - file.write(' // b/c-tagging + jet-mistagging\n') - file.write(' MAuint32 Ntaus = event.rec()->taus().size();\n') - file.write(' for (MAuint32 i=0; ijets().size(); i++)\n') - file.write(' {\n') - for reco_ID in [ ['5', 'b', 'Btag'], ['4', 'c', 'Ctag'] ]: - pretag='' - for true_ID in [ ['5', 'b', 'true_btag'], ['4', 'c', 'true_ctag'], ['21', 'j', '' ] ]: - if self.HaveRules(true_ID[:-1], reco_ID[:-1]): - file.write(' // We have a true ' + true_ID[-2].replace('j','light') + '-jet: is it ' + reco_ID[-2] + '-tagged?\n') - if true_ID[-1]=='': - file.write(' ' + pretag + '\n') - else: - file.write(' ' + pretag + 'if (event.rec()->jets()[i].' + true_ID[-1]+ '())\n') - file.write(' {\n') - self.PrintTagger(true_ID[:-1], reco_ID[:-1], file,'(&event.rec()->jets()[i])',reco_ID[-1]) - file.write(' }\n\n') - pretag='else ' - file.write(' // We have a '+reco_ID[-2]+'-tagged jet -> moving on with the next jet\n') - file.write(' if (event.rec()->jets()[i].'+reco_ID[-1].lower()+'()) { continue; }\n\n') - # Do we have some mistagging of a jet as any other object - if self.HaveRules(['21', 'j'], ['15', 'ta','11','e','22','a']): - file.write(' // We have a true b/c-jet -> cannot be mistagged\n') - file.write(' if (event.rec()->jets()[i].true_btag() || event.rec()->jets()[i].true_ctag()) { continue; }\n\n') - file.write(' // if not, is it mis-tagged as anything?\n') - file.write(' else\n') - file.write(' {\n') - for reco_ID in [ ['15', 'ta', 'TauMistag'], ['11', 'e', 'Electron'], ['22', 'a', 'Photon'] ]: - # Checking the existence of the related rules - if not self.HaveRules(['21', 'j'], reco_ID[:-1]): - continue - file.write(' {\n') - file.write(' // if not, is it '+reco_ID[2].split('Mistag')[0]+'-tagged?\n') - self.PrintTagger(['21', 'j'], reco_ID[:-1],file,'(&event.rec()->jets()[i])',reco_ID[2]) - file.write(' }\n') - file.write(' }\n') - file.write(' }\n\n') - file.write(' for (MAuint32 i=toRemove.size();i>0;i--)\n') - file.write(' event.rec()->jets().erase(event.rec()->jets().begin() + toRemove[i-1]);\n') - file.write(' toRemove.clear();\n\n') - - # tau-tagging - if self.HaveRules(['15', 'ta'], ['15', 'ta']): - file.write(' // tau-tagging\n') - file.write(' for (MAuint32 i=0; itaus()[i])','Jet') - file.write(' }\n') - file.write(' for (MAuint32 i=toRemove.size();i>0;i--)\n') - file.write(' event.rec()->taus().erase(event.rec()->taus().begin() + toRemove[i-1]);\n') - file.write(' toRemove.clear();\n\n') - - # Muon and electron mis-tagging - for true_ID in [ ['13', 'mu', 'muons'], ['11', 'e', 'electrons'], ['22', 'a', 'photons'] ]: - if self.HaveRules(true_ID[:-1], ['11', 'e', '22', 'a', '21', 'j', '13', 'mu']): - file.write(' // Mistagging of ' + true_ID[-1] + '\n') - file.write(' for (MAuint32 i=0; i' + true_ID[-1] + '().size(); i++)\n') - file.write(' {\n') - self.PrintTagger(true_ID[:-1], ['11', 'e', '22', 'a', '21', 'j', '13', 'mu'], file, - '(&event.rec()->' + true_ID[-1] + '()[i])','LeptonicMistag') - file.write(' }\n') - file.write(' for (MAuint32 i=toRemove.size();i>0;i--)\n') - file.write(' event.rec()->' + true_ID[-1] + '().erase(event.rec()->' + true_ID[-1] + '().begin() + toRemove[i-1]);\n') - file.write(' toRemove.clear();\n\n') - - # End - file.write('}\n\n') - - def HaveRules(self, true_list, reco_list): - for key, val in self.fastsim.tagger.rules.items(): - if val['id_true'] in true_list and val['id_reco'] in reco_list: - return True - return False + unique_rules = [] + for key, rule in self.fastsim.tagger.rules.items(): + if (int(rule["id_true"]), int(rule["id_reco"])) not in unique_rules: + unique_rules.append((int(rule["id_true"]), int(rule["id_reco"]))) + for true_id, reco_id in unique_rules: + file.write("\n"+JobTaggerMain.base[(true_id, reco_id)] + " {\n") - def PrintTagger(self, true_list, reco_list, file, obj, prop): - # To get information on the existence of a tagger for a given particle species - check_initializer = 0 - for key, val in self.fastsim.tagger.rules.items(): - if val['id_true'] in true_list and val['id_reco'] in reco_list: - eff_str = [] - initializer = 'MAdouble64 ' - if check_initializer > 0: - initializer = '' - for eff_key, eff_val in val['efficiencies'].items(): - my_eff_str = eff_val['bounds'].tocpp_call(obj,\ - 'bnd_'+str(val['id_true'])+'_'+str(val['id_reco'])+'_'+str(eff_key)) - my_eff_str +=' * ' - my_eff_str += eff_val['function'].tocpp_call(obj,\ - 'eff_'+str(val['id_true'])+'_'+str(val['id_reco'])+'_'+str(eff_key)) - eff_str.append(my_eff_str) - file.write(' ' + initializer + ' efficiency = ' + ' + '.join(eff_str) +';\n') - if prop=='TauMistag': - file.write(' if (RANDOM->flat() < efficiency)\n') - file.write(' {\n') - file.write(' RecTauFormat* newTau = event.rec()->GetNewTau();\n') - file.write(' newTau->setMomentum('+obj+'->momentum());\n') - file.write(' newTau->setNtracks(' + obj + '->ntracks());\n') - file.write(' newTau->setMc(' + obj + '->mc());\n') - file.write(' newTau->setDecayMode(PHYSICS->GetTauDecayMode(newTau->mc()));\n') - file.write(' MAint32 charge = 0;\n') - file.write(' for (MAuint32 icst=0;icst<'+obj+'->constituents().size();icst++)\n') - file.write(' charge += PDG->GetCharge(event.mc()->particles()['+obj+'->constituents()[icst]].pdgid());\n') - file.write(' newTau->setCharge(charge>0);\n') - file.write(' toRemove.push_back(i);\n') - file.write(' continue;\n') - file.write(' }\n') - elif prop in ['Jet', 'LeptonicMistag', 'Electron', 'Photon']: - if 'tau' in obj and prop=='Jet': - file.write(' if (RANDOM->flat() > efficiency)\n') - else: - file.write(' if (RANDOM->flat() < efficiency)\n') - # Get the object for the reco object - newprop = prop - if val['id_reco'] in ['11', 'e'] : - newprop = 'Electron' - elif val['id_reco'] in ['13', 'mu'] : - newprop = 'Muon' - elif val['id_reco'] in ['22', 'a'] : - newprop = 'Photon' - elif val['id_reco'] in ['21', 'j'] : - newprop = 'Jet' - file.write(' {\n') - file.write(' Rec'+newprop.replace('Electron','Lepton').replace('Muon','Lepton')+ \ - 'Format* NewParticle = event.rec()->GetNew'+newprop+'();\n') - file.write(' NewParticle->setMomentum('+obj+'->momentum());\n') - file.write(' NewParticle->setMc(' + obj + '->mc());\n') - if newprop in ['Electron', 'Muon']: - if 'muon' in obj or 'electron' in obj: - file.write(' NewParticle->SetCharge(' + obj + '->charge());\n') - else: - file.write(' if(RANDOM->flat() > 0.5)\n') - file.write(' NewParticle->SetCharge(1.);\n') - file.write(' else)\n') - file.write(' NewParticle->SetCharge(-1.);\n') - elif newprop=='Jet': - if 'tau' in obj: - file.write(' NewParticle->setNtracks(' + obj + '->ntracks());\n') - else: - file.write(' NewParticle->setNtracks(1);\n') - file.write(' THT += '+obj+'->pt();\n') - file.write(' Meff += '+obj+'->pt();\n') - file.write(' MALorentzVector MissHT = event.rec()->MHT().momentum() - '+obj+'->momentum();\n') - file.write(' (&event.rec()->MHT().momentum())->SetPxPyPzE(MissHT.Px(), MissHT.Py(), 0., MissHT.E());\n') - if 'jets' in obj and newprop in ['Electron', 'Photon']: - file.write(' THT -= '+obj+'->pt();\n') - file.write(' Meff -= '+obj+'->pt();\n') - file.write(' MALorentzVector MissHT = event.rec()->MHT().momentum() + '+obj+'->momentum();\n') - file.write(' (&event.rec()->MHT().momentum())->SetPxPyPzE(MissHT.Px(), MissHT.Py(), 0., MissHT.E());\n') - file.write(' toRemove.push_back(i);\n') - file.write(' continue;\n') - file.write(' }\n') - else: - if true_list[0] in reco_list: - file.write(' if (RANDOM->flat() > efficiency)') - file.write(' { ' + obj+'->set'+prop+'(false); }\n') - else: - file.write(' if (RANDOM->flat() < efficiency)') - file.write(' { ' + obj+'->set'+prop+'(true); }\n') - check_initializer+=1 + check_initializer = 0 + for key, val in self.fastsim.tagger.rules.items(): + if val['id_true'] in [str(true_id)] and val['id_reco'] in [str(reco_id)]: + eff_str = [] + initializer = 'MAfloat32 ' + if check_initializer > 0: + initializer = '' + for eff_key, eff_val in val['efficiencies'].items(): + my_eff_str = eff_val['bounds'].tocpp_call( + "object",'bnd_'+str(val['id_true'])+'_'+str(val['id_reco'])+'_'+str(eff_key), pointer=".", + ) + my_eff_str +=' * ' + my_eff_str += eff_val['function'].tocpp_call( + "object", 'eff_'+str(val['id_true'])+'_'+str(val['id_reco'])+'_'+str(eff_key), pointer=".", + ) + eff_str.append(my_eff_str) + file.write(' ' + initializer + ' efficiency = ' + ' + '.join(eff_str) +';\n') + check_initializer += 1 + file.write(" return efficiency;\n}\n") diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index 7ae68778..663971fc 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -72,7 +72,7 @@ namespace MA5 { /// Destructor virtual ~SFSTaggerBase() {} - virtual void Initialize(SFSTaggerBaseOptions &opt) + virtual void Initialize() { /// @brief Booleans for code efficiency /// Turn on the usage of tau tagging efficiency @@ -85,8 +85,6 @@ namespace MA5 { _isElectronTaggingOn = false; /// Turn on the usage of photon (mis)tagging efficiency _isPhotonTaggingOn = false; - /// Initialize options - SetOptions(opt); } /// @brief Execution: execute truth and detector level tagging algorithm @@ -126,39 +124,39 @@ namespace MA5 { ///===============// /// B-jet tagging efficiency (b as b) - virtual MAfloat32 b_tagging_eff(const RecJetFormat &jet) const { return 1.; } + virtual MAfloat32 b_tagging_eff(const RecJetFormat &object) const { return 1.; } /// B-jet mistagging as C-jet (b as c) - virtual MAfloat32 b_mistag_c(const RecJetFormat &jet) const { return 0.; } + virtual MAfloat32 b_mistag_c(const RecJetFormat &object) const { return 0.; } //===============// // C-Tagging // //===============// /// C-jet tagging efficiency (c as c) - virtual MAfloat32 c_tagging_eff(const RecJetFormat &jet) const { return 1.; } + virtual MAfloat32 c_tagging_eff(const RecJetFormat &object) const { return 1.; } /// C-jet mistagging as C-jet (c as b) - virtual MAfloat32 c_mistag_b(const RecJetFormat &jet) const { return 0.; } + virtual MAfloat32 c_mistag_b(const RecJetFormat &object) const { return 0.; } //=======================// // Light-Jet Tagging // //=======================// /// Light-Jet mistagging as b-jet (j as b) - virtual MAfloat32 lightjet_mistag_b(const RecJetFormat &jet) const { return 0.; } + virtual MAfloat32 lightjet_mistag_b(const RecJetFormat &object) const { return 0.; } /// Light-Jet mistagging as c jet (j as c) - virtual MAfloat32 lightjet_mistag_c(const RecJetFormat &jet) const { return 0.; } + virtual MAfloat32 lightjet_mistag_c(const RecJetFormat &object) const { return 0.; } /// Light-Jet mistagging as tau (j as ta) - virtual MAfloat32 lightjet_mistag_tau(const RecJetFormat &jet) const { return 0.; } + virtual MAfloat32 lightjet_mistag_tau(const RecJetFormat &object) const { return 0.; } /// Light-Jet mistagging as electron (j as e) - virtual MAfloat32 lightjet_mistag_electron(const RecJetFormat &jet) const { return 0.; } + virtual MAfloat32 lightjet_mistag_electron(const RecJetFormat &object) const { return 0.; } /// Light-Jet mistagging as photon (j as photon) - virtual MAfloat32 lightjet_mistag_photon(const RecJetFormat &jet) const { return 0.; } + virtual MAfloat32 lightjet_mistag_photon(const RecJetFormat &object) const { return 0.; } //=================// // Tau Tagging // @@ -176,46 +174,46 @@ namespace MA5 { } /// Tau tagging efficiency (ta as ta) - virtual MAfloat32 tau_tagging_eff(const RecTauFormat &tau) const { return 1.; } + virtual MAfloat32 tau_tagging_eff(const RecTauFormat &object) const { return 1.; } //=======================// // Electron Tagging // //======================// /// Electron mistagging as muon (e as mu) - virtual MAfloat32 electron_mistag_muon(const RecLeptonFormat &electron) const { return 0.; } + virtual MAfloat32 electron_mistag_muon(const RecLeptonFormat &object) const { return 0.; } /// Electron mistagging as photon (e as a) - virtual MAfloat32 electron_mistag_photon(const RecLeptonFormat &electron) const { return 0.; } + virtual MAfloat32 electron_mistag_photon(const RecLeptonFormat &object) const { return 0.; } /// Electron mistagging as light jet (e as j) - virtual MAfloat32 electron_mistag_lightjet(const RecLeptonFormat &electron) const { return 0.; } + virtual MAfloat32 electron_mistag_lightjet(const RecLeptonFormat &object) const { return 0.; } //==================// // Muon Tagging // //==================// /// Electron mistagging as electron (mu as e) - virtual MAfloat32 muon_mistag_electron(const RecLeptonFormat &muon) const { return 0.; } + virtual MAfloat32 muon_mistag_electron(const RecLeptonFormat &object) const { return 0.; } /// Electron mistagging as photon (mu as a) - virtual MAfloat32 muon_mistag_photon(const RecLeptonFormat &muon) const { return 0.; } + virtual MAfloat32 muon_mistag_photon(const RecLeptonFormat &object) const { return 0.; } /// Electron mistagging as light jet (mu as j) - virtual MAfloat32 muon_mistag_lightjet(const RecLeptonFormat &muon) const { return 0.; } + virtual MAfloat32 muon_mistag_lightjet(const RecLeptonFormat &object) const { return 0.; } //====================// // Photon Tagging // //====================// /// Electron mistagging as electron (a as e) - virtual MAfloat32 photon_mistag_electron(const RecPhotonFormat &photon) const { return 0.; } + virtual MAfloat32 photon_mistag_electron(const RecPhotonFormat &object) const { return 0.; } /// Electron mistagging as muon (a as mu) - virtual MAfloat32 photon_mistag_muon(const RecPhotonFormat &photon) const { return 0.; } + virtual MAfloat32 photon_mistag_muon(const RecPhotonFormat &object) const { return 0.; } /// Electron mistagging as light jet (a as j) - virtual MAfloat32 photon_mistag_lightjet(const RecPhotonFormat &photon) const { return 0.; } + virtual MAfloat32 photon_mistag_lightjet(const RecPhotonFormat &object) const { return 0.; } }; } diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index 0045f1be..34a5afce 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -75,6 +75,7 @@ MAbool JetClusterer::Initialize(const std::map& options myTagger_ = new SFSTaggerBase(); myTaggerOptions_ = new SFSTaggerBaseOptions(); mySmearer_->Initialize(true); + myTagger_->Initialize(); /// Loop ower options @@ -220,7 +221,7 @@ MAbool JetClusterer::Initialize(const std::map& options /// configure algo algo_->Initialize(); /// Configure Tagger - myTagger_->Initialize(*myTaggerOptions_); + myTagger_->SetOptions(*myTaggerOptions_); return true; } diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index 493b7451..45705900 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -160,7 +160,8 @@ namespace MA5 void LoadTagger(SFSTaggerBase* tagger) { myTagger_ = tagger; - myTagger_->Initialize(*myTaggerOptions_); + myTagger_->Initialize(); + myTagger_->SetOptions(*myTaggerOptions_); if (SFSbanner_) {PrintSFSBanner(); SFSbanner_ = false;} } From ef06a61d48777c945bf07e523e7a7f2f949076f5 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 18:41:18 +0100 Subject: [PATCH 21/67] move SFS header file inclusion from analysis to analysisList.h --- madanalysis/IOinterface/job_writer.py | 4 ++++ madanalysis/core/expert_mode.py | 17 ++++++++++------- madanalysis/misc/run_recast.py | 4 ++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/madanalysis/IOinterface/job_writer.py b/madanalysis/IOinterface/job_writer.py index cd428bd9..baaa9174 100644 --- a/madanalysis/IOinterface/job_writer.py +++ b/madanalysis/IOinterface/job_writer.py @@ -692,6 +692,10 @@ def WriteSelectionSource(self,main): file.write('#include "SampleAnalyzer/Process/Analyzer/AnalyzerManager.h"\n') file.write('#include "SampleAnalyzer/User/Analyzer/user.h"\n') file.write('#include "SampleAnalyzer/Commons/Service/LogStream.h"\n') + if self.main.superfastsim.isTaggerOn(): + file.write('#include "new_tagger.h"\n') + if self.main.superfastsim.isNewSmearerOn(): + file.write('#include "new_smearer_reco.h"\n') file.write('\n') file.write('// ------------------------------------------' +\ '-----------------------------------\n') diff --git a/madanalysis/core/expert_mode.py b/madanalysis/core/expert_mode.py index b2ad2830..4b385f52 100644 --- a/madanalysis/core/expert_mode.py +++ b/madanalysis/core/expert_mode.py @@ -155,15 +155,18 @@ def Copy(self,name,config=''): # if fastsim functionalities are needed if config!='': - with open(self.path+'/Build/SampleAnalyzer/User/Analyzer/'+title+'.h','r') as f: + with open(self.path+'/Build/SampleAnalyzer/User/Analyzer/analysisList.h','r') as f: header = f.readlines() - to_include = [x for x in os.listdir(self.path+'/Build/SampleAnalyzer/User/Analyzer/') if x in ['new_smearer_reco.h', - 'new_tagger.h']] - top_header = header[:header.index('namespace MA5\n')] - bottom_header = header[header.index('namespace MA5\n'):] - for inc in to_include: + to_include = [x for x in os.listdir(self.path + '/Build/SampleAnalyzer/User/Analyzer/') if + x in ['new_smearer_reco.h', 'new_tagger.h']] + + top_header = header[:header.index('// -----------------------------------------------------------------------------\n')] + bottom_header = header[header.index('// -----------------------------------------------------------------------------\n'):] + for idx, inc in enumerate(to_include): + if idx == 0: + top_header.append("/// SFS Headers\n") top_header.append('#include "'+inc+'"\n') - open(self.path+'/Build/SampleAnalyzer/User/Analyzer/'+title+'.h','w').writelines(top_header+bottom_header) + open(self.path+'/Build/SampleAnalyzer/User/Analyzer/analysisList.h','w').writelines(top_header+bottom_header) return True diff --git a/madanalysis/misc/run_recast.py b/madanalysis/misc/run_recast.py index c580a027..9f2eeb18 100644 --- a/madanalysis/misc/run_recast.py +++ b/madanalysis/misc/run_recast.py @@ -357,6 +357,10 @@ def run_SimplifiedFastSim(self,dataset,card,analysislist): analysisList.write('#include "SampleAnalyzer/User/Analyzer/'+ana+'.h"\n') analysisList.write('#include "SampleAnalyzer/Process/Analyzer/AnalyzerManager.h"\n') analysisList.write('#include "SampleAnalyzer/Commons/Service/LogStream.h"\n\n') + if self.main.superfastsim.isTaggerOn(): + analysisList.write('#include "new_tagger.h"\n') + if self.main.superfastsim.isNewSmearerOn(): + analysisList.write('#include "new_smearer_reco.h"\n') analysisList.write('// -----------------------------------------------------------------------------\n') analysisList.write('// BuildUserTable\n') analysisList.write('// -----------------------------------------------------------------------------\n') From 213f678a494427fcfc71879336669fced901bffa Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 18:59:31 +0100 Subject: [PATCH 22/67] update changelog-v2.0.md --- doc/releases/changelog-v2.0.md | 34 +++++++++++++++++-- .../Commons/Base/SFSTaggerBase.cpp | 6 ++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/doc/releases/changelog-v2.0.md b/doc/releases/changelog-v2.0.md index a4fb0aff..362b06ac 100644 --- a/doc/releases/changelog-v2.0.md +++ b/doc/releases/changelog-v2.0.md @@ -1,13 +1,43 @@ -# Release 2.0-dev (development release) +# Release 2.0.0-dev (development release) ## New features since last release +* Substructure module have been implemented to MadAnalysis 5. + [(#13)](https://github.com/MadAnalysis/madanalysis5/pull/13) + * Module includes the following functionality through normal/expert mode + * VariableR: normal and expert mode + * SoftDrop: expert mode + * Clusterer: expert mode + * Jet Filtering: expert mode + * Reclustering: expert mode + * Nsubjettiness: expert mode + * Pruner: expert mode + * Energy Correlator: expert mode + * HEPTopTagger: expert mode + * `RecJetFormat` has been wrapped with `PseudoJet` to accommodate dynamic + transition between two objects. + + All these methods can be used through SFS interface. + +* Substructure and HEPTopTagger has been redesigned to be shared library +so that MadAnalysis can be compiled without these modules as well. + [(#63)](https://github.com/MadAnalysis/madanalysis5/pull/63) + +* Tagger module has been redesigned to accommodate substructure module. + [(#86)](https://github.com/MadAnalysis/madanalysis5/pull/86) + + ## Improvements +* SFS libraries included in `analysisList.h` file instead of main analysis + file. This will lead to much cleaner and independent analysis construction. + [(#86)](https://github.com/MadAnalysis/madanalysis5/pull/86) + ## Bug fixes ## Contributors This release contains contributions from (in alphabetical order): -Jack Y. Araz, Benjamin Fuks \ No newline at end of file +[Jack Y. Araz](https://github.com/jackaraz), +[Benjamin Fuks](https://github.com/BFuks) \ No newline at end of file diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index 60fe5a96..f5235d83 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -33,13 +33,13 @@ namespace MA5 { void SFSTaggerBase::PrintParam() const { std::string excl = _options.btag_exclusive ? "Exclusive" : "Inclusive"; - INFO << " with bjet: dR = " << _options.btag_matching_deltaR << " ; " << excl << endmsg; + INFO << " with bjet: ΔR = " << _options.btag_matching_deltaR << " ; " << excl << endmsg; excl = _options.ctag_exclusive ? "Exclusive" : "Inclusive"; - INFO << " with cjet: dR = " << _options.ctag_matching_deltaR << " ; " << excl << endmsg; + INFO << " with cjet: ΔR = " << _options.ctag_matching_deltaR << " ; " << excl << endmsg; if (_options.tautag_jetbased) { excl = _options.ctag_exclusive ? "Exclusive" : "Inclusive"; - INFO << " with tau : dR = " << _options.tautag_matching_deltaR << " ; " << excl << endmsg; + INFO << " with tau : ΔR = " << _options.tautag_matching_deltaR << " ; " << excl << endmsg; } else { From e08fe7ca5f6a598c290d6b1806451c3f911248af Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 19:01:28 +0100 Subject: [PATCH 23/67] bump version minor --- bin/ma5 | 4 ++-- tools/SampleAnalyzer/Commons/Base/Configuration.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/ma5 b/bin/ma5 index a71d537a..9dced86e 100755 --- a/bin/ma5 +++ b/bin/ma5 @@ -68,8 +68,8 @@ sys.path.insert(0, servicedir) # Release version # Do not touch it !!!!! -version = "2.0" -date = "2022/05/24" +version = "2.0.1" +date = "2022/06/09" # Loading the MadAnalysis session import madanalysis.core.launcher diff --git a/tools/SampleAnalyzer/Commons/Base/Configuration.cpp b/tools/SampleAnalyzer/Commons/Base/Configuration.cpp index fa88de12..a9cf8f1f 100644 --- a/tools/SampleAnalyzer/Commons/Base/Configuration.cpp +++ b/tools/SampleAnalyzer/Commons/Base/Configuration.cpp @@ -40,8 +40,8 @@ using namespace MA5; // Initializing static data members // ----------------------------------------------------------------------------- // DO NOT TOUCH THESE LINES -const std::string Configuration::sampleanalyzer_version_ = "2.0"; -const std::string Configuration::sampleanalyzer_date_ = "2022/05/24"; +const std::string Configuration::sampleanalyzer_version_ = "2.0.1"; +const std::string Configuration::sampleanalyzer_date_ = "2022/06/09"; // DO NOT TOUCH THESE LINES // ----------------------------------------------------------------------------- From d1cc375fa1b64dc26c9e7415ea5a13fa9987fc1d Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 9 Jun 2022 23:01:35 +0100 Subject: [PATCH 24/67] use functions to set parameters --- tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index f5235d83..016becc6 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -460,10 +460,10 @@ namespace MA5 { void SFSTaggerBase::Jet2Tau(const RecJetFormat * myJet, RecTauFormat *myTau, EventFormat &myEvent) const { myTau->setMomentum(myJet->momentum()); - myTau->ntracks_ = myJet->ntracks(); - myTau->mc_ = myJet->mc_; - myTau->DecayMode_ = PHYSICS->GetTauDecayMode(myTau->mc_); - myTau->pseudojet_ = myJet->pseudojet_; + myTau->setNtracks(myJet->ntracks()); + myTau->setMc(myJet->mc_); + myTau->setDecayMode(PHYSICS->GetTauDecayMode(myTau->mc_)); + myTau->setPseudoJet(myJet->pseudojet_); MAint32 charge = 0; myTau->Constituents_.reserve(myJet->Constituents_.size()); @@ -473,7 +473,7 @@ namespace MA5 { for (auto &constit: myTau->Constituents_) charge += PDG->GetCharge(myEvent.mc()->particles()[constit].pdgid()); - myTau->charge_ = charge > 0 ? true : false; + myTau->setCharge(charge > 0 ? true : false); } } \ No newline at end of file From a70fe9842c24d4645671e83d6dadfce3f68ba532 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Wed, 22 Jun 2022 13:11:41 +0100 Subject: [PATCH 25/67] change vector definitions to typefef --- .../Process/Analyzer/AnalyzerBase.h | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/tools/SampleAnalyzer/Process/Analyzer/AnalyzerBase.h b/tools/SampleAnalyzer/Process/Analyzer/AnalyzerBase.h index f75b98e0..6e5b9ad1 100644 --- a/tools/SampleAnalyzer/Process/Analyzer/AnalyzerBase.h +++ b/tools/SampleAnalyzer/Process/Analyzer/AnalyzerBase.h @@ -42,16 +42,16 @@ // FJcontrib tools #ifdef MA5_FASTJET_MODE - #include "SampleAnalyzer/Interfaces/substructure/SoftDrop.h" - #include "SampleAnalyzer/Interfaces/substructure/Cluster.h" - #include "SampleAnalyzer/Interfaces/substructure/Recluster.h" - #include "SampleAnalyzer/Interfaces/substructure/Nsubjettiness.h" - #include "SampleAnalyzer/Interfaces/substructure/VariableR.h" - #include "SampleAnalyzer/Interfaces/substructure/Pruner.h" - #include "SampleAnalyzer/Interfaces/substructure/Selector.h" - #include "SampleAnalyzer/Interfaces/substructure/Filter.h" - #include "SampleAnalyzer/Interfaces/substructure/EnergyCorrelator.h" - #include "SampleAnalyzer/Interfaces/HEPTopTagger/HTT.h" +#include "SampleAnalyzer/Interfaces/substructure/SoftDrop.h" +#include "SampleAnalyzer/Interfaces/substructure/Cluster.h" +#include "SampleAnalyzer/Interfaces/substructure/Recluster.h" +#include "SampleAnalyzer/Interfaces/substructure/Nsubjettiness.h" +#include "SampleAnalyzer/Interfaces/substructure/VariableR.h" +#include "SampleAnalyzer/Interfaces/substructure/Pruner.h" +#include "SampleAnalyzer/Interfaces/substructure/Selector.h" +#include "SampleAnalyzer/Interfaces/substructure/Filter.h" +#include "SampleAnalyzer/Interfaces/substructure/EnergyCorrelator.h" +#include "SampleAnalyzer/Interfaces/HEPTopTagger/HTT.h" #endif // STL headers @@ -65,16 +65,17 @@ #define INIT_ANALYSIS(CLASS,NAME) public: CLASS() {setName(NAME);} virtual ~CLASS() {} private: // Introduce shorthand for widely used reconstructed objects -#define RecJet MA5::RecJetFormat * -#define RecJets std::vector -#define RecTau MA5::RecTauFormat * -#define RecTaus std::vector -#define RecLepton MA5::RecLeptonFormat * -#define RecLeptons std::vector -#define RecPhoton MA5::RecPhotonFormat * -#define RecPhotons std::vector -#define RecTrack MA5::RecTrackFormat * -#define RecTracks std::vector +#define RecJet MA5::RecJetFormat * +typedef std::vector RecJets; +#define RecTau MA5::RecTauFormat * +typedef std::vector RecTaus; +#define RecLepton MA5::RecLeptonFormat * +typedef std::vector RecLeptons; +#define RecPhoton MA5::RecPhotonFormat * +typedef std::vector RecPhotons; +#define RecTrack MA5::RecTrackFormat * +typedef std::vector RecTracks; + namespace MA5 { class AnalyzerBase From 29d1d51820498d12fac2f73e4b8e2235c8cbb9a3 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Wed, 22 Jun 2022 13:51:32 +0100 Subject: [PATCH 26/67] add loose, mid, tight tagging options to the jet class --- .../Commons/DataFormat/RecJetFormat.cpp | 135 ++++++++++++++ .../Commons/DataFormat/RecJetFormat.h | 175 ++++++++++++------ 2 files changed, 250 insertions(+), 60 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp index 62d97519..9a939351 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp @@ -29,6 +29,141 @@ #include "fastjet/PseudoJet.hh" namespace MA5 { + + /// Clear all information + void RecJetFormat::clear() + { + ntracks_ = 0; + loose_btag_ = false; + loose_ctag_ = false; + loose_tautag_ = false; + mid_btag_ = false; + mid_ctag_ = false; + mid_tautag_ = false; + tight_btag_ = false; + tight_ctag_ = false; + tight_tautag_ = false; + true_ctag_ = false; + true_btag_ = false; + true_tautag_ = false; + isolCones_.clear(); + Constituents_.clear(); + } + + /// Accessor to the number of tracks + const MAuint16 RecJetFormat::ntracks() const {return ntracks_;} + + /// Setting ntracks + void RecJetFormat::setNtracks(MAuint16 ntracks) { ntracks_=ntracks; } + + /// Add one constituent + void RecJetFormat::AddConstituent(const MAint32& index) { Constituents_.push_back(index); } + + /// get constituent collections + const std::vector& RecJetFormat::constituents() const { return Constituents_; } + + /// Add one isolation cone + void RecJetFormat::AddIsolCone (const IsolationConeType& cone) { isolCones_.push_back(cone); } + + /// get the collection of isolation cones + const std::vector& RecJetFormat::isolCones() const { return isolCones_; } + + ///==================/// + /// Tagger accessors /// + ///==================/// + + /// Accessor to the loose b-tag + const MAbool& RecJetFormat::btag() const { return loose_btag(); } + + /// Accessor to the loose c-tag + const MAbool& RecJetFormat::ctag() const { return loose_ctag(); } + + /// Accessor to the loose c-tag + const MAbool& RecJetFormat::tautag() const { return loose_tautag(); } + + /// Accessor to the loose b-tag + const MAbool& RecJetFormat::loose_btag() const { return loose_btag_; } + + /// Accessor to the loose c-tag + const MAbool& RecJetFormat::loose_ctag() const { return loose_ctag_; } + + /// Accessor to the loose c-tag + const MAbool& RecJetFormat::loose_tautag() const { return loose_tautag_; } + + /// Accessor to the mid b-tag + const MAbool& RecJetFormat::mid_btag() const { return mid_btag_; } + + /// Accessor to the mid c-tag + const MAbool& RecJetFormat::mid_ctag() const { return mid_ctag_; } + + /// Accessor to the mid c-tag + const MAbool& RecJetFormat::mid_tautag() const { return mid_tautag_; } + + /// Accessor to the tight b-tag + const MAbool& RecJetFormat::tight_btag() const { return tight_btag_; } + + /// Accessor to the tight c-tag + const MAbool& RecJetFormat::tight_ctag() const { return tight_ctag_; } + + /// Accessor to the tight c-tag + const MAbool& RecJetFormat::tight_tautag() const { return tight_tautag_; } + + /// Accessor to the true c-tag + const MAbool& RecJetFormat::true_ctag() const {return true_btag_;} + + /// Accessor to the true b-tag + const MAbool& RecJetFormat::true_btag() const {return true_ctag_;} + + /// Accessor to the true tau-tag + const MAbool& RecJetFormat::true_tautag() const {return true_tautag_;} + + /// Setters for tagger + + /// Setting a new true_btag_ value + void RecJetFormat::setTrueBtag(const MAbool& tag) { true_btag_ = tag;} + + /// Setting a new true_ctag_ value + void RecJetFormat::setTrueCtag(const MAbool& tag) { true_ctag_ = tag;} + + /// Setting a new true_tautag_ value + void RecJetFormat::setTrueTautag(const MAbool& tag) { true_tautag_ = tag;} + + /// Setting a new loose_btag_ value + void RecJetFormat::setBtag(const MAbool& tag) { setLooseBtag(tag); } + + /// Setting a new loose_ctag_ value + void RecJetFormat::setCtag(const MAbool& tag) { setLooseCtag(tag); } + + /// Setting a new loose_tautag_ value + void RecJetFormat::setTautag(const MAbool& tag) { setLooseTautag(tag); } + + /// Setting a new loose_btag_ value + void RecJetFormat::setLooseBtag(const MAbool& tag) { loose_btag_ = tag; } + + /// Setting a new loose_ctag_ value + void RecJetFormat::setLooseCtag(const MAbool& tag) { loose_ctag_ = tag; } + + /// Setting a new loose_tautag_ value + void RecJetFormat::setLooseTautag(const MAbool& tag) { loose_tautag_ = tag; } + + /// Setting a new Mid_btag_ value + void RecJetFormat::setMidBtag(const MAbool& tag) { mid_btag_ = tag; } + + /// Setting a new Mid_ctag_ value + void RecJetFormat::setMidCtag(const MAbool& tag) { mid_ctag_ = tag; } + + /// Setting a new Mid_tautag_ value + void RecJetFormat::setMidTautag(const MAbool& tag) { mid_tautag_ = tag; } + + /// Setting a new Tight_btag_ value + void RecJetFormat::setTightBtag(const MAbool& tag) { tight_btag_ = tag; } + + /// Setting a new Tight_ctag_ value + void RecJetFormat::setTightCtag(const MAbool& tag) { tight_ctag_ = tag; } + + /// Setting a new Tight_tautag_ value + void RecJetFormat::setTightTautag(const MAbool& tag) { tight_tautag_ = tag; } + // return a vector of all subjets of the current jet (in the sense of the exclusive algorithm) // that would be obtained when running the algorithm with the given dcut. std::vector RecJetFormat::exclusive_subjets(MAfloat32 dcut) const diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h index 40270b93..01e252c3 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h @@ -91,11 +91,27 @@ namespace MA5 protected: MAuint16 ntracks_; /// number of tracks - MAbool btag_; /// b-tag - MAbool ctag_; /// c-tag - MAbool tautag_; /// tau-tag + + /// Tags are separated into 4 cathegories truth, loose, mid, tight. + /// Truth is used for MC event tagging rest is from detector simulations. + /// Loose tagging will be used as default for backwards compatibility btag() + /// ctag(), tautag() will return loose tagging criteria. + MAbool loose_btag_; /// loose b-tag + MAbool loose_ctag_; /// loose c-tag + MAbool loose_tautag_; /// loose tau-tag + + MAbool mid_btag_; /// tight b-tag + MAbool mid_ctag_; /// tight c-tag + MAbool mid_tautag_; /// tight tau-tag + + MAbool tight_btag_; /// tight b-tag + MAbool tight_ctag_; /// tight c-tag + MAbool tight_tautag_; /// tight tau-tag + MAbool true_ctag_; /// c-tag (before id or misid) MAbool true_btag_; /// b-tag (before id or misid) + MAbool true_tautag_; /// tau-tag (before id or misid) + std::vector Constituents_; /// indices of the MC particles std::vector isolCones_; // isolation cones @@ -112,21 +128,21 @@ namespace MA5 /// Constructor without arguments RecJetFormat() - { Reset(); } + { clear(); } /// Constructor with argument RecJetFormat(MAfloat64 pt, MAfloat64 eta, MAfloat64 phi, MAfloat64 m) - { Reset(); momentum_.SetPtEtaPhiM(pt,eta,phi,m); } + { clear(); momentum_.SetPtEtaPhiM(pt,eta,phi,m); } /// Constructor with argument RecJetFormat(const MALorentzVector& p) - { Reset(); momentum_.SetPxPyPzE(p.Px(),p.Py(),p.Pz(),p.E()); } + { clear(); momentum_.SetPxPyPzE(p.Px(),p.Py(),p.Pz(),p.E()); } #ifdef MA5_FASTJET_MODE /// Constructor with argument RecJetFormat(fastjet::PseudoJet& jet) { - Reset(); + clear(); momentum_.SetPxPyPzE(jet.px(), jet.py(), jet.pz(), jet.e()); pseudojet_=jet; } @@ -140,87 +156,126 @@ namespace MA5 virtual void Print() const { INFO << "ntracks =" << /*set::setw(8)*/"" << std::left << ntracks_ << ", " - << "btag = " << /*set::setw(8)*/"" << std::left << btag_ << ", " - << "ctag = " << /*set::setw(8)*/"" << std::left << ctag_ << ", "; + << "btag = " << /*set::setw(8)*/"" << std::left << loose_btag_ << ", " + << "ctag = " << /*set::setw(8)*/"" << std::left << loose_ctag_ << ", "; RecParticleFormat::Print(); } /// Clear all information - virtual void Reset() - { - ntracks_ = 0; - btag_ = false; - ctag_ = false; - tautag_ = false; - true_btag_ = false; - true_ctag_ = false; - isolCones_.clear(); - Constituents_.clear(); - } + virtual void Reset() { clear(); } + + /// Clear all information + void clear(); /// Accessor to the number of tracks - const MAuint16 ntracks() const - {return ntracks_;} + const MAuint16 ntracks() const; + + /// Setting ntracks + void setNtracks(MAuint16 ntracks); + + /// Tagger options + + /// Accessor to the loose b-tag + const MAbool& btag() const; + + /// Accessor to the loose c-tag + const MAbool& ctag() const; + + /// Accessor to the loose c-tag + const MAbool& tautag() const; + + /// Accessor to the loose b-tag + const MAbool& loose_btag() const; + + /// Accessor to the loose c-tag + const MAbool& loose_ctag() const; - /// Accessor to the b-tag - const MAbool& btag() const - {return btag_;} + /// Accessor to the loose c-tag + const MAbool& loose_tautag() const; - /// Accessor to the c-tag - const MAbool& ctag() const - {return ctag_;} + /// Accessor to the mid b-tag + const MAbool& mid_btag() const; + + /// Accessor to the mid c-tag + const MAbool& mid_ctag() const; + + /// Accessor to the mid c-tag + const MAbool& mid_tautag() const; + + /// Accessor to the tight b-tag + const MAbool& tight_btag() const; + + /// Accessor to the tight c-tag + const MAbool& tight_ctag() const; + + /// Accessor to the tight c-tag + const MAbool& tight_tautag() const; /// Accessor to the true c-tag - const MAbool& true_ctag() const - {return true_ctag_;} + const MAbool& true_ctag() const; /// Accessor to the true b-tag - const MAbool& true_btag() const - {return true_btag_;} + const MAbool& true_btag() const; + + /// Accessor to the true tau-tag + const MAbool& true_tautag() const; /// Setting a new true_btag_ value - void setTrueBtag(const MAbool& tag) - {true_btag_=tag;} + void setTrueBtag(const MAbool& tag); - /// Setting a new btag_ value - void setBtag(const MAbool& tag) - {btag_=tag;} + /// Setting a new true_ctag_ value + void setTrueCtag(const MAbool& tag); - /// Setting a new ctag_ value - void setCtag(const MAbool& tag) - {ctag_=tag;} + /// Setting a new true_tautag_ value + void setTrueTautag(const MAbool& tag); - /// Setting a new true_ctag_ value - void setTrueCtag(const MAbool& tag) - {true_ctag_=tag;} + /// Setting a new loose_btag_ value + void setBtag(const MAbool& tag); - /// Accessor to the tautag - const MAbool& tautag() const - { return tautag_; } + /// Setting a new loose_ctag_ value + void setCtag(const MAbool& tag); - /// Setting a new tautag_ value - void setTautag(const MAbool& tag) - {tautag_=tag;} + /// Setting a new loose_tautag_ value + void setTautag(const MAbool& tag); - /// Setting ntracks - void setNtracks(MAuint16 ntracks) - { ntracks_=ntracks; } + /// Setting a new loose_btag_ value + void setLooseBtag(const MAbool& tag); + + /// Setting a new loose_ctag_ value + void setLooseCtag(const MAbool& tag); + + /// Setting a new loose_tautag_ value + void setLooseTautag(const MAbool& tag); + + /// Setting a new Mid_btag_ value + void setMidBtag(const MAbool& tag); + + /// Setting a new Mid_ctag_ value + void setMidCtag(const MAbool& tag); + + /// Setting a new Mid_tautag_ value + void setMidTautag(const MAbool& tag); + + /// Setting a new Tight_btag_ value + void setTightBtag(const MAbool& tag); + + /// Setting a new Tight_ctag_ value + void setTightCtag(const MAbool& tag); + + /// Setting a new Tight_tautag_ value + void setTightTautag(const MAbool& tag); /// Add one constituent - void AddConstituent (const MAint32& index) - {Constituents_.push_back(index);} + void AddConstituent (const MAint32& index); /// get constituent collections - const std::vector& constituents() const - { return Constituents_; } + const std::vector& constituents() const; /// Add one isolation cone - void AddIsolCone (const IsolationConeType& cone) - {isolCones_.push_back(cone);} + void AddIsolCone (const IsolationConeType& cone); /// get the collection of isolation cones - const std::vector& isolCones() const - { return isolCones_; } + const std::vector& isolCones() const; #ifdef MA5_FASTJET_MODE // Accessor for pseudojets From f8c7cebde9e76ac6a810865b8dace3f0061d51f4 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Wed, 22 Jun 2022 16:30:15 +0100 Subject: [PATCH 27/67] adapt tagger to have loose, mid, tight taggers --- .../Commons/Base/SFSTaggerBase.cpp | 264 +++++++++--------- .../Commons/Base/SFSTaggerBase.h | 113 +++++--- .../Commons/DataFormat/RecJetFormat.cpp | 27 +- .../Commons/DataFormat/RecJetFormat.h | 9 + 4 files changed, 245 insertions(+), 168 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index 016becc6..2b8d901f 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -47,6 +47,20 @@ namespace MA5 { } } + /// Convert jet to tau + MAfloat32 SFSTaggerBase::tau_tagging_eff(const RecJetFormat &jet, TaggerStatus status) const + { + RecTauFormat myTau; + myTau.setMomentum(jet.momentum()); + myTau.ntracks_ = jet.ntracks(); + myTau.mc_ = jet.mc_; + + if (status == TaggerStatus::MID) return mid_tau_tagging_eff(myTau); + else if (status == TaggerStatus::TIGHT) return tight_tau_tagging_eff(myTau); + else return loose_tau_tagging_eff(myTau); + } + + /// Execute tagger void SFSTaggerBase::Execute(EventFormat &myEvent) const { /// Shortcut for global event variables @@ -63,131 +77,136 @@ namespace MA5 { /// Get initial number of taus. /// @attention if tau tagging is jet based Ntau will be zero MAuint32 Ntau = myEvent.rec()->taus().size(); - - /// Jet tagging with detector effects std::vector toRemove; - MAuint32 ijet = -1; - if (_isJetTaggingOn || _options.tautag_jetbased) { - for (auto &jet: myEvent.rec()->jets()) + /// Jet tagging with detector effects + MAint32 ijet = -1; + for (auto &jet: myEvent.rec()->jets()) + { + ijet++; + /// We have a true b-jet: is it b-tagged? + if (jet.true_btag()) + { + jet.setLooseBtag(RANDOM->flat() < loose_b_tagging_eff(jet)); + jet.setMidBtag(RANDOM->flat() < mid_b_tagging_eff(jet)); + jet.setTightBtag(RANDOM->flat() < tight_b_tagging_eff(jet)); + } + /// We have a true c-jet: is it b-tagged? + else if (jet.true_ctag()) + { + jet.setLooseBtag(RANDOM->flat() < loose_c_mistag_b(jet)); + jet.setMidBtag(RANDOM->flat() < mid_c_mistag_b(jet)); + jet.setTightBtag(RANDOM->flat() < tight_c_mistag_b(jet)); + } + /// We have a true light-jet: is it b-tagged? + else + { + jet.setLooseBtag(RANDOM->flat() < lightjet_mistag_b_loose(jet)); + jet.setMidBtag(RANDOM->flat() < lightjet_mistag_b_mid(jet)); + jet.setTightBtag(RANDOM->flat() < lightjet_mistag_b_tight(jet)); + } + + /// We have a true b-jet: is it c-tagged? + if (jet.true_btag()) + { + /// We have a b-tagged jet -> moving on with the next jet + jet.setLooseCtag(!jet.loose_btag() && RANDOM->flat() < loose_b_mistag_c(jet)); + jet.setMidCtag(!jet.mid_btag() && RANDOM->flat() < mid_b_mistag_c(jet)); + jet.setTightCtag(!jet.tight_btag() && RANDOM->flat() < tight_b_mistag_c(jet)); + } + /// We have a true c-jet: is it c-tagged? + else if (jet.true_ctag()) + { + jet.setLooseCtag(!jet.loose_btag() && RANDOM->flat() < loose_c_tagging_eff(jet)); + jet.setMidCtag(!jet.mid_btag() && RANDOM->flat() < mid_c_tagging_eff(jet)); + jet.setTightCtag(!jet.tight_btag() && RANDOM->flat() < tight_c_tagging_eff(jet)); + } + /// We have a true light-jet: is it c-tagged? + else { - ijet++; - if (jet.tautag()) + jet.setLooseCtag(RANDOM->flat() < lightjet_mistag_c_loose(jet)); + jet.setMidCtag(RANDOM->flat() < lightjet_mistag_c_mid(jet)); + jet.setTightCtag(RANDOM->flat() < lightjet_mistag_c_tight(jet)); + } + + if (_options.tautag_jetbased) + { + if (jet.true_tautag()) { - if (RANDOM->flat() < tau_tagging_eff(jet)) - { + jet.setLooseTautag(!jet.loose_btag() && !jet.loose_ctag() && + RANDOM->flat() < tau_tagging_eff(jet, LOOSE)); + jet.setMidTautag(!jet.mid_btag() && !jet.mid_ctag() && + RANDOM->flat() < tau_tagging_eff(jet, MID)); + jet.setTightTautag(!jet.tight_btag() && !jet.tight_ctag() && + RANDOM->flat() < tau_tagging_eff(jet, TIGHT)); + } else { + jet.setLooseTautag(!jet.loose_btag() && !jet.loose_ctag() && + RANDOM->flat() < lightjet_mistag_tau_loose(jet)); + jet.setMidTautag(!jet.mid_btag() && !jet.mid_ctag() && + RANDOM->flat() < lightjet_mistag_tau_mid(jet)); + jet.setTightTautag(!jet.tight_btag() && !jet.tight_ctag() && + RANDOM->flat() < lightjet_mistag_tau_tight(jet)); + } + + } + + /// We have a true b/c-jet -> cannot be mistagged + if (jet.ctag() || jet.btag() || jet.tautag()) continue; + /// if not, is it mis-tagged as anything? + else + { + /// Scope for light jet mistagging as tau + if (!_options.tautag_jetbased) { + /// if not, is it Tau-tagged? + if (RANDOM->flat() < lightjet_mistag_tau_loose(jet)) { RecTauFormat *newTau = myEvent.rec()->GetNewTau(); Jet2Tau(&jet, newTau, myEvent); toRemove.push_back(ijet); continue; } - /// @attention This is for consistency. Tau tag is created for this application only. - jet.setTautag(false); - } - /// Do not continue if tagger is not on (for code efficiency) - if (!_isJetTaggingOn) continue; - - /// We have a true b-jet: is it b-tagged? - if (jet.true_btag()) - { - if (RANDOM->flat() > b_tagging_eff(jet)) jet.setBtag(false); - } - /// We have a true c-jet: is it b-tagged? - else if (jet.true_ctag()) - { - if (RANDOM->flat() < c_mistag_b(jet)) { - jet.setBtag(true); jet.setCtag(false); - } - } - /// We have a true light-jet: is it b-tagged? - else - { - if (RANDOM->flat() < lightjet_mistag_b(jet)) jet.setBtag(true); } - - /// We have a b-tagged jet -> moving on with the next jet - if (jet.btag()) continue; - - /// We have a true b-jet: is it c-tagged? - if (jet.true_btag()) + /// Scope for light jet mistagging for electron { - if (RANDOM->flat() < b_mistag_c(jet)) { - jet.setCtag(true); jet.setBtag(false); + /// if not, is it Electron-tagged? + if (RANDOM->flat() < lightjet_mistag_electron(jet)) + { + RecLeptonFormat* NewParticle = myEvent.rec()->GetNewElectron(); + NewParticle->setMomentum(jet.momentum()); + NewParticle->setMc(jet.mc()); + /// @attention charge can also be determined via total constituent charge + NewParticle->SetCharge(RANDOM->flat() > 0.5 ? 1. : -1.); + THT -= jet.pt(); + Meff -= jet.pt(); + MALorentzVector MissHT = myEvent.rec()->MHT().momentum() + jet.momentum(); + (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( + MissHT.Px(), MissHT.Py(), 0., MissHT.E() + ); + toRemove.push_back(ijet); } } - /// We have a true c-jet: is it c-tagged? - else if (jet.true_ctag()) - { - if (RANDOM->flat() > c_tagging_eff(jet)) jet.setCtag(false); - } - /// We have a true light-jet: is it c-tagged? - else - { - if (RANDOM->flat() < lightjet_mistag_c(jet)) jet.setCtag(true); - } - - /// We have a c-tagged jet -> moving on with the next jet - if (jet.ctag()) continue; - - /// We have a true b/c-jet -> cannot be mistagged - if (jet.ctag() || jet.btag()) continue; - /// if not, is it mis-tagged as anything? - else + /// Scope for light jet mistagging for photon { - /// Scope for light jet mistagging as tau + /// if not, is it Photon-tagged? + if (RANDOM->flat() < lightjet_mistag_photon(jet)) { - /// if not, is it Tau-tagged? - if (RANDOM->flat() < lightjet_mistag_tau(jet)) { - RecTauFormat *newTau = myEvent.rec()->GetNewTau(); - Jet2Tau(&jet, newTau, myEvent); - toRemove.push_back(ijet); - continue; - } - } - /// Scope for light jet mistagging for electron - { - /// if not, is it Electron-tagged? - if (RANDOM->flat() < lightjet_mistag_electron(jet)) - { - RecLeptonFormat* NewParticle = myEvent.rec()->GetNewElectron(); - NewParticle->setMomentum(jet.momentum()); - NewParticle->setMc(jet.mc()); - /// @attention charge can also be determined via total constituent charge - NewParticle->SetCharge(RANDOM->flat() > 0.5 ? 1. : -1.); - THT -= jet.pt(); - Meff -= jet.pt(); - MALorentzVector MissHT = myEvent.rec()->MHT().momentum() + jet.momentum(); - (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( - MissHT.Px(), MissHT.Py(), 0., MissHT.E() - ); - toRemove.push_back(ijet); - } - } - /// Scope for light jet mistagging for photon - { - /// if not, is it Photon-tagged? - if (RANDOM->flat() < lightjet_mistag_photon(jet)) - { - RecPhotonFormat* NewParticle = myEvent.rec()->GetNewPhoton(); - NewParticle->setMomentum(jet.momentum()); - NewParticle->setMc(jet.mc()); - THT -= jet.pt(); - Meff -= jet.pt(); - MALorentzVector MissHT = myEvent.rec()->MHT().momentum() + jet.momentum(); - (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( - MissHT.Px(), MissHT.Py(), 0., MissHT.E() - ); - toRemove.push_back(ijet); - continue; - } + RecPhotonFormat* NewParticle = myEvent.rec()->GetNewPhoton(); + NewParticle->setMomentum(jet.momentum()); + NewParticle->setMc(jet.mc()); + THT -= jet.pt(); + Meff -= jet.pt(); + MALorentzVector MissHT = myEvent.rec()->MHT().momentum() + jet.momentum(); + (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( + MissHT.Px(), MissHT.Py(), 0., MissHT.E() + ); + toRemove.push_back(ijet); + continue; } } } - /// Remove jets from the collection - for (MAuint32 i = toRemove.size(); i > 0; i--) - myEvent.rec()->jets().erase(myEvent.rec()->jets().begin() + toRemove[i-1]); - toRemove.clear(); } - + /// Remove jets from the collection + for (MAuint32 i = toRemove.size(); i > 0; i--) + myEvent.rec()->jets().erase(myEvent.rec()->jets().begin() + toRemove[i-1]); + toRemove.clear(); if (_isTauTaggingEffOn) { @@ -384,18 +403,10 @@ namespace MA5 { { current_ijet = ijet; DeltaRmax = dR; } - else - { - myEvent.rec()->jets()[ijet].setTrueBtag(true); - myEvent.rec()->jets()[ijet].setBtag(true); - } + else { myEvent.rec()->jets()[ijet].setTrueBtag(true); } } } - if (current_ijet >= 0) - { - myEvent.rec()->jets()[current_ijet].setTrueBtag(true); - myEvent.rec()->jets()[current_ijet].setBtag(true); - } + if (current_ijet >= 0) myEvent.rec()->jets()[current_ijet].setTrueBtag(true); } } @@ -408,6 +419,7 @@ namespace MA5 { MAint32 current_ijet = -1; for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) { + if (myEvent.rec()->jets()[ijet].true_btag()) continue; MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(cHadron); if (dR <= DeltaRmax) { @@ -415,18 +427,10 @@ namespace MA5 { { current_ijet = ijet; DeltaRmax = dR; } - else - { - myEvent.rec()->jets()[ijet].setTrueCtag(true); - myEvent.rec()->jets()[ijet].setCtag(true); - } + else { myEvent.rec()->jets()[ijet].setTrueCtag(true); } } } - if (current_ijet >= 0) - { - myEvent.rec()->jets()[current_ijet].setTrueCtag(true); - myEvent.rec()->jets()[current_ijet].setCtag(true); - } + if (current_ijet >= 0) myEvent.rec()->jets()[current_ijet].setTrueCtag(true); } } @@ -449,10 +453,10 @@ namespace MA5 { { DeltaRmax = dR; current_jet = ijet; } - else myEvent.rec()->jets()[current_jet].setTautag(true); + else myEvent.rec()->jets()[current_jet].setTrueTautag(true); } } - if (current_jet >= 0) myEvent.rec()->jets()[current_jet].setTautag(true); + if (current_jet >= 0) myEvent.rec()->jets()[current_jet].setTrueTautag(true); } } @@ -473,7 +477,7 @@ namespace MA5 { for (auto &constit: myTau->Constituents_) charge += PDG->GetCharge(myEvent.mc()->particles()[constit].pdgid()); - myTau->setCharge(charge > 0 ? true : false); + myTau->setCharge(charge > 0); } } \ No newline at end of file diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index 663971fc..eaf3191f 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -29,6 +29,9 @@ namespace MA5 { + /// Status of the tagger + enum TaggerStatus {LOOSE, MID, TIGHT}; + struct SFSTaggerBaseOptions { /// @brief Tagging options /// @@ -123,97 +126,137 @@ namespace MA5 { /// B-Tagging // ///===============// - /// B-jet tagging efficiency (b as b) - virtual MAfloat32 b_tagging_eff(const RecJetFormat &object) const { return 1.; } + /// loose B-jet tagging efficiency (b as b) + virtual MAfloat32 loose_b_tagging_eff(const RecJetFormat &object) const { return 2.; } + + /// loose B-jet mistagging as C-jet (b as c) + virtual MAfloat32 loose_b_mistag_c(const RecJetFormat &object) const { return -1.; } + + /// mid B-jet tagging efficiency (b as b) + virtual MAfloat32 mid_b_tagging_eff(const RecJetFormat &object) const { return 2.; } + + /// loose B-jet mistagging as C-jet (b as c) + virtual MAfloat32 mid_b_mistag_c(const RecJetFormat &object) const { return -1.; } + + /// tight B-jet tagging efficiency (b as b) + virtual MAfloat32 tight_b_tagging_eff(const RecJetFormat &object) const { return 2.; } - /// B-jet mistagging as C-jet (b as c) - virtual MAfloat32 b_mistag_c(const RecJetFormat &object) const { return 0.; } + /// loose B-jet mistagging as C-jet (b as c) + virtual MAfloat32 tight_b_mistag_c(const RecJetFormat &object) const { return -1.; } //===============// // C-Tagging // //===============// - /// C-jet tagging efficiency (c as c) - virtual MAfloat32 c_tagging_eff(const RecJetFormat &object) const { return 1.; } + /// loose C-jet tagging efficiency (c as c) + virtual MAfloat32 loose_c_tagging_eff(const RecJetFormat &object) const { return 2.; } + + /// loose C-jet mistagging as C-jet (c as b) + virtual MAfloat32 loose_c_mistag_b(const RecJetFormat &object) const { return -1.; } + + /// mid C-jet tagging efficiency (c as c) + virtual MAfloat32 mid_c_tagging_eff(const RecJetFormat &object) const { return 2.; } + + /// mid C-jet mistagging as C-jet (c as b) + virtual MAfloat32 mid_c_mistag_b(const RecJetFormat &object) const { return -1.; } + + /// tight C-jet tagging efficiency (c as c) + virtual MAfloat32 tight_c_tagging_eff(const RecJetFormat &object) const { return 2.; } - /// C-jet mistagging as C-jet (c as b) - virtual MAfloat32 c_mistag_b(const RecJetFormat &object) const { return 0.; } + /// tight C-jet mistagging as C-jet (c as b) + virtual MAfloat32 tight_c_mistag_b(const RecJetFormat &object) const { return -1.; } //=======================// // Light-Jet Tagging // //=======================// - /// Light-Jet mistagging as b-jet (j as b) - virtual MAfloat32 lightjet_mistag_b(const RecJetFormat &object) const { return 0.; } + /// loose Light-Jet mistagging as b-jet (j as b) + virtual MAfloat32 lightjet_mistag_b_loose(const RecJetFormat &object) const { return -1.; } - /// Light-Jet mistagging as c jet (j as c) - virtual MAfloat32 lightjet_mistag_c(const RecJetFormat &object) const { return 0.; } + /// loose Light-Jet mistagging as c jet (j as c) + virtual MAfloat32 lightjet_mistag_c_loose(const RecJetFormat &object) const { return -1.; } - /// Light-Jet mistagging as tau (j as ta) - virtual MAfloat32 lightjet_mistag_tau(const RecJetFormat &object) const { return 0.; } + /// loose Light-Jet mistagging as tau (j as ta) + virtual MAfloat32 lightjet_mistag_tau_loose(const RecJetFormat &object) const { return -1.; } + + /// mid Light-Jet mistagging as b-jet (j as b) + virtual MAfloat32 lightjet_mistag_b_mid(const RecJetFormat &object) const { return -1.; } + + /// mid Light-Jet mistagging as c jet (j as c) + virtual MAfloat32 lightjet_mistag_c_mid(const RecJetFormat &object) const { return -1.; } + + /// mid Light-Jet mistagging as tau (j as ta) + virtual MAfloat32 lightjet_mistag_tau_mid(const RecJetFormat &object) const { return -1.; } + + /// tight Light-Jet mistagging as b-jet (j as b) + virtual MAfloat32 lightjet_mistag_b_tight(const RecJetFormat &object) const { return -1.; } + + /// tight Light-Jet mistagging as c jet (j as c) + virtual MAfloat32 lightjet_mistag_c_tight(const RecJetFormat &object) const { return -1.; } + + /// tight Light-Jet mistagging as tau (j as ta) + virtual MAfloat32 lightjet_mistag_tau_tight(const RecJetFormat &object) const { return -1.; } /// Light-Jet mistagging as electron (j as e) - virtual MAfloat32 lightjet_mistag_electron(const RecJetFormat &object) const { return 0.; } + virtual MAfloat32 lightjet_mistag_electron(const RecJetFormat &object) const { return -1.; } /// Light-Jet mistagging as photon (j as photon) - virtual MAfloat32 lightjet_mistag_photon(const RecJetFormat &object) const { return 0.; } + virtual MAfloat32 lightjet_mistag_photon(const RecJetFormat &object) const { return -1.; } //=================// // Tau Tagging // //=================// /// Convert jet to tau - MAfloat32 tau_tagging_eff(const RecJetFormat &jet) const - { - RecTauFormat myTau; - myTau.setMomentum(jet.momentum()); - myTau.ntracks_ = jet.ntracks(); - myTau.mc_ = jet.mc_; + MAfloat32 tau_tagging_eff(const RecJetFormat &jet, TaggerStatus status) const; - return tau_tagging_eff(myTau); - } + /// loose_Tau tagging efficiency (ta as ta) + virtual MAfloat32 loose_tau_tagging_eff(const RecTauFormat &object) const { return 2.; } + + /// mid_Tau tagging efficiency (ta as ta) + virtual MAfloat32 mid_tau_tagging_eff(const RecTauFormat &object) const { return 2.; } - /// Tau tagging efficiency (ta as ta) - virtual MAfloat32 tau_tagging_eff(const RecTauFormat &object) const { return 1.; } + /// tight_Tau tagging efficiency (ta as ta) + virtual MAfloat32 tight_tau_tagging_eff(const RecTauFormat &object) const { return 2.; } //=======================// // Electron Tagging // //======================// /// Electron mistagging as muon (e as mu) - virtual MAfloat32 electron_mistag_muon(const RecLeptonFormat &object) const { return 0.; } + virtual MAfloat32 electron_mistag_muon(const RecLeptonFormat &object) const { return -1.; } /// Electron mistagging as photon (e as a) - virtual MAfloat32 electron_mistag_photon(const RecLeptonFormat &object) const { return 0.; } + virtual MAfloat32 electron_mistag_photon(const RecLeptonFormat &object) const { return -1.; } /// Electron mistagging as light jet (e as j) - virtual MAfloat32 electron_mistag_lightjet(const RecLeptonFormat &object) const { return 0.; } + virtual MAfloat32 electron_mistag_lightjet(const RecLeptonFormat &object) const { return -1.; } //==================// // Muon Tagging // //==================// /// Electron mistagging as electron (mu as e) - virtual MAfloat32 muon_mistag_electron(const RecLeptonFormat &object) const { return 0.; } + virtual MAfloat32 muon_mistag_electron(const RecLeptonFormat &object) const { return -1.; } /// Electron mistagging as photon (mu as a) - virtual MAfloat32 muon_mistag_photon(const RecLeptonFormat &object) const { return 0.; } + virtual MAfloat32 muon_mistag_photon(const RecLeptonFormat &object) const { return -1.; } /// Electron mistagging as light jet (mu as j) - virtual MAfloat32 muon_mistag_lightjet(const RecLeptonFormat &object) const { return 0.; } + virtual MAfloat32 muon_mistag_lightjet(const RecLeptonFormat &object) const { return -1.; } //====================// // Photon Tagging // //====================// /// Electron mistagging as electron (a as e) - virtual MAfloat32 photon_mistag_electron(const RecPhotonFormat &object) const { return 0.; } + virtual MAfloat32 photon_mistag_electron(const RecPhotonFormat &object) const { return -1.; } /// Electron mistagging as muon (a as mu) - virtual MAfloat32 photon_mistag_muon(const RecPhotonFormat &object) const { return 0.; } + virtual MAfloat32 photon_mistag_muon(const RecPhotonFormat &object) const { return -1.; } /// Electron mistagging as light jet (a as j) - virtual MAfloat32 photon_mistag_lightjet(const RecPhotonFormat &object) const { return 0.; } + virtual MAfloat32 photon_mistag_lightjet(const RecPhotonFormat &object) const { return -1.; } }; } diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp index 9a939351..6b10b474 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp @@ -25,9 +25,6 @@ #ifdef MA5_FASTJET_MODE -// FastJet headers -#include "fastjet/PseudoJet.hh" - namespace MA5 { /// Clear all information @@ -164,6 +161,30 @@ namespace MA5 { /// Setting a new Tight_tautag_ value void RecJetFormat::setTightTautag(const MAbool& tag) { tight_tautag_ = tag; } + /// Set all b-tags + void RecJetFormat::setAllBtags(const MAbool &tag) { + true_btag_ = tag; + loose_btag_ = tag; + mid_btag_ = tag; + tight_btag_ = tag; + } + + /// Set all c-tags + void RecJetFormat::setAllCtags(const MAbool &tag) { + true_ctag_ = tag; + loose_ctag_ = tag; + mid_ctag_ = tag; + tight_ctag_ = tag; + } + + /// Set all tau-tags + void RecJetFormat::setAllTautags(const MAbool &tag) { + true_tautag_ = tag; + loose_tautag_ = tag; + mid_tautag_ = tag; + tight_tautag_ = tag; + } + // return a vector of all subjets of the current jet (in the sense of the exclusive algorithm) // that would be obtained when running the algorithm with the given dcut. std::vector RecJetFormat::exclusive_subjets(MAfloat32 dcut) const diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h index 01e252c3..499d4fe1 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h @@ -265,6 +265,15 @@ namespace MA5 /// Setting a new Tight_tautag_ value void setTightTautag(const MAbool& tag); + /// Set all b-tags + void setAllBtags(const MAbool& tag); + + /// Set all c-tags + void setAllCtags(const MAbool& tag); + + /// Set all tau-tags + void setAllTautags(const MAbool& tag); + /// Add one constituent void AddConstituent (const MAint32& index); From fa6136381c1aaec8e49978778e6a06a13078cfc4 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Wed, 22 Jun 2022 16:31:35 +0100 Subject: [PATCH 28/67] butfix in hadron based tau tagging --- tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index 2b8d901f..54e5036e 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -213,7 +213,7 @@ namespace MA5 { /// @attention In Jet based tau tagging this loop will not run. If its runnning thats a bug for (MAuint32 itau = 0; itau < Ntau; itau++) { - if (RANDOM->flat() > tau_tagging_eff(myEvent.rec()->taus()[itau])) + if (RANDOM->flat() > loose_tau_tagging_eff(myEvent.rec()->taus()[itau])) { RecJetFormat* NewParticle = myEvent.rec()->GetNewJet(); NewParticle->setMomentum((&myEvent.rec()->taus()[itau])->momentum()); From 793104898b29fbbd251c0636edc299807cf5ed53 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Wed, 22 Jun 2022 16:35:07 +0100 Subject: [PATCH 29/67] adapt packages to the new tagger --- .../Process/JetClustering/TauTagger.cpp | 315 --------------- .../Process/JetClustering/TauTagger.h | 96 ----- .../Process/JetClustering/bTagger.cpp | 367 ------------------ .../Process/JetClustering/bTagger.h | 99 ----- .../Process/JetClustering/cTagger.cpp | 260 ------------- .../Process/JetClustering/cTagger.h | 79 ---- .../Process/Reader/LHCOReader.cpp | 4 +- 7 files changed, 2 insertions(+), 1218 deletions(-) delete mode 100644 tools/SampleAnalyzer/Process/JetClustering/TauTagger.cpp delete mode 100644 tools/SampleAnalyzer/Process/JetClustering/TauTagger.h delete mode 100644 tools/SampleAnalyzer/Process/JetClustering/bTagger.cpp delete mode 100644 tools/SampleAnalyzer/Process/JetClustering/bTagger.h delete mode 100644 tools/SampleAnalyzer/Process/JetClustering/cTagger.cpp delete mode 100644 tools/SampleAnalyzer/Process/JetClustering/cTagger.h diff --git a/tools/SampleAnalyzer/Process/JetClustering/TauTagger.cpp b/tools/SampleAnalyzer/Process/JetClustering/TauTagger.cpp deleted file mode 100644 index dd30e608..00000000 --- a/tools/SampleAnalyzer/Process/JetClustering/TauTagger.cpp +++ /dev/null @@ -1,315 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks -// The MadAnalysis development team, email: -// -// This file is part of MadAnalysis 5. -// Official website: -// -// MadAnalysis 5 is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// MadAnalysis 5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with MadAnalysis 5. If not, see -// -//////////////////////////////////////////////////////////////////////////////// - - -// STL headers -#include - -// SampleAnalyzer headers -#include "SampleAnalyzer/Process/JetClustering/TauTagger.h" -#include "SampleAnalyzer/Commons/Service/RandomService.h" -#include "SampleAnalyzer/Commons/Service/ExceptionService.h" - - -using namespace MA5; - - -void TauTagger::Method1 (SampleFormat& mySample, EventFormat& myEvent) -{ - // Performing mis-id - if (doMisefficiency_) - { - std::vector toRemove; - for (MAuint32 i=0;ijets().size();i++) - { - // keeping only light jets - if (myEvent.rec()->jets()[i].true_ctag_ || - myEvent.rec()->jets()[i].true_btag_) continue; - - // simulating mis-id - if (RANDOM->flat() < misid_ljet_) - { - RecTauFormat* myTau = myEvent.rec()->GetNewTau(); - Jet2Tau(&myEvent.rec()->jets()[i], myTau, myEvent); - toRemove.push_back(i); - } - } - for (MAint32 i=toRemove.size()-1; i>=0;i--) - { - myEvent.rec()->jets().erase(myEvent.rec()->jets().begin() - + toRemove[i]); - } - } - -} - -void TauTagger::Method2 (SampleFormat& mySample, EventFormat& myEvent) -{ - std::vector Candidates; - - for (MAuint32 i=0;ijets().size();i++) - { - if (myEvent.rec()->jets()[i].ntracks()!=1 && myEvent.rec()->jets()[i].ntracks()!=3) continue; - - MAbool tag = false; - // Loop on the jets constituents - for (MAuint32 j=0;jjets()[i].Constituents_.size();j++) - { - // Searching for a tau in the history - MAint32 N = myEvent.rec()->jets()[i].Constituents_[j]; - MCParticleFormat* particle = & myEvent.mc()->particles()[N]; - while (!tag) - { - if (particle==0) - { - ERROR << "No particle" << endmsg; - break; - } - if (particle->statuscode()==3) break; - - if (std::abs(particle->pdgid())==15) - { - tag = true; - myEvent.rec()->jets()[i].mc_ = particle; - break; - } - - if (particle->mothers().size()>1 && particle->mothers()[1]!=particle->mothers()[0]) break; - - particle = particle->mothers()[0]; - } - - if (tag) break; - } - - if (tag) Candidates.push_back(& myEvent.rec()->jets()[i]); - } - - if (Exclusive_) - { - MAuint32 i = 0; - MAuint32 n = Candidates.size(); - - while (imc()->dr(Candidates[i]); - - while (jmc()==Candidates[j]->mc()) - { - MAfloat32 DeltaR2 = Candidates[j]->mc()->dr(Candidates[j]); - - if (DeltaR20;i--) - { - RecTauFormat* myTau = myEvent.rec()->GetNewTau(); - Jet2Tau(Candidates[i-1], myTau, myEvent); - // BENJ PB COMPIL: myEvent.rec()->jets().erase((std::vector::iterator) Candidates[i-1]); - - // Remove the tau-identified jet from the list - MAuint32 pos=myEvent.rec()->jets().size(); - for (MAuint32 ind=0;indjets().size();ind++) - { - if (&(myEvent.rec()->jets()[ind])==Candidates[i-1]) {pos=ind;break;} - } - if (pos!=myEvent.rec()->jets().size()) // must never happen - myEvent.rec()->jets().erase(myEvent.rec()->jets().begin()+pos); - } - Candidates.clear(); -} - -void TauTagger::Method3 (SampleFormat& mySample, EventFormat& myEvent) -{ - std::vector Candidates; - - // Jets preselection using method 2 - for (MAuint32 i=0;ijets().size();i++) - { - if (myEvent.rec()->jets()[i].ntracks()!=1 && myEvent.rec()->jets()[i].ntracks()!=3) continue; - - MAbool tag = false; - for (MAuint32 j=0;jjets()[i].Constituents_.size();j++) - { - MAint32 N = myEvent.rec()->jets()[i].Constituents_[j]; - MCParticleFormat* particle = & myEvent.mc()->particles()[N]; - while (!tag) - { - if (particle==0) - { - ERROR << "No particle" << endmsg; - break; - } - - if (particle->statuscode()==3) break; - - if (std::abs(particle->pdgid())==15) - { - tag = true; - myEvent.rec()->jets()[i].mc_ = particle; - break; - } - - if (particle->mothers().size()>1 && particle->mothers()[1]!=particle->mothers()[0]) break; - - particle = particle->mothers()[0]; - } - - if (tag) break; - } - - if (tag) Candidates.push_back(& myEvent.rec()->jets()[i]); - } - - std::vector Taus; - - // tau-tagging using method 1 - for (MAuint32 i=0;iparticles().size();i++) - { - if (std::abs(myEvent.mc()->particles()[i].pdgid())!=15) continue; - - if (!IsLast(&myEvent.mc()->particles()[i], myEvent)) continue; - - MAfloat64 DeltaRmax = DeltaRmax_; - MAbool tag = false; - - for (MAuint32 j=Candidates.size();j>0;j--) - { - MAfloat32 DeltaR = myEvent.mc()->particles()[i].dr(Candidates[j-1]); - - if (DeltaR <= DeltaRmax) - { - if (Exclusive_) - { - if (tag) Taus.pop_back(); - tag = true; - DeltaRmax = DeltaR; - } - Taus.push_back(Candidates[j-1]); - Candidates.erase(Candidates.begin()+j-1); - } - } - } - - sort(Taus.begin(),Taus.end()); - - for (MAuint32 j=Taus.size();j>0;j--) - { - RecTauFormat* myTau = myEvent.rec()->GetNewTau(); - Jet2Tau(Taus[j-1], myTau, myEvent); - // PB Benj compil: myEvent.rec()->jets().erase((std::vector::iterator) Taus[j-1]); - - // Remove the tau-identified jet from the list - MAuint32 pos=myEvent.rec()->jets().size(); - for (MAuint32 ind=0;indjets().size();ind++) - { - if (&(myEvent.rec()->jets()[ind])==Taus[j-1]) {pos=ind;break;} - } - if (pos!=myEvent.rec()->jets().size()) // must never happen - myEvent.rec()->jets().erase(myEvent.rec()->jets().begin()+pos); - - - } - - Taus.clear(); - Candidates.clear(); -} - - -void TauTagger::Jet2Tau (RecJetFormat* myJet, RecTauFormat* myTau, EventFormat& myEvent) -{ - myTau->setMomentum(myJet->momentum()); - myTau->ntracks_ = myJet->ntracks(); - myTau->mc_ = myJet->mc_; - myTau->DecayMode_ = PHYSICS->GetTauDecayMode(myTau->mc_); - - MAint32 charge = 0; - - for (MAuint32 i=0;iConstituents_.size();i++) - { - charge += PDG->GetCharge(myEvent.mc()->particles()[myJet->Constituents_[i]].pdgid()); - } - - if (charge>0) myTau->charge_ = true; - else if (charge<=0) myTau->charge_ = false; -} - - -MAbool TauTagger::SetParameter(const std::string& key, - const std::string& value, - std::string header) -{ - // miss-id efficiency - if (key=="misid_ljet") - { - MAfloat32 tmp=0; - std::stringstream str; - str << value; - str >> tmp; - if (tmp<0) - { - WARNING << "'misid_ljet' efficiency must be a positive value. " - << "Using the default value = " - << misid_ljet_ << endmsg; - } - else if (tmp>1) - { - WARNING << "'misid_ljet' efficiency cannot be greater than 1. " - << "Using the default value = " - << misid_ljet_ << endmsg; - } - else misid_ljet_=tmp; - if (misid_ljet_==0.0) doMisefficiency_=false; else doMisefficiency_=true; - } - - // Other - else return TaggerBase::SetParameter(key,value,header); - - return true; - -} - - -std::string TauTagger::GetParameters() -{ - std::stringstream str; - str << "IDeff=" << Efficiency_; - str << " ; MisID(q)=" << misid_ljet_; - return str.str(); -} diff --git a/tools/SampleAnalyzer/Process/JetClustering/TauTagger.h b/tools/SampleAnalyzer/Process/JetClustering/TauTagger.h deleted file mode 100644 index 8384d637..00000000 --- a/tools/SampleAnalyzer/Process/JetClustering/TauTagger.h +++ /dev/null @@ -1,96 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks -// The MadAnalysis development team, email: -// -// This file is part of MadAnalysis 5. -// Official website: -// -// MadAnalysis 5 is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// MadAnalysis 5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with MadAnalysis 5. If not, see -// -//////////////////////////////////////////////////////////////////////////////// - - -#ifndef TAUTAGGER_H -#define TAUTAGGER_H - - -// SampleAnalyser headers -#include "SampleAnalyzer/Commons/Base/TaggerBase.h" - - -namespace MA5 -{ - -class TauTagger: public TaggerBase -{ -//--------------------------------------------------------------------------------- -// data members -//--------------------------------------------------------------------------------- - protected : - - /// Mis-identification efficiency - MAfloat32 misid_ljet_; - - /// Apply misefficiency - MAbool doMisefficiency_; - // TH1F* htest; - -//--------------------------------------------------------------------------------- -// method members -//--------------------------------------------------------------------------------- - public : - - /// Constructor without argument - TauTagger () - { - misid_ljet_=0.0; - doMisefficiency_=false; - // htest = new TH1F("eric","eric",10,0,10); - } - - /// Destructor - virtual ~TauTagger () - { /*htest->SaveAs("Alloul.root");*/ } - - /// Matching using dr - virtual void Method1 (SampleFormat& mySample, EventFormat& myEvent); - - /// Matching using the history - virtual void Method2 (SampleFormat& mySample, EventFormat& myEvent); - - /// Matching using a jet preselection with the history before calculating dr - virtual void Method3 (SampleFormat& mySample, EventFormat& myEvent); - - /// Matching general method - virtual void Execute(SampleFormat& mySample, EventFormat& myEvent) - { - if (Method_==1) Method1(mySample,myEvent); - else if (Method_==2) Method2(mySample,myEvent); - else if (Method_==3) Method3(mySample,myEvent); - } - - /// Fill the Tau format with the information from the jet format - void Jet2Tau (RecJetFormat* myJet, RecTauFormat* myTau, EventFormat& myEvent); - - /// Set a parameter - virtual MAbool SetParameter(const std::string& key, const std::string& value,std::string header); - - virtual std::string GetParameters(); - -}; - -} - -#endif diff --git a/tools/SampleAnalyzer/Process/JetClustering/bTagger.cpp b/tools/SampleAnalyzer/Process/JetClustering/bTagger.cpp deleted file mode 100644 index 4bde6e28..00000000 --- a/tools/SampleAnalyzer/Process/JetClustering/bTagger.cpp +++ /dev/null @@ -1,367 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks -// The MadAnalysis development team, email: -// -// This file is part of MadAnalysis 5. -// Official website: -// -// MadAnalysis 5 is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// MadAnalysis 5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with MadAnalysis 5. If not, see -// -//////////////////////////////////////////////////////////////////////////////// - - -// SampleAnalyzer headesr -#include "SampleAnalyzer/Commons/Service/RandomService.h" -#include "SampleAnalyzer/Process/JetClustering/bTagger.h" -#include - - -using namespace MA5; - - -void bTagger::Method1 (SampleFormat& mySample, EventFormat& myEvent) -{ - std::vector Candidates; - - // Matching b-quarks to jets - for (MAuint32 i=0;iMCBquarks_.size();i++) - { - RecJetFormat* tag = 0; - MAfloat64 DeltaRmax = DeltaRmax_; - - // loop on the jets - for (MAuint32 j=0;jjets().size();j++) - { - if (myEvent.rec()->jets()[j].pt()<1e-10) continue; - MAfloat32 DeltaR = myEvent.rec()->MCBquarks_[i]->dr(myEvent.rec()->jets()[j]); - - if (DeltaR <= DeltaRmax) - { - if (Exclusive_) - { - tag = &(myEvent.rec()->jets()[j]); - DeltaRmax = DeltaR; - } - else Candidates.push_back(& myEvent.rec()->jets()[j]); - } - } - if (Exclusive_ && tag!=0) Candidates.push_back(tag); - } - - // Tagging the b-jet - for (MAuint32 i=0;itrue_btag_ = true; - } - Candidates.clear(); - - // Matching c-quarks to jets - for (MAuint32 i=0;iMCCquarks_.size();i++) - { - RecJetFormat* tag = 0; - MAfloat64 DeltaRmax = DeltaRmax_; - - // loop on the jets - for (MAuint32 j=0;jjets().size();j++) - { - if (myEvent.rec()->jets()[j].pt()<1e-10) continue; - - MAfloat32 DeltaR = - myEvent.rec()->MCCquarks_[i]->dr(myEvent.rec()->jets()[j]); - - if (DeltaR <= DeltaRmax) - { - if (Exclusive_) - { - tag = &(myEvent.rec()->jets()[j]); - DeltaRmax = DeltaR; - } - else Candidates.push_back(& myEvent.rec()->jets()[j]); - } - } - if (Exclusive_ && tag!=0) Candidates.push_back(tag); - } - - // Tagging the c-jet - for (MAuint32 i=0;itrue_btag_) continue; - Candidates[i]->true_ctag_ = true; - } - - // Identification and misidentification - for (MAuint32 i=0;ijets().size();i++) - { - RecJetFormat* jet = &(myEvent.rec()->jets()[i]); - - // 100% identification - if (jet->true_btag_) jet->btag_=true; - if (!doEfficiency_ && !doMisefficiency_) continue; - - // identification efficiency - if (doEfficiency_ && jet->true_btag_) - { - if (RANDOM->flat() >= Efficiency_) jet->btag_=false; - } - - // mis-identification (c-quark) - if (doMisefficiency_ && !jet->true_btag_ && jet->true_ctag_) - { - if (RANDOM->flat() < misid_cjet_) jet->btag_=true; - } - - // mis-identification (light quarks) - else if (doMisefficiency_ && !jet->true_btag_ && !jet->true_ctag_) - { - if (RANDOM->flat() < misid_ljet_) jet->btag_=true; - } - } - -} - -void bTagger::Method2 (SampleFormat& mySample, EventFormat& myEvent) -{ - std::vector Candidates; - - for (MAuint32 i=0;ijets().size();i++) - { - MAbool b = false; - - for (MAuint32 j=0;jjets()[i].Constituents_.size();j++) - { - MAint32 N = myEvent.rec()->jets()[i].Constituents_[j]; - MCParticleFormat* particle = & myEvent.mc()->particles()[N]; - while (!b) - { - if (particle==0) - { - INFO << "No particle" << endmsg; - break; - } - - if (particle->statuscode()==3) break; - - if (PHYSICS->Id->IsBHadron(particle->pdgid()) && IsLastBHadron(particle, myEvent)) - { - b = true; - myEvent.rec()->jets()[i].mc_ = particle; - break; - } - - if (particle->mothers().size()>1 && particle->mothers()[1]!=particle->mothers()[0]) break; - - particle = particle->mothers()[0]; - } - - if (b) break; - } - - if (b) Candidates.push_back(& myEvent.rec()->jets()[i]); - } - - if (Exclusive_) - { - MAuint32 i = 0; - MAuint32 n = Candidates.size(); - - while (imc()->dr(Candidates[i]); - - while (jmc()==Candidates[j]->mc()) - { - MAfloat32 DeltaR2 = Candidates[j]->mc()->dr(Candidates[j]); - - if (DeltaR2btag_ = true; - } -} - -void bTagger::Method3 (SampleFormat& mySample, EventFormat& myEvent) -{ - std::vector Candidates; - - // jet preselection using method 2 - for (MAuint32 i=0;ijets().size();i++) - { - MAbool b = false; - - for (MAuint32 j=0;jjets()[i].Constituents_.size();j++) - { - MAint32 N = myEvent.rec()->jets()[i].Constituents_[j]; - MCParticleFormat* particle = & myEvent.mc()->particles()[N]; - while (!b) - { - if (particle==0) - { - INFO << "No particle" << endmsg; - break; - } - - if (particle->statuscode()==3) break; - - if (PHYSICS->Id->IsBHadron(particle->pdgid()) && IsLastBHadron(particle, myEvent)) - { - b = true; - myEvent.rec()->jets()[i].mc_ = particle; - break; - } - - if (particle->mothers().size()>1 && particle->mothers()[1]!=particle->mothers()[0]) break; - - particle = particle->mothers()[0]; - } - - if (b) break; - } - - if (b) Candidates.push_back(& myEvent.rec()->jets()[i]); - } - - // b-tagging using method 1 - for (MAuint32 i=0;iparticles().size();i++) - { - if (std::abs(myEvent.mc()->particles()[i].pdgid())!=5) continue; - - if (!IsLast(&myEvent.mc()->particles()[i], myEvent)) continue; - - MAuint32 k = 0; - - for (MAuint32 j=Candidates.size();j>0;j--) - { - MAfloat32 DeltaR = myEvent.mc()->particles()[i].dr(Candidates[j-1]); - - if (DeltaR <= DeltaRmax_) - { - k++; - std::swap (Candidates[j-1], Candidates[Candidates.size()-k]); - } - } - - if (Exclusive_) - { - while (k>1) - { - if (Candidates[Candidates.size()-1]->e() > Candidates[Candidates.size()-2]->e()) std::swap(Candidates[Candidates.size()-1], Candidates[Candidates.size()-2]); - Candidates.pop_back(); - k--; - } - } - - for (MAuint32 j=0;jbtag_=true; - Candidates.pop_back(); - } - } - - Candidates.clear(); -} - -MAbool bTagger::IsLastBHadron(MCParticleFormat* part, EventFormat& myEvent) -{ - for (MAuint32 i=0; iparticles().size(); i++) - { - if (myEvent.mc()->particles()[i].mothers()[0]== part) - { - if (PHYSICS->Id->IsBHadron(myEvent.mc()->particles()[i].pdgid())) return false; - } - } - return true; -} - - -MAbool bTagger::SetParameter(const std::string& key, - const std::string& value, - std::string header) -{ - // miss-id efficiency - if (key=="misid_ljet") - { - MAfloat32 tmp=0; - std::stringstream str; - str << value; - str >> tmp; - if (tmp<0) - { - WARNING << "'misid_ljet' efficiency must be a positive value. " - << "Using the default value = " - << misid_ljet_ << endmsg; - } - else if (tmp>1) - { - WARNING << "'misid_ljet' efficiency cannot be greater than 1. " - << "Using the default value = " - << misid_ljet_ << endmsg; - } - else misid_ljet_=tmp; - if (misid_ljet_!=0.0) doMisefficiency_=true; - } - - // miss-id efficiency - else if (key=="misid_cjet") - { - MAfloat32 tmp=0; - std::stringstream str; - str << value; - str >> tmp; - if (tmp<0) - { - WARNING << "'misid_cjet' efficiency must be a positive value. " - << "Using the default value = " - << misid_cjet_ << endmsg; - } - else if (tmp>1) - { - WARNING << "'misid_cjet' efficiency cannot be greater than 1. " - << "Using the default value = " - << misid_cjet_ << endmsg; - } - else misid_cjet_=tmp; - if (misid_cjet_!=0.0) doMisefficiency_=true; - } - - // Other - else return TaggerBase::SetParameter(key,value,header); - return true; -} - -std::string bTagger::GetParameters() -{ - std::stringstream str; - str << "dR=" << DeltaRmax_ << " ; "; - if (Exclusive_) str << "Exclusive ; "; else str << "Inclusive ; "; - str << "IDeff=" << Efficiency_; - str << " ; MisID(c)=" << misid_cjet_; - str << " ; MisID(q)=" << misid_ljet_; - return str.str(); -} diff --git a/tools/SampleAnalyzer/Process/JetClustering/bTagger.h b/tools/SampleAnalyzer/Process/JetClustering/bTagger.h deleted file mode 100644 index 01038734..00000000 --- a/tools/SampleAnalyzer/Process/JetClustering/bTagger.h +++ /dev/null @@ -1,99 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks -// The MadAnalysis development team, email: -// -// This file is part of MadAnalysis 5. -// Official website: -// -// MadAnalysis 5 is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// MadAnalysis 5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with MadAnalysis 5. If not, see -// -//////////////////////////////////////////////////////////////////////////////// - - -#ifndef BTAGGER_H -#define BTAGGER_H - - -// SampleAnalyzer headers -#include "SampleAnalyzer/Commons/Base/TaggerBase.h" - - -namespace MA5 -{ - -class bTagger:public TaggerBase -{ -//--------------------------------------------------------------------------------- -// data members -//--------------------------------------------------------------------------------- - - protected : - - /// Mis-identification efficiency - MAfloat32 misid_ljet_; - - /// Mis-identification efficiency - MAfloat32 misid_cjet_; - - /// Apply misefficiency - MAbool doMisefficiency_; - - -//--------------------------------------------------------------------------------- -// method members -//--------------------------------------------------------------------------------- - public : - - /// Constructor without argument - bTagger() - { - misid_cjet_=0.0; - misid_ljet_=0.0; - doMisefficiency_=false; - } - - /// Destructor - virtual ~bTagger() {} - - /// Matching using dr - virtual void Method1 (SampleFormat& mySample, EventFormat& myEvent); - - /// Matching using the history - virtual void Method2 (SampleFormat& mySample, EventFormat& myEvent); - - /// Matching using a jet preselection with the history before calculating dr - virtual void Method3 (SampleFormat& mySample, EventFormat& myEvent); - - /// Matching general method - virtual void Execute(SampleFormat& mySample, EventFormat& myEvent) - { - if (Method_==1) Method1(mySample,myEvent); - else if (Method_==2) Method2(mySample,myEvent); - else if (Method_==3) Method3(mySample,myEvent); - } - - /// Is this B hadron the last in the decay chain ? - MAbool IsLastBHadron(MCParticleFormat* part, EventFormat& myEvent); - - /// Set a parameter - virtual MAbool SetParameter(const std::string& key, const std::string& value,std::string header); - - virtual std::string GetParameters(); - -}; - -} - -#endif diff --git a/tools/SampleAnalyzer/Process/JetClustering/cTagger.cpp b/tools/SampleAnalyzer/Process/JetClustering/cTagger.cpp deleted file mode 100644 index e96f0158..00000000 --- a/tools/SampleAnalyzer/Process/JetClustering/cTagger.cpp +++ /dev/null @@ -1,260 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks -// The MadAnalysis development team, email: -// -// This file is part of MadAnalysis 5. -// Official website: -// -// MadAnalysis 5 is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// MadAnalysis 5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with MadAnalysis 5. If not, see -// -//////////////////////////////////////////////////////////////////////////////// - - -// SampleAnalyzer headers -#include "SampleAnalyzer/Process/JetClustering/cTagger.h" - -// STL headers -#include - - -using namespace MA5; - -// Matching using dr -void cTagger::Method1 (SampleFormat& mySample, EventFormat& myEvent) -{ - std::vector Candidates; - - // loop on the particles searching for last c - for (MAuint32 i=0;iparticles().size();i++) - { - if (PHYSICS->Id->IsInitialState(myEvent.mc()->particles()[i])) continue; - if (std::abs(myEvent.mc()->particles()[i].pdgid())!=4) continue; - if (!IsLast(&myEvent.mc()->particles()[i], myEvent)) continue; - - MAbool tag = false; - MAfloat64 DeltaRmax = DeltaRmax_; - - // loop on the jets - for (MAuint32 j=0;jjets().size();j++) - { - if (myEvent.rec()->jets()[j].btag()) continue; - - // Calculating DeltaR - MAfloat32 DeltaR = myEvent.mc()->particles()[i].dr(myEvent.rec()->jets()[j]); - - // Adding the jet to the candidates if DeltaR <= DeltaRmax - if (DeltaR <= DeltaRmax) - { - if (Exclusive_) - { - if (tag) Candidates.pop_back(); - tag = true; - DeltaRmax = DeltaR; - } - Candidates.push_back(& myEvent.rec()->jets()[j]); - } - } - - // Tagging the candidates - for (MAuint32 i=0;itrue_ctag_ = true; - } - - Candidates.clear(); - } -} - -// Matching using history -void cTagger::Method2 (SampleFormat& mySample, EventFormat& myEvent) -{ - std::vector Candidates; - - for (MAuint32 i=0;ijets().size();i++) - { - if (myEvent.rec()->jets()[i].btag()) continue; - - MAbool c = false; - - for (MAuint32 j=0;jjets()[i].Constituents_.size();j++) - { - MAint32 N = myEvent.rec()->jets()[i].Constituents_[j]; - MCParticleFormat* particle = & myEvent.mc()->particles()[N]; - while (!c) - { - if (particle==0) - { - INFO << "No particle" << endmsg; - break; - } - - if (particle->statuscode()==3) break; - - if (PHYSICS->Id->IsCHadron(particle->pdgid()) && IsLastCHadron(particle, myEvent)) - { - c = true; - myEvent.rec()->jets()[i].mc_ = particle; - break; - } - - if (particle->mothers()[1]!=0 && particle->mothers()[1]!=particle->mothers()[0]) break; - - particle = particle->mothers()[0]; - } - - if (c) break; - } - - if (c) Candidates.push_back(& myEvent.rec()->jets()[i]); - } - - if (Exclusive_) - { - MAuint32 i = 0; - MAuint32 n = Candidates.size(); - - while (imc()->dr(Candidates[i]); - - while (jmc()==Candidates[j]->mc()) - { - MAfloat32 DeltaR2 = Candidates[j]->mc()->dr(Candidates[j]); - - if (DeltaR2true_ctag_ = true; - } - - Candidates.clear(); -} - -void cTagger::Method3 (SampleFormat& mySample, EventFormat& myEvent) -{ - std::vector Candidates; - - // jet preselection using method 2 - for (MAuint32 i=0;ijets().size();i++) - { - if (myEvent.rec()->jets()[i].btag()) continue; - - MAbool c = false; - - for (MAuint32 j=0;jjets()[i].Constituents_.size();j++) - { - MAint32 N = myEvent.rec()->jets()[i].Constituents_[j]; - MCParticleFormat* particle = & myEvent.mc()->particles()[N]; - while (!c) - { - if (particle==0) - { - INFO << "No particle" << endmsg; - break; - } - - if (particle->statuscode()==3) break; - - if (PHYSICS->Id->IsCHadron(particle->pdgid()) && IsLastCHadron(particle, myEvent)) - { - c = true; - myEvent.rec()->jets()[i].mc_ = particle; - break; - } - - if (particle->mothers()[1]!=0 && particle->mothers()[1]!=particle->mothers()[0]) break; - - particle = particle->mothers()[0]; - } - - if (c) break; - } - - if (c) Candidates.push_back(& myEvent.rec()->jets()[i]); - } - - // c-tagging using method 1 - for (MAuint32 i=0;iparticles().size();i++) - { - if (std::abs(myEvent.mc()->particles()[i].pdgid())!=4) continue; - - if (!IsLast(&myEvent.mc()->particles()[i], myEvent)) continue; - - MAuint32 k = 0; - - for (MAuint32 j=Candidates.size();j>0;j--) - { - MAfloat32 DeltaR = myEvent.mc()->particles()[i].dr(Candidates[j-1]); - - if (DeltaR <= DeltaRmax_) - { - k++; - std::swap (Candidates[j-1], Candidates[Candidates.size()-k]); - } - } - - if (Exclusive_) - { - while (k>1) - { - if (Candidates[Candidates.size()-1]->e() > Candidates[Candidates.size()-2]->e()) std::swap(Candidates[Candidates.size()-1], Candidates[Candidates.size()-2]); - Candidates.pop_back(); - k--; - } - } - - for (MAuint32 j=0;jtrue_ctag_=true; - Candidates.pop_back(); - } - } - - Candidates.clear(); -} - -MAbool cTagger::IsLastCHadron(MCParticleFormat* part, EventFormat& myEvent) -{ - for (MAuint32 i=0; iparticles().size(); i++) - { - if (myEvent.mc()->particles()[i].mothers()[0]== part) - { - if (PHYSICS->Id->IsCHadron(myEvent.mc()->particles()[i].pdgid())) return false; - } - } - return true; -} - -std::string cTagger::GetParameters() -{ - std::stringstream str; - // str << "R=" << R_ << " ; p=" << p_ << " ; PTmin=" << Ptmin_; - return str.str(); -} diff --git a/tools/SampleAnalyzer/Process/JetClustering/cTagger.h b/tools/SampleAnalyzer/Process/JetClustering/cTagger.h deleted file mode 100644 index beedb8e7..00000000 --- a/tools/SampleAnalyzer/Process/JetClustering/cTagger.h +++ /dev/null @@ -1,79 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks -// The MadAnalysis development team, email: -// -// This file is part of MadAnalysis 5. -// Official website: -// -// MadAnalysis 5 is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// MadAnalysis 5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with MadAnalysis 5. If not, see -// -//////////////////////////////////////////////////////////////////////////////// - - -#ifndef CTAGGER_H -#define CTAGGER_H - - -// SampleAnalyzer headers -#include "SampleAnalyzer/Commons/Base/TaggerBase.h" - - -namespace MA5 -{ - -class cTagger:public TaggerBase -{ -//--------------------------------------------------------------------------------- -// data members -//--------------------------------------------------------------------------------- - -//--------------------------------------------------------------------------------- -// method members -//--------------------------------------------------------------------------------- - public : - - /// Constructor without argument - cTagger() {} - - /// Destructor - virtual ~cTagger () {} - - /// Matching using dr - virtual void Method1 (SampleFormat& mySample, EventFormat& myEvent); - - /// Matching using the history - virtual void Method2 (SampleFormat& mySample, EventFormat& myEvent); - - /// Matching using a jet preselection with the history before calculating dr - virtual void Method3 (SampleFormat& mySample, EventFormat& myEvent); - - /// Matching general method - virtual void Execute(SampleFormat& mySample, EventFormat& myEvent) - { - if (Method_==1) Method1(mySample,myEvent); - else if (Method_==2) Method2(mySample,myEvent); - else if (Method_==3) Method3(mySample,myEvent); - } - - /// Is this C hadron the last in the decay chain ? - MAbool IsLastCHadron(MCParticleFormat* part, EventFormat& myEvent); - - virtual std::string GetParameters(); - -}; - -} - -#endif diff --git a/tools/SampleAnalyzer/Process/Reader/LHCOReader.cpp b/tools/SampleAnalyzer/Process/Reader/LHCOReader.cpp index 3f17dc1a..8a5bc02d 100644 --- a/tools/SampleAnalyzer/Process/Reader/LHCOReader.cpp +++ b/tools/SampleAnalyzer/Process/Reader/LHCOReader.cpp @@ -363,8 +363,8 @@ void LHCOReader::FillEventParticleLine(const std::string& line, EventFormat& myE // 8th column : btag str >> tmp; - if ( tmp == 1. || tmp ==2.) jet->btag_=true; - else jet->btag_ =false; + if ( tmp == 1. || tmp ==2.) jet->loose_btag_=true; + else jet->loose_btag_ =false; str >> jet->HEoverEE_; } From 65bcabc476185abfcb0def3283cefea91056a4c1 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Wed, 22 Jun 2022 23:21:06 +0100 Subject: [PATCH 30/67] adapt SFS tagging interface --- madanalysis/fastsim/fastsim.py | 81 +++++++++++++++-------- madanalysis/fastsim/tagger.py | 98 ++++++++++++++++++++++------ madanalysis/job/job_tagger_header.py | 73 ++++++++++++--------- madanalysis/job/job_tagger_main.py | 43 ++++-------- 4 files changed, 187 insertions(+), 108 deletions(-) diff --git a/madanalysis/fastsim/fastsim.py b/madanalysis/fastsim/fastsim.py index 5be344f3..5d6091c2 100644 --- a/madanalysis/fastsim/fastsim.py +++ b/madanalysis/fastsim/fastsim.py @@ -25,7 +25,7 @@ from __future__ import absolute_import import logging from madanalysis.fastsim.ast import AST -from madanalysis.fastsim.tagger import Tagger +from madanalysis.fastsim.tagger import Tagger, TaggerStatus from madanalysis.fastsim.smearer import Smearer from madanalysis.fastsim.recoefficiency import RecoEfficiency from madanalysis.fastsim.scaling import Scaling @@ -71,11 +71,11 @@ def Reset(self): self.photon_isocone_radius = [] # Definition of a new tagging/smearing rule - def define(self,args,prts): - prts.Add('c',[4]) - prts.Add('track',[]) # PDGID is not important - prts.Add('JES', []) # PDGID is not important - prts_remove = ['c','track','JES'] + def define(self, args, prts): + prts.Add('c', [4]) + prts.Add('track', []) # PDGID is not important + prts.Add('JES', []) # PDGID is not important + prts_remove = ['c', 'track', 'JES'] ## remove all initializations when this session is over def remove_prts_def(prts_remove,prts): @@ -87,11 +87,11 @@ def is_pdgcode(prt): return (prt[0] in ('-','+') and prt[1:].isdigit()) or prt.isdigit() ## Checking the length of the argument list - if (args[0]=='tagger' and len(args)<5) or (args[0]=='smearer' and len(args)<3) \ - or (args[0]=='reco_efficiency' and len(args)<3) or (args[0]=='jes' and len(args)<2) \ - or (args[0]=='energy_scaling' and len(args)<3) or (args[0]=='scaling' and len(args)<4): + if (args[0] == 'tagger' and len(args) < 5) or (args[0] == 'smearer' and len(args) < 3) \ + or (args[0] == 'reco_efficiency' and len(args) < 3) or (args[0] == 'jes' and len(args) < 2) \ + or (args[0] == 'energy_scaling' and len(args) < 3) or (args[0] == 'scaling' and len(args) < 4): self.logger.error('Not enough arguments for tagging/smearing/reconstruction/scaling') - remove_prts_def(prts_remove,prts) + remove_prts_def(prts_remove, prts) return ## Checking the first argument @@ -176,39 +176,43 @@ def is_pdgcode(prt): to_decode=args[4:] ## Getting the bounds and the function - function, bounds = self.decode_args(to_decode) + function, bounds, tags = self.decode_args(to_decode) if function=='': self.logger.error('Cannot decode the function or the bounds - ' + args[0] + ' ignored.') remove_prts_def(prts_remove,prts) return ## Adding a rule to a tagger/smearer - if args[0]=='tagger': - self.tagger.add_rule(true_id,reco_id,function,bounds) - elif args[0]=='smearer': - self.smearer.add_rule(true_id,obs,function,bounds) - elif args[0]=='reco_efficiency': - self.reco.add_rule(true_id,function,bounds) - elif args[0] in ['jes','energy_scaling','scaling']: - self.scaling.add_rule(true_id,obs,function,bounds) - remove_prts_def(prts_remove,prts) + if args[0] == 'tagger': + self.tagger.add_rule(true_id, reco_id, function, bounds, TaggerStatus.get_status(tags)) + elif args[0] == 'smearer': + self.smearer.add_rule(true_id, obs, function, bounds) + elif args[0] == 'reco_efficiency': + self.reco.add_rule(true_id, function, bounds) + elif args[0] in ['jes', 'energy_scaling', 'scaling']: + self.scaling.add_rule(true_id, obs, function, bounds) + remove_prts_def(prts_remove, prts) return # Transform the arguments passed in the interpreter in the right format def decode_args(self,myargs): # Special formating for the power operator - args = ' '.join(myargs).replace('^',' ^ ') - for symb in ['< =','> =','= =']: + args = ' '.join(myargs).replace('^', ' ^ ') + for symb in ['< =', '> =', '= =']: args = args.replace(symb, ''.join(symb.split())) args = args.split() ## To get the difference pieces of the command Nbracket1 = 0 Nbracket2 = 0 + Nbracket3 = 0 beginOptions = len(args) endOptions = -1 foundOptions = False + beginTags = len(args) + endTags = -1 + foundTags = False ## Extraction of the arguments for i in range(0,len(args)): @@ -225,14 +229,35 @@ def decode_args(self,myargs): Nbracket2-=1 if Nbracket1==0: endOptions = i + # Look for tagging options + elif args[i] == "{": + Nbracket3+=1 + if Nbracket1 == 0 and Nbracket2 == 0: + beginTags = i + foundTags = True + elif args[i] == "}": + Nbracket3-=1 + if Nbracket1 == 0 and Nbracket2 == 0: + endTags = i + ## Sanity if Nbracket1!=0: self.logger.error("number of opening '(' and closing ')' does not match.") - return '', [] + return '', [], None if Nbracket2!=0: self.logger.error("number of opening '[' and closing ']' does not match.") - return '', [] + return '', [], None + if Nbracket3!=0: + self.logger.error("number of opening '{' and closing '}' does not match.") + return '', [], None + + ## Find tags + tags = args[beginTags + 1:endTags] + if len(tags) > 1: + self.logger.error("Can not process more than one tag.") + return '', [], None + tags = tags[0] if len(tags) == 1 else "" ## Putting the bounds into an AST bounds = ' '.join(args[beginOptions+1:endOptions]) @@ -242,10 +267,14 @@ def decode_args(self,myargs): ast_bounds.feed(bounds) ## Putting the efficiency into an AST - efficiency = ' ' .join(args[:beginOptions]) + start_from = beginOptions if foundOptions else beginTags + efficiency = ' ' .join(args[:start_from]) ast_eff = AST(1, self.observables.full_list) ast_eff.feed(efficiency) - return ast_eff, ast_bounds + + self.logger.debug(f"Tags: {tags}\nBounds: {bounds}\nefficiency: {efficiency}") + + return ast_eff, ast_bounds, tags diff --git a/madanalysis/fastsim/tagger.py b/madanalysis/fastsim/tagger.py index 9f1dc131..69678309 100644 --- a/madanalysis/fastsim/tagger.py +++ b/madanalysis/fastsim/tagger.py @@ -24,33 +24,82 @@ from __future__ import absolute_import import logging -class Tagger: +from typing import Any, Optional +from enum import Enum, auto + +AST = Any + +class TaggerStatus(Enum): + NONE = auto() + LOOSE = auto() + MID = auto() + TIGHT = auto() + + @staticmethod + def get_status(status: str): + """Convert string to tagger status""" + if status.lower() == "loose": + return TaggerStatus.LOOSE + elif status.lower() in ["mid", "medium"]: + return TaggerStatus.MID + elif status.lower() == "tight": + return TaggerStatus.TIGHT + else: + return TaggerStatus.NONE + @staticmethod + def to_str(status): + if status == TaggerStatus.LOOSE: + return "loose" + elif status == TaggerStatus.MID: + return "mid" + elif status == TaggerStatus.TIGHT: + return "tight" + else: + return "" + + +class Tagger: # Initialization def __init__(self): - self.logger = logging.getLogger('MA5'); + self.logger = logging.getLogger('MA5') self.rules = {} + def add_rule(self, id_true: str, id_reco: str, function: AST, bounds: AST, tag: Optional[TaggerStatus] = None) -> None: + """ + Adding a rule to the tagger. The bounds and function are written as ASTs + + :param id_true: true particle id + :param id_reco: particle id to be reconstructed + :param function: efficiency function + :param bounds: bounds of the function + :param tag: status of the tagger + :return: + """ - # Adding a rule to the tagger - # The bounds and function are written as ASTs - def add_rule(self,id_true, id_reco, function, bounds): ## Checking wether the tagger is supported - if not self.is_supported(id_true, id_reco): + if not self.is_supported(id_true, id_reco, tag): return + ## Default tag for jets and taus is loose tag. If tag is not given convert to loose + if id_reco in ["21", "4", "5", "15"] and id_true in ["21", "4", "5", "15"]: + tag = tag if tag != TaggerStatus.NONE else TaggerStatus.LOOSE ## Checking whether the reco/true pair already exists - key_number=len(list(self.rules.keys()))+1 + key_number = len(list(self.rules.keys())) + 1 for key, value in self.rules.items(): - if value['id_true']==id_true and value['id_reco']==id_reco: + if value['id_true'] == id_true and value['id_reco'] == id_reco and value["tag"] == tag: key_number = key if not key_number in list(self.rules.keys()): - self.rules[key_number] = { 'id_true':id_true, 'id_reco':id_reco, - 'efficiencies':{} } + self.rules[key_number] = dict( + id_true=id_true, + id_reco=id_reco, + efficiencies=dict(), + tag=tag + ) ## Defining a new rule ID for an existing tagger - eff_key = len(self.rules[key_number]['efficiencies'])+1 - self.rules[key_number]['efficiencies'][eff_key] = { 'function':function, - 'bounds': bounds } + eff_key = len(self.rules[key_number]['efficiencies']) + 1 + self.rules[key_number]['efficiencies'][eff_key] = {'function': function, + 'bounds': bounds} def display(self): @@ -59,8 +108,8 @@ def display(self): self.logger.info('*********************************') for key in self.rules.keys(): myrule = self.rules[key] - self.logger.info(str(key) + ' - Tagging a true PDG-' + str(myrule['id_true']) + \ - ' as a PDG-' + str(myrule['id_reco'])) + self.logger.info(f"{key} - Tagging a true PDG-{myrule['id_true']} as a PDG-{myrule['id_reco']}" \ + + (myrule["tag"] != TaggerStatus.NONE)*f" with {TaggerStatus.to_str(myrule['tag'])} tag.") for eff_key in myrule['efficiencies'].keys(): cpp_name = 'eff_'+str(myrule['id_true'])+'_'+str(myrule['id_reco'])+\ '_'+str(eff_key) @@ -77,11 +126,20 @@ def display(self): self.logger.info(' --------------------') - def is_supported(self,id_true, id_reco): - supported = { '5':['21','4','5'], '4':['21','4','5'], '15':['15','21'], - '21' : ['11','13','22'], '11' : ['13','22', '21'], - '13' : ['11','22'], '22' : ['11','13', '21']} + def is_supported(self,id_true: str, id_reco: str, tag: TaggerStatus): + supported = {'5': ['21', '4', '5'], '4': ['21', '4', '5'], '15': ['15', '21'], + '21': ['11', '13', '22'], '11': ['13', '22', '21'], + '13': ['11', '22'], '22': ['11', '13', '21']} if id_reco not in list(supported.keys()) or id_true not in supported[id_reco]: - self.logger.error('This tagger is currently not supported (tagging '+ id_true + ' as ' + id_reco + '). Tagger ignored.') + self.logger.error( + f"This tagger is currently not supported (tagging {id_true} as {id_reco}). Tagger ignored." + ) return False + if tag in [TaggerStatus.LOOSE, TaggerStatus.MID, TaggerStatus.TIGHT]: + if id_reco not in ["21", "4", "5", "15"] or id_true not in ["21", "4", "5", "15"]: + self.logger.error( + f"This tagger is currently not supported. {id_true} can not be tagged as {id_reco} with " + f"{TaggerStatus.to_str(tag)} tag." + ) + return False return True diff --git a/madanalysis/job/job_tagger_header.py b/madanalysis/job/job_tagger_header.py index d2cd85b4..fbfbd61f 100644 --- a/madanalysis/job/job_tagger_header.py +++ b/madanalysis/job/job_tagger_header.py @@ -21,30 +21,31 @@ # ################################################################################ +from madanalysis.fastsim.tagger import TaggerStatus class JobTaggerHeader: # structure: (true_id, reco_id) : "..." base = { - (5, 5): "\t/// B-jet tagging efficiency (b as b)\n\tMAfloat32 b_tagging_eff(const RecJetFormat &object) const", - (5, 4): "\t/// B-jet mistagging as C-jet (b as c)\n\tMAfloat32 b_mistag_c(const RecJetFormat &object) const", - (4, 4): "\t/// C-jet tagging efficiency (c as c)\n\tMAfloat32 c_tagging_eff(const RecJetFormat &object) const", - (4, 5): "\t/// C-jet mistagging as C-jet (c as b)\n\tMAfloat32 c_mistag_b(const RecJetFormat &object) const", - (21, 5): "\t/// Light-Jet mistagging as b-jet (j as b)\n\tMAfloat32 lightjet_mistag_b(const RecJetFormat &object) const", - (21, 4): "\t/// Light-Jet mistagging as c jet (j as c)\n\tMAfloat32 lightjet_mistag_c(const RecJetFormat &object) const", - (21, 15): "\t/// Light-Jet mistagging as tau (j as ta)\n\tMAfloat32 lightjet_mistag_tau(const RecJetFormat &object) const", - (21, 11): "\t/// Light-Jet mistagging as electron (j as e)\n\tMAfloat32 lightjet_mistag_electron(const RecJetFormat &object) const", - (21, 22): "\t/// Light-Jet mistagging as photon (j as photon)\n\tMAfloat32 lightjet_mistag_photon(const RecJetFormat &object) const", - (15, 15): "\t/// Tau tagging efficiency (ta as ta)\n\tMAfloat32 tau_tagging_eff(const RecTauFormat &object) const", - (11, 13): "\t/// Electron mistagging as muon (e as mu)\n\tMAfloat32 electron_mistag_muon(const RecLeptonFormat &object) const", - (11, 22): "\t/// Electron mistagging as photon (e as a)\n\tMAfloat32 electron_mistag_photon(const RecLeptonFormat &object) const", - (11, 21): "\t/// Electron mistagging as light jet (e as j)\n\tMAfloat32 electron_mistag_lightjet(const RecLeptonFormat &object) const", - (13, 11): "\t/// Electron mistagging as electron (mu as e)\n\tMAfloat32 muon_mistag_electron(const RecLeptonFormat &object) const", - (13, 22): "\t/// Electron mistagging as photon (mu as a)\n\tMAfloat32 muon_mistag_photon(const RecLeptonFormat &object) const", - (13, 21): "\t/// Electron mistagging as light jet (mu as j)\n\tMAfloat32 muon_mistag_lightjet(const RecLeptonFormat &object) const", - (22, 11): "\t/// Electron mistagging as electron (a as e)\n\tMAfloat32 photon_mistag_electron(const RecPhotonFormat &object) const", - (22, 13): "\t/// Electron mistagging as muon (a as mu)\n\tMAfloat32 photon_mistag_muon(const RecPhotonFormat &object) const", - (22, 21): "\t/// Electron mistagging as light jet (a as j)\n\tMAfloat32 photon_mistag_lightjet(const RecPhotonFormat &object) const", + (5, 5): lambda tag: f"/// B-jet tagging efficiency (b as b)\nMAfloat32 NewTagger::{tag}_b_tagging_eff(const RecJetFormat &object) const", + (5, 4): lambda tag: f"/// B-jet mistagging as C-jet (b as c)\nMAfloat32 NewTagger::{tag}_b_mistag_c(const RecJetFormat &object) const", + (4, 4): lambda tag: f"/// C-jet tagging efficiency (c as c)\nMAfloat32 NewTagger::{tag}_c_tagging_eff(const RecJetFormat &object) const", + (4, 5): lambda tag: f"/// C-jet mistagging as C-jet (c as b)\nMAfloat32 NewTagger::{tag}_c_mistag_b(const RecJetFormat &object) const", + (21, 5): lambda tag: f"/// Light-Jet mistagging as b-jet (j as b)\nMAfloat32 NewTagger::lightjet_mistag_b_{tag}(const RecJetFormat &object) const", + (21, 4): lambda tag: f"/// Light-Jet mistagging as c jet (j as c)\nMAfloat32 NewTagger::lightjet_mistag_c_{tag}(const RecJetFormat &object) const", + (21, 15): lambda tag: f"/// Light-Jet mistagging as tau (j as ta)\nMAfloat32 NewTagger::lightjet_mistag_tau_{tag}(const RecJetFormat &object) const", + (21, 11): lambda tag: f"/// Light-Jet mistagging as electron (j as e)\nMAfloat32 NewTagger::lightjet_mistag_electron(const RecJetFormat &object) const", + (21, 22): lambda tag: f"/// Light-Jet mistagging as photon (j as photon)\nMAfloat32 NewTagger::lightjet_mistag_photon(const RecJetFormat &object) const", + (15, 15): lambda tag: f"/// Tau tagging efficiency (ta as ta)\nMAfloat32 NewTagger::{tag}_tau_tagging_eff(const RecTauFormat &object) const", + (11, 13): lambda tag: f"/// Electron mistagging as muon (e as mu)\nMAfloat32 NewTagger::electron_mistag_muon(const RecLeptonFormat &object) const", + (11, 22): lambda tag: f"/// Electron mistagging as photon (e as a)\nMAfloat32 NewTagger::electron_mistag_photon(const RecLeptonFormat &object) const", + (11, 21): lambda tag: f"/// Electron mistagging as light jet (e as j)\nMAfloat32 NewTagger::electron_mistag_lightjet(const RecLeptonFormat &object) const", + (13, 11): lambda tag: f"/// Electron mistagging as electron (mu as e)\nMAfloat32 NewTagger::muon_mistag_electron(const RecLeptonFormat &object) const", + (13, 22): lambda tag: f"/// Electron mistagging as photon (mu as a)\nMAfloat32 NewTagger::muon_mistag_photon(const RecLeptonFormat &object) const", + (13, 21): lambda tag: f"/// Electron mistagging as light jet (mu as j)\nMAfloat32 NewTagger::muon_mistag_lightjet(const RecLeptonFormat &object) const", + (22, 11): lambda tag: f"/// Electron mistagging as electron (a as e)\nMAfloat32 NewTagger::photon_mistag_electron(const RecPhotonFormat &object) const", + (22, 13): lambda tag: f"/// Electron mistagging as muon (a as mu)\nMAfloat32 NewTagger::photon_mistag_muon(const RecPhotonFormat &object) const", + (22, 21): lambda tag: f"/// Electron mistagging as light jet (a as j)\nMAfloat32 NewTagger::photon_mistag_lightjet(const RecPhotonFormat &object) const", } @@ -54,8 +55,8 @@ def __init__(self, fastsim): self.unique_rules = [] for key, rule in self.fastsim.tagger.rules.items(): - if (int(rule["id_true"]), int(rule["id_reco"])) not in self.unique_rules: - self.unique_rules.append((int(rule["id_true"]), int(rule["id_reco"]))) + if (int(rule["id_true"]), int(rule["id_reco"]), TaggerStatus.to_str(rule["tag"])) not in self.unique_rules: + self.unique_rules.append((int(rule["id_true"]), int(rule["id_reco"]), TaggerStatus.to_str(rule["tag"]))) ## Writing NewTagger.h @@ -68,7 +69,7 @@ def WriteNewTaggerHeader(self, file): file.write(' class NewTagger: public SFSTaggerBase {\n') file.write(' private:\n') file.write(' /// Code efficiency booleans\n') - file.write(' MAbool _isJetTaggingOn, _isTauTaggingEffOn, _isMuonTaggingOn, _isElectronTaggingOn, _isPhotonTaggingOn;\n') + file.write(' MAbool _isTauTaggingEffOn, _isMuonTaggingOn, _isElectronTaggingOn, _isPhotonTaggingOn;\n') file.write(' SFSTaggerBaseOptions _options;\n') file.write(' public :\n') file.write(' /// Constructor without argument\n') @@ -78,9 +79,9 @@ def WriteNewTaggerHeader(self, file): file.write(' void Initialize() {\n') file.write(' /// @brief Booleans for code efficiency\n') file.write(' /// Turn on the usage of tau tagging efficiency\n') - file.write(f" _isTauTaggingEffOn = {'true' if (5,5) in self.unique_rules else 'false'};\n") - file.write(' /// Turn on the usage of jet (mis)tagging efficiency\n') - file.write(f" _isJetTaggingOn = {'true' if any([x in self.unique_rules for x in [(5,5), (4,5), (21,5), (5,4), (4,4), (21,4), (21,15), (21,11), (21,22)]]) else 'false'};\n") + file.write(f" _isTauTaggingEffOn = {'true' if (5,5) in [(x[0], x[1]) for x in self.unique_rules] else 'false'};\n") + # file.write(' /// Turn on the usage of jet (mis)tagging efficiency\n') + # file.write(f" _isJetTaggingOn = {'true' if any([x in self.unique_rules for x in [(5,5), (4,5), (21,5), (5,4), (4,4), (21,4), (21,15), (21,11), (21,22)]]) else 'false'};\n") file.write(' /// Turn on the usage of muon (mis)tagging efficiency\n') file.write(f" _isMuonTaggingOn = {'true' if 13 in [x[0] for x in self.unique_rules] else 'false'};\n") file.write(' /// Turn on the usage of electron (mis)tagging efficiency\n') @@ -94,7 +95,9 @@ def WriteNewTaggerHeader(self, file): file.write(' /// //\n') file.write(' ///==========================================//\n\n') for rule in self.unique_rules: - file.write(JobTaggerHeader.base[rule] + ";\n") + header = JobTaggerHeader.base[(rule[0], rule[1])](rule[2]).split("\n") + file.write(f"\t{header[0]}\n") + file.write(f"\t{header[1].replace('NewTagger::', '')};\n") file.write(' };\n}\n#endif //MADANALYSIS5_NEW_TAGGER_H') @@ -109,11 +112,17 @@ def WriteNewTaggerEfficiencies(self,file): for eff_key in value['efficiencies'].keys(): eff_fnc = value['efficiencies'][eff_key]['function'] eff_bnd = value['efficiencies'][eff_key]['bounds' ] - file.write(eff_fnc.tocpp('MAdouble64', \ - 'eff_'+str(value['id_true']) + '_' + str(value['id_reco'])+'_'+\ - str(eff_key))+'\n') - file.write(eff_bnd.tocpp('MAbool', \ - 'bnd_'+str(value['id_true']) + '_' + str(value['id_reco'])+'_'+\ - str(eff_key)) + '\n') + file.write( + eff_fnc.tocpp( + 'MAdouble64', + f"eff_{value['id_true']}_{value['id_reco']}_{eff_key}_{TaggerStatus.to_str(value['tag'])}" + )+'\n' + ) + file.write( + eff_bnd.tocpp( + 'MAbool', + f"bnd_{value['id_true']}_{value['id_reco']}_{eff_key}_{TaggerStatus.to_str(value['tag'])}" + ) + '\n' + ) file.write('#endif') diff --git a/madanalysis/job/job_tagger_main.py b/madanalysis/job/job_tagger_main.py index 663fc6f8..70a8bf24 100644 --- a/madanalysis/job/job_tagger_main.py +++ b/madanalysis/job/job_tagger_main.py @@ -21,32 +21,11 @@ # ################################################################################ +from madanalysis.job.job_tagger_header import JobTaggerHeader +from madanalysis.fastsim.tagger import TaggerStatus class JobTaggerMain: - # structure: (true_id, reco_id) : "..." - base = { - (5, 5): "/// B-jet tagging efficiency (b as b)\nMAfloat32 NewTagger::b_tagging_eff(const RecJetFormat &object) const", - (5, 4): "/// B-jet mistagging as C-jet (b as c)\nMAfloat32 NewTagger::b_mistag_c(const RecJetFormat &object) const", - (4, 4): "/// C-jet tagging efficiency (c as c)\nMAfloat32 NewTagger::c_tagging_eff(const RecJetFormat &object) const", - (4, 5): "/// C-jet mistagging as C-jet (c as b)\nMAfloat32 NewTagger::c_mistag_b(const RecJetFormat &object) const", - (21, 5): "/// Light-Jet mistagging as b-jet (j as b)\nMAfloat32 NewTagger::lightjet_mistag_b(const RecJetFormat &object) const", - (21, 4): "/// Light-Jet mistagging as c jet (j as c)\nMAfloat32 NewTagger::lightjet_mistag_c(const RecJetFormat &object) const", - (21, 15): "/// Light-Jet mistagging as tau (j as ta)\nMAfloat32 NewTagger::lightjet_mistag_tau(const RecJetFormat &object) const", - (21, 11): "/// Light-Jet mistagging as electron (j as e)\nMAfloat32 NewTagger::lightjet_mistag_electron(const RecJetFormat &object) const", - (21, 22): "/// Light-Jet mistagging as photon (j as photon)\nMAfloat32 NewTagger::lightjet_mistag_photon(const RecJetFormat &object) const", - (15, 15): "/// Tau tagging efficiency (ta as ta)\nMAfloat32 NewTagger::tau_tagging_eff(const RecTauFormat &object) const", - (11, 13): "/// Electron mistagging as muon (e as mu)\nMAfloat32 NewTagger::electron_mistag_muon(const RecLeptonFormat &object) const", - (11, 22): "/// Electron mistagging as photon (e as a)\nMAfloat32 NewTagger::electron_mistag_photon(const RecLeptonFormat &object) const", - (11, 21): "/// Electron mistagging as light jet (e as j)\nMAfloat32 NewTagger::electron_mistag_lightjet(const RecLeptonFormat &object) const", - (13, 11): "/// Electron mistagging as electron (mu as e)\nMAfloat32 NewTagger::muon_mistag_electron(const RecLeptonFormat &object) const", - (13, 22): "/// Electron mistagging as photon (mu as a)\nMAfloat32 NewTagger::muon_mistag_photon(const RecLeptonFormat &object) const", - (13, 21): "/// Electron mistagging as light jet (mu as j)\nMAfloat32 NewTagger::muon_mistag_lightjet(const RecLeptonFormat &object) const", - (22, 11): "/// Electron mistagging as electron (a as e)\nMAfloat32 NewTagger::photon_mistag_electron(const RecPhotonFormat &object) const", - (22, 13): "/// Electron mistagging as muon (a as mu)\nMAfloat32 NewTagger::photon_mistag_muon(const RecPhotonFormat &object) const", - (22, 21): "/// Electron mistagging as light jet (a as j)\nMAfloat32 NewTagger::photon_mistag_lightjet(const RecPhotonFormat &object) const", - } - ## Initialization def __init__(self, fastsim): self.fastsim = fastsim @@ -61,26 +40,30 @@ def WriteNewTaggerSource(self, file): unique_rules = [] for key, rule in self.fastsim.tagger.rules.items(): - if (int(rule["id_true"]), int(rule["id_reco"])) not in unique_rules: - unique_rules.append((int(rule["id_true"]), int(rule["id_reco"]))) + if (int(rule["id_true"]), int(rule["id_reco"]), TaggerStatus.to_str(rule["tag"])) not in unique_rules: + unique_rules.append((int(rule["id_true"]), int(rule["id_reco"]), TaggerStatus.to_str(rule["tag"]))) - for true_id, reco_id in unique_rules: - file.write("\n"+JobTaggerMain.base[(true_id, reco_id)] + " {\n") + for true_id, reco_id, tag in unique_rules: + file.write("\n" + JobTaggerHeader.base[(true_id, reco_id)](tag) + " {\n") check_initializer = 0 for key, val in self.fastsim.tagger.rules.items(): - if val['id_true'] in [str(true_id)] and val['id_reco'] in [str(reco_id)]: + if val['id_true'] in [str(true_id)] and val['id_reco'] in [str(reco_id)] and val["tag"] == TaggerStatus.get_status(tag): eff_str = [] initializer = 'MAfloat32 ' if check_initializer > 0: initializer = '' for eff_key, eff_val in val['efficiencies'].items(): my_eff_str = eff_val['bounds'].tocpp_call( - "object",'bnd_'+str(val['id_true'])+'_'+str(val['id_reco'])+'_'+str(eff_key), pointer=".", + "object", + f"bnd_{val['id_true']}_{val['id_reco']}_{eff_key}_{TaggerStatus.to_str(val['tag'])}", + pointer=".", ) my_eff_str +=' * ' my_eff_str += eff_val['function'].tocpp_call( - "object", 'eff_'+str(val['id_true'])+'_'+str(val['id_reco'])+'_'+str(eff_key), pointer=".", + "object", + f"eff_{val['id_true']}_{val['id_reco']}_{eff_key}_{TaggerStatus.to_str(val['tag'])}", + pointer=".", ) eff_str.append(my_eff_str) file.write(' ' + initializer + ' efficiency = ' + ' + '.join(eff_str) +';\n') From cd7bf1174524a4fe5d55f2c1e29bbc43ee98b2c6 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 23 Jun 2022 09:37:33 +0100 Subject: [PATCH 31/67] bugfix in tagger structure --- madanalysis/job/job_tagger_header.py | 8 +- .../Commons/Base/SFSTaggerBase.cpp | 232 +++++++++--------- 2 files changed, 122 insertions(+), 118 deletions(-) diff --git a/madanalysis/job/job_tagger_header.py b/madanalysis/job/job_tagger_header.py index fbfbd61f..e229fe72 100644 --- a/madanalysis/job/job_tagger_header.py +++ b/madanalysis/job/job_tagger_header.py @@ -69,7 +69,7 @@ def WriteNewTaggerHeader(self, file): file.write(' class NewTagger: public SFSTaggerBase {\n') file.write(' private:\n') file.write(' /// Code efficiency booleans\n') - file.write(' MAbool _isTauTaggingEffOn, _isMuonTaggingOn, _isElectronTaggingOn, _isPhotonTaggingOn;\n') + file.write(' MAbool _isJetTaggingOn, _isTauTaggingEffOn, _isMuonTaggingOn, _isElectronTaggingOn, _isPhotonTaggingOn;\n') file.write(' SFSTaggerBaseOptions _options;\n') file.write(' public :\n') file.write(' /// Constructor without argument\n') @@ -80,8 +80,8 @@ def WriteNewTaggerHeader(self, file): file.write(' /// @brief Booleans for code efficiency\n') file.write(' /// Turn on the usage of tau tagging efficiency\n') file.write(f" _isTauTaggingEffOn = {'true' if (5,5) in [(x[0], x[1]) for x in self.unique_rules] else 'false'};\n") - # file.write(' /// Turn on the usage of jet (mis)tagging efficiency\n') - # file.write(f" _isJetTaggingOn = {'true' if any([x in self.unique_rules for x in [(5,5), (4,5), (21,5), (5,4), (4,4), (21,4), (21,15), (21,11), (21,22)]]) else 'false'};\n") + file.write(' /// Turn on the usage of jet (mis)tagging efficiency\n') + file.write(f" _isJetTaggingOn = {'true' if any([x in [(x[0], x[1]) for x in self.unique_rules] for x in [(5,5), (4,5), (21,5), (5,4), (4,4), (21,4), (21,15), (21,11), (21,22)]]) else 'false'};\n") file.write(' /// Turn on the usage of muon (mis)tagging efficiency\n') file.write(f" _isMuonTaggingOn = {'true' if 13 in [x[0] for x in self.unique_rules] else 'false'};\n") file.write(' /// Turn on the usage of electron (mis)tagging efficiency\n') @@ -96,7 +96,7 @@ def WriteNewTaggerHeader(self, file): file.write(' ///==========================================//\n\n') for rule in self.unique_rules: header = JobTaggerHeader.base[(rule[0], rule[1])](rule[2]).split("\n") - file.write(f"\t{header[0]}\n") + file.write(f"\n\t{header[0]}\n") file.write(f"\t{header[1].replace('NewTagger::', '')};\n") file.write(' };\n}\n#endif //MADANALYSIS5_NEW_TAGGER_H') diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index 54e5036e..69b11867 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -79,126 +79,130 @@ namespace MA5 { MAuint32 Ntau = myEvent.rec()->taus().size(); std::vector toRemove; /// Jet tagging with detector effects - MAint32 ijet = -1; - for (auto &jet: myEvent.rec()->jets()) + if (_isJetTaggingOn) { - ijet++; - /// We have a true b-jet: is it b-tagged? - if (jet.true_btag()) + MAint32 ijet = -1; + for (auto &jet: myEvent.rec()->jets()) { - jet.setLooseBtag(RANDOM->flat() < loose_b_tagging_eff(jet)); - jet.setMidBtag(RANDOM->flat() < mid_b_tagging_eff(jet)); - jet.setTightBtag(RANDOM->flat() < tight_b_tagging_eff(jet)); - } - /// We have a true c-jet: is it b-tagged? - else if (jet.true_ctag()) - { - jet.setLooseBtag(RANDOM->flat() < loose_c_mistag_b(jet)); - jet.setMidBtag(RANDOM->flat() < mid_c_mistag_b(jet)); - jet.setTightBtag(RANDOM->flat() < tight_c_mistag_b(jet)); - } - /// We have a true light-jet: is it b-tagged? - else - { - jet.setLooseBtag(RANDOM->flat() < lightjet_mistag_b_loose(jet)); - jet.setMidBtag(RANDOM->flat() < lightjet_mistag_b_mid(jet)); - jet.setTightBtag(RANDOM->flat() < lightjet_mistag_b_tight(jet)); - } - - /// We have a true b-jet: is it c-tagged? - if (jet.true_btag()) - { - /// We have a b-tagged jet -> moving on with the next jet - jet.setLooseCtag(!jet.loose_btag() && RANDOM->flat() < loose_b_mistag_c(jet)); - jet.setMidCtag(!jet.mid_btag() && RANDOM->flat() < mid_b_mistag_c(jet)); - jet.setTightCtag(!jet.tight_btag() && RANDOM->flat() < tight_b_mistag_c(jet)); - } - /// We have a true c-jet: is it c-tagged? - else if (jet.true_ctag()) - { - jet.setLooseCtag(!jet.loose_btag() && RANDOM->flat() < loose_c_tagging_eff(jet)); - jet.setMidCtag(!jet.mid_btag() && RANDOM->flat() < mid_c_tagging_eff(jet)); - jet.setTightCtag(!jet.tight_btag() && RANDOM->flat() < tight_c_tagging_eff(jet)); - } - /// We have a true light-jet: is it c-tagged? - else - { - jet.setLooseCtag(RANDOM->flat() < lightjet_mistag_c_loose(jet)); - jet.setMidCtag(RANDOM->flat() < lightjet_mistag_c_mid(jet)); - jet.setTightCtag(RANDOM->flat() < lightjet_mistag_c_tight(jet)); - } - - if (_options.tautag_jetbased) - { - if (jet.true_tautag()) + ijet++; + /// We have a true b-jet: is it b-tagged? + if (jet.true_btag()) { - jet.setLooseTautag(!jet.loose_btag() && !jet.loose_ctag() && - RANDOM->flat() < tau_tagging_eff(jet, LOOSE)); - jet.setMidTautag(!jet.mid_btag() && !jet.mid_ctag() && - RANDOM->flat() < tau_tagging_eff(jet, MID)); - jet.setTightTautag(!jet.tight_btag() && !jet.tight_ctag() && - RANDOM->flat() < tau_tagging_eff(jet, TIGHT)); - } else { - jet.setLooseTautag(!jet.loose_btag() && !jet.loose_ctag() && - RANDOM->flat() < lightjet_mistag_tau_loose(jet)); - jet.setMidTautag(!jet.mid_btag() && !jet.mid_ctag() && - RANDOM->flat() < lightjet_mistag_tau_mid(jet)); - jet.setTightTautag(!jet.tight_btag() && !jet.tight_ctag() && - RANDOM->flat() < lightjet_mistag_tau_tight(jet)); + if (RANDOM->flat() > loose_b_tagging_eff(jet)) jet.setLooseBtag(false); + if (RANDOM->flat() < mid_b_tagging_eff(jet)) jet.setMidBtag(false); + if (RANDOM->flat() < tight_b_tagging_eff(jet)) jet.setTightBtag(false); + } + /// We have a true c-jet: is it b-tagged? + else if (jet.true_ctag()) + { + if (RANDOM->flat() < loose_c_mistag_b(jet)) jet.setLooseBtag(true); + if (RANDOM->flat() < mid_c_mistag_b(jet)) jet.setMidBtag(true); + if (RANDOM->flat() < tight_c_mistag_b(jet)) jet.setTightBtag(true); + } + /// We have a true light-jet: is it b-tagged? + else + { + if (RANDOM->flat() < lightjet_mistag_b_loose(jet)) jet.setLooseBtag(true); + if (RANDOM->flat() < lightjet_mistag_b_mid(jet)) jet.setMidBtag(true); + if (RANDOM->flat() < lightjet_mistag_b_tight(jet)) jet.setTightBtag(true); } - } - - /// We have a true b/c-jet -> cannot be mistagged - if (jet.ctag() || jet.btag() || jet.tautag()) continue; - /// if not, is it mis-tagged as anything? - else - { - /// Scope for light jet mistagging as tau - if (!_options.tautag_jetbased) { - /// if not, is it Tau-tagged? - if (RANDOM->flat() < lightjet_mistag_tau_loose(jet)) { - RecTauFormat *newTau = myEvent.rec()->GetNewTau(); - Jet2Tau(&jet, newTau, myEvent); - toRemove.push_back(ijet); - continue; - } + /// We have a true b-jet: is it c-tagged? + if (jet.true_btag()) + { + /// We have a b-tagged jet -> moving on with the next jet + if (!jet.loose_btag() && RANDOM->flat() < loose_b_mistag_c(jet)) jet.setLooseCtag(true); + if (!jet.mid_btag() && RANDOM->flat() < mid_b_mistag_c(jet)) jet.setMidCtag(true); + if (!jet.tight_btag() && RANDOM->flat() < tight_b_mistag_c(jet)) jet.setTightCtag(true); + } + /// We have a true c-jet: is it c-tagged? + else if (jet.true_ctag()) + { + if (!jet.loose_btag() && RANDOM->flat() > loose_c_tagging_eff(jet)) jet.setLooseCtag(false); + if (!jet.mid_btag() && RANDOM->flat() > mid_c_tagging_eff(jet)) jet.setMidCtag(false); + if (!jet.tight_btag() && RANDOM->flat() > tight_c_tagging_eff(jet)) jet.setTightCtag(false); } - /// Scope for light jet mistagging for electron + /// We have a true light-jet: is it c-tagged? + else { - /// if not, is it Electron-tagged? - if (RANDOM->flat() < lightjet_mistag_electron(jet)) + if (!jet.loose_btag() && RANDOM->flat() < lightjet_mistag_c_loose(jet)) jet.setLooseCtag(true); + if (!jet.mid_btag() && RANDOM->flat() < lightjet_mistag_c_mid(jet)) jet.setMidCtag(true); + if (!jet.tight_btag() && RANDOM->flat() < lightjet_mistag_c_tight(jet)) jet.setTightCtag(true); + } + + if (_options.tautag_jetbased) + { + if (jet.true_tautag()) { - RecLeptonFormat* NewParticle = myEvent.rec()->GetNewElectron(); - NewParticle->setMomentum(jet.momentum()); - NewParticle->setMc(jet.mc()); - /// @attention charge can also be determined via total constituent charge - NewParticle->SetCharge(RANDOM->flat() > 0.5 ? 1. : -1.); - THT -= jet.pt(); - Meff -= jet.pt(); - MALorentzVector MissHT = myEvent.rec()->MHT().momentum() + jet.momentum(); - (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( - MissHT.Px(), MissHT.Py(), 0., MissHT.E() - ); - toRemove.push_back(ijet); + if (!jet.loose_btag() && !jet.loose_ctag() && RANDOM->flat() > tau_tagging_eff(jet, LOOSE)) + jet.setLooseTautag(false); + if (!jet.mid_btag() && !jet.mid_ctag() && RANDOM->flat() > tau_tagging_eff(jet, MID)) + jet.setMidTautag(false); + if (!jet.tight_btag() && !jet.tight_ctag() && RANDOM->flat() > tau_tagging_eff(jet, TIGHT)) + jet.setTightTautag(false); + } else { + if (!jet.loose_btag() && !jet.loose_ctag() && RANDOM->flat() < lightjet_mistag_tau_loose(jet)) + jet.setLooseTautag(true); + if (!jet.mid_btag() && !jet.mid_ctag() && RANDOM->flat() < lightjet_mistag_tau_mid(jet)) + jet.setMidTautag(true); + if (!jet.tight_btag() && !jet.tight_ctag() && RANDOM->flat() < lightjet_mistag_tau_tight(jet)) + jet.setTightTautag(true); } } - /// Scope for light jet mistagging for photon + + /// We have a true b/c-jet -> cannot be mistagged + /// @attention Loose tag is always the default + if (jet.loose_ctag() || jet.loose_btag() || jet.loose_tautag()) continue; + + /// if not, is it mis-tagged as anything? + else { - /// if not, is it Photon-tagged? - if (RANDOM->flat() < lightjet_mistag_photon(jet)) + /// Scope for light jet mistagging as tau + if (!_options.tautag_jetbased) { + /// if not, is it Tau-tagged? + if (RANDOM->flat() < lightjet_mistag_tau_loose(jet)) { + RecTauFormat *newTau = myEvent.rec()->GetNewTau(); + Jet2Tau(&jet, newTau, myEvent); + toRemove.push_back(ijet); + continue; + } + } + /// Scope for light jet mistagging for electron + { + /// if not, is it Electron-tagged? + if (RANDOM->flat() < lightjet_mistag_electron(jet)) + { + RecLeptonFormat* NewParticle = myEvent.rec()->GetNewElectron(); + NewParticle->setMomentum(jet.momentum()); + NewParticle->setMc(jet.mc()); + /// @attention charge can also be determined via total constituent charge + NewParticle->SetCharge(RANDOM->flat() > 0.5 ? 1. : -1.); + THT -= jet.pt(); + Meff -= jet.pt(); + MALorentzVector MissHT = myEvent.rec()->MHT().momentum() + jet.momentum(); + (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( + MissHT.Px(), MissHT.Py(), 0., MissHT.E() + ); + toRemove.push_back(ijet); + } + } + /// Scope for light jet mistagging for photon { - RecPhotonFormat* NewParticle = myEvent.rec()->GetNewPhoton(); - NewParticle->setMomentum(jet.momentum()); - NewParticle->setMc(jet.mc()); - THT -= jet.pt(); - Meff -= jet.pt(); - MALorentzVector MissHT = myEvent.rec()->MHT().momentum() + jet.momentum(); - (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( - MissHT.Px(), MissHT.Py(), 0., MissHT.E() - ); - toRemove.push_back(ijet); - continue; + /// if not, is it Photon-tagged? + if (RANDOM->flat() < lightjet_mistag_photon(jet)) + { + RecPhotonFormat* NewParticle = myEvent.rec()->GetNewPhoton(); + NewParticle->setMomentum(jet.momentum()); + NewParticle->setMc(jet.mc()); + THT -= jet.pt(); + Meff -= jet.pt(); + MALorentzVector MissHT = myEvent.rec()->MHT().momentum() + jet.momentum(); + (&myEvent.rec()->MHT().momentum())->SetPxPyPzE( + MissHT.Px(), MissHT.Py(), 0., MissHT.E() + ); + toRemove.push_back(ijet); + continue; + } } } } @@ -403,10 +407,10 @@ namespace MA5 { { current_ijet = ijet; DeltaRmax = dR; } - else { myEvent.rec()->jets()[ijet].setTrueBtag(true); } + else { myEvent.rec()->jets()[ijet].setAllBtags(true); } } } - if (current_ijet >= 0) myEvent.rec()->jets()[current_ijet].setTrueBtag(true); + if (current_ijet >= 0) myEvent.rec()->jets()[current_ijet].setAllBtags(true); } } @@ -427,10 +431,10 @@ namespace MA5 { { current_ijet = ijet; DeltaRmax = dR; } - else { myEvent.rec()->jets()[ijet].setTrueCtag(true); } + else { myEvent.rec()->jets()[ijet].setAllCtags(true); } } } - if (current_ijet >= 0) myEvent.rec()->jets()[current_ijet].setTrueCtag(true); + if (current_ijet >= 0) myEvent.rec()->jets()[current_ijet].setAllCtags(true); } } @@ -453,10 +457,10 @@ namespace MA5 { { DeltaRmax = dR; current_jet = ijet; } - else myEvent.rec()->jets()[current_jet].setTrueTautag(true); + else myEvent.rec()->jets()[current_jet].setAllTautags(true); } } - if (current_jet >= 0) myEvent.rec()->jets()[current_jet].setTrueTautag(true); + if (current_jet >= 0) myEvent.rec()->jets()[current_jet].setAllTautags(true); } } From ef26851ed922150e47b4d5331b3ee08f0f2378f9 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 23 Jun 2022 14:21:18 +0100 Subject: [PATCH 32/67] bugfix in btag efficiencies --- .../Commons/Base/SFSTaggerBase.cpp | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index 69b11867..0e54c3ed 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -89,8 +89,8 @@ namespace MA5 { if (jet.true_btag()) { if (RANDOM->flat() > loose_b_tagging_eff(jet)) jet.setLooseBtag(false); - if (RANDOM->flat() < mid_b_tagging_eff(jet)) jet.setMidBtag(false); - if (RANDOM->flat() < tight_b_tagging_eff(jet)) jet.setTightBtag(false); + if (RANDOM->flat() > mid_b_tagging_eff(jet)) jet.setMidBtag(false); + if (RANDOM->flat() > tight_b_tagging_eff(jet)) jet.setTightBtag(false); } /// We have a true c-jet: is it b-tagged? else if (jet.true_ctag()) @@ -394,10 +394,15 @@ namespace MA5 { /// Truth B-Jet tagging void SFSTaggerBase::BJetTagging(EventFormat &myEvent) const { + /// Bjet candidates + std::vector Candidates; + for (auto &bHadron: myEvent.rec()->MCBquarks_) { + RecJetFormat* tag = 0; MAfloat32 DeltaRmax = _options.btag_matching_deltaR; - MAint32 current_ijet = -1; + + /// Loop over jets for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) { MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(bHadron); @@ -405,22 +410,31 @@ namespace MA5 { { if (_options.btag_exclusive) { - current_ijet = ijet; DeltaRmax = dR; + tag = &(myEvent.rec()->jets()[ijet]); + DeltaRmax = dR; } - else { myEvent.rec()->jets()[ijet].setAllBtags(true); } + else Candidates.push_back(&(myEvent.rec()->jets()[ijet])); } } - if (current_ijet >= 0) myEvent.rec()->jets()[current_ijet].setAllBtags(true); + if (_options.btag_exclusive && tag!=0) Candidates.push_back(tag); } + + for (auto &jet: Candidates) + jet->setAllBtags(true); } /// Truth C-Jet tagging void SFSTaggerBase::CJetTagging(EventFormat &myEvent) const { + /// Cjet candidates + std::vector Candidates; + for (auto &cHadron: myEvent.rec()->MCCquarks_) { MAfloat32 DeltaRmax = _options.ctag_matching_deltaR; - MAint32 current_ijet = -1; + RecJetFormat* tag = 0; + + /// Loop over jets for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) { if (myEvent.rec()->jets()[ijet].true_btag()) continue; @@ -429,13 +443,17 @@ namespace MA5 { { if (_options.ctag_exclusive) { - current_ijet = ijet; DeltaRmax = dR; + tag = &(myEvent.rec()->jets()[ijet]); + DeltaRmax = dR; } - else { myEvent.rec()->jets()[ijet].setAllCtags(true); } + else Candidates.push_back(&(myEvent.rec()->jets()[ijet])); } } - if (current_ijet >= 0) myEvent.rec()->jets()[current_ijet].setAllCtags(true); + if (_options.ctag_exclusive && tag!=0) Candidates.push_back(tag); } + + for (auto &jet: Candidates) + jet->setAllCtags(true); } /// This method implements tau matching for jets From 8588c19b1ffa22e8012bb85a312162331069277e Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 23 Jun 2022 15:13:34 +0100 Subject: [PATCH 33/67] fix tagger to match previous tagger --- .../Commons/Base/SFSTaggerBase.cpp | 66 +++++++++---------- .../Commons/Base/SFSTaggerBase.h | 7 +- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index 0e54c3ed..cbf88d32 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -32,17 +32,22 @@ namespace MA5 { /// Print parameters void SFSTaggerBase::PrintParam() const { + /// Print B-taggging options std::string excl = _options.btag_exclusive ? "Exclusive" : "Inclusive"; INFO << " with bjet: ΔR = " << _options.btag_matching_deltaR << " ; " << excl << endmsg; excl = _options.ctag_exclusive ? "Exclusive" : "Inclusive"; - INFO << " with cjet: ΔR = " << _options.ctag_matching_deltaR << " ; " << excl << endmsg; - if (_options.tautag_jetbased) - { + + /// Print C-tagging options + if (_options.enable_ctagging) { + INFO << " with cjet: ΔR = " + << _options.ctag_matching_deltaR << " ; " << excl << endmsg; + } + + /// Print Tau-tagging options + if (_options.tautag_jetbased) { excl = _options.ctag_exclusive ? "Exclusive" : "Inclusive"; INFO << " with tau : ΔR = " << _options.tautag_matching_deltaR << " ; " << excl << endmsg; - } - else - { + } else { INFO << " with tau : hadron-based tagging" << endmsg; } } @@ -394,45 +399,37 @@ namespace MA5 { /// Truth B-Jet tagging void SFSTaggerBase::BJetTagging(EventFormat &myEvent) const { - /// Bjet candidates - std::vector Candidates; - + /// Loop over B-hadrons for (auto &bHadron: myEvent.rec()->MCBquarks_) { - RecJetFormat* tag = 0; MAfloat32 DeltaRmax = _options.btag_matching_deltaR; - + /// @attention If not exclusive `current_ijet` will always be -1 + /// thus jets will only be tagged with respect to dR + MAint32 current_ijet = -1; /// Loop over jets for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) { MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(bHadron); if (dR <= DeltaRmax) { - if (_options.btag_exclusive) - { - tag = &(myEvent.rec()->jets()[ijet]); - DeltaRmax = dR; - } - else Candidates.push_back(&(myEvent.rec()->jets()[ijet])); + if (_options.btag_exclusive) { current_ijet = ijet; DeltaRmax = dR; } + else myEvent.rec()->jets()[ijet].setAllBtags(true); } } - if (_options.btag_exclusive && tag!=0) Candidates.push_back(tag); + if (current_ijet >= 0) myEvent.rec()->jets()[current_ijet].setAllBtags(true); } - - for (auto &jet: Candidates) - jet->setAllBtags(true); } /// Truth C-Jet tagging void SFSTaggerBase::CJetTagging(EventFormat &myEvent) const { - /// Cjet candidates - std::vector Candidates; - + /// Loop over C-hadrons for (auto &cHadron: myEvent.rec()->MCCquarks_) { MAfloat32 DeltaRmax = _options.ctag_matching_deltaR; - RecJetFormat* tag = 0; + /// @attention If not exclusive `current_ijet` will always be -1 + /// thus jets will only be tagged with respect to dR + MAint32 current_ijet = -1; /// Loop over jets for (MAuint32 ijet = 0; ijet < myEvent.rec()->jets().size(); ijet++) @@ -441,19 +438,20 @@ namespace MA5 { MAfloat32 dR = myEvent.rec()->jets()[ijet].dr(cHadron); if (dR <= DeltaRmax) { - if (_options.ctag_exclusive) - { - tag = &(myEvent.rec()->jets()[ijet]); - DeltaRmax = dR; + if (_options.ctag_exclusive) { current_ijet = ijet; DeltaRmax = dR; } + else { + if (_options.enable_ctagging) + myEvent.rec()->jets()[ijet].setAllCtags(true); + else myEvent.rec()->jets()[ijet].setTrueCtag(true); } - else Candidates.push_back(&(myEvent.rec()->jets()[ijet])); } } - if (_options.ctag_exclusive && tag!=0) Candidates.push_back(tag); + if (current_ijet >= 0) { + if (_options.enable_ctagging) + myEvent.rec()->jets()[current_ijet].setAllCtags(true); + else myEvent.rec()->jets()[current_ijet].setTrueCtag(true); + } } - - for (auto &jet: Candidates) - jet->setAllCtags(true); } /// This method implements tau matching for jets diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index eaf3191f..ad7e3eb8 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -48,11 +48,12 @@ namespace MA5 { /// a jet and the jet will be considered as tau jet. /// /// @warning DR matching for tau tagging is only available on jet based method - MAfloat32 btag_matching_deltaR = 0.3; + MAfloat32 btag_matching_deltaR = 0.5; MAbool btag_exclusive = true; - MAfloat32 ctag_matching_deltaR = 0.3; + MAbool enable_ctagging = false; + MAfloat32 ctag_matching_deltaR = 0.5; MAbool ctag_exclusive = true; - MAfloat32 tautag_matching_deltaR = 0.3; + MAfloat32 tautag_matching_deltaR = 0.5; MAbool tautag_exclusive = true; MAbool tautag_jetbased = false; }; From d22ac496a6f21e0cf94cbf4efc072b57d96fdf88 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 23 Jun 2022 16:20:15 +0100 Subject: [PATCH 34/67] expand docstring --- tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index ad7e3eb8..d5e19911 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -42,6 +42,11 @@ namespace MA5 { /// /// options starting with ctag and tautag are the ones corresponding to c-jet and tau-jet tagging /// + /// @warning Old tagger did not have c-tagger. In order to match the results from the old + /// tagger, adding @code enable_ctagging = false @endcode .This makes sure that the results + /// do not change between versions. Additionally @code deltaR = 0.5 @endcode was the default + /// value in old version that has been reinstated as well. + /// /// @code taujtag_jetbased : bool@endcode /// States the nature of tau tagging proecedure. If false, the hadronic tau in the event history /// will be found and used as hadronic tau object. if True, this hadronic tau will be matched with From 2699ff5ae1297e22da122c2c8dba3ea47048072e Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 23 Jun 2022 16:20:40 +0100 Subject: [PATCH 35/67] adapt jet identification algo --- .../configuration/beauty_identification.py | 11 ++---- .../configuration/charm_identification.py | 39 +++++++++++++------ .../configuration/tau_identification.py | 32 ++++++++------- madanalysis/interpreter/cmd_set.py | 1 + 4 files changed, 51 insertions(+), 32 deletions(-) diff --git a/madanalysis/configuration/beauty_identification.py b/madanalysis/configuration/beauty_identification.py index ae7f44d1..6702ced0 100644 --- a/madanalysis/configuration/beauty_identification.py +++ b/madanalysis/configuration/beauty_identification.py @@ -36,7 +36,7 @@ class BeautyIdentification: userVariables = { "bjet_id.matching_dr": [str(default_matching_dr)], - "bjet_id.exclusive": [str(default_exclusive)], + "bjet_id.exclusive": ["True", "False"], } def __init__(self): @@ -70,15 +70,12 @@ def SampleAnalyzerConfigString(self): } def user_GetValues(self, variable): - try: - return BeautyIdentification.userVariables[variable] - except: - return [] + return BeautyIdentification.userVariables.get(variable, []) def user_GetParameters(self): return list(BeautyIdentification.userVariables.keys()) - def user_SetParameter(self, parameter, value): + def user_SetParameter(self, parameter: str, value: str) -> bool: # matching deltar if parameter == "bjet_id.matching_dr": try: @@ -93,7 +90,7 @@ def user_SetParameter(self, parameter, value): # exclusive elif parameter == "bjet_id.exclusive": - if value not in ["true", "false"]: + if value.lower() not in ["true", "false"]: logging.getLogger("MA5").error("'exclusive' possible values are : 'true', 'false'") return False self.exclusive = value == "true" diff --git a/madanalysis/configuration/charm_identification.py b/madanalysis/configuration/charm_identification.py index a03862f0..1d83aa57 100644 --- a/madanalysis/configuration/charm_identification.py +++ b/madanalysis/configuration/charm_identification.py @@ -31,19 +31,20 @@ class CharmIdentification: default_matching_dr = 0.5 default_exclusive = True - userVariables = { - "cjet_id.matching_dr": [str(default_matching_dr)], - "cjet_id.exclusive": [str(default_exclusive)], - } + userVariables = {"cjet_id.status": ["on", "off"]} def __init__(self): self.matching_dr = CharmIdentification.default_matching_dr self.exclusive = CharmIdentification.default_exclusive + self.status = False def Display(self): - logging.getLogger("MA5").info(" + b-jet identification:") - self.user_DisplayParameter("cjet_id.matching_dr") - self.user_DisplayParameter("cjet_id.exclusive") + logging.getLogger("MA5").info(" + c-jet identification:") + if self.status: + self.user_DisplayParameter("cjet_id.matching_dr") + self.user_DisplayParameter("cjet_id.exclusive") + else: + logging.getLogger("MA5").info(" + Disabled") def user_DisplayParameter(self, parameter): if parameter == "cjet_id.matching_dr": @@ -61,18 +62,16 @@ def SampleAnalyzerConfigString(self): return { "cjet_id.matching_dr": str(self.matching_dr), "cjet_id.exclusive": "1" if self.exclusive else "0", + "cjet_id.enable_ctagging": "1" if self.status else "0", } def user_GetValues(self, variable): - try: - return CharmIdentification.userVariables[variable] - except: - return [] + return CharmIdentification.userVariables.get(variable, []) def user_GetParameters(self): return list(CharmIdentification.userVariables.keys()) - def user_SetParameter(self, parameter, value): + def user_SetParameter(self, parameter, value: str) -> bool: # matching deltar if parameter == "cjet_id.matching_dr": try: @@ -85,6 +84,22 @@ def user_SetParameter(self, parameter, value): return False self.matching_dr = number + # Enable ctagger + elif parameter == "cjet_id.status": + if value.lower() not in ["on", "off"]: + logging.getLogger("MA5").error("C-Jet tagging status can only be `on` or `off`.") + return False + self.status = value.lower() == "on" + if self.status and "cjet_id.matching_dr" not in CharmIdentification.userVariables.keys(): + CharmIdentification.userVariables.update( + { + "cjet_id.matching_dr": [str(CharmIdentification.default_matching_dr)], + "cjet_id.exclusive": ["True", "False"], + } + ) + else: + CharmIdentification.userVariables = {"cjet_id.status": ["on", "off"]} + # exclusive elif parameter == "cjet_id.exclusive": if value not in ["true", "false"]: diff --git a/madanalysis/configuration/tau_identification.py b/madanalysis/configuration/tau_identification.py index 8822a99f..31fa4622 100644 --- a/madanalysis/configuration/tau_identification.py +++ b/madanalysis/configuration/tau_identification.py @@ -30,33 +30,33 @@ class TauIdentification: default_matching_dr = 0.3 default_exclusive = False - default_efficiency = 1.0 - default_misid_ljet = 0.0 default_reconstruction_method = "hadron-based" userVariables = { - "tau_id.matching_dr": [str(default_misid_ljet)], "tau_id.reconstruction_method": ["jet-based", "hadron-based"], } def __init__(self): - self.efficiency = TauIdentification.default_efficiency - self.misid_ljet = TauIdentification.default_misid_ljet self.matching_dr = TauIdentification.default_matching_dr self.reconstruction_method = TauIdentification.default_reconstruction_method self.exclusive = TauIdentification.default_exclusive def Display(self): logging.getLogger("MA5").info(" + hadronic-tau identification:") - self.user_DisplayParameter("tau_id.matching_dr") + if self.reconstruction_method == "jet-based": + self.user_DisplayParameter("tau_id.matching_dr") self.user_DisplayParameter("tau_id.reconstruction_method") def user_DisplayParameter(self, parameter): if parameter == "tau_id.matching_dr": logging.getLogger("MA5").info(f" + DeltaR matching = {self.matching_dr:.2f}") - elif parameter == "tau_id.clustering_method": + elif parameter == "tau_id.reconstruction_method": logging.getLogger("MA5").info( - f" + Reconstruction method = {self.reconstruction_method}" + f" + Reconstruction method: {self.reconstruction_method}" + ) + elif parameter == "tau_id.exclusive": + logging.getLogger("MA5").info( + f" + exclusive algo = {'true' if self.exclusive else 'false'}" ) else: logging.getLogger("MA5").error( @@ -67,14 +67,11 @@ def SampleAnalyzerConfigString(self): return { "tau_id.matching_dr": str(self.matching_dr), "tau_id.reconstruction_method": "1" if self.reconstruction_method == "jet-based" else "0", - "tau_id.exclusive" : "1" if self.exclusive else "0", + "tau_id.exclusive": "1" if self.exclusive else "0", } def user_GetValues(self, variable): - try: - return TauIdentification.userVariables[variable] - except: - return [] + return TauIdentification.userVariables.get(variable, []) def user_GetParameters(self): return list(TauIdentification.userVariables.keys()) @@ -118,6 +115,15 @@ def user_SetParameter(self, parameter, value): + ", ".join(TauIdentification.userVariables["tau_id.reconstruction_method"]) ) return False + if self.reconstruction_method == "jet-based": + TauIdentification.userVariables.update( + {"tau_id.matching_dr": [str(TauIdentification.default_matching_dr)], + "tau_id.exclusive": ["True", "False"]} + ) + else: + TauIdentification.userVariables = { + "tau_id.reconstruction_method": ["jet-based", "hadron-based"] + } # efficiency elif parameter == "tau_id.efficiency": diff --git a/madanalysis/interpreter/cmd_set.py b/madanalysis/interpreter/cmd_set.py index 00564a17..1662ca8e 100644 --- a/madanalysis/interpreter/cmd_set.py +++ b/madanalysis/interpreter/cmd_set.py @@ -103,6 +103,7 @@ def do_main(self,args): object = args[0] # object = object.lower() object = object.replace('fastsim.bjet_id.','fastsim.bjet_idXXX') + object = object.replace('fastsim.cjet_id.','fastsim.cjet_idXXX') object = object.replace('fastsim.tau_id.','fastsim.tau_idXXX') objs = object.split('.') for i in range(len(objs)): From 684cf735edcb3792c1a4a84f9778d93056982353 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 23 Jun 2022 16:33:34 +0100 Subject: [PATCH 36/67] add switch to enable ctagging --- .../Process/JetClustering/JetClusterer.cpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index 34a5afce..9714dfac 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -150,7 +150,25 @@ MAbool JetClusterer::Initialize(const std::map& options } /// What is the cjet matching DR else if (key == "cjet_id.matching_dr") myTaggerOptions_->ctag_matching_deltaR = tmp; - /// Is cjet run via exclusive algorithm + + /// Is CJet tagging enabled + else if (key == "cjet_id.enable_ctagging") + { + try { + if (tmp == 1.) myTaggerOptions_->enable_ctagging = true; + else if (tmp == 0.) myTaggerOptions_->enable_ctagging = false; + else + throw EXCEPTION_WARNING( + "'cjet_id.enable_ctagging' must be equal to 0 or 1. Using default " + "value 'cjet_id.enable_ctagging' = " \ + + CONVERT->ToString(myTaggerOptions_->enable_ctagging), "", 0 + ); + } + catch (const std::exception &e) { + MANAGE_EXCEPTION(e); + } + } + /// Is taujet run via exclusive algorithm else if (key == "tau_id.exclusive") { try { From 9a52d6473b83041080e4e5758429e744c3d1c2c7 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 23 Jun 2022 18:04:43 +0100 Subject: [PATCH 37/67] code efficiency booleans are moved to SFSTaggerBase --- madanalysis/job/job_tagger_header.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/madanalysis/job/job_tagger_header.py b/madanalysis/job/job_tagger_header.py index e229fe72..6657d4bf 100644 --- a/madanalysis/job/job_tagger_header.py +++ b/madanalysis/job/job_tagger_header.py @@ -67,10 +67,6 @@ def WriteNewTaggerHeader(self, file): file.write('#include "SampleAnalyzer/Commons/Base/SFSTaggerBase.h"\n') file.write('namespace MA5 {\n') file.write(' class NewTagger: public SFSTaggerBase {\n') - file.write(' private:\n') - file.write(' /// Code efficiency booleans\n') - file.write(' MAbool _isJetTaggingOn, _isTauTaggingEffOn, _isMuonTaggingOn, _isElectronTaggingOn, _isPhotonTaggingOn;\n') - file.write(' SFSTaggerBaseOptions _options;\n') file.write(' public :\n') file.write(' /// Constructor without argument\n') file.write(' NewTagger() {}\n\n') From 2ef3a1e19e9997f510cf661761b4914c792c379c Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 23 Jun 2022 18:05:43 +0100 Subject: [PATCH 38/67] bugfix in tagger names --- tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp index 6b10b474..cfcb0a3e 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.cpp @@ -106,10 +106,10 @@ namespace MA5 { const MAbool& RecJetFormat::tight_tautag() const { return tight_tautag_; } /// Accessor to the true c-tag - const MAbool& RecJetFormat::true_ctag() const {return true_btag_;} + const MAbool& RecJetFormat::true_ctag() const {return true_ctag_;} /// Accessor to the true b-tag - const MAbool& RecJetFormat::true_btag() const {return true_ctag_;} + const MAbool& RecJetFormat::true_btag() const {return true_btag_;} /// Accessor to the true tau-tag const MAbool& RecJetFormat::true_tautag() const {return true_tautag_;} From 23cbb439c3bcfad2fc1d14220eaf30783185405a Mon Sep 17 00:00:00 2001 From: jackaraz Date: Thu, 23 Jun 2022 18:06:17 +0100 Subject: [PATCH 39/67] move efficiency booleans to protected --- tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index d5e19911..4144d390 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -69,7 +69,7 @@ namespace MA5 { /// and used during tagging. If not defined, by default truth level tagging will be applied. class SFSTaggerBase { - private: + protected: /// Code efficiency booleans MAbool _isJetTaggingOn, _isTauTaggingEffOn, _isMuonTaggingOn, _isElectronTaggingOn, _isPhotonTaggingOn; SFSTaggerBaseOptions _options; From 4dac49536614418e62da3081981f0701126481cc Mon Sep 17 00:00:00 2001 From: jackaraz Date: Fri, 24 Jun 2022 09:03:10 +0100 Subject: [PATCH 40/67] bugfix for backwards compatibility --- .../Interfaces/fastjet/ClusterAlgoFastJet.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp b/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp index 70778dd5..3e9ccbed 100644 --- a/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp +++ b/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp @@ -113,7 +113,11 @@ MAbool ClusterAlgoFastJet::Execute(SampleFormat& mySample, EventFormat& myEvent, ); } - Meff += MET->pt(); + /// @attention in the earlier version of the code Meff is filled with MET->pt() at this point + /// we now switched to MHT because in the earlier version of the code when this function + /// executed MET was empty. For numerical consistency we use MHT here. + /// For details see JetClusterer.cpp and ClusterAlgoFastjet.cpp in v1.10.x + Meff += MHT->pt(); return true; } From aca18af07fbc986a8c0db47110f0892e41d5f9d8 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Fri, 24 Jun 2022 10:35:37 +0100 Subject: [PATCH 41/67] bugfix in code efficiency booleans --- madanalysis/job/job_tagger_header.py | 2 +- tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/madanalysis/job/job_tagger_header.py b/madanalysis/job/job_tagger_header.py index 6657d4bf..2831e0e9 100644 --- a/madanalysis/job/job_tagger_header.py +++ b/madanalysis/job/job_tagger_header.py @@ -75,7 +75,7 @@ def WriteNewTaggerHeader(self, file): file.write(' void Initialize() {\n') file.write(' /// @brief Booleans for code efficiency\n') file.write(' /// Turn on the usage of tau tagging efficiency\n') - file.write(f" _isTauTaggingEffOn = {'true' if (5,5) in [(x[0], x[1]) for x in self.unique_rules] else 'false'};\n") + file.write(f" _isTauTaggingEffOn = {'true' if (15, 15) in [(x[0], x[1]) for x in self.unique_rules] else 'false'};\n") file.write(' /// Turn on the usage of jet (mis)tagging efficiency\n') file.write(f" _isJetTaggingOn = {'true' if any([x in [(x[0], x[1]) for x in self.unique_rules] for x in [(5,5), (4,5), (21,5), (5,4), (4,4), (21,4), (21,15), (21,11), (21,22)]]) else 'false'};\n") file.write(' /// Turn on the usage of muon (mis)tagging efficiency\n') diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index cbf88d32..9b069ccd 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -217,7 +217,7 @@ namespace MA5 { myEvent.rec()->jets().erase(myEvent.rec()->jets().begin() + toRemove[i-1]); toRemove.clear(); - if (_isTauTaggingEffOn) + if (_isTauTaggingEffOn && !_options.tautag_jetbased) { /// @attention In Jet based tau tagging this loop will not run. If its runnning thats a bug for (MAuint32 itau = 0; itau < Ntau; itau++) From 5007303f9fb617638cad858ca0b95a93397fa266 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Fri, 24 Jun 2022 11:29:14 +0100 Subject: [PATCH 42/67] expand the printing functionality --- tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index 9b069ccd..dc4de519 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -34,19 +34,24 @@ namespace MA5 { { /// Print B-taggging options std::string excl = _options.btag_exclusive ? "Exclusive" : "Inclusive"; - INFO << " with bjet: ΔR = " << _options.btag_matching_deltaR << " ; " << excl << endmsg; + INFO << " with bjet: matching ΔR = " + << _options.btag_matching_deltaR + << " ; " << excl << endmsg; excl = _options.ctag_exclusive ? "Exclusive" : "Inclusive"; /// Print C-tagging options if (_options.enable_ctagging) { - INFO << " with cjet: ΔR = " - << _options.ctag_matching_deltaR << " ; " << excl << endmsg; + INFO << " with cjet: matching ΔR = " + << _options.ctag_matching_deltaR + << " ; " << excl << endmsg; } /// Print Tau-tagging options if (_options.tautag_jetbased) { excl = _options.ctag_exclusive ? "Exclusive" : "Inclusive"; - INFO << " with tau : ΔR = " << _options.tautag_matching_deltaR << " ; " << excl << endmsg; + INFO << " with tau : matching ΔR = " + << _options.tautag_matching_deltaR + << " ; " << excl << endmsg; } else { INFO << " with tau : hadron-based tagging" << endmsg; } From 6064eabc3c50bc24a57fdf0bfb427ff63b729d11 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Fri, 24 Jun 2022 16:15:28 +0100 Subject: [PATCH 43/67] update changelog --- doc/releases/changelog-v2.0.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/releases/changelog-v2.0.md b/doc/releases/changelog-v2.0.md index 362b06ac..ff6b9383 100644 --- a/doc/releases/changelog-v2.0.md +++ b/doc/releases/changelog-v2.0.md @@ -26,6 +26,10 @@ so that MadAnalysis can be compiled without these modules as well. * Tagger module has been redesigned to accommodate substructure module. [(#86)](https://github.com/MadAnalysis/madanalysis5/pull/86) +* Multilevel object tagging has been enabled through SFS. + ([#97](https://github.com/MadAnalysis/madanalysis5/pull/97)) + * Option to activate c-jet tagging has been introduced. + * Option to use jet-based hadronic tau matching has been introduced. ## Improvements @@ -35,6 +39,9 @@ so that MadAnalysis can be compiled without these modules as well. ## Bug fixes +* Various bugfixes for matching the numeric results to the Ma5 v1.10. + ([#97](https://github.com/MadAnalysis/madanalysis5/pull/97)) + ## Contributors This release contains contributions from (in alphabetical order): From 03304933bd4ea4a0ad90d37abd8ac9ae58b1d4d7 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Fri, 24 Jun 2022 17:26:59 +0100 Subject: [PATCH 44/67] expand docstring * The numeric difference between multitag and main branch is visible when ExclusiveId_ = false --- tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index 45705900..f19dbe3c 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -70,7 +70,13 @@ namespace MA5 /// Print SFS banner MAbool SFSbanner_; - /// Exclusive id for tau-elec-photon-jet + /// @brief Exclusive id for tau-elec-photon-jet + /// @code ExclusiveId_ = true; @endcode + /// Exclusive algorithm: FS Leptons (photons) originated from hadronic decays + /// will not be included in Lepton (photon) collection. + /// @code ExclusiveId_ = false; @endcode + /// Includive algorithm: All FS leptons (photons) will be included in + /// their corresponding containers. MAbool ExclusiveId_; /// Primary Jet ID From d6a5c4921e04374a4fdb160387612f7657a28e84 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Fri, 24 Jun 2022 22:38:06 +0100 Subject: [PATCH 45/67] fix the numeric difference in inclusive mode between main branch --- .../Process/JetClustering/JetClusterer.cpp | 262 ++++++++---------- 1 file changed, 123 insertions(+), 139 deletions(-) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index 9714dfac..60ff003c 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -288,25 +288,25 @@ MAbool JetClusterer::IsLast(const MCParticleFormat* part, EventFormat& myEvent) MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) { // Safety - if (mySample.mc()==0 || myEvent.mc()==0) return false; - if (mySample.rec()==0) mySample.InitializeRec(); - if (myEvent.rec() ==0) myEvent.InitializeRec(); + if (mySample.mc() == 0 || myEvent.mc() == 0) return false; + if (mySample.rec() == 0) mySample.InitializeRec(); + if (myEvent.rec() == 0) myEvent.InitializeRec(); // Reseting the reconstructed event myEvent.rec()->Reset(); // Veto - std::vector vetos(myEvent.mc()->particles().size(),false); - std::set vetos2; + std::vector vetos(myEvent.mc()->particles().size(), false); + std::set vetos2; // shortcut for TET & THT - MAfloat64 & TET = myEvent.rec()->TET(); + MAfloat64 &TET = myEvent.rec()->TET(); // MAfloat64 & THT = myEvent.rec()->THT(); - RecParticleFormat* MET = &(myEvent.rec()->MET()); - RecParticleFormat* MHT = &(myEvent.rec()->MHT()); + RecParticleFormat *MET = &(myEvent.rec()->MET()); + RecParticleFormat *MHT = &(myEvent.rec()->MHT()); // Filling the dataformat with electron/muon - for (MAuint32 i=0;iparticles().size();i++) + for (MAuint32 i = 0; i < myEvent.mc()->particles().size(); i++) { const MCParticleFormat& part = myEvent.mc()->particles()[i]; MAuint32 absid = std::abs(part.pdgid()); @@ -372,7 +372,7 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) if (!found) myEvent.rec()->MCBquarks_.push_back(&(part)); } - // looking for c quarks + /// looking for c quarks else if (absid==4) { MAbool found=false; @@ -384,7 +384,7 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) if (!found) myEvent.rec()->MCCquarks_.push_back(&(part)); } - // looking for taus + /// looking for taus else if (absid==15) { // rejecting particle if coming from hadronization @@ -416,9 +416,7 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) } if (!found) myEvent.rec()->MCMuonicTaus_.push_back(&(part)); } - - // Saving taus decaying into electrons (only one copy) - else if (electronic) + else if (electronic) // Saving taus decaying into electrons (only one copy) { MAbool found=false; for (MAuint32 j=0;jMCElectronicTaus_.size();j++) @@ -428,9 +426,7 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) } if (!found) myEvent.rec()->MCElectronicTaus_.push_back(&(part)); } - - // Saving taus decaying into hadrons (only copy) - else + else // Saving taus decaying into hadrons (only copy) { MAbool found=false; for (MAuint32 j=0;jMCHadronicTaus_.size();j++) @@ -444,101 +440,92 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) myEvent.rec()->MCHadronicTaus_.push_back(&(part)); /// If tau tagging is jet based do not proceed - if (!myTaggerOptions_->tautag_jetbased) - { - // Smearing the hadronic taus - MCParticleFormat smeared = mySmearer_->Execute( - &part, static_cast(absid) + if (myTaggerOptions_->tautag_jetbased) continue; + + // Smearing the hadronic taus + MCParticleFormat smeared = mySmearer_->Execute( + &part, static_cast(absid) + ); + // If smeared pt is zero, no need to count the particle but it still needs + // to be vetoed for jet clustering. + if (smeared.pt() > 1e-10) { + // Creating reco hadronic taus + RecTauFormat* myTau = myEvent.rec()->GetNewTau(); + if (part.pdgid()>0) myTau->setCharge(-1); + else myTau->setCharge(+1); + myTau->setMomentum(smeared.momentum()); + myTau->setD0(smeared.d0()); + myTau->setDZ(smeared.dz()); + myTau->setD0Approx(smeared.d0_approx()); + myTau->setDZApprox(smeared.dz_approx()); + myTau->setProductionVertex( + MALorentzVector(part.mothers()[0]->decay_vertex().X(), + part.mothers()[0]->decay_vertex().Y(), + part.mothers()[0]->decay_vertex().Z(), + 0.0) ); - // If smeared pt is zero, no need to count the particle but it still needs - // to be vetoed for jet clustering. - if (smeared.pt() > 1e-10) - { - // Creating reco hadronic taus - RecTauFormat* myTau = myEvent.rec()->GetNewTau(); - if (part.pdgid()>0) myTau->setCharge(-1); - else myTau->setCharge(+1); - myTau->setMomentum(smeared.momentum()); - myTau->setD0(smeared.d0()); - myTau->setDZ(smeared.dz()); - myTau->setD0Approx(smeared.d0_approx()); - myTau->setDZApprox(smeared.dz_approx()); - myTau->setProductionVertex( - MALorentzVector(part.mothers()[0]->decay_vertex().X(), - part.mothers()[0]->decay_vertex().Y(), - part.mothers()[0]->decay_vertex().Z(), - 0.0) - ); - myTau->setClosestApproach(smeared.closest_approach()); - myTau->setMc(&part); - myTau->setDecayMode(PHYSICS->GetTauDecayMode(myTau->mc())); - if (myTau->DecayMode()<=0) myTau->setNtracks(0); // ERROR case - else if (myTau->DecayMode()==7 || - myTau->DecayMode()==9) myTau->setNtracks(3); // 3-Prong - else myTau->setNtracks(1); // 1-Prong - - /// Set MET and TET - if (ExclusiveId_) { - (*MET) -= myTau->momentum(); - TET += myTau->pt(); - } - } - - // Searching final state - GetFinalState(&part,vetos2); - } + myTau->setClosestApproach(smeared.closest_approach()); + myTau->setMc(&part); + myTau->setDecayMode(PHYSICS->GetTauDecayMode(myTau->mc())); + if (myTau->DecayMode() <= 0) myTau->setNtracks(0); // ERROR case + else if (myTau->DecayMode() == 7 || + myTau->DecayMode() == 9) + myTau->setNtracks(3); // 3-Prong + else myTau->setNtracks(1); // 1-Prong + + /// Set MET and TET + if (ExclusiveId_) { (*MET) -= myTau->momentum(); TET += myTau->pt(); } + + } // (smeared.pt() < 1e-10) + + // Searching final state + GetFinalState(&part,vetos2); } } - } - } + } // if (absid==15) + } // if (PHYSICS->Id->IsInterState(part)) - // Keeping only final states + // Keeping only final states else if (PHYSICS->Id->IsFinalState(part)) { - // keeping only electron, muon and photon - if (absid==22 || absid==11 || absid==13) + // rejecting particle if coming from hadronization + if (!(ExclusiveId_ && LOOP->ComingFromHadronDecay(&part, mySample))) { - // rejecting particle if coming from hadronization - if ( !(ExclusiveId_ && LOOP->ComingFromHadronDecay(&part,mySample))) + // Muons + if (absid == 13) { - - // Muons - if (absid==13) - { - vetos[i]=true; - - // Smearing its momentum - MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); - if (smeared.pt() <= 1e-10) continue; - - RecLeptonFormat * muon = myEvent.rec()->GetNewMuon(); - muon->setMomentum(smeared.momentum()); - muon->setD0(smeared.d0()); - muon->setDZ(smeared.dz()); - muon->setD0Approx(smeared.d0_approx()); - muon->setDZApprox(smeared.dz_approx()); - muon->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), - part.mothers()[0]->decay_vertex().Y(), - part.mothers()[0]->decay_vertex().Z(),0.0)); - muon->setClosestApproach(smeared.closest_approach()); - muon->setMc(&(part)); - if (part.pdgid()==13) muon->SetCharge(-1); - else muon->SetCharge(+1); + vetos[i]=true; + + // Smearing its momentum + MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); + if (smeared.pt() > 1e-10) { + RecLeptonFormat *current_muon = myEvent.rec()->GetNewMuon(); + current_muon->setMomentum(smeared.momentum()); + current_muon->setD0(smeared.d0()); + current_muon->setDZ(smeared.dz()); + current_muon->setD0Approx(smeared.d0_approx()); + current_muon->setDZApprox(smeared.dz_approx()); + current_muon->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), + part.mothers()[0]->decay_vertex().Y(), + part.mothers()[0]->decay_vertex().Z(), 0.0)); + current_muon->setClosestApproach(smeared.closest_approach()); + current_muon->setMc(&(part)); + if (part.pdgid() == 13) current_muon->SetCharge(-1); + else current_muon->SetCharge(+1); /// Set MET and TET - (*MET) -= muon->momentum(); - TET += muon->pt(); + (*MET) -= current_muon->momentum(); + TET += current_muon->pt(); } + } // (absid == 13) + // Electrons + else if (absid==11) + { + vetos[i]=true; - // Electrons - else if (absid==11) - { - vetos[i]=true; - - // Smearing the electron momentum - MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); - if (smeared.pt() <= 1e-10) continue; - + // Smearing the electron momentum + MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); + if (smeared.pt() > 1e-10) { RecLeptonFormat * elec = myEvent.rec()->GetNewElectron(); elec->setMomentum(smeared.momentum()); elec->setD0(smeared.d0()); @@ -554,44 +541,41 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) else elec->SetCharge(+1); /// Set MET and TET - if (ExclusiveId_) { - (*MET) -= elec->momentum(); - TET += elec->pt(); - } + if (ExclusiveId_) { (*MET) -= elec->momentum(); TET += elec->pt(); } } - - // Photons - else if (absid==22) + } // if (absid==11) + // Photons + else if (absid==22 ) + { + if (!LOOP->IrrelevantPhoton(&part,mySample)) { - if (!LOOP->IrrelevantPhoton(&part,mySample)) - { - vetos[i]=true; - - // Smearing the photon momentum - MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); - if (smeared.pt() <= 1e-10) continue; - - RecPhotonFormat * photon = myEvent.rec()->GetNewPhoton(); - photon->setMomentum(smeared.momentum()); - photon->setD0(smeared.d0()); - photon->setDZ(smeared.dz()); - photon->setD0Approx(smeared.d0_approx()); - photon->setDZApprox(smeared.dz_approx()); - photon->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), - part.mothers()[0]->decay_vertex().Y(), - part.mothers()[0]->decay_vertex().Z(),0.0)); - photon->setClosestApproach(smeared.closest_approach()); - photon->setMc(&(part)); + vetos[i]=true; + + // Smearing the photon momentum + MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); + if (smeared.pt() > 1e-10) { + RecPhotonFormat * current_photon = myEvent.rec()->GetNewPhoton(); + current_photon->setMomentum(smeared.momentum()); + current_photon->setD0(smeared.d0()); + current_photon->setDZ(smeared.dz()); + current_photon->setD0Approx(smeared.d0_approx()); + current_photon->setDZApprox(smeared.dz_approx()); + current_photon->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), + part.mothers()[0]->decay_vertex().Y(), + part.mothers()[0]->decay_vertex().Z(), + 0.0)); + current_photon->setClosestApproach(smeared.closest_approach()); + current_photon->setMc(&(part)); /// Set MET and TET - if (ExclusiveId_) { - (*MET) -= photon->momentum(); - TET += photon->pt(); - } - } - } - } + if (ExclusiveId_) { (*MET) -= current_photon->momentum(); TET += current_photon->pt(); } + } // (smeared.pt() <= 1e-10) + } // (!LOOP->IrrelevantPhoton(&part,mySample)) + } // (absid==22 && !reject_hadronic) } + + // Collect Hadrons for jet clustering... + // Putting the good inputs into the containter // Good inputs = - final state // - visible @@ -605,8 +589,7 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) if (vetos[i]) continue; if (vetos2.find(&part)!=vetos2.end()) continue; } - - // NonExclusive Id mode + // NonExclusive Id mode else if (std::abs(part.pdgid())==13) continue; // Smearer module returns a smeared MCParticleFormat object @@ -617,14 +600,15 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) // Filling good particle for clustering myEvent.rec()->AddHadron(smeared, i); - } - } + + } // if (PHYSICS->Id->IsFinalState(part)) + } // for (MAuint32 i=0;iparticles().size();i++) // Set Primary Jet ID myEvent.rec()->SetPrimaryJetID(JetID_); // Launching the clustering // -> Filling the collection: myEvent->rec()->jets() - algo_->Execute(mySample,myEvent,mySmearer_); + algo_->Execute(mySample, myEvent, mySmearer_); #ifdef MA5_FASTJET_MODE // Cluster additional jets separately. In order to save time Execute function @@ -685,7 +669,7 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) } // Load additional Jets -MAbool JetClusterer::LoadJetConfiguration(std::map options) +MAbool JetClusterer::LoadJetConfiguration(std::map options) { #ifdef MA5_FASTJET_MODE std::string new_jetid; From 8d57c08b091d6ac5e6bf6db1e98a762e795952dd Mon Sep 17 00:00:00 2001 From: jackaraz Date: Fri, 24 Jun 2022 22:54:56 +0100 Subject: [PATCH 46/67] clean the heap in JetClusterer.h --- .../Process/JetClustering/JetClusterer.h | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index f19dbe3c..77113cac 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -115,26 +115,25 @@ namespace MA5 public : /// Constructor without argument - JetClusterer (ClusterAlgoBase* algo) - { + JetClusterer (ClusterAlgoBase* algo) { // Initializing tagger - algo_ = algo; + algo_ = algo; #ifdef MA5_FASTJET_MODE cluster_collection_.clear(); substructure_collection_.clear(); #endif - mySmearer_ = 0; - myTagger_ = 0; + mySmearer_ = 0; + myTagger_ = 0; myTaggerOptions_ = 0; SFSbanner_ = true; ExclusiveId_ = false; - JetID_ = "Ma5Jet"; - muon=0; - electron=0; - tauH=0; - tauM=0; - tauE=0; - photon=0; + JetID_ = "Ma5Jet"; + muon = 0; + electron = 0; + tauH = 0; + tauM = 0; + tauE = 0; + photon = 0; isocone_track_radius_.clear(); isocone_electron_radius_.clear(); isocone_muon_radius_.clear(); @@ -142,8 +141,12 @@ namespace MA5 } /// Destructor - ~JetClusterer() - { } + ~JetClusterer() { + if (algo_ != 0) delete algo_; + if (mySmearer_ != 0) delete mySmearer_; + if (myTagger_ != 0) delete myTagger_; + if (myTaggerOptions_ != 0) delete myTaggerOptions_; + } /// Initialization MAbool Initialize(const std::map& options); From 087619c169f42e90173a315e523b83dbc4b014fa Mon Sep 17 00:00:00 2001 From: jackaraz Date: Fri, 24 Jun 2022 23:14:10 +0100 Subject: [PATCH 47/67] remove unnecessary headers --- .../Interfaces/fastjet/ClusterAlgoFastJet.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp b/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp index 3e9ccbed..0f3687db 100644 --- a/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp +++ b/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp @@ -24,14 +24,6 @@ // SampleAnalyser headers #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.h" -#include "SampleAnalyzer/Commons/Service/LoopService.h" -#include "SampleAnalyzer/Commons/Service/Physics.h" -#include "SampleAnalyzer/Commons/Service/PDGService.h" -#include "SampleAnalyzer/Commons/Base/SmearerBase.h" - -// FastJet headers -#include - using namespace MA5; From 93c6e0a46b0318284d1610311f2335c570f1e781 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Fri, 24 Jun 2022 23:17:16 +0100 Subject: [PATCH 48/67] turn off verbosity of the tracker --- tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index 60ff003c..13595a99 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -346,7 +346,7 @@ MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) track->setProductionVertex(new_vertex); track->setClosestApproach(smeared_track.closest_approach()); track->setMc(&(part)); - track->SetCharge(PDG->GetCharge(part.pdgid()) / 3.); + track->SetCharge(PDG->GetCharge(part.pdgid(), false) / 3.); } } } From c2b3df595fef768ecf7ad7b4829a511ab79cfcb4 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 09:08:26 +0100 Subject: [PATCH 49/67] extend the documentation --- tools/SampleAnalyzer/Commons/Service/Utils.h | 57 ++++++++++++-------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/tools/SampleAnalyzer/Commons/Service/Utils.h b/tools/SampleAnalyzer/Commons/Service/Utils.h index 3a8d7441..b69f4310 100644 --- a/tools/SampleAnalyzer/Commons/Service/Utils.h +++ b/tools/SampleAnalyzer/Commons/Service/Utils.h @@ -46,6 +46,8 @@ namespace MA5 // ===== Vector operations ===== // // ============================= // + /// Create a new vector by adding two vectors together. + /// @attention this wont change the content of two original vectors template std::vector operator+(const std::vector &A, const std::vector &B) { @@ -56,6 +58,9 @@ namespace MA5 return AB; } + /// Add second vector to the first vector + /// @attention this wont create a new vector but + /// will add the second to the first template std::vector &operator+=(std::vector &A, const std::vector &B) { @@ -124,34 +129,42 @@ namespace MA5 // Overlap Removal // //=================// - // Overlap Removal + /// @brief Overlap Removal + /// Remove overlaping objects from the first collection (v1) with + /// respect to a minimum deltaR distance from the second collection (v2) template std::vector - OverlapRemoval(std::vector &v1, std::vector &v2, - const MAdouble64 &drmin) + OverlapRemoval(std::vector &v1, std::vector &v2, + const MAdouble64 &drmin) { - // Determining with objects should be removed - std::vector mask(v1.size(),false); - for (MAuint32 j=0;jdr(v1[j]) < drmin) - { - mask[j]=true; - break; - } - - // Building the cleaned container - std::vector cleaned_v1; - for (MAuint32 i=0;i mask(v1.size(),false); + for (MAuint32 j=0;jdr(v1[j]) < drmin) + { + mask[j]=true; + break; + } + + // Building the cleaned container + std::vector cleaned_v1; + for (MAuint32 i=0;idr(el) > 0.2;}); + /// Example: + /// @code + /// signaljets = conditional_removal(signaljets,signalel, + /// [] (const RecJetFormat * jet, const RecLeptonFormat * el) + /// {return jet->dr(el) > 0.2;}); + /// @endcode + /// Remove objects from the first collection (v1) with respect + /// to a boolean function between v1 and second collection. template std::vector conditional_removal( - std::vector &v1, std::vector &v2, FN func + std::vector &v1, std::vector &v2, FN func ) { // Determining with objects should be removed From 1e7c9abd20eddd74a2b395547b174e7458d4483d Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 09:08:36 +0100 Subject: [PATCH 50/67] remove old tagger --- .../Commons/Base/TaggerBase.cpp | 131 ------------------ .../SampleAnalyzer/Commons/Base/TaggerBase.h | 126 ----------------- 2 files changed, 257 deletions(-) delete mode 100644 tools/SampleAnalyzer/Commons/Base/TaggerBase.cpp delete mode 100644 tools/SampleAnalyzer/Commons/Base/TaggerBase.h diff --git a/tools/SampleAnalyzer/Commons/Base/TaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/TaggerBase.cpp deleted file mode 100644 index ecf9a868..00000000 --- a/tools/SampleAnalyzer/Commons/Base/TaggerBase.cpp +++ /dev/null @@ -1,131 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks -// The MadAnalysis development team, email: -// -// This file is part of MadAnalysis 5. -// Official website: -// -// MadAnalysis 5 is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// MadAnalysis 5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with MadAnalysis 5. If not, see -// -//////////////////////////////////////////////////////////////////////////////// - - -// SampleAnalyzer headers -#include "SampleAnalyzer/Commons/Base/TaggerBase.h" -#include "SampleAnalyzer/Commons/Service/ExceptionService.h" -#include "SampleAnalyzer/Commons/Service/ConvertService.h" - - -using namespace MA5; - -MAbool TaggerBase::IsLast(MCParticleFormat* part, EventFormat& myEvent) -{ - for (MAuint32 i=0; idaughters().size(); i++) - { - if (part->daughters()[i]->pdgid()==part->pdgid()) return false; - } - return true; -} - - - - -MAbool TaggerBase::SetParameter(const std::string& key, - const std::string& value, - std::string header) -{ - // Method - if (key=="method") - { - MAint32 tmp=0; - std::stringstream str,str2; - std::string Method_str; - str << value; - str >> tmp; - str2 << Method_; - str2 >> Method_str; - try - { - if (tmp<0 || tmp>3) throw EXCEPTION_WARNING("Available methods are 1, 2 and 3. Using the default value = "+Method_str,"",0); - Method_=tmp; - } - catch(const std::exception& e) - { - MANAGE_EXCEPTION(e); - } - } - - // deltaR - else if (key=="matching_dr") - { - MAfloat32 tmp=0; - std::stringstream str; - str << value; - str >> tmp; - try - { - if (tmp<0) throw EXCEPTION_WARNING("DeltaRmax must be a positive value. Using the default value = "+CONVERT->ToString(DeltaRmax_),"",0); - DeltaRmax_=tmp; - } - catch(const std::exception& e) - { - MANAGE_EXCEPTION(e); - } - } - - // exclusive - else if (key=="exclusive") - { - MAint32 tmp=0; - std::stringstream str; - str << value; - str >> tmp; - try - { - if (tmp<0) throw EXCEPTION_WARNING("Exclusive_ must be equal to 0 or 1.value. Using the default value = "+CONVERT->ToString(Exclusive_),"",0); - Exclusive_=(tmp==1); - } - catch(const std::exception& e) - { - MANAGE_EXCEPTION(e); - } - } - - // efficiency - else if (key=="efficiency") - { - MAfloat32 tmp=0; - std::stringstream str; - str << value; - str >> tmp; - try - { - if (tmp<0) throw EXCEPTION_WARNING("Efficiency must be a positive value. Using the default value = "+CONVERT->ToString(Efficiency_),"",0); - if (tmp>1) throw EXCEPTION_WARNING("Efficiency cannot be greater than 1. Using the default value = "+CONVERT->ToString(Efficiency_),"",0); - Efficiency_=tmp; - } - catch(const std::exception& e) - { - MANAGE_EXCEPTION(e); - } - if (Efficiency_!=1) doEfficiency_=true; else doEfficiency_=false; - } - - // Other - else return false; - - return true; - -} diff --git a/tools/SampleAnalyzer/Commons/Base/TaggerBase.h b/tools/SampleAnalyzer/Commons/Base/TaggerBase.h deleted file mode 100644 index 0cd53ccb..00000000 --- a/tools/SampleAnalyzer/Commons/Base/TaggerBase.h +++ /dev/null @@ -1,126 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks -// The MadAnalysis development team, email: -// -// This file is part of MadAnalysis 5. -// Official website: -// -// MadAnalysis 5 is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// MadAnalysis 5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with MadAnalysis 5. If not, see -// -//////////////////////////////////////////////////////////////////////////////// - - -#ifndef TAGGERBASE_H -#define TAGGERBASE_H - - -// STL headers -#include - -// SampleAnalyser headers -#include "SampleAnalyzer/Commons/Base/PortableDatatypes.h" -#include "SampleAnalyzer/Commons/DataFormat/EventFormat.h" -#include "SampleAnalyzer/Commons/DataFormat/SampleFormat.h" -#include "SampleAnalyzer/Commons/DataFormat/RecJetFormat.h" -#include "SampleAnalyzer/Commons/Service/Physics.h" -#include "SampleAnalyzer/Commons/Service/PDGService.h" -#include "SampleAnalyzer/Commons/Service/RandomService.h" - - -namespace MA5 -{ - -class TaggerBase -{ -//--------------------------------------------------------------------------------- -// data members -//--------------------------------------------------------------------------------- - protected : - - /// Method used - MAint32 Method_; - - /// Delta R max - MAfloat32 DeltaRmax_; - - /// Is the tagging exclusive ? - MAbool Exclusive_; - - /// Efficiency - MAfloat32 Efficiency_; - - /// Applying efficiency - MAbool doEfficiency_; - -//--------------------------------------------------------------------------------- -// method members -//--------------------------------------------------------------------------------- - public : - - /// Constructor without argument - TaggerBase() - { - Method_=1; - DeltaRmax_=0.5; - Exclusive_=false; - Efficiency_=1.; - doEfficiency_=false; - } - - /// Destructor - virtual ~TaggerBase() - {} - - /// Matching using dr - virtual void Method1(SampleFormat& mySample, EventFormat& myEvent)=0; - - /// Matching using the history - virtual void Method2(SampleFormat& mySample, EventFormat& myEvent)=0; - - /// Matching using a jet preselection with the history before calculating dr - virtual void Method3(SampleFormat& mySample, EventFormat& myEvent)=0; - - /// Matching general method - virtual void Execute(SampleFormat& mySample, EventFormat& myEvent)=0; - - /// Accessor to the selected method - MAint32 GetMethod() - {return Method_;} - - /// - MAbool IsLast(MCParticleFormat* part, EventFormat& myEvent); - - /// Set a parameter - virtual MAbool SetParameter(const std::string& key, const std::string& value, std::string header=""); - - /// Function for identification - MAbool IsIdentified() const - { - // no efficiency = default - if (!doEfficiency_) return true; - - // applying efficiency - MAdouble64 value = RANDOM->flat(); - if (value < Efficiency_) return true; - else return false; - } - - virtual std::string GetParameters()=0; - -}; - -} - -#endif From 593778ced76d58f19bf17f194060276e9dbdb5a4 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 09:08:57 +0100 Subject: [PATCH 51/67] update destructor --- tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index 77113cac..71bb7b82 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -146,6 +146,12 @@ namespace MA5 if (mySmearer_ != 0) delete mySmearer_; if (myTagger_ != 0) delete myTagger_; if (myTaggerOptions_ != 0) delete myTaggerOptions_; +#ifdef MA5_FASTJET_MODE + for (auto &col: cluster_collection_) + if (col.second != 0) delete col.second; + for (auto &col: substructure_collection_) + if (col.second != 0) delete col.second; +#endif } /// Initialization From 708d8a381c649331b20f4afd3c33381d382a4f5b Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 09:22:24 +0100 Subject: [PATCH 52/67] clean the header file --- .../Process/JetClustering/JetClusterer.cpp | 66 +++++++++++++++++ .../Process/JetClustering/JetClusterer.h | 72 +++---------------- 2 files changed, 77 insertions(+), 61 deletions(-) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index 13595a99..f7c5230b 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -28,9 +28,16 @@ #include "SampleAnalyzer/Commons/Service/ExceptionService.h" #include "SampleAnalyzer/Commons/Service/ConvertService.h" #include "SampleAnalyzer/Commons/Service/PDGService.h" +#include "SampleAnalyzer/Commons/Base/ClusterAlgoBase.h" +#include "SampleAnalyzer/Commons/Service/Physics.h" #ifdef MA5_FASTJET_MODE #include "SampleAnalyzer/Interfaces/substructure/VariableR.h" + #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoStandard.h" + #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoSISCone.h" + #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFMidpoint.h" + #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFJetClu.h" + #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoGridJet.h" #endif using namespace MA5; @@ -60,6 +67,65 @@ void SetConeRadius( } } +/// Constructor +JetClusterer::JetClusterer (ClusterAlgoBase* algo){ + // Initializing tagger + algo_ = algo; +#ifdef MA5_FASTJET_MODE + cluster_collection_.clear(); + substructure_collection_.clear(); +#endif + mySmearer_ = 0; + myTagger_ = 0; + myTaggerOptions_ = 0; + SFSbanner_ = true; + ExclusiveId_ = false; + JetID_ = "Ma5Jet"; + muon = 0; + electron = 0; + tauH = 0; + tauM = 0; + tauE = 0; + photon = 0; + isocone_track_radius_.clear(); + isocone_electron_radius_.clear(); + isocone_muon_radius_.clear(); + isocone_photon_radius_.clear(); +} + + +///Destructor +JetClusterer::~JetClusterer() { + if (algo_ != 0) delete algo_; + if (mySmearer_ != 0) delete mySmearer_; + if (myTagger_ != 0) delete myTagger_; + if (myTaggerOptions_ != 0) delete myTaggerOptions_; +#ifdef MA5_FASTJET_MODE + for (auto &col: cluster_collection_) + if (col.second != 0) delete col.second; + for (auto &col: substructure_collection_) + if (col.second != 0) delete col.second; +#endif +} + +/// Accessor to the jet clusterer name +std::string JetClusterer::GetName() +{ + if (algo_==0) return "NotDefined"; + else return algo_->GetName(); +} + +/// Accessor to the tagger parameters +void JetClusterer::TaggerParameters() +{ myTagger_->PrintParam(); } + +/// Print parameters +void JetClusterer::PrintParam() +{ algo_->PrintParam(); } + +/// Accessor to the jet clusterer parameters +std::string JetClusterer::GetParameters() +{ return algo_->GetParameters(); } // ----------------------------------------------------------------------------- diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index 71bb7b82..abacf563 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -28,31 +28,22 @@ // SampleAnalyser headers #include "SampleAnalyzer/Commons/DataFormat/EventFormat.h" #include "SampleAnalyzer/Commons/DataFormat/SampleFormat.h" -#include "SampleAnalyzer/Commons/Service/Physics.h" -#include "SampleAnalyzer/Commons/Base/ClusterAlgoBase.h" #include "SampleAnalyzer/Commons/Base/SmearerBase.h" #include "SampleAnalyzer/Commons/Base/SFSTaggerBase.h" #ifdef MA5_FASTJET_MODE -#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoStandard.h" -#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoSISCone.h" -#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFMidpoint.h" -#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFJetClu.h" -#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoGridJet.h" #include "SampleAnalyzer/Interfaces/substructure/ClusterBase.h" #endif // STL headers -#include -#include #include -namespace MA5 -{ +namespace MA5 { - class JetClusterer - { + class ClusterAlgoBase; + + class JetClusterer { //-------------------------------------------------------------------------- // data members //-------------------------------------------------------------------------- @@ -114,45 +105,11 @@ namespace MA5 //-------------------------------------------------------------------------- public : - /// Constructor without argument - JetClusterer (ClusterAlgoBase* algo) { - // Initializing tagger - algo_ = algo; -#ifdef MA5_FASTJET_MODE - cluster_collection_.clear(); - substructure_collection_.clear(); -#endif - mySmearer_ = 0; - myTagger_ = 0; - myTaggerOptions_ = 0; - SFSbanner_ = true; - ExclusiveId_ = false; - JetID_ = "Ma5Jet"; - muon = 0; - electron = 0; - tauH = 0; - tauM = 0; - tauE = 0; - photon = 0; - isocone_track_radius_.clear(); - isocone_electron_radius_.clear(); - isocone_muon_radius_.clear(); - isocone_photon_radius_.clear(); - } + /// Constructor + JetClusterer (ClusterAlgoBase* algo); /// Destructor - ~JetClusterer() { - if (algo_ != 0) delete algo_; - if (mySmearer_ != 0) delete mySmearer_; - if (myTagger_ != 0) delete myTagger_; - if (myTaggerOptions_ != 0) delete myTaggerOptions_; -#ifdef MA5_FASTJET_MODE - for (auto &col: cluster_collection_) - if (col.second != 0) delete col.second; - for (auto &col: substructure_collection_) - if (col.second != 0) delete col.second; -#endif - } + ~JetClusterer(); /// Initialization MAbool Initialize(const std::map& options); @@ -184,23 +141,16 @@ namespace MA5 MAbool LoadJetConfiguration(std::map options); /// Accessor to the jet clusterer name - std::string GetName() - { - if (algo_==0) return "NotDefined"; - else return algo_->GetName(); - } + std::string GetName(); /// Accessor to the tagger parameters - void TaggerParameters() - { myTagger_->PrintParam(); } + void TaggerParameters(); /// Print parameters - void PrintParam() - { algo_->PrintParam(); } + void PrintParam(); /// Accessor to the jet clusterer parameters - std::string GetParameters() - { return algo_->GetParameters(); } + std::string GetParameters(); /// SFS Banner void PrintSFSBanner() From 2c0bd437944a309419b07edf56153efa32bed30c Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 09:30:20 +0100 Subject: [PATCH 53/67] limit the scope of the namespace --- .../Process/JetClustering/JetClusterer.cpp | 1190 ++++++++--------- 1 file changed, 594 insertions(+), 596 deletions(-) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index f7c5230b..c3e4d790 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -32,713 +32,709 @@ #include "SampleAnalyzer/Commons/Service/Physics.h" #ifdef MA5_FASTJET_MODE - #include "SampleAnalyzer/Interfaces/substructure/VariableR.h" - #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoStandard.h" - #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoSISCone.h" - #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFMidpoint.h" - #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFJetClu.h" - #include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoGridJet.h" +#include "SampleAnalyzer/Interfaces/substructure/VariableR.h" +#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoStandard.h" +#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoSISCone.h" +#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFMidpoint.h" +#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoCDFJetClu.h" +#include "SampleAnalyzer/Interfaces/fastjet/ClusterAlgoGridJet.h" #endif -using namespace MA5; +namespace MA5 { -/// Set isolation cones for tracks, e, mu, photon based on tower objects -template -void SetConeRadius( - std::vector cone_radius, std::vector& objects, MCParticleFormat part, MAbool addself=false -) -{ - for (MAuint32 iR=0; iR + void SetConeRadius( + std::vector cone_radius, std::vector& objects, MCParticleFormat part, MAbool addself=false + ) { - for (MAuint32 i=0; iaddsumPT(part.pt()); - current_isocone->addSumET(part.et()); - if (addself) + IsolationConeType* current_isocone = objects[i].GetIsolCone(cone_radius[iR]); + if (objects[i].dr(part.momentum()) < cone_radius[iR]) { - current_isocone->setSelfPT(objects[i].pt()); - current_isocone->setSelfET(objects[i].et()); + current_isocone->addsumPT(part.pt()); + current_isocone->addSumET(part.et()); + if (addself) + { + current_isocone->setSelfPT(objects[i].pt()); + current_isocone->setSelfET(objects[i].et()); + } } } } } -} -/// Constructor -JetClusterer::JetClusterer (ClusterAlgoBase* algo){ - // Initializing tagger - algo_ = algo; + /// Constructor + JetClusterer::JetClusterer (ClusterAlgoBase* algo){ + // Initializing tagger + algo_ = algo; #ifdef MA5_FASTJET_MODE - cluster_collection_.clear(); - substructure_collection_.clear(); + cluster_collection_.clear(); + substructure_collection_.clear(); #endif - mySmearer_ = 0; - myTagger_ = 0; - myTaggerOptions_ = 0; - SFSbanner_ = true; - ExclusiveId_ = false; - JetID_ = "Ma5Jet"; - muon = 0; - electron = 0; - tauH = 0; - tauM = 0; - tauE = 0; - photon = 0; - isocone_track_radius_.clear(); - isocone_electron_radius_.clear(); - isocone_muon_radius_.clear(); - isocone_photon_radius_.clear(); -} - - -///Destructor -JetClusterer::~JetClusterer() { - if (algo_ != 0) delete algo_; - if (mySmearer_ != 0) delete mySmearer_; - if (myTagger_ != 0) delete myTagger_; - if (myTaggerOptions_ != 0) delete myTaggerOptions_; + mySmearer_ = 0; + myTagger_ = 0; + myTaggerOptions_ = 0; + SFSbanner_ = true; + ExclusiveId_ = false; + JetID_ = "Ma5Jet"; + muon = 0; + electron = 0; + tauH = 0; + tauM = 0; + tauE = 0; + photon = 0; + isocone_track_radius_.clear(); + isocone_electron_radius_.clear(); + isocone_muon_radius_.clear(); + isocone_photon_radius_.clear(); + } + + + ///Destructor + JetClusterer::~JetClusterer() { + if (algo_ != 0) delete algo_; + if (mySmearer_ != 0) delete mySmearer_; + if (myTagger_ != 0) delete myTagger_; + if (myTaggerOptions_ != 0) delete myTaggerOptions_; #ifdef MA5_FASTJET_MODE - for (auto &col: cluster_collection_) - if (col.second != 0) delete col.second; - for (auto &col: substructure_collection_) - if (col.second != 0) delete col.second; + for (auto &col: cluster_collection_) + if (col.second != 0) delete col.second; + for (auto &col: substructure_collection_) + if (col.second != 0) delete col.second; #endif -} - -/// Accessor to the jet clusterer name -std::string JetClusterer::GetName() -{ - if (algo_==0) return "NotDefined"; - else return algo_->GetName(); -} - -/// Accessor to the tagger parameters -void JetClusterer::TaggerParameters() -{ myTagger_->PrintParam(); } - -/// Print parameters -void JetClusterer::PrintParam() -{ algo_->PrintParam(); } - -/// Accessor to the jet clusterer parameters -std::string JetClusterer::GetParameters() -{ return algo_->GetParameters(); } - - -// ----------------------------------------------------------------------------- -// Initialize -// ----------------------------------------------------------------------------- -MAbool JetClusterer::Initialize(const std::map& options) -{ - // algo defined ? - if (algo_==0) return false; - - // configure tagger - mySmearer_ = new SmearerBase(); - myTagger_ = new SFSTaggerBase(); - myTaggerOptions_ = new SFSTaggerBaseOptions(); - mySmearer_->Initialize(true); - myTagger_->Initialize(); - - - /// Loop ower options - for (const auto &opt: options) + } + + /// Accessor to the jet clusterer name + std::string JetClusterer::GetName() { - std::string key = ClusterAlgoBase::Lower(opt.first); - MAbool result=false; + if (algo_==0) return "NotDefined"; + else return algo_->GetName(); + } + + /// Accessor to the tagger parameters + void JetClusterer::TaggerParameters() { myTagger_->PrintParam(); } + + /// Print parameters + void JetClusterer::PrintParam() { algo_->PrintParam(); } - /// Initialize exclusive algorithm for jet clustering - if (key == "exclusive_id") + /// Accessor to the jet clusterer parameters + std::string JetClusterer::GetParameters() { return algo_->GetParameters(); } + + + // ----------------------------------------------------------------------------- + // Initialize + // ----------------------------------------------------------------------------- + MAbool JetClusterer::Initialize(const std::map& options) + { + // algo defined ? + if (algo_==0) return false; + + // configure tagger + mySmearer_ = new SmearerBase(); + myTagger_ = new SFSTaggerBase(); + myTaggerOptions_ = new SFSTaggerBaseOptions(); + mySmearer_->Initialize(true); + myTagger_->Initialize(); + + + /// Loop ower options + for (const auto &opt: options) { - MAint32 tmp=0; - std::stringstream str; - str << opt.second; - str >> tmp; - try + std::string key = ClusterAlgoBase::Lower(opt.first); + MAbool result=false; + + /// Initialize exclusive algorithm for jet clustering + if (key == "exclusive_id") { - if (tmp==1) ExclusiveId_=true; - else if (tmp==0) ExclusiveId_=false; - else throw EXCEPTION_WARNING( - "'exclusive_id' must be equal to 0 or 1. Using default value 'exclusive_id' = " \ + MAint32 tmp=0; + std::stringstream str; + str << opt.second; + str >> tmp; + try + { + if (tmp==1) ExclusiveId_=true; + else if (tmp==0) ExclusiveId_=false; + else throw EXCEPTION_WARNING( + "'exclusive_id' must be equal to 0 or 1. Using default value 'exclusive_id' = " \ + CONVERT->ToString(ExclusiveId_), "", 0 - ); - } - catch(const std::exception& e) - { - MANAGE_EXCEPTION(e); - } - result=true; - } - /// B tagging options - else if (key.find("bjet_id.") == 0 || key.find("cjet_id.") == 0 || key.find("tau_id.") == 0) - { - /// Turn the input value to float - MAfloat32 tmp = 0; - std::stringstream str; - str << opt.second; - str >> tmp; - - /// Is bjet run via exclusive algorithm - if (key == "bjet_id.exclusive") { - try { - if (tmp == 1.) myTaggerOptions_->btag_exclusive = true; - else if (tmp == 0.) myTaggerOptions_->btag_exclusive = false; - else - throw EXCEPTION_WARNING( - "'bjet_id.exclusive' must be equal to 0 or 1. Using default value 'bjet_id.exclusive' = " \ - + CONVERT->ToString(myTaggerOptions_->btag_exclusive), "", 0 ); } - catch (const std::exception &e) { + catch(const std::exception& e) + { MANAGE_EXCEPTION(e); } + result=true; } - /// What is the bjet matching DR - else if (key == "bjet_id.matching_dr") myTaggerOptions_->btag_matching_deltaR = tmp; - /// Is cjet run via exclusive algorithm - else if (key == "cjet_id.exclusive") + /// B tagging options + else if (key.find("bjet_id.") == 0 || key.find("cjet_id.") == 0 || key.find("tau_id.") == 0) { - try { - if (tmp == 1.) myTaggerOptions_->ctag_exclusive = true; - else if (tmp == 0.) myTaggerOptions_->ctag_exclusive = false; - else - throw EXCEPTION_WARNING( - "'cjet_id.exclusive' must be equal to 0 or 1. Using default value 'cjet_id.exclusive' = " \ - + CONVERT->ToString(myTaggerOptions_->ctag_exclusive), "", 0 - ); + /// Turn the input value to float + MAfloat32 tmp = 0; + std::stringstream str; + str << opt.second; + str >> tmp; + + /// Is bjet run via exclusive algorithm + if (key == "bjet_id.exclusive") { + try { + if (tmp == 1.) myTaggerOptions_->btag_exclusive = true; + else if (tmp == 0.) myTaggerOptions_->btag_exclusive = false; + else + throw EXCEPTION_WARNING( + "'bjet_id.exclusive' must be equal to 0 or 1. Using default value 'bjet_id.exclusive' = " \ + + CONVERT->ToString(myTaggerOptions_->btag_exclusive), "", 0 + ); + } + catch (const std::exception &e) { + MANAGE_EXCEPTION(e); + } } - catch (const std::exception &e) { - MANAGE_EXCEPTION(e); + /// What is the bjet matching DR + else if (key == "bjet_id.matching_dr") myTaggerOptions_->btag_matching_deltaR = tmp; + /// Is cjet run via exclusive algorithm + else if (key == "cjet_id.exclusive") + { + try { + if (tmp == 1.) myTaggerOptions_->ctag_exclusive = true; + else if (tmp == 0.) myTaggerOptions_->ctag_exclusive = false; + else + throw EXCEPTION_WARNING( + "'cjet_id.exclusive' must be equal to 0 or 1. Using default value 'cjet_id.exclusive' = " \ + + CONVERT->ToString(myTaggerOptions_->ctag_exclusive), "", 0 + ); + } + catch (const std::exception &e) { + MANAGE_EXCEPTION(e); + } } - } - /// What is the cjet matching DR - else if (key == "cjet_id.matching_dr") myTaggerOptions_->ctag_matching_deltaR = tmp; + /// What is the cjet matching DR + else if (key == "cjet_id.matching_dr") myTaggerOptions_->ctag_matching_deltaR = tmp; - /// Is CJet tagging enabled - else if (key == "cjet_id.enable_ctagging") - { - try { - if (tmp == 1.) myTaggerOptions_->enable_ctagging = true; - else if (tmp == 0.) myTaggerOptions_->enable_ctagging = false; - else - throw EXCEPTION_WARNING( - "'cjet_id.enable_ctagging' must be equal to 0 or 1. Using default " - "value 'cjet_id.enable_ctagging' = " \ + /// Is CJet tagging enabled + else if (key == "cjet_id.enable_ctagging") + { + try { + if (tmp == 1.) myTaggerOptions_->enable_ctagging = true; + else if (tmp == 0.) myTaggerOptions_->enable_ctagging = false; + else + throw EXCEPTION_WARNING( + "'cjet_id.enable_ctagging' must be equal to 0 or 1. Using default " + "value 'cjet_id.enable_ctagging' = " \ + CONVERT->ToString(myTaggerOptions_->enable_ctagging), "", 0 - ); - } - catch (const std::exception &e) { - MANAGE_EXCEPTION(e); + ); + } + catch (const std::exception &e) { + MANAGE_EXCEPTION(e); + } } - } - /// Is taujet run via exclusive algorithm - else if (key == "tau_id.exclusive") - { - try { - if (tmp == 1.) myTaggerOptions_->tautag_exclusive = true; - else if (tmp == 0.) myTaggerOptions_->tautag_exclusive = false; - else - throw EXCEPTION_WARNING( - "'cjet_id.exclusive' must be equal to 0 or 1. Using default value 'cjet_id.exclusive' = " \ + /// Is taujet run via exclusive algorithm + else if (key == "tau_id.exclusive") + { + try { + if (tmp == 1.) myTaggerOptions_->tautag_exclusive = true; + else if (tmp == 0.) myTaggerOptions_->tautag_exclusive = false; + else + throw EXCEPTION_WARNING( + "'cjet_id.exclusive' must be equal to 0 or 1. Using default value 'cjet_id.exclusive' = " \ + CONVERT->ToString(myTaggerOptions_->ctag_exclusive), "", 0 - ); - } - catch (const std::exception &e) { - MANAGE_EXCEPTION(e); + ); + } + catch (const std::exception &e) { + MANAGE_EXCEPTION(e); + } } - } - else if (key == "tau_id.matching_dr") myTaggerOptions_->tautag_matching_deltaR = tmp; - else if (key == "tau_id.reconstruction_method") - { - try { - if (tmp == 1.) myTaggerOptions_->tautag_jetbased = true; - else if (tmp == 0.) myTaggerOptions_->tautag_jetbased = false; - else - throw EXCEPTION_WARNING( - "Hadronic tau tagging has only two options 0 corresponds to hadron-based tagging algorithm " - "and 1 corresponds to jet-based tagging algorithm. Default, hadron-based, " - "algorithm will be used", "", 0 - ); + else if (key == "tau_id.matching_dr") myTaggerOptions_->tautag_matching_deltaR = tmp; + else if (key == "tau_id.reconstruction_method") + { + try { + if (tmp == 1.) myTaggerOptions_->tautag_jetbased = true; + else if (tmp == 0.) myTaggerOptions_->tautag_jetbased = false; + else + throw EXCEPTION_WARNING( + "Hadronic tau tagging has only two options 0 corresponds to hadron-based tagging algorithm " + "and 1 corresponds to jet-based tagging algorithm. Default, hadron-based, " + "algorithm will be used", "", 0 + ); + } + catch (const std::exception &e) { + MANAGE_EXCEPTION(e); + myTaggerOptions_->tautag_jetbased = false; + } } - catch (const std::exception &e) { - MANAGE_EXCEPTION(e); - myTaggerOptions_->tautag_jetbased = false; + else + { + try { throw EXCEPTION_WARNING("Parameter = "+key+" unknown. It will be skipped.","",0); } + catch(const std::exception& e) { MANAGE_EXCEPTION(e); } } + result=true; } - else + /// clustering algo + else if (key.find("cluster.")==0) result = algo_->SetParameter(key.substr(8),opt.second); + /// Primary Jet ID + else if (key == "jetid") { - try { throw EXCEPTION_WARNING("Parameter = "+key+" unknown. It will be skipped.","",0); } - catch(const std::exception& e) { MANAGE_EXCEPTION(e); } + JetID_ = opt.second; + result = true; } - result=true; - } - /// clustering algo - else if (key.find("cluster.")==0) result = algo_->SetParameter(key.substr(8),opt.second); - /// Primary Jet ID - else if (key == "jetid") - { - JetID_ = opt.second; - result = true; - } - /// Isolation cone radius for tracker - else if (key.find("isolation")==0) - { - std::stringstream str(opt.second); - for (MAfloat64 tmp; str >> tmp;) + /// Isolation cone radius for tracker + else if (key.find("isolation")==0) { - if (tmp>0. && key.substr(10) == "track.radius") isocone_track_radius_.push_back(tmp); - if (tmp>0. && key.substr(10) == "electron.radius") isocone_electron_radius_.push_back(tmp); - if (tmp>0. && key.substr(10) == "muon.radius") isocone_muon_radius_.push_back(tmp); - if (tmp>0. && key.substr(10) == "photon.radius") isocone_photon_radius_.push_back(tmp); - if (str.peek() == ',' || str.peek() == ' ') str.ignore(); + std::stringstream str(opt.second); + for (MAfloat64 tmp; str >> tmp;) + { + if (tmp>0. && key.substr(10) == "track.radius") isocone_track_radius_.push_back(tmp); + if (tmp>0. && key.substr(10) == "electron.radius") isocone_electron_radius_.push_back(tmp); + if (tmp>0. && key.substr(10) == "muon.radius") isocone_muon_radius_.push_back(tmp); + if (tmp>0. && key.substr(10) == "photon.radius") isocone_photon_radius_.push_back(tmp); + if (str.peek() == ',' || str.peek() == ' ') str.ignore(); + } + result = true; } - result = true; + + /// Other + try { if (!result) throw EXCEPTION_WARNING("Parameter = "+key+" unknown. It will be skipped.","",0); } + catch(const std::exception& e) { MANAGE_EXCEPTION(e); } } + /// configure algo + algo_->Initialize(); + /// Configure Tagger + myTagger_->SetOptions(*myTaggerOptions_); - /// Other - try { if (!result) throw EXCEPTION_WARNING("Parameter = "+key+" unknown. It will be skipped.","",0); } - catch(const std::exception& e) { MANAGE_EXCEPTION(e); } + return true; } - /// configure algo - algo_->Initialize(); - /// Configure Tagger - myTagger_->SetOptions(*myTaggerOptions_); - return true; -} - - -// ----------------------------------------------------------------------------- -// Finalize -// ----------------------------------------------------------------------------- -void JetClusterer::Finalize() -{ - if (algo_!=0) delete algo_; - if (mySmearer_!=0) delete mySmearer_; - if (myTaggerOptions_!=0) delete myTaggerOptions_; - if (myTagger_!=0) delete myTagger_; -} - - -// ----------------------------------------------------------------------------- -// GetFinalState -// ----------------------------------------------------------------------------- -void JetClusterer::GetFinalState(const MCParticleFormat* part, std::set& finalstates) -{ - for (MAuint32 i=0; idaughters().size(); i++) + + // ----------------------------------------------------------------------------- + // Finalize + // ----------------------------------------------------------------------------- + void JetClusterer::Finalize() { - if (PHYSICS->Id->IsFinalState(part->daughters()[i])) finalstates.insert(part->daughters()[i]); - else return GetFinalState(part->daughters()[i],finalstates); + if (algo_!=0) delete algo_; + if (mySmearer_!=0) delete mySmearer_; + if (myTaggerOptions_!=0) delete myTaggerOptions_; + if (myTagger_!=0) delete myTagger_; } -} -// ----------------------------------------------------------------------------- -// IsLast -// ----------------------------------------------------------------------------- -MAbool JetClusterer::IsLast(const MCParticleFormat* part, EventFormat& myEvent) -{ - for (MAuint32 i=0; idaughters().size(); i++) + // ----------------------------------------------------------------------------- + // GetFinalState + // ----------------------------------------------------------------------------- + void JetClusterer::GetFinalState(const MCParticleFormat* part, std::set& finalstates) { - if (part->daughters()[i]->pdgid()==part->pdgid()) return false; + for (MAuint32 i=0; idaughters().size(); i++) + { + if (PHYSICS->Id->IsFinalState(part->daughters()[i])) finalstates.insert(part->daughters()[i]); + else return GetFinalState(part->daughters()[i],finalstates); + } } - return true; -} - -// ----------------------------------------------------------------------------- -// Execute -// ----------------------------------------------------------------------------- -MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) -{ - // Safety - if (mySample.mc() == 0 || myEvent.mc() == 0) return false; - if (mySample.rec() == 0) mySample.InitializeRec(); - if (myEvent.rec() == 0) myEvent.InitializeRec(); - - // Reseting the reconstructed event - myEvent.rec()->Reset(); - - // Veto - std::vector vetos(myEvent.mc()->particles().size(), false); - std::set vetos2; - - // shortcut for TET & THT - MAfloat64 &TET = myEvent.rec()->TET(); - // MAfloat64 & THT = myEvent.rec()->THT(); - RecParticleFormat *MET = &(myEvent.rec()->MET()); - RecParticleFormat *MHT = &(myEvent.rec()->MHT()); - - // Filling the dataformat with electron/muon - for (MAuint32 i = 0; i < myEvent.mc()->particles().size(); i++) - { - const MCParticleFormat& part = myEvent.mc()->particles()[i]; - MAuint32 absid = std::abs(part.pdgid()); - // Rejecting particle with a null pt (initial state ?) - if (part.pt()<1e-10) continue; - // Run particle propagator - if (mySmearer_->isPropagatorOn() && part.mothers().size()>0) - mySmearer_->ParticlePropagator(const_cast(&part)); - - /// @attention delphes based analyses already has tracks - /// Set up tracks as charged FS particles OR charged interstate particles with nonzero ctau - if (PDG->IsCharged(part.pdgid()) && part.mothers().size()>0 && algo_!=0) + // ----------------------------------------------------------------------------- + // IsLast + // ----------------------------------------------------------------------------- + MAbool JetClusterer::IsLast(const MCParticleFormat* part, EventFormat& myEvent) + { + for (MAuint32 i=0; idaughters().size(); i++) { - // Minimum tracking requirement is around 0.5 mm see ref. 1007.1988 - if (part.ctau() > 0. || PHYSICS->Id->IsFinalState(part)) - { - // Reminder: -1 is reserved for the tracks - MCParticleFormat smeared_track = mySmearer_->Execute(&part, -1); - if (smeared_track.pt() > 1e-5) - { - RecTrackFormat * track = myEvent.rec()->GetNewTrack(); - MALorentzVector trk_mom; - trk_mom.SetPtEtaPhiM(smeared_track.pt(), - smeared_track.eta(), - smeared_track.phi(),0.0); - track->setMomentum(trk_mom); - track->setD0(smeared_track.d0()); - track->setDZ(smeared_track.dz()); - track->setD0Approx(smeared_track.d0_approx()); - track->setDZApprox(smeared_track.dz_approx()); - MAdouble64 ctau = PHYSICS->Id->IsFinalState(part) ? 0.0 : part.mothers()[0]->ctau(); - MALorentzVector new_vertex(part.mothers()[0]->decay_vertex().X(), - part.mothers()[0]->decay_vertex().Y(), - part.mothers()[0]->decay_vertex().Z(), ctau); - track->setProductionVertex(new_vertex); - track->setClosestApproach(smeared_track.closest_approach()); - track->setMc(&(part)); - track->SetCharge(PDG->GetCharge(part.pdgid(), false) / 3.); - } - } + if (part->daughters()[i]->pdgid()==part->pdgid()) return false; } + return true; + } - // Treating intermediate particles - if (PHYSICS->Id->IsInterState(part)) + // ----------------------------------------------------------------------------- + // Execute + // ----------------------------------------------------------------------------- + MAbool JetClusterer::Execute(SampleFormat& mySample, EventFormat& myEvent) + { + // Safety + if (mySample.mc() == 0 || myEvent.mc() == 0) return false; + if (mySample.rec() == 0) mySample.InitializeRec(); + if (myEvent.rec() == 0) myEvent.InitializeRec(); + + // Reseting the reconstructed event + myEvent.rec()->Reset(); + + // Veto + std::vector vetos(myEvent.mc()->particles().size(), false); + std::set vetos2; + + // shortcut for TET & THT + MAfloat64 &TET = myEvent.rec()->TET(); + // MAfloat64 & THT = myEvent.rec()->THT(); + RecParticleFormat *MET = &(myEvent.rec()->MET()); + RecParticleFormat *MHT = &(myEvent.rec()->MHT()); + + // Filling the dataformat with electron/muon + for (MAuint32 i = 0; i < myEvent.mc()->particles().size(); i++) { - // rejecting not interesting particles - if (absid!=5 && absid!=4 && absid!=15) continue; + const MCParticleFormat& part = myEvent.mc()->particles()[i]; + MAuint32 absid = std::abs(part.pdgid()); - // keeping the last particle with the same id in the decay chain - if (!IsLast(&part, myEvent)) continue; + // Rejecting particle with a null pt (initial state ?) + if (part.pt()<1e-10) continue; - // looking for b quarks - if (absid==5) - { - MAbool found=false; - for (MAuint32 j=0;jMCBquarks_.size();j++) - { - if (myEvent.rec()->MCBquarks_[j]==&(part)) - {found=true; break;} - } - if (!found) myEvent.rec()->MCBquarks_.push_back(&(part)); - } + // Run particle propagator + if (mySmearer_->isPropagatorOn() && part.mothers().size()>0) + mySmearer_->ParticlePropagator(const_cast(&part)); - /// looking for c quarks - else if (absid==4) + /// @attention delphes based analyses already has tracks + /// Set up tracks as charged FS particles OR charged interstate particles with nonzero ctau + if (PDG->IsCharged(part.pdgid()) && part.mothers().size()>0 && algo_!=0) { - MAbool found=false; - for (MAuint32 j=0;jMCCquarks_.size();j++) + // Minimum tracking requirement is around 0.5 mm see ref. 1007.1988 + if (part.ctau() > 0. || PHYSICS->Id->IsFinalState(part)) { - if (myEvent.rec()->MCCquarks_[j]==&(part)) - {found=true; break;} + // Reminder: -1 is reserved for the tracks + MCParticleFormat smeared_track = mySmearer_->Execute(&part, -1); + if (smeared_track.pt() > 1e-5) + { + RecTrackFormat * track = myEvent.rec()->GetNewTrack(); + MALorentzVector trk_mom; + trk_mom.SetPtEtaPhiM(smeared_track.pt(), + smeared_track.eta(), + smeared_track.phi(),0.0); + track->setMomentum(trk_mom); + track->setD0(smeared_track.d0()); + track->setDZ(smeared_track.dz()); + track->setD0Approx(smeared_track.d0_approx()); + track->setDZApprox(smeared_track.dz_approx()); + MAdouble64 ctau = PHYSICS->Id->IsFinalState(part) ? 0.0 : part.mothers()[0]->ctau(); + MALorentzVector new_vertex(part.mothers()[0]->decay_vertex().X(), + part.mothers()[0]->decay_vertex().Y(), + part.mothers()[0]->decay_vertex().Z(), ctau); + track->setProductionVertex(new_vertex); + track->setClosestApproach(smeared_track.closest_approach()); + track->setMc(&(part)); + track->SetCharge(PDG->GetCharge(part.pdgid(), false) / 3.); + } } - if (!found) myEvent.rec()->MCCquarks_.push_back(&(part)); } - /// looking for taus - else if (absid==15) + // Treating intermediate particles + if (PHYSICS->Id->IsInterState(part)) { - // rejecting particle if coming from hadronization - if (LOOP->ComingFromHadronDecay(&part,mySample,myEvent.mc()->particles().size())) continue; + // rejecting not interesting particles + if (absid!=5 && absid!=4 && absid!=15) continue; - // Looking taus daughters id - MAbool leptonic = true; - MAbool muonic = false; - MAbool electronic = false; - for (MAuint32 j=0;jpdgid()); - if (pdgid==13) muonic=true; - else if (pdgid==11) electronic=true; - else if (pdgid!=22 /*photons*/ && - !(pdgid>=11 && pdgid<=16) /*neutrinos*/) - leptonic=false; - } - if (!leptonic) {muonic=false; electronic=false;} + // keeping the last particle with the same id in the decay chain + if (!IsLast(&part, myEvent)) continue; - // Saving taus decaying into muons (only one copy) - if (muonic) + // looking for b quarks + if (absid==5) { MAbool found=false; - for (MAuint32 j=0;jMCMuonicTaus_.size();j++) + for (MAuint32 j=0;jMCBquarks_.size();j++) { - if (myEvent.rec()->MCMuonicTaus_[j]==&(part)) + if (myEvent.rec()->MCBquarks_[j]==&(part)) {found=true; break;} } - if (!found) myEvent.rec()->MCMuonicTaus_.push_back(&(part)); + if (!found) myEvent.rec()->MCBquarks_.push_back(&(part)); } - else if (electronic) // Saving taus decaying into electrons (only one copy) + + /// looking for c quarks + else if (absid==4) { MAbool found=false; - for (MAuint32 j=0;jMCElectronicTaus_.size();j++) + for (MAuint32 j=0;jMCCquarks_.size();j++) { - if (myEvent.rec()->MCElectronicTaus_[j]==&(part)) + if (myEvent.rec()->MCCquarks_[j]==&(part)) {found=true; break;} } - if (!found) myEvent.rec()->MCElectronicTaus_.push_back(&(part)); + if (!found) myEvent.rec()->MCCquarks_.push_back(&(part)); } - else // Saving taus decaying into hadrons (only copy) + + /// looking for taus + else if (absid==15) { - MAbool found=false; - for (MAuint32 j=0;jMCHadronicTaus_.size();j++) + // rejecting particle if coming from hadronization + if (LOOP->ComingFromHadronDecay(&part,mySample,myEvent.mc()->particles().size())) continue; + + // Looking taus daughters id + MAbool leptonic = true; + MAbool muonic = false; + MAbool electronic = false; + for (MAuint32 j=0;jMCHadronicTaus_[j]==&(part)) - {found=true; break;} + MAuint32 pdgid = std::abs(part.daughters()[j]->pdgid()); + if (pdgid==13) muonic=true; + else if (pdgid==11) electronic=true; + else if (pdgid!=22 /*photons*/ && + !(pdgid>=11 && pdgid<=16) /*neutrinos*/) + leptonic=false; } - if (!found) - { - // Saving the hadrons in MC container - myEvent.rec()->MCHadronicTaus_.push_back(&(part)); + if (!leptonic) {muonic=false; electronic=false;} - /// If tau tagging is jet based do not proceed - if (myTaggerOptions_->tautag_jetbased) continue; - - // Smearing the hadronic taus - MCParticleFormat smeared = mySmearer_->Execute( - &part, static_cast(absid) - ); - // If smeared pt is zero, no need to count the particle but it still needs - // to be vetoed for jet clustering. - if (smeared.pt() > 1e-10) { - // Creating reco hadronic taus - RecTauFormat* myTau = myEvent.rec()->GetNewTau(); - if (part.pdgid()>0) myTau->setCharge(-1); - else myTau->setCharge(+1); - myTau->setMomentum(smeared.momentum()); - myTau->setD0(smeared.d0()); - myTau->setDZ(smeared.dz()); - myTau->setD0Approx(smeared.d0_approx()); - myTau->setDZApprox(smeared.dz_approx()); - myTau->setProductionVertex( - MALorentzVector(part.mothers()[0]->decay_vertex().X(), - part.mothers()[0]->decay_vertex().Y(), - part.mothers()[0]->decay_vertex().Z(), - 0.0) + // Saving taus decaying into muons (only one copy) + if (muonic) + { + MAbool found=false; + for (MAuint32 j=0;jMCMuonicTaus_.size();j++) + { + if (myEvent.rec()->MCMuonicTaus_[j]==&(part)) + {found=true; break;} + } + if (!found) myEvent.rec()->MCMuonicTaus_.push_back(&(part)); + } + else if (electronic) // Saving taus decaying into electrons (only one copy) + { + MAbool found=false; + for (MAuint32 j=0;jMCElectronicTaus_.size();j++) + { + if (myEvent.rec()->MCElectronicTaus_[j]==&(part)) + {found=true; break;} + } + if (!found) myEvent.rec()->MCElectronicTaus_.push_back(&(part)); + } + else // Saving taus decaying into hadrons (only copy) + { + MAbool found=false; + for (MAuint32 j=0;jMCHadronicTaus_.size();j++) + { + if (myEvent.rec()->MCHadronicTaus_[j]==&(part)) + {found=true; break;} + } + if (!found) + { + // Saving the hadrons in MC container + myEvent.rec()->MCHadronicTaus_.push_back(&(part)); + + /// If tau tagging is jet based do not proceed + if (myTaggerOptions_->tautag_jetbased) continue; + + // Smearing the hadronic taus + MCParticleFormat smeared = mySmearer_->Execute( + &part, static_cast(absid) ); - myTau->setClosestApproach(smeared.closest_approach()); - myTau->setMc(&part); - myTau->setDecayMode(PHYSICS->GetTauDecayMode(myTau->mc())); - if (myTau->DecayMode() <= 0) myTau->setNtracks(0); // ERROR case - else if (myTau->DecayMode() == 7 || - myTau->DecayMode() == 9) - myTau->setNtracks(3); // 3-Prong - else myTau->setNtracks(1); // 1-Prong - - /// Set MET and TET - if (ExclusiveId_) { (*MET) -= myTau->momentum(); TET += myTau->pt(); } - - } // (smeared.pt() < 1e-10) - - // Searching final state - GetFinalState(&part,vetos2); + // If smeared pt is zero, no need to count the particle but it still needs + // to be vetoed for jet clustering. + if (smeared.pt() > 1e-10) { + // Creating reco hadronic taus + RecTauFormat* myTau = myEvent.rec()->GetNewTau(); + if (part.pdgid()>0) myTau->setCharge(-1); + else myTau->setCharge(+1); + myTau->setMomentum(smeared.momentum()); + myTau->setD0(smeared.d0()); + myTau->setDZ(smeared.dz()); + myTau->setD0Approx(smeared.d0_approx()); + myTau->setDZApprox(smeared.dz_approx()); + myTau->setProductionVertex( + MALorentzVector(part.mothers()[0]->decay_vertex().X(), + part.mothers()[0]->decay_vertex().Y(), + part.mothers()[0]->decay_vertex().Z(), + 0.0) + ); + myTau->setClosestApproach(smeared.closest_approach()); + myTau->setMc(&part); + myTau->setDecayMode(PHYSICS->GetTauDecayMode(myTau->mc())); + if (myTau->DecayMode() <= 0) myTau->setNtracks(0); // ERROR case + else if (myTau->DecayMode() == 7 || + myTau->DecayMode() == 9) + myTau->setNtracks(3); // 3-Prong + else myTau->setNtracks(1); // 1-Prong + + /// Set MET and TET + if (ExclusiveId_) { (*MET) -= myTau->momentum(); TET += myTau->pt(); } + + } // (smeared.pt() < 1e-10) + + // Searching final state + GetFinalState(&part,vetos2); + } } - } - } // if (absid==15) - } // if (PHYSICS->Id->IsInterState(part)) + } // if (absid==15) + } // if (PHYSICS->Id->IsInterState(part)) - // Keeping only final states - else if (PHYSICS->Id->IsFinalState(part)) - { - // rejecting particle if coming from hadronization - if (!(ExclusiveId_ && LOOP->ComingFromHadronDecay(&part, mySample))) + // Keeping only final states + else if (PHYSICS->Id->IsFinalState(part)) { - // Muons - if (absid == 13) - { - vetos[i]=true; - - // Smearing its momentum - MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); - if (smeared.pt() > 1e-10) { - RecLeptonFormat *current_muon = myEvent.rec()->GetNewMuon(); - current_muon->setMomentum(smeared.momentum()); - current_muon->setD0(smeared.d0()); - current_muon->setDZ(smeared.dz()); - current_muon->setD0Approx(smeared.d0_approx()); - current_muon->setDZApprox(smeared.dz_approx()); - current_muon->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), - part.mothers()[0]->decay_vertex().Y(), - part.mothers()[0]->decay_vertex().Z(), 0.0)); - current_muon->setClosestApproach(smeared.closest_approach()); - current_muon->setMc(&(part)); - if (part.pdgid() == 13) current_muon->SetCharge(-1); - else current_muon->SetCharge(+1); - - /// Set MET and TET - (*MET) -= current_muon->momentum(); - TET += current_muon->pt(); - } - } // (absid == 13) - // Electrons - else if (absid==11) - { - vetos[i]=true; - - // Smearing the electron momentum - MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); - if (smeared.pt() > 1e-10) { - RecLeptonFormat * elec = myEvent.rec()->GetNewElectron(); - elec->setMomentum(smeared.momentum()); - elec->setD0(smeared.d0()); - elec->setDZ(smeared.dz()); - elec->setD0Approx(smeared.d0_approx()); - elec->setDZApprox(smeared.dz_approx()); - elec->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), - part.mothers()[0]->decay_vertex().Y(), - part.mothers()[0]->decay_vertex().Z(),0.0)); - elec->setClosestApproach(smeared.closest_approach()); - elec->setMc(&(part)); - if (part.pdgid()==11) elec->SetCharge(-1); - else elec->SetCharge(+1); - - /// Set MET and TET - if (ExclusiveId_) { (*MET) -= elec->momentum(); TET += elec->pt(); } - } - } // if (absid==11) - // Photons - else if (absid==22 ) + // rejecting particle if coming from hadronization + if (!(ExclusiveId_ && LOOP->ComingFromHadronDecay(&part, mySample))) { - if (!LOOP->IrrelevantPhoton(&part,mySample)) + // Muons + if (absid == 13) { vetos[i]=true; - // Smearing the photon momentum + // Smearing its momentum MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); if (smeared.pt() > 1e-10) { - RecPhotonFormat * current_photon = myEvent.rec()->GetNewPhoton(); - current_photon->setMomentum(smeared.momentum()); - current_photon->setD0(smeared.d0()); - current_photon->setDZ(smeared.dz()); - current_photon->setD0Approx(smeared.d0_approx()); - current_photon->setDZApprox(smeared.dz_approx()); - current_photon->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), - part.mothers()[0]->decay_vertex().Y(), - part.mothers()[0]->decay_vertex().Z(), - 0.0)); - current_photon->setClosestApproach(smeared.closest_approach()); - current_photon->setMc(&(part)); + RecLeptonFormat *current_muon = myEvent.rec()->GetNewMuon(); + current_muon->setMomentum(smeared.momentum()); + current_muon->setD0(smeared.d0()); + current_muon->setDZ(smeared.dz()); + current_muon->setD0Approx(smeared.d0_approx()); + current_muon->setDZApprox(smeared.dz_approx()); + current_muon->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), + part.mothers()[0]->decay_vertex().Y(), + part.mothers()[0]->decay_vertex().Z(), 0.0)); + current_muon->setClosestApproach(smeared.closest_approach()); + current_muon->setMc(&(part)); + if (part.pdgid() == 13) current_muon->SetCharge(-1); + else current_muon->SetCharge(+1); /// Set MET and TET - if (ExclusiveId_) { (*MET) -= current_photon->momentum(); TET += current_photon->pt(); } - } // (smeared.pt() <= 1e-10) - } // (!LOOP->IrrelevantPhoton(&part,mySample)) - } // (absid==22 && !reject_hadronic) - } + (*MET) -= current_muon->momentum(); + TET += current_muon->pt(); + } + } // (absid == 13) + // Electrons + else if (absid==11) + { + vetos[i]=true; - // Collect Hadrons for jet clustering... + // Smearing the electron momentum + MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); + if (smeared.pt() > 1e-10) { + RecLeptonFormat * elec = myEvent.rec()->GetNewElectron(); + elec->setMomentum(smeared.momentum()); + elec->setD0(smeared.d0()); + elec->setDZ(smeared.dz()); + elec->setD0Approx(smeared.d0_approx()); + elec->setDZApprox(smeared.dz_approx()); + elec->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), + part.mothers()[0]->decay_vertex().Y(), + part.mothers()[0]->decay_vertex().Z(),0.0)); + elec->setClosestApproach(smeared.closest_approach()); + elec->setMc(&(part)); + if (part.pdgid()==11) elec->SetCharge(-1); + else elec->SetCharge(+1); - // Putting the good inputs into the containter - // Good inputs = - final state - // - visible - // - if exclusiveID=1: particles not vetoed - // - if exclusiveID=0: all particles except muons - if (PHYSICS->Id->IsInvisible(part) || algo_==0) continue; + /// Set MET and TET + if (ExclusiveId_) { (*MET) -= elec->momentum(); TET += elec->pt(); } + } + } // if (absid==11) + // Photons + else if (absid==22 ) + { + if (!LOOP->IrrelevantPhoton(&part,mySample)) + { + vetos[i]=true; + + // Smearing the photon momentum + MCParticleFormat smeared = mySmearer_->Execute(&part, static_cast(absid)); + if (smeared.pt() > 1e-10) { + RecPhotonFormat * current_photon = myEvent.rec()->GetNewPhoton(); + current_photon->setMomentum(smeared.momentum()); + current_photon->setD0(smeared.d0()); + current_photon->setDZ(smeared.dz()); + current_photon->setD0Approx(smeared.d0_approx()); + current_photon->setDZApprox(smeared.dz_approx()); + current_photon->setProductionVertex(MALorentzVector(part.mothers()[0]->decay_vertex().X(), + part.mothers()[0]->decay_vertex().Y(), + part.mothers()[0]->decay_vertex().Z(), + 0.0)); + current_photon->setClosestApproach(smeared.closest_approach()); + current_photon->setMc(&(part)); + + /// Set MET and TET + if (ExclusiveId_) { (*MET) -= current_photon->momentum(); TET += current_photon->pt(); } + } // (smeared.pt() <= 1e-10) + } // (!LOOP->IrrelevantPhoton(&part,mySample)) + } // (absid==22 && !reject_hadronic) + } - // ExclusiveId mode - if (ExclusiveId_) - { - if (vetos[i]) continue; - if (vetos2.find(&part)!=vetos2.end()) continue; - } - // NonExclusive Id mode - else if (std::abs(part.pdgid())==13) continue; + // Collect Hadrons for jet clustering... + + // Putting the good inputs into the containter + // Good inputs = - final state + // - visible + // - if exclusiveID=1: particles not vetoed + // - if exclusiveID=0: all particles except muons + if (PHYSICS->Id->IsInvisible(part) || algo_==0) continue; - // Smearer module returns a smeared MCParticleFormat object - // Default: NullSmearer, that does nothing - // Reminder: 0 is reserved for the jet constituents - MCParticleFormat smeared = mySmearer_->Execute(&part, 0); - if (smeared.pt() <= 1e-10) continue; + // ExclusiveId mode + if (ExclusiveId_) + { + if (vetos[i]) continue; + if (vetos2.find(&part)!=vetos2.end()) continue; + } + // NonExclusive Id mode + else if (std::abs(part.pdgid())==13) continue; - // Filling good particle for clustering - myEvent.rec()->AddHadron(smeared, i); + // Smearer module returns a smeared MCParticleFormat object + // Default: NullSmearer, that does nothing + // Reminder: 0 is reserved for the jet constituents + MCParticleFormat smeared = mySmearer_->Execute(&part, 0); + if (smeared.pt() <= 1e-10) continue; - } // if (PHYSICS->Id->IsFinalState(part)) - } // for (MAuint32 i=0;iparticles().size();i++) + // Filling good particle for clustering + myEvent.rec()->AddHadron(smeared, i); - // Set Primary Jet ID - myEvent.rec()->SetPrimaryJetID(JetID_); - // Launching the clustering - // -> Filling the collection: myEvent->rec()->jets() - algo_->Execute(mySample, myEvent, mySmearer_); + } // if (PHYSICS->Id->IsFinalState(part)) + } // for (MAuint32 i=0;iparticles().size();i++) + + // Set Primary Jet ID + myEvent.rec()->SetPrimaryJetID(JetID_); + // Launching the clustering + // -> Filling the collection: myEvent->rec()->jets() + algo_->Execute(mySample, myEvent, mySmearer_); #ifdef MA5_FASTJET_MODE - // Cluster additional jets separately. In order to save time Execute function - // saves hadron inputs into memory and that configuration is used for the rest - // of the jets. - for (auto &collection_item: cluster_collection_) - collection_item.second->Cluster(myEvent, collection_item.first); - for (auto &substructure: substructure_collection_) - substructure.second->Execute(myEvent, substructure.first); + // Cluster additional jets separately. In order to save time Execute function + // saves hadron inputs into memory and that configuration is used for the rest + // of the jets. + for (auto &collection_item: cluster_collection_) + collection_item.second->Cluster(myEvent, collection_item.first); + for (auto &substructure: substructure_collection_) + substructure.second->Execute(myEvent, substructure.first); #endif - MET->momentum().SetPz(0.); - MET->momentum().SetE(MET->momentum().Pt()); - MHT->momentum().SetPz(0.); - MHT->momentum().SetE(MHT->momentum().Pt()); + MET->momentum().SetPz(0.); + MET->momentum().SetE(MET->momentum().Pt()); + MHT->momentum().SetPz(0.); + MHT->momentum().SetE(MHT->momentum().Pt()); - /// Execute tagger - myTagger_->Execute(myEvent); + /// Execute tagger + myTagger_->Execute(myEvent); - // Sorting the objects - std::sort(myEvent.rec()->electrons_.begin(), myEvent.rec()->electrons_.end(), - [](RecLeptonFormat const & lep1, RecLeptonFormat const & lep2){ return lep1.pt() > lep2.pt(); }); - std::sort(myEvent.rec()->muons_.begin(), myEvent.rec()->muons_.end(), - [](RecLeptonFormat const & lep1, RecLeptonFormat const & lep2){ return lep1.pt() > lep2.pt(); }); - std::sort(myEvent.rec()->taus_.begin(), myEvent.rec()->taus_.end(), - [](RecTauFormat const & ta1, RecTauFormat const & ta2){ return ta1.pt() > ta2.pt(); }); - std::sort(myEvent.rec()->photons_.begin(), myEvent.rec()->photons_.end(), - [](RecPhotonFormat const & ph1, RecPhotonFormat const & ph2){ return ph1.pt() > ph2.pt(); }); - std::sort(myEvent.rec()->jets().begin(), myEvent.rec()->jets().end(), - [](RecJetFormat &j1, RecJetFormat &j2) { return j1.pt() > j2.pt();}); + // Sorting the objects + std::sort(myEvent.rec()->electrons_.begin(), myEvent.rec()->electrons_.end(), + [](RecLeptonFormat const & lep1, RecLeptonFormat const & lep2){ return lep1.pt() > lep2.pt(); }); + std::sort(myEvent.rec()->muons_.begin(), myEvent.rec()->muons_.end(), + [](RecLeptonFormat const & lep1, RecLeptonFormat const & lep2){ return lep1.pt() > lep2.pt(); }); + std::sort(myEvent.rec()->taus_.begin(), myEvent.rec()->taus_.end(), + [](RecTauFormat const & ta1, RecTauFormat const & ta2){ return ta1.pt() > ta2.pt(); }); + std::sort(myEvent.rec()->photons_.begin(), myEvent.rec()->photons_.end(), + [](RecPhotonFormat const & ph1, RecPhotonFormat const & ph2){ return ph1.pt() > ph2.pt(); }); + std::sort(myEvent.rec()->jets().begin(), myEvent.rec()->jets().end(), + [](RecJetFormat &j1, RecJetFormat &j2) { return j1.pt() > j2.pt();}); #ifdef MA5_FASTJET_MODE - // Setup isolation cones - if (isocone_track_radius_.size() > 0 || isocone_electron_radius_.size() > 0 || \ + // Setup isolation cones + if (isocone_track_radius_.size() > 0 || isocone_electron_radius_.size() > 0 || \ isocone_muon_radius_.size() > 0 || isocone_photon_radius_.size() > 0) - { - for (auto &part: myEvent.rec()->cluster_inputs()) - { - MCParticleFormat current_jet; - current_jet.momentum().SetPxPyPzE(part.px(),part.py(),part.pz(),part.e()); - // Set track isolation - // Isolation cone is applied to each particle that deposits energy in HCAL; - // all hadronic activity assumed to reach to HCAL - SetConeRadius(isocone_track_radius_, myEvent.rec()->tracks(), current_jet, false); - // Set Electron isolation - SetConeRadius(isocone_electron_radius_, myEvent.rec()->electrons(), current_jet, !ExclusiveId_); - // Set Muon isolation - SetConeRadius(isocone_muon_radius_, myEvent.rec()->muons(), current_jet, false); - // Set Photon isolation - SetConeRadius(isocone_photon_radius_, myEvent.rec()->photons(), current_jet, !ExclusiveId_); - } + { + for (auto &part: myEvent.rec()->cluster_inputs()) + { + MCParticleFormat current_jet; + current_jet.momentum().SetPxPyPzE(part.px(),part.py(),part.pz(),part.e()); + // Set track isolation + // Isolation cone is applied to each particle that deposits energy in HCAL; + // all hadronic activity assumed to reach to HCAL + SetConeRadius(isocone_track_radius_, myEvent.rec()->tracks(), current_jet, false); + // Set Electron isolation + SetConeRadius(isocone_electron_radius_, myEvent.rec()->electrons(), current_jet, !ExclusiveId_); + // Set Muon isolation + SetConeRadius(isocone_muon_radius_, myEvent.rec()->muons(), current_jet, false); + // Set Photon isolation + SetConeRadius(isocone_photon_radius_, myEvent.rec()->photons(), current_jet, !ExclusiveId_); + } - } + } #endif - return true; -} + return true; + } -// Load additional Jets -MAbool JetClusterer::LoadJetConfiguration(std::map options) -{ + // Load additional Jets + MAbool JetClusterer::LoadJetConfiguration(std::map options) { #ifdef MA5_FASTJET_MODE - std::string new_jetid; + std::string new_jetid; std::string algorithm; if (options.find("algorithm") == options.end()) { @@ -793,7 +789,7 @@ MAbool JetClusterer::LoadJetConfiguration(std::map opt } continue; } - // clustering algo -> keep the previous syntax + // clustering algo -> keep the previous syntax else if (key.find("cluster.")==0) { clustering_params.insert(std::pair(key.substr(8),it.second)); @@ -803,12 +799,12 @@ MAbool JetClusterer::LoadJetConfiguration(std::map opt // Other try { - throw EXCEPTION_WARNING("Parameter = "+key+" unknown. It will be skipped.","",0); + throw EXCEPTION_WARNING("Parameter = "+key+" unknown. It will be skipped.","",0); } catch(const std::exception& e) { - MANAGE_EXCEPTION(e); - return false; + MANAGE_EXCEPTION(e); + return false; } } @@ -853,7 +849,7 @@ MAbool JetClusterer::LoadJetConfiguration(std::map opt variableR = new Substructure::VariableR(rho, minR, maxR, ctype, strategy, ptmin, isExclusive); substructure_collection_.insert( - std::pair(options["JetID"], variableR) + std::pair(options["JetID"], variableR) ); std::string exclusive = isExclusive ? "True" : "False"; @@ -877,7 +873,9 @@ MAbool JetClusterer::LoadJetConfiguration(std::map opt return true; #else - ERROR << "FastJet has not been enabled. Can not add jets to the analysis." << endmsg; + ERROR << "FastJet has not been enabled. Can not add jets to the analysis." << endmsg; return true; #endif -} \ No newline at end of file + } + +} // namespace \ No newline at end of file From 1dd5603220d6c8a4b21984f3f62512d923a765ed Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 09:52:29 +0100 Subject: [PATCH 54/67] extend jet definitions --- tools/SampleAnalyzer/Interfaces/substructure/Commons.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/SampleAnalyzer/Interfaces/substructure/Commons.h b/tools/SampleAnalyzer/Interfaces/substructure/Commons.h index baa83ce9..31d06963 100644 --- a/tools/SampleAnalyzer/Interfaces/substructure/Commons.h +++ b/tools/SampleAnalyzer/Interfaces/substructure/Commons.h @@ -32,7 +32,9 @@ namespace MA5{ namespace Substructure { // Accessor for jet clustering algorithms - enum Algorithm {antikt, cambridge, kt}; + enum Algorithm { + antikt = 0, akt = 0, AKT = 0, ANTIKT = 0, cambridge = 1, ca = 1, CA = 1, CAMBRIDGE = 1, kt = 2, KT = 2 + }; } } From fe4feae940d71f4b57157f07b6c3351ed50120e9 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 16:07:35 +0100 Subject: [PATCH 55/67] bugfix in heap allocation for Filter --- tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp | 4 ++-- tools/SampleAnalyzer/Interfaces/substructure/Filter.h | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp b/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp index 1f09546e..cfabc930 100644 --- a/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp +++ b/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp @@ -32,8 +32,8 @@ namespace MA5 { Filter::~Filter() { - delete JetDefinition_; - delete JetFilter_; + if (JetDefinition_ != 0) delete JetDefinition_; + if (JetFilter_ != 0) delete JetFilter_; } //============================// diff --git a/tools/SampleAnalyzer/Interfaces/substructure/Filter.h b/tools/SampleAnalyzer/Interfaces/substructure/Filter.h index a233fcfd..f9cb7508 100644 --- a/tools/SampleAnalyzer/Interfaces/substructure/Filter.h +++ b/tools/SampleAnalyzer/Interfaces/substructure/Filter.h @@ -30,6 +30,7 @@ namespace fastjet { class Filter; + class JetDefinition; } namespace MA5 { @@ -67,7 +68,10 @@ namespace MA5 { public: /// Constructor without argument - Filter() {} + Filter() { + JetDefinition_ = 0; + JetFilter_ = 0; + } /// Destructor ~Filter(); From 4e828e4e384211b14aa5109e067c367370b9d184 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 19:17:55 +0100 Subject: [PATCH 56/67] bugfix in pointer initializer --- tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp b/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp index cfabc930..884c3604 100644 --- a/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp +++ b/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp @@ -53,7 +53,7 @@ namespace MA5 { void Filter::Initialize(MAfloat32 Rfilt, Selector selector, MAfloat32 rho) { - Rfilt_=Rfilt; rho_=rho; + Rfilt_=Rfilt; rho_=rho, JetDefinition_ = 0; init_filter(selector,false); } From f2def75eda794967abf01f5d20113ceabd29683a Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 19:30:02 +0100 Subject: [PATCH 57/67] add interface test for jet substructure --- madanalysis/IOinterface/library_writer.py | 56 +- madanalysis/core/main.py | 3 + .../SampleAnalyzer/Test/Substructure/Test.cpp | 112 ++++ .../Test/Substructure/input.dat | 487 ++++++++++++++++++ 4 files changed, 646 insertions(+), 12 deletions(-) create mode 100644 tools/SampleAnalyzer/Test/Substructure/Test.cpp create mode 100644 tools/SampleAnalyzer/Test/Substructure/input.dat diff --git a/madanalysis/IOinterface/library_writer.py b/madanalysis/IOinterface/library_writer.py index 498b60d1..39812f29 100644 --- a/madanalysis/IOinterface/library_writer.py +++ b/madanalysis/IOinterface/library_writer.py @@ -121,6 +121,8 @@ def WriteMakefileForInterfaces(self,package): filename = self.path+"/SampleAnalyzer/Test/Makefile_zlib" elif package=='test_fastjet': filename = self.path+"/SampleAnalyzer/Test/Makefile_fastjet" + elif package=='test_substructure': + filename = self.path+"/SampleAnalyzer/Test/Makefile_substructure" elif package=='test_htt': filename = self.path+"/SampleAnalyzer/Test/Makefile_htt" elif package=='test_delphes': @@ -146,6 +148,8 @@ def WriteMakefileForInterfaces(self,package): title='*zlib-interface* test' elif package=='test_fastjet': title='*fastjet-interface* test' + elif package=='test_substructure': + title='*substructure-interface* test' elif package=='test_htt': title='*htt-interface* test' elif package=='test_delphes': @@ -186,6 +190,19 @@ def WriteMakefileForInterfaces(self,package): 'cleanup_substructure.log', 'mrproper_substructure.log'] ) + elif package == "test_substructure": + options.has_commons = True + options.has_fastjet_inc = True + options.has_fastjet_lib = True + options.ma5_fastjet_mode = True + options.has_fastjet_ma5lib = True + options.has_substructure = True + toRemove.extend( + ['compilation_test_substructure.log', + 'linking_test_substructure.log', + 'cleanup_test_substructure.log', + 'mrproper_test_substructure.log'] + ) elif package == "HEPTopTagger": options.has_commons=True options.has_fastjet_inc=True @@ -203,7 +220,7 @@ def WriteMakefileForInterfaces(self,package): elif package == "test_htt": options.has_commons=True options.has_fastjet_inc=True - # options.has_fastjet_lib=True + options.has_fastjet_lib=True # @JACK: To be able to use fastjet in Ma5 data structure options.ma5_fastjet_mode=True options.has_fastjet_ma5lib = True @@ -342,9 +359,12 @@ def WriteMakefileForInterfaces(self,package): elif package=='test_fastjet': cppfiles = ['Fastjet/*.cpp'] hfiles = ['Fastjet/*.h'] + elif package=='test_substructure': + cppfiles = ['Substructure/*.cpp'] + hfiles = [] elif package=='test_htt': cppfiles = ['HEPTopTagger/*.cpp'] - hfiles = ['HEPTopTagger/*.h'] + hfiles = [] elif package=='test_delphes': cppfiles = ['Delphes/*.cpp'] hfiles = ['Delphes/*.h'] @@ -379,6 +399,10 @@ def WriteMakefileForInterfaces(self,package): isLibrary=False ProductName='TestFastjet' ProductPath='../Bin/' + elif package=='test_substructure': + isLibrary=False + ProductName='TestSubstructure' + ProductPath='../Bin/' elif package=='test_htt': isLibrary=False ProductName='TestHEPTopTagger' @@ -416,16 +440,18 @@ def Compile(self,ncores,package,folder): # log file name if package in ['process','commons','test','configuration']: logfile = folder+'/compilation.log' - elif package in ['test_process','test_commons','test_zlib','test_fastjet', "test_htt", 'test_root','test_delphes','test_delphesMA5tune']: - logfile = folder+'/compilation_'+package[5:]+'.log' + elif package in ['test_process', 'test_commons', 'test_zlib', 'test_fastjet', "test_substructure", "test_htt", + 'test_root', 'test_delphes', 'test_delphesMA5tune']: + logfile = folder + '/compilation_' + package[5:] + '.log' else: logfile = folder+'/compilation_'+package+'.log' # makefile if package in ['process','commons','test','configuration']: makefile = 'Makefile' - elif package in ['test_process','test_commons','test_zlib','test_fastjet', "test_htt", 'test_root','test_delphes','test_delphesMA5tune']: - makefile = 'Makefile_'+package[5:] + elif package in ['test_process', 'test_commons', 'test_zlib', 'test_fastjet', "test_substructure", "test_htt", + 'test_root', 'test_delphes', 'test_delphesMA5tune']: + makefile = 'Makefile_' + package[5:] else: makefile = 'Makefile_'+package @@ -451,7 +477,8 @@ def Link(self,package,folder): # log file name if package in ['process','commons','test','configuration']: logfile = folder+'/linking.log' - elif package in ['test_process','test_commons','test_zlib','test_fastjet',"test_htt",'test_root','test_delphes','test_delphesMA5tune']: + elif package in ['test_process', 'test_commons', 'test_zlib', 'test_fastjet', "test_substructure", "test_htt", + 'test_root', 'test_delphes', 'test_delphesMA5tune']: logfile = folder+'/linking_'+package[5:]+'.log' else: logfile = folder+'/linking_'+package+'.log' @@ -459,7 +486,8 @@ def Link(self,package,folder): # makefile if package in ['process','commons','test','configuration']: makefile = 'Makefile' - elif package in ['test_process','test_commons','test_zlib','test_fastjet',"test_htt",'test_root','test_delphes','test_delphesMA5tune']: + elif package in ['test_process', 'test_commons', 'test_zlib', 'test_fastjet', "test_substructure", "test_htt", + 'test_root', 'test_delphes', 'test_delphesMA5tune']: makefile = 'Makefile_'+package[5:] else: makefile = 'Makefile_'+package @@ -483,7 +511,8 @@ def Clean(self,package,folder): # log file name if package in ['process','commons','configuration','test']: logfile = folder+'/cleanup.log' - elif package in ['test_process','test_commons','test_zlib','test_fastjet',"test_htt",'test_root','test_delphes','test_delphesMA5tune']: + elif package in ['test_process', 'test_commons', 'test_zlib', 'test_fastjet', "test_substructure", "test_htt", + 'test_root', 'test_delphes', 'test_delphesMA5tune']: logfile = folder+'/cleanup_'+package[5:]+'.log' else: logfile = folder+'/cleanup_'+package+'.log' @@ -491,7 +520,8 @@ def Clean(self,package,folder): # makefile if package in ['process','commons','test','configuration']: makefile = 'Makefile' - elif package in ['test_process','test_commons','test_zlib','test_fastjet',"test_htt",'test_root','test_delphes','test_delphesMA5tune']: + elif package in ['test_process', 'test_commons', 'test_zlib', 'test_fastjet', "test_substructure", "test_htt", + 'test_root', 'test_delphes', 'test_delphesMA5tune']: makefile = 'Makefile_'+package[5:] else: makefile = 'Makefile_'+package @@ -515,7 +545,8 @@ def MrProper(self,package,folder): # log file name if package in ['process','commons','configuration']: logfile = folder+'/mrproper.log' - elif package in ['test_process','test_commons','test_zlib','test_root','test_fastjet',"test_htt",'test_delphes','test_delphesMA5tune']: + elif package in ['test_process', 'test_commons', 'test_zlib', 'test_root', 'test_fastjet', "test_substructure", + "test_htt", 'test_delphes', 'test_delphesMA5tune']: logfile = folder+'/mrproper_'+package[5:]+'.log' else: logfile = folder+'/mrproper_'+package+'.log' @@ -525,7 +556,8 @@ def MrProper(self,package,folder): # makefile if package in ['process','commons','test','configuration']: makefile = 'Makefile' - elif package in ['test_process','test_commons','test_zlib','test_root','test_fastjet',"test_htt",'test_delphes','test_delphesMA5tune']: + elif package in ['test_process', 'test_commons', 'test_zlib', 'test_root', 'test_fastjet', "test_substructure", + "test_htt", 'test_delphes', 'test_delphesMA5tune']: makefile = 'Makefile_'+package[5:] else: makefile = 'Makefile_'+package diff --git a/madanalysis/core/main.py b/madanalysis/core/main.py index c2d7fc74..570b539a 100644 --- a/madanalysis/core/main.py +++ b/madanalysis/core/main.py @@ -587,6 +587,9 @@ def BuildLibrary(self,forced=False): libraries.append(['substructure', 'interface to Jet Substructure module', 'substructure', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Lib/libsubstructure_for_ma5.so', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Interfaces', False]) + libraries.append(['test_substructure', 'interface to Jet Substructure module', 'test_substructure', + self.archi_info.ma5dir + '/tools/SampleAnalyzer/Bin/TestSubstructure', + self.archi_info.ma5dir + '/tools/SampleAnalyzer/Test/', True]) if self.archi_info.has_heptoptagger: libraries.append(['HEPTopTagger', 'interface to HEPTopTagger module', 'HEPTopTagger', self.archi_info.ma5dir + '/tools/SampleAnalyzer/Lib/libHEPTopTagger_for_ma5.so', diff --git a/tools/SampleAnalyzer/Test/Substructure/Test.cpp b/tools/SampleAnalyzer/Test/Substructure/Test.cpp new file mode 100644 index 00000000..9b381179 --- /dev/null +++ b/tools/SampleAnalyzer/Test/Substructure/Test.cpp @@ -0,0 +1,112 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2012-2022 Jack Araz, Eric Conte & Benjamin Fuks +// The MadAnalysis development team, email: +// +// This file is part of MadAnalysis 5. +// Official website: +// +// MadAnalysis 5 is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// MadAnalysis 5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with MadAnalysis 5. If not, see +// +//////////////////////////////////////////////////////////////////////////////// + +/// STL headers +#include +#include + +#define EPSILON 1E-3 + +/// Fastjet headers +#include "fastjet/PseudoJet.hh" +#include "fastjet/ClusterSequence.hh" + +/// SampleAnalyzer headers +#include "SampleAnalyzer/Interfaces/substructure/ClusterBase.h" +#include "SampleAnalyzer/Commons/DataFormat/RecJetFormat.h" +#include "SampleAnalyzer/Interfaces/substructure/SoftDrop.h" +#include "SampleAnalyzer/Interfaces/substructure/Filter.h" +#include "SampleAnalyzer/Interfaces/substructure/EnergyCorrelator.h" +#include "SampleAnalyzer/Interfaces/substructure/Nsubjettiness.h" + +using namespace MA5; + +int main(int argc, char *argv[]) +{ + std::cout << "BEGIN-SAMPLEANALYZER-TEST" << std::endl; + /// Collect data + std::ifstream fin("../Test/Substructure/input.dat",std::ifstream::in); + std::vector input_clusters; + + while(!fin.eof()){ + double x,y,z,e; + fastjet::PseudoJet p; + fin >> x >> y >> z >> e; + if(!fin.eof()){ + p.reset(x/1000., y/1000., z/1000., e/1000.); + input_clusters.push_back(p); + } + } + std::cout << " * ReadEvent: " << input_clusters.size() << " particles are read." << std::endl; + + // jet definition + fastjet::JetDefinition jet_def(fastjet::cambridge_algorithm,1.5); + fastjet::ClusterSequence clust_seq(input_clusters, jet_def); + std::vector jets = sorted_by_pt(clust_seq.inclusive_jets(200.)); + + std::vector Ma5Jet; + Ma5Jet.reserve(jets.size()); + for (auto &jet: jets) + { + RecJetFormat* current_jet = new RecJetFormat(jet); + Ma5Jet.push_back(current_jet); + } + + /// Test Soft Drop + std::cout << " * TESTING SOFTDROP" << std::endl; + Substructure::SoftDrop softDrop; + softDrop.Initialize(2.0, 0.1); + const RecJetFormat * softdrop_jet = softDrop.Execute(Ma5Jet[0]); + double sn = softdrop_jet->m(); + assert(std::fabs(24.8832 - sn) < EPSILON); + std::cout << " * SOFTDROP PASSED" << std::endl; + + /// Test Jet Filtering + std::cout << " * TESTING JET FILTERING" << std::endl; + Substructure::Filter jetFiltering; + jetFiltering.Initialize(0.2, Substructure::SelectorPtFractionMin(0.03)); + const RecJetFormat * filteredJet = jetFiltering.Execute(Ma5Jet[0]); + assert(std::fabs(389.646 - filteredJet->pt()) < EPSILON); + std::cout << " * JET FILTERING PASSED" << std::endl; + + /// Test Energy Correlator + std::cout << " * TESTING ENERGY CORRELATOR" << std::endl; + Substructure::EnergyCorrelator EC; + EC.Initialize(1, 0.1, Substructure::EnergyCorrelator::Measure::pt_R, + Substructure::EnergyCorrelator::Strategy::storage_array); + double ec = EC.Execute(Ma5Jet[0]); + assert(std::fabs(438.954 - ec) < EPSILON); + std::cout << " * ENERGY CORRELATOR PASSED " << std::endl; + + /// Test Nsubjettiness + std::cout << " * TESTING NSUBJETTINESS" << std::endl; + Substructure::Nsubjettiness nsub; + nsub.Initialize(1,Substructure::Nsubjettiness::KT_Axes, + Substructure::Nsubjettiness::NormalizedMeasure, 0.1, 0.2); + double tau1 = nsub.Execute(Ma5Jet[0]); + assert(std::fabs(0.916149 - tau1) < EPSILON); + std::cout << " * NSUBJETTINESS PASSED " << std::endl; + + std::cout << "END-SAMPLEANALYZER-TEST" << std::endl; + return 0; +} diff --git a/tools/SampleAnalyzer/Test/Substructure/input.dat b/tools/SampleAnalyzer/Test/Substructure/input.dat new file mode 100644 index 00000000..fe164801 --- /dev/null +++ b/tools/SampleAnalyzer/Test/Substructure/input.dat @@ -0,0 +1,487 @@ +-262828.28125 -37260.6914062 384220.0625 467003.34375 +91748.5859375 -27.1914653778 -307108.8125 320520.875 +49375.2070312 31864.6445312 -289290.25 295198.4375 +-56361.40625 -9070.01269531 87140.8359375 104174.84375 +-38652.3828125 -9321.82910156 52296.1054688 65694.640625 +27339.0273438 -803.389892578 -92703.5078125 96654.0625 +-26921.8417969 -428.954956055 37357.5664062 46049.5078125 +20283.6035156 15317.3222656 -125727.453125 128270.953125 +11743.2900391 10041.6083984 -62235.0117188 64124.375 +12284.4560547 4137.37011719 -20377.8066406 24151.2050781 +12948.5683594 3389.88183594 -22987.4921875 26600.4042969 +8350.02148438 6227.83154297 -54209.8945312 55201.6445312 +12593.4316406 2621.63623047 -17925.65625 22063.46875 +8381.69042969 5947.32861328 -44970.9453125 46130.3515625 +8744.58789062 10235.875 -12780.5859375 18562.9824219 +10077.0 2011.40698242 -13120.5322266 16665.5351562 +7958.91552734 -304.003234863 -27919.90625 29033.7382812 +5247.63671875 5161.31152344 -26414.5761719 27420.9160156 +-5823.84423828 -4992.96630859 -42936.3984375 43616.296875 +7877.40722656 3169.27709961 -12834.9238281 15389.3837891 +9008.80859375 1094.70837402 -14217.6708984 16867.1035156 +6030.64404297 4830.66845703 -27466.8945312 28533.0390625 +7088.68164062 -1248.40454102 -24956.8691406 25974.0878906 +-5385.23876953 -4034.65014648 -41866.0351562 42403.3515625 +-5953.47314453 -818.315734863 11296.3476562 12795.3486328 +-6033.20166016 2157.71728516 -11531.7246094 13192.2685547 +2813.2199707 4162.75683594 -5983.00830078 7812.75488281 +-3796.89697266 -2010.4954834 -23267.8339844 23661.1621094 +-3449.09790039 -1948.15405273 -26755.5195312 27047.1699219 +2825.33569336 3332.71801758 -39253.1054688 39495.515625 +-704.811889648 -3554.98388672 4685.0703125 5923.22167969 +1787.67114258 3390.96850586 -30731.9589844 30970.1113281 +2822.04589844 1908.34851074 -4727.93066406 5827.44091797 +-2718.5065918 -1361.89526367 -17808.9648438 18066.6621094 +2314.6706543 2173.609375 -23550.4609375 23763.5546875 +2079.96191406 1817.25952148 -13189.3427734 13475.4384766 +-3139.3605957 -359.250671387 -21060.9414062 21296.6640625 +2381.96313477 -1837.50708008 -1978.39282227 3600.5859375 +-2215.61645508 -2164.63720703 -5743.60400391 6525.61083984 +2028.18005371 -2506.23217773 1749.79455566 3668.30957031 +2217.0690918 2310.91259766 -25428.984375 25629.8457031 +-981.927062988 -2704.92260742 -5464.68798828 6176.05078125 +600.509643555 3844.10693359 -6967.27539062 7980.01855469 +704.931640625 2972.93164062 -7098.66845703 7728.28222656 +2085.75830078 1349.60131836 28900.1816406 29006.7636719 +1915.98986816 916.612670898 -7508.51025391 7803.13525391 +2094.40600586 232.242874146 -13610.8945312 13773.0507812 +1526.36010742 1242.13476562 -7716.13769531 7963.13085938 +-2746.13793945 88.2766647339 -18135.4335938 18342.3828125 +2191.77661133 552.271057129 1168.96289062 2544.67333984 +255.844009399 -3903.72094727 2934.05859375 4890.11181641 +1913.65844727 898.008178711 -13810.4902344 13971.3330078 +1621.09521484 1574.62231445 -11646.4091797 11863.6513672 +2223.62207031 570.982849121 -5756.26855469 6197.18847656 +-522.127258301 -2244.05273438 3040.63769531 3814.953125 +-174.492858887 -3164.26489258 -817.360229492 3272.78125 +1614.54602051 722.862976074 -5324.75439453 5610.90917969 +938.118774414 1266.47949219 2650.36450195 3083.58056641 +312.832977295 1838.39990234 -2887.26757812 3437.13427734 +2097.16943359 -178.851150513 -3859.69067383 4396.28466797 +462.524047852 1668.72412109 -48369.1914062 48400.1796875 +1763.11669922 -100.443534851 -7347.39160156 7556.64160156 +-2007.359375 -1439.74328613 -14646.8828125 14853.7382812 +-1491.56774902 -2015.51147461 -27279.4179688 27394.4101562 +-250.73765564 1558.46508789 -11323.9423828 11433.4316406 +-820.134094238 -1374.69604492 -7668.22949219 7833.52734375 +-1485.52844238 -1044.64208984 -10141.0625 10302.3886719 +1736.36889648 780.41595459 -7111.36132812 7361.75830078 +564.364501953 2735.49438477 -3625.45092773 4576.60693359 +1132.23474121 1322.04504395 -6660.22607422 6883.92089844 +-1198.35314941 1567.47412109 3504.90332031 4022.1105957 +-1329.75085449 -517.757507324 -8186.36132812 8309.80273438 +162.938156128 -2149.66577148 1266.98266602 2500.57128906 +318.917999268 1652.02612305 -711.65222168 1826.84094238 +-1373.86242676 -504.761016846 -6853.77734375 7008.31982422 +-538.830505371 -1113.89794922 175.269561768 1249.73046875 +-1525.13366699 -1239.56445312 20253.0859375 20348.21875 +1436.31091309 -1275.0567627 825.262207031 2090.41064453 +-1260.11132812 -343.291564941 -7511.16552734 7623.86621094 +806.304260254 1052.7734375 -6650.68603516 6781.59863281 +-845.054504395 -339.39730835 312.721160889 962.861450195 +1310.94665527 -562.239746094 -1123.6862793 1815.86499023 +-1415.40917969 -480.199432373 471.943450928 1567.38806152 +871.563781738 1207.51098633 690.198608398 1641.36535645 +1038.77307129 951.005249023 993.350524902 1723.4284668 +1192.66125488 223.306976318 30405.125 30429.3261719 +1617.2479248 109.64969635 -3562.63891602 3914.06567383 +1270.22314453 1107.73010254 2815.06884766 3281.02807617 +482.555938721 -1518.50341797 -18428.8730469 18497.6230469 +438.629180908 1399.40026855 6344.6796875 6511.96435547 +995.477294922 1118.9453125 -2744.21826172 3126.29931641 +822.610168457 912.888305664 879.369628906 1511.0736084 +849.860778809 -522.42376709 -477.870422363 1106.14196777 +887.648376465 1082.79089355 -2830.91870117 3158.23632812 +-863.762634277 -559.446044922 -644.490783691 1214.26281738 +-611.824768066 -789.309875488 651.943786621 1192.63171387 +872.105895996 1260.16955566 -3333.99682617 3669.35009766 +-458.224487305 -1236.43591309 -9177.515625 9271.75976562 +49.6180877686 1512.18591309 -1691.99401855 2269.80444336 +-529.809936523 -1684.52746582 -20542.5351562 20618.2949219 +-382.146606445 -1297.02770996 946.741149902 1650.64709473 +-846.894958496 779.324035645 802.80670166 1403.23754883 +-1020.53814697 -465.639007568 79.17628479 1124.53845215 +-541.511291504 -756.554626465 -33.6217536926 930.988647461 +-601.907958984 918.814025879 1657.37524414 1988.31713867 +-284.526245117 -790.704650879 459.430664062 957.729370117 +-1179.81591797 174.548751831 -1288.37561035 1755.66064453 +-372.674224854 1065.50354004 -937.564025879 1467.38208008 +-641.194702148 1292.24365234 8523.02539062 8644.24609375 +-1329.95727539 474.188293457 -2533.83496094 2900.68286133 +-774.682983398 -693.28894043 1207.16540527 1593.12011719 +-173.357635498 -1362.89648438 -6724.88134766 6863.78662109 +923.385009766 -447.741119385 1435.65075684 1764.71105957 +-131.506134033 -1240.15856934 -1371.10131836 1853.4309082 +152.407089233 1024.84313965 -4442.35107422 4561.58007812 +-388.034667969 -1743.34667969 -4857.14892578 5175.10644531 +28.8218517303 827.351989746 611.513244629 1029.21838379 +-713.239257812 -535.20300293 -603.27545166 1076.61218262 +408.54196167 -1047.60595703 2223.99169922 2492.09228516 +-536.688293457 581.162963867 447.101898193 908.67199707 +-538.630065918 778.856384277 4092.98364258 4201.1015625 +1298.83300781 261.48348999 -7382.58203125 7500.52392578 +296.064178467 490.221160889 -814.047180176 995.310791016 +-650.196838379 -914.89440918 6232.91210938 6333.16503906 +-525.977172852 504.729675293 317.242828369 795.01385498 +735.250549316 -213.968917847 83.1222686768 770.250183105 +-890.990905762 -420.830627441 83.0220413208 988.865966797 +783.354309082 -245.334060669 -2967.29418945 3078.74438477 +734.996337891 -875.291381836 -6173.00585938 6277.92626953 +1010.52886963 -133.647521973 -4768.70410156 4876.43017578 +-589.18182373 -1015.94714355 -3689.71875 3872.11938477 +492.598022461 -551.046691895 161.226623535 756.504638672 +952.441467285 -208.858718872 1017.33483887 1409.16174316 +587.325561523 -553.907165527 -282.663391113 855.373046875 +-517.000732422 817.67565918 5933.26708984 6011.6171875 +426.454437256 539.410827637 -516.087890625 859.752380371 +-53.6471290588 -819.964416504 777.189025879 1131.03601074 +727.422729492 345.823547363 -567.226867676 985.131469727 +308.830718994 -1019.74041748 -4115.98193359 4251.65332031 +-1198.95483398 -86.7623596191 -4723.87841797 4874.42773438 +517.332763672 867.619873047 -4177.671875 4298.0625 +-668.43145752 735.75378418 4155.03076172 4272.28466797 +834.549743652 -118.977394104 -2343.74291992 2490.73486328 +573.262023926 -397.155883789 -305.467834473 761.362426758 +823.065307617 -465.268920898 1062.48510742 1422.24694824 +344.761657715 314.649261475 -613.287109375 770.704772949 +334.78237915 -991.119628906 2778.61816406 2969.02612305 +503.9140625 79.8409805298 -188.871566772 544.03717041 +900.073974609 -425.625366211 -1177.66235352 1542.13452148 +815.48638916 147.437774658 -222.811889648 858.138122559 +200.588439941 730.981933594 700.556762695 1032.15795898 +699.409973145 -31.4416770935 -3636.48291016 3703.26489258 +-561.655639648 272.765411377 360.038879395 720.75378418 +-67.3348236084 1097.43554688 -2401.57910156 2641.30297852 +455.367797852 -957.807006836 3556.61816406 3711.37255859 +-267.922607422 -348.292541504 234.385818481 498.023010254 +516.044921875 -308.130828857 -106.130371094 610.336486816 +938.558349609 -128.904434204 -5032.88183594 5121.27001953 +-638.60925293 210.899688721 -215.054443359 706.079956055 +-431.378997803 912.12097168 -2317.87646484 2527.96435547 +421.531524658 -379.098175049 -124.144950867 580.358703613 +832.04901123 310.176757812 -2575.70019531 2724.47192383 +523.560852051 477.808563232 -1087.71936035 1298.28747559 +146.527374268 729.412597656 -858.203613281 1135.79333496 +236.483352661 317.019256592 271.149993896 479.528839111 +626.035339355 -277.622253418 167.327728271 704.977233887 +-237.485610962 -597.302490234 379.810211182 746.609313965 +-415.548339844 49.4954338074 588.368225098 722.016174316 +-767.734863281 -124.035804749 -4185.78417969 4257.41601562 +-376.712036133 -28.4294128418 22143.0078125 22146.2304688 +-1466.69152832 362.372497559 -17770.0761719 17834.1835938 +-35.7425804138 -602.385925293 468.195983887 763.776000977 +118.548225403 667.631713867 -362.680389404 768.975219727 +-810.63092041 -0.766242802143 -4476.29492188 4549.10302734 +760.559082031 37.2016944885 -2249.82788086 2375.19677734 +-673.293029785 246.188217163 1015.38427734 1242.95507812 +-615.966796875 -141.921203613 -795.820983887 1016.31085205 +-625.619750977 -94.9657592773 545.519104004 835.469726562 +-674.986083984 -60.0000457764 -2100.16357422 2206.78344727 +-983.894714355 -189.238250732 5618.57324219 5707.20800781 +-462.86038208 628.733886719 -977.716369629 1251.1895752 +-681.070556641 406.60559082 -4293.76806641 4366.42089844 +388.348693848 -380.472320557 -305.118011475 623.434753418 +-791.956054688 334.706115723 -3534.76953125 3637.83154297 +-60.0955429077 386.388641357 -738.289916992 835.451782227 +533.533203125 -556.23651123 -1723.53491211 1888.02258301 +300.582397461 -587.664123535 -372.446044922 757.901672363 +-649.266784668 -480.324707031 3841.48706055 3925.46582031 +-469.191223145 21.6893558502 526.020935059 705.201293945 +-475.140289307 -422.237976074 2271.65283203 2358.90869141 +627.509887695 159.860198975 -2268.89355469 2359.49194336 +-524.50390625 -258.241394043 -415.043670654 716.975769043 +97.7850723267 -363.942871094 -526.411315918 647.398803711 +-423.86126709 -563.23626709 -131.224624634 717.016967773 +468.814849854 398.713439941 -1710.11083984 1817.48144531 +97.6282196045 408.330047607 -199.558151245 464.852813721 +158.529266357 510.820892334 3709.49560547 3747.85644531 +217.423309326 867.723205566 983.342468262 1329.3527832 +462.597351074 -221.711029053 -293.458618164 590.990722656 +593.361694336 86.7153091431 -2784.77758789 2848.61083984 +301.84854126 319.171295166 -828.247741699 937.537841797 +-451.792205811 -367.286407471 216.360641479 621.150085449 +57.599647522 -694.848449707 2061.38354492 2176.10522461 +-344.99307251 137.072219849 -559.782348633 671.688415527 +74.6533203125 491.861297607 504.520111084 708.54864502 +462.521942139 413.522399902 294.856262207 686.926147461 +-223.304122925 -778.011535645 -4365.04199219 4439.45458984 +-593.881958008 -86.4216842651 -628.596679688 869.078979492 +-654.293457031 516.888305664 2925.91943359 3042.41308594 +308.123626709 536.714172363 711.274841309 942.82244873 +173.813980103 358.704406738 643.456542969 756.912475586 +403.918395996 110.70362854 315.307495117 524.236755371 +-253.448684692 -691.819458008 -4047.29370117 4113.81054688 +-282.351898193 -254.000045776 -733.335571289 825.844848633 +-475.100158691 -364.081573486 -481.698272705 768.315551758 +-547.64276123 199.301010132 233.105102539 627.671447754 +-278.313720703 374.846618652 188.98828125 503.671600342 +-277.796386719 166.296508789 -362.516021729 486.048583984 +416.798095703 197.326034546 -990.376037598 1092.47558594 +-573.639648438 -16.9672050476 -901.180541992 1068.39916992 +352.827148438 -327.371582031 -981.545043945 1093.20166016 +-493.110473633 -84.2465438843 -1393.92749023 1480.97583008 +488.145233154 725.678405762 4190.03320312 4280.33544922 +-333.722717285 120.859825134 188.820053101 402.033538818 +147.969024658 564.411743164 666.423461914 885.762756348 +51.8463935852 488.826599121 53.2623825073 494.445526123 +-316.197845459 110.937149048 580.84197998 670.571044922 +-27.8103256226 -317.200073242 387.858734131 501.820373535 +324.063934326 437.047302246 -2411.89111328 2472.49804688 +-636.129882812 218.908782959 -1222.38769531 1395.28271484 +169.190734863 309.595794678 -119.753662109 372.580200195 +338.617919922 -242.122360229 444.244720459 608.801025391 +-160.208831787 -515.892700195 47.0025596619 542.237365723 +-294.32623291 511.082977295 2777.48657227 2839.4128418 +500.136413574 -202.411132812 229.591659546 586.360839844 +5.63457632065 -555.795349121 253.65536499 610.967468262 +462.86138916 409.835021973 -507.220977783 799.67401123 +-662.945373535 391.005767822 2575.82421875 2688.35498047 +290.333984375 -206.520736694 632.408691406 725.868713379 +-604.27166748 -250.062332153 -2796.03857422 2871.49902344 +571.509094238 -33.6293334961 -1431.41113281 1541.65222168 +-26.2659912109 433.382873535 -161.049438477 463.08480835 +-156.630844116 -522.260131836 389.788360596 670.241638184 +349.069488525 -393.421447754 -699.447998047 875.1328125 +536.940734863 206.954956055 -1305.26501465 1426.48254395 +72.0006408691 514.795227051 762.119018555 922.509399414 +-466.163360596 -454.779602051 2003.78515625 2106.96166992 +420.062744141 167.231811523 -829.331359863 944.56854248 +-316.611907959 46.2869796753 -459.694763184 560.09362793 +461.769683838 21.3243484497 -561.858459473 727.578796387 +713.323791504 155.398742676 2509.33740234 2613.37988281 +151.880142212 448.439025879 -430.491394043 639.912475586 +-354.073486328 -119.888580322 17.9272441864 374.249511719 +-377.810058594 131.730407715 -322.07711792 513.640930176 +404.681243896 -230.214706421 -651.016723633 800.367736816 +754.399108887 -284.005645752 2994.89868164 3101.48266602 +190.535842896 -543.331298828 -2091.59301758 2169.39477539 +-138.606689453 -290.071502686 -557.816955566 643.826904297 +-99.6377105713 389.992492676 -138.461990356 425.668334961 +199.540161133 120.513793945 -492.237487793 544.644470215 +140.776580811 -387.11138916 1213.13269043 1281.15734863 +197.653152466 -561.432006836 1923.80603027 2013.77807617 +-217.050094604 34.339214325 462.049926758 511.644470215 +194.867889404 412.699279785 -354.015716553 577.599609375 +-389.516204834 -93.1831436157 -1031.07617188 1106.13024902 +394.682434082 -251.406311035 -617.98815918 775.17010498 +434.605224609 156.028564453 781.891784668 908.06463623 +-331.840270996 148.312042236 -496.01171875 614.932556152 +-613.820678711 -153.514358521 3967.40722656 4017.54443359 +-334.732299805 356.984619141 2878.83227539 2920.12988281 +-429.916870117 113.178840637 735.996276855 859.842102051 +251.299819946 -121.22593689 352.710388184 449.724304199 +205.583816528 437.387145996 -2335.59594727 2385.07446289 +104.813278198 288.961395264 -402.654296875 506.571807861 +500.685852051 -247.550827026 1657.0300293 1748.63269043 +172.375793457 479.123535156 2582.60009766 2632.31762695 +269.613494873 122.841186523 -407.748321533 504.023895264 +463.969665527 213.867614746 1848.93408203 1918.21911621 +-319.873931885 47.0999565125 -211.167480469 386.172821045 +344.343994141 359.908111572 -614.543151855 791.056213379 +-286.990692139 256.091766357 445.16293335 588.316833496 +-302.182067871 -47.797416687 -360.491638184 472.813720703 +266.249267578 82.690826416 -70.6683197021 287.611633301 +-149.067932129 -251.618408203 -4.61803674698 292.496826172 +-95.1179351807 -355.493652344 306.690704346 479.043151855 +32.0886955261 303.170288086 -121.342590332 328.12487793 +-475.029388428 341.353210449 -1915.39050293 2002.7220459 +212.276916504 508.549316406 2596.06445312 2653.90917969 +278.998199463 -271.806152344 -312.554229736 499.40838623 +315.761016846 304.05557251 -1385.42468262 1453.11950684 +171.852920532 -286.031066895 12.7945156097 333.9324646 +-17.6159324646 -268.700317383 151.720672607 309.078216553 +128.488037109 -597.067260742 1897.08337402 1992.96862793 +-530.381835938 78.6207504272 -2039.44995117 2108.75366211 +479.200286865 -85.4499206543 -954.213562012 1071.19470215 +102.341445923 -159.653213501 231.835128784 299.517028809 +-326.195953369 81.1711044312 65.5880355835 342.48260498 +-54.5026741028 343.759368896 -486.809844971 598.43536377 +-297.390808105 183.343917847 489.430908203 601.330932617 +66.450630188 541.080749512 2030.26428223 2102.17919922 +424.039337158 315.36315918 -1390.52709961 1487.5579834 +135.606994629 -542.359375 1131.7557373 1262.30505371 +300.006622314 515.374755859 3171.39526367 3226.97436523 +-232.625640869 -488.262084961 -3304.32421875 3348.29394531 +-355.56942749 263.937530518 1111.25134277 1196.23254395 +259.941467285 190.144119263 329.010894775 460.404724121 +-56.679233551 259.404418945 -461.680023193 532.589538574 +628.396850586 212.266067505 3604.41577148 3664.93554688 +-251.757629395 -13.1753025055 310.52053833 399.973114014 +-123.085548401 446.650146484 -1433.63110352 1506.63354492 +-292.178222656 115.445121765 256.161529541 405.357147217 +190.950286865 210.480300903 154.712982178 323.573913574 +459.692260742 -308.790466309 3003.34204102 3053.9699707 +-609.905822754 88.3035964966 -3474.88085938 3529.10473633 +396.213867188 84.3817062378 -2070.54589844 2109.80224609 +-456.605499268 98.8492126465 -1880.04919434 1937.22607422 +-164.544616699 9.20334815979 215.798736572 271.530334473 +-479.104553223 -119.672813416 -2051.58642578 2110.18237305 +-36.602191925 -273.757476807 374.200897217 465.090515137 +-436.196563721 -87.2987594604 -1892.67553711 1944.25024414 +-214.1197052 -191.587921143 146.143981934 322.352661133 +58.9035415649 368.769348145 -350.373199463 512.07598877 +-236.277282715 118.350708008 -337.138397217 428.364501953 +260.056060791 96.7209701538 -281.221710205 395.056640625 +-281.198883057 163.421859741 -210.2159729 387.25994873 +-264.817871094 332.861785889 -1342.33239746 1408.11279297 +262.019805908 36.643081665 135.458938599 297.230926514 +-251.715316772 -63.4830818176 -253.558868408 362.881256104 +347.9559021 158.801452637 -883.803588867 963.016113281 +374.597381592 61.5379981995 -881.764038086 960.009338379 +-23.932800293 312.515289307 -624.864624023 699.066772461 +281.37789917 72.8103942871 -924.723205566 969.323425293 +-433.695648193 53.7456359863 -2307.03027344 2348.05639648 +257.729614258 -39.1830558777 -355.778839111 441.065124512 +-146.164962769 -260.103240967 499.8722229 582.142700195 +355.016143799 -126.603157043 -1146.71496582 1207.07080078 +-138.08215332 51.7156028748 255.152069092 294.692657471 +-168.015975952 278.885375977 -1318.15380859 1357.76867676 +132.063751221 -140.952407837 -142.850524902 240.238815308 +95.8837509155 -266.76184082 -552.183044434 620.694519043 +135.615203857 -242.973403931 189.839279175 336.847900391 +20.6344642639 -290.318969727 527.892944336 602.811645508 +-167.970367432 -213.385147095 -455.352203369 530.181945801 +97.2250823975 -374.248962402 -1296.18945312 1352.63525391 +-91.2280807495 -367.808013916 -889.321716309 966.694580078 +-131.47227478 211.87979126 -91.8306884766 265.727081299 +-55.2641525269 -148.862075806 138.252944946 210.54196167 +-143.674880981 -193.43862915 -67.8905563354 250.339981079 +-30.2230625153 248.029647827 -363.470031738 441.069824219 +113.644088745 -187.894989014 472.587738037 521.112915039 +3.3240942955 249.213134766 166.733566284 299.863830566 +-383.713012695 135.277450562 920.890563965 1006.76464844 +-382.265594482 17.7993602753 -1302.96435547 1357.99853516 +-223.464401245 24.9094543457 181.689498901 289.081115723 +-189.236953735 207.208312988 -495.655975342 569.579467773 +222.078536987 297.124511719 -1494.32763672 1539.68078613 +-223.431472778 -196.718185425 957.71295166 1002.91265869 +-344.869598389 -102.645675659 -1241.64172363 1292.72790527 +-172.276107788 185.804870605 70.0271987915 262.88079834 +-87.6056137085 -200.651199341 14.1392669678 219.398193359 +365.271942139 -50.3414382935 2583.91455078 2610.09057617 +-128.827575684 360.034942627 -1517.47949219 1564.91711426 +147.933319092 133.809631348 -100.383560181 223.307281494 +182.054428101 115.89629364 364.396881104 423.510162354 +227.978164673 103.810997009 496.736297607 556.325195312 +-236.795196533 -76.6067047119 537.746154785 592.546630859 +52.0244255066 202.5887146 221.462692261 304.621826172 +-198.262893677 6.91983938217 -114.469871521 229.04019165 +164.477416992 179.123977661 642.093200684 686.60168457 +11.3924407959 -225.364883423 -156.393783569 274.55078125 +-377.296539307 -57.265171051 1347.79162598 1400.77624512 +53.9463348389 208.212753296 -349.218414307 410.14175415 +-226.705459595 105.810073853 -361.151641846 439.342285156 +9.05097484589 -230.571640015 -191.034866333 299.565551758 +205.304382324 -13.4783067703 -126.156303406 241.344085693 +52.2612380981 -316.610015869 -842.544128418 901.58404541 +-199.450576782 -268.484985352 1588.97912598 1623.79785156 +102.144836426 132.941543579 19.01121521 168.725952148 +-162.219360352 -159.069946289 -78.9279632568 240.516098022 +-274.397918701 -126.455024719 870.174682617 921.134643555 +-172.870407104 -311.16595459 2078.16040039 2108.42578125 +142.09487915 103.34009552 -204.136001587 269.335540771 +128.987762451 -173.421676636 -346.717529297 408.565734863 +-200.201080322 117.854873657 -252.305221558 342.96963501 +136.163497925 284.958526611 -1377.5847168 1413.32287598 +-243.369186401 -273.252746582 -1287.58056641 1338.56616211 +-78.6706848145 72.0934371948 -163.837936401 195.523422241 +85.2420272827 -63.8692359924 -68.0201263428 126.381248474 +5.48315286636 169.746551514 19.1963806152 170.916519165 +-174.321136475 -104.290061951 422.362365723 468.672851562 +-171.783859253 76.5187225342 60.4166183472 197.522094727 +-175.505126953 25.5033969879 -217.225921631 280.427490234 +123.021682739 107.014671326 -451.839294434 480.359466553 +257.343231201 218.456741333 1710.3013916 1743.2956543 +150.419433594 -38.9184989929 -401.071899414 430.115478516 +69.3821640015 149.40536499 230.240112305 283.101318359 +-65.3087005615 -76.3590698242 199.564559937 223.4322052 +-101.875679016 112.979660034 -163.442932129 223.286026001 +-258.444122314 -157.256561279 -1107.35888672 1147.94018555 +26.7573318481 -93.475112915 -207.100631714 228.788604736 +-90.1658096313 -251.101425171 1174.62353516 1204.5423584 +130.258453369 280.837738037 1293.95117188 1330.46862793 +98.7972183228 -273.000793457 -1406.56286621 1436.21362305 +233.238555908 -12.0738554001 1060.44787598 1085.86169434 +180.79699707 26.977306366 -9.73153781891 183.057449341 +-135.318725586 -108.293296814 -45.3031349182 179.139526367 +-241.098632812 156.288497925 1572.01745605 1598.05932617 +-158.164474487 26.3298530579 -153.631286621 222.062683105 +143.044540405 -130.906036377 602.377807617 632.816833496 +-38.0151290894 -153.505233765 150.350479126 218.206954956 +176.451507568 -152.510238647 503.92175293 555.276184082 +-209.217941284 42.8756561279 127.991287231 248.982406616 +-226.651504517 106.940330505 76.5094833374 262.03213501 +90.9969940186 -58.3109817505 -209.628112793 235.848617554 +-190.11050415 -168.852767944 -1228.45581055 1254.49475098 +184.489456177 -26.777256012 -1039.73449707 1056.31494141 +245.028427124 -175.379852295 -1342.34960938 1375.75415039 +89.744758606 -161.848114014 502.412475586 535.413146973 +-142.788375854 -123.909431458 -670.08404541 696.243286133 +-129.925552368 44.6646118164 -235.412002563 272.569976807 +-3.10773539543 243.49937439 -975.948791504 1005.87158203 +-130.704086304 121.191932678 -607.82244873 633.418640137 +134.020446777 -46.7718048096 -376.337371826 402.217468262 +25.1293697357 170.080566406 596.797546387 621.068603516 +-137.978118896 -104.483901978 -166.665588379 240.275390625 +-37.2089080811 75.2833099365 -160.025909424 180.721801758 +-75.1667709351 3.75725960732 -183.045562744 197.913711548 +-6.59699249268 128.646194458 -325.193634033 349.777435303 +271.550994873 19.8085670471 1403.52368164 1429.68908691 +7.60999155045 -173.525817871 380.973937988 418.700683594 +87.3937835693 -63.5869140625 -207.347915649 233.824996948 +70.2305145264 51.5499992371 241.805297852 257.020477295 +91.5034408569 57.7856636047 -185.578186035 214.828598022 +67.8807525635 211.434646606 -1140.46276855 1161.88110352 +-65.2170333862 9.60854530334 113.410140991 131.177154541 +-110.315155029 38.7354698181 -4.27238368988 116.996253967 +-59.7876815796 -103.070579529 -545.44317627 558.30670166 +-223.654174805 -61.4167022705 1192.27661133 1214.6262207 +-70.257598877 32.8206558228 170.350860596 187.170349121 +9.43720436096 -61.059135437 -104.676460266 121.55015564 +6.63288640976 137.884368896 -465.530578613 485.566497803 +54.5453643799 113.486709595 -221.424118042 254.721557617 +28.1700057983 219.639907837 1144.94055176 1166.15783691 +-141.597320557 129.026733398 979.586486816 998.141967773 +-80.9826049805 -75.3437576294 -248.48147583 271.988800049 +-67.3579406738 -139.726715088 -886.251831055 899.723815918 +76.3685150146 120.071853638 620.328430176 636.440673828 +-53.4710731506 -38.8368110657 -337.47164917 343.881622314 +104.30229187 64.1203765869 -261.096923828 288.378204346 +-80.242477417 -36.8715782166 306.120422363 318.60333252 +-90.038772583 99.4113616943 -325.559204102 352.105651855 +117.634368896 -18.4335079193 -519.202575684 532.680908203 +81.977973938 -73.9195022583 -80.9333877563 136.874740601 +82.7330703735 -76.2519989014 -541.958740234 553.514587402 +9.33701038361 110.972351074 -225.654510498 251.638626099 +66.8926849365 31.8457736969 83.4559936523 111.596092224 +49.5910148621 -2.2472307682 -32.2575263977 59.201915741 +-6.24311637878 -113.670272827 -352.448669434 370.378143311 +-36.5033340454 -80.7571258545 204.021392822 222.438613892 +-32.5940551758 93.2269668579 -440.178283691 451.121459961 +5.00377035141 -94.771156311 141.518661499 170.394073486 +-38.3466682434 -83.0532684326 -298.994232178 312.675323486 +23.6306476593 65.3635787964 63.7607917786 94.3199005127 +101.937843323 -27.0256843567 141.090637207 176.148452759 +-39.9993515015 110.605171204 -348.257354736 367.58215332 +68.3928146362 -107.130355835 187.432174683 226.462600708 +107.049041748 -26.8194923401 1.71462702751 110.37084198 +95.2299728394 -69.8327484131 -216.167831421 246.320709229 +-66.8646240234 139.910812378 -443.23928833 469.581695557 +-30.3158168793 46.7943191528 -32.6409225464 64.6079483032 +22.1420478821 61.4740638733 -123.377555847 139.611434937 +-15.6072301865 -62.802898407 -189.245330811 200.003967285 +-65.5332717896 140.362091064 35.4454345703 158.910369873 +28.5883274078 59.5948486328 -212.651702881 222.687194824 +-9.90988254547 27.4723072052 -32.4371299744 43.6474609375 +-56.8140068054 -97.529876709 -193.117675781 223.683578491 +2.33134198189 65.6356201172 65.0542678833 92.442024231 +-29.886844635 -43.8190879822 -224.325531006 230.510910034 +33.0511398315 -16.1610527039 -25.3651657104 44.6872367859 +74.1563262939 18.1758918762 -88.0356216431 116.532371521 +17.1007156372 -29.3813762665 16.0730609894 37.6037635803 +-10.3711366653 2.94795441628 11.6719636917 15.8897972107 +-0.340210616589 -7.37204265594 9.37533473969 11.9314565659 +-15.8926486969 0.626824915409 13.8912763596 21.1172142029 +-3.47081518173 -3.99431276321 24.684173584 25.2449893951 +-3.17013216019 1.83064675331 -6.8429479599 7.76060199738 +-0.348987787962 1.07221770287 1.96187603474 2.26283025742 From 636b13bc9d98a78a8cc80ce09fc6d7c8c33cd25d Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 19:30:10 +0100 Subject: [PATCH 58/67] update HTT test --- .../SampleAnalyzer/Test/HEPTopTagger/Test.cpp | 61 +++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/tools/SampleAnalyzer/Test/HEPTopTagger/Test.cpp b/tools/SampleAnalyzer/Test/HEPTopTagger/Test.cpp index b82dddc4..2f8d4774 100644 --- a/tools/SampleAnalyzer/Test/HEPTopTagger/Test.cpp +++ b/tools/SampleAnalyzer/Test/HEPTopTagger/Test.cpp @@ -21,6 +21,17 @@ // //////////////////////////////////////////////////////////////////////////////// +/// STL headers +#include +#include + +#define EPSILON 1E-3 + +/// Fastjet headers +#include "fastjet/PseudoJet.hh" +#include "fastjet/ClusterSequence.hh" + +/// SampleAnalyzer headers #include "SampleAnalyzer/Interfaces/HEPTopTagger/HTT.h" using namespace MA5; @@ -31,14 +42,56 @@ using namespace MA5; int main(int argc, char *argv[]) { std::cout << "BEGIN-SAMPLEANALYZER-TEST" << std::endl; + + /// Collect data + std::ifstream fin("../Test/Substructure/input.dat",std::ifstream::in); + std::vector input_clusters; + + while(!fin.eof()){ + double x,y,z,e; + fastjet::PseudoJet p; + fin >> x >> y >> z >> e; + if(!fin.eof()){ + p.reset(x/1000., y/1000., z/1000., e/1000.); + input_clusters.push_back(p); + } + } + std::cout << " * ReadEvent: " << input_clusters.size() << " particles are read." << std::endl; + + // jet definition + fastjet::JetDefinition jet_def(fastjet::cambridge_algorithm,1.5); + fastjet::ClusterSequence clust_seq(input_clusters, jet_def); + std::vector jets = sorted_by_pt(clust_seq.inclusive_jets(200.)); + + std::vector Ma5Jet; + Ma5Jet.reserve(jets.size()); + for (auto &jet: jets) + { + RecJetFormat* current_jet = new RecJetFormat(jet); + Ma5Jet.push_back(current_jet); + } + + std::cout << " * TESTING HEPTOPTAGGER" << std::endl; MA5::Substructure::HTT tagger; MA5::Substructure::HTT::InputParameters param; - param.do_optimalR = false; - param.reclustering_algorithm = Substructure::kt; - INFO << "initializing HTT " << endmsg; + param.max_subjet = 30.; + param.mass_drop = 0.8; + param.filtering_R = 0.3; + param.filt_N = 5; + param.filtering_minpt = 30.; + param.mode = Substructure::HTT::TWO_STEP_FILTER; tagger.Initialize(param); - INFO << "HTT initialized" << endmsg; tagger.get_settings(); + + tagger.Execute(Ma5Jet[1]); + if (tagger.is_tagged()){ + std::cout << " * Input fatjet: pT = " << Ma5Jet[1]->pt() << std::endl; + std::cout << " * Output: pT = " << tagger.top()->pt() + << " Mass = " << tagger.top()->m() << std::endl; + assert(std::fabs(tagger.top()->m() - 177.188) < EPSILON); + } + std::cout << " * HEPTOPTAGGER PASSED " << std::endl; + std::cout << "END-SAMPLEANALYZER-TEST" << std::endl; return 0; } From 8f67c6e184f2bfd060aa8797530a051e83233023 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Sat, 25 Jun 2022 22:15:50 +0100 Subject: [PATCH 59/67] update changelog-v2.0.md --- doc/releases/changelog-v2.0.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/releases/changelog-v2.0.md b/doc/releases/changelog-v2.0.md index ff6b9383..ba4b18e0 100644 --- a/doc/releases/changelog-v2.0.md +++ b/doc/releases/changelog-v2.0.md @@ -37,6 +37,10 @@ so that MadAnalysis can be compiled without these modules as well. file. This will lead to much cleaner and independent analysis construction. [(#86)](https://github.com/MadAnalysis/madanalysis5/pull/86) +* Compilation time testing has been added for Jet Substructure and + HEPTopTagger interfaces + ([#86](https://github.com/MadAnalysis/madanalysis5/pull/86)). + ## Bug fixes * Various bugfixes for matching the numeric results to the Ma5 v1.10. From 5409785ba234890a23b47adef1884a2700f57a30 Mon Sep 17 00:00:00 2001 From: BFuks Date: Mon, 4 Jul 2022 15:10:18 +0200 Subject: [PATCH 60/67] polishing the language --- bin/ma5 | 2 +- doc/releases/changelog-v2.0.md | 39 +++++++++++++++++----------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/bin/ma5 b/bin/ma5 index 747433d3..51b8f932 100755 --- a/bin/ma5 +++ b/bin/ma5 @@ -68,7 +68,7 @@ sys.path.insert(0, servicedir) # Release version # Do not touch it !!!!! version = "2.0.1" -date = "2022/06/09" +date = "2022/07/04" # Loading the MadAnalysis session import madanalysis.core.launcher diff --git a/doc/releases/changelog-v2.0.md b/doc/releases/changelog-v2.0.md index ba4b18e0..b6726270 100644 --- a/doc/releases/changelog-v2.0.md +++ b/doc/releases/changelog-v2.0.md @@ -2,9 +2,9 @@ ## New features since last release -* Substructure module have been implemented to MadAnalysis 5. - [(#13)](https://github.com/MadAnalysis/madanalysis5/pull/13) - * Module includes the following functionality through normal/expert mode +* A module allowing for jet substructure studies has been implemented in + MadAnalysis 5. [(#13)](https://github.com/MadAnalysis/madanalysis5/pull/13) + * It includes the following fastjet-contrib functionalities: * VariableR: normal and expert mode * SoftDrop: expert mode * Clusterer: expert mode @@ -14,36 +14,37 @@ * Pruner: expert mode * Energy Correlator: expert mode * HEPTopTagger: expert mode - * `RecJetFormat` has been wrapped with `PseudoJet` to accommodate dynamic - transition between two objects. - - All these methods can be used through SFS interface. + * `RecJetFormat` has been wrapped with a `PseudoJet` structure to accommodate + dynamic transition between two objects. -* Substructure and HEPTopTagger has been redesigned to be shared library -so that MadAnalysis can be compiled without these modules as well. + All these methods can be used through the SFS interface. + +* Substructure and HEPTopTagger has been redesigned to be shared libraries, so + that MadAnalysis could be compiled without these modules as well. [(#63)](https://github.com/MadAnalysis/madanalysis5/pull/63) -* Tagger module has been redesigned to accommodate substructure module. +* The tagger module has been redesigned to accommodate the features of + substructure module. [(#86)](https://github.com/MadAnalysis/madanalysis5/pull/86) - -* Multilevel object tagging has been enabled through SFS. + +* Multi-level object tagging has been enabled through the SFS framework. ([#97](https://github.com/MadAnalysis/madanalysis5/pull/97)) - * Option to activate c-jet tagging has been introduced. + * Option to activate charm-jet tagging has been introduced. * Option to use jet-based hadronic tau matching has been introduced. ## Improvements -* SFS libraries included in `analysisList.h` file instead of main analysis - file. This will lead to much cleaner and independent analysis construction. - [(#86)](https://github.com/MadAnalysis/madanalysis5/pull/86) +* The SFS libraries are now included in the file `analysisList.h`, instead of in + the main analysis file. This leads to much cleaner and independent analysis + construction. [(#86)](https://github.com/MadAnalysis/madanalysis5/pull/86) -* Compilation time testing has been added for Jet Substructure and +* Compilation time testing has been added for the jet Substructure and HEPTopTagger interfaces ([#86](https://github.com/MadAnalysis/madanalysis5/pull/86)). ## Bug fixes -* Various bugfixes for matching the numeric results to the Ma5 v1.10. +* Various bugfixes for matching the numeric results to MA5 v1.10. ([#97](https://github.com/MadAnalysis/madanalysis5/pull/97)) ## Contributors @@ -51,4 +52,4 @@ so that MadAnalysis can be compiled without these modules as well. This release contains contributions from (in alphabetical order): [Jack Y. Araz](https://github.com/jackaraz), -[Benjamin Fuks](https://github.com/BFuks) \ No newline at end of file +[Benjamin Fuks](https://github.com/BFuks) From dc3c7cb6ef4982a5afdad2f96f7a116b24598e15 Mon Sep 17 00:00:00 2001 From: BFuks Date: Tue, 5 Jul 2022 11:40:09 +0200 Subject: [PATCH 61/67] =?UTF-8?q?=20-=20Polishing=20error=20and=20warning?= =?UTF-8?q?=20messages=20all=20over=20the=20place.=20=20-=20Fixing=20a=20c?= =?UTF-8?q?ompilation=20bugs=20with=20the=20delphes=20interface=20and=20th?= =?UTF-8?q?e=20new=20b-tagging.=20=20-=20Adding=20the=20=E2=80=98med?= =?UTF-8?q?=E2=80=99=20keyword=20for=20medium=20b-jets.=20=20-=20Updating?= =?UTF-8?q?=20the=20way=20to=20enable=20tau=20tagging.=20=20-=20Issues=20w?= =?UTF-8?q?ith=20the=20various=20taggers=20in=20SFSTaggerBase=20that=20cou?= =?UTF-8?q?ld=20yield=20inconsistencies.=20=20-=20Printout=20in=20RecJetFo?= =?UTF-8?q?rmat=20(all=20tags=20printed=20now).=20=20-=20MET=20calculation?= =?UTF-8?q?=20to=20discuss=20in=20ClusterAlgoFastjet.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/beauty_identification.py | 24 ++---- .../configuration/tau_identification.py | 29 +++---- madanalysis/fastsim/tagger.py | 8 +- madanalysis/job/job_tagger_header.py | 34 ++++----- .../Commons/Base/Configuration.cpp | 2 +- .../Commons/Base/SFSTaggerBase.cpp | 75 +++++++++---------- .../Commons/Base/SFSTaggerBase.h | 12 +-- .../Commons/DataFormat/RecJetFormat.h | 11 ++- .../delphes/DelphesMemoryInterface.cpp | 4 +- .../Interfaces/delphes/DelphesTreeReader.cpp | 12 +-- .../Interfaces/fastjet/ClusterAlgoFastJet.cpp | 5 +- .../Interfaces/substructure/Filter.cpp | 4 +- .../Process/JetClustering/JetClusterer.cpp | 14 ++-- .../Process/JetClustering/JetClusterer.h | 12 +-- 14 files changed, 116 insertions(+), 130 deletions(-) diff --git a/madanalysis/configuration/beauty_identification.py b/madanalysis/configuration/beauty_identification.py index 6702ced0..42a4431c 100644 --- a/madanalysis/configuration/beauty_identification.py +++ b/madanalysis/configuration/beauty_identification.py @@ -97,34 +97,22 @@ def user_SetParameter(self, parameter: str, value: str) -> bool: # efficiency elif parameter == "bjet_id.efficiency": - logging.getLogger("MA5").error( - "This function has been deprecated, please use SFS functionality instead." - ) - logging.getLogger("MA5").error( - "Same functionality can be captured via following command in SFS:" - ) + logging.getLogger("MA5").error("This function is deprecated; please use the corresponding SFS functionality instead.") + logging.getLogger("MA5").error("This can be achieved by typing the following command:") logging.getLogger("MA5").error(f" -> define tagger b as b {value}") return False # mis efficiency (cjet) elif parameter == "bjet_id.misid_cjet": - logging.getLogger("MA5").error( - "This function has been deprecated, please use SFS functionality instead." - ) - logging.getLogger("MA5").error( - "Same functionality can be captured via following command in SFS:" - ) + logging.getLogger("MA5").error("This function is deprecated; please use the corresponding SFS functionality instead.") + logging.getLogger("MA5").error("This can be achieved by typing the following command:") logging.getLogger("MA5").error(f" -> define tagger b as c {value}") return False # mis efficiency (ljet) elif parameter == "bjet_id.misid_ljet": - logging.getLogger("MA5").error( - "This function has been deprecated, please use SFS functionality instead." - ) - logging.getLogger("MA5").error( - "Same functionality can be captured via following command in SFS:" - ) + logging.getLogger("MA5").error("This function is deprecated; please use the corresponding SFS functionality instead.") + logging.getLogger("MA5").error("This can be achieved by typing the following command:") logging.getLogger("MA5").error(f" -> define tagger b as j {value}") return False diff --git a/madanalysis/configuration/tau_identification.py b/madanalysis/configuration/tau_identification.py index 31fa4622..0c8ef380 100644 --- a/madanalysis/configuration/tau_identification.py +++ b/madanalysis/configuration/tau_identification.py @@ -82,14 +82,14 @@ def user_SetParameter(self, parameter, value): try: number = float(value) except: - logging.getLogger("MA5").error("the 'matching deltaR' must be a float value.") + logging.getLogger("MA5").error("the 'matching deltaR' parameter must be a float.") return False if number <= 0: - logging.getLogger("MA5").error("the 'matching deltaR' cannot be negative or null.") + logging.getLogger("MA5").error("the 'matching deltaR' parameter cannot be negative or zero.") return False if self.reconstruction_method == "hadron-based": - logging.getLogger("MA5").warning("Hadronic tau matching is only available in jet-based tagging mode.") - logging.getLogger("MA5").warning("To activate jet-based tagging type " + logging.getLogger("MA5").warning("Hadronic tau matching is only available in the jet-based tagging mode.") + logging.getLogger("MA5").warning("To activate jet-based tagging, please type:" "`set main.fastsim.tau_id.reconstruction_method = jet-based`") self.matching_dr = number @@ -99,9 +99,8 @@ def user_SetParameter(self, parameter, value): logging.getLogger('MA5').error("'exclusive' possible values are : 'true', 'false'") return False if self.reconstruction_method == "hadron-based": - logging.getLogger("MA5").warning("Exclusive Hadronic tau matching is only available " - "in jet-based tagging mode.") - logging.getLogger("MA5").warning("To activate jet-based tagging type " + logging.getLogger("MA5").warning("Exclusive Hadronic tau matching is only available in the jet-based tagging mode.") + logging.getLogger("MA5").warning("To activate jet-based tagging, please type:" "`set main.fastsim.tau_id.reconstruction_method = jet-based`") self.exclusive = (value == "true") @@ -127,23 +126,15 @@ def user_SetParameter(self, parameter, value): # efficiency elif parameter == "tau_id.efficiency": - logging.getLogger("MA5").error( - "This function has been deprecated, please use SFS functionality instead." - ) - logging.getLogger("MA5").error( - "Same functionality can be captured via following command in SFS:" - ) + logging.getLogger("MA5").error("This function is deprecated; please use the corresponding SFS functionality instead.") + logging.getLogger("MA5").error("This can be achieved by typing the following command:") logging.getLogger("MA5").error(f" -> define tagger ta as ta {value}") return False # mis efficiency (ljet) elif parameter == "tau_id.misid_ljet": - logging.getLogger("MA5").error( - "This function has been deprecated, please use SFS functionality instead." - ) - logging.getLogger("MA5").error( - "Same functionality can be captured via following command in SFS:" - ) + logging.getLogger("MA5").error("This function is deprecated; please use the corresponding SFS functionality instead.") + logging.getLogger("MA5").error("This can be achieved by typing the following command:") logging.getLogger("MA5").error(f" -> define tagger ta as j {value}") return False diff --git a/madanalysis/fastsim/tagger.py b/madanalysis/fastsim/tagger.py index 69678309..747e8e87 100644 --- a/madanalysis/fastsim/tagger.py +++ b/madanalysis/fastsim/tagger.py @@ -37,10 +37,10 @@ class TaggerStatus(Enum): @staticmethod def get_status(status: str): - """Convert string to tagger status""" + """Convert string to tagger criterion""" if status.lower() == "loose": return TaggerStatus.LOOSE - elif status.lower() in ["mid", "medium"]: + elif status.lower() in ["med", "mid", "medium"]: return TaggerStatus.MID elif status.lower() == "tight": return TaggerStatus.TIGHT @@ -52,7 +52,7 @@ def to_str(status): if status == TaggerStatus.LOOSE: return "loose" elif status == TaggerStatus.MID: - return "mid" + return "medium" elif status == TaggerStatus.TIGHT: return "tight" else: @@ -73,7 +73,7 @@ def add_rule(self, id_true: str, id_reco: str, function: AST, bounds: AST, tag: :param id_reco: particle id to be reconstructed :param function: efficiency function :param bounds: bounds of the function - :param tag: status of the tagger + :param tag: loose/medium/tight criterion of the tagger :return: """ diff --git a/madanalysis/job/job_tagger_header.py b/madanalysis/job/job_tagger_header.py index 2831e0e9..09e3635c 100644 --- a/madanalysis/job/job_tagger_header.py +++ b/madanalysis/job/job_tagger_header.py @@ -28,24 +28,24 @@ class JobTaggerHeader: # structure: (true_id, reco_id) : "..." base = { (5, 5): lambda tag: f"/// B-jet tagging efficiency (b as b)\nMAfloat32 NewTagger::{tag}_b_tagging_eff(const RecJetFormat &object) const", - (5, 4): lambda tag: f"/// B-jet mistagging as C-jet (b as c)\nMAfloat32 NewTagger::{tag}_b_mistag_c(const RecJetFormat &object) const", + (5, 4): lambda tag: f"/// B-jet mistagging rate as a C-jet (b as c)\nMAfloat32 NewTagger::{tag}_b_mistag_c(const RecJetFormat &object) const", (4, 4): lambda tag: f"/// C-jet tagging efficiency (c as c)\nMAfloat32 NewTagger::{tag}_c_tagging_eff(const RecJetFormat &object) const", - (4, 5): lambda tag: f"/// C-jet mistagging as C-jet (c as b)\nMAfloat32 NewTagger::{tag}_c_mistag_b(const RecJetFormat &object) const", - (21, 5): lambda tag: f"/// Light-Jet mistagging as b-jet (j as b)\nMAfloat32 NewTagger::lightjet_mistag_b_{tag}(const RecJetFormat &object) const", - (21, 4): lambda tag: f"/// Light-Jet mistagging as c jet (j as c)\nMAfloat32 NewTagger::lightjet_mistag_c_{tag}(const RecJetFormat &object) const", - (21, 15): lambda tag: f"/// Light-Jet mistagging as tau (j as ta)\nMAfloat32 NewTagger::lightjet_mistag_tau_{tag}(const RecJetFormat &object) const", - (21, 11): lambda tag: f"/// Light-Jet mistagging as electron (j as e)\nMAfloat32 NewTagger::lightjet_mistag_electron(const RecJetFormat &object) const", - (21, 22): lambda tag: f"/// Light-Jet mistagging as photon (j as photon)\nMAfloat32 NewTagger::lightjet_mistag_photon(const RecJetFormat &object) const", + (4, 5): lambda tag: f"/// C-jet mistagging rate as a B-jet (c as b)\nMAfloat32 NewTagger::{tag}_c_mistag_b(const RecJetFormat &object) const", + (21, 5): lambda tag: f"/// Light-Jet mistagging rate as a b-jet (j as b)\nMAfloat32 NewTagger::lightjet_mistag_b_{tag}(const RecJetFormat &object) const", + (21, 4): lambda tag: f"/// Light-Jet mistagging rate as a c jet (j as c)\nMAfloat32 NewTagger::lightjet_mistag_c_{tag}(const RecJetFormat &object) const", + (21, 15): lambda tag: f"/// Light-Jet mistagging rate as a tau (j as ta)\nMAfloat32 NewTagger::lightjet_mistag_tau_{tag}(const RecJetFormat &object) const", + (21, 11): lambda tag: f"/// Light-Jet mistagging rate as an electron (j as e)\nMAfloat32 NewTagger::lightjet_mistag_electron(const RecJetFormat &object) const", + (21, 22): lambda tag: f"/// Light-Jet mistagging rate as a photon (j as photon)\nMAfloat32 NewTagger::lightjet_mistag_photon(const RecJetFormat &object) const", (15, 15): lambda tag: f"/// Tau tagging efficiency (ta as ta)\nMAfloat32 NewTagger::{tag}_tau_tagging_eff(const RecTauFormat &object) const", - (11, 13): lambda tag: f"/// Electron mistagging as muon (e as mu)\nMAfloat32 NewTagger::electron_mistag_muon(const RecLeptonFormat &object) const", - (11, 22): lambda tag: f"/// Electron mistagging as photon (e as a)\nMAfloat32 NewTagger::electron_mistag_photon(const RecLeptonFormat &object) const", - (11, 21): lambda tag: f"/// Electron mistagging as light jet (e as j)\nMAfloat32 NewTagger::electron_mistag_lightjet(const RecLeptonFormat &object) const", - (13, 11): lambda tag: f"/// Electron mistagging as electron (mu as e)\nMAfloat32 NewTagger::muon_mistag_electron(const RecLeptonFormat &object) const", - (13, 22): lambda tag: f"/// Electron mistagging as photon (mu as a)\nMAfloat32 NewTagger::muon_mistag_photon(const RecLeptonFormat &object) const", - (13, 21): lambda tag: f"/// Electron mistagging as light jet (mu as j)\nMAfloat32 NewTagger::muon_mistag_lightjet(const RecLeptonFormat &object) const", - (22, 11): lambda tag: f"/// Electron mistagging as electron (a as e)\nMAfloat32 NewTagger::photon_mistag_electron(const RecPhotonFormat &object) const", - (22, 13): lambda tag: f"/// Electron mistagging as muon (a as mu)\nMAfloat32 NewTagger::photon_mistag_muon(const RecPhotonFormat &object) const", - (22, 21): lambda tag: f"/// Electron mistagging as light jet (a as j)\nMAfloat32 NewTagger::photon_mistag_lightjet(const RecPhotonFormat &object) const", + (11, 13): lambda tag: f"/// Electron mistagging rate as a muon (e as mu)\nMAfloat32 NewTagger::electron_mistag_muon(const RecLeptonFormat &object) const", + (11, 22): lambda tag: f"/// Electron mistagging rate as a photon (e as a)\nMAfloat32 NewTagger::electron_mistag_photon(const RecLeptonFormat &object) const", + (11, 21): lambda tag: f"/// Electron mistagging rate as a light jet (e as j)\nMAfloat32 NewTagger::electron_mistag_lightjet(const RecLeptonFormat &object) const", + (13, 11): lambda tag: f"/// Electron mistagging rate as an electron (mu as e)\nMAfloat32 NewTagger::muon_mistag_electron(const RecLeptonFormat &object) const", + (13, 22): lambda tag: f"/// Electron mistagging rate as a photon (mu as a)\nMAfloat32 NewTagger::muon_mistag_photon(const RecLeptonFormat &object) const", + (13, 21): lambda tag: f"/// Electron mistagging rate as a light jet (mu as j)\nMAfloat32 NewTagger::muon_mistag_lightjet(const RecLeptonFormat &object) const", + (22, 11): lambda tag: f"/// Electron mistagging rate as an electron (a as e)\nMAfloat32 NewTagger::photon_mistag_electron(const RecPhotonFormat &object) const", + (22, 13): lambda tag: f"/// Electron mistagging rate as a muon (a as mu)\nMAfloat32 NewTagger::photon_mistag_muon(const RecPhotonFormat &object) const", + (22, 21): lambda tag: f"/// Electron mistagging rate as a light jet (a as j)\nMAfloat32 NewTagger::photon_mistag_lightjet(const RecPhotonFormat &object) const", } @@ -75,7 +75,7 @@ def WriteNewTaggerHeader(self, file): file.write(' void Initialize() {\n') file.write(' /// @brief Booleans for code efficiency\n') file.write(' /// Turn on the usage of tau tagging efficiency\n') - file.write(f" _isTauTaggingEffOn = {'true' if (15, 15) in [(x[0], x[1]) for x in self.unique_rules] else 'false'};\n") + file.write(f" _isTauTaggingEffOn = {'true' if any([x in [(x[0], x[1]) for x in self.unique_rules] for x in [(15,15), (21,15)]]) else 'false'};\n") file.write(' /// Turn on the usage of jet (mis)tagging efficiency\n') file.write(f" _isJetTaggingOn = {'true' if any([x in [(x[0], x[1]) for x in self.unique_rules] for x in [(5,5), (4,5), (21,5), (5,4), (4,4), (21,4), (21,15), (21,11), (21,22)]]) else 'false'};\n") file.write(' /// Turn on the usage of muon (mis)tagging efficiency\n') diff --git a/tools/SampleAnalyzer/Commons/Base/Configuration.cpp b/tools/SampleAnalyzer/Commons/Base/Configuration.cpp index a9cf8f1f..0d75473e 100644 --- a/tools/SampleAnalyzer/Commons/Base/Configuration.cpp +++ b/tools/SampleAnalyzer/Commons/Base/Configuration.cpp @@ -41,7 +41,7 @@ using namespace MA5; // ----------------------------------------------------------------------------- // DO NOT TOUCH THESE LINES const std::string Configuration::sampleanalyzer_version_ = "2.0.1"; -const std::string Configuration::sampleanalyzer_date_ = "2022/06/09"; +const std::string Configuration::sampleanalyzer_date_ = "2022/07/04"; // DO NOT TOUCH THESE LINES // ----------------------------------------------------------------------------- diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp index dc4de519..4179c666 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.cpp @@ -95,68 +95,65 @@ namespace MA5 { for (auto &jet: myEvent.rec()->jets()) { ijet++; + MAfloat64 flat = RANDOM->flat(); /// We have a true b-jet: is it b-tagged? if (jet.true_btag()) { - if (RANDOM->flat() > loose_b_tagging_eff(jet)) jet.setLooseBtag(false); - if (RANDOM->flat() > mid_b_tagging_eff(jet)) jet.setMidBtag(false); - if (RANDOM->flat() > tight_b_tagging_eff(jet)) jet.setTightBtag(false); + if (flat > loose_b_tagging_eff(jet)) jet.setLooseBtag(false); + if (flat > mid_b_tagging_eff(jet)) jet.setMidBtag(false); + if (flat > tight_b_tagging_eff(jet)) jet.setTightBtag(false); } /// We have a true c-jet: is it b-tagged? else if (jet.true_ctag()) { - if (RANDOM->flat() < loose_c_mistag_b(jet)) jet.setLooseBtag(true); - if (RANDOM->flat() < mid_c_mistag_b(jet)) jet.setMidBtag(true); - if (RANDOM->flat() < tight_c_mistag_b(jet)) jet.setTightBtag(true); + if (flat < loose_c_mistag_b(jet)) jet.setLooseBtag(true); + if (flat < mid_c_mistag_b(jet)) jet.setMidBtag(true); + if (flat < tight_c_mistag_b(jet)) jet.setTightBtag(true); } /// We have a true light-jet: is it b-tagged? else { - if (RANDOM->flat() < lightjet_mistag_b_loose(jet)) jet.setLooseBtag(true); - if (RANDOM->flat() < lightjet_mistag_b_mid(jet)) jet.setMidBtag(true); - if (RANDOM->flat() < lightjet_mistag_b_tight(jet)) jet.setTightBtag(true); + if (flat < lightjet_mistag_b_loose(jet)) jet.setLooseBtag(true); + if (flat < lightjet_mistag_b_mid(jet)) jet.setMidBtag(true); + if (flat < lightjet_mistag_b_tight(jet)) jet.setTightBtag(true); } /// We have a true b-jet: is it c-tagged? - if (jet.true_btag()) + if (jet.true_btag() && !jet.loose_btag()) { /// We have a b-tagged jet -> moving on with the next jet - if (!jet.loose_btag() && RANDOM->flat() < loose_b_mistag_c(jet)) jet.setLooseCtag(true); - if (!jet.mid_btag() && RANDOM->flat() < mid_b_mistag_c(jet)) jet.setMidCtag(true); - if (!jet.tight_btag() && RANDOM->flat() < tight_b_mistag_c(jet)) jet.setTightCtag(true); + if (flat < loose_b_mistag_c(jet)) jet.setLooseCtag(true); + if (flat < mid_b_mistag_c(jet)) jet.setMidCtag(true); + if (flat < tight_b_mistag_c(jet)) jet.setTightCtag(true); } /// We have a true c-jet: is it c-tagged? - else if (jet.true_ctag()) + else if (jet.true_ctag() && !jet.loose_btag()) { - if (!jet.loose_btag() && RANDOM->flat() > loose_c_tagging_eff(jet)) jet.setLooseCtag(false); - if (!jet.mid_btag() && RANDOM->flat() > mid_c_tagging_eff(jet)) jet.setMidCtag(false); - if (!jet.tight_btag() && RANDOM->flat() > tight_c_tagging_eff(jet)) jet.setTightCtag(false); + if (flat > loose_c_tagging_eff(jet)) jet.setLooseCtag(false); + if (flat > mid_c_tagging_eff(jet)) jet.setMidCtag(false); + if (flat > tight_c_tagging_eff(jet)) jet.setTightCtag(false); } /// We have a true light-jet: is it c-tagged? - else + else if (!jet.loose_btag() && !jet.loose_ctag()) { - if (!jet.loose_btag() && RANDOM->flat() < lightjet_mistag_c_loose(jet)) jet.setLooseCtag(true); - if (!jet.mid_btag() && RANDOM->flat() < lightjet_mistag_c_mid(jet)) jet.setMidCtag(true); - if (!jet.tight_btag() && RANDOM->flat() < lightjet_mistag_c_tight(jet)) jet.setTightCtag(true); + if (flat < lightjet_mistag_c_loose(jet)) jet.setLooseCtag(true); + if (flat < lightjet_mistag_c_mid(jet)) jet.setMidCtag(true); + if (flat < lightjet_mistag_c_tight(jet)) jet.setTightCtag(true); } if (_options.tautag_jetbased) { - if (jet.true_tautag()) + if (jet.true_tautag() && !jet.loose_btag() && !jet.loose_ctag()) + { + if (flat > tau_tagging_eff(jet, LOOSE)) jet.setLooseTautag(false); + if (flat > tau_tagging_eff(jet, MID)) jet.setMidTautag(false); + if (flat > tau_tagging_eff(jet, TIGHT)) jet.setTightTautag(false); + } + else if (!jet.loose_btag() && !jet.loose_ctag()) { - if (!jet.loose_btag() && !jet.loose_ctag() && RANDOM->flat() > tau_tagging_eff(jet, LOOSE)) - jet.setLooseTautag(false); - if (!jet.mid_btag() && !jet.mid_ctag() && RANDOM->flat() > tau_tagging_eff(jet, MID)) - jet.setMidTautag(false); - if (!jet.tight_btag() && !jet.tight_ctag() && RANDOM->flat() > tau_tagging_eff(jet, TIGHT)) - jet.setTightTautag(false); - } else { - if (!jet.loose_btag() && !jet.loose_ctag() && RANDOM->flat() < lightjet_mistag_tau_loose(jet)) - jet.setLooseTautag(true); - if (!jet.mid_btag() && !jet.mid_ctag() && RANDOM->flat() < lightjet_mistag_tau_mid(jet)) - jet.setMidTautag(true); - if (!jet.tight_btag() && !jet.tight_ctag() && RANDOM->flat() < lightjet_mistag_tau_tight(jet)) - jet.setTightTautag(true); + if (flat < lightjet_mistag_tau_loose(jet)) jet.setLooseTautag(true); + if (flat < lightjet_mistag_tau_mid(jet)) jet.setMidTautag(true); + if (flat < lightjet_mistag_tau_tight(jet)) jet.setTightTautag(true); } } @@ -170,7 +167,7 @@ namespace MA5 { /// Scope for light jet mistagging as tau if (!_options.tautag_jetbased) { /// if not, is it Tau-tagged? - if (RANDOM->flat() < lightjet_mistag_tau_loose(jet)) { + if (flat < lightjet_mistag_tau_loose(jet)) { RecTauFormat *newTau = myEvent.rec()->GetNewTau(); Jet2Tau(&jet, newTau, myEvent); toRemove.push_back(ijet); @@ -180,7 +177,7 @@ namespace MA5 { /// Scope for light jet mistagging for electron { /// if not, is it Electron-tagged? - if (RANDOM->flat() < lightjet_mistag_electron(jet)) + if (flat < lightjet_mistag_electron(jet)) { RecLeptonFormat* NewParticle = myEvent.rec()->GetNewElectron(); NewParticle->setMomentum(jet.momentum()); @@ -199,7 +196,7 @@ namespace MA5 { /// Scope for light jet mistagging for photon { /// if not, is it Photon-tagged? - if (RANDOM->flat() < lightjet_mistag_photon(jet)) + if (flat < lightjet_mistag_photon(jet)) { RecPhotonFormat* NewParticle = myEvent.rec()->GetNewPhoton(); NewParticle->setMomentum(jet.momentum()); @@ -505,4 +502,4 @@ namespace MA5 { myTau->setCharge(charge > 0); } -} \ No newline at end of file +} diff --git a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h index 4144d390..2c39cd17 100644 --- a/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h +++ b/tools/SampleAnalyzer/Commons/Base/SFSTaggerBase.h @@ -36,9 +36,9 @@ namespace MA5 { /// @brief Tagging options /// /// @code btag_matching_deltaR : double @endcode - /// matching deltaR is the threshold for maximum dR distance between a jet and B-hadron + /// matching deltaR is the upper threshold on the dR distance between a jet and B-hadron /// @code btag_exclusive : bool @endcode - /// exclusive algorithm is designed to dynamically find the jet that best matches to the B-hadron + /// The exclusive algorithm is designed to dynamically find the jet that best matches with a given B-hadron /// /// options starting with ctag and tautag are the ones corresponding to c-jet and tau-jet tagging /// @@ -48,11 +48,11 @@ namespace MA5 { /// value in old version that has been reinstated as well. /// /// @code taujtag_jetbased : bool@endcode - /// States the nature of tau tagging proecedure. If false, the hadronic tau in the event history - /// will be found and used as hadronic tau object. if True, this hadronic tau will be matched with - /// a jet and the jet will be considered as tau jet. + /// States the nature of the tau tagging proecedure. If false, hadronic taus in the event history + /// will be found and used as hadronic tau object. If True, this hadronic tau will be matched with + /// a jet and the jet will be considered as a tau jet. /// - /// @warning DR matching for tau tagging is only available on jet based method + /// @warning DR matching for tau tagging is only available with the jet-based method MAfloat32 btag_matching_deltaR = 0.5; MAbool btag_exclusive = true; MAbool enable_ctagging = false; diff --git a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h index 499d4fe1..41532f85 100644 --- a/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h +++ b/tools/SampleAnalyzer/Commons/DataFormat/RecJetFormat.h @@ -156,8 +156,15 @@ namespace MA5 virtual void Print() const { INFO << "ntracks =" << /*set::setw(8)*/"" << std::left << ntracks_ << ", " - << "btag = " << /*set::setw(8)*/"" << std::left << loose_btag_ << ", " - << "ctag = " << /*set::setw(8)*/"" << std::left << loose_ctag_ << ", "; + << "loose btag = " << std::left << loose_btag_ << ", " + << "loose ctag = " << std::left << loose_ctag_ << ", " + << "medium btag = " << std::left << mid_btag_ << ", " + << "medium ctag = " << std::left << mid_ctag_ << ", " + << "tight btag = " << std::left << tight_btag_ << ", " + << "tight ctag = " << std::left << tight_ctag_ << ", " + << "loose tautag = " << std::left << loose_tautag_ << ", " + << "medium tautag = " << std::left << mid_tautag_ << ", " + << "tight tautag = " << std::left << tight_tautag_ << ", "; RecParticleFormat::Print(); } diff --git a/tools/SampleAnalyzer/Interfaces/delphes/DelphesMemoryInterface.cpp b/tools/SampleAnalyzer/Interfaces/delphes/DelphesMemoryInterface.cpp index cfa2fce3..424c3dcc 100644 --- a/tools/SampleAnalyzer/Interfaces/delphes/DelphesMemoryInterface.cpp +++ b/tools/SampleAnalyzer/Interfaces/delphes/DelphesMemoryInterface.cpp @@ -184,7 +184,7 @@ MAbool DelphesMemoryInterface::TransfertDELPHEStoMA5(SampleFormat& mySample, Eve { RecJetFormat* jet = myEvent.rec()->GetNewJet(); jet->momentum_.SetPxPyPzE(cand->Momentum.Px(),cand->Momentum.Py(),cand->Momentum.Pz(),cand->Momentum.E()); - jet->btag_ = cand->BTag; + jet->loose_btag_ = cand->BTag; if (cand->Eem!=0) jet->HEoverEE_ = cand->Ehad/cand->Eem; else jet->HEoverEE_ = 999.; jet->ntracks_ = 0; // To fix later } @@ -204,7 +204,7 @@ MAbool DelphesMemoryInterface::TransfertDELPHEStoMA5(SampleFormat& mySample, Eve } RecJetFormat* genjet = myEvent.rec()->GetNewGenJet(); genjet->momentum_ = cand->Momentum; - genjet->btag_ = cand->BTag; + genjet->loose_btag_ = cand->BTag; } }*/ diff --git a/tools/SampleAnalyzer/Interfaces/delphes/DelphesTreeReader.cpp b/tools/SampleAnalyzer/Interfaces/delphes/DelphesTreeReader.cpp index d103473c..c32b53ee 100644 --- a/tools/SampleAnalyzer/Interfaces/delphes/DelphesTreeReader.cpp +++ b/tools/SampleAnalyzer/Interfaces/delphes/DelphesTreeReader.cpp @@ -586,9 +586,9 @@ void DelphesTreeReader::FillEvent(EventFormat& myEvent, SampleFormat& mySample) { // Creating new jet output_jets.emplace_back(part->PT,part->Eta,part->Phi,part->Mass); - output_jets.back().ntracks_ = 0; // To fix later - output_jets.back().btag_ = part->BTag; - output_jets.back().HEoverEE_ = part->EhadOverEem; + output_jets.back().ntracks_ = 0; // To fix later + output_jets.back().loose_btag_ = part->BTag; + output_jets.back().HEoverEE_ = part->EhadOverEem; // Setting corresponding gen particle /* for (MAuint32 j=0;j(part->Particles.GetEntries());j++) @@ -624,9 +624,9 @@ void DelphesTreeReader::FillEvent(EventFormat& myEvent, SampleFormat& mySample) // Setting jet info jet->momentum_.SetPtEtaPhiM(part->PT,part->Eta,part->Phi,part->Mass); - jet->ntracks_ = 0; // To fix later - jet->btag_ = part->BTag; - jet->HEoverEE_ = part->EhadOverEem; + jet->ntracks_ = 0; // To fix later + jet->loose_btag_ = part->BTag; + jet->HEoverEE_ = part->EhadOverEem; } } diff --git a/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp b/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp index 0f3687db..fbacdec2 100644 --- a/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp +++ b/tools/SampleAnalyzer/Interfaces/fastjet/ClusterAlgoFastJet.cpp @@ -109,7 +109,10 @@ MAbool ClusterAlgoFastJet::Execute(SampleFormat& mySample, EventFormat& myEvent, /// we now switched to MHT because in the earlier version of the code when this function /// executed MET was empty. For numerical consistency we use MHT here. /// For details see JetClusterer.cpp and ClusterAlgoFastjet.cpp in v1.10.x - Meff += MHT->pt(); + /// BENJ" changed back to MET; to be discussed. + Meff += MET->pt(); + + // Exit return true; } diff --git a/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp b/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp index 884c3604..404971ed 100644 --- a/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp +++ b/tools/SampleAnalyzer/Interfaces/substructure/Filter.cpp @@ -53,7 +53,7 @@ namespace MA5 { void Filter::Initialize(MAfloat32 Rfilt, Selector selector, MAfloat32 rho) { - Rfilt_=Rfilt; rho_=rho, JetDefinition_ = 0; + Rfilt_=Rfilt; rho_=rho; JetDefinition_ = 0; init_filter(selector,false); } @@ -97,4 +97,4 @@ namespace MA5 { return output_jets; } } -} \ No newline at end of file +} diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index c3e4d790..ede8c25e 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -81,12 +81,12 @@ namespace MA5 { SFSbanner_ = true; ExclusiveId_ = false; JetID_ = "Ma5Jet"; - muon = 0; - electron = 0; - tauH = 0; - tauM = 0; - tauE = 0; - photon = 0; + muon_ = 0; + electron_ = 0; + tauH_ = 0; + tauM_ = 0; + tauE_ = 0; + photon_ = 0; isocone_track_radius_.clear(); isocone_electron_radius_.clear(); isocone_muon_radius_.clear(); @@ -878,4 +878,4 @@ namespace MA5 { #endif } -} // namespace \ No newline at end of file +} // namespace diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index abacf563..1387aa9a 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -81,12 +81,12 @@ namespace MA5 { std::map substructure_collection_; #endif - MAuint32 muon; - MAuint32 electron; - MAuint32 tauH; - MAuint32 tauM; - MAuint32 tauE; - MAuint32 photon; + MAuint32 muon_; + MAuint32 electron_; + MAuint32 tauH_; + MAuint32 tauM_; + MAuint32 tauE_; + MAuint32 photon_; // Track Isolation radius std::vector isocone_track_radius_; From b3084dcc44a5004a7240f27281e80121d31d0c95 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Mon, 18 Jul 2022 09:06:04 +0100 Subject: [PATCH 62/67] revert `_isTauTaggingEffOn` definition --- madanalysis/job/job_tagger_header.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/madanalysis/job/job_tagger_header.py b/madanalysis/job/job_tagger_header.py index 09e3635c..7580e357 100644 --- a/madanalysis/job/job_tagger_header.py +++ b/madanalysis/job/job_tagger_header.py @@ -75,7 +75,7 @@ def WriteNewTaggerHeader(self, file): file.write(' void Initialize() {\n') file.write(' /// @brief Booleans for code efficiency\n') file.write(' /// Turn on the usage of tau tagging efficiency\n') - file.write(f" _isTauTaggingEffOn = {'true' if any([x in [(x[0], x[1]) for x in self.unique_rules] for x in [(15,15), (21,15)]]) else 'false'};\n") + file.write(f" _isTauTaggingEffOn = {'true' if (15, 15) in [(x[0], x[1]) for x in self.unique_rules] else 'false'};\n") file.write(' /// Turn on the usage of jet (mis)tagging efficiency\n') file.write(f" _isJetTaggingOn = {'true' if any([x in [(x[0], x[1]) for x in self.unique_rules] for x in [(5,5), (4,5), (21,5), (5,4), (4,4), (21,4), (21,15), (21,11), (21,22)]]) else 'false'};\n") file.write(' /// Turn on the usage of muon (mis)tagging efficiency\n') From c990e68846d559228852f6e3f44ccc64d28cf323 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Mon, 18 Jul 2022 09:06:25 +0100 Subject: [PATCH 63/67] update changelog-v2.0.md --- doc/releases/changelog-v2.0.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/releases/changelog-v2.0.md b/doc/releases/changelog-v2.0.md index b6726270..c807c122 100644 --- a/doc/releases/changelog-v2.0.md +++ b/doc/releases/changelog-v2.0.md @@ -47,6 +47,9 @@ * Various bugfixes for matching the numeric results to MA5 v1.10. ([#97](https://github.com/MadAnalysis/madanalysis5/pull/97)) +* $M_{eff}$ definition has been fixed. + [(#86)](https://github.com/MadAnalysis/madanalysis5/pull/86) + ## Contributors This release contains contributions from (in alphabetical order): From 3681002c1681f9c1a8e0ce2a7e966cc7de2ae74a Mon Sep 17 00:00:00 2001 From: jackaraz Date: Mon, 18 Jul 2022 09:16:37 +0100 Subject: [PATCH 64/67] protection against prereleases --- madanalysis/system/checkup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/madanalysis/system/checkup.py b/madanalysis/system/checkup.py index e8322b53..4629f6f7 100644 --- a/madanalysis/system/checkup.py +++ b/madanalysis/system/checkup.py @@ -554,7 +554,7 @@ def check_updates(self): meta = json.loads(out) - latest_version = [int(x) for x in meta['tag_name'][1:].split(".")] + latest_version = [int(x) for x in meta['tag_name'][1:].split("_")[0].split(".")] current_version = [int(x) for x in self.archi_info.ma5_version.split(".")] def compare_versions(version1, version2): From c49a4fd004a693aa2dcd5b0b34dad6ca40b4606d Mon Sep 17 00:00:00 2001 From: jackaraz Date: Mon, 18 Jul 2022 09:27:26 +0100 Subject: [PATCH 65/67] update changelog-v2.0.md --- doc/releases/changelog-v2.0.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/releases/changelog-v2.0.md b/doc/releases/changelog-v2.0.md index c807c122..50867217 100644 --- a/doc/releases/changelog-v2.0.md +++ b/doc/releases/changelog-v2.0.md @@ -32,6 +32,9 @@ * Option to activate charm-jet tagging has been introduced. * Option to use jet-based hadronic tau matching has been introduced. +* Command to fix random seed has been added. + [(#86)](https://github.com/MadAnalysis/madanalysis5/pull/86) + ## Improvements * The SFS libraries are now included in the file `analysisList.h`, instead of in From b788cb2ee73396a74428541dacccd53952d08f23 Mon Sep 17 00:00:00 2001 From: jackaraz Date: Mon, 18 Jul 2022 09:42:05 +0100 Subject: [PATCH 66/67] update README.md --- README.md | 5 ++++- doc/README.md | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 51367571..98380cae 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ ![Python v3.8](https://img.shields.io/badge/python-3670A0?style=plastic&logo=python&logoColor=ffdd54&label=3.8&color=brightgreen) ![C++](https://img.shields.io/badge/c++-%2300599C.svg?style=plastic&logo=c%2B%2B&logoColor=white&label=11) +[![CI](https://github.com/MadAnalysis/madanalysis5/actions/workflows/quick_validation.yml/badge.svg?style=plastic)](https://github.com/MadAnalysis/madanalysis5/actions/workflows/quick_validation.yml) + ## Outline - [What is MadAnalysis 5?](#what-is-madanalysis-5) - [Requirements](#requirements) @@ -234,7 +236,8 @@ authors thank you for this. In the following you can find supported third party software that can be used within MadAnalysis 5. The [latest release](https://github.com/MadAnalysis/madanalysis5/releases) of MadAnalysis 5 has been tested with enlisted versions. -- [FastJet](http://fastjet.fr) v3.3.3 +- [FastJet](http://fastjet.fr) v3.4.0 +- [FastJet Contrib](https://fastjet.hepforge.org/contrib/) v1.048 - [Delphes](https://github.com/delphes/delphes) v3.4.3 - [ROOT](https://root.cern) v6.04.08 - [pyhf](https://github.com/scikit-hep/pyhf) v0.6.3 diff --git a/doc/README.md b/doc/README.md index 5aec86d2..fb475b51 100644 --- a/doc/README.md +++ b/doc/README.md @@ -16,3 +16,7 @@ Information can also be found in the following files. project from its early days to now. - [PAD](./PAD.md): guidelines to submit a new analysis to our Public Analysis Database (PAD). + +Further details on the usage of specific modules can be found in the following files: +- [Jet Substructure](../tools/SampleAnalyzer/Interfaces/substructure/README.md) +- [HEPTopTagger](../tools/SampleAnalyzer/Interfaces/HEPTopTagger/README.md) From 214bcb009faadafb196344589116766d8bb0ce1a Mon Sep 17 00:00:00 2001 From: jackaraz Date: Mon, 18 Jul 2022 09:45:57 +0100 Subject: [PATCH 67/67] remove unused integer declerations --- .../SampleAnalyzer/Process/JetClustering/JetClusterer.cpp | 6 ------ tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h | 7 ------- 2 files changed, 13 deletions(-) diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp index ede8c25e..16144afa 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.cpp @@ -81,12 +81,6 @@ namespace MA5 { SFSbanner_ = true; ExclusiveId_ = false; JetID_ = "Ma5Jet"; - muon_ = 0; - electron_ = 0; - tauH_ = 0; - tauM_ = 0; - tauE_ = 0; - photon_ = 0; isocone_track_radius_.clear(); isocone_electron_radius_.clear(); isocone_muon_radius_.clear(); diff --git a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h index 1387aa9a..9ac71199 100644 --- a/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h +++ b/tools/SampleAnalyzer/Process/JetClustering/JetClusterer.h @@ -81,13 +81,6 @@ namespace MA5 { std::map substructure_collection_; #endif - MAuint32 muon_; - MAuint32 electron_; - MAuint32 tauH_; - MAuint32 tauM_; - MAuint32 tauE_; - MAuint32 photon_; - // Track Isolation radius std::vector isocone_track_radius_;