test
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  const RandomEngineAndDistribution* engine):
26  CaloHitMaker(calo,DetId::Ecal,EcalPreshower,2),
27  psLayer1Entrance_(layer1entrance),
28  psLayer1Dir_(layer1dir),
29  psLayer2Entrance_(layer2entrance),
30  psLayer2Dir_(layer2dir),
31  totalLayer1_(0.),totalLayer2_(0.),
32  theGenerator(aGenerator),
33  random(engine)
34 {
35  double dummyt;
36  anglecorrection1_ = 0.;
37  anglecorrection2_ = 0.;
38  // Check if the entrance points are really on the wafers
39  // Layer 1
40  layer1valid_ = (layer1entrance.Mag2()>0.);
41  if(layer1valid_)
42  {
43  int z=(psLayer1Entrance_.z()>0)? 1:-1;
44  Plane3D plan1(0.,0.,1.,-z*myCalorimeter->preshowerZPosition(1));
45 
46  psLayer1Entrance_ = intersect(plan1,layer1entrance,layer1entrance+layer1dir,dummyt,false);
47 
48  XYZVector zaxis(0,0,1);
49  XYZVector planeVec1=(zaxis.Cross(layer1dir)).Unit();
51  Point(0,0,1),
52  Point(1,0,0),
53  (Point)psLayer1Entrance_,
54  (Point)(psLayer1Entrance_+layer1dir),
55  (Point)(psLayer1Entrance_+planeVec1));
56 
57  anglecorrection1_ = fabs(zaxis.Dot(layer1dir));
59  // std::cout << " Layer 1 entrance " << psLayer1Entrance_ << std::endl;
60  // std::cout << " Layer 1 corr " << anglecorrection1_ << std::endl;
61  }
62 
63  // Layer 2
64  layer2valid_ = (layer2entrance.Mag2()>0.);
65  if(layer2valid_)
66  {
67  int z=(psLayer2Entrance_.z()>0) ? 1:-1;
68  Plane3D plan2(0.,0.,1.,-z*myCalorimeter->preshowerZPosition(2));
69 
70  psLayer2Entrance_ = intersect(plan2,layer2entrance,layer2entrance+layer2dir,dummyt,false);
71 
72  XYZVector zaxis(0,0,1);
73  XYZVector planeVec2=(zaxis.Cross(layer2dir)).Unit();
75  Point(0,0,1),
76  Point(1,0,0),
77  (Point)psLayer2Entrance_,
78  (Point)(psLayer2Entrance_+layer2dir),
79  (Point)(psLayer2Entrance_+planeVec2));
80 
81  anglecorrection2_ = fabs(zaxis.Dot(layer2dir));
83  // std::cout << " Layer 2 entrance " << psLayer2Entrance_ << std::endl;
84  // std::cout << " Layer 2 corr " << anglecorrection2_ << std::endl;
85  }
86  // theGenerator=LandauFluctuationGenerator();
87 }
88 
89 
90 bool
91 PreshowerHitMaker::addHit(double r,double phi,unsigned layer)
92 {
93  if((layer==1&&!layer1valid_)||((layer==2&&!layer2valid_))) return false;
94 
95  r*=moliereRadius;
96  XYZPoint point (r*std::cos(phi),r*std::sin(phi),0.);
97  point = (layer==1) ? locToGlobal1_((Point)point) : locToGlobal2_((Point)point);
98  // std::cout << " Point " << point << std::endl;
99  int z=(point.z()>0) ? 1: -1;
100  point = XYZPoint(point.x(),point.y(),z*myCalorimeter->preshowerZPosition(layer));
101  // std::cout << "r " << r << " Point after " << point << std::endl;
102  // std::cout << " Layer " << layer << " " << point << std::endl;
103  DetId strip = myCalorimeter->getEcalPreshowerGeometry()->getClosestCellInPlane(GlobalPoint(point.x(),point.y(),point.z()),layer);
104 
105  float meanspot=(layer==1) ? mip1_ : mip2_;
106  float spote = meanspot + 0.000021*theGenerator->landau(random);
107  spote *= ( (layer==1) ? anglecorrection1_ : anglecorrection2_ );
108 
109  if(!strip.null())
110  {
111  //calculate time of flight
112  double tof = (myCalorimeter->getEcalPreshowerGeometry()->getGeometry(strip)->getPosition().mag())/29.98;//speed of light
113  CaloHitID current_id(strip.rawId(),tof,0); //no track yet
114  std::map<CaloHitID,float>::iterator cellitr;
115  cellitr = hitMap_.find(current_id);
116  if( cellitr==hitMap_.end())
117  {
118  hitMap_.insert(std::pair<CaloHitID,float>(current_id,spote));
119  }
120  else
121  {
122  cellitr->second+=spote;
123  }
124  // std::cout << " found " << stripNumber << " " << spote <<std::endl;
125  if(layer==1){
126  totalLayer1_+=spote;
127  }
128  else if (layer==2) {
129  totalLayer2_+=spote;
130  }
131  return true;
132  }
133  // std::cout << " Could not find a cell " << point << std::endl;
134  return false;
135 }
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_
TRandom random
Definition: MVATrainer.cc:138
PreshowerHitMaker(CaloGeometryHelper *calo, const XYZPoint &, const XYZVector &, const XYZPoint &, const XYZVector &, const LandauFluctuationGenerator *aGenerator, const RandomEngineAndDistribution *engine)
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
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
double landau(RandomEngineAndDistribution const *random) const
Random generator of the dE/dX spread (Landau function)
Definition: DetId.h:18
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
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
const RandomEngineAndDistribution * random
Definition: DDAxes.h:10