File indexing completed on 2024-09-07 04:37:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include "DataFormats/Common/interface/Ref.h"
0021 #include "DataFormats/Common/interface/RefVector.h"
0022 #include "DataFormats/L1TCorrelator/interface/TkJet.h"
0023 #include "DataFormats/L1TCorrelator/interface/TkJetFwd.h"
0024 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0025 #include "DataFormats/L1TrackTrigger/interface/TTTrack.h"
0026 #include "DataFormats/L1Trigger/interface/VertexWord.h"
0027
0028
0029 #include "FWCore/Framework/interface/Frameworkfwd.h"
0030 #include "FWCore/Framework/interface/stream/EDProducer.h"
0031 #include "FWCore/Framework/interface/Event.h"
0032 #include "FWCore/Framework/interface/EventSetup.h"
0033 #include "FWCore/Framework/interface/MakerMacros.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 #include "FWCore/Utilities/interface/StreamID.h"
0036 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0037
0038
0039 #include "L1TrackJetClustering.h"
0040
0041 using namespace std;
0042 using namespace edm;
0043 using namespace l1t;
0044 using namespace l1ttrackjet;
0045
0046 class L1TrackJetProducer : public stream::EDProducer<> {
0047 public:
0048 explicit L1TrackJetProducer(const ParameterSet &);
0049 ~L1TrackJetProducer() override = default;
0050 typedef TTTrack<Ref_Phase2TrackerDigi_> L1TTTrackType;
0051 typedef vector<L1TTTrackType> L1TTTrackCollectionType;
0052 typedef edm::RefVector<L1TTTrackCollectionType> L1TTTrackRefCollectionType;
0053 static void fillDescriptions(ConfigurationDescriptions &descriptions);
0054
0055 private:
0056 void produce(Event &, const EventSetup &) override;
0057
0058
0059
0060 vector<Ptr<L1TTTrackType>> L1TrkPtrs_;
0061 const float trkZMax_;
0062 const float trkPtMax_;
0063 const float trkEtaMax_;
0064 const int lowpTJetMinTrackMultiplicity_;
0065 const float lowpTJetThreshold_;
0066 const int highpTJetMinTrackMultiplicity_;
0067 const float highpTJetThreshold_;
0068 const int zBins_;
0069 const int etaBins_;
0070 const int phiBins_;
0071 const double minTrkJetpT_;
0072 float zStep_;
0073 float etaStep_;
0074 float phiStep_;
0075 const bool displaced_;
0076 const float d0CutNStubs4_;
0077 const float d0CutNStubs5_;
0078 const int nDisplacedTracks_;
0079
0080 const EDGetTokenT<L1TTTrackRefCollectionType> trackToken_;
0081 };
0082
0083 L1TrackJetProducer::L1TrackJetProducer(const ParameterSet &iConfig)
0084 : trkZMax_(iConfig.getParameter<double>("trk_zMax")),
0085 trkPtMax_(iConfig.getParameter<double>("trk_ptMax")),
0086 trkEtaMax_(iConfig.getParameter<double>("trk_etaMax")),
0087 lowpTJetMinTrackMultiplicity_(iConfig.getParameter<int>("lowpTJetMinTrackMultiplicity")),
0088 lowpTJetThreshold_(iConfig.getParameter<double>("lowpTJetThreshold")),
0089 highpTJetMinTrackMultiplicity_(iConfig.getParameter<int>("highpTJetMinTrackMultiplicity")),
0090 highpTJetThreshold_(iConfig.getParameter<double>("highpTJetThreshold")),
0091 zBins_(iConfig.getParameter<int>("zBins")),
0092 etaBins_(iConfig.getParameter<int>("etaBins")),
0093 phiBins_(iConfig.getParameter<int>("phiBins")),
0094 minTrkJetpT_(iConfig.getParameter<double>("minTrkJetpT")),
0095 displaced_(iConfig.getParameter<bool>("displaced")),
0096 d0CutNStubs4_(iConfig.getParameter<double>("d0_cutNStubs4")),
0097 d0CutNStubs5_(iConfig.getParameter<double>("d0_cutNStubs5")),
0098 nDisplacedTracks_(iConfig.getParameter<int>("nDisplacedTracks")),
0099 trackToken_(consumes<L1TTTrackRefCollectionType>(iConfig.getParameter<InputTag>("L1TrackInputTag"))) {
0100 zStep_ = 2.0 * trkZMax_ / (zBins_ + 1);
0101 etaStep_ = 2.0 * trkEtaMax_ / etaBins_;
0102 phiStep_ = 2 * M_PI / phiBins_;
0103
0104 if (displaced_)
0105 produces<TkJetCollection>("L1TrackJetsExtended");
0106 else
0107 produces<TkJetCollection>("L1TrackJets");
0108 }
0109
0110 void L1TrackJetProducer::produce(Event &iEvent, const EventSetup &iSetup) {
0111 unique_ptr<TkJetCollection> L1TrackJetProducer(new TkJetCollection);
0112
0113
0114 edm::Handle<L1TTTrackRefCollectionType> TTTrackHandle;
0115 iEvent.getByToken(trackToken_, TTTrackHandle);
0116
0117 L1TrkPtrs_.clear();
0118
0119
0120 for (unsigned int this_l1track = 0; this_l1track < TTTrackHandle->size(); this_l1track++) {
0121 edm::Ptr<L1TTTrackType> trkPtr(TTTrackHandle, this_l1track);
0122 L1TrkPtrs_.push_back(trkPtr);
0123 }
0124
0125
0126 if (L1TrkPtrs_.empty()) {
0127 if (displaced_)
0128 iEvent.put(std::move(L1TrackJetProducer), "L1TrackJetsExtended");
0129 else
0130 iEvent.put(std::move(L1TrackJetProducer), "L1TrackJets");
0131 return;
0132 }
0133
0134 MaxZBin mzb;
0135 mzb.znum = -1;
0136 mzb.nclust = -1;
0137 mzb.ht = -1;
0138
0139
0140 EtaPhiBin epbins_default[phiBins_][etaBins_];
0141 float phi = -1.0 * M_PI;
0142 for (int i = 0; i < phiBins_; ++i) {
0143 float eta = -1.0 * trkEtaMax_;
0144 for (int j = 0; j < etaBins_; ++j) {
0145 epbins_default[i][j].phi = (phi + (phi + phiStep_)) / 2.0;
0146 epbins_default[i][j].eta = (eta + (eta + etaStep_)) / 2.0;
0147 eta += etaStep_;
0148 }
0149 phi += phiStep_;
0150 }
0151
0152
0153 std::vector<float> zmins, zmaxs;
0154 for (int zbin = 0; zbin < zBins_; zbin++) {
0155 zmins.push_back(-1.0 * trkZMax_ + zStep_ * zbin);
0156 zmaxs.push_back(-1.0 * trkZMax_ + zStep_ * zbin + zStep_ * 2);
0157 }
0158
0159
0160 std::vector<std::vector<EtaPhiBin>> L1clusters;
0161 L1clusters.reserve(phiBins_);
0162 std::vector<EtaPhiBin> L2clusters;
0163
0164
0165 for (int i = 0; i < phiBins_; ++i) {
0166 for (int j = 0; j < etaBins_; ++j) {
0167 epbins_default[i][j].pTtot = 0;
0168 epbins_default[i][j].used = false;
0169 epbins_default[i][j].ntracks = 0;
0170 epbins_default[i][j].nxtracks = 0;
0171 epbins_default[i][j].trackidx.clear();
0172 }
0173 }
0174
0175 for (unsigned int zbin = 0; zbin < zmins.size(); ++zbin) {
0176
0177 float zmin = zmins[zbin];
0178 float zmax = zmaxs[zbin];
0179 EtaPhiBin epbins[phiBins_][etaBins_];
0180 std::copy(&epbins_default[0][0], &epbins_default[0][0] + phiBins_ * etaBins_, &epbins[0][0]);
0181
0182
0183 L1clusters.clear();
0184 L2clusters.clear();
0185
0186
0187 for (unsigned int k = 0; k < L1TrkPtrs_.size(); ++k) {
0188 float trkZ = L1TrkPtrs_[k]->z0();
0189 if (zmax < trkZ)
0190 continue;
0191 if (zmin > trkZ)
0192 continue;
0193 if (zbin == 0 && zmin == trkZ)
0194 continue;
0195 float trkpt = L1TrkPtrs_[k]->momentum().perp();
0196 float trketa = L1TrkPtrs_[k]->momentum().eta();
0197 float trkphi = L1TrkPtrs_[k]->momentum().phi();
0198 float trkd0 = L1TrkPtrs_[k]->d0();
0199 int trknstubs = (int)L1TrkPtrs_[k]->getStubRefs().size();
0200 for (int i = 0; i < phiBins_; ++i) {
0201 for (int j = 0; j < etaBins_; ++j) {
0202 float eta_min = epbins[i][j].eta - etaStep_ / 2.0;
0203 float eta_max = epbins[i][j].eta + etaStep_ / 2.0;
0204 float phi_min = epbins[i][j].phi - phiStep_ / 2.0;
0205 float phi_max = epbins[i][j].phi + phiStep_ / 2.0;
0206
0207 if ((trketa < eta_min) || (trketa > eta_max) || (trkphi < phi_min) || (trkphi > phi_max))
0208 continue;
0209
0210 if (trkpt < trkPtMax_)
0211 epbins[i][j].pTtot += trkpt;
0212 else
0213 epbins[i][j].pTtot += trkPtMax_;
0214 if ((std::abs(trkd0) > d0CutNStubs5_ && trknstubs >= 5 && d0CutNStubs5_ >= 0) ||
0215 (trknstubs == 4 && std::abs(trkd0) > d0CutNStubs4_ && d0CutNStubs4_ >= 0))
0216 epbins[i][j].nxtracks += 1;
0217 epbins[i][j].trackidx.push_back(k);
0218 ++epbins[i][j].ntracks;
0219 }
0220 }
0221 }
0222
0223
0224 for (int phibin = 0; phibin < phiBins_; ++phibin) {
0225 L1clusters.push_back(L1_clustering<EtaPhiBin, float, float, float>(epbins[phibin], etaBins_, etaStep_));
0226 }
0227
0228
0229 L2clusters = L2_clustering<EtaPhiBin, float, float, float>(L1clusters, phiBins_, phiStep_, etaStep_);
0230
0231
0232 float sum_pt = 0;
0233 for (unsigned int k = 0; k < L2clusters.size(); ++k) {
0234 if (L2clusters[k].pTtot > lowpTJetThreshold_ && L2clusters[k].ntracks < lowpTJetMinTrackMultiplicity_)
0235 continue;
0236 if (L2clusters[k].pTtot > highpTJetThreshold_ && L2clusters[k].ntracks < highpTJetMinTrackMultiplicity_)
0237 continue;
0238 if (L2clusters[k].pTtot > minTrkJetpT_)
0239 sum_pt += L2clusters[k].pTtot;
0240 }
0241
0242 if (sum_pt < mzb.ht)
0243 continue;
0244
0245
0246 mzb.ht = sum_pt;
0247 mzb.znum = zbin;
0248 mzb.clusters = L2clusters;
0249 mzb.nclust = L2clusters.size();
0250 mzb.zbincenter = (zmin + zmax) / 2.0;
0251 }
0252
0253
0254 vector<Ptr<L1TTTrackType>> L1TrackAssocJet;
0255 for (unsigned int j = 0; j < mzb.clusters.size(); ++j) {
0256 float jetEta = mzb.clusters[j].eta;
0257 float jetPhi = mzb.clusters[j].phi;
0258 float jetPt = mzb.clusters[j].pTtot;
0259 float jetPx = jetPt * cos(jetPhi);
0260 float jetPy = jetPt * sin(jetPhi);
0261 float jetPz = jetPt * sinh(jetEta);
0262 float jetP = jetPt * cosh(jetEta);
0263 int totalDisptrk = mzb.clusters[j].nxtracks;
0264 bool isDispJet = (totalDisptrk >= nDisplacedTracks_);
0265
0266 math::XYZTLorentzVector jetP4(jetPx, jetPy, jetPz, jetP);
0267 L1TrackAssocJet.clear();
0268 for (unsigned int itrk = 0; itrk < mzb.clusters[j].trackidx.size(); itrk++)
0269 L1TrackAssocJet.push_back(L1TrkPtrs_[mzb.clusters[j].trackidx[itrk]]);
0270
0271 TkJet trkJet(jetP4, L1TrackAssocJet, mzb.zbincenter, mzb.clusters[j].ntracks, 0, totalDisptrk, 0, isDispJet);
0272
0273 L1TrackJetProducer->push_back(trkJet);
0274 }
0275
0276 std::sort(L1TrackJetProducer->begin(), L1TrackJetProducer->end(), [](auto &a, auto &b) { return a.pt() > b.pt(); });
0277 if (displaced_)
0278 iEvent.put(std::move(L1TrackJetProducer), "L1TrackJetsExtended");
0279 else
0280 iEvent.put(std::move(L1TrackJetProducer), "L1TrackJets");
0281 }
0282
0283 void L1TrackJetProducer::fillDescriptions(ConfigurationDescriptions &descriptions) {
0284 ParameterSetDescription desc;
0285 desc.add<edm::InputTag>(
0286 "L1TrackInputTag", edm::InputTag("l1tTrackVertexAssociationProducerForJets", "Level1TTTracksSelectedAssociated"));
0287 desc.add<double>("trk_zMax", 15.0);
0288 desc.add<double>("trk_ptMax", 200.0);
0289 desc.add<double>("trk_etaMax", 2.4);
0290 desc.add<double>("minTrkJetpT", -1.0);
0291 desc.add<int>("etaBins", 24);
0292 desc.add<int>("phiBins", 27);
0293 desc.add<int>("zBins", 1);
0294 desc.add<double>("d0_cutNStubs4", -1);
0295 desc.add<double>("d0_cutNStubs5", -1);
0296 desc.add<int>("lowpTJetMinTrackMultiplicity", 2);
0297 desc.add<double>("lowpTJetThreshold", 50.0);
0298 desc.add<int>("highpTJetMinTrackMultiplicity", 3);
0299 desc.add<double>("highpTJetThreshold", 100.0);
0300 desc.add<bool>("displaced", false);
0301 desc.add<int>("nDisplacedTracks", 2);
0302 descriptions.add("l1tTrackJets", desc);
0303 }
0304
0305
0306 DEFINE_FWK_MODULE(L1TrackJetProducer);