CMS 3D CMS Logo

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_( consumes<std::vector<PileupSummaryInfo> >(iConfig.getParameter<edm::InputTag>("pileupSummaryInfos")) ),
50 generatorInfo_( consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("generatorInfo")) )
51 {
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() || pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing()!=0)
70  {
71  bool found=false;
72  for(bunchCrossing=0; bunchCrossing<pileupSummaryInfos.product()->size() && !found; ++bunchCrossing)
73  {
74  if( pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing() == 0 ){
75  found=true;
76  bunchCrossing--;
77  }
78  }
79  if(!found){
80  edm::LogInfo("RemovePileUpDominatedEventsGen") << "In-time pile-up not found!" << endl;
81  return true;
82  }
83  }
84 
85 // cout << "Using "<<bunchCrossing<<endl;
86 // cout << "pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing() "<<pileupSummaryInfos.product()->at(bunchCrossing).getBunchCrossing()<<endl;
87 
88  //get the PU pt-hat max
89  float signal_pT_hat = -1;
90  float pu_pT_hat_max = -1;
91 
92  PileupSummaryInfo puSummary_onTime = pileupSummaryInfos.product()->at(bunchCrossing);
93  for(const auto& pu_pT_hat : puSummary_onTime.getPU_pT_hats()) if (pu_pT_hat>pu_pT_hat_max) pu_pT_hat_max = pu_pT_hat;
94 
95  //get the signal pt-hat
96  signal_pT_hat = generatorInfo->qScale();
97 
98  //save PU - signal pt-hat
99  std::unique_ptr<float> pOut(new float());
100  *pOut=signal_pT_hat-pu_pT_hat_max;
101  iEvent.put(std::move(pOut));
102 
103  //filter the event
104  if (signal_pT_hat>pu_pT_hat_max) return true;
105  return false;
106 }
107 
108 
111  desc.add<edm::InputTag> ("pileupSummaryInfos",edm::InputTag("addPileupInfo"));
112  desc.add<edm::InputTag> ("generatorInfo",edm::InputTag("generator"));
113  descriptions.addDefault(desc);
114 }
115 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupSummaryInfos_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bool filter(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDGetTokenT< GenEventInfoProduct > generatorInfo_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
double qScale() const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
RemovePileUpDominatedEventsGen(const edm::ParameterSet &)
const std::vector< float > & getPU_pT_hats() const
T const * product() const
Definition: Handle.h:74
HLT enums.
~RemovePileUpDominatedEventsGen() override
def move(src, dest)
Definition: eostools.py:511