CMS 3D CMS Logo

MixBoostEvtVtxGenerator.cc
Go to the documentation of this file.
1 
2 /*
3 ________________________________________________________________________
4 
5  MixBoostEvtVtxGenerator
6 
7  Smear vertex according to the Beta function on the transverse plane
8  and a Gaussian on the z axis. It allows the beam to have a crossing
9  angle (slopes dxdz and dydz).
10 
11  Based on GaussEvtVtxGenerator
12  implemented by Francisco Yumiceva (yumiceva@fnal.gov)
13 
14  FERMILAB
15  2006
16 ________________________________________________________________________
17 */
18 
19 //lingshan: add beta for z-axis boost
20 
21 //#include "IOMC/EventVertexGenerators/interface/BetafuncEvtVtxGenerator.h"
22 
26 
29 
34 
35 #include "CLHEP/Units/GlobalSystemOfUnits.h"
36 #include "CLHEP/Units/GlobalPhysicalConstants.h"
37 //#include "CLHEP/Vector/ThreeVector.h"
38 #include "HepMC/SimpleVector.h"
39 #include "TMatrixD.h"
40 
41 #include <iostream>
42 
43 using namespace edm;
44 using namespace std;
45 using namespace CLHEP;
46 
47 class RandGaussQ;
48 class FourVector;
49 
51 public:
53  ~MixBoostEvtVtxGenerator() override;
54 
56  void produce(edm::Event&, const edm::EventSetup&) override;
57  virtual TMatrixD* GetInvLorentzBoost();
58  virtual HepMC::FourVector* getVertex(edm::Event&);
59  virtual HepMC::FourVector* getRecVertex(edm::Event&);
60 
62  void sigmaZ(double s = 1.0);
63 
65  void X0(double m = 0) { fX0 = m; }
67  void Y0(double m = 0) { fY0 = m; }
69  void Z0(double m = 0) { fZ0 = m; }
70 
72  void Phi(double m = 0) { phi_ = m; }
74  void Alpha(double m = 0) { alpha_ = m; }
75  void Beta(double m = 0) { beta_ = m; }
76 
78  void betastar(double m = 0) { fbetastar = m; }
80  void emittance(double m = 0) { femittance = m; }
81 
83  double BetaFunction(double z, double z0);
84 
85 private:
89  MixBoostEvtVtxGenerator& operator=(const MixBoostEvtVtxGenerator& rhs) = delete;
90 
91  double alpha_, phi_;
92  //TMatrixD boost_;
93  double beta_;
94  double fX0, fY0, fZ0;
95  double fSigmaZ;
96  //double fdxdz, fdydz;
97  double fbetastar, femittance;
98  double falpha;
99 
100  HepMC::FourVector* fVertex;
101  TMatrixD* boost_;
102  double fTimeOffset;
103 
108  std::vector<double> vtxOffset;
109 };
110 
112  : fVertex(nullptr),
113  boost_(nullptr),
114  fTimeOffset(0),
115  vtxLabel(mayConsume<reco::VertexCollection>(pset.getParameter<edm::InputTag>("vtxLabel"))),
116  signalLabel(consumes<HepMCProduct>(pset.getParameter<edm::InputTag>("signalLabel"))),
117  mixLabel(consumes<CrossingFrame<HepMCProduct> >(pset.getParameter<edm::InputTag>("mixLabel"))),
118  useRecVertex(pset.exists("useRecVertex") ? pset.getParameter<bool>("useRecVertex") : false) {
119  beta_ = pset.getParameter<double>("Beta");
120  alpha_ = 0;
121  phi_ = 0;
122  if (pset.exists("Alpha")) {
123  alpha_ = pset.getParameter<double>("Alpha") * radian;
124  phi_ = pset.getParameter<double>("Phi") * radian;
125  }
126 
127  vtxOffset.resize(3);
128  if (pset.exists("vtxOffset"))
129  vtxOffset = pset.getParameter<std::vector<double> >("vtxOffset");
130 
131  produces<edm::HepMCProduct>();
132 }
133 
135  if (fVertex != nullptr)
136  delete fVertex;
137  if (boost_ != nullptr)
138  delete boost_;
139 }
140 
142  return sqrt(femittance * (fbetastar + (((z - z0) * (z - z0)) / fbetastar)));
143 }
144 
146  if (s >= 0) {
147  fSigmaZ = s;
148  } else {
149  throw cms::Exception("LogicError") << "Error in MixBoostEvtVtxGenerator::sigmaZ: "
150  << "Illegal resolution in Z (negative)";
151  }
152 }
153 
155  //alpha_ = 0;
156  //phi_ = 142.e-6;
157  // if (boost_ != 0 ) return boost_;
158 
159  //boost_.ResizeTo(4,4);
160  //boost_ = new TMatrixD(4,4);
161  TMatrixD tmpboost(4, 4);
162  TMatrixD tmpboostZ(4, 4);
163  TMatrixD tmpboostXYZ(4, 4);
164 
165  //if ( (alpha_ == 0) && (phi_==0) ) { boost_->Zero(); return boost_; }
166 
167  // Lorentz boost to frame where the collision is head-on
168  // phi is the half crossing angle in the plane ZS
169  // alpha is the angle to the S axis from the X axis in the XY plane
170 
171  tmpboost(0, 0) = 1. / cos(phi_);
172  tmpboost(0, 1) = -cos(alpha_) * sin(phi_);
173  tmpboost(0, 2) = -tan(phi_) * sin(phi_);
174  tmpboost(0, 3) = -sin(alpha_) * sin(phi_);
175  tmpboost(1, 0) = -cos(alpha_) * tan(phi_);
176  tmpboost(1, 1) = 1.;
177  tmpboost(1, 2) = cos(alpha_) * tan(phi_);
178  tmpboost(1, 3) = 0.;
179  tmpboost(2, 0) = 0.;
180  tmpboost(2, 1) = -cos(alpha_) * sin(phi_);
181  tmpboost(2, 2) = cos(phi_);
182  tmpboost(2, 3) = -sin(alpha_) * sin(phi_);
183  tmpboost(3, 0) = -sin(alpha_) * tan(phi_);
184  tmpboost(3, 1) = 0.;
185  tmpboost(3, 2) = sin(alpha_) * tan(phi_);
186  tmpboost(3, 3) = 1.;
187  //cout<<"beta "<<beta_;
188  double gama = 1.0 / sqrt(1 - beta_ * beta_);
189  tmpboostZ(0, 0) = gama;
190  tmpboostZ(0, 1) = 0.;
191  tmpboostZ(0, 2) = -1.0 * beta_ * gama;
192  tmpboostZ(0, 3) = 0.;
193  tmpboostZ(1, 0) = 0.;
194  tmpboostZ(1, 1) = 1.;
195  tmpboostZ(1, 2) = 0.;
196  tmpboostZ(1, 3) = 0.;
197  tmpboostZ(2, 0) = -1.0 * beta_ * gama;
198  tmpboostZ(2, 1) = 0.;
199  tmpboostZ(2, 2) = gama;
200  tmpboostZ(2, 3) = 0.;
201  tmpboostZ(3, 0) = 0.;
202  tmpboostZ(3, 1) = 0.;
203  tmpboostZ(3, 2) = 0.;
204  tmpboostZ(3, 3) = 1.;
205 
206  tmpboostXYZ = tmpboostZ * tmpboost;
207  tmpboostXYZ.Invert();
208 
209  //cout<<"Boosting with beta : "<<beta_<<endl;
210 
211  boost_ = new TMatrixD(tmpboostXYZ);
212  boost_->Print();
213 
214  return boost_;
215 }
216 
217 HepMC::FourVector* MixBoostEvtVtxGenerator::getVertex(Event& evt) {
218  const HepMC::GenEvent* inev = nullptr;
219 
221  evt.getByToken(mixLabel, cf);
223 
224  const HepMCProduct& bkg = mix.getObject(1);
225  if (!(bkg.isVtxGenApplied())) {
226  throw cms::Exception("MatchVtx") << "Input background does not have smeared vertex!" << endl;
227  } else {
228  inev = bkg.GetEvent();
229  }
230 
231  HepMC::GenVertex* genvtx = inev->signal_process_vertex();
232  if (!genvtx) {
233  cout << "No Signal Process Vertex!" << endl;
234  HepMC::GenEvent::particle_const_iterator pt = inev->particles_begin();
235  HepMC::GenEvent::particle_const_iterator ptend = inev->particles_end();
236  while (!genvtx || (genvtx->particles_in_size() == 1 && pt != ptend)) {
237  if (!genvtx)
238  cout << "No Gen Vertex!" << endl;
239  if (pt == ptend)
240  cout << "End reached!" << endl;
241  genvtx = (*pt)->production_vertex();
242  ++pt;
243  }
244  }
245  double aX, aY, aZ, aT;
246 
247  aX = genvtx->position().x();
248  aY = genvtx->position().y();
249  aZ = genvtx->position().z();
250  aT = genvtx->position().t();
251 
252  if (!fVertex)
253  fVertex = new HepMC::FourVector();
254  fVertex->set(aX, aY, aZ, aT);
255 
256  return fVertex;
257 }
258 
261  evt.getByToken(vtxLabel, input);
262 
263  double aX, aY, aZ;
264 
265  aX = input->begin()->position().x() + vtxOffset[0];
266  aY = input->begin()->position().y() + vtxOffset[1];
267  aZ = input->begin()->position().z() + vtxOffset[2];
268 
269  if (!fVertex)
270  fVertex = new HepMC::FourVector();
271  fVertex->set(10.0 * aX, 10.0 * aY, 10.0 * aZ, 0.0); // HepMC positions in mm (RECO in cm)
272 
273  return fVertex;
274 }
275 
277  Handle<HepMCProduct> HepUnsmearedMCEvt;
278  evt.getByToken(signalLabel, HepUnsmearedMCEvt);
279 
280  // Copy the HepMC::GenEvent
281  HepMC::GenEvent* genevt = new HepMC::GenEvent(*HepUnsmearedMCEvt->GetEvent());
282  std::unique_ptr<edm::HepMCProduct> HepMCEvt(new edm::HepMCProduct(genevt));
283  // generate new vertex & apply the shift
284  //
285 
286  HepMCEvt->boostToLab(GetInvLorentzBoost(), "vertex");
287  HepMCEvt->boostToLab(GetInvLorentzBoost(), "momentum");
288 
289  HepMCEvt->applyVtxGen(useRecVertex ? getRecVertex(evt) : getVertex(evt));
290 
291  evt.put(std::move(HepMCEvt));
292  return;
293 }
294 
MixBoostEvtVtxGenerator::signalLabel
edm::EDGetTokenT< HepMCProduct > signalLabel
Definition: MixBoostEvtVtxGenerator.cc:105
MixBoostEvtVtxGenerator::Beta
void Beta(double m=0)
Definition: MixBoostEvtVtxGenerator.cc:75
MixBoostEvtVtxGenerator::emittance
void emittance(double m=0)
emittance (no the normalized)
Definition: MixBoostEvtVtxGenerator.cc:80
electrons_cff.bool
bool
Definition: electrons_cff.py:372
input
static const std::string input
Definition: EdmProvDump.cc:48
funct::false
false
Definition: Factorize.h:34
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EDProducer.h
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
CTPPSRecHitProducer_cfi.mixLabel
mixLabel
Definition: CTPPSRecHitProducer_cfi.py:5
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
edm::EDGetTokenT< reco::VertexCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
VtxSmearedMatchHI_cff.signalLabel
signalLabel
Definition: VtxSmearedMatchHI_cff.py:6
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
gather_cfg.cout
cout
Definition: gather_cfg.py:144
MixBoostEvtVtxGenerator::~MixBoostEvtVtxGenerator
~MixBoostEvtVtxGenerator() override
Definition: MixBoostEvtVtxGenerator.cc:134
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
MixBoostEvtVtxGenerator::MixBoostEvtVtxGenerator
MixBoostEvtVtxGenerator(const edm::ParameterSet &p)
Definition: MixBoostEvtVtxGenerator.cc:111
edm::Handle
Definition: AssociativeIterator.h:50
MixBoostEvtVtxGenerator::alpha_
double alpha_
Definition: MixBoostEvtVtxGenerator.cc:91
MixBoostEvtVtxGenerator::femittance
double femittance
Definition: MixBoostEvtVtxGenerator.cc:97
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
MixBoostEvtVtxGenerator::vtxOffset
std::vector< double > vtxOffset
Definition: MixBoostEvtVtxGenerator.cc:108
MixBoostEvtVtxGenerator::mixLabel
edm::EDGetTokenT< CrossingFrame< HepMCProduct > > mixLabel
Definition: MixBoostEvtVtxGenerator.cc:106
MixBoostEvtVtxGenerator::falpha
double falpha
Definition: MixBoostEvtVtxGenerator.cc:98
CrossingFrame
Definition: CrossingFrame.h:38
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
MixBoostEvtVtxGenerator::phi_
double phi_
Definition: MixBoostEvtVtxGenerator.cc:91
MixBoostEvtVtxGenerator::Z0
void Z0(double m=0)
set mean in Z in cm
Definition: MixBoostEvtVtxGenerator.cc:69
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MixCollection.h
MixCollection
Definition: MixCollection.h:11
MixBoostEvtVtxGenerator::fbetastar
double fbetastar
Definition: MixBoostEvtVtxGenerator.cc:97
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DDAxes::z
MixBoostEvtVtxGenerator::Alpha
void Alpha(double m=0)
angle between crossing plane and horizontal plane
Definition: MixBoostEvtVtxGenerator.cc:74
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
MixBoostEvtVtxGenerator::X0
void X0(double m=0)
set mean in X in cm
Definition: MixBoostEvtVtxGenerator.cc:65
HLTMuonOfflineAnalyzer_cfi.z0
z0
Definition: HLTMuonOfflineAnalyzer_cfi.py:98
CLHEP
Definition: CocoaGlobals.h:27
Vertex.h
MixBoostEvtVtxGenerator::useRecVertex
bool useRecVertex
Definition: MixBoostEvtVtxGenerator.cc:107
MixBoostEvtVtxGenerator::Phi
void Phi(double m=0)
set half crossing angle
Definition: MixBoostEvtVtxGenerator.cc:72
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
MixBoostEvtVtxGenerator::beta_
double beta_
Definition: MixBoostEvtVtxGenerator.cc:93
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:132
MixBoostEvtVtxGenerator::sigmaZ
void sigmaZ(double s=1.0)
set resolution in Z in cm
Definition: MixBoostEvtVtxGenerator.cc:145
edm::EventSetup
Definition: EventSetup.h:57
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
MixBoostEvtVtxGenerator::GetInvLorentzBoost
virtual TMatrixD * GetInvLorentzBoost()
Definition: MixBoostEvtVtxGenerator.cc:154
InputTag.h
MixBoostEvtVtxGenerator::getVertex
virtual HepMC::FourVector * getVertex(edm::Event &)
Definition: MixBoostEvtVtxGenerator.cc:217
MixBoostEvtVtxGenerator::BetaFunction
double BetaFunction(double z, double z0)
beta function
Definition: MixBoostEvtVtxGenerator.cc:141
MixBoostEvtVtxGenerator::getRecVertex
virtual HepMC::FourVector * getRecVertex(edm::Event &)
Definition: MixBoostEvtVtxGenerator.cc:259
MixBoostEvtVtxGenerator::vtxLabel
edm::EDGetTokenT< reco::VertexCollection > vtxLabel
Definition: MixBoostEvtVtxGenerator.cc:104
VertexFwd.h
MixBoostEvtVtxGenerator::boost_
TMatrixD * boost_
Definition: MixBoostEvtVtxGenerator.cc:101
MixBoostEvtVtxGenerator::produce
void produce(edm::Event &, const edm::EventSetup &) override
return a new event vertex
Definition: MixBoostEvtVtxGenerator.cc:276
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
MatchRecVtx_cfi.useRecVertex
useRecVertex
Definition: MatchRecVtx_cfi.py:10
MixBoostEvtVtxGenerator::fTimeOffset
double fTimeOffset
Definition: MixBoostEvtVtxGenerator.cc:102
MixBoostEvtVtxGenerator::fZ0
double fZ0
Definition: MixBoostEvtVtxGenerator.cc:94
Exception
Definition: hltDiff.cc:246
MixBoostEvtVtxGenerator::fSigmaZ
double fSigmaZ
Definition: MixBoostEvtVtxGenerator.cc:95
edm::EDProducer
Definition: EDProducer.h:36
Exception.h
MixBoostEvtVtxGenerator
Definition: MixBoostEvtVtxGenerator.cc:50
MixBoostEvtVtxGenerator::betastar
void betastar(double m=0)
set beta_star
Definition: MixBoostEvtVtxGenerator.cc:78
MixBoostEvtVtxGenerator::Y0
void Y0(double m=0)
set mean in Y in cm
Definition: MixBoostEvtVtxGenerator.cc:67
edm::HepMCProduct
Definition: HepMCProduct.h:18
ParameterSet.h
HepMCProduct.h
fftjetvertexadder_cfi.sigmaZ
sigmaZ
Definition: fftjetvertexadder_cfi.py:32
edm::Event
Definition: Event.h:73
GeneratorMix_cff.mix
mix
Definition: GeneratorMix_cff.py:6
VtxSmearedMatchHI_cff.vtxLabel
vtxLabel
Definition: VtxSmearedMatchHI_cff.py:8
MixBoostEvtVtxGenerator::fVertex
HepMC::FourVector * fVertex
Definition: MixBoostEvtVtxGenerator.cc:100
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27