forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 27
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
GBDT-Based Displaced Vertex Producer #1257
Open
ryanm124
wants to merge
23
commits into
cms-l1t-offline:phase2-l1t-integration-14_0_0_pre3
Choose a base branch
from
ryanm124:displacedVertexBDTSim
base: phase2-l1t-integration-14_0_0_pre3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0255f1a
Adding Displaced Vertexing Producer
ryanm124 24413dc
Modifying track quality MVA inputs for displaced tracks
ryanm124 acde98b
Reverting changes to prompt track quality BDT, adding fix to MVA scor…
ryanm124 0dde2bd
Adding newest BDT model file and displaced vertexing analyzer
ryanm124 dbf8525
Adding back tanL to prompt MVA and adding check for extended tracking…
ryanm124 d95ffe9
Adding option to run displaced vertexing in ntupler maker, reverting …
ryanm124 ca83bc8
Removing Displaced Vertexing Analyzer macro
ryanm124 63cdfcf
Changing BDT model to slimmed version, moved track selection to track…
ryanm124 93ea36d
Adding check for number of mother partucles in ntuple maker and fixed…
ryanm124 0786d1f
Removing unused class methods
ryanm124 8f39115
Changing track selection producer collection output name and correcti…
ryanm124 34584c5
Adding displaced vertexing track selector to schedule and code format…
ryanm124 bff29e9
Removing track selection module and moving cuts to python config. Fix…
ryanm124 0a9fccc
Adding RT cut to producer and adding isHard boolean to ntuple
ryanm124 a9e384e
Adding displaced vertexing emulation
ryanm124 7e435db
Adding file to convert xgboost model to conifer
ryanm124 41431b6
Adding plotting script
ryanm124 3245d7a
Final changes for emulation, changing bit widths for BDT input to ap_…
ryanm124 6459a2c
Adding do plot check for vertex plots
ryanm124 61a3c52
Cleaning up code
ryanm124 a71a93f
Deleting unused models and scripts
ryanm124 b4ed6f3
Moving BDT to seperate PR in data directory
ryanm124 04c75c3
Removing track selection producer changes and removing displaced trac…
ryanm124 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#ifndef DataFormats_L1TVertex_DisplacedVertex_h | ||
#define DataFormats_L1TVertex_DisplacedVertex_h | ||
#include <vector> | ||
#include "DataFormats/Common/interface/Ptr.h" | ||
#include "DataFormats/L1TrackTrigger/interface/TTTrack.h" | ||
#include "DataFormats/L1TrackTrigger/interface/TTTypes.h" | ||
#include <ap_int.h> | ||
|
||
namespace l1t { | ||
|
||
class DisplacedTrueVertex { | ||
public: | ||
DisplacedTrueVertex(float d_T, float R_T, float cos_T, float x, float y, float z, float openingAngle, float parentPt) | ||
: d_T_(d_T), R_T_(R_T), cos_T_(cos_T), x_(x), y_(y), z_(z), openingAngle_(openingAngle), parentPt_(parentPt) {} | ||
DisplacedTrueVertex() {} | ||
~DisplacedTrueVertex() {} | ||
float d_T() const { return d_T_; } | ||
float R_T() const { return R_T_; } | ||
float cos_T() const { return cos_T_; } | ||
float x() const { return x_; } | ||
float y() const { return y_; } | ||
float z() const { return z_; } | ||
float openingAngle() const { return openingAngle_; } | ||
float parentPt() const { return parentPt_; } | ||
|
||
private: | ||
float d_T_; | ||
float R_T_; | ||
float cos_T_; | ||
float x_; | ||
float y_; | ||
float z_; | ||
float openingAngle_; | ||
float parentPt_; | ||
}; | ||
typedef std::vector<DisplacedTrueVertex> DisplacedTrueVertexCollection; | ||
|
||
class DisplacedTrackVertex { | ||
|
||
public: | ||
DisplacedTrackVertex(int firstIndexTrk, | ||
int secondIndexTrk, | ||
int inTraj, | ||
float d_T, | ||
float R_T, | ||
float cos_T, | ||
float del_Z, | ||
float x, | ||
float y, | ||
float z, | ||
float openingAngle, | ||
float parentPt, | ||
bool isReal) | ||
: firstIndexTrk_(firstIndexTrk), | ||
secondIndexTrk_(secondIndexTrk), | ||
inTraj_(inTraj), | ||
d_T_(d_T), | ||
R_T_(R_T), | ||
cos_T_(cos_T), | ||
del_Z_(del_Z), | ||
x_(x), | ||
y_(y), | ||
z_(z), | ||
openingAngle_(openingAngle), | ||
parentPt_(parentPt), | ||
isReal_(isReal) {} | ||
DisplacedTrackVertex() {} | ||
~DisplacedTrackVertex() {} | ||
void setScore(float score) { score_ = score; } | ||
float d_T() const { return d_T_; } | ||
float R_T() const { return R_T_; } | ||
float cos_T() const { return cos_T_; } | ||
float x() const { return x_; } | ||
float y() const { return y_; } | ||
float z() const { return z_; } | ||
float openingAngle() const { return openingAngle_; } | ||
float parentPt() const { return parentPt_; } | ||
int firstIndexTrk() const { return firstIndexTrk_; } | ||
int secondIndexTrk() const { return secondIndexTrk_; } | ||
int inTraj() const { return inTraj_; } | ||
float del_Z() const { return del_Z_; } | ||
bool isReal() const { return isReal_; } | ||
float score() const { return score_; } | ||
|
||
private: | ||
int firstIndexTrk_; | ||
int secondIndexTrk_; | ||
int inTraj_; | ||
float d_T_; | ||
float R_T_; | ||
float cos_T_; | ||
float del_Z_; | ||
float x_; | ||
float y_; | ||
float z_; | ||
float openingAngle_; | ||
float parentPt_; | ||
bool isReal_; | ||
float score_; | ||
}; | ||
|
||
typedef std::vector<DisplacedTrackVertex> DisplacedTrackVertexCollection; | ||
} // namespace l1t | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
L1Trigger/L1TTrackMatch/interface/DisplacedVertexProducer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
#ifndef __L1Trigger_L1TTrackMatch_DisplacedVertexProducer_h__ | ||
#define __L1Trigger_L1TTrackMatch_DisplacedVertexProducer_h__ | ||
|
||
#include "DataFormats/L1Trigger/interface/DisplacedVertex.h" | ||
#include "FWCore/Framework/interface/global/EDProducer.h" | ||
#include "DataFormats/L1TrackTrigger/interface/TTTypes.h" | ||
#include "DataFormats/L1TrackTrigger/interface/TTTrack.h" | ||
#include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h" | ||
#include "TMath.h" | ||
#include <iostream> | ||
#include <map> | ||
#include <set> | ||
#include <string> | ||
#include <vector> | ||
#include <valarray> | ||
#include <ap_int.h> | ||
#include "conifer.h" | ||
|
||
using namespace std; | ||
|
||
class Track_Parameters { | ||
public: | ||
float pt; | ||
float d0; | ||
float z0; | ||
float eta; | ||
float phi; | ||
float charge; | ||
float rho; | ||
int index; | ||
float x0; | ||
float y0; | ||
int nstubs; | ||
float chi2rphi; | ||
float chi2rz; | ||
float bendchi2; | ||
float MVA1; | ||
|
||
float z(float x, float y) { | ||
float t = std::sinh(eta); | ||
float r = TMath::Sqrt(pow(x, 2) + pow(y, 2)); | ||
return (z0 + | ||
(t * r * | ||
(1 + (pow(d0, 2) / pow(r, 2)) + | ||
(1.0 / 6.0) * pow(r / (2 * rho), 2)))); // can do higher order terms if necessary from displaced math | ||
} | ||
Track_Parameters(float pt_in, | ||
float d0_in, | ||
float z0_in, | ||
float eta_in, | ||
float phi_in, | ||
float rho_in = 0, | ||
int index_in = -1, | ||
int nstubs_in = 0, | ||
float chi2rphi_in = 0, | ||
float chi2rz_in = 0, | ||
float bendchi2_in = 0, | ||
float MVA1_in = 0) { | ||
pt = pt_in; | ||
d0 = d0_in; | ||
z0 = z0_in; | ||
eta = eta_in; | ||
phi = phi_in; | ||
if (rho_in > 0) { | ||
charge = 1; | ||
} else if (rho_in < 0) { | ||
charge = -1; | ||
} else { | ||
charge = 0; | ||
} | ||
index = index_in; | ||
rho = fabs(rho_in); | ||
x0 = (rho + charge * d0) * TMath::Cos(phi - (charge * TMath::Pi() / 2)); | ||
y0 = (rho + charge * d0) * TMath::Sin(phi - (charge * TMath::Pi() / 2)); | ||
nstubs = nstubs_in; | ||
chi2rphi = chi2rphi_in; | ||
chi2rz = chi2rz_in; | ||
bendchi2 = bendchi2_in; | ||
MVA1 = MVA1_in; | ||
} | ||
Track_Parameters(){}; | ||
~Track_Parameters(){}; | ||
}; | ||
|
||
inline std::valarray<float> calcPVec(Track_Parameters a, double_t v_x, double_t v_y) { | ||
std::valarray<float> r_vec = {float(v_x) - a.x0, float(v_y) - a.y0}; | ||
std::valarray<float> p_vec = {-r_vec[1], r_vec[0]}; | ||
if (a.charge > 0) { | ||
p_vec *= -1; | ||
} | ||
if ((p_vec[0] != 0.0) || (p_vec[1] != 0.0)) { | ||
p_vec /= TMath::Sqrt(pow(p_vec[0], 2) + pow(p_vec[1], 2)); | ||
} | ||
p_vec *= a.pt; | ||
return p_vec; | ||
} | ||
|
||
class Vertex_Parameters { | ||
public: | ||
Double_t x_dv; | ||
Double_t y_dv; | ||
Double_t z_dv; | ||
Track_Parameters a; | ||
Track_Parameters b; | ||
std::vector<Track_Parameters> tracks = {}; | ||
float p_mag; | ||
float p2_mag; | ||
float openingAngle = -999.0; | ||
float R_T; | ||
float cos_T = -999.0; | ||
float d_T; | ||
float delta_z; | ||
float phi; | ||
Vertex_Parameters(Double_t x_dv_in, | ||
Double_t y_dv_in, | ||
Double_t z_dv_in, | ||
Track_Parameters a_in, | ||
Track_Parameters b_in) | ||
: a(a_in), b(b_in) { | ||
x_dv = x_dv_in; | ||
y_dv = y_dv_in; | ||
z_dv = z_dv_in; | ||
tracks.push_back(a_in); | ||
tracks.push_back(b_in); | ||
std::valarray<float> p_trk_1 = calcPVec(a_in, x_dv_in, y_dv_in); | ||
std::valarray<float> p_trk_2 = calcPVec(b_in, x_dv_in, y_dv_in); | ||
std::valarray<float> p_tot = p_trk_1 + p_trk_2; | ||
p_mag = TMath::Sqrt(pow(p_tot[0], 2) + pow(p_tot[1], 2)); | ||
if (((p_trk_1[0] != 0.0) || (p_trk_2[1] != 0.0)) && ((p_trk_2[0] != 0.0) || (p_trk_2[1] != 0.0))) { | ||
openingAngle = | ||
(p_trk_1[0] * p_trk_2[0] + p_trk_1[1] * p_trk_2[1]) / | ||
(TMath::Sqrt(pow(p_trk_1[0], 2) + pow(p_trk_1[1], 2)) * TMath::Sqrt(pow(p_trk_2[0], 2) + pow(p_trk_2[1], 2))); | ||
} | ||
R_T = TMath::Sqrt(pow(x_dv_in, 2) + pow(y_dv_in, 2)); | ||
if ((R_T != 0.0) && ((p_tot[0] != 0.0) || (p_tot[1] != 0.0))) { | ||
cos_T = (p_tot[0] * x_dv_in + p_tot[1] * y_dv_in) / (R_T * TMath::Sqrt(pow(p_tot[0], 2) + pow(p_tot[1], 2))); | ||
} | ||
phi = atan2(p_tot[1], p_tot[0]); | ||
d_T = fabs(cos(phi) * y_dv_in - sin(phi) * x_dv_in); | ||
p2_mag = pow(a_in.pt, 2) + pow(b_in.pt, 2); | ||
delta_z = fabs(a_in.z(x_dv_in, y_dv_in) - b_in.z(x_dv_in, y_dv_in)); | ||
} | ||
|
||
Vertex_Parameters(){}; | ||
~Vertex_Parameters(){}; | ||
}; | ||
|
||
class DisplacedVertexProducer : public edm::global::EDProducer<> { | ||
public: | ||
explicit DisplacedVertexProducer(const edm::ParameterSet&); | ||
~DisplacedVertexProducer() override = default; | ||
typedef TTTrack<Ref_Phase2TrackerDigi_> L1TTTrackType; | ||
|
||
private: | ||
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; | ||
double FloatPtFromBits(const L1TTTrackType &) const; | ||
double FloatEtaFromBits(const L1TTTrackType &) const; | ||
double FloatPhiFromBits(const L1TTTrackType &) const; | ||
double FloatZ0FromBits(const L1TTTrackType &) const; | ||
double FloatD0FromBits(const L1TTTrackType &) const; | ||
int ChargeFromBits(const L1TTTrackType &) const; | ||
|
||
private: | ||
const edm::EDGetTokenT<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> ttTrackMCTruthToken_; | ||
const edm::EDGetTokenT<std::vector<TTTrack<Ref_Phase2TrackerDigi_>>> trackToken_; | ||
const edm::EDGetTokenT<std::vector<TTTrack<Ref_Phase2TrackerDigi_>>> trackGTTToken_; | ||
const std::string outputTrackCollectionName_; | ||
const std::string outputTrackEmulationCollectionName_; | ||
const std::string model_; | ||
const bool runEmulation_; | ||
const edm::ParameterSet cutSet_; | ||
const double chi2rzMax_, promptMVAMin_, ptMin_, etaMax_, dispD0Min_, promptMVADispTrackMin_, | ||
overlapEtaMin_, overlapEtaMax_; | ||
const int overlapNStubsMin_; | ||
const double diskEtaMin_, diskD0Min_, barrelD0Min_, RTMin_, RTMax_; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any extant Track Trigger classes for handling vertexes that would be good to centralize this class with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal preference would be to get rid of this class as well and use these variables directly in the DisplacedVertexProducer class to avoid another vertex-like class, but I also see why you may want to set it up like this. It doesn't quite follow how the other GTT object classes are set up so I would suggest maybe changing this class to a struct instead as it's really only holding variables to be used by DisplacedVertexProducer.
There is no vertex class that has all of these variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this (class => functions) be done as a "code improvement" in a second stage? L1 is requesting that this PR is merged in order for @ryanm124 to show the plots at an upcoming conference. that request is to have code to be able to reproduce the results, and it seems code improvements wouldn't be necessary for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok with me for this comment. There does seem to be some potential logic issues brought up in other comments that might need more addressing. And at minimum, the code checks and formatting should be done and It doesn't seem like the formatting has been applied. You should run these two commands:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code formatting has been applied 93ea36d