00001 #include "RecoParticleFlow/PFClusterTools/interface/Utils.h"
00002
00003 #include <stdio.h>
00004 #include <math.h>
00005 #include <regex.h>
00006 #include <glob.h>
00007
00008 #include "TCanvas.h"
00009 #include "TVector3.h"
00010
00011 using namespace std;
00012 using namespace pftools;
00013 bool Utils::StringMatch(const char* str, const char* pattern) {
00014 int status;
00015 regex_t re;
00016
00017 if( regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0 )
00018 return false;
00019
00020 status = regexec(&re, str, (size_t)0, NULL, 0);
00021 regfree(&re);
00022
00023 if (status != 0)
00024 return false;
00025
00026 return true;
00027 }
00028
00029
00030 TCanvas* Utils::DivideCanvas( TCanvas *cv, int nPads ) {
00031 if( !cv ) return 0;
00032
00033 if( nPads<=1 ) return cv;
00034 int sqnP = (unsigned int) (sqrt( nPads ));
00035 int nC = sqnP;
00036 int nL = sqnP;
00037
00038 while( nC*nL < nPads )
00039 if( nC < nL ) nC++;
00040 else nL++;
00041
00042 cv->Divide( nC, nL, 0.005, 0.005, 0 );
00043 return cv;
00044 }
00045
00046 vector<string> Utils::Glob(const char* pattern) {
00047
00048 glob_t globbuf;
00049
00050 globbuf.gl_offs = 2;
00051 glob(pattern, GLOB_TILDE|GLOB_BRACE|GLOB_MARK, NULL, &globbuf);
00052
00053 vector<string> results;
00054 for(unsigned i=0; i<globbuf.gl_pathc; i++) {
00055 results.push_back(globbuf.gl_pathv[i]);
00056 }
00057
00058 globfree(&globbuf);
00059 return results;
00060 }
00061
00062 string Utils::Date() {
00063 string date("date +%d%b%Y_%H%M%S");
00064 FILE *in = popen(date.c_str(), "r");
00065 char result[100];
00066 if(fscanf(in,"%s",result) != EOF) {
00067 return string(result);
00068 }
00069 else return string("");
00070 }
00071
00072
00073 TVector3 Utils::VectorEPRtoXYZ( const TVector3& posepr ) {
00074 TVector3 posxyz(1,1,1);
00075 posxyz.SetMag( posepr.Z() );
00076 double theta = 2*atan( exp( - posepr.X() ) );
00077 posxyz.SetTheta( theta );
00078 posxyz.SetPhi( posepr.Y() );
00079
00080 return posxyz;
00081 }
00082
00083