CMS 3D CMS Logo

TPFastJetProducer.cc
Go to the documentation of this file.
1 // //
3 // Producer of TPFastJets, //
4 // Cluster tracking particles using fastjet //
5 // //
6 // Created by: Claire Savard (Oct. 2023) //
7 // //
9 
10 // system include files
11 #include <memory>
12 
13 // user include files
26 
27 // L1 objects
33 
34 // truth object
37 
38 // geometry
41 
42 #include <fastjet/JetDefinition.hh>
43 
44 #include <string>
45 #include "TMath.h"
46 #include "TH1.h"
47 
48 using namespace l1t;
49 using namespace edm;
50 using namespace std;
51 
53 // //
54 // CLASS DEFINITION //
55 // //
57 
59 public:
60  explicit TPFastJetProducer(const edm::ParameterSet&);
61  ~TPFastJetProducer() override = default;
62 
63  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
64 
65 private:
66  void produce(edm::Event&, const edm::EventSetup&) override;
67 
68  // track selection criteria
69  const float tpPtMin_;
70  const float tpEtaMax_;
71  const float tpZMax_;
72  const int tpNStubMin_;
73  const int tpNStubLayerMin_;
74  const float coneSize_; // Use anti-kt with this cone size
75 
79 };
80 
81 // constructor
83  : tpPtMin_((float)iConfig.getParameter<double>("tp_ptMin")),
84  tpEtaMax_((float)iConfig.getParameter<double>("tp_etaMax")),
85  tpZMax_((float)iConfig.getParameter<double>("tp_zMax")),
86  tpNStubMin_((int)iConfig.getParameter<int>("tp_nStubMin")),
87  tpNStubLayerMin_((int)iConfig.getParameter<int>("tp_nStubLayerMin")),
88  coneSize_((float)iConfig.getParameter<double>("coneSize")),
89  trackingParticleToken_(
90  consumes<std::vector<TrackingParticle>>(iConfig.getParameter<edm::InputTag>("TrackingParticleInputTag"))),
91  ttStubMCTruthToken_(consumes<TTStubAssociationMap<Ref_Phase2TrackerDigi_>>(
92  iConfig.getParameter<edm::InputTag>("MCTruthStubInputTag"))),
94  produces<TkJetCollection>("TPFastJets");
95 }
96 
97 // producer
99  std::unique_ptr<TkJetCollection> TPFastJets(new TkJetCollection);
100 
101  // Tracking particles
102  edm::Handle<std::vector<TrackingParticle>> TrackingParticleHandle;
103  iEvent.getByToken(trackingParticleToken_, TrackingParticleHandle);
104  std::vector<TrackingParticle>::const_iterator iterTP;
105 
106  // MC truth association maps
108  iEvent.getByToken(ttStubMCTruthToken_, MCTruthTTStubHandle);
109 
110  // Tracker Topology
111  const TrackerTopology& tTopo = iSetup.getData(tTopoToken_);
112 
113  fastjet::JetDefinition jet_def(fastjet::antikt_algorithm, coneSize_);
114  std::vector<fastjet::PseudoJet> JetInputs;
115 
116  // loop over tps
117  unsigned int this_tp = 0;
118  for (iterTP = TrackingParticleHandle->begin(); iterTP != TrackingParticleHandle->end(); iterTP++) {
119  edm::Ptr<TrackingParticle> tp_ptr(TrackingParticleHandle, this_tp);
120  this_tp++;
121 
122  std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
123  theStubRefs = MCTruthTTStubHandle->findTTStubRefs(tp_ptr);
124  int nStubTP = (int)theStubRefs.size();
125 
126  // how many layers/disks have stubs?
127  int hasStubInLayer[11] = {0};
128  for (auto& theStubRef : theStubRefs) {
129  DetId detid(theStubRef->getDetId());
130 
131  int layer = -1;
132  if (detid.subdetId() == StripSubdetector::TOB) {
133  layer = static_cast<int>(tTopo.layer(detid)) - 1; //fill in array as entries 0-5
134  } else if (detid.subdetId() == StripSubdetector::TID) {
135  layer = static_cast<int>(tTopo.layer(detid)) + 5; //fill in array as entries 6-10
136  }
137 
138  //treat genuine stubs separately (==2 is genuine, ==1 is not)
139  if (MCTruthTTStubHandle->findTrackingParticlePtr(theStubRef).isNull() && hasStubInLayer[layer] < 2)
140  hasStubInLayer[layer] = 1;
141  else
142  hasStubInLayer[layer] = 2;
143  }
144 
145  int nStubLayerTP = 0;
146  for (int isum : hasStubInLayer) {
147  if (isum >= 1)
148  nStubLayerTP += 1;
149  }
150 
151  // tp quality cuts to match L1 tracks
152  if (iterTP->pt() < tpPtMin_)
153  continue;
154  if (fabs(iterTP->eta()) > tpEtaMax_)
155  continue;
156  if (nStubTP < tpNStubMin_)
157  continue;
158  if (nStubLayerTP < tpNStubLayerMin_)
159  continue;
160  if (fabs(iterTP->z0()) > tpZMax_)
161  continue;
162  if (iterTP->charge() == 0.) // extra check that all tps are charged
163  continue;
164  if (iterTP->eventId().event() > 0) // only select hard interaction tps
165  continue;
166 
167  fastjet::PseudoJet psuedoJet(iterTP->px(), iterTP->py(), iterTP->pz(), iterTP->energy());
168  JetInputs.push_back(psuedoJet); // input tps for clustering
169  JetInputs.back().set_user_index(this_tp - 1); // save tp index in the collection
170  } // end loop over tps
171 
172  fastjet::ClusterSequence cs(JetInputs, jet_def); // define the output jet collection
173  std::vector<fastjet::PseudoJet> JetOutputs =
174  fastjet::sorted_by_pt(cs.inclusive_jets(0)); // output jet collection, pT-ordered
175 
176  for (unsigned int ijet = 0; ijet < JetOutputs.size(); ++ijet) {
178  JetOutputs[ijet].px(), JetOutputs[ijet].py(), JetOutputs[ijet].pz(), JetOutputs[ijet].modp());
179  float sumpt = 0;
180  float avgZ = 0;
181  std::vector<edm::Ptr<TrackingParticle>> tpPtrs;
182  std::vector<fastjet::PseudoJet> fjConstituents = fastjet::sorted_by_pt(cs.constituents(JetOutputs[ijet]));
183 
184  for (unsigned int i = 0; i < fjConstituents.size(); ++i) {
185  auto index = fjConstituents[i].user_index();
186  edm::Ptr<TrackingParticle> tpPtr(TrackingParticleHandle, index);
187  tpPtrs.push_back(tpPtr); // tracking particles in the jet
188  sumpt = sumpt + tpPtr->pt();
189  avgZ = avgZ + tpPtr->pt() * tpPtr->z0();
190  }
191  avgZ = avgZ / sumpt;
193  std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>> dummyL1TrackPtrs; // can't create TkJet with tp references
194  TkJet tpJet(jetP4, dummyL1TrackPtrs, avgZ, fjConstituents.size(), 0, 0, 0, false);
195  TPFastJets->push_back(tpJet);
196  } //end loop over Jet Outputs
197 
198  iEvent.put(std::move(TPFastJets), "TPFastJets");
199 }
200 
202  // The following says we do not know what parameters are allowed so do no validation
204  desc.add<edm::InputTag>("TrackingParticleInputTag", edm::InputTag("mix", "MergedTrackTruth"));
205  desc.add<edm::InputTag>("MCTruthStubInputTag", edm::InputTag("TTStubAssociatorFromPixelDigis", "StubAccepted"));
206  desc.add<double>("tp_ptMin", 2.0);
207  desc.add<double>("tp_etaMax", 2.4);
208  desc.add<double>("tp_zMax", 15.);
209  desc.add<int>("tp_nStubMin", 4);
210  desc.add<int>("tp_nStubLayerMin", 4);
211  desc.add<double>("coneSize", 0.4);
212  descriptions.add("tpFastJets", desc);
213 }
214 
215 //define this as a plug-in
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
delete x;
Definition: CaloConfig.h:22
double isum
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
unsigned int layer(const DetId &id) const
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static constexpr auto TOB
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
Definition: DetId.h:17
edm::EDGetTokenT< TTStubAssociationMap< Ref_Phase2TrackerDigi_ > > ttStubMCTruthToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
edm::EDGetTokenT< std::vector< TrackingParticle > > trackingParticleToken_
Monte Carlo truth information used for tracking validation.
double pt() const
Transverse momentum. Note this is taken from the first SimTrack only.
std::vector< TkJet > TkJetCollection
Definition: TkJetFwd.h:20
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
Stores association of Truth Particles (TP) to L1 Track-Trigger Stubs.
static constexpr auto TID
def move(src, dest)
Definition: eostools.py:511
double z0() const
z0 parameter
void produce(edm::Event &, const edm::EventSetup &) override
TPFastJetProducer(const edm::ParameterSet &)