Skip to content

Commit 5bb27b3

Browse files
N-Plxbaltzell
authored andcommitted
refactor: move writing of the projection bank
1 parent cb272a9 commit 5bb27b3

File tree

3 files changed

+117
-88
lines changed

3 files changed

+117
-88
lines changed

reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.jlab.rec.atof.trackMatch;
22

33
import java.util.ArrayList;
4-
import java.util.List;
54

65
import org.jlab.io.base.DataBank;
76
import org.jlab.io.base.DataEvent;
@@ -30,7 +29,7 @@ public class TrackProjector {
3029
/**
3130
* projections of tracks.
3231
*/
33-
private List<TrackProjection> projections;
32+
private ArrayList<TrackProjection> projections;
3433

3534
/**
3635
* solenoid magnitude
@@ -52,7 +51,7 @@ public TrackProjector() {
5251
* @return a {@link List} of {@link TrackProjection} objects representing
5352
* the projections.
5453
*/
55-
public List<TrackProjection> getProjections() {
54+
public ArrayList<TrackProjection> getProjections() {
5655
return projections;
5756
}
5857

@@ -70,7 +69,7 @@ public Double getB() {
7069
*
7170
* @param Projections a {@link List} of {@link TrackProjection}.
7271
*/
73-
public void setProjections(List<TrackProjection> Projections) {
72+
public void setProjections(ArrayList<TrackProjection> Projections) {
7473
this.projections = Projections;
7574
}
7675

@@ -104,7 +103,6 @@ public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb)
104103
DataBank bank = event.getBank(track_bank_name);
105104
int nt = bank.rows(); // number of tracks
106105
TrackProjection projection = new TrackProjection();
107-
DataBank outputBank = event.createBank("AHDC::Projections", nt);
108106
for (int i = 0; i < nt; i++) {
109107

110108
double x = bank.getFloat("x", i);
@@ -136,9 +134,7 @@ public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb)
136134
projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength());
137135
projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength());
138136
projections.add(projection);
139-
fill_out_bank(outputBank, projection, i);
140137
}
141-
event.appendBank(outputBank);
142138
}
143139
}
144140

@@ -203,25 +199,9 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd
203199
projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength());
204200
projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength());
205201
projections.add(projection);
206-
fill_out_bank(outputBank, projection, i);
207202
}
208-
event.appendBank(outputBank);
209203
}
210204
}
211-
212-
public static void fill_out_bank(DataBank outputBank, TrackProjection projection, int i) {
213-
outputBank.setFloat("x_at_bar", i, (float) projection.getBarIntersect().x());
214-
outputBank.setFloat("y_at_bar", i, (float) projection.getBarIntersect().y());
215-
outputBank.setFloat("z_at_bar", i, (float) projection.getBarIntersect().z());
216-
outputBank.setFloat("L_at_bar", i, (float) projection.getBarPathLength());
217-
outputBank.setFloat("L_in_bar", i, (float) projection.getBarInPathLength());
218-
outputBank.setFloat("x_at_wedge", i, (float) projection.getWedgeIntersect().x());
219-
outputBank.setFloat("y_at_wedge", i, (float) projection.getWedgeIntersect().y());
220-
outputBank.setFloat("z_at_wedge", i, (float) projection.getWedgeIntersect().z());
221-
outputBank.setFloat("L_at_wedge", i, (float) projection.getWedgePathLength());
222-
outputBank.setFloat("L_in_wedge", i, (float) projection.getWedgeInPathLength());
223-
224-
}
225205

226206
public static void main(String arg[]) {
227207

reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java

Lines changed: 112 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,118 +6,167 @@
66
import org.jlab.rec.atof.cluster.AtofCluster;
77
import org.jlab.rec.atof.hit.AtofHit;
88
import org.jlab.rec.atof.hit.BarHit;
9+
import org.jlab.rec.atof.trackMatch.TrackProjection;
910

1011
/**
11-
* The {@code RecoBankWriter} writes the banks needed for the atof reconstruction:
12-
* track projections, hits and clusters info.
13-
*
12+
* The {@code RecoBankWriter} writes the banks needed for the atof
13+
* reconstruction: track projections, hits and clusters info.
14+
*
1415
* @author pilleux
1516
*/
1617
public class RecoBankWriter {
17-
18+
1819
/**
1920
* Writes the bank of atof hits.
20-
*
21+
*
2122
* @param event the {@link DataEvent} in which to add the bank
22-
* @param wedgeHits the {@link ArrayList} of {@link AtofHit}
23-
* containing the wedge hits to be added to the bank
24-
* @param barHits the {@link ArrayList} of {@link BarHit}
25-
* containing the bar hits to be added to the bank
26-
*
23+
* @param wedgeHits the {@link ArrayList} of {@link AtofHit} containing the
24+
* wedge hits to be added to the bank
25+
* @param barHits the {@link ArrayList} of {@link BarHit} containing the bar
26+
* hits to be added to the bank
27+
*
2728
* @return {@link DataBank} the bank with all the hits read in the event.
28-
*
29+
*
2930
*/
3031
public static DataBank fillAtofHitBank(DataEvent event, ArrayList<AtofHit> wedgeHits, ArrayList<BarHit> barHits) {
31-
32+
3233
ArrayList<AtofHit> hitList = new ArrayList<>();
3334
hitList.addAll(wedgeHits);
3435
hitList.addAll(barHits);
35-
36-
DataBank bank = event.createBank("ATOF::hits", hitList.size());
37-
36+
37+
DataBank bank = event.createBank("ATOF::hits", hitList.size());
38+
3839
if (bank == null) {
3940
System.err.println("COULD NOT CREATE A ATOF::hits BANK!!!!!!");
4041
return null;
4142
}
42-
43-
for(int i =0; i< hitList.size(); i++) {
44-
bank.setShort("id",i, (short)(i+1));
45-
bank.setInt("sector",i, (int) hitList.get(i).getSector());
46-
bank.setInt("layer",i, (int) hitList.get(i).getLayer());
47-
bank.setInt("component",i, (int) hitList.get(i).getComponent());
48-
bank.setFloat("time",i, (float) hitList.get(i).getTime());
49-
bank.setFloat("x",i, (float) (hitList.get(i).getX()));
50-
bank.setFloat("y",i, (float) (hitList.get(i).getY()));
51-
bank.setFloat("z",i, (float) (hitList.get(i).getZ()));
52-
bank.setFloat("energy",i, (float) hitList.get(i).getEnergy());
53-
bank.setFloat("inlength",i, (float) (hitList.get(i).getInPathLength()));
54-
bank.setFloat("pathlength",i, (float) (hitList.get(i).getPathLength()));
43+
44+
for (int i = 0; i < hitList.size(); i++) {
45+
bank.setShort("id", i, (short) (i + 1));
46+
bank.setInt("sector", i, (int) hitList.get(i).getSector());
47+
bank.setInt("layer", i, (int) hitList.get(i).getLayer());
48+
bank.setInt("component", i, (int) hitList.get(i).getComponent());
49+
bank.setFloat("time", i, (float) hitList.get(i).getTime());
50+
bank.setFloat("x", i, (float) (hitList.get(i).getX()));
51+
bank.setFloat("y", i, (float) (hitList.get(i).getY()));
52+
bank.setFloat("z", i, (float) (hitList.get(i).getZ()));
53+
bank.setFloat("energy", i, (float) hitList.get(i).getEnergy());
54+
bank.setFloat("inlength", i, (float) (hitList.get(i).getInPathLength()));
55+
bank.setFloat("pathlength", i, (float) (hitList.get(i).getPathLength()));
5556
}
5657
return bank;
5758
}
58-
59+
5960
/**
6061
* Writes the bank of atof clusters.
61-
*
62+
*
6263
* @param event the {@link DataEvent} in which to add the bank
63-
* @param clusterList the {@link ArrayList} of {@link AtofCluster}
64+
* @param clusterList the {@link ArrayList} of {@link AtofCluster}
6465
* containing the clusters info to be added to the bank
65-
*
66-
* @return {@link DataBank} the bank with all the clusters built in the event.
67-
*
66+
*
67+
* @return {@link DataBank} the bank with all the clusters built in the
68+
* event.
69+
*
6870
*/
6971
public static DataBank fillAtofClusterBank(DataEvent event, ArrayList<AtofCluster> clusterList) {
70-
71-
DataBank bank = event.createBank("ATOF::clusters", clusterList.size());
72-
72+
73+
DataBank bank = event.createBank("ATOF::clusters", clusterList.size());
74+
7375
if (bank == null) {
7476
System.err.println("COULD NOT CREATE A ATOF::clusters BANK!!!!!!");
7577
return null;
7678
}
77-
78-
for(int i =0; i< clusterList.size(); i++) {
79-
bank.setShort("id",i, (short)(i+1));
80-
bank.setInt("barsize",i, (int) clusterList.get(i).getBarHits().size());
81-
bank.setInt("wedgesize",i, (int) clusterList.get(i).getWedgeHits().size());
82-
bank.setFloat("time",i, (float) clusterList.get(i).getTime());
83-
bank.setFloat("x",i, (float) (clusterList.get(i).getX()));
84-
bank.setFloat("y",i, (float) (clusterList.get(i).getY()));
85-
bank.setFloat("z",i, (float) (clusterList.get(i).getZ()));
86-
bank.setFloat("energy",i, (float) clusterList.get(i).getEnergy());
87-
bank.setFloat("inpathlength",i, (float) (clusterList.get(i).getInPathLength()));
88-
bank.setFloat("pathlength",i, (float) (clusterList.get(i).getPathLength()));
79+
80+
for (int i = 0; i < clusterList.size(); i++) {
81+
bank.setShort("id", i, (short) (i + 1));
82+
bank.setInt("barsize", i, (int) clusterList.get(i).getBarHits().size());
83+
bank.setInt("wedgesize", i, (int) clusterList.get(i).getWedgeHits().size());
84+
bank.setFloat("time", i, (float) clusterList.get(i).getTime());
85+
bank.setFloat("x", i, (float) (clusterList.get(i).getX()));
86+
bank.setFloat("y", i, (float) (clusterList.get(i).getY()));
87+
bank.setFloat("z", i, (float) (clusterList.get(i).getZ()));
88+
bank.setFloat("energy", i, (float) clusterList.get(i).getEnergy());
89+
bank.setFloat("inpathlength", i, (float) (clusterList.get(i).getInPathLength()));
90+
bank.setFloat("pathlength", i, (float) (clusterList.get(i).getPathLength()));
8991
}
9092
return bank;
9193
}
92-
94+
95+
/**
96+
* Writes the bank of track projections.
97+
*
98+
* @param event the {@link DataEvent} in which to add the bank
99+
* @param projections the {@link ArrayList} of {@link TrackProjection}
100+
* containing the track projection info to be added to the bank
101+
*
102+
* @return {@link DataBank} the bank with all the projected tracks in the
103+
* event.
104+
*
105+
*/
106+
public static DataBank fillProjectionsBank(DataEvent event, ArrayList<TrackProjection> projections) {
107+
108+
DataBank bank = event.createBank("AHDC::Projections", projections.size());
109+
110+
if (bank == null) {
111+
System.err.println("COULD NOT CREATE A AHDC::Projections BANK!!!!!!");
112+
return null;
113+
}
114+
115+
for (int i = 0; i < projections.size(); i++) {
116+
TrackProjection projection = projections.get(i);
117+
bank.setFloat("x_at_bar", i, (float) projection.getBarIntersect().x());
118+
bank.setFloat("y_at_bar", i, (float) projection.getBarIntersect().y());
119+
bank.setFloat("z_at_bar", i, (float) projection.getBarIntersect().z());
120+
bank.setFloat("L_at_bar", i, (float) projection.getBarPathLength());
121+
bank.setFloat("L_in_bar", i, (float) projection.getBarInPathLength());
122+
bank.setFloat("x_at_wedge", i, (float) projection.getWedgeIntersect().x());
123+
bank.setFloat("y_at_wedge", i, (float) projection.getWedgeIntersect().y());
124+
bank.setFloat("z_at_wedge", i, (float) projection.getWedgeIntersect().z());
125+
bank.setFloat("L_at_wedge", i, (float) projection.getWedgePathLength());
126+
bank.setFloat("L_in_wedge", i, (float) projection.getWedgeInPathLength());
127+
}
128+
return bank;
129+
}
130+
93131
/**
94132
* Appends the atof banks to an event.
95-
*
133+
*
96134
* @param event the {@link DataEvent} in which to append the banks
97-
* @param clusterList the {@link ArrayList} of {@link AtofCluster}
135+
* @param clusterList the {@link ArrayList} of {@link AtofCluster}
98136
* containing the clusters info to be added to the bank
99-
* @param wedgeHits the {@link ArrayList} of {@link AtofHit}
100-
* containing the wedge hits info to be added
101-
* @param barHits the {@link ArrayList} of {@link BarHit}
102-
* containing the bar hits info to be added
103-
*
137+
* @param wedgeHits the {@link ArrayList} of {@link AtofHit} containing the
138+
* wedge hits info to be added
139+
* @param barHits the {@link ArrayList} of {@link BarHit} containing the bar
140+
* hits info to be added
141+
* @param projections the {@link ArrayList} of {@link TrackProjection} containing the
142+
* track projections info to be added
143+
*
104144
* @return 0 if it worked, 1 if it failed
105-
*
145+
*
106146
*/
107-
public int appendAtofBanks(DataEvent event, ArrayList<AtofHit> wedgeHits, ArrayList<BarHit> barHits, ArrayList<AtofCluster> clusterList) {
147+
public int appendAtofBanks(DataEvent event, ArrayList<AtofHit> wedgeHits, ArrayList<BarHit> barHits, ArrayList<AtofCluster> clusterList, ArrayList<TrackProjection> projections) {
148+
149+
DataBank projbank = this.fillProjectionsBank(event, projections);
150+
if (projbank != null) {
151+
event.appendBank(projbank);
152+
} else {
153+
return 1;
154+
}
108155

109156
DataBank hitbank = this.fillAtofHitBank(event, wedgeHits, barHits);
110157
if (hitbank != null) {
111158
event.appendBank(hitbank);
159+
} else {
160+
return 1;
112161
}
113-
else return 1;
114162

115163
DataBank clusterbank = fillAtofClusterBank(event, clusterList);
116164
if (clusterbank != null) {
117165
event.appendBank(clusterbank);
166+
} else {
167+
return 1;
118168
}
119-
else return 1;
120-
169+
121170
return 0;
122171
}
123172

@@ -126,5 +175,5 @@ public int appendAtofBanks(DataEvent event, ArrayList<AtofHit> wedgeHits, ArrayL
126175
*/
127176
public static void main(String[] args) {
128177
}
129-
178+
130179
}

reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public boolean processDataEvent(DataEvent event) {
7474

7575
//Hit finder init
7676
HitFinder hitfinder = new HitFinder();
77-
hitfinder.findHits(event, Atof);
77+
hitfinder.findHits(event, Atof, projector);
7878

7979
ArrayList<AtofHit> WedgeHits = hitfinder.getWedgeHits();
8080
ArrayList<BarHit> BarHits = hitfinder.getBarHits();
@@ -91,7 +91,7 @@ public boolean processDataEvent(DataEvent event) {
9191
ArrayList<AtofCluster> Clusters = clusterFinder.getClusters();
9292

9393
if (WedgeHits.size() != 0 || BarHits.size() != 0) {
94-
rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters);
94+
rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters, projector.getProjections());
9595
}
9696
return true;
9797
}

0 commit comments

Comments
 (0)