CMS 3D CMS Logo

Public Member Functions | Private Attributes

pat::ObjectResolutionCalc Class Reference

Class to calculate MC resolutions for pat objects. More...

#include <PhysicsTools/PatUtils/interface/ObjectResolutionCalc.h>

List of all members.

Public Member Functions

int etaBin (float eta)
 ObjectResolutionCalc ()
 ObjectResolutionCalc (TString resopath, bool useNN)
float obsRes (int obs, int eta, float eT)
template<typename T >
void operator() (T &obj)
 ~ObjectResolutionCalc ()

Private Attributes

std::vector< float > etaBinVals_
TF1 fResVsEt_ [10][10]
TMultiLayerPerceptron * network_ [10]
TFile * resoFile_
bool useNN_

Detailed Description

Class to calculate MC resolutions for pat objects.

Author:
Jan Heyninck, Petra Van Mulders, Christophe Delaere
Version:
Id:
ObjectResolutionCalc.h,v 1.5 2008/10/08 19:19:25 gpetrucc Exp

Definition at line 40 of file ObjectResolutionCalc.h.


Constructor & Destructor Documentation

pat::ObjectResolutionCalc::ObjectResolutionCalc ( )
ObjectResolutionCalc::ObjectResolutionCalc ( TString  resopath,
bool  useNN = false 
)

Definition at line 12 of file ObjectResolutionCalc.cc.

References b, etaBin(), etaBinVals_, fResVsEt_, combine::key, relativeConstraints::keys, mergeVDriftHistosByStation::name, network_, NULL, AlCaHLTBitMon_ParallelJobs::p, resoFile_, tmp, and useNN_.

                                                                              : useNN_(useNN) {
  edm::LogVerbatim("ObjectResolutionCalc") << ("ObjectResolutionCalc") << "=== Constructing a TopObjectResolutionCalc...";
  resoFile_ = new TFile(resopath);
  if (!resoFile_) edm::LogError("ObjectResolutionCalc") << "No resolutions fits for this file available: "<<resopath<<"...";
  TString  resObsName[8] = {"_ares","_bres","_cres","_dres","_thres","_phres","_etres","_etares"};
  
  TList* keys = resoFile_->GetListOfKeys();
  TIter nextitem(keys);
  TKey* key = NULL;
  while((key = (TKey*)nextitem())) {
    TString name = key->GetName();
    if(useNN_) {
      for(Int_t ro=0; ro<8; ro++) {
        TString obsName = resObsName[ro]; obsName += "_NN";
        if(name.Contains(obsName)){
          network_[ro] = (TMultiLayerPerceptron*) resoFile_->GetKey(name)->ReadObj();
        }
      }
    }
    else 
    { 
      if(name.Contains("etabin") && (!name.Contains("etbin"))) {
        for(int p=0; p<8; p++){
          if(name.Contains(resObsName[p])){
            TString etabin = name; etabin.Remove(0,etabin.Index("_")+1); etabin.Remove(0,etabin.Index("_")+7);
            int etaBin = etabin.Atoi();
            TH1F *tmp = (TH1F*) (resoFile_->GetKey(name)->ReadObj());
            fResVsEt_[p][etaBin] = (TF1)(*(tmp -> GetFunction("F_"+name)));
          }
        }
      }
    }
  }
  // find etabin values
  TH1F *tmpEta = (TH1F*) (resoFile_->GetKey("hEtaBins")->ReadObj());
  for(int b=1; b<=tmpEta->GetNbinsX(); b++) etaBinVals_.push_back(tmpEta->GetXaxis()->GetBinLowEdge(b));
  etaBinVals_.push_back(tmpEta->GetXaxis()->GetBinUpEdge(tmpEta->GetNbinsX()));
  edm::LogVerbatim("ObjectResolutionCalc") << "Found "<<etaBinVals_.size()-1  << " eta-bins with edges: ( ";
  for(size_t u=0; u<etaBinVals_.size(); u++) edm::LogVerbatim("ObjectResolutionCalc") << etaBinVals_[u]<<", ";
  edm::LogVerbatim("ObjectResolutionCalc") << "\b\b )"<<std::endl;
  
  edm::LogVerbatim("ObjectResolutionCalc") << "=== done." << std::endl;
}
ObjectResolutionCalc::~ObjectResolutionCalc ( )

Definition at line 58 of file ObjectResolutionCalc.cc.

References resoFile_.

                                            {
  delete resoFile_;
}

Member Function Documentation

int ObjectResolutionCalc::etaBin ( float  eta)

Definition at line 71 of file ObjectResolutionCalc.cc.

References newFWLiteAna::bin, etaBinVals_, and i.

Referenced by ObjectResolutionCalc().

                                          {
  int nrEtaBins = etaBinVals_.size()-1;
  int bin = nrEtaBins-1;
  for(int i=0; i<nrEtaBins; i++) {
    if(fabs(eta) > etaBinVals_[i] && fabs(eta) < etaBinVals_[i+1]) bin = i;
  }
  return bin;
}
float ObjectResolutionCalc::obsRes ( int  obs,
int  eta,
float  eT 
)

Definition at line 63 of file ObjectResolutionCalc.cc.

References eta(), Exception, fResVsEt_, edm::errors::LogicError, and useNN_.

                                                             {
  if (useNN_) throw edm::Exception( edm::errors::LogicError, 
                                   "TopObjectResolutionCalc::obsRes should never be called when using a NN for resolutions." );
  float res = fResVsEt_[obs][eta].Eval(eT);
  return res;
}
template<typename T >
void pat::ObjectResolutionCalc::operator() ( T obj) [inline]

Definition at line 59 of file ObjectResolutionCalc.h.

{ }

Member Data Documentation

std::vector<float> pat::ObjectResolutionCalc::etaBinVals_ [private]

Definition at line 65 of file ObjectResolutionCalc.h.

Referenced by etaBin(), and ObjectResolutionCalc().

TF1 pat::ObjectResolutionCalc::fResVsEt_[10][10] [private]

Definition at line 66 of file ObjectResolutionCalc.h.

Referenced by ObjectResolutionCalc(), and obsRes().

TMultiLayerPerceptron* pat::ObjectResolutionCalc::network_[10] [private]

Definition at line 67 of file ObjectResolutionCalc.h.

Referenced by ObjectResolutionCalc().

Definition at line 64 of file ObjectResolutionCalc.h.

Referenced by ObjectResolutionCalc(), and ~ObjectResolutionCalc().

Definition at line 68 of file ObjectResolutionCalc.h.

Referenced by ObjectResolutionCalc(), and obsRes().