ATLAS Offline Software
Loading...
Searching...
No Matches
AODJetRetriever.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
11
12namespace JiveXML {
13
20 AODJetRetriever::AODJetRetriever(const std::string& type,const std::string& name,const IInterface* parent):
21 AthAlgTool(type,name,parent),
22 m_typeName("Jet"){
23
24 //Only declare the interface
25 declareInterface<IDataRetriever>(this);
26
27 declareProperty("FavouriteJetCollection" ,m_sgKeyFavourite = "AntiKt4TopoEMJets" ,
28 "Collection to be first in output, shown in Atlantis without switching");
29 declareProperty("OtherJetCollections" ,m_otherKeys,
30 "Other collections to be retrieved. If list left empty, all available retrieved");
31 declareProperty("DoWriteHLT", m_doWriteHLT = false,"Ignore HLTAutokey object by default."); // ignore HLTAutoKey objects
32 declareProperty("WriteJetQuality", m_writeJetQuality = false,"Don't write extended jet quality details by default.");
33 }
34
39 StatusCode AODJetRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
40
41 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "in retrieveAll()" << endmsg;
42
44 const JetCollection* jets;
45
46 //obtain the default collection first
47 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve " << dataTypeName() << " (" << m_sgKeyFavourite << ")" << endmsg;
48 StatusCode sc = evtStore()->retrieve(jets, m_sgKeyFavourite);
49 if (sc.isFailure() ) {
50 if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << m_sgKeyFavourite << " not found in SG " << endmsg;
51 }else{
52 DataMap data = getData(jets);
53 if ( FormatTool->AddToEvent(dataTypeName(), m_sgKeyFavourite+"_AOD", &data).isFailure()){
54 if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << m_sgKeyFavourite << " not found in SG " << endmsg;
55 }else{
56 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << m_sgKeyFavourite << ") AODJet retrieved" << endmsg;
57 }
58 }
59
60 if ( m_otherKeys.empty() ) {
61 //obtain all other collections from StoreGate
62 if (( evtStore()->retrieve(iterator, end)).isFailure()){
63 if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Unable to retrieve iterator for Jet collection" << endmsg;
64// return false;
65 }
66
67 for (; iterator!=end; ++iterator) {
68
69 std::string::size_type position = iterator.key().find("HLTAutoKey",0);
70 if ( m_doWriteHLT ){ position = 99; } // override SG key find
71
72// if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " AODJet: HLTAutoKey in " << iterator.key() << " at position "
73// << position << endmsg;
74 if ( position != 0 ){ // SG key doesn't contain HLTAutoKey
75 if (iterator.key()!=m_sgKeyFavourite) {
76 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve all " << dataTypeName() << " (" << iterator.key() << ")" << endmsg;
78 if ( FormatTool->AddToEvent(dataTypeName(), iterator.key()+"_AOD", &data).isFailure()){
79 if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << iterator.key() << " not found in SG " << endmsg;
80 }else{
81 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << iterator.key() << ") AODJet retrieved" << endmsg;
82 }
83 }
84 }
85 }
86 }else {
87 //obtain all collections with the given keys
88 std::vector<std::string>::const_iterator keyIter;
89 for ( keyIter=m_otherKeys.begin(); keyIter!=m_otherKeys.end(); ++keyIter ){
90 if ( !evtStore()->contains<JetCollection>( (*keyIter) ) ){ continue; } // skip if not in SG
91 StatusCode sc = evtStore()->retrieve( jets, (*keyIter) );
92 if (!sc.isFailure()) {
93 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve selected " << dataTypeName() << " (" << (*keyIter) << ")" << endmsg;
94 DataMap data = getData(jets);
95 if ( FormatTool->AddToEvent(dataTypeName(), (*keyIter)+"_AOD", &data).isFailure()){
96 if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << (*keyIter) << " not found in SG " << endmsg;
97 }else{
98 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << (*keyIter) << ") retrieved" << endmsg;
99 }
100 }
101 }
102 }
103 //All collections retrieved okay
104 return StatusCode::SUCCESS;
105 }
106
107
115
116 if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "retrieve()" << endmsg;
117
119
120 DataVect phi; phi.reserve(jets->size());
121 DataVect eta; eta.reserve(jets->size());
122 DataVect et; et.reserve(jets->size());
123 DataVect pt; pt.reserve(jets->size());
124/* need to be added to AtlantisJava/event.dtd !
125 DataVect flavourTagWeight; flavourTagWeight.reserve(jets->size());
126 DataVect charge; charge.reserve(jets->size());
127*/
128 DataVect energy; energy.reserve(jets->size());
129 DataVect mass; mass.reserve(jets->size());
130 DataVect px; px.reserve(jets->size());
131 DataVect py; py.reserve(jets->size());
132 DataVect pz; pz.reserve(jets->size());
133 DataVect idVec; idVec.reserve(jets->size());
134
135 DataVect bTagName; bTagName.reserve(jets->size());
136 DataVect bTagValue; bTagValue.reserve(jets->size());
137
138 // jet quality variables:
139 DataVect quality; quality.reserve(jets->size());
140 DataVect qualityLAr; qualityLAr.reserve(jets->size());
141 DataVect qualityTile; qualityTile.reserve(jets->size());
142 DataVect time; time.reserve(jets->size());
143 DataVect timeClusters; timeClusters.reserve(jets->size());
144 DataVect n90cells; n90cells.reserve(jets->size());
145 DataVect n90const; n90const.reserve(jets->size());
146 DataVect hecf; hecf.reserve(jets->size());
147 DataVect emfrac; emfrac.reserve(jets->size());
148 DataVect tileGap3f; tileGap3f.reserve(jets->size());
149 DataVect fcorCell; fcorCell.reserve(jets->size());
150 DataVect fcorDotx; fcorDotx.reserve(jets->size());
151 DataVect fcorJet; fcorJet.reserve(jets->size());
152 DataVect fcorJetForCell; fcorJetForCell.reserve(jets->size());
153 DataVect nbadcells; nbadcells.reserve(jets->size());
154 DataVect fracSamplingMax; fracSamplingMax.reserve(jets->size());
155 DataVect sMax; sMax.reserve(jets->size());
156 DataVect OutOfTimeEfrac; OutOfTimeEfrac.reserve(jets->size());
157 DataVect isGood; isGood.reserve(jets->size());
158 DataVect isBad; isBad.reserve(jets->size());
159 DataVect isUgly; isUgly.reserve(jets->size());
160 DataVect jvf; jvf.reserve(jets->size());
161
162 int id = 0;
163
164 JetCollection::const_iterator itr = jets->begin();
165 for (; itr != jets->end(); ++itr) {
166 phi.push_back(DataType((*itr)->phi()));
167 eta.push_back(DataType((*itr)->eta()));
168 et.push_back(DataType((*itr)->et()/CLHEP::GeV));
169 pt.push_back(DataType((*itr)->pt()/CLHEP::GeV));
170 idVec.push_back( DataType( ++id ));
171
172//from: http://alxr.usatlas.bnl.gov/lxr/source/atlas/PhysicsAnalysis/AnalysisCommon/AnalysisExamples/src/JetTagAna.cxx
173//
174 // bjet tagger values
175 bTagName.push_back( DataType( "JetFitterCOMBNN" ));
176 bTagValue.push_back( DataType( (*itr)->getFlavourTagWeight("JetFitterCOMBNN") ));
177 bTagName.push_back( DataType( "JetFitterTagNN" ));
178 bTagValue.push_back( DataType( (*itr)->getFlavourTagWeight("JetFitterTagNN") ));
179 bTagName.push_back( DataType( "IP3D+SV1" ));
180 bTagValue.push_back( DataType( (*itr)->getFlavourTagWeight() ));
181 bTagName.push_back( DataType( "IP2D" ));
182 bTagValue.push_back( DataType( (*itr)->getFlavourTagWeight("IP2D") ));
183 bTagName.push_back( DataType( "IP3D" ));
184 bTagValue.push_back( DataType( (*itr)->getFlavourTagWeight("IP3D") ));
185 bTagName.push_back( DataType( "SV1" ));
186 bTagValue.push_back( DataType( (*itr)->getFlavourTagWeight("SV1") ));
187 bTagName.push_back( DataType( "SV2" ));
188 bTagValue.push_back( DataType( (*itr)->getFlavourTagWeight("SV2") ));
189 bTagName.push_back( DataType( "MV1" ));
190 bTagValue.push_back( DataType( (*itr)->getFlavourTagWeight("MV1") ));
191 bTagName.push_back( DataType( "MV2" ));
192 bTagValue.push_back( DataType( (*itr)->getFlavourTagWeight("MV2") ));
193
194 // basic jet quality
195 quality.push_back(DataType((*itr)->getMoment("LArQuality")));
196
197 isGood.push_back(DataType( 1 ));
198 isBad.push_back(DataType( 0 ));
199 isUgly.push_back(DataType( 0 ));
200 emfrac.push_back(DataType( 0.5 ));
201
202
203 jvf.push_back( DataType((*itr)->getMoment("JVF") ));
204
205 energy.push_back( DataType((*itr)->e()/CLHEP::GeV ) );
206 mass.push_back(DataType((*itr)->m()/CLHEP::GeV));
207 px.push_back( DataType((*itr)->px()/CLHEP::GeV ) );
208 py.push_back( DataType((*itr)->py()/CLHEP::GeV ) );
209 pz.push_back( DataType((*itr)->pz()/CLHEP::GeV ) );
210 }
211
212 // Start with mandatory entries
213 const auto n = phi.size();
214 DataMap["phi"] = std::move(phi);
215 DataMap["eta"] = std::move(eta);
216 DataMap["et"] = std::move(et);
217 DataMap["pt"] = std::move(pt);
218 DataMap["id"] = std::move(idVec);
219
220 DataMap["bTagName multiple=\"9\""] = std::move(bTagName); // assigned by hand !
221 DataMap["bTagValue multiple=\"9\""] = std::move(bTagValue);
222
223 // basic jet quality
224 DataMap["quality"] = std::move(quality);
225 DataMap["isGood"] = std::move(isGood);
226 DataMap["isBad"] = std::move(isBad);
227 DataMap["isUgly"] = std::move(isUgly);
228 DataMap["emfrac"] = std::move(emfrac);
229
230 DataMap["jvf"] = std::move(jvf);
231
232 if (m_writeJetQuality){ // extended jet quality
233 DataMap["qualityLAr"] = std::move(qualityLAr);
234 DataMap["qualityTile"] = std::move(qualityTile);
235 DataMap["time"] = std::move(time);
236 DataMap["timeClusters"] = std::move(timeClusters);
237 DataMap["n90cells"] = std::move(n90cells);
238 DataMap["n90const"] = std::move(n90const);
239 DataMap["hecf"] = std::move(hecf);
240 DataMap["tileGap3f"] = std::move(tileGap3f);
241 DataMap["fcorCell"] = std::move(fcorCell);
242 DataMap["fcorDotx"] = std::move(fcorDotx);
243 DataMap["fcorJet"] = std::move(fcorJet);
244 DataMap["fcorJetForCell"] = std::move(fcorJetForCell);
245 DataMap["nbadcells"] = std::move(nbadcells);
246 DataMap["fracSamplingMax"] = std::move(fracSamplingMax);
247 DataMap["sMax"] = std::move(sMax);
248 DataMap["OutOfTimeEfrac"] = std::move(OutOfTimeEfrac);
249 } // writeJetQuality
250
251 // further details
252 // four-vectors
253
254 DataMap["mass"] = std::move(mass);
255 DataMap["px"] = std::move(px);
256 DataMap["py"] = std::move(py);
257 DataMap["pz"] = std::move(pz);
258 DataMap["energy"] = std::move(energy);
259
260 if (msgLvl(MSG::DEBUG)) {
261 msg(MSG::DEBUG) << dataTypeName() << " (AOD, no cells), collection: " << dataTypeName();
262 msg(MSG::DEBUG) << " retrieved with " << n << " entries"<< endmsg;
263 }
264
265 //All collections retrieved okay
266 return DataMap;
267
268 } // retrieve
269
270 //--------------------------------------------------------------------------
271
272} // JiveXML namespace
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define endmsg
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::vector< std::string > m_otherKeys
virtual std::string dataTypeName() const
Return the name of the data type.
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
AODJetRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
const std::string m_typeName
The data type that is generated by this retriever.
const DataMap getData(const JetCollection *)
Rretrieve basic parameters, mainly four-vectors.
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
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
Extra patterns decribing particle interation process.