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  //calculate time of flight
61  double dist = std::sqrt(point.X()*point.X() + point.Y()*point.Y() + point.Z()*point.Z());
62  double tof = dist/29.98; //speed of light
63 
64  DetId thecellID(myCalorimeter->getClosestCell(point,false,false));
65 
66  HcalDetId myDetId(thecellID);
67 
68 // if ( myDetId.subdetId() == HcalForward ) {
69 // std::cout << "HcalHitMaker : " << point.Z() << " " << myDetId.depth() << std::endl;
70 // }
71 
72 // std::cout << "BEFORE" << std::endl;
73 // std::cout << "HcalHitMaker : subdetId : " << myDetId.subdetId() << std::endl;
74 // std::cout << "HcalHitMaker : depth : " << myDetId.depth() << std::endl;
75 // std::cout << "HcalHitMaker : ieta : " << myDetId.ieta() << std::endl;
76 // std::cout << "HcalHitMaker : iphi : " << myDetId.iphi() << std::endl;
77 // std::cout << "HcalHitMaker : spotE : " << spotEnergy << std::endl;
78 // std::cout << "HcalHitMaker : point.X : " << point.X() << std::endl;
79 // std::cout << "HcalHitMaker : point.Y : " << point.Y() << std::endl;
80 // std::cout << "HcalHitMaker : point.Z : " << point.Z() << std::endl;
81 
82  if ( myDetId.subdetId() == HcalForward ) {
83  int mylayer = layer;
84  if ( myDetId.depth()==2 ) {
85  mylayer = (int)layer;
86  } else {
87  mylayer = 1;
88  }
89  HcalDetId myDetId2((HcalSubdetector)myDetId.subdetId(),myDetId.ieta(),myDetId.iphi(),mylayer);
90  thecellID = myDetId2;
91  myDetId = myDetId2;
92  }
93 
94 
95 
96  if(!thecellID.null() && myDetId.depth()>0)
97  {
98  CaloHitID current_id(thecellID.rawId(),tof,0); //no track yet
99 
100  // std::cout << " FamosHcalHitMaker::addHit - the cell num " << cell
101  // << std::endl;
102 
103  std::map<CaloHitID,float>::iterator cellitr;
104  cellitr = hitMap_.find(current_id);
105  if(cellitr==hitMap_.end())
106  {
107  hitMap_.insert(std::pair<CaloHitID,float>(current_id,spotEnergy));
108  }
109  else
110  {
111  cellitr->second+=spotEnergy;
112  }
113  return true;
114  }
115  return false;
116 }
117 
118 bool
119 HcalHitMaker::setDepth(double depth,bool inCm)
120 {
122  std::vector<CaloSegment>::const_iterator segiterator;
123  if(inCm)
124  {
125  segiterator = find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inSegment(currentDepth_));
126  }
127  else
128  {
129  if(EMSHOWER)
130  segiterator = find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inX0Segment(currentDepth_));
131 
132  //Hadron shower
133  if(HADSHOWER)
134  segiterator = find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inL0Segment(currentDepth_));
135  }
136 
137  if(segiterator==myGrid.getSegments().end())
138  {
139  // Special trick - As advised by Salavat, no leakage should be simulated
140  if(depth > myGrid.getSegments().back().sL0Exit())
141  {
142  segiterator= find_if(myGrid.getSegments().begin(),myGrid.getSegments().end(),CaloSegment::inL0Segment(myGrid.getSegments().back().sL0Exit()-1.));
143  depth=segiterator->sL0Exit()-1.;
145  if(segiterator==myGrid.getSegments().end())
146  {
147  std::cout << " Could not go at such depth " << EMSHOWER << " " << currentDepth_ << std::endl;
148  std::cout << " Track " << *(myGrid.getFSimTrack()) << std::endl;
149  return false;
150  }
151  }
152  else
153  {
154  std::cout << " Could not go at such depth " << EMSHOWER << " " << currentDepth_ << " " << myGrid.getSegments().back().sL0Exit() << std::endl;
155  std::cout << " Track " << *(myGrid.getFSimTrack()) << std::endl;
156  return false;
157  }
158  }
159 
160 
161  XYZPoint origin;
162  if(inCm)
163  {
164  origin=segiterator->positionAtDepthincm(currentDepth_);
165  }
166  else
167  {
168  if(EMSHOWER)
169  origin=segiterator->positionAtDepthinX0(currentDepth_);
170  if(HADSHOWER)
171  origin=segiterator->positionAtDepthinL0(currentDepth_);
172  }
173  XYZVector zaxis(0,0,1);
174  XYZVector planeVec1=(zaxis.Cross(particleDirection)).Unit();
176  Point(0,0,1),
177  Point(1,0,0),
178  (Point)origin,
179  (Point)(origin+particleDirection),
180  (Point)(origin+planeVec1));
181  return true;
182 }
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:26
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:47
T sqrt(T t)
Definition: SSEVec.h:48
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:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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:18
std::map< CaloHitID, float > hitMap_
Definition: CaloHitMaker.h:65
double interactionLength
Definition: CaloHitMaker.h:50
Geom::Phi< T > phi() const
double moliereRadius
Definition: CaloHitMaker.h:49
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:25
EcalHitMaker & myGrid
Definition: HcalHitMaker.h:43
math::XYZVector XYZVector
Definition: CaloHitMaker.h:25
tuple cout
Definition: gather_cfg.py:121
XYZVector particleDirection
Definition: HcalHitMaker.h:47
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:51
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