-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaddHistos.sh
executable file
·53 lines (49 loc) · 1.32 KB
/
addHistos.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Originally written by Samuel May <sjmay@ucsd.edu>
# Modified (slightly) by Philip Chang <philip@ucsd.edu>
### Function to add large numbers (>100) of histograms using hadd ###
### hadd seems to have a limit on the number of histograms you can give it, ###
### this adds histos in groups of 100 so you can sleep easy knowing that hadd ###
### hasn't skipped over any of your well-deserved histograms ###
### Arg1: name of output histogram (e.g. "histosMaster") ###
### Arg2: name of input histogram (e.g. "histosToAdd_4.root" would be input ###
### as "histosToAdd" ###
### Arg3: (OPTIONAL) number of cores to run on (default 1) ###
function addHistos
{
if (( $# < 3 ))
then
nPar=1
else
nPar=$3
fi
NFILES=$(ls ${2}*.root | wc -l)
echo $NFILES
histosToAdd=""
bigHistos=""
idx1=1
idx2=1
while (($idx1 <= ${NFILES}))
do
for ((i=1; i<=100; i++))
do
if (($idx1 <= ${NFILES}))
then
if [ -e $2"_"$idx1".root" ]; then
histosToAdd=$histosToAdd" "$2"_"$idx1".root"
fi
let "idx1++"
fi
done
hadd -f -k $1"_"$idx2".root" $histosToAdd &
if (($idx2 % $nPar == 0))
then
wait
fi
bigHistos=$bigHistos" "$1"_"$idx2".root"
histosToAdd=""
let "idx2++"
done
wait
hadd -f -k $1".root" $bigHistos
}
addHistos $*