![Logo](../../ATLAS-Logo-Square-Blue-RGB.png) |
ATLAS Offline Software
|
Go to the documentation of this file.
8 #include "CLHEP/Random/RandomEngine.h"
32 return StatusCode::FAILURE;
47 return StatusCode::FAILURE;
51 return StatusCode::SUCCESS;
60 return StatusCode::SUCCESS;
64 const EventContext& ctx)
const
68 rngWrapper->
setSeed( rngName, ctx );
79 ATH_MSG_ERROR(
"No TruthParticle collection with name " <<
"TruthGen" <<
" found in StoreGate!");
80 return StatusCode::FAILURE;
83 const EventContext& ctx = Gaudi::Hive::currentContext();
87 setFilterPassed(
false);
88 return StatusCode::FAILURE;
92 unsigned int nPart = xTruthParticleContainer->
size();
93 for (
unsigned int iPart = 0; iPart < nPart; ++iPart) {
97 if (!
part->isGenStable())
continue;
100 int pID =
part->pdgId();
104 const double pT =
part->pt();
105 const double eta =
part->eta();
110 " pdg id = " << pID <<
111 " charge = " << pCharge <<
" in acceptance");
125 double orig_event_weight = 1;
132 setFilterPassed(
false);
133 return StatusCode::SUCCESS;
147 double rnd = rndmGen->flat();
157 setFilterPassed(
true);
159 double final_event_weight = 1;
163 <<
" nch weight: " <<
weight
164 <<
" orig_event_weight: " << orig_event_weight
165 <<
" new_event_weight: " << final_event_weight);
167 return StatusCode::SUCCESS;
170 setFilterPassed(
false);
171 return StatusCode::SUCCESS;
190 if (
event->weights().empty()) {
191 event->weights().push_back( 1/
weight );
193 for (
auto &
w:
event-> weights()) {
198 event->add_attribute(
"filterWeight", std::make_shared<HepMC3::DoubleAttribute>(1/
weight));
210 return lhs.
x < rhs.
x;
214 return lhs.
y < rhs.
y;
219 const double dummy = -1;
222 auto lower = std::upper_bound(
points.begin(),
points.end(),
225 if(lower !=
points.begin()) lower--;
227 const auto &
x = lower->
x;
228 const auto &
y = lower->
y;;
229 const auto & slope = lower-> slope;;
232 const auto w_fc = (nch-
x)*slope +
y;
242 if(points.empty())
return -1;
244 const double dummy = -1;
253 if(min_item != max_item) {
254 const auto smallest = std::min_element(min_item, max_item,
comp_y);
255 minimum =
std::min(minimum, smallest->
y);
263 if(
x.size() < 2 ||
x.size() !=
y.size()) {
264 std::cout <<
"Spline not properly defined. SplineX, SplineY vectors are required to have at least 2 elements and same size.\n";
265 return StatusCode::FAILURE;
269 for(
size_t i=0;
i<
x.size()-1;
i++){
271 const auto & x0 =
x[
i];
272 const auto & y0 =
y[
i];
273 const auto &
x1 =
x[
i+1];
274 const auto &
y1 =
y[
i+1];
276 const auto dx =
x1 - x0;
277 const auto dy =
y1 - y0;
280 std::cout <<
"Spline not properly defined. SplineX is required to be monotonically increasing.\n";
281 return StatusCode::FAILURE;
287 return StatusCode::SUCCESS;
298 return StatusCode::FAILURE;
301 if(! first_event-> weights().
empty()) {
305 return StatusCode::SUCCESS;
def retrieve(aClass, aKey=None)
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
StatusCode initialize(std::vector< double > &x, std::vector< double > &y)
Scalar eta() const
pseudorapidity method
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
StatusCode event_weight(double &event_weight) const
read the event weight
std::vector< double > m_weight_fun_x
Spline points.
StatusCode accept(const xAOD::Muon *mu)
double value(int nch) const
get value for certain x
xAODChargedTracksWeightFilter(const std::string &name, ISvcLocator *pSvcLocator)
double m_nevents_selected
Number of events passing selection (weighted, orig weight)
std::vector< Point > points
n-1 spline points filled at initialization
bool comp_y(const Point &lhs, const Point &rhs)
double m_nevents_accepted
Number of events passing weight-filtering (weighted, origin weight)
Linear spline representation of a function used to calculate weights.
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
double get_nch_weight(int nch) const
get weight to filter and weight events
Base class for event generator filtering modules.
std::vector< double > m_weight_fun_y
StatusCode filterInitialize()
POOL::TEvent event(POOL::TEvent::kClassAccess)
::StatusCode StatusCode
StatusCode definition for legacy code.
Class describing a truth particle in the MC record.
void weight_event(double weight)
modify the event weight by weight
#define CHECK(...)
Evaluate an expression and check for errors.
double get_minimum(double min, double max) const
get minimum over certain range (requires initialization to extrapolate)
A wrapper class for event-slot-local random engines.
Linear spline representation of a function used to calculate weights.
double charge(const T &p)
xAODChargedTracksWeightFilter::Spline::Point Point
ServiceHandle< IAthRNGSvc > m_rndmSvc
Rndm generator service.
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
#define ATH_MSG_WARNING(x)
StatusCode filterFinalize()
CLHEP::HepRandomEngine * getRandomEngine(const std::string &streamName, const EventContext &ctx) const
bool comp_x(const Point &lhs, const Point &rhs)
size_type size() const noexcept
Returns the number of elements in the collection.
const HepMC::GenEvent * event_const() const
Access the current signal event (const)