ATLAS Offline Software
SmoothedTopTagger.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
9 {
10  // minimum and maximum pT of jets to tag
11  declareProperty( "JetPtMin", m_jetPtMin = 350.0e3);
12  declareProperty( "JetPtMax", m_jetPtMax = 3000.0e3);
13 
14  // cut functions that describe the tagger cuts that will be made
15  declareProperty( "VarCutFuncs", m_varCutExprs={}, "") ;
16  // names of the variables that are used for cuts
17  declareProperty( "VarCutNames", m_varCutNames={}, "") ;
18 
19 
20 }
21 
23 
24  ATH_MSG_INFO( "Initializing SmoothedTopTagger tool" );
25 
26  if( ! m_configFile.empty() ) {
27 
30 
31  TString prefix = "";
32  if ( ! m_wkpt.empty() ) prefix = m_wkpt+".";
33 
34  // read the number of variables for tagger from file
35  m_numTaggerVars = std::stoi(m_configReader.GetValue( prefix+"NumVars", ""));
36 
37  ATH_MSG_DEBUG("Number of variables used by tagger is " << std::to_string(m_numTaggerVars));
38 
39  std::string varName, varCutExpr;
40  for (int i = 1; i <= m_numTaggerVars; i++) {
41  // read the cut name corresponding to this variable
42  varName = m_configReader.GetValue( prefix+"Var"+std::to_string(i), "");
43 
44  if (varName.empty()) {
45  ATH_MSG_ERROR("Config file does not specify Var" << std::to_string(i) << "!") ;
46  return StatusCode::FAILURE;
47  }
48 
49  if (std::find(m_recognisedCuts.begin(), m_recognisedCuts.end(), varName) == m_recognisedCuts.end()) {
50  ATH_MSG_ERROR("Unrecognised variable " << varName << " in config file!") ;
51  return StatusCode::FAILURE;
52  }
53 
54  m_varCutNames.push_back(varName);
55 
56  // read cut expression
57  varCutExpr = m_configReader.GetValue( prefix+m_varCutNames.back()+"Cut", "");
58 
59  if (varCutExpr.empty()) {
60  ATH_MSG_ERROR("Config file does not specify Var" << std::to_string(i) << " cut!") ;
61  return StatusCode::FAILURE;
62  }
63 
64  m_varCutExprs.push_back(varCutExpr);
65 
66  ATH_MSG_DEBUG("Read Var" << std::to_string(i) << " from file:");
67  ATH_MSG_DEBUG(" Variable: " << m_varCutNames.back());
68  ATH_MSG_DEBUG(" Cut: " << m_varCutExprs.back());
69  }
70 
71  // get the decoration name
72  m_decorationName = m_configReader.GetValue("DecorationName" ,"");
73  } else { // no config file
74 
75  // determine number of tagger variables from size of vectors
77 
78  // make sure all of the tagger variables are recognised
79  for (const std::string& var: m_varCutNames) {
80  if (std::find(m_recognisedCuts.begin(), m_recognisedCuts.end(), var) == m_recognisedCuts.end()) {
81  ATH_MSG_ERROR("Unrecognised variable " << var << " provided!") ;
82  return StatusCode::FAILURE;
83  }
84  }
85  } // if config file
86 
87  // make sure cut names vector is not empty
88  if (m_varCutNames.empty()) {
89  ATH_MSG_ERROR( "Tagger variable names vector is empty." ) ;
90  return StatusCode::FAILURE;
91  }
92 
93  // make sure cut expressions vector is not empty
94  if (m_varCutExprs.empty()) {
95  ATH_MSG_ERROR( "Tagger variable cuts vector is empty." ) ;
96  return StatusCode::FAILURE;
97  }
98 
99  // make sure all vectors have the same length
100  if (int(m_varCutNames.size()) != int(m_varCutExprs.size())) {
101  ATH_MSG_ERROR( "Tagger variable names and cuts vectors don't have the same size." ) ;
102  return StatusCode::FAILURE;
103  }
104 
105  // make cut functions into TFI objects
106  for (int i = 0; i < m_numTaggerVars; i++) {
107  m_varCutFuncs.push_back(
108  std::make_unique<TF1>(m_varCutNames[i].c_str(), m_varCutExprs[i].c_str())
109  );
110  ATH_MSG_DEBUG("Configured " << m_varCutNames[i] << " : " << m_varCutExprs[i] << " cut TF1");
111  }
112 
113  ATH_MSG_INFO( "Smoothed top Tagger tool initialized with cuts:" );
114  for (int i = 0; i < m_numTaggerVars; i++) {
115  ATH_MSG_INFO( m_varCutNames[i]+" cut : "<< m_varCutExprs[i] );
116  }
117  ATH_MSG_INFO( "DecorationName : "<< m_decorationName );
118 
119  // add cuts for the output TAccept
120  // initialize decorators as decorationName+_decorator
121  ATH_MSG_INFO( "Additional decorators that will be attached to jet :" );
122 
123  if (std::find(m_varCutNames.begin(), m_varCutNames.end(), "Mass") != m_varCutNames.end() || std::find(m_varCutNames.begin(), m_varCutNames.end(), "mass") != m_varCutNames.end()) {
124  m_acceptInfo.addCut( "PassMass" , "mJet > mCut" );
125  // initialize decorators for passing cuts
126  // this uses m_decPassMassKey inherited from JSSTaggerBase
128  ATH_CHECK( m_decPassMassKey.initialize() );
129  m_dec_mcut = m_containerName + "." + m_decorationName + "_" + m_dec_mcut.key();
130  ATH_CHECK( m_dec_mcut.initialize() );
131  ATH_MSG_INFO( " " << m_dec_mcut.key() << " : mass cut" );
132  ATH_MSG_INFO( " " << m_decPassMassKey.key() << " : pass mass cut");
133  }
134 
135  if (std::find(m_varCutNames.begin(), m_varCutNames.end(), "Sphericity") != m_varCutNames.end() || std::find(m_varCutNames.begin(), m_varCutNames.end(), "sphericity") != m_varCutNames.end()) {
136  m_acceptInfo.addCut( "PassSphericity" , "SphericityJet > SphericityCut" );
138  ATH_CHECK( m_decPassSphericityKey.initialize() );
140  ATH_CHECK( m_dec_sphericitycut.initialize() );
141  ATH_MSG_INFO( " " << m_dec_sphericitycut.key() << " : Sphericity cut" );
142  ATH_MSG_INFO( " " << m_decPassSphericityKey.key() << " : pass Sphericity cut" );
143  }
144 
147 
149  printCuts();
150 
151  return StatusCode::SUCCESS;
152 } // end initialize()
153 
155 
156  ATH_MSG_DEBUG( "Obtaining smoothed top result" );
157 
159  asg::AcceptData acceptData( &m_acceptInfo );
160 
162  ATH_CHECK( resetCuts( acceptData ) );
163 
165  ATH_CHECK( checkKinRange( jet, acceptData ) );
166 
167  // get the relevant attributes of the jet
168  // mass and pt - note that this will depend on the configuration of the calibration used
169  float jet_pt = jet.pt()/1000.0;
170  float jet_mass = jet.m()/1000.0;
171 
174 
175  // configure decorators from JSSTaggerBase class
178 
179  // initialize for use in other statements
180  bool passCuts = true;
181  float cut_var;
182  for (int i = 0; i < m_numTaggerVars; i++) {
183  // evaluate the cut value on this variable
184  cut_var = m_varCutFuncs[i]->Eval(jet_pt);
185 
186  // check which variable this cut corresponds to and make the
187  // selection
188  // when more taggers are implemented add the variables required
189  // into this if-else ladder
190  if (m_varCutNames[i] == "Mass" || m_varCutNames[i] == "mass") {
191  // decorators for jet after applying cuts
194 
195  // decorate cut
196  decMCut(jet) = cut_var;
197 
198  // make cut and decorate on jet
199  if(jet_mass > cut_var) {
200  acceptData.setCutResult("PassMass",true);
201  }
202  decPassMass(jet) = acceptData.getCutResult("PassMass");
203  passCuts = passCuts && acceptData.getCutResult("PassMass");
204  }
205  else if (m_varCutNames[i] == "Sphericity" || m_varCutNames[i] == "sphericity") {
206  float sphericity = 0;
207 
208  // setup read/write handles for sphericity cut decorations & reading variables
212 
213  // decorate cut
214  decSphericityCut(jet) = cut_var;
215 
216  // read sphericity variable
217  if ( !readSphericity.isAvailable() ) {
218  ATH_MSG_VERBOSE( "The Sphericity variable is not available in your file" );
219  acceptData.setCutResult("ValidJetContent", false);
220  decValidJetContent(jet) = false;
221  } else {
222  // get sphericity only if it is decorated
223  sphericity = readSphericity(jet);
224  }
225 
226  // make cut and decorate results
227  if (sphericity > cut_var) {
228  acceptData.setCutResult("PassSphericity", true);
229  }
230  decPassSphericity(jet) = acceptData.getCutResult("PassSphericity");
231  // incorporate cut into complete set of selections
232  passCuts = passCuts && acceptData.getCutResult("PassSphericity");
233  }
234  }
235 
236  // decorate jets with tagging information and whether content is valid
237  decValidJetContent(jet) = acceptData.getCutResult("ValidJetContent");
238  decTagged(jet) = passCuts;
239 
240  return StatusCode::SUCCESS;
241 }
242 
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
JSSTaggerBase::resetCuts
StatusCode resetCuts(asg::AcceptData &acceptData) const
Reset cuts.
Definition: JSSTaggerBase.cxx:338
SmoothedTopTagger::m_varCutFuncs
std::vector< std::unique_ptr< TF1 > > m_varCutFuncs
Definition: SmoothedTopTagger.h:37
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SmoothedTopTagger::m_decPassSphericityKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_decPassSphericityKey
Definition: SmoothedTopTagger.h:44
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
JSSTaggerBase::m_configFile
std::string m_configFile
Configuration file name.
Definition: JSSTaggerBase.h:111
JSSTaggerBase::m_configReader
TEnv m_configReader
TEnv instance to read config files.
Definition: JSSTaggerBase.h:62
SmoothedTopTagger::m_dec_sphericitycut
SG::WriteDecorHandleKey< xAOD::JetContainer > m_dec_sphericitycut
Definition: SmoothedTopTagger.h:41
JSSTaggerBase::m_jetPtMin
float m_jetPtMin
Kinematic bounds for the jet - the units are controlled by m_ptGeV.
Definition: JSSTaggerBase.h:132
JSSTaggerBase::m_decorationName
std::string m_decorationName
Decoration name.
Definition: JSSTaggerBase.h:202
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
JSSTaggerBase::m_decValidJetContentKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_decValidJetContentKey
Definition: JSSTaggerBase.h:76
JSSTaggerBase::m_jetPtMax
float m_jetPtMax
Definition: JSSTaggerBase.h:133
SmoothedTopTagger::SmoothedTopTagger
SmoothedTopTagger(const std::string &name)
Definition: SmoothedTopTagger.cxx:7
SmoothedTopTagger::tag
virtual StatusCode tag(const xAOD::Jet &jet) const override
Decorate single jet with tagging info.
Definition: SmoothedTopTagger.cxx:154
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
lumiFormat.i
int i
Definition: lumiFormat.py:92
PixelAthClusterMonAlgCfg.varName
string varName
end cluster ToT and charge
Definition: PixelAthClusterMonAlgCfg.py:117
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
JSSTaggerBase::checkKinRange
StatusCode checkKinRange(const xAOD::Jet &jet, asg::AcceptData &acceptData) const
Check and record if jet passes kinematic constraints.
Definition: JSSTaggerBase.cxx:370
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
SmoothedTopTagger.h
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
JSSTaggerBase::calculateJSSRatios
int calculateJSSRatios(const xAOD::Jet &jet) const
Calculate JSS moment ratios in case they are not already saved TODO: Remove this once JSSMomentTools ...
Definition: JSSTaggerBase.cxx:416
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
JSSTaggerBase::m_wkpt
std::string m_wkpt
Tagger information.
Definition: JSSTaggerBase.h:128
JSSTaggerBase
Definition: JSSTaggerBase.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
JSSTaggerBase::initialize
virtual StatusCode initialize() override
Initialize the tool.
Definition: JSSTaggerBase.cxx:73
JSSTaggerBase::m_acceptInfo
asg::AcceptInfo m_acceptInfo
Object that stores the results for a jet.
Definition: JSSTaggerBase.h:65
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
SmoothedTopTagger::m_dec_mcut
SG::WriteDecorHandleKey< xAOD::JetContainer > m_dec_mcut
Definition: SmoothedTopTagger.h:40
SmoothedTopTagger::initialize
virtual StatusCode initialize() override
Initialize the tool.
Definition: SmoothedTopTagger.cxx:22
JSSTaggerBase::printCuts
void printCuts() const
Print configured cuts.
Definition: JSSTaggerBase.cxx:817
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
asg::AcceptData::setCutResult
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:134
asg::AcceptData::getCutResult
bool getCutResult(const std::string &cutName) const
Get the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:98
SmoothedTopTagger::m_numTaggerVars
int m_numTaggerVars
Definition: SmoothedTopTagger.h:28
JSSTaggerBase::m_readSphericityKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_readSphericityKey
Definition: JSSTaggerBase.h:176
JSSTaggerBase::getConfigReader
StatusCode getConfigReader()
Get configReader StatusCode.
Definition: JSSTaggerBase.cxx:300
JSSTaggerBase::m_decPassMassKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_decPassMassKey
Definition: JSSTaggerBase.h:79
SmoothedTopTagger::m_recognisedCuts
std::vector< std::string > m_recognisedCuts
Definition: SmoothedTopTagger.h:51
SmoothedTopTagger::m_varCutExprs
std::vector< std::string > m_varCutExprs
Definition: SmoothedTopTagger.h:31
asg::AcceptData
Definition: AcceptData.h:30
SG::ReadDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
SmoothedTopTagger::m_varCutNames
std::vector< std::string > m_varCutNames
Definition: SmoothedTopTagger.h:34
JSSTaggerBase::m_decTaggedKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_decTaggedKey
WriteDecorHandle keys for tagging bools.
Definition: JSSTaggerBase.h:71
asg::AcceptInfo::addCut
int addCut(const std::string &cutName, const std::string &cutDescription)
Add a cut; returning the cut position.
Definition: AcceptInfo.h:53
JSSTaggerBase::m_containerName
std::string m_containerName
Configurable members.
Definition: JSSTaggerBase.h:105