-
Notifications
You must be signed in to change notification settings - Fork 1
/
RootReader.sh
1260 lines (1039 loc) · 44.3 KB
/
RootReader.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#rm read
# -rpath option might be necessary with some ROOT installations
# -lSpectrum option might be necessary with some ROOT installations
#g++ geometry.C read.C analysis.C main.C -rpath ${ROOTSYS}/lib `root-config --libs --cflags` -lSpectrum -o read
#g++ geometry.C read.C analysis.C main.C `root-config --libs --cflags` -lSpectrum -o read
threadsStarted=0
threadCounter=0
counter=0
stopNewThreads="0"
fastRunNumber=0
fastInFolder=0
fastOutfolder=0
fastHeaderSize=0
fastRunDir=0
fastRunName=0
fastLineArr=0
showInformation() {
echo " _____ _ _____ _ "
echo " | __ \ | | | __ \ | | "
echo " | |__) |___ ___ | |_| |__) |___ __ _ __| | ___ _ __ "
echo " | _ // _ \ / _ \| __| _ // _ \/ _\` |/ _\` |/ _ \ '__|"
echo " | | \ \ (_) | (_) | |_| | \ \ __/ (_| | (_| | __/ | "
echo " |_| \_\___/ \___/ \__|_| \_\___|\__,_|\__,_|\___|_| "
echo " "
echo " _ _ _ _ _ _ _ _ _ _ _ _ ";
echo " / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ ";
echo " ( F | i | n | a | l ) ( V | e | r | s | i | o | n )";
echo " \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ ";
echo " "
echo "This tool helps you to start your prefered ROOT reading analysis."
echo "Made with love by Jan Zimmermann in 2019/2020 ([email protected])"
echo "-------------------------------------------------------"
}
checkDependencies() {
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' zenity | grep "ok installed")
if [ "" == "$PKG_OK" ]; then
echo Please enter the sudo password to install Zenity
sudo apt-get install zenity
else
echo "Zenity is installed! "
fi
BUS_OK=$(dpkg-query -W --showformat='${Status}\n' dbus-x11 | grep "ok installed")
if [ "" == "$BUS_OK" ]; then
echo Please enter the sudo password to install DBUSx11
sudo apt-get install dbus-x11
else
echo "dbus-x11 is installed! "
fi
}
chooseOutFolder() {
checkDependencies
outFolder=$(zenity --file-selection --directory --title "Select output Folder (.bin Files)?")
# echo $outFolder
}
chooseInFolder() {
checkDependencies
inFolder=$(zenity --file-selection --directory --title "Select input Folder (.bin Files)?")
}
createInAndOutFolder() {
if [ ! -d "$1" ]; then
mkdir "$1"
fi
if [ ! -d "$2" ]; then
mkdir "$2"
fi
}
parseRunList() {
dir_name=$0
rl_file=$1
nameSchema=$2
# construct array. contains the elements separated by "_" delimiter in $dir_name
IFS="_" read -r -a fields <<<"$dir_name"
nfields=${#fields[@]}
# get run number
runNr=${fields[0]}
if [ "$nameSchema" == "2019" ]; then
# get pdgID, beam energy
#11_pos3_angle0_e26_ch32
# pos=$(echo ${fields[1]} | cut -c 4-)
pos=$(echo ${fields[1]} | cut -c 4-)
angle=$(echo ${fields[2]} | cut -c 6-)
energy=$(echo ${fields[3]} | cut -c 2-)
channel=$(echo ${fields[4]} | cut -c 3-)
# echo "Runlist (2019) creating..."
line_to_runlsit="$runNr $dir_name $pos $angle $energy $channel"
else
runParticle=${fields[1]}
case $runParticle in
muon[6])
pdgID="-13"
energy="6"
;;
pion[1-6])
pdgID="211"
energy=$(echo $runParticle | cut -c 5)
;;
e5)
pdgID="-11"
energy=5
;;
*)
echo "UNKNOWN particle description in run $runNr"
;;
esac
# get measurement position
runMP=${fields[2]}
case $runMP in
pos[0-9] | pos[1][0-9]) # 0°/30° measurements, no xy-coordinates
frontMP=$(echo $runMP | cut -c 4-)
;;
scanBD) # 90° WOM scans, hardcoded $sideMP
side_pos_x=${fields[3]}
side_pos_y=${fields[4]}
case $side_pos_y in
0)
case $side_pos_x in
0) sideMP=18 ;; 6) sideMP=19 ;; 12) sideMP=20 ;; 18) sideMP=21 ;; 24) sideMP=22 ;;
esac
;;
1)
case $side_pos_x in
0) sideMP=23 ;; 6) sideMP=24 ;; 12) sideMP=25 ;; 18) sideMP=26 ;; 24) sideMP=27 ;;
esac
;;
2)
case $side_pos_x in
0) sideMP=28 ;; 6) sideMP=29 ;; 12) sideMP=30 ;; 18) sideMP=31 ;; 24) sideMP=32 ;;
esac
;;
3)
case $side_pos_x in
0) sideMP=33 ;; 6) sideMP=34 ;; 12) sideMP=35 ;; 18) sideMP=36 ;; 24) sideMP=37 ;;
esac
;;
esac
;;
*)
echo "UNKNOWN position description in run $runNr"
;;
esac
# get angle
case $nfields in
3)
angle="0"
;;
4)
angle="0"
;;
5)
angle=$(echo "${fields[3]}" | cut -c 6-)
;;
7)
angle=$(echo "${fields[5]}" | cut -c 6-)
;;
*)
echo "UNKNOWN angele description in run $runNr"
;;
esac
######################
## PRINT TO RUNLIST ##
######################
# line_to_runlsit
case $nfields in
[3-5])
line_to_runlsit="$runNr $dir_name $frontMP $pdgID $energy $angle"
;;
7)
line_to_runlsit="$runNr $dir_name $sideMP $pdgID $energy $angle $side_pos_x $side_pos_y"
;;
esac
echo "Runlist (2018) creating..."
fi
#echo "$line_to_runlsit"
echo "$line_to_runlsit" >>"$rl_file"
}
compileRead() {
echo "Compiling Read.C..."
g++ ./src/geometry.C ./src/read.C ./src/analysis.C ./src/main.C ./src/misc.C $(root-config --libs --cflags) -lSpectrum -o ./src/read
echo "Compiling done!"
}
readFull() {
if [ "$shouldCompile" = true ]; then
compileRead
fi
runNr=$1
readAll=false
inFolder=$2
outFolder=$3
headerSize=$4
saveFolder=$outFolder
echo "$runNr"
echo "$2"
echo "$3"
echo "$4"
echo "$saveFolder"
if [[ " ${runNumber[@]} " =~ "a" ]]; then
readAll=true
fi
mkdir "$saveFolder"
while read line; do
[[ $line == \#* ]] && continue
lineArr=($line)
doRun="0"
if [[ " ${runNumber[@]} " =~ " ${lineArr[0]} " ]]; then
# echo "PRINT 2: " ${runNumber[@]} ${lineArr[0]}
doRun="1"
fi
if [ "$doRun" = "1" ] || [ $readAll = true ]; then
runName=${lineArr[1]}
runDir=$saveFolder/$runName
mkdir "$runDir"
if [ ! -e runDir/$runName.list ]; then
ls $inFolder/$runName | grep \.bin >$runDir/$runName.list
fi
#time $here/readFull $runDir/$runName.list $inFolder/$runName/ $runDir/out.root ${lineArr[0]} ${lineArr[2]} ${lineArr[3]} ${lineArr[4]} ${lineArr[5]} ${lineArr[6]}
time ./src/read $runDir/$runName.list $inFolder/$runName/ $runDir/$runName.root $runName $headerSize "$isDC" "$dynamicBL" "$useCalibValues" "${lineArr[0]}" "${lineArr[1]}" "${lineArr[2]}" "${lineArr[3]}" "${lineArr[4]}" "${lineArr[5]}" "$automaticWindow" "$iWForceRun"
fi
done <./RootRunlist.txt
}
compileMerger() {
echo "Compiling Root Merger..."
g++ ./src/mergeROOTFiles.C $(root-config --libs --cflags) -lSpectrum -o ./src/mergeROOTFiles
echo "Compiling done!"
}
merger() {
rootFileList=$1
./src/mergeROOTFiles $rootFileList $2 $3
#merge PDF Waves.pdf
pdfunite $(find $2 -name "*waveforms.pdf") $2/waveforms.pdf
pdfunite $(find $2 -name "*waveforms_chSum.pdf") $2/waveforms_chSum.pdf
pdfunite $(find $2 -name "*waveforms_womSum.pdf") $2/waveforms_womSum.pdf
}
installPDFUnite() {
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' poppler-utils | grep "ok installed")
if [ "" == "$PKG_OK" ]; then
echo Please enter the sudo password to install PDF Unite to create PDF files
sudo apt-get install poppler-utils
else
echo "PDFUnite is installed! "
fi
}
readFast() {
if [ "$shouldCompile" = true ]; then
compileRead
fi
installPDFUnite
compileMerger
readAll=false
inFolder=$2
outFolder=$3
headerSize=$4
saveFolder=$outFolder
if [[ " ${runNumber[@]} " =~ "a" ]]; then
readAll=true
fi
mkdir "$saveFolder"
rootFileList=""
# " ${runNr[@]} " =~ " ${lineArr[0]} "
time (
while read line; do
# echo $line
[[ $line == \#* ]] && continue #Wenn die Zeile leer ist wird "continue" ausgeführt
lineArr=($line)
doRun="0"
if [[ " ${runNumber[@]} " =~ " ${lineArr[0]} " ]]; then
# echo "PRINT 2: " ${runNumber[@]} ${lineArr[0]}
doRun="1"
fi
if [ "$doRun" = "1" ] || [ $readAll = true ]; then #lineArr ist ein Array aus jeder Zeile, getrennt durch Leerzeichen. linearray[0] ist die Run NUMMER
rootFileList=""
runName=${lineArr[1]}
runDir=$saveFolder/$runName
mkdir "$runDir"
rm -rf $runDir/*
if [ ! -e $runDir/$runName.list ]; then
ls $inFolder/$runName | grep \.bin >$runDir/$runName.list #Durchsucht das RunName verzeichnis nach bins files und erstellt eine Runlist
fi
counter=0
threadCounter=0
#Für jede Bin einzeln durchlaufen
while read lineTemp; do
# ls *.cfg | xargs -P 4 -n 1 read_cfg.sh
# Create RunList for every file
echo $lineTemp >$runDir/$counter.list
mkdir $runDir/$counter
runDirRelative="${runDir//$here/}"
rootTreeFilePath=".$runDirRelative/$counter/out.root/T"
rootFileList="${rootFileList}||$rootTreeFilePath"
counter=$((counter + 1))
done \
<$runDir/$runName.list
fastInFolder=$inFolder
fastOutFolder=$outFolder
fastHeaderSize=$headerSize
fastRunDir=$runDir
fastLineArr=($line)
fastRunName=${fastLineArr[1]}
fastRunNumber=$runNr
remainder=$((counter % threads))
loopNumber=$((counter / threads))
#loopNumber=$((loopNumber - 1)) #to have to correct number in the loop
# if [ "$remainder" != "0" ]; then
# loopNumber=$((loopNumber + 1))
# fi
echo "Loop Number: $loopNumber Number of Files: $counter Extra Threads: $remainder Threads: $threads"
for currentBin in $(seq 1 $loopNumber); do
echo "Main Thread Loop Started"
for ((i = 0; i < "$threads"; i++)); do
readFastIteration $threadCounter &
threadCounter=$((threadCounter + 1))
done
wait
done
for currentBinRemain in $(seq 1 $remainder); do
echo "Remainder Thread Started"
readFastIteration $threadCounter &
threadCounter=$((threadCounter + 1))
done
wait
merger $rootFileList $runDir $runName
#rm $runDir/*.list
rm -rf $runDir/*/
find $runDir -name "*.list" -type f -delete
fi
done \
<./RootRunlist.txt
#reads lines of "runslist"
)
}
readRoot() {
threads=$1
runNumber=$2 #a=ALL
inFolder=$3
outFolder=$4
headerSize=$5
if [ "$threads" -gt "1" ]; then
readFast $runNumber $inFolder $outFolder $headerSize
else
readFull $runNumber $inFolder $outFolder $headerSize
fi
}
readFastIteration() {
./src/read $fastRunDir/$1.list $fastInFolder/$fastRunName/ $fastRunDir/$1/out.root $fastRunName $fastHeaderSize "$isDC" "$dynamicBL" "$useCalibValues" "${fastLineArr[0]}" "${fastLineArr[1]}" "${fastLineArr[2]}" "${fastLineArr[3]}" "${fastLineArr[4]}" "${fastLineArr[5]}" "$automaticWindow" "$iWForceRun"
}
saveConfig() {
rm config.txt 2>/dev/null
destdir=config.txt
echo "$inFolder" >>"$destdir"
echo "$outFolder" >>"$destdir"
echo "$threads" >>"$destdir"
echo "${runNumber[@]}" >>"$destdir"
echo "$headerSize" >>"$destdir"
echo "$isDC" >>"$destdir"
echo "$dynamicBL" >>"$destdir"
echo "$useCalibValues" >>"$destdir"
echo "$useExistingRunList" >>"$destdir"
echo "$automaticConfig" >>"$destdir"
echo "$automaticWindow" >>"$destdir"
echo "config saved!"
}
saveAnalysisPath() {
rm analysisPath.txt 2>/dev/null
destdir=analysisPath.txt
echo "$analysisPath" >>"$destdir"
}
loadAnalysisPath() {
if test -f "analysisPath.txt"; then
if ! test -z "$(awk 'NR == 1' analysisPath.txt)"; then
analysisPath=$(awk 'NR == 1' analysisPath.txt)
fi
fi
}
checkAutomaticConfig() {
if test -f "config.txt"; then
tempConfig=$(awk 'NR == 10' config.txt)
fi
if [ "$tempConfig" = true ]; then
loadConfig
fi
}
loadConfig() {
#destdir=config.txt
#$inFolder=$( sed -n '1 p' config.txt )
if test -f "config.txt"; then
inFolder=$(awk 'NR == 1' config.txt)
outFolder=$(awk 'NR == 2' config.txt)
threads=$(awk 'NR == 3' config.txt)
runNumberTemp=$(awk 'NR == 4' config.txt)
runNumber=($runNumberTemp)
headerSize=$(awk 'NR == 5' config.txt)
isDC=$(awk 'NR == 6' config.txt)
dynamicBL=$(awk 'NR == 7' config.txt)
useCalibValues=$(awk 'NR == 8' config.txt)
useExistingRunList=$(awk 'NR == 9' config.txt)
automaticConfig=$(awk 'NR == 10' config.txt)
automaticWindow=$(awk 'NR == 11' config.txt)
echo "config loaded!"
else
echo "config file not found! Save a config first!"
fi
}
startAutomaticEffRun() {
echo "Start? (Run: ${runNumber[*]})"
select yn in "Yes" "No"; do
case $yn in
\
"No")
break 2
;;
"Yes")
echo "Started for runs: (${runNumber[*]}) "
echo "Select DC Run:"
read runNumberDC
iwScriptDir=$(find $analysisPath -name 'IntegrationWindowAnalysis.sh' -printf "%h\n")
rootfileFolderDir=$analysisPath/rootfiles
rootfileFolderDirFinished=$analysisPath/finishedRootfiles
mkdir -p $rootfileFolderDirFinished;
echo "Location of the Integration Scripts $iwScriptDir"
echo "Location of the Rootfile Folder $rootfileFolderDir"
echo "Make sure there are already the correct rootfiles in the analysis/rootfiles folder or press copy to move them from the runfolder to /rootfiles!"
echo "Yes -> starts automatic Baseline File creation"
select yn in "Create" "Copy" "Continue"; do
case $yn in
"Create")
echo "Start creating Rootfiles with a constant Baseline? (Run: ${runNumber[*]})"
startAutomaticBaseline
break
;;
"Continue")
break
;;
"Copy")
for n in ${runNumber[@]}; do
find . -type f -name "${n}_*" -a -name '*.root' -exec cp {} $rootfileFolderDir \;
done
break
;;
esac
done
echo "Calculating the Integration windows by the sum Histograms (Check the histograms)"
($iwScriptDir/IntegrationWindowAnalysis.sh)
echo "Done Integration Window Script! "
echo "Moving IntegrationWindows.txt to RunHelper/src"
cwd=$(pwd)
find $iwScriptDir -type f -name "IntegrationWindows.txt" -exec cp {} $cwd/src/ \;
automaticWindow=true #make sure this is on
echo "Run with new Integration Windows... "
start
echo "Moving files..."
for n in ${runNumber[@]}; do
find . -type f -name "${n}_*" -a -name '*.root' -exec cp {} $rootfileFolderDir \;
done
echo "Calculating the Correction Factor..."
($iwScriptDir/IntegrationWindowAnalysis.sh)
echo "Done Integration Window Script! "
echo "Moving CorrectionValues.txt to RunHelper/src"
cwd=$(pwd)
find $iwScriptDir -type f -name "CorrectionValues.txt" -exec cp {} $cwd/src/ \;
echo "Run with Correction Factor... "
start
echo "Moving IW files..."
for n in ${runNumber[@]}; do
find . -type f -name "${n}_*" -a -name '*.root' -exec cp {} "$rootfileFolderDirFinished" \;
find $rootfileFolderDir -type f -name "${n}_*" -a -name '*.root' -exec rm -rf {} \;
done
echo "Automatic Integration Done! Moved files to $rootfileFolderDirFinished"
dcScriptDir=$(find $analysisPath -name 'DCProbability.py' -printf "%h\n")
rootfileFolderDir=$analysisPath/rootfiles
savedRunNumber=("${runNumber[@]}")
unset runNumber
runNumber=("${runNumberDC[@]}")
for wRun in "${savedRunNumber[@]}"; do
#find runname
aRunName=$(grep -I "IW_${wRun}_" ./src/IntegrationWindows.txt | tail -1 | cut -f1 -d"=")
echo "Using $aRunName"
iWForceRun=$aRunName
automaticWindow=false
#start DC reading with IW from aRunName
start
echo "Moving DC files..."
suffix="iw$wRun"
path=$(find . -type f -name "${runNumber}_dc*" -a -name '*.root')
echo "origin path: $path, destination: $rootfileFolderDir/${runNumber}_dc_${suffix}.root"
if cp $path "$rootfileFolderDir/${runNumber}_dc_${suffix}.root"; then
echo "Moving successfull!"
else
echo "Moving not successfull! :("
exit 222
fi
done
runNumber=("${savedRunNumber[@]}")
echo "Done with the automatic efficiency run!"
break
;;
esac
done
}
startAutomaticDCRun() {
#Goal: Calculate 2 DC Limits, with 1 calib IW and measurement IW -> 2 DC Analysis, with different IW
dcScriptDir=$(find $analysisPath -name 'DCProbability.py' -printf "%h\n")
rootfileFolderDir=$analysisPath/rootfiles
echo "Using runs: ${runNumber[*]}"
savedRunNumber=("${runNumber[@]}")
unset runNumber
echo "Select DC Run:"
read runNumber
useCalibValues="1"
for wRun in "${savedRunNumber[@]}"; do
#find runname
aRunName=$(grep -I "IW_${wRun}_" ./src/IntegrationWindows.txt | tail -1 | cut -f1 -d"=")
echo "Using $aRunName"
iWForceRun=$aRunName
automaticWindow=false
#start DC reading with IW from aRunName
echo "DEBUG: $runNumber ${savedRunNumber[*]}"
start
echo "Moving files..."
shouldCompile=false
suffix="iw$wRun"
path=$(find . -type f -name "${runNumber}_dc*" -a -name '*.root')
echo "path: $path"
if cp $path "$rootfileFolderDir/${runNumber}_dc_${suffix}.root"; then
echo Moving successfull!
else
exit 222
fi
done
runNumber=("${savedUunNumber[@]}")
automaticWindow=true
#python $dcScriptDir/DCProbability.py
}
startAutomaticBaseline() {
while true; do
select yn in "Yes" "No"; do
case $yn in
\
"No")
break 2
;;
"Yes")
echo "Started for runs: (${runNumber[*]}) "
baselineScriptDir=$(find $analysisPath -name 'BaselineAverage.sh' -printf "%h\n")
rootfileFolderDir=$analysisPath/rootfiles
echo "Location of the Baseline Script $baselineScriptDir"
echo "Location of the Rootfile Folder $rootfileFolderDir"
echo "Starting Runs with dynamic Baseline..."
dynamicBL="1"
start
echo "Moving files..."
for n in ${runNumber[@]}; do
find . -type f -name "${n}_*" -a -name '*.root' -exec cp {} $rootfileFolderDir \;
done
echo "Starting Baseline Script"
($baselineScriptDir/BaselineAverage.sh)
echo "Done Baseline Script! "
echo "Moving Baselines.txt to RunHelper/src"
cwd=$(pwd)
find $baselineScriptDir -type f -name "Baselines.txt" -exec cp {} $cwd/src/ \;
echo "Starting Runs with constant Baseline..."
dynamicBL="0"
start
echo "Moving files..."
for n in ${runNumber[@]}; do
find . -type f -name "${n}_*" -a -name '*.root' -exec cp {} $rootfileFolderDir \;
done
echo "Automatic Baseline done!"
break 2
;;
esac
done
done
}
startAutomaticIntegration() {
echo "Start? (Run: ${runNumber[*]})"
select yn in "Yes" "No"; do
case $yn in
\
"No")
break 2
;;
"Yes")
echo "Started for runs: (${runNumber[*]}) "
iwScriptDir=$(find $analysisPath -name 'IntegrationWindowAnalysis.sh' -printf "%h\n")
rootfileFolderDir=$analysisPath/rootfiles
rootfileFolderDirFinished=$analysisPath/finishedRootfiles
mkdir -p $rootfileFolderDirFinished;
echo "Make sure there are already the correct rootfiles in the analysis/rootfiles folder or press copy to move them from the runfolder to /rootfiles!"
echo "Yes -> starts automatic Baseline File creation"
select yn in "Create" "Copy" "Continue"; do
case $yn in
"Create")
echo "Start creating Rootfiles with a constant Baseline? (Run: ${runNumber[*]})"
startAutomaticBaseline
break
;;
"Continue")
break
;;
"Copy")
for n in ${runNumber[@]}; do
find . -type f -name "${n}_*" -a -name '*.root' -exec cp {} $rootfileFolderDir \;
done
break
;;
esac
done
echo "Location of the Integration Scripts $iwScriptDir"
echo "Location of the Rootfile Folder $rootfileFolderDir"
echo "Calculating the Integration windows by the sum Histograms (Check the histograms)"
($iwScriptDir/IntegrationWindowAnalysis.sh)
echo "Done Integration Window Script! "
echo "Moving IntegrationWindows.txt to RunHelper/src"
cwd=$(pwd)
find $iwScriptDir -type f -name "IntegrationWindows.txt" -exec cp {} $cwd/src/ \;
automaticWindow=true #make sure this is on
echo "Run with new Integration Windows... "
start
echo "Moving files..."
for n in ${runNumber[@]}; do
find . -type f -name "${n}_*" -a -name '*.root' -exec cp {} $rootfileFolderDir \;
done
echo "Calculating the Correction Factor..."
($iwScriptDir/IntegrationWindowAnalysis.sh)
echo "Done Integration Window Script! "
echo "Moving CorrectionValues.txt to RunHelper/src"
cwd=$(pwd)
find $iwScriptDir -type f -name "CorrectionValues.txt" -exec cp {} $cwd/src/ \;
echo "Run with Correction Factor... "
start
echo "Moving files..."
for n in ${runNumber[@]}; do
find . -type f -name "${n}_*" -a -name '*.root' -exec cp {} "$rootfileFolderDirFinished" \;
find $rootfileFolderDir -type f -name "${n}_*" -a -name '*.root' -exec rm -rf {} \;
done
echo "Automatic Integration Done! Moved to: $rootfileFolderDirFinished"
break
;;
esac
done
}
start() {
echo " _____ _ _ "
echo " / ____| | | | "
echo " | (___ | |_ __ _ _ __| |_ "
echo " \___ \| __/ _\` | '__| __|"
echo " ____) | || (_| | | | |_ "
echo " |_____/ \__\__,_|_| \__|"
echo " "
echo " "
echo "--------------------------------PARAMETER--------------------------------"
echo "Input data folder: $inFolder"
echo "Output data folder: $outFolder"
echo "Compiles the scripts: $shouldCompile"
echo "Threads: $threads"
echo "RunNumber: ${runNumber[*]}"
echo "Use Existing RunList: $useExistingRunList"
echo "Header Size: $headerSize"
echo "Automatic Config: $automaticConfig"
echo "---------------------------------------------"
if [ "$automaticConfig" = true ]; then
saveConfig
fi
createInAndOutFolder $inFolder $outFolder
if [ "$useExistingRunList" = false ]; then
echo "Creating a runlist for all input folder Files... (Name: RootRunlist.txt)"
export -f parseRunList
runlist="RootRunlist.txt"
rm "$runlist"
ls $inFolder | sort -n | xargs -n 1 -P 1 bash -c "parseRunList $runlist $nameSchema"
#Check if readList exists
if [ -f $runList ]; then
echo "Runlist created successfully!"
else
echo "Runlist creation failed!"
fi
fi
readRoot $threads $runNumber $inFolder $outFolder $headerSize
echo "---------------------------------------------"
echo " ____ ___ _ _ _____ "
echo " | _ \ / _ \ | \ | || ____|"
echo " | | | || | | || \| || _| "
echo " | |_| || |_| || |\ || |___ "
echo " |____/ \___/ |_| \_||_____|"
echo " "
echo "---------------------------------------------"
}
# ██████╗ ██████╗ ██████╗ ███████╗
#██╔════╝██╔═══██╗██╔══██╗██╔════╝
#██║ ██║ ██║██║ ██║█████╗
#██║ ██║ ██║██║ ██║██╔══╝
#╚██████╗╚██████╔╝██████╔╝███████╗
# ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
showInformation
here=$(pwd)
src=$here/src/
inFolder=$here/data
outFolder=$here/runs
shouldCompile=true
automaticConfig=true
threads=6
runNumber=a
headerSize=a
useExistingRunList=false
automaticWindow=true
useCalibValues="0"
dynamicBL="1"
isDC="0"
nameSchema="2019"
checkAutomaticConfig
loadAnalysisPath
echo "-------------------------------------------------------"
echo "Select an option!"
while true; do
echo "-------------------------------------------------------"
echo "-------------------------------------------------------"
echo "-------------------------------------------------------"
# select yn in "Start" "RunMode ($threads)" "RunNumber (${runNumber[*]})" "Change Input Folder ($inFolder)" "Change Output Folder ($outFolder)" "Compile Readscripts ($shouldCompile)" "Binary Headersize ($headerSize)" "Calibration/Baseline" "Use existing RunList ($useExistingRunList)" "RunList Naming Schema ($nameSchema)" "Load Config" "Save Config" "Informations"; do
select yn in "Start" "RunNumber (${runNumber[*]})" "Settings" "Tools" "Load Config" "Save Config" "Informations"; do
case $yn in
\
\
"Settings")
while true; do
select yn in "Threads ($threads)" "Automatic Integration Window ($automaticWindow)" "Automatic Config Saving ($automaticConfig)" "Compile Readscripts ($shouldCompile)" "Binary Headersize ($headerSize)" "Calibration/Baseline" "Use existing RunList ($useExistingRunList)" "RunList Naming Schema ($nameSchema)" "Change Input Folder ($inFolder)" "Change Output Folder ($outFolder)" "<- Back"; do
case $yn in
\
"<- Back")
break 2
;;
"Threads ($threads)")
echo "How many threads should run parallel? (1 Thread -> Slow, but no ROOT File merging), 8 CORE CPU -> Max 8 Threads, 1 Thread takes about 1GB RAM"
read threads
break
;;
"Automatic Integration Window ($automaticWindow)")
echo "Uses the values stored in the IntegrationWindow.txt File, generated by the analysis tool 'IntegrationWindowAnalysis' , if false -> hardcoded values in read.C"
if [ "$automaticWindow" = false ]; then
automaticWindow=true
else
automaticWindow=false
fi
break
;;
"Automatic Config Saving ($automaticConfig)")
echo "Saves and restores the latest started run config! (Changing this automatically saves the config)"
if [ "$automaticConfig" = false ]; then
automaticConfig=true
else
automaticConfig=false
fi
saveConfig
break
;;
\
"Change Input Folder ($inFolder)")
chooseInFolder
break
;;
"Binary Headersize ($headerSize)")
echo "Enter the headersize of the binary files (Depends on the WC version)"
echo "Version: <2.8.14: 327, ==2.8.14: 328, >2.8.14: 403 -> a=automatic"
read headerSize
break
;;
"Change Output Folder ($outFolder)")
chooseOutFolder
break
;;
"Compile Readscripts ($shouldCompile)")
if [ "$shouldCompile" = false ]; then
shouldCompile=true
else
shouldCompile=false
fi
break
;;
"Is Dark Count Measurement ($isDC)")
if [ "$isDC" = "0" ]; then
isDC="1"
else
isDC="0"
fi
break
;;
"Use existing RunList ($useExistingRunList)")
if [ "$useExistingRunList" = false ]; then
useExistingRunList=true
else
useExistingRunList=false
fi
break
;;
"RunList Naming Schema ($nameSchema)")
echo "Enter Name Schema ($nameSchema)"
read nameSchema
break
;;
"Dynamic Baseline ($dynamicBL)")
if [ "$dynamicBL" = "0" ]; then
dynamicBL="1"
else
dynamicBL="0"
fi
break
;;
"Calibrate Measurement ($useCalibValues)")
if [ "$useCalibValues" = "0" ]; then
useCalibValues="1"
else
useCalibValues="0"
fi
break
;;
"Calibration/Baseline")
while true; do
select yn in "Is Dark Count Measurement ($isDC)" "Dynamic Baseline ($dynamicBL)" "Calibrate Measurement ($useCalibValues)" "<- Back"; do
case $yn in
\
"<- Back")
break 2
;;
"Is Dark Count Measurement ($isDC)")
if [ "$isDC" = "0" ]; then
isDC="1"
else
isDC="0"