Logbook Christian

Ganga Merge Script

#!/usr/bin/env python

import fileinput, string, sys, os, subprocess
import re
import ROOT
from optparse import OptionParser
from xml.dom import minidom

parser = OptionParser()
parser.add_option('-j', '--jobid', action='store', type='int', dest='jobid')
parser.add_option('-t', '--type', action='store', type='string', dest='type')
parser.add_option('-f', '--file', action='store', type='string', dest='Outputname')
parser.add_option('-R', '--resubmit', action='store', type='string', dest='Resubmit')
(options, args) = parser.parse_args()

jobid = options.jobid
Outname = options.Outputname


if options.type == 'BLppi Events' :
    expr = 'BLppi_Tuple/#accept'
    SearchTuple = 'BLppi_Tuple/DecayTree'
    RootFile = 'BLppiTuple.root'
if options.type == 'BKSpipi Events' :
    expr = 'BKSpipi_Tuple/#accept'
    SearchTuple = 'BKSpipi_Tuple/DecayTree'
    RootFile = 'BLppiTuple.root'

if options.type == 'BDpp Events' :
    expr = 'BDppbar_Tuple/#accept'
    SearchTuple = 'BDppbar_Tuple/DecayTree'
    RootFile = 'BDppbarTuple.root'
if options.type == 'BDpipi Events' :
    expr = 'BDpipi_Tuple/#accept'
    SearchTuple = 'BDpipi_Tuple/DecayTree'
    RootFile = 'BDppbarTuple.root'

if options.type == 'D0 Events' :
    expr = re.compile(r'\| \"D0 Candidates\"')
    SearchTuple = 'D0Data/D0Data'
    RootFile = 'D0Data.root'
if options.type == 'MuMu Events' :
    expr = re.compile(r'\"JpsiData\/J\/psi Candidates\"')
    SearchTuple = 'JpsiData/JpsiData'
    RootFile = 'JpsiData.root'
if options.type == 'Lambda Events' :
    expr = re.compile(r'\| \"Lambda Candidates\"')
    SearchTuple = 'LamData/LamData'
    RootFile = 'LamData.root'

fail = []
done = []
nofile = []
hanging = []
tocopy = []

for k in xrange(len(jobs(jobid).subjobs)) :
    if jobs(jobid).subjobs(k).status == 'failed' :
        fail.append(k)
    if jobs(jobid).subjobs(k).status == 'completed' :
        done.append(k)
    if jobs(jobid).subjobs(k).status == 'submitted' :
        hanging.append(k)

for i in done :
    filename = '/afs/cern.ch/user/c/cvoss/gangadir/workspace/cvoss/LocalXML/' + str(jobid) + '/' + str(i) +'/output/summary.xml'
    # try:
    #     file = open(filename,'r')
    # except IOError as (errno, strerror):
    #     print 'no OutputFile for job ' + str(i)
    # data = file.read()
    # file.close()
    xmlDoc = minidom.parse(filename)
    xmlList = xmlDoc.getElementsByTagName('counter')
    for s in xmlList :
        if s.attributes['name'].value == expr:
            if s.childNodes[0].nodeValue != '0':
                tocopy.append(i)
    # found = False
    # for line in file :
    #     found = found or (expr.search(line) is not None)
    # if not found : nofile.append(i)
    # if found : tocopy.append(i)

print 'Jobs with undefined status: ' + str(hanging)
print 'Jobs without closed rootfile: ' + str(nofile)
print 'Jobs failed: ' + str(fail)
print 'Jobs succesfull: ' + str(tocopy)

if options.Resubmit == 'True' :
    for i in nofile :
        jobs(jobnum).subjobs(i).resubmit()
    for i in hanging :
        jobs(jobnum).subjobs(i).kill()
        jobs(jobnum).subjobs(i).resubmit()
    for i in fail :
        jobs(jobnum).subjobs(i).resubmit()
    sys.exit("Finished resubmitting")

t = ROOT.TChain(SearchTuple)   

for file in tocopy :
    rootfile = '/castor/cern.ch/user/c/cvoss/' + str(jobid) + '/' + str(file) + '/outputdata/' + RootFile
    t.Add(rootfile)
print 'Merging File'
outfilename = '/castor/cern.ch/user/c/cvoss/MergedData/' + Outname
print outfilename
t.Merge(outfilename)

Download from GRID

#!/bin/bash

source ~/.bashrc
SetupProject LHCbDirac
cd $2

for i in $(cat $1)
do
    echo "Downloading $i"
    DIR=`echo $i | cut -d "." -f 2 | cut -d "/" -f 1`
    mkdir $DIR
    cd $DIR
    dirac-dms-get-file $i
    cd ..
done

Ganga making Local() backend use specified folder

Open
$MYSITEROOT/lhcb/GANGA/GANGA_<version>/install/ganga/python/Ganga/Lib/Localhost/Localhost.py
Change True to False in
config.addOption('remove_workdir', True, 'remove automatically the local working directory when the job completed')
Add another option, default is empty,
/tmp
will be used in this case
config.addOption('work_path', '', 'Location for tmp data')
Modify
workdir = tempfile.mkdtemp()
to be
workdir = tempfile.mkdtemp(prefix=config['work_path'])
Set Path in
.gangarc
accordingly

Requirements file for running RooFit in DaVinci

#============================================================================
# Created    : 2002-05-23
# Maintainer : Juan Palacios
#
# Documentation on the requirement file can be found at
# http://cern.ch/lhcb-comp/Support/html/new_structure.pdf
#============================================================================
package           DaVinciUser
version           v8r5p2

#============================================================================
# Structure, i.e. directories to process. 
#============================================================================
branches          cmt doc src options

#============================================================================
# Used packages.
#============================================================================
use DaVinciKernel      v*    Phys
use MCEvent            v*    Event
use LinkerEvent        v*    Event
use LoKi               v*    Phys                                                                                                            
use DecayTreeTuple     v*    Phys
use DecayTreeFitter    v*    Phys
use ROOT               v*    LCG_Interfaces

macro_append ROOT_linkopts " -lTreePlayer -lCore -lGui -lHist -lGpad -lMathCore -lMatrix -lPhysics -lRooFit -lRooFitCore -lFoam -lMinuit -lRooStats -lTMVA" 
#============================================================================
# Component library building rule
#============================================================================
library          DaVinciUser    ../src/*.cpp -import=AIDA

#============================================================================
# define component library link options
#============================================================================
apply_pattern component_library library=DaVinciUser
#============================================================================

Textformat für TH2D

Hi Tim,

If you take the version in CVS, you can set the format via gStyle->SetPaintTextFormat(format); The default is format="g"

Rene Brun

Timothy E. Miller wrote: >
> Dear ROOT-ers,
>
> I am pretty sure it is possible but I can't find the
> documentation. How does one set the format of the
> histogram bin contents when executing the TH2::Draw("TEXT")
> command?
>
> i.e. instead of as many decimal places as will fit due
> to text size, I would like the format to be forced at
> something like 1.23 (3.2g or 4.2g...I always forget how
> to count these things)
>
> Thanks in advance,
> -Tim

Hi,

What you get with "option 2" is the expected behavior: When the whole histogram content is >=0 the empty bins (=0) are not drawn. So you see the pad color for these bins. Only if there is negative bins, the bins with content 0 are painted normally because they might be not empty. I agree there is a problem with "option 3" . I am fixing it right now. To bypass the problem you can do: gStyle->SetHistTopMargin(0);

or:

histo->SetMinimum(-1);

I'll let you know when it will be fixed.

Cheers, Olivier

Track Definitions

TrackTypes
   { TypeUnknown = 0,                // track of undefined type
                Velo = 1,            // VELO track
                VeloR = 2,           // 2D VELO track
                Long = 3,            // forward track
                Upstream = 4,        // upstream track
                Downstream = 5,      // downstream track
                Ttrack = 6,          // seed track
                Muon = 7,            // muon track
                Calo = 8,            // calo cosmics track
                TT = 9               // TT track
      };

Eos Usage

Mounting EOS on lxplus

You can mount EOS into your AFS home directory as follows:

bash-3.2$ mkdir -p $HOME/eos
bash-3.2$ eosmount $HOME/eos
OK
===> Mountpoint   : /afs/cern.ch/user/t/test/eos
===> Fuse-Options : kernel_cache,attr_timeout=30,entry_timeout=30,max_readahead=131072,max_write=4194304,fsname=eoslhcb.cern.ch root://eoslhcb.cern.ch//eos/
===> xrootd ra             : 131072
===> xrootd cache          : 393216
===> fuse debug            : 0
===> fuse write-cache      : 1
===> fuse write-cache-size : 100000000

Please unmount it once you are over or before you log out !!!

bash-3.2$ eosumount $HOME/eos
or if you have some hanging mount
bash-3.2$ eosforceumount $HOME/eos

Warning: after 24h the mount has to re-authenticate and your kerberos token will have expired in the meanwhile. So whenever you login into lxplus re-fresh (=eosumount + eosmount) any existing mount (even better don't let it there).

Disclaimer: the FUSE module is not recommended for production usage and the use is at your own risk. EOS is not mounted/mountable on lxbatch nodes!

Find more information: http://eos.cern.ch/index.php?option=com_content&view=article&id=87:using-eos-at-cern&catid=31:general&Itemid=41

Boost Library usage for command line options

// Include the headers relevant to the boost::program_options
// library
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/tokenizer.hpp>
#include <boost/token_functions.hpp>

using namespace boost;
using namespace boost::program_options;

#include <iostream>
#include <fstream>

// Include std::exception so we can handling any argument errors
// emitted by the command line parser
#include <exception>

using namespace std;

int main(int argc , char **argv)
{

// Add descriptive text for display when help argument is
// supplied
options_description desc(
    “\nAn example command using Boost command line “
    ”arguments.\n\nAllowed arguments”);

// Define command line arguments using either formats:
//
//     (“long-name,short-name”, “Description of argument”)
//     for flag values or
//
//     (“long-name,short-name”, <data-type>, 
//     “Description of argument”) arguments with values
//
// Remember that arguments with values may be multi-values
// and must be vectors
desc.add_options()
    (“help,h”, “Produce this help message.”)
    (“memory-report,m”, “Print a memory usage report to “
     ”the log at termination.”)
    (“restart,r”, “Restart the application.”)
    (“template,t”, “Creates an input file template of “
     ”the specified name and then exits.”)
    (“validate,v”, “Validate an input file for correctness ”
     ”and then exits.”)
    (“output-file,o”, value< vector<string> >(),
     “Specifies output file.”)
    (“input-file,i”, value< vector<string> >(),
     “Specifies input file.”);

// Map positional parameters to their tag valued types 
// (e.g. –input-file parameters)
positional_options_description p;
p.add(“input-file”, -1);

// Parse the command line catching and displaying any 
// parser errors
variables_map vm;
try
{
    store(command_line_parser(
    argc, argv).options(desc).positional(p).run(), vm);
    notify(vm);
} catch (std::exception &e)
{
    cout << endl << e.what() << endl;
    cout << desc << endl;
}

// Display help text when requested
if (vm.count(“help”))
{
    cout << “–help specified” << endl;
    cout << desc << endl;
}

// Display the state of the arguments supplied
if (vm.count(“memory-report”))
{
    cout << “–memory-report specified” << endl;
}

if (vm.count(“restart”))
{
    cout << “–restart specified” << endl;
}

if (vm.count(“template”))
{
    cout << “–template specified” << endl;
}

if (vm.count(“validate”))
{
    cout << “–validate specified” << endl;
}

if (vm.count(“output-file”))
{
    vector<string> outputFilename =
        vm["output-file"].as< vector<string> >();
    cout << “–output-file specified with value = “
        << outputFilename[0] << endl;
}

if (vm.count(“input-file”))
{
    vector<string> inputFilename =
        vm["input-file"].as< vector<string> >();
    cout << “–input-file specified with value = “
        << inputFilename[0] << endl;
}

return EXIT_SUCCESS;

}
How to accept empty value in boost::program_options
desc.add_options()
 ("replay,r", po::value<std::string>()->implicit_value("stdin"), "bla bla bla")

Use latex in multithreaded mode

pdflatex --shell-escape main.tex && make -j 4 -f main.makefile && pdflatex --shell-escape main.tex 

Use TF2 C-compiled function in a program to be compiled as well

A TF1 can be created from any C++ class implementing the operator()(double *x, double *p). The advantage of the function object is that he can have a state and reference therefore what-ever other object. In this way the user can customize his function.

Example:

class  MyFunctionObject {
 public:
   // use constructor to customize your function object
   double operator() (double *x, double *p) {
      // function implementation using class data members
   }
};
{
    ....
   MyFunctionObject fobj;
   TF1 * f = new TF1("f",fobj,0,1,npar);    // create TF1 class.
   .....
}

-- ChristianVoss - 21-Mar-2013

Edit | Attach | Watch | Print version | History: r19 < r18 < r17 < r16 < r15 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r19 - 2016-04-06 - ChristianVoss
 
    • 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-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback