Skip to content

Commit

Permalink
Implement an EDFilter to select events based on their bunch crossing
Browse files Browse the repository at this point in the history
Implement a global EDFilter "BunchCrossingFilter" to select events based
on their bunch cfrossing number (between 1 and 3564 inclusive).

Include a test configuration based on 2018 data.
  • Loading branch information
fwyzard committed Oct 26, 2018
1 parent d144f80 commit 618cd1f
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
46 changes: 46 additions & 0 deletions FWCore/Modules/src/BunchCrossingFilter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

#include "FWCore/Framework/interface/global/EDFilter.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

template <typename T>
std::vector<T> sorted(std::vector<T> v) {
std::sort(v.begin(), v.end());
return v;
}

namespace edm {
class BunchCrossingFilter : public global::EDFilter<> {
public:
explicit BunchCrossingFilter(ParameterSet const& config);

static void fillDescriptions(ConfigurationDescriptions& descriptions);
bool filter(StreamID, Event& event, EventSetup const&) const final;

private:
const std::vector<unsigned int> bunches_;
};

BunchCrossingFilter::BunchCrossingFilter(ParameterSet const& config) :
bunches_(sorted(config.getParameter<std::vector<unsigned int>>("bunches")))
{
}

bool BunchCrossingFilter::filter(StreamID, Event& event, EventSetup const&) const
{
return std::binary_search(bunches_.begin(), bunches_.end(), event.bunchCrossing());
}

void
BunchCrossingFilter::fillDescriptions(ConfigurationDescriptions& descriptions) {
ParameterSetDescription desc;
desc.add<std::vector<unsigned int>>("bunches", {})->setComment("List of bunch crossings for which events should be accepted [1-3564].");
descriptions.add("bunchCrossingFilter", desc);
}
}

using edm::BunchCrossingFilter;
DEFINE_FWK_MODULE(BunchCrossingFilter);
78 changes: 78 additions & 0 deletions FWCore/Modules/test/testBunchCrossingFilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# simple test for the BunchCrossingFilter

# colliding bunches in run 317435, fill 6759, scheme 25ns_2556b_2544_2215_2332_144bpi_20injV2:
# 81-128, 136-183
# 215-262, 270-317, 325-372,
# 404-451, 459-506, 514-561,
# 593-640, 648-695, 703-750,
# 786-833, 841-888,
# 920-967, 975-1022, 1030-1077,
# 1109-1156, 1164-1211, 1219-1266,
# 1298-1345, 1353-1400, 1408-1455,
# 1487-1534, 1542-1589, 1597-1644,
# 1680-1727, 1735-1782,
# 1814-1861, 1869-1916, 1924-1971,
# 2003-2050, 2058-2105, 2113-2160,
# 2192-2239, 2247-2294, 2302-2349,
# 2381-2428, 2436-2483, 2491-2538,
# 2574-2621, 2629-2676,
# 2708-2755, 2763-2810, 2818-2865,
# 2897-2944, 2952-2999, 3007-3054,
# 3086-3133, 3141-3188, 3196-3243,
# 3275-3322, 3330-3377, 3385-3432
# (see https://lpc.web.cern.ch/fillingSchemes/2018/25ns_2556b_2544_2215_2332_144bpi_20injV2.csv)

import FWCore.ParameterSet.Config as cms

process = cms.Process('TEST')

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(-1)
)

process.options = cms.untracked.PSet(
wantSummary = cms.untracked.bool(True)
)

process.load('FWCore.MessageService.MessageLogger_cfi')

# input data
process.source = cms.Source('PoolSource',
fileNames = cms.untracked.vstring('/store/data/Run2018B/ZeroBias/RAW/v1/000/317/435/00000/10FA8B3F-5A68-E811-A1D9-FA163E481185.root')
)

from FWCore.Modules.bunchCrossingFilter_cfi import bunchCrossingFilter as _bunchCrossingFilter

# empty input, do not select any bunch crossings
process.selectNone = _bunchCrossingFilter.clone(
bunches = cms.vuint32(),
)

# full range of possible bunch crossings [1,3564]
process.selectAll = _bunchCrossingFilter.clone(
bunches = cms.vuint32(range(1,3565))
)

# select bx 536
process.selectSingle = _bunchCrossingFilter.clone(
bunches = cms.vuint32(536)
)

# select the whole train 514-561
process.selectTrain = _bunchCrossingFilter.clone(
bunches = cms.vuint32(range(514,562))
)

# inverted to veto (non-colliding) bx 1
process.selectEmpty = _bunchCrossingFilter.clone(
bunches = cms.vuint32(1)
)

process.SelectNone = cms.Path( process.selectNone )
process.SelectAll = cms.Path( process.selectAll )
process.SelectSingle = cms.Path( process.selectSingle )
process.SelectTrain = cms.Path( process.selectTrain )
process.VetoEmpty = cms.Path( ~ process.selectEmpty )
process.VetoSingle = cms.Path( ~ process.selectSingle )
process.VetoTrain = cms.Path( ~ process.selectTrain )
process.SelectTrainButOne = cms.Path( process.selectTrain * ~ process.selectSingle )

0 comments on commit 618cd1f

Please sign in to comment.