CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/PhysicsTools/PatUtils/src/ObjectResolutionCalc.cc

Go to the documentation of this file.
00001 //
00002 // $Id: ObjectResolutionCalc.cc,v 1.5 2008/10/08 19:19:25 gpetrucc Exp $
00003 //
00004 
00005 #include "PhysicsTools/PatUtils/interface/ObjectResolutionCalc.h"
00006 
00007 
00008 using namespace pat;
00009 
00010 
00011 // constructor with path; default should not be used
00012 ObjectResolutionCalc::ObjectResolutionCalc(TString resopath, bool useNN = false): useNN_(useNN) {
00013   edm::LogVerbatim("ObjectResolutionCalc") << ("ObjectResolutionCalc") << "=== Constructing a TopObjectResolutionCalc...";
00014   resoFile_ = new TFile(resopath);
00015   if (!resoFile_) edm::LogError("ObjectResolutionCalc") << "No resolutions fits for this file available: "<<resopath<<"...";
00016   TString  resObsName[8] = {"_ares","_bres","_cres","_dres","_thres","_phres","_etres","_etares"};
00017   
00018   TList* keys = resoFile_->GetListOfKeys();
00019   TIter nextitem(keys);
00020   TKey* key = NULL;
00021   while((key = (TKey*)nextitem())) {
00022     TString name = key->GetName();
00023     if(useNN_) {
00024       for(Int_t ro=0; ro<8; ro++) {
00025         TString obsName = resObsName[ro]; obsName += "_NN";
00026         if(name.Contains(obsName)){
00027           network_[ro] = (TMultiLayerPerceptron*) resoFile_->GetKey(name)->ReadObj();
00028         }
00029       }
00030     }
00031     else 
00032     { 
00033       if(name.Contains("etabin") && (!name.Contains("etbin"))) {
00034         for(int p=0; p<8; p++){
00035           if(name.Contains(resObsName[p])){
00036             TString etabin = name; etabin.Remove(0,etabin.Index("_")+1); etabin.Remove(0,etabin.Index("_")+7);
00037             int etaBin = etabin.Atoi();
00038             TH1F *tmp = (TH1F*) (resoFile_->GetKey(name)->ReadObj());
00039             fResVsEt_[p][etaBin] = (TF1)(*(tmp -> GetFunction("F_"+name)));
00040           }
00041         }
00042       }
00043     }
00044   }
00045   // find etabin values
00046   TH1F *tmpEta = (TH1F*) (resoFile_->GetKey("hEtaBins")->ReadObj());
00047   for(int b=1; b<=tmpEta->GetNbinsX(); b++) etaBinVals_.push_back(tmpEta->GetXaxis()->GetBinLowEdge(b));
00048   etaBinVals_.push_back(tmpEta->GetXaxis()->GetBinUpEdge(tmpEta->GetNbinsX()));
00049   edm::LogVerbatim("ObjectResolutionCalc") << "Found "<<etaBinVals_.size()-1  << " eta-bins with edges: ( ";
00050   for(size_t u=0; u<etaBinVals_.size(); u++) edm::LogVerbatim("ObjectResolutionCalc") << etaBinVals_[u]<<", ";
00051   edm::LogVerbatim("ObjectResolutionCalc") << "\b\b )"<<std::endl;
00052   
00053   edm::LogVerbatim("ObjectResolutionCalc") << "=== done." << std::endl;
00054 }
00055 
00056 
00057 // destructor
00058 ObjectResolutionCalc::~ObjectResolutionCalc() {
00059   delete resoFile_;
00060 }
00061 
00062 
00063 float ObjectResolutionCalc::obsRes(int obs, int eta, float eT) {
00064   if (useNN_) throw edm::Exception( edm::errors::LogicError, 
00065                                    "TopObjectResolutionCalc::obsRes should never be called when using a NN for resolutions." );
00066   float res = fResVsEt_[obs][eta].Eval(eT);
00067   return res;
00068 }
00069 
00070 
00071 int ObjectResolutionCalc::etaBin(float eta) {
00072   int nrEtaBins = etaBinVals_.size()-1;
00073   int bin = nrEtaBins-1;
00074   for(int i=0; i<nrEtaBins; i++) {
00075     if(fabs(eta) > etaBinVals_[i] && fabs(eta) < etaBinVals_[i+1]) bin = i;
00076   }
00077   return bin;
00078 }
00079 
00080 #if OBSOLETE
00081 void ObjectResolutionCalc::operator()(Electron & obj) {
00082   if (useNN_) {
00083     double v[2];
00084     v[0]=obj.et();
00085     v[1]=obj.eta();
00086     obj.setResolutionA(     network_[0]->Evaluate(0,v ));
00087     obj.setResolutionB(     network_[1]->Evaluate(0,v ));
00088     obj.setResolutionC(     network_[2]->Evaluate(0,v ));
00089     obj.setResolutionD(     network_[3]->Evaluate(0,v ));       
00090     obj.setResolutionTheta( network_[4]->Evaluate(0,v ));        
00091     obj.setResolutionPhi(   network_[5]->Evaluate(0,v ));       
00092     obj.setResolutionEt(    network_[6]->Evaluate(0,v ));       
00093     obj.setResolutionEta(   network_[7]->Evaluate(0,v ));
00094   } else {
00095     int bin = this->etaBin(obj.eta());
00096     obj.setResolutionA(     this->obsRes(0,bin,obj.et()) );
00097     obj.setResolutionB(     this->obsRes(1,bin,obj.et()) );
00098     obj.setResolutionC(     this->obsRes(2,bin,obj.et()) ); 
00099     obj.setResolutionD(     this->obsRes(3,bin,obj.et()) ); 
00100     obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );  
00101     obj.setResolutionPhi(   this->obsRes(5,bin,obj.et()) ); 
00102     obj.setResolutionEt(    this->obsRes(6,bin,obj.et()) ); 
00103     obj.setResolutionEta(   this->obsRes(7,bin,obj.et()) );
00104   }
00105 }
00106 
00107 
00108 void ObjectResolutionCalc::operator()(Muon & obj) {
00109   if (useNN_) {
00110     double v[2];
00111     v[0]=obj.et();
00112     v[1]=obj.eta();
00113     obj.setResolutionA(     network_[0]->Evaluate(0,v ));
00114     obj.setResolutionB(     network_[1]->Evaluate(0,v ));
00115     obj.setResolutionC(     network_[2]->Evaluate(0,v ));
00116     obj.setResolutionD(     network_[3]->Evaluate(0,v ));       
00117     obj.setResolutionTheta( network_[4]->Evaluate(0,v ));        
00118     obj.setResolutionPhi(   network_[5]->Evaluate(0,v ));       
00119     obj.setResolutionEt(    network_[6]->Evaluate(0,v ));       
00120     obj.setResolutionEta(   network_[7]->Evaluate(0,v ));
00121   } else {
00122     int bin = this->etaBin(obj.eta());
00123     obj.setResolutionA(     this->obsRes(0,bin,obj.et()) );
00124     obj.setResolutionB(     this->obsRes(1,bin,obj.et()) );
00125     obj.setResolutionC(     this->obsRes(2,bin,obj.et()) ); 
00126     obj.setResolutionD(     this->obsRes(3,bin,obj.et()) ); 
00127     obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );  
00128     obj.setResolutionPhi(   this->obsRes(5,bin,obj.et()) ); 
00129     obj.setResolutionEt(    this->obsRes(6,bin,obj.et()) ); 
00130     obj.setResolutionEta(   this->obsRes(7,bin,obj.et()) );
00131   }
00132 }
00133 
00134 
00135 void ObjectResolutionCalc::operator()(Jet & obj) {
00136   if (useNN_) {
00137     double v[2];
00138     v[0]=obj.et();
00139     v[1]=obj.eta();
00140     obj.setResolutionA(     network_[0]->Evaluate(0,v ));
00141     obj.setResolutionB(     network_[1]->Evaluate(0,v ));
00142     obj.setResolutionC(     network_[2]->Evaluate(0,v ));
00143     obj.setResolutionD(     network_[3]->Evaluate(0,v ));       
00144     obj.setResolutionTheta( network_[4]->Evaluate(0,v ));        
00145     obj.setResolutionPhi(   network_[5]->Evaluate(0,v ));       
00146     obj.setResolutionEt(    network_[6]->Evaluate(0,v ));       
00147     obj.setResolutionEta(   network_[7]->Evaluate(0,v ));
00148   } else {
00149     int bin = this->etaBin(obj.eta());
00150     obj.setResolutionA(     this->obsRes(0,bin,obj.et()) );
00151     obj.setResolutionB(     this->obsRes(1,bin,obj.et()) );
00152     obj.setResolutionC(     this->obsRes(2,bin,obj.et()) ); 
00153     obj.setResolutionD(     this->obsRes(3,bin,obj.et()) ); 
00154     obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );  
00155     obj.setResolutionPhi(   this->obsRes(5,bin,obj.et()) ); 
00156     obj.setResolutionEt(    this->obsRes(6,bin,obj.et()) ); 
00157     obj.setResolutionEta(   this->obsRes(7,bin,obj.et()) );
00158   }
00159 }
00160 
00161 
00162 void ObjectResolutionCalc::operator()(MET & obj) {
00163   if (useNN_) {
00164     double v[2];
00165     v[0]=obj.et();
00166     v[1]=obj.eta();
00167     obj.setResolutionA(     network_[0]->Evaluate(0,v ));
00168     obj.setResolutionB(     network_[1]->Evaluate(0,v ));
00169     obj.setResolutionC(     network_[2]->Evaluate(0,v ));
00170     obj.setResolutionD(     network_[3]->Evaluate(0,v ));
00171     obj.setResolutionTheta( 1000000.  );                        // Total freedom        
00172     obj.setResolutionPhi(   network_[5]->Evaluate(0,v ));       
00173     obj.setResolutionEt(    network_[6]->Evaluate(0,v ));       
00174     obj.setResolutionEta(   1000000.  );                        // Total freedom
00175   } else {
00176     obj.setResolutionA(     this->obsRes(0,0,obj.et())  );
00177     obj.setResolutionC(     this->obsRes(1,0,obj.et())  );
00178     obj.setResolutionB(     this->obsRes(2,0,obj.et())  );
00179     obj.setResolutionD(     this->obsRes(3,0,obj.et())  );
00180     obj.setResolutionTheta( 1000000.  );                        // Total freedom
00181     obj.setResolutionPhi(   this->obsRes(5,0,obj.et())  );
00182     obj.setResolutionEt(    this->obsRes(6,0,obj.et())  );
00183     obj.setResolutionEta(   1000000.  );                        // Total freedom
00184   }
00185 }
00186 
00187 
00188 void ObjectResolutionCalc::operator()(Tau & obj) {
00189   if (useNN_) {
00190     double v[2];
00191     v[0]=obj.et();
00192     v[1]=obj.eta();
00193     obj.setResolutionA(     network_[0]->Evaluate(0,v ));
00194     obj.setResolutionB(     network_[1]->Evaluate(0,v ));
00195     obj.setResolutionC(     network_[2]->Evaluate(0,v ));
00196     obj.setResolutionD(     network_[3]->Evaluate(0,v ));       
00197     obj.setResolutionTheta( network_[4]->Evaluate(0,v ));        
00198     obj.setResolutionPhi(   network_[5]->Evaluate(0,v ));       
00199     obj.setResolutionEt(    network_[6]->Evaluate(0,v ));       
00200     obj.setResolutionEta(   network_[7]->Evaluate(0,v ));
00201   } else {
00202     int bin = this->etaBin(obj.eta());
00203     obj.setResolutionA(     this->obsRes(0,bin,obj.et()) );
00204     obj.setResolutionB(     this->obsRes(1,bin,obj.et()) );
00205     obj.setResolutionC(     this->obsRes(2,bin,obj.et()) ); 
00206     obj.setResolutionD(     this->obsRes(3,bin,obj.et()) ); 
00207     obj.setResolutionTheta( this->obsRes(4,bin,obj.et()) );  
00208     obj.setResolutionPhi(   this->obsRes(5,bin,obj.et()) ); 
00209     obj.setResolutionEt(    this->obsRes(6,bin,obj.et()) ); 
00210     obj.setResolutionEta(   this->obsRes(7,bin,obj.et()) );
00211   }
00212 }
00213 #endif