Skip to content
Merged

Iss1079 #1080

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
43 changes: 43 additions & 0 deletions tracking/src/main/java/org/hps/recon/tracking/kalman/KalTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class KalTrack {
private Map<MeasurementSite, Vec> interceptMomVects;
Map<Integer, MeasurementSite> millipedeMap;
Map<Integer, MeasurementSite> lyrMap;
Map<Integer, Integer> laymilli;
public int eventNumber;
public boolean bad;
HelixState helixAtOrigin;
Expand Down Expand Up @@ -317,6 +318,48 @@ private void makeMillipedeMap() {
}
}

private void makeLayMilli(){
laymilli = new HashMap<Integer, Integer>(14);
for (MeasurementSite site : SiteList){
laymilli.put(site.m.millipedeID,site.m.Layer);
}
}

public int millToLay(int millipedeID){
if (laymilli == null) {
makeLayMilli();
}
if (millipedeMap.containsKey(millipedeID)) {
return laymilli.get(millipedeID);
} else {
return -1;
}
}

// Does the scatX for Millipede
public double scatXMillipede(int millipedeID){
if (laymilli == null) {
makeLayMilli();
}
if (laymilli.containsKey(millipedeID)) {
return scatX(laymilli.get(millipedeID));
} else {
return -1000.0;
}
}

// Does the scatZ for Millipede
public double scatZMillipede(int millipedeID){
if (laymilli == null) {
makeLayMilli();
}
if (laymilli.containsKey(millipedeID)) {
return scatZ(laymilli.get(millipedeID));
} else {
return -1000.0;
}
}

// Find the change in smoothed helix angle in XY between one layer and the next
public double scatX(int layer) {
if (lyrMap == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.hps.recon.tracking.TrackData;
import org.hps.recon.tracking.TrackIntersectData;
import org.hps.recon.tracking.TrackResidualsData;
//import org.hps.recon.tracking.KFKinkData;

import org.hps.recon.tracking.MaterialSupervisor.ScatteringDetectorVolume;
import org.hps.recon.tracking.MaterialSupervisor.SiStripPlane;
import org.hps.recon.tracking.gbl.GBLStripClusterData;
Expand Down Expand Up @@ -85,6 +87,7 @@ public class KalmanPatRecDriver extends Driver {
private double mxChi2Vtx; // Maximum chi^2 for 5-hit tracks with a vertex constraint
private int numEvtPlots; // Number of event displays to plot (gnuplot files)
private boolean doDebugPlots; // Whether to make all the debugging histograms
private boolean doForLayer; // Does the track residuals and kinks per layer, not millipede id
private int siHitsLimit; // Maximum number of SiClusters in one event allowed for KF pattern reco
// (protection against monster events)
private double seedCompThr; // Threshold for seedTrack helix parameters compatibility
Expand All @@ -100,6 +103,7 @@ public class KalmanPatRecDriver extends Driver {
private boolean useBeamPositionConditions; // True to use beam position from database
private boolean useFixedVertexZPosition; // True to override the database just for the z beam position
private Level logLevel = Level.WARNING; // Set log level from steering
private boolean addKinks;
private boolean addResiduals; // If true add the hit-on-track residuals to the LCIO event
private List<HpsSiSensor> sensors = null; // List of tracker sensors

Expand Down Expand Up @@ -132,10 +136,18 @@ public void setSiHitsLimit(int input) {
siHitsLimit = input;
}

public void setAddKinks(boolean input) {
addKinks = input;
}

public void setAddResiduals(boolean input) {
addResiduals = input;
}

public void setDoForLayer(boolean input) {
doForLayer = input;
}

public void setTargetPosition(double target_pos){
this.target_pos = target_pos;
}
Expand Down Expand Up @@ -322,16 +334,21 @@ public void process(EventHeader event) {
//For GBL Refitting
List<GBLStripClusterData> allClstrs = new ArrayList<GBLStripClusterData>();
List<LCRelation> gblStripClusterDataRelations = new ArrayList<LCRelation>();


//For layer by layer X and Z Kinks
List<TrackResidualsData> trackXKinks = new ArrayList<TrackResidualsData>();
List<LCRelation> trackXKinksRelations = new ArrayList<LCRelation>();
List<TrackResidualsData> trackZKinks = new ArrayList<TrackResidualsData>();
List<LCRelation> trackZKinksRelations = new ArrayList<LCRelation>();

//For hit-on-track residuals information
List<TrackResidualsData> trackResiduals = new ArrayList<TrackResidualsData>();
List<LCRelation> trackResidualsRelations = new ArrayList<LCRelation>();
List<TrackIntersectData> trackIntersects = new ArrayList<TrackIntersectData>();
List<LCRelation> trackIntersectsRelations = new ArrayList<LCRelation>();

ArrayList<KalTrack>[] kPatList = prepareTrackCollections(event, outputFullTracks, trackDataCollection, trackDataRelations, allClstrs, gblStripClusterDataRelations, trackResiduals, trackResidualsRelations, trackIntersects, trackIntersectsRelations);
ArrayList<KalTrack>[] kPatList = prepareTrackCollections(event, outputFullTracks, trackDataCollection, trackDataRelations, allClstrs, gblStripClusterDataRelations,trackXKinks,trackXKinksRelations,trackZKinks,trackZKinksRelations,trackResiduals, trackResidualsRelations, trackIntersects, trackIntersectsRelations);


// ArrayList<KalTrack>[] kPatList = prepareTrackCollections(event, outputFullTracks, trackDataCollection, trackDataRelations, allClstrs, gblStripClusterDataRelations, trackResiduals, trackResidualsRelations);
//mg debug why the track data relations (and others I think) are screwed
// for (LCRelation tdRel: trackDataRelations){
Expand All @@ -344,12 +361,19 @@ public void process(EventHeader event) {
event.put("KFGBLStripClusterDataRelations", gblStripClusterDataRelations, LCRelation.class, flag);
event.put("KFTrackData",trackDataCollection, TrackData.class,0);
event.put("KFTrackDataRelations",trackDataRelations,LCRelation.class,0);


if (addKinks) {
event.put("KFXKink", trackXKinks, TrackResidualsData.class,0);
event.put("KFXKinkRelations", trackXKinksRelations,LCRelation.class,0);
event.put("KFZKink", trackZKinks, TrackResidualsData.class,0);
event.put("KFZKinkRelations", trackZKinksRelations,LCRelation.class,0);
}

if (addResiduals) {
event.put("KFUnbiasRes", trackResiduals, TrackResidualsData.class,0);
event.put("KFUnbiasResRelations",trackResidualsRelations, LCRelation.class,0);
event.put("KFUnbiasInt", trackIntersects, TrackIntersectData.class, 0);
event.put("KFUnbiasIntRelations", trackIntersectsRelations, LCRelation.class, 0);
event.put("KFUnbiasInt", trackIntersects, TrackIntersectData.class, 0);
event.put("KFUnbiasIntRelations", trackIntersectsRelations, LCRelation.class, 0);
}

if (kPlot != null) {
Expand Down Expand Up @@ -384,6 +408,8 @@ public int compare(TrackerHit o1, TrackerHit o2) {
private ArrayList<KalTrack>[] prepareTrackCollections(EventHeader event, List<Track> outputFullTracks,
List<TrackData> trackDataCollection, List<LCRelation> trackDataRelations,
List<GBLStripClusterData> allClstrs, List<LCRelation> gblStripClusterDataRelations,
List<TrackResidualsData> trackXKinks, List<LCRelation> trackXKinksRelations,
List<TrackResidualsData> trackZKinks, List<LCRelation> trackZKinksRelations,
List<TrackResidualsData> trackResiduals, List<LCRelation> trackResidualsRelations,
List<TrackIntersectData> trackIntersects, List<LCRelation> trackIntersectsRelations) {

Expand Down Expand Up @@ -502,32 +528,35 @@ private ArrayList<KalTrack>[] prepareTrackCollections(EventHeader event, List<Tr

//Add the TrackResiduals
List<Integer> layers = new ArrayList<Integer>();
List<Double> residuals = new ArrayList<Double>();
List<Double> residuals = new ArrayList<Double>();
List<Float> sigmas = new ArrayList<Float>();
List<Integer> layersInt = new ArrayList<Integer>();
List<Double> intersect = new ArrayList<Double>();
List<Integer> layersInt = new ArrayList<Integer>();
List<Double> intersect = new ArrayList<Double>();
List<Float> sigmasInt = new ArrayList<Float>();
int uindex = 0;
int vindex = 1;
int windex = 2;
//...loop over clusters and save millipedID to residuals
for (GBLStripClusterData clstr : clstrs) {
for (GBLStripClusterData clstr: clstrs) {
Pair<Double,Double> res_and_sigma = kTk.unbiasedResidualMillipede(clstr.getId());
if (res_and_sigma.getSecondElement() > -1.) {
layers.add(clstr.getId());
residuals.add(res_and_sigma.getFirstElement());
int i = clstr.getId();
if(doForLayer){
i = kTk.millToLay(i);
}
layers.add(i);
residuals.add(res_and_sigma.getFirstElement());
sigmas.add(res_and_sigma.getSecondElement().floatValue());
}
}//Loop on clusters
for (int ilay = 0; ilay<14; ilay++) {
}
for(int ilay = 0;ilay<14;ilay++){
Pair<Double[], Double> inter_and_sigma = kTk.unbiasedIntersect(ilay, true);
layersInt.add(ilay);
intersect.add(inter_and_sigma.getFirstElement()[uindex]);
intersect.add(inter_and_sigma.getFirstElement()[vindex]);
intersect.add(inter_and_sigma.getFirstElement()[windex]);
sigmasInt.add(inter_and_sigma.getSecondElement().floatValue());
}//Loop on layers

//Add the Track Data
TrackData KFtrackData = new TrackData(trackerVolume, (float) kTk.getTime(), qualityArray, momentum_f, (float) origin_bFieldY, (float) target_bFieldY, (float) ecal_bFieldY, (float) svtCenter_bFieldY);
trackDataCollection.add(KFtrackData);
Expand All @@ -541,7 +570,27 @@ private ArrayList<KalTrack>[] prepareTrackCollections(EventHeader event, List<Tr
trackIntersectsRelations.add(new BaseLCRelation(intersectData, KalmanTrackHPS));


/*
//Add the Kinks
layers = new ArrayList<Integer>();
List<Double> Xkinks = new ArrayList<Double>();
List<Double> Zkinks = new ArrayList<Double>();
for(GBLStripClusterData clstr: clstrs){
int milliID = clstr.getId();
int i = milliID;
if(doForLayer){
i = kTk.millToLay(i);
}
layers.add(i);
Xkinks.add(kTk.scatXMillipede(i));
Zkinks.add(kTk.scatZMillipede(i));
}
TrackResidualsData kinkXData = new TrackResidualsData(trackerVolume,layers,Xkinks,sigmas);
trackXKinks.add(kinkXData);
trackXKinksRelations.add(new BaseLCRelation(kinkXData, KalmanTrackHPS));
TrackResidualsData kinkZData = new TrackResidualsData(trackerVolume,layers,Zkinks,sigmas);
trackZKinks.add(kinkZData);
trackZKinksRelations.add(new BaseLCRelation(kinkZData, KalmanTrackHPS));
/*
if (KalmanTrackHPS.getTrackerHits().size() != residuals.size()) {
System.out.println("KalmanPatRecDriver::Residuals consistency check failed.");
System.out.printf("Track has %d hits while I have %d residuals \n", KalmanTrackHPS.getTrackerHits().size(), residuals.size());
Expand Down