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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public RICHBankBuilder() {
}
@Override
public boolean isGoodEvent(DataEvent event) {

DataBank part = event.getBank("REC::Particle");

DataBank part = event.getBank("REC::Particle");
if(part.rows()<1 ||
if(part.rows()<1 ||
part.getInt("pid", 0)!=11 ||
((int) (Math.abs(part.getShort("status", 0))/1000))!=2)
return false;
Expand All @@ -37,7 +38,8 @@ public DataBank buildCalibBank(DataEvent event) {
DataBank hits = event.getBank("RICH::Hit");
DataBank clus = event.getBank("RICH::Cluster");
DataBank phos = event.getBank("RICH::Photon");



List<Integer> goodPhotons = new ArrayList<>();
for(int i=0; i<phos.rows(); i++) {
int pid = phos.getInt("hypo_pid", i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import org.jlab.geom.prim.Point3D;

public class RICHCluster extends ArrayList<RICHHit> {
public class RICHCluster extends ArrayList<RICHHit> implements Comparable<RICHCluster> {

/**
* A cluster in the RICH consists of an array of anodes in one PMT
Expand Down Expand Up @@ -339,14 +339,31 @@ public void merge(RICHCluster clu) {

}

// ----------------
public boolean overlaps(RICHCluster clu) {
// ----------------

if (this.get(0).get_sector() != clu.get(0).get_sector() ) return false;
if (this.get(0).get_pmt() != clu.get(0).get_pmt() ) return false;

for(int i=0; i<clu.size(); i++){
RICHHit rhit = clu.get(i);
if(this.contains(rhit) || this.containsHit(rhit))
return true;
}
return false;
}

// ----------------
public boolean containsHit(RICHHit hit) {
// ----------------
// checks if the hit belongs to any nonet around its already associated hits

boolean addFlag = false;
if(this.get(0).get_sector()!=hit.get_sector())return addFlag;
if(this.get(0).get_pmt()!=hit.get_pmt())return addFlag;


for(int j = 0; j< this.size(); j++) {
double tDiff = Math.abs(hit.get_Time() - this.get(j).get_Time());
int xDiff = Math.abs(hit.get_idx() - this.get(j).get_idx());
Expand All @@ -357,24 +374,42 @@ public boolean containsHit(RICHHit hit) {
}


// ----------------
@Override
// ----------------
public int compareTo(RICHCluster ocluster) {
// ----------------
//System.out.println(" --> comp "+this.get_channel()+" "+this.get_charge()+" "+ocluster.get_channel()+" "+ocluster.get_charge());
if(this.get_charge() == ocluster.get_charge())return 0;
if(this.get_charge() > ocluster.get_charge()){
return 1;
}else{
//if(this.get_charge() == ocluster.get_charge())return 0;
//if(this.get_charge() > ocluster.get_charge()){
// return 1;
//}else{
// return -1;
//}

if(this.get(0).get_sector()!=ocluster.get(0).get_sector())
return this.get(0).get_sector()>ocluster.get(0).get_sector() ? 1 : -1;

if(this.get(0).get_pmt()!=ocluster.get(0).get_pmt())
return this.get(0).get_pmt()>ocluster.get(0).get_pmt() ? 1 : -1;

if(this.get_size() == ocluster.get_size())
return 0;
else if(this.get_size() > ocluster.get_size())
return -1;
}
else
return 1;


}


// ----------------
public void showCluster() {
// ----------------
System.out.format("Cluster ID %3d PMT %4d Siz %4d Ch %7.1f T %7.1f raw %7.1f wT %7.1f glxy %4d %4d XYZ %7.2f %7.2f %7.2f wXYZ %7.2f %7.2f %7.2f \n",
System.out.format("Cluster ID %3d sector %1d PMT %4d Siz %4d Ch %7.1f T %7.1f raw %7.1f wT %7.1f glxy %4d %4d XYZ %7.2f %7.2f %7.2f wXYZ %7.2f %7.2f %7.2f \n",
this.clusid,
this.get(0).get_sector(),
this.get(0).get_pmt(),
this.get_size(),
this.get_charge(),
Expand All @@ -383,9 +418,9 @@ public void showCluster() {
this.get_x(), this.get_y(), this.get_z(),
this.get_wx(), this.get_wy(), this.get_wz());
for(int j = 0; j< this.size(); j++) {
System.out.format(" --> hit # %3d ID %3d idxy %3d %3d dur %4d \n",
j, this.get(j).get_id(),
this.get(j).get_idx(), this.get(j).get_idy(), this.get(j).get_duration());
System.out.format(" --> hit # %3d ID %3d anode %2d idxy %3d %3d dur %4d clu %2d\n",
j, this.get(j).get_id(), this.get(j).get_anode(),
this.get(j).get_idx(), this.get(j).get_idy(), this.get(j).get_duration(), this.get(j).get_cluster());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ public boolean passHitSelection(RICHHit hit) {
}


// ----------------
@Override
// ----------------
public int compareTo(RICHHit ohit) {
// ----------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,12 @@ public ArrayList<RICHCluster> findClusters(ArrayList<RICHHit> hits) {
// ----------------

int debugMode = 0;


ArrayList<RICHCluster> allclusters = new ArrayList();
if(debugMode>=2) {
System.out.println("--------------------\n");
System.out.println("Building allclusters\n");
System.out.println("Building allclusters for event number " + richevent.get_EventID() + "\n");
System.out.println("--------------------\n");
}

Expand Down Expand Up @@ -301,12 +303,16 @@ public ArrayList<RICHCluster> findClusters(ArrayList<RICHHit> hits) {
}
}

if(debugMode>=2){
// Ordering the cluster
Collections.sort(allclusters);


if(debugMode>=2){
System.out.println("List of all Clusters");
for(int i=0; i<allclusters.size(); i++) {
allclusters.get(i).showCluster();
}
}
}

return allclusters;
}
Expand All @@ -317,54 +323,102 @@ public ArrayList<RICHCluster> selectGoodClusters(ArrayList<RICHCluster> allclust
// ----------------

int debugMode = 0;

if(debugMode>=1) {
System.out.println("--------------------\n");
System.out.println("Selecting good clusters");
System.out.println("--------------------\n");
}

ArrayList<RICHCluster> clusters = new ArrayList();
if(debugMode>=2) System.out.println("\nSelecting good clusters");
ArrayList<RICHCluster> goodclusters = new ArrayList();


int nclu = 0;
for(int i=0; i<allclusters.size(); i++) {
if(allclusters.get(i).isgoodCluster()) {
RICHCluster goodclu = allclusters.get(i);
int merge = 0 ;
for (int j=0; j<clusters.size(); j++){
if(clusters.get(j).get(0).get_pmt() == goodclu.get(0).get_pmt()){
clusters.get(j).merge(goodclu);
merge = 1;
if(debugMode>=1)System.out.format(" merge clu %d %d xyz %7.2f %7.2f %7.2f to %d %d \n",i,goodclu.get_id(),goodclu.get_x(), goodclu.get_y(), goodclu.get_z(), j,clusters.get(j).get_id());
}
}
if(merge==0){
nclu++;
goodclu.set_id(nclu);
clusters.add(goodclu);
}
}else{
// cancel hit to cluster link
RICHCluster badclu = allclusters.get(i);
for(int j = 0; j< badclu.size(); j++) {
badclu.get(j).set_cluster(0);
}
}
}
RICHCluster clu = allclusters.get(i);

if(debugMode>=1){
if (debugMode>=1) {
System.out.println(" ---> Looking at cluster " + i + " id=" + clu.get_id() + " Sector=" + clu.get(0).get_sector() + " PMT=" + clu.get(0).get_pmt() + " size=" + clu.size());
for (int k=0; k<clu.size(); k++) {
System.out.println(" k=" + k + " hit id=" + clu.get(k).get_id() + " anode " + clu.get(k).get_anode());
}
}

int merge = 0;
for (int j=0; j<clusters.size(); j++) {

if ( clusters.get(j).overlaps(clu) ) {
clusters.get(j).merge(clu);
merge = 1;

if(debugMode>=1) {
System.out.println(" merging cluster " + clu.get_id() + " to cluster " + clusters.get(j).get_id() + " newsize=" + clusters.get(j).size() );
}
}
}


if(merge==0){
nclu++;
clu.set_id(nclu);
clusters.add(clu);

if(debugMode>=1) {
System.out.println(" Creating new cluster " + clusters.get(nclu-1).get_id() + " size=" + clusters.get(nclu-1).size() );
}

}

}

/*if(debugMode>=1){
System.out.format("-------------------------\n");
System.out.format("List of selected Clusters %4d \n",clusters.size());
System.out.format("List of merged Clusters %4d \n",clusters.size());
System.out.format("-------------------------\n");
for(int i=0; i<clusters.size(); i++) {
clusters.get(i).showCluster();
}
}
}*/


/* Now selecting the good clusters */
int ngoodclu = 0;
for(int i=0; i<clusters.size(); i++) {
RICHCluster clu = clusters.get(i);
if(clu.isgoodCluster()){
if (debugMode>=1) {
System.out.println(" ---> Selecting good cluster " + i + " id=" + clu.get_id() + " Sector=" + clu.get(0).get_sector() + " PMT=" + clu.get(0).get_pmt() + " size=" + clu.size());
}

/*Collections.sort(clusters);
ngoodclu++;
clu.set_id(ngoodclu);
for (int j=0; j<clu.size(); j++) {
clu.get(j).set_cluster(ngoodclu);
}

goodclusters.add(clu);
}
else {
for (int j=0; j<clu.size(); j++) {
clu.get(j).set_cluster(0);
}

}

}

if(debugMode>=1){
System.out.println("List of sorted Clusters");
for(int i=0; i<clusters.size(); i++) {
clusters.get(i).showCluster();
System.out.format("-------------------------\n");
System.out.format("List of good Clusters %4d \n", goodclusters.size());
System.out.format("-------------------------\n");
for(int i=0; i<goodclusters.size(); i++) {
goodclusters.get(i).showCluster();
}
}*/
}


return clusters;
return goodclusters;
}


Expand All @@ -389,7 +443,7 @@ public void find_XTalk(ArrayList<RICHHit> hits, ArrayList<RICHCluster> allcluste
if(hiti.get_cluster()!=0) continue; // this hit is not yet associated with a cluster
if(debugMode==1)System.out.println("Hit pair "+ih+" "+hiti.get_id()+" "+hiti.get_pmt()+" "+hiti.get_channel()+" "+hiti.get_duration()+" "+hiti.get_cluster()+" | " +jh+" "+hitj.get_id()+" "+hitj.get_pmt()+" "+hitj.get_channel()+" "+hitj.get_duration()+" "+hitj.get_cluster());

if(hiti.get_pmt()==hitj.get_pmt() && hitj.get_duration()*100 < hiti.get_duration()*richpar.GOODHIT_FRAC){
if(hiti.get_sector()==hitj.get_sector() && hiti.get_pmt()==hitj.get_pmt() && hitj.get_duration()*100 < hiti.get_duration()*richpar.GOODHIT_FRAC){
for(int k=-1; k<=1; k+=2 ) {
if(hiti.get_channel() == (k+hitj.get_channel())) {hitj.set_xtalk(1000+hiti.get_id()+1); if(debugMode==1)System.out.println(" E Xtalk "+hitj.get_xtalk());}
}
Expand Down
Loading