00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "IOMC/EventVertexGenerators/interface/BetafuncEvtVtxGenerator.h"
00023 #include "FWCore/Utilities/interface/Exception.h"
00024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00025
00026 #include "CLHEP/Random/RandGaussQ.h"
00027 #include "CLHEP/Units/SystemOfUnits.h"
00028 #include "CLHEP/Units/PhysicalConstants.h"
00029
00030 #include "HepMC/SimpleVector.h"
00031
00032 #include <iostream>
00033
00034
00035
00036 BetafuncEvtVtxGenerator::BetafuncEvtVtxGenerator(const edm::ParameterSet & p )
00037 : BaseEvtVtxGenerator(p)
00038 {
00039
00040 fRandom = new CLHEP::RandGaussQ(getEngine());
00041
00042 fX0 = p.getParameter<double>("X0")*cm;
00043 fY0 = p.getParameter<double>("Y0")*cm;
00044 fZ0 = p.getParameter<double>("Z0")*cm;
00045 fSigmaZ = p.getParameter<double>("SigmaZ")*cm;
00046 alpha_ = p.getParameter<double>("Alpha")*radian;
00047 phi_ = p.getParameter<double>("Phi")*radian;
00048 fbetastar = p.getParameter<double>("BetaStar")*cm;
00049 femittance = p.getParameter<double>("Emittance")*cm;
00050 fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light;
00051
00052 if (fSigmaZ <= 0) {
00053 throw cms::Exception("Configuration")
00054 << "Error in BetafuncEvtVtxGenerator: "
00055 << "Illegal resolution in Z (SigmaZ is negative)";
00056 }
00057
00058
00059 }
00060
00061 BetafuncEvtVtxGenerator::~BetafuncEvtVtxGenerator()
00062 {
00063 delete fRandom;
00064 }
00065
00066
00067
00068 HepMC::FourVector* BetafuncEvtVtxGenerator::newVertex() {
00069
00070
00071 double X,Y,Z;
00072
00073 double tmp_sigz = fRandom->fire(0., fSigmaZ);
00074 Z = tmp_sigz + fZ0;
00075
00076 double tmp_sigx = BetaFunction(tmp_sigz,fZ0);
00077 X = fRandom->fire(0.,tmp_sigx) + fX0;
00078
00079 double tmp_sigy = BetaFunction(tmp_sigz,fZ0);
00080 Y = fRandom->fire(0.,tmp_sigy) + fY0;
00081
00082
00083
00084 if ( fVertex == 0 ) fVertex = new HepMC::FourVector();
00085 fVertex->set(X,Y,Z,fTimeOffset);
00086
00087 return fVertex;
00088 }
00089
00090 double BetafuncEvtVtxGenerator::BetaFunction(double z, double z0)
00091 {
00092 return sqrt(femittance*(fbetastar+(((z-z0)*(z-z0))/fbetastar)));
00093
00094 }
00095
00096
00097 void BetafuncEvtVtxGenerator::sigmaZ(double s)
00098 {
00099 if (s>=0 ) {
00100 fSigmaZ=s;
00101 }
00102 else {
00103 throw cms::Exception("LogicError")
00104 << "Error in BetafuncEvtVtxGenerator::sigmaZ: "
00105 << "Illegal resolution in Z (negative)";
00106 }
00107 }
00108
00109 TMatrixD* BetafuncEvtVtxGenerator::GetInvLorentzBoost() {
00110
00111
00112
00113
00114 if (boost_ != 0 ) return boost_;
00115
00116
00117
00118 TMatrixD tmpboost(4,4);
00119
00120
00121
00122
00123
00124
00125
00126 tmpboost(0,0) = 1./cos(phi_);
00127 tmpboost(0,1) = - cos(alpha_)*sin(phi_);
00128 tmpboost(0,2) = - tan(phi_)*sin(phi_);
00129 tmpboost(0,3) = - sin(alpha_)*sin(phi_);
00130 tmpboost(1,0) = - cos(alpha_)*tan(phi_);
00131 tmpboost(1,1) = 1.;
00132 tmpboost(1,2) = cos(alpha_)*tan(phi_);
00133 tmpboost(1,3) = 0.;
00134 tmpboost(2,0) = 0.;
00135 tmpboost(2,1) = - cos(alpha_)*sin(phi_);
00136 tmpboost(2,2) = cos(phi_);
00137 tmpboost(2,3) = - sin(alpha_)*sin(phi_);
00138 tmpboost(3,0) = - sin(alpha_)*tan(phi_);
00139 tmpboost(3,1) = 0.;
00140 tmpboost(3,2) = sin(alpha_)*tan(phi_);
00141 tmpboost(3,3) = 1.;
00142
00143 tmpboost.Invert();
00144 boost_ = new TMatrixD(tmpboost);
00145
00146
00147 return boost_;
00148 }