1212import java .util .List ;
1313import java .util .Set ;
1414
15+ import org .hps .conditions .beam .BeamEnergy .BeamEnergyCollection ;
1516import org .hps .recon .ecal .cluster .ClusterUtilities ;
1617import org .hps .recon .tracking .CoordinateTransformations ;
1718import org .hps .recon .tracking .TrackUtils ;
@@ -48,12 +49,18 @@ public abstract class ReconParticleDriver extends Driver {
4849 public static final int MOLLER_BOT = 1 ;
4950
5051 // normalized cluster-track distance required for qualifying as a match:
51- private double MAXNSIGMAPOSITIONMATCH = 30 .0 ;
52+ private double MAXNSIGMAPOSITIONMATCH = 15 .0 ;
5253
5354 HPSEcal3 ecal ;
5455
5556 protected boolean isMC = false ;
5657 private boolean disablePID = false ;
58+
59+ public void setUseCorrectedClusterPositionsForMatching (boolean val ){
60+ useCorrectedClusterPositionsForMatching = val ;
61+ }
62+
63+ boolean useCorrectedClusterPositionsForMatching = false ;
5764
5865 // ==============================================================
5966 // ==== Class Variables =========================================
@@ -355,6 +362,10 @@ protected void detectorChanged(Detector detector) {
355362
356363 ecal = (HPSEcal3 ) detector .getSubdetector ("Ecal" );
357364 matcher .setBFieldMap (detector .getFieldMap ());
365+ BeamEnergyCollection beamEnergyCollection =
366+ this .getConditionsManager ().getCachedConditions (BeamEnergyCollection .class , "beam_energies" ).getCachedData ();
367+
368+ matcher .setBeamEnergy (beamEnergyCollection .get (0 ).getBeamEnergy ());
358369
359370 }
360371
@@ -433,7 +444,17 @@ protected List<ReconstructedParticle> makeReconstructedParticles(List<Cluster> c
433444 // try to find a matching cluster:
434445 Cluster matchedCluster = null ;
435446 for (Cluster cluster : clusters ) {
436-
447+
448+ //if the option to use corrected cluster positions is selected, then
449+ //create a copy of the current cluster, and apply corrections to it
450+ //before calculating nsigma. Default is don't use corrections.
451+ Cluster originalCluster = cluster ;
452+ if (useCorrectedClusterPositionsForMatching ){
453+ cluster = new BaseCluster (cluster );
454+ double ypos = TrackUtils .getTrackStateAtECal (particle .getTracks ().get (0 )).getReferencePoint ()[2 ];
455+ ClusterUtilities .applyCorrections (ecal , cluster , ypos ,isMC );
456+ }
457+
437458 // normalized distance between this cluster and track:
438459 final double thisNSigma = matcher .getNSigmaPosition (cluster , particle );
439460
@@ -447,7 +468,7 @@ protected List<ReconstructedParticle> makeReconstructedParticles(List<Cluster> c
447468
448469 // we found a new best cluster candidate for this track:
449470 smallestNSigma = thisNSigma ;
450- matchedCluster = cluster ;
471+ matchedCluster = originalCluster ;
451472
452473 // prefer using GBL tracks to correct (later) the clusters, for some consistency:
453474 if (track .getType () >= 32 || !clusterToTrack .containsKey (matchedCluster )) {
@@ -535,6 +556,14 @@ protected List<ReconstructedParticle> makeReconstructedParticles(List<Cluster> c
535556 }
536557 HepLorentzVector fourVector = new BasicHepLorentzVector (clusterEnergy , momentum );
537558 ((BaseReconstructedParticle ) particle ).set4Vector (fourVector );
559+
560+ // recalculate track-cluster matching n_sigma using corrected cluster positions
561+ // if that option is selected
562+ if (!particle .getClusters ().isEmpty () && useCorrectedClusterPositionsForMatching ){
563+ double goodnessPID_corrected = matcher .getNSigmaPosition (particle .getClusters ().get (0 ), particle );
564+ ((BaseReconstructedParticle ) particle ).setGoodnessOfPid (goodnessPID_corrected );
565+ }
566+
538567 }
539568
540569 // Return the list of reconstructed particles.
@@ -711,4 +740,9 @@ protected void startOfData() {
711740 protected void endOfData () {
712741 // matcher.saveHistograms();
713742 }
743+
744+
745+ public void setSnapToEdge (boolean val ){
746+ this .matcher .setSnapToEdge (val );
747+ }
714748}
0 commit comments