Skip to content

Commit 617f485

Browse files
authored
Merge pull request #46891 from mkirsano/ChangeSmearing
Change Vtx generators to allow HepMC3Product smearing
2 parents dc3efc8 + e872742 commit 617f485

14 files changed

+62
-114
lines changed

IOMC/EventVertexGenerators/interface/BaseEvtVtxGenerator.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "FWCore/Framework/interface/stream/EDProducer.h"
77
#include "FWCore/Utilities/interface/EDGetToken.h"
88

9+
#include "Math/Vector4D.h"
910
#include "TMatrixD.h"
1011

1112
namespace HepMC {
@@ -29,12 +30,7 @@ class BaseEvtVtxGenerator : public edm::stream::EDProducer<> {
2930

3031
void produce(edm::Event&, const edm::EventSetup&) override;
3132

32-
virtual HepMC::FourVector newVertex(CLHEP::HepRandomEngine*) const = 0;
33-
/** This method - and the comment - is a left-over from COBRA-OSCAR time :
34-
* return the last generated event vertex.
35-
* If no vertex has been generated yet, a NULL pointer is returned. */
36-
//virtual CLHEP::Hep3Vector* lastVertex() { return fVertex; }
37-
//virtual HepMC::FourVector* lastVertex() { return fVertex; }
33+
virtual ROOT::Math::XYZTVector vertexShift(CLHEP::HepRandomEngine*) const = 0;
3834

3935
virtual TMatrixD const* GetInvLorentzBoost() const = 0;
4036

IOMC/EventVertexGenerators/interface/BeamProfileVtxGenerator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class BeamProfileVtxGenerator : public BaseEvtVtxGenerator {
2626
~BeamProfileVtxGenerator() override;
2727

2828
/// return a new event vertex
29-
//virtual CLHEP::Hep3Vector * newVertex();
30-
HepMC::FourVector newVertex(CLHEP::HepRandomEngine*) const override;
29+
ROOT::Math::XYZTVector vertexShift(CLHEP::HepRandomEngine*) const override;
3130

3231
TMatrixD const* GetInvLorentzBoost() const override { return nullptr; }
3332

IOMC/EventVertexGenerators/interface/BetafuncEvtVtxGenerator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class BetafuncEvtVtxGenerator : public BaseEvtVtxGenerator {
4343
void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
4444

4545
/// return a new event vertex
46-
//virtual CLHEP::Hep3Vector * newVertex();
47-
HepMC::FourVector newVertex(CLHEP::HepRandomEngine*) const override;
46+
ROOT::Math::XYZTVector vertexShift(CLHEP::HepRandomEngine*) const override;
4847

4948
TMatrixD const* GetInvLorentzBoost() const override;
5049

IOMC/EventVertexGenerators/interface/FlatEvtVtxGenerator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class FlatEvtVtxGenerator : public BaseEvtVtxGenerator {
2929
~FlatEvtVtxGenerator() override;
3030

3131
/// return a new event vertex
32-
//virtual CLHEP::Hep3Vector* newVertex();
33-
HepMC::FourVector newVertex(CLHEP::HepRandomEngine*) const override;
32+
ROOT::Math::XYZTVector vertexShift(CLHEP::HepRandomEngine*) const override;
3433

3534
const TMatrixD* GetInvLorentzBoost() const override { return nullptr; }
3635

IOMC/EventVertexGenerators/interface/GaussEvtVtxGenerator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class GaussEvtVtxGenerator : public BaseEvtVtxGenerator {
3232
void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
3333

3434
/// return a new event vertex
35-
//virtual CLHEP::Hep3Vector* newVertex();
36-
HepMC::FourVector newVertex(CLHEP::HepRandomEngine*) const override;
35+
ROOT::Math::XYZTVector vertexShift(CLHEP::HepRandomEngine*) const override;
3736

3837
TMatrixD const* GetInvLorentzBoost() const override { return nullptr; }
3938

IOMC/EventVertexGenerators/interface/HLLHCEvtVtxGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class HLLHCEvtVtxGenerator : public BaseEvtVtxGenerator {
4444
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
4545

4646
/// return a new event vertex
47-
HepMC::FourVector newVertex(CLHEP::HepRandomEngine*) const override;
47+
ROOT::Math::XYZTVector vertexShift(CLHEP::HepRandomEngine*) const override;
4848

4949
TMatrixD const* GetInvLorentzBoost() const override { return nullptr; };
5050

IOMC/EventVertexGenerators/interface/PassThroughEvtVtxGenerator.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,24 @@
44
*/
55

66
#include "IOMC/EventVertexGenerators/interface/BaseEvtVtxGenerator.h"
7-
#include "FWCore/Framework/interface/stream/EDProducer.h"
8-
#include "FWCore/Utilities/interface/EDGetToken.h"
97

108
#include "TMatrixD.h"
119

12-
namespace HepMC {
13-
class FourVector;
14-
}
15-
1610
namespace CLHEP {
1711
class HepRandomEngine;
1812
}
1913

20-
namespace edm {
21-
class HepMCProduct;
22-
}
23-
2414
class PassThroughEvtVtxGenerator : public BaseEvtVtxGenerator {
2515
public:
2616
// ctor & dtor
2717
explicit PassThroughEvtVtxGenerator(const edm::ParameterSet&);
2818
~PassThroughEvtVtxGenerator() override;
2919

30-
void produce(edm::Event&, const edm::EventSetup&) override;
31-
32-
HepMC::FourVector newVertex(CLHEP::HepRandomEngine*) const override;
20+
ROOT::Math::XYZTVector vertexShift(CLHEP::HepRandomEngine*) const override;
3321

3422
TMatrixD const* GetInvLorentzBoost() const override { return nullptr; };
3523

3624
private:
37-
edm::EDGetTokenT<edm::HepMCProduct> sourceToken;
3825
};
3926

4027
#endif

IOMC/EventVertexGenerators/src/BaseEvtVtxGenerator.cc

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
*/
43

@@ -18,13 +17,8 @@
1817
#include "DataFormats/Provenance/interface/Provenance.h"
1918
#include "FWCore/Utilities/interface/EDMException.h"
2019

21-
//#include "HepMC/GenEvent.h"
22-
// #include "CLHEP/Vector/ThreeVector.h"
23-
// #include "HepMC/SimpleVector.h"
24-
2520
using namespace edm;
2621
using namespace CLHEP;
27-
//using namespace HepMC;
2822

2923
BaseEvtVtxGenerator::BaseEvtVtxGenerator(const ParameterSet& pset) {
3024
Service<RandomNumberGenerator> rng;
@@ -59,7 +53,8 @@ void BaseEvtVtxGenerator::produce(Event& evt, const EventSetup&) {
5953
std::unique_ptr<edm::HepMCProduct> HepMCEvt(new edm::HepMCProduct(genevt));
6054
// generate new vertex & apply the shift
6155
//
62-
HepMCEvt->applyVtxGen(newVertex(engine));
56+
ROOT::Math::XYZTVector VertexShift = vertexShift(engine);
57+
HepMCEvt->applyVtxGen(HepMC::FourVector(VertexShift.x(), VertexShift.y(), VertexShift.z(), VertexShift.t()));
6358

6459
HepMCEvt->boostToLab(GetInvLorentzBoost(), "vertex");
6560
HepMCEvt->boostToLab(GetInvLorentzBoost(), "momentum");
@@ -76,7 +71,26 @@ void BaseEvtVtxGenerator::produce(Event& evt, const EventSetup&) {
7671

7772
HepMC3::GenEvent* genevt3 = new HepMC3::GenEvent();
7873
genevt3->read_data(*HepUnsmearedMCEvt3->GetEvent());
79-
HepMC3Product* productcopy3 = new HepMC3Product(genevt3); // For the moment do not really smear HepMC3
74+
HepMC3Product* productcopy3 = new HepMC3Product(genevt3);
75+
ROOT::Math::XYZTVector VertexShift = vertexShift(engine);
76+
productcopy3->applyVtxGen(HepMC3::FourVector(VertexShift.x(), VertexShift.y(), VertexShift.z(), VertexShift.t()));
77+
78+
if (GetInvLorentzBoost() != nullptr) {
79+
TMatrixD tmplorentz(*GetInvLorentzBoost());
80+
TMatrixD p4(4, 1);
81+
p4(0, 0) = 1.;
82+
p4(1, 0) = 1.;
83+
p4(2, 0) = 1.;
84+
p4(3, 0) = 1.; // Check if the boost matrix is not trivial
85+
TMatrixD p4lab(4, 1);
86+
p4lab = tmplorentz * p4;
87+
if (p4lab(0, 0) - p4(0, 0) != 0. || p4lab(1, 0) - p4(1, 0) != 0. || p4lab(2, 0) - p4(2, 0) != 0. ||
88+
p4lab(3, 0) - p4(3, 0) != 0.) { // not trivial:
89+
productcopy3->boostToLab(GetInvLorentzBoost(), "vertex");
90+
productcopy3->boostToLab(GetInvLorentzBoost(), "momentum");
91+
}
92+
}
93+
8094
std::unique_ptr<edm::HepMC3Product> HepMC3Evt(productcopy3);
8195
evt.put(std::move(HepMC3Evt));
8296
}

IOMC/EventVertexGenerators/src/BeamProfileVtxGenerator.cc

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <CLHEP/Random/RandGaussQ.h>
1212
#include <CLHEP/Units/SystemOfUnits.h>
1313
#include <CLHEP/Units/GlobalPhysicalConstants.h>
14-
#include "HepMC/SimpleVector.h"
1514

1615
#include <fstream>
1716
#include <string>
@@ -80,8 +79,7 @@ BeamProfileVtxGenerator::BeamProfileVtxGenerator(const edm::ParameterSet& p) : B
8079

8180
BeamProfileVtxGenerator::~BeamProfileVtxGenerator() {}
8281

83-
//Hep3Vector * BeamProfileVtxGenerator::newVertex() {
84-
HepMC::FourVector BeamProfileVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) const {
82+
ROOT::Math::XYZTVector BeamProfileVtxGenerator::vertexShift(CLHEP::HepRandomEngine* engine) const {
8583
double aX, aY;
8684
if (ffile) {
8785
double r1 = engine->flat();
@@ -121,32 +119,33 @@ HepMC::FourVector BeamProfileVtxGenerator::newVertex(CLHEP::HepRandomEngine* eng
121119
/*
122120
static const double kRadToDeg ( 180./M_PI ) ;
123121
std::cout<<"theta = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
124-
<<fTheta*kRadToDeg<<", phi="<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
125-
<< fPhi*kRadToDeg <<", PSI="<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
126-
<<fPsi*kRadToDeg<<std::endl ;
127-
*/
122+
<<fTheta*kRadToDeg<<", phi="<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
123+
<< fPhi*kRadToDeg <<", PSI="<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
124+
<<fPsi*kRadToDeg<<std::endl ;
125+
*/
126+
128127
const HepGeom::RotateZ3D R1(fPhi - M_PI);
129128
const HepGeom::Point3D<double> xUnit(0, 1, 0);
130129
const HepGeom::Point3D<double> zUnit(0, 0, 1);
131130
const HepGeom::Transform3D RXRZ(HepGeom::Rotate3D(-fTheta, R1 * xUnit) * R1);
132131
const HepGeom::Transform3D TRF(HepGeom::Rotate3D(fPsi, RXRZ * zUnit) * RXRZ);
133132
/*
134133
std::cout<<"\n\n$$$$$$$$$$$Transform="
135-
<<" thetaZ = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
136-
<<TRF.getRotation().thetaZ()*kRadToDeg
137-
<<", phiZ = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
138-
<<TRF.getRotation().phiZ()*kRadToDeg
139-
<<", thetaY = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
140-
<<TRF.getRotation().thetaY()*kRadToDeg
141-
<<", phiY = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
142-
<<TRF.getRotation().phiY()*kRadToDeg
143-
<<", thetaX = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
144-
<<TRF.getRotation().thetaX()*kRadToDeg
145-
<<", phiX = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
146-
<<TRF.getRotation().phiX()*kRadToDeg
147-
<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
148-
<<TRF.getTranslation()<<std::endl ;
149-
*/
134+
<<" thetaZ = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
135+
<<TRF.getRotation().thetaZ()*kRadToDeg
136+
<<", phiZ = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
137+
<<TRF.getRotation().phiZ()*kRadToDeg
138+
<<", thetaY = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
139+
<<TRF.getRotation().thetaY()*kRadToDeg
140+
<<", phiY = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
141+
<<TRF.getRotation().phiY()*kRadToDeg
142+
<<", thetaX = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
143+
<<TRF.getRotation().thetaX()*kRadToDeg
144+
<<", phiX = "<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
145+
<<TRF.getRotation().phiX()*kRadToDeg
146+
<<std::setw(7) << std::setiosflags( std::ios::fixed ) << std::setprecision(5)
147+
<<TRF.getTranslation()<<std::endl ;
148+
*/
150149
const HepGeom::Vector3D<double> pv(TRF * av);
151150

152151
xp = pv.x();
@@ -156,7 +155,7 @@ HepMC::FourVector BeamProfileVtxGenerator::newVertex(CLHEP::HepRandomEngine* eng
156155

157156
LogDebug("VertexGenerator") << "BeamProfileVtxGenerator: Vertex created "
158157
<< "at (" << xp << ", " << yp << ", " << zp << ", " << fTimeOffset << ")";
159-
return HepMC::FourVector(xp, yp, zp, fTimeOffset);
158+
return ROOT::Math::XYZTVector(xp, yp, zp, fTimeOffset);
160159
;
161160
}
162161

IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ ________________________________________________________________________
2424
#include <CLHEP/Random/RandGaussQ.h>
2525
#include <CLHEP/Units/SystemOfUnits.h>
2626
#include <CLHEP/Units/GlobalPhysicalConstants.h>
27-
#include "HepMC/SimpleVector.h"
2827

2928
using CLHEP::cm;
3029
using CLHEP::ns;
@@ -72,7 +71,7 @@ void BetafuncEvtVtxGenerator::update(const edm::EventSetup& iEventSetup) {
7271
}
7372
}
7473

75-
HepMC::FourVector BetafuncEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* engine) const {
74+
ROOT::Math::XYZTVector BetafuncEvtVtxGenerator::vertexShift(CLHEP::HepRandomEngine* engine) const {
7675
double X, Y, Z;
7776

7877
double tmp_sigz = CLHEP::RandGaussQ::shoot(engine, 0., fSigmaZ);
@@ -91,7 +90,7 @@ HepMC::FourVector BetafuncEvtVtxGenerator::newVertex(CLHEP::HepRandomEngine* eng
9190
double tmp_sigt = CLHEP::RandGaussQ::shoot(engine, 0., fSigmaZ);
9291
double T = tmp_sigt + fTimeOffset;
9392

94-
return HepMC::FourVector(X, Y, Z, T);
93+
return ROOT::Math::XYZTVector(X, Y, Z, T);
9594
}
9695

9796
double BetafuncEvtVtxGenerator::BetaFunction(double z, double z0) const {

0 commit comments

Comments
 (0)