ATLAS Offline Software
Loading...
Searching...
No Matches
JetCnv_p5.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5*/
6
7// Implementation file for class JetCnv_p5
8// Author: R.Seuster<seuster@cern.ch>
10
11// STL includes
12
13// DataModelAthenaPool includes
15
17
18// JetEvent includes
19#include "JetEvent/Jet.h"
23
24// JetEventTPCnv includes
27
28#include <vector>
29using std::vector;
30
31
32
34
35// pre-allocate converters
36// static const P4ImplPxPyPzECnv_p1 momCnv;
39
40void JetCnv_p5::persToTrans( const Jet_p5* pers,
41 Jet* trans,
42 MsgStream& msg ) const
43{
44 if(msg.level() == MSG::DEBUG ) msg << MSG::DEBUG << "Loading Jet from persistent state... " << endmsg;
45
46 navCnv.persToTrans( &pers->m_nav,
47 &trans->navigableBase(), msg );
48 // store as floats and use compressors for the signal state
49 // momCnv.persToTrans( &pers->m_momentum, &trans->momentumBase(), msg );
50 pbsCnv.persToTrans( &pers->m_partBase, &trans->particleBase(), msg);
51
52 trans->m_jetAuthor = pers->m_author;
53
54 if(pers->m_usedForTrigger) {
55 trans->m_RoIword = pers->m_recoStatus;
57 } else {
58 trans->m_RoIword = 0xFFFFFFFF;
60 }
61
62 trans->m_constituentsN = pers->m_constituentsN;
63 if (trans->m_constituentsN > 10000 ) {
64 // then we assume this is non physical. Most probably this means
65 // we are reading pre 15.1.0 files were m_constituentsN was not saved
66 // and that ROOT is assigning a default value. we reset it to 0
67 trans->m_constituentsN = 0;
68 }
69
70
71 // Make sure we get consistent results between debug/opt.
72#if __FLT_EVAL_METHOD__ == 2
73 long double px = pers->m_momentum.m_px;
74 long double py = pers->m_momentum.m_py;
75 long double pz = pers->m_momentum.m_pz;
76 long double m = pers->m_momentum.m_m;
77#else
78 double px = pers->m_momentum.m_px;
79 double py = pers->m_momentum.m_py;
80 double pz = pers->m_momentum.m_pz;
81 double m = pers->m_momentum.m_m;
82#endif
83 double e;
84 if(m<0) e = std::sqrt(px*px+py*py+pz*pz-m*m);
85 else e = std::sqrt(px*px+py*py+pz*pz+m*m);
86 trans->setPx(px);
87 trans->setPy(py);
88 trans->setPz(pz);
89 trans->setE(e);
90 pbsCnv.persToTrans( &pers->m_partBase, &trans->particleBase(), msg);
91
92 if(msg.level() == MSG::DEBUG ) {
93
94 msg << MSG::DEBUG << "Reading jets " << trans->jetAuthor() << " pers_e = "<<e
95 //<< " reco status " << std::hex << trans->m_recoStatus << std::dec
96 << " sig state = "<< trans->signalState() << endmsg;
97 }
98
99
100 // deal with signal state
101 if ( !pers->m_rawSignal.empty() )
102 {
103 SignalStateCnv statecnv;
104 JetConverterTypes::momentum mom = statecnv.decompress( pers->m_rawSignal, pers->m_momentum, msg );
105
106 //trans->setSignalState(P4SignalState::JETEMSCALE);
107 px = mom.m_px;
108 py = mom.m_py;
109 pz = mom.m_pz;
110 m = mom.m_m;
111 e=sqrt(px*px+py*py+pz*pz+m*m);
112 trans->setRawPx(px);
113 trans->setRawPy(py);
114 trans->setRawPz(pz);
115 trans->setRawE(e);
116
117
118 } else {
119 // no raw signal has been saved this means that JETEMSCALE == JETFINAL (truth jets for ex)
120 Jet::hlv_t vec4 = trans->hlv();
122 trans->set4Mom(vec4);
124 }
125
126 if(msg.level() == MSG::DEBUG ) {
127 msg << MSG::DEBUG << " --> signal state saved : ";
128 if ( !pers->m_rawSignal.empty() ){
129 msg << MSG::DEBUG << " raw_e =" << trans->getRawE() << " constscale_e=" << trans->getCScaleE() << " final_e="<<trans->e() << endmsg;
130 } else msg << MSG::DEBUG<< " None " << endmsg;
131 }
132
133
134 // deal with constituent state :
136 // we assume constituent scale is JETEMSCALE ...
137 // For now, this is correct in any known situation
138
139 trans->setCScaleE(trans->getRawE());
140 trans->setCScalePx(trans->getRawPx());
141 trans->setCScalePy(trans->getRawPy());
142 trans->setCScalePz(trans->getRawPz());
143
145 } else {
146
147 // Then we recompute JETCONSTITUENTSCALE :
148 Jet::hlv_t vec4 = trans->constituent_sum4Mom(); // WARNING constituent_sum4Mom(s) is tricky
149 trans->setCScaleE( vec4.e());
150 trans->setCScalePx(vec4.px());
151 trans->setCScalePy(vec4.py());
152 trans->setCScalePz(vec4.pz());
153
155 }
156 if(msg.level() == MSG::DEBUG ) msg << MSG::DEBUG << " --> raw constituent : "<< (trans->constituentSignalState() == P4SignalState::UNCALIBRATED)
157 << " new constscale_e ="<< trans->getCScaleE() << endmsg;
158
159
160
162 std::vector<std::string> momentNames = keydesc->getKeys(JetKeyConstants::ShapeCat);
163 if( !(pers)->m_shapeStore.empty() ){
164 if( momentNames.size() < (pers)->m_shapeStore.size() ) { if( ! pers->m_usedForTrigger ) {
165 msg << MSG::WARNING << " JetCnv_p5 can't convert moments ! num max keys = "<< momentNames.size() << " persistant jet has n= "<< (pers)->m_shapeStore.size() <<endmsg; }
166 }
167 else {
168 for(size_t i=0;i<(pers)->m_shapeStore.size();i++){
169 trans->setMoment(momentNames[i], (pers)->m_shapeStore[i], true);
170 }
171 }
172 }
173 // Translate recoStatus
174 double jetTime = (pers->m_recoStatus >> 16)*0.01;
175 double jetQuality = ((pers->m_recoStatus & 65535) >> 3)*(1./8191.);
176 // Store these in the moments?
177
178 trans->setMoment("Timing", jetTime);
179 trans->setMoment("LArQuality", jetQuality);
180
181 const_cast<Jet_p5*>(pers)->m_shapeStore.clear();
182
183 //
184 // The tag info store can contain nulls. The system
185 // doesn't deal well with that, so we need to filter them out
186 // first. We are dealing with pointers here, not actual objects.
187 //
188
189 if (pers->m_tagJetInfo.empty()) {
190 if (trans->m_tagInfoStore != nullptr) {
191 trans->m_tagInfoStore->clear();
192 }
193 } else {
194 if (trans->m_tagInfoStore != nullptr) {
195 delete trans->m_tagInfoStore;
196 }
197
198 vector<const JetTagInfoBase *> *ptags =
199 m_taginfoCnv.createTransientConst(&(pers->m_tagJetInfo), msg);
200 if (ptags != nullptr) {
201 vector<const JetTagInfoBase*> &tags (*ptags);
202 for (unsigned int i = 0; i < tags.size(); i++) {
203 trans->addInfo(tags[i]);
204 }
205 delete ptags;
206 }
207 }
208
209 //
210 // The tag associations are similar to the tag info store
211 // above.
212 //
213
214 if (pers->m_associations.empty()) {
215 if (trans->m_assocStore != nullptr) {
216 trans->m_assocStore->clear();
217 }
218 } else {
219 if (trans->m_assocStore != nullptr) {
220 delete trans->m_assocStore;
221 }
222 trans->m_assocStore = new vector<const JetAssociationBase*> ();
223 vector<const JetAssociationBase *> *pass =
224 m_tagAssCnv.createTransientConst(&(pers->m_associations), msg);
225
226 if (pass != nullptr) {
227 vector<const JetAssociationBase *> &ass (*pass);
228 vector<const JetAssociationBase *> &store (*trans->m_assocStore);
229 for (unsigned int i = 0; i < ass.size(); i++) {
230 unsigned int index = ass[i]->m_keyIndex;
231 if (index >= store.size()) {
232 store.resize(index+1, nullptr);
233 }
234 store[index] = ass[i];
235 ass[i] = nullptr; // Make sure nothing bad happens.
236 }
237 delete pass;
238 }
239 }
240
241 if(msg.level() == MSG::DEBUG ) msg << MSG::DEBUG << "Loaded Jet from persistent state [OK]. Final e=" << trans->e()
242 << endmsg;
243}
244
245
246
247
248// ------------------------------------------------------------------------------------------------
249// ------------------------------------------------------------------------------------------------
250
251void JetCnv_p5::transToPers( const Jet* trans,
252 Jet_p5* pers,
253 MsgStream& msg ) const
254{
255
256 // This part is only for trigger now
257 pers->m_usedForTrigger = true;
258
259
260
261 if( ! s_write0constit) {
262 navCnv.transToPers( &trans->navigableBase(), &pers->m_nav, msg );
263 }
264
265 // we store the momentum now as floats, plus use signal state compressors
266 // momCnv.transToPers( &trans->momentumBase(), &pers->m_momentum, msg );
267 pbsCnv.transToPers( &trans->particleBase(), &pers->m_partBase, msg);
268
269
270 //Jet::signalstate_t s = trans->signalState();
271 pers->m_rawSignal.clear();
272 pers->m_momentum = JetConverterTypes::momentum( trans->px(),
273 trans->py(),
274 trans->pz(),
275 trans->m() );
276
277 if(msg.level() == MSG::DEBUG ) {
278
279 msg << MSG::DEBUG << "Writing jets " << trans->jetAuthor() << " trans_e = "<< trans->e()
280 << " skipping constituent : "<< s_write0constit << endmsg;
281 }
282
283
284
285
286 pbsCnv.transToPers( &trans->particleBase(), &pers->m_partBase, msg);
287
288 pers->m_author = trans->m_jetAuthor;
289
290
291 // for trigger : recostatus == roiword
292 pers->m_recoStatus = trans->m_RoIword ;
293
294
295 pers->m_constituentsN = trans->m_constituentsN;
296
297
299 const JetMomentMap * map = trans->getMomentMap();
300 if(map) {
301 const std::vector<JetMoment::MomentData> *rec = map->getRecord(trans->m_jetId);
302 if( rec ) {
304 (pers)->m_shapeStore.resize(keys.size());
305 for(size_t i=0;i< rec->size();++i){
306 (pers)->m_shapeStore[i] = rec->operator[](i).moment();
307 }
308 }
309 }
310 // std::vector<std::string> momentkeys = trans->getShapeKeys();
311 // (pers)->m_shapeStore.resize(momentkeys.size());
312 // for(size_t i=0;i< momentkeys.size();++i){
313 // (pers)->m_shapeStore[i] = trans->getShape(momentkeys[i]);
314 // }
315
320
321 if (trans->m_tagInfoStore != nullptr) {
322 vector<const JetTagInfoBase*> goodTagInfo;
323 const vector<const JetTagInfoBase*> &tagInfo(*(trans->m_tagInfoStore));
324 for (unsigned int i = 0; i < tagInfo.size(); i++) {
325 if (tagInfo[i] != nullptr) {
326 goodTagInfo.push_back(tagInfo[i]);
327 }
328 }
329 m_taginfoCnv.transToPers(&goodTagInfo, &(pers->m_tagJetInfo), msg);
330 }
331
335
336 if (trans->m_assocStore != nullptr) {
337 vector<const JetAssociationBase*> goodAssInfo;
338 const vector<const JetAssociationBase*> &assInfo(*trans->m_assocStore);
339
340 for (unsigned int i = 0; i < assInfo.size(); i++) {
341 if (assInfo[i] != nullptr) {
342 goodAssInfo.push_back(assInfo[i]);
343 }
344 }
345
346 m_tagAssCnv.transToPers(&goodAssInfo, &pers->m_associations, msg);
347 }
348
349 if(msg.level() == MSG::DEBUG ){
350 msg << MSG::DEBUG << "Created persistent state of Jet [OK]" << endmsg;
351 }
352 }
#define endmsg
NavigableCnv_p1< Navigable< INavigable4MomentumCollection, double > > NavigableCnv_t
static const NavigableCnv_t navCnv
Definition JetCnv_p1.cxx:31
static const ParticleBaseCnv_p1 pbsCnv
Definition JetCnv_p4.cxx:39
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current JetMomentMap
This file contains the class definition for the NavigableCnv_p1 class.
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()
virtual const record_t * getRecord(size_t jetIndex) const
get the full record for a given jet
JetConverterTypes::signalState_pers_t m_rawSignal
Definition Jet_p5.h:76
std::vector< TPObjRef > m_associations
JetAssociationBase objects.
Definition Jet_p5.h:94
std::vector< TPObjRef > m_tagJetInfo
JetTagInfoBase objects.
Definition Jet_p5.h:91
unsigned int m_constituentsN
Definition Jet_p5.h:102
JetConverterTypes::momentum m_momentum
the 4-mom part
Definition Jet_p5.h:75
ParticleBase_p1 m_partBase
The Particle base stuff – since Jet now inherits from particle base.
Definition Jet_p5.h:79
unsigned int m_author
storing what jet algorithm the jet belongs to
Definition Jet_p5.h:82
unsigned int m_recoStatus
we store the recoStatus for jets here
Definition Jet_p5.h:98
Navigable_p1< uint32_t, double > m_nav
the navigable part
Definition Jet_p5.h:67
bool m_usedForTrigger
Definition Jet_p5.h:100
double getRawPz() const
Definition Jet.cxx:931
virtual void setE(double e)
Kinematics are now handled by the base class, except for the following.
signalstate_t constituentSignalState() const
Get the current Signal state of the jet constituents.
const shape_map_t * getMomentMap(bool addIfMissing) const
Definition Jet.cxx:1164
virtual void setPx(double Px)
size_t m_jetId
the identifier of this jet within its collection.
CLHEP::HepLorentzVector hlv_t
virtual void setPz(double pz)
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.
std::string jetAuthor() const
Author and calibration history are encoded in a simple way inside the jet object.
Definition Jet.cxx:1108
size_t m_jetAuthor
Jet author store.
assostore_t * m_assocStore
key descriptor for all jet stores
double getCScaleE() const
Definition Jet.cxx:933
hlv_t constituent_sum4Mom() const
Sum of weighted constituent four-momentums.
Definition Jet.cxx:702
void setCScaleE(double e)
Sets uncalibrated .
Definition Jet.cxx:910
void setCScalePy(double py)
Sets uncalibrated .
Definition Jet.cxx:914
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
void setCScalePx(double px)
Sets uncalibrated .
Definition Jet.cxx:912
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 setCScalePz(double pz)
Sets uncalibrated .
Definition Jet.cxx:916
void setRawPz(double pz)
Sets uncalibrated .
Definition Jet.cxx:907
virtual void setPy(double py)
signalstate_t m_constituentSigState
Constituent Signal State.
void transToPers(const Navigable_t &trans, PersNavigable_t &pers, const SG::ThinningCache *cache, MsgStream &log) const
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...
virtual bool setSignalState(state_t s)
set the current signal state
virtual double m() const
mass
const particle_type & particleBase() const
access to underlying base type (IParticle-like)
virtual state_t signalState() const
Retrieve current signal state.
virtual double pz() const
z component of momentum
virtual double e() const
energy
virtual double py() const
y component of momentum
virtual CLHEP::HepLorentzVector hlv() const
CLHEP HepLorentzVector.
const navigable_type & navigableBase() const
access to underlying base type (INavigable-like)
virtual void set4Mom(const I4Momentum &p4)
set 4Momentum (will throw exception if cannot be implemented)
virtual double px() const
We re-define here extra class routines that will allow direct access to signal state kinematics witho...
JetConverterTypes::momentum decompress(const JetConverterTypes::signalState_pers_t &ps, JetConverterTypes::momentum momCal, MsgStream &msg) 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