CMS 3D CMS Logo

PFResolutionMap Class Reference

Resolution Map (resolution as a function of eta and E). More...

#include <RecoParticleFlow/PFClusterTools/interface/PFResolutionMap.h>

List of all members.

Public Member Functions

int FindBin (double eta, double e)
 extrapolation requires overloading of this function
const char * GetMapFile () const
double getRes (double eta, double phi, double e, int MapEta=-1)
 PFResolutionMap (const TH2D &h)
 create a map from a 2d histogram
 PFResolutionMap (const char *name, unsigned nbinseta, double mineta, double maxeta, unsigned nbinse, double mine, double maxe, double value=-1)
 create an empty map and initialize it
 PFResolutionMap (const char *name, const char *mapfile)
 create a map from text file mapfile
 PFResolutionMap ()
 default constructor
bool ReadMapFile (const char *mapfile)
 read text file
bool WriteMapFile (const char *mapfile)
 write text file is not const because mapFile_ will be updated

Private Member Functions

double dCrackPhi (double phi, double eta)
bool IsInAPhiCrack (double phi, double eta)
double minimum (double a, double b)

Private Attributes

std::string mapFile_

Static Private Attributes

static const unsigned lineSize_ = 10000

Friends

std::ostream & operator<< (std::ostream &out, const PFResolutionMap &rm)
 print this map


Detailed Description

Resolution Map (resolution as a function of eta and E).

Basically just a TH2D with text I/O

Author:
Colin Bernet
Todo:
extrapolation
Date:
January 2006

Definition at line 18 of file PFResolutionMap.h.


Constructor & Destructor Documentation

PFResolutionMap::PFResolutionMap (  )  [inline]

default constructor

Definition at line 23 of file PFResolutionMap.h.

00023 : TH2D() {}

PFResolutionMap::PFResolutionMap ( const char *  name,
const char *  mapfile 
)

create a map from text file mapfile

Definition at line 72 of file PFResolutionMap.cc.

References err, and ReadMapFile().

00072                                                                       { 
00073   SetTitle(name);
00074   GetXaxis()->SetTitle("#eta");
00075   GetYaxis()->SetTitle("E");
00076   if( ! ReadMapFile(mapfile) ) {
00077     string err = "PFResolutionMap::PFResolutionMap : cannot read file ";
00078     err += mapfile;
00079     throw invalid_argument(err);
00080   }
00081 }

PFResolutionMap::PFResolutionMap ( const char *  name,
unsigned  nbinseta,
double  mineta,
double  maxeta,
unsigned  nbinse,
double  mine,
double  maxe,
double  value = -1 
)

create an empty map and initialize it

Definition at line 16 of file PFResolutionMap.cc.

00020   : TH2D(name, name, nbinseta, mineta, maxeta, nbinse, mine, maxe) {
00021   // fNbinsEta(nbinseta), fMinEta(mineta), fMaxEta(maxeta),
00022   //    fNbinsE(nbinse), fMinE(mine), fMaxE(maxe) {
00023 
00024   GetXaxis()->SetTitle("#eta");
00025   GetYaxis()->SetTitle("E");
00026 
00027   if(value>0) {
00028     for(int ie=1; ie<=GetNbinsY(); ie++) {
00029       for(int ieta=1; ieta<=GetNbinsX(); ieta++) {
00030         SetBinContent(ieta,ie, value);
00031       }
00032     }  
00033   }
00034   // cout<<"creating resolution map "<<endl;
00035   // Print("all");
00036   
00037 }

PFResolutionMap::PFResolutionMap ( const TH2D &  h  )  [inline]

create a map from a 2d histogram

Definition at line 34 of file PFResolutionMap.h.

00034 : TH2D(h) {}


Member Function Documentation

double PFResolutionMap::dCrackPhi ( double  phi,
double  eta 
) [private]

Definition at line 302 of file PFResolutionMap.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), i, m, minimum(), and pi.

Referenced by IsInAPhiCrack().

00302                                                        {
00303 
00304   static double pi= M_PI;// 3.14159265358979323846;
00305   
00306   //Location of the 18 phi-cracks
00307   static std::vector<double> cPhi;
00308   cPhi.resize(18,0);
00309   cPhi[0]=2.97025;
00310   for(unsigned i=1;i<=17;i++) cPhi[i]=cPhi[0]-2*i*pi/18;
00311 
00312   //Shift of this location if eta<0
00313   static double delta_cPhi=0.00638;
00314 
00315   double m; //the result
00316 
00317   //the location is shifted
00318   if(eta<0){ 
00319     phi +=delta_cPhi;
00320     if(phi>pi) phi-=2*pi;
00321   }
00322   if (phi>=-pi && phi<=pi){
00323 
00324     //the problem of the extrema
00325     if (phi<cPhi[17] || phi>=cPhi[0]){
00326       if (phi<0) phi+= 2*pi;
00327       m = minimum(phi -cPhi[0],phi-cPhi[17]-2*pi);              
00328     }
00329 
00330     //between these extrema...
00331     else{
00332       bool OK = false;
00333       unsigned i=16;
00334       while(!OK){
00335         if (phi<cPhi[i]){
00336           m=minimum(phi-cPhi[i+1],phi-cPhi[i]);
00337           OK=true;
00338         }
00339         else i-=1;
00340       }
00341     }
00342   }
00343   else{
00344     m=0.;        //if there is a problem, we assum that we are in a crack
00345     std::cout<<"Problem in dminphi"<<std::endl;
00346   }
00347   if(eta<0) m=-m;   //because of the disymetry
00348   return m;
00349 }

int PFResolutionMap::FindBin ( double  eta,
double  e 
)

extrapolation requires overloading of this function

Definition at line 256 of file PFResolutionMap.cc.

Referenced by getRes(), GoodSeedProducer::produce(), PFBlockAlgo::testECALAndHCAL(), PFBlockAlgo::testLinkByRecHit(), PFBlockAlgo::testPSAndECAL(), PFBlockAlgo::testTrackAndECAL(), and PFBlockAlgo::testTrackAndHCAL().

00256                                                  {
00257   if(e >= GetYaxis()->GetXmax() )
00258     e = GetYaxis()->GetXmax() - 0.001;
00259   
00260   return TH2D::FindBin(eta,e);
00261 }

const char* PFResolutionMap::GetMapFile (  )  const [inline]

Definition at line 49 of file PFResolutionMap.h.

References mapFile_.

Referenced by operator<<().

00049 {return mapFile_.c_str();}

double PFResolutionMap::getRes ( double  eta,
double  phi,
double  e,
int  MapEta = -1 
)

Definition at line 231 of file PFResolutionMap.cc.

References FindBin(), IsInAPhiCrack(), and res.

00231                                                                           {
00232   static double fMinEta = -2.95;
00233   static double fMaxEta = 2.95;
00234   static double fMinE=0;
00235   static double fMaxE=100;
00236 
00237   if( eta<fMinEta ) eta = fMinEta+0.001;
00238   if( eta>fMaxEta ) eta = fMaxEta-0.001;
00239  
00240   if( e<fMinE ) e = fMinE+0.001;
00241   if( e>fMaxE ) e = fMaxE-0.001;
00242 
00243   unsigned bin = FindBin(TMath::Abs(eta),e);
00244 
00245   double res= GetBinContent(bin);
00246   if(MapEta>-1){
00247     if((eta<1.48) && IsInAPhiCrack(phi,eta))
00248       if(MapEta==1) res *= 1.88;
00249       else res *= 1.65;
00250   }
00251   return res;
00252 }

bool PFResolutionMap::IsInAPhiCrack ( double  phi,
double  eta 
) [private]

Definition at line 288 of file PFResolutionMap.cc.

References dCrackPhi().

Referenced by getRes().

00288                                                          {
00289   double dminPhi = dCrackPhi(phi,eta);
00290   bool Is = (TMath::Abs(dminPhi)<0.005);
00291   return Is;
00292 }

double PFResolutionMap::minimum ( double  a,
double  b 
) [private]

Definition at line 295 of file PFResolutionMap.cc.

Referenced by dCrackPhi().

00295                                                 {
00296   if(TMath::Abs(b)<TMath::Abs(a)) a=b;
00297   return a;
00298 }

bool PFResolutionMap::ReadMapFile ( const char *  mapfile  ) 

read text file

Definition at line 110 of file PFResolutionMap.cc.

References empty, i, j, lineSize_, mapFile_, and s.

Referenced by PFResolutionMap().

00110                                                      {
00111   
00112   // open the file
00113 
00114   ifstream inf(mapfile);
00115   if( !inf.good() ) {
00116     // cout<<"PFResolutionMap::Read : cannot open file "<<mapfile<<endl;
00117     return false;
00118   }
00119   
00120   // first data describes the map
00121 
00122   int nbinseta=0;
00123   double mineta=0;
00124   double maxeta=0;
00125   
00126   int nbinse=0;
00127   double mine=0;
00128   double maxe=0;
00129   
00130   inf>>nbinseta;
00131   inf>>mineta;
00132   inf>>maxeta;
00133 
00134   inf>>nbinse;
00135   inf>>mine;
00136   inf>>maxe;
00137 
00138   SetBins(nbinseta, mineta, maxeta, nbinse, mine, maxe);
00139 
00140   // Init(fNbinsEta,fMinEta,fMaxEta,fNbinsE,fMinE,fMaxE);
00141 
00142   // char data[lineSize_];
00143   char s[lineSize_];
00144   int pos=inf.tellg();
00145 
00146   // parse map data
00147   int i=1;
00148   do { 
00149     inf.seekg(pos);
00150     inf.getline(s,lineSize_);
00151     
00152     pos = inf.tellg();     
00153  
00154     if(string(s).empty()) {
00155       continue; // remove empty lines
00156     }
00157 
00158     istringstream lin(s);  
00159 
00160     double dataw;
00161     int j=1;
00162     do {
00163       lin>>dataw;
00164       SetBinContent(j, i, dataw);
00165       j++;
00166     } while (lin.good() );
00167     i++;
00168   } while(inf.good());
00169   
00170   if(inf.eof()) {
00171     mapFile_ = mapfile;  
00172     return true;
00173   }
00174   else {
00175     // cout<<"error"<<endl;
00176     return false;
00177   }
00178   
00179   mapFile_ = mapfile;  
00180   return true;
00181 }

bool PFResolutionMap::WriteMapFile ( const char *  mapfile  ) 

write text file is not const because mapFile_ will be updated

Definition at line 84 of file PFResolutionMap.cc.

References TestMuL1L2Filter_cff::cerr, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), and mapFile_.

00084                                                       {
00085 
00086   //  assert(fData.size() == fNbinsEta*fNbinsE);
00087 
00088 
00089   // open the file
00090 
00091   ofstream outf(mapfile);
00092   if( !outf.good() ) {
00093     cout<<"PFResolutionMap::Write : cannot open file "<<mapfile<<endl;
00094     return false;
00095   }
00096   
00097   outf<<(*this)<<endl;
00098   if(!outf.good() ) {
00099     cerr<<"PFResolutionMap::Write : corrupted file "<<mapfile<<endl;
00100     return false;
00101   }
00102   else {
00103     mapFile_ = mapfile;
00104     return true;
00105   }
00106 }


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const PFResolutionMap rm 
) [friend]

print this map


Member Data Documentation

const unsigned PFResolutionMap::lineSize_ = 10000 [static, private]

Definition at line 58 of file PFResolutionMap.h.

Referenced by ReadMapFile().

std::string PFResolutionMap::mapFile_ [private]

Definition at line 59 of file PFResolutionMap.h.

Referenced by GetMapFile(), ReadMapFile(), and WriteMapFile().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:29:46 2009 for CMSSW by  doxygen 1.5.4