Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-01-29 23:44:57

0001 // Package:    SiOuterTracker
0002 // Class:      SiOuterTracker
0003 //
0004 // Author: Emily MacDonald (emily.kaelyn.macdonald@cern.ch)
0005 
0006 // system include files
0007 #include <memory>
0008 #include <vector>
0009 #include <numeric>
0010 #include <iostream>
0011 #include <fstream>
0012 #include <string>
0013 
0014 // user include files
0015 #include "DataFormats/Common/interface/DetSetVector.h"
0016 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0017 #include "DataFormats/Common/interface/Ptr.h"
0018 #include "DataFormats/Common/interface/Ref.h"
0019 #include "DataFormats/L1TrackTrigger/interface/TTCluster.h"
0020 #include "DataFormats/L1TrackTrigger/interface/TTStub.h"
0021 #include "DataFormats/L1TrackTrigger/interface/TTTrack.h"
0022 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0023 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0024 
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0027 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0028 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0029 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0030 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0031 #include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h"
0032 #include "SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h"
0033 #include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h"
0034 
0035 #include "DQMOffline/L1Trigger/interface/L1TPhase2OuterTrackerTkMET.h"
0036 
0037 // constructors and destructor
0038 L1TPhase2OuterTrackerTkMET::L1TPhase2OuterTrackerTkMET(const edm::ParameterSet& iConfig)
0039     : conf_(iConfig), m_topoToken(esConsumes()) {
0040   topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
0041   ttTrackToken_ =
0042       consumes<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > >(conf_.getParameter<edm::InputTag>("TTTracksTag"));
0043   pvToken = consumes<l1t::VertexWordCollection>(conf_.getParameter<edm::InputTag>("L1VertexInputTag"));
0044 
0045   maxZ0 = conf_.getParameter<double>("maxZ0");
0046   DeltaZ = conf_.getParameter<double>("DeltaZ");
0047   chi2dofMax = conf_.getParameter<double>("chi2dofMax");
0048   bendchi2Max = conf_.getParameter<double>("bendchi2Max");
0049   minPt = conf_.getParameter<double>("minPt");
0050   nStubsmin = iConfig.getParameter<int>("nStubsmin");
0051   nStubsPSmin = iConfig.getParameter<int>("nStubsPSmin");
0052   maxPt = conf_.getParameter<double>("maxPt");
0053   maxEta = conf_.getParameter<double>("maxEta");
0054   HighPtTracks = iConfig.getParameter<int>("HighPtTracks");
0055 }
0056 
0057 L1TPhase2OuterTrackerTkMET::~L1TPhase2OuterTrackerTkMET() {
0058   // do anything here that needs to be done at desctruction time
0059   // (e.g. close files, deallocate resources etc.)
0060 }
0061 
0062 // member functions
0063 
0064 // ------------ method called for each event  ------------
0065 void L1TPhase2OuterTrackerTkMET::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0066   // L1 Primaries
0067   edm::Handle<l1t::VertexWordCollection> L1VertexHandle;
0068   iEvent.getByToken(pvToken, L1VertexHandle);
0069 
0070   edm::Handle<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > > TTTrackHandle;
0071   iEvent.getByToken(ttTrackToken_, TTTrackHandle);
0072 
0073   // for PS stubs
0074   // Tracker Topology
0075   const TrackerTopology* const tTopo = &iSetup.getData(m_topoToken);
0076 
0077   // Adding protection
0078   if (!TTTrackHandle.isValid()) {
0079     edm::LogWarning("L1TPhase2OuterTrackerTkMET") << "cant find tracks" << std::endl;
0080     return;
0081   }
0082   if (!L1VertexHandle.isValid()) {
0083     edm::LogWarning("L1TPhase2OuterTrackerTkMET") << "cant find vertex" << std::endl;
0084     return;
0085   }
0086   float sumPx = 0;
0087   float sumPy = 0;
0088   double sumPx_PU = 0;
0089   double sumPy_PU = 0;
0090   int nTracks_counter = 0;
0091 
0092   float zVTX = L1VertexHandle->begin()->z0();
0093   unsigned int tkCnt = 0;
0094   for (const auto& trackIter : *TTTrackHandle) {
0095     edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_> > tempTrackPtr(TTTrackHandle, tkCnt++);  /// Make the pointer
0096     float pt = tempTrackPtr->momentum().perp();
0097     float phi = tempTrackPtr->momentum().phi();
0098     float eta = tempTrackPtr->momentum().eta();
0099     std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_> >, TTStub<Ref_Phase2TrackerDigi_> > >
0100         theStubs = trackIter.getStubRefs();
0101     int nstubs = (int)theStubs.size();
0102 
0103     float chi2dof = tempTrackPtr->chi2Red();
0104     float bendchi2 = tempTrackPtr->stubPtConsistency();
0105     float z0 = tempTrackPtr->z0();
0106 
0107     if (pt < minPt || fabs(z0) > maxZ0 || fabs(eta) > maxEta || chi2dof > chi2dofMax || bendchi2 > bendchi2Max)
0108       continue;
0109     if (maxPt > 0 && pt > maxPt) {
0110       if (HighPtTracks == 0)
0111         continue;  // ignore these very high PT tracks: truncate
0112       if (HighPtTracks == 1)
0113         pt = maxPt;  // saturate
0114     }
0115 
0116     int nPS = 0.;  // number of stubs in PS modules
0117     // loop over the stubs
0118     for (unsigned int istub = 0; istub < (unsigned int)theStubs.size(); istub++) {
0119       DetId detId(theStubs.at(istub)->getDetId());
0120       if (detId.det() == DetId::Detector::Tracker) {
0121         if ((detId.subdetId() == StripSubdetector::TOB && tTopo->tobLayer(detId) <= 3) ||
0122             (detId.subdetId() == StripSubdetector::TID && tTopo->tidRing(detId) <= 9))
0123           nPS++;
0124       }
0125     }
0126 
0127     if (nstubs < nStubsmin || nPS < nStubsPSmin)
0128       continue;
0129 
0130     // construct deltaZ cut to be based on track eta
0131     if (fabs(eta) >= 0 && fabs(eta) < 0.7)
0132       DeltaZ = 0.4;
0133     else if (fabs(eta) >= 0.7 && fabs(eta) < 1.0)
0134       DeltaZ = 0.6;
0135     else if (fabs(eta) >= 1.0 && fabs(eta) < 1.2)
0136       DeltaZ = 0.76;
0137     else if (fabs(eta) >= 1.2 && fabs(eta) < 1.6)
0138       DeltaZ = 1.0;
0139     else if (fabs(eta) >= 1.6 && fabs(eta) < 2.0)
0140       DeltaZ = 1.7;
0141     else if (fabs(eta) >= 2.0 && fabs(eta) <= 2.4)
0142       DeltaZ = 2.2;
0143 
0144     if (fabs(z0 - zVTX) <= DeltaZ) {
0145       nTracks_counter++;
0146       Track_Pt->Fill(pt);
0147       Track_NStubs->Fill(nstubs);
0148       Track_NPSstubs->Fill(nPS);
0149       Track_Eta->Fill(eta);
0150       Track_VtxZ->Fill(z0);
0151       Track_Chi2Dof->Fill(chi2dof);
0152       Track_BendChi2->Fill(bendchi2);
0153 
0154       sumPx += pt * cos(phi);
0155       sumPy += pt * sin(phi);
0156     } else {  // PU sums
0157       sumPx_PU += pt * cos(phi);
0158       sumPy_PU += pt * sin(phi);
0159     }
0160   }  // end loop over tracks
0161 
0162   Track_N->Fill(nTracks_counter);
0163   float et = sqrt(sumPx * sumPx + sumPy * sumPy);
0164   double etmiss_PU = sqrt(sumPx_PU * sumPx_PU + sumPy_PU * sumPy_PU);
0165 
0166   math::XYZTLorentzVector missingEt(-sumPx, -sumPy, 0, et);
0167 
0168   TkMET_QualityCuts->Fill(missingEt.Pt());
0169   TkMET_PU->Fill(etmiss_PU);
0170 
0171 }  // end of method
0172 
0173 // ------------ method called once each job just before starting event loop  ------------
0174 //Creating all histograms for DQM file output
0175 void L1TPhase2OuterTrackerTkMET::bookHistograms(DQMStore::IBooker& iBooker,
0176                                                 edm::Run const& run,
0177                                                 edm::EventSetup const& es) {
0178   std::string HistoName;
0179   iBooker.setCurrentFolder(topFolderName_ + "/TkMET_Tracks/");
0180 
0181   // Num of L1Tracks in tkMET selection
0182   HistoName = "Track_N";
0183   edm::ParameterSet psTrack_N = conf_.getParameter<edm::ParameterSet>("TH1_NTracks");
0184   Track_N = iBooker.book1D(HistoName,
0185                            HistoName,
0186                            psTrack_N.getParameter<int32_t>("Nbinsx"),
0187                            psTrack_N.getParameter<double>("xmin"),
0188                            psTrack_N.getParameter<double>("xmax"));
0189   Track_N->setAxisTitle("# L1 Tracks", 1);
0190   Track_N->setAxisTitle("# Events", 2);
0191 
0192   //Pt of the tracks
0193   edm::ParameterSet psTrack_Pt = conf_.getParameter<edm::ParameterSet>("TH1_Track_Pt");
0194   HistoName = "Track_Pt";
0195   Track_Pt = iBooker.book1D(HistoName,
0196                             HistoName,
0197                             psTrack_Pt.getParameter<int32_t>("Nbinsx"),
0198                             psTrack_Pt.getParameter<double>("xmin"),
0199                             psTrack_Pt.getParameter<double>("xmax"));
0200   Track_Pt->setAxisTitle("p_{T} [GeV]", 1);
0201   Track_Pt->setAxisTitle("# L1 Tracks", 2);
0202 
0203   //Eta
0204   edm::ParameterSet psTrack_Eta = conf_.getParameter<edm::ParameterSet>("TH1_Track_Eta");
0205   HistoName = "Track_Eta";
0206   Track_Eta = iBooker.book1D(HistoName,
0207                              HistoName,
0208                              psTrack_Eta.getParameter<int32_t>("Nbinsx"),
0209                              psTrack_Eta.getParameter<double>("xmin"),
0210                              psTrack_Eta.getParameter<double>("xmax"));
0211   Track_Eta->setAxisTitle("#eta", 1);
0212   Track_Eta->setAxisTitle("# L1 Tracks", 2);
0213 
0214   //VtxZ
0215   edm::ParameterSet psTrack_VtxZ = conf_.getParameter<edm::ParameterSet>("TH1_Track_VtxZ");
0216   HistoName = "Track_VtxZ";
0217   Track_VtxZ = iBooker.book1D(HistoName,
0218                               HistoName,
0219                               psTrack_VtxZ.getParameter<int32_t>("Nbinsx"),
0220                               psTrack_VtxZ.getParameter<double>("xmin"),
0221                               psTrack_VtxZ.getParameter<double>("xmax"));
0222   Track_VtxZ->setAxisTitle("L1 Track vertex position z [cm]", 1);
0223   Track_VtxZ->setAxisTitle("# L1 Tracks", 2);
0224 
0225   //chi2dof
0226   edm::ParameterSet psTrack_Chi2Dof = conf_.getParameter<edm::ParameterSet>("TH1_Track_Chi2Dof");
0227   HistoName = "Track_Chi2Dof";
0228   Track_Chi2Dof = iBooker.book1D(HistoName,
0229                                  HistoName,
0230                                  psTrack_Chi2Dof.getParameter<int32_t>("Nbinsx"),
0231                                  psTrack_Chi2Dof.getParameter<double>("xmin"),
0232                                  psTrack_Chi2Dof.getParameter<double>("xmax"));
0233   Track_Chi2Dof->setAxisTitle("L1 Track #chi^{2}/D.O.F.", 1);
0234   Track_Chi2Dof->setAxisTitle("# L1 Tracks", 2);
0235 
0236   //bend chi2
0237   edm::ParameterSet psTrack_BendChi2 = conf_.getParameter<edm::ParameterSet>("TH1_Track_BendChi2");
0238   HistoName = "Track_BendChi2";
0239   Track_BendChi2 = iBooker.book1D(HistoName,
0240                                   HistoName,
0241                                   psTrack_BendChi2.getParameter<int32_t>("Nbinsx"),
0242                                   psTrack_BendChi2.getParameter<double>("xmin"),
0243                                   psTrack_BendChi2.getParameter<double>("xmax"));
0244   Track_BendChi2->setAxisTitle("L1 Track Bend #chi^{2}", 1);
0245   Track_BendChi2->setAxisTitle("# L1 Tracks", 2);
0246 
0247   //nstubs
0248   edm::ParameterSet psTrack_NStubs = conf_.getParameter<edm::ParameterSet>("TH1_Track_NStubs");
0249   HistoName = "Track_NStubs";
0250   Track_NStubs = iBooker.book1D(HistoName,
0251                                 HistoName,
0252                                 psTrack_NStubs.getParameter<int32_t>("Nbinsx"),
0253                                 psTrack_NStubs.getParameter<double>("xmin"),
0254                                 psTrack_NStubs.getParameter<double>("xmax"));
0255   Track_NStubs->setAxisTitle("# L1 Stubs", 1);
0256   Track_NStubs->setAxisTitle("# L1 Tracks", 2);
0257 
0258   //nPSstubs
0259   edm::ParameterSet psTrack_NPSstubs = conf_.getParameter<edm::ParameterSet>("TH1_Track_NPSstubs");
0260   HistoName = "Track_NPSstubs";
0261   Track_NPSstubs = iBooker.book1D(HistoName,
0262                                   HistoName,
0263                                   psTrack_NPSstubs.getParameter<int32_t>("Nbinsx"),
0264                                   psTrack_NPSstubs.getParameter<double>("xmin"),
0265                                   psTrack_NPSstubs.getParameter<double>("xmax"));
0266   Track_NPSstubs->setAxisTitle("# PS Stubs", 1);
0267   Track_NPSstubs->setAxisTitle("# L1 Tracks", 2);
0268 
0269   iBooker.setCurrentFolder(topFolderName_ + "/TkMET");
0270   //loose tkMET
0271   edm::ParameterSet psTrack_TkMET = conf_.getParameter<edm::ParameterSet>("TH1_Track_TkMET");
0272   HistoName = "TkMET_QualityCuts";
0273   TkMET_QualityCuts = iBooker.book1D(HistoName,
0274                                      HistoName,
0275                                      psTrack_TkMET.getParameter<int32_t>("Nbinsx"),
0276                                      psTrack_TkMET.getParameter<double>("xmin"),
0277                                      psTrack_TkMET.getParameter<double>("xmax"));
0278   TkMET_QualityCuts->setAxisTitle("L1 Track MET [GeV]", 1);
0279   TkMET_QualityCuts->setAxisTitle("# Events", 2);
0280 
0281   //tkMET -- PU only
0282   HistoName = "TkMET_PU";
0283   TkMET_PU = iBooker.book1D(HistoName,
0284                             HistoName,
0285                             psTrack_TkMET.getParameter<int32_t>("Nbinsx"),
0286                             psTrack_TkMET.getParameter<double>("xmin"),
0287                             psTrack_TkMET.getParameter<double>("xmax"));
0288   TkMET_PU->setAxisTitle("L1 Track MET (PU only) [GeV]", 1);
0289   TkMET_PU->setAxisTitle("# Events", 2);
0290 }  //end of method
0291 
0292 DEFINE_FWK_MODULE(L1TPhase2OuterTrackerTkMET);