ATLAS Offline Software
JetCnv_p4.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // JetCnv_p4.cxx
8 // Implementation file for class JetCnv_p4
9 // Author: R.Seuster<seuster@cern.ch>
11 
12 // STL includes
13 
14 // JetEvent includes
15 #include "JetEvent/Jet.h"
18 
19 // DataModelAthenaPool includes
21 
22 // EventCommonTPCnv includes
24 
25 // JetEventTPCnv includes
28 
30 
31 #include <vector>
32 using std::vector;
33 
35 
36 // pre-allocate converters
37 static const P4ImplPxPyPzECnv_p1 momCnv;
38 static const NavigableCnv_t navCnv;
39 static const ParticleBaseCnv_p1 pbsCnv;
40 
41 
43  : m_badIndex (false),
44  m_nIndexTest (0)
45 {
46 }
47 
48 // Destructor
50 
52 // Const methods:
54 
55 void JetCnv_p4::persToTrans( const Jet_p4* pers,
56  Jet* trans,
57  MsgStream& msg ) const
58 {
59  msg << MSG::DEBUG << "Loading Jet from persistent state... e = "<< pers->m_momentum.m_ene
60  << endmsg;
61 
62  navCnv.persToTrans( &pers->m_nav,
63  &trans->navigableBase(), msg );
64  momCnv.persToTrans( &pers->m_momentum, &trans->momentumBase(), msg );
65  pbsCnv.persToTrans( &pers->m_partBase, &trans->particleBase(), msg);
66 
67  msg << MSG::DEBUG << " after momCnv e=" << trans->e() <<endmsg;
68 
69  trans->m_jetAuthor = pers->m_author;
70 
71  //
72  // create the store only if non-zero size (waste of space for constituents)
73  // Use swap to move the vector from one to the other - this way we
74  // don't waste time doing a copy.
75  //
76 
77 
79  std::vector<std::string> momentNames = keydesc->getKeys(JetKeyConstants::ShapeCat);
80  if( !(pers)->m_shapeStore.empty() ){
81  if( momentNames.size() < (pers)->m_shapeStore.size() ) {}
82  // if( ! pers->m_usedForTrigger ) { msg << MSG::WARNING << " JetCnv_p4 can't convert moments ! num max keys = "<< momentNames.size() << " persistant jet has n="<< (pers)->m_shapeStore.size() <<endmsg; }
83  else {
84  for(size_t i=0;i<(pers)->m_shapeStore.size();i++){
85  trans->setMoment(momentNames[i], (pers)->m_shapeStore[i], true);
86  }
87  }
88  }
89  const_cast<Jet_p4*>(pers)->m_shapeStore.clear();
90 
91  //
92  // The tag info store can contain nulls. The system
93  // doesn't deal well with that, so we need to filter them out
94  // first. We are dealing with pointers here, not actual objects.
95  //
96 
97  if (pers->m_tagJetInfo.empty()) {
98  if (trans->m_tagInfoStore != nullptr) {
99  trans->m_tagInfoStore->clear();
100  }
101  } else {
102  if (trans->m_tagInfoStore != nullptr) {
103  delete trans->m_tagInfoStore;
104  }
105 
106  vector<const JetTagInfoBase *> *ptags =
108  if (ptags != nullptr) {
109  vector<const JetTagInfoBase*> &tags (*ptags);
110  for (unsigned int i = 0; i < tags.size(); i++) {
111  trans->addInfo(tags[i]);
112  }
113  delete ptags;
114  }
115  }
116 
117  //
118  // The tag associations are similar to the tag info store
119  // above.
120  //
121 
122  if (pers->m_associations.empty()) {
123  if (trans->m_assocStore != nullptr) {
124  trans->m_assocStore->clear();
125  }
126  } else {
127  if (trans->m_assocStore != nullptr) {
128  delete trans->m_assocStore;
129  }
130  trans->m_assocStore = new vector<const JetAssociationBase*> ();
131  vector<const JetAssociationBase *> *pass =
133 
134  if (pass != nullptr) {
135  vector<const JetAssociationBase *> &ass (*pass);
136  vector<const JetAssociationBase *> &store (*trans->m_assocStore);
137  for (unsigned int i = 0; i < ass.size(); i++) {
138  // We want to read in the association objects and stick them
139  // into the store vector, at the indices that are stored in the
140  // objects.
141  //
142  // A catch, though, is that in 14.2.0, the indices are not filled
143  // in properly --- one gets garbage. In that case, one can use
144  // the setAssociation method to store the association. We don't
145  // want to do that, though, if the index information is available.
146  //
147  // Further complicating this, there seems to be no reliable way
148  // of distinguishing between these cases, at least not without
149  // trying to dig the version string out of metadata, which has
150  // its own set of issues.
151  //
152  // Instead, we'll do this. The first 10 times we go through
153  // here, we'll cross-check the saved index against what we
154  // compute via getIndex(). If there are any mismatches,
155  // we'll revert to using setAssociation from then on.
156  // Otherwise, we'll just use the index directly.
157  //
158  // Here, m_nIndexTest is the number of times we've done
159  // the cross-check. m_badIndex is set to true if we find
160  // a mismatch.
161 
162  // The stored index.
163  unsigned int index = ass[i]->keyIndex();
164 
165  // Cross-check against getIndex() for up to the first 10 times.
166  if (m_nIndexTest < 10 && !m_badIndex) {
167  ++m_nIndexTest;
168  if (JetKeyDescriptorInstance::instance()->getIndex ("JetAssociations",
169  ass[i]->name()) != index)
170  m_badIndex = true;
171  }
172 
173  // Store the association, either using setAssociation, or
174  // directly using the stored index.
175  if (m_badIndex)
176  trans->setAssociation (ass[i]);
177  else {
178  if (index >= store.size()) {
179  store.resize(index+1, nullptr);
180  }
181  store[index] = ass[i];
182  }
183 
184  ass[i] = nullptr; // Make sure nothing bad happens.
185  }
186  delete pass;
187  }
188  }
189 
190  // default signal state
192 
193  SignalStateCnv statecnv;
194 
195  trans->setRawE ( statecnv.ratio_from_char( pers->m_ratioE) * trans->e() );
196  trans->setRawPx ( statecnv.ratio_from_char(pers->m_ratioPx) * trans->px());
197  trans->setRawPy ( statecnv.ratio_from_char(pers->m_ratioPy) * trans->py());
198  trans->setRawPz ( statecnv.ratio_from_char(pers->m_ratioPz) * trans->pz());
199 
200 
201  msg << MSG::DEBUG << "Loaded Jet from persistent state [OK]"
202  << endmsg;
203 }
204 
205 void JetCnv_p4::transToPers( const Jet* trans,
206  Jet_p4* pers,
207  MsgStream& msg ) const
208 {
209  navCnv.transToPers( &trans->navigableBase(), &pers->m_nav, msg );
210  momCnv.transToPers( &trans->momentumBase(), &pers->m_momentum, msg );
211  pbsCnv.transToPers( &trans->particleBase(), &pers->m_partBase, msg);
212 
213 
214  pers->m_author = trans->m_jetAuthor;
215 
216  // if ( bool(trans->m_shapeStore) )
217  // pers->m_shapeStore = *(trans->m_shapeStore);
218  // else
219  // pers->m_shapeStore.clear();
220 
225 
226  if (trans->m_tagInfoStore != nullptr) {
227  vector<const JetTagInfoBase*> goodTagInfo;
228  const vector<const JetTagInfoBase*> &tagInfo(*(trans->m_tagInfoStore));
229  for (unsigned int i = 0; i < tagInfo.size(); i++) {
230  if (tagInfo[i] != nullptr) {
231  goodTagInfo.push_back(tagInfo[i]);
232  }
233  }
234  m_taginfoCnv.transToPers(&goodTagInfo, &(pers->m_tagJetInfo), msg);
235  }
236 
240 
241  if (trans->m_assocStore != nullptr) {
242  vector<const JetAssociationBase*> goodAssInfo;
243  const vector<const JetAssociationBase*> &assInfo(*trans->m_assocStore);
244 
245  for (unsigned int i = 0; i < assInfo.size(); i++) {
246  if (assInfo[i] != nullptr) {
247  goodAssInfo.push_back(assInfo[i]);
248  }
249  }
250 
251  m_tagAssCnv.transToPers(&goodAssInfo, &pers->m_associations, msg);
252  }
253 
254  SignalStateCnv statecnv;
255 
256  pers->m_ratioE = statecnv.char_from_ratio(trans->getRawE() / trans->e(P4SignalState::CALIBRATED) );
257  pers->m_ratioPx = statecnv.char_from_ratio(trans->getRawPx() / trans->px(P4SignalState::CALIBRATED));
258  pers->m_ratioPy = statecnv.char_from_ratio(trans->getRawPy() / trans->py(P4SignalState::CALIBRATED));
259  pers->m_ratioPz = statecnv.char_from_ratio(trans->getRawPz() / trans->pz(P4SignalState::CALIBRATED));
260 
261 
262 
263  msg << MSG::DEBUG << "Created persistent state of Jet [OK] e="<< pers->m_momentum.m_ene
264  << endmsg;
265 }
SignalStateCnv
Definition: JetSignalStateCnv.h:50
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
P4PxPyPzE_p1::m_ene
float m_ene
Definition: P4PxPyPzE_p1.h:42
ParticleSigStateImpl::py
virtual double py() const
y component of momentum
Definition: ParticleSigStateImpl.h:679
ParticleSigStateImpl::e
virtual double e() const
energy
Definition: ParticleSigStateImpl.h:751
Jet
Basic data class defines behavior for all Jet objects The Jet class is the principal data class for...
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:47
JetTagInfoBase.h
index
Definition: index.py:1
ParticleSigStateImpl::px
virtual double px() const
We re-define here extra class routines that will allow direct access to signal state kinematics witho...
Definition: ParticleSigStateImpl.h:671
JetKeyConstants::ShapeCat
static const key_t ShapeCat
Index category for jet shapes.
Definition: JetKeyDescriptor.h:88
JetCnv_p4::JetCnv_p4
JetCnv_p4()
Default constructor:
Definition: JetCnv_p4.cxx:42
JetAssociationBase.h
ParticleSigStateImpl::particleBase
const particle_type & particleBase() const
access to underlying base type (IParticle-like)
Definition: ParticleSigStateImpl.h:469
ParticleSigStateImpl::momentumBase
const momentum_type & momentumBase(state_t s) const
access to underlying base type (I4Momentum-like)
Definition: ParticleSigStateImpl.h:447
JetCnv_p4::m_badIndex
std::atomic< bool > m_badIndex
Definition: JetCnv_p4.h:83
JetCnv_p4::m_tagAssCnv
TagAssCollectionCnv m_tagAssCnv
Definition: JetCnv_p4.h:80
Jet_p4::m_ratioPz
char m_ratioPz
ratio for uncalibrated p_y
Definition: Jet_p4.h:95
Jet::getRawPz
double getRawPz() const
Definition: Jet.cxx:930
JetCnv_p4.h
NavigableCnv_p1::persToTrans
void persToTrans(const PersNavigable_t &pers, Navigable_t &trans, MsgStream &log) const
Jet_p4::m_nav
Navigable_p1< uint32_t, double > m_nav
the navigable part
Definition: Jet_p4.h:72
P4ImplPxPyPzECnv_p1.h
JetKeyDescriptorInstance::instance
static JetKeyDescriptorInstance * instance()
Definition: JetKeyDescriptor.h:123
Jet::setAssociation
void setAssociation(const T *pAssoc, bool useLink=false)
Set association object.
Jet_p4::m_partBase
ParticleBase_p1 m_partBase
The Particle base stuff – since Jet now inherrits from particle base.
Definition: Jet_p4.h:78
ParticleBaseCnv_p1::persToTrans
virtual void persToTrans(const ParticleBase_p1 *persObj, ParticleBase *transObj, MsgStream &msg) const final
Method creating the transient representation of ParticleBase from its persistent representation Parti...
Definition: ParticleBaseCnv_p1.cxx:49
JetCnv_p4::m_nIndexTest
std::atomic< int > m_nIndexTest
Definition: JetCnv_p4.h:84
JetCnv_p4::transToPers
virtual void transToPers(const Jet *transObj, Jet_p4 *persObj, MsgStream &msg) const override
Method creating the persistent representation Jet_p4 from its transient representation Jet.
Definition: JetCnv_p4.cxx:205
Jet::setRawPy
void setRawPy(double py)
Sets uncalibrated .
Definition: Jet.cxx:904
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
Jet_p4
Definition: Jet_p4.h:37
Jet::setRawE
void setRawE(double e)
Sets uncalibrated
Definition: Jet.cxx:900
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Jet_p4::m_ratioE
char m_ratioE
Definition: Jet_p4.h:92
ParticleBaseCnv_p1.h
Jet_p4::m_momentum
P4PxPyPzE_p1 m_momentum
the 4-mom part
Definition: Jet_p4.h:75
Jet_p4::m_associations
std::vector< TPObjRef > m_associations
JetAssociationBase objects.
Definition: Jet_p4.h:89
JetCnv_p4::persToTrans
virtual void persToTrans(const Jet_p4 *persObj, Jet *transObj, MsgStream &msg) const override
Method creating the transient representation of Jet from its persistent representation Jet_p4.
Definition: JetCnv_p4.cxx:55
Jet::getRawPy
double getRawPy() const
Definition: Jet.cxx:929
Jet::m_tagInfoStore
tagstore_t * m_tagInfoStore
Tag info store.
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:741
Jet::setRawPz
void setRawPz(double pz)
Sets uncalibrated .
Definition: Jet.cxx:906
ParticleSigStateImpl::navigableBase
const navigable_type & navigableBase() const
access to underlying base type (INavigable-like)
Definition: ParticleSigStateImpl.h:439
JetKeyDescriptorInstance::getKeys
const std::vector< key_t > & getKeys(const category_t &cat) const
Definition: JetKeyDescriptor.cxx:178
Jet_p4::m_author
unsigned int m_author
Definition: Jet_p4.h:80
Jet::m_jetAuthor
size_t m_jetAuthor
Jet author store.
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:725
P4ImplPxPyPzECnv_p1
Definition: P4ImplPxPyPzECnv_p1.h:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
JetSignalStateCnv.h
JetCnv_p4::m_taginfoCnv
TagInfoCollectionCnv m_taginfoCnv
Definition: JetCnv_p4.h:73
ParticleBaseCnv_p1
Definition: ParticleBaseCnv_p1.h:30
Jet_p4::m_ratioPy
char m_ratioPy
ratio for uncalibrated p_x
Definition: Jet_p4.h:94
NavigableCnv_p1::transToPers
void transToPers(const Navigable_t &trans, PersNavigable_t &pers, const SG::ThinningCache *cache, MsgStream &log) const
Jet::m_assocStore
assostore_t * m_assocStore
key descriptor for all jet stores
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:738
DeMoScan.index
string index
Definition: DeMoScan.py:364
Jet::getRawPx
double getRawPx() const
Definition: Jet.cxx:928
Jet_p4::m_tagJetInfo
std::vector< TPObjRef > m_tagJetInfo
JetTagInfoBase objects.
Definition: Jet_p4.h:86
Jet::addInfo
void addInfo(const TAGINFO *tag)
Add tag info object.
ParticleSigStateImpl::setSignalState
virtual bool setSignalState(state_t s)
set the current signal state
Definition: ParticleSigStateImpl.h:1157
SignalStateCnv::char_from_ratio
char char_from_ratio(double r) const
Definition: JetSignalStateCnv.h:73
DEBUG
#define DEBUG
Definition: page_access.h:11
SignalStateCnv::ratio_from_char
double ratio_from_char(char c) const
Definition: JetSignalStateCnv.h:85
Jet::setMoment
void setMoment(const mkey_t &shapeName, shape_t shape, bool addIfMissing=true) const
Alias for setShape.
P4SignalState::CALIBRATED
@ CALIBRATED
Definition: ISignalState.h:31
Jet::getRawE
double getRawE() const
Definition: Jet.cxx:927
ParticleBaseCnv_p1::transToPers
virtual void transToPers(const ParticleBase *transObj, ParticleBase_p1 *persObj, MsgStream &msg) const final
Method creating the persistent representation ParticleBase_p1 from its transient representation Parti...
Definition: ParticleBaseCnv_p1.cxx:80
TPPolyVectorCnvConst::transToPers
virtual void transToPers(const TRANS *transVect, PERS *persVect, MsgStream &log) const
Converts vector of TRANS::value_type objects to vector of PERS::value_type objects,...
Definition: TPConverter.h:1154
Jet.h
P4ImplPxPyPzECnv_p1::persToTrans
virtual void persToTrans(const P4ImplPxPyPzE_p1 *persObj, P4ImplPxPyPzE *transObj, MsgStream &msg) const override
Method creating the transient representation of P4ImplPxPyPzE from its persistent representation P4Im...
Definition: P4ImplPxPyPzECnv_p1.cxx:26
NavigableCnv_p1.h
This file contains the class definition for the NavigableCnv_p1 class. NOTE: it should be included fi...
ParticleSigStateImpl::pz
virtual double pz() const
z component of momentum
Definition: ParticleSigStateImpl.h:687
Jet_p4::m_ratioPx
char m_ratioPx
ratio for uncalibrated E
Definition: Jet_p4.h:93
JetKeyDescriptorInstance
Definition: JetKeyDescriptor.h:100
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Jet::setRawPx
void setRawPx(double px)
Sets uncalibrated .
Definition: Jet.cxx:902
TPConverterConstBase::createTransientConst
virtual TRANS * createTransientConst(const PERS *persObj, MsgStream &log) const
ass
make the histogram assessment part of the config
Definition: hcg.cxx:626
P4ImplPxPyPzECnv_p1::transToPers
virtual void transToPers(const P4ImplPxPyPzE *transObj, P4ImplPxPyPzE_p1 *persObj, MsgStream &msg) const override
Method creating the persistent representation P4ImplPxPyPzE_p1 from its transient representation P4Px...
Definition: P4ImplPxPyPzECnv_p1.cxx:38
NavigableCnv_p1
Definition: NavigableCnv_p1.h:29