ATLAS Offline Software
Loading...
Searching...
No Matches
BJetRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9#include "CLHEP/Units/SystemOfUnits.h"
10
11namespace JiveXML {
12
19 BJetRetriever::BJetRetriever(const std::string& type,const std::string& name,const IInterface* parent):
20 AthAlgTool(type,name,parent),
21 m_typeName("BJet"){
22
23 //Only declare the interface
24 declareInterface<IDataRetriever>(this);
25
26 declareProperty("FavouriteJetCollection" ,m_sgKeyFavourite = "AntiKt4TopoEMJets",
27 "Collection to be first in output, shown in Atlantis without switching");
28 declareProperty("OtherJetCollections" ,m_otherKeys,
29 "Other collections to be retrieved. If list left empty, all available retrieved");
30 declareProperty("DoWriteHLT", m_doWriteHLT = false,"Ignore HLTAutokey object by default."); // ignore HLTAutoKey objects
31 declareProperty("WeightCut", m_weightCut = 2.4,"Weight cut flavourTagWeight, to assign lhSig = 1. Currently: JetFitterCOMBNN");
32 // >2.4 is recommended cut for JetFitterCOMBNN. 30Nov11
33 }
34
40 StatusCode BJetRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
41
42 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "in retrieveAll()" << endmsg;
43
45 const JetCollection* jets;
46
47 //obtain the default collection first
48 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve " << dataTypeName() << " (" << m_sgKeyFavourite << ")" << endmsg;
49 StatusCode sc = evtStore()->retrieve(jets, m_sgKeyFavourite);
50 if (sc.isFailure() ) {
51 if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << m_sgKeyFavourite << " not found in SG " << endmsg;
52 }else{
53 DataMap data = getData(jets);
54 if ( FormatTool->AddToEvent(dataTypeName(), m_sgKeyFavourite+"_AOD", &data).isFailure()){
55 if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << m_sgKeyFavourite << " not found in SG " << endmsg;
56 }else{
57 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << m_sgKeyFavourite << ") BJet retrieved" << endmsg;
58 }
59 }
60
61 if ( m_otherKeys.empty() ) {
62 //obtain all other collections from StoreGate
63 if (( evtStore()->retrieve(iterator, end)).isFailure()){
64 if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Unable to retrieve iterator for Jet collection" << endmsg;
65// return false;
66 }
67
68 for (; iterator!=end; ++iterator) {
69
70 std::string::size_type position = iterator.key().find("HLTAutoKey",0);
71 if ( m_doWriteHLT ){ position = 99; } // override SG key find
72
73// if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " BJet: HLTAutoKey in " << iterator.key() << " at position "
74// << position << endmsg;
75 if ( position != 0 ){ // SG key doesn't contain HLTAutoKey
76 if (iterator.key()!=m_sgKeyFavourite) {
77 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve all " << dataTypeName() << " (" << iterator.key() << ")" << endmsg;
79 if ( FormatTool->AddToEvent(dataTypeName(), iterator.key()+"_AOD", &data).isFailure()){
80 if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << iterator.key() << " not found in SG " << endmsg;
81 }else{
82 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << iterator.key() << ") BJet retrieved" << endmsg;
83 }
84 }
85 }
86 }
87 }else {
88 //obtain all collections with the given keys
89 std::vector<std::string>::const_iterator keyIter;
90 for ( keyIter=m_otherKeys.begin(); keyIter!=m_otherKeys.end(); ++keyIter ){
91 if ( !evtStore()->contains<JetCollection>( (*keyIter) ) ){ continue; } // skip if not in SG
92 StatusCode sc = evtStore()->retrieve( jets, (*keyIter) );
93 if (!sc.isFailure()) {
94 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve selected " << dataTypeName() << " (" << (*keyIter) << ")" << endmsg;
95 DataMap data = getData(jets);
96 if ( FormatTool->AddToEvent(dataTypeName(), (*keyIter)+"_AOD", &data).isFailure()){
97 if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << (*keyIter) << " not found in SG " << endmsg;
98 }else{
99 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << (*keyIter) << ") retrieved" << endmsg;
100 }
101 }
102 }
103 }
104 //All collections retrieved okay
105 return StatusCode::SUCCESS;
106 }
107
108
117
118 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "retrieve()" << endmsg;
119
121
122 DataVect phi; phi.reserve(jets->size());
123 DataVect eta; eta.reserve(jets->size());
124 DataVect pt; pt.reserve(jets->size());
125 DataVect energy; energy.reserve(jets->size());
126
127 DataVect mass; mass.reserve(jets->size());
128 DataVect px; px.reserve(jets->size());
129 DataVect py; py.reserve(jets->size());
130 DataVect pz; pz.reserve(jets->size());
131
132 DataVect weight; weight.reserve(jets->size());
133 DataVect lhSig; lhSig.reserve(jets->size());
134 DataVect charge; charge.reserve(jets->size());
135 DataVect label; label.reserve(jets->size());
136
137 float dummyLhSig = 0.;
138
139 std::string myLabel ="none";
140
141 if ( jets->size() == 0 ){
142 ATH_MSG_DEBUG( "JetCollection for BJets is empty" );
143 }else{
144 JetCollection::const_iterator itr = jets->begin();
145 for (; itr != jets->end(); ++itr) {
146
147 // lhSig obsolete from 14.2.x ! Now: weight.
148 // for backwards compatibility: AtlantisJava uses still lhSig.
150 // if ( (*itr)->getFlavourTagWeight() > m_weightCut ){ // 'good' BJet
153 //
154 if ( (*itr)->getFlavourTagWeight("JetFitterCOMBNN") > m_weightCut ){ // 'good' BJet
155 dummyLhSig = 1.;
156 }else{
157 dummyLhSig = 0.;
158 }
159 std::string myLabel ="none";
160 myLabel =
161 "weight_JetFitterCOMBNN=" + DataType( (*itr)->getFlavourTagWeight("JetFitterCOMBNN") ).toString() + "_"
162 + "WeightJetFitterTagNN=" + DataType( (*itr)->getFlavourTagWeight("JetFitterTagNN") ).toString() + "_"
163 + "WeightIP3DSV1=" + DataType( (*itr)->getFlavourTagWeight() ).toString() + "_"
164 + "WeightIP2D=" + DataType( (*itr)->getFlavourTagWeight("IP2D") ).toString() + "_"
165 + "WeightIP3D=" + DataType( (*itr)->getFlavourTagWeight("IP3D") ).toString() + "_"
166 + "WeightSV1=" + DataType( (*itr)->getFlavourTagWeight("SV1") ).toString() + "_"
167 + "WeightSV2=" + DataType( (*itr)->getFlavourTagWeight("SV2") ).toString() + "_";
168
169 phi.emplace_back((*itr)->phi());
170 eta.emplace_back((*itr)->eta());
171 pt.emplace_back((*itr)->pt()/CLHEP::GeV);
172 energy.emplace_back( (*itr)->e()/CLHEP::GeV );
173 mass.emplace_back((*itr)->m()/CLHEP::GeV);
174 px.emplace_back( (*itr)->px()/CLHEP::GeV );
175 py.emplace_back( (*itr)->py()/CLHEP::GeV );
176 pz.emplace_back( (*itr)->pz()/CLHEP::GeV );
177 weight.emplace_back( (*itr)->getFlavourTagWeight("JetFitterCOMBNN")); // recommended choice 30Nov11
178 lhSig.emplace_back( dummyLhSig ); // dummy only ! See above.
179 charge.emplace_back( (*itr)->charge());
180 label.emplace_back( myLabel );
181 }
182 }
183 // Start with mandatory entries
184 const auto nEntries = phi.size();
185 DataMap["phi"] = std::move(phi);
186 DataMap["eta"] = std::move(eta);
187 DataMap["pt"] = std::move(pt);
188 DataMap["energy"] = std::move(energy);
189 // four-vectors
190 DataMap["mass"] = std::move(mass);
191 DataMap["px"] = std::move(px);
192 DataMap["py"] = std::move(py);
193 DataMap["pz"] = std::move(pz);
194
195 // further details
196 DataMap["weight"] = std::move(weight);
197 DataMap["lhSig"] = std::move(lhSig);
198 DataMap["charge"] = std::move(charge);
199 DataMap["label"] = std::move(label);
200
201 ATH_MSG_DEBUG( dataTypeName() << " BJets (AOD, no cells), collection: " << dataTypeName()
202 << " retrieved with " << nEntries << " entries, weight cut set to: "
203 << m_weightCut);
204
205 //All collections retrieved okay
206 return DataMap;
207
208 } // retrieve
209
210} // JiveXML namespace
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define endmsg
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static Double_t sc
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
std::string m_sgKeyFavourite
const std::string m_typeName
The data type that is generated by this retriever.
virtual std::string dataTypeName() const
Return the name of the data type.
BJetRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
const DataMap getData(const JetCollection *)
Retrieve basic parameters, mainly four-vectors.
std::vector< std::string > m_otherKeys
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
a const_iterator facade to DataHandle.
Definition SGIterator.h:164
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
std::string label(const std::string &format, int i)
Definition label.h:19
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
std::map< std::string, DataVect > DataMap
Definition DataType.h:59
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition DataType.h:58