ATLAS Offline Software
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 
12 namespace JiveXML {
13 
20  AODJetRetriever::AODJetRetriever(const std::string& type,const std::string& name,const IInterface* 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{
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;
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  // isGood.push_back(DataType(JetCaloQualityUtils::isGood(*itr)));
203  // isBad.push_back(DataType(JetCaloQualityUtils::isBad(*itr)));
204  // isUgly.push_back(DataType(JetCaloQualityUtils::isUgly(*itr)));
205  // emfrac.push_back(DataType(JetCaloHelper::jetEMFraction(*itr)));
206 
207  /* not working anymore with xAOD - temporarily removed
208  if (m_writeJetQuality){ // extended jet quality
209  qualityLAr.push_back(DataType(JetCaloQualityUtils::jetQualityLAr(*itr))); // this caused problems in AOD !
210  qualityTile.push_back(DataType(JetCaloQualityUtils::jetQualityTile(*itr))); // this caused problems in AOD !
211  time.push_back(DataType(JetCaloQualityUtils::jetTime(*itr))); //(*itr)->getJetTime() without sign
212  timeClusters.push_back(DataType(JetCaloQualityUtils::jetTimeClusters(*itr)));
213  n90cells.push_back(DataType(JetCaloQualityUtils::nLeadingCells(*itr,0.9))); //(*itr)->getMoment("n90")
214  n90const.push_back(DataType(JetCaloQualityUtils::nLeadingConstituents(*itr,0.9)));
215  hecf.push_back(DataType(JetCaloQualityUtils::hecF(*itr)));
216  tileGap3f.push_back(DataType(JetCaloQualityUtils::tileGap3F(*itr)));
217  fcorCell.push_back(DataType((*itr)->getMoment("BCH_CORR_CELL")));
218  fcorDotx.push_back(DataType((*itr)->getMoment("BCH_CORR_DOTX")));
219  fcorJet.push_back(DataType((*itr)->getMoment("BCH_CORR_JET")));
220  fcorJetForCell.push_back(DataType((*itr)->getMoment("BCH_CORR_JET_FORCELL")));
221  nbadcells.push_back(DataType((*itr)->getMoment("N_BAD_CELLS_CORR")));
222  int SamplingMax = CaloSampling::Unknown;
223  fracSamplingMax.push_back(DataType(JetCaloQualityUtils::fracSamplingMax(*itr, SamplingMax)));
224  sMax.push_back(DataType(SamplingMax));
225  OutOfTimeEfrac.push_back(DataType(JetCaloQualityUtils::jetOutOfTimeEnergyFraction(*itr,25)));
226  } // writeJetQuality
227  */
228 
229 /* need to be added to AtlantisJava/event.dtd !
230  charge.push_back( DataType((*itr)->charge()));
231  flavourTagWeight.push_back( DataType((*itr)->getFlavourTagWeight()));
232 */
233  jvf.push_back( DataType((*itr)->getMoment("JVF") ));
234 
235  energy.push_back( DataType((*itr)->e()/CLHEP::GeV ) );
236  mass.push_back(DataType((*itr)->m()/CLHEP::GeV));
237  px.push_back( DataType((*itr)->px()/CLHEP::GeV ) );
238  py.push_back( DataType((*itr)->py()/CLHEP::GeV ) );
239  pz.push_back( DataType((*itr)->pz()/CLHEP::GeV ) );
240  }
241 
242  // Start with mandatory entries
243  const auto n = phi.size();
244  DataMap["phi"] = std::move(phi);
245  DataMap["eta"] = std::move(eta);
246  DataMap["et"] = std::move(et);
247  DataMap["pt"] = std::move(pt);
248  DataMap["id"] = std::move(idVec);
249 
250  DataMap["bTagName multiple=\"9\""] = std::move(bTagName); // assigned by hand !
251  DataMap["bTagValue multiple=\"9\""] = std::move(bTagValue);
252 
253  // basic jet quality
254  DataMap["quality"] = std::move(quality);
255  DataMap["isGood"] = std::move(isGood);
256  DataMap["isBad"] = std::move(isBad);
257  DataMap["isUgly"] = std::move(isUgly);
258  DataMap["emfrac"] = std::move(emfrac);
259 
260  DataMap["jvf"] = std::move(jvf);
261 
262  if (m_writeJetQuality){ // extended jet quality
263  DataMap["qualityLAr"] = std::move(qualityLAr);
264  DataMap["qualityTile"] = std::move(qualityTile);
265  DataMap["time"] = std::move(time);
266  DataMap["timeClusters"] = std::move(timeClusters);
267  DataMap["n90cells"] = std::move(n90cells);
268  DataMap["n90const"] = std::move(n90const);
269  DataMap["hecf"] = std::move(hecf);
270  DataMap["tileGap3f"] = std::move(tileGap3f);
271  DataMap["fcorCell"] = std::move(fcorCell);
272  DataMap["fcorDotx"] = std::move(fcorDotx);
273  DataMap["fcorJet"] = std::move(fcorJet);
274  DataMap["fcorJetForCell"] = std::move(fcorJetForCell);
275  DataMap["nbadcells"] = std::move(nbadcells);
276  DataMap["fracSamplingMax"] = std::move(fracSamplingMax);
277  DataMap["sMax"] = std::move(sMax);
278  DataMap["OutOfTimeEfrac"] = std::move(OutOfTimeEfrac);
279  } // writeJetQuality
280 
281  // further details
282  // four-vectors
283 /* need to be added to AtlantisJava/event.dtd !
284  DataMap["charge"] = charge;
285  DataMap["flavourTagWeight"] = flavourTagWeight;
286 */
287  DataMap["mass"] = std::move(mass);
288  DataMap["px"] = std::move(px);
289  DataMap["py"] = std::move(py);
290  DataMap["pz"] = std::move(pz);
291  DataMap["energy"] = std::move(energy);
292 
293  if (msgLvl(MSG::DEBUG)) {
294  msg(MSG::DEBUG) << dataTypeName() << " (AOD, no cells), collection: " << dataTypeName();
295  msg(MSG::DEBUG) << " retrieved with " << n << " entries"<< endmsg;
296  }
297 
298  //All collections retrieved okay
299  return DataMap;
300 
301  } // retrieve
302 
303  //--------------------------------------------------------------------------
304 
305 } // JiveXML namespace
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
et
Extra patterns decribing particle interation process.
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
test_pyathena.px
px
Definition: test_pyathena.py:18
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
AODJetRetriever.h
JiveXML::AODJetRetriever::m_sgKeyFavourite
std::string m_sgKeyFavourite
Definition: AODJetRetriever.h:52
xAOD::et
et
Definition: TrigEMCluster_v1.cxx:25
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
JiveXML::AODJetRetriever::AODJetRetriever
AODJetRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: AODJetRetriever.cxx:20
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
JiveXML::AODJetRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: AODJetRetriever.cxx:39
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
test_pyathena.pt
pt
Definition: test_pyathena.py:11
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
JiveXML::AODJetRetriever::getData
const DataMap getData(const JetCollection *)
Rretrieve basic parameters, mainly four-vectors.
Definition: AODJetRetriever.cxx:114
JiveXML::AODJetRetriever::m_doWriteHLT
bool m_doWriteHLT
Definition: AODJetRetriever.h:54
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
JetCollection.h
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
test_pyathena.parent
parent
Definition: test_pyathena.py:15
JiveXML::AODJetRetriever::m_otherKeys
std::vector< std::string > m_otherKeys
Definition: AODJetRetriever.h:53
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:21
Amg::py
@ py
Definition: GeoPrimitives.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
JiveXML::AODJetRetriever::m_writeJetQuality
bool m_writeJetQuality
Definition: AODJetRetriever.h:55
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
JetCollection
Container for Jets
Definition: JetCollection.h:30
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
JiveXML::AODJetRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: AODJetRetriever.h:46
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
AthAlgTool
Definition: AthAlgTool.h:26
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
SG::ConstIterator
Definition: SGIterator.h:163