CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATJetUpdater.cc
Go to the documentation of this file.
1 //
2 
3 
5 
8 
12 
14 
17 
19 
20 #include <vector>
21 #include <memory>
22 #include <algorithm>
23 
24 
25 using namespace pat;
26 
27 
29  useUserData_(iConfig.exists("userData"))
30 {
31  // initialize configurables
32  jetsToken_ = consumes<edm::View<Jet> >(iConfig.getParameter<edm::InputTag>( "jetSource" ));
33  addJetCorrFactors_ = iConfig.getParameter<bool>( "addJetCorrFactors" );
34  jetCorrFactorsTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "jetCorrFactorsSource" ), [this](edm::InputTag const & tag){return mayConsume<edm::ValueMap<JetCorrFactors> >(tag);});
35  // Check to see if the user wants to add user data
36  if ( useUserData_ ) {
37  userDataHelper_ = PATUserDataHelper<Jet>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
38  }
39  // produces vector of jets
40  produces<std::vector<Jet> >();
41 }
42 
43 
44 PATJetUpdater::~PATJetUpdater() {
45 
46 }
47 
48 
50 {
51  // Get the vector of jets
53  iEvent.getByToken(jetsToken_, jets);
54 
55  // read in the jet correction factors ValueMap
56  std::vector<edm::ValueMap<JetCorrFactors> > jetCorrs;
57  if (addJetCorrFactors_) {
58  for ( size_t i = 0; i < jetCorrFactorsTokens_.size(); ++i ) {
60  iEvent.getByToken(jetCorrFactorsTokens_[i], jetCorr);
61  jetCorrs.push_back( *jetCorr );
62  }
63  }
64 
65  // loop over jets
66  std::auto_ptr< std::vector<Jet> > patJets ( new std::vector<Jet>() );
67 
68  bool first=true; // this is introduced to issue warnings only for the first jet
69  for (edm::View<Jet>::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++) {
70 
71  // construct the Jet from the ref -> save ref to original object
72  unsigned int idx = itJet - jets->begin();
73  edm::RefToBase<Jet> jetRef = jets->refAt(idx);
74  edm::Ptr<Jet> jetPtr = jets->ptrAt(idx);
75  Jet ajet(jetPtr);
76 
77  if (addJetCorrFactors_) {
78  unsigned int setindex = ajet.availableJECSets().size();
79  // Undo previous jet energy corrections
80  ajet.setP4(ajet.correctedP4(0));
81  // add additional JetCorrs to the jet
82  for ( unsigned int i=0; i<jetCorrFactorsTokens_.size(); ++i ) {
83  const JetCorrFactors& jcf = jetCorrs[i][jetRef];
84  // uncomment for debugging
85  // jcf.print();
86  ajet.addJECFactors(jcf);
87  }
88  std::vector<std::string> levels = jetCorrs[0][jetRef].correctionLabels();
89  if(std::find(levels.begin(), levels.end(), "L2L3Residual")!=levels.end()){
90  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("L2L3Residual"), JetCorrFactors::NONE, setindex);
91  }
92  else if(std::find(levels.begin(), levels.end(), "L3Absolute")!=levels.end()){
93  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("L3Absolute"), JetCorrFactors::NONE, setindex);
94  }
95  else{
96  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("Uncorrected"), JetCorrFactors::NONE, setindex);
97  if(first){
98  edm::LogWarning("L3Absolute not found") << "L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n"
99  << "of module " << jetCorrs[0][jetRef].jecSet() << " jets will remain"
100  << " uncorrected."; first=false;
101  }
102  }
103  }
104 
105  if ( useUserData_ ) {
106  userDataHelper_.add( ajet, iEvent, iSetup );
107  }
108 
109  patJets->push_back(ajet);
110  }
111 
112  // sort jets in pt
113  std::sort(patJets->begin(), patJets->end(), pTComparator_);
114 
115  // put genEvt in Event
116  iEvent.put(patJets);
117 
118 }
119 
120 // ParameterSet description for module
122 {
124  iDesc.setComment("PAT jet producer module");
125 
126  // input source
127  iDesc.add<edm::InputTag>("jetSource", edm::InputTag("no default"))->setComment("input collection");
128 
129  // jet energy corrections
130  iDesc.add<bool>("addJetCorrFactors", true);
131  std::vector<edm::InputTag> emptyVInputTags;
132  iDesc.add<std::vector<edm::InputTag> >("jetCorrFactorsSource", emptyVInputTags);
133 
134  // Check to see if the user wants to add user data
135  edm::ParameterSetDescription userDataPSet;
137  iDesc.addOptional("userData", userDataPSet);
138 
139  descriptions.add("PATJetUpdater", iDesc);
140 }
141 
143 
void initializeJEC(unsigned int level, const JetCorrFactors::Flavor &flavor=JetCorrFactors::NONE, unsigned int set=0)
initialize the jet to a given JEC level during creation starting from Uncorrected ...
T getParameter(std::string const &) const
Assists in assimilating all pat::UserData into pat objects.
int i
Definition: DBlmapReader.cc:9
GreaterByPt< Jet > pTComparator_
Definition: PATJetUpdater.h:52
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
void addJECFactors(const JetCorrFactors &jec)
add more sets of energy correction factors
Definition: Jet.h:171
const std::vector< std::string > availableJECSets() const
-— methods for jet corrections -—
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
PATJetUpdater(const edm::ParameterSet &iConfig)
virtual void setP4(const LorentzVector &p4)
set 4-momentum
const LorentzVector & correctedP4(const std::string &level, const std::string &flavor="none", const std::string &set="") const
Definition: Jet.h:155
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
static void fillDescription(edm::ParameterSetDescription &iDesc)
void setComment(std::string const &value)
int iEvent
Definition: GenABIO.cc:230
Produces pat::Jet&#39;s.
Definition: PATJetUpdater.h:34
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
Class for the storage of jet correction factors.
vector< PseudoJet > jets
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
Analysis-level calorimeter jet class.
Definition: Jet.h:77
void add(std::string const &label, ParameterSetDescription const &psetDescription)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
pat::PATUserDataHelper< pat::Jet > userDataHelper_
Definition: PATJetUpdater.h:55
edm::EDGetTokenT< edm::View< Jet > > jetsToken_
Definition: PATJetUpdater.h:48
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
std::vector< edm::EDGetTokenT< edm::ValueMap< JetCorrFactors > > > jetCorrFactorsTokens_
Definition: PATJetUpdater.h:50