AlexeyBoldyrev - 2016-02-16

shell

  • Find by name:
find . -name "filename"

  • Find the word foo in files recursively:
grep -r "foo" .

  • Rename sample.root to 2HDM_800.root recursively:
find . -iname "*sample.root*" -exec rename sample.root 2HDM_800.root '{}' \;

  • Compare two files including line permutations
diff <(sort file1) <(sort file2)

  • Display 2nd line of the file
awk 'NR==2' file.txt

  • Display 19th line from the end of the file
awk -v n=$n '{x[NR%19]=$0}END{print x[(NR+1)%19]}' file.txt

ROOT tips

Draw over sum
  • nominal_Loose->Draw("Sum$(jet_pt)","nJets==6","")

Get list of branches
  • root -l file.root
  • nominal->MakeClass()

Open a root file, then Print() and Scan() it.
{
  TFile f("wp.root" ) ;
  TTree *t = f.Get( "AOphysics" ) ;
  t->Print() ;
  t->Scan( "EVT", "passIso==1&&wLJ==1" ) ;
}
Example: physics->Scan("EventNumber:el_n:mu_n:tau_n:trk_n:jet_n:mcevt_weight:mc_n","EventNumber==10441484")

How to check duplicate events in a TTree?
root[0] myTree->SetScanField(0);
root[1] myTree->Scan("eventNb:runNb:LS:zVtx:Reco_QQ_4mom.M()"); >tree.log
$ wc -l tree.log
$ sort -u tree.log | wc -l
If the tree has duplicated events, both wc -l will not give same number of lines.

Draw variables with a selection using GUI

  • Mouse right click on the your Tree of "Files" panel/tab. Select StartViewer
  • Drag and drop your variable into X:
  • Drag and drop your cut variable into Scissors
  • Mouse right click on the Scissors. Select EditExpression and put desired selection

Draw variables from command line
  • TFile *f = new TFile("ttbar.root", "READ");
  • nominal->Draw("Centrality_all")
  • nominal->Draw("Centrality_all","weight_mc>0","same")

Draw normalised variables at the same canvas
nominal.Draw("TMVA_NB>>pos","","weight_mc==1")
pos->SetLineColor(kRed);
pos.GetYaxis()->SetRange(0.0,0.03)
Double_t scale = 1/pos.Integral()
pos.Scale(scale)
nominal.Draw("TMVA_NB>>neg","","weight_mc<0")
Double_t scale2 = 1/neg.Integral()
neg.Scale(scale2)
pos.Draw()
neg->SetLineColor(kBlue);
neg.Draw("same")
c1->SaveAs("ttbb_TMVA_NB_pos_neg.png")
.q

ROOT >6.06 features
https://root.cern.ch/how/how-quickly-inspect-content-file

Special variables
  • Alt$(primary,alternate) : return the value of "primary" if it is available for the current iteration otherwise return the value of "alternate". For example, with arr1[3] and arr2[2]
  • Entry$ : return the current entry number (same as TTree::GetReadEntry())
  • LocalEntry$ : return the current entry number in the current tree of a chain (same as GetTree()->GetReadEntry())
  • Entries$ : return the total number of entries (same as TTree::GetEntries())
  • Length$ : return the total number of element of this formula for this entry (same as TTreeFormula::GetNdata())
  • Iteration$ : return the current iteration over this formula for this entry (i.e. varies from 0 to Length$).
  • Length$(formula) : return the total number of element of the formula given as a parameter.
  • Sum$(formula) : return the sum of the value of the elements of the formula given as a parameter. For example the mean for all the elements in one entry can be calculated with: Sum$(formula)/Length$(formula)

Root Commands and Examples:

GRID tools

  • Setup rucio
setupATLAS
lsetup rucio
voms-proxy-init -voms atlas

  • List files:
rucio list-dids user.boldyrev.*02-09-1_output.root

  • Download datasets or files:
rucio download user.boldyrev.*02-09-1_output.root

  • Download single file:
For example, to download the file DAOD_TOPQ1.06850222._000001.pool.root.1 of the dataset rucio download mc15_13TeV.410000.PowhegPythiaEvtGen_P2012_ttbar_hdamp172p5_nonallhad.merge.DAOD_TOPQ1.e3698_s2608_s2183_r6765_r6282_p2442, do the following:
rucio download mc15_13TeV:DAOD_TOPQ1.06850222._000001.pool.root.1
or
rucio download --nrandom 1 mc15_13TeV:mc15_13TeV.343367.aMcAtNloPythia8EvtGen_A14_NNPDF23_NNPDF30ME_ttH125_allhad.merge.DAOD_TOPQ1.e4706_s2726_r7326_r6282_p2516

  • Find which dataset to which a file belongs
setupATLAS
lsetup rucio
rucio list-file-replicas mc15_13TeV:DAOD_TOPQ1.07174728._000001.pool.root.1
rucio list-file-replicas mc15_13TeV:DAOD_TOPQ1.06405917._000001.pool.root.1

  • Example download procedure
directory_download="/data/wbm/ATL-TAS/ATL-TAS-2015-150/records/2015-11-20T1645Z"
mkdir -p "${directory_download}"
cd "${directory_download}"
setupATLAS
localSetupRucioClients
voms-proxy-init -voms atlas
rucio list-dids user.aknue.*p2425.02-03-30-01-largeR25ns_newGRL_output.root
rucio download user.aknue.*p2425.02-03-30-01-largeR25ns_newGRL_output.root

SVN

  • http://svnbook.red-bean.com/
  • svn co svn+ssh://boldyrev@svn.cern.ch/reps/atlasinst/Institutes/UdineICTP/package package
  • svn co svn+ssh://boldyrev@svn.cern.ch/reps/atlasphys-exo/Physics/Exotic/HQT/FourTopsLJets/Run2/Moriond2016/trunk trunk

To update or commit:
svn update [files]
svn commit [files] -m 'comments'

Other useful SVN commands:
  • to setup our group svn: export SVNROOT=svn+ssh://svn.cern.ch/reps/atlasinst/Institutes/UdineICTP
  • to get a package: svn co $SVNROOT/< Package > Package
  • to update: svn update
  • to commit changes: svn commit [] -m "< description >"
  • svn info (info about files)
  • svn log --limit 3 (last 3 log entries)
  • svn status -u (shows if file is out-of-date w.r.t. repsoitory with * in 8th column)
  • svn resolve --accept working sandwich.txt (After manual edit of file to resolve conflict by hand using working copy)
  • svn propset svn:keywords "Date Author Rev" (then add fixed width tags $Rev:: $ )
  • svn propedit svn:ignore . (then add filenames and wildcard patterns to list of files to ignore for directory ".")
  • svn log -v -r HEAD:BASE (shows log entries between your base version and the head version. -v option is verbose = shows which files changed)
  • svnadmin create RepositoryName (cd to directory where you want the repo first!)
  • svnadmin dump /path/to/repository > repository-name.dmp (export entire repository to a file)
  • svnadmin load --force-uuid repository-name< repository-name.dmp (import entire repository from a file)
  • svnadmin recover /path/to/repository (makes repository self-consistent again - use if you get errors)
  • svn diff --diff-cmd /usr/bin/diff -x "-B -b" (use your own diff command and pass args into it)
  • svn status -v -N (list each files status and which revision it was last modified, do not recurse into subdirs (-N) )

SVN Twiki:

LaTeX

  • (lxplus) export PATH=/afs/cern.ch/sw/XML/texlive/latest/bin/x86_64-linux:$PATH
  • spell-check: ispell -d british -t file.tex

PDF tricks

  • Insert blank page after every page (useful for slides review)
#!/bin/bash

if [ $# -ne 1 ]
then
  echo "Usage example: ./bashscript src.pdf"
  exit $E_BADARGS
else
  NUM=$(pdftk $1 dump_data | grep 'NumberOfPages' | awk '{split($0,a,": "); print a[2]}')
  COMMSTR=''

  for i in $(seq 1 $NUM);
  do
    COMMSTR="$COMMSTR A$i B1 " 
  done
  $(echo "" | ps2pdf -sPAPERSIZE=a4 - pageblanche.pdf)
  $(pdftk A=$1 B=pageblanche.pdf cat $COMMSTR output 'mod_'$1)
  (pdfnup 'mod_'$1 --nup 1x1 --landscape --outfile 'print_'$1)
  $(rm pageblanche.pdf && rm 'mod_'$1)

fi
Edit | Attach | Watch | Print version | History: r19 < r18 < r17 < r16 < r15 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r19 - 2018-03-12 - AlexeyBoldyrev
 
    • 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-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback