Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/run-detectors-timelines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ echo "}"

# output detector subdirectories
detDirs=(
alert
band
bmtbst
central
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.jlab.clas.timeline.analysis
import java.util.concurrent.ConcurrentHashMap
import org.jlab.groot.data.TDirectory
import org.jlab.groot.data.GraphErrors
import org.jlab.clas.timeline.fitter.ALERTFitter

class alert_atof_tdc {

def data = new ConcurrentHashMap()

def processRun(dir, run) {

data[run] = [run:run]
def trigger = dir.getObject('/TRIGGER/bits')
def reference_trigger_bit = 0
data[run].put('bits', trigger)
(0..<720).collect{index->
int sector = index / (12 * 4);
int layer = (index % (12 * 4)) / 12;
int component = index % 12;
def file_index = '';
if (component <= 10) file_index = String.format('sector%d_layer%d_component%d_order0', sector, layer, component)
else file_index = String.format('sector%d_layer%d_component%d_order1', sector, layer, component-1)
def h1 = dir.getObject(String.format('/ALERT/TDC_%s', file_index))
data[run].put(String.format('atof_tdc_%s', file_index), h1)
def f1 = ALERTFitter.tdcfitter(h1)
data[run].put(String.format('fit_atof_tdc_%s', file_index), f1)
data[run].put(String.format('peak_location_atof_tdc_%s', file_index), f1.getParameter(1))
data[run].put(String.format('sigma_atof_tdc_%s', file_index), f1.getParameter(2))
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) )
}
}



def write() {

['peak_location', 'sigma', 'integral_normalized_to_trigger'].each{variable->
(0..<15).collect{sector->
(0..<4).collect{layer->
def names = []
TDirectory out = new TDirectory()
out.mkdir('/timelines')
(0..<12).collect{component->
def file_index = ''
if (component <= 10) file_index = String.format('sector%d_layer%d_component%d_order0', sector, layer, component)
else file_index = String.format('sector%d_layer%d_component%d_order1', sector, layer, component-1)
names << String.format('atof_tdc_%s', file_index)
}
names.each{ name ->
def gr = new GraphErrors(name)
gr.setTitle("ATOF TDC peak " + variable.replace('_', ' '))
gr.setTitleY("ATOF TDC peak " + variable.replace('_', ' '))
gr.setTitleX("run number")
data.sort{it.key}.each{run,it->
out.mkdir('/'+it.run)
out.cd('/'+it.run)
out.addDataSet(it[name])
out.addDataSet(it['fit_'+name])
gr.addPoint(it.run, it[variable + '_' + name], 0, 0)
}
out.cd('/timelines')
out.addDataSet(gr)
}
out.writeFile(String.format('alert_atof_tdc_%s_sector%d_layer%d.hipo', variable, sector, layer))
}
}
}
}
}
51 changes: 51 additions & 0 deletions src/main/java/org/jlab/clas/timeline/fitter/ALERTFitter.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
*
* Fitter package for CND
*
* Writer: Sangbaek Lee
*
**/
package org.jlab.clas.timeline.fitter
import org.jlab.groot.fitter.DataFitter
import org.jlab.groot.data.H1F
import org.jlab.groot.math.F1D


class ALERTFitter{

static F1D tdcfitter(H1F h1){
def f1 =new F1D("fit:"+h1.getName(),"[amp]*gaus(x,[mean],[sigma])+[cst]", -5.0, 5.0);
f1.setLineColor(33);
f1.setLineWidth(10);
f1.setOptStat("1111");
double maxz = h1.getBinContent(h1.getMaximumBin());
f1.setRange(h1.getMaximumBin() + 350.5 - 50, h1.getMaximumBin() + 350.5 + 50);
f1.setParameter(0,maxz);
f1.setParameter(1, h1.getMaximumBin() + 350.5);
f1.setParameter(2, 20);
f1.setParameter(3, 0.0);
if (maxz>0) f1.setParLimits(0, maxz*0.9,maxz*1.1);
f1.setParLimits(3, 0.0, 0.1*maxz);

double hMean, hRMS

DataFitter.fit(f1, h1, "");

def makefit = {func->
hMean = func.getParameter(1)
hRMS = func.getParameter(2).abs()
func.setRange(Math.max(hMean-2.5*hRMS, 350.0),Math.min(hMean+2.5*hRMS, 550.0))
func.setParLimits(0, func.getParameter(0)*0.9,func.getParameter(0)*1.1);
f1.setParLimits(3, 0.0, 0.1*func.getParameter(0));
DataFitter.fit(func,h1,"Q")
return [func.getChiSquare(), (0..<func.getNPars()).collect{func.getParameter(it)}]
}

def fits1 = (0..20).collect{makefit(f1)}
def bestfit = fits1.sort()[0]
f1.setParameters(*bestfit[1])
//makefit(f1)

return f1
}
}
170 changes: 170 additions & 0 deletions src/main/java/org/jlab/clas/timeline/histograms/ALERT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package org.jlab.clas.timeline.histograms;

import java.util.*;
// import org.jlab.clas.pdg.PhysicsConstants;

import org.jlab.groot.data.H1F;
// import org.jlab.groot.data.H2F;
import org.jlab.groot.math.F1D;
// import org.jlab.groot.fitter.DataFitter;
import org.jlab.io.base.DataBank;
import org.jlab.io.base.DataEvent;
import org.jlab.groot.data.TDirectory;
// import org.jlab.clas.physics.Particle;
import org.jlab.utils.groups.IndexedTable;
// import org.jlab.detector.calib.utils.CalibrationConstants;
import org.jlab.detector.calib.utils.ConstantsManager;
/**
*
* @author sangbaek
*/
public class ALERT {

boolean userTimeBased;
public int runNum, trigger;
public long trigger_word;
public String outputDir;

public boolean hasRF;
public double startTime, rfTime;

public double rfPeriod;
public int rf_large_integer;

//Hodoscope
public H1F[] TDC;
private H1F bits;

public IndexedTable rfTable;

public ConstantsManager ccdb;
private float tdc_bin_time = 0.015625f; // ns/bin

public ALERT(int reqrunNum, String reqOutputDir, float reqEb, boolean reqTimeBased) {
runNum = reqrunNum;
outputDir = reqOutputDir;
userTimeBased = reqTimeBased;

startTime = -1000;
rfTime = -1000;
trigger = 0;

rfPeriod = 4.008;
ccdb = new ConstantsManager();
ccdb.init(Arrays.asList(new String[]{"/daq/tt/fthodo", "/calibration/eb/rf/config"}));
rfTable = ccdb.getConstants(runNum, "/calibration/eb/rf/config");
if (rfTable.hasEntry(1, 1, 1)) {
System.out.println(String.format("RF period from ccdb for run %d: %f", runNum, rfTable.getDoubleValue("clock", 1, 1, 1)));
rfPeriod = rfTable.getDoubleValue("clock", 1, 1, 1);
}
rf_large_integer = 1000;

//Hodoscope Histograms
TDC = new H1F[720];

for (int index = 0; index < 720; index++) {
int sector = 0;
int layer = 0;
int component = 0;
int order = 0;

sector = index / (12 * 4);
layer = (index % (12 * 4)) / 12;
component = index % 12;
order = 0;
if (component == 11){
component = 10;
order = 1;
}

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);
TDC[index].setTitleX("TDC (ns)");
TDC[index].setTitleY("Counts");
TDC[index].setFillColor(4);
}
bits = new H1F("bits", "bits",65,0,65);
bits.getDataX(0);
bits.getEntries();
bits.getMaximumBin();
bits.getAxis().getNBins();

}

// public void fillAHDC(DataBank HodoHits) {
// }

public void fillATOF(DataBank atof_tdc) {
int rows = atof_tdc.rows();
for (int loop = 0; loop < rows; loop++) {
int sector = atof_tdc.getInt("sector", loop);
int layer = atof_tdc.getInt("layer", loop);
int component = atof_tdc.getInt("component", loop);
int order = atof_tdc.getInt("order", loop);
int tdc = atof_tdc.getInt("TDC", loop);
int index = sector * 48 + layer * 12 + component + order;

TDC[index].fill(tdc*tdc_bin_time);
}
}

public void processEvent(DataEvent event) {

DataBank recBankEB = null;
DataBank recEvenEB = null;
DataBank runConfig = null;
DataBank atof_tdc = null;

if (event.hasBank("REC::Particle")) {
recBankEB = event.getBank("REC::Particle");
}
if (event.hasBank("REC::Event")) {
recEvenEB = event.getBank("REC::Event");
}
if (event.hasBank("RUN::config")) {
runConfig = event.getBank("RUN::config");
}
if (event.hasBank("ATOF::tdc")) {
atof_tdc = event.getBank("ATOF::tdc");
}

if (runConfig!= null){
trigger_word = runConfig.getLong("trigger", 0);
bits.fill(64);
for (int i=0; i<64; ++i){
if ( 1 == ((trigger_word>>i)&1) ) {
bits.fill(i);
}
}
}

if (recEvenEB != null) {
startTime = recEvenEB.getFloat("startTime", 0);
rfTime = recEvenEB.getFloat("RFTime", 0);
}

//Get trigger particle
if (recBankEB != null) {
trigger = recBankEB.getInt("pid", 0);
}

if (atof_tdc != null) {
fillATOF(atof_tdc);
}

}

public void write() {
TDirectory dirout = new TDirectory();
dirout.mkdir("/ALERT/");
dirout.cd("/ALERT/");
for (int index = 0; index < 720; index++) {
dirout.addDataSet(TDC[index]);
}
dirout.mkdir("/TRIGGER/");
dirout.cd("/TRIGGER/");
dirout.addDataSet(bits);
if(runNum>0) dirout.writeFile(outputDir+"/out_ALERT_"+runNum+".hipo");
else dirout.writeFile(outputDir+"/out_ALERT.hipo");
}

}
2 changes: 2 additions & 0 deletions src/main/java/org/jlab/clas/timeline/run_analysis.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.jlab.clas.timeline.analysis
import org.jlab.groot.data.TDirectory

def engines = [
out_ALERT: [new alert_atof_tdc(),
],
out_BAND: [new band_adccor(),
new band_lasertime(),
new band_meantimeadc(),
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jlab/clas/timeline/run_histograms.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static void main(String[] args) {
CND ana_cnd = new CND(runNum,outputDir,useTB);
FT ana_ft = new FT(runNum,outputDir,useTB);
BAND ana_band = new BAND(runNum,outputDir,EB,useTB);
ALERT ana_alert = new ALERT(runNum,outputDir,EB,useTB);
helicity helicity = new helicity();
trigger trigger = new trigger();

Expand Down Expand Up @@ -88,6 +89,7 @@ public static void main(String[] args) {
ana_cnd.processEvent(event);
ana_ft.processEvent(event);
ana_band.processEvent(event);
ana_alert.processEvent(event);
ana_rich.processEvent(event);
helicity.processEvent(event);
trigger.processEvent(event);
Expand Down Expand Up @@ -117,6 +119,7 @@ public static void main(String[] args) {
ana_cnd.write();
ana_ft.write();
ana_band.write();
ana_alert.write();
ana_rich.write();
helicity.write(outputDir, runNum);
trigger.write(outputDir, runNum);
Expand Down