File indexing completed on 2024-04-06 12:23:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 #include <memory>
0050
0051
0052 #include "FWCore/Framework/interface/Frameworkfwd.h"
0053 #include "FWCore/Framework/interface/global/EDFilter.h"
0054
0055 #include "FWCore/Framework/interface/Event.h"
0056 #include "FWCore/Framework/interface/MakerMacros.h"
0057
0058 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0059
0060 #include "DataFormats/HepMCCandidate/interface/FlavorHistoryEvent.h"
0061 #include "DataFormats/HepMCCandidate/interface/FlavorHistory.h"
0062 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0063
0064 #include "PhysicsTools/HepMCCandAlgos/interface/FlavorHistorySelectorUtil.h"
0065
0066 #include "FWCore/Utilities/interface/Exception.h"
0067 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0068 #include "DataFormats/Math/interface/deltaR.h"
0069
0070 #include "PhysicsTools/HepMCCandAlgos/interface/FlavorHistorySelectorUtil.h"
0071
0072 #include <vector>
0073
0074
0075
0076
0077
0078 class FlavorHistoryFilter : public edm::global::EDFilter<> {
0079 public:
0080 typedef reco::FlavorHistory::FLAVOR_T flavor_type;
0081 typedef std::vector<int> flavor_vector;
0082
0083 explicit FlavorHistoryFilter(const edm::ParameterSet&);
0084
0085 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0086
0087 private:
0088 bool filter(edm::StreamID, ::edm::Event&, const edm::EventSetup&) const override;
0089
0090
0091 edm::EDGetTokenT<reco::FlavorHistoryEvent> bsrcToken_;
0092 edm::EDGetTokenT<reco::FlavorHistoryEvent> csrcToken_;
0093 int pathToSelect_;
0094 double dr_;
0095
0096 std::unique_ptr<reco::FlavorHistorySelectorUtil const> bb_me_;
0097 std::unique_ptr<reco::FlavorHistorySelectorUtil const> b_me_;
0098 std::unique_ptr<reco::FlavorHistorySelectorUtil const> cc_me_;
0099 std::unique_ptr<reco::FlavorHistorySelectorUtil const> c_me_;
0100 std::unique_ptr<reco::FlavorHistorySelectorUtil const> b_ps_;
0101 std::unique_ptr<reco::FlavorHistorySelectorUtil const> c_ps_;
0102 std::unique_ptr<reco::FlavorHistorySelectorUtil const>
0103 bb_me_comp_;
0104 std::unique_ptr<reco::FlavorHistorySelectorUtil const>
0105 cc_me_comp_;
0106 std::unique_ptr<reco::FlavorHistorySelectorUtil const>
0107 b_ps_comp_;
0108 std::unique_ptr<reco::FlavorHistorySelectorUtil const>
0109 c_ps_comp_;
0110
0111 };
0112
0113 using namespace edm;
0114 using namespace reco;
0115 using namespace std;
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128 FlavorHistoryFilter::FlavorHistoryFilter(const edm::ParameterSet& iConfig)
0129 : bsrcToken_(consumes<FlavorHistoryEvent>(iConfig.getParameter<edm::InputTag>("bsrc"))),
0130 csrcToken_(consumes<FlavorHistoryEvent>(iConfig.getParameter<edm::InputTag>("csrc"))) {
0131 pathToSelect_ = iConfig.getParameter<int>("pathToSelect");
0132
0133
0134
0135 dr_ = iConfig.getParameter<double>("dr");
0136 bool verbose(iConfig.getParameter<bool>("verbose"));
0137
0138
0139
0140
0141
0142 double dr0 = 0.0;
0143 double dr1 = dr_;
0144 double dr2 = 99999.0;
0145
0146
0147 std::vector<int> me_ids;
0148 me_ids.push_back(2);
0149 me_ids.push_back(3);
0150
0151
0152 std::vector<int> ps_ids;
0153 ps_ids.push_back(1);
0154
0155
0156 bb_me_ = std::make_unique<FlavorHistorySelectorUtil>(5, 2, me_ids, dr1, dr2, verbose);
0157
0158
0159 b_me_ = std::make_unique<FlavorHistorySelectorUtil>(5, 1, me_ids, dr0, dr0, verbose);
0160
0161
0162 cc_me_ = std::make_unique<FlavorHistorySelectorUtil>(4, 2, me_ids, dr1, dr2, verbose);
0163
0164
0165 c_me_ = std::make_unique<FlavorHistorySelectorUtil>(4, 1, me_ids, dr0, dr0, verbose);
0166
0167
0168 b_ps_ = std::make_unique<FlavorHistorySelectorUtil>(5, 1, ps_ids, dr0, dr1, verbose);
0169
0170
0171 c_ps_ = std::make_unique<FlavorHistorySelectorUtil>(4, 1, ps_ids, dr0, dr1, verbose);
0172
0173
0174 bb_me_comp_ = std::make_unique<FlavorHistorySelectorUtil>(5, 2, me_ids, dr0, dr1, verbose);
0175
0176
0177 cc_me_comp_ = std::make_unique<FlavorHistorySelectorUtil>(4, 2, me_ids, dr0, dr1, verbose);
0178
0179
0180 b_ps_comp_ = std::make_unique<FlavorHistorySelectorUtil>(5, 2, ps_ids, dr1, dr2, verbose);
0181
0182
0183 c_ps_comp_ = std::make_unique<FlavorHistorySelectorUtil>(4, 2, ps_ids, dr1, dr2, verbose);
0184
0185
0186
0187
0188 produces<unsigned int>();
0189 }
0190
0191 void FlavorHistoryFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0192 edm::ParameterSetDescription desc;
0193
0194 desc.add<edm::InputTag>("bsrc");
0195 desc.add<edm::InputTag>("csrc");
0196 desc.add<int>("pathToSelect", -1);
0197 desc.add<double>("dr");
0198 desc.add<bool>("verbose");
0199
0200 descriptions.addDefault(desc);
0201 }
0202
0203 bool FlavorHistoryFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0204
0205 Handle<FlavorHistoryEvent> bFlavorHistoryEvent;
0206 iEvent.getByToken(bsrcToken_, bFlavorHistoryEvent);
0207
0208 Handle<FlavorHistoryEvent> cFlavorHistoryEvent;
0209 iEvent.getByToken(csrcToken_, cFlavorHistoryEvent);
0210
0211 auto selection = std::make_unique<unsigned int>(0);
0212
0213
0214 unsigned int nb = bFlavorHistoryEvent->nb();
0215
0216 unsigned int nc = cFlavorHistoryEvent->nc();
0217
0218
0219 FlavorHistory::FLAVOR_T bFlavorSource = bFlavorHistoryEvent->flavorSource();
0220 FlavorHistory::FLAVOR_T cFlavorSource = cFlavorHistoryEvent->flavorSource();
0221 FlavorHistory::FLAVOR_T flavorSource = FlavorHistory::FLAVOR_NULL;
0222
0223 unsigned int highestFlavor = 0;
0224
0225 double dr = -1;
0226
0227
0228
0229
0230
0231
0232 if (bFlavorSource >= cFlavorSource) {
0233 flavorSource = bFlavorHistoryEvent->flavorSource();
0234 highestFlavor = bFlavorHistoryEvent->highestFlavor();
0235 dr = bFlavorHistoryEvent->deltaR();
0236 } else {
0237 flavorSource = cFlavorHistoryEvent->flavorSource();
0238 highestFlavor = cFlavorHistoryEvent->highestFlavor();
0239 dr = cFlavorHistoryEvent->deltaR();
0240 }
0241
0242 *selection = 0;
0243
0244 if (bb_me_->select(nb, nc, highestFlavor, flavorSource, dr))
0245 *selection = 1;
0246 else if (b_me_->select(nb, nc, highestFlavor, flavorSource, dr))
0247 *selection = 2;
0248 else if (cc_me_->select(nb, nc, highestFlavor, flavorSource, dr))
0249 *selection = 3;
0250 else if (c_me_->select(nb, nc, highestFlavor, flavorSource, dr))
0251 *selection = 4;
0252 else if (b_ps_->select(nb, nc, highestFlavor, flavorSource, dr))
0253 *selection = 5;
0254 else if (c_ps_->select(nb, nc, highestFlavor, flavorSource, dr))
0255 *selection = 6;
0256 else if (bb_me_comp_->select(nb, nc, highestFlavor, flavorSource, dr))
0257 *selection = 7;
0258 else if (cc_me_comp_->select(nb, nc, highestFlavor, flavorSource, dr))
0259 *selection = 8;
0260 else if (b_ps_comp_->select(nb, nc, highestFlavor, flavorSource, dr))
0261 *selection = 9;
0262 else if (c_ps_comp_->select(nb, nc, highestFlavor, flavorSource, dr))
0263 *selection = 10;
0264 else
0265 *selection = 11;
0266
0267 bool pass = false;
0268 if (pathToSelect_ > 0) {
0269 pass = (*selection > 0 && *selection == static_cast<unsigned int>(pathToSelect_));
0270 } else {
0271 pass = true;
0272 }
0273
0274 iEvent.put(std::move(selection));
0275
0276 return pass;
0277 }
0278
0279
0280 DEFINE_FWK_MODULE(FlavorHistoryFilter);