CMS 3D CMS Logo

AnalysisTasksAnalyzerJEC.cc
Go to the documentation of this file.
5 #include "TH2.h"
6 #include "TProfile.h"
10  Jets_(cfg.getParameter<edm::InputTag>("Jets")),
11  jecLevel_(cfg.getParameter<std::string>("jecLevel")),
12  patJetCorrFactors_(cfg.getParameter<std::string>("patJetCorrFactors")),
13  help_(cfg.getParameter<bool>("help"))
14 {
15 
16  hists_["Response" ] = fs.make<TH2F>("Response" , "response; #eta;p_{T}(reco)/p_{T}(gen)" , 5, -3.3, 3.3, 100, 0.4, 1.6);
17  jetInEvents_=0;
18 }
20  edm::BasicAnalyzer::BasicAnalyzer(cfg, fs),
21  Jets_(cfg.getParameter<edm::InputTag>("Jets")),
22  JetsToken_(iC.consumes<std::vector<pat::Jet> >(Jets_)),
23  jecLevel_(cfg.getParameter<std::string>("jecLevel")),
24  patJetCorrFactors_(cfg.getParameter<std::string>("patJetCorrFactors")),
25  help_(cfg.getParameter<bool>("help"))
26 {
27 
28  hists_["Response" ] = fs.make<TH2F>("Response" , "response; #eta;p_{T}(reco)/p_{T}(gen)" , 5, -3.3, 3.3, 100, 0.4, 1.6);
29  jetInEvents_=0;
30 }
33 {
34 
36  TFile* file=new TFile("myResponse"+TString(jecLevel_)+".root", "RECREATE");
37  TProfile* prof = hists_["Response" ]->ProfileX();
38  prof->Write();
39  file->Write();
40  file->Close();
41 }
43 void
45 {
46  // define what Jet you are using; this is necessary as FWLite is not
47  // capable of reading edm::Views
48  using pat::Jet;
49 
50  // Handle to the Jet collection
52  event.getByLabel(Jets_, Jets);
53 
54  // loop Jet collection and fill histograms
55  for(std::vector<Jet>::const_iterator jet_it=Jets->begin(); jet_it!=Jets->end(); ++jet_it){
56 
57 
59  if(help_==true){
60  if(jetInEvents_==0){
61  std::cout<<"\n \n number of available JEC sets: "<< jet_it->availableJECSets().size() << std::endl;
62  for(unsigned int k=0; k< jet_it->availableJECSets().size(); ++k){
63  std::cout<<"\n \n available JEC Set: "<< jet_it->availableJECSets()[k] << std::endl;
64  }
65  std::cout<<"\n \n*** You found out which JEC Sets exist! Now correct it in your config file."<<std::endl;
66  std::cout<<"\n \n number of available JEC levels "<< jet_it->availableJECLevels().size() << std::endl;
67  for(unsigned int k=0; k< jet_it->availableJECLevels().size(); ++k){
68  std::cout<<"\n \n available JEC: "<< jet_it->availableJECLevels(patJetCorrFactors_)[k] << std::endl;
69  }
70  std::cout<<"\n \n**** You did it correctly congratulations!!!! And you found out which JEC levels are saved within the jets. Correct this in your configuration file." <<std::endl;
71  }
72  }
73 
74  if(jet_it->genParticlesSize()>0){
75  hists_["Response" ]->Fill( jet_it->correctedJet(jecLevel_).eta(), jet_it->correctedJet(jecLevel_).pt()/ jet_it->genParticle(0)->pt());
76  std::cout<<"\n \n**** You did it correctly congratulations!!!! "<< std::endl;
77  }
78  jetInEvents_+=1;
79  }
80 }
AnalysisTasksAnalyzerJEC(const edm::ParameterSet &cfg, TFileDirectory &fs)
default constructor
edm::InputTag Jets_
input tag for mouns
Abstract base class for FWLite and EDM friendly analyzers.
Definition: HeavyIon.h:7
Definition: Jet.py:1
T * make(const Args &...args) const
make new ROOT object
edm::EDGetTokenT< std::vector< pat::Jet > > JetsToken_
void analyze(const edm::EventBase &event) override
everything that needs to be done during the event loop
~AnalysisTasksAnalyzerJEC() override
default destructor
int k[5][pyjets_maxn]
std::map< std::string, TH2 * > hists_
histograms
HLT enums.
Definition: event.py:1