Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ticlv5: adapt the validation to run with both v4 and v5 #28

Merged
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
7 changes: 3 additions & 4 deletions RecoHGCal/TICL/plugins/TICLGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ class Node {
const std::vector<unsigned int>& getInnerNeighbours() const { return innerNeighboursId_; }
void findSubComponents(std::vector<Node>& graph, std::vector<unsigned int>& subComponent, std::string tabs);


inline bool isInnerNeighbour(const unsigned int tid){
auto findInner = std::find(innerNeighboursId_.begin(), innerNeighboursId_.end(), tid);
return findInner != innerNeighboursId_.end();
inline bool isInnerNeighbour(const unsigned int tid) {
auto findInner = std::find(innerNeighboursId_.begin(), innerNeighboursId_.end(), tid);
return findInner != innerNeighboursId_.end();
}

~Node() = default;
Expand Down
101 changes: 63 additions & 38 deletions RecoHGCal/TICL/plugins/TracksterLinkingbySkeletons.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
namespace {
bool isRoundTrackster(std::array<ticl::Vector, 3> skeleton) { return (skeleton[0].Z() == skeleton[2].Z()); }

bool isGoodTrackster(const ticl::Trackster &trackster, const std::array<ticl::Vector, 3> &skeleton, const unsigned int min_num_lcs, const float min_trackster_energy, const float pca_quality_th ) {
bool isGoodTrackster(const ticl::Trackster& trackster,
const std::array<ticl::Vector, 3> &skeleton,
const unsigned int min_num_lcs,
const float min_trackster_energy,
const float pca_quality_th) {
bool isGood = false;

if (isRoundTrackster(skeleton) or trackster.vertices().size() < min_num_lcs or trackster.raw_energy() < min_trackster_energy) {
if (isRoundTrackster(skeleton) or trackster.vertices().size() < min_num_lcs or
trackster.raw_energy() < min_trackster_energy) {
isGood = false;
} else {
auto const &eigenvalues = trackster.eigenvalues();
Expand All @@ -37,7 +42,8 @@ namespace {
std::sqrt(point2.x() * point2.x() + point2.y() * point2.y()) * std::abs(point1.z()) / std::abs(point2.z());
float delta_phi = reco::deltaPhi(point1.Phi(), point2.Phi());
float projective_distance = (r1 - r2_at_z1) * (r1 - r2_at_z1) + r2_at_z1 * r2_at_z1 * delta_phi * delta_phi;
LogDebug("TracksterLinkingbySkeletons") << "Computing distance between point : " << point1 << " And point " << point2 << " Distance " << projective_distance << std::endl;
LogDebug("TracksterLinkingbySkeletons") << "Computing distance between point : " << point1 << " And point "
<< point2 << " Distance " << projective_distance << std::endl;
return projective_distance;
}
} // namespace
Expand All @@ -54,9 +60,7 @@ TracksterLinkingbySkeletons::TracksterLinkingbySkeletons(const edm::ParameterSet
dot_prod_th_(conf.getParameter<double>("dot_prod_th")),
min_distance_z_(conf.getParameter<double>("min_distance_z")),
max_distance_closest_points_(conf.getParameter<double>("max_distance_closest_points")),
max_z_distance_closest_ponts_(conf.getParameter<double>("max_z_distance_closest_ponts"))
{}

max_z_distance_closest_ponts_(conf.getParameter<double>("max_z_distance_closest_ponts")) {}

void TracksterLinkingbySkeletons::buildLayers() {
// build disks at HGCal front & EM-Had interface for track propagation
Expand Down Expand Up @@ -164,27 +168,35 @@ bool TracksterLinkingbySkeletons::areCompatible(const ticl::Trackster &myTrackst
const std::array<ticl::Vector, 3> &mySkeleton,
const std::array<ticl::Vector, 3> &otherSkeleton) {
if (!isGoodTrackster(myTrackster, mySkeleton, min_num_lcs_, min_trackster_energy_, pca_quality_th_)) {
LogDebug("TracksterLinkingbySkeletons") << "Inner Trackster wi energy " << myTrackster.raw_energy() << " Num LCs " << myTrackster.vertices().size() << " NOT GOOD " << std::endl;
LogDebug("TracksterLinkingbySkeletons") << "Inner Trackster wi energy " << myTrackster.raw_energy() << " Num LCs "
<< myTrackster.vertices().size() << " NOT GOOD " << std::endl;
return false;
} else {
LogDebug("TracksterLinkingbySkeletons") << "Inner Trackster wi energy " << myTrackster.raw_energy() << " Num LCs " << myTrackster.vertices().size() << " IS GOOD " << std::endl;
LogDebug("TracksterLinkingbySkeletons") << "Inner Trackster wi energy " << myTrackster.raw_energy() << " Num LCs "
<< myTrackster.vertices().size() << " IS GOOD " << std::endl;
float proj_distance = projective_distance(mySkeleton[1], otherSkeleton[1]);
bool areAlignedInProjectiveSpace = proj_distance < alignement_projective_th_;
LogDebug("TracksterLinkingbySkeletons") << "\t Trying to compare with outer Trackster with energy " << otherTrackster.raw_energy() << " Num LCS " << otherTrackster.vertices().size() << " Projective distance " << proj_distance << " areAlignedProjective " << areAlignedInProjectiveSpace << " TH " << alignement_projective_th_ << std::endl;
LogDebug("TracksterLinkingbySkeletons")
<< "\t Trying to compare with outer Trackster with energy " << otherTrackster.raw_energy() << " Num LCS "
<< otherTrackster.vertices().size() << " Projective distance " << proj_distance << " areAlignedProjective "
<< areAlignedInProjectiveSpace << " TH " << alignement_projective_th_ << std::endl;
if (isGoodTrackster(otherTrackster, otherSkeleton, min_num_lcs_, min_trackster_energy_, pca_quality_th_)) {
// if both tracksters are good, then we can check the projective distance between the barycenters.
// if the barycenters are aligned, then we check that the two skeletons are aligned
if (areAlignedInProjectiveSpace) {
auto dotProdSkeletons = ((mySkeleton[2] - mySkeleton[0]).Unit()).Dot((otherSkeleton[2] - otherSkeleton[0]).Unit());
bool alignedSkeletons =
dotProdSkeletons > dot_prod_th_;
LogDebug("TracksterLinkingbySkeletons") << "\t Outer Trackster is Good, checking for skeleton alignment " << alignedSkeletons << " dotProd " << dotProdSkeletons << " TH " << dot_prod_th_ << std::endl;
if(alignedSkeletons)
LogDebug("TracksterLinkingbySkeletons") << "\t\t Linked! " << std::endl;
auto dotProdSkeletons =
((mySkeleton[2] - mySkeleton[0]).Unit()).Dot((otherSkeleton[2] - otherSkeleton[0]).Unit());
bool alignedSkeletons = dotProdSkeletons > dot_prod_th_;
LogDebug("TracksterLinkingbySkeletons")
<< "\t Outer Trackster is Good, checking for skeleton alignment " << alignedSkeletons << " dotProd "
<< dotProdSkeletons << " TH " << dot_prod_th_ << std::endl;
if (alignedSkeletons)
LogDebug("TracksterLinkingbySkeletons") << "\t\t Linked! " << std::endl;
return alignedSkeletons;
} else {
// we measure the distance between the two closest nodes in the two skeletons
LogDebug("TracksterLinkingbySkeletons") << "\t Outer Trackster is not aligned, check skeletons distances " << std::endl;
LogDebug("TracksterLinkingbySkeletons")
<< "\t Outer Trackster is not aligned, check skeletons distances " << std::endl;
int myClosestPoint = -1;
int otherClosestPoint = -1;
float minDistance_z = std::numeric_limits<float>::max();
Expand All @@ -198,25 +210,36 @@ bool TracksterLinkingbySkeletons::areCompatible(const ticl::Trackster &myTrackst
}
}
}
LogDebug("TracksterLinkingbySkeletons") << "\t\t Check distance in Z " << minDistance_z << " TH " << min_distance_z_ << std::endl;
LogDebug("TracksterLinkingbySkeletons")
<< "\t\t Check distance in Z " << minDistance_z << " TH " << min_distance_z_ << std::endl;
if (minDistance_z < min_distance_z_) {
LogDebug("TracksterLinkingbySkeletons") << "\t Trackster have distance in Z " << minDistance_z << "Checking if they are aligned in projective space " << projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]) << " TH " << alignement_projective_th_ << std::endl;
if(projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]) < alignement_projective_th_){
LogDebug("TracksterLinkingbySkeletons")
<< "\t Trackster have distance in Z " << minDistance_z
<< "Checking if they are aligned in projective space "
<< projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]) << " TH "
<< alignement_projective_th_ << std::endl;
if (projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]) <
alignement_projective_th_) {
LogDebug("TracksterLinkingbySkeletons") << "\t\t Linked! " << std::endl;
}
return projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]) < alignement_projective_th_;
return projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]) <
alignement_projective_th_;
} else {
LogDebug("TracksterLinkingbySkeletons") << "\t\t Not Linked Distance Z " << minDistance_z << std::endl;
return false;
}
}
} else {
LogDebug("TracksterLinkingbySkeletons") << "\t Outer Trackster is NOT GOOD, check projective space alignment " << areAlignedInProjectiveSpace << " proj_distance " << alignement_projective_th_ << std::endl;
LogDebug("TracksterLinkingbySkeletons")
<< "\t Outer Trackster is NOT GOOD, check projective space alignment " << areAlignedInProjectiveSpace
<< " proj_distance " << alignement_projective_th_ << std::endl;
if (areAlignedInProjectiveSpace) {
LogDebug("TracksterLinkingbySkeletons") << "\t\t Linked! " << std::endl;
return true;
} else {
LogDebug("TracksterLinkingbySkeletons") << "\t Not aligned in projective space, check distance between closest points in the two skeletons " << std::endl;
LogDebug("TracksterLinkingbySkeletons")
<< "\t Not aligned in projective space, check distance between closest points in the two skeletons "
<< std::endl;
// we measure the distance between the two closest nodes in the two skeletons
int myClosestPoint = -1;
int otherClosestPoint = -1;
Expand All @@ -233,15 +256,16 @@ bool TracksterLinkingbySkeletons::areCompatible(const ticl::Trackster &myTrackst
}
}
float d = projective_distance(mySkeleton[myClosestPoint], otherSkeleton[otherClosestPoint]);
LogDebug("TracksterLinkingbySkeletons") << "\t\t Distance between closest points " << d << " TH " << 10.f << " Z Distance " << minDistance_z << " TH " << max_distance_closest_points_ << std::endl;
if(d < max_distance_closest_points_ and minDistance_z < max_z_distance_closest_ponts_){
LogDebug("TracksterLinkingbySkeletons")
<< "\t\t Distance between closest points " << d << " TH " << 10.f << " Z Distance " << minDistance_z
<< " TH " << max_distance_closest_points_ << std::endl;
if (d < max_distance_closest_points_ and minDistance_z < max_z_distance_closest_ponts_) {
LogDebug("TracksterLinkingbySkeletons") << "\t\t\t Linked! " << d << std::endl;
}
else{
LogDebug("TracksterLinkingbySkeletons") << "Distance between closest point " << d << " Distance in z " << max_z_distance_closest_ponts_ << std::endl;
} else {
LogDebug("TracksterLinkingbySkeletons") << "Distance between closest point " << d << " Distance in z "
<< max_z_distance_closest_ponts_ << std::endl;
}


return d < max_distance_closest_points_ and minDistance_z < max_z_distance_closest_ponts_;
}
}
Expand Down Expand Up @@ -293,8 +317,7 @@ void TracksterLinkingbySkeletons::linkTracksters(
float eta_max = std::min(abs(bary.eta()) + del_, TileConstants::maxEta);
int tileIndex = bary.eta() > 0.f;
const auto &tiles = tracksterTile[tileIndex];
std::array<int, 4> search_box = tiles.searchBoxEtaPhi(
eta_min, eta_max, bary.phi() - del_, bary.phi() + del_);
std::array<int, 4> search_box = tiles.searchBoxEtaPhi(eta_min, eta_max, bary.phi() - del_, bary.phi() + del_);
if (search_box[2] > search_box[3]) {
search_box[3] += TileConstants::nPhiBins;
}
Expand All @@ -307,10 +330,13 @@ void TracksterLinkingbySkeletons::linkTracksters(
continue;
if (maskReceivedLink[n] == 0 or allNodes[t_idx].isInnerNeighbour(n))
continue;
if (isGoodTrackster(tracksters[t_idx], skeletons[t_idx], min_num_lcs_, min_trackster_energy_, pca_quality_th_)){
LogDebug("TracksterLinkingbySkeletons") << "Trying to Link Trackster " << t_idx << " With Trackster " << n << std::endl;
if (isGoodTrackster(
tracksters[t_idx], skeletons[t_idx], min_num_lcs_, min_trackster_energy_, pca_quality_th_)) {
LogDebug("TracksterLinkingbySkeletons")
<< "Trying to Link Trackster " << t_idx << " With Trackster " << n << std::endl;
if (areCompatible(tracksters[t_idx], tracksters[n], skeletons[t_idx], skeletons[n])) {
LogDebug("TracksterLinkingbySkeletons") << "\t==== LINK: Trackster " << t_idx << " Linked with Trackster " << n << std::endl;
LogDebug("TracksterLinkingbySkeletons")
<< "\t==== LINK: Trackster " << t_idx << " Linked with Trackster " << n << std::endl;
maskReceivedLink[n] = 0;
allNodes[t_idx].addOuterNeighbour(n);
allNodes[n].addInnerNeighbour(t_idx);
Expand All @@ -322,21 +348,20 @@ void TracksterLinkingbySkeletons::linkTracksters(
}
}


LogDebug("TracksterLinkingbySkeletons") << "**************** FINAL GRAPH **********************" << std::endl;
LogDebug("TracksterLinkingbySkeletons") << "**************** FINAL GRAPH **********************" << std::endl;
for (auto const &node : allNodes) {
if (isRootTracksters[node.getId()]) {
LogDebug("TracksterLinkingbySkeletons")
LogDebug("TracksterLinkingbySkeletons")
<< "ISROOT "
<< " Node " << node.getId() << " position " << tracksters[node.getId()].barycenter() << " energy "
<< tracksters[node.getId()].raw_energy() << std::endl;
} else {
LogDebug("TracksterLinkingbySkeletons")
LogDebug("TracksterLinkingbySkeletons")
<< "Node " << node.getId() << " position " << tracksters[node.getId()].barycenter() << " energy "
<< tracksters[node.getId()].raw_energy() << std::endl;
}
}
LogDebug("TracksterLinkingbySkeletons") << "********************************************************" << std::endl;
LogDebug("TracksterLinkingbySkeletons") << "********************************************************" << std::endl;

TICLGraph graph(allNodes, isRootTracksters);

Expand Down
23 changes: 15 additions & 8 deletions RecoHGCal/TICL/python/customiseForTICLv5_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from RecoHGCal.TICL.ticlDumper_cfi import ticlDumper
from RecoHGCal.TICL.mergedTrackstersProducer_cfi import mergedTrackstersProducer as _mergedTrackstersProducer
from SimCalorimetry.HGCalAssociatorProducers.TSToSimTSAssociation_cfi import tracksterSimTracksterAssociationLinkingbyCLUE3D as _tracksterSimTracksterAssociationLinkingbyCLUE3D
from SimCalorimetry.HGCalAssociatorProducers.TSToSimTSAssociation_cfi import tracksterSimTracksterAssociationPRbyCLUE3D as _tracksterSimTracksterAssociationPRbyCLUE3D
from Validation.HGCalValidation.HGCalValidator_cff import hgcalValidatorv5
from SimCalorimetry.HGCalAssociatorProducers.TSToSimTSAssociation_cfi import tracksterSimTracksterAssociationPRbyCLUE3D as _tracksterSimTracksterAssociationPRbyCLUE3D
from Validation.HGCalValidation.HGCalValidator_cff import hgcalValidator
from RecoLocalCalo.HGCalRecProducers.HGCalUncalibRecHit_cfi import HGCalUncalibRecHit
from RecoHGCal.TICL.SimTracksters_cff import ticlSimTracksters

Expand Down Expand Up @@ -88,7 +88,7 @@ def customiseForTICLv5(process, enableDumper = False):
label_tst = cms.InputTag("ticlTrackstersCLUE3DHAD")
)

process.mergedTrackstersProducer = _mergedTrackstersProducer.clone()
process.mergedTrackstersProducer = _mergedTrackstersProducer.clone()

process.tracksterSimTracksterAssociationLinkingbyCLUE3D = _tracksterSimTracksterAssociationLinkingbyCLUE3D.clone(
label_tst = cms.InputTag("mergedTrackstersProducer")
Expand All @@ -107,8 +107,8 @@ def customiseForTICLv5(process, enableDumper = False):
process.tracksterSimTracksterAssociationLinking.label_tst = cms.InputTag("ticlCandidate")
process.tracksterSimTracksterAssociationPR.label_tst = cms.InputTag("ticlCandidate")

process.tracksterSimTracksterAssociationLinkingPU.label_tst = cms.InputTag("ticlTracksterLinks")
process.tracksterSimTracksterAssociationPRPU.label_tst = cms.InputTag("ticlTracksterLinks")
process.tracksterSimTracksterAssociationLinkingPU.label_tst = cms.InputTag("ticlCandidate")
process.tracksterSimTracksterAssociationPRPU.label_tst = cms.InputTag("ticlCandidate")
process.mergeTICLTask = cms.Task()
process.pfTICL = _pfTICLProducerV5.clone()
process.hgcalAssociators = cms.Task(process.mergedTrackstersProducer, process.lcAssocByEnergyScoreProducer, process.layerClusterCaloParticleAssociationProducer,
Expand All @@ -122,11 +122,18 @@ def customiseForTICLv5(process, enableDumper = False):
process.tracksterSimTracksterAssociationLinkingPU, process.tracksterSimTracksterAssociationPRPU
)

process.hgcalValidatorv5 = hgcalValidatorv5.clone(

labelTst = ["ticlTrackstersCLUE3DEM", "ticlTrackstersCLUE3DHAD", "ticlTracksterLinks"]
labelTst.extend([cms.InputTag("ticlSimTracksters", "fromCPs"), cms.InputTag("ticlSimTracksters")])
lcInputMask = ["ticlTrackstersCLUE3DEM", "ticlTrackstersCLUE3DHAD", "ticlTracksterLinks"]
lcInputMask.extend([cms.InputTag("ticlSimTracksters", "fromCPs"), cms.InputTag("ticlSimTracksters")])
process.hgcalValidator = hgcalValidator.clone(
label_tst = cms.VInputTag(labelTst),
LayerClustersInputMask = cms.VInputTag(lcInputMask),
ticlTrackstersMerge = cms.InputTag("ticlCandidate"),
trackstersclue3d = cms.InputTag("mergedTrackstersProducer")
)
process.hgcalValidatorSequence = cms.Sequence(process.hgcalValidatorv5)

process.hgcalValidatorSequence = cms.Sequence(process.hgcalValidator)
process.hgcalValidation = cms.Sequence(process.hgcalSimHitValidationEE+process.hgcalSimHitValidationHEF+process.hgcalSimHitValidationHEB+process.hgcalDigiValidationEE+process.hgcalDigiValidationHEF+process.hgcalDigiValidationHEB+process.hgcalRecHitValidationEE+process.hgcalRecHitValidationHEF+process.hgcalRecHitValidationHEB+process.hgcalHitValidationSequence+process.hgcalValidatorSequence+process.hgcalTiclPFValidation+process.hgcalPFJetValidation)
process.globalValidationHGCal = cms.Sequence(process.hgcalValidation)
process.validation_step9 = cms.EndPath(process.globalValidationHGCal)
Expand Down
1 change: 1 addition & 0 deletions Validation/HGCalValidation/interface/HGCalValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class HGCalValidator : public DQMGlobalEDAnalyzer<HGCalValidatorHistograms> {
const bool doCandidatesPlots_;
std::string label_candidates_;
const edm::FileInPath cummatbudinxo_;
const bool isTICLv5_;

std::vector<edm::EDGetTokenT<reco::CaloClusterCollection>> labelToken;
edm::EDGetTokenT<std::vector<SimCluster>> simClusters_;
Expand Down
Loading