CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CalibAnalyzer.h
Go to the documentation of this file.
1 #ifndef CalibAnalyzer_h
2 #define CalibAnalyzer_h
3 
4 #include <memory>
5 #include <string>
6 #include <vector>
7 
8 #include "TH1F.h"
9 #include "TH2F.h"
10 
16 
20 
23 #include "Validation/RecoJets/interface/CompType.h"
24 #include "Validation/RecoJets/interface/NameScheme.h"
25 
26 
27 template <typename Ref, typename Rec, typename Alg>
29 
30  public:
31 
32  explicit CalibAnalyzer(const edm::ParameterSet&);
34 
35  private:
36 
37  virtual void beginJob();
38  virtual void analyze(const edm::Event&, const edm::EventSetup&);
39  virtual void endJob(){ alg_.summarize(); };
40 
41  void fill(const double& var, const double& val, const std::vector<double>& bins, const std::vector<TH1F*>& hists);
42 
43  private:
44 
48  int type_; // comparison type (0:ratio/1:rel diff)
49  int bins_; // number of bins in fit histograms
50  double min_, max_; // min/max of fit histograms
51  std::vector<double> binsPt_, binsEta_; // binning in pt/eta
52 
53  private:
54 
55  TH2F *recVsRef_;
56  TH1F *calPt_, *resPt_; // cal/res vs pt
57  std::vector<TH1F*> ktPt_; // calibration plots vs pt
58  TH1F *calEta_, *resEta_; // cal/res vs eta
59  std::vector<TH1F*> ktEta_; // calibration plots vs eta
60  std::vector<TH1F*> calEtaPt_, resEtaPt_; // cal/res vs eta and pt
61  std::vector<std::vector<TH1F*> > ktEtaPt_; // calibration plots vs eta and pt
62 
63  Alg alg_; // matching/balancing algorithm
64 };
65 
66 template <typename Ref, typename Rec, typename Alg>
68  recs_( cfg.getParameter<edm::InputTag>( "recs" ) ),
69  refs_( cfg.getParameter<edm::InputTag>( "refs" ) ),
70  hist_( cfg.getParameter<std::string > ( "hist" ) ),
71  type_( cfg.getParameter<int>( "type" ) ),
72  bins_( cfg.getParameter<int>( "bins" ) ),
73  min_ ( cfg.getParameter<double>( "min" ) ),
74  max_ ( cfg.getParameter<double>( "max" ) ),
75  binsPt_ ( cfg.getParameter<std::vector<double> >( "binsPt" ) ),
76  binsEta_( cfg.getParameter<std::vector<double> >( "binsEta" ) ),
77  alg_( cfg )
78 {
79 }
80 
81 template <typename Ref, typename Rec, typename Alg>
83 {
84  edm::Handle<Ref> refs;
85  evt.getByLabel(refs_, refs);
86 
87  edm::Handle<Rec> recs;
88  evt.getByLabel(recs_, recs);
89 
90  // do matching
91  std::map<unsigned int, unsigned int> matches=alg_(*refs, *recs);
92 
93  if( !matches.size()>0 )
94  edm::LogWarning ( "NoMatchOrBalance" )
95  << "No single match/balance found to any Rec object in collection";
96 
97  // fill comparison plots for matched jets
98  for(std::map<unsigned int, unsigned int>::const_iterator match=matches.begin();
99  match!=matches.end(); ++match){
100 
101  CompType cmp(type_);
102  double val=cmp((*refs)[match->first].pt(), (*recs)[match->second].pt());
103 
104  fill((*refs)[match->first].pt(), val, binsPt_, ktPt_ );// inclusive binned in pt
105  fill((*refs)[match->first].eta(), val, binsEta_, ktEta_);// inclusive binned in eta
106 
107  // differential in eta binned in pt
108  for(int idx=0; idx<((int)binsEta_.size()-1); ++idx)
109  if( (binsEta_[idx]<(*refs)[match->first].eta()) && ((*refs)[match->first].eta()<binsEta_[idx+1]) )
110  fill((*refs)[match->first].pt(), val, binsPt_, ktEtaPt_[idx] );
111  recVsRef_->Fill( TMath::Log10((*refs)[match->first].pt()), TMath::Log10((*recs)[match->second].pt()) );
112  }
113 }
114 
115 template <typename Ref, typename Rec, typename Alg>
116 void CalibAnalyzer<Ref, Rec, Alg>::fill(const double& var, const double& val, const std::vector<double>& bins, const std::vector<TH1F*>& hists)
117 {
118  for(unsigned int idx=0; idx<(bins.size()-1); ++idx){
119  if( (bins[idx]<var) && (var<bins[idx+1]) ){
120  hists[idx]->Fill( val );
121  }
122  }
123 }
124 
125 template <typename Ref, typename Rec, typename Alg>
127 {
128  if( hist_.empty() )
129  return;
130 
132  if( !fs )
133  throw edm::Exception( edm::errors::Configuration, "TFile Service is not registered in cfg file" );
134 
135  ofstream hist(hist_.c_str(), std::ios::out);
136  NameScheme val("val"), fit("fit"), cal("cal"), res("res");
137 
138  // book additional control histograms
139  recVsRef_= fs->make<TH2F>( val.name("recVsRef"),val.name("recVsRef"), 20, 1., 3., 20, 1., 3.);
140 
141  // book kt histograms differential in pt
142  for(int idx=0; idx<((int)binsPt_.size()-1); ++idx)
143  ktPt_.push_back( fs->make<TH1F>(fit.name(hist, "ktPt",idx), fit.name("kt",idx), bins_, min_, max_) );
144  calPt_= fs->make<TH1F>(cal.name(hist, "ktPt"), cal.name("calPt"), ((int)binsPt_.size()-1), &binsPt_[0]);
145  resPt_= fs->make<TH1F>(res.name(hist, "ktPt"), res.name("resPt"), ((int)binsPt_.size()-1), &binsPt_[0]);
146 
147  // book kt histograms differential in eta
148  for(int jdx=0; jdx<((int)binsEta_.size()-1); ++jdx)
149  ktEta_.push_back(fs->make<TH1F>(fit.name(hist, "ktEta",jdx),fit.name("kt",jdx), bins_, min_, max_) );
150  calEta_= fs->make<TH1F>(cal.name(hist, "ktEta"), cal.name("calEta"), ((int)binsEta_.size()-1), &binsEta_[0]);
151  resEta_= fs->make<TH1F>(res.name(hist, "ktEta"), res.name("resEta"), ((int)binsEta_.size()-1), &binsEta_[0]);
152 
153  // book kt histograms differential in eta and pt
154  for(int jdx=0; jdx<((int)binsEta_.size()-1); ++jdx){
155  std::vector<TH1F*> buffer;
156  calEtaPt_.push_back(fs->make<TH1F>(cal.name(hist,"ktEtaPt",jdx), cal.name("calEtaPt",jdx), ((int)binsPt_.size()-1), &binsPt_[0]));
157  resEtaPt_.push_back(fs->make<TH1F>(res.name(hist,"ktEtaPt",jdx), res.name("resEtaPt",jdx), ((int)binsPt_.size()-1), &binsPt_[0]));
158  for(int idx=0; idx<((int)binsPt_.size()-1); ++idx)
159  buffer.push_back( fs->make<TH1F>(fit.name(hist, "ktEtaPt",jdx,idx), fit.name("ktEtaPt",jdx,idx), bins_, min_, max_) );
160  ktEtaPt_.push_back(buffer);
161  }
162 }
163 
164 #endif
edm::InputTag recs_
Definition: CalibAnalyzer.h:45
CompType
supported comparison types
string fill
Definition: lumiContext.py:319
std::vector< double > binsPt_
Definition: CalibAnalyzer.h:51
std::string hist_
Definition: CalibAnalyzer.h:47
std::vector< TH1F * > calEtaPt_
Definition: CalibAnalyzer.h:60
void fill(const double &var, const double &val, const std::vector< double > &bins, const std::vector< TH1F * > &hists)
std::vector< std::vector< TH1F * > > ktEtaPt_
Definition: CalibAnalyzer.h:61
std::vector< double > binsEta_
Definition: CalibAnalyzer.h:51
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
edm::InputTag refs_
Definition: CalibAnalyzer.h:46
CalibAnalyzer(const edm::ParameterSet &)
Definition: CalibAnalyzer.h:67
tuple out
Definition: dbtoconf.py:99
virtual void beginJob()
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: CalibAnalyzer.h:82
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
TH2F * recVsRef_
Definition: CalibAnalyzer.h:55
std::vector< TH1F * > ktEta_
Definition: CalibAnalyzer.h:59
std::vector< TH1F * > ktPt_
Definition: CalibAnalyzer.h:57
T * make() const
make new ROOT object
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
std::vector< TH1F * > resEtaPt_
Definition: CalibAnalyzer.h:60
virtual void endJob()
Definition: CalibAnalyzer.h:39
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")