Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
util::RemoveBeamSpills Class Reference

Reject triggers that are too close to beam spills. More...

Inheritance diagram for util::RemoveBeamSpills:
art::EDFilter art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDFilter
 
using WorkerType = WorkerT< EDFilter >
 
template<typename UserConfig >
using Table = ProducerBase::Table< UserConfig >
 

Public Member Functions

 RemoveBeamSpills (const fhicl::ParameterSet &pset)
 
virtual ~RemoveBeamSpills ()
 
void beginJob ()
 
bool filter (art::Event &evt)
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< Tconsumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TconsumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< TmayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TmayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Static Public Attributes

static constexpr bool Pass {true}
 
static constexpr bool Fail {false}
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Protected Attributes

std::string fRawDataLabel
 
double fVetoWindow
 
double fEpsilon
 
int fTotTrigs
 
int fRejTrigs
 
std::unique_ptr< BeamFolderfFolder
 
TH1 * fClosest
 

Detailed Description

Reject triggers that are too close to beam spills.

Definition at line 29 of file RemoveBeamSpills_module.cc.

Member Typedef Documentation

using art::EDFilter::ModuleType = EDFilter
inherited

Definition at line 37 of file EDFilter.h.

template<typename UserConfig >
using art::EDFilter::Table = ProducerBase::Table<UserConfig>
inherited

Definition at line 46 of file EDFilter.h.

using art::EDFilter::WorkerType = WorkerT<EDFilter>
inherited

Definition at line 38 of file EDFilter.h.

Constructor & Destructor Documentation

util::RemoveBeamSpills::RemoveBeamSpills ( const fhicl::ParameterSet pset)
explicit

Definition at line 50 of file RemoveBeamSpills_module.cc.

References fEpsilon, fFolder, fRawDataLabel, fVetoWindow, fhicl::ParameterSet::get(), and string.

51  : fTotTrigs(0), fRejTrigs(0)
52  {
53  fRawDataLabel = pset.get<std::string>("RawDataLabel");
54  fVetoWindow = pset.get<double>("VetoWindow");
55  fEpsilon = pset.get<double>("Epsilon");
56 
58  fFolder = ifbeam->getBeamFolder(pset.get<std::string>("Bundle"),
59  pset.get<std::string>("URL"),
60  pset.get<double>("DBTimeWindow"));
61 
62  // Look this far back in time for a spill, in seconds
63  fFolder->set_epsilon(fEpsilon);
64  }
std::unique_ptr< BeamFolder > fFolder
T get(std::string const &key) const
Definition: ParameterSet.h:231
enum BeamMode string
util::RemoveBeamSpills::~RemoveBeamSpills ( )
virtual

Definition at line 67 of file RemoveBeamSpills_module.cc.

References om::cout, allTimeWatchdog::endl, fRejTrigs, and fTotTrigs.

68  {
69  if(fTotTrigs)
70  std::cout << "RemoveBeamSpills: of " << fTotTrigs
71  << " triggers, rejected "
72  << fRejTrigs << " ("
73  << .01*((10000*fRejTrigs)/fTotTrigs) << "%)" << std::endl;
74  }
OStream cout
Definition: OStream.cxx:6

Member Function Documentation

void util::RemoveBeamSpills::beginJob ( )
virtual

Reimplemented from art::EDFilter.

Definition at line 77 of file RemoveBeamSpills_module.cc.

References fClosest, and art::TFileDirectory::make().

78  {
80  fClosest = tfs->make<TH1F>("closest", ";#Deltat (sec)", 2000, -.01, +.01);
81  }
T * make(ARGS...args) const
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 146 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

147 {
148  if (!moduleContext_)
149  return ProductToken<T>::invalid();
150 
151  consumables_[BT].emplace_back(ConsumableType::Product,
152  TypeID{typeid(T)},
153  it.label(),
154  it.instance(),
155  it.process());
156  return ProductToken<T>{it};
157 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 161 of file Consumer.h.

References T.

162 {
163  if (!moduleContext_)
164  return;
165 
166  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
167 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 171 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

172 {
173  if (!moduleContext_)
174  return ViewToken<T>::invalid();
175 
176  consumables_[BT].emplace_back(ConsumableType::ViewElement,
177  TypeID{typeid(T)},
178  it.label(),
179  it.instance(),
180  it.process());
181  return ViewToken<T>{it};
182 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited
CurrentProcessingContext const* art::EDFilter::currentContext ( ) const
protectedinherited
bool util::RemoveBeamSpills::filter ( art::Event evt)
virtual

Implements art::EDFilter.

Definition at line 84 of file RemoveBeamSpills_module.cc.

References ana::assert(), stan::math::ceil(), novadaq::timeutils::convertNovaTimeToUnixTime(), DEFINE_ART_MODULE(), geo::GeometryBase::DetId(), e, stan::math::fabs(), fFolder, fRawDataLabel, fRejTrigs, fTotTrigs, fVetoWindow, geom(), art::DataViewImpl::getByLabel(), art::Event::isRealData(), novadaq::cnv::kFARDET, string, confusionMatrixTree::t, and msf_helper::timespec.

85  {
86  // Doesn't apply to MC
87  if(!evt.isRealData()) return true;
88 
89  ++fTotTrigs;
90 
91  // Get trigger information to extract trigger time
93  evt.getByLabel(fRawDataLabel, trigv);
94  assert(!trigv->empty());
95  const rawdata::RawTrigger& trig = (*trigv)[0];
96 
97  // Get trigger time in unix time
98  struct timespec unixTime;
99  novadaq::timeutils::convertNovaTimeToUnixTime(trig.fTriggerTimingMarker_TimeStart, unixTime);
100  const double eventTime = unixTime.tv_sec + 1e-9*unixTime.tv_nsec;
101 
102  // If we're in the far detector, apply a time-of-flight correction to the trigger time
103  double tof = 0;
105  if (geom->DetId() == novadaq::cnv::kFARDET) tof = 810e3/3e8; // 810km/c
106  const double eventTimeCorrected = eventTime - tof;
107 
108  // Query the database to get NuMI trigger time. This query gives the EA9SNC value, which is
109  // a value stored to the database once per second that represents the time in seconds since
110  // the last trigger. Here we fetch both "ea9snc" (time since last trigger) and "time" (time
111  // value was stored to the database), and so "time - ea9snc" gives us the absolute time of
112  // the most recent trigger once per second.
113  //
114  // Note that we round the trigger time up to the closest second by calling ceil when querying
115  // the database below. This is intentional and makes ifbeam queries more robust. Querying the
116  // database can be a little fragile sometimes, and we can simplify it by making two assumptions:
117  //
118  // 1) the NuMI spill occurs at a rate less than 1Hz
119  // 2) Values are written to the database once per second, on the second
120  //
121  // If we round up the trigger time to the next second, then we'll pull out the value from the
122  // database that comes in at the _end_ of the second in which the trigger occurred. We then
123  // use the ea9snc value to look backwards in time to the most recent trigger; if the value is
124  // <1s then there's a chance it will coincide with the trigger and we veto it. The value stored
125  // in the database at the _start_ of the second in which the trigger occurs is not going to be
126  // useful to us, since the ea9snc value can only refer backwards in time to before our trigger
127  // occurred.
128 
129  double ea9snc, time;
130  try{
131  fFolder->GetNamedData(ceil(eventTimeCorrected), "G:EA9SNC@", &ea9snc, &time);
132  }
133  catch(std::exception& e) {
134  std::string err(e.what());
135  if (err.find("variable not found")) {
136  const time_t t = eventTimeCorrected;
137  mf::LogError("RemoveBeamSpills") << "Couldn't find anything in ifbeam db! Timestamp: "
138  << std::ctime(&t);
139  } else {
140  mf::LogError("RemoveBeamSpills") << "Exception encountered: " << e.what();
141  }
142  abort();
143  }
144  double deltaT = fabs(eventTimeCorrected - (time - ea9snc));
145  bool reject = deltaT < fVetoWindow;
146  if (reject) {
147  ++fRejTrigs;
148  mf::LogInfo("RemoveBeamSpills") << "Vetoed event with trigger time "
149  << std::fixed << eventTimeCorrected << " due to spill at time "
150  << time-ea9snc << " (deltaT = " << deltaT << ")" << std::defaultfloat;
151  }
152  return !reject;
153 
154  }
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool isRealData() const
Definition: Event.h:83
std::unique_ptr< BeamFolder > fFolder
bool convertNovaTimeToUnixTime(uint64_t const &inputNovaTime, struct timespec &outputUnixTime)
::xsd::cxx::tree::time< char, simple_type > time
Definition: Database.h:194
Far Detector at Ash River, MN.
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void geom(int which=0)
Definition: geom.C:163
assert(nhit_max >=nhit_nbins)
Float_t e
Definition: plot.C:35
fvar< T > ceil(const fvar< T > &x)
Definition: ceil.hpp:11
enum BeamMode string
seed_t art::EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited
template<typename PROD , BranchType B>
ProductID art::EDFilter::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 131 of file EDFilter.h.

References art::EDFilter::moduleDescription_.

Referenced by novaddt::HoughTrackMaker::create_associations().

132  {
133  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
134  instanceName);
135  }
ModuleDescription moduleDescription_
Definition: EDFilter.h:124
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 189 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

190 {
191  if (!moduleContext_)
192  return ProductToken<T>::invalid();
193 
194  consumables_[BT].emplace_back(ConsumableType::Product,
195  TypeID{typeid(T)},
196  it.label(),
197  it.instance(),
198  it.process());
199  return ProductToken<T>{it};
200 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 204 of file Consumer.h.

References T.

205 {
206  if (!moduleContext_)
207  return;
208 
209  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
210 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 214 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

215 {
216  if (!moduleContext_)
217  return ViewToken<T>::invalid();
218 
219  consumables_[BT].emplace_back(ConsumableType::ViewElement,
220  TypeID{typeid(T)},
221  it.label(),
222  it.instance(),
223  it.process());
224  return ViewToken<T>{it};
225 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID(), and string.

41  {
42  return true;
43  }
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Referenced by art::RootOutput::endJob().

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Member Data Documentation

constexpr bool art::EDFilter::Fail {false}
staticinherited

Definition at line 33 of file EDFilter.h.

Referenced by evgen::GENIEFilter::filter().

TH1* util::RemoveBeamSpills::fClosest
protected

Definition at line 46 of file RemoveBeamSpills_module.cc.

Referenced by beginJob().

double util::RemoveBeamSpills::fEpsilon
protected

Definition at line 40 of file RemoveBeamSpills_module.cc.

Referenced by RemoveBeamSpills().

std::unique_ptr<BeamFolder> util::RemoveBeamSpills::fFolder
protected

Definition at line 44 of file RemoveBeamSpills_module.cc.

Referenced by filter(), and RemoveBeamSpills().

std::string util::RemoveBeamSpills::fRawDataLabel
protected

Definition at line 39 of file RemoveBeamSpills_module.cc.

Referenced by filter(), and RemoveBeamSpills().

int util::RemoveBeamSpills::fRejTrigs
protected

Definition at line 42 of file RemoveBeamSpills_module.cc.

Referenced by filter(), and ~RemoveBeamSpills().

int util::RemoveBeamSpills::fTotTrigs
protected

Definition at line 42 of file RemoveBeamSpills_module.cc.

Referenced by filter(), and ~RemoveBeamSpills().

double util::RemoveBeamSpills::fVetoWindow
protected

Definition at line 40 of file RemoveBeamSpills_module.cc.

Referenced by filter(), and RemoveBeamSpills().

constexpr bool art::EDFilter::Pass {true}
staticinherited

Definition at line 32 of file EDFilter.h.

Referenced by evgen::GENIEFilter::filter().


The documentation for this class was generated from the following file: