Skip to content

Commit

Permalink
Merge branch 'development' into iss72-uRwell-newGeo
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaelladevita authored Aug 31, 2023
2 parents 5b15a97 + a106009 commit c0696ea
Show file tree
Hide file tree
Showing 16 changed files with 490 additions and 22 deletions.
8 changes: 8 additions & 0 deletions bin/hipo-json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

. `dirname $0`/env.sh

java -Xms1024m \
-cp "$CLAS12DIR/lib/clas/*:$CLAS12DIR/lib/plugins/*" \
org.jlab.utils.JsonUtils \
$*
2 changes: 1 addition & 1 deletion bin/run-groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ echo "*****************************************"
echo " "
echo " "
export JAVA_OPTS="-Dsun.java2d.pmoffscreen=false -Djava.util.logging.config.file=$CLAS12DIR/etc/logging/debug.properties -Xms1024m -Xmx2048m -XX:+UseSerialGC"
groovy -cp "$JYPATH" $*
groovy -cp "$JYPATH" "$@"
50 changes: 50 additions & 0 deletions bin/run-jshell
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

. `dirname $0`/env.sh

export CLAS12DIR=`dirname $0`/..

#--------------------------------------------------------------
# Adding supporting COAT jar files
for i in `ls -a $CLAS12DIR/lib/clas/*.jar`
do
#echo "$i"
if [ -z "${JYPATH}" ] ; then
JYPATH="$i"
else
JYPATH=${JYPATH}:"$i"
fi
done
#--------------------------------------------------------------
# Adding supporting plugins directory
for i in `ls -a $CLAS12DIR/lib/services/*.jar`
do
if [ -z "${JYPATH}" ] ; then
JYPATH="$i"
else
JYPATH=${JYPATH}:"$i"
fi
done
#--------------------------------------------------------------
# Adding supporting plugins directory
#--------------------------------------------------------------
# Done loading plugins
#--------------------------------------------------------------
# Adding supporting plugins directory
for i in `ls -a $CLAS12DIR/lib/utils/*.jar`
do
if [ -z "${JYPATH}" ] ; then
JYPATH="$i"
else
JYPATH=${JYPATH}:"$i"
fi
done
#-------------------------------------------------------------
echo " "
echo " "
echo "*****************************************"
echo "* Running COAT-JAVA JShell Scripts *"
echo "*****************************************"
echo " "
echo " "
jshell --class-path "$JYPATH" "$@"
4 changes: 2 additions & 2 deletions build-coatjava.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ cp -r etc coatjava/
which python3 >& /dev/null && python=python3 || python=python
$python etc/bankdefs/util/bankSplit.py coatjava/etc/bankdefs/hipo4 || exit 1
mkdir -p coatjava/lib/clas
cp external-dependencies/JEventViewer-1.1.jar coatjava/lib/clas/
cp external-dependencies/vecmath-1.3.1-2.jar coatjava/lib/clas/
#cp external-dependencies/JEventViewer-1.1.jar coatjava/lib/clas/
#cp external-dependencies/vecmath-1.3.1-2.jar coatjava/lib/clas/
mkdir -p coatjava/lib/utils
cp external-dependencies/jclara-4.3-SNAPSHOT.jar coatjava/lib/utils
#cp external-dependencies/jaw-1.0.jar coatjava/lib/utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ public void printDictionary() {
}

public void readDictionary(String fileName, TestMode mode, int wireBinning, int stripBinning, int sectorDependence) {
this.readDictionary(fileName, mode, wireBinning, stripBinning, sectorDependence, -1);
}

public void readDictionary(String fileName, TestMode mode, int wireBinning, int stripBinning, int sectorDependence, int maxRoads) {

System.out.println("\nReading dictionary from file " + fileName);
System.out.println("\nMaximum number of roads set to: " + maxRoads);
int nFull = 0;
int nDupli = 0;

if(maxRoads<0) maxRoads = Integer.MAX_VALUE;

File fileDict = new File(fileName);

try {
Expand All @@ -52,7 +59,7 @@ public void readDictionary(String fileName, TestMode mode, int wireBinning, int
ProgressPrintout progress = new ProgressPrintout();

String line = null;
while ((line = txtreader.readLine()) != null) {
while ((line = txtreader.readLine()) != null && maxRoads>nFull) {

Road road = new Road(line);
road.setBinning(wireBinning, stripBinning, sectorDependence);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ public EmbeddedCanvasTabbed getCanvas() {
return canvas;
}

public void init(String filename, TestMode mode, int wireBin, int stripBin, int sectorDependence) {
public void init(String filename, TestMode mode, int wireBin, int stripBin, int sectorDependence, int maxRoads) {
this.dictionary = new Dictionary();
this.dictionary.readDictionary(filename, mode, wireBin, stripBin, sectorDependence);
this.dictionary.readDictionary(filename, mode, wireBin, stripBin, sectorDependence, maxRoads);
this.createHistos(mode, wireBin, stripBin, sectorDependence);
this.plotRoads();
}
Expand Down Expand Up @@ -313,14 +313,15 @@ public static void main(String[] args) {
parser.addOption("-pid" , "0", "select particle PID for new dictionary, 0: no selection,");
parser.addOption("-charge" , "0", "select particle charge for new dictionary, 0: no selection");
parser.addOption("-wire" , "1", "dc wire bin size in road finding");
parser.addOption("-strip" , "2", "pcal strip bin size in road finding");
parser.addOption("-strip" , "1", "pcal strip bin size in road finding");
parser.addOption("-sector" , "0", "sector dependent roads, 0=false, 1=true)");
parser.addOption("-smear" , "1", "smearing in wire/paddle/strip matching");
parser.addOption("-mode" , "0", "select test mode, " + TestMode.getOptionsString());
parser.addOption("-threshold", "1", "select roads momentum threshold in GeV");
parser.addOption("-vzmin" , "-10", "minimum vz (cm)");
parser.addOption("-vzmax" , "10", "maximum vz (cm)");
parser.addOption("-n" ,"-1", "maximum number of events to process for validation");
parser.addOption("-r" ,"-1", "maximum number of roads to use for validation");
parser.parse(args);

String dictionaryFileName = null;
Expand Down Expand Up @@ -362,6 +363,7 @@ public static void main(String[] args) {
System.exit(1);
}
int maxEvents = parser.getOption("-n").intValue();
int maxRoads = parser.getOption("-r").intValue();

double thrs = parser.getOption("-threshold").doubleValue();
double vzmin = parser.getOption("-vzmin").doubleValue();
Expand All @@ -381,9 +383,10 @@ public static void main(String[] args) {
System.out.println("Smearing for wire/paddle/strip matching set to: " + smear);
System.out.println("Test mode set to: " + mode);
System.out.println("Maximum number of events to process set to: " + maxEvents);
System.out.println("Maximum number of roads to use set to: " + maxRoads);

DictionaryValidator validator = new DictionaryValidator();
validator.init(dictionaryFileName, mode, wireBin, stripBin, sector);
validator.init(dictionaryFileName, mode, wireBin, stripBin, sector, maxRoads);
// tm.printDictionary();
validator.processFile(testFileName,wireBin,stripBin,sector,smear,mode,maxEvents,pid,charge,thrs, vzmin, vzmax);
validator.plotHistos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static ArrayList<Road> getRoads(DataEvent event, int chargeSelect, int pi
}
}
road.setSector((byte) trackSector);
if(road.getLayerHits(3)<3 || road.getSuperLayers()!=6) continue;
// if(road.getSuperLayerHits(3)<3 || road.getSuperLayers()!=6) continue;
// now check other detectors
// check FTOF
if(recScintillator!=null) {
Expand Down Expand Up @@ -578,11 +578,11 @@ public byte getSector() {
return (byte) sec;
}

public int getLayerHits(int layer) {
public int getSuperLayerHits(int superlayer) {
int n=0;
if(layer>0 && layer<=6) {
for(int isl=0; isl<6; isl++) {
if(this.dcWires[layer-1+isl*6]>0) n++;
if(superlayer>0 && superlayer<=6) {
for(int il=0; il<6; il++) {
if(this.dcWires[(superlayer-1)*6+il]>0) n++;
}
}
return n;
Expand All @@ -606,7 +606,7 @@ public Particle getParticle() {

public double getPhi() {
double phi = Math.toDegrees(particle.phi());
if(sector==0)
if(this.getSector()==0)
return (phi+360+30)%60-30;
else
return phi;
Expand All @@ -618,18 +618,20 @@ public ArrayList<Byte> getKey() {

public ArrayList<Byte> getKey(TestMode mode) {
ArrayList<Byte> road = new ArrayList<>();
for(int i=0; i<13; i++) {
road.add((byte) 0);
}

for(int isl=0; isl<6; isl++) {
for(int il=0; il<6; il++) {
int layer = isl*6+il+1;
if(this.dcWires[layer-1] != 0) {
road.add(this.getWire(layer));
road.set(isl, this.getWire(layer));
break;
}
}
}
for(int i=6; i<13; i++) {
road.add((byte) 0);
}

if(mode.contains(TestMode.DCPCALU)) {
road.set(8, this.getStrip(1));
if(mode.contains(TestMode.DCFTOFPCALU)) {
Expand Down Expand Up @@ -684,12 +686,13 @@ public List<ArrayList<Byte>> getKeys(TestMode mode, int width) {
}}}}}}}}}}}
return keys;
}

public final boolean isValid() {
return this.isValid(TestMode.DC);
}

public boolean isValid(TestMode mode) {
boolean value = this.getLayerHits(3)>=3 && this.getSuperLayers()==6;
boolean value = this.getSuperLayerHits(3)>=3 && this.getSuperLayers()==6;
if(mode.contains(TestMode.DCPCALU)) {
value = value && this.ecalStrips[0]>0;
if(mode.contains(TestMode.DCFTOFPCALU)) {
Expand Down
63 changes: 63 additions & 0 deletions common-tools/clas-io/src/main/java/org/jlab/utils/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import java.io.OutputStreamWriter;
import org.jlab.io.base.DataBank;
import org.jlab.io.base.DataEvent;
import org.jlab.jnp.hipo4.data.Bank;
import org.jlab.jnp.hipo4.data.Event;
import org.jlab.jnp.hipo4.io.HipoReader;
import org.jlab.jnp.utils.json.JsonArray;
import org.jlab.jnp.utils.json.JsonObject;
import org.jlab.jnp.utils.json.JsonValue;
import org.jlab.jnp.utils.json.PrettyPrint;
import org.jlab.utils.options.OptionParser;
import org.json.JSONObject;

/**
Expand Down Expand Up @@ -49,6 +53,15 @@ public static void show(DataBank bank, String varName) {
show(read(bank,varName));
}

/**
* Just print it to the screen, nicely.
* @param bank
* @param varName
*/
public static void show(Bank bank, String varName) {
show(read(bank,varName));
}

/**
* Convenience method to get a JsonObject from a bank.
* @param bank bank to read
Expand All @@ -58,6 +71,14 @@ public static void show(DataBank bank, String varName) {
public static JsonObject read(DataBank bank, String varName) {
return JsonObject.readFrom(new String(bank.getByte(varName)));
}

public static JsonObject read(Bank bank, String varName) {
byte[] x = new byte[bank.getRows()];
for (int i=0; i<bank.getRows(); ++i) {
x[i] = bank.getByte(varName,i);
}
return JsonObject.readFrom(new String(x));
}

/**
* This won't be useful once DataBank.setByte(String,byte[]) is implemented
Expand Down Expand Up @@ -239,5 +260,47 @@ public static DataBank extend(DataEvent event, String bankName, String varName,
return extend(event, bankName, varName, Map2Json(extension));
}

public static void main(String args[]) {
OptionParser parser = new OptionParser("hipo-json");
parser.addRequired("-b","bank name");
parser.addOption("-v", "json", "variable name");
parser.addOption("-i", "1", "ignore parsing errors");
parser.setRequiresInputList(true);
parser.parse(args);
final String bankName = parser.getOption("-b").stringValue();
final String varName = parser.getOption("-v").stringValue();
int nerrors = 0;
for (String filename : parser.getInputList()) {
Event event = new Event();
HipoReader reader = new HipoReader();
reader.open(filename);
if (!reader.getSchemaFactory().hasSchema(bankName)) {
System.err.println("\nERROR: Bank does not exist in file's schema: "+bankName);
System.exit(1);
}
if (!reader.getSchemaFactory().getSchema(bankName).hasEntry(varName)) {
System.err.println("\nERROR: Variable does not exist in file's schema: "+bankName+"."+varName);
System.exit(1);
}
System.err.println(reader.getSchemaFactory().getSchema(bankName).getSchemaString());
Bank bank = reader.getSchemaFactory().getBank(bankName);
while (reader.hasNext()) {
reader.nextEvent(event);
if (event.hasBank(reader.getSchemaFactory().getSchema(bankName))) {
event.read(bank);
try {
JsonUtils.show(bank,varName);
}
catch (org.jlab.jnp.utils.json.ParseException e) {
if (++nerrors > 3 && parser.getOption("-i").intValue()!=0) {
System.err.println("\nERROR: Too many parsing errors.\nAre you sure your variable "+bankName+"."+varName+" is a byte array representing a JSON string?");
System.exit(1);
}
}
}
}
reader.close();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public void findTrajectory() {
stVec.setTrkThetaAtSurface(ThetaTrackIntersPlane);
stVec.setTrkToModuleAngle(trkToMPlnAngl);
stVec.setCalcCentroidStrip(CalcCentroidStrip);
stVec.setSurfaceDetector(DetectorType.BST.getDetectorId());
if(stateVecs.size()>0
&& stateVecs.get(stateVecs.size()-1).x()==stVec.x()
&& stateVecs.get(stateVecs.size()-1).y()==stVec.y()
Expand Down Expand Up @@ -230,7 +231,8 @@ public void findTrajectory() {
stVec.setTrkThetaAtSurface(ThetaTrackIntersSurf);
stVec.setTrkToModuleAngle(trkToMPlnAngl);
stVec.setCalcCentroidStrip(CalcCentroidStrip);
if(stateVecs.size()>0
stVec.setSurfaceDetector(DetectorType.BMT.getDetectorId());
if(stateVecs.size()>0
&& stateVecs.get(stateVecs.size()-1).x()==stVec.x()
&& stateVecs.get(stateVecs.size()-1).y()==stVec.y()
&& stateVecs.get(stateVecs.size()-1).z()==stVec.z()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList<Cross> candCrossList
continue;
}

stVec.setSurfaceDetector(DetectorType.BST.getDetectorId());
Cluster clsOnTrk = null;
if (l % 2 == 0) {
clsOnTrk = c.getCluster1();
Expand Down Expand Up @@ -195,6 +196,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList<Cross> candCrossList
continue;
}

stVec.setSurfaceDetector(DetectorType.BMT.getDetectorId());
if (c.getType()==BMTType.C) { //C-detector measuring Z
//if(traj.isFinal) { // reset the cross only for final trajectory

Expand Down Expand Up @@ -226,9 +228,9 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList<Cross> candCrossList
}

//Collections.sort(stateVecs);

stateVecs.sort(Comparator.comparing(StateVec::y));
for (int l = 0; l < stateVecs.size(); l++) {
for (int l = 0; l < stateVecs.size(); l++) {
stateVecs.get(l).setSurfaceDetector(DetectorType.CVT.getDetectorId());
stateVecs.get(l).setPlaneIdx(l);
}
traj.setTrajectory(stateVecs);
Expand Down
Loading

0 comments on commit c0696ea

Please sign in to comment.