ATLAS Offline Software
ParticleShallowClone.h
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // ParticleShallowClone.h
8 // @author: Karsten Koeneke - February 2013
10 #ifndef PARTICLEEVENT_PARTICLESHALLOWCLONE_H
11 #define PARTICLEEVENT_PARTICLESHALLOWCLONE_H 1
12 
13 #include "AthLinks/ElementLink.h"
14 #include "EventKernel/IParticle.h"
16 #include "FourMom/P4PxPyPzE.h"
17 
18 // VxVertex includes
19 #include "VxVertex/VxContainer.h"
20 #include "VxVertex/VxCandidate.h"
21 #include "VxVertex/RecVertex.h"
22 
23 
24 /* OPEN QUESTIONS:
25  I could template this class with two template arguemnts:
26  One being the type of 4Momentum (P4PxPyPzE, P4PtEtaPhiM,...)
27  and the other being the type of the master particle (egamma, Muon, TauJet,...)
28  I could then implement the specific methods for each particle as well,
29  i.e., forward them to the original master. And the underlying 4Momentum
30  implementation would be identical to the one of the master.
31  However, I could still not dynamic_cast to the type of the master particle
32  nor could I use the containers of this and the master interchangably.
33  So it may not be worth the effort? Too little benefit?
34 */
35 
36 
37 
38 // Typedefs
43 
45 
46 namespace Analysis
47 {
48 
50  virtual public IParticle
51  {
52 
53  // Public typedefs
54  public:
57 
58 
59  public:
60 
63  P4Momentum_t ( ),
64  m_masterLink ( ),
65  m_originLink ( ),
66  m_hasCharge ( false ),
67  m_charge ( 0.0 )
68  {
69  }
70 
71 
75  explicit ParticleShallowClone( const MasterLink_t& theMasterLink ) :
76  P4Momentum_t ( *theMasterLink ),
77  m_originLink ( (*theMasterLink)->originLink() ),
78  m_hasCharge ( (*theMasterLink)->hasCharge() ),
79  m_charge ( (*theMasterLink)->charge() )
80  {
81  // Assign the ElementLink to the original master particle,
82  // including searching until we don't have a ParticleShallowClone any more
83  const ParticleShallowClone* pscPtr = dynamic_cast<const ParticleShallowClone*>(*theMasterLink);
84  m_masterLink = pscPtr ? pscPtr->getMasterLink() : theMasterLink;
85  }
86 
87 
92  ParticleShallowClone( const MasterLink_t& theMasterLink,
93  const I4Momentum* the4Mom,
94  const ChargeType theCharge = std::numeric_limits<ChargeType>::quiet_NaN(),
95  const ElementLink<VxContainer>* theOriginLink = 0 ) :
96  P4Momentum_t ( the4Mom )
97  {
98  // Assign the ElementLink to the original master particle,
99  // including searching until we don't have a ParticleShallowClone any more
100  const ParticleShallowClone* pscPtr = dynamic_cast<const ParticleShallowClone*>(*theMasterLink);
101  m_masterLink = pscPtr ? pscPtr->getMasterLink() : theMasterLink;
102 
103  // Check if a charge was given. Is so, use it. If not, get the one from the orignal master particle
104  if ( std::isnan(theCharge) )
105  {
106  m_hasCharge = (*theMasterLink)->hasCharge();
107  m_charge = (*theMasterLink)->charge();
108  }
109  else
110  {
111  m_hasCharge = true;
112  m_charge = theCharge;
113  }
114 
115  // Check if an origin was given. Is so, use it. If not, get the one from the orignal master particle
116  if ( theOriginLink )
117  {
118  m_originLink = *theOriginLink;
119  }
120  else
121  {
122  m_originLink = (*theMasterLink)->originLink();
123  }
124  }
125 
126 
127 
129  // Use default.
130 
131 
132 
134  //~ParticleShallowClone( );
135 
136 
137 
139  public:
140 
142  const MasterLink_t& getMasterLink() const;
143 
145  const Master_t* getMasterPtr() const;
146 
147 
148 
149 
150  // All public methods that come from IAthenaBarCode
151  // QUESTION: Should the ParticleShallowClone own a new barcode? For now, no.
152  public:
153 
155  virtual AthenaBarCode_t getAthenaBarCode() const;
156 
158  virtual bool hasSameAthenaBarCode(const IAthenaBarCode &/*obj*/) const;
159 
161  virtual bool hasSameAthenaBarCodeExceptVersion(const IAthenaBarCode &/*obj*/) const;
162 
164  virtual AthenaBarCodeVersion_t getVersion() const;
165 
166  /* These setters are not implemented! Users should get the master particle and modify its barcode directly...
168  virtual void setAthenaBarCode(AthenaBarCode_t id);
169 
171  virtual void newVersion();
172 
174  virtual void setVersion(AthenaBarCodeVersion_t newversion);
175  */
176 
177 
178 
179  // All public methods that come from INavigable
180  public:
181 
183  virtual void fillToken(INavigationToken&) const;
184 
186  virtual void fillToken(INavigationToken&, const std::any&) const;
187 
188 
189 
190  // All public methods that come from IParticle
191  public:
192 
197  virtual ParticleDataType::DataType dataType() const;
198 
201  virtual const Trk::RecVertex* origin() const;
202 
205  virtual const ElementLink<VxContainer>& originLink() const ; // FIXME: WHY NOT RETURN A REFERENCE???
206 
209  virtual bool hasCharge() const;
210 
215  virtual ChargeType charge() const;
216 
219  virtual bool hasPdgId() const;
220 
223  virtual int pdgId() const;
224 
225 
226  // Set functions (for IParticle)
227 
229  virtual void set_charge( ChargeType theCharge );
230 
232  virtual void set_origin( const VxContainer* theContainer, int index );
233 
235  virtual void set_origin( const VxContainer* theContainer,
236  const Trk::VxCandidate * vertex );
237 
238  /* These setters are not implemented!
239  Users should get the master particle and modify its PDG_ID or ParticleDataType directly... */
240  //virtual void set_dataType( ParticleDataType::DataType x );
241  //virtual void set_pdgId( int x );
242 
243 
244 
246  const momentum_type& momentumBase() const;
248 
249 
250 
251  public:
252  /* Need to implement this as the union of all others
253  virtual std::ostream& dump(std::ostream&) const; // FIXME: Need to actually re-implement it here for full correctness!
254  */
255 
256 
257 
258  // All private data memebers that this class needs on top of the ones inherited
259  private:
260  friend class ::ParticleShallowCloneCnv_p1;
261 
264 
267 
270 
275 
276 
277  };
278 
279 } // End of namespace Analysis
280 
281 
283 // Inline methods:
285 inline
287 {
288  return m_masterLink;
289 }
290 
291 
292 inline
294 {
295  if ( m_masterLink.isValid() )
296  {
297  return *m_masterLink;
298  }
299  else
300  {
301  //ATH_MSG_ERROR ( "You tried to implicitly cast from an ParticleShallowClone to a INavigable4Momentum, but the pointed-at INavigable4Momentum doesn't exist! Returning NULL..." );
302  return 0;
303  }
304 }
305 
306 
307 // Implementations for methods comming from IAthenaBarCode
308 inline
310 {
311  return (*m_masterLink)->getAthenaBarCode();
312 }
313 
314 inline
316 {
317  return (*m_masterLink)->hasSameAthenaBarCode(obj);
318 }
319 
320 inline
322 {
323  return (*m_masterLink)->hasSameAthenaBarCodeExceptVersion(obj);
324 }
325 
326 inline
328 {
329  return (*m_masterLink)->getVersion();
330 }
331 
332 
333 // Implementations for methods comming from INavigable
334 inline
336 {
337  (*m_masterLink)->fillToken(theToken);
338  return;
339 }
340 
341 inline
342 void Analysis::ParticleShallowClone::fillToken(INavigationToken& theToken, const std::any& theOther) const
343 {
344  (*m_masterLink)->fillToken(theToken, theOther);
345  return;
346 }
347 
348 
349 // Implementations for methods comming from IParticle
350 inline
352 {
353  return (*m_masterLink)->dataType();
354 }
355 
356 inline
358 {
359  return (!m_originLink.isValid())
360  ? 0
361  : &(**m_originLink).recVertex();
362 }
363 
364 inline
366 {
367  return m_originLink;
368 }
369 
370 inline
372 {
373  return m_hasCharge;
374 }
375 
376 inline
378 {
379  return m_charge;
380 }
381 
382 inline
384 {
385  return (*m_masterLink)->hasPdgId();
386 }
387 
388 inline
390 {
391  return (*m_masterLink)->pdgId();
392 }
393 
394 inline
396 {
397  m_charge = theCharge;
398  m_hasCharge = true;
399  return;
400 }
401 
402 inline
404 {
405  m_originLink = ElementLink< VxContainer >(*theContainer, index);
406  return;
407 }
408 
409 inline
411  const Trk::VxCandidate * vertex )
412 {
413  m_originLink = ElementLink< VxContainer >
414  ( vertex,*theContainer );
415  return;
416 }
417 
418 inline
420 {
421  return *this;
422 }
423 
424 inline
426 {
427  return *this;
428 }
429 
430 
431 
432 /*
433 inline
434 std::ostream& Analysis::ParticleShallowClone::dump(std::ostream& val) const
435 {
436  return (*m_masterLink)->dump(val);
437 }
438 */
439 
440 #endif // PARTICLEEVENT_PARTICLESHALLOWCLONE_H
RecVertex.h
Analysis::ParticleShallowClone::getAthenaBarCode
virtual AthenaBarCode_t getAthenaBarCode() const
Public getter.
Definition: ParticleShallowClone.h:309
Analysis::ParticleShallowClone::ParticleShallowClone
ParticleShallowClone(const MasterLink_t &theMasterLink)
Standard constructor with an ElementLink to the original particle.
Definition: ParticleShallowClone.h:75
I4Momentum
Definition: I4Momentum.h:31
Analysis::ParticleShallowClone::origin
virtual const Trk::RecVertex * origin() const
Return a RecVertex corresponding to particle's Origin (used directly from this shallow clone particle...
Definition: ParticleShallowClone.h:357
Analysis::ParticleShallowClone::getMasterPtr
const Master_t * getMasterPtr() const
Get a const pointer to the original "master" particle.
Definition: ParticleShallowClone.h:293
Analysis::ParticleShallowClone::ParticleShallowClone
ParticleShallowClone(const MasterLink_t &theMasterLink, const I4Momentum *the4Mom, const ChargeType theCharge=std::numeric_limits< ChargeType >::quiet_NaN(), const ElementLink< VxContainer > *theOriginLink=0)
Standard constructor with an ElementLink to the original particle and all other parameters explicitly...
Definition: ParticleShallowClone.h:92
Analysis::ParticleShallowClone::m_hasCharge
bool m_hasCharge
Switch to tell if this particle has a charge.
Definition: ParticleShallowClone.h:269
Analysis::ParticleShallowClone::hasPdgId
virtual bool hasPdgId() const
method to check if particle id information is available (forwareded to the orignal "master" particle)
Definition: ParticleShallowClone.h:383
index
Definition: index.py:1
P4Momentum_t
P4PxPyPzE P4Momentum_t
Definition: ParticleShallowClone.h:42
Analysis::ParticleShallowClone::m_charge
ChargeType m_charge
Value of the charge of the particle (this has real meaning, only if hasCharge() returns true)
Definition: ParticleShallowClone.h:274
IParticle.h
Master_t
IParticle Master_t
Definition: ParticleShallowClone.h:39
ParticleDataType::DataType
DataType
Definition: Event/EventKernel/EventKernel/IParticle.h:36
Analysis::ParticleShallowClone::hasSameAthenaBarCode
virtual bool hasSameAthenaBarCode(const IAthenaBarCode &) const
Comparing & Versioning Control.
Definition: ParticleShallowClone.h:315
Analysis::ParticleShallowClone::m_originLink
ElementLink< VxContainer > m_originLink
Persistent pointer (ElementLink) to the origin of this particle.
Definition: ParticleShallowClone.h:266
Trk::RecVertex
Trk::RecVertex inherits from Trk::Vertex.
Definition: RecVertex.h:44
MasterLink_t
ElementLink< MasterContainer_t > MasterLink_t
Definition: ParticleShallowClone.h:41
AthenaBarCode_t
uint64_t AthenaBarCode_t
barcode for all INav4Mom classes
Definition: AthenaKernel/AthenaKernel/IAthenaBarCode.h:44
Analysis::ParticleShallowClone::hasCharge
virtual bool hasCharge() const
method to check if charge information is available (used directly from this shallow clone particle)
Definition: ParticleShallowClone.h:371
Analysis::ParticleShallowClone::momentum_type
P4PxPyPzE momentum_type
publish the type of the base class (ie: 'traits-itize' it)
Definition: ParticleShallowClone.h:56
Analysis::ParticleShallowClone::fillToken
virtual void fillToken(INavigationToken &) const
Implement method from INavigable (forwareded to the orignal "master" particle)
Definition: ParticleShallowClone.h:335
INavigationToken
Definition: INavigationToken.h:24
VxContainer.h
Analysis::ParticleShallowClone::momentumBase
const momentum_type & momentumBase() const
access to underlying base type (I4Momentum-like)
Definition: ParticleShallowClone.h:419
VxContainer
Definition: VxContainer.h:28
Analysis::ParticleShallowClone::set_origin
virtual void set_origin(const VxContainer *theContainer, int index)
Set method to set the charge of this shallow clone particle (the original "master" particle remains u...
Definition: ParticleShallowClone.h:403
Analysis::ParticleShallowClone
Definition: ParticleShallowClone.h:51
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
IAthenaBarCode
Definition: AthenaKernel/AthenaKernel/IAthenaBarCode.h:48
Analysis::ParticleShallowClone::hasSameAthenaBarCodeExceptVersion
virtual bool hasSameAthenaBarCodeExceptVersion(const IAthenaBarCode &) const
Comparing & Versioning Control.
Definition: ParticleShallowClone.h:321
Analysis::ParticleShallowClone::pdgId
virtual int pdgId() const
Return particle id (forwareded to the orignal "master" particle)
Definition: ParticleShallowClone.h:389
VxCandidate.h
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
Analysis::ParticleShallowClone::charge
virtual ChargeType charge() const
returns charge as a typedef ChargeType currently Charge Type is a double for jets this may be changed...
Definition: ParticleShallowClone.h:377
ChargeType
double ChargeType
typedef ChargeType used to anticipate changes here
Definition: Event/EventKernel/EventKernel/IParticle.h:40
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
Analysis::ParticleShallowClone::ParticleShallowClone
ParticleShallowClone()
The default constructor.
Definition: ParticleShallowClone.h:62
MasterContainer_t
IParticleContainer MasterContainer_t
Definition: ParticleShallowClone.h:40
P4PxPyPzE
Definition: P4PxPyPzE.h:29
Trk::VxCandidate
Definition: VxCandidate.h:27
Analysis::ParticleShallowClone::set_charge
virtual void set_charge(ChargeType theCharge)
Set method to set the charge of this shallow clone particle (the original "master" particle remains u...
Definition: ParticleShallowClone.h:395
Analysis::ParticleShallowClone::dataType
virtual ParticleDataType::DataType dataType() const
Return enum indicating real data, fast, or full simulation Return Type has a DataType enum with the f...
Definition: ParticleShallowClone.h:351
IParticleContainer.h
AthenaBarCodeVersion_t
AthenaBarCode_t AthenaBarCodeVersion_t
Definition: AthenaKernel/AthenaKernel/IAthenaBarCode.h:46
Analysis::ParticleShallowClone::getVersion
virtual AthenaBarCodeVersion_t getVersion() const
Comparing & Versioning Control.
Definition: ParticleShallowClone.h:327
Analysis::ParticleShallowClone::originLink
virtual const ElementLink< VxContainer > & originLink() const
Return an ElementLink corresponding to particle's Origin (used directly from this shallow clone parti...
Definition: ParticleShallowClone.h:365
P4PxPyPzE.h
Analysis::ParticleShallowClone::m_masterLink
MasterLink_t m_masterLink
The persistent pointer (ElementLink) to the original "master" particle.
Definition: ParticleShallowClone.h:263
python.PyAthena.obj
obj
Definition: PyAthena.py:135
IParticle
Definition: Event/EventKernel/EventKernel/IParticle.h:43
Analysis::ParticleShallowClone::getMasterLink
const MasterLink_t & getMasterLink() const
Copy constructor.
Definition: ParticleShallowClone.h:286
ParticleShallowCloneCnv_p1
Definition: ParticleShallowCloneCnv_p1.h:30