CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1TrackFastJetProducer.cc
Go to the documentation of this file.
1 // //
3 // Producer of TkJet, //
4 // Cluster L1 tracks using fastjet //
5 // //
7 
8 // system include files
9 #include <memory>
10 
11 // user include files
25 
26 // L1 objects
31 
32 // geometry
35 
36 #include <fastjet/JetDefinition.hh>
37 
38 #include <string>
39 #include "TMath.h"
40 #include "TH1.h"
41 
42 using namespace l1t;
43 using namespace edm;
44 using namespace std;
45 
47 // //
48 // CLASS DEFINITION //
49 // //
51 
53 public:
55  typedef std::vector<L1TTTrackType> L1TTTrackCollectionType;
56 
58  ~L1TrackFastJetProducer() override;
59 
60  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
61 
62 private:
63  //void beginJob() override;
64  void produce(edm::Event&, const edm::EventSetup&) override;
65  //void endJob() override;
66 
67  // track selection criteria
68  float trkZMax_; // in [cm]
69  float trkChi2dofMax_; // maximum track chi2dof
70  double trkBendChi2Max_; // maximum track bendchi2
71  float trkPtMin_; // in [GeV]
72  float trkEtaMax_; // in [rad]
73  int trkNStubMin_; // minimum number of stubs
74  int trkNPSStubMin_; // minimum number of PS stubs
75  double deltaZ0Cut_; // save with |L1z-z0| < maxZ0
76  double coneSize_; // Use anti-kt with this cone size
80  bool displaced_; //use prompt/displaced tracks
81 
85 };
86 
87 // constructor
89  : trackToken_(consumes<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > >(
90  iConfig.getParameter<edm::InputTag>("L1TrackInputTag"))),
91  pvToken_(consumes<TkPrimaryVertexCollection>(iConfig.getParameter<edm::InputTag>("L1PrimaryVertexTag"))),
93  trkZMax_ = (float)iConfig.getParameter<double>("trk_zMax");
94  trkChi2dofMax_ = (float)iConfig.getParameter<double>("trk_chi2dofMax");
95  trkBendChi2Max_ = iConfig.getParameter<double>("trk_bendChi2Max");
96  trkPtMin_ = (float)iConfig.getParameter<double>("trk_ptMin");
97  trkEtaMax_ = (float)iConfig.getParameter<double>("trk_etaMax");
98  trkNStubMin_ = (int)iConfig.getParameter<int>("trk_nStubMin");
99  trkNPSStubMin_ = (int)iConfig.getParameter<int>("trk_nPSStubMin");
100  deltaZ0Cut_ = (float)iConfig.getParameter<double>("deltaZ0Cut");
101  coneSize_ = (float)iConfig.getParameter<double>("coneSize");
102  doTightChi2_ = iConfig.getParameter<bool>("doTightChi2");
103  trkPtTightChi2_ = (float)iConfig.getParameter<double>("trk_ptTightChi2");
104  trkChi2dofTightChi2_ = (float)iConfig.getParameter<double>("trk_chi2dofTightChi2");
105  displaced_ = iConfig.getParameter<bool>("displaced");
106  if (displaced_)
107  produces<TkJetCollection>("L1TrackFastJetsExtended");
108  else
109  produces<TkJetCollection>("L1TrackFastJets");
110 }
111 
112 // destructor
114 
115 // producer
117  std::unique_ptr<TkJetCollection> L1TrackFastJets(new TkJetCollection);
118 
119  // L1 tracks
121  iEvent.getByToken(trackToken_, TTTrackHandle);
122  std::vector<TTTrack<Ref_Phase2TrackerDigi_> >::const_iterator iterL1Track;
123 
124  // Tracker Topology
125  const TrackerTopology& tTopo = iSetup.getData(tTopoToken_);
126 
127  edm::Handle<TkPrimaryVertexCollection> TkPrimaryVertexHandle;
128  iEvent.getByToken(pvToken_, TkPrimaryVertexHandle);
129 
130  fastjet::JetDefinition jet_def(fastjet::antikt_algorithm, coneSize_);
131  std::vector<fastjet::PseudoJet> JetInputs;
132 
133  float recoVtx = TkPrimaryVertexHandle->begin()->zvertex();
134  unsigned int this_l1track = 0;
135  for (iterL1Track = TTTrackHandle->begin(); iterL1Track != TTTrackHandle->end(); iterL1Track++) {
136  this_l1track++;
137  float trk_pt = iterL1Track->momentum().perp();
138  float trk_z0 = iterL1Track->z0();
139  float trk_chi2dof = iterL1Track->chi2Red();
140  float trk_bendchi2 = iterL1Track->stubPtConsistency();
141  std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_> >, TTStub<Ref_Phase2TrackerDigi_> > >
142  theStubs = iterL1Track->getStubRefs();
143  int trk_nstub = (int)theStubs.size();
144 
145  if (fabs(trk_z0) > trkZMax_)
146  continue;
147  if (fabs(iterL1Track->momentum().eta()) > trkEtaMax_)
148  continue;
149  if (trk_pt < trkPtMin_)
150  continue;
151  if (trk_nstub < trkNStubMin_)
152  continue;
153  if (trk_chi2dof > trkChi2dofMax_)
154  continue;
155  if (trk_bendchi2 > trkBendChi2Max_)
156  continue;
157  if (doTightChi2_ && (trk_pt > trkPtTightChi2_ && trk_chi2dof > trkChi2dofTightChi2_))
158  continue;
159 
160  int trk_nPS = 0;
161  for (int istub = 0; istub < trk_nstub; istub++) {
162  DetId detId(theStubs.at(istub)->getDetId());
163  bool tmp_isPS = false;
164  if (detId.det() == DetId::Detector::Tracker) {
165  if (detId.subdetId() == StripSubdetector::TOB && tTopo.tobLayer(detId) <= 3)
166  tmp_isPS = true;
167  else if (detId.subdetId() == StripSubdetector::TID && tTopo.tidRing(detId) <= 9)
168  tmp_isPS = true;
169  }
170  if (tmp_isPS)
171  trk_nPS++;
172  }
173  if (trk_nPS < trkNPSStubMin_)
174  continue;
175  if (fabs(recoVtx - trk_z0) > deltaZ0Cut_)
176  continue;
177 
178  fastjet::PseudoJet psuedoJet(iterL1Track->momentum().x(),
179  iterL1Track->momentum().y(),
180  iterL1Track->momentum().z(),
181  iterL1Track->momentum().mag());
182  JetInputs.push_back(psuedoJet); // input tracks for clustering
183  JetInputs.back().set_user_index(this_l1track - 1); // save track index in the collection
184  } // end loop over tracks
185 
186  fastjet::ClusterSequence cs(JetInputs, jet_def); // define the output jet collection
187  std::vector<fastjet::PseudoJet> JetOutputs =
188  fastjet::sorted_by_pt(cs.inclusive_jets(0)); // output jet collection, pT-ordered
189 
190  for (unsigned int ijet = 0; ijet < JetOutputs.size(); ++ijet) {
192  JetOutputs[ijet].px(), JetOutputs[ijet].py(), JetOutputs[ijet].pz(), JetOutputs[ijet].modp());
193  float sumpt = 0;
194  float avgZ = 0;
195  std::vector<edm::Ptr<L1TTTrackType> > L1TrackPtrs;
196  std::vector<fastjet::PseudoJet> fjConstituents = fastjet::sorted_by_pt(cs.constituents(JetOutputs[ijet]));
197 
198  for (unsigned int i = 0; i < fjConstituents.size(); ++i) {
199  auto index = fjConstituents[i].user_index();
200  edm::Ptr<L1TTTrackType> trkPtr(TTTrackHandle, index);
201  L1TrackPtrs.push_back(trkPtr); // L1Tracks in the jet
202  sumpt = sumpt + trkPtr->momentum().perp();
203  avgZ = avgZ + trkPtr->momentum().perp() * trkPtr->z0();
204  }
205  avgZ = avgZ / sumpt;
207  TkJet trkJet(jetP4, jetRef, L1TrackPtrs, avgZ);
208  L1TrackFastJets->push_back(trkJet);
209  } //end loop over Jet Outputs
210 
211  if (displaced_)
212  iEvent.put(std::move(L1TrackFastJets), "L1TrackFastJetsExtended");
213  else
214  iEvent.put(std::move(L1TrackFastJets), "L1TrackFastJets");
215 }
216 
217 //void L1TrackFastJetProducer::beginJob() {}
218 
219 //void L1TrackFastJetProducer::endJob() {}
220 
222  //The following says we do not know what parameters are allowed so do no validation
223  // Please change this to state exactly what you do use, even if it is no parameters
225  desc.setUnknown();
226  descriptions.addDefault(desc);
227 }
228 
229 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
unsigned int tidRing(const DetId &id) const
JetDefinition jet_def
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unique_ptr< ClusterSequence > cs
void produce(edm::Event &, const edm::EventSetup &) override
L1TrackFastJetProducer(const edm::ParameterSet &)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< L1TTTrackType > L1TTTrackCollectionType
def move
Definition: eostools.py:511
static constexpr auto TOB
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
Definition: DetId.h:17
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
const edm::EDGetTokenT< std::vector< TTTrack< Ref_Phase2TrackerDigi_ > > > trackToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
std::vector< TkPrimaryVertex > TkPrimaryVertexCollection
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< TkJet > TkJetCollection
Definition: TkJetFwd.h:20
edm::EDGetTokenT< TkPrimaryVertexCollection > pvToken_
static constexpr auto TID
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
tTopoToken_
unsigned int tobLayer(const DetId &id) const