NuGeneral Class Reference

#include <NuGeneral.h>

List of all members.

Public Member Functions

 NuGeneral ()
 ~NuGeneral ()
void CopyAcrossObjects (TDirectory *dirInput, TDirectory *dirOutput, const std::vector< std::string > &vObjectNames) const
void EpochTo1995 (std::vector< Double_t > &t) const
void EpochTo1995 (Int_t &t) const
std::string GetTestReleaseDir () const
std::string GetBaseReleaseDir () const
std::string GetReleaseDirToUse (std::string sPackageDir) const
std::string IdHEPAsString (Int_t IdHEP) const
Double_t OscWeight (Double_t DeltaM2, Double_t Sin22Theta, Double_t Enu) const
TGraph * TGraphMap (const std::map< Int_t, Float_t > &m) const
TGraph * TGraphVect (std::vector< Double_t > &vX, std::vector< Double_t > &vY) const
void TGraphMinMax (std::vector< TGraph * > &v) const
void TGraphOffset (std::vector< TGraph * > &v, Double_t factor=1) const
void TH1FFill (TH1F *h, const std::vector< Double_t > &vX) const
void TH1FFill (TH1F *h, const std::vector< Double_t > &vX, const std::vector< Double_t > &vY) const
void TProfileFill (TProfile *p, std::vector< Double_t > &vX, std::vector< Double_t > &vY) const
void TProfile2DFill (TProfile2D *p, std::vector< Double_t > &vX, std::vector< Double_t > &vY, std::vector< Double_t > &vZ) const
Int_t Rnd (Double_t x) const
void SetGraphAxis (TAxis *a, Int_t startTimeSecs, Int_t endTimeSecs) const
void SetGraphAxisEtc (TGraph *g, Int_t startTimeSecs, Int_t endTimeSecs) const
void FlipVector (std::vector< Double_t > &v) const
void NormaliseVector (std::vector< Double_t > &v, Int_t mode=1) const
void ScaleMap (std::map< Int_t, Float_t > &m, const std::map< Int_t, Float_t > &scaleFactor) const
void ScaleVector (std::vector< Double_t > &v, Double_t scaleFactor) const

Detailed Description

Definition at line 21 of file NuGeneral.h.


Constructor & Destructor Documentation

NuGeneral::NuGeneral (  ) 

Definition at line 35 of file NuGeneral.cxx.

References Msg::kDebug, and MSG.

00036 {
00037   MSG("NuGeneral",Msg::kDebug)
00038     <<"Running NuGeneral Constructor..."<<endl;
00039 
00040 
00041   MSG("NuGeneral",Msg::kDebug)
00042     <<"Finished NuGeneral Constructor"<<endl;
00043 }

NuGeneral::~NuGeneral (  ) 

Definition at line 47 of file NuGeneral.cxx.

References Msg::kDebug, and MSG.

00048 {
00049   MSG("NuGeneral",Msg::kDebug)
00050     <<"Running NuGeneral Destructor..."<<endl;
00051   
00052 
00053   MSG("NuGeneral",Msg::kDebug)
00054     <<"Finished NuGeneral Destructor"<<endl;
00055 }


Member Function Documentation

void NuGeneral::CopyAcrossObjects ( TDirectory *  dirInput,
TDirectory *  dirOutput,
const std::vector< std::string > &  vObjectNames 
) const

Definition at line 162 of file NuGeneral.cxx.

References Msg::kInfo, and MAXMSG.

Referenced by NuAnalysis::CopyAcrossHistos(), and NuDSTAna::CopyAcrossHistos().

00166 {
00167   cout<<"NuGeneral: copying across objects"<<endl;
00168 
00169   TDirectory* directoryOrig=gDirectory;
00170   //cout<<"Original directory is:"<<endl;
00171   //directoryOrig->Print();
00172   
00173   //change to the directory where the files are kept
00174   gDirectory=dirInput;
00175   //cout<<"Changed to input directory:"<<endl;
00176   //gDirectory->Print();
00177   
00178   //vector to store the pointers to the histograms to copy across
00179   vector<TObject*> vObjects;
00180   
00181   //get the pointers
00182   for (vector<string>::const_iterator iter=vObjectNames.begin();
00183        iter!=vObjectNames.end();++iter){
00184     TObject* h=gROOT->FindObject(iter->c_str());
00185     vObjects.push_back(h);
00186     if (!h) {
00187       MAXMSG("NuGeneral",Msg::kInfo,10)
00188         <<"CopyAcrossObjects: Can't find object="<<*iter<<endl;
00189     }
00190   }
00191   
00192   //change to the directory where the objects are to be written
00193   gDirectory=dirOutput;
00194   //cout<<"Changed to output directory:"<<endl;
00195   //gDirectory->Print();
00196 
00197   //loop over the objects and write them out
00198   for (vector<TObject*>::const_iterator iter=vObjects.begin();
00199        iter!=vObjects.end();++iter){
00200     if (*iter) {
00201       (*iter)->Write();
00202     }
00203   }
00204 
00205   //reset the global directory to the original directory
00206   gDirectory=directoryOrig;
00207 }

void NuGeneral::EpochTo1995 ( Int_t &  t  )  const

Definition at line 588 of file NuGeneral.cxx.

00589 {
00590   t-=788918400;// seconds between 1970 and 1995
00591 }

void NuGeneral::EpochTo1995 ( std::vector< Double_t > &  t  )  const

Definition at line 572 of file NuGeneral.cxx.

References Msg::kWarning, and MSG.

Referenced by NuAnalysis::ChargeSignCut(), NuAnalysis::Efficiencies(), NuAnalysis::EnergySpect(), NuTime::FillTime(), NuTime::FillTimeHistos(), NuTime::FillVsTimeHistos(), NuTime::FillVsTimeHistos2(), and NuAnalysis::NuMuBarAppearance().

00573 {
00574   if (t.empty()) {
00575     MSG("NuGeneral",Msg::kWarning) 
00576       <<"EpochTo1995: One or more vectors is empty"<<endl;
00577     return;
00578   }
00579 
00580   UInt_t vSize=t.size();
00581   for (UInt_t i=0;i<vSize;i++){
00582     t[i]-=788918400;// seconds between 1970 and 1995
00583   }
00584 }

void NuGeneral::FlipVector ( std::vector< Double_t > &  v  )  const

Definition at line 814 of file NuGeneral.cxx.

00815 {
00816   vector<Double_t> tempV=v;
00817   for (UInt_t i=0;i<v.size();i++) v[i]=tempV[v.size()-1-i];
00818 }

std::string NuGeneral::GetBaseReleaseDir (  )  const

Definition at line 139 of file NuGeneral.cxx.

References Msg::kError, and MSG.

Referenced by GetReleaseDirToUse().

00140 {
00141   //get the environmental variable
00142   char* anaDir=getenv("SRT_PUBLIC_CONTEXT");
00143   
00144   //use a string to hold env instead 
00145   string sAnaDir="";
00146   
00147   if (anaDir!=NULL) {
00148     sAnaDir=anaDir;
00149   }
00150   else {
00151     MSG("NuGeneral",Msg::kError) 
00152       <<"Environmental variable $SRT_PUBLIC_CONTEXT not set"<<endl
00153       <<"Will abort here..."<<endl;
00154     assert(false);
00155   }
00156   
00157   return sAnaDir;
00158 }

std::string NuGeneral::GetReleaseDirToUse ( std::string  sPackageDir  )  const

this returns the location of either the test or base release directory e.g. /home/hartnell/minos/minossoft/releases/development which one depends on whether the package exists the test release is returned if it exists if neither directories exist then it aborts

sPackageDir should be say "Mad" or other package name it also works if you give say "Mad/data"

Definition at line 59 of file NuGeneral.cxx.

References GetBaseReleaseDir(), GetTestReleaseDir(), Msg::kDebug, Msg::kInfo, Msg::kWarning, MAXMSG, and stat.

Referenced by NuFCRunInfo::BuildMMRunFC(), NuCutImps::CC0720Resolution::CC0720Resolution(), NuCutImps::CC1070Resolution::CC1070Resolution(), NuCutImps::CC2014NewCoilCutResolution::CC2014NewCoilCutResolution(), NuCutImps::CC2014Resolution::CC2014Resolution(), NuPIDInterface::GetFileNameAbID(), NuPIDInterface::GetFileNameJeID(), NuPIDInterface::GetFileNamekNNID(), NuPIDInterface::GetRoIDPlus(), NuReco::GetShowerEnergykNN(), NuPIDInterface::InitialiseJmID(), NuPIDInterface::InitialiseRoID(), and MajorityCurvature::MajorityCurvature().

00060 {
00069 
00070   const string sPub=this->GetBaseReleaseDir();
00071   const string sPriv=this->GetTestReleaseDir();
00072 
00073   //set default return value to sPriv
00074   string sAnaDir=sPriv;
00075   
00076   //try private context first
00077   string sTmp=sPriv+"/"+sPackageDir;
00078   struct stat ss;
00079   MAXMSG("NuGeneral",Msg::kDebug,10)<<"sTmp="<<sTmp<<endl;
00080   if(stat(sTmp.c_str(),&ss)==-1) {
00081     MAXMSG("NuGeneral",Msg::kInfo,10)
00082       <<"Package="<<sPackageDir
00083       <<" not present in SRT_PRIVATE_CONTEXT="<<sPriv
00084       <<", trying SRT_PUBLIC_CONTEXT="<<sPub<<"..."<<endl;
00085     
00086     //now test public context
00087     sTmp=sPub+"/"+sPackageDir;
00088     MAXMSG("NuGeneral",Msg::kDebug,10)<<"sTmp2="<<sTmp<<endl;
00089     if(stat(sTmp.c_str(),&ss)==-1) {
00090       MAXMSG("NuGeneral",Msg::kWarning,10)
00091         <<"Package="<<sPackageDir
00092         <<" not present in SRT_PUBLIC_CONTEXT="<<sPub
00093         <<" or SRT_PRIVATE_CONTEXT="<<sPriv
00094         <<", will abort here..."<<endl;
00095       assert(false);
00096     }
00097     //public context exists so use that
00098     else {
00099       MAXMSG("NuGeneral",Msg::kInfo,10)
00100         <<"Using SRT_PUBLIC_CONTEXT="<<sPub
00101         <<" for package="<<sPackageDir<<endl;
00102       sAnaDir=sPub;
00103     }
00104   }
00105   else {
00106     MAXMSG("NuGeneral",Msg::kInfo,10)
00107       <<"Using SRT_PRIVATE_CONTEXT="<<sPriv
00108       <<" for package="<<sPackageDir<<endl;
00109   }
00110   
00111   return sAnaDir;
00112 }

std::string NuGeneral::GetTestReleaseDir (  )  const

Definition at line 116 of file NuGeneral.cxx.

References Msg::kError, and MSG.

Referenced by GetReleaseDirToUse().

00117 {
00118   //get the environmental variable
00119   char* anaDir=getenv("SRT_PRIVATE_CONTEXT");
00120   
00121   //use a string to hold env instead 
00122   string sAnaDir="";
00123   
00124   if (anaDir!=NULL) {
00125     sAnaDir=anaDir;
00126   }
00127   else {
00128     MSG("NuGeneral",Msg::kError) 
00129       <<"Environmental variable $SRT_PRIVATE_CONTEXT not set"<<endl
00130       <<"Will abort here..."<<endl;
00131     assert(false);
00132   }
00133 
00134   return sAnaDir;
00135 }

std::string NuGeneral::IdHEPAsString ( Int_t  IdHEP  )  const

Definition at line 884 of file NuGeneral.cxx.

References Form().

Referenced by NuCounter::PrintStdhepCounter().

00885 {
00886   string sIdHEP="";
00887   
00888   Bool_t shortName=true;
00889   if (shortName) {
00890     if (IdHEP==22) sIdHEP="photon";
00891     
00892     else if (IdHEP==11) sIdHEP="e-";
00893     else if (IdHEP==-11) sIdHEP="e+";
00894     else if (IdHEP==13) sIdHEP="mu-";
00895     else if (IdHEP==-13) sIdHEP="mu+";
00896     else if (IdHEP==15) sIdHEP="tau-";
00897     else if (IdHEP==-15) sIdHEP="tau+";
00898 
00899     else if (IdHEP==12) sIdHEP="nue";
00900     else if (IdHEP==-12) sIdHEP="nuebar";
00901     else if (IdHEP==14) sIdHEP="numu";
00902     else if (IdHEP==-14) sIdHEP="numubar";
00903     else if (IdHEP==16) sIdHEP="nutaubar";
00904     else if (IdHEP==-16) sIdHEP="nutaubar";
00905 
00906     else if (IdHEP==211) sIdHEP="pi+";
00907     else if (IdHEP==-211) sIdHEP="pi-";
00908     else if (IdHEP==221) sIdHEP="eta+";
00909     else if (IdHEP==-221) sIdHEP="eta-";
00910     else if (IdHEP==111) sIdHEP="pi0";
00911     
00912     else if (IdHEP==213) sIdHEP="rho+";
00913     else if (IdHEP==-213) sIdHEP="rho-";
00914     else if (IdHEP==223) sIdHEP="omega+";
00915     else if (IdHEP==-223) sIdHEP="omega-";
00916     else if (IdHEP==113) sIdHEP="rho0";
00917     
00918     else if (IdHEP==321) sIdHEP="k+";
00919     else if (IdHEP==-321) sIdHEP="k-";
00920     else if (IdHEP==310) sIdHEP="k-short";
00921     else if (IdHEP==130) sIdHEP="k-long";
00922     else if (IdHEP==311) sIdHEP="k0";
00923 
00924     else if (IdHEP==411) sIdHEP="D+";
00925     else if (IdHEP==421) sIdHEP="D0";
00926     else if (IdHEP==431) sIdHEP="D??";
00927     else if (IdHEP==4122) sIdHEP="Lambda_c+";
00928 
00929     else if (IdHEP==2212) sIdHEP="p+";
00930     else if (IdHEP==-2212) sIdHEP="p-";
00931     else if (IdHEP==2112) sIdHEP="n";
00932 
00933     else if (IdHEP==1114) sIdHEP="delta-";
00934     else if (IdHEP==-2114) sIdHEP="delta0";
00935     else if (IdHEP==2214) sIdHEP="delta+";
00936     else if (IdHEP==2224) sIdHEP="delta++";
00937     
00938     else if (IdHEP==28) sIdHEP="geantino";
00939   }
00940   else {
00941 
00942   }
00943   
00944   if (sIdHEP==""){
00945     string sForm=Form("%d",IdHEP);
00946     sIdHEP="IdHEP="+sForm+"=?";
00947   }
00948 
00949   return sIdHEP;
00950 }

void NuGeneral::NormaliseVector ( std::vector< Double_t > &  v,
Int_t  mode = 1 
) const

Definition at line 732 of file NuGeneral.cxx.

References Msg::kInfo, Msg::kVerbose, and MSG.

00733 {
00734   if (v.size()>0){
00735 
00736     if (mode==1){//simple average
00737       //find average
00738       Double_t average=0;
00739       for (UInt_t i=0;i<v.size();i++) average+=v[i];
00740       average/=v.size();
00741       
00742       MSG("NuGeneral",Msg::kVerbose)<<"Average="<<average<<endl; 
00743       
00744       //normalise
00745       for (UInt_t i=0;i<v.size();i++) v[i]/=average;
00746     }
00747     else if (mode==2){//fit the function to remove effect of outliers
00748       
00749       Double_t vMax=-9e50;
00750       Double_t vMin=9e50;
00751 
00752       //work out mins and maxs
00753       for (UInt_t i=0;i<v.size();i++){
00754         if (v[i]>vMax) vMax=v[i];
00755         if (v[i]<vMin) vMin=v[i];
00756       }
00757       
00758       //limit the number of bins
00759       Int_t numBins=300;
00760       if (4*v.size()<10000) numBins=4*v.size();
00761 
00762       MSG("NuGeneral",Msg::kInfo)
00763         <<"vMax="<<vMax <<", vMin="<<vMin<<", numBins="<<numBins<<endl;
00764 
00765       //create the histo
00766       TH1F* h=new TH1F("h","h",numBins,vMin-fabs(0.1*vMin),
00767                        vMax+fabs(0.1*vMin));
00768       h->SetBit(TH1::kCanRebin);
00769 
00770       Double_t average=0;
00771       for (UInt_t i=0;i<v.size();i++){
00772         //find average
00773         average+=v[i];
00774 
00775         //fill the histo
00776         h->Fill(v[i]);
00777       }
00778       average/=v.size();
00779 
00780       //fit but use 0 (zero!) otherwise it stamps on the current canvas!
00781       h->Fit("gaus","q0");
00782       TF1* func=h->GetFunction("gaus");
00783       Double_t p1=func->GetParameter(1);
00784       Double_t p2=func->GetParameter(2);
00785 
00786       //don't use the fit if it is screwed up
00787       Double_t avToNormWith=p1;
00788       if (p1<vMin || p1>vMax) avToNormWith=average;
00789 
00790       MSG("NuGeneral",Msg::kInfo)
00791         <<"Fitted mean="<<p1
00792         <<" (average="<<average
00793         <<") fitted rms="<<p2
00794         <<", using avToNormWith="<<avToNormWith<<endl;
00795 
00796       //normalise
00797       for (UInt_t i=0;i<v.size();i++) v[i]/=avToNormWith;
00798 
00799       delete h;
00800     }
00801   }
00802 }

Double_t NuGeneral::OscWeight ( Double_t  DeltaM2,
Double_t  Sin22Theta,
Double_t  Enu 
) const

Definition at line 868 of file NuGeneral.cxx.

References Lit::Distance().

Referenced by NuDSTAna::NMBAna(), NuAnalysis::NMBSummaryTreeAna(), and NuAnalysis::NuMuBarAppearance().

00870 {
00871   //calculate oscillation probability
00872   const Double_t Distance = 735.1;
00873   Double_t weight=1;
00874   Double_t sinm=0;
00875   
00876   sinm=sin((1.26693276*DeltaM2*Distance)/Enu);
00877   weight=1.- Sin22Theta * sinm * sinm;
00878 
00879   return weight;
00880 }

Int_t NuGeneral::Rnd ( Double_t  x  )  const

Definition at line 822 of file NuGeneral.cxx.

00823 {
00824   Double_t xi=0;
00825 
00826   Double_t floatPart=modf(x,&xi); 
00827 
00828   //round up if necessary
00829   if (floatPart>0.5) xi++;
00830 
00831   return static_cast<Int_t>(xi);
00832 }

void NuGeneral::ScaleMap ( std::map< Int_t, Float_t > &  m,
const std::map< Int_t, Float_t > &  scaleFactor 
) const

Definition at line 836 of file NuGeneral.cxx.

References Msg::kVerbose, Msg::kWarning, and MSG.

00838 {
00839   if (m.size()==scaleFactor.size()){
00840     
00841     map<Int_t,Float_t>::iterator mIter=m.begin();
00842     map<Int_t,Float_t>::const_iterator scale=scaleFactor.begin();
00843 
00844     //loop over map and scale it
00845     while (mIter!=m.end()){
00846 
00847       //divide by the scale factor
00848       if (scale->second!=0){
00849         MSG("NuGeneral",Msg::kVerbose)
00850           <<"mIter="<<mIter->second<<", scale="<<scale->second<<endl;
00851         mIter->second/=scale->second;
00852       }
00853       else MSG("NuGeneral",Msg::kWarning)<<"Scale factor zero!"<<endl;
00854 
00855       mIter++;
00856       scale++;
00857     }
00858   }
00859   else{
00860     MSG("NuGeneral",Msg::kWarning)
00861       <<"Not scaling map, vectors are different sizes!"<<endl;
00862   }
00863 }

void NuGeneral::ScaleVector ( std::vector< Double_t > &  v,
Double_t  scaleFactor 
) const

Definition at line 806 of file NuGeneral.cxx.

00808 {
00809   for (UInt_t i=0;i<v.size();i++) v[i]*=scaleFactor;
00810 }

void NuGeneral::SetGraphAxis ( TAxis *  a,
Int_t  startTimeSecs,
Int_t  endTimeSecs 
) const

Definition at line 328 of file NuGeneral.cxx.

References Form(), Msg::kInfo, Msg::kWarning, and MSG.

Referenced by NuAnalysis::ChargeSignCut(), NuAnalysis::Efficiencies(), NuAnalysis::EnergySpect(), NuTime::FillTimeHistos(), NuTime::FillVsTimeHistos(), NuTime::FillVsTimeHistos2(), and NuAnalysis::NuMuBarAppearance().

00330 {
00331   if (!a){
00332     MSG("NuGeneral",Msg::kWarning)
00333       <<"Input axis pointer is null! Will do nothing"<<endl;
00334     return;
00335   }
00336 
00337   //get datimes
00338   TDatime startDatime;
00339   startDatime.Set(startTimeSecs+788918400);
00340   TDatime endDatime;
00341   endDatime.Set(endTimeSecs+788918400);
00342 
00343   //play around with the formatting a little
00344   string sStartHour=Form("%d",startDatime.GetHour());
00345   string sStartMinute=Form("%d",startDatime.GetMinute());
00346   string sStartSecond=Form("%d",startDatime.GetSecond());
00347   string sStartYear=Form("%d",startDatime.GetYear());
00348   string sStartMonth=Form("%d",startDatime.GetMonth());
00349   string sStartDay=Form("%d",startDatime.GetDay());
00350   if (startDatime.GetHour()<10) sStartHour="0"+sStartHour;
00351   if (startDatime.GetMinute()<10) sStartMinute="0"+sStartMinute;
00352   if (startDatime.GetSecond()<10) sStartSecond="0"+sStartSecond;
00353   if (startDatime.GetMonth()<10) sStartMonth="0"+sStartMonth;
00354   if (startDatime.GetDay()<10) sStartDay="0"+sStartDay;
00355 
00356   //play around with the formatting a little
00357   string sEndHour=Form("%d",endDatime.GetHour());
00358   string sEndMinute=Form("%d",endDatime.GetMinute());
00359   string sEndSecond=Form("%d",endDatime.GetSecond());
00360   string sEndYear=Form("%d",endDatime.GetYear());
00361   string sEndMonth=Form("%d",endDatime.GetMonth());
00362   string sEndDay=Form("%d",endDatime.GetDay());
00363   if (endDatime.GetHour()<10) sEndHour="0"+sEndHour;
00364   if (endDatime.GetMinute()<10) sEndMinute="0"+sEndMinute;
00365   if (endDatime.GetSecond()<10) sEndSecond="0"+sEndSecond;
00366   if (endDatime.GetMonth()<10) sEndMonth="0"+sEndMonth;
00367   if (endDatime.GetDay()<10) sEndDay="0"+sEndDay;
00368 
00369   static Bool_t firstTime=true;
00370   if (firstTime){
00371     MSG("NuGeneral",Msg::kInfo) 
00372       <<"Setting axis info:"<<endl;
00373     MSG("NuGeneral",Msg::kInfo) 
00374       <<"  Start time "<<sStartHour
00375       <<":"<<sStartMinute
00376       <<":"<<sStartSecond
00377       <<" on "<<startDatime.GetYear()
00378       <<"/"<<sStartMonth
00379       <<"/"<<sStartDay
00380       <<endl;
00381 
00382     MSG("NuGeneral",Msg::kInfo) 
00383       <<"  End time   "<<sEndHour
00384       <<":"<<sEndMinute
00385       <<":"<<sEndSecond
00386       <<" on "<<endDatime.GetYear()
00387       <<"/"<<sEndMonth
00388       <<"/"<<sEndDay
00389       <<endl;
00390   }
00391 
00392   Int_t timeRange=endTimeSecs-startTimeSecs;
00393    
00394   if (sStartDay==sEndDay && timeRange<1*24*60*60){
00395     string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay+")";
00396     a->SetTitle(title.c_str());
00397     a->SetTimeFormat("%H:%M");
00398   }
00399   else if (timeRange>=1*24*60*60 && timeRange<2*24*60*60){//1-2 days
00400     string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
00401       +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
00402     a->SetTitle(title.c_str());
00403     a->SetTimeFormat("%H:%M");
00404   }
00405   else if (timeRange>=2*24*60*60 && timeRange<5*24*60*60){//2-5 days
00406     string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
00407       +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
00408     a->SetTitle(title.c_str());
00409     a->SetTimeFormat("%H:%M-%d/%m");
00410   }
00411   else if (timeRange>=5*24*60*60 && timeRange<20*24*60*60){//5-20 days
00412     string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
00413       +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
00414     a->SetTitle(title.c_str());
00415     a->SetTimeFormat("%d/%m");
00416   }
00417   else if (timeRange>=20*24*60*60 && timeRange<90*24*60*60){//20-90 days
00418     string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
00419       +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
00420     a->SetTitle(title.c_str());
00421     a->SetTimeFormat("%Y/%m/%d");
00422   }
00423   else if (timeRange>=90*24*60*60 && 
00424            timeRange<2*365*24*60*60){//50-2*365 days
00425     string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
00426       +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
00427     a->SetTitle(title.c_str());
00428     a->SetTimeFormat("%Y/%m");//Y for year with century
00429   }
00430   else{
00431     string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
00432       +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
00433     a->SetTitle(title.c_str());
00434     a->SetTimeFormat("%H:%M-%d/%m");
00435     //stop it cramming loads of days on the axis!
00436     a->SetNdivisions(506);
00437     //n = N1 + 100*N2 + 10000*N3
00438     //N1=number of primary divisions.
00439     //N2=number of secondary divisions.
00440     //N3=number of 3rd divisions.
00441   }
00442    
00443   //TDatime da(2003,02,28,12,00,00);
00444   //          gStyle->SetTimeOffset(da.Convert());
00445 
00446   if (firstTime) {
00447     MSG("NuGeneral",Msg::kInfo) 
00448       <<"Set axis title to be '"<<a->GetTitle()<<"'"<<endl;
00449   }
00450 
00451   //other x-axis defaults
00452   a->SetTimeDisplay(1);
00453   firstTime=false;
00454 }

void NuGeneral::SetGraphAxisEtc ( TGraph *  g,
Int_t  startTimeSecs,
Int_t  endTimeSecs 
) const

Definition at line 211 of file NuGeneral.cxx.

References Form(), Msg::kError, Msg::kInfo, Msg::kVerbose, and MSG.

00213 {
00214   MSG("NuGeneral",Msg::kVerbose)
00215     <<endl<<" ** Running the SetGraphAxisEtc method... ** "<<endl;
00216 
00217   TDatime startDatime;
00218   startDatime.Set(startTimeSecs+788918400);
00219   TDatime endDatime;
00220   endDatime.Set(endTimeSecs+788918400);
00221 
00222   //play around with the formatting a little
00223   string sStartHour=Form("%d",startDatime.GetHour());
00224   string sStartMinute=Form("%d",startDatime.GetMinute());
00225   string sStartSecond=Form("%d",startDatime.GetSecond());
00226   string sStartYear=Form("%d",startDatime.GetYear());
00227   string sStartMonth=Form("%d",startDatime.GetMonth());
00228   string sStartDay=Form("%d",startDatime.GetDay());
00229   if (startDatime.GetHour()<10) sStartHour="0"+sStartHour;
00230   if (startDatime.GetMinute()<10) sStartMinute="0"+sStartMinute;
00231   if (startDatime.GetSecond()<10) sStartSecond="0"+sStartSecond;
00232   if (startDatime.GetMonth()<10) sStartMonth="0"+sStartMonth;
00233   if (startDatime.GetDay()<10) sStartDay="0"+sStartDay;
00234 
00235   //play around with the formatting a little
00236   string sEndHour=Form("%d",endDatime.GetHour());
00237   string sEndMinute=Form("%d",endDatime.GetMinute());
00238   string sEndSecond=Form("%d",endDatime.GetSecond());
00239   string sEndYear=Form("%d",endDatime.GetYear());
00240   string sEndMonth=Form("%d",endDatime.GetMonth());
00241   string sEndDay=Form("%d",endDatime.GetDay());
00242   if (endDatime.GetHour()<10) sEndHour="0"+sEndHour;
00243   if (endDatime.GetMinute()<10) sEndMinute="0"+sEndMinute;
00244   if (endDatime.GetSecond()<10) sEndSecond="0"+sEndSecond;
00245   if (endDatime.GetMonth()<10) sEndMonth="0"+sEndMonth;
00246   if (endDatime.GetDay()<10) sEndDay="0"+sEndDay;
00247 
00248   static Bool_t firstTime=true;
00249   if (firstTime){
00250     MSG("NuGeneral",Msg::kInfo) 
00251       <<"Setting graph axis info:"<<endl;
00252     MSG("NuGeneral",Msg::kInfo) 
00253       <<"  Start time "<<sStartHour
00254       <<":"<<sStartMinute
00255       <<":"<<sStartSecond
00256       <<" on "<<startDatime.GetYear()
00257       <<"/"<<sStartMonth
00258       <<"/"<<sStartDay
00259       <<endl;
00260     
00261     MSG("NuGeneral",Msg::kInfo) 
00262       <<"  End time "<<sEndHour
00263       <<":"<<sEndMinute
00264       <<":"<<sEndSecond
00265       <<" on "<<endDatime.GetYear()
00266       <<"/"<<sEndMonth
00267       <<"/"<<sEndDay
00268       <<endl;
00269   }
00270   firstTime=false;
00271 
00272   Int_t timeRange=endTimeSecs-startTimeSecs;
00273 
00274   //check graph pointer is not null
00275   if (g){
00276     if (sStartDay==sEndDay && timeRange<1*24*60*60){
00277       string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay+")";
00278       g->GetXaxis()->SetTitle(title.c_str());
00279       g->GetXaxis()->SetTimeFormat("%H:%M");
00280     }
00281     else if (timeRange>1*24*60*60 && timeRange<2*24*60*60){//1-2 days
00282       string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
00283         +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
00284       g->GetXaxis()->SetTitle(title.c_str());
00285       g->GetXaxis()->SetTimeFormat("%H:%M");
00286     }
00287     else if (timeRange>2*24*60*60 && timeRange<5*24*60*60){//2-5 days
00288       string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
00289         +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
00290       g->GetXaxis()->SetTitle(title.c_str());
00291       g->GetXaxis()->SetTimeFormat("%H:%M-%d/%m");
00292     }
00293     else{
00294       string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
00295         +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
00296       g->GetXaxis()->SetTitle(title.c_str());
00297       g->GetXaxis()->SetTimeFormat("%H:%M-%d/%m");
00298       //stop it cramming loads of days on the axis!
00299       g->GetXaxis()->SetNdivisions(506);
00300       //n = N1 + 100*N2 + 10000*N3
00301       //N1=number of primary divisions.
00302       //N2=number of secondary divisions.
00303       //N3=number of 3rd divisions.
00304     }
00305     
00306     //other x-axis defaults
00307     g->GetXaxis()->SetTimeDisplay(1);
00308     g->GetXaxis()->CenterTitle();
00309     
00310     //other defaults
00311     g->SetMarkerStyle(3);
00312     g->SetMarkerColor(2);
00313     g->SetMarkerSize(0.35);
00314     g->SetLineColor(46);
00315   }
00316   else{
00317     MSG("NuGeneral",Msg::kError)
00318       <<"Input graph pointer is null!"
00319       <<" Will do nothing."<<endl;
00320   }
00321 
00322   MSG("NuGeneral",Msg::kVerbose)
00323     <<endl<<" ** Finished the SetGraphAxisEtc method... **"<<endl;
00324 }

TGraph * NuGeneral::TGraphMap ( const std::map< Int_t, Float_t > &  m  )  const

Definition at line 713 of file NuGeneral.cxx.

References Munits::g.

00714 {
00715   TGraph* g=new TGraph(m.size());
00716 
00717   map<Int_t,Float_t>::const_iterator mIter=m.begin();
00718 
00719   Int_t i=0;
00720 
00721   while (mIter!=m.end()){
00722     g->SetPoint(i,mIter->first,mIter->second);
00723 
00724     i++;
00725     mIter++;
00726   }
00727   return g;
00728 }

void NuGeneral::TGraphMinMax ( std::vector< TGraph * > &  v  )  const
void NuGeneral::TGraphOffset ( std::vector< TGraph * > &  v,
Double_t  factor = 1 
) const

Definition at line 627 of file NuGeneral.cxx.

References Msg::kDebug, Msg::kVerbose, max, min, and MSG.

00629 {
00630   Double_t max=-1e200;
00631   Double_t min=+1e200;
00632 
00633   //find the min and max
00634   for (vector<TGraph*>::iterator vIt=v.begin();vIt!=v.end();++vIt){
00635     for (Int_t i=0;i<(*vIt)->GetN();i++){
00636       Double_t x=0;
00637       Double_t y=0;
00638       (*vIt)->GetPoint(i,x,y);
00639       MSG("NuGeneral",Msg::kVerbose)
00640         <<"i="<<i<<", x="<<x<<", y="<<y<<endl;
00641 
00642       //find the min and max
00643       if (y>max) max=y;
00644       if (y<min) min=y;
00645     }
00646   }
00647 
00648   //change the scale
00649   for (vector<TGraph*>::iterator vIt=v.begin();vIt!=v.end();++vIt){
00650     for (Int_t i=0;i<(*vIt)->GetN();i++){
00651       Double_t x=0;
00652       Double_t y=0;
00653       (*vIt)->GetPoint(i,x,y);
00654       MSG("NuGeneral",Msg::kVerbose)
00655         <<"i="<<i<<", x="<<x<<", y="<<y<<endl;
00656 
00657       //scale the y value
00658       y-=min;
00659       y*=factor;//scale by factor, e.g. convert to nanosec
00660       (*vIt)->SetPoint(i,x,y);
00661     }
00662   }
00663 
00664   MSG("NuGeneral",Msg::kDebug)
00665     <<"Found min="<<min<<", max="<<max<<endl;
00666 
00667   //convert min and max
00668   max=(max-min)*factor;  
00669   min=(min-min)*factor;
00670   MSG("NuGeneral",Msg::kDebug)
00671     <<"Converted range to min="<<min<<", max="<<max<<endl;
00672   
00673   //now set the min and max for 10% above and below size of range
00674   for (vector<TGraph*>::iterator vIt=v.begin();vIt!=v.end();++vIt){
00675     (*vIt)->SetMinimum(min-0.1*(max-min));
00676     (*vIt)->SetMaximum(max+0.1*(max-min));
00677   }
00678 }

TGraph * NuGeneral::TGraphVect ( std::vector< Double_t > &  vX,
std::vector< Double_t > &  vY 
) const

Definition at line 595 of file NuGeneral.cxx.

References Munits::g, Msg::kDebug, Msg::kWarning, and MSG.

00597 {
00598   MSG("NuGeneral",Msg::kDebug) 
00599     <<" ** Running TGraphVect method... **"<<endl;
00600 
00601   if (vX.empty()) {
00602     MSG("NuGeneral",Msg::kWarning) 
00603       <<"TGraphVect: One or more vectors is empty"<<endl;
00604     return 0;
00605   }
00606 
00607   if (vX.size()!=vY.size()) {
00608     MSG("NuGeneral",Msg::kWarning) 
00609       <<"TGraphVect: vectors different sizes; returning..."<<endl;
00610     return 0;
00611   }
00612 
00613   TGraph* g=new TGraph(vX.size());
00614 
00615   UInt_t vSize=vX.size();
00616   for (UInt_t i=0;i<vSize;i++){
00617     g->SetPoint(i,vX[i],vY[i]);
00618   }
00619 
00620   MSG("NuGeneral",Msg::kDebug) 
00621     <<" ** Finished TGraphVect method **"<<endl;
00622   return g;
00623 }

void NuGeneral::TH1FFill ( TH1F *  h,
const std::vector< Double_t > &  vX,
const std::vector< Double_t > &  vY 
) const

This function fills a histogram using vX with a weight of vY

Definition at line 480 of file NuGeneral.cxx.

References Msg::kWarning, and MSG.

00482 {
00484 
00485   if (vX.empty() || vY.empty()) {
00486     MSG("NuGeneral",Msg::kWarning) 
00487       <<"One or more vectors is empty"<<endl;
00488     return;
00489   }
00490 
00491   if (!h){
00492     MSG("NuGeneral",Msg::kWarning) 
00493       <<"pointer==0"<<endl;
00494     return;
00495   }
00496 
00497   UInt_t vSize=vX.size();
00498   for (UInt_t i=0;i<vSize;i++){
00499     h->Fill(vX[i],vY[i]);
00500   }
00501 }

void NuGeneral::TH1FFill ( TH1F *  h,
const std::vector< Double_t > &  vX 
) const

Definition at line 458 of file NuGeneral.cxx.

References Msg::kWarning, and MSG.

Referenced by NuAnalysis::ChargeSignCut(), NuAnalysis::Efficiencies(), NuAnalysis::EnergySpect(), NuTime::FillTimeHistos(), and NuAnalysis::NuMuBarAppearance().

00459 {
00460   if (vX.empty()) {
00461     MSG("NuGeneral",Msg::kWarning) 
00462       <<"One or more vectors is empty"<<endl;
00463     return;
00464   }
00465 
00466   if (!h){
00467     MSG("NuGeneral",Msg::kWarning) 
00468       <<"pointer==0"<<endl;
00469     return;
00470   }
00471 
00472   UInt_t vSize=vX.size();
00473   for (UInt_t i=0;i<vSize;i++){
00474     h->Fill(vX[i]);
00475   }
00476 }

void NuGeneral::TProfile2DFill ( TProfile2D *  p,
std::vector< Double_t > &  vX,
std::vector< Double_t > &  vY,
std::vector< Double_t > &  vZ 
) const

Definition at line 541 of file NuGeneral.cxx.

References Msg::kWarning, and MSG.

00545 {
00546   if (vX.empty()) {
00547     MSG("NuGeneral",Msg::kWarning) 
00548       <<"FillTProfile2D: One or more vectors is empty"<<endl;
00549     return;
00550   }
00551 
00552   if (!p){
00553     MSG("NuGeneral",Msg::kWarning) 
00554       <<"FillTProfile2D: TProfile2D pointer==0"<<endl;
00555     return;
00556   }
00557 
00558   if (vX.size()!=vY.size() || vX.size()!=vZ.size()) {
00559     MSG("NuGeneral",Msg::kWarning) 
00560       <<"FillTProfile2D: vectors different sizes; returning..."<<endl;
00561     return;
00562   }
00563 
00564   UInt_t vSize=vX.size();
00565   for (UInt_t i=0;i<vSize;i++){
00566     p->Fill(vX[i],vY[i],vZ[i]);
00567   }
00568 }

void NuGeneral::TProfileFill ( TProfile *  p,
std::vector< Double_t > &  vX,
std::vector< Double_t > &  vY 
) const

Definition at line 505 of file NuGeneral.cxx.

References Msg::kDebug, Msg::kWarning, and MSG.

00508 {
00509   MSG("NuGeneral",Msg::kDebug) 
00510     <<" ** Running FillTProfile method... **"<<endl;
00511 
00512   if (vX.empty()) {
00513     MSG("NuGeneral",Msg::kWarning) 
00514       <<"FillTProfile: One or more vectors is empty"<<endl;
00515     return;
00516   }
00517 
00518   if (!p){
00519     MSG("NuGeneral",Msg::kWarning) 
00520       <<"FillTProfile: TProfile pointer==0"<<endl;
00521     return;
00522   }
00523 
00524   if (vX.size()!=vY.size()) {
00525     MSG("NuGeneral",Msg::kWarning) 
00526       <<"FillTProfile: vectors different sizes; returning..."<<endl;
00527     return;
00528   }
00529 
00530   UInt_t vSize=vX.size();
00531   for (UInt_t i=0;i<vSize;i++){
00532     p->Fill(vX[i],vY[i]);
00533   }
00534 
00535   MSG("NuGeneral",Msg::kDebug) 
00536     <<" ** Finished FillTProfile method **"<<endl;
00537 }


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1