CMS 3D CMS Logo

HcalHitMaker.cc
Go to the documentation of this file.
5 #include <algorithm>
6 #include <cmath>
7 
9 
11  : CaloHitMaker(grid.getCalorimeter(),
12  DetId::Hcal,
13  HcalHitMaker::getSubHcalDet(grid.getFSimTrack()),
14  grid.getFSimTrack()->onHcal() ? grid.getFSimTrack()->onHcal() : grid.getFSimTrack()->onVFcal() + 1,
15  shower),
16  myGrid(grid),
17  myTrack((grid.getFSimTrack())) {
18  // normalize the direction
22  mapCalculated_ = false;
23  //std::cout << " Famos HCAL " << grid.getTrack()->onHcal() << " " << grid.getTrack()->onVFcal() << " " << showerType << std::endl;
24  if (EMSHOWER && (abs(grid.getFSimTrack()->type()) != 11 && grid.getFSimTrack()->type() != 22)) {
25  std::cout << " FamosHcalHitMaker : Strange. The following shower has EM type" << std::endl
26  << *grid.getFSimTrack() << std::endl;
27  }
28 }
29 
30 bool HcalHitMaker::addHit(double r, double phi, unsigned layer) {
31  // std::cout << " FamosHcalHitMaker::addHit - radiusFactor = " << radiusFactor
32  // << std::endl;
33 
35 
36  // Watch out !!!! (Point) is a real point in the MathCore terminology (not a redefined a XYZPoint which
37  // is actually a XYZVector in the MatchCore terminology). Therefore, the Transform3D is correctly applied
39  return addHit(point, layer);
40 }
41 
42 bool HcalHitMaker::addHit(const XYZPoint& point, unsigned layer) {
43  // Temporary nasty hacks to avoid misbehaviour of not-intended-for-that
44  // getClosestCell in case of large (eta beyond HF ...) and in EM showers
45  if (fabs(point.Z()) > 2000 || fabs(point.X()) > 2000 || fabs(point.Y()) > 2000) {
46  if (EMSHOWER)
47  edm::LogWarning("HcalHitMaker") << "received a hit very far from the detector " << point
48  << " coming from an electromagnetic shower. - Ignoring it" << std::endl;
49  else if (HADSHOWER)
50  edm::LogWarning("HcalHitMaker") << "received a hit very far from the detector " << point
51  << " coming from a hadron shower. - Ignoring it" << std::endl;
52  else if (MIP)
53  edm::LogWarning("HcalHitMaker") << "received a hit very far from the detector " << point
54  << " coming from a muon. - Ignoring it" << std::endl;
55  return false;
56  }
57 
58  double pointeta = fabs(point.eta());
59  if (pointeta > 5.19)
60  return false;
61 
62  //calculate time of flight
63  double dist = std::sqrt(point.X() * point.X() + point.Y() * point.Y() + point.Z() * point.Z());
64  double tof = dist / 29.98; //speed of light
65 
66  DetId thecellID(myCalorimeter->getClosestCell(point, false, false));
67 
68  HcalDetId myDetId(thecellID);
69 
70  // if ( myDetId.subdetId() == HcalForward ) {
71  // std::cout << "HcalHitMaker : " << point.Z() << " " << myDetId.depth() << std::endl;
72  // }
73 
74  // std::cout << "BEFORE" << std::endl;
75  // std::cout << "HcalHitMaker : subdetId : " << myDetId.subdetId() << std::endl;
76  // std::cout << "HcalHitMaker : depth : " << myDetId.depth() << std::endl;
77  // std::cout << "HcalHitMaker : ieta : " << myDetId.ieta() << std::endl;
78  // std::cout << "HcalHitMaker : iphi : " << myDetId.iphi() << std::endl;
79  // std::cout << "HcalHitMaker : spotE : " << spotEnergy << std::endl;
80  // std::cout << "HcalHitMaker : point.X : " << point.X() << std::endl;
81  // std::cout << "HcalHitMaker : point.Y : " << point.Y() << std::endl;
82  // std::cout << "HcalHitMaker : point.Z : " << point.Z() << std::endl;
83 
84  if (myDetId.subdetId() == HcalForward) {
85  int mylayer = layer;
86  if (myDetId.depth() == 2) {
87  mylayer = (int)layer;
88  } else {
89  mylayer = 1;
90  }
91  HcalDetId myDetId2((HcalSubdetector)myDetId.subdetId(), myDetId.ieta(), myDetId.iphi(), mylayer);
92  thecellID = myDetId2;
93  myDetId = myDetId2;
94  }
95 
96  if (!thecellID.null() && myDetId.depth() > 0) {
97  CaloHitID current_id(thecellID.rawId(), tof, 0); //no track yet
98 
99  // std::cout << " FamosHcalHitMaker::addHit - the cell num " << cell
100  // << std::endl;
101 
102  std::map<CaloHitID, float>::iterator cellitr;
103  cellitr = hitMap_.find(current_id);
104  if (cellitr == hitMap_.end()) {
105  hitMap_.insert(std::pair<CaloHitID, float>(current_id, spotEnergy));
106  } else {
107  cellitr->second += spotEnergy;
108  }
109  return true;
110  }
111  return false;
112 }
113 
114 bool HcalHitMaker::setDepth(double depth, bool inCm) {
116  std::vector<CaloSegment>::const_iterator segiterator;
117  if (inCm) {
118  segiterator =
120  } else {
121  if (EMSHOWER)
122  segiterator =
124 
125  //Hadron shower
126  if (HADSHOWER)
127  segiterator =
129  }
130 
131  if (segiterator == myGrid.getSegments().end()) {
132  // Special trick - As advised by Salavat, no leakage should be simulated
133  if (depth > myGrid.getSegments().back().sL0Exit()) {
134  segiterator = find_if(myGrid.getSegments().begin(),
135  myGrid.getSegments().end(),
136  CaloSegment::inL0Segment(myGrid.getSegments().back().sL0Exit() - 1.));
137  depth = segiterator->sL0Exit() - 1.;
139  if (segiterator == myGrid.getSegments().end()) {
140  std::cout << " Could not go at such depth " << EMSHOWER << " " << currentDepth_ << std::endl;
141  std::cout << " Track " << *(myGrid.getFSimTrack()) << std::endl;
142  return false;
143  }
144  } else {
145  std::cout << " Could not go at such depth " << EMSHOWER << " " << currentDepth_ << " "
146  << myGrid.getSegments().back().sL0Exit() << std::endl;
147  std::cout << " Track " << *(myGrid.getFSimTrack()) << std::endl;
148  return false;
149  }
150  }
151 
152  XYZPoint origin;
153  if (inCm) {
154  origin = segiterator->positionAtDepthincm(currentDepth_);
155  } else {
156  if (EMSHOWER)
157  origin = segiterator->positionAtDepthinX0(currentDepth_);
158  if (HADSHOWER)
159  origin = segiterator->positionAtDepthinL0(currentDepth_);
160  }
161  XYZVector zaxis(0, 0, 1);
162  XYZVector planeVec1 = (zaxis.Cross(particleDirection)).Unit();
163  locToGlobal_ = Transform3D(Point(0, 0, 0),
164  Point(0, 0, 1),
165  Point(1, 0, 0),
166  (Point)origin,
167  (Point)(origin + particleDirection),
168  (Point)(origin + planeVec1));
169  return true;
170 }
DetId getClosestCell(const XYZPoint &point, bool ecal, bool central) const
const FSimTrack * myTrack
Definition: HcalHitMaker.h:43
std::map< CaloHitID, float > hitMap_
Definition: CaloHitMaker.h:61
const RawParticle & ecalEntrance() const
The particle at ECAL entrance.
Definition: FSimTrack.h:143
const std::vector< CaloSegment > & getSegments() const
Definition: EcalHitMaker.h:95
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
math::XYZVector XYZPoint
Definition: CaloHitMaker.h:23
Transform3D locToGlobal_
Definition: HcalHitMaker.h:49
double radiusFactor_
Definition: HcalHitMaker.h:50
ROOT::Math::Transform3DPJ::Point Point
Definition: HcalHitMaker.cc:8
const CaloGeometryHelper * myCalorimeter
Definition: CaloHitMaker.h:44
bool addHit(double r, double phi, unsigned layer=0) override
add the hit in the HCAL in local coordinates
Definition: HcalHitMaker.cc:30
T sqrt(T t)
Definition: SSEVec.h:19
ROOT::Math::Transform3DPJ Transform3D
Definition: HcalHitMaker.h:20
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
PositionVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Point
Definition: Transform3DPJ.h:58
HcalHitMaker(EcalHitMaker &, unsigned)
Definition: HcalHitMaker.cc:10
bool mapCalculated_
Definition: HcalHitMaker.h:51
XYZPoint ecalEntrance_
Definition: HcalHitMaker.h:44
This class is used to determine if a point lies in the segment.
Definition: CaloSegment.h:87
XYZVector Vect() const
the momentum threevector
Definition: RawParticle.h:323
Definition: DetId.h:17
double interactionLength
Definition: CaloHitMaker.h:47
const FSimTrack * getFSimTrack() const
To retrieve the track.
Definition: EcalHitMaker.h:120
double moliereRadius
Definition: CaloHitMaker.h:46
EcalHitMaker & myGrid
Definition: HcalHitMaker.h:41
Structure Point Contains parameters of Gaussian fits to DMRs.
math::XYZVector XYZVector
Definition: CaloHitMaker.h:22
XYZVector particleDirection
Definition: HcalHitMaker.h:45
Log< level::Warning, false > LogWarning
const XYZPoint & ecalEntrance() const
used in FamosHcalHitMaker
Definition: EcalHitMaker.h:123
double spotEnergy
Definition: CaloHitMaker.h:48
double currentDepth_
Definition: HcalHitMaker.h:48
bool setDepth(double, bool inCm=false)
set the depth in X0 or Lambda0 units depending on showerType
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5