New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run3-TB51 Correct the beam momentum generator for HGCal TB studies #29114
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#include <ostream> | ||
#include "IOMC/ParticleGuns/interface/BeamMomentumGunProducer.h" | ||
|
||
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" | ||
|
@@ -13,6 +12,8 @@ | |
#include "CLHEP/Random/RandFlat.h" | ||
|
||
#include "TFile.h" | ||
#include <cmath> | ||
#include <ostream> | ||
|
||
namespace CLHEP { | ||
class HepRandomEngine; | ||
|
@@ -104,23 +105,42 @@ namespace edm { | |
double mass = pData->mass().value(); | ||
if (fVerbosity > 0) | ||
edm::LogVerbatim("BeamMomentumGun") << "PDGId: " << partID << " mass: " << mass; | ||
double xp = (xoff_ + mm2cm_ * parX_->at(ip)); | ||
double yp = (yoff_ + mm2cm_ * parY_->at(ip)); | ||
HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(xp, yp, zpos_)); | ||
double xp = (xoff_ * cm2mm_ + (-1) * parY_->at(ip)); // 90 degree rotation applied | ||
double yp = (yoff_ * cm2mm_ + parX_->at(ip)); // 90 degree rotation applied | ||
double zp = zpos_ * cm2mm_; | ||
HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(xp, yp, zp)); | ||
double pxGeV = MeV2GeV_ * parPx_->at(ip); | ||
double pyGeV = MeV2GeV_ * parPy_->at(ip); | ||
double pzGeV = MeV2GeV_ * parPz_->at(ip); | ||
double momRand2 = pxGeV * pxGeV + pyGeV * pyGeV + pzGeV * pzGeV; | ||
double energy = std::sqrt(momRand2 + mass * mass); | ||
double mom = std::sqrt(momRand2); | ||
HepMC::FourVector pGeV(pxGeV, pyGeV, pzGeV, energy); | ||
double ptheta = pGeV.theta(); | ||
double pphi = pGeV.phi(); | ||
double theta = CLHEP::RandFlat::shoot(engine, fMinTheta, fMaxTheta); | ||
double phi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi); | ||
double px = mom * sin(theta) * cos(phi); | ||
double py = mom * sin(theta) * sin(phi); | ||
double pz = mom * cos(theta); | ||
|
||
if (fVerbosity > 0) | ||
edm::LogVerbatim("BeamMomentumGun") << "px:py:pz " << px << ":" << py << ":" << pz; | ||
if (phi > M_PI) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are functions in https://github.com/cms-sw/cmssw/blob/master/DataFormats/Math/interface/deltaPhi.h to do this automatically, better to use them |
||
phi = -(2 * M_PI - phi); | ||
double newtheta = ptheta + theta; | ||
if (newtheta > M_PI && newtheta <= 2 * M_PI) | ||
newtheta = 2 * M_PI - newtheta; | ||
double newphi = pphi + phi; | ||
if (newphi > M_PI && newphi <= 2 * M_PI) | ||
newphi = -(2 * M_PI - newphi); | ||
else if (newphi < -M_PI && newphi >= -2 * M_PI) | ||
newphi = 2 * M_PI + newphi; | ||
double px = mom * sin(newtheta) * cos(newphi); | ||
double py = mom * sin(newtheta) * sin(newphi); | ||
double pz = mom * cos(newtheta); | ||
|
||
if (fVerbosity > 0) { | ||
edm::LogVerbatim("BeamMomentumGun") << "ptheta:pphi " << ptheta << ":" << pphi << "\ntheta:phi " << theta << ":" | ||
<< phi << "\nnewtheta:newphi " << newtheta << ":" << newphi; | ||
|
||
edm::LogVerbatim("BeamMomentumGun") | ||
<< "x:y:z [mm] " << xp << ":" << yp << ":" << zpos_ << "\npx:py:pz [GeV] " << px << ":" << py << ":" << pz; | ||
} | ||
|
||
HepMC::FourVector p(px, py, pz, energy); | ||
HepMC::GenParticle* part = new HepMC::GenParticle(p, partID, 1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this include should not be needed, please remove it