ATLAS Offline Software
Loading...
Searching...
No Matches
JetCnv_p4.cxx
Go to the documentation of this file.
1
2
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>
32using std::vector;
33
35
36// pre-allocate converters
40
41
43 : m_badIndex (false),
44 m_nIndexTest (0)
45{
46}
47
48// Destructor
50
52// Const methods:
54
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 =
107 m_taginfoCnv.createTransientConst(&(pers->m_tagJetInfo), msg);
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 =
132 m_tagAssCnv.createTransientConst(&(pers->m_associations), msg);
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
205void 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}
#define endmsg
NavigableCnv_p1< Navigable< INavigable4MomentumCollection, double > > NavigableCnv_t
static const NavigableCnv_t navCnv
Definition JetCnv_p1.cxx:31
static const P4ImplPxPyPzECnv_p1 momCnv
Definition JetCnv_p1.cxx:30
static const ParticleBaseCnv_p1 pbsCnv
Definition JetCnv_p4.cxx:39
This file contains the class definition for the NavigableCnv_p1 class.
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
std::atomic< int > m_nIndexTest
Definition JetCnv_p4.h:84
JetCnv_p4()
Default constructor:
Definition JetCnv_p4.cxx:42
TagInfoCollectionCnv m_taginfoCnv
Definition JetCnv_p4.h:73
std::atomic< bool > m_badIndex
Definition JetCnv_p4.h:83
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.
TagAssCollectionCnv m_tagAssCnv
Definition JetCnv_p4.h:80
Theses classes implement a mapping between string and index used by jets.
const std::vector< key_t > & getKeys(const category_t &cat) const
static JetKeyDescriptorInstance * instance()
P4PxPyPzE_p1 m_momentum
the 4-mom part
Definition Jet_p4.h:75
Navigable_p1< uint32_t, double > m_nav
the navigable part
Definition Jet_p4.h:72
unsigned int m_author
Definition Jet_p4.h:80
char m_ratioPy
ratio for uncalibrated p_x
Definition Jet_p4.h:94
char m_ratioPx
ratio for uncalibrated E
Definition Jet_p4.h:93
char m_ratioE
Definition Jet_p4.h:92
ParticleBase_p1 m_partBase
The Particle base stuff – since Jet now inherrits from particle base.
Definition Jet_p4.h:78
char m_ratioPz
ratio for uncalibrated p_y
Definition Jet_p4.h:95
std::vector< TPObjRef > m_associations
JetAssociationBase objects.
Definition Jet_p4.h:89
std::vector< TPObjRef > m_tagJetInfo
JetTagInfoBase objects.
Definition Jet_p4.h:86
double getRawPz() const
Definition Jet.cxx:931
double getRawPy() const
Definition Jet.cxx:930
void addInfo(const TAGINFO *tag)
Add tag info object.
double getRawPx() const
Definition Jet.cxx:929
tagstore_t * m_tagInfoStore
Tag info store.
void setAssociation(const T *pAssoc, bool useLink=false)
Set association object.
size_t m_jetAuthor
Jet author store.
assostore_t * m_assocStore
key descriptor for all jet stores
void setMoment(const mkey_t &shapeName, shape_t shape, bool addIfMissing=true) const
Alias for setShape.
void setRawPx(double px)
Sets uncalibrated .
Definition Jet.cxx:903
double getRawE() const
Definition Jet.cxx:928
void setRawE(double e)
Sets uncalibrated .
Definition Jet.cxx:901
void setRawPy(double py)
Sets uncalibrated .
Definition Jet.cxx:905
void setRawPz(double pz)
Sets uncalibrated .
Definition Jet.cxx:907
virtual bool setSignalState(state_t s)
set the current signal state
const particle_type & particleBase() const
access to underlying base type (IParticle-like)
virtual double pz() const
z component of momentum
virtual double e() const
energy
virtual double py() const
y component of momentum
const navigable_type & navigableBase() const
access to underlying base type (INavigable-like)
const momentum_type & momentumBase(state_t s) const
access to underlying base type (I4Momentum-like)
virtual double px() const
We re-define here extra class routines that will allow direct access to signal state kinematics witho...
double ratio_from_char(char c) const
char char_from_ratio(double r) const
make the histogram assessment part of the config
Definition hcg.cxx:627
std::vector< std::string > tags
Definition hcg.cxx:105
Definition index.py:1
static const key_t ShapeCat
Index category for jet shapes.
MsgStream & msg
Definition testRead.cxx:32