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

GBDT-Based Displaced Vertex Producer #1257

Open
wants to merge 23 commits into
base: phase2-l1t-integration-14_0_0_pre3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0255f1a
Adding Displaced Vertexing Producer
ryanm124 May 8, 2024
24413dc
Modifying track quality MVA inputs for displaced tracks
ryanm124 May 8, 2024
acde98b
Reverting changes to prompt track quality BDT, adding fix to MVA scor…
ryanm124 May 13, 2024
0dde2bd
Adding newest BDT model file and displaced vertexing analyzer
ryanm124 May 14, 2024
dbf8525
Adding back tanL to prompt MVA and adding check for extended tracking…
ryanm124 May 17, 2024
d95ffe9
Adding option to run displaced vertexing in ntupler maker, reverting …
ryanm124 May 19, 2024
ca83bc8
Removing Displaced Vertexing Analyzer macro
ryanm124 May 28, 2024
63cdfcf
Changing BDT model to slimmed version, moved track selection to track…
ryanm124 Jul 1, 2024
93ea36d
Adding check for number of mother partucles in ntuple maker and fixed…
ryanm124 Jul 1, 2024
0786d1f
Removing unused class methods
ryanm124 Jul 2, 2024
8f39115
Changing track selection producer collection output name and correcti…
ryanm124 Jul 3, 2024
34584c5
Adding displaced vertexing track selector to schedule and code format…
ryanm124 Jul 5, 2024
bff29e9
Removing track selection module and moving cuts to python config. Fix…
ryanm124 Jul 31, 2024
0a9fccc
Adding RT cut to producer and adding isHard boolean to ntuple
ryanm124 Sep 18, 2024
a9e384e
Adding displaced vertexing emulation
ryanm124 Oct 17, 2024
7e435db
Adding file to convert xgboost model to conifer
ryanm124 Oct 17, 2024
41431b6
Adding plotting script
ryanm124 Oct 22, 2024
3245d7a
Final changes for emulation, changing bit widths for BDT input to ap_…
ryanm124 Nov 4, 2024
6459a2c
Adding do plot check for vertex plots
ryanm124 Nov 14, 2024
61a3c52
Cleaning up code
ryanm124 Nov 14, 2024
a71a93f
Deleting unused models and scripts
ryanm124 Nov 14, 2024
b4ed6f3
Moving BDT to seperate PR in data directory
ryanm124 Nov 14, 2024
04c75c3
Removing track selection producer changes and removing displaced trac…
ryanm124 Nov 18, 2024
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
82 changes: 82 additions & 0 deletions DataFormats/L1Trigger/interface/DisplacedVertex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#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"

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 firstIndexPt, int secondIndexPt, int inTraj, float d_T, float R_T, float cos_T, float del_Z, float x, float y, float z, float openingAngle, float parentPt, int delIndexPt, bool isReal): firstIndexTrk_(firstIndexTrk), secondIndexTrk_(secondIndexTrk), firstIndexPt_(firstIndexPt), secondIndexPt_(secondIndexPt), 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), delIndexPt_(delIndexPt), 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 firstIndexPt() const { return firstIndexPt_; }
int secondIndexPt() const { return secondIndexPt_; }
int inTraj() const { return inTraj_; }
float del_Z() const { return del_Z_; }
int delIndexPt() const { return delIndexPt_; }
bool isReal() const { return isReal_; }
float score() const { return score_; }
private:
int firstIndexTrk_;
int secondIndexTrk_;
int firstIndexPt_;
int secondIndexPt_;
int inTraj_;
float d_T_;
float R_T_;
float cos_T_;
float del_Z_;
float x_;
float y_;
float z_;
float openingAngle_;
float parentPt_;
int delIndexPt_;
bool isReal_;
float score_;
};

typedef std::vector<DisplacedTrackVertex> DisplacedTrackVertexCollection;
}

#endif
1 change: 1 addition & 0 deletions DataFormats/L1Trigger/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
#include "DataFormats/Common/interface/RefToBase.h"
#include "DataFormats/L1Trigger/interface/P2GTCandidate.h"
#include "DataFormats/L1Trigger/interface/P2GTAlgoBlock.h"
#include "DataFormats/L1Trigger/interface/DisplacedVertex.h"
5 changes: 5 additions & 0 deletions DataFormats/L1Trigger/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@
<class name="edm::Wrapper<l1t::VertexWordCollection>"/>
<class name="edm::Ref<l1t::VertexWordCollection>" />

<class name="l1t::DisplacedTrackVertex">
</class>
<class name="std::vector<l1t::DisplacedTrackVertex>"/>
<class name="edm::Wrapper<std::vector<l1t::DisplacedTrackVertex> >"/>

<class name="l1t::TkJetWord" ClassVersion="4">
<version ClassVersion="4" checksum="2346039066"/>
<version ClassVersion="3" checksum="3521396532"/>
Expand Down
264 changes: 264 additions & 0 deletions L1Trigger/L1TTrackMatch/interface/DisplacedVertexProducer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
#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 "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 "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h"
#include "SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h"
#include "TMath.h"
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <valarray>

using namespace std;

class Track_Parameters

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to create this new class? Can you just use the TTTrack class?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was convenient to define a class which contains the parameters of the projection of the track on the transverse plane just so I only calculate it once per track. Is there a preference for using functions or class methods for this type of thing?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preference is not necessarily for functions versus class members, but for condensing the number of in use classes to try and consolidate code and functionality.

There are at least a few things conceptually similar between TTrack and it's parent class TTTrack_TrackWord and this track parameters class. It would be good if the track trigger developers could try to centralize as many common elements to most types of tracks in one place if possible

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what would you recommend? I could try inheriting from TTrack in my class and only add the extra functionality I need or I could try to do without an additional class at all.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My recommendation would be to remove this class entirely, pass the L1 track into these functions and use the TTTrack/TTTrack_Word variables directly, and similarly for everywhere else this is used like here.

{
public:
float pt;
float d0;
float dxy = -99999;
float z0;
float eta;
float phi;
float charge;
float rho;
int index;
int pdgid = -99999;
float vx;
float vy;
float vz;
Track_Parameters* tp;
float x0;
float y0;
int nstubs;
float chi2rphi;
float chi2rz;
float bendchi2;
float MVA1;
float MVA2;

float dist_calc(float x_dv, float y_dv, float x, float y){
dxy = TMath::Sqrt((x_dv-x)*(x_dv-x) + (y_dv-y)*(y_dv-y));
return dxy;
}
float x(float phi_T=0){
return (-charge * rho * TMath::Sin(phi - charge*phi_T) + (d0 + charge * rho) * TMath::Sin(phi));
}
float y(float phi_T=0){
return ( charge * rho * TMath::Cos(phi - charge*phi_T) - (d0 + charge * rho) * TMath::Cos(phi));
}
float z(float phi_T=0){
float theta = 2 * TMath::ATan(TMath::Exp(-eta));
return (z0 + rho*phi_T/TMath::Tan(theta));
}
float deltaPhi_T(Double_t phi1, Double_t phi2)
{
Double_t dPhi = phi1 - phi2;
if (dPhi >= TMath::Pi())
dPhi -= 2. * TMath::Pi();
if (dPhi <= -TMath::Pi())
dPhi += 2. * TMath::Pi();
return dPhi;
}
float phi_T(float x, float y){
float num = x - (d0 + charge * rho) * TMath::Sin(phi);
float den = y + (d0 + charge * rho) * TMath::Cos(phi);
return ((phi-TMath::ATan2(num,-den))/charge);
}
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, int pdgid_in, float vx_in, float vy_in, float vz_in, float charge_in=0, int index_in=-1, Track_Parameters* tp_in=nullptr, int nstubs_in=0, float chi2rphi_in=0, float chi2rz_in=0, float bendchi2_in=0, float MVA1_in=0, float MVA2_in=0)
{
pt = pt_in;
d0 = d0_in;
z0 = z0_in;
eta = eta_in;
phi = phi_in;
if(charge_in > 0){
charge = 1;
}
else if (charge_in < 0){
charge = -1;
}
else{
charge = 0;
}
index = index_in;
pdgid = pdgid_in;
vx = vx_in;
vy = vy_in;
vz = vz_in;
tp = tp_in;
rho = fabs(1/charge_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;
MVA2 = MVA2_in;
}
Track_Parameters(){};
~Track_Parameters(){};
};

constexpr bool operator==(const Track_Parameters* lhs, const Track_Parameters& rhs)
{
return (lhs->pt==rhs.pt && lhs->d0==rhs.d0 && lhs->z0==rhs.z0 && lhs->eta==rhs.eta && lhs->phi==rhs.phi);
}
constexpr bool operator==(const Track_Parameters& lhs, const Track_Parameters* rhs)
{
return (lhs.pt==rhs->pt && lhs.d0==rhs->d0 && lhs.z0==rhs->z0 && lhs.eta==rhs->eta && lhs.phi==rhs->phi);
}
constexpr bool operator==(const Track_Parameters& lhs, const Track_Parameters& rhs)
{
return (lhs.pt==rhs.pt && lhs.d0==rhs.d0 && lhs.z0==rhs.z0 && lhs.eta==rhs.eta && lhs.phi==rhs.phi);
}

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;
}
p_vec /= TMath::Sqrt(pow(p_vec[0],2)+pow(p_vec[1],2));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that the arguments to this vector will end up as 0? This will causes errors if so.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check for this in this commit 63cdfcf

p_vec *= a.pt;
return p_vec;
}

class Vertex_Parameters
{
public:

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?

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.

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?

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:

scram build code-checks
scram build code-format

Copy link
Author

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

Double_t x_dv;
Double_t y_dv;
Double_t z_dv;
float score;
Track_Parameters a;
Track_Parameters b;
int inTraj;
bool matched = false;
std::vector<Track_Parameters> tracks = {};
float p_mag;
float p2_mag;
float openingAngle;
float R_T;
float cos_T;
float alpha_T;
float d_T;
float chi2rphidofSum;
float chi2rzdofSum;
float bendchi2Sum;
float MVA1Sum;
float MVA2Sum;
int numStubsSum;
float delta_z;
float delta_eta;
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, float score_in=-1, int inTraj_in=4):
a(a_in),
b(b_in)
{
x_dv = x_dv_in;
y_dv = y_dv_in;
z_dv = z_dv_in;
score = score_in;
tracks.push_back(a_in);
tracks.push_back(b_in);
inTraj = inTraj_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));
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)));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question about possible division by zero errors here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check for this in this commit 63cdfcf

R_T = TMath::Sqrt(pow(x_dv_in,2)+pow(y_dv_in,2));
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)));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check for this in this commit 63cdfcf

alpha_T = acos(cos_T);
phi = atan2(p_tot[1],p_tot[0]);
d_T = fabs(cos(phi)*y_dv_in-sin(phi)*x_dv_in);
int ndof_1 = 2 * a_in.nstubs - 5;
float chi2rphidof_1 = a_in.chi2rphi / ndof_1;
float chi2rzdof_1 = a_in.chi2rz / ndof_1;
float bendchi2_1 = a_in.bendchi2;
int ndof_2 = 2 * b_in.nstubs - 5;
float chi2rphidof_2 = b_in.chi2rphi / ndof_2;
float chi2rzdof_2 = b_in.chi2rz / ndof_2;
float bendchi2_2 = b_in.bendchi2;
chi2rphidofSum = chi2rphidof_1 + chi2rphidof_2;
chi2rzdofSum = chi2rzdof_1 + chi2rzdof_2;
bendchi2Sum = bendchi2_1 + bendchi2_2;
MVA1Sum = a_in.MVA1 + b_in.MVA1;
MVA2Sum = a_in.MVA2 + b_in.MVA2;
numStubsSum = a_in.nstubs + b_in.nstubs;
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));
delta_eta = fabs(a_in.eta-b_in.eta);
}

void addTrack(Track_Parameters trk){
tracks.push_back(trk);
std::valarray<float> p_tot = {0,0};
for(auto track : tracks){
p_tot+= calcPVec(track,x_dv,y_dv);
}
p_mag = TMath::Sqrt(pow(p_tot[0],2)+pow(p_tot[1],2));
cos_T = (p_tot[0]*x_dv+p_tot[1]*y_dv)/(R_T*TMath::Sqrt(pow(p_tot[0],2)+pow(p_tot[1],2)));
alpha_T = acos(cos_T);
phi = atan2(p_tot[1],p_tot[0]);
d_T = fabs(cos(phi)*y_dv-sin(phi)*x_dv);
int ndof = 2 * trk.nstubs - 5;
float chi2rphidof = trk.chi2rphi / ndof;
float chi2rzdof = trk.chi2rz / ndof;
float bendchi2 = trk.bendchi2;
chi2rphidofSum+= chi2rphidof;
chi2rzdofSum+= chi2rzdof;
bendchi2Sum+= bendchi2;
numStubsSum+= trk.nstubs;
p2_mag+= pow(trk.pt,2);
MVA1Sum+= trk.MVA1;
MVA2Sum+= trk.MVA2;
}

Vertex_Parameters(){};
~Vertex_Parameters(){};
};

constexpr bool operator==(const Vertex_Parameters& lhs, const Vertex_Parameters& rhs)
{
return (lhs.x_dv==rhs.x_dv && lhs.y_dv==rhs.y_dv && lhs.z_dv==rhs.z_dv);
}

class DisplacedVertexProducer : public edm::global::EDProducer<> {
public:
explicit DisplacedVertexProducer(const edm::ParameterSet&);
~DisplacedVertexProducer() override {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
~DisplacedVertexProducer() override {}
~DisplacedVertexProducer() override = default;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented this


private:
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;

private:
const edm::EDGetTokenT<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> ttTrackMCTruthToken_;
const edm::EDGetTokenT<std::vector<TTTrack<Ref_Phase2TrackerDigi_> >> trackToken_;
const std::string outputTrackCollectionName_;
const std::string qualityAlgorithm_;
const std::string ONNXmodel_;
const std::string ONNXInputName_;
const std::vector<std::string> featureNames_;
std::unique_ptr<cms::Ort::ONNXRuntime> runTime_;
};

#endif
Loading