templates

loop in bins of TH2F

for(int bx=1; bx<=h2->GetNbinsX(); ++bx){
  

canvas + empty frame with axis

TCanvas *c = new TCanvas("c","c", 700, 500);
c->DrawFrame( 0, 0, 50, 100);

canvas

TCanvas *c = new TCanvas("c","c", 700, 500);
c->SetFillColor(0); 
c->SetFillStyle(0); 
c->SetHighLightColor(0);
//c->SetTopMargin(0.06);
//c->SetRightMargin(0.05);
//c->SetBottomMargin(0.13);      
//c->SetLeftMargin(0.15);
//c->SetGridy();

char name[500];
sprintf(name,"plot.png");
c->Print(name,"png"); 

kip

  TH2F *kip = new TH2F("kip",NULL,2, 0, 1, 2, 0, 1);
  kip->SetStats(kFALSE);
  kip->GetXaxis()->SetTitle("");
  kip->GetYaxis()->SetTitle("");
  kip->GetXaxis()->SetNdivisions(505);
  kip->GetXaxis()->SetTitleFont(42);
  kip->GetXaxis()->SetTitleSize(0.05);
  kip->GetXaxis()->SetLabelSize(0.05);
  kip->GetXaxis()->SetTitleOffset(1.1);               
  kip->GetYaxis()->SetTitleFont(42);
  kip->GetYaxis()->SetLabelSize(0.05);  
  kip->GetYaxis()->SetTitleSize(0.05);
  kip->GetYaxis()->SetTitleOffset(1.0);

graph

  • from a csv file

  TGraph *gr = new TGraph("../data/4148.csv","%lg %lg"," \t,;");
  gr->SetMarkerStyle(20);
  gr->SetMarkerSize(1.2);
  gr->SetMarkerColor(4);
  gr->SetLineColor(4);
  gr->SetLineWidth(1);

legend

TLegend* leg=new TLegend(0.15, 0.7, 0.3, 0.8);
leg->SetFillColor(0);
leg->SetBorderSize(1);
leg->SetTextSize(0.04);
leg->SetTextFont(42);
leg->SetNColumns(2);
leg->AddEntry(f1,"function","L");

TF1

  TF1 *f1 = new TF1("f1","[0]+[1]*x", 0, 1);
  f1->SetParName(0,"Ordinate"); 
  f1->SetParName(1,"Slope"); 
  f1->SetParameters(0,1);
  f1->SetLineStyle(1);
  f1->SetLineWidth(2);
  f1->SetLineColor(2);

TLine

  TLine *l1 = new TLine(0, 200, 50, 200);
  l1->SetLineWidth(3);
  l1->SetLineStyle(1);

Get list of keys and iterate

TFile *f = new TFile(name);
if(f->IsZombie()){
   cout << "Could not open file " << name << endl;
   return;
}

TIter next(f->GetListOfKeys());
TKey *key;
int cnt=0;
while ((key = (TKey*)next())) {
   cout << key->GetName() << " " << key->GetClassName() << endl;
   TClass *cl = gROOT->GetClass(key->GetClassName());
   if(cl->InheritsFrom("TH1"))
      cnt++;
}

Command line arguments to CINT macro

root -l 'Compare.C("arg1","arg2")'

Read ascii file and create TTree

This works also within CINT.

TFile *file = new TFile(outFileName,"RECREATE");
TTree *tree = new TTree("tree","tree");

float a,b,c;
tree->Branch("a",&a,"a/F");
tree->Branch("b",&b,"b/F");
tree->Branch("c",&c,"c/F");

char line[4096];
istringstream iss;
stringbuf *pbuf;  
int rtmp, cnt=0;
  
ifstream ff(filename);
if(ff){
  cout << "Filename '" << filename << "' opened ok" << endl;   
  do {
    ff.getline(line, 4096);
    iss.str(line);
    iss.clear(std::ios::goodbit);
    pbuf = iss.rdbuf();
    rtmp = pbuf->pubseekoff(0, std::ios::beg, std::ios::in);      
    if(strchr("#",line[0])) continue; // skip comments
    if(cnt==0){ cnt++; continue; } // skip first line
  
    iss >> a >> b >> c;
    tree->Fill();
    cnt++;
    } while ( ff.good() );          
  }
  else{
    cout << " ----> can't find  file " << filename << ". Exiting..."  << endl << endl;    
  }

  tree->Print();
  tree->Write();
  file->Close();

Source compilation with Python support

v6.20.04, python 3.7

Python

  • install Python 3.8 from https://www.python.org/downloads/mac-osx/
    • the pkg installer will install the Framework in /Library/Frameworks/Python.framework/Versions/3.8 and links are created within /usr/local/bin
  • install additional python packages: pip3 install --user numpy pandas matplotlib root_numpy root_pandas

ROOT and required packages

% tar xvzf root_v6.20.04.source.tar.gz
% cd root-6.20.04
% mkdir build
% cd build
  • configure, make and install
    • in case of need, check cmake options cmake --help-variable-list
% cmake ../ \
-DCMAKE_INSTALL_PREFIX=/Users/sevilla/cernbox/Software/OSX/root/v6.20.04.macosx64-10.14-clang110-src \
-DPYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.8/bin/python3 \
-DPYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 \
-DPYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.8/lib \
-Dbuiltin_glew=ON \
-DGLEW_INCLUDE_DIR=/usr/local/Cellar/glew/2.1.0_1/include
% make -j4
% make install

Verify everything works ok:

[sevilla@Sergios-MBP]:~$ python
Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>>

v5.30.06, python 2.7

./configure macosx \
--prefix=/Users/sevilla/software/root/v5.32.00.macosx106-i386-gcc-4.2-python27 \
--incdir=/Users/sevilla/software/root/v5.32.00.macosx106-i386-gcc-4.2-python27/include \
--libdir=/Users/sevilla/software/root/v5.32.00.macosx106-i386-gcc-4.2-python27/lib \
--etcdir=/Users/sevilla/software/root/v5.32.00.macosx106-i386-gcc-4.2-python27/etc \
--with-x11-libdir=/opt/local/lib \
--with-xpm-libdir=/opt/local/lib \
--with-xft-libdir=/opt/local/lib \
--with-xext-libdir=/opt/local/lib \
--with-python-incdir=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 \
--with-python-libdir=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib \
--enable-builtin-freetype \
--disable-xrootd

    • make
    • make install
    • run python in 32-bit mode: alias python="arch -i386 /opt/local/bin/python2.7"

  • 64-bit, Python 2.7:
    • same command as above, but architecture left to macosx64 or blank (64-build will be used by default)
    • no need to start python in 32-bit: alias python="/opt/local/bin/python2.7"

ROOT compilation through cygwin and VS

export PATH=$PATH:/c/Program\ Files/Microsoft\ Visual\ Studio\ 10.0/Common7/IDE
export PATH=$PATH:/c/Program\ Files/Microsoft\ Visual\ Studio\ 10.0/Common7/Tools
export PATH=$PATH:/c/Program\ Files/Microsoft\ Visual\ Studio\ 10.0/VC/bin
    • edit C:\cygwin\Cygwin.bat and add
call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
so that the file should look like as:
@echo off
call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
C:
chdir C:\cygwin\bin
bash --login -i
  • download a ROOT development version (source code) from http://root.cern.ch/drupal/content/downloading-root
    • extract the .tar.gz either using a windows-based application (7-zip) or the command line through cygwin
  • open a cygwin console and cd to: /cygdrive/c/root_source
    • please note that if the cygwin setup has been correctly done, the following advertisement has to be displayed in the first line of the new shell :
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
  • ./configure and solve the missing dependencies from the default cygwin installation
    • root 5.29.02, only GNU make >= 3.80 was missing, so good enough
    • you might want to leave the options of the configure script to their default values, in which case ROOT will be installed within the HOME area of the current user in the cygwin windows directory (e.g. C:\cygwin\home\sevilla). If we want to install it within C: (outside the cygwin structure), we can change the prefix argument:
  • remove /usr/bin/link.exe (see this post http://root.cern.ch/phpBB3/viewtopic.php?f=5&t=10624&p=45824&hilit=unknown+option+l+cygwin#p45824)
  • compile with make

-- SergioGonzalez - 2016-08-26

Edit | Attach | Watch | Print version | History: r12 < r11 < r10 < r9 < r8 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r12 - 2020-06-30 - SergioGonzalez
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback