From 618cd1fdaa9e4667438bb8f50fc3d974a99d88b4 Mon Sep 17 00:00:00 2001 From: Andrea Bocci Date: Fri, 26 Oct 2018 16:11:13 +0200 Subject: [PATCH] Implement an EDFilter to select events based on their bunch crossing 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. --- FWCore/Modules/src/BunchCrossingFilter.cc | 46 +++++++++++ .../Modules/test/testBunchCrossingFilter.py | 78 +++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 FWCore/Modules/src/BunchCrossingFilter.cc create mode 100644 FWCore/Modules/test/testBunchCrossingFilter.py diff --git a/FWCore/Modules/src/BunchCrossingFilter.cc b/FWCore/Modules/src/BunchCrossingFilter.cc new file mode 100644 index 0000000000000..fd5f042330e7d --- /dev/null +++ b/FWCore/Modules/src/BunchCrossingFilter.cc @@ -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 +std::vector sorted(std::vector 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 bunches_; + }; + + BunchCrossingFilter::BunchCrossingFilter(ParameterSet const& config) : + bunches_(sorted(config.getParameter>("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>("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); diff --git a/FWCore/Modules/test/testBunchCrossingFilter.py b/FWCore/Modules/test/testBunchCrossingFilter.py new file mode 100644 index 0000000000000..e02d62a56ff33 --- /dev/null +++ b/FWCore/Modules/test/testBunchCrossingFilter.py @@ -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 )