Skip to content

Commit 6af74d9

Browse files
committed
use DetectorDescriptor instead of copying
1 parent 9082b50 commit 6af74d9

2 files changed

Lines changed: 56 additions & 57 deletions

File tree

‎reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java‎

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jlab.rec.cvt.hit;
22

3+
import org.jlab.detector.base.DetectorDescriptor;
34
import org.jlab.detector.base.DetectorType;
45
import org.jlab.geom.prim.Line3D;
56
import org.jlab.geom.prim.Point3D;
@@ -16,12 +17,8 @@ public class Hit implements Comparable<Hit> {
1617
// class implements Comparable interface to allow for sorting a collection of hits by wire number values
1718

1819
private int _Id; // Hit Id
19-
20-
private DetectorType _Detector; // the detector SVT or BMT
20+
private DetectorDescriptor _Descriptor;
2121
private BMTType _Type; // for the BMT, either C or Z
22-
23-
private int _Sector; // sector[1...24] for SVT, [1..3] for BMT
24-
private int _Layer; // layer [1,...]
2522
private Strip _Strip; // Strip object
2623

2724
private double _docaToTrk; // 3-D distance of closest approach of the helix to the wire
@@ -35,29 +32,38 @@ public class Hit implements Comparable<Hit> {
3532
public int MCstatus = -1;
3633
public boolean isCorrupted;
3734

38-
// constructor
39-
public Hit(DetectorType detector, BMTType type, int sector, int layer, Strip strip) {
40-
this._Detector = detector; // 0 = SVT, 1 = BMT
41-
this._Type = type; // set according to BMTType
42-
this._Sector = sector;
43-
this._Layer = layer;
35+
public Hit(DetectorDescriptor descriptor, BMTType type, Strip strip) {
36+
this._Descriptor = descriptor;
37+
this._Type = type;
4438
this._Strip = strip;
45-
39+
}
40+
41+
public Hit(DetectorType detector, BMTType type, int sector, int layer, Strip strip) {
42+
this._Descriptor = new DetectorDescriptor();
43+
this._Descriptor.setType(detector);
44+
this._Descriptor.setSector(sector);
45+
this._Descriptor.setLayer(layer);
46+
this._Type = type;
47+
this._Strip = strip;
4648
}
4749

50+
public DetectorDescriptor getDescriptor() {
51+
return _Descriptor;
52+
}
53+
4854
public DetectorType getDetector() {
49-
return _Detector;
55+
return _Descriptor.getType();
5056
}
5157

52-
public void setDetector(DetectorType _detector) {
53-
this._Detector = _detector;
58+
public final void setDetector(DetectorType _detector) {
59+
this._Descriptor.setType(_detector);
5460
}
5561

5662
public BMTType getType() {
5763
return _Type;
5864
}
5965

60-
public void setType(BMTType type) {
66+
public final void setType(BMTType type) {
6167
this._Type = type;
6268
}
6369

@@ -66,40 +72,40 @@ public void setType(BMTType type) {
6672
* @return the sector (1...24)
6773
*/
6874
public int getSector() {
69-
return _Sector;
75+
return _Descriptor.getSector();
7076
}
7177

7278
/**
7379
* Sets the sector
7480
*
7581
* @param _Sector
7682
*/
77-
public void setSector(int _Sector) {
78-
this._Sector = _Sector;
83+
public final void setSector(int _Sector) {
84+
this._Descriptor.setSector(_Sector);
7985
}
8086

8187
/**
8288
*
8389
* @return the layer (1...8)
8490
*/
8591
public int getLayer() {
86-
return _Layer;
92+
return _Descriptor.getLayer();
8793
}
8894

8995
/**
9096
* Sets the layer
9197
*
9298
* @param _Layer
9399
*/
94-
public void setLayer(int _Layer) {
95-
this._Layer = _Layer;
100+
public final void setLayer(int _Layer) {
101+
this._Descriptor.setLayer(_Layer);
96102
}
97103

98104
public Strip getStrip() {
99105
return _Strip;
100106
}
101107

102-
public void setStrip(Strip _Strip) {
108+
public final void setStrip(Strip _Strip) {
103109
this._Strip = _Strip;
104110
}
105111

@@ -116,7 +122,7 @@ public int getId() {
116122
*
117123
* @param _Id
118124
*/
119-
public void setId(int _Id) {
125+
public final void setId(int _Id) {
120126
this._Id = _Id;
121127
}
122128

@@ -125,15 +131,15 @@ public void setId(int _Id) {
125131
* @return region (1...4)
126132
*/
127133
public int getRegion() {
128-
return (int) (this._Layer + 1) / 2;
134+
return (int) (this.getLayer() + 1) / 2;
129135
}
130136

131137
/**
132138
*
133139
* @return superlayer 1 or 2 in region (1...4)
134140
*/
135141
public int getRegionSlayer() {
136-
return (this._Layer + 1) % 2 + 1;
142+
return (this.getLayer() + 1) % 2 + 1;
137143
}
138144

139145
/**

‎reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java‎

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.ArrayList;
44
import java.util.Collection;
55
import java.util.Collections;
6-
import java.util.Comparator;
76
import java.util.HashMap;
87
import java.util.List;
98
import java.util.Map;
@@ -62,7 +61,6 @@ public class Track extends Trajectory implements Comparable<Track> {
6261
private int secondaryNDF; // for track with no beamSpot information
6362
private int _status = 0;
6463

65-
6664
public Track(Helix helix) {
6765
super(helix);
6866
if (helix != null) {
@@ -97,7 +95,6 @@ public Track(Seed seed, KFitter kf) {
9795
this.setStatus(-1);
9896
}
9997
}
100-
10198

10299
public Track(Seed seed, KFitter kf, int pid) {
103100
this(seed, kf);
@@ -162,23 +159,23 @@ public Helix getSecondaryHelix() {
162159
return secondaryHelix;
163160
}
164161

165-
public void setSecondaryHelix(Helix secondaryHelix) {
162+
public final void setSecondaryHelix(Helix secondaryHelix) {
166163
this.secondaryHelix = secondaryHelix;
167164
}
168165

169166
public double getSecondaryChi2() {
170167
return secondaryChi2;
171168
}
172169

173-
public void setSecondaryChi2(double secondaryChi2) {
170+
public final void setSecondaryChi2(double secondaryChi2) {
174171
this.secondaryChi2 = secondaryChi2;
175172
}
176173

177174
public int getSecondaryNDF() {
178175
return secondaryNDF;
179176
}
180177

181-
public void setSecondaryNDF(int secondaryNDF) {
178+
public final void setSecondaryNDF(int secondaryNDF) {
182179
this.secondaryNDF = secondaryNDF;
183180
}
184181

@@ -205,8 +202,7 @@ public final void setPXYZ() {
205202
calcPt = 100;
206203
setQ(1);
207204
}
208-
double calcPz = 0;
209-
calcPz = calcPt * helix.getTanDip();
205+
double calcPz = calcPt * helix.getTanDip();
210206
double calcP = Math.sqrt(calcPt * calcPt + calcPz * calcPz);
211207
setPt(calcPt);
212208
setPz(calcPz);
@@ -217,6 +213,8 @@ public final void setPXYZ() {
217213
/**
218214
* Updates the crosses positions based on trajectories or helix
219215
* @param trackId
216+
* @param xb
217+
* @param yb
220218
*/
221219
public void update_Crosses(int trackId, double xb, double yb) {
222220
for (int i = 0; i < this.size(); i++) {
@@ -288,12 +286,7 @@ public boolean equals(Object obj) {
288286
if (getClass() != obj.getClass()) {
289287
return false;
290288
}
291-
Track other = (Track) obj;
292-
if (this.getId() != other.getId()) {
293-
return false;
294-
}
295-
296-
return true;
289+
return this.getId() == ((Track)obj).getId();
297290
}
298291

299292
@Override
@@ -328,9 +321,9 @@ else if(this.getChi2() > Constants.CHI2CUT * (this.getNDF() + 5))
328321
return false;
329322
if(this.getNDF() < Constants.NDFCUT)
330323
return false;
331-
if(this.getHelix().radius() < Constants.getInstance().getRCUT())
324+
if(this.getHelix().radius() < Constants.getRCUT())
332325
return false;
333-
if(Math.abs(Geometry.getInstance().getTargetZOffset()-this.getHelix().getZ0()) > Geometry.getInstance().getTargetHalfLength()+Constants.getInstance().getZRANGE())
326+
if(Math.abs(Geometry.getInstance().getTargetZOffset()-this.getHelix().getZ0()) > Geometry.getInstance().getTargetHalfLength()+Constants.getZRANGE())
334327
return false;
335328
else
336329
return true;
@@ -396,7 +389,7 @@ public int getPID() {
396389
return _PID;
397390
}
398391

399-
public void setPID(int _PID) {
392+
public final void setPID(int _PID) {
400393
this._PID = _PID;
401394
}
402395

@@ -445,13 +438,14 @@ public final void setKFTrajectories(Map<Integer, HitOnTrack> trajectory) {
445438
public int getStatus() {
446439
return _status;
447440
}
448-
public void setStatus(int passKFFlag) {
441+
public final void setStatus(int passKFFlag) {
449442
//for status word:
450443
int nSVT = 0;
451444
int nBMTZ = 0;
452445
int nBMTC = 0;
453446
// fills the list of cross ids for crosses belonging to that reconstructed track
454-
for (int j = 0; j < this.size(); j++) {
447+
int size = this.size();
448+
for (int j = 0; j < size; j++) {
455449
// counter to get status word
456450
if (this.get(j).getDetector() == DetectorType.BST) {
457451
nSVT++;
@@ -565,7 +559,8 @@ else if(MLayer.getDetectorType(index) == DetectorType.BMT) {
565559

566560
private static int[] getTrackKey(Track track) {
567561
int[] cids = new int[9];
568-
for (int i = 0; i < track.size(); i++) {
562+
int size = track.size();
563+
for (int i = 0; i < size; i++) {
569564
Cross c = track.get(i);
570565
if(c.getDetector()==DetectorType.BST) {
571566
cids[c.getRegion()-1] = c.getId();
@@ -593,23 +588,25 @@ public static void removeOverlappingTracks(List<Track> tracks) {
593588
return;
594589
Map<Integer, Track> map = new HashMap<>();
595590
Map<Integer, Track> selectedTracks = new HashMap<>();
596-
for (int i = 0; i < tracks.size(); i++) {
591+
final int size = tracks.size();
592+
for (int i = 0; i < size; i++) {
597593
Track t1 = tracks.get(i);
598594
t1.setTempId(i+1);
599595
map.put(i+1, t1);
600596
}
601-
for (int i = 0; i < tracks.size(); i++) {
597+
for (int i = 0; i < size; i++) {
602598
Track t1 = tracks.get(i);
603599
int[] cids = getTrackKey(t1);
604600
for (int j = 0;j < tracks.size(); j++) {
605601
boolean ov = false;
606602
if(i==j) continue;
607603
Track t2 = tracks.get(j);
608604
int[] cids2 = getTrackKey(t2);
609-
for(int k = 0; k<9; k++) {
605+
for(int k = 0; k < 9; k++) {
610606
if(cids[k]!=-1) {
611607
if(cids[k]==cids2[k]) {
612608
ov=true;
609+
break;
613610
}
614611
}
615612
}
@@ -618,7 +615,7 @@ public static void removeOverlappingTracks(List<Track> tracks) {
618615
}
619616
}
620617
}
621-
for (int i = 0; i < tracks.size(); i++) {
618+
for (int i = 0; i < size; i++) {
622619
List<Track> ovlTracks = new ArrayList<>();
623620
Track t1 = tracks.get(i);
624621
ovlTracks.add(t1);
@@ -638,9 +635,10 @@ public static void removeOverlappingTracks(List<Track> tracks) {
638635
}
639636

640637
public static void checkForOverlaps(List<Track> tracks, String msg) {
641-
for (int i = 0; i < tracks.size(); i++) {
638+
int size = tracks.size();
639+
for (int i = 0; i < size; i++) {
642640
Track t1 = tracks.get(i);
643-
for(int j=0; j<tracks.size(); j++ ) {
641+
for(int j=0; j<size; j++ ) {
644642
Track t2 = tracks.get(j);
645643
if(i!=j && t1.overlapWith(t2)) {
646644
System.out.println(msg + " " + "overlap");
@@ -649,7 +647,6 @@ public static void checkForOverlaps(List<Track> tracks, String msg) {
649647
}
650648
}
651649

652-
653650
@Override
654651
public String toString() {
655652
String str = String.format("Track id=%d, q=%d, p=%.3f GeV pt=%.3f GeV, d0=%.3f deg, phi=%.3f deg, z0=%.3f deg, tandip=%.3f deg, NDF=%d, chi2=%.3f, seed method=%d, KF iterations=%d, status=%d\n",
@@ -661,8 +658,4 @@ public String toString() {
661658
return str;
662659
}
663660

664-
665-
666-
667-
668661
}

0 commit comments

Comments
 (0)