ATLAS Offline Software
Functions
chargeCalculator.h File Reference
#include <iostream>
#include <sstream>
#include <vector>
#include "CLHEP/Units/PhysicalConstants.h"
#include "GeneratorObjects/HepMcParticleLink.h"
#include "MuonSimData/MuonSimData.h"
#include "MuonSimData/MuonSimDataCollection.h"
#include "MuonSimEvent/MDTSimHitCollection.h"
#include "AtlasHepMC/GenParticle.h"
Include dependency graph for chargeCalculator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

double chargeCalculator (const EventContext &ctx, const MDTSimHit &hit, unsigned short eventId=0)
 

Function Documentation

◆ chargeCalculator()

double chargeCalculator ( const EventContext &  ctx,
const MDTSimHit hit,
unsigned short  eventId = 0 
)

Definition at line 30 of file chargeCalculator.h.

30  {
31  const HepMcParticleLink trkParticle = HepMcParticleLink::getRedirectedLink(hit.particleLink(), eventId, ctx); // This link should now correctly resolve to the TruthEvent McEventCollection in the main StoreGateSvc.
32  HepMC::ConstGenParticlePtr genParticle = trkParticle.cptr();
33  double qcharge = 1.;
34  if (genParticle) {
35  const int particleEncoding = genParticle->pdg_id();
36  if (((int)(std::abs(particleEncoding) / 10000000) == 1) && ((int)(std::abs(particleEncoding) / 100000) == 100)) { // TODO use a function from TruthUtils/AtlasPID.h
37  qcharge = ((std::abs(particleEncoding) / 100000.0) - 100.0) * 1000.0;
38  if (particleEncoding < 0.0) qcharge = -qcharge;
39  }
40  else if (((int)(std::abs(particleEncoding) / 10000000) == 2) && ((int)(std::abs(particleEncoding) / 100000) == 200)) { // TODO use a function from TruthUtils/AtlasPID.h
41  qcharge = (double)((std::abs(particleEncoding) / 1000) % 100) / (double)((std::abs(particleEncoding) / 10) % 100);
42  if (particleEncoding < 0.0) qcharge = -qcharge;
43  }
44  }
45  return qcharge;
46 }
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
MDTSimHit::particleLink
const HepMcParticleLink & particleLink() const
Definition: MDTSimHit.h:100