Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion DataProducts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ cet_make_library(
src/CrystalId.cc
src/ExtMonFNALChipId.cc
src/ExtMonFNALPixelId.cc
src/FilterFraction.cc
src/GenVector.cc
src/PDGCode.cc
src/PrescaleFilterFraction.cc
src/STMChannel.cc
src/StrawEnd.cc
src/StrawId.cc
Expand All @@ -27,7 +29,7 @@ art_dictionary( NO_CHECK_CLASS_VERSION # For some reason this segfaults
Offline::DataProducts
)

if( BUILD_PYTHON_INTERFACE )
if( BUILD_PYTHON_INTERFACE )
mu2e_swig(DataProducts_swig src/pywrap.i DataProducts)
endif()

Expand Down
34 changes: 34 additions & 0 deletions DataProducts/inc/FilterFraction.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// art product to record the selection fraction of a filter. This product could be
// part of the raw data output (trigger prescale) or simulation presampling.
// Original author: Dave Brown (LBNL) 2026
//
#ifndef DataProducts_FilterFraction_hh
#define DataProducts_FilterFraction_hh
#include <cstdint>
namespace mu2e {
class FilterFraction {
public:
FilterFraction(uint64_t nseen, uint64_t npassed) : nseen_(nseen), npassed_(npassed) {}
// default
FilterFraction(){}
virtual ~FilterFraction(){}
// accessors
double filterFraction() const { return nseen_ > 0 ? double(npassed_)/double(nseen_) : 0.0; }
uint64_t nSeen() const { return nseen_; }
uint64_t nPassed() const { return npassed_; }
bool chained() const { return chained_; }
// concatenate multiple subruns in the same path
FilterFraction& operator +=(FilterFraction const& other);
FilterFraction operator + (FilterFraction const& other) const;
// concatenate with an upstream filter
FilterFraction chain(FilterFraction const& upstream) const;
private:
uint64_t nseen_ = 0; // number of events processed by this filter
uint64_t npassed_ = 0; // number of events passed by this filter
bool chained_ = false; // is this product the result of a chain of filters?
protected:
void setChained() { chained_ = true; }
};
}
#endif
26 changes: 26 additions & 0 deletions DataProducts/inc/PrescaleFilterFraction.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// art product to record the prescale filter fraction.
// Original author: Dave Brown (LBNL) 2026
//
#ifndef DataProducts_PrescaleFilterFraction_hh
#define DataProducts_PrescaleFilterFraction_hh
#include "Offline/DataProducts/inc/FilterFraction.hh"
namespace mu2e {
class PrescaleFilterFraction : public FilterFraction {
public:
PrescaleFilterFraction(uint32_t prescale, uint64_t nseen, uint64_t npassed) : FilterFraction(nseen, npassed), prescale_(prescale) {}
PrescaleFilterFraction(uint32_t prescale) : prescale_(prescale) {}
PrescaleFilterFraction(){}
// accessors
uint32_t prescale() const { return prescale_; }
double prescaleFraction() const { return 1.0/double(prescale_); }
// concatenate multiple subruns in the same path
PrescaleFilterFraction& operator +=(PrescaleFilterFraction const& other);
PrescaleFilterFraction operator + (PrescaleFilterFraction const& other) const;
// concatenate with an upstream prescale filter
PrescaleFilterFraction chain(PrescaleFilterFraction const& upstream) const;
private:
uint32_t prescale_ = 0; // number of events to process for 1 to pass (on average)
};
}
#endif
22 changes: 22 additions & 0 deletions DataProducts/src/FilterFraction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "Offline/DataProducts/inc/FilterFraction.hh"
#include <stdexcept>

namespace mu2e {
FilterFraction& FilterFraction::operator +=(FilterFraction const& other) {
nseen_ += other.nSeen();
npassed_ += other.nPassed();
return *this;
}
FilterFraction FilterFraction::operator + (FilterFraction const& other) const {
auto retval = *this;
retval += other;
return retval;
}
// concatenate with an upstream filter. The values must match!
FilterFraction FilterFraction::chain(FilterFraction const& upstream) const {
if(upstream.nPassed() != nSeen())throw std::runtime_error("Filter counts conflict");
auto retval = FilterFraction(upstream.nSeen(),nPassed());
retval.setChained();
return retval;
}
}
24 changes: 24 additions & 0 deletions DataProducts/src/PrescaleFilterFraction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "Offline/DataProducts/inc/PrescaleFilterFraction.hh"
#include <stdexcept>

namespace mu2e {
PrescaleFilterFraction& PrescaleFilterFraction::operator +=(PrescaleFilterFraction const& other) {
if(other.prescale() != prescale())throw std::runtime_error("Prescale values conflict");
// invoke base class
(static_cast<FilterFraction*>(this))->operator+=(other);
return *this;
}
PrescaleFilterFraction PrescaleFilterFraction::operator + (PrescaleFilterFraction const& other) const {
auto retval = *this;
retval += other;
return retval;
}
// concatenate with an upstream filter
PrescaleFilterFraction PrescaleFilterFraction::chain(PrescaleFilterFraction const& upstream) const {
if(upstream.nPassed() != nSeen())throw std::runtime_error("Filter counts conflict");
// the net prescale of a chain is the product of the individual prescale values
auto retval = PrescaleFilterFraction(prescale()*upstream.prescale(),upstream.nSeen(),nPassed());
retval.setChained();
return retval;
}
}
4 changes: 4 additions & 0 deletions DataProducts/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@
#include "Offline/DataProducts/inc/STMChannel.hh"
#include "Offline/DataProducts/inc/STMTestBeamEventInfo.hh"

// Filter
#include "Offline/DataProducts/inc/FilterFraction.hh"
#include "Offline/DataProducts/inc/PrescaleFilterFraction.hh"

// General
#include "Offline/DataProducts/inc/SurfaceId.hh"
9 changes: 8 additions & 1 deletion DataProducts/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,16 @@
<class name="mu2e::STMTestBeamEventInfo" />
<class name="art::Wrapper<mu2e::STMTestBeamEventInfo>" />

<!-- ********* general ********* -->
<!-- ********* filter ********* -->
<class name="mu2e::FilterFraction"/>
<class name="art::Wrapper<mu2e::FilterFraction>" />
<class name="mu2e::PrescaleFilterFraction"/>
<class name="art::Wrapper<mu2e::PrescaleFilterFraction>" />

<!-- ********* general ********* -->
<class name="mu2e::SurfaceIdDetail"/>
<class name="mu2e::SurfaceIdEnum"/>
<class name="mu2e::SurfaceId"/>


</lcgdict>
22 changes: 16 additions & 6 deletions Filters/src/RandomPrescaleFilter_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "Offline/SeedService/inc/SeedService.hh"
#include "CLHEP/Random/RandFlat.h"
#include "Offline/DataProducts/inc/PrescaleFilterFraction.hh"

namespace mu2e
{
Expand All @@ -22,7 +23,7 @@ namespace mu2e
public:

struct Config {
fhicl::Atom<float> nPrescale { fhicl::Name("nPrescale"), fhicl::Comment("Average number of events to process for 1 to pass the filter"), 1.0};
fhicl::Atom<unsigned> nPrescale { fhicl::Name("nPrescale"), fhicl::Comment("Average number of events to process for 1 to pass the filter")};
fhicl::Atom<int> debugLevel{ fhicl::Name("debugLevel"),fhicl::Comment("debug level"),0 };
};
using Parameters = art::EDFilter::Table<Config>;
Expand All @@ -39,22 +40,26 @@ namespace mu2e
RandomPrescaleFilter & operator = (RandomPrescaleFilter &&) = delete;

bool filter(art::Event & e) override;
virtual bool endRun(art::Run& run ) override;
bool endSubRun(art::SubRun& subrun ) override;

private:
art::RandomNumberGenerator::base_engine_t& engine_;
CLHEP::RandFlat randflat_;
int debug_;
unsigned nevt_, npass_;
uint32_t prescale_;
uint64_t nevt_, npass_;
};

RandomPrescaleFilter::RandomPrescaleFilter(const Parameters& conf) :
art::EDFilter{conf},
engine_(createEngine( art::ServiceHandle<SeedService>()->getSeed())),
randflat_( engine_, 0.0, conf().nPrescale() ),
debug_(conf().debugLevel()),
prescale_(conf().nPrescale()),
nevt_(0), npass_(0)
{}
{
produces<mu2e::FilterFraction,art::InSubRun>();
}

inline bool RandomPrescaleFilter::filter(art::Event & event)
{
Expand All @@ -64,10 +69,15 @@ namespace mu2e
return retval;
}

bool RandomPrescaleFilter::endRun( art::Run& run ) {
bool RandomPrescaleFilter::endSubRun( art::SubRun& subrun ) {
auto ff = std::make_unique<PrescaleFilterFraction>(prescale_, nevt_,npass_);
subrun.put(std::move(ff),"",art::fullSubRun());
if(debug_ > 0 && nevt_ > 0){
std::cout << moduleDescription().moduleLabel() << " passed " << npass_ << " events out of " << nevt_ << " for a ratio of " << float(npass_)/float(nevt_) << std::endl;
double frac = prescale_ > 0 ? 1.0/double(prescale_) : 0.0;
std::cout << moduleDescription().moduleLabel() << " passed " << npass_ << " events out of " << nevt_ << " for a ratio of " << float(npass_)/float(nevt_) << " with an expected fraction of " << frac << std::endl;
}
// reset
npass_ = 0; nevt_ = 0;
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions Print/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ cet_make_library(
src/CrvStepPrinter.cc
src/EventWindowMarkerPrinter.cc
src/GenParticlePrinter.cc
src/FilterFractionPrinter.cc
src/PrescaleFilterFractionPrinter.cc
src/HelixSeedPrinter.cc
src/KalSeedPrinter.cc
src/MCTrajectoryPrinter.cc
Expand Down
1 change: 0 additions & 1 deletion Print/fcl/printCosmicLivetime.fcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#
# print products with a moderate amount of output - includes cuts on energy
#
Expand Down
40 changes: 40 additions & 0 deletions Print/fcl/printFilterFraction.fcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# print products with a moderate amount of output - includes cuts on energy
#

#include "Offline/fcl/minimalMessageService.fcl"
#include "Offline/fcl/standardServices.fcl"

process_name : print

services : {
message : @local::default_message
GlobalConstantsService : { inputFile : "Offline/GlobalConstantsService/data/globalConstants_01.txt" }
}

physics :{
analyzers: {

printModule : {
module_type : PrintModule
PrintEvent : false
verbose : 0
PrintSubRun : true
FilterFractionPrinter : {
verbose : 1
}
PrescaleFilterFractionPrinter : {
verbose : 1
}
} # printModule


} # analyzers

ana : [ printModule ]
end_paths : [ ana ]

}

services.message.destinations.log.categories.ArtSummary.limit : 0
services.message.destinations.statistics.stats : @local::mf_null
37 changes: 37 additions & 0 deletions Print/inc/FilterFractionPrinter.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Utility class to print FilterFraction
//
#ifndef Print_inc_FilterFractionPrinter_hh
#define Print_inc_FilterFractionPrinter_hh

#include <cstring>
#include <iostream>

#include "Offline/DataProducts/inc/FilterFraction.hh"
#include "Offline/Print/inc/ProductPrinter.hh"
#include "art/Framework/Principal/Handle.h"
#include "canvas/Persistency/Common/Ptr.h"

namespace mu2e {

class FilterFractionPrinter : public ProductPrinter {
public:
FilterFractionPrinter() {}
FilterFractionPrinter(const Config& conf) : ProductPrinter(conf) {}

// all the ways to request a printout
void Print(art::Event const& event, std::ostream& os = std::cout) override;
void PrintSubRun(art::SubRun const& subrun,
std::ostream& os = std::cout) override;
void Print(const art::Handle<FilterFraction>& handle,
std::ostream& os = std::cout);
void Print(const art::ValidHandle<FilterFraction>& handle,
std::ostream& os = std::cout);
void Print(const mu2e::FilterFraction& obj, int ind = -1,
std::ostream& os = std::cout);
void PrintHeader(const std::string& tag, std::ostream& os = std::cout);
private:
};

} // namespace mu2e
#endif
37 changes: 37 additions & 0 deletions Print/inc/PrescaleFilterFractionPrinter.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Utility class to print PrescaleFilterFraction
//
#ifndef Print_inc_PrescaleFilterFractionPrinter_hh
#define Print_inc_PrescaleFilterFractionPrinter_hh

#include <cstring>
#include <iostream>

#include "Offline/DataProducts/inc/PrescaleFilterFraction.hh"
#include "Offline/Print/inc/ProductPrinter.hh"
#include "art/Framework/Principal/Handle.h"
#include "canvas/Persistency/Common/Ptr.h"

namespace mu2e {

class PrescaleFilterFractionPrinter : public ProductPrinter {
public:
PrescaleFilterFractionPrinter() {}
PrescaleFilterFractionPrinter(const Config& conf) : ProductPrinter(conf) {}

// all the ways to request a printout
void Print(art::Event const& event, std::ostream& os = std::cout) override;
void PrintSubRun(art::SubRun const& subrun,
std::ostream& os = std::cout) override;
void Print(const art::Handle<PrescaleFilterFraction>& handle,
std::ostream& os = std::cout);
void Print(const art::ValidHandle<PrescaleFilterFraction>& handle,
std::ostream& os = std::cout);
void Print(const mu2e::PrescaleFilterFraction& obj, int ind = -1,
std::ostream& os = std::cout);
void PrintHeader(const std::string& tag, std::ostream& os = std::cout);
private:
};

} // namespace mu2e
#endif
9 changes: 4 additions & 5 deletions Print/src/CosmicLivetimePrinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

void mu2e::CosmicLivetimePrinter::Print(art::Event const& event, std::ostream& os) {}

void mu2e::CosmicLivetimePrinter::PrintSubRun(art::SubRun const& subrun,
std::ostream& os) {
void mu2e::CosmicLivetimePrinter::PrintSubRun(art::SubRun const& subrun, std::ostream& os) {
if (verbose() < 1) return;
if (tags().empty()) {
// if a list of instances not specified, print all instances
Expand All @@ -19,15 +18,15 @@ void mu2e::CosmicLivetimePrinter::PrintSubRun(art::SubRun const& subrun,
auto vscl = subrun.getMany<art::Sampled<CosmicLivetime>>();
if(vscl.size() > 0){
for (auto const& scl : vscl){
std::cout << "SampledCosmicLivetime with tag " << scl->originalInputTag() << std::endl;
os << "SampledCosmicLivetime with tag " << scl->originalInputTag() << std::endl;
auto sinfomh = subrun.getHandle<art::SampledSubRunInfo>("SamplingInput");
if(sinfomh.isValid()){
auto const& sinfom = *sinfomh;
for(auto sinfoit = sinfom.begin(); sinfoit != sinfom.end(); ++sinfoit) {
if(sinfoit->first.find("Cosmic") != std::string::npos){
std::cout << "With SampledSubRunInfo entry for dataset " << sinfoit->first << " Has the following CosmicLivetimes: " << std::endl;
os << "With SampledSubRunInfo entry for dataset " << sinfoit->first << " Has the following CosmicLivetimes: " << std::endl;
for(auto const& sr : sinfoit->second.ids){
std::cout << sr << " : ";
os << sr << " : ";
auto sclp = scl->get(sinfoit->first,sr);
if(!sclp.empty()) Print(*sclp);
}
Expand Down
Loading