CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalHitMaker.cc
Go to the documentation of this file.
5 #include <algorithm>
6 #include <cmath>
7 
9 
11  :CaloHitMaker(grid.getCalorimeter(),DetId::Hcal,HcalHitMaker::getSubHcalDet(grid.getFSimTrack()),
12  grid.getFSimTrack()->onHcal()?grid.getFSimTrack()->onHcal():grid.getFSimTrack()->onVFcal()+1,shower),
13  myGrid(grid), myTrack((grid.getFSimTrack()))
14 {
15  // normalize the direction
17  particleDirection=myTrack->ecalEntrance().Vect().Unit();
19  mapCalculated_=false;
20  //std::cout << " Famos HCAL " << grid.getTrack()->onHcal() << " " << grid.getTrack()->onVFcal() << " " << showerType << std::endl;
21  if(EMSHOWER&&(abs(grid.getFSimTrack()->type())!=11 && grid.getFSimTrack()->type()!=22))
22  {
23  std::cout << " FamosHcalHitMaker : Strange. The following shower has EM type" << std::endl <<* grid.getFSimTrack() << std::endl;
24  }
25 }
26 
27 bool
28 HcalHitMaker::addHit(double r,double phi,unsigned layer)
29 {
30  // std::cout << " FamosHcalHitMaker::addHit - radiusFactor = " << radiusFactor
31  // << std::endl;
32 
34 
35  // Watch out !!!! (Point) is a real point in the MathCore terminology (not a redefined a XYZPoint which
36  // is actually a XYZVector in the MatchCore terminology). Therefore, the Transform3D is correctly applied
37  point = locToGlobal_((Point)point);
38  return addHit(point,layer);
39 }
40 
41 bool HcalHitMaker::addHit(const XYZPoint& point, unsigned layer)
42 {
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  {
47  if(EMSHOWER)
48  edm::LogWarning("HcalHitMaker") << "received a hit very far from the detector " << point << " 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 << " coming from a hadron shower. - Ignoring it" << std::endl;
51  else if(MIP)
52  edm::LogWarning("HcalHitMaker") << "received a hit very far from the detector " << point << " coming from a muon. - Ignoring it" << std::endl;
53  return false;
54  }
55 
56 
57  double pointeta = fabs(point.eta());
58  if(pointeta > 5.19) return false;
59 
60  DetId thecellID(myCalorimeter->getClosestCell(point,false,false));
61 
62  HcalDetId myDetId(thecellID);
63 
64 // if ( myDetId.subdetId() == HcalForward ) {
65 // std::cout << "HcalHitMaker : " << point.Z() << " " << myDetId.depth() << std::endl;
66 // }
67 
68 // std::cout << "BEFORE" << std::endl;
69 // std::cout << "HcalHitMaker : subdetId : " << myDetId.subdetId() << std::endl;
70 // std::cout << "HcalHitMaker : depth : " << myDetId.depth() << std::endl;
71 // std::cout << "HcalHitMaker : ieta : " << myDetId.ieta() << std::endl;
72 // std::cout << "HcalHitMaker : iphi : " << myDetId.iphi() << std::endl;
73 // std::cout << "HcalHitMaker : spotE : " << spotEnergy << std::endl;
74 // std::cout << "HcalHitMaker : point.X : " << point.X() << std::endl;
75 // std::cout << "HcalHitMaker : point.Y : " << point.Y() << std::endl;
76 // std::cout << "HcalHitMaker : point.Z : " << point.Z() << std::endl;
77 
78  if ( myDetId.subdetId() == HcalForward ) {
79  int mylayer = layer;
80  if ( myDetId.depth()==2 ) {
81  mylayer = (int)layer;
82  } else {
83  mylayer = 1;
84  }
85  HcalDetId myDetId2((HcalSubdetector)myDetId.subdetId(),myDetId.ieta(),myDetId.iphi(),mylayer);
86  thecellID = myDetId2;
87  }
88 
89 
90 
91  if(!thecellID.null())
92  {
93  uint32_t cell(thecellID.rawId());
94 
95  // std::cout << " FamosHcalHitMaker::addHit - the cell num " << cell
96  // << std::endl;
97 
98  std::map<uint32_t,float>::iterator cellitr;
99  cellitr = hitMap_.find(cell);
100  if(cellitr==hitMap_.end())
101  {
102  hitMap_.insert(std::pair<uint32_t,float>(cell,spotEnergy));
103  }
104  else
105  {
106  cellitr->second+=spotEnergy;
107  }
108  return true;
109  }
110  return false;
111 }
112 
113 bool
114 HcalHitMaker::setDepth(double depth,bool inCm)
115 {
116  currentDepth_=depth;
117  std::vector<CaloSegment>::const_iterator segiterator;
118  if(inCm)
119  {
120  segiterator = find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inSegment(currentDepth_));
121  }
122  else
123  {
124  if(EMSHOWER)
125  segiterator = find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inX0Segment(currentDepth_));
126 
127  //Hadron shower
128  if(HADSHOWER)
129  segiterator = find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inL0Segment(currentDepth_));
130  }
131 
132  if(segiterator==myGrid.getSegments().end())
133  {
134  // Special trick - As advised by Salavat, no leakage should be simulated
135  if(depth > myGrid.getSegments().back().sL0Exit())
136  {
137  segiterator= find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inL0Segment(myGrid.getSegments().back().sL0Exit()-1.));
138  depth=segiterator->sL0Exit()-1.;
139  currentDepth_=depth;
140  if(segiterator==myGrid.getSegments().end())
141  {
142  std::cout << " Could not go at such depth " << EMSHOWER << " " << currentDepth_ << std::endl;
143  std::cout << " Track " << *(myGrid.getFSimTrack()) << std::endl;
144  return false;
145  }
146  }
147  else
148  {
149  std::cout << " Could not go at such depth " << EMSHOWER << " " << currentDepth_ << " " << myGrid.getSegments().back().sL0Exit() << std::endl;
150  std::cout << " Track " << *(myGrid.getFSimTrack()) << std::endl;
151  return false;
152  }
153  }
154 
155 
156  XYZPoint origin;
157  if(inCm)
158  {
159  origin=segiterator->positionAtDepthincm(currentDepth_);
160  }
161  else
162  {
163  if(EMSHOWER)
164  origin=segiterator->positionAtDepthinX0(currentDepth_);
165  if(HADSHOWER)
166  origin=segiterator->positionAtDepthinL0(currentDepth_);
167  }
168  XYZVector zaxis(0,0,1);
169  XYZVector planeVec1=(zaxis.Cross(particleDirection)).Unit();
171  Point(0,0,1),
172  Point(1,0,0),
173  (Point)origin,
174  (Point)(origin+particleDirection),
175  (Point)(origin+planeVec1));
176  return true;
177 }
PositionVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Point
Definition: Transform3DPJ.h:66
const FSimTrack * myTrack
Definition: HcalHitMaker.h:45
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
math::XYZVector XYZPoint
Definition: CaloHitMaker.h:25
#define abs(x)
Definition: mlp_lapack.h:159
Transform3D locToGlobal_
Definition: HcalHitMaker.h:51
std::pair< double, double > Point
Definition: CaloEllipse.h:18
double radiusFactor_
Definition: HcalHitMaker.h:52
const CaloGeometryHelper * myCalorimeter
Definition: CaloHitMaker.h:46
ROOT::Math::Transform3DPJ Transform3D
Definition: HcalHitMaker.h:22
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
math::XYZPoint Point
HcalSubdetector
Definition: HcalAssistant.h:32
const RawParticle & ecalEntrance() const
The particle at ECAL entrance.
Definition: FSimTrack.h:133
HcalHitMaker(EcalHitMaker &, unsigned)
Definition: HcalHitMaker.cc:10
bool mapCalculated_
Definition: HcalHitMaker.h:53
XYZPoint ecalEntrance_
Definition: HcalHitMaker.h:46
This class is used to determine if a point lies in the segment.
Definition: CaloSegment.h:86
Definition: DetId.h:20
double interactionLength
Definition: CaloHitMaker.h:49
double moliereRadius
Definition: CaloHitMaker.h:48
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:40
EcalHitMaker & myGrid
Definition: HcalHitMaker.h:43
math::XYZVector XYZVector
Definition: CaloHitMaker.h:24
tuple cout
Definition: gather_cfg.py:121
XYZVector particleDirection
Definition: HcalHitMaker.h:47
std::map< uint32_t, float > hitMap_
Definition: CaloHitMaker.h:64
DetId getClosestCell(const XYZPoint &point, bool ecal, bool central) const
bool addHit(double r, double phi, unsigned layer=0)
add the hit in the HCAL in local coordinates
Definition: HcalHitMaker.cc:28
double spotEnergy
Definition: CaloHitMaker.h:50
double currentDepth_
Definition: HcalHitMaker.h:50
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
const FSimTrack * getFSimTrack() const
To retrieve the track.
Definition: EcalHitMaker.h:125
const std::vector< CaloSegment > & getSegments() const
Definition: EcalHitMaker.h:99
const XYZPoint & ecalEntrance() const
used in FamosHcalHitMaker
Definition: EcalHitMaker.h:128
Definition: DDAxes.h:10