Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40415 from michael-pitt/CMSSW_10_6_X
Add TaggedProton filter for analysis with tagged protons [10_6_X]
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
GeneratorInterface/Core/interface/TaggedProtonHepMCFilter.h
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef __TAGGEDPROTONHEPMCFILTER__ | ||
#define __TAGGEDPROTONHEPMCFILTER__ | ||
|
||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
|
||
#include "GeneratorInterface/Core/interface/BaseHepMCFilter.h" | ||
|
||
class TaggedProtonHepMCFilter : public BaseHepMCFilter { | ||
private: | ||
const int proton_PDGID_ = 2212; | ||
const int neutron_PDGID_ = 2112; | ||
const double xiMin_; | ||
const double xiMax_; | ||
const double oneOverbeamEnergy_; | ||
const int nProtons_; | ||
|
||
public: | ||
explicit TaggedProtonHepMCFilter(const edm::ParameterSet &); | ||
~TaggedProtonHepMCFilter() override = default; | ||
|
||
bool filter(const HepMC::GenEvent *evt) override; | ||
}; | ||
|
||
#endif |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "GeneratorInterface/Core/interface/TaggedProtonHepMCFilter.h" | ||
|
||
TaggedProtonHepMCFilter::TaggedProtonHepMCFilter(const edm::ParameterSet &iConfig) | ||
: xiMin_(iConfig.getParameter<double>("xiMin")), | ||
xiMax_(iConfig.getParameter<double>("xiMax")), | ||
oneOverbeamEnergy_(2.0 / iConfig.getParameter<double>("comEnergy")), | ||
nProtons_(iConfig.getParameter<int>("nProtons")) {} | ||
|
||
bool TaggedProtonHepMCFilter::filter(const HepMC::GenEvent *evt) { | ||
// Going through the particle list, and count good protons | ||
int nGoodProtons = 0; | ||
for (HepMC::GenEvent::particle_const_iterator particle = evt->particles_begin(); particle != evt->particles_end(); | ||
++particle) { | ||
if ((*particle)->pdg_id() == proton_PDGID_ && 1 == (*particle)->status()) { | ||
HepMC::FourVector p4 = (*particle)->momentum(); | ||
double xi = (1.0 - std::abs(p4.pz()) * oneOverbeamEnergy_); | ||
if (xi > xiMin_ && xi < xiMax_) | ||
nGoodProtons++; | ||
if (nGoodProtons >= nProtons_) | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |