CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RemovePileUpDominatedEventsGen.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RemovePileUpDominatedEventsGen/RemovePileUpDominatedEventsGen
4 // Class: RemovePileUpDominatedEventsGen
5 //
18 //
19 // Original Author: Silvio DONATO
20 // Created: Fri, 12 Dec 2014 12:48:57 GMT
21 //
22 //
23 
24 #include <memory>
25 
30 #include <iostream>
33 
35 public:
38  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
39 
40 private:
41  bool filter(edm::Event&, const edm::EventSetup&) override;
42 
45  unsigned int bunchCrossing;
46 };
47 
49  : pileupSummaryInfos_(
50  consumes<std::vector<PileupSummaryInfo> >(iConfig.getParameter<edm::InputTag>("pileupSummaryInfos"))),
51  generatorInfo_(consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("generatorInfo"))) {
52  bunchCrossing = 0;
53  produces<float>();
54 }
55 
57 
59  using namespace edm;
60  using namespace std;
61 
63  iEvent.getByToken(generatorInfo_, generatorInfo);
64 
65  edm::Handle<std::vector<PileupSummaryInfo> > pileupSummaryInfos;
66  iEvent.getByToken(pileupSummaryInfos_, pileupSummaryInfos);
67 
68  //find in-time pile-up
69  if (bunchCrossing >= pileupSummaryInfos.product()->size() ||
70  pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing() != 0) {
71  bool found = false;
72  for (bunchCrossing = 0; bunchCrossing < pileupSummaryInfos.product()->size() && !found; ++bunchCrossing) {
73  if (pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing() == 0) {
74  found = true;
75  bunchCrossing--;
76  }
77  }
78  if (!found) {
79  edm::LogInfo("RemovePileUpDominatedEventsGen") << "In-time pile-up not found!" << endl;
80  return true;
81  }
82  }
83 
84  // cout << "Using "<<bunchCrossing<<endl;
85  // cout << "pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing() "<<pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing()<<endl;
86 
87  //get the PU pt-hat max
88  float signal_pT_hat = -1;
89  float pu_pT_hat_max = -1;
90 
91  PileupSummaryInfo puSummary_onTime = pileupSummaryInfos.product()->at(bunchCrossing);
92  for (const auto& pu_pT_hat : puSummary_onTime.getPU_pT_hats())
93  if (pu_pT_hat > pu_pT_hat_max)
94  pu_pT_hat_max = pu_pT_hat;
95 
96  //get the signal pt-hat
97  signal_pT_hat = generatorInfo->qScale();
98 
99  //save PU - signal pt-hat
100  std::unique_ptr<float> pOut(new float());
101  *pOut = signal_pT_hat - pu_pT_hat_max;
102  iEvent.put(std::move(pOut));
103 
104  //filter the event
105  if (signal_pT_hat > pu_pT_hat_max)
106  return true;
107  return false;
108 }
109 
112  desc.add<edm::InputTag>("pileupSummaryInfos", edm::InputTag("addPileupInfo"));
113  desc.add<edm::InputTag>("generatorInfo", edm::InputTag("generator"));
114  descriptions.addDefault(desc);
115 }
116 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupSummaryInfos_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
bool filter(edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< GenEventInfoProduct > generatorInfo_
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
def move
Definition: eostools.py:511
ParameterDescriptionBase * add(U const &iLabel, T const &value)
RemovePileUpDominatedEventsGen(const edm::ParameterSet &)
Log< level::Info, false > LogInfo
~RemovePileUpDominatedEventsGen() override