EventPrescale_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: EventPrescale
3 // Module Type: filter
4 // File: EventPrescale_module.cc
5 //
6 // Generated at Thu Feb 13 05:14:01 2014 by Matthew Tamsett using artmod
7 // from cetpkgsupport v1_04_02.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
18 
19 #include <iostream>
20 #include <memory>
21 
22 #include <stdlib.h> // for rand
23 #include <time.h> // for rand seed
24 //---------------------------------------------------------------------
25 namespace novaddt {
26  class EventPrescale;
27 }
28 //---------------------------------------------------------------------
30  public:
31  explicit EventPrescale(fhicl::ParameterSet const & p);
32  virtual ~EventPrescale();
33  bool filter(art::Event & e) override;
34  void endJob() override;
35  private:
36  // Declare member data here.
37  // Configuration options
38  unsigned int _prescale; ///< prescale factor (1 out of every this many passes are issued as real triggers)
39  std::string _mode; ///< prescale mode, can be either fixed or random
40  unsigned int _seed; ///< random number generator seed
41  unsigned int _nEvents = 0;
42  unsigned int _nAccepted = 0;
43 
44 };
45 //---------------------------------------------------------------------
47 : _prescale (p.get<unsigned int>("prescale" ))
48 , _mode (p.get<std::string >("mode" ))
49 , _seed (p.get<unsigned int>("seed", time(NULL)))
50 {
51  // Call appropriate Produces<>() functions here.
52  std::cout << "--- novaddt::EventPrescale instantiate" << std::endl;
53  std::cout << "\t prescale: " << _prescale << std::endl;
54  std::cout << "\t mode: " << _mode << std::endl;
55  std::cout << "\t seed: " << _seed << std::endl;
56 
57  // assert that the mode requested is configured
58  assert( (_mode == "fixed") || (_mode == "random") );
59 
60  // seed the random number generator, use a random default if not specified
61  // in the configuration file.
62  srand(_seed);
63 }
64 //---------------------------------------------------------------------
66 {
67  // Clean up dynamic memory and other resources here.
68 }
69 //---------------------------------------------------------------------
71 {
72  LOG_DEBUG("EventPrescale")<< "--- novaddt::EventPrescale filter. Event: "
73  << event.id().event()
74  << std::endl;
75  _nEvents++;
76 
77  // check prescale
78  if ( ((_mode=="fixed") && ( _nEvents%_prescale == _prescale-1)) ||
79  ((_mode=="random") && (rand()%_prescale == _prescale-1)) ){
80  _nAccepted++;
81  LOG_DEBUG("EventPrescale")<< "\t - not prescaled" << std::endl;
82  return true;
83  } // end of check on prescale
84 
85  // if not accepted by prescale return false
86  return false;
87 }
88 //---------------------------------------------------------------------
90 {
91  std::cout << "--- novaddt::EventPrescale endJob" << std::endl;
92  std::cout << "\tNumber of events seen: " << _nEvents << std::endl;
93  std::cout << "\tNumber of events accepted: " << _nAccepted << std::endl;
94 }
95 //---------------------------------------------------------------------
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
const char * p
Definition: xmltok.h:285
DEFINE_ART_MODULE(TestTMapFile)
unsigned int _seed
random number generator seed
EventPrescale(fhicl::ParameterSet const &p)
OStream cout
Definition: OStream.cxx:6
std::string _mode
prescale mode, can be either fixed or random
assert(nhit_max >=nhit_nbins)
bool filter(art::Event &e) override
Float_t e
Definition: plot.C:35
unsigned int _prescale
prescale factor (1 out of every this many passes are issued as real triggers)
enum BeamMode string