From 4e9d06f56ed5f18a1b23e929437793f72acdd936 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Sat, 5 Sep 2020 13:01:04 -0400 Subject: [PATCH 01/21] mvn clean coat-lib in build scrip --- build-coatjava.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build-coatjava.sh b/build-coatjava.sh index bf11ae5644..e4620bc385 100755 --- a/build-coatjava.sh +++ b/build-coatjava.sh @@ -73,6 +73,7 @@ mkdir -p coatjava/lib/services ### clean up any cache copies ### rm -rf ~/.m2/repository/org/hep/hipo rm -rf ~/.m2/repository/org/jlab +cd common-tools/coat-lib; $mvn clean; cd - unset CLAS12DIR if [ $runUnitTests == "yes" ]; then From 3fa310bc5ab2b879f3986b099a8774cbbdb4872f Mon Sep 17 00:00:00 2001 From: Adam Hobart Date: Tue, 8 Sep 2020 16:00:39 +0200 Subject: [PATCH 02/21] restructured cnd clustering and added clusterid to cnd hits bank --- etc/bankdefs/hipo4/cnd.json | 1 + .../jlab/rec/cnd/banks/RecoBankWriter.java | 159 ++++-- .../org/jlab/rec/cnd/cluster/CNDCluster.java | 16 +- .../rec/cnd/cluster/CNDClusterFinder.java | 533 +++++++----------- .../java/org/jlab/rec/cnd/hit/CndHit.java | 13 + .../service/cnd/CNDCalibrationEngine.java | 47 +- 6 files changed, 338 insertions(+), 431 deletions(-) mode change 100644 => 100755 etc/bankdefs/hipo4/cnd.json mode change 100644 => 100755 reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDCluster.java mode change 100644 => 100755 reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDClusterFinder.java mode change 100644 => 100755 reconstruction/cnd/src/main/java/org/jlab/service/cnd/CNDCalibrationEngine.java diff --git a/etc/bankdefs/hipo4/cnd.json b/etc/bankdefs/hipo4/cnd.json old mode 100644 new mode 100755 index beb18320ef..f4867206bf --- a/etc/bankdefs/hipo4/cnd.json +++ b/etc/bankdefs/hipo4/cnd.json @@ -8,6 +8,7 @@ {"name":"id", "type":"S", "info":"id of the hit"}, {"name":"status", "type":"S", "info":"status of the hit"}, {"name":"trkID", "type":"S", "info":"match CVT track index"}, + {"name":"clusterid", "type":"S", "info":"pointer to the cluster"}, {"name":"sector", "type":"B", "info":"sector of CND"}, {"name":"layer", "type":"B", "info":"panel id of CND"}, {"name":"component", "type":"S", "info":"paddle id of CND"}, diff --git a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/banks/RecoBankWriter.java b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/banks/RecoBankWriter.java index 99750f084c..215721879c 100755 --- a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/banks/RecoBankWriter.java +++ b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/banks/RecoBankWriter.java @@ -4,60 +4,115 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.rec.cnd.hit.CndHit; - +import org.jlab.rec.cnd.cluster.CNDCluster; public class RecoBankWriter { - - - // write useful information in the bank - public static DataBank fillCndHitBanks(DataEvent event, ArrayList hitlist) { - - DataBank bank = event.createBank("CND::hits", hitlist.size()); - - if (bank == null) { - System.err.println("COULD NOT CREATE A CND::Hits BANK!!!!!!"); - return null; - } - - // the bank use cm as distance units -> need to convert from mm - for(int i =0; i< hitlist.size(); i++) { - bank.setShort("id",i, (short)(i+1)); - bank.setByte("sector",i, (byte) hitlist.get(i).Sector()); - bank.setByte("layer",i, (byte) hitlist.get(i).Layer()); - bank.setShort("component",i, (short) hitlist.get(i).Component()); - bank.setShort("trkID",i, (short) hitlist.get(i).get_AssociatedTrkId()); - bank.setFloat("time",i, (float) hitlist.get(i).Time()); - bank.setFloat("x",i, (float) (hitlist.get(i).X()/10.)); - bank.setFloat("y",i, (float) (hitlist.get(i).Y()/10.)); - bank.setFloat("z",i, (float) (hitlist.get(i).Z()/10.)); - bank.setFloat("x_unc",i, (float) (hitlist.get(i).get_uX()/10.)); - bank.setFloat("y_unc",i, (float) (hitlist.get(i).get_uY()/10.)); - bank.setFloat("z_unc",i, (float) (hitlist.get(i).get_uZ()/10.)); - bank.setFloat("tx",i, (float) (hitlist.get(i).get_tX()/10.)); - bank.setFloat("ty",i, (float) (hitlist.get(i).get_tY()/10.)); - bank.setFloat("tz",i, (float) (hitlist.get(i).get_tZ()/10.)); - bank.setFloat("energy",i, (float) hitlist.get(i).Edep()); - bank.setFloat("tlength",i, (float) (hitlist.get(i).tLength()/10.)); // units is cm - bank.setFloat("pathlength",i, (float) (hitlist.get(i).pathLength()/10.)); // units is cm - bank.setShort("indexLadc",i, (short) hitlist.get(i).indexLadc()); - bank.setShort("indexRadc",i, (short) hitlist.get(i).indexRadc()); - bank.setShort("indexLtdc",i, (short) hitlist.get(i).indexLtdc()); - bank.setShort("indexRtdc",i, (short) hitlist.get(i).indexRtdc()); - - } - return bank; - - } - - public void appendCNDBanks(DataEvent event,ArrayList hitlist) { - if(hitlist.size()!=0){ - DataBank bank = this.fillCndHitBanks((DataEvent) event, hitlist); - //bank.show(); - event.appendBanks(bank); - //event.show(); - } - } - + + + // write useful information in the bank + public static DataBank fillCndHitBanks(DataEvent event, ArrayList hitlist) { + + DataBank bank = event.createBank("CND::hits", hitlist.size()); + + if (bank == null) { + System.err.println("COULD NOT CREATE A CND::Hits BANK!!!!!!"); + return null; + } + + // the bank use cm as distance units -> need to convert from mm + for(int i =0; i< hitlist.size(); i++) { + bank.setShort("id",i, (short)(i+1)); + bank.setByte("sector",i, (byte) hitlist.get(i).Sector()); + bank.setByte("layer",i, (byte) hitlist.get(i).Layer()); + bank.setShort("component",i, (short) hitlist.get(i).Component()); + bank.setShort("trkID",i, (short) hitlist.get(i).get_AssociatedTrkId()); + bank.setShort("clusterid", i, (short) hitlist.get(i).get_AssociatedClusterID()); + bank.setFloat("time",i, (float) hitlist.get(i).Time()); + bank.setFloat("x",i, (float) (hitlist.get(i).X()/10.)); + bank.setFloat("y",i, (float) (hitlist.get(i).Y()/10.)); + bank.setFloat("z",i, (float) (hitlist.get(i).Z()/10.)); + bank.setFloat("x_unc",i, (float) (hitlist.get(i).get_uX()/10.)); + bank.setFloat("y_unc",i, (float) (hitlist.get(i).get_uY()/10.)); + bank.setFloat("z_unc",i, (float) (hitlist.get(i).get_uZ()/10.)); + bank.setFloat("tx",i, (float) (hitlist.get(i).get_tX()/10.)); + bank.setFloat("ty",i, (float) (hitlist.get(i).get_tY()/10.)); + bank.setFloat("tz",i, (float) (hitlist.get(i).get_tZ()/10.)); + bank.setFloat("energy",i, (float) hitlist.get(i).Edep()); + bank.setFloat("tlength",i, (float) (hitlist.get(i).tLength()/10.)); // units is cm + bank.setFloat("pathlength",i, (float) (hitlist.get(i).pathLength()/10.)); // units is cm + bank.setShort("indexLadc",i, (short) hitlist.get(i).indexLadc()); + bank.setShort("indexRadc",i, (short) hitlist.get(i).indexRadc()); + bank.setShort("indexLtdc",i, (short) hitlist.get(i).indexLtdc()); + bank.setShort("indexRtdc",i, (short) hitlist.get(i).indexRtdc()); + + } + return bank; + + } + + + + + + + public DataBank fillClustersBank(DataEvent event, ArrayList cluslist) { + + if (cluslist == null) { + return null; + } + if (cluslist.size() == 0) { + return null; + } + + + DataBank bank = event.createBank("CND::clusters", cluslist.size()); + if (bank == null) { + System.err.println("COULD NOT CREATE A CND::clusters BANK!!!!!!"); + return null; + } + for(int i =0; i< cluslist.size(); i++) { + bank.setShort("id",i, (short) cluslist.get(i).get_id() ); + bank.setShort("size",i, (short) cluslist.get(i).get_nhits() ); + bank.setByte("sector",i, (byte)(1* cluslist.get(i).get_sector()) ); + bank.setByte("layer",i, (byte)(1* cluslist.get(i).get_layer()) ); + bank.setShort("component",i, (short) cluslist.get(i).get_component() ); + bank.setFloat("energy",i, (float)(1.0* cluslist.get(i).get_energysum()) ); + bank.setFloat("x",i, (float)(1.0* cluslist.get(i).get_x()) ); + bank.setFloat("y",i, (float)(1.0* cluslist.get(i).get_y()) ); + bank.setFloat("z",i, (float)(1.0* cluslist.get(i).get_z()) ); + bank.setFloat("time",i, (float)(1.0* cluslist.get(i).get_time()) ); + bank.setShort("status",i, (short) cluslist.get(i).get_status()); + bank.setByte("layermult",i, (byte) cluslist.get(i).get_layermultip() ); + bank.setByte("layer1",i, (byte) cluslist.get(i).get_layer1() ); + bank.setByte("layer2",i, (byte) cluslist.get(i).get_layer2() ); + bank.setByte("layer3",i, (byte) cluslist.get(i).get_layer3() ); + bank.setFloat("pathLengthThruBar",i, (float) cluslist.get(i).get_pathLengthThruBar()); + } + + return bank; + } + + + + + + + + public void appendCNDBanks(DataEvent event,ArrayList hitlist, ArrayList cluslist) { + if(hitlist.size()!=0){ + DataBank bank = this.fillCndHitBanks((DataEvent) event, hitlist); + //bank.show(); + event.appendBanks(bank); + //event.show(); + } + + + if(cluslist.size()!=0){ + DataBank bank1 = this.fillClustersBank((DataEvent) event, cluslist); + event.appendBanks(bank1); + } + } + } diff --git a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDCluster.java b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDCluster.java old mode 100644 new mode 100755 index 9693ee28bc..4376406ad3 --- a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDCluster.java +++ b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDCluster.java @@ -19,14 +19,12 @@ public class CNDCluster extends ArrayList implements Comparable _cndhits; @@ -47,13 +45,7 @@ public void set_pathLengthThruBar(double pathLengthThruBar){ _pathLengthThruBar = pathLengthThruBar; } - public int get_veto(){ - return _veto; - } - public void set_veto(int veto){ - _veto = veto; - } - + //get_layermultip and set_layermultip methods public int get_layermultip(){ diff --git a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDClusterFinder.java b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDClusterFinder.java old mode 100644 new mode 100755 index bd51223f39..e8bede7213 --- a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDClusterFinder.java +++ b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDClusterFinder.java @@ -2,6 +2,12 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + + +import org.jlab.utils.groups.IndexedList; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.rec.cnd.hit.CndHit; @@ -22,325 +28,208 @@ public class CNDClusterFinder { private double cluster_size_ = 5;//apparently 5 cm according to Rong, no!!! + private boolean debug = false; + + public CNDClusterFinder() { // TODO Auto-generated constructor stub } + public void setDebug(boolean debug) { + this.debug = debug; + } + + public ArrayList findClusters(ArrayList hits) { - ArrayList clusters = new ArrayList(); - - /// variables for clustering of hits - int size = 0; - double hitenergy_temp = 0.0; - ArrayList clusters_nhits;//hit multiplicity?? - ArrayList clusters_energysum; - ArrayList clusters_hitenergy; - ArrayList clusters_x; - ArrayList clusters_y; - ArrayList clusters_z; - ArrayList clusters_time; - ArrayList clusters_xTimesEdep; - ArrayList clusters_yTimesEdep; - ArrayList clusters_zTimesEdep; - ArrayList clusters_timeTimesEdep; - ArrayList clusters_sector; - ArrayList clusters_layer; - ArrayList clusters_component; - ArrayList clusters_status; - ArrayList clusters_pathLengthThruBar = new ArrayList(); - double[] closest_distance = new double[1]; - int[] subA = new int[1]; - int[] subB = new int[1]; - //ArrayList clusters_veto; - ArrayList clusters_layermultip; - ArrayList clusters_layer1; - ArrayList clusters_layer2; - ArrayList clusters_layer3; + // sort hits by energy + Collections.sort(hits, new sortByEnergy()); + if(debug) { + for(int i=0; i(); - clusters_energysum = new ArrayList(); - clusters_hitenergy = new ArrayList(); - clusters_x = new ArrayList(); - clusters_y = new ArrayList(); - clusters_z = new ArrayList(); - clusters_time = new ArrayList(); - clusters_xTimesEdep = new ArrayList(); - clusters_yTimesEdep = new ArrayList(); - clusters_zTimesEdep = new ArrayList(); - clusters_timeTimesEdep = new ArrayList(); - clusters_sector = new ArrayList(); - clusters_layer = new ArrayList(); - clusters_component = new ArrayList(); - clusters_status = new ArrayList(); + + ArrayList clusters = new ArrayList(); - //veto - //clusters_veto = new ArrayList(); - //implement layer multiplicity - clusters_layermultip = new ArrayList(); - clusters_layer1 = new ArrayList(); - clusters_layer2 = new ArrayList(); - clusters_layer3 = new ArrayList(); + IndexedList> clustered_hits = new IndexedList>(1); - + + //loop over hits to group hits in clusters based on the mesure "distance", to be improved + int j=0; + double closest_distance = 1.0e15; + int good_index = -1; + int size = hits.size(); - size = hits.size(); for (int i = 0; i < size; i++) { - if( hits.get(i).Edep()<0.5 )continue; //energy threshold?? - clusters_nhits.add(1); - //energysum and energy hit are the same? - clusters_energysum.add(hits.get(i).Edep()); - clusters_hitenergy.add(hits.get(i).Edep()); - //// using the unit cm instead of mm, so divided by 10 - clusters_x.add(hits.get(i).X() /10.0); - clusters_y.add(hits.get(i).Y() /10.0); - clusters_z.add(hits.get(i).Z() /10.0); - clusters_time.add(hits.get(i).Time()); - clusters_xTimesEdep.add(hits.get(i).X() /10.0*hits.get(i).Edep()); - clusters_yTimesEdep.add(hits.get(i).Y() /10.0*hits.get(i).Edep()); - clusters_zTimesEdep.add(hits.get(i).Z() /10.0*hits.get(i).Edep()); - clusters_timeTimesEdep.add(hits.get(i).Time()*hits.get(i).Edep()); - clusters_sector.add(hits.get(i).Sector()); - clusters_layer.add(hits.get(i).Layer()); - clusters_component.add(hits.get(i).Component()); - clusters_status.add(0); - clusters_layermultip.add(1); - clusters_pathLengthThruBar.add(hits.get(i).tLength()/10.0); - //clusters_veto.add(-99); + if( hits.get(i).Edep()<0.5 )continue; //energy threshold - if(hits.get(i).Layer()==1){ - clusters_layer1.add(1); - clusters_layer2.add(0); - clusters_layer3.add(0); - } - else if(hits.get(i).Layer()==2){ - clusters_layer1.add(0); - clusters_layer2.add(1); - clusters_layer3.add(0); - } - else{ - clusters_layer1.add(0); - clusters_layer2.add(0); - clusters_layer3.add(1); - } + CndHit thisHit = (CndHit) hits.get(i); - } - - //// clustering of the CND hits - /// only one hit, no need to do clustering - if(clusters_nhits.size()==1){ - //// do nothing. - } - ///the case for two good cnd hits - else if(clusters_nhits.size()==2){ - /// combine the two hits or not... s=sqrt(DeltaX^2 + DeltaY^2 + DeltaZ^2 + DeltaT^2) ??? - double distance = sqrt( (clusters_x.get(0)-clusters_x.get(1))*(clusters_x.get(0)-clusters_x.get(1))/sigmaX(clusters_x.get(0))/sigmaX(clusters_x.get(1)) - +(clusters_y.get(0)-clusters_y.get(1))*(clusters_y.get(0)-clusters_y.get(1))/sigmaY(clusters_y.get(0))/sigmaY(clusters_y.get(1)) - +(clusters_z.get(0)-clusters_z.get(1))*(clusters_z.get(0)-clusters_z.get(1))/sigmaZ(clusters_z.get(0))/sigmaZ(clusters_z.get(1)) - +(clusters_time.get(0)-clusters_time.get(1))*(clusters_time.get(0)-clusters_time.get(1))/sigmaTime(clusters_time.get(0))/sigmaTime(clusters_time.get(1)) ); - //the 5 thing criteria... - if(distance < cluster_size_){ - - - - - if(clusters_layer1.get(0) ==1 || clusters_layer1.get(1)==1){ - clusters_layer1.set(0, 1); - } - if(clusters_layer2.get(0) ==1 || clusters_layer2.get(1)==1){ - clusters_layer2.set(0, 1); - } - if(clusters_layer3.get(0) ==1 || clusters_layer3.get(1)==1){ - clusters_layer3.set(0, 1); - } - - - clusters_layermultip.set(0, clusters_layer1.get(0)+clusters_layer2.get(0)+clusters_layer3.get(0)); - - + closest_distance = 1.0e15; + good_index = -1; + + for(int k =0; k cluster_size_) + { + + continue; + + } + else + { + if(distance(), j); + clustered_hits.getItem(j).add(thisHit); + j++; + + } + else + { - clusters_pathLengthThruBar.set(0,clusters_pathLengthThruBar.get(0)+clusters_pathLengthThruBar.get(1)); - clusters_pathLengthThruBar.remove(1); + clustered_hits.getItem(good_index).add(thisHit); - clusters_nhits.remove(1); - clusters_energysum.remove(1); - clusters_x.remove(1); - clusters_y.remove(1); - clusters_z.remove(1); - clusters_time.remove(1); - clusters_sector.remove(1); - clusters_layer.remove(1); - //## layer multiplicity for 2 hits is trivial - clusters_layermultip.remove(1); - clusters_layer1.remove(1); - clusters_layer2.remove(1); - clusters_layer3.remove(1); - clusters_component.remove(1); - clusters_status.remove(1); - //clusters_veto.remove(1); } + + + } - //// more than two cnd hits - //// hierarchiral clustering - else if(clusters_nhits.size()>2){ - int clusters_number = clusters_x.size(); - while(true){ - closest_distance[0] = 1.0e15; - subA[0] = -1; - subB[0] = -1; - find_closest(0, clusters_x, clusters_y, clusters_z, clusters_time, subA, subB, closest_distance); - if(subA[0]==-1 || subB[0]==-1)break; - else{ - - - int clusters_number_now = clusters_x.size(); - - - - - if(clusters_layer1.get(subA[0]) ==1 || clusters_layer1.get(subB[0])==1){ - clusters_layer1.set(subA[0], 1); - } - if(clusters_layer2.get(subA[0]) ==1 || clusters_layer2.get(subB[0])==1){ - clusters_layer2.set(subA[0], 1); - } - if(clusters_layer3.get(subA[0]) ==1 || clusters_layer3.get(subB[0])==1){ - clusters_layer3.set(subA[0], 1); - } - - - - clusters_layermultip.set(subA[0], clusters_layer1.get(subA[0])+clusters_layer2.get(subA[0])+clusters_layer3.get(subA[0])); - - - - - //// mark down the sector, layer, component of the dominant hit - if(clusters_hitenergy.get(subA[0]) < clusters_hitenergy.get(subB[0])){ - clusters_sector.set(subA[0], clusters_sector.get(subB[0]) ); - clusters_layer.set(subA[0], clusters_layer.get(subB[0]) ); - clusters_component.set(subA[0], clusters_component.get(subB[0]) ); - clusters_hitenergy.set(subA[0], clusters_hitenergy.get(subB[0]) ); - - - clusters_x.set(subA[0], clusters_x.get(subB[0])); - clusters_y.set(subA[0], clusters_y.get(subB[0])); - clusters_z.set(subA[0], clusters_z.get(subB[0])); - clusters_time.set(subA[0], clusters_time.get(subB[0])); + + + // sort lists by energy + if(debug) System.out.println("Sorted"); + for (int index = 0; index hitList = clustered_hits.getItem(index); + Collections.sort(hitList, new sortByEnergy()); + if(debug) { + for(int i=0; i type; array of cluster found in the event } @@ -361,65 +250,45 @@ else if(clusters_nhits.size()>2){ private double sigmaBeta(double beta){ return 0.065*beta; } /// find the two closest hits among all the hits - private void find_closest(int begin, ArrayList x, ArrayList y, ArrayList z, ArrayList time, - int[] subA, int[] subB, double[] closest_distance){ - if((begin+1)>=x.size())return; - - - - for(int i=begin+1;i cluster_size_){ - // - continue; - } - else{ - if(distance x, ArrayList y, ArrayList z, ArrayList time, + int[] subA, int[] subB, double[] closest_distance){ + if((begin+1)>=x.size())return; + + + + for(int i=begin+1;i cluster_size_){ + // + continue; + } + else{ + if(distance10 && nhits<3) || (energysum<=10 && nhits<4)){ - alpha++; - } - //CND related condition for CND and CTOF veto - if((energysum<30 && layermultip==1)){ - alpha++; - alpha++; - } - if(((energysum)<10 && nhits<3 && layermultip==2)){ - alpha++; - alpha++; - alpha++; - alpha++; + class sortByEnergy implements Comparator { + @Override + public int compare(CndHit a, CndHit b) { + if(a.Edep() cndclusters = cndclusterFinder.findClusters(hits); + + + + if(hits.size()!=0){ // DataBank outbank = RecoBankWriter.fillCndHitBanks(event, hits); // event.appendBanks(outbank); // event.show(); // System.out.println("in process event "); - rbc.appendCNDBanks(event,hits); + rbc.appendCNDBanks(event,hits,cndclusters); // ecnd++; // if(event.hasBank("CVTRec::Tracks")){ // posmatch++; @@ -160,40 +171,6 @@ public boolean processDataEvent(DataEvent event) { - //// clustering of the CND hits - CNDClusterFinder cndclusterFinder = new CNDClusterFinder(); - ArrayList cndclusters = cndclusterFinder.findClusters(hits); - - - /// Filling the banks of CND clusters - int size = cndclusters.size(); - if(size>0){ - DataBank bank2 = event.createBank("CND::clusters", size); - if (bank2 == null) { - System.err.println("COULD NOT CREATE A CND::clusters BANK!!!!!!"); - return false; - } - for(int i =0; i< size; i++) { - bank2.setShort("id",i, (short) cndclusters.get(i).get_id() ); - bank2.setShort("size",i, (short) cndclusters.get(i).get_nhits() ); - bank2.setByte("sector",i, (byte)(1* cndclusters.get(i).get_sector()) ); - bank2.setByte("layer",i, (byte)(1* cndclusters.get(i).get_layer()) ); - bank2.setShort("component",i, (short) cndclusters.get(i).get_component() ); - bank2.setFloat("energy",i, (float)(1.0* cndclusters.get(i).get_energysum()) ); - bank2.setFloat("x",i, (float)(1.0* cndclusters.get(i).get_x()) ); - bank2.setFloat("y",i, (float)(1.0* cndclusters.get(i).get_y()) ); - bank2.setFloat("z",i, (float)(1.0* cndclusters.get(i).get_z()) ); - bank2.setFloat("time",i, (float)(1.0* cndclusters.get(i).get_time()) ); - bank2.setShort("status",i, (short) cndclusters.get(i).get_status()); - //should add here the layer multiplicity - bank2.setByte("layermult",i, (byte) cndclusters.get(i).get_layermultip() ); - bank2.setByte("layer1",i, (byte) cndclusters.get(i).get_layer1() ); - bank2.setByte("layer2",i, (byte) cndclusters.get(i).get_layer2() ); - bank2.setByte("layer3",i, (byte) cndclusters.get(i).get_layer3() ); - bank2.setFloat("pathLengthThruBar",i, (float) cndclusters.get(i).get_pathLengthThruBar()); - } - event.appendBanks(bank2); - } return true; From 97e3336393a341935809ae6756d233a172eafec4 Mon Sep 17 00:00:00 2001 From: ajhobart <53663743+ajhobart@users.noreply.github.com> Date: Wed, 9 Sep 2020 10:11:05 +0200 Subject: [PATCH 03/21] Update CNDClusterFinder.java always measure distance with respect to seed hit in cluster --- .../main/java/org/jlab/rec/cnd/cluster/CNDClusterFinder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDClusterFinder.java b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDClusterFinder.java index e8bede7213..97ba9ebd8e 100755 --- a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDClusterFinder.java +++ b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/cluster/CNDClusterFinder.java @@ -80,9 +80,9 @@ public ArrayList findClusters(ArrayList hits) { for(int k =0; k Date: Wed, 9 Sep 2020 18:37:51 -0400 Subject: [PATCH 04/21] Expanded HEVT and added TGBI as well as filled in more bank information in bos2hipo (#578) * Added TGBI bank as well as updated existing banks. * Added HEADER::tgbi and added betta to EVENT::particle * fixed ststat * Switched from betta to beta * Changed HEADER::tgpb to TAGGER::tgpb Co-authored-by: Blake Huck Co-authored-by: Blake Huck --- .../org/jlab/io/utils/Bos2HipoEventBank.java | 45 ++++++++++++++- etc/bankdefs/hipo4/clas6event.json | 56 ++++++++++++++++--- 2 files changed, 92 insertions(+), 9 deletions(-) diff --git a/common-tools/clas-io/src/main/java/org/jlab/io/utils/Bos2HipoEventBank.java b/common-tools/clas-io/src/main/java/org/jlab/io/utils/Bos2HipoEventBank.java index 2477c45174..2df2c40fec 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/io/utils/Bos2HipoEventBank.java +++ b/common-tools/clas-io/src/main/java/org/jlab/io/utils/Bos2HipoEventBank.java @@ -49,12 +49,21 @@ public void initHipoBank(DataEvent hipoEvent){ if(this.bosDataBanks.containsKey("HEVT")==true){ DataBank bankHEVT = hipoEvent.createBank("HEADER::info", 1); + bankHEVT.setInt("estatus", 0, this.bosDataBanks.get("HEVT").getInt("ESTATUS")[0]); bankHEVT.setInt("nrun", 0, this.bosDataBanks.get("HEVT").getInt("NRUN")[0]); bankHEVT.setInt("nevt", 0, this.bosDataBanks.get("HEVT").getInt("NEVENT")[0]); + bankHEVT.setInt("type", 0, this.bosDataBanks.get("HEVT").getInt("TYPE")[0]); + bankHEVT.setInt("npgp", 0, this.bosDataBanks.get("HEVT").getInt("NPGP")[0]); + bankHEVT.setInt("trgprs", 0, this.bosDataBanks.get("HEVT").getInt("TRGPRS")[0]); + bankHEVT.setFloat("tg", 0, this.bosDataBanks.get("HEVT").getFloat("TG")[0]); bankHEVT.setFloat("stt" , 0, this.bosDataBanks.get("HEVT").getFloat("STT")[0]); bankHEVT.setFloat("fc" , 0, this.bosDataBanks.get("HEVT").getFloat("FC")[0]); bankHEVT.setFloat("fcg" , 0, this.bosDataBanks.get("HEVT").getFloat("FCG")[0]); - + bankHEVT.setFloat("rf1", 0, this.bosDataBanks.get("HEVT").getFloat("RF1")[0]); + bankHEVT.setFloat("rf2", 0, this.bosDataBanks.get("HEVT").getFloat("RF2")[0]); + bankHEVT.setFloat("con1", 0, this.bosDataBanks.get("HEVT").getFloat("CON1")[0]); + bankHEVT.setFloat("con2", 0, this.bosDataBanks.get("HEVT").getFloat("CON2")[0]); + bankHEVT.setFloat("con3", 0, this.bosDataBanks.get("HEVT").getFloat("CON3")[0]); int evtclass = this.bosDataBanks.get("HEVT").getInt("TRGPRS")[0]; byte ihelicity = 0; if(evtclass<0) ihelicity = 1; @@ -88,8 +97,10 @@ public void initHipoBank(DataEvent hipoEvent){ hipoEVNTp.setByte("lcstat", loop, (byte) bEVNT.getInt("LCstat")[loop]); hipoEVNTp.setByte("scstat", loop, (byte) bEVNT.getInt("SCstat")[loop]); hipoEVNTp.setByte("ccstat", loop, (byte) bEVNT.getInt("CCstat")[loop]); + hipoEVNTp.setByte("ststat", loop, (byte) bEVNT.getInt("STstat")[loop]); hipoEVNTp.setInt("pid",loop, bEVNT.getInt("ID")[loop]); + hipoEVNTp.setFloat("beta", loop, bEVNT.getFloat("Betta")[loop]); hipoEVNTp.setFloat("mass", loop,bEVNT.getFloat("Mass")[loop]); hipoEVNTp.setFloat("px", loop,bEVNT.getFloat("Pmom")[loop]*bEVNT.getFloat("Cx")[loop]); hipoEVNTp.setFloat("py", loop,bEVNT.getFloat("Pmom")[loop]*bEVNT.getFloat("cy")[loop]); @@ -112,7 +123,17 @@ public void initHipoBank(DataEvent hipoEvent){ } this.hipoDataBanks.put("TGPB", hipoTGPBp); } - + if(this.bosDataBanks.containsKey("TGBI")==true){ + BosDataBank tgbi = (BosDataBank) this.bosDataBanks.get("TGBI"); + DataBank hipoTGBIp = hipoEvent.createBank("HEADER::tgbi",tgbi.rows()); + hipoTGBIp.setInt("latch1", 0, tgbi.getInt("latch1")[0]); + hipoTGBIp.setInt("helicity_scaler", 0, tgbi.getInt("helicity_scaler")[0]); + hipoTGBIp.setInt("interrupt_time", 0, tgbi.getInt("interrupt_time")[0]); + hipoTGBIp.setInt("latch2", 0, tgbi.getInt("latch2")[0]); + hipoTGBIp.setInt("level3", 0, tgbi.getInt("level3")[0]); + + this.hipoDataBanks.put("TGBI", hipoTGBIp); + } if(this.bosDataBanks.containsKey("TAGR")==true){ BosDataBank tagr = (BosDataBank) this.bosDataBanks.get("TAGR"); DataBank hipoTAGRp = hipoEvent.createBank("TAGGER::tagr",tagr.rows()); @@ -151,6 +172,7 @@ public void initHipoBank(DataEvent hipoEvent){ hipoDCPB.setFloat("z_v", loop, bDCPB.getFloat("Z_v")[loop]); hipoDCPB.setFloat("r_v", loop, bDCPB.getFloat("R_v")[loop]); hipoDCPB.setFloat("chi2", loop, bDCPB.getFloat("Chi2")[loop]); + hipoDCPB.setInt("status", loop, bDCPB.getInt("Status")[loop]); } this.hipoDataBanks.put("DCPB", hipoDCPB); } @@ -176,6 +198,10 @@ public void initHipoBank(DataEvent hipoEvent){ hipoICPB.setFloat("tc", loop, bICPB.getFloat("Time")[loop]); hipoICPB.setFloat("xc", loop, bICPB.getFloat("X")[loop]); hipoICPB.setFloat("yc", loop, bICPB.getFloat("Y")[loop]); + hipoICPB.setFloat("m2_hit", loop, bICPB.getFloat("M2_hit")[loop]); + hipoICPB.setFloat("m3_hit", loop, bICPB.getFloat("M3_hit")[loop]); + hipoICPB.setInt("status", loop, bICPB.getInt("Status")[loop]); + hipoICPB.setFloat("zc", loop, bICPB.getFloat("Z")[loop]); } this.hipoDataBanks.put("ICPB", hipoICPB); } @@ -199,7 +225,13 @@ public void initHipoBank(DataEvent hipoEvent){ hipoECPB.setFloat("x", loop, bECPB.getFloat("X") [loop]); hipoECPB.setFloat("y", loop, bECPB.getFloat("Y") [loop]); hipoECPB.setFloat("z", loop, bECPB.getFloat("Z") [loop]); + hipoECPB.setFloat("m2_hit", loop, bECPB.getFloat("M2_hit")[loop]); + hipoECPB.setFloat("m3_hit", loop, bECPB.getFloat("M3_hit")[loop]); + hipoECPB.setFloat("m4_hit", loop, bECPB.getFloat("M4_hit")[loop]); hipoECPB.setFloat("chi2", loop, bECPB.getFloat("Chi2EC") [loop]); + hipoECPB.setInt("innstr", loop, bECPB.getInt("InnStr")[loop]); + hipoECPB.setInt("outstr", loop, bECPB.getInt("OutStr")[loop]); + hipoECPB.setInt("status", loop, bECPB.getInt("Status")[loop]); } this.hipoDataBanks.put("ECPB", hipoECPB); //banklist.add(hipoECPB); @@ -212,7 +244,9 @@ public void initHipoBank(DataEvent hipoEvent){ for(int loop = 0; loop < rows; loop++){ int scht = bLCPB.getInt("ScHt")[loop]; int sector = (int) scht/100; + int lchit_id = scht - sector; hipoLCPB.setByte("sector", loop, (byte) sector); + hipoLCPB.setByte("hit_id", loop, (byte) lchit_id); hipoLCPB.setFloat("etot", loop, bLCPB.getFloat("Etot")[loop]); hipoLCPB.setFloat("ein" , loop, bLCPB.getFloat("Ein")[loop]); hipoLCPB.setFloat("time", loop, bLCPB.getFloat("Time") [loop]); @@ -221,6 +255,7 @@ public void initHipoBank(DataEvent hipoEvent){ hipoLCPB.setFloat("y", loop, bLCPB.getFloat("Y") [loop]); hipoLCPB.setFloat("z", loop, bLCPB.getFloat("Z") [loop]); hipoLCPB.setFloat("chi2", loop, bLCPB.getFloat("Chi2LC") [loop]); + hipoLCPB.setInt("status", loop, bLCPB.getInt("Status") [loop]); } this.hipoDataBanks.put("LCPB", hipoLCPB); //banklist.add(hipoECPB); @@ -232,15 +267,18 @@ public void initHipoBank(DataEvent hipoEvent){ for(int loop = 0; loop < rows; loop++){ int sector = bSCPB.getInt("ScPdHt")[loop]/10000; int paddle = bSCPB.getInt("ScPdHt")[loop]/100 - sector*100; + int hit_id = bSCPB.getInt("ScPdHt")[loop] - sector - paddle; //System.err.println(" " + bSCPB.getInt("ScPdHt")[loop] + // " sector = " + sector + " " + paddle); //int paddle = bSCPB.getInt("ScPdHt")[loop]/10000; hipoSCPB.setByte("sector", loop, (byte) sector); hipoSCPB.setByte("paddle", loop, (byte) paddle); + hipoSCPB.setByte("hit_id", loop, (byte) hit_id); hipoSCPB.setFloat("edep", loop, bSCPB.getFloat("Edep") [loop]); hipoSCPB.setFloat("time", loop, bSCPB.getFloat("Time") [loop]); hipoSCPB.setFloat("path", loop, bSCPB.getFloat("Path") [loop]); hipoSCPB.setFloat("chi2", loop, bSCPB.getFloat("Chi2SC") [loop]); + hipoSCPB.setInt("status", loop, bSCPB.getInt("Status") [loop]); } this.hipoDataBanks.put("SCPB", hipoSCPB); } @@ -251,9 +289,12 @@ public void initHipoBank(DataEvent hipoEvent){ DataBank hipoCCPB = hipoEvent.createBank("DETECTOR::ccpb", rows); for(int loop = 0; loop < rows; loop++){ int sector = bCCPB.getInt("ScSgHt")[loop]/100; + int cluster = bCCPB.getInt("ScSgHt")[loop] - sector*100; //int paddle = bSCPB.getInt("ScPdHt")[loop]/10000; hipoCCPB.setByte("sector", loop, (byte) sector); + hipoCCPB.setInt("clusterid", loop, cluster); hipoCCPB.setFloat("nphe", loop, bCCPB.getFloat("Nphe") [loop]); + hipoCCPB.setInt("status", loop, bCCPB.getInt("Status") [loop]); hipoCCPB.setFloat("time", loop, bCCPB.getFloat("Time") [loop]); hipoCCPB.setFloat("path", loop, bCCPB.getFloat("Path") [loop]); hipoCCPB.setFloat("chi2", loop, bCCPB.getFloat("Chi2CC") [loop]); diff --git a/etc/bankdefs/hipo4/clas6event.json b/etc/bankdefs/hipo4/clas6event.json index 733a87d425..f37a2e0c95 100644 --- a/etc/bankdefs/hipo4/clas6event.json +++ b/etc/bankdefs/hipo4/clas6event.json @@ -5,17 +5,40 @@ "item" : 1, "info": "Event Header Information", "entries": [ + {"name": "estatus", "type": "I", "info": "event status after reconstruction"}, {"name": "nrun", "type": "I", "info": "run number"}, {"name": "nevt", "type": "I", "info": "event number"}, + {"name": "type", "type": "I", "info": "event type (data or mc)"}, + {"name": "npgp", "type": "I", "info": "number of final reconstructed particles*100 + number of geometrically reconstructed particles"}, + {"name": "trgprs", "type": "I", "info": "trigger type*10000 + prescale factor for that trigger (event class)"}, {"name": "trigger", "type": "I", "info": "trigger type"}, {"name": "helicity", "type": "B", "info": "faraday cup gated"}, {"name": "fc", "type": "F", "info": "faraday cup"}, {"name": "fcg", "type": "F", "info": "faraday cup gated"}, + {"name": "tg", "type": "F", "info": "clock gated"}, {"name": "stt", "type": "F", "info": "start time"}, + {"name": "rf1", "type": "F", "info": "rf time1"}, + {"name": "rf2", "type": "F", "info": "rf time2"}, + {"name": "con1", "type": "F", "info": "control rates1"}, + {"name": "con2", "type": "F", "info": "control rates2"}, + {"name": "con3", "type": "F", "info": "control rates3"}, {"name": "rastr1", "type": "S", "info": "rastr 1"}, {"name": "rastr2", "type": "S", "info": "rastr 2"} ] }, + { + "name": "HEADER::tgbi", + "group": 31000, + "item" : 43, + "info" : "TGBI Bank", + "entries": [ + {"name": "latch1", "type": "I", "info": "level1 trigger latch word (16 bits)"}, + {"name": "helicity_scaler", "type": "I", "info": "helicity interval count"}, + {"name": "interrupt_time", "type": "I", "info": "interrupt time from microsec clock"}, + {"name": "latch2", "type": "I", "info": "level2 trigger latch word (16 bits)"}, + {"name": "level3", "type": "I", "info": "level3 trigger word (32 bits)"} + ] + }, { "name": "EVENT::particle", "group": 31000, @@ -25,6 +48,7 @@ {"name": "status", "type": "B", "info": "status of the particle"}, {"name": "charge", "type": "B", "info": "charge of the particle"}, {"name": "pid", "type": "I", "info": "particle ID"}, + {"name": "beta", "type": "F", "info": "Particle velocity in the units of c (=R_trk/TOF/c)"}, {"name": "mass", "type": "F", "info": "particle mass calculated from beta"}, {"name": "px", "type": "F", "info": "x component of momentum"}, {"name": "py", "type": "F", "info": "y component of momentum"}, @@ -36,6 +60,7 @@ {"name": "ecstat", "type": "B", "info": "pointer to ec bank"}, {"name": "scstat", "type": "B", "info": "pointer to sc bank"}, {"name": "ccstat", "type": "B", "info": "pointer to cc bank"}, + {"name": "ststat", "type": "B", "info": "pointer to st bank"}, {"name": "lcstat", "type": "B", "info": "pointer to cc bank"} ] }, @@ -89,7 +114,13 @@ {"name": "x", "type": "F", "info": "x coordinate of the hit"}, {"name": "y", "type": "F", "info": "y coordinate of the hit"}, {"name": "z", "type": "F", "info": "z coordinate of the hit"}, - {"name": "chi2", "type": "F", "info": "quality measure of geometrical tracking"} + {"name": "m2_hit", "type": "F", "info": "second moment of hit pattern"}, + {"name": "m3_hit", "type": "F", "info": "third moment of hit pattern"}, + {"name": "m4_hit", "type": "F", "info": "fourth moment of hit pattern"}, + {"name": "innstr", "type": "I", "info": "10000*UI+100*VI+WI"}, + {"name": "outstr", "type": "I", "info": "10000*UO+100*VO+WO"}, + {"name": "chi2", "type": "F", "info": "quality measure of geometrical tracking"}, + {"name": "status", "type": "I", "info": "Status word"} ] }, { @@ -100,10 +131,12 @@ "entries": [ {"name": "sector", "type": "B", "info": "hit sector"}, {"name": "paddle", "type": "B", "info": "hit sector"}, + {"name": "hit_id", "type": "B", "info": "hit ID"}, {"name": "edep", "type": "F", "info": "deposited energy"}, {"name": "time", "type": "F", "info": "time of the hit"}, {"name": "path", "type": "F", "info": "path of the hit"}, - {"name": "chi2", "type": "F", "info": "quality measure of geometrical tracking"} + {"name": "chi2", "type": "F", "info": "quality measure of geometrical tracking"}, + {"name": "status", "type": "I", "info": "Status word"} ] }, { @@ -113,10 +146,12 @@ "info": "CC detector bank", "entries": [ {"name": "sector", "type": "B", "info": "hit sector"}, + {"name": "clusterid","type": "I", "info": "cluster id"}, {"name": "nphe", "type": "F", "info": "number of photo-electrons"}, {"name": "time", "type": "F", "info": "time of the hit"}, {"name": "path", "type": "F", "info": "path of the hit"}, - {"name": "chi2", "type": "F", "info": "Geometrical tracking: angle between cc hit and nearest sc hit"} + {"name": "chi2", "type": "F", "info": "Geometrical tracking: angle between cc hit and nearest sc hit"}, + {"name": "status", "type": "I", "info": "Status word - now 10*(CC segment number)"} ] }, { @@ -126,6 +161,7 @@ "info": "LC detector bank", "entries": [ {"name": "sector", "type": "B", "info": "hit sector"}, + {"name": "hit_id", "type": "B", "info": "hit ID"}, {"name": "etot", "type": "F", "info": "total energy of the hit"}, {"name": "ein", "type": "F", "info": "inner energy of the hit"}, {"name": "time", "type": "F", "info": "time of the hit"}, @@ -133,7 +169,8 @@ {"name": "x", "type": "F", "info": "x coordinate of the hit"}, {"name": "y", "type": "F", "info": "y coordinate of the hit"}, {"name": "z", "type": "F", "info": "z coordinate of the hit"}, - {"name": "chi2", "type": "F", "info": "quality measure of geometrical tracking"} + {"name": "chi2", "type": "F", "info": "quality measure of geometrical tracking"}, + {"name": "status", "type": "I", "info": "Status word"} ] }, { @@ -154,9 +191,10 @@ {"name": "y_v", "type": "F", "info": "vertex Y after fiting to the beam position"}, {"name": "z_v", "type": "F", "info": "vertex Z after fiting to the beam position"}, {"name": "r_v", "type": "F", "info": "distance from production vertex to the beam"}, - {"name": "chi2", "type": "F", "info": "Chisquare of track fitting"} + {"name": "chi2", "type": "F", "info": "Chisquare of track fitting"}, + {"name": "status", "type": "I", "info": "Status word"} ] - }, + }, { "name": "TAGGER::tagr", "group": 31000, @@ -193,7 +231,11 @@ {"name": "ecc", "type": "F", "info": "Energy of central hit crystal in cluster"}, {"name": "tc", "type": "F", "info": "Time relative to event start time"}, {"name": "xc", "type": "F", "info": "x coord of hit (diff from ich_x)"}, - {"name": "yc", "type": "F", "info": "y coord of hit (diff from ich_y)"} + {"name": "yc", "type": "F", "info": "y coord of hit (diff from ich_y)"}, + {"name": "zc", "type": "F", "info": "z coordinate of hit (front face of IC)"}, + {"name": "m2_hit", "type": "F", "info": "second moment of _hit pattern"}, + {"name": "m3_hit", "type": "F", "info": "third moment of _hit pattern"}, + {"name": "status", "type": "I", "info": "Ncrystals+10000*Hit_ID in ICHB"} ] } ] From 3eb2f676c67ac5aff18c1fa0e6918b1409753cec Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Sat, 19 Sep 2020 12:11:28 -0400 Subject: [PATCH 05/21] add convience scaler getters --- .../detector/decode/DaqScalersSequence.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java index 7de896b1ff..3122b77af3 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java @@ -24,6 +24,8 @@ public class DaqScalersSequence implements Comparator { public static final double TI_CLOCK_FREQ = 250e6; // Hz protected final List scalers=new ArrayList<>(); + + private Bank rcfgBank=null; public class Interval { private DaqScalers previous = null; @@ -115,6 +117,15 @@ public DaqScalers get(long timestamp) { return null; } + /** + * @param event + * @return the most recent DaqScalers for the given event + */ + public DaqScalers get(Event event) { + event.read(this.rcfgBank); + return this.get(this.rcfgBank.getLong("timestamp", 0)); + } + /** * @param timestamp TI timestamp (i.e. RUN::config.timestamp) * @return smallest interval of scaler readings around that timestamp @@ -122,14 +133,37 @@ public DaqScalers get(long timestamp) { public Interval getInterval(long timestamp) { return this.getInterval(timestamp,timestamp); } + + /** + * @param event + * @return smallest interval of scaler readings around that event + */ + public Interval getInterval(Event event) { + event.read(this.rcfgBank); + return this.getInterval(this.rcfgBank.getLong("timestamp", 0)); + } + /** * @param t1 first TI timestamp (i.e. RUN::config.timestamp) * @param t2 second TI timestamp - * @return an interval of scaler readings around those timestamps + * @return smallest interval of scaler readings around those timestamps */ public Interval getInterval(long t1,long t2) { return new Interval(this,t1,t2); } + + /** + * @param event1 first event + * @param event2 second event + * @return smallest interval of scaler readings around those events + */ + public Interval getInterval(Event event1, Event event2) { + event1.read(this.rcfgBank); + final long t1 = this.rcfgBank.getLong("timestamp",0); + event2.read(this.rcfgBank); + final long t2 = this.rcfgBank.getLong("timestamp",0); + return this.getInterval(t1,t2); + } /** * This reads tag=1 events for RUN::scaler banks, and initializes and returns @@ -148,6 +182,10 @@ public static DaqScalersSequence readSequence(List filenames) { HipoReader reader = new HipoReader(); reader.setTags(1); reader.open(filename); + + if (seq.rcfgBank==null) { + seq.rcfgBank = new Bank(reader.getSchemaFactory().getSchema("RUN::config")); + } SchemaFactory schema = reader.getSchemaFactory(); From 17f57dad9341bcfe1ebfa69e84062e4485044517 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Sat, 19 Sep 2020 12:11:33 -0400 Subject: [PATCH 06/21] fix offline-helicity sign convention --- .../org/jlab/detector/helicity/HelicityState.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicityState.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicityState.java index bb43be0711..2a94129c04 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicityState.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicityState.java @@ -114,6 +114,10 @@ public static HelicityState createFromFadcBank(Bank adcBank) { if (state.helicityRaw==HelicityBit.UDF) state.hwStatus |= Mask.HELICITY; if (state.pairSync==HelicityBit.UDF) state.hwStatus |= Mask.SYNC; if (state.patternSync==HelicityBit.UDF) state.hwStatus |= Mask.PATTERN; + + // Fix the overall sign-convention error in the offline helicity: + state.invert(); + state.fixMissingReadouts(); return state; } @@ -252,4 +256,14 @@ public void setHalfWavePlate(byte hwp) { public HelicityBit getPairSync() { return this.pairSync; } public HelicityBit getPatternSync() { return this.patternSync; } + /** + * Inverts the helicity/helicityRaw components of this state + * @return this state after inversion + */ + public HelicityState invert() { + this.helicity = HelicityBit.getFlipped(this.helicity); + this.helicityRaw = HelicityBit.getFlipped(this.helicityRaw); + return this; + } + } From 1f3ef71eaed43a28a152b618fb76d8afd5e3df42 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Sat, 19 Sep 2020 12:11:42 -0400 Subject: [PATCH 07/21] provide offline-helicity sign flip in postprocessing (for previously decoded data) --- .../analysis/postprocess/Tag1ToEvent.java | 25 ++++++++++++------- .../helicity/HelicitySequenceManager.java | 15 ++++++++++- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/Tag1ToEvent.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/Tag1ToEvent.java index 3dfa2246ac..4a1b955de3 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/Tag1ToEvent.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/Tag1ToEvent.java @@ -40,6 +40,7 @@ public static void main(String[] args) { OptionParser parser = new OptionParser("postprocess"); parser.addOption("-q","0","do beam charge and livetime (0/1=false/true)"); parser.addOption("-d","0","do delayed helicity (0/1=false/true)"); + parser.addOption("-f","0","do global offline helicity flip (0/1=false/true)"); parser.addRequired("-o","output.hipo"); parser.parse(args); @@ -57,13 +58,14 @@ public static void main(String[] args) { // helicity / beamcharge options: final boolean doHelicity = parser.getOption("-d").intValue() != 0; final boolean doBeamCharge = parser.getOption("-q").intValue() != 0; + final boolean doHelicityFlip = parser.getOption("-f").intValue() != 0; if (!doHelicity && !doBeamCharge) { parser.printUsage(); System.err.println("\n >>>>> error : at least one of -q/-d must be specified\n"); System.exit(1); } - HelicitySequenceManager helSeq = new HelicitySequenceManager(8,inputList); + HelicitySequenceManager helSeq = new HelicitySequenceManager(8,inputList,doHelicityFlip); DaqScalersSequence chargeSeq = DaqScalersSequence.readSequence(inputList); HipoWriterSorted writer = new HipoWriterSorted(); @@ -75,9 +77,9 @@ public static void main(String[] args) { // we're going to modify this bank: Bank recEventBank = new Bank(writer.getSchemaFactory().getSchema("REC::Event")); - - // FIXME: we shouldn't need this bank, but just the event: - Bank runConfigBank = new Bank(writer.getSchemaFactory().getSchema("RUN::config")); + + // we're going to modify this bank if doHelicityFlip is set: + Bank helFlipBank = new Bank(writer.getSchemaFactory().getSchema("HEL::flip")); long badCharge = 0; long goodCharge = 0; @@ -93,17 +95,22 @@ public static void main(String[] args) { reader.nextEvent(event); event.read(recEventBank); + event.read(helFlipBank); + event.remove(recEventBank.getSchema()); - // FIXME: we shouldn't need this bank, but just the event: - event.read(runConfigBank); - final long timestamp = runConfigBank.getLong("timestamp", 0); + if (doHelicityFlip && helFlipBank.getRows()>0) { + event.remove(helFlipBank.getSchema()); + helFlipBank.setByte("helicity", 0, (byte)-helFlipBank.getByte("helicity",0)); + helFlipBank.setByte("helicityRaw", 0, (byte)-helFlipBank.getByte("helicityRaw",0)); + event.write(helFlipBank); + } // do the lookups: HelicityBit hb = helSeq.search(event); - DaqScalers ds = chargeSeq.get(timestamp); + DaqScalers ds = chargeSeq.get(event); - // write heliicty to REC::Event: + // write helicity to REC::Event: if (Math.abs(hb.value())==1) goodHelicity++; else badHelicity++; if (doHelicity) { diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java index e44f92d627..787087c5fb 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java @@ -21,9 +21,16 @@ public final class HelicitySequenceManager { SchemaFactory schema=null; private final int delay; private int verbosity=1; + private boolean flip=false; private volatile Map seqMap=new HashMap<>(); Bank rcfgBank=null; + public HelicitySequenceManager(int delay,List filenames,boolean flip) { + this.flip=flip; + this.delay=delay; + initialize(filenames); + } + public HelicitySequenceManager(int delay,List filenames) { this.delay=delay; initialize(filenames); @@ -33,6 +40,12 @@ private HelicitySequenceManager(int delay,HipoReader reader) { this.delay=delay; initialize(reader); } + + private HelicitySequenceManager(int delay,HipoReader reader,boolean flip) { + this.flip=flip; + this.delay=delay; + initialize(reader); + } public void setVerbosity(int verbosity) { this.verbosity=verbosity; @@ -51,7 +64,7 @@ private boolean addState(int runno,HelicityState state) { System.exit(1); } } - return seqMap.get(runno).addState(state); + return seqMap.get(runno).addState(this.flip?state.invert():state); } public HelicitySequence getSequence(int runno) { From 9ee34635e476c645d4d4cae20ba0d28245f11c65 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Sun, 20 Sep 2020 17:51:26 -0400 Subject: [PATCH 08/21] add HEL::scaler bank --- etc/bankdefs/hipo4/header.json | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/etc/bankdefs/hipo4/header.json b/etc/bankdefs/hipo4/header.json index 176606d238..6aba14c5c4 100644 --- a/etc/bankdefs/hipo4/header.json +++ b/etc/bankdefs/hipo4/header.json @@ -41,11 +41,11 @@ "name": "RUN::scaler", "group": 10000, "item": 14, - "info": "Scaler information", + "info": "Run-integrated, analyzed scalers.", "entries": [ - {"name":"fcupgated", "type":"F", "info":"Beam charge, integrated from beginning of run, gated (nano-Coulomb)"}, + {"name":"fcupgated", "type":"F", "info":"Beam charge, integrated from beginning of run, DAQ-gated (nano-Coulomb)"}, {"name":"fcup", "type":"F", "info":"Beam charge, integrated from beginning of run, ungated (nano-Coulomb)"}, - {"name":"livetime", "type":"F", "info":"Livetime during one scaler period"} + {"name":"livetime", "type":"F", "info":"DAQ livetime during one scaler period"} ] }, { @@ -56,5 +56,22 @@ "entries":[ { "name":"json" , "type":"B", "info":"json character" } ] + }, + { + "name": "HEL::scaler", + "group": 10000, + "item": 16, + "info": "Helicity-gated, analyzed scalers.", + "entries": [ + {"name":"fcupgated", "type":"F", "info":"Beam charge from Faraday cup, DAQ-gated (nano-Coulomb)"}, + {"name":"fcup", "type":"F", "info":"Beam charge from Faraday cup, (nano-Coulomb)"}, + {"name":"slmgated", "type":"F", "info":"Beam charge from SLM, DAQ-gated (nano-Coulomb)"}, + {"name":"slm", "type":"F", "info":"Beam charge from SLM (nano-Coulomb)"}, + {"name":"clockgated", "type":"F", "info":"Clock, DAQ-gated"}, + {"name":"clock", "type":"F", "info":"Clock"}, + {"name":"helicity", "type":"B", "info":"Helicity state, HWP-corrected"}, + {"name":"helicityRaw","type":"B", "info":"Helicity state"}, + {"name":"livetime", "type":"F", "info":"DAQ livetime"} + ] } ] From bc8e0557bc28fa3eaafdba876d79cb7c115c7973 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Sun, 20 Sep 2020 19:10:27 -0400 Subject: [PATCH 09/21] add a state-offset option on helicity lookups --- .../helicity/HelicityAnalysisSimple.java | 13 +--- .../detector/helicity/HelicitySequence.java | 16 ++++- .../helicity/HelicitySequenceDelayed.java | 15 ++++- .../helicity/HelicitySequenceManager.java | 66 +++++++++++++++---- 4 files changed, 83 insertions(+), 27 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicityAnalysisSimple.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicityAnalysisSimple.java index def72512a6..651d41fd58 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicityAnalysisSimple.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicityAnalysisSimple.java @@ -62,20 +62,13 @@ public static void main(String[] args) { nevents++; Bank flipBank=new Bank(schema.getSchema("HEL::flip")); - Bank rcfgBank=new Bank(schema.getSchema("RUN::config")); Bank onliBank=new Bank(schema.getSchema("HEL::online")); Event event=new Event(); reader.nextEvent(event); event.read(flipBank); - event.read(rcfgBank); event.read(onliBank); - // Get RUN::config.runno/timestamp for this event: - if (rcfgBank.getRows()<=0) continue; - final long timestamp = rcfgBank.getLong("timestamp",0); - final int runno = rcfgBank.getInt("run",0); - // Get HEL::online.rawHelicity, the online, delay-corrected // helicity for this event (if available): //HelicityBit level3 = HelicityBit.UDF; @@ -87,18 +80,18 @@ public static void main(String[] args) { // based on the measured sequence. If the timestamp is outside // the measured range, or the measured sequence is corrupted between // the timestamp and the delayed timestamp, this will return null. - final HelicityBit measured = seq.search(runno,timestamp); + final HelicityBit measured = seq.search(event); // Same as previous, except assumes the pseudo-random generator's // prediction, which allows to access states later than the measured // range and cross intermediate sequence corruption. However, it // requires a 4x longer consecutive valid sequence for initialization // than the non-generator methods. - //final HelicityBit lookedup = seq.searchGenerated(runno,timestamp); + //final HelicityBit lookedup = seq.searchGenerated(event); // Same as previous, except relies on TI clock synced with helicity clock // instead of counting states: - //final HelicityBit predicted = seq.predictGenerated(runno,timestamp); + //final HelicityBit predicted = seq.predictGenerated(event); if (measured==HelicityBit.UDF) { nbad++; diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequence.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequence.java index 1376dd9783..561e6ba9a9 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequence.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequence.java @@ -213,9 +213,19 @@ protected HelicityBit get(int n) { * @return the helicity state, null if timestamp is outside of measured range */ public HelicityBit search(long timestamp) { - HelicityState state = this.searchState(timestamp); - if (state==null) return HelicityBit.UDF; - else return state.getHelicity(); + return this.search(timestamp,0); + } + + /** + * Find the state corresponding to a given timestamp in the measured sequence. + * @param timestamp TI timestamp (i.e. RUN::config.timestamp) + * @param offset number of states offset + * @return the helicity state, null if timestamp is outside of measured range + */ + public HelicityBit search(long timestamp,int offset) { + final int index = this.searchIndex(timestamp)+offset; + if (index < 0) return HelicityBit.UDF; + else return this.getState(index).getHelicity(); } /** diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceDelayed.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceDelayed.java index 8512d5942e..b2399b1b1a 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceDelayed.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceDelayed.java @@ -102,7 +102,20 @@ protected HelicityBit get(int n) { */ @Override public HelicityBit search(long timestamp) { - return this.get(super.searchIndex(timestamp)); + return this.search(timestamp,0); + } + + /** + * Get the delay-corrected state of a TI timestamp by searching the measured + * sequence and walking forward, returning HelicityBit.UDF if any errors + * along the way. + * + * @param timestamp TI-timestamp (i.e. RUN::config.timestamp) + * @param offset number of states offset + * @return the helicity bit + */ + public HelicityBit search(long timestamp,int offset) { + return this.get(super.searchIndex(timestamp)+offset); } /** diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java index e44f92d627..3b67f185e4 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java @@ -11,8 +11,8 @@ import org.jlab.jnp.hipo4.io.HipoReader; /** - * * Manage helicity sequences for multiple run numbers simultaneously. + * A wrapper around {@link HelicitySequenceDelayed} * * @author baltzell */ @@ -23,12 +23,20 @@ public final class HelicitySequenceManager { private int verbosity=1; private volatile Map seqMap=new HashMap<>(); Bank rcfgBank=null; - + + /** + * @param delay number of states delayed + * @param filenames list of filenames to initialize from + */ public HelicitySequenceManager(int delay,List filenames) { this.delay=delay; initialize(filenames); } + /** + * @param delay number of states delayed + * @param reader HipoReader to initialize from + */ private HelicitySequenceManager(int delay,HipoReader reader) { this.delay=delay; initialize(reader); @@ -54,34 +62,70 @@ private boolean addState(int runno,HelicityState state) { return seqMap.get(runno).addState(state); } + /** + * @param runno run number + * @return sequence for given run number + */ public HelicitySequence getSequence(int runno) { if (seqMap.containsKey(runno)) return seqMap.get(runno); return null; } + /** + * @param runno run number + * @param timestamp TI timestamp + * @return helicity for given run number and timestamp + */ public HelicityBit search(int runno, long timestamp) { - if (seqMap.containsKey(runno)) return seqMap.get(runno).search(timestamp); + return this.search(runno,timestamp,0); + } + + /** + * @param runno run number + * @param timestamp TI timestamp + * @param offset number of states offset + * @return helicity for given run number and timestamp plus offset + */ + public HelicityBit search(int runno, long timestamp,int offset) { + if (seqMap.containsKey(runno)) return seqMap.get(runno).search(timestamp,offset); return HelicityBit.UDF; } + + /** + * @param event HIPO event + * @return helicity for given event + */ + public HelicityBit search(Event event) { + return this.search(event,0); + } + + /** + * @param event HIPO event + * @param offset number of states offset + * @return helicity for given event plus offset + */ + public HelicityBit search(Event event,int offset) { + event.read(this.rcfgBank); + if (rcfgBank.getRows()<1) return HelicityBit.UDF; + return this.search(rcfgBank.getInt("run",0),rcfgBank.getLong("timestamp",0),offset); + } + public HelicityBit predictGenerated(int runno, long timestamp) { if (seqMap.containsKey(runno)) return seqMap.get(runno).predictGenerated(timestamp); return HelicityBit.UDF; } + public HelicityBit searchGenerated(int runno, long timestamp) { if (seqMap.containsKey(runno)) return seqMap.get(runno).searchGenerated(timestamp); return HelicityBit.UDF; } - - public HelicityBit search(Event event) { - event.read(this.rcfgBank); - if (rcfgBank.getRows()<1) return HelicityBit.UDF; - return this.search(rcfgBank.getInt("run",0),rcfgBank.getLong("timestamp",0)); - } + public HelicityBit predictGenerated(Event event) { event.read(this.rcfgBank); if (rcfgBank.getRows()<1) return HelicityBit.UDF; return this.predictGenerated(rcfgBank.getInt("run",0),rcfgBank.getLong("timestamp",0)); } + public HelicityBit searchGenerated(Event event) { event.read(this.rcfgBank); if (rcfgBank.getRows()<1) return HelicityBit.UDF; @@ -122,10 +166,6 @@ private void initialize(HipoReader reader) { } } - /** - * Initialize from a list of file names: - * @param filenames - */ private void initialize(List filenames) { for (String filename : filenames) { HipoReader reader = new HipoReader(); From 27877f90d611386a99910bb959684e5986095c5b Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Sun, 20 Sep 2020 19:21:25 -0400 Subject: [PATCH 10/21] rewire DaqScalers, with new CCDB table for SLM, to add support for HEL::scaler --- .../analysis/postprocess/RebuildScalers.java | 48 +++++++-- .../analysis/postprocess/Tag1ToEvent.java | 4 +- .../jlab/detector/decode/CLASDecoder4.java | 38 +++++--- .../org/jlab/detector/decode/DaqScalers.java | 97 ++++++++++++------- .../detector/decode/DaqScalersSequence.java | 10 +- .../detector/decode/DetectorEventDecoder.java | 4 +- 6 files changed, 135 insertions(+), 66 deletions(-) diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java index b4e4133439..84f846de00 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java @@ -7,6 +7,7 @@ import org.jlab.detector.calib.utils.ConstantsManager; import org.jlab.detector.calib.utils.RCDBConstants; import org.jlab.detector.decode.DaqScalers; +import org.jlab.detector.helicity.HelicitySequenceManager; import org.jlab.jnp.hipo4.data.Bank; import org.jlab.jnp.hipo4.data.Event; import org.jlab.jnp.hipo4.io.HipoReader; @@ -23,6 +24,7 @@ public class RebuildScalers { static final String CCDB_FCUP_TABLE="/runcontrol/fcup"; + static final String CCDB_SLM_TABLE="/runcontrol/slm"; public static void main(String[] args) { @@ -36,6 +38,8 @@ public static void main(String[] args) { System.exit(1); } + HelicitySequenceManager helSeq = new HelicitySequenceManager(8,inputList); + HipoWriterSorted writer = new HipoWriterSorted(); writer.getSchemaFactory().initFromDirectory(ClasUtilsFile.getResourceDir("COATJAVA", "etc/bankdefs/hipo4")); writer.setCompressionType(1); @@ -44,10 +48,11 @@ public static void main(String[] args) { Event event = new Event(); Bank rawScalerBank = new Bank(writer.getSchemaFactory().getSchema("RAW::scaler")); Bank runScalerBank = new Bank(writer.getSchemaFactory().getSchema("RUN::scaler")); + Bank helScalerBank = new Bank(writer.getSchemaFactory().getSchema("HEL::scaler")); Bank runConfigBank = new Bank(writer.getSchemaFactory().getSchema("RUN::config")); ConstantsManager conman = new ConstantsManager(); - conman.init(Arrays.asList(new String[]{CCDB_FCUP_TABLE})); + conman.init(Arrays.asList(new String[]{CCDB_FCUP_TABLE,CCDB_SLM_TABLE})); for (String filename : inputList) { @@ -55,7 +60,8 @@ public static void main(String[] args) { reader.open(filename); RCDBConstants rcdb = null; - IndexedTable ccdb = null; + IndexedTable ccdb_fcup = null; + IndexedTable ccdb_slm = null; while (reader.hasNext()) { @@ -63,6 +69,7 @@ public static void main(String[] args) { reader.nextEvent(event); event.read(runConfigBank); event.read(runScalerBank); + event.read(helScalerBank); event.read(rawScalerBank); // this is the bank we're here to rebuild: @@ -70,12 +77,13 @@ public static void main(String[] args) { // get CCDB/RCDB constants: if (runConfigBank.getInt("run",0) >= 100) { - ccdb = conman.getConstants(runConfigBank.getInt("run",0),CCDB_FCUP_TABLE); + ccdb_fcup = conman.getConstants(runConfigBank.getInt("run",0),CCDB_FCUP_TABLE); + ccdb_slm = conman.getConstants(runConfigBank.getInt("run",0),CCDB_SLM_TABLE); rcdb = conman.getRcdbConstants(runConfigBank.getInt("run",0)); } // now rebuild the RUN::scaler bank: - if (rcdb!=null && ccdb !=null && rawScalerBank.getRows()>0) { + if (rcdb!=null && ccdb_fcup !=null && rawScalerBank.getRows()>0) { // Run duration in seconds. Nasty but works, until RCDB (uses java.sql.Time) // is changed to support full date and not just HH:MM:SS. Meanwhile just @@ -86,12 +94,34 @@ public static void main(String[] args) { final double s2 = uet.getSeconds()+60*uet.getMinutes()+60*60*uet.getHours(); final double seconds = s20) scalerEvent.write(rawScaler); if(rawRunConf.getRows()>0) scalerEvent.write(rawRunConf); - Bank recScaler = decoder.createReconScalerBank(decodedEvent); - if (recScaler != null) { - decodedEvent.write(recScaler); - scalerEvent.write(recScaler); + Bank[] scalers = decoder.createReconScalerBanks(decodedEvent); + if (scalers != null) { + for (Bank b : scalers) { + decodedEvent.write(b); + scalerEvent.write(b); + } } if (epics!=null) { diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalers.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalers.java index 6656cf9c47..b12a3bfdaa 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalers.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalers.java @@ -38,31 +38,27 @@ */ public class DaqScalers { - private float beamCharge=0; - private float beamChargeGated=0; - private float livetime=0; - private long timestamp = 0; public Dsc2RawReading dsc2=null; public StruckRawReading struck=null; + + private long timestamp=0; public void setTimestamp(long timestamp) { this.timestamp=timestamp; } - private void setBeamCharge(float q) { this.beamCharge=q; } - private void setBeamChargeGated(float q) { this.beamChargeGated=q; } - private void setLivetime(float l) { this.livetime=l; } - public float getBeamCharge() { return beamCharge; } - public float getBeamChargeGated() { return beamChargeGated; } - public float getLivetime() { return livetime; } - public long getTimestamp() { return timestamp; } - public void show() { System.out.println("BCG=%.3f LT=%.3f"); } + public long getTimestamp(){ return this.timestamp; } + @Deprecated public double getBeamChargeGated() { return this.dsc2.getBeamChargeGated(); } + @Deprecated public double getBeamCharge() { return this.dsc2.getBeamCharge(); } + @Deprecated public double getLivetime() { return this.struck.getLivetime(); } + /** * @param runScalerBank HIPO RUN::scaler bank */ public static DaqScalers create(Bank runScalerBank) { DaqScalers ds=new DaqScalers(); + ds.dsc2=new Dsc2RawReading(); for (int ii=0; ii 0 && struck.getGatedClock()>0) { + double q = (double)(struck.getSlm() - slm_offset * struck.getClockSeconds() ); + double qg = (double)(struck.getGatedSlm() - slm_offset * struck.getGatedClockSeconds() ); + struck.setBeamChargeSLM(q * slm_atten / slm_slope); + struck.setBeamChargeGatedSLM(qg * slm_atten / slm_slope); + struck.setLivetime((double)struck.getGatedClock() / struck.getClock()); + } if (dsc2.getClock() > 0) { + double live = (double)dsc2.getGatedSlm() / dsc2.getSlm(); + double q = (double)(dsc2.getFcup() - fcup_offset * seconds ); + double qg = (double)(dsc2.getGatedFcup() - fcup_offset * seconds * live); + dsc2.setBeamCharge(q * fcup_atten / fcup_slope); + dsc2.setBeamChargeGated(qg * fcup_atten / fcup_slope); + dsc2.setLivetime(struck.getClock()>0?(double)struck.getGatedClock()/struck.getClock():-1); + } - float live = (float)dsc2.getGatedSlm() / dsc2.getSlm(); - float q = (float)(dsc2.getFcup() - fcup_offset * seconds ); - float qg = (float)(dsc2.getGatedFcup() - fcup_offset * seconds * live); - q *= fcup_atten / fcup_slope; - qg *= fcup_atten / fcup_slope; - float l = -1; - if (struck.getClock()>0) { - l = (float)struck.getGatedClock() / struck.getClock(); - } + if (dsc2.getClock()>0 || struck.getClock()>0) { DaqScalers ds=new DaqScalers(); - ds.setBeamCharge(q); - ds.setBeamChargeGated(qg); - ds.setLivetime(l); ds.dsc2=dsc2; ds.struck=struck; return ds; } + return null; } @@ -111,9 +115,9 @@ public static DaqScalers create(Bank rawScalerBank,IndexedTable fcupTable,double * @param rawScalerBank HIPO RAW::scaler bank * @param fcupTable /runcontrol/fcup IndexedTable from CCDB */ - public static DaqScalers create(Bank rawScalerBank,IndexedTable fcupTable) { + public static DaqScalers create(Bank rawScalerBank,IndexedTable fcupTable,IndexedTable slmTable) { Dsc2RawReading dsc2 = new Dsc2RawReading(rawScalerBank); - return create(rawScalerBank,fcupTable,dsc2.getGatedClockTime()); + return create(rawScalerBank,fcupTable,slmTable,dsc2.getGatedClockSeconds()); } private static class RawReading { @@ -135,8 +139,25 @@ private static class RawReading { public long getGatedClock() { return this.gatedClock; } public long getGatedFcup() { return this.gatedFcup; } public long getGatedSlm() { return this.gatedSlm; } - public double getClockTime() { return this.clock / this.clockFreq; } - public double getGatedClockTime() { return this.gatedClock / this.clockFreq; } + public double getClockSeconds() { return (double)this.clock / this.clockFreq; } + public double getGatedClockSeconds() { return (double)this.gatedClock / this.clockFreq; } + + // not really "raw" anymore: + private double beamCharge=0; + private double beamChargeGated=0; + private double beamChargeSLM=0; + private double beamChargeGatedSLM=0; + private double livetime=0; + protected void setBeamCharge(double q) { this.beamCharge=q; } + protected void setBeamChargeGated(double q) { this.beamChargeGated=q; } + protected void setBeamChargeSLM(double q) { this.beamChargeSLM=q; } + protected void setBeamChargeGatedSLM(double q) { this.beamChargeGatedSLM=q; } + protected void setLivetime(double l) { this.livetime=l; } + public double getBeamCharge() { return beamCharge; } + public double getBeamChargeGated() { return beamChargeGated; } + public double getLivetime() { return livetime; } + public double getBeamChargeSLM() { return beamChargeSLM; } + public double getBeamChargeGatedSLM() { return beamChargeGatedSLM; } } public static class StruckRawReading extends RawReading { @@ -164,6 +185,8 @@ public static class StruckRawReading extends RawReading { private static final int CHAN_SLM_SETTLE=33; private static final int CHAN_CLOCK_SETTLE=34; + public StruckRawReading() {} + public StruckRawReading(Bank bank) { // the STRUCK's clock is 1 MHz @@ -228,6 +251,8 @@ public static class Dsc2RawReading extends RawReading{ private static final int CHAN_SLM=49; private static final int CHAN_CLOCK=50; + public Dsc2RawReading() {} + public Dsc2RawReading(Bank bank) { // the DSC2's clock is (currently) 1 MHz diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java index 7de896b1ff..6547d30a6e 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java @@ -38,15 +38,15 @@ protected Interval(DaqScalersSequence seq, long t1, long t2) { } public double getBeamChargeGated() { if (previous!=null && next!=null) { - return this.next.getBeamChargeGated() - -this.previous.getBeamChargeGated(); + return this.next.dsc2.getBeamChargeGated() + -this.previous.dsc2.getBeamChargeGated(); } return 0; } public double getBeamCharge() { if (previous!=null && next!=null) { - return this.next.getBeamCharge() - -this.previous.getBeamCharge(); + return this.next.dsc2.getBeamCharge() + -this.previous.dsc2.getBeamCharge(); } return 0; } @@ -226,7 +226,7 @@ public static void main(String[] args) { else { good++; // do something useful with beam charge here: - System.out.println(timestamp+" "+ds.getBeamCharge()+" "+ds.getBeamChargeGated()); + System.out.println(timestamp+" "+ds.dsc2.getBeamCharge()+" "+ds.dsc2.getBeamChargeGated()); } } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java index ce936f5f94..3e13b79165 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java @@ -96,7 +96,7 @@ public final void initDecoderDev(){ translationManager.init(keysTrans,tablesTrans); fitterManager.init(keysFitter, tablesFitter); - scalerManager.init(Arrays.asList(new String[]{"/runcontrol/fcup","/runcontrol/hwp"})); + scalerManager.init(Arrays.asList(new String[]{"/runcontrol/fcup","/runcontrol/slm","/runcontrol/hwp"})); } public final void initDecoder(){ @@ -119,7 +119,7 @@ public final void initDecoder(){ }); fitterManager.init(keysFitter, tablesFitter); - scalerManager.init(Arrays.asList(new String[]{"/runcontrol/fcup","/runcontrol/hwp"})); + scalerManager.init(Arrays.asList(new String[]{"/runcontrol/fcup","/runcontrol/slm","/runcontrol/hwp"})); } /** * Set the flag to use extended fitter instead of basic fitter From 1af8b960755840a0eee0eba9db15064fa40b566c Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 21 Sep 2020 10:30:55 -0400 Subject: [PATCH 11/21] refactor DaqScalers --- .../jlab/analysis/eventmerger/FilterFcup.java | 2 +- .../analysis/eventmerger/FilterTrigger.java | 2 +- .../eventmerger/RandomTriggerFilter.java | 2 +- .../analysis/postprocess/RebuildScalers.java | 2 +- .../analysis/postprocess/Tag1ToEvent.java | 4 +- .../jlab/detector/decode/CLASDecoder4.java | 3 +- .../org/jlab/detector/decode/DaqScalers.java | 303 ------------------ .../org/jlab/detector/scalers/DaqScaler.java | 72 +++++ .../org/jlab/detector/scalers/DaqScalers.java | 100 ++++++ .../DaqScalersSequence.java | 3 +- .../org/jlab/detector/scalers/Dsc2Scaler.java | 69 ++++ .../jlab/detector/scalers/StruckScaler.java | 84 +++++ 12 files changed, 335 insertions(+), 311 deletions(-) delete mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalers.java create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalers.java rename common-tools/clas-detector/src/main/java/org/jlab/detector/{decode => scalers}/DaqScalersSequence.java (99%) create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScaler.java diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/FilterFcup.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/FilterFcup.java index 7bca1c4486..b651a793fd 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/FilterFcup.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/FilterFcup.java @@ -1,7 +1,7 @@ package org.jlab.analysis.eventmerger; import java.util.LinkedHashMap; import java.util.Map; -import org.jlab.detector.decode.DaqScalersSequence; +import org.jlab.detector.scalers.DaqScalersSequence; import org.jlab.jnp.hipo4.data.*; import org.jlab.jnp.hipo4.io.HipoReader; import org.jlab.jnp.utils.data.TextHistogram; diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/FilterTrigger.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/FilterTrigger.java index c9119f80ae..7b1f18a33f 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/FilterTrigger.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/FilterTrigger.java @@ -1,5 +1,5 @@ package org.jlab.analysis.eventmerger; -import org.jlab.detector.decode.DaqScalersSequence; +import org.jlab.detector.scalers.DaqScalersSequence; import org.jlab.jnp.hipo4.data.*; import org.jlab.jnp.hipo4.io.HipoReader; import org.jlab.jnp.utils.data.*; diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/RandomTriggerFilter.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/RandomTriggerFilter.java index 0e6f82751c..688112bf1d 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/RandomTriggerFilter.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/RandomTriggerFilter.java @@ -1,6 +1,6 @@ package org.jlab.analysis.eventmerger; import java.util.List; -import org.jlab.detector.decode.DaqScalersSequence; +import org.jlab.detector.scalers.DaqScalersSequence; import org.jlab.jnp.hipo4.data.*; import org.jlab.jnp.hipo4.io.HipoReader; import org.jlab.jnp.hipo4.io.HipoWriterSorted; diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java index 84f846de00..92404fdef1 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java @@ -6,7 +6,7 @@ import java.util.List; import org.jlab.detector.calib.utils.ConstantsManager; import org.jlab.detector.calib.utils.RCDBConstants; -import org.jlab.detector.decode.DaqScalers; +import org.jlab.detector.scalers.DaqScalers; import org.jlab.detector.helicity.HelicitySequenceManager; import org.jlab.jnp.hipo4.data.Bank; import org.jlab.jnp.hipo4.data.Event; diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/Tag1ToEvent.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/Tag1ToEvent.java index bb7e425f75..3fca6f71b0 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/Tag1ToEvent.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/Tag1ToEvent.java @@ -11,8 +11,8 @@ import org.jlab.utils.system.ClasUtilsFile; -import org.jlab.detector.decode.DaqScalers; -import org.jlab.detector.decode.DaqScalersSequence; +import org.jlab.detector.scalers.DaqScalers; +import org.jlab.detector.scalers.DaqScalersSequence; import org.jlab.detector.helicity.HelicityBit; import org.jlab.detector.helicity.HelicitySequenceManager; diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java index 351ff58d37..f735106e61 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java @@ -5,6 +5,7 @@ */ package org.jlab.detector.decode; +import org.jlab.detector.scalers.DaqScalers; import java.util.ArrayList; import java.util.List; @@ -617,7 +618,7 @@ public Bank[] createReconScalerBanks(Event event){ Bank scalerBank = new Bank(schemaFactory.getSchema("RUN::scaler"),1); scalerBank.putFloat("fcup",0,(float)r.dsc2.getBeamCharge()); scalerBank.putFloat("fcupgated",0,(float)r.dsc2.getBeamChargeGated()); - scalerBank.putFloat("livetime",0,(float)r.dsc2.getLivetime()); + scalerBank.putFloat("livetime",0,(float)r.struck.getLivetime()); Bank helicityBank = new Bank(schemaFactory.getSchema("HEL::scaler"),1); helicityBank.putFloat("fcup",0,(float)r.struck.getBeamCharge()); diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalers.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalers.java deleted file mode 100644 index b12a3bfdaa..0000000000 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalers.java +++ /dev/null @@ -1,303 +0,0 @@ -package org.jlab.detector.decode; - -import org.jlab.jnp.hipo4.data.Bank; -import org.jlab.utils.groups.IndexedTable; - -/** - * - * Read the occasional scaler bank, extract beam charge, livetime, etc. - * - * We have at least two relevant scaler hardware boards, STRUCK and DSC2, both - * readout on helicity flips and with DAQ-busy gating, both decoded into RAW::scaler. - * This class reads RAW::scaler and converts to more user-friendly information. - * - * STRUCK. Latching on helicity states, zeroed upon readout, with both helicity - * settle (normally 500 us) and non-settle counts, useful for "instantaneous" - * livetime, beam charge asymmetry, beam trip studies, ... - * - * DSC2. Integrating since beginning of run, useful for beam charge normalization. - * - * @see logbook entry - * and common-tools/clas-detector/doc - * - * The EPICS equation for converting Faraday Cup raw scaler S to beam current I: - * I [nA] = (S [Hz] - offset ) / slope * attenuation; - * - * offset/slope/attenuation are read from CCDB - * - * Accounting for the offset in accumulated beam charge requires knowledge of - * time duration. Currently, the (32 bit) DSC2 clock is zeroed at run start - * but at 1 Mhz rolls over every 35 seconds, and the (48 bit) 250 MHz TI timestamp - * can also rollover within a run since only zeroed upon reboot. Instead we allow - * run duration to be passed in, e.g. using run start time from RCDB and event - * unix time from RUN::config. - * - * FIXME: Use CCDB for GATEINVERTED, CLOCK_FREQ, CRATE/SLOT/CHAN - * - * @author baltzell - */ -public class DaqScalers { - - public Dsc2RawReading dsc2=null; - public StruckRawReading struck=null; - - private long timestamp=0; - public void setTimestamp(long timestamp) { this.timestamp=timestamp; } - public long getTimestamp(){ return this.timestamp; } - - @Deprecated public double getBeamChargeGated() { return this.dsc2.getBeamChargeGated(); } - @Deprecated public double getBeamCharge() { return this.dsc2.getBeamCharge(); } - @Deprecated public double getLivetime() { return this.struck.getLivetime(); } - - /** - * @param runScalerBank HIPO RUN::scaler bank - */ - public static DaqScalers create(Bank runScalerBank) { - DaqScalers ds=new DaqScalers(); - ds.dsc2=new Dsc2RawReading(); - for (int ii=0; ii 0 && struck.getGatedClock()>0) { - double q = (double)(struck.getSlm() - slm_offset * struck.getClockSeconds() ); - double qg = (double)(struck.getGatedSlm() - slm_offset * struck.getGatedClockSeconds() ); - struck.setBeamChargeSLM(q * slm_atten / slm_slope); - struck.setBeamChargeGatedSLM(qg * slm_atten / slm_slope); - struck.setLivetime((double)struck.getGatedClock() / struck.getClock()); - } - - if (dsc2.getClock() > 0) { - double live = (double)dsc2.getGatedSlm() / dsc2.getSlm(); - double q = (double)(dsc2.getFcup() - fcup_offset * seconds ); - double qg = (double)(dsc2.getGatedFcup() - fcup_offset * seconds * live); - dsc2.setBeamCharge(q * fcup_atten / fcup_slope); - dsc2.setBeamChargeGated(qg * fcup_atten / fcup_slope); - dsc2.setLivetime(struck.getClock()>0?(double)struck.getGatedClock()/struck.getClock():-1); - } - - if (dsc2.getClock()>0 || struck.getClock()>0) { - DaqScalers ds=new DaqScalers(); - ds.dsc2=dsc2; - ds.struck=struck; - return ds; - } - - return null; - } - - /** - * Same as create(Bank,IndexedTable,double), except relies on DSC2's clock. - * - * @param rawScalerBank HIPO RAW::scaler bank - * @param fcupTable /runcontrol/fcup IndexedTable from CCDB - */ - public static DaqScalers create(Bank rawScalerBank,IndexedTable fcupTable,IndexedTable slmTable) { - Dsc2RawReading dsc2 = new Dsc2RawReading(rawScalerBank); - return create(rawScalerBank,fcupTable,slmTable,dsc2.getGatedClockSeconds()); - } - - private static class RawReading { - - protected static final String RAWBANKNAME="RAW::scaler"; - protected static final int CRATE=64; - - protected double clockFreq=1; // Hz - protected long fcup=-1; // counts - protected long clock=-1; // counts - protected long slm=-1; // counts - protected long gatedFcup=-1; // counts - protected long gatedClock=-1; // counts - protected long gatedSlm=-1; // counts - - public long getClock() { return this.clock; } - public long getFcup() { return this.fcup; } - public long getSlm() { return this.slm; } - public long getGatedClock() { return this.gatedClock; } - public long getGatedFcup() { return this.gatedFcup; } - public long getGatedSlm() { return this.gatedSlm; } - public double getClockSeconds() { return (double)this.clock / this.clockFreq; } - public double getGatedClockSeconds() { return (double)this.gatedClock / this.clockFreq; } - - // not really "raw" anymore: - private double beamCharge=0; - private double beamChargeGated=0; - private double beamChargeSLM=0; - private double beamChargeGatedSLM=0; - private double livetime=0; - protected void setBeamCharge(double q) { this.beamCharge=q; } - protected void setBeamChargeGated(double q) { this.beamChargeGated=q; } - protected void setBeamChargeSLM(double q) { this.beamChargeSLM=q; } - protected void setBeamChargeGatedSLM(double q) { this.beamChargeGatedSLM=q; } - protected void setLivetime(double l) { this.livetime=l; } - public double getBeamCharge() { return beamCharge; } - public double getBeamChargeGated() { return beamChargeGated; } - public double getLivetime() { return livetime; } - public double getBeamChargeSLM() { return beamChargeSLM; } - public double getBeamChargeGatedSLM() { return beamChargeGatedSLM; } - } - - public static class StruckRawReading extends RawReading { - - private static final boolean GATEINVERTED=false; - - private final byte UDF=0; - private final byte POSITIVE=1; - private final byte NEGATIVE=-1; - private byte helicity=UDF; - private byte quartet=UDF; - public byte getHelicity() { return this.helicity; } - public byte getQuartet() { return this.quartet; } - - private static final int SLOT_GATED=0; - private static final int SLOT_UNGATED=1; - - // these are the non-settle periods: - private static final int CHAN_FCUP=0; - private static final int CHAN_SLM=1; - private static final int CHAN_CLOCK=2; - - // these are the settle periods (currently ignored): - private static final int CHAN_FCUP_SETTLE=32; - private static final int CHAN_SLM_SETTLE=33; - private static final int CHAN_CLOCK_SETTLE=34; - - public StruckRawReading() {} - - public StruckRawReading(Bank bank) { - - // the STRUCK's clock is 1 MHz - this.clockFreq = 1e6; - - // this will get the last entries (most recent) in the bank - for (int k=0; k 0 ? POSITIVE : NEGATIVE; - this.quartet = bank.getByte("quartet",k) > 0 ? POSITIVE : NEGATIVE; - this.gatedFcup = bank.getLong("value",k); - break; - case CHAN_SLM: - this.gatedSlm = bank.getLong("value",k); - break; - case CHAN_CLOCK: - this.gatedClock = bank.getLong("value",k); - break; - default: - break; - } - } - else if (bank.getInt("slot",k)==SLOT_UNGATED) { - switch (bank.getInt("channel",k)) { - case CHAN_FCUP: - this.fcup = bank.getLong("value",k); - break; - case CHAN_SLM: - this.slm = bank.getLong("value",k); - break; - case CHAN_CLOCK: - this.clock = bank.getLong("value",k); - break; - default: - break; - } - } - } - if (GATEINVERTED) { - gatedSlm = slm - gatedSlm; - gatedFcup = fcup - gatedFcup; - gatedClock = clock - gatedClock; - } - } - } - - public static class Dsc2RawReading extends RawReading{ - - private static final boolean GATEINVERTED=true; - - // DSC has TRG and TDC thresholds, we use only TDC here: - private static final int SLOT=64; - private static final int CHAN_FCUP_GATED=16; - private static final int CHAN_SLM_GATED=17; - private static final int CHAN_CLOCK_GATED=18; - private static final int CHAN_FCUP=48; - private static final int CHAN_SLM=49; - private static final int CHAN_CLOCK=50; - - public Dsc2RawReading() {} - - public Dsc2RawReading(Bank bank) { - - // the DSC2's clock is (currently) 1 MHz - // FIXME: use CCDB - this.clockFreq=1e6; - - // this will get the last entries (most recent) in the bank - for (int k=0; k 0 && this.gatedClock>0) { + + final double fcup_slope = fcupTable.getDoubleValue("slope",0,0,0); // Hz/nA + final double fcup_offset = fcupTable.getDoubleValue("offset",0,0,0); // Hz + final double fcup_atten = fcupTable.getDoubleValue("atten",0,0,0); // attenuation + final double slm_slope = slmTable.getDoubleValue("slope",0,0,0); // Hz/nA + final double slm_offset = slmTable.getDoubleValue("offset",0,0,0); // Hz + final double slm_atten = slmTable.getDoubleValue("atten",0,0,0); // attenuation + + double q,qg; + + q = this.slm - slm_offset * seconds; + qg = this.gatedSlm - slm_offset * seconds; + this.beamChargeSLM = q * slm_atten / slm_slope; + this.beamChargeGatedSLM = qg * slm_atten / slm_slope; + this.livetime = (double)this.gatedClock / this.clock; + + q = this.fcup - fcup_offset * seconds; + qg = this.gatedFcup - fcup_offset * seconds; + this.beamCharge = q * fcup_atten / fcup_slope; + this.beamChargeGated = qg * fcup_atten / fcup_slope; + } + } + + protected final void calibrate(IndexedTable fcupTable,IndexedTable slmTable) { + this.calibrate(fcupTable,slmTable,((double)this.gatedClock)/this.clockFreq); + } +} diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalers.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalers.java new file mode 100644 index 0000000000..295629e0a7 --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalers.java @@ -0,0 +1,100 @@ +package org.jlab.detector.scalers; + +import org.jlab.jnp.hipo4.data.Bank; +import org.jlab.utils.groups.IndexedTable; + +/** + * + * Read the occasional scaler bank, extract beam charge, livetime, etc. + * + * We have at least two relevant scaler hardware boards, STRUCK and DSC2, both + * readout on helicity flips and with DAQ-busy gating, both decoded into RAW::scaler. + * This class reads RAW::scaler and converts to more user-friendly information. + * + * STRUCK. Latching on helicity states, zeroed upon readout, with both helicity + * settle (normally 500 us) and non-settle counts, useful for "instantaneous" + * livetime, beam charge asymmetry, beam trip studies, ... + * + * DSC2. Integrating since beginning of run, useful for beam charge normalization. + * + * @see logbook entry + * and common-tools/clas-detector/doc + * + * The EPICS equation for converting Faraday Cup raw scaler S to beam current I: + * I [nA] = (S [Hz] - offset ) / slope * attenuation; + * + * offset/slope/attenuation are read from CCDB + * + * Accounting for the offset in accumulated beam charge requires knowledge of + * time duration. Currently, the (32 bit) DSC2 clock is zeroed at run start + * but at 1 Mhz rolls over every 35 seconds, and the (48 bit) 250 MHz TI timestamp + * can also rollover within a run since only zeroed upon reboot. Instead we allow + * run duration to be passed in, e.g. using run start time from RCDB and event + * unix time from RUN::config. + * + * FIXME: Use CCDB for GATEINVERTED, CLOCK_FREQ, CRATE/SLOT/CHAN + * + * @author baltzell + */ +public class DaqScalers { + + public Dsc2Scaler dsc2=null; + public StruckScaler struck=null; + + private long timestamp=0; + public void setTimestamp(long timestamp) { this.timestamp=timestamp; } + public long getTimestamp(){ return this.timestamp; } + + @Deprecated public double getBeamChargeGated() { return this.dsc2.getBeamChargeGated(); } + @Deprecated public double getBeamCharge() { return this.dsc2.getBeamCharge(); } + @Deprecated public double getLivetime() { return this.struck.getLivetime(); } + + /** + * @param runScalerBank HIPO RUN::scaler bank + */ + public static DaqScalers create(Bank runScalerBank) { + DaqScalers ds=new DaqScalers(); + ds.dsc2=new Dsc2Scaler(); + for (int ii=0; ii0 || struck.getClock()>0) { + DaqScalers ds=new DaqScalers(); + ds.dsc2=dsc2; + ds.struck=struck; + return ds; + } + return null; + } + + /** + * Same as create(Bank,IndexedTable,double), except relies on DSC2's clock. + * + * @param rawScalerBank HIPO RAW::scaler bank + * @param fcupTable /runcontrol/fcup IndexedTable from CCDB + */ + public static DaqScalers create(Bank rawScalerBank,IndexedTable fcupTable,IndexedTable slmTable) { + Dsc2Scaler dsc2 = new Dsc2Scaler(rawScalerBank,fcupTable,slmTable); + return create(rawScalerBank,fcupTable,slmTable,dsc2.getGatedClockSeconds()); + } + + + + + +} + diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java similarity index 99% rename from common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java rename to common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java index 6547d30a6e..2d19b3438d 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DaqScalersSequence.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java @@ -1,4 +1,4 @@ -package org.jlab.detector.decode; +package org.jlab.detector.scalers; import java.util.List; import java.util.ArrayList; @@ -10,6 +10,7 @@ import org.jlab.jnp.hipo4.data.Event; import org.jlab.jnp.hipo4.data.Bank; import org.jlab.jnp.hipo4.data.SchemaFactory; +import org.jlab.detector.scalers.DaqScalers; /** * For easy access to most recent scaler readout for any given event. diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java new file mode 100644 index 0000000000..b406bd9ce5 --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java @@ -0,0 +1,69 @@ +package org.jlab.detector.scalers; + +import org.jlab.jnp.hipo4.data.Bank; +import org.jlab.utils.groups.IndexedTable; + +public class Dsc2Scaler extends DaqScaler{ + + private static final boolean GATEINVERTED=true; + + // DSC has TRG and TDC thresholds, we use only TDC here: + private static final int SLOT=64; + private static final int CHAN_FCUP_GATED=16; + private static final int CHAN_SLM_GATED=17; + private static final int CHAN_CLOCK_GATED=18; + private static final int CHAN_FCUP=48; + private static final int CHAN_SLM=49; + private static final int CHAN_CLOCK=50; + + public Dsc2Scaler() {} + + public Dsc2Scaler(Bank bank,IndexedTable fcupTable,IndexedTable slmTable) { + this(bank,fcupTable,slmTable,1); + this.calibrate(fcupTable,slmTable); + } + + public Dsc2Scaler(Bank bank,IndexedTable fcupTable,IndexedTable slmTable,double seconds) { + + // the DSC2's clock is (currently) 1 MHz + // FIXME: use CCDB + this.clockFreq=1e6; + + // this will get the last entries (most recent) in the bank + for (int k=0; k 0 ? POSITIVE : NEGATIVE; + this.quartet = bank.getByte("quartet",k) > 0 ? POSITIVE : NEGATIVE; + this.gatedFcup = bank.getLong("value",k); + break; + case CHAN_SLM: + this.gatedSlm = bank.getLong("value",k); + break; + case CHAN_CLOCK: + this.gatedClock = bank.getLong("value",k); + break; + default: + break; + } + } + else if (bank.getInt("slot",k)==SLOT_UNGATED) { + switch (bank.getInt("channel",k)) { + case CHAN_FCUP: + this.fcup = bank.getLong("value",k); + break; + case CHAN_SLM: + this.slm = bank.getLong("value",k); + break; + case CHAN_CLOCK: + this.clock = bank.getLong("value",k); + break; + default: + break; + } + } + } + if (GATEINVERTED) { + gatedSlm = slm - gatedSlm; + gatedFcup = fcup - gatedFcup; + gatedClock = clock - gatedClock; + } + + this.calibrate(fcupTable,slmTable); + } +} \ No newline at end of file From 80735eebf22bb26c9e4ef68ef78a0d6531d717e6 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 21 Sep 2020 12:52:10 -0400 Subject: [PATCH 12/21] fix fallout from scaler refactor --- .../org/jlab/detector/scalers/DaqScaler.java | 49 ++++++++++++------- .../org/jlab/detector/scalers/Dsc2Scaler.java | 25 ++++++++-- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java index 90b0d7a2f4..eef3e53de1 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java @@ -15,16 +15,18 @@ public class DaqScaler { protected long gatedClock=-1; // counts protected long gatedSlm=-1; // counts - public long getClock() { return this.clock; } - public long getFcup() { return this.fcup; } - public long getSlm() { return this.slm; } - public long getGatedClock() { return this.gatedClock; } - public long getGatedFcup() { return this.gatedFcup; } - public long getGatedSlm() { return this.gatedSlm; } - public double getClockSeconds() { return (double)this.clock / this.clockFreq; } - public double getGatedClockSeconds() { return (double)this.gatedClock / this.clockFreq; } + public final long getClock() { return this.clock; } + public final long getFcup() { return this.fcup; } + public final long getSlm() { return this.slm; } + public final long getGatedClock() { return this.gatedClock; } + public final long getGatedFcup() { return this.gatedFcup; } + public final long getGatedSlm() { return this.gatedSlm; } + public final double getClockSeconds() { return (double)this.clock / this.clockFreq; } + public final double getGatedClockSeconds() { return (double)this.gatedClock / this.clockFreq; } + public final double getLivetimeClock() { return (double)this.gatedClock / this.clock; } + public final double getLivetimeFcup() {return (double)this.gatedFcup / this.fcup; } + public final double getLivetimeSLM() {return (double)this.gatedSlm / this.slm; } - // not really "raw" anymore: protected double beamCharge=0; protected double beamChargeGated=0; protected double beamChargeSLM=0; @@ -41,9 +43,15 @@ public class DaqScaler { public double getBeamChargeSLM() { return beamChargeSLM; } public double getBeamChargeGatedSLM() { return beamChargeGatedSLM; } - protected final void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double seconds) { - if (this.clock > 0 && this.gatedClock>0) { - + /** + * Manually choose dwell and live-dwell times, e.g. if clock rolls over. + * @param fcupTable + * @param slmTable + * @param seconds + * @param liveSeconds + */ + protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double seconds,double liveSeconds) { + if (this.clock > 0) { final double fcup_slope = fcupTable.getDoubleValue("slope",0,0,0); // Hz/nA final double fcup_offset = fcupTable.getDoubleValue("offset",0,0,0); // Hz final double fcup_atten = fcupTable.getDoubleValue("atten",0,0,0); // attenuation @@ -53,20 +61,25 @@ protected final void calibrate(IndexedTable fcupTable,IndexedTable slmTable,doub double q,qg; - q = this.slm - slm_offset * seconds; - qg = this.gatedSlm - slm_offset * seconds; + q = (double)this.slm - slm_offset * seconds; + qg = (double)this.gatedSlm - slm_offset * liveSeconds; this.beamChargeSLM = q * slm_atten / slm_slope; this.beamChargeGatedSLM = qg * slm_atten / slm_slope; this.livetime = (double)this.gatedClock / this.clock; - q = this.fcup - fcup_offset * seconds; - qg = this.gatedFcup - fcup_offset * seconds; + q = (double)this.fcup - fcup_offset * seconds; + qg = (double)this.gatedFcup - fcup_offset * liveSeconds; this.beamCharge = q * fcup_atten / fcup_slope; this.beamChargeGated = qg * fcup_atten / fcup_slope; } } - + + /** + * Use the scaler's own clock to get dwell and live-dwell times + * @param fcupTable + * @param slmTable + */ protected final void calibrate(IndexedTable fcupTable,IndexedTable slmTable) { - this.calibrate(fcupTable,slmTable,((double)this.gatedClock)/this.clockFreq); + this.calibrate(fcupTable,slmTable,this.getClockSeconds(),this.getGatedClockSeconds()); } } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java index b406bd9ce5..83c67653d2 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java @@ -18,11 +18,6 @@ public class Dsc2Scaler extends DaqScaler{ public Dsc2Scaler() {} - public Dsc2Scaler(Bank bank,IndexedTable fcupTable,IndexedTable slmTable) { - this(bank,fcupTable,slmTable,1); - this.calibrate(fcupTable,slmTable); - } - public Dsc2Scaler(Bank bank,IndexedTable fcupTable,IndexedTable slmTable,double seconds) { // the DSC2's clock is (currently) 1 MHz @@ -66,4 +61,24 @@ public Dsc2Scaler(Bank bank,IndexedTable fcupTable,IndexedTable slmTable,double this.calibrate(fcupTable,slmTable,seconds); } + + public Dsc2Scaler(Bank bank,IndexedTable fcupTable,IndexedTable slmTable) { + this(bank,fcupTable,slmTable,1); + this.calibrate(fcupTable,slmTable); + } + + /** + * During some run periods, the run-integrating DSC2 scaler's clock frequency + * was too large and rolls over during the run. So here we can pass in seconds + * (e.g. based on RCDB run start time) instead. + * @param fcupTable + * @param slmTable + * @param seconds + */ + protected final void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double seconds) { + if (this.slm>0) { + super.calibrate(fcupTable,slmTable,seconds,seconds*((double)this.gatedSlm)/this.slm); + } + } + } \ No newline at end of file From b499a75f9f8a39131100b03bf10df6774423ffac Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 21 Sep 2020 15:18:13 -0400 Subject: [PATCH 13/21] remove livetime from HEL::scaler, fall back to SLM if Fcup slope/atten negative --- .../analysis/postprocess/RebuildScalers.java | 7 +++---- .../jlab/detector/decode/CLASDecoder4.java | 3 +-- .../org/jlab/detector/scalers/DaqScaler.java | 21 ++++++++++++------- .../org/jlab/detector/scalers/DaqScalers.java | 4 ---- etc/bankdefs/hipo4/header.json | 3 +-- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java index 92404fdef1..9983ba11d7 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java @@ -99,15 +99,15 @@ public static void main(String[] args) { // modify RUN::scaler: runScalerBank.putFloat("fcupgated",0, (float) ds.dsc2.getBeamChargeGated()); runScalerBank.putFloat("fcup",0, (float) ds.dsc2.getBeamCharge()); - runScalerBank.putFloat("livetime",0, (float) ds.dsc2.getLivetime()); + runScalerBank.putFloat("livetime",0, (float) ds.struck.getLivetimeClock()); // modify HEL::scaler: helScalerBank.putFloat("fcup",0, (float) ds.struck.getBeamCharge()); helScalerBank.putFloat("fcupgated",0, (float) ds.struck.getBeamChargeGated()); helScalerBank.putFloat("slm",0, (float) ds.struck.getBeamChargeSLM()); helScalerBank.putFloat("slmgated",0, (float) ds.struck.getBeamChargeGatedSLM()); - helScalerBank.putFloat("clock",0,ds.struck.getClock()); - helScalerBank.putFloat("clockgated",0,ds.struck.getGatedClock()); + helScalerBank.putFloat("clock",0,(float)ds.struck.getClock()); + helScalerBank.putFloat("clockgated",0,(float)ds.struck.getGatedClock()); // the scaler banks always are delayed relative to helicity changes, // so assign the previous helicity state to this scaler reading: helScalerBank.putByte("helicity",0,helSeq.search(event,-1).value()); @@ -118,7 +118,6 @@ public static void main(String[] args) { helScalerBank.putByte("helicityRaw",0,helSeq.search(event,-1).value()); } - // put modified HEL/RUN::scaler back in the event: event.write(runScalerBank); event.write(helScalerBank); diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java index f735106e61..fd57d5364f 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java @@ -618,7 +618,7 @@ public Bank[] createReconScalerBanks(Event event){ Bank scalerBank = new Bank(schemaFactory.getSchema("RUN::scaler"),1); scalerBank.putFloat("fcup",0,(float)r.dsc2.getBeamCharge()); scalerBank.putFloat("fcupgated",0,(float)r.dsc2.getBeamChargeGated()); - scalerBank.putFloat("livetime",0,(float)r.struck.getLivetime()); + scalerBank.putFloat("livetime",0,(float)r.struck.getLivetimeClock()); Bank helicityBank = new Bank(schemaFactory.getSchema("HEL::scaler"),1); helicityBank.putFloat("fcup",0,(float)r.struck.getBeamCharge()); @@ -627,7 +627,6 @@ public Bank[] createReconScalerBanks(Event event){ helicityBank.putFloat("slmgated",0,(float)r.struck.getBeamChargeGatedSLM()); helicityBank.putFloat("clock",0,(float)r.struck.getClock()); helicityBank.putFloat("clockgated",0,(float)r.struck.getGatedClock()); - helicityBank.putFloat("livetime",0,(float)r.struck.getLivetime()); Bank ret[] = {scalerBank,helicityBank}; return ret; diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java index eef3e53de1..e0b2f8368f 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java @@ -51,6 +51,7 @@ public class DaqScaler { * @param liveSeconds */ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double seconds,double liveSeconds) { + if (this.clock > 0) { final double fcup_slope = fcupTable.getDoubleValue("slope",0,0,0); // Hz/nA final double fcup_offset = fcupTable.getDoubleValue("offset",0,0,0); // Hz @@ -59,18 +60,22 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec final double slm_offset = slmTable.getDoubleValue("offset",0,0,0); // Hz final double slm_atten = slmTable.getDoubleValue("atten",0,0,0); // attenuation - double q,qg; - - q = (double)this.slm - slm_offset * seconds; - qg = (double)this.gatedSlm - slm_offset * liveSeconds; + double q = (double)this.slm - slm_offset * seconds; + double qg = (double)this.gatedSlm - slm_offset * liveSeconds; this.beamChargeSLM = q * slm_atten / slm_slope; this.beamChargeGatedSLM = qg * slm_atten / slm_slope; this.livetime = (double)this.gatedClock / this.clock; - q = (double)this.fcup - fcup_offset * seconds; - qg = (double)this.gatedFcup - fcup_offset * liveSeconds; - this.beamCharge = q * fcup_atten / fcup_slope; - this.beamChargeGated = qg * fcup_atten / fcup_slope; + if (fcup_atten<0 || fcup_slope<0) { + this.beamCharge = this.beamChargeSLM; + this.beamChargeGated = this.beamChargeGatedSLM; + } + else { + q = (double)this.fcup - fcup_offset * seconds; + qg = (double)this.gatedFcup - fcup_offset * liveSeconds; + this.beamCharge = q * fcup_atten / fcup_slope; + this.beamChargeGated = qg * fcup_atten / fcup_slope; + } } } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalers.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalers.java index 295629e0a7..93c6d0b978 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalers.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalers.java @@ -45,10 +45,6 @@ public class DaqScalers { public void setTimestamp(long timestamp) { this.timestamp=timestamp; } public long getTimestamp(){ return this.timestamp; } - @Deprecated public double getBeamChargeGated() { return this.dsc2.getBeamChargeGated(); } - @Deprecated public double getBeamCharge() { return this.dsc2.getBeamCharge(); } - @Deprecated public double getLivetime() { return this.struck.getLivetime(); } - /** * @param runScalerBank HIPO RUN::scaler bank */ diff --git a/etc/bankdefs/hipo4/header.json b/etc/bankdefs/hipo4/header.json index 6aba14c5c4..b217ffeae8 100644 --- a/etc/bankdefs/hipo4/header.json +++ b/etc/bankdefs/hipo4/header.json @@ -70,8 +70,7 @@ {"name":"clockgated", "type":"F", "info":"Clock, DAQ-gated"}, {"name":"clock", "type":"F", "info":"Clock"}, {"name":"helicity", "type":"B", "info":"Helicity state, HWP-corrected"}, - {"name":"helicityRaw","type":"B", "info":"Helicity state"}, - {"name":"livetime", "type":"F", "info":"DAQ livetime"} + {"name":"helicityRaw","type":"B", "info":"Helicity state"} ] } ] From 1f96aef4062afc10c4da8aa13deedeba928206fe Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Wed, 23 Sep 2020 09:21:35 -0400 Subject: [PATCH 14/21] move bank creation to DaqScalers --- .../analysis/postprocess/RebuildScalers.java | 41 ++---- .../analysis/postprocess/Tag1ToEvent.java | 4 +- .../jlab/detector/decode/CLASDecoder4.java | 30 +---- .../org/jlab/detector/scalers/DaqScalers.java | 126 ++++++++++++++++-- .../org/jlab/detector/scalers/Dsc2Scaler.java | 10 +- 5 files changed, 136 insertions(+), 75 deletions(-) diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java index 9983ba11d7..4f77df1fe2 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/postprocess/RebuildScalers.java @@ -74,6 +74,7 @@ public static void main(String[] args) { // this is the bank we're here to rebuild: event.remove(runScalerBank.getSchema()); + event.remove(helScalerBank.getSchema()); // get CCDB/RCDB constants: if (runConfigBank.getInt("run",0) >= 100) { @@ -85,39 +86,23 @@ public static void main(String[] args) { // now rebuild the RUN::scaler bank: if (rcdb!=null && ccdb_fcup !=null && rawScalerBank.getRows()>0) { - // Run duration in seconds. Nasty but works, until RCDB (uses java.sql.Time) - // is changed to support full date and not just HH:MM:SS. Meanwhile just - // requires that runs last less than 24 hours. - Date uet = new Date(runConfigBank.getInt("unixtime",0)*1000L); + // Inputs for calculation run duration in seconds, since for + // some run periods the DSC2 clock rolls over during a run. Time rst = rcdb.getTime("run_start_time"); - final double s1 = rst.getSeconds()+60*rst.getMinutes()+60*60*rst.getHours(); - final double s2 = uet.getSeconds()+60*uet.getMinutes()+60*60*uet.getHours(); - final double seconds = s2 Date: Fri, 25 Sep 2020 17:47:15 -0400 Subject: [PATCH 15/21] assign neutral momentum (to zero) even if no start time --- .../java/org/jlab/service/eb/EBAnalyzer.java | 165 +++++++++--------- 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBAnalyzer.java b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBAnalyzer.java index 29ce34aeaa..f880091535 100644 --- a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBAnalyzer.java +++ b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBAnalyzer.java @@ -112,68 +112,69 @@ else if (p.getStatus().isForward() && p.getCharge()!=0) { } // no good candidates, abort: - if (electronFT.size()<1 || chargedFD.size()<1) return; + if (electronFT.size()>0 && chargedFD.size()>0) { - // the index of the FT particle with the best FT-FD timing-match: - int iMinTimeDiffFT = -1; + // the index of the FT particle with the best FT-FD timing-match: + int iMinTimeDiffFT = -1; - // anything relevant must be better than half-bucket: - double minTimeDiff = this.ccdb.getDouble(EBCCDBEnum.RF_BUCKET_LENGTH)/2; + // anything relevant must be better than half-bucket: + double minTimeDiff = this.ccdb.getDouble(EBCCDBEnum.RF_BUCKET_LENGTH)/2; - // loop over FT electron candidates: - for (int itag=0; itag=0) { - // reassign trigger particle: - for (DetectorParticle p : event.getParticles()) { - p.setTriggerParticle(false); - } - electronFT.get(iMinTimeDiffFT).setTriggerParticle(true); + // reassign trigger particle: + for (DetectorParticle p : event.getParticles()) { + p.setTriggerParticle(false); + } + electronFT.get(iMinTimeDiffFT).setTriggerParticle(true); - // set start time: - final double startTime = ebrf.getStartTime(electronFT.get(iMinTimeDiffFT),DetectorType.FTCAL,-1); - event.getEventHeader().setStartTimeFT(startTime); - assignParticleStartTimes(event,DetectorType.FTCAL,-1); - - // recalculate betas, pids, etc: - this.assignBetas(event,true); - this.assignPids(event,true); + // set start time: + final double startTime = ebrf.getStartTime(electronFT.get(iMinTimeDiffFT),DetectorType.FTCAL,-1); + event.getEventHeader().setStartTimeFT(startTime); + assignParticleStartTimes(event,DetectorType.FTCAL,-1); + + // recalculate betas, pids, etc: + this.assignBetas(event,true); + this.assignPids(event,true); + } + } this.assignNeutralMomenta(event); } @@ -190,50 +191,50 @@ public void processEvent(DetectorEvent event) { if (event.getParticles().size() <= 0) return; DetectorParticle trigger = event.getTriggerParticle(); - if (trigger==null) return; + if (trigger!=null) { - // priority is to identify a trigger time: - boolean foundTriggerTime=false; - double startTime=-1000; + // priority is to identify a trigger time: + boolean foundTriggerTime=false; + double startTime=-1000; - // electron/positron/pion is trigger particle: - if (trigger.getPid()==11 || trigger.getPid()==-11 || - trigger.getPid()==211 || trigger.getPid()==-211) { + // electron/positron/pion is trigger particle: + if (trigger.getPid()==11 || trigger.getPid()==-11 || + trigger.getPid()==211 || trigger.getPid()==-211) { - trigger.setBeta(trigger.getTheoryBeta(trigger.getPid())); - trigger.setMass(PDGDatabase.getParticleById(trigger.getPid()).mass()); + trigger.setBeta(trigger.getTheoryBeta(trigger.getPid())); + trigger.setMass(PDGDatabase.getParticleById(trigger.getPid()).mass()); - // prefer FTOF Panel 1B: - if (trigger.hasHit(DetectorType.FTOF, 2)==true){ - startTime = ebrf.getStartTime(trigger,DetectorType.FTOF,2); - assignParticleStartTimes(event,DetectorType.FTOF,2); - foundTriggerTime = true; - } + // prefer FTOF Panel 1B: + if (trigger.hasHit(DetectorType.FTOF, 2)==true){ + startTime = ebrf.getStartTime(trigger,DetectorType.FTOF,2); + assignParticleStartTimes(event,DetectorType.FTOF,2); + foundTriggerTime = true; + } - // else use FTOF Panel 1A: - else if (trigger.hasHit(DetectorType.FTOF, 1)==true){ - startTime = ebrf.getStartTime(trigger,DetectorType.FTOF,1); - assignParticleStartTimes(event,DetectorType.FTOF,1); - foundTriggerTime = true; + // else use FTOF Panel 1A: + else if (trigger.hasHit(DetectorType.FTOF, 1)==true){ + startTime = ebrf.getStartTime(trigger,DetectorType.FTOF,1); + assignParticleStartTimes(event,DetectorType.FTOF,1); + foundTriggerTime = true; + } } - } - // neutral is trigger particle: - else if (trigger.getPid()==0 || trigger.getPid()==22) { - trigger.setBeta(1.0); - trigger.setMass(0.0); - // TODO: implement full neutral trigger start time? - //foundTriggerTime=true; - } + // neutral is trigger particle: + else if (trigger.getPid()==0 || trigger.getPid()==22) { + trigger.setBeta(1.0); + trigger.setMass(0.0); + // TODO: implement full neutral trigger start time? + //foundTriggerTime=true; + } - // we found event start time, so set it and do pid: - if (foundTriggerTime) { - event.getEventHeader().setStartTime(startTime); - this.assignBetas(event,false); - this.assignPids(event,false); - this.assignNeutralMomenta(event); + // we found event start time, so set it and do pid: + if (foundTriggerTime) { + event.getEventHeader().setStartTime(startTime); + this.assignBetas(event,false); + this.assignPids(event,false); + } } - + this.assignNeutralMomenta(event); } /** From 2517f77572494df513fe784274242f1df4a36764 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Fri, 2 Oct 2020 09:11:02 -0400 Subject: [PATCH 16/21] add hit-based DST schema --- etc/bankdefs/util/bankSplit.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/etc/bankdefs/util/bankSplit.py b/etc/bankdefs/util/bankSplit.py index 06719ac3be..58bd91619c 100644 --- a/etc/bankdefs/util/bankSplit.py +++ b/etc/bankdefs/util/bankSplit.py @@ -50,11 +50,19 @@ def createdirandlinks(dirname, banklist): # create dst, calibration and monitoring directories dst = ["BAND::laser","RUN::config","RAW::epics","RAW::scaler","REC::Event","REC::Particle","REC::Calorimeter","REC::Cherenkov","REC::CovMat","REC::ForwardTagger","REC::Scintillator","REC::ScintExtras","REC::Track","REC::Traj","RECFT::Event","RECFT::Particle","RICH::tdc","RICH::ringCher","RICH::hadCher","RUN::scaler","HEL::flip","HEL::online","MC::Event","MC::Header","MC::Lund","MC::Particle","MC::True"] + calibration = ["BAND::adc","BAND::tdc","BAND::hits","BAND::rawhits","BAND::laser","CND::adc","CND::hits","CND::tdc","CTOF::adc","CTOF::hits","CTOF::tdc","CVTRec::Tracks","ECAL::adc","ECAL::calib","ECAL::clusters","ECAL::peaks","ECAL::tdc","FT::particles","FTCAL::adc","FTCAL::clusters","FTCAL::hits","FTHODO::adc","FTHODO::clusters","FTHODO::hits","FTOF::adc","FTOF::hits","FTOF::tdc","HEL::flip","HEL::online","HTCC::adc","HTCC::rec","LTCC::adc","LTCC::clusters","MC::Event","MC::Header","MC::Lund","MC::Particle","MC::True","RAW::epics","RAW::scaler","REC::Calorimeter","REC::Cherenkov","REC::CovMat","REC::Event","REC::ForwardTagger","REC::Particle","REC::Scintillator","REC::ScintExtras","REC::Track","REC::Traj","RECFT::Event","RECFT::Particle","RF::adc","RF::tdc","RICH::tdc","RICH::hits","RICH::hadCher","RICH::hadrons","RICH::photons","RICH::ringCher","RUN::config","RUN::rf","RUN::scaler","RUN::trigger","TimeBasedTrkg::TBCrosses","TimeBasedTrkg::TBHits","TimeBasedTrkg::TBSegments","TimeBasedTrkg::TBSegmentTrajectory","TimeBasedTrkg::TBTracks","TimeBasedTrkg::Trajectory"] + monitoring = ["BAND::adc","BAND::tdc","BAND::rawhits","BAND::laser","BAND::hits","BMT::adc","BMTRec::Clusters","BMTRec::Crosses","BMTRec::Hits","BMTRec::LayerEffs","BST::adc","BSTRec::Clusters","BSTRec::Crosses","BSTRec::Hits","BSTRec::LayerEffs","CND::adc","CND::clusters","CND::hits","CND::tdc","CTOF::adc","CTOF::hits","CTOF::tdc","CVTRec::Tracks","CVTRec::Trajectory","ECAL::adc","ECAL::calib","ECAL::clusters","ECAL::hits","ECAL::peaks","ECAL::tdc","FT::particles","FTCAL::adc","FTCAL::clusters","FTCAL::hits","FTHODO::adc","FTHODO::clusters","FTHODO::hits","FTOF::adc","FTOF::hits","FTOF::tdc","HEL::adc","HEL::flip","HEL::online","HitBasedTrkg::HBTracks","HTCC::adc","HTCC::rec","LTCC::adc","LTCC::clusters","MC::Event","MC::Header","MC::Lund","MC::Particle","MC::True","RAW::epics","RAW::scaler","RAW::vtp","REC::Calorimeter","REC::Cherenkov","REC::CovMat","REC::Event","REC::ForwardTagger","REC::Particle","REC::Scintillator","REC::ScintExtras","REC::Track","REC::Traj","RECFT::Event","RECFT::Particle","RECHB::Calorimeter","RECHB::Cherenkov","RECHB::Event","RECHB::ForwardTagger","RECHB::Particle","RECHB::Scintillator","RECHB::Track","RF::adc","RF::tdc","RICH::tdc","RICH::hits","RICH::hadCher","RICH::hadrons","RICH::photons","RICH::ringCher","RUN::config","RUN::rf","RUN::scaler","RUN::trigger","TimeBasedTrkg::TBCrosses","TimeBasedTrkg::TBHits","TimeBasedTrkg::TBSegments","TimeBasedTrkg::TBSegmentTrajectory","TimeBasedTrkg::TBTracks","TimeBasedTrkg::Trajectory"] + ebrerun=list(dst) ebrerun.extend(["FTOF::hits","TimeBasedTrkg::TBTracks","TimeBasedTrkg::Trajectory","TimeBasedTrkg::TBCovMat","HitBasedTrkg::HBTracks","FTOF::hbhits","ECAL::clusters","CTOF::hits","CND::clusters","HTCC::rec","LTCC::clusters","ECAL::moments","CVTRec::Tracks","CVTRec::Trajectory","FT::particles","FTCAL::clusters","FTHODO::clusters","RUN:rf"]) + +dsthb=list(dst) +dsthb.extend(["RECHB::Event","RECHB::Particle","RECHB::Calorimeter","RECHB::Cherenkov","RECHB::CovMat","RECHB::ForwardTagger","RECHB::Scintillator","RECHB::ScintExtras","RECHB::Track"]) + createdirandlinks("dst/", dst) +createdirandlinks("dsthb/", dsthb) createdirandlinks("calibration/", calibration) createdirandlinks("monitoring/", monitoring) #createdirandlinks("ebrerun/", ebrerun) From 77b475c7063db1f6b6d5612d9be1aba7b8e69b3c Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Fri, 2 Oct 2020 13:59:31 -0400 Subject: [PATCH 17/21] use atten=0 to kill SLM/FCup to avoid confusion, so switch to zero-check for SLM to override FCup --- .../src/main/java/org/jlab/detector/scalers/DaqScaler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java index e0b2f8368f..111a740bb2 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java @@ -66,7 +66,7 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec this.beamChargeGatedSLM = qg * slm_atten / slm_slope; this.livetime = (double)this.gatedClock / this.clock; - if (fcup_atten<0 || fcup_slope<0) { + if (fcup_atten<1e-8 || fcup_slope<1e-8) { this.beamCharge = this.beamChargeSLM; this.beamChargeGated = this.beamChargeGatedSLM; } From 8ed53986f8b1a2e6f3c5a63b1e6f6d7fd88020c9 Mon Sep 17 00:00:00 2001 From: dcpayette Date: Sun, 4 Oct 2020 12:17:45 -0400 Subject: [PATCH 18/21] Bonusdev (#590) * added gains support, fixed NaN issue in reco * time window corrections; changes to adc thresholds * time window adjustments; more ccdb additions * adding more rows to output bank * added support to turn off time shift * Disentangler updates; bank updates * Fixed missing bank name * Added new phi reco formula * new phi reconstruction formula * small update to reader * more ccdb changes * Reco uses smallest time now; added more flags * long/short tshift * pushed a fix for incorrect row/col calculation * fixed radians/degrees bug * updated chi2 * adjust momentum correction * phi range update, adding term to r reconstruction * additional phi updates * updated phi calculation for pads * gain fix * gain fix, row/col swap * chi2 issues * one more chi update * Updated R function and Chi2 function * Updated R function and Chi2 function (small change) * units changed for reconstruction * Added yaml flag * added yaml flag * updates to reconstruction format * fixing a small units issue * updated chi2 for correct helix radius * added additional items to ccdb and corresponding support * more ccdb for disentangler * checking disentangler flag in TA, and adding chi2 threshold to helix fitter * fixed a bug in the helix fitter * array out of bounds exception fix * added chi2 percentage cut * bug fix in helix fitter * second bugfix for helix fitter * version for official PR * Update data.yaml * Update mc.yaml * Update reconstruction.yaml Co-authored-by: dcpayette Co-authored-by: raffaelladevita Co-authored-by: Nathan Baltzell Co-authored-by: gavalian --- etc/bankdefs/hipo4/rtpc.json | 75 +++++---- etc/services/data.yaml | 2 +- etc/services/mc.yaml | 2 + etc/services/reconstruction.yaml | 5 +- .../org/jlab/rec/rtpc/banks/HitReader.java | 6 +- .../jlab/rec/rtpc/banks/RecoBankWriter.java | 48 ++++-- .../org/jlab/rec/rtpc/hit/FinalTrackInfo.java | 27 +++- .../org/jlab/rec/rtpc/hit/HelixFitJava.java | 16 +- .../org/jlab/rec/rtpc/hit/HelixFitObject.java | 13 +- .../org/jlab/rec/rtpc/hit/HelixFitTest.java | 147 +++++++++++++----- .../org/jlab/rec/rtpc/hit/HitParameters.java | 68 ++++++-- .../java/org/jlab/rec/rtpc/hit/PadVector.java | 27 +++- .../org/jlab/rec/rtpc/hit/RecoHitVector.java | 29 +++- .../org/jlab/rec/rtpc/hit/ReducedTrack.java | 127 +++++++++------ .../org/jlab/rec/rtpc/hit/TimeAverage.java | 24 ++- .../jlab/rec/rtpc/hit/TrackDisentangler.java | 118 +++++++++----- .../org/jlab/rec/rtpc/hit/TrackFinder.java | 19 ++- .../org/jlab/rec/rtpc/hit/TrackHitReco.java | 93 +++++++---- .../org/jlab/rec/rtpc/hit/TrackUtils.java | 19 ++- .../org/jlab/service/rtpc/RTPCEngine.java | 87 ++++++----- 20 files changed, 657 insertions(+), 295 deletions(-) diff --git a/etc/bankdefs/hipo4/rtpc.json b/etc/bankdefs/hipo4/rtpc.json index 58dbcbb1e8..23cb3ed1d0 100644 --- a/etc/bankdefs/hipo4/rtpc.json +++ b/etc/bankdefs/hipo4/rtpc.json @@ -1,35 +1,50 @@ [ - { - "name": "RTPC::hits", - "group": 1720, - "item" : 1, - "info": "reconstructed RTPC hits", - "entries": [ - {"name":"trkID", "type":"I", "info":"Track ID of the hit"}, - {"name":"id", "type":"I", "info":"cell id"}, - {"name":"time", "type":"F", "info":"Time (ns)"}, - {"name":"x", "type":"F", "info":"x pos (mm)"}, - {"name":"y", "type":"F", "info":"y pos (mm)"}, - {"name":"z", "type":"F", "info":"z pos (mm)"}, - {"name":"tdiff", "type":"F", "info":"Time shift (ns)"} - ] - }, - { + { + "name": "RTPC::hits", + "group": 21900, + "item" : 21, + "info": "reconstructed RTPC hits", + "entries": [ + {"name":"trkID", "type":"I", "info":"Track ID of the hit"}, + {"name":"id", "type":"I", "info":"cell id"}, + {"name":"time", "type":"F", "info":"Time (ns)"}, + {"name":"x", "type":"F", "info":"x pos (mm)"}, + {"name":"y", "type":"F", "info":"y pos (mm)"}, + {"name":"z", "type":"F", "info":"z pos (mm)"}, + {"name":"tdiff", "type":"F", "info":"Time shift (ns)"} + ] + }, + { "name": "RTPC::tracks", - "group": 1720, - "item" : 2, + "group": 21900, + "item" : 22, "info" : "reconstructed track info", "entries": [ - {"name":"trkID", "type":"I", "info":"Track ID of the hit"}, - {"name":"px", "type":"F", "info":"X component of the momentum (GeV)"}, - {"name":"py", "type":"F", "info":"Y component of the momentum (GeV)"}, - {"name":"pz", "type":"F", "info":"Z component of the momentum (GeV)"}, - {"name":"vz", "type":"F", "info":"Z component of the reconstructed vertex (cm)"}, - {"name":"theta", "type":"F", "info":"Theta from the Helix fit of the track (rad)"}, - {"name":"phi", "type":"F", "info":"Phi from the Helix fit of the track (rad)"}, - {"name":"nhits", "type":"I", "info":"Number of hits in the track"}, - {"name":"path", "type":"F", "info":"Length of the Track (mm)"}, - {"name":"dedx", "type":"F", "info":"dEdx for the Track (MeV/mm)"} + {"name":"trkID", "type":"I", "info":"Track ID of the hit"}, + {"name":"px", "type":"F", "info":"X component of the momentum (GeV)"}, + {"name":"py", "type":"F", "info":"Y component of the momentum (GeV)"}, + {"name":"pz", "type":"F", "info":"Z component of the momentum (GeV)"}, + {"name":"vz", "type":"F", "info":"Z component of the reconstructed vertex (cm)"}, + {"name":"theta", "type":"F", "info":"Theta from the Helix fit of the track (deg)"}, + {"name":"phi", "type":"F", "info":"Phi from the Helix fit of the track (deg)"}, + {"name":"nhits", "type":"I", "info":"Number of hits in the track"}, + {"name":"path", "type":"F", "info":"Length of the Track (mm)"}, + {"name":"adcsum", "type":"F", "info":"Total ADC sum of the Track"}, + {"name":"dedx", "type":"F", "info":"dEdx for the Track (MeV/mm)"}, + {"name":"r_helix", "type":"F", "info":"Radius of the helix fit (mm)"}, + {"name":"x_helix", "type":"F", "info":"X-coordinate of the center of helix fit (mm)"}, + {"name":"y_helix", "type":"F", "info":"Y-coordinate of the center of helix fit (mm)"}, + {"name":"chi2_helix", "type":"F", "info":"Chi squared of the helix fit"}, + {"name":"min_row", "type":"F", "info":"Pad row of hit with smallest time"}, + {"name":"min_col", "type":"F", "info":"Pad col of hit with smallest time"}, + {"name":"max_row", "type":"F", "info":"Pad row of hit with largest time"}, + {"name":"max_col", "type":"F", "info":"Pad col of hit with largest time"}, + {"name":"min_time", "type":"F", "info":"Smallest time in track not shifted (ns)"}, + {"name":"max_time", "type":"F", "info":"Largest time in track not shifted (ns)"}, + {"name":"min_radius", "type":"F", "info":"Smallest reconstructed radius (mm)"}, + {"name":"max_radius", "type":"F", "info":"Largest reconstructed radius (mm)"}, + {"name":"min_phi", "type":"F", "info":"Smallest reconstructed phi (rad)"}, + {"name":"max_phi", "type":"F", "info":"Largest reconstructed phi (rad)"} ] - } - ] + } +] diff --git a/etc/services/data.yaml b/etc/services/data.yaml index d03a86cea7..c70a442da3 100644 --- a/etc/services/data.yaml +++ b/etc/services/data.yaml @@ -77,6 +77,6 @@ configuration: variation: rga_fall2018 EBTB: variation: rga_fall2018 - + mime-types: - binary/data-hipo diff --git a/etc/services/mc.yaml b/etc/services/mc.yaml index df8f1a054c..8c92be8ee8 100644 --- a/etc/services/mc.yaml +++ b/etc/services/mc.yaml @@ -51,6 +51,8 @@ configuration: MAGFIELDS: magfieldSolenoidMap: Symm_solenoid_r601_phi1_z1201_13June2018.dat magfieldTorusMap: Symm_torus_r2501_phi16_z251_24Apr2018.dat + RTPC: + rtpcSimulation: "true" mime-types: - binary/data-hipo diff --git a/etc/services/reconstruction.yaml b/etc/services/reconstruction.yaml index 1e94725545..9533c500c2 100644 --- a/etc/services/reconstruction.yaml +++ b/etc/services/reconstruction.yaml @@ -71,9 +71,6 @@ configuration: # EBTB: # variation: default # timestamp: 08/22/2018 - RTPC: - rtpcSimulation: "false" - rtpcCosmic: "true" - rtpcBeamlineFit: "false" + mime-types: - binary/data-hipo diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/banks/HitReader.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/banks/HitReader.java index f0ce9fd8f3..da76c6dd16 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/banks/HitReader.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/banks/HitReader.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.lang.Math; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; @@ -81,7 +82,7 @@ public void fetch_RTPCHits(DataEvent event, boolean simulation, boolean cosmic) if(simulation) Edep[i]/=1000000; - if(Time[i] <= 0 || Time[i] > 12000 || component < 0 || layer < 0)// || tid[i] != 2) + if(Time[i] < 0 || Time[i] > 9600 || component < 0 || layer < 0)// || tid[i] != 2) { Time[i] = 0; Edep[i] = 0; @@ -89,9 +90,8 @@ public void fetch_RTPCHits(DataEvent event, boolean simulation, boolean cosmic) posY[i] = 0; posZ[i] = 0; } - Hit hit = new Hit(1, cellID[i], 1, Time[i]); - if(cosmic){ + if(!simulation){ Edep[i] -= 256; if(Edep[i] < 0) Edep[i] = 0; } diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/banks/RecoBankWriter.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/banks/RecoBankWriter.java index 3bbcc1ac7b..0632061914 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/banks/RecoBankWriter.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/banks/RecoBankWriter.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.HashMap; import org.jlab.rec.rtpc.hit.FinalTrackInfo; +import org.jlab.rec.rtpc.hit.PadVector; public class RecoBankWriter { @@ -27,7 +28,7 @@ public DataBank fillRTPCHitsBank(DataEvent event, HitParameters params) { listsize++; } } - + if(listsize == 0) return null; DataBank bank = event.createBank("RTPC::hits", listsize); @@ -63,9 +64,9 @@ public DataBank fillRTPCHitsBank(DataEvent event, HitParameters params) { public DataBank fillRTPCTrackBank(DataEvent event, HitParameters params) { HashMap finaltrackinfomap = params.get_finaltrackinfomap(); + HashMap> recotrackmap = params.get_recotrackmap(); int listsize = finaltrackinfomap.size(); if(listsize == 0) return null; - if(finaltrackinfomap.size() == 0) return null; int row = 0; @@ -78,22 +79,41 @@ public DataBank fillRTPCTrackBank(DataEvent event, HitParameters params) { } for(int TID : finaltrackinfomap.keySet()) { - + FinalTrackInfo track = finaltrackinfomap.get(TID); + List listhits = recotrackmap.get(TID); + RecoHitVector hitvec = recotrackmap.get(TID).get(0); + PadVector smallpad = params.get_padvector(hitvec.smallhit().pad()); + PadVector largepad = params.get_padvector(hitvec.largehit().pad()); + bank.setInt("trkID", row, TID); - bank.setFloat("px", row, (float) finaltrackinfomap.get(TID).get_px()/1000); - bank.setFloat("py", row, (float) finaltrackinfomap.get(TID).get_py()/1000); - bank.setFloat("pz", row, (float) finaltrackinfomap.get(TID).get_pz()/1000); - bank.setFloat("vz", row, (float) finaltrackinfomap.get(TID).get_vz()/10); - bank.setFloat("theta", row, (float) finaltrackinfomap.get(TID).get_theta()); - bank.setFloat("phi", row, (float) finaltrackinfomap.get(TID).get_phi()); - bank.setInt("nhits", row, finaltrackinfomap.get(TID).get_numhits()); - bank.setFloat("path", row, (float) finaltrackinfomap.get(TID).get_tl()); - bank.setFloat("dedx", row, (float) finaltrackinfomap.get(TID).get_dEdx()); + bank.setFloat("px", row, (float) track.get_px()/1000); + bank.setFloat("py", row, (float) track.get_py()/1000); + bank.setFloat("pz", row, (float) track.get_pz()/1000); + bank.setFloat("vz", row, (float) track.get_vz()/10); + bank.setFloat("theta", row, (float) track.get_theta()); + bank.setFloat("phi", row, (float) track.get_phi()); + bank.setInt("nhits", row, track.get_numhits()); + bank.setFloat("path", row, (float) track.get_tl()); + bank.setFloat("adcsum", row, (float) track.get_ADCsum()); + bank.setFloat("dedx", row, (float) track.get_dEdx()); + bank.setFloat("r_helix", row, (float) track.get_R()); + bank.setFloat("x_helix", row, (float) track.get_A()); + bank.setFloat("y_helix", row, (float) track.get_B()); + bank.setFloat("chi2_helix", row, (float) track.get_chi2()); + bank.setFloat("min_row", row, (float) smallpad.row()); + bank.setFloat("min_col", row, (float) smallpad.col()); + bank.setFloat("max_row", row, (float) largepad.row()); + bank.setFloat("max_col", row, (float) largepad.col()); + bank.setFloat("min_time", row, (float) hitvec.smallhit().time()); + bank.setFloat("max_time", row, (float) hitvec.largehit().time()); + bank.setFloat("min_radius", row, (float) listhits.get(listhits.size()-1).r()); + bank.setFloat("max_radius", row, (float) listhits.get(0).r()); + bank.setFloat("min_phi", row, (float) listhits.get(listhits.size()-1).phi()); + bank.setFloat("max_phi", row, (float) listhits.get(0).phi()); row++; - //bank.show(); } - + //bank.show(); return bank; } } \ No newline at end of file diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/FinalTrackInfo.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/FinalTrackInfo.java index 6bcefff4d8..ee351e37da 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/FinalTrackInfo.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/FinalTrackInfo.java @@ -20,10 +20,15 @@ public class FinalTrackInfo { private double _theta; private double _phi; private int _numhits; + private double _R; + private double _A; + private double _B; + private double _chi2; + private double _ADCsum; public FinalTrackInfo(){} - public FinalTrackInfo(double px, double py, double pz, double vz, double theta, double phi, int numhits, double tl, double dEdx){ + public FinalTrackInfo(double px, double py, double pz, double vz, double theta, double phi, int numhits, double tl, double ADCsum, double dEdx, double R, double A, double B, double chi2){ _px = px; _py = py; _pz = pz; @@ -33,6 +38,11 @@ public FinalTrackInfo(double px, double py, double pz, double vz, double theta, _numhits = numhits; _tl = tl; _dEdx = dEdx; + _R = R; + _A = A; + _B = B; + _chi2 = chi2; + _ADCsum = ADCsum; } public void set_px(double px){ @@ -90,4 +100,19 @@ public double get_dEdx(){ public double get_vz(){ return _vz; } + public double get_R(){ + return _R; + } + public double get_A(){ + return _A; + } + public double get_B(){ + return _B; + } + public double get_chi2(){ + return _chi2; + } + public double get_ADCsum(){ + return _ADCsum; + } } diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitJava.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitJava.java index dae3fa71e0..fd551d6ebd 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitJava.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitJava.java @@ -820,23 +820,27 @@ C TAN(LAMBDA) {=DZ/DS}TAN(ANGLE TO X,Y PLANE) } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ - HelixFitObject HelixFit(int PointNum, double szPos[][], int fit_track_to_beamline )// double R, double A, double B, + HelixFitObject HelixFit(int PointNum, double szPos[][], int fit_track_to_beamline)// double R, double A, double B, //double Phi_deg, double Theta_deg, double Z0, int fit_track_to_beamline ) { double PI=Math.acos(0.0)*2; //double Rho=0,Phi=0,Theta=0,X0=0,Y0=0,DCA=0,Chi2=0; - double R; double Phi_deg; double Theta_deg; HelixFitObject h = helix_fit(PointNum, szPos, fit_track_to_beamline); - R=Math.abs(h.get_Rho()); - Phi_deg=h.get_Phi()*180./PI; - Theta_deg=h.get_Theta()*180./PI; - h.set_Rho(R); + Phi_deg=Math.toDegrees(h.get_Phi()); + if(Phi_deg >= 180){ + Phi_deg -= 360; + } + if(Phi_deg < -180){ + Phi_deg += 360; + } + Theta_deg=Math.toDegrees(h.get_Theta()); h.set_Phi(Phi_deg); h.set_Theta(Theta_deg); + //System.out.println("DOCA " + h.get_DCA()); return h; diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitObject.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitObject.java index 75994841f3..048f4cd94f 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitObject.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitObject.java @@ -20,6 +20,7 @@ public class HelixFitObject { private double _Z0; private double _DCA; private double _Chi2; + private double _magfield; public HelixFitObject(){ //default constructor @@ -36,6 +37,7 @@ public HelixFitObject(double Rho, double A, double B, double Phi, double Theta, _Z0 = Z0; _DCA = DCA; _Chi2 = Chi2; + _magfield = 50; } public double get_Rho(){ return _Rho; @@ -86,16 +88,16 @@ public double get_Chi2(){ return _Chi2; } public double get_Mom(){ - return 0.3*50*get_Rho()/10; + return 0.3*_magfield*Math.abs(_Rho)/(10*Math.sin(Math.toRadians(_Theta))); } public double get_px(){ - return get_Mom()*Math.cos(get_Phi())*Math.sin(get_Theta()); + return get_Mom()*Math.cos(Math.toRadians(_Phi))*Math.sin(Math.toRadians(_Theta)); } public double get_py(){ - return get_Mom()*Math.sin(get_Phi())*Math.sin(get_Theta()); + return get_Mom()*Math.sin(Math.toRadians(_Phi))*Math.sin(Math.toRadians(_Theta)); } public double get_pz(){ - return get_Mom()*Math.cos(get_Theta()); + return get_Mom()*Math.cos(Math.toRadians(_Theta)); } public double get_trackl(){ return 0; @@ -103,5 +105,8 @@ public double get_trackl(){ public double get_dEdx(){ return 0; } + public void set_magfield(double magfield){ + _magfield = magfield; + } } \ No newline at end of file diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitTest.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitTest.java index f227a1c89e..f8b3112887 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitTest.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HelixFitTest.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.List; +import java.util.ArrayList; import org.jlab.clas.physics.Vector3; /** @@ -14,43 +15,119 @@ * @author davidpayette */ public class HelixFitTest { - public HelixFitTest(HitParameters params, int fitToBeamline){ - HashMap> recotrackmap = params.get_recotrackmap(); - HashMap finaltrackinfomap = new HashMap<>(); - double szpos[][] = new double[10000][3]; - int hit = 0; + private double chi2termthreshold = 20; + private double chi2percthreshold = 50; + private double szpos[][]; + private int fittobeamline = 0; + private double magfield = 0; + private int minhitcount = 5; + private HashMap> recotrackmap = new HashMap<>(); + private HashMap> newrecotrackmap = new HashMap<>(); + private HashMap finaltrackinfomap = new HashMap<>(); + private boolean cosmic = false; + public HelixFitTest(HitParameters params, int fitToBeamline, double _magfield, boolean cosm){ + magfield = _magfield; + fittobeamline = fitToBeamline; + recotrackmap = params.get_recotrackmap(); + minhitcount = params.get_minhitspertrackreco(); + List trackstoremove = new ArrayList<>(); + cosmic = cosm; + chi2termthreshold = params.get_chi2termthreshold(); + chi2percthreshold = params.get_chi2percthreshold(); for(int TID : recotrackmap.keySet()){ - int numhits = recotrackmap.get(TID).size(); - double ADCsum = 0; - for(hit = 0; hit < numhits; hit++){ - szpos[hit][0] = recotrackmap.get(TID).get(hit).x(); - szpos[hit][1] = recotrackmap.get(TID).get(hit).y(); - szpos[hit][2] = recotrackmap.get(TID).get(hit).z(); - ADCsum += recotrackmap.get(TID).get(hit).adc(); - } - HelixFitJava h = new HelixFitJava(); - HelixFitObject ho = h.HelixFit(hit,szpos,fitToBeamline); - Vector3 v1 = new Vector3(); - double dz = 0; - - dz = recotrackmap.get(TID).get(numhits-1).z() - recotrackmap.get(TID).get(0).z(); - v1 = new Vector3(recotrackmap.get(TID).get(0).x()-ho.get_A(),recotrackmap.get(TID).get(0).y()-ho.get_B(),0); - Vector3 v2 = new Vector3(recotrackmap.get(TID).get(numhits-1).x()-ho.get_A(),recotrackmap.get(TID).get(numhits-1).y()-ho.get_B(),0); - double psi = Math.toRadians(v1.theta(v2)); //angle theta for helix - double momfit = ho.get_Mom(); - double gain = 1; - double px = ho.get_px(); - double py = ho.get_py(); - double pz = ho.get_pz(); - double vz = ho.get_Z0(); - double theta = ho.get_Theta(); - double phi = ho.get_Phi(); - double tl = 0; - if(ho.get_Rho() > 0) Math.sqrt(ho.get_Rho()*ho.get_Rho()*psi*psi + dz*dz); - double dEdx = 0; - if(tl != 0) dEdx = ADCsum/(gain*tl); - finaltrackinfomap.put(TID, new FinalTrackInfo(px,py,pz,vz,theta,phi,numhits,tl,dEdx)); + findtrackparams(TID,recotrackmap.get(TID),0); } + params.set_recotrackmap(newrecotrackmap); params.set_finaltrackinfomap(finaltrackinfomap); } + private double phichi2(double phi0, double r, double R){ + return Math.toRadians(phi0) - Math.asin(r/(2*R)); + } + private double zchi2(double z0, double theta0, double r, double R){ + R = Math.abs(R); + return z0 + 2*R*Math.asin(r/(2*R))/Math.tan(Math.toRadians(theta0)); + } + + private void findtrackparams(int TID, List track, int iter){ + szpos = new double[10000][3]; + int numhits = track.size(); + double ADCsum = 0; + int hit = 0; + for(hit = 0; hit < numhits; hit++){ + szpos[hit][0] = track.get(hit).x(); + szpos[hit][1] = track.get(hit).y(); + szpos[hit][2] = track.get(hit).z(); + ADCsum += track.get(hit).adc(); + } + HelixFitJava h = new HelixFitJava(); + HelixFitObject ho = h.HelixFit(hit,szpos,fittobeamline); + ho.set_magfield(magfield); + double dz = 0; + + dz = track.get(numhits-1).z() - track.get(0).z(); + Vector3 v1 = new Vector3(track.get(0).x()-ho.get_A(),track.get(0).y()-ho.get_B(),0); + Vector3 v2 = new Vector3(track.get(numhits-1).x()-ho.get_A(),track.get(numhits-1).y()-ho.get_B(),0); + double psi = Math.toRadians(v1.theta(v2)); //angle theta for helix + double momfit = ho.get_Mom(); + double px = ho.get_px(); + double py = ho.get_py(); + double pz = ho.get_pz(); + double vz = ho.get_Z0(); + double theta = ho.get_Theta(); + double phi = ho.get_Phi(); + double tl = 0; + double R = ho.get_Rho(); + double A = ho.get_A(); + double B = ho.get_B(); + double chi2 = 0; + double hitphi = 0; + double hitz = 0; + double hitr = 0; + double denphi = 0.0001; + double denz = 1.44; + double chi2phiterm = 0; + double chi2zterm = 0; + double chi2term = 0; + boolean removehits = false; + List hitstoremove = new ArrayList<>(); + //calculate chi2 + for(hit = 0; hit < numhits; hit++){ + hitr = track.get(hit).r(); + hitphi = track.get(hit).phi(); + hitz = track.get(hit).z(); + chi2phiterm = (hitphi - phichi2(phi,hitr,R)); + if(chi2phiterm < -Math.PI) chi2phiterm += 2*Math.PI; + else if(chi2phiterm > Math.PI) chi2phiterm -= 2*Math.PI; + chi2phiterm = chi2phiterm*chi2phiterm; + chi2phiterm /= denphi; + chi2zterm = (hitz - zchi2(vz,theta,hitr,R))*(hitz - zchi2(vz,theta,hitr,R))/denz; + chi2term = chi2phiterm + chi2zterm; + chi2 += chi2term; + if(chi2term > chi2termthreshold && iter == 0 && !cosmic) hitstoremove.add(hit); //if the hit messes up chi2 too much we are going to remove it + } + + if(hitstoremove.size() > 0 && iter == 0 && !cosmic){ //make a new track containing the hits leftover and fit it again + if(((double)hitstoremove.size()/(double)numhits) >= chi2percthreshold/100) removehits = true; + List newtrack = new ArrayList<>(); + for(int i = 0; i < numhits; i++){ + if(!hitstoremove.contains(i)) newtrack.add(track.get(i)); + } + if(!newtrack.isEmpty() && !removehits) findtrackparams(TID,newtrack,1); + return; + } + + R = Math.abs(R); + chi2 += (R-Math.sqrt(A*A + B*B))*(R-Math.sqrt(A*A + B*B)); + chi2 /= 2*numhits - 4; + + if(R > 0) tl = Math.sqrt(R*R*psi*psi + dz*dz); + double dEdx = 0; + if(Double.isNaN(tl)) tl = 0; + if(tl != 0 && !Double.isNaN(tl)) dEdx = ADCsum/tl; + if(TID != 0 && numhits > minhitcount){ + newrecotrackmap.put(TID, track); + finaltrackinfomap.put(TID, new FinalTrackInfo(px,py,pz,vz,theta,phi,numhits,tl,ADCsum,dEdx,ho.get_Rho(),A,B,chi2)); + } + + } } \ No newline at end of file diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HitParameters.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HitParameters.java index cf55027016..a67465ac34 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HitParameters.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/HitParameters.java @@ -11,7 +11,7 @@ public class HitParameters { final private int _SignalStepSize = 10; final private int _BinSize = 40; final private int _NBinKept = 3; - final private int _TrigWindSize = 10000; + private int _TrigWindSize = 9600; private int _eventnum = 0; private ADCMap _ADCMap = new ADCMap(); private HashMap> _TimeMap = new HashMap<>(); @@ -39,48 +39,72 @@ public class HitParameters { private int _timeadjlimit = 4; private double _zthreshTF = 16; private double _phithreshTF = 0.16; + private double _zthreshTFgap = 20; + private double _phithreshTFgap = 0.20; private double _zthreshTD = 8; private double _phithreshTD = 0.1; + private double _zthreshTDgap = 10; + private double _phithreshTDgap = 0.12; + private double _TFtotaltracktimeflag = 5000; + private double _TFtotalpadtimeflag = 1000; private int _tthreshTD = 300; + private int _tthreshTDgap = 300; private double _adcthresh = 320; private int _minhitspertrack = 5; - private double[] _tmaxparms = new double[5]; - private double[] _toffparms = new double[5]; + private int _minhitspertrackreco = 10; + private double[] _atparms = new double[5]; + private double[] _btparms = new double[5]; + private double[] _ctparms = new double[5]; private double[] _aphiparms = new double[5]; private double[] _bphiparms = new double[5]; - private double[] _tgapparms = new double[5]; - private double[] _phigapparms = new double[5]; + private double[] _cphiparms = new double[5]; private double _tl = 0; private double _tp = 0; private double _tr = 0; private double _tcathode = 0; + private double _tshiftfactorshort = 0; + private double _tshiftfactorlong = 0; + private double _chi2termthreshold = 20; + private double _chi2percthreshold = 50; public void init(ConstantsManager manager, int runNo){ - IndexedTable gain_balance = manager.getConstants(runNo, "/calibration/rtpc/gain_balance"); IndexedTable time_offsets = manager.getConstants(runNo, "/calibration/rtpc/time_offsets"); IndexedTable time_parms = manager.getConstants(runNo, "/calibration/rtpc/time_parms"); IndexedTable recon_parms = manager.getConstants(runNo, "/calibration/rtpc/recon_parms"); + _TrigWindSize = (int) recon_parms.getDoubleValue("Dtm", 1,1,3); + _chi2termthreshold = recon_parms.getDoubleValue("Dzm", 1,1,3); + _chi2percthreshold = recon_parms.getDoubleValue("Dphim",1,1,3); _timeadjlimit = (int) recon_parms.getDoubleValue("Dtm", 1,1,1); _zthreshTF = recon_parms.getDoubleValue("Dzm", 1,1,1); _phithreshTF = recon_parms.getDoubleValue("Dphim", 1,1,1); + _zthreshTFgap = recon_parms.getDoubleValue("Dzm", 1,1,4); + _phithreshTFgap = recon_parms.getDoubleValue("Dphim", 1,1,4); _adcthresh = recon_parms.getDoubleValue("ADCmin", 1,1,1); _minhitspertrack = (int) recon_parms.getDoubleValue("Hitmin",1,1,1); + _minhitspertrackreco = (int) recon_parms.getDoubleValue("Hitmin",1,1,2); _zthreshTD = recon_parms.getDoubleValue("Dzm", 1,1,2); _phithreshTD = recon_parms.getDoubleValue("Dphim", 1,1,2); + _zthreshTDgap = recon_parms.getDoubleValue("Dzm", 1,1,5); + _phithreshTDgap = recon_parms.getDoubleValue("Dphim", 1,1,5); + _TFtotaltracktimeflag = recon_parms.getDoubleValue("Dtm", 1,1,6); + _TFtotalpadtimeflag = recon_parms.getDoubleValue("Dtm", 1,1,7); _tthreshTD = (int) recon_parms.getDoubleValue("Dtm",1,1,2); + _tthreshTDgap = (int) recon_parms.getDoubleValue("Dtm",1,1,5); for(int i = 0; i < 5; i++){ - _tmaxparms[i] = time_parms.getDoubleValue("z"+i, 1,1,1); - _toffparms[i] = time_parms.getDoubleValue("z"+i, 1,1,2); - _aphiparms[i] = time_parms.getDoubleValue("z"+i, 1,1,3); - _bphiparms[i] = time_parms.getDoubleValue("z"+i, 1,1,4); - _tgapparms[i] = time_parms.getDoubleValue("z"+i, 1,1,5); - _phigapparms[i] = time_parms.getDoubleValue("z"+i, 1,1,6); + _atparms[i] = time_parms.getDoubleValue("z"+i, 1,1,1); + _btparms[i] = time_parms.getDoubleValue("z"+i, 1,1,2); + _ctparms[i] = time_parms.getDoubleValue("z"+i, 1,1,3); + _aphiparms[i] = time_parms.getDoubleValue("z"+i, 1,1,4); + _bphiparms[i] = time_parms.getDoubleValue("z"+i, 1,1,5); + _cphiparms[i] = time_parms.getDoubleValue("z"+i, 1,1,6); } _tl = time_offsets.getDoubleValue("tl", 1,1,3); _tp = time_offsets.getDoubleValue("tp", 1,1,3); _tr = time_offsets.getDoubleValue("tr", 1,1,3); _tcathode = time_parms.getDoubleValue("z0", 1,1,7); + _tshiftfactorshort = time_parms.getDoubleValue("z1",1,1,7); + _tshiftfactorlong = time_parms.getDoubleValue("z2",1,1,7); } public int get_SignalStepSize(){return _SignalStepSize;} // step size of the signal before integration (arbitrary value) @@ -121,19 +145,31 @@ public PadVector get_padvector(int pad) { public double get_phithreshTF(){return _phithreshTF;} public double get_zthreshTD(){return _zthreshTD;} public double get_phithreshTD(){return _phithreshTD;} + public double get_zthreshTFgap(){return _zthreshTFgap;} + public double get_phithreshTFgap(){return _phithreshTFgap;} + public double get_zthreshTDgap(){return _zthreshTDgap;} + public double get_phithreshTDgap(){return _phithreshTDgap;} public int get_tthreshTD(){return _tthreshTD;} + public int get_tthreshTDgap(){return _tthreshTDgap;} public double get_adcthresh(){return _adcthresh;} public int get_minhitspertrack(){return _minhitspertrack;} - public double[] get_tmaxparms(){return _tmaxparms;} - public double[] get_toffparms(){return _toffparms;} + public int get_minhitspertrackreco(){return _minhitspertrackreco;} + public double[] get_atparms(){return _atparms;} + public double[] get_btparms(){return _btparms;} public double[] get_aphiparms(){return _aphiparms;} public double[] get_bphiparms(){return _bphiparms;} - public double[] get_tgapparms(){return _tgapparms;} - public double[] get_phigapparms(){return _phigapparms;} + public double[] get_ctparms(){return _ctparms;} + public double[] get_cphiparms(){return _cphiparms;} public double get_tl(){return _tl;} public double get_tp(){return _tp;} public double get_tr(){return _tr;} public double get_tcathode(){return _tcathode;} + public double get_tshiftfactorshort(){return _tshiftfactorshort;} + public double get_tshiftfactorlong(){return _tshiftfactorlong;} + public double get_TFtotaltracktimeflag(){return _TFtotaltracktimeflag;} + public double get_TFtotalpadtimeflag(){return _TFtotalpadtimeflag;} + public double get_chi2termthreshold(){return _chi2termthreshold;} + public double get_chi2percthreshold(){return _chi2percthreshold;} public void set_ADCMap(ADCMap _ADCMap){this._ADCMap = _ADCMap;} public void set_TimeMap(HashMap> _TimeMap){this._TimeMap = _TimeMap;} diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/PadVector.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/PadVector.java index a1d6963302..b875de3713 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/PadVector.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/PadVector.java @@ -25,18 +25,26 @@ public class PadVector { private double z_pad; public PadVector(int padnum){ - chan = (double)padnum; + chan = padnum; col = (chan-1)%Num_of_Cols+1; - row=(chan-col)/Num_of_Cols; - z_shift = row%4; + row=(chan-col)/Num_of_Cols+1; + z_shift = (row-1)%4; - phi_pad=(row*phi_per_pad)+(phi_per_pad/2.0); + /*phi_pad=((row-1)*phi_per_pad)+(phi_per_pad/2.0); if(phi_pad>= 2.0*PI) { phi_pad -= 2.0*PI; } if(phi_pad<0){ phi_pad += 2.0*PI; + }*/ + phi_pad = Math.toRadians((row-1)*2 + 1); + + if(phi_pad >= PI) { + phi_pad -= 2.0*PI; + } + if(phi_pad < -PI){ + phi_pad += 2.0*PI; } z_pad=z0+((col-1)*PAD_L)+(PAD_L/2.0)+z_shift; @@ -47,7 +55,12 @@ public PadVector(int padnum){ z_pad); } - + public double row(){ + return row; + } + public double col(){ + return col; + } public double x(){ return _vec.x(); } @@ -59,6 +72,10 @@ public double y(){ public double z(){ return _vec.z(); } + + public double r(){ + return _vec.rho(); + } public double phi(){ return _vec.phi(); diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/RecoHitVector.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/RecoHitVector.java index 8a279cd02c..81e35302b4 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/RecoHitVector.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/RecoHitVector.java @@ -9,6 +9,11 @@ public class RecoHitVector { private double dt; private double time; private double _adc; + private HitVector _smallhit; + private HitVector _largehit; + private double _r; + private double _phi; + public RecoHitVector() { @@ -21,7 +26,7 @@ public RecoHitVector() _adc = 0; } - public RecoHitVector(int padnum, double xrec, double yrec, double zrec, double tdiff, double t, double adc) + public RecoHitVector(int padnum, double xrec, double yrec, double zrec, double rrec, double phirec, double tdiff, double t, double adc, HitVector smallhit, HitVector largehit) { pad = padnum; x = xrec; @@ -30,6 +35,11 @@ public RecoHitVector(int padnum, double xrec, double yrec, double zrec, double t dt = tdiff; time = t; _adc = adc; + _smallhit = smallhit; + _largehit = largehit; + _r = rrec; + _phi = phirec; + } public void setpad(int padnum) @@ -95,6 +105,21 @@ public double dt() public double adc(){ return _adc; } - + + public double r(){ + return _r; + } + + public double phi(){ + return _phi; + } + + public HitVector smallhit(){ + return _smallhit; + } + + public HitVector largehit(){ + return _largehit; + } } diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/ReducedTrack.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/ReducedTrack.java index 1182359d2c..dedb9e393c 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/ReducedTrack.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/ReducedTrack.java @@ -10,56 +10,81 @@ public class ReducedTrack { - private List _hits = new ArrayList(); - private boolean _flagTrack = false; - - public ReducedTrack() { - //Default Constructor - } - - public void addHit(HitVector v) { - _hits.add(v); - } - - public void sortHits() { - Collections.sort(_hits, new Comparator() { - @Override - public int compare(HitVector v1, HitVector v2) { - return Double.compare(v2.time(),v1.time()); - } - }); - } - - public double getSmallT() { - return _hits.get(_hits.size()-1).time(); - } - - public double getLargeT() { - return _hits.get(0).time(); - } - - public Set getAllPads() { - Set pads = new HashSet(); - for(HitVector v : _hits) { - pads.add(v.pad()); - } - return pads; - } - - public List getAllHits() { - return _hits; - } - - public void flagTrack() { - _flagTrack = true; - } - - public boolean isTrackFlagged() { - return _flagTrack; - } - - public HitVector getLastHit(){ - return _hits.get(_hits.size()-1); + private List _hits = new ArrayList(); + private boolean _flagTrack = false; + + public ReducedTrack() { + //Default Constructor + } + + public void addHit(HitVector v) { + _hits.add(v); + } + + public void sortHits() { + Collections.sort(_hits, new Comparator() { + @Override + public int compare(HitVector v1, HitVector v2) { + return Double.compare(v2.time(),v1.time()); + } + }); + } + + public double getSmallT() { + return _hits.get(_hits.size()-1).time(); + } + + public double getLargeT() { + return _hits.get(0).time(); + } + + public HitVector getSmallTHit(){ + return _hits.get(_hits.size()-1); + } + + public HitVector getLargeTHit(){ + return _hits.get(0); + } + + public Set getAllPads() { + Set pads = new HashSet(); + for(HitVector v : _hits) { + pads.add(v.pad()); + } + return pads; + } + + public List getAllHits() { + return _hits; + } + + public void flagTrack() { + _flagTrack = true; + } + + public boolean isTrackFlagged() { + return _flagTrack; + } + + public HitVector getLastHit(){ + return _hits.get(_hits.size()-1); + } + + public List getLastNHits(int N){ + List l = new ArrayList<>(); + if(N > _hits.size()) N = _hits.size(); + for(int i = _hits.size()-N; i < _hits.size(); i++){ + l.add(_hits.get(i)); + } + return l; + } + + public List getFirstNHits(int N){ + List l = new ArrayList<>(); + if(N > _hits.size()) N = _hits.size(); + for(int i = 0; i < N; i++){ + l.add(_hits.get(i)); } - + return l; + } } diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TimeAverage.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TimeAverage.java index a045ad3f17..346bd02c2e 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TimeAverage.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TimeAverage.java @@ -14,6 +14,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.jlab.detector.calib.utils.ConstantsManager; +import org.jlab.utils.groups.IndexedTable; public class TimeAverage { @@ -30,15 +32,21 @@ public class TimeAverage { private double adcthresh = 0; private double sumnum = 0; private double sumden = 0; + private double gain = 1; + private int row = 0; + private int col = 0; + private double TFtotaltracktimeflag = 5000; + - public TimeAverage(HitParameters params) { + public TimeAverage(ConstantsManager manager, HitParameters params, int runNo) { /* *Initializations */ TIDMap = params.get_trackmap(); ADCMap = params.get_ADCMap(); tids = TIDMap.getAllTrackIDs(); - + IndexedTable gains = manager.getConstants(runNo, "/calibration/rtpc/gain_balance"); + TFtotaltracktimeflag = params.get_TFtotaltracktimeflag(); /* * Main Algorithm @@ -64,7 +72,7 @@ public TimeAverage(HitParameters params) { } } - adcthresh = adcmax/2; + adcthresh = adcmax/4; for(int time : timesbypad) { //Loop to calculate weighted average time using ADC values which are above half of the maximum adc = ADCMap.getADC(pad,time); if(adc > adcthresh) { @@ -74,9 +82,15 @@ public TimeAverage(HitParameters params) { } averagetime = sumnum/sumden; PadVector p = params.get_padvector(pad); - HitVector v = new HitVector(pad,p.z(),p.phi(),averagetime,sumden); + + gain = gains.getDoubleValue("gain", 1,(int)p.row(),(int)p.col()); + //System.out.println("gain" + (int)p.col() + " " + (int)p.row() + " " + gain); + if(gain == 0) gain = 1; + HitVector v = new HitVector(pad,p.z(),p.phi(),averagetime,sumden/gain); rtrack.addHit(v); } + rtrack.sortHits(); + if(Math.abs(rtrack.getLargeT()-rtrack.getSmallT()) < TFtotaltracktimeflag) rtrack.flagTrack(); RTIDMap.addTrack(rtrack); } @@ -85,5 +99,5 @@ public TimeAverage(HitParameters params) { */ params.set_rtrackmap(RTIDMap); - } + } } diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackDisentangler.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackDisentangler.java index dea886a1b7..3104d80812 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackDisentangler.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackDisentangler.java @@ -17,52 +17,69 @@ public class TrackDisentangler { private ReducedTrackMap NewTrackMap = new ReducedTrackMap(); private ReducedTrack rtrack; private int maxdeltat = 300; + private int maxdeltatgap = 300; private double maxdeltaz = 8; private double maxdeltaphi = 0.10; + private double maxdeltazgap = 10; + private double maxdeltaphigap = 0.12; - public TrackDisentangler(HitParameters params){ + public TrackDisentangler(HitParameters params, boolean disentangle){ - RTIDMap = params.get_rtrackmap(); - maxdeltat = params.get_tthreshTD(); - maxdeltaz = params.get_zthreshTD(); - maxdeltaphi = params.get_phithreshTD(); - - List origtidlist = RTIDMap.getAllTrackIDs(); - for(int tid : origtidlist){ - rtrack = RTIDMap.getTrack(tid); - if(rtrack.isTrackFlagged()){ - NewTrackMap = new ReducedTrackMap(); - rtrack.sortHits(); - List hits = rtrack.getAllHits(); - for(HitVector hit : hits){ - sortHit(hit); - } - List newtidlist = NewTrackMap.getAllTrackIDs(); - List removedtracks = new ArrayList<>(); - for(int tid1 : newtidlist){ - for(int tid2 : newtidlist){ - if(tid1 != tid2 && !removedtracks.contains(tid1) && !removedtracks.contains(tid2)){ - ReducedTrack t1 = NewTrackMap.getTrack(tid1); - ReducedTrack t2 = NewTrackMap.getTrack(tid2); - HitVector h1 = t1.getLastHit(); - HitVector h2 = t2.getLastHit(); - if(Math.abs(h1.z() - h2.z()) < maxdeltaz && - (Math.abs(h1.phi() - h2.phi()) < maxdeltaphi || Math.abs(h1.phi() - h2.phi() - 2*Math.PI) < maxdeltaphi)){ - NewTrackMap.mergeTracks(tid1, tid2); - NewTrackMap.getTrack(tid1).sortHits(); - removedtracks.add(tid2); + if(disentangle){ + RTIDMap = params.get_rtrackmap(); + maxdeltat = params.get_tthreshTD(); + maxdeltatgap = params.get_tthreshTDgap(); + maxdeltaz = params.get_zthreshTD(); + maxdeltaphi = params.get_phithreshTD(); + maxdeltazgap = params.get_zthreshTDgap(); + maxdeltaphigap = params.get_phithreshTDgap(); + + List origtidlist = RTIDMap.getAllTrackIDs(); + for(int tid : origtidlist){ + rtrack = RTIDMap.getTrack(tid); + if(rtrack.isTrackFlagged()){ + NewTrackMap = new ReducedTrackMap(); + rtrack.sortHits(); + List hits = rtrack.getAllHits(); + for(HitVector hit : hits){ + sortHit(hit); + } + List newtidlist = NewTrackMap.getAllTrackIDs(); + List removedtracks = new ArrayList<>(); + for(int tid1 : newtidlist){ + for(int tid2 : newtidlist){ + if(tid1 != tid2 && !removedtracks.contains(tid1) && !removedtracks.contains(tid2)){ + ReducedTrack t1 = NewTrackMap.getTrack(tid1); + ReducedTrack t2 = NewTrackMap.getTrack(tid2); + List h1list = new ArrayList<>(); + List h2list = new ArrayList<>(); + h1list.addAll(t1.getFirstNHits(2)); + h1list.addAll(t1.getLastNHits(2)); + h2list.addAll(t2.getFirstNHits(2)); + h2list.addAll(t2.getLastNHits(2)); + HITSLOOP: + for(HitVector h1 : h1list){ + for(HitVector h2 : h2list){ + if(compareHits(h1,h2)){ + NewTrackMap.mergeTracks(tid1, tid2); + NewTrackMap.getTrack(tid1).sortHits(); + removedtracks.add(tid2); + break HITSLOOP; + } + } + } } } } - } - RTIDMap.removeTrack(tid); - newtidlist = NewTrackMap.getAllTrackIDs(); - for(int tidfinal : newtidlist){ - RTIDMap.addTrack(NewTrackMap.getTrack(tidfinal)); + RTIDMap.removeTrack(tid); + newtidlist = NewTrackMap.getAllTrackIDs(); + for(int tidfinal : newtidlist){ + RTIDMap.addTrack(NewTrackMap.getTrack(tidfinal)); + } } } + params.set_rtrackmap(RTIDMap); } - params.set_rtrackmap(RTIDMap); } @@ -73,13 +90,10 @@ private void sortHit(HitVector hit){ for(int tid : TIDList){ ReducedTrack t = NewTrackMap.getTrack(tid); HitVector comphit = t.getLastHit(); - if(comphit.time() - hit.time() < maxdeltat && - hit.time() < comphit.time() && - Math.abs(hit.z() - comphit.z()) < maxdeltaz && - (Math.abs(hit.phi() - comphit.phi()) < maxdeltaphi || Math.abs(hit.phi() - comphit.phi() - Math.PI * 2) < maxdeltaphi)){ + if(compareHitsTime(hit,comphit)){ t.addHit(hit); hitsorted = true; - } + } } if(!hitsorted){ ReducedTrack newt = new ReducedTrack(); @@ -87,5 +101,27 @@ private void sortHit(HitVector hit){ NewTrackMap.addTrack(newt); } } + + private boolean compareHits(HitVector a, HitVector b){ + double zdiff = a.z() - b.z(); + double phidiff = Math.abs(a.phi() - b.phi()); + if(phidiff > Math.PI){ + return Math.abs(phidiff - 2*Math.PI) < maxdeltaphigap && zdiff < maxdeltazgap; + }else{ + return phidiff < maxdeltaphi && zdiff < maxdeltaz; + } + } + + private boolean compareHitsTime(HitVector a, HitVector b){ + double zdiff = a.z() - b.z(); + double phidiff = Math.abs(a.phi() - b.phi()); + boolean torder = false; + if(a.time() < b.time()) torder = true; + if(phidiff > Math.PI){ + return b.time() - a.time() < maxdeltatgap && torder && Math.abs(phidiff - 2*Math.PI) < maxdeltaphigap && zdiff < maxdeltazgap; + }else{ + return b.time() - a.time() < maxdeltat && torder && phidiff < maxdeltaphi && zdiff < maxdeltaz; + } + } } diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackFinder.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackFinder.java index 599b7f9dde..363ce8190d 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackFinder.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackFinder.java @@ -7,6 +7,7 @@ package org.jlab.rec.rtpc.hit; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Set; @@ -23,7 +24,7 @@ public class TrackFinder { private List PadList; private int TrigWindSize; private int StepSize = 120;//Bin Size of Dream Electronics Output - private double adcthresh = 1e-6; + private double adcthresh = 0; private int padloopsize;// = PadList.size(); private boolean padSorted = false; private List padTIDlist = new ArrayList<>(); @@ -36,6 +37,11 @@ public class TrackFinder { private int minhitcount = 5; private double zthresh = 16; private double phithresh = 0.16; + private double zthreshgap = 20; + private double phithreshgap = 0.20; + private double TFtotaltracktimeflag = 5000; + private double TFtotalpadtimeflag = 1000; + public TrackFinder(HitParameters params, boolean cosmic) { /* @@ -46,8 +52,12 @@ public TrackFinder(HitParameters params, boolean cosmic) { minhitcount = params.get_minhitspertrack(); zthresh = params.get_zthreshTF(); phithresh = params.get_phithreshTF(); + zthreshgap = params.get_zthreshTFgap(); + phithreshgap = params.get_phithreshTFgap(); ADCMap = params.get_ADCMap(); PadList = params.get_PadList(); + TFtotaltracktimeflag = params.get_TFtotaltracktimeflag(); + TFtotalpadtimeflag = params.get_TFtotalpadtimeflag(); TrigWindSize = params.get_TrigWindSize(); padloopsize = PadList.size(); @@ -83,7 +93,7 @@ public TrackFinder(HitParameters params, boolean cosmic) { PADCHECKLOOP: //Loop over pads for(int checkpad : padlist) { PadVector checkpadvec = params.get_padvector(checkpad); - if(tutil.comparePads(PadVec, checkpadvec, method, cosmic, zthresh, phithresh)) { //compares the position of two pads + if(tutil.comparePads(PadVec, checkpadvec, method, cosmic, zthresh, zthreshgap, phithresh, phithreshgap)) { //compares the position of two pads track.addPad(time, pad); //assign pad to track padSorted = true; //flag set padTIDlist.add(tid); //track the TID assigned @@ -150,11 +160,14 @@ public TrackFinder(HitParameters params, boolean cosmic) { if(time > tmax) tmax = time; if(time < tmin) tmin = time; } - if(tmax - tmin > 1000){ + if(tmax - tmin > TFtotalpadtimeflag){ t.flagTrack(); break; } } + List times = t.getAllTimeSlices(); + Collections.sort(times); + if(times.get(times.size()-1) - times.get(0) > TFtotaltracktimeflag) t.flagTrack(); } } diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackHitReco.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackHitReco.java index 2c4999876a..01c897123b 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackHitReco.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackHitReco.java @@ -8,7 +8,6 @@ package org.jlab.rec.rtpc.hit; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -58,7 +57,13 @@ public class TrackHitReco { private double larget; private double smallt; + private HitVector smallthit; + private HitVector largethit; + private PadVector smalltpadvec; + private PadVector largetpadvec; private double tcathode; + private double tdiffshort; + private double tdifflong; private double tdiff; private double Time; private int cellID; @@ -70,35 +75,46 @@ public class TrackHitReco { private double x_rec; private double y_rec; - private double[] t_offset = new double[5]; - private double toffset = 0; - private double[] t_max = new double[5]; - private double tmax = 0; + private double[] a_t = new double[5]; + private double at = 0; + private double[] b_t = new double[5]; + private double bt = 0; private double[] a_phi = new double[5]; private double aphi = 0; private double bphi = 0; private double[] b_phi = new double[5]; - private double[] phi_gap = new double[5]; - private double phigap = 0; + private double[] c_phi = new double[5]; + private double[] c_t = new double[5]; + private double ct = 0; + private double cphi = 0; private double tl = 0; private double tp = 0; private double tr = 0; - + private double tshiftfactorshort = 1; + private double tshiftfactorlong = 0; + private int smalltpad; + private int largetpad; + private int minhitcount = 5; private boolean _cosmic = false; - public TrackHitReco(HitParameters params, List rawHits, boolean cosmic) { - + public TrackHitReco(HitParameters params, List rawHits, boolean cosmic, double magfield){ + _cosmic = cosmic; - t_offset = params.get_toffparms(); - t_max = params.get_tmaxparms(); + a_t = params.get_atparms(); + b_t = params.get_btparms(); a_phi = params.get_aphiparms(); b_phi = params.get_bphiparms(); - phi_gap = params.get_phigapparms(); + c_phi = params.get_cphiparms(); + c_t = params.get_ctparms(); tl = params.get_tl(); tp = params.get_tp(); tr = params.get_tr(); tcathode = params.get_tcathode(); + tshiftfactorshort = params.get_tshiftfactorshort(); + tshiftfactorlong = params.get_tshiftfactorlong(); + minhitcount = params.get_minhitspertrackreco(); + HashMap> recotrackmap = new HashMap<>(); ReducedTrackMap RTIDMap = params.get_rtrackmap(); List tids = RTIDMap.getAllTrackIDs(); @@ -106,40 +122,50 @@ public TrackHitReco(HitParameters params, List rawHits, boolean cosmic) { for(int TID : tids) { double adc = 0; ReducedTrack track = RTIDMap.getTrack(TID); + List allhits = track.getAllHits(); + if(allhits.size() < minhitcount) continue; track.sortHits(); - smallt = track.getSmallT(); - larget = track.getLargeT(); - - tdiff = tcathode - larget; + smallthit = track.getSmallTHit(); + largethit = track.getLargeTHit(); + smallt = smallthit.time(); + larget = largethit.time(); + largetpad = largethit.pad(); + tdiffshort = tcathode - smallt; + tdifflong = tcathode - larget; + tdiffshort *= tshiftfactorshort; + tdifflong *= tshiftfactorlong; + tdiff = tdiffshort + tdifflong; recotrackmap.put(TID, new ArrayList<>()); - List allhits = track.getAllHits(); for(HitVector hit : allhits) { adc += hit.adc(); cellID = hit.pad(); Time = hit.time(); - if(!cosmic) Time += tdiff; + if(!cosmic){ + Time += tdiff; + } // find reconstructed position of ionization from Time info drifttime = Time; r_rec = get_r_rec(hit.z(),drifttime); //in mm - dphi = get_dphi(hit.z(),r_rec); // in rad + dphi = get_dphi(hit.z(),r_rec,magfield); // in rad phi_rec=hit.phi()-dphi; if(cosmic) phi_rec = hit.phi(); - if(phi_rec<0.0) { + if(phi_rec<-Math.PI) { phi_rec+=2.0*Math.PI; } - if(phi_rec>2.0*Math.PI){ + if(phi_rec>Math.PI){ phi_rec-=2.0*Math.PI; } // x,y,z pos of reconstructed track x_rec=r_rec*(Math.cos(phi_rec)); y_rec=r_rec*(Math.sin(phi_rec)); - - recotrackmap.get(TID).add(new RecoHitVector(cellID,x_rec,y_rec,hit.z(),tdiff,Time,hit.adc())); + if(!Double.isNaN(x_rec) && !Double.isNaN(y_rec) && !Double.isNaN(hit.z())){ + recotrackmap.get(TID).add(new RecoHitVector(cellID,x_rec,y_rec,hit.z(),r_rec,phi_rec,tdiff,Time,hit.adc(),smallthit,largethit)); + } } } @@ -147,21 +173,26 @@ public TrackHitReco(HitParameters params, List rawHits, boolean cosmic) { } private double get_rec_coef(double[] parms, double z2) { - double z = z2/1000; + double z = z2/10; return parms[4]*z*z*z*z + parms[3]*z*z*z + parms[2]*z*z + parms[1]*z + parms[0]; } private double get_r_rec(double z,double t){ - toffset = get_rec_coef(t_offset,z) + tl + tp + tr; - tmax = get_rec_coef(t_max,z); - return Math.sqrt((70*70*(1-((t-toffset)/tmax)))+(30*30*((t-toffset)/tmax))); + at = get_rec_coef(a_t,z) + tl + tp + tr; + bt = get_rec_coef(b_t,z); + ct = 100*get_rec_coef(c_t,z); + double x = (t-at)/bt; + double rmax = 70; + double rmin = 30; + return Math.sqrt(rmax*rmax*(1-x) + rmin*rmin*x + ct*(1-x)*x); } - private double get_dphi(double z, double r){ + private double get_dphi(double z, double r, double magfield){ aphi = get_rec_coef(a_phi,z); bphi = get_rec_coef(b_phi,z); - phigap = get_rec_coef(phi_gap,z); - return aphi*(7-r/10)+bphi*(7-r/10)*(7-r/10) + phigap; // in rad + cphi = get_rec_coef(c_phi,z); + //return aphi*(7-r/10)+bphi*(7-r/10)*(7-r/10) + phigap; // in rad + return aphi + bphi * Math.log(70/r) + 100*cphi*((1/(r*r))-(1/(70*70))); } diff --git a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackUtils.java b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackUtils.java index b71efe2801..d38c8a6bd9 100644 --- a/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackUtils.java +++ b/reconstruction/rtpc/src/main/java/org/jlab/rec/rtpc/hit/TrackUtils.java @@ -8,16 +8,22 @@ public class TrackUtils { //private double zthresh = 16; private double zthresh = 200; private double phithresh = 7; + private double zthreshgap = 20; + private double phithreshgap = 0.20; public TrackUtils() {} - public boolean comparePads(PadVector p1, PadVector p2, String Method, boolean cosmic, double dz, double dphi) { + public boolean comparePads(PadVector p1, PadVector p2, String Method, boolean cosmic, double dz, double dzgap, double dphi, double dphigap) { if(cosmic){ zthresh = 200; - phithresh = 7; + phithresh = 7; + zthreshgap = zthresh; + phithreshgap = phithresh; }else{ zthresh = dz; phithresh = dphi; + zthreshgap = dzgap; + phithreshgap = dphigap; } if(Method == "ellipse") {return ellipseMethod(p1, p2);} if(Method == "phiz") {return phizMethod(p1,p2);} @@ -44,10 +50,15 @@ private boolean phizMethod(PadVector p1, PadVector p2) { double p2phi = p2.phi(); double p1z = p1.z(); double p2z = p2.z(); - double phidiff = p2phi-p1phi; + double phidiff = Math.abs(p2phi-p1phi); double zdiff = Math.abs(p1z-p2z); //System.out.println(p1phi + " " + p2phi + " " + (p1phi - p2phi)); - return ((Math.abs(phidiff) eventselect) break; eventcount ++; } - + writer.close(); */ System.out.println("finished " + (System.nanoTime() - starttime)*Math.pow(10,-9)); } -} +} \ No newline at end of file From 327149509d0a389ba08410299d585c2e62557c48 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Mon, 5 Oct 2020 14:33:26 -0400 Subject: [PATCH 19/21] Return for tracks not swimmable to HTCC sphere. (#583) Set fail flag for track not swimmable to reference surfaces used for EB matching to detectors. Pass only tracks with on-fail flag. --- .../rec/dc/track/TrackCandListFinder.java | 33 ++++++++++++------- .../java/org/jlab/service/dc/DCTBEngine.java | 2 ++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/reconstruction/dc/src/main/java/org/jlab/rec/dc/track/TrackCandListFinder.java b/reconstruction/dc/src/main/java/org/jlab/rec/dc/track/TrackCandListFinder.java index 73df657bbd..f5756b3178 100755 --- a/reconstruction/dc/src/main/java/org/jlab/rec/dc/track/TrackCandListFinder.java +++ b/reconstruction/dc/src/main/java/org/jlab/rec/dc/track/TrackCandListFinder.java @@ -462,9 +462,10 @@ public void setTrackPars(Track cand, // swimming to a ref points outside of the last DC region double[] VecAtTarOut = dcSwim.SwimToPlaneTiltSecSys(cand.get(0).get_Sector(), 592); - if(VecAtTarOut==null) + if(VecAtTarOut==null) { + cand.fit_Successful = false; return; - + } double xOuter = VecAtTarOut[0]; double yOuter = VecAtTarOut[1]; double zOuter = VecAtTarOut[2]; @@ -523,8 +524,10 @@ public void setTrackPars(Track cand, double[] Vt = dcSwim.SwimToBeamLine(xB, yB); - if(Vt==null) + if(Vt==null) { + cand.fit_Successful = false; return; + } // recalc new vertex using plane stopper //int sector = cand.get(2).get_Sector(); @@ -560,6 +563,10 @@ public void setTrackPars(Track cand, pxOrFix, pyOrFix, pzOrFix, cand.get_Q()); double[] VecAtHtccSurf = dcSwim.SwimToSphere(175); + if(VecAtHtccSurf==null) { + cand.fit_Successful = false; + return; + } double xInner = VecAtHtccSurf[0]; double yInner = VecAtHtccSurf[1]; double zInner = VecAtHtccSurf[2]; @@ -844,15 +851,17 @@ private List findStraightTracks(CrossList crossList, DCGeant4Factory DcDe cand.set_P(1. / Math.abs(kFit.finalStateVec.Q)); cand.set_Q((int) Math.signum(kFit.finalStateVec.Q)); this.setTrackPars(cand, traj, trjFind, fn, kFit.finalStateVec.z, DcDetector, dcSwim); - // candidate parameters are set from the state vector - cand.set_FitChi2(kFit.chi2); - cand.set_FitNDF(kFit.NDF); - cand.set_FitConvergenceStatus(kFit.ConvStatus); - cand.set_Id(cands.size() + 1); - cand.set_CovMat(kFit.finalCovMat.covMat); - cand.set_Trajectory(kFit.kfStateVecsAlongTrajectory); - // add candidate to list of tracks - cands.add(cand); + if(cand.fit_Successful==true) { + // candidate parameters are set from the state vector + cand.set_FitChi2(kFit.chi2); + cand.set_FitNDF(kFit.NDF); + cand.set_FitConvergenceStatus(kFit.ConvStatus); + cand.set_Id(cands.size() + 1); + cand.set_CovMat(kFit.finalCovMat.covMat); + cand.set_Trajectory(kFit.kfStateVecsAlongTrajectory); + // add candidate to list of tracks + cands.add(cand); + } } //this.matchHits(traj.get_Trajectory(), cand, DcDetector); cands.add(cand); diff --git a/reconstruction/dc/src/main/java/org/jlab/service/dc/DCTBEngine.java b/reconstruction/dc/src/main/java/org/jlab/service/dc/DCTBEngine.java index 18259bd614..6fcf9d65fb 100755 --- a/reconstruction/dc/src/main/java/org/jlab/service/dc/DCTBEngine.java +++ b/reconstruction/dc/src/main/java/org/jlab/service/dc/DCTBEngine.java @@ -235,6 +235,8 @@ public boolean processDataEvent(DataEvent event) { trkcandFinder.setTrackPars(TrackArray[i], new Trajectory(), trjFind, fn, kFit.finalStateVec.z, dcDetector, dcSwim, beamXoffset, beamYoffset); // candidate parameters are set from the state vector + if(TrackArray[i].fit_Successful==false) + continue; TrackArray[i].set_FitChi2(kFit.chi2); TrackArray[i].set_FitNDF(kFit.NDF); TrackArray[i].set_Trajectory(kFit.kfStateVecsAlongTrajectory); From 2662e72968538c7362413ad799af5e0a9c7ca8b1 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 5 Oct 2020 21:28:32 +0200 Subject: [PATCH 20/21] version bump and RTPC banks added to predefined schemas --- common-tools/clas-analysis/pom.xml | 14 +++++++------- common-tools/clas-detector/pom.xml | 10 +++++----- common-tools/clas-geometry/pom.xml | 4 ++-- common-tools/clas-io/pom.xml | 6 +++--- common-tools/clas-jcsg/pom.xml | 8 ++++---- common-tools/clas-math/pom.xml | 4 ++-- common-tools/clas-physics/pom.xml | 4 ++-- common-tools/clas-reco/pom.xml | 14 +++++++------- common-tools/clas-utils/pom.xml | 4 ++-- common-tools/cnuphys/ced/pom.xml | 8 ++++---- common-tools/cnuphys/magfield/pom.xml | 2 +- common-tools/cnuphys/swimmer/pom.xml | 2 +- common-tools/coat-lib/deployDistribution.sh | 2 +- common-tools/coat-lib/pom.xml | 20 ++++++++++---------- common-tools/parent/pom.xml | 2 +- common-tools/pom.xml | 4 ++-- common-tools/swim-tools/pom.xml | 6 +++--- etc/bankdefs/util/bankSplit.py | 6 +++--- parent/pom.xml | 2 +- pom.xml | 4 ++-- reconstruction/band/pom.xml | 2 +- reconstruction/cnd/pom.xml | 2 +- reconstruction/cvt/pom.xml | 10 +++++----- reconstruction/dc/pom.xml | 12 ++++++------ reconstruction/eb/pom.xml | 10 +++++----- reconstruction/ec/pom.xml | 14 +++++++------- reconstruction/ft/pom.xml | 8 ++++---- reconstruction/fvt/pom.xml | 6 +++--- reconstruction/htcc/pom.xml | 8 ++++---- reconstruction/ltcc/pom.xml | 6 +++--- reconstruction/pom.xml | 4 ++-- reconstruction/rich/pom.xml | 8 ++++---- reconstruction/rtpc/pom.xml | 6 +++--- reconstruction/tof/pom.xml | 4 ++-- 34 files changed, 113 insertions(+), 113 deletions(-) diff --git a/common-tools/clas-analysis/pom.xml b/common-tools/clas-analysis/pom.xml index 891947c69b..835c0d8ab3 100644 --- a/common-tools/clas-analysis/pom.xml +++ b/common-tools/clas-analysis/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-analysis - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT @@ -30,31 +30,31 @@ org.jlab.clas clas-utils - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT org.jlab.clas clas-physics - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT org.jlab.clas clas-io - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT org.jlab.clas clas-geometry - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT org.jlab.clas clas-detector - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT diff --git a/common-tools/clas-detector/pom.xml b/common-tools/clas-detector/pom.xml index b72eee8158..a94b3c2d1e 100644 --- a/common-tools/clas-detector/pom.xml +++ b/common-tools/clas-detector/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-detector - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT @@ -30,7 +30,7 @@ org.jlab.clas clas-utils - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT @@ -42,13 +42,13 @@ org.jlab.clas clas-io - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT org.jlab.clas clas-geometry - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT diff --git a/common-tools/clas-geometry/pom.xml b/common-tools/clas-geometry/pom.xml index b3df39a866..57eb64b528 100644 --- a/common-tools/clas-geometry/pom.xml +++ b/common-tools/clas-geometry/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-geometry - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT diff --git a/common-tools/clas-io/pom.xml b/common-tools/clas-io/pom.xml index e616cb5e30..9009e5402b 100644 --- a/common-tools/clas-io/pom.xml +++ b/common-tools/clas-io/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-io - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT @@ -75,7 +75,7 @@ org.jlab.clas clas-utils - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT diff --git a/common-tools/clas-jcsg/pom.xml b/common-tools/clas-jcsg/pom.xml index c17fb5bc75..ad8b65c324 100644 --- a/common-tools/clas-jcsg/pom.xml +++ b/common-tools/clas-jcsg/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-jcsg - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT @@ -40,12 +40,12 @@ org.jlab.clas clas-geometry - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT org.jlab.clas clas-detector - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT java3d diff --git a/common-tools/clas-math/pom.xml b/common-tools/clas-math/pom.xml index 472cc44d73..2f50d65e6d 100644 --- a/common-tools/clas-math/pom.xml +++ b/common-tools/clas-math/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-math - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT diff --git a/common-tools/clas-physics/pom.xml b/common-tools/clas-physics/pom.xml index ba7b522b27..a56d1b12c3 100644 --- a/common-tools/clas-physics/pom.xml +++ b/common-tools/clas-physics/pom.xml @@ -4,7 +4,7 @@ org.jlab.clas clas-physics - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT jar @@ -23,7 +23,7 @@ org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT diff --git a/common-tools/clas-reco/pom.xml b/common-tools/clas-reco/pom.xml index 5603622df9..b6f531f5fd 100644 --- a/common-tools/clas-reco/pom.xml +++ b/common-tools/clas-reco/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-reco - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT @@ -67,7 +67,7 @@ org.jlab.clas clas-math - 6.5.9-SNAPSHOT + 6b.5.11-SNAPSHOT