HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HGCSSSimHit.cc
Go to the documentation of this file.
1 #include <iomanip>
2 #include <cmath>
3 #include <stdlib.h>
4 
5 #include "HGCal/TBStandaloneSimulator/interface/HGCSSSimHit.hh"
6 #include "HGCal/TBStandaloneSimulator/interface/HGCSSGeometryConversion.hh"
7 #include "HGCal/TBStandaloneSimulator/interface/G4SiHit.hh"
8 #include "TH2Poly.h"
9 
10 
11 HGCSSSimHit::HGCSSSimHit(const G4SiHit & aSiHit,
12  const unsigned & asilayer,
13  TH2Poly* map,
14  const float )
15 {
16  energy_ = aSiHit.energy;
17  //energy weighted time
18  //PS: need to call calculateTime() after all hits
19  //have been added to have divided by totalE!!
20  time_ = aSiHit.time * aSiHit.energy;
21  zpos_ = aSiHit.hit_z;
22  setLayer(aSiHit.layer, asilayer);
23 
24  //coordinates in mm
25  double x = aSiHit.hit_x;
26  double y = aSiHit.hit_y;
27  //cellid encoding:
28  cellid_ = map->FindBin(x, y);
29 
30  //std::cout << "aSiHit.layer = " << aSiHit.layer
31  // << " asilayer = " << asilayer
32  // << std::endl;
33 
34  nGammas_ = 0;
35  nElectrons_ = 0;
36  nMuons_ = 0;
37  nNeutrons_ = 0;
38  nProtons_ = 0;
39  nHadrons_ = 0;
40  if(abs(aSiHit.pdgId) == 22) nGammas_++;
41  else if(abs(aSiHit.pdgId) == 11) nElectrons_++;
42  else if(abs(aSiHit.pdgId) == 13) nMuons_++;
43  else if(abs(aSiHit.pdgId) == 2112) nNeutrons_++;
44  else if(abs(aSiHit.pdgId) == 2212) nProtons_++;
45  else nHadrons_++;
46 
47  trackIDMainParent_ = aSiHit.parentId;
48  energyMainParent_ = aSiHit.energy;
49 
50 }
51 
52 void HGCSSSimHit::Add(const G4SiHit & aSiHit)
53 {
54 
55  time_ = time_ + aSiHit.time * aSiHit.energy;
56  //PS: need to call calculateTime() after all hits
57  //have been added to have divided by totalE!!
58 
59  if(abs(aSiHit.pdgId) == 22) nGammas_++;
60  else if(abs(aSiHit.pdgId) == 11) nElectrons_++;
61  else if(abs(aSiHit.pdgId) == 13) nMuons_++;
62  else if(abs(aSiHit.pdgId) == 2112) nNeutrons_++;
63  else if(abs(aSiHit.pdgId) == 2212) nProtons_++;
64  else nHadrons_++;
65 
66  energy_ += aSiHit.energy;
67  if (aSiHit.energy > energyMainParent_) {
68  trackIDMainParent_ = aSiHit.parentId;
69  energyMainParent_ = aSiHit.energy;
70  }
71 
72 }
73 
74 
75 std::pair<double, double> HGCSSSimHit::get_xy(const bool isScintillator,
76  const HGCSSGeometryConversion & aGeom) const
77 {
78  if (isScintillator) return aGeom.squareGeom.find(cellid_)->second;
79  else return aGeom.hexaGeom.find(cellid_)->second;
80 
81 }
82 
83 ROOT::Math::XYZPoint HGCSSSimHit::position(const bool isScintillator,
84  const HGCSSGeometryConversion & aGeom) const
85 {
86  std::pair<double, double> xy = get_xy(isScintillator, aGeom);
87  return ROOT::Math::XYZPoint(xy.first / 10., xy.second / 10., zpos_ / 10.);
88 }
89 
90 double HGCSSSimHit::theta(const bool isScintillator,
91  const HGCSSGeometryConversion & aGeom) const
92 {
93  return 2 * atan(exp(-1.*eta(isScintillator, aGeom)));
94 }
95 
96 double HGCSSSimHit::eta(const bool isScintillator,
97  const HGCSSGeometryConversion & aGeom) const
98 {
99  return position(isScintillator, aGeom).eta();
100 }
101 
102 double HGCSSSimHit::phi(const bool isScintillator,
103  const HGCSSGeometryConversion & aGeom) const
104 {
105  return position(isScintillator, aGeom).phi();
106 }
107 
108 void HGCSSSimHit::Print(std::ostream & aOs) const
109 {
110  aOs << "====================================" << std::endl
111  << " = Layer " << layer() << " siLayer " << silayer() << " cellid " << cellid_ << std::endl
112  << " = Energy " << energy_ << " time " << time_ << std::endl
113  << " = g " << nGammas_
114  << " e " << nElectrons_
115  << " mu " << nMuons_
116  << " neutron " << nNeutrons_
117  << " proton " << nProtons_
118  << " had " << nHadrons_
119  << std::endl
120  << " = main parent: trackID " << trackIDMainParent_ << " efrac " << mainParentEfrac()
121  << std::endl
122  << "====================================" << std::endl;
123 
124 }
125