Skip to content

Commit 09015b8

Browse files
authored
Add the preliminary ALERT timeline to the main branch (#304)
This is an urgent PR for the RG-L to check the commissioning with the timeline. It passed the CI, so I'm merging it.
1 parent e3e0e68 commit 09015b8

6 files changed

Lines changed: 297 additions & 0 deletions

File tree

bin/run-detectors-timelines.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ echo "}"
142142

143143
# output detector subdirectories
144144
detDirs=(
145+
alert
145146
band
146147
bmtbst
147148
central
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.jlab.clas.timeline.analysis
2+
import java.util.concurrent.ConcurrentHashMap
3+
import org.jlab.groot.data.TDirectory
4+
import org.jlab.groot.data.GraphErrors
5+
import org.jlab.clas.timeline.fitter.ALERTFitter
6+
7+
class alert_atof_tdc {
8+
9+
def data = new ConcurrentHashMap()
10+
11+
def processRun(dir, run) {
12+
13+
data[run] = [run:run]
14+
def trigger = dir.getObject('/TRIGGER/bits')
15+
def reference_trigger_bit = 0
16+
data[run].put('bits', trigger)
17+
(0..<720).collect{index->
18+
int sector = index / (12 * 4);
19+
int layer = (index % (12 * 4)) / 12;
20+
int component = index % 12;
21+
def file_index = '';
22+
if (component <= 10) file_index = String.format('sector%d_layer%d_component%d_order0', sector, layer, component)
23+
else file_index = String.format('sector%d_layer%d_component%d_order1', sector, layer, component-1)
24+
def h1 = dir.getObject(String.format('/ALERT/TDC_%s', file_index))
25+
data[run].put(String.format('atof_tdc_%s', file_index), h1)
26+
def f1 = ALERTFitter.tdcfitter(h1)
27+
data[run].put(String.format('fit_atof_tdc_%s', file_index), f1)
28+
data[run].put(String.format('peak_location_atof_tdc_%s', file_index), f1.getParameter(1))
29+
data[run].put(String.format('sigma_atof_tdc_%s', file_index), f1.getParameter(2))
30+
data[run].put(String.format('integral_normalized_to_trigger_atof_tdc_%s', file_index), Math.sqrt(2*3.141597f) * f1.getParameter(0) * f1.getParameter(2)/trigger.getBinContent(reference_trigger_bit) )
31+
}
32+
}
33+
34+
35+
36+
def write() {
37+
38+
['peak_location', 'sigma', 'integral_normalized_to_trigger'].each{variable->
39+
(0..<15).collect{sector->
40+
(0..<4).collect{layer->
41+
def names = []
42+
TDirectory out = new TDirectory()
43+
out.mkdir('/timelines')
44+
(0..<12).collect{component->
45+
def file_index = ''
46+
if (component <= 10) file_index = String.format('sector%d_layer%d_component%d_order0', sector, layer, component)
47+
else file_index = String.format('sector%d_layer%d_component%d_order1', sector, layer, component-1)
48+
names << String.format('atof_tdc_%s', file_index)
49+
}
50+
names.each{ name ->
51+
def gr = new GraphErrors(name)
52+
gr.setTitle("ATOF TDC peak " + variable.replace('_', ' '))
53+
gr.setTitleY("ATOF TDC peak " + variable.replace('_', ' '))
54+
gr.setTitleX("run number")
55+
data.sort{it.key}.each{run,it->
56+
out.mkdir('/'+it.run)
57+
out.cd('/'+it.run)
58+
out.addDataSet(it[name])
59+
out.addDataSet(it['fit_'+name])
60+
gr.addPoint(it.run, it[variable + '_' + name], 0, 0)
61+
}
62+
out.cd('/timelines')
63+
out.addDataSet(gr)
64+
}
65+
out.writeFile(String.format('alert_atof_tdc_%s_sector%d_layer%d.hipo', variable, sector, layer))
66+
}
67+
}
68+
}
69+
}
70+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
*
3+
* Fitter package for CND
4+
*
5+
* Writer: Sangbaek Lee
6+
*
7+
**/
8+
package org.jlab.clas.timeline.fitter
9+
import org.jlab.groot.fitter.DataFitter
10+
import org.jlab.groot.data.H1F
11+
import org.jlab.groot.math.F1D
12+
13+
14+
class ALERTFitter{
15+
16+
static F1D tdcfitter(H1F h1){
17+
def f1 =new F1D("fit:"+h1.getName(),"[amp]*gaus(x,[mean],[sigma])+[cst]", -5.0, 5.0);
18+
f1.setLineColor(33);
19+
f1.setLineWidth(10);
20+
f1.setOptStat("1111");
21+
double maxz = h1.getBinContent(h1.getMaximumBin());
22+
f1.setRange(h1.getMaximumBin() + 350.5 - 50, h1.getMaximumBin() + 350.5 + 50);
23+
f1.setParameter(0,maxz);
24+
f1.setParameter(1, h1.getMaximumBin() + 350.5);
25+
f1.setParameter(2, 20);
26+
f1.setParameter(3, 0.0);
27+
if (maxz>0) f1.setParLimits(0, maxz*0.9,maxz*1.1);
28+
f1.setParLimits(3, 0.0, 0.1*maxz);
29+
30+
double hMean, hRMS
31+
32+
DataFitter.fit(f1, h1, "");
33+
34+
def makefit = {func->
35+
hMean = func.getParameter(1)
36+
hRMS = func.getParameter(2).abs()
37+
func.setRange(Math.max(hMean-2.5*hRMS, 350.0),Math.min(hMean+2.5*hRMS, 550.0))
38+
func.setParLimits(0, func.getParameter(0)*0.9,func.getParameter(0)*1.1);
39+
f1.setParLimits(3, 0.0, 0.1*func.getParameter(0));
40+
DataFitter.fit(func,h1,"Q")
41+
return [func.getChiSquare(), (0..<func.getNPars()).collect{func.getParameter(it)}]
42+
}
43+
44+
def fits1 = (0..20).collect{makefit(f1)}
45+
def bestfit = fits1.sort()[0]
46+
f1.setParameters(*bestfit[1])
47+
//makefit(f1)
48+
49+
return f1
50+
}
51+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package org.jlab.clas.timeline.histograms;
2+
3+
import java.util.*;
4+
// import org.jlab.clas.pdg.PhysicsConstants;
5+
6+
import org.jlab.groot.data.H1F;
7+
// import org.jlab.groot.data.H2F;
8+
import org.jlab.groot.math.F1D;
9+
// import org.jlab.groot.fitter.DataFitter;
10+
import org.jlab.io.base.DataBank;
11+
import org.jlab.io.base.DataEvent;
12+
import org.jlab.groot.data.TDirectory;
13+
// import org.jlab.clas.physics.Particle;
14+
import org.jlab.utils.groups.IndexedTable;
15+
// import org.jlab.detector.calib.utils.CalibrationConstants;
16+
import org.jlab.detector.calib.utils.ConstantsManager;
17+
/**
18+
*
19+
* @author sangbaek
20+
*/
21+
public class ALERT {
22+
23+
boolean userTimeBased;
24+
public int runNum, trigger;
25+
public long trigger_word;
26+
public String outputDir;
27+
28+
public boolean hasRF;
29+
public double startTime, rfTime;
30+
31+
public double rfPeriod;
32+
public int rf_large_integer;
33+
34+
//Hodoscope
35+
public H1F[] TDC;
36+
private H1F bits;
37+
38+
public IndexedTable rfTable;
39+
40+
public ConstantsManager ccdb;
41+
private float tdc_bin_time = 0.015625f; // ns/bin
42+
43+
public ALERT(int reqrunNum, String reqOutputDir, float reqEb, boolean reqTimeBased) {
44+
runNum = reqrunNum;
45+
outputDir = reqOutputDir;
46+
userTimeBased = reqTimeBased;
47+
48+
startTime = -1000;
49+
rfTime = -1000;
50+
trigger = 0;
51+
52+
rfPeriod = 4.008;
53+
ccdb = new ConstantsManager();
54+
ccdb.init(Arrays.asList(new String[]{"/daq/tt/fthodo", "/calibration/eb/rf/config"}));
55+
rfTable = ccdb.getConstants(runNum, "/calibration/eb/rf/config");
56+
if (rfTable.hasEntry(1, 1, 1)) {
57+
System.out.println(String.format("RF period from ccdb for run %d: %f", runNum, rfTable.getDoubleValue("clock", 1, 1, 1)));
58+
rfPeriod = rfTable.getDoubleValue("clock", 1, 1, 1);
59+
}
60+
rf_large_integer = 1000;
61+
62+
//Hodoscope Histograms
63+
TDC = new H1F[720];
64+
65+
for (int index = 0; index < 720; index++) {
66+
int sector = 0;
67+
int layer = 0;
68+
int component = 0;
69+
int order = 0;
70+
71+
sector = index / (12 * 4);
72+
layer = (index % (12 * 4)) / 12;
73+
component = index % 12;
74+
order = 0;
75+
if (component == 11){
76+
component = 10;
77+
order = 1;
78+
}
79+
80+
TDC[index] = new H1F(String.format("TDC_sector%d_layer%d_component%d_order%d", sector, layer, component, order), String.format("TDC sector%d layer%d component%d order%d", sector, layer, component, order), 200, 350.0, 550.0);
81+
TDC[index].setTitleX("TDC (ns)");
82+
TDC[index].setTitleY("Counts");
83+
TDC[index].setFillColor(4);
84+
}
85+
bits = new H1F("bits", "bits",65,0,65);
86+
bits.getDataX(0);
87+
bits.getEntries();
88+
bits.getMaximumBin();
89+
bits.getAxis().getNBins();
90+
91+
}
92+
93+
// public void fillAHDC(DataBank HodoHits) {
94+
// }
95+
96+
public void fillATOF(DataBank atof_tdc) {
97+
int rows = atof_tdc.rows();
98+
for (int loop = 0; loop < rows; loop++) {
99+
int sector = atof_tdc.getInt("sector", loop);
100+
int layer = atof_tdc.getInt("layer", loop);
101+
int component = atof_tdc.getInt("component", loop);
102+
int order = atof_tdc.getInt("order", loop);
103+
int tdc = atof_tdc.getInt("TDC", loop);
104+
int index = sector * 48 + layer * 12 + component + order;
105+
106+
TDC[index].fill(tdc*tdc_bin_time);
107+
}
108+
}
109+
110+
public void processEvent(DataEvent event) {
111+
112+
DataBank recBankEB = null;
113+
DataBank recEvenEB = null;
114+
DataBank runConfig = null;
115+
DataBank atof_tdc = null;
116+
117+
if (event.hasBank("REC::Particle")) {
118+
recBankEB = event.getBank("REC::Particle");
119+
}
120+
if (event.hasBank("REC::Event")) {
121+
recEvenEB = event.getBank("REC::Event");
122+
}
123+
if (event.hasBank("RUN::config")) {
124+
runConfig = event.getBank("RUN::config");
125+
}
126+
if (event.hasBank("ATOF::tdc")) {
127+
atof_tdc = event.getBank("ATOF::tdc");
128+
}
129+
130+
if (runConfig!= null){
131+
trigger_word = runConfig.getLong("trigger", 0);
132+
bits.fill(64);
133+
for (int i=0; i<64; ++i){
134+
if ( 1 == ((trigger_word>>i)&1) ) {
135+
bits.fill(i);
136+
}
137+
}
138+
}
139+
140+
if (recEvenEB != null) {
141+
startTime = recEvenEB.getFloat("startTime", 0);
142+
rfTime = recEvenEB.getFloat("RFTime", 0);
143+
}
144+
145+
//Get trigger particle
146+
if (recBankEB != null) {
147+
trigger = recBankEB.getInt("pid", 0);
148+
}
149+
150+
if (atof_tdc != null) {
151+
fillATOF(atof_tdc);
152+
}
153+
154+
}
155+
156+
public void write() {
157+
TDirectory dirout = new TDirectory();
158+
dirout.mkdir("/ALERT/");
159+
dirout.cd("/ALERT/");
160+
for (int index = 0; index < 720; index++) {
161+
dirout.addDataSet(TDC[index]);
162+
}
163+
dirout.mkdir("/TRIGGER/");
164+
dirout.cd("/TRIGGER/");
165+
dirout.addDataSet(bits);
166+
if(runNum>0) dirout.writeFile(outputDir+"/out_ALERT_"+runNum+".hipo");
167+
else dirout.writeFile(outputDir+"/out_ALERT.hipo");
168+
}
169+
170+
}

src/main/java/org/jlab/clas/timeline/run_analysis.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package org.jlab.clas.timeline.analysis
33
import org.jlab.groot.data.TDirectory
44

55
def engines = [
6+
out_ALERT: [new alert_atof_tdc(),
7+
],
68
out_BAND: [new band_adccor(),
79
new band_lasertime(),
810
new band_meantimeadc(),

src/main/java/org/jlab/clas/timeline/run_histograms.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public static void main(String[] args) {
4141
CND ana_cnd = new CND(runNum,outputDir,useTB);
4242
FT ana_ft = new FT(runNum,outputDir,useTB);
4343
BAND ana_band = new BAND(runNum,outputDir,EB,useTB);
44+
ALERT ana_alert = new ALERT(runNum,outputDir,EB,useTB);
4445
helicity helicity = new helicity();
4546
trigger trigger = new trigger();
4647

@@ -88,6 +89,7 @@ public static void main(String[] args) {
8889
ana_cnd.processEvent(event);
8990
ana_ft.processEvent(event);
9091
ana_band.processEvent(event);
92+
ana_alert.processEvent(event);
9193
ana_rich.processEvent(event);
9294
helicity.processEvent(event);
9395
trigger.processEvent(event);
@@ -117,6 +119,7 @@ public static void main(String[] args) {
117119
ana_cnd.write();
118120
ana_ft.write();
119121
ana_band.write();
122+
ana_alert.write();
120123
ana_rich.write();
121124
helicity.write(outputDir, runNum);
122125
trigger.write(outputDir, runNum);

0 commit comments

Comments
 (0)