Skip to content

Commit

Permalink
Adding helicity values to the chargeTree.json (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwgibbs authored Feb 14, 2025
1 parent 6394276 commit 3294722
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions qa-physics/buildChargeTree.groovy
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jlab.groot.data.TDirectory
import org.jlab.groot.data.H1F
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import org.jlab.clas.timeline.util.Tools
Expand All @@ -10,8 +12,15 @@ if(args.length<1) {
System.exit(101)
}
inDir = args[0] + "/outdat"
monDir = args[0] + "/outmon"
//----------------------------------------------------------------------------------

def monFile
def inMdir = new TDirectory()
def runPrevious = -1 // initialize the previous run number
def binPrevious = -1 // initialize the previous bin number
def helicity = [] // list to hold the helicity values per run per bin
def helState = [-1,0,1] // labels for the json file
def tok
int r=0
def runnum, binnum, sector
Expand Down Expand Up @@ -48,6 +57,32 @@ dataFile.eachLine { line ->
ufcStop = tok[r++].toBigDecimal()
livetime = tok.size()>11 ? tok[r++].toBigDecimal() : -1

// open monitor_<runnum>.hipo
// data_table.dat has lines that repeat the run number and bin number.
// Use runPrevious and binPrevious to avoid repeating the extraction of the histogram bin contents
if(runnum!=runPrevious){
runPrevious = runnum
binPrevious = -1
monFile = new File("${monDir}/monitor_${runnum}.hipo")
println "Opening $monFile"
if(!(monFile.exists())) throw new Exception("monitor<run>.hipo not found")
try {
inMdir.readFile(monDir + "/" + monFile.getName())
} catch(Exception ex) {
System.err.println("ERROR: cannot read file $monFile; it may be corrupt")
return
}
}

if(binnum!=binPrevious){
binPrevious = binnum
def histName = "helic_scaler_chargeWeighted_" + runnum + "_" + binnum
H1F hist = (H1F)inMdir.getObject(runnum + "/",histName);
helicity.add(hist.getBinContent(0))
helicity.add(hist.getBinContent(1))
helicity.add(hist.getBinContent(2))
}

// fill tree
if(sector==1) {
println "add $runnum $binnum"
Expand All @@ -60,6 +95,8 @@ dataFile.eachLine { line ->
'livetime':livetime
]}
)
helState.eachWithIndex { it, i -> T.addLeaf(chargeTree,[runnum,binnum,'fcChargeHelicity',it],{helicity[i]})}
helicity.clear() // reset the helicity list
}
T.addLeaf(chargeTree,[runnum,binnum,'nElec',sector],{nElec})
}
Expand Down

0 comments on commit 3294722

Please sign in to comment.