Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f64421c
Adding Displaced Vertexing Producer
ryanm124 May 8, 2024
e920470
Modifying track quality MVA inputs for displaced tracks
ryanm124 May 8, 2024
266bc11
Reverting changes to prompt track quality BDT, adding fix to MVA scor…
ryanm124 May 13, 2024
918ed68
Adding newest BDT model file and displaced vertexing analyzer
ryanm124 May 14, 2024
ee300da
Adding back tanL to prompt MVA and adding check for extended tracking…
ryanm124 May 17, 2024
ff6682c
Adding option to run displaced vertexing in ntupler maker, reverting …
ryanm124 May 19, 2024
89bdbb0
Removing Displaced Vertexing Analyzer macro
ryanm124 May 28, 2024
be063e6
Changing BDT model to slimmed version, moved track selection to track…
ryanm124 Jul 1, 2024
794bc0d
Adding check for number of mother partucles in ntuple maker and fixed…
ryanm124 Jul 1, 2024
84705ee
Removing unused class methods
ryanm124 Jul 2, 2024
7e10f75
Changing track selection producer collection output name and correcti…
ryanm124 Jul 3, 2024
04ac122
Adding displaced vertexing track selector to schedule and code format…
ryanm124 Jul 5, 2024
df499eb
Removing track selection module and moving cuts to python config. Fix…
ryanm124 Jul 31, 2024
d499bfd
Adding RT cut to producer and adding isHard boolean to ntuple
ryanm124 Sep 18, 2024
e1a92db
Adding displaced vertexing emulation
ryanm124 Oct 17, 2024
b1f566a
Adding file to convert xgboost model to conifer
ryanm124 Oct 17, 2024
9730cab
Adding plotting script
ryanm124 Oct 22, 2024
b2bddce
Final changes for emulation, changing bit widths for BDT input to ap_…
ryanm124 Nov 4, 2024
577dc3c
Adding do plot check for vertex plots
ryanm124 Nov 14, 2024
9ea648d
Cleaning up code
ryanm124 Nov 14, 2024
96b9459
Deleting unused models and scripts
ryanm124 Nov 14, 2024
d245a34
Moving BDT to seperate PR in data directory
ryanm124 Nov 14, 2024
1fe5509
Removing track selection producer changes and removing displaced trac…
ryanm124 Nov 18, 2024
07db5f5
Correcting TTTrack include
ryanm124 Feb 23, 2025
8b860f2
Removing repeated code in displaced vertex producer, removing unneede…
ryanm124 Feb 23, 2025
0a0ddc0
Flipping d0 sign due to sign difference in track word, adding conifer…
ryanm124 Feb 24, 2025
b14318c
Coding style changes
ryanm124 Feb 24, 2025
00b95db
Changing model location input from string to relative file path
ryanm124 Feb 26, 2025
9492234
Removed unused ancestry functions
ryanm124 Feb 26, 2025
2e21915
Adding hepmc to buildfile
ryanm124 Mar 2, 2025
49df272
Removing shift in input parameters now that conifer bug is resolved, …
ryanm124 Mar 28, 2025
276ecb9
Changed tmath functions to std equivalents. Reverted track quality pa…
ryanm124 Mar 28, 2025
b5b8115
Fixed non-zero momentum check in opening angle calculation
ryanm124 Mar 28, 2025
f36f616
Removed using std namespace, corrected track quality default values, …
ryanm124 Apr 1, 2025
ea1df83
Reverting d0 sign change in track unpacker and changing displaced ver…
ryanm124 Apr 1, 2025
7ec02ec
Appending displaced vertexing to schedule in config
ryanm124 Apr 8, 2025
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
104 changes: 104 additions & 0 deletions DataFormats/L1Trigger/interface/DisplacedVertex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#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() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

(As an aside: could probably remove this, but I don't think a modification is needed for a merge)

~DisplacedTrackVertex() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

(As an aside: could probably remove this, but I don't think a modification is needed for a merge)

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
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"
6 changes: 6 additions & 0 deletions DataFormats/L1Trigger/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@
<class name="edm::Wrapper<l1t::VertexWordCollection>"/>
<class name="edm::Ref<l1t::VertexWordCollection>" />

<class name="l1t::DisplacedTrackVertex" ClassVersion="3">
<version ClassVersion="3" checksum="698293252"/>
</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
2 changes: 2 additions & 0 deletions L1Trigger/L1TTrackMatch/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<use name="root"/>
<use name="rootrflx"/>
<use name="hls"/>
<use name="conifer"/>
<use name="hepmc"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CI was failing without these additions so they're necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say the reason for why hepmc seems to be needed should be understood first. L1Trigger code depending on HepMC sounds strange.

Ok, I see

#include "DataFormats/HepMCCandidate/interface/GenParticle.h"

but it doesn't seem to be used. If it would be, the proper place to add the dependence would be in
https://github.com/cms-sw/cmssw/blob/master/L1Trigger/L1TTrackMatch/test/BuildFile.xml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The plugins already depend on HepMC from the master branch build file: https://github.com/cms-sw/cmssw/blob/master/L1Trigger/L1TTrackMatch/plugins/BuildFile.xml. The only difference is my includes, which need HepMC, are in a header file which uses the build file here https://github.com/cms-sw/cmssw/blob/master/L1Trigger/L1TTrackMatch/BuildFile.xml

Copy link
Contributor Author

@ryanm124 ryanm124 Apr 1, 2025

Choose a reason for hiding this comment

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

I believe the include that needs HepMC is the TTtrack association here: https://github.com/ryanm124/cmssw/blob/f36f6162982a95dcd5b7acfa6609220e4855ac9b/L1Trigger/L1TTrackMatch/interface/DisplacedVertexProducer.h#L14. This was causing the CI to fail earlier although the logs are no longer accessible

<export>
<lib name="1"/>
</export>
176 changes: 176 additions & 0 deletions L1Trigger/L1TTrackMatch/interface/DisplacedVertexProducer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#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 "SimDataFormats/Associations/interface/TTTrackAssociationMap.h"
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <valarray>
#include <ap_int.h>
#include "conifer.h"

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 trackZAtVertex(float x, float y) {
float t = std::sinh(eta);
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor points but for code readability: you use the std namespace but specify the std::sinh here but then presumably are using std::pow below, but then using TMath::Sqrt and TMath::cos and sin. I suggest choosing one library for your maths functions and sticking with it throughout

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally we prefer std over TMath.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've replaced all the tmath functions with std ones in 276ecb9

float r = std::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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are half the parameters given a default value and the rest not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The defaults are never needed so I've removed them in 276ecb9

float d0_in,
float z0_in,
float eta_in,
float phi_in,
float rho_in,
int index_in,
int nstubs_in,
float chi2rphi_in,
float chi2rz_in,
float bendchi2_in,
float MVA1_in) {
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) * std::cos(phi - (charge * std::numbers::pi / 2));
y0 = (rho + charge * d0) * std::sin(phi - (charge * std::numbers::pi / 2));
nstubs = nstubs_in;
chi2rphi = chi2rphi_in;
chi2rz = chi2rz_in;
bendchi2 = bendchi2_in;
MVA1 = MVA1_in;
}
Track_Parameters() {};
Copy link
Contributor

Choose a reason for hiding this comment

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

(As an aside: could probably remove this, but I don't think a modification is needed for a merge)

~Track_Parameters() {};
Copy link
Contributor

Choose a reason for hiding this comment

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

(As an aside: could probably remove this, but I don't think a modification is needed for a merge)

};

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 /= std::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 = std::sqrt(pow(p_tot[0], 2) + pow(p_tot[1], 2));
if (((p_trk_1[0] != 0.0) || (p_trk_1[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]) /
(std::sqrt(pow(p_trk_1[0], 2) + pow(p_trk_1[1], 2)) * std::sqrt(pow(p_trk_2[0], 2) + pow(p_trk_2[1], 2)));
}
R_T = std::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 * std::sqrt(pow(p_tot[0], 2) + pow(p_tot[1], 2)));
}
phi = atan2(p_tot[1], p_tot[0]);
d_T = fabs(std::cos(phi) * y_dv_in - std::sin(phi) * x_dv_in);
p2_mag = pow(a_in.pt, 2) + pow(b_in.pt, 2);
delta_z = fabs(a_in.trackZAtVertex(x_dv_in, y_dv_in) - b_in.trackZAtVertex(x_dv_in, y_dv_in));
}

Vertex_Parameters() {};
Copy link
Contributor

Choose a reason for hiding this comment

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

(As an aside: could probably remove this, but I don't think a modification is needed for a merge)

~Vertex_Parameters() {};
Copy link
Contributor

Choose a reason for hiding this comment

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

(As an aside: could probably remove this, but I don't think a modification is needed for a merge)

};

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 outputVertexCollectionName_;
const edm::FileInPath 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
Loading