ATLAS Offline Software
chargeCalculator.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MDT_DIGITIZATION_CHARGECALCULATOR_H
6 #define MDT_DIGITIZATION_CHARGECALCULATOR_H
7 /*-----------------------------------------------
8 
9 Created 20-8-2011 by Oleg.Bulekov@cern.ch
10 Function chargeCalculator returns the value of electric charge for Qball particle.
11 The information about charge coded in the pdgid of Qball particle is used.
12 It is supposed that the first digit of decimal number of charge corresponds
13 to the third digit of decimal number of the pdgid.
14 (e.g. Qball pdgid=10000200 corresponds to Q=2 )
15 
16 -----------------------------------------------*/
17 
18 #include <iostream>
19 #include <sstream>
20 #include <vector>
21 
22 #include "CLHEP/Units/PhysicalConstants.h"
27 // SB
28 #include "AtlasHepMC/GenParticle.h"
29 //
30 double chargeCalculator(const EventContext& ctx, const MDTSimHit& hit, unsigned short eventId = 0) {
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 }
47 
48 #endif
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MDTSimHit
Definition: MDTSimHit.h:21
chargeCalculator
double chargeCalculator(const EventContext &ctx, const MDTSimHit &hit, unsigned short eventId=0)
Definition: chargeCalculator.h:30
GenParticle.h
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
MDTSimHitCollection.h
MDTSimHit::particleLink
const HepMcParticleLink & particleLink() const
Definition: MDTSimHit.h:100
MuonSimDataCollection.h
MuonSimData.h