CMS 3D CMS Logo

Static Public Member Functions

Utils Class Reference

Utility functions. More...

#include <Utils.h>

List of all members.

Static Public Member Functions

static std::string date ()
 returns the date
static std::string Date ()
 returns the date
static TCanvas * DivideCanvas (TCanvas *cv, int nPads)
 divide a TCanvas in a nice way
static std::vector< std::string > Glob (const char *pattern)
 get all files matching pattern
static double mpi_pi (double angle)
 returns angle between mpi and pi
static std::vector< std::string > myGlob (const char *pattern)
 get all files matching pattern
static bool stringMatch (const char *string, const char *pattern)
 match a string to a regexp
static bool StringMatch (const char *string, const char *pattern)
 match a string to a regexp
static TVector3 VectorEPRtoXYZ (const TVector3 &posepr)
 converts a vector (in eta,phi,R) to a vector in (x,y,z)

Detailed Description

Utility functions.

Author:
Colin Bernet
Date:
January 2006

Definition at line 16 of file Utils.h.


Member Function Documentation

string Utils::date ( ) [static]

returns the date

Definition at line 41 of file Utils.cc.

References recoMuon::in, and query::result.

                     {
  string date("date +%d%b%Y_%H%M%S");
  FILE *in = popen(date.c_str(), "r");
  char result[100];
  if(fscanf(in,"%s",result) != EOF) {
    return string(result);
  }
  else return string("");
}
string Utils::Date ( ) [static]

returns the date

Definition at line 62 of file Utils.cc.

References recoMuon::in, and query::result.

                     {
  string date("date +%d%b%Y_%H%M%S");
  FILE *in = popen(date.c_str(), "r");
  char result[100];
  if(fscanf(in,"%s",result) != EOF) {
    return string(result);
  }
  else return string("");
}
TCanvas * Utils::DivideCanvas ( TCanvas *  cv,
int  nPads 
) [static]

divide a TCanvas in a nice way

Definition at line 30 of file Utils.cc.

References mathSSE::sqrt().

                                                     {  
  if( !cv ) return 0;
  
  if( nPads<=1 ) return cv;
  int sqnP = (unsigned int) (sqrt( nPads ));
  int nC = sqnP;
  int nL = sqnP;
  
  while( nC*nL < nPads ) 
    if( nC < nL ) nC++;
    else nL++;
  
  cv->Divide( nC, nL, 0.005, 0.005, 0 );
  return cv;
}
vector< string > Utils::Glob ( const char *  pattern) [static]

get all files matching pattern

Definition at line 46 of file Utils.cc.

References i, NULL, and python::entryComment::results.

Referenced by IO::IO().

                                               {

  glob_t globbuf;

  globbuf.gl_offs = 2;
  glob(pattern, GLOB_TILDE|GLOB_BRACE|GLOB_MARK, NULL, &globbuf);

  vector<string> results;
  for(unsigned i=0; i<globbuf.gl_pathc; i++) {
    results.push_back(globbuf.gl_pathv[i]);
  }
  
  globfree(&globbuf);
  return results;
}
double Utils::mpi_pi ( double  angle) [static]

returns angle between mpi and pi

Definition at line 52 of file Utils.cc.

References angle(), pi, and pi2.

                                   {

  const double pi = 3.14159265358979323;
  const double pi2 = pi*2.;
  while(angle>pi) angle -= pi2;
  while(angle<-pi) angle += pi2;
  return angle;
}
vector< string > Utils::myGlob ( const char *  pattern) [static]

get all files matching pattern

Definition at line 25 of file Utils.cc.

References i, NULL, and python::entryComment::results.

                                                 {

  glob_t globbuf;

  globbuf.gl_offs = 2;
  glob(pattern, GLOB_TILDE|GLOB_BRACE|GLOB_MARK, NULL, &globbuf);

  vector<string> results;
  for(unsigned i=0; i<globbuf.gl_pathc; i++) {
    results.push_back(globbuf.gl_pathv[i]);
  }
  
  globfree(&globbuf);
  return results;
}
bool Utils::stringMatch ( const char *  string,
const char *  pattern 
) [static]

match a string to a regexp

Definition at line 9 of file Utils.cc.

References NULL, and ntuplemaker::status.

                                                            {
  int    status;
  regex_t    re;
  
  if( regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0 )
    return false;
  
  status = regexec(&re, str, (size_t)0, NULL, 0);
  regfree(&re);
  
  if (status != 0)
    return false;
  
  return true;
}
bool Utils::StringMatch ( const char *  string,
const char *  pattern 
) [static]

match a string to a regexp

Definition at line 13 of file Utils.cc.

References NULL, and ntuplemaker::status.

                                                            {
  int    status;
  regex_t    re;
  
  if( regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0 )
    return false;
  
  status = regexec(&re, str, (size_t)0, NULL, 0);
  regfree(&re);
  
  if (status != 0)
    return false;
  
  return true;
}
TVector3 Utils::VectorEPRtoXYZ ( const TVector3 &  posepr) [static]

converts a vector (in eta,phi,R) to a vector in (x,y,z)

Definition at line 73 of file Utils.cc.

References create_public_lumi_plots::exp, and theta().

Referenced by PFRootEventManager::tauBenchmark().

                                                       {
  TVector3 posxyz(1,1,1); // to be called before a SetMag
  posxyz.SetMag( posepr.Z() );
  double theta = 2*atan( exp( - posepr.X() ) );
  posxyz.SetTheta( theta );
  posxyz.SetPhi( posepr.Y() );  

  return posxyz;
}