CMS 3D CMS Logo

L1TrackFastJetProducer.cc
Go to the documentation of this file.
1 // //
3 // Producer of TrackFastJet, //
4 // Cluster L1 tracks using fastjet //
5 // //
6 // Updates: Claire Savard (claire.savard@colorado.edu), Nov. 2023 //
7 // //
9 
10 // system include files
11 #include <memory>
12 
13 // user include files
27 
28 // L1 objects
33 
34 // geometry
37 
38 #include <fastjet/JetDefinition.hh>
39 
40 #include <string>
41 #include "TMath.h"
42 #include "TH1.h"
43 
44 using namespace l1t;
45 using namespace edm;
46 using namespace std;
47 
49 // //
50 // CLASS DEFINITION //
51 // //
53 
55 public:
57  typedef std::vector<L1TTTrackType> L1TTTrackCollectionType;
59 
61  ~L1TrackFastJetProducer() override;
62 
63  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
64 
65 private:
66  void produce(edm::Event&, const edm::EventSetup&) override;
67 
68  // jet configurations
69  const double coneSize_; // Use anti-kt with this cone size
70  const bool displaced_; //use prompt/displaced tracks
71 
73 };
74 
75 // constructor
77  : coneSize_((float)iConfig.getParameter<double>("coneSize")),
78  displaced_(iConfig.getParameter<bool>("displaced")),
79  trackToken_(consumes<L1TTTrackRefCollectionType>(iConfig.getParameter<InputTag>("L1TrackInputTag"))) {
80  if (displaced_)
81  produces<TkJetCollection>("L1TrackFastJetsExtended");
82  else
83  produces<TkJetCollection>("L1TrackFastJets");
84 }
85 
86 // destructor
88 
89 // producer
91  std::unique_ptr<TkJetCollection> L1TrackFastJets(new TkJetCollection);
92 
93  // L1 tracks
95  iEvent.getByToken(trackToken_, TTTrackHandle);
96 
97  fastjet::JetDefinition jet_def(fastjet::antikt_algorithm, coneSize_);
98  std::vector<fastjet::PseudoJet> JetInputs;
99 
100  for (unsigned int this_l1track = 0; this_l1track < TTTrackHandle->size(); this_l1track++) {
101  edm::Ptr<L1TTTrackType> iterL1Track(TTTrackHandle, this_l1track);
102 
103  fastjet::PseudoJet psuedoJet(iterL1Track->momentum().x(),
104  iterL1Track->momentum().y(),
105  iterL1Track->momentum().z(),
106  iterL1Track->momentum().mag());
107  JetInputs.push_back(psuedoJet); // input tracks for clustering
108  JetInputs.back().set_user_index(this_l1track); // save track index in the collection
109  } // end loop over tracks
110 
111  fastjet::ClusterSequence cs(JetInputs, jet_def); // define the output jet collection
112  std::vector<fastjet::PseudoJet> JetOutputs =
113  fastjet::sorted_by_pt(cs.inclusive_jets(0)); // output jet collection, pT-ordered
114 
115  for (unsigned int ijet = 0; ijet < JetOutputs.size(); ++ijet) {
117  JetOutputs[ijet].px(), JetOutputs[ijet].py(), JetOutputs[ijet].pz(), JetOutputs[ijet].modp());
118  float sumpt = 0;
119  float avgZ = 0;
120  std::vector<edm::Ptr<L1TTTrackType> > L1TrackPtrs;
121  std::vector<fastjet::PseudoJet> fjConstituents = fastjet::sorted_by_pt(cs.constituents(JetOutputs[ijet]));
122 
123  for (unsigned int i = 0; i < fjConstituents.size(); ++i) {
124  auto index = fjConstituents[i].user_index();
125  edm::Ptr<L1TTTrackType> trkPtr(TTTrackHandle, index);
126  L1TrackPtrs.push_back(trkPtr); // L1Tracks in the jet
127  sumpt = sumpt + trkPtr->momentum().perp();
128  avgZ = avgZ + trkPtr->momentum().perp() * trkPtr->z0();
129  }
130  avgZ = avgZ / sumpt;
132  TkJet trkJet(jetP4, jetRef, L1TrackPtrs, avgZ);
133  L1TrackFastJets->push_back(trkJet);
134  } //end loop over Jet Outputs
135 
136  if (displaced_)
137  iEvent.put(std::move(L1TrackFastJets), "L1TrackFastJetsExtended");
138  else
139  iEvent.put(std::move(L1TrackFastJets), "L1TrackFastJets");
140 }
141 
143  //The following says we do not know what parameters are allowed so do no validation
145  desc.add<edm::InputTag>(
146  "L1PVertexInputTag",
147  edm::InputTag("l1tTrackVertexAssociationProducerForJets", "Level1TTTracksSelectedAssociated"));
148  desc.add<double>("coneSize", 0.5);
149  desc.add<bool>("displaced", false);
150 }
151 
152 //define this as a plug-in
T perp() const
Definition: PV3DBase.h:69
const EDGetTokenT< L1TTTrackRefCollectionType > trackToken_
T z() const
Definition: PV3DBase.h:61
delete x;
Definition: CaloConfig.h:22
GlobalVector momentum() const
Track momentum.
Definition: TTTrack.h:295
void produce(edm::Event &, const edm::EventSetup &) override
L1TrackFastJetProducer(const edm::ParameterSet &)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
int iEvent
Definition: GenABIO.cc:224
std::vector< L1TTTrackType > L1TTTrackCollectionType
T mag() const
Definition: PV3DBase.h:64
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::RefVector< L1TTTrackCollectionType > L1TTTrackRefCollectionType
HLT enums.
double z0() const
Track z0.
Definition: TTTrack.h:330
std::vector< TkJet > TkJetCollection
Definition: TkJetFwd.h:20
def move(src, dest)
Definition: eostools.py:511