Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-26 00:19:29

0001 // Original Author:  Emmanuelle Perez,40 1-A28,+41227671915,
0002 //         Created:  Tue Nov 12 17:03:19 CET 2013
0003 // Modified by Emily MacDonald, 30 Nov 2018
0004 // Modified by Christopher Brown 27 March 2021
0005 
0006 // system include files
0007 #include <algorithm>
0008 #include <memory>
0009 
0010 // user include files
0011 #include "FWCore/Framework/interface/Frameworkfwd.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "DataFormats/L1TCorrelator/interface/TkEtMiss.h"
0015 #include "DataFormats/L1TCorrelator/interface/TkEtMissFwd.h"
0016 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0017 #include "DataFormats/Math/interface/LorentzVector.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/EventSetup.h"
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 #include "FWCore/Framework/interface/global/EDProducer.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 
0025 using namespace l1t;
0026 
0027 class L1TrackerEtMissProducer : public edm::global::EDProducer<> {
0028 public:
0029   typedef TTTrack<Ref_Phase2TrackerDigi_> L1TTTrackType;
0030   typedef std::vector<L1TTTrackType> L1TTTrackCollectionType;
0031   typedef edm::RefVector<L1TTTrackCollectionType> L1TTTrackRefCollectionType;
0032 
0033   explicit L1TrackerEtMissProducer(const edm::ParameterSet&);
0034   ~L1TrackerEtMissProducer() override = default;
0035 
0036 private:
0037   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0038 
0039   // ----------member data ---------------------------
0040   const edm::EDGetTokenT<L1TTTrackRefCollectionType> trackToken_;
0041   const edm::EDGetTokenT<L1TTTrackRefCollectionType> vtxAssocTrackToken_;
0042   const std::string L1MetCollectionName;
0043   const float maxPt_;       // in GeV
0044   const int highPtTracks_;  // saturate or truncate
0045   const bool debug_;
0046 };
0047 
0048 // constructor
0049 L1TrackerEtMissProducer::L1TrackerEtMissProducer(const edm::ParameterSet& iConfig)
0050     : trackToken_(consumes<L1TTTrackRefCollectionType>(iConfig.getParameter<edm::InputTag>("L1TrackInputTag"))),
0051       vtxAssocTrackToken_(
0052           consumes<L1TTTrackRefCollectionType>(iConfig.getParameter<edm::InputTag>("L1TrackAssociatedInputTag"))),
0053       L1MetCollectionName(iConfig.getParameter<std::string>("L1MetCollectionName")),
0054       maxPt_(iConfig.getParameter<double>("maxPt")),
0055       highPtTracks_(iConfig.getParameter<int>("highPtTracks")),
0056       debug_(iConfig.getParameter<bool>("debug")) {
0057   produces<TkEtMissCollection>(L1MetCollectionName);
0058 }
0059 
0060 void L1TrackerEtMissProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0061   using namespace edm;
0062 
0063   std::unique_ptr<TkEtMissCollection> METCollection(new TkEtMissCollection);
0064 
0065   edm::Handle<L1TTTrackRefCollectionType> L1TTTrackHandle;
0066   iEvent.getByToken(trackToken_, L1TTTrackHandle);
0067 
0068   edm::Handle<L1TTTrackRefCollectionType> L1TTTrackAssociatedHandle;
0069   iEvent.getByToken(vtxAssocTrackToken_, L1TTTrackAssociatedHandle);
0070 
0071   if (!L1TTTrackHandle.isValid()) {
0072     LogError("L1TrackerEtMissProducer") << "\nWarning: L1TTTrackCollection not found in the event. Exit\n";
0073     return;
0074   }
0075 
0076   if (!L1TTTrackAssociatedHandle.isValid()) {
0077     LogError("L1TrackerEtMissProducer") << "\nWarning: L1TTTrackAssociatedCollection not found in the event. Exit\n";
0078     return;
0079   }
0080 
0081   float sumPx = 0;
0082   float sumPy = 0;
0083   float etTot = 0;
0084   double sumPx_PU = 0;
0085   double sumPy_PU = 0;
0086   double etTot_PU = 0;
0087 
0088   int numqualitytracks = 0;
0089   int numassoctracks = 0;
0090 
0091   for (const auto& track : *L1TTTrackHandle) {
0092     float pt = track->momentum().perp();
0093     float phi = track->momentum().phi();
0094 
0095     if (maxPt_ > 0 && pt > maxPt_) {
0096       if (highPtTracks_ == 0)
0097         continue;  // ignore these very high PT tracks: truncate
0098       if (highPtTracks_ == 1)
0099         pt = maxPt_;  // saturate
0100     }
0101 
0102     numqualitytracks++;
0103 
0104     if (std::find(L1TTTrackAssociatedHandle->begin(), L1TTTrackAssociatedHandle->end(), track) !=
0105         L1TTTrackAssociatedHandle->end()) {
0106       numassoctracks++;
0107       sumPx += pt * cos(phi);
0108       sumPy += pt * sin(phi);
0109       etTot += pt;
0110     } else {  // PU sums
0111       sumPx_PU += pt * cos(phi);
0112       sumPy_PU += pt * sin(phi);
0113       etTot_PU += pt;
0114     }
0115   }  // end loop over tracks
0116 
0117   float et = sqrt(sumPx * sumPx + sumPy * sumPy);
0118   double etphi = atan2(sumPy, sumPx);
0119 
0120   math::XYZTLorentzVector missingEt(-sumPx, -sumPy, 0, et);
0121 
0122   if (debug_) {
0123     edm::LogVerbatim("L1TrackerEtMissProducer") << "====Global Pt===="
0124                                                 << "\n"
0125                                                 << "Px: " << sumPx << "| Py: " << sumPy << "\n"
0126                                                 << "====MET==="
0127                                                 << "\n"
0128                                                 << "MET: " << et << "| Phi: " << etphi << "\n"
0129 
0130                                                 << "# Tracks after quality cuts: " << L1TTTrackHandle->size() << "\n"
0131                                                 << "# Tacks after additional highPt Cuts: " << numqualitytracks << "\n"
0132                                                 << "# Tracks associated to vertex: " << numassoctracks << "\n"
0133                                                 << "========================================================"
0134                                                 << "\n";
0135   }
0136 
0137   int ibx = 0;
0138   METCollection->push_back(TkEtMiss(missingEt, TkEtMiss::kMET, etphi, numassoctracks, ibx));
0139 
0140   iEvent.put(std::move(METCollection), L1MetCollectionName);
0141 }  // end producer
0142 
0143 DEFINE_FWK_MODULE(L1TrackerEtMissProducer);