EgammaTruthxAODHelpers.cxx 2.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/

#include "xAODEgamma/EgammaTruthxAODHelpers.h"
#include "xAODEgamma/Egamma.h"
#include "xAODEgamma/Photon.h"
#include "xAODEgamma/Electron.h"
#include "xAODTruth/TruthVertex.h"
#include "xAODTruth/TruthParticle.h"
11
#include "xAODTruth/xAODTruthHelpers.h"
12
13
14
15
16
17
#include "xAODTruth/TruthParticleContainer.h"
#include "xAODEgamma/ElectronContainer.h"
#include "xAODEgamma/PhotonContainer.h"

// ==================================================================

18
19
const xAOD::Electron* xAOD::EgammaHelpers::getRecoElectron(const xAOD::TruthParticle* particle){
  return getLink<xAOD::Electron>(particle, "recoElectronLink");
20
21
}

22
23
const xAOD::Photon* xAOD::EgammaHelpers::getRecoPhoton(const xAOD::TruthParticle* particle){
  return getLink<xAOD::Photon>(particle, "recoPhotonLink");
24
25
26
27
28
}
// ==================================================================

//Is the object matched to a true converted photon with R < maxRadius
bool xAOD::EgammaHelpers::isTrueConvertedPhoton(const xAOD::Photon* ph, float maxRadius /* = 800. */){
29
  const xAOD::TruthParticle *truthPh = xAOD::TruthHelpers::getTruthParticle(*ph);
30
31
32
33
34
35
  if (!truthPh) {return false;}
  // In older versions egammaTruthParticles did not have a decay vertex associated
  // so we look for the original truth particle
  if (truthPh->hasDecayVtx()){ 
    return isTrueConvertedPhoton(truthPh, maxRadius);
  }
36
  const xAOD::TruthParticle *orgTruthPh = xAOD::TruthHelpers::getTruthParticle(*truthPh);
37
38
39
40
41
42
43
44
45
46
47
  if (!orgTruthPh){ return false;}
  return xAOD::EgammaHelpers::isTrueConvertedPhoton(orgTruthPh, maxRadius);
}

//Is the true object a converted photon with R < maxRadius
bool xAOD::EgammaHelpers::isTrueConvertedPhoton(const xAOD::TruthParticle* truthPh, float maxRadius /*= 800.*/){
  return (truthPh->pdgId() == 22 && truthPh->hasDecayVtx() 
	  && truthPh->decayVtx()->perp() < maxRadius); 
}

// ==================================================================
48
49
50
const xAOD::TruthParticle* xAOD::EgammaHelpers::getBkgElectronMother(const xAOD::Electron* el){ 
  const xAOD::TruthParticle *truthel = xAOD::TruthHelpers::getTruthParticle(*el);
  return getBkgElectronMother(truthel);
51
}
52
53
54
55
56

const xAOD::TruthParticle* xAOD::EgammaHelpers::getBkgElectronMother(const xAOD::TruthParticle* truthel){

  //Truth must exist and be an electron
  if (!truthel || truthel->absPdgId()!=11){ 
57
58
    return 0;
  }
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  ///
  // The first parent has to exist
  if (!truthel->nParents()){
    return 0;
  }
  //And has to be a photon or electron
  const xAOD::TruthParticle* parent = truthel->parent();
  if(parent->absPdgId() !=22 && parent->absPdgId() !=11){
    return 0;
  }
  while (parent->nParents()){ //Loop over the generations 
    const xAOD::TruthParticle* tmp = parent->parent();
    //You want to see an electron or a photon 
    if(tmp->absPdgId() ==22 || tmp->absPdgId() ==11){
      parent=tmp;
74
    }
75
76
77
78
79
    else{ // if we do not see any more electron and photons we stop
      break ; 
    }
  }
  return parent;
80
}
81