-
Notifications
You must be signed in to change notification settings - Fork 2
/
chargeSum.groovy
63 lines (45 loc) · 1.61 KB
/
chargeSum.groovy
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
// calculate total analyzed charge for an example event loop
// with QA cuts enabled
// - you must specify a hipo file as an argument
// imports
import org.jlab.io.hipo.HipoDataSource // to read HIPO files
import clasqa.QADB // access QADB
// instantiate HIPO file reader for specified HIPO file
def inHipoFile
if(args.length>=1) inHipoFile = args[0]
else { System.err << "ERROR: specify hipo file\n"; return; }
def reader = new HipoDataSource()
reader.open(inHipoFile)
// instantiate QADB
QADB qa = new QADB("latest")
// alternatively, specify run range to restrict QADB (may be more efficient)
//QADB qa = new QADB("latest",5000,5500);
// define variables
def evCount = 0
def event
def runnum,evnum
// event loop
println "begin event loop..."
while(reader.hasEvent()) {
if(evCount%10000==0) println "$evCount events analyzed"
// truncate event loop (for quick testing)
if(evCount>1e5) { println "event loop truncated!"; break; }
event = reader.getNextEvent()
// get run and event numbers
runnum = event.getBank("RUN::config").getInt('run',0)
evnum = event.getBank("RUN::config").getInt('event',0)
// QA cuts
if(qa.OkForAsymmetry(runnum,evnum)) {
// accumulate charge; note that although the call to
// QADB::accumulateCharge() charge happens for each
// event within a QA bin that passed the QA cuts, that
// bin's charge will only be accumulated once, so
// overcounting is not possible
qa.accumulateCharge()
/* continue your analysis here */
}
evCount++
}
// print charge
println "\ntotal accumulated charge analyzed:\nrun=$runnum charge=" +
qa.getAccumulatedCharge() + " nC"