CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PreshowerHitMaker.cc
Go to the documentation of this file.
2 #
8 
9 #include "Math/GenVector/Plane3D.h"
10 
11 #include <cmath>
12 
15 
16 // LandauFluctuationGenerator PreshowerHitMaker::theGenerator=LandauFluctuationGenerator();
17 
19  CaloGeometryHelper * calo,
20  const XYZPoint& layer1entrance,
21  const XYZVector& layer1dir,
22  const XYZPoint& layer2entrance,
23  const XYZVector& layer2dir,
24  const LandauFluctuationGenerator* aGenerator):
25  CaloHitMaker(calo,DetId::Ecal,EcalPreshower,2),
26  psLayer1Entrance_(layer1entrance),
27  psLayer1Dir_(layer1dir),
28  psLayer2Entrance_(layer2entrance),
29  psLayer2Dir_(layer2dir),
30  totalLayer1_(0.),totalLayer2_(0.),
31  theGenerator(aGenerator)
32 {
33  double dummyt;
34  anglecorrection1_ = 0.;
35  anglecorrection2_ = 0.;
36  // Check if the entrance points are really on the wafers
37  // Layer 1
38  layer1valid_ = (layer1entrance.Mag2()>0.);
39  if(layer1valid_)
40  {
41  int z=(psLayer1Entrance_.z()>0)? 1:-1;
42  Plane3D plan1(0.,0.,1.,-z*myCalorimeter->preshowerZPosition(1));
43 
44  psLayer1Entrance_ = intersect(plan1,layer1entrance,layer1entrance+layer1dir,dummyt,false);
45 
46  XYZVector zaxis(0,0,1);
47  XYZVector planeVec1=(zaxis.Cross(layer1dir)).Unit();
49  Point(0,0,1),
50  Point(1,0,0),
51  (Point)psLayer1Entrance_,
52  (Point)(psLayer1Entrance_+layer1dir),
53  (Point)(psLayer1Entrance_+planeVec1));
54 
55  anglecorrection1_ = fabs(zaxis.Dot(layer1dir));
57  // std::cout << " Layer 1 entrance " << psLayer1Entrance_ << std::endl;
58  // std::cout << " Layer 1 corr " << anglecorrection1_ << std::endl;
59  }
60 
61  // Layer 2
62  layer2valid_ = (layer2entrance.Mag2()>0.);
63  if(layer2valid_)
64  {
65  int z=(psLayer2Entrance_.z()>0) ? 1:-1;
66  Plane3D plan2(0.,0.,1.,-z*myCalorimeter->preshowerZPosition(2));
67 
68  psLayer2Entrance_ = intersect(plan2,layer2entrance,layer2entrance+layer2dir,dummyt,false);
69 
70  XYZVector zaxis(0,0,1);
71  XYZVector planeVec2=(zaxis.Cross(layer2dir)).Unit();
73  Point(0,0,1),
74  Point(1,0,0),
75  (Point)psLayer2Entrance_,
76  (Point)(psLayer2Entrance_+layer2dir),
77  (Point)(psLayer2Entrance_+planeVec2));
78 
79  anglecorrection2_ = fabs(zaxis.Dot(layer2dir));
81  // std::cout << " Layer 2 entrance " << psLayer2Entrance_ << std::endl;
82  // std::cout << " Layer 2 corr " << anglecorrection2_ << std::endl;
83  }
84  // theGenerator=LandauFluctuationGenerator();
85 }
86 
87 
88 bool
89 PreshowerHitMaker::addHit(double r,double phi,unsigned layer)
90 {
91  if((layer==1&&!layer1valid_)||((layer==2&&!layer2valid_))) return false;
92 
93  r*=moliereRadius;
94  XYZPoint point (r*std::cos(phi),r*std::sin(phi),0.);
95  point = (layer==1) ? locToGlobal1_((Point)point) : locToGlobal2_((Point)point);
96  // std::cout << " Point " << point << std::endl;
97  int z=(point.z()>0) ? 1: -1;
98  point = XYZPoint(point.x(),point.y(),z*myCalorimeter->preshowerZPosition(layer));
99  // std::cout << "r " << r << " Point after " << point << std::endl;
100  // std::cout << " Layer " << layer << " " << point << std::endl;
101  DetId strip = myCalorimeter->getEcalPreshowerGeometry()->getClosestCellInPlane(GlobalPoint(point.x(),point.y(),point.z()),layer);
102 
103  float meanspot=(layer==1) ? mip1_ : mip2_;
104  float spote = meanspot + 0.000021*theGenerator->landau();
105  spote *= ( (layer==1) ? anglecorrection1_ : anglecorrection2_ );
106 
107  if(!strip.null())
108  {
109  //calculate time of flight
110  double tof = (myCalorimeter->getEcalPreshowerGeometry()->getGeometry(strip)->getPosition().mag())/29.98;//speed of light
111  CaloHitID current_id(strip.rawId(),tof,0); //no track yet
112  std::map<CaloHitID,float>::iterator cellitr;
113  cellitr = hitMap_.find(current_id);
114  if( cellitr==hitMap_.end())
115  {
116  hitMap_.insert(std::pair<CaloHitID,float>(current_id,spote));
117  }
118  else
119  {
120  cellitr->second+=spote;
121  }
122  // std::cout << " found " << stripNumber << " " << spote <<std::endl;
123  if(layer==1){
124  totalLayer1_+=spote;
125  }
126  else if (layer==2) {
127  totalLayer2_+=spote;
128  }
129  return true;
130  }
131  // std::cout << " Could not find a cell " << point << std::endl;
132  return false;
133 }
double preshowerZPosition(int layer) const
PositionVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Point
Definition: Transform3DPJ.h:66
math::XYZVector XYZPoint
bool addHit(double r, double phi, unsigned layer=0)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
math::XYZVector XYZPoint
Definition: CaloHitMaker.h:26
const EcalPreshowerGeometry * getEcalPreshowerGeometry() const
Definition: Calorimeter.h:55
Transform3D locToGlobal1_
std::pair< double, double > Point
Definition: CaloEllipse.h:18
float float float z
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const CaloGeometryHelper * myCalorimeter
Definition: CaloHitMaker.h:47
double landau() const
Random generator of the dE/dX spread (Landau function)
T mag() const
Definition: PV3DBase.h:67
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
math::XYZPoint Point
virtual DetId getClosestCellInPlane(const GlobalPoint &r, int plane) const
static XYZPoint intersect(const Plane3D &p, const XYZPoint &a, const XYZPoint &b, double &t, bool segment, bool debug=false)
Definition: CaloHitMaker.cc:38
ROOT::Math::Transform3DPJ Transform3D
Definition: DetId.h:20
std::map< CaloHitID, float > hitMap_
Definition: CaloHitMaker.h:65
ROOT::Math::Plane3D Plane3D
Definition: CaloHitMaker.h:27
Transform3D locToGlobal2_
double moliereRadius
Definition: CaloHitMaker.h:49
PreshowerHitMaker(CaloGeometryHelper *calo, const XYZPoint &, const XYZVector &, const XYZPoint &, const XYZVector &, const LandauFluctuationGenerator *aGenerator)
math::XYZVector XYZVector
Definition: CaloHitMaker.h:25
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
const LandauFluctuationGenerator * theGenerator
The Landau Fluctuation generator.
ROOT::Math::Plane3D Plane3D
*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
Definition: DDAxes.h:10