Skip to content

Commit

Permalink
Removing output to cout and replacing CLHEP HepLorentzVector by the R…
Browse files Browse the repository at this point in the history
…OOT version
  • Loading branch information
mundim committed Dec 4, 2018
1 parent dba9d40 commit f2efc82
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,10 @@ class H_BeamParticle;
class H_RecRPObject;
class H_BeamLine;

namespace CLHEP
{
class HepLorentzVector;
}
class CTPPSFastTrackingProducer : public edm::stream::EDProducer<> {
public:
explicit CTPPSFastTrackingProducer(const edm::ParameterSet&);
~CTPPSFastTrackingProducer() override;
typedef CLHEP::HepLorentzVector LorentzVector;

private:
void beginStream(edm::StreamID) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Description: [one line class summary]
#include "Utilities/PPS/interface/PPSUtilities.h"
#include "CLHEP/Units/GlobalSystemOfUnits.h"
#include "CLHEP/Units/GlobalPhysicalConstants.h"
#include <CLHEP/Vector/LorentzVector.h>
#include "TLorentzVector.h"
// hector includes
#include "H_Parameters.h"
#include "H_BeamLine.h"
Expand Down Expand Up @@ -340,12 +340,12 @@ void CTPPSFastTrackingProducer::FastReco(int Direction,H_RecRPObject* station)
double py = partP*sin(theta)*sin(phi);
double pz = partP*cos(theta);
double e = sqrt(partP*partP+PPSTools::ProtonMassSQ);
LorentzVector p(px,py,pz,e);
TLorentzVector p(px,py,pz,e);
// Invert the Lorentz boost made to take into account the crossing angle during simulation
if (fCrossAngleCorr) PPSTools::LorentzBoost(p,"MC");
//Getting the Xi and t (squared four momentum transferred) of the reconstructed track
PPSTools::Get_t_and_xi(const_cast<CLHEP::HepLorentzVector*>(&p),t,xi);
double pxx = p.px(); double pyy = p.py(); double pzz = p.pz();
PPSTools::Get_t_and_xi(const_cast<TLorentzVector*>(&p),t,xi);
double pxx = p.Px(); double pyy = p.Py(); double pzz = p.Pz();
math::XYZVector momentum (pxx,pyy,pzz);
math::XYZPoint vertex (x0,y0,0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Description: [one line class summary]
#include "DataFormats/GeometryVector/interface/LocalVector.h"

#include "Utilities/PPS/interface/PPSUnitConversion.h"
#include <CLHEP/Vector/LorentzVector.h>

//
// class declaration
Expand All @@ -59,7 +58,6 @@ class CTPPSSimHitProducer : public edm::stream::EDProducer<> {
public:
explicit CTPPSSimHitProducer(const edm::ParameterSet&);
~CTPPSSimHitProducer() override;
typedef CLHEP::HepLorentzVector LorentzVector;

private:
void beginStream(edm::StreamID) override;
Expand Down Expand Up @@ -124,7 +122,7 @@ CTPPSSimHitProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
for(HepMC::GenEvent::vertex_const_iterator ivtx = Evt->vertices_begin();ivtx!=Evt->vertices_end();ivtx++) {
if ((*ivtx)->id()!=0) continue;
double prim_vtxZ=(*ivtx)->position().z()*mm_to_m; //in meters
// Get the vertices at the entrance of CTPPS and get the protons coming out of them (propagated by Hector)
// Get the vertices at the entrance of CTPPS and get the protons coming out of them (propagated by Hector)
for(HepMC::GenVertex::particles_out_const_iterator i=(*ivtx)->particles_out_const_begin(); i != (*ivtx)->particles_out_const_end();++i) {
int pid = (*i)->pdg_id();
if(pid!=2212) continue;
Expand All @@ -141,7 +139,7 @@ CTPPSSimHitProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
// Convert to ns for internal calculations.
const double c_light_s = 2.99792458e+11;// mm/s;
const double s_to_ns = 1.e9;
const double m_to_mm = 1.e3;
const double m_to_mm = 1.e3;
double x_tr1 = 0. , x_tr2 = 0. , x_tof = 0., y_tr1 = 0. , y_tr2 = 0. , y_tof = 0., z_tr1 = 0.;
double z_tr2 = fz_tracker2; //m
double z_tof = fz_timing; //m
Expand Down
6 changes: 3 additions & 3 deletions SimPPS/PPSSimTrackProducer/plugins/PPSSimTrackProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "SimDataFormats/Forward/interface/LHCTransportLink.h"
#include "SimDataFormats/Forward/interface/LHCTransportLinkContainer.h"

Expand Down Expand Up @@ -58,7 +58,7 @@ class PPSSimTrackProducer : public edm::stream::EDProducer<> {
// ----------member data ---------------------------
bool m_verbosity;
ProtonTransport* theTransporter = nullptr;
std::string m_InTag;
edm::InputTag m_InTag;
edm::EDGetTokenT<edm::HepMCProduct> m_InTagToken;

std::string m_transportMethod;
Expand All @@ -82,7 +82,7 @@ PPSSimTrackProducer::PPSSimTrackProducer(const edm::ParameterSet& iConfig)
{
//now do what ever other initialization is needed
// TransportHector
m_InTag = iConfig.getParameter<std::string>("HepMCProductLabel") ;
m_InTag = iConfig.getParameter<edm::InputTag>("HepMCProductLabel") ;
m_InTagToken = consumes<edm::HepMCProduct>(m_InTag);

m_verbosity = iConfig.getParameter<bool>("Verbosity");
Expand Down
3 changes: 2 additions & 1 deletion SimTransport/HectorProducer/src/HectorProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "IOMC/RandomEngine/src/TRandomAdaptor.h"

// SimpleConfigurable replacement
Expand All @@ -30,7 +31,7 @@
class TRandom3;

HectorProducer::HectorProducer(edm::ParameterSet const & p):
m_HepMC(consumes<edm::HepMCProduct>(p.getParameter<std::string>("HepMCProductLabel")))
m_HepMC(consumes<edm::HepMCProduct>(p.getParameter<edm::InputTag>("HepMCProductLabel")))
{
m_verbosity = p.getParameter<bool>("Verbosity");
m_FP420Transport = p.getParameter<bool>("FP420Transport");
Expand Down
2 changes: 0 additions & 2 deletions SimTransport/PPSProtonTransport/interface/HectorTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

namespace CLHEP
{
class HepLorentzVector;
class HepRandomEngine;
}

Expand All @@ -48,7 +47,6 @@ class H_BeamLine;

class HectorTransport: public ProtonTransport {
public:
typedef CLHEP::HepLorentzVector LorentzVector;

HectorTransport();
HectorTransport(const edm::ParameterSet & ps, bool verbosity);
Expand Down
6 changes: 3 additions & 3 deletions SimTransport/PPSProtonTransport/interface/ProtonTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "SimDataFormats/Forward/interface/LHCTransportLink.h"
#include <vector>
#include <map>
#include "TLorentzVector.h"

namespace CLHEP
{
class HepRandomEngine;
class HepLorentzVector;
}
class ProtonTransport {
public:
Expand All @@ -20,7 +20,7 @@ class ProtonTransport {
std::vector<LHCTransportLink>& getCorrespondenceMap() { return m_CorrespondenceMap; }
virtual void process(const HepMC::GenEvent * ev , const edm::EventSetup & es, CLHEP::HepRandomEngine * engine)=0;
void ApplyBeamCorrection(HepMC::GenParticle* p);
void ApplyBeamCorrection(CLHEP::HepLorentzVector& p);
void ApplyBeamCorrection(TLorentzVector& p);
void addPartToHepMC( HepMC::GenEvent * );
void clear();

Expand All @@ -38,7 +38,7 @@ class ProtonTransport {
double fCrossingAngle_56;

std::vector<LHCTransportLink> m_CorrespondenceMap;
std::map<unsigned int, CLHEP::HepLorentzVector*> m_beamPart;
std::map<unsigned int, TLorentzVector*> m_beamPart;
std::map<unsigned int, double> m_xAtTrPoint;
std::map<unsigned int, double> m_yAtTrPoint;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from SimTransport.PPSProtonTransport.TotemBeamConditions_cff import BeamConditionsGlobal
LHCTransport = cms.EDProducer('PPSSimTrackProducer',
TransportMethod = cms.string('Totem'),
HepMCProductLabel = cms.string('generatorSmeared'),
HepMCProductLabel = cms.InputTag('generatorSmeared'),
Verbosity = cms.bool(False),
sqrtS = cms.double(13.0e3),

Expand Down
22 changes: 13 additions & 9 deletions SimTransport/PPSProtonTransport/src/HectorTransport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <CLHEP/Units/GlobalSystemOfUnits.h>
#include <CLHEP/Units/GlobalPhysicalConstants.h>
#include <CLHEP/Random/RandGauss.h>
#include <CLHEP/Vector/LorentzVector.h>
#include "TLorentzVector.h"
//Hector headers
#include "H_BeamLine.h"
#include "H_BeamParticle.h"
Expand Down Expand Up @@ -44,7 +44,10 @@ HectorTransport::HectorTransport(const edm::ParameterSet & param, bool verbosity
fBeamYatIP = hector_par.getUntrackedParameter<double>("BeamYatIP",fVtxMeanY);
bApplyZShift = hector_par.getParameter<bool>("ApplyZShift");
//PPS

edm::LogInfo("ProtonTransport")
<<"=============================================================================\n"
<<" Bulding LHC Proton transporter based on HECTOR model\n"
<<"=============================================================================\n";
setBeamLine();
PPSTools::fBeamMomentum=fBeamMomentum;
PPSTools::fBeamEnergy=fBeamEnergy;
Expand All @@ -67,6 +70,7 @@ void HectorTransport::process( const HepMC::GenEvent * ev , const edm::EventSetu
}
bool HectorTransport::transportProton(const HepMC::GenParticle* gpart)
{
edm::LogInfo("ProtonTransport")<<"Starting proton transport using HECTOR method\n";
H_BeamParticle* h_p = nullptr;

double px,py,pz,e;
Expand All @@ -85,7 +89,7 @@ bool HectorTransport::transportProton(const HepMC::GenParticle* gpart)
int direction = (pz>0)?1:-1;

// Apply Beam and Crossing Angle Corrections
LorentzVector* p_out = new LorentzVector(px,py,pz,e);
TLorentzVector* p_out = new TLorentzVector(px,py,pz,e);
PPSTools::LorentzBoost(*p_out,"LAB");

ApplyBeamCorrection(*p_out);
Expand All @@ -96,17 +100,17 @@ bool HectorTransport::transportProton(const HepMC::GenParticle* gpart)
double ZforPosition = gpart->production_vertex()->position().z()/cm;//cm

h_p = new H_BeamParticle(mass,charge);
h_p->set4Momentum(-direction*p_out->px(), p_out->py(), fabs(p_out->pz()), p_out->e());
h_p->set4Momentum(-direction*p_out->Px(), p_out->Py(), fabs(p_out->Pz()), p_out->E());
// shift the beam position to the given beam position at IP (in cm)
XforPosition=(XforPosition-fVtxMeanX)+fBeamXatIP*mm_to_cm;
YforPosition=(YforPosition-fVtxMeanY)+fBeamYatIP*mm_to_cm;
//ZforPosition stays the same, move the closed orbit only in the X,Y plane
//
// shift the starting position of the track to Z=0 if configured so (all the variables below are still in cm)
if (bApplyZShift) {
double fCrossingAngle = (p_out->pz()>0)?fCrossingAngle_45:-fCrossingAngle_56;
XforPosition = XforPosition+(tan((long double)fCrossingAngle*urad)-((long double)p_out->px())/((long double)p_out->pz()))*ZforPosition;
YforPosition = YforPosition-((long double)p_out->py())/((long double)p_out->pz())*ZforPosition;
double fCrossingAngle = (p_out->Pz()>0)?fCrossingAngle_45:-fCrossingAngle_56;
XforPosition = XforPosition+(tan((long double)fCrossingAngle*urad)-((long double)p_out->Px())/((long double)p_out->Pz()))*ZforPosition;
YforPosition = YforPosition-((long double)p_out->Py())/((long double)p_out->Pz())*ZforPosition;
ZforPosition = 0.;
}

Expand Down Expand Up @@ -146,9 +150,9 @@ bool HectorTransport::transportProton(const HepMC::GenParticle* gpart)
//
h_p->propagate( _targetZ );

p_out = new LorentzVector(PPSTools::HectorParticle2LorentzVector(*h_p,direction));
p_out = new TLorentzVector(PPSTools::HectorParticle2LorentzVector(*h_p,direction));

p_out->setPx(direction*p_out->px());
p_out->SetPx(direction*p_out->Px());
x1_ctpps = direction*h_p->getX()*um_to_mm;
y1_ctpps = h_p->getY()*um_to_mm;

Expand Down
55 changes: 27 additions & 28 deletions SimTransport/PPSProtonTransport/src/ProtonTransport.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "SimTransport/PPSProtonTransport/interface/ProtonTransport.h"
#include "Utilities/PPS/interface/PPSUnitConversion.h"
#include "CLHEP/Random/RandGauss.h"
#include "CLHEP/Vector/LorentzVector.h"
#include "CLHEP/Units/GlobalSystemOfUnits.h"
#include "CLHEP/Units/GlobalPhysicalConstants.h"

Expand All @@ -10,15 +9,15 @@ ProtonTransport::ProtonTransport() {};
ProtonTransport::~ProtonTransport() {};
void ProtonTransport::clear()
{
for (std::map<unsigned int,CLHEP::HepLorentzVector* >::iterator it = m_beamPart.begin(); it != m_beamPart.end(); ++it ) delete (*it).second;
for (std::map<unsigned int,TLorentzVector* >::iterator it = m_beamPart.begin(); it != m_beamPart.end(); ++it ) delete (*it).second;
m_beamPart.clear(); m_xAtTrPoint.clear(); m_yAtTrPoint.clear();
};

void ProtonTransport::addPartToHepMC( HepMC::GenEvent * evt )
{
NEvent++;
m_CorrespondenceMap.clear();
std::map< unsigned int, CLHEP::HepLorentzVector* >::iterator it;
std::map< unsigned int, TLorentzVector* >::iterator it;

int direction=0;
HepMC::GenParticle * gpart;
Expand All @@ -40,12 +39,12 @@ void ProtonTransport::addPartToHepMC( HepMC::GenEvent * evt )
//
if(ddd == 0.) continue;
if(m_verbosity) {
LogDebug("HectorTransportEventProcessing") <<"HectorTransport:: x= "<< (*(m_xAtTrPoint.find(line))).second<< "\n"
<<"HectorTransport:: y= "<< (*(m_yAtTrPoint.find(line))).second<< "\n"
<<"HectorTransport:: z= "<< ddd * direction*m_to_mm << "\n"
<<"HectorTransport:: t= "<< time;
LogDebug("ProtonTransportEventProcessing") <<"ProtonTransport:: x= "<< (*(m_xAtTrPoint.find(line))).second<< "\n"
<<"ProtonTransport:: y= "<< (*(m_yAtTrPoint.find(line))).second<< "\n"
<<"ProtonTransport:: z= "<< ddd * direction*m_to_mm << "\n"
<<"ProtonTransport:: t= "<< time;
}
CLHEP::HepLorentzVector* p_out = (it).second;
TLorentzVector* p_out = (it).second;

HepMC::GenVertex * vert = new HepMC::GenVertex(
HepMC::FourVector( (*(m_xAtTrPoint.find(line))).second,
Expand All @@ -54,40 +53,40 @@ void ProtonTransport::addPartToHepMC( HepMC::GenEvent * evt )

gpart->set_status( 2 );
vert->add_particle_in( gpart );
vert->add_particle_out( new HepMC::GenParticle( HepMC::FourVector(p_out->px(),p_out->py(),p_out->pz(),p_out->e()), gpart->pdg_id(), 1, gpart->flow() )) ;
vert->add_particle_out( new HepMC::GenParticle( HepMC::FourVector(p_out->Px(),p_out->Py(),p_out->Pz(),p_out->E()), gpart->pdg_id(), 1, gpart->flow() )) ;
evt->add_vertex( vert );

int ingoing = (*vert->particles_in_const_begin())->barcode();
int outgoing = (*vert->particles_out_const_begin())->barcode();

LHCTransportLink theLink(ingoing,outgoing);
if (m_verbosity) LogDebug("HectorTransportEventProcessing") << "HectorTransport:addPartToHepMC: LHCTransportLink " << theLink;
if (m_verbosity) LogDebug("ProtonTransportEventProcessing") << "ProtonTransport:addPartToHepMC: LHCTransportLink " << theLink;
m_CorrespondenceMap.push_back(theLink);
}
}
void ProtonTransport::ApplyBeamCorrection(HepMC::GenParticle* p)
{
CLHEP::HepLorentzVector p_out;
p_out.setPx(p->momentum().px());
p_out.setPy(p->momentum().py());
p_out.setPz(p->momentum().pz());
p_out.setE(p->momentum().e());
TLorentzVector p_out;
p_out.SetPx(p->momentum().px());
p_out.SetPy(p->momentum().py());
p_out.SetPz(p->momentum().pz());
p_out.SetE(p->momentum().e());
ApplyBeamCorrection(p_out);
p->set_momentum(HepMC::FourVector(p_out.px(),p_out.py(),p_out.pz(),p_out.e()));
p->set_momentum(HepMC::FourVector(p_out.Px(),p_out.Py(),p_out.Pz(),p_out.E()));
}
void ProtonTransport::ApplyBeamCorrection(CLHEP::HepLorentzVector& p_out)
void ProtonTransport::ApplyBeamCorrection(TLorentzVector& p_out)
{
double theta = p_out.theta();
double thetax = atan(p_out.px()/fabs(p_out.pz()));
double thetay = atan(p_out.py()/fabs(p_out.pz()));
double energy = p_out.e();
double theta = p_out.Theta();
double thetax = atan(p_out.Px()/fabs(p_out.Pz()));
double thetay = atan(p_out.Py()/fabs(p_out.Pz()));
double energy = p_out.E();
double urad = 1e-6;

int direction = (p_out.pz()>0)?1:-1;
int direction = (p_out.Pz()>0)?1:-1;

if (p_out.pz()<0) theta=CLHEP::pi-theta;
if (p_out.Pz()<0) theta=CLHEP::pi-theta;

if (MODE==TransportMode::TOTEM) thetax+=(p_out.pz()>0)?fCrossingAngle_45*urad:fCrossingAngle_56*urad;
if (MODE==TransportMode::TOTEM) thetax+=(p_out.Pz()>0)?fCrossingAngle_45*urad:fCrossingAngle_56*urad;

double dtheta_x = (double)CLHEP::RandGauss::shoot(engine,0.,m_sigmaSTX);
double dtheta_y = (double)CLHEP::RandGauss::shoot(engine,0.,m_sigmaSTY);
Expand All @@ -98,8 +97,8 @@ void ProtonTransport::ApplyBeamCorrection(CLHEP::HepLorentzVector& p_out)
energy+=denergy;
double p = sqrt(pow(energy,2)-pow(CLHEP::proton_mass_c2/GeV,2));

p_out.setPx((double)p*sin(s_theta)*cos(s_phi));
p_out.setPy((double)p*sin(s_theta)*sin(s_phi));
p_out.setPz((double)p*(cos(s_theta))*direction);
p_out.setE(energy);
p_out.SetPx((double)p*sin(s_theta)*cos(s_phi));
p_out.SetPy((double)p*sin(s_theta)*sin(s_phi));
p_out.SetPz((double)p*(cos(s_theta))*direction);
p_out.SetE(energy);
}
Loading

0 comments on commit f2efc82

Please sign in to comment.