Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-26 02:43:44

0001 //////////////////////////////////////////////////////////////////////
0002 //                                                                  //
0003 //  Analyzer for making mini-ntuple for L1 track performance plots  //
0004 //                                                                  //
0005 //////////////////////////////////////////////////////////////////////
0006 
0007 ////////////////////
0008 // FRAMEWORK HEADERS
0009 #include "FWCore/PluginManager/interface/ModuleDef.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "FWCore/Utilities/interface/InputTag.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/ServiceRegistry/interface/Service.h"
0018 
0019 ///////////////////////
0020 // DATA FORMATS HEADERS
0021 #include "DataFormats/Common/interface/Handle.h"
0022 #include "DataFormats/Common/interface/Ref.h"
0023 
0024 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0025 #include "DataFormats/L1TrackTrigger/interface/TTCluster.h"
0026 #include "DataFormats/L1TrackTrigger/interface/TTStub.h"
0027 #include "DataFormats/L1TrackTrigger/interface/TTTrack.h"
0028 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0029 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h"
0030 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0031 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0032 #include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h"
0033 #include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h"
0034 #include "SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h"
0035 #include "Geometry/Records/interface/StackedTrackerGeometryRecord.h"
0036 
0037 #include "DataFormats/JetReco/interface/GenJetCollection.h"
0038 #include "DataFormats/JetReco/interface/GenJet.h"
0039 
0040 ////////////////////////////
0041 // DETECTOR GEOMETRY HEADERS
0042 #include "MagneticField/Engine/interface/MagneticField.h"
0043 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0044 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0045 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0046 #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h"
0047 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
0048 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0049 
0050 #include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h"
0051 #include "Geometry/CommonTopologies/interface/PixelGeomDetType.h"
0052 #include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyBuilder.h"
0053 #include "Geometry/Records/interface/StackedTrackerGeometryRecord.h"
0054 
0055 ////////////////
0056 // PHYSICS TOOLS
0057 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0058 
0059 //My additions
0060 #include "DataFormats/L1TCorrelator/interface/TkJet.h"
0061 #include "DataFormats/L1TCorrelator/interface/TkJetFwd.h"
0062 #include "DataFormats/L1Trigger/interface/TkJetWord.h"
0063 #include "DataFormats/Math/interface/LorentzVector.h"
0064 #include "DataFormats/L1TCorrelator/interface/TkEtMiss.h"
0065 #include "DataFormats/L1TCorrelator/interface/TkEtMissFwd.h"
0066 #include "DataFormats/L1TCorrelator/interface/TkHTMiss.h"
0067 #include "DataFormats/L1TCorrelator/interface/TkHTMissFwd.h"
0068 #include "DataFormats/L1Trigger/interface/Vertex.h"
0069 #include "DataFormats/L1Trigger/interface/VertexWord.h"
0070 #include "DataFormats/L1Trigger/interface/EtSum.h"
0071 #include "L1Trigger/L1TTrackMatch/interface/L1TkEtMissEmuAlgo.h"
0072 #include "L1Trigger/L1TTrackMatch/interface/L1TkHTMissEmulatorProducer.h"
0073 
0074 ///////////////
0075 // ROOT HEADERS
0076 #include <TROOT.h>
0077 #include <TCanvas.h>
0078 #include <TTree.h>
0079 #include <TFile.h>
0080 #include <TF1.h>
0081 #include <TH2F.h>
0082 #include <TH1F.h>
0083 #include <TLorentzVector.h>
0084 
0085 //////////////
0086 // STD HEADERS
0087 #include <memory>
0088 #include <string>
0089 #include <iostream>
0090 
0091 //////////////
0092 // NAMESPACES
0093 using namespace std;
0094 using namespace edm;
0095 
0096 //////////////////////////////
0097 //                          //
0098 //     CLASS DEFINITION     //
0099 //                          //
0100 //////////////////////////////
0101 
0102 class L1TrackObjectNtupleMaker : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0103 private:
0104   // ----------constants, enums and typedefs ---------
0105   typedef TTTrack<Ref_Phase2TrackerDigi_> L1Track;
0106   typedef edm::Ptr<L1Track> L1TrackPtr;
0107   typedef std::vector<L1TrackPtr> L1TrackPtrCollection;
0108   typedef std::vector<L1Track> L1TrackCollection;
0109   typedef edm::Ref<L1TrackCollection> L1TrackRef;
0110   typedef std::vector<L1TrackRef> L1TrackRefCollection;
0111 
0112 public:
0113   // Constructor/destructor
0114   explicit L1TrackObjectNtupleMaker(const edm::ParameterSet& iConfig);
0115   ~L1TrackObjectNtupleMaker() override;
0116 
0117   // Mandatory methods
0118   void beginJob() override;
0119   void endJob() override;
0120   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0121 
0122   // Other member functions
0123   int getSelectedTrackIndex(const L1TrackRef& trackRef,
0124                             const edm::Handle<L1TrackRefCollection>& selectedTrackRefs) const;
0125 
0126 private:
0127   //-----------------------------------------------------------------------------------------------
0128   // Containers of parameters passed by python configuration file
0129   edm::ParameterSet config;
0130 
0131   int MyProcess;       // 11/13/211 for single electrons/muons/pions, 6/15 for pions from ttbar/taus, 1 for inclusive
0132   bool DebugMode;      // lots of debug printout statements
0133   bool SaveAllTracks;  // store in ntuples not only truth-matched tracks but ALL tracks
0134   bool SaveStubs;      // option to save also stubs in the ntuples (makes them large...)
0135   string Displaced;    // "Prompt", "Displaced", "Both"
0136   int TP_minNStub;  // require TPs to have >= minNStub (defining efficiency denominator) (==0 means to only require >= 1 cluster)
0137   int TP_minNStubLayer;  // require TPs to have stubs in >= minNStubLayer layers/disks (defining efficiency denominator)
0138   double TP_minPt;       // save TPs with pt > minPt
0139   double TP_maxEta;      // save TPs with |eta| < maxEta
0140   double TP_maxZ0;       // save TPs with |z0| < maxZ0
0141   int L1Tk_minNStub;     // require L1 tracks to have >= minNStub (this is mostly for tracklet purposes)
0142   bool SaveTrackJets;
0143   bool SaveTrackSums;
0144 
0145   edm::InputTag L1TrackInputTag;                           // L1 track collection
0146   edm::InputTag MCTruthTrackInputTag;                      // MC truth collection
0147   edm::InputTag L1TrackGTTInputTag;                        // L1 track collection
0148   edm::InputTag L1TrackSelectedInputTag;                   // L1 track collection
0149   edm::InputTag L1TrackSelectedEmulationInputTag;          // L1 track collection
0150   edm::InputTag L1TrackExtendedInputTag;                   // L1 track collection
0151   edm::InputTag MCTruthTrackExtendedInputTag;              // MC truth collection
0152   edm::InputTag L1TrackExtendedGTTInputTag;                // L1 track collection
0153   edm::InputTag L1TrackExtendedSelectedInputTag;           // L1 track collection
0154   edm::InputTag L1TrackExtendedSelectedEmulationInputTag;  // L1 track collection
0155   edm::InputTag MCTruthClusterInputTag;
0156   edm::InputTag L1StubInputTag;
0157   edm::InputTag MCTruthStubInputTag;
0158   edm::InputTag TrackingParticleInputTag;
0159   edm::InputTag TrackingVertexInputTag;
0160   edm::InputTag GenJetInputTag;
0161   edm::InputTag RecoVertexInputTag;
0162   edm::InputTag RecoVertexEmuInputTag;
0163   edm::InputTag GenParticleInputTag;
0164 
0165   edm::InputTag TrackFastJetsInputTag;
0166   edm::InputTag TrackJetsInputTag;
0167   edm::InputTag TrackJetsEmuInputTag;
0168   edm::InputTag TrackMETInputTag;
0169   edm::InputTag TrackMETEmuInputTag;
0170   edm::InputTag TrackMHTInputTag;
0171   edm::InputTag TrackMHTEmuInputTag;
0172 
0173   edm::InputTag TrackFastJetsExtendedInputTag;
0174   edm::InputTag TrackJetsExtendedInputTag;
0175   edm::InputTag TrackJetsExtendedEmuInputTag;
0176   edm::InputTag TrackMETExtendedInputTag;
0177   //edm::InputTag TrackMETEmuExtendedInputTag;
0178   edm::InputTag TrackMHTExtendedInputTag;
0179   edm::InputTag TrackMHTEmuExtendedInputTag;
0180 
0181   edm::EDGetTokenT<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>> ttClusterToken_;
0182   edm::EDGetTokenT<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>> ttStubToken_;
0183   edm::EDGetTokenT<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>> ttClusterMCTruthToken_;
0184   edm::EDGetTokenT<TTStubAssociationMap<Ref_Phase2TrackerDigi_>> ttStubMCTruthToken_;
0185 
0186   edm::EDGetTokenT<L1TrackCollection> ttTrackToken_;
0187   edm::EDGetTokenT<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> ttTrackMCTruthToken_;
0188   edm::EDGetTokenT<L1TrackCollection> ttTrackGTTToken_;
0189   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedToken_;
0190   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedEmulationToken_;
0191   edm::EDGetTokenT<L1TrackCollection> ttTrackExtendedToken_;
0192   edm::EDGetTokenT<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> ttTrackMCTruthExtendedToken_;
0193   edm::EDGetTokenT<L1TrackCollection> ttTrackExtendedGTTToken_;
0194   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedToken_;
0195   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedEmulationToken_;
0196 
0197   edm::EDGetTokenT<std::vector<TrackingParticle>> TrackingParticleToken_;
0198   edm::EDGetTokenT<std::vector<TrackingVertex>> TrackingVertexToken_;
0199   edm::EDGetTokenT<std::vector<reco::GenJet>> GenJetToken_;
0200   edm::EDGetTokenT<std::vector<reco::GenParticle>> GenParticleToken_;
0201   edm::EDGetTokenT<l1t::VertexCollection> L1VertexToken_;
0202   edm::EDGetTokenT<l1t::VertexWordCollection> L1VertexEmuToken_;
0203 
0204   edm::EDGetTokenT<std::vector<l1t::TkJet>> TrackFastJetsToken_;
0205   edm::EDGetTokenT<std::vector<l1t::TkJet>> TrackFastJetsExtendedToken_;
0206   edm::EDGetTokenT<std::vector<l1t::TkEtMiss>> TrackMETToken_;
0207   edm::EDGetTokenT<std::vector<l1t::TkEtMiss>> TrackMETExtendedToken_;
0208   edm::EDGetTokenT<std::vector<l1t::EtSum>> TrackMETEmuToken_;
0209   //edm::EDGetTokenT<std::vector<l1t::TkEtMiss>> TrackMETEmuExtendedToken_;
0210   edm::EDGetTokenT<l1t::TkHTMissCollection> TrackMHTToken_;
0211   edm::EDGetTokenT<l1t::TkHTMissCollection> TrackMHTExtendedToken_;
0212   edm::EDGetTokenT<std::vector<l1t::EtSum>> TrackMHTEmuToken_;
0213   edm::EDGetTokenT<std::vector<l1t::EtSum>> TrackMHTEmuExtendedToken_;
0214   edm::EDGetTokenT<l1t::TkJetCollection> TrackJetsToken_;
0215   edm::EDGetTokenT<l1t::TkJetCollection> TrackJetsExtendedToken_;
0216   edm::EDGetTokenT<l1t::TkJetWordCollection> TrackJetsEmuToken_;
0217   edm::EDGetTokenT<l1t::TkJetWordCollection> TrackJetsExtendedEmuToken_;
0218 
0219   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0220   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tGeomToken_;
0221 
0222   //-----------------------------------------------------------------------------------------------
0223   // tree & branches for mini-ntuple
0224   bool available_;  // ROOT file for histograms is open.
0225   TTree* eventTree;
0226 
0227   // primary vertex
0228   std::vector<float>* m_pv_L1reco;
0229   std::vector<float>* m_pv_L1reco_sum;
0230   std::vector<float>* m_pv_L1reco_emu;
0231   std::vector<float>* m_pv_MC;
0232   std::vector<int>* m_MC_lep;
0233 
0234   //gen particles
0235   std::vector<float>* m_gen_pt;
0236   std::vector<float>* m_gen_phi;
0237   std::vector<float>* m_gen_pdgid;
0238   std::vector<float>* m_gen_z0;
0239 
0240   // all L1 tracks (prompt)
0241   std::vector<float>* m_trk_pt;
0242   std::vector<float>* m_trk_eta;
0243   std::vector<float>* m_trk_phi;
0244   std::vector<float>* m_trk_phi_local;
0245   std::vector<float>* m_trk_d0;  // (filled if nFitPar==5, else 999)
0246   std::vector<float>* m_trk_z0;
0247   std::vector<float>* m_trk_chi2;
0248   std::vector<float>* m_trk_chi2dof;
0249   std::vector<float>* m_trk_chi2rphi;
0250   std::vector<float>* m_trk_chi2rz;
0251   std::vector<float>* m_trk_bendchi2;
0252   std::vector<float>* m_trk_MVA1;
0253   std::vector<int>* m_trk_nstub;
0254   std::vector<int>* m_trk_lhits;
0255   std::vector<int>* m_trk_dhits;
0256   std::vector<int>* m_trk_seed;
0257   std::vector<int>* m_trk_hitpattern;
0258   std::vector<unsigned int>* m_trk_phiSector;
0259   std::vector<int>* m_trk_genuine;
0260   std::vector<int>* m_trk_loose;
0261   std::vector<int>* m_trk_unknown;
0262   std::vector<int>* m_trk_combinatoric;
0263   std::vector<int>* m_trk_fake;  //0 fake, 1 track from primary interaction, 2 secondary track
0264   std::vector<int>* m_trk_matchtp_pdgid;
0265   std::vector<float>* m_trk_matchtp_pt;
0266   std::vector<float>* m_trk_matchtp_eta;
0267   std::vector<float>* m_trk_matchtp_phi;
0268   std::vector<float>* m_trk_matchtp_z0;
0269   std::vector<float>* m_trk_matchtp_dxy;
0270   std::vector<float>* m_trk_gtt_pt;
0271   std::vector<float>* m_trk_gtt_eta;
0272   std::vector<float>* m_trk_gtt_phi;
0273   std::vector<int>* m_trk_selected_index;
0274   std::vector<int>* m_trk_selected_emulation_index;
0275 
0276   // all L1 tracks (extended)
0277   std::vector<float>* m_trkExt_pt;
0278   std::vector<float>* m_trkExt_eta;
0279   std::vector<float>* m_trkExt_phi;
0280   std::vector<float>* m_trkExt_phi_local;
0281   std::vector<float>* m_trkExt_d0;  // (filled if nFitPar==5, else 999)
0282   std::vector<float>* m_trkExt_z0;
0283   std::vector<float>* m_trkExt_chi2;
0284   std::vector<float>* m_trkExt_chi2dof;
0285   std::vector<float>* m_trkExt_chi2rphi;
0286   std::vector<float>* m_trkExt_chi2rz;
0287   std::vector<float>* m_trkExt_bendchi2;
0288   std::vector<float>* m_trkExt_MVA;
0289   std::vector<int>* m_trkExt_nstub;
0290   std::vector<int>* m_trkExt_lhits;
0291   std::vector<int>* m_trkExt_dhits;
0292   std::vector<int>* m_trkExt_seed;
0293   std::vector<int>* m_trkExt_hitpattern;
0294   std::vector<unsigned int>* m_trkExt_phiSector;
0295   std::vector<int>* m_trkExt_genuine;
0296   std::vector<int>* m_trkExt_loose;
0297   std::vector<int>* m_trkExt_unknown;
0298   std::vector<int>* m_trkExt_combinatoric;
0299   std::vector<int>* m_trkExt_fake;  //0 fake, 1 track from primary interaction, 2 secondary track
0300   std::vector<int>* m_trkExt_matchtp_pdgid;
0301   std::vector<float>* m_trkExt_matchtp_pt;
0302   std::vector<float>* m_trkExt_matchtp_eta;
0303   std::vector<float>* m_trkExt_matchtp_phi;
0304   std::vector<float>* m_trkExt_matchtp_z0;
0305   std::vector<float>* m_trkExt_matchtp_dxy;
0306   std::vector<float>* m_trkExt_gtt_pt;
0307   std::vector<float>* m_trkExt_gtt_eta;
0308   std::vector<float>* m_trkExt_gtt_phi;
0309   std::vector<int>* m_trkExt_selected_index;
0310   std::vector<int>* m_trkExt_selected_emulation_index;
0311 
0312   // all tracking particles
0313   std::vector<float>* m_tp_pt;
0314   std::vector<float>* m_tp_eta;
0315   std::vector<float>* m_tp_phi;
0316   std::vector<float>* m_tp_dxy;
0317   std::vector<float>* m_tp_d0;
0318   std::vector<float>* m_tp_z0;
0319   std::vector<float>* m_tp_d0_prod;
0320   std::vector<float>* m_tp_z0_prod;
0321   std::vector<int>* m_tp_pdgid;
0322   std::vector<int>* m_tp_nmatch;
0323   std::vector<int>* m_tp_nstub;
0324   std::vector<int>* m_tp_eventid;
0325   std::vector<int>* m_tp_charge;
0326 
0327   // *L1 track* properties if m_tp_nmatch > 0 (prompt)
0328   std::vector<float>* m_matchtrk_pt;
0329   std::vector<float>* m_matchtrk_eta;
0330   std::vector<float>* m_matchtrk_phi;
0331   std::vector<float>* m_matchtrk_d0;  //this variable is only filled if nFitPar==5
0332   std::vector<float>* m_matchtrk_z0;
0333   std::vector<float>* m_matchtrk_chi2;
0334   std::vector<float>* m_matchtrk_chi2dof;
0335   std::vector<float>* m_matchtrk_chi2rphi;
0336   std::vector<float>* m_matchtrk_chi2rz;
0337   std::vector<float>* m_matchtrk_bendchi2;
0338   std::vector<float>* m_matchtrk_MVA1;
0339   std::vector<int>* m_matchtrk_nstub;
0340   std::vector<int>* m_matchtrk_lhits;
0341   std::vector<int>* m_matchtrk_dhits;
0342   std::vector<int>* m_matchtrk_seed;
0343   std::vector<int>* m_matchtrk_hitpattern;
0344 
0345   // *L1 track* properties if m_tp_nmatch > 0 (extended)
0346   std::vector<float>* m_matchtrkExt_pt;
0347   std::vector<float>* m_matchtrkExt_eta;
0348   std::vector<float>* m_matchtrkExt_phi;
0349   std::vector<float>* m_matchtrkExt_d0;  //this variable is only filled if nFitPar==5
0350   std::vector<float>* m_matchtrkExt_z0;
0351   std::vector<float>* m_matchtrkExt_chi2;
0352   std::vector<float>* m_matchtrkExt_chi2dof;
0353   std::vector<float>* m_matchtrkExt_chi2rphi;
0354   std::vector<float>* m_matchtrkExt_chi2rz;
0355   std::vector<float>* m_matchtrkExt_bendchi2;
0356   std::vector<float>* m_matchtrkExt_MVA;
0357   std::vector<int>* m_matchtrkExt_nstub;
0358   std::vector<int>* m_matchtrkExt_lhits;
0359   std::vector<int>* m_matchtrkExt_dhits;
0360   std::vector<int>* m_matchtrkExt_seed;
0361   std::vector<int>* m_matchtrkExt_hitpattern;
0362 
0363   // ALL stubs
0364   std::vector<float>* m_allstub_x;
0365   std::vector<float>* m_allstub_y;
0366   std::vector<float>* m_allstub_z;
0367   std::vector<int>* m_allstub_isBarrel;  // stub is in barrel (1) or in disk (0)
0368   std::vector<int>* m_allstub_layer;
0369   std::vector<int>* m_allstub_isPSmodule;
0370   std::vector<float>* m_allstub_trigDisplace;
0371   std::vector<float>* m_allstub_trigOffset;
0372   std::vector<float>* m_allstub_trigPos;
0373   std::vector<float>* m_allstub_trigBend;
0374 
0375   // stub associated with tracking particle ?
0376   std::vector<int>* m_allstub_matchTP_pdgid;  // -999 if not matched
0377   std::vector<float>* m_allstub_matchTP_pt;   // -999 if not matched
0378   std::vector<float>* m_allstub_matchTP_eta;  // -999 if not matched
0379   std::vector<float>* m_allstub_matchTP_phi;  // -999 if not matched
0380   std::vector<int>* m_allstub_genuine;
0381 
0382   //prompt
0383   float trueMET = 0;
0384   float trueTkMET = 0;
0385   float trkMET = 0;
0386   float trkMHT = 0;
0387   float trkHT = 0;
0388   float trkMHTEmu = 0;
0389   float trkMHTEmuPhi = 0;
0390   float trkHTEmu = 0;
0391   float trkMETEmu = 0;
0392   float trkMETEmuPhi = 0;
0393 
0394   //displaced
0395   float trkMETExt = 0;
0396   float trkMHTExt = 0;
0397   float trkHTExt = 0;
0398   float trkMHTEmuExt = 0;
0399   float trkMHTEmuPhiExt = 0;
0400   float trkHTEmuExt = 0;
0401 
0402   //fast track jet
0403   std::vector<float>* m_trkfastjet_vz;
0404   std::vector<float>* m_trkfastjet_p;
0405   std::vector<float>* m_trkfastjet_phi;
0406   std::vector<float>* m_trkfastjet_eta;
0407   std::vector<float>* m_trkfastjet_pt;
0408   std::vector<int>* m_trkfastjet_ntracks;
0409   std::vector<float>* m_trkfastjet_tp_sumpt;
0410   std::vector<float>* m_trkfastjet_truetp_sumpt;
0411 
0412   std::vector<float>* m_trkfastjetExt_vz;
0413   std::vector<float>* m_trkfastjetExt_p;
0414   std::vector<float>* m_trkfastjetExt_phi;
0415   std::vector<float>* m_trkfastjetExt_eta;
0416   std::vector<float>* m_trkfastjetExt_pt;
0417   std::vector<int>* m_trkfastjetExt_ntracks;
0418   std::vector<float>* m_trkfastjetExt_tp_sumpt;
0419   std::vector<float>* m_trkfastjetExt_truetp_sumpt;
0420 
0421   std::vector<float>* m_trkjet_vz;
0422   std::vector<float>* m_trkjet_p;
0423   std::vector<float>* m_trkjet_phi;
0424   std::vector<float>* m_trkjet_eta;
0425   std::vector<float>* m_trkjet_pt;
0426   std::vector<int>* m_trkjet_ntracks;
0427   std::vector<int>* m_trkjet_nDisplaced;
0428   std::vector<int>* m_trkjet_nTight;
0429   std::vector<int>* m_trkjet_nTightDisplaced;
0430   std::vector<int>* m_trkjet_ntdtrk;
0431 
0432   std::vector<float>* m_trkjetem_pt;
0433   std::vector<float>* m_trkjetem_phi;
0434   std::vector<float>* m_trkjetem_eta;
0435   std::vector<float>* m_trkjetem_z;
0436   std::vector<int>* m_trkjetem_ntracks;
0437   std::vector<int>* m_trkjetem_nxtracks;
0438 
0439   std::vector<float>* m_trkjetExt_vz;
0440   std::vector<float>* m_trkjetExt_p;
0441   std::vector<float>* m_trkjetExt_phi;
0442   std::vector<float>* m_trkjetExt_eta;
0443   std::vector<float>* m_trkjetExt_pt;
0444   std::vector<int>* m_trkjetExt_ntracks;
0445   std::vector<int>* m_trkjetExt_nDisplaced;
0446   std::vector<int>* m_trkjetExt_nTight;
0447   std::vector<int>* m_trkjetExt_nTightDisplaced;
0448   std::vector<int>* m_trkjetExt_ntdtrk;
0449 
0450   std::vector<float>* m_trkjetemExt_pt;
0451   std::vector<float>* m_trkjetemExt_phi;
0452   std::vector<float>* m_trkjetemExt_eta;
0453   std::vector<float>* m_trkjetemExt_z;
0454   std::vector<int>* m_trkjetemExt_ntracks;
0455   std::vector<int>* m_trkjetemExt_nxtracks;
0456 };
0457 
0458 //////////////////////////////////
0459 //                              //
0460 //     CLASS IMPLEMENTATION     //
0461 //                              //
0462 //////////////////////////////////
0463 
0464 //////////////
0465 // CONSTRUCTOR
0466 L1TrackObjectNtupleMaker::L1TrackObjectNtupleMaker(edm::ParameterSet const& iConfig) : config(iConfig) {
0467   MyProcess = iConfig.getParameter<int>("MyProcess");
0468   DebugMode = iConfig.getParameter<bool>("DebugMode");
0469   SaveAllTracks = iConfig.getParameter<bool>("SaveAllTracks");
0470   SaveStubs = iConfig.getParameter<bool>("SaveStubs");
0471   Displaced = iConfig.getParameter<string>("Displaced");
0472   TP_minNStub = iConfig.getParameter<int>("TP_minNStub");
0473   TP_minNStubLayer = iConfig.getParameter<int>("TP_minNStubLayer");
0474   TP_minPt = iConfig.getParameter<double>("TP_minPt");
0475   TP_maxEta = iConfig.getParameter<double>("TP_maxEta");
0476   TP_maxZ0 = iConfig.getParameter<double>("TP_maxZ0");
0477   L1Tk_minNStub = iConfig.getParameter<int>("L1Tk_minNStub");
0478 
0479   SaveTrackJets = iConfig.getParameter<bool>("SaveTrackJets");
0480   SaveTrackSums = iConfig.getParameter<bool>("SaveTrackSums");
0481 
0482   L1StubInputTag = iConfig.getParameter<edm::InputTag>("L1StubInputTag");
0483   MCTruthClusterInputTag = iConfig.getParameter<edm::InputTag>("MCTruthClusterInputTag");
0484   MCTruthStubInputTag = iConfig.getParameter<edm::InputTag>("MCTruthStubInputTag");
0485   TrackingParticleInputTag = iConfig.getParameter<edm::InputTag>("TrackingParticleInputTag");
0486   TrackingVertexInputTag = iConfig.getParameter<edm::InputTag>("TrackingVertexInputTag");
0487   GenJetInputTag = iConfig.getParameter<edm::InputTag>("GenJetInputTag");
0488   RecoVertexInputTag = iConfig.getParameter<InputTag>("RecoVertexInputTag");
0489   RecoVertexEmuInputTag = iConfig.getParameter<InputTag>("RecoVertexEmuInputTag");
0490   GenParticleInputTag = iConfig.getParameter<InputTag>("GenParticleInputTag");
0491 
0492   if (Displaced == "Prompt" || Displaced == "Both") {
0493     L1TrackInputTag = iConfig.getParameter<edm::InputTag>("L1TrackInputTag");
0494     MCTruthTrackInputTag = iConfig.getParameter<edm::InputTag>("MCTruthTrackInputTag");
0495     L1TrackGTTInputTag = iConfig.getParameter<edm::InputTag>("L1TrackGTTInputTag");
0496     L1TrackSelectedInputTag = iConfig.getParameter<edm::InputTag>("L1TrackSelectedInputTag");
0497     L1TrackSelectedEmulationInputTag = iConfig.getParameter<edm::InputTag>("L1TrackSelectedEmulationInputTag");
0498     TrackFastJetsInputTag = iConfig.getParameter<InputTag>("TrackFastJetsInputTag");
0499     TrackJetsInputTag = iConfig.getParameter<InputTag>("TrackJetsInputTag");
0500     TrackJetsEmuInputTag = iConfig.getParameter<InputTag>("TrackJetsEmuInputTag");
0501     TrackMETInputTag = iConfig.getParameter<InputTag>("TrackMETInputTag");
0502     TrackMETEmuInputTag = iConfig.getParameter<InputTag>("TrackMETEmuInputTag");
0503     TrackMHTInputTag = iConfig.getParameter<InputTag>("TrackMHTInputTag");
0504     TrackMHTEmuInputTag = iConfig.getParameter<InputTag>("TrackMHTEmuInputTag");
0505 
0506     ttTrackToken_ = consumes<L1TrackCollection>(L1TrackInputTag);
0507     ttTrackMCTruthToken_ = consumes<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>(MCTruthTrackInputTag);
0508     ttTrackGTTToken_ = consumes<L1TrackCollection>(L1TrackGTTInputTag);
0509     ttTrackSelectedToken_ = consumes<L1TrackRefCollection>(L1TrackSelectedInputTag);
0510     ttTrackSelectedEmulationToken_ = consumes<L1TrackRefCollection>(L1TrackSelectedEmulationInputTag);
0511     TrackFastJetsToken_ = consumes<std::vector<l1t::TkJet>>(TrackFastJetsInputTag);
0512     TrackJetsToken_ = consumes<l1t::TkJetCollection>(TrackJetsInputTag);
0513     TrackJetsEmuToken_ = consumes<l1t::TkJetWordCollection>(TrackJetsEmuInputTag);
0514     TrackMETToken_ = consumes<std::vector<l1t::TkEtMiss>>(TrackMETInputTag);
0515     TrackMETEmuToken_ = consumes<std::vector<l1t::EtSum>>(TrackMETEmuInputTag);
0516     TrackMHTToken_ = consumes<l1t::TkHTMissCollection>(TrackMHTInputTag);
0517     TrackMHTEmuToken_ = consumes<std::vector<l1t::EtSum>>(TrackMHTEmuInputTag);
0518   }
0519 
0520   if (Displaced == "Displaced" || Displaced == "Both") {
0521     L1TrackExtendedInputTag = iConfig.getParameter<edm::InputTag>("L1TrackExtendedInputTag");
0522     MCTruthTrackExtendedInputTag = iConfig.getParameter<edm::InputTag>("MCTruthTrackExtendedInputTag");
0523     L1TrackExtendedGTTInputTag = iConfig.getParameter<edm::InputTag>("L1TrackExtendedGTTInputTag");
0524     L1TrackExtendedSelectedInputTag = iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedInputTag");
0525     L1TrackExtendedSelectedEmulationInputTag =
0526         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedEmulationInputTag");
0527     TrackFastJetsExtendedInputTag = iConfig.getParameter<InputTag>("TrackFastJetsExtendedInputTag");
0528     TrackJetsExtendedInputTag = iConfig.getParameter<InputTag>("TrackJetsExtendedInputTag");
0529     TrackJetsExtendedEmuInputTag = iConfig.getParameter<InputTag>("TrackJetsExtendedEmuInputTag");
0530     TrackMETExtendedInputTag = iConfig.getParameter<InputTag>("TrackMETExtendedInputTag");
0531     TrackMHTExtendedInputTag = iConfig.getParameter<InputTag>("TrackMHTExtendedInputTag");
0532     TrackMHTEmuInputTag = iConfig.getParameter<InputTag>("TrackMHTEmuInputTag");
0533     TrackMHTEmuExtendedInputTag = iConfig.getParameter<InputTag>("TrackMHTEmuExtendedInputTag");
0534 
0535     ttTrackExtendedToken_ = consumes<L1TrackCollection>(L1TrackExtendedInputTag);
0536     ttTrackMCTruthExtendedToken_ =
0537         consumes<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>(MCTruthTrackExtendedInputTag);
0538     ttTrackExtendedGTTToken_ = consumes<L1TrackCollection>(L1TrackExtendedGTTInputTag);
0539     ttTrackExtendedSelectedToken_ = consumes<L1TrackRefCollection>(L1TrackExtendedSelectedInputTag);
0540     ttTrackExtendedSelectedEmulationToken_ = consumes<L1TrackRefCollection>(L1TrackExtendedSelectedEmulationInputTag);
0541     TrackFastJetsExtendedToken_ = consumes<std::vector<l1t::TkJet>>(TrackFastJetsExtendedInputTag);
0542     TrackJetsExtendedToken_ = consumes<l1t::TkJetCollection>(TrackJetsExtendedInputTag);
0543     TrackJetsExtendedEmuToken_ = consumes<l1t::TkJetWordCollection>(TrackJetsExtendedEmuInputTag);
0544     TrackMETExtendedToken_ = consumes<std::vector<l1t::TkEtMiss>>(TrackMETExtendedInputTag);
0545     TrackMHTExtendedToken_ = consumes<l1t::TkHTMissCollection>(TrackMHTExtendedInputTag);
0546     TrackMHTEmuToken_ = consumes<std::vector<l1t::EtSum>>(TrackMHTEmuInputTag);
0547     TrackMHTEmuExtendedToken_ = consumes<std::vector<l1t::EtSum>>(TrackMHTEmuExtendedInputTag);
0548   }
0549 
0550   ttStubToken_ = consumes<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>(L1StubInputTag);
0551   ttClusterMCTruthToken_ = consumes<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>(MCTruthClusterInputTag);
0552   ttStubMCTruthToken_ = consumes<TTStubAssociationMap<Ref_Phase2TrackerDigi_>>(MCTruthStubInputTag);
0553   TrackingParticleToken_ = consumes<std::vector<TrackingParticle>>(TrackingParticleInputTag);
0554   TrackingVertexToken_ = consumes<std::vector<TrackingVertex>>(TrackingVertexInputTag);
0555   GenJetToken_ = consumes<std::vector<reco::GenJet>>(GenJetInputTag);
0556   GenParticleToken_ = consumes<std::vector<reco::GenParticle>>(GenParticleInputTag);
0557   L1VertexToken_ = consumes<l1t::VertexCollection>(RecoVertexInputTag);
0558   L1VertexEmuToken_ = consumes<l1t::VertexWordCollection>(RecoVertexEmuInputTag);
0559   tTopoToken_ = esConsumes<TrackerTopology, TrackerTopologyRcd>(edm::ESInputTag("", ""));
0560   tGeomToken_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>(edm::ESInputTag("", ""));
0561 
0562   usesResource(TFileService::kSharedResource);
0563 }
0564 
0565 /////////////
0566 // DESTRUCTOR
0567 L1TrackObjectNtupleMaker::~L1TrackObjectNtupleMaker() {}
0568 
0569 //////////
0570 // END JOB
0571 void L1TrackObjectNtupleMaker::endJob() {
0572   // things to be done at the exit of the event Loop
0573   //  edm::LogVerbatim("Tracklet") << "L1TrackObjectNtupleMaker::endJob";
0574 }
0575 
0576 ////////////
0577 // BEGIN JOB
0578 void L1TrackObjectNtupleMaker::beginJob() {
0579   // things to be done before entering the event Loop
0580   //  edm::LogVerbatim("Tracklet") << "L1TrackObjectNtupleMaker::beginJob";
0581 
0582   //-----------------------------------------------------------------------------------------------
0583   // book histograms / make ntuple
0584   edm::Service<TFileService> fs;
0585   available_ = fs.isAvailable();
0586   if (not available_)
0587     return;  // No ROOT file open.
0588 
0589   // initilize
0590   m_trk_pt = new std::vector<float>;
0591   m_trk_eta = new std::vector<float>;
0592   m_trk_phi = new std::vector<float>;
0593   m_trk_phi_local = new std::vector<float>;
0594   m_trk_z0 = new std::vector<float>;
0595   m_trk_d0 = new std::vector<float>;
0596   m_trk_chi2 = new std::vector<float>;
0597   m_trk_chi2dof = new std::vector<float>;
0598   m_trk_chi2rphi = new std::vector<float>;
0599   m_trk_chi2rz = new std::vector<float>;
0600   m_trk_bendchi2 = new std::vector<float>;
0601   m_trk_MVA1 = new std::vector<float>;
0602   m_trk_nstub = new std::vector<int>;
0603   m_trk_lhits = new std::vector<int>;
0604   m_trk_dhits = new std::vector<int>;
0605   m_trk_seed = new std::vector<int>;
0606   m_trk_hitpattern = new std::vector<int>;
0607   m_trk_phiSector = new std::vector<unsigned int>;
0608   m_trk_genuine = new std::vector<int>;
0609   m_trk_loose = new std::vector<int>;
0610   m_trk_unknown = new std::vector<int>;
0611   m_trk_combinatoric = new std::vector<int>;
0612   m_trk_fake = new std::vector<int>;
0613   m_trk_matchtp_pdgid = new std::vector<int>;
0614   m_trk_matchtp_pt = new std::vector<float>;
0615   m_trk_matchtp_eta = new std::vector<float>;
0616   m_trk_matchtp_phi = new std::vector<float>;
0617   m_trk_matchtp_z0 = new std::vector<float>;
0618   m_trk_matchtp_dxy = new std::vector<float>;
0619   m_trk_gtt_pt = new std::vector<float>;
0620   m_trk_gtt_eta = new std::vector<float>;
0621   m_trk_gtt_phi = new std::vector<float>;
0622   m_trk_selected_index = new std::vector<int>;
0623   m_trk_selected_emulation_index = new std::vector<int>;
0624 
0625   m_trkExt_pt = new std::vector<float>;
0626   m_trkExt_eta = new std::vector<float>;
0627   m_trkExt_phi = new std::vector<float>;
0628   m_trkExt_phi_local = new std::vector<float>;
0629   m_trkExt_z0 = new std::vector<float>;
0630   m_trkExt_d0 = new std::vector<float>;
0631   m_trkExt_chi2 = new std::vector<float>;
0632   m_trkExt_chi2dof = new std::vector<float>;
0633   m_trkExt_chi2rphi = new std::vector<float>;
0634   m_trkExt_chi2rz = new std::vector<float>;
0635   m_trkExt_bendchi2 = new std::vector<float>;
0636   m_trkExt_MVA = new std::vector<float>;
0637   m_trkExt_nstub = new std::vector<int>;
0638   m_trkExt_lhits = new std::vector<int>;
0639   m_trkExt_dhits = new std::vector<int>;
0640   m_trkExt_seed = new std::vector<int>;
0641   m_trkExt_hitpattern = new std::vector<int>;
0642   m_trkExt_phiSector = new std::vector<unsigned int>;
0643   m_trkExt_genuine = new std::vector<int>;
0644   m_trkExt_loose = new std::vector<int>;
0645   m_trkExt_unknown = new std::vector<int>;
0646   m_trkExt_combinatoric = new std::vector<int>;
0647   m_trkExt_fake = new std::vector<int>;
0648   m_trkExt_matchtp_pdgid = new std::vector<int>;
0649   m_trkExt_matchtp_pt = new std::vector<float>;
0650   m_trkExt_matchtp_eta = new std::vector<float>;
0651   m_trkExt_matchtp_phi = new std::vector<float>;
0652   m_trkExt_matchtp_z0 = new std::vector<float>;
0653   m_trkExt_matchtp_dxy = new std::vector<float>;
0654   m_trkExt_gtt_pt = new std::vector<float>;
0655   m_trkExt_gtt_eta = new std::vector<float>;
0656   m_trkExt_gtt_phi = new std::vector<float>;
0657   m_trkExt_selected_index = new std::vector<int>;
0658   m_trkExt_selected_emulation_index = new std::vector<int>;
0659 
0660   m_tp_pt = new std::vector<float>;
0661   m_tp_eta = new std::vector<float>;
0662   m_tp_phi = new std::vector<float>;
0663   m_tp_dxy = new std::vector<float>;
0664   m_tp_d0 = new std::vector<float>;
0665   m_tp_z0 = new std::vector<float>;
0666   m_tp_d0_prod = new std::vector<float>;
0667   m_tp_z0_prod = new std::vector<float>;
0668   m_tp_pdgid = new std::vector<int>;
0669   m_tp_nmatch = new std::vector<int>;
0670   m_tp_nstub = new std::vector<int>;
0671   m_tp_eventid = new std::vector<int>;
0672   m_tp_charge = new std::vector<int>;
0673 
0674   m_gen_pt = new std::vector<float>;
0675   m_gen_phi = new std::vector<float>;
0676   m_gen_pdgid = new std::vector<float>;
0677   m_gen_z0 = new std::vector<float>;
0678 
0679   m_matchtrk_pt = new std::vector<float>;
0680   m_matchtrk_eta = new std::vector<float>;
0681   m_matchtrk_phi = new std::vector<float>;
0682   m_matchtrk_z0 = new std::vector<float>;
0683   m_matchtrk_d0 = new std::vector<float>;
0684   m_matchtrk_chi2 = new std::vector<float>;
0685   m_matchtrk_chi2dof = new std::vector<float>;
0686   m_matchtrk_chi2rphi = new std::vector<float>;
0687   m_matchtrk_chi2rz = new std::vector<float>;
0688   m_matchtrk_bendchi2 = new std::vector<float>;
0689   m_matchtrk_MVA1 = new std::vector<float>;
0690   m_matchtrk_nstub = new std::vector<int>;
0691   m_matchtrk_dhits = new std::vector<int>;
0692   m_matchtrk_lhits = new std::vector<int>;
0693   m_matchtrk_seed = new std::vector<int>;
0694   m_matchtrk_hitpattern = new std::vector<int>;
0695 
0696   m_matchtrkExt_pt = new std::vector<float>;
0697   m_matchtrkExt_eta = new std::vector<float>;
0698   m_matchtrkExt_phi = new std::vector<float>;
0699   m_matchtrkExt_z0 = new std::vector<float>;
0700   m_matchtrkExt_d0 = new std::vector<float>;
0701   m_matchtrkExt_chi2 = new std::vector<float>;
0702   m_matchtrkExt_chi2dof = new std::vector<float>;
0703   m_matchtrkExt_chi2rphi = new std::vector<float>;
0704   m_matchtrkExt_chi2rz = new std::vector<float>;
0705   m_matchtrkExt_bendchi2 = new std::vector<float>;
0706   m_matchtrkExt_MVA = new std::vector<float>;
0707   m_matchtrkExt_nstub = new std::vector<int>;
0708   m_matchtrkExt_dhits = new std::vector<int>;
0709   m_matchtrkExt_lhits = new std::vector<int>;
0710   m_matchtrkExt_seed = new std::vector<int>;
0711   m_matchtrkExt_hitpattern = new std::vector<int>;
0712 
0713   m_allstub_x = new std::vector<float>;
0714   m_allstub_y = new std::vector<float>;
0715   m_allstub_z = new std::vector<float>;
0716   m_allstub_isBarrel = new std::vector<int>;
0717   m_allstub_layer = new std::vector<int>;
0718   m_allstub_isPSmodule = new std::vector<int>;
0719   m_allstub_trigDisplace = new std::vector<float>;
0720   m_allstub_trigOffset = new std::vector<float>;
0721   m_allstub_trigPos = new std::vector<float>;
0722   m_allstub_trigBend = new std::vector<float>;
0723   m_allstub_matchTP_pdgid = new std::vector<int>;
0724   m_allstub_matchTP_pt = new std::vector<float>;
0725   m_allstub_matchTP_eta = new std::vector<float>;
0726   m_allstub_matchTP_phi = new std::vector<float>;
0727   m_allstub_genuine = new std::vector<int>;
0728 
0729   m_pv_L1reco = new std::vector<float>;
0730   m_pv_L1reco_sum = new std::vector<float>;
0731   m_pv_L1reco_emu = new std::vector<float>;
0732   m_pv_MC = new std::vector<float>;
0733   m_MC_lep = new std::vector<int>;
0734 
0735   m_trkjet_eta = new std::vector<float>;
0736   m_trkjet_vz = new std::vector<float>;
0737   m_trkjet_phi = new std::vector<float>;
0738   m_trkjet_p = new std::vector<float>;
0739   m_trkjet_pt = new std::vector<float>;
0740   m_trkjet_ntracks = new std::vector<int>;
0741   m_trkjet_nDisplaced = new std::vector<int>;
0742   m_trkjet_nTight = new std::vector<int>;
0743   m_trkjet_nTightDisplaced = new std::vector<int>;
0744   m_trkjet_ntdtrk = new std::vector<int>;
0745 
0746   m_trkjetem_pt = new std::vector<float>;
0747   m_trkjetem_phi = new std::vector<float>;
0748   m_trkjetem_eta = new std::vector<float>;
0749   m_trkjetem_z = new std::vector<float>;
0750   m_trkjetem_ntracks = new std::vector<int>;
0751   m_trkjetem_nxtracks = new std::vector<int>;
0752 
0753   m_trkfastjet_eta = new std::vector<float>;
0754   m_trkfastjet_vz = new std::vector<float>;
0755   m_trkfastjet_phi = new std::vector<float>;
0756   m_trkfastjet_p = new std::vector<float>;
0757   m_trkfastjet_pt = new std::vector<float>;
0758   m_trkfastjet_ntracks = new std::vector<int>;
0759   m_trkfastjet_tp_sumpt = new std::vector<float>;
0760   m_trkfastjet_truetp_sumpt = new std::vector<float>;
0761 
0762   m_trkjetExt_eta = new std::vector<float>;
0763   m_trkjetExt_vz = new std::vector<float>;
0764   m_trkjetExt_phi = new std::vector<float>;
0765   m_trkjetExt_p = new std::vector<float>;
0766   m_trkjetExt_pt = new std::vector<float>;
0767   m_trkjetExt_ntracks = new std::vector<int>;
0768   m_trkjetExt_nDisplaced = new std::vector<int>;
0769   m_trkjetExt_nTight = new std::vector<int>;
0770   m_trkjetExt_nTightDisplaced = new std::vector<int>;
0771   m_trkjetExt_ntdtrk = new std::vector<int>;
0772 
0773   m_trkjetemExt_pt = new std::vector<float>;
0774   m_trkjetemExt_phi = new std::vector<float>;
0775   m_trkjetemExt_eta = new std::vector<float>;
0776   m_trkjetemExt_z = new std::vector<float>;
0777   m_trkjetemExt_ntracks = new std::vector<int>;
0778   m_trkjetemExt_nxtracks = new std::vector<int>;
0779 
0780   m_trkfastjetExt_eta = new std::vector<float>;
0781   m_trkfastjetExt_vz = new std::vector<float>;
0782   m_trkfastjetExt_phi = new std::vector<float>;
0783   m_trkfastjetExt_p = new std::vector<float>;
0784   m_trkfastjetExt_pt = new std::vector<float>;
0785   m_trkfastjetExt_ntracks = new std::vector<int>;
0786   m_trkfastjetExt_tp_sumpt = new std::vector<float>;
0787   m_trkfastjetExt_truetp_sumpt = new std::vector<float>;
0788 
0789   // ntuple
0790   eventTree = fs->make<TTree>("eventTree", "Event tree");
0791   if (SaveAllTracks && (Displaced == "Prompt" || Displaced == "Both")) {
0792     eventTree->Branch("trk_pt", &m_trk_pt);
0793     eventTree->Branch("trk_eta", &m_trk_eta);
0794     eventTree->Branch("trk_phi", &m_trk_phi);
0795     eventTree->Branch("trk_phi_local", &m_trk_phi_local);
0796     eventTree->Branch("trk_d0", &m_trk_d0);
0797     eventTree->Branch("trk_z0", &m_trk_z0);
0798     eventTree->Branch("trk_chi2", &m_trk_chi2);
0799     eventTree->Branch("trk_chi2dof", &m_trk_chi2dof);
0800     eventTree->Branch("trk_chi2rphi", &m_trk_chi2rphi);
0801     eventTree->Branch("trk_chi2rz", &m_trk_chi2rz);
0802     eventTree->Branch("trk_bendchi2", &m_trk_bendchi2);
0803     eventTree->Branch("trk_MVA1", &m_trk_MVA1);
0804     eventTree->Branch("trk_nstub", &m_trk_nstub);
0805     eventTree->Branch("trk_lhits", &m_trk_lhits);
0806     eventTree->Branch("trk_dhits", &m_trk_dhits);
0807     eventTree->Branch("trk_seed", &m_trk_seed);
0808     eventTree->Branch("trk_hitpattern", &m_trk_hitpattern);
0809     eventTree->Branch("trk_phiSector", &m_trk_phiSector);
0810     eventTree->Branch("trk_genuine", &m_trk_genuine);
0811     eventTree->Branch("trk_loose", &m_trk_loose);
0812     eventTree->Branch("trk_unknown", &m_trk_unknown);
0813     eventTree->Branch("trk_combinatoric", &m_trk_combinatoric);
0814     eventTree->Branch("trk_fake", &m_trk_fake);
0815     eventTree->Branch("trk_matchtp_pdgid", &m_trk_matchtp_pdgid);
0816     eventTree->Branch("trk_matchtp_pt", &m_trk_matchtp_pt);
0817     eventTree->Branch("trk_matchtp_eta", &m_trk_matchtp_eta);
0818     eventTree->Branch("trk_matchtp_phi", &m_trk_matchtp_phi);
0819     eventTree->Branch("trk_matchtp_z0", &m_trk_matchtp_z0);
0820     eventTree->Branch("trk_matchtp_dxy", &m_trk_matchtp_dxy);
0821     eventTree->Branch("trk_gtt_pt", &m_trk_gtt_pt);
0822     eventTree->Branch("trk_gtt_eta", &m_trk_gtt_eta);
0823     eventTree->Branch("trk_gtt_phi", &m_trk_gtt_phi);
0824     eventTree->Branch("trk_gtt_selected_index", &m_trk_selected_index);
0825     eventTree->Branch("trk_gtt_selected_emulation_index", &m_trk_selected_emulation_index);
0826   }
0827 
0828   if (SaveAllTracks && (Displaced == "Displaced" || Displaced == "Both")) {
0829     eventTree->Branch("trkExt_pt", &m_trkExt_pt);
0830     eventTree->Branch("trkExt_eta", &m_trkExt_eta);
0831     eventTree->Branch("trkExt_phi", &m_trkExt_phi);
0832     eventTree->Branch("trkExt_phi_local", &m_trkExt_phi_local);
0833     eventTree->Branch("trkExt_d0", &m_trkExt_d0);
0834     eventTree->Branch("trkExt_z0", &m_trkExt_z0);
0835     eventTree->Branch("trkExt_chi2", &m_trkExt_chi2);
0836     eventTree->Branch("trkExt_chi2dof", &m_trkExt_chi2dof);
0837     eventTree->Branch("trkExt_chi2rphi", &m_trkExt_chi2rphi);
0838     eventTree->Branch("trkExt_chi2rz", &m_trkExt_chi2rz);
0839     eventTree->Branch("trkExt_bendchi2", &m_trkExt_bendchi2);
0840     eventTree->Branch("trkExt_MVA", &m_trkExt_MVA);
0841     eventTree->Branch("trkExt_nstub", &m_trkExt_nstub);
0842     eventTree->Branch("trkExt_lhits", &m_trkExt_lhits);
0843     eventTree->Branch("trkExt_dhits", &m_trkExt_dhits);
0844     eventTree->Branch("trkExt_seed", &m_trkExt_seed);
0845     eventTree->Branch("trkExt_hitpattern", &m_trkExt_hitpattern);
0846     eventTree->Branch("trkExt_phiSector", &m_trkExt_phiSector);
0847     eventTree->Branch("trkExt_genuine", &m_trkExt_genuine);
0848     eventTree->Branch("trkExt_loose", &m_trkExt_loose);
0849     eventTree->Branch("trkExt_unknown", &m_trkExt_unknown);
0850     eventTree->Branch("trkExt_combinatoric", &m_trkExt_combinatoric);
0851     eventTree->Branch("trkExt_fake", &m_trkExt_fake);
0852     eventTree->Branch("trkExt_matchtp_pdgid", &m_trkExt_matchtp_pdgid);
0853     eventTree->Branch("trkExt_matchtp_pt", &m_trkExt_matchtp_pt);
0854     eventTree->Branch("trkExt_matchtp_eta", &m_trkExt_matchtp_eta);
0855     eventTree->Branch("trkExt_matchtp_phi", &m_trkExt_matchtp_phi);
0856     eventTree->Branch("trkExt_matchtp_z0", &m_trkExt_matchtp_z0);
0857     eventTree->Branch("trkExt_matchtp_dxy", &m_trkExt_matchtp_dxy);
0858     eventTree->Branch("trkExt_gtt_pt", &m_trkExt_gtt_pt);
0859     eventTree->Branch("trkExt_gtt_eta", &m_trkExt_gtt_eta);
0860     eventTree->Branch("trkExt_gtt_phi", &m_trkExt_gtt_phi);
0861     eventTree->Branch("trkExt_gtt_selected_index", &m_trkExt_selected_index);
0862     eventTree->Branch("trkExt_gtt_selected_emulation_index", &m_trkExt_selected_emulation_index);
0863   }
0864   eventTree->Branch("tp_pt", &m_tp_pt);
0865   eventTree->Branch("tp_eta", &m_tp_eta);
0866   eventTree->Branch("tp_phi", &m_tp_phi);
0867   eventTree->Branch("tp_dxy", &m_tp_dxy);
0868   eventTree->Branch("tp_d0", &m_tp_d0);
0869   eventTree->Branch("tp_z0", &m_tp_z0);
0870   eventTree->Branch("tp_d0_prod", &m_tp_d0_prod);
0871   eventTree->Branch("tp_z0_prod", &m_tp_z0_prod);
0872   eventTree->Branch("tp_pdgid", &m_tp_pdgid);
0873   eventTree->Branch("tp_nmatch", &m_tp_nmatch);
0874   eventTree->Branch("tp_nstub", &m_tp_nstub);
0875   eventTree->Branch("tp_eventid", &m_tp_eventid);
0876   eventTree->Branch("tp_charge", &m_tp_charge);
0877 
0878   if (Displaced == "Prompt" || Displaced == "Both") {
0879     eventTree->Branch("matchtrk_pt", &m_matchtrk_pt);
0880     eventTree->Branch("matchtrk_eta", &m_matchtrk_eta);
0881     eventTree->Branch("matchtrk_phi", &m_matchtrk_phi);
0882     eventTree->Branch("matchtrk_z0", &m_matchtrk_z0);
0883     eventTree->Branch("matchtrk_d0", &m_matchtrk_d0);
0884     eventTree->Branch("matchtrk_chi2", &m_matchtrk_chi2);
0885     eventTree->Branch("matchtrk_chi2dof", &m_matchtrk_chi2dof);
0886     eventTree->Branch("matchtrk_chi2rphi", &m_matchtrk_chi2rphi);
0887     eventTree->Branch("matchtrk_chi2rz", &m_matchtrk_chi2rz);
0888     eventTree->Branch("matchtrk_bendchi2", &m_matchtrk_bendchi2);
0889     eventTree->Branch("matchtrk_MVA1", &m_matchtrk_MVA1);
0890     eventTree->Branch("matchtrk_nstub", &m_matchtrk_nstub);
0891     eventTree->Branch("matchtrk_lhits", &m_matchtrk_lhits);
0892     eventTree->Branch("matchtrk_dhits", &m_matchtrk_dhits);
0893     eventTree->Branch("matchtrk_seed", &m_matchtrk_seed);
0894     eventTree->Branch("matchtrk_hitpattern", &m_matchtrk_hitpattern);
0895   }
0896 
0897   if (Displaced == "Displaced" || Displaced == "Both") {
0898     eventTree->Branch("matchtrkExt_pt", &m_matchtrkExt_pt);
0899     eventTree->Branch("matchtrkExt_eta", &m_matchtrkExt_eta);
0900     eventTree->Branch("matchtrkExt_phi", &m_matchtrkExt_phi);
0901     eventTree->Branch("matchtrkExt_z0", &m_matchtrkExt_z0);
0902     eventTree->Branch("matchtrkExt_d0", &m_matchtrkExt_d0);
0903     eventTree->Branch("matchtrkExt_chi2", &m_matchtrkExt_chi2);
0904     eventTree->Branch("matchtrkExt_chi2dof", &m_matchtrkExt_chi2dof);
0905     eventTree->Branch("matchtrkExt_chi2rphi", &m_matchtrkExt_chi2rphi);
0906     eventTree->Branch("matchtrkExt_chi2rz", &m_matchtrkExt_chi2rz);
0907     eventTree->Branch("matchtrkExt_bendchi2", &m_matchtrkExt_bendchi2);
0908     eventTree->Branch("matchtrkExt_MVA", &m_matchtrkExt_MVA);
0909     eventTree->Branch("matchtrkExt_nstub", &m_matchtrkExt_nstub);
0910     eventTree->Branch("matchtrkExt_lhits", &m_matchtrkExt_lhits);
0911     eventTree->Branch("matchtrkExt_dhits", &m_matchtrkExt_dhits);
0912     eventTree->Branch("matchtrkExt_seed", &m_matchtrkExt_seed);
0913     eventTree->Branch("matchtrkExt_hitpattern", &m_matchtrkExt_hitpattern);
0914   }
0915 
0916   if (SaveStubs) {
0917     eventTree->Branch("allstub_x", &m_allstub_x);
0918     eventTree->Branch("allstub_y", &m_allstub_y);
0919     eventTree->Branch("allstub_z", &m_allstub_z);
0920     eventTree->Branch("allstub_isBarrel", &m_allstub_isBarrel);
0921     eventTree->Branch("allstub_layer", &m_allstub_layer);
0922     eventTree->Branch("allstub_isPSmodule", &m_allstub_isPSmodule);
0923     eventTree->Branch("allstub_trigDisplace", &m_allstub_trigDisplace);
0924     eventTree->Branch("allstub_trigOffset", &m_allstub_trigOffset);
0925     eventTree->Branch("allstub_trigPos", &m_allstub_trigPos);
0926     eventTree->Branch("allstub_trigBend", &m_allstub_trigBend);
0927     eventTree->Branch("allstub_matchTP_pdgid", &m_allstub_matchTP_pdgid);
0928     eventTree->Branch("allstub_matchTP_pt", &m_allstub_matchTP_pt);
0929     eventTree->Branch("allstub_matchTP_eta", &m_allstub_matchTP_eta);
0930     eventTree->Branch("allstub_matchTP_phi", &m_allstub_matchTP_phi);
0931     eventTree->Branch("allstub_genuine", &m_allstub_genuine);
0932   }
0933 
0934   eventTree->Branch("pv_L1reco", &m_pv_L1reco);
0935   eventTree->Branch("pv_L1reco_sum", &m_pv_L1reco_sum);
0936   eventTree->Branch("pv_L1reco_emu", &m_pv_L1reco_emu);
0937   eventTree->Branch("MC_lep", &m_MC_lep);
0938   eventTree->Branch("pv_MC", &m_pv_MC);
0939   eventTree->Branch("gen_pt", &m_gen_pt);
0940   eventTree->Branch("gen_phi", &m_gen_phi);
0941   eventTree->Branch("gen_pdgid", &m_gen_pdgid);
0942   eventTree->Branch("gen_z0", &m_gen_z0);
0943 
0944   if (SaveTrackJets) {
0945     if (Displaced == "Prompt" || Displaced == "Both") {
0946       eventTree->Branch("trkfastjet_eta", &m_trkfastjet_eta);
0947       eventTree->Branch("trkfastjet_vz", &m_trkfastjet_vz);
0948       eventTree->Branch("trkfastjet_p", &m_trkfastjet_p);
0949       eventTree->Branch("trkfastjet_pt", &m_trkfastjet_pt);
0950       eventTree->Branch("trkfastjet_phi", &m_trkfastjet_phi);
0951       eventTree->Branch("trkfastjet_ntracks", &m_trkfastjet_ntracks);
0952       eventTree->Branch("trkfastjet_truetp_sumpt", m_trkfastjet_truetp_sumpt);
0953 
0954       eventTree->Branch("trkjet_eta", &m_trkjet_eta);
0955       eventTree->Branch("trkjet_vz", &m_trkjet_vz);
0956       eventTree->Branch("trkjet_p", &m_trkjet_p);
0957       eventTree->Branch("trkjet_pt", &m_trkjet_pt);
0958       eventTree->Branch("trkjet_phi", &m_trkjet_phi);
0959       eventTree->Branch("trkjet_ntracks", &m_trkjet_ntracks);
0960       eventTree->Branch("trkjet_nDisplaced", &m_trkjet_nDisplaced);
0961       eventTree->Branch("trkjet_nTight", &m_trkjet_nTight);
0962       eventTree->Branch("trkjet_nTightDisplaced", &m_trkjet_nTightDisplaced);
0963 
0964       eventTree->Branch("trkjetem_eta", &m_trkjetem_eta);
0965       eventTree->Branch("trkjetem_pt", &m_trkjetem_pt);
0966       eventTree->Branch("trkjetem_phi", &m_trkjetem_phi);
0967       eventTree->Branch("trkjetem_z", &m_trkjetem_z);
0968       eventTree->Branch("trkjetem_ntracks", &m_trkjetem_ntracks);
0969       eventTree->Branch("trkjetem_nxtracks", &m_trkjetem_nxtracks);
0970     }
0971     if (Displaced == "Displaced" || Displaced == "Both") {
0972       eventTree->Branch("trkfastjetExt_eta", &m_trkfastjetExt_eta);
0973       eventTree->Branch("trkfastjetExt_vz", &m_trkfastjetExt_vz);
0974       eventTree->Branch("trkfastjetExt_p", &m_trkfastjetExt_p);
0975       eventTree->Branch("trkfastjetExt_pt", &m_trkfastjetExt_pt);
0976       eventTree->Branch("trkfastjetExt_phi", &m_trkfastjetExt_phi);
0977       eventTree->Branch("trkfastjetExt_ntracks", &m_trkfastjetExt_ntracks);
0978       eventTree->Branch("trkfastjetExt_truetp_sumpt", m_trkfastjetExt_truetp_sumpt);
0979 
0980       eventTree->Branch("trkjetExt_eta", &m_trkjetExt_eta);
0981       eventTree->Branch("trkjetExt_vz", &m_trkjetExt_vz);
0982       eventTree->Branch("trkjetExt_p", &m_trkjetExt_p);
0983       eventTree->Branch("trkjetExt_pt", &m_trkjetExt_pt);
0984       eventTree->Branch("trkjetExt_phi", &m_trkjetExt_phi);
0985       eventTree->Branch("trkjetExt_ntracks", &m_trkjetExt_ntracks);
0986       eventTree->Branch("trkjetExt_nDisplaced", &m_trkjetExt_nDisplaced);
0987       eventTree->Branch("trkjetExt_nTight", &m_trkjetExt_nTight);
0988       eventTree->Branch("trkjetExt_nTightDisplaced", &m_trkjetExt_nTightDisplaced);
0989 
0990       eventTree->Branch("trkjetemExt_eta", &m_trkjetemExt_eta);
0991       eventTree->Branch("trkjetemExt_pt", &m_trkjetemExt_pt);
0992       eventTree->Branch("trkjetemExt_phi", &m_trkjetemExt_phi);
0993       eventTree->Branch("trkjetemExt_z", &m_trkjetemExt_z);
0994       eventTree->Branch("trkjetemExt_ntracks", &m_trkjetemExt_ntracks);
0995       eventTree->Branch("trkjetemExt_nxtracks", &m_trkjetemExt_nxtracks);
0996     }
0997   }
0998 
0999   if (SaveTrackSums) {
1000     eventTree->Branch("trueMET", &trueMET, "trueMET/F");
1001     eventTree->Branch("trueTkMET", &trueTkMET, "trueTkMET/F");
1002 
1003     if (Displaced == "Prompt" || Displaced == "Both") {
1004       eventTree->Branch("trkMET", &trkMET, "trkMET/F");
1005       eventTree->Branch("trkMETEmu", &trkMETEmu, "trkMETEmu/F");
1006       eventTree->Branch("trkMHT", &trkMHT, "trkMHT/F");
1007       eventTree->Branch("trkHT", &trkHT, "trkHT/F");
1008       eventTree->Branch("trkMHTEmu", &trkMHTEmu, "trkMHTEmu/F");
1009       eventTree->Branch("trkMHTEmuPhi", &trkMHTEmuPhi, "trkMHTEmuPhi/F");
1010       eventTree->Branch("trkHTEmu", &trkHTEmu, "trkHTEmu/F");
1011     }
1012     if (Displaced == "Displaced" || Displaced == "Both") {
1013       eventTree->Branch("trkMETExt", &trkMETExt, "trkMETExt/F");
1014       eventTree->Branch("trkMHTExt", &trkMHTExt, "trkMHTExt/F");
1015       eventTree->Branch("trkHTExt", &trkHTExt, "trkHTExt/F");
1016       eventTree->Branch("trkMHTEmuExt", &trkMHTEmuExt, "trkMHTEmuExt/F");
1017       eventTree->Branch("trkMHTEmuPhiExt", &trkMHTEmuPhiExt, "trkMHTEmuPhiExt/F");
1018       eventTree->Branch("trkHTEmuExt", &trkHTEmuExt, "trkHTEmuExt/F");
1019     }
1020   }
1021 }
1022 
1023 //////////
1024 // ANALYZE
1025 void L1TrackObjectNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
1026   if (not available_)
1027     return;  // No ROOT file open.
1028 
1029   if (!(MyProcess == 13 || MyProcess == 11 || MyProcess == 211 || MyProcess == 6 || MyProcess == 15 ||
1030         MyProcess == 1)) {
1031     edm::LogVerbatim("Tracklet") << "The specified MyProcess is invalid! Exiting...";
1032     return;
1033   }
1034 
1035   // clear variables
1036   if (SaveAllTracks && (Displaced == "Prompt" || Displaced == "Both")) {
1037     m_trk_pt->clear();
1038     m_trk_eta->clear();
1039     m_trk_phi->clear();
1040     m_trk_phi_local->clear();
1041     m_trk_d0->clear();
1042     m_trk_z0->clear();
1043     m_trk_chi2->clear();
1044     m_trk_chi2dof->clear();
1045     m_trk_chi2rphi->clear();
1046     m_trk_chi2rz->clear();
1047     m_trk_bendchi2->clear();
1048     m_trk_MVA1->clear();
1049     m_trk_nstub->clear();
1050     m_trk_lhits->clear();
1051     m_trk_dhits->clear();
1052     m_trk_seed->clear();
1053     m_trk_hitpattern->clear();
1054     m_trk_phiSector->clear();
1055     m_trk_genuine->clear();
1056     m_trk_loose->clear();
1057     m_trk_unknown->clear();
1058     m_trk_combinatoric->clear();
1059     m_trk_fake->clear();
1060     m_trk_matchtp_pdgid->clear();
1061     m_trk_matchtp_pt->clear();
1062     m_trk_matchtp_eta->clear();
1063     m_trk_matchtp_phi->clear();
1064     m_trk_matchtp_z0->clear();
1065     m_trk_matchtp_dxy->clear();
1066     m_trk_gtt_pt->clear();
1067     m_trk_gtt_eta->clear();
1068     m_trk_gtt_phi->clear();
1069     m_trk_selected_index->clear();
1070     m_trk_selected_emulation_index->clear();
1071   }
1072   if (SaveAllTracks && (Displaced == "Displaced" || Displaced == "Both")) {
1073     m_trkExt_pt->clear();
1074     m_trkExt_eta->clear();
1075     m_trkExt_phi->clear();
1076     m_trkExt_phi_local->clear();
1077     m_trkExt_d0->clear();
1078     m_trkExt_z0->clear();
1079     m_trkExt_chi2->clear();
1080     m_trkExt_chi2dof->clear();
1081     m_trkExt_chi2rphi->clear();
1082     m_trkExt_chi2rz->clear();
1083     m_trkExt_bendchi2->clear();
1084     m_trkExt_MVA->clear();
1085     m_trkExt_nstub->clear();
1086     m_trkExt_lhits->clear();
1087     m_trkExt_dhits->clear();
1088     m_trkExt_seed->clear();
1089     m_trkExt_hitpattern->clear();
1090     m_trkExt_phiSector->clear();
1091     m_trkExt_genuine->clear();
1092     m_trkExt_loose->clear();
1093     m_trkExt_unknown->clear();
1094     m_trkExt_combinatoric->clear();
1095     m_trkExt_fake->clear();
1096     m_trkExt_matchtp_pdgid->clear();
1097     m_trkExt_matchtp_pt->clear();
1098     m_trkExt_matchtp_eta->clear();
1099     m_trkExt_matchtp_phi->clear();
1100     m_trkExt_matchtp_z0->clear();
1101     m_trkExt_matchtp_dxy->clear();
1102     m_trkExt_gtt_pt->clear();
1103     m_trkExt_gtt_eta->clear();
1104     m_trkExt_gtt_phi->clear();
1105     m_trkExt_selected_index->clear();
1106     m_trkExt_selected_emulation_index->clear();
1107   }
1108   m_tp_pt->clear();
1109   m_tp_eta->clear();
1110   m_tp_phi->clear();
1111   m_tp_dxy->clear();
1112   m_tp_d0->clear();
1113   m_tp_z0->clear();
1114   m_tp_d0_prod->clear();
1115   m_tp_z0_prod->clear();
1116   m_tp_pdgid->clear();
1117   m_tp_nmatch->clear();
1118   m_tp_nstub->clear();
1119   m_tp_eventid->clear();
1120   m_tp_charge->clear();
1121 
1122   m_gen_pt->clear();
1123   m_gen_phi->clear();
1124   m_gen_pdgid->clear();
1125   m_gen_z0->clear();
1126 
1127   if (Displaced == "Prompt" || Displaced == "Both") {
1128     m_matchtrk_pt->clear();
1129     m_matchtrk_eta->clear();
1130     m_matchtrk_phi->clear();
1131     m_matchtrk_z0->clear();
1132     m_matchtrk_d0->clear();
1133     m_matchtrk_chi2->clear();
1134     m_matchtrk_chi2dof->clear();
1135     m_matchtrk_chi2rphi->clear();
1136     m_matchtrk_chi2rz->clear();
1137     m_matchtrk_bendchi2->clear();
1138     m_matchtrk_MVA1->clear();
1139     m_matchtrk_nstub->clear();
1140     m_matchtrk_lhits->clear();
1141     m_matchtrk_dhits->clear();
1142     m_matchtrk_seed->clear();
1143     m_matchtrk_hitpattern->clear();
1144   }
1145 
1146   if (Displaced == "Displaced" || Displaced == "Both") {
1147     m_matchtrkExt_pt->clear();
1148     m_matchtrkExt_eta->clear();
1149     m_matchtrkExt_phi->clear();
1150     m_matchtrkExt_z0->clear();
1151     m_matchtrkExt_d0->clear();
1152     m_matchtrkExt_chi2->clear();
1153     m_matchtrkExt_chi2dof->clear();
1154     m_matchtrkExt_chi2rphi->clear();
1155     m_matchtrkExt_chi2rz->clear();
1156     m_matchtrkExt_bendchi2->clear();
1157     m_matchtrkExt_MVA->clear();
1158     m_matchtrkExt_nstub->clear();
1159     m_matchtrkExt_lhits->clear();
1160     m_matchtrkExt_dhits->clear();
1161     m_matchtrkExt_seed->clear();
1162     m_matchtrkExt_hitpattern->clear();
1163   }
1164 
1165   if (SaveStubs) {
1166     m_allstub_x->clear();
1167     m_allstub_y->clear();
1168     m_allstub_z->clear();
1169     m_allstub_isBarrel->clear();
1170     m_allstub_layer->clear();
1171     m_allstub_isPSmodule->clear();
1172     m_allstub_trigDisplace->clear();
1173     m_allstub_trigOffset->clear();
1174     m_allstub_trigPos->clear();
1175     m_allstub_trigBend->clear();
1176     m_allstub_matchTP_pdgid->clear();
1177     m_allstub_matchTP_pt->clear();
1178     m_allstub_matchTP_eta->clear();
1179     m_allstub_matchTP_phi->clear();
1180     m_allstub_genuine->clear();
1181   }
1182 
1183   if (SaveTrackJets) {
1184     if (Displaced == "Prompt" || Displaced == "Both") {
1185       m_trkjet_eta->clear();
1186       m_trkjet_pt->clear();
1187       m_trkjet_vz->clear();
1188       m_trkjet_phi->clear();
1189       m_trkjet_p->clear();
1190       m_trkjet_ntracks->clear();
1191       m_trkjet_nDisplaced->clear();
1192       m_trkjet_nTight->clear();
1193       m_trkjet_nTightDisplaced->clear();
1194       m_trkjet_ntdtrk->clear();
1195       m_trkfastjet_eta->clear();
1196       m_trkfastjet_pt->clear();
1197       m_trkfastjet_vz->clear();
1198       m_trkfastjet_phi->clear();
1199       m_trkfastjet_p->clear();
1200       m_trkfastjet_ntracks->clear();
1201       m_trkfastjet_truetp_sumpt->clear();
1202       m_trkfastjet_tp_sumpt->clear();
1203       m_trkjetem_eta->clear();
1204       m_trkjetem_pt->clear();
1205       m_trkjetem_phi->clear();
1206       m_trkjetem_z->clear();
1207       m_trkjetem_ntracks->clear();
1208       m_trkjetem_nxtracks->clear();
1209     }
1210     if (Displaced == "Displaced" || Displaced == "Both") {
1211       m_trkjetExt_eta->clear();
1212       m_trkjetExt_pt->clear();
1213       m_trkjetExt_vz->clear();
1214       m_trkjetExt_phi->clear();
1215       m_trkjetExt_p->clear();
1216       m_trkjetExt_ntracks->clear();
1217       m_trkjetExt_nDisplaced->clear();
1218       m_trkjetExt_nTight->clear();
1219       m_trkjetExt_nTightDisplaced->clear();
1220       m_trkjetExt_ntdtrk->clear();
1221       m_trkfastjetExt_eta->clear();
1222       m_trkfastjetExt_pt->clear();
1223       m_trkfastjetExt_vz->clear();
1224       m_trkfastjetExt_phi->clear();
1225       m_trkfastjetExt_p->clear();
1226       m_trkfastjetExt_ntracks->clear();
1227       m_trkfastjetExt_truetp_sumpt->clear();
1228       m_trkfastjetExt_tp_sumpt->clear();
1229       m_trkjetemExt_eta->clear();
1230       m_trkjetemExt_pt->clear();
1231       m_trkjetemExt_phi->clear();
1232       m_trkjetemExt_z->clear();
1233       m_trkjetemExt_ntracks->clear();
1234       m_trkjetemExt_nxtracks->clear();
1235     }
1236 
1237     m_pv_L1reco->clear();
1238     m_pv_L1reco_sum->clear();
1239     m_pv_L1reco_emu->clear();
1240     m_pv_MC->clear();
1241     m_MC_lep->clear();
1242   }
1243 
1244   // -----------------------------------------------------------------------------------------------
1245   // retrieve various containers
1246   // -----------------------------------------------------------------------------------------------
1247 
1248   // L1 stubs
1249   edm::Handle<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>> TTStubHandle;
1250   if (SaveStubs)
1251     iEvent.getByToken(ttStubToken_, TTStubHandle);
1252 
1253   // MC truth association maps
1254   edm::Handle<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>> MCTruthTTClusterHandle;
1255   iEvent.getByToken(ttClusterMCTruthToken_, MCTruthTTClusterHandle);
1256   edm::Handle<TTStubAssociationMap<Ref_Phase2TrackerDigi_>> MCTruthTTStubHandle;
1257   iEvent.getByToken(ttStubMCTruthToken_, MCTruthTTStubHandle);
1258 
1259   // tracking particles
1260   edm::Handle<std::vector<TrackingParticle>> TrackingParticleHandle;
1261   edm::Handle<std::vector<TrackingVertex>> TrackingVertexHandle;
1262   iEvent.getByToken(TrackingParticleToken_, TrackingParticleHandle);
1263   iEvent.getByToken(TrackingVertexToken_, TrackingVertexHandle);
1264 
1265   // -----------------------------------------------------------------------------------------------
1266   // more for TTStubs
1267   const TrackerTopology& tTopo = iSetup.getData(tTopoToken_);
1268   const TrackerGeometry& tGeom = iSetup.getData(tGeomToken_);
1269 
1270   //Gen particles
1271   edm::Handle<std::vector<reco::GenParticle>> GenParticleHandle;
1272   iEvent.getByToken(GenParticleToken_, GenParticleHandle);
1273 
1274   //Vertex
1275   edm::Handle<l1t::VertexCollection> L1TkPrimaryVertexHandle;
1276   iEvent.getByToken(L1VertexToken_, L1TkPrimaryVertexHandle);
1277   std::vector<l1t::Vertex>::const_iterator vtxIter;
1278 
1279   edm::Handle<l1t::VertexWordCollection> L1TkPrimaryVertexEmuHandle;
1280   iEvent.getByToken(L1VertexEmuToken_, L1TkPrimaryVertexEmuHandle);
1281   std::vector<l1t::VertexWord>::const_iterator vtxEmuIter;
1282 
1283   // Track jets
1284   edm::Handle<std::vector<l1t::TkJet>> TrackFastJetsHandle;
1285   edm::Handle<std::vector<l1t::TkJet>> TrackFastJetsExtendedHandle;
1286   edm::Handle<l1t::TkJetCollection> TrackJetsHandle;
1287   edm::Handle<l1t::TkJetCollection> TrackJetsExtendedHandle;
1288   edm::Handle<l1t::TkJetWordCollection> TrackJetsEmuHandle;
1289   edm::Handle<l1t::TkJetWordCollection> TrackJetsExtendedEmuHandle;
1290   std::vector<l1t::TkJet>::const_iterator jetIter;
1291   std::vector<l1t::TkJetWord>::const_iterator jetemIter;
1292 
1293   // Track Sums
1294   edm::Handle<std::vector<l1t::TkEtMiss>> L1TkMETHandle;
1295   edm::Handle<std::vector<l1t::TkEtMiss>> L1TkMETExtendedHandle;
1296   edm::Handle<std::vector<l1t::EtSum>> L1TkMETEmuHandle;
1297   edm::Handle<std::vector<l1t::TkHTMiss>> L1TkMHTHandle;
1298   edm::Handle<std::vector<l1t::TkHTMiss>> L1TkMHTExtendedHandle;
1299   edm::Handle<std::vector<l1t::EtSum>> L1TkMHTEmuHandle;
1300   edm::Handle<std::vector<l1t::EtSum>> L1TkMHTEmuExtendedHandle;
1301 
1302   // L1 tracks
1303   edm::Handle<L1TrackCollection> TTTrackHandle;
1304   edm::Handle<L1TrackCollection> TTTrackExtendedHandle;
1305   edm::Handle<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> MCTruthTTTrackHandle;
1306   edm::Handle<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> MCTruthTTTrackExtendedHandle;
1307   edm::Handle<L1TrackCollection> TTTrackGTTHandle;
1308   edm::Handle<L1TrackCollection> TTTrackExtendedGTTHandle;
1309   edm::Handle<L1TrackRefCollection> TTTrackSelectedHandle;
1310   edm::Handle<L1TrackRefCollection> TTTrackSelectedEmulationHandle;
1311   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedHandle;
1312   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedEmulationHandle;
1313   L1TrackCollection::const_iterator iterL1Track;
1314 
1315   if (Displaced == "Prompt" || Displaced == "Both") {
1316     iEvent.getByToken(TrackFastJetsToken_, TrackFastJetsHandle);
1317     iEvent.getByToken(TrackJetsToken_, TrackJetsHandle);
1318     iEvent.getByToken(TrackJetsEmuToken_, TrackJetsEmuHandle);
1319     iEvent.getByToken(TrackMETToken_, L1TkMETHandle);
1320     iEvent.getByToken(TrackMETEmuToken_, L1TkMETEmuHandle);
1321     iEvent.getByToken(TrackMHTToken_, L1TkMHTHandle);
1322     iEvent.getByToken(TrackMHTEmuToken_, L1TkMHTEmuHandle);
1323     iEvent.getByToken(ttTrackToken_, TTTrackHandle);
1324     iEvent.getByToken(ttTrackMCTruthToken_, MCTruthTTTrackHandle);
1325     iEvent.getByToken(ttTrackGTTToken_, TTTrackGTTHandle);
1326     iEvent.getByToken(ttTrackSelectedToken_, TTTrackSelectedHandle);
1327     iEvent.getByToken(ttTrackSelectedEmulationToken_, TTTrackSelectedEmulationHandle);
1328   }
1329   if (Displaced == "Displaced" || Displaced == "Both") {
1330     iEvent.getByToken(TrackFastJetsExtendedToken_, TrackFastJetsExtendedHandle);
1331     iEvent.getByToken(TrackJetsExtendedToken_, TrackJetsExtendedHandle);
1332     iEvent.getByToken(TrackJetsExtendedEmuToken_, TrackJetsExtendedEmuHandle);
1333     iEvent.getByToken(TrackMETExtendedToken_, L1TkMETExtendedHandle);
1334     iEvent.getByToken(TrackMHTExtendedToken_, L1TkMHTExtendedHandle);
1335     iEvent.getByToken(TrackMHTEmuExtendedToken_, L1TkMHTEmuExtendedHandle);
1336     iEvent.getByToken(ttTrackExtendedToken_, TTTrackExtendedHandle);
1337     iEvent.getByToken(ttTrackMCTruthExtendedToken_, MCTruthTTTrackExtendedHandle);
1338     iEvent.getByToken(ttTrackExtendedGTTToken_, TTTrackExtendedGTTHandle);
1339     iEvent.getByToken(ttTrackExtendedSelectedToken_, TTTrackExtendedSelectedHandle);
1340     iEvent.getByToken(ttTrackExtendedSelectedEmulationToken_, TTTrackExtendedSelectedEmulationHandle);
1341   }
1342 
1343   //Loop over gen particles
1344   if (GenParticleHandle.isValid()) {
1345     vector<reco::GenParticle>::const_iterator genpartIter;
1346 
1347     float zvtx_gen = -999;
1348     float trueMETx = 0;
1349     float trueMETy = 0;
1350     trueMET = 0;
1351     for (genpartIter = GenParticleHandle->begin(); genpartIter != GenParticleHandle->end(); ++genpartIter) {
1352       int status = genpartIter->status();
1353       if (status != 1)
1354         continue;
1355       zvtx_gen = genpartIter->vz();  //for gen vertex
1356       int id = genpartIter->pdgId();
1357       bool isNeutrino = false;
1358       if ((std::abs(id) == 12 || std::abs(id) == 14 || std::abs(id) == 16))
1359         isNeutrino = true;
1360       if (isNeutrino || id == 1000022) {
1361         trueMETx += genpartIter->pt() * cos(genpartIter->phi());
1362         trueMETy += genpartIter->pt() * sin(genpartIter->phi());
1363       }
1364 
1365       m_gen_pt->push_back(genpartIter->pt());
1366       m_gen_phi->push_back(genpartIter->phi());
1367       m_gen_pdgid->push_back(genpartIter->pdgId());
1368       m_gen_z0->push_back(zvtx_gen);
1369     }
1370 
1371     trueMET = sqrt(trueMETx * trueMETx + trueMETy * trueMETy);
1372     m_pv_MC->push_back(zvtx_gen);
1373   } else {
1374     edm::LogWarning("DataNotFound") << "\nWarning: GenParticleHandle not found in the event" << std::endl;
1375   }
1376 
1377   // ----------------------------------------------------------------------------------------------
1378   // loop over L1 stubs
1379   // ----------------------------------------------------------------------------------------------
1380   if (SaveStubs) {
1381     for (auto gd = tGeom.dets().begin(); gd != tGeom.dets().end(); gd++) {
1382       DetId detid = (*gd)->geographicalId();
1383       if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
1384         continue;
1385       if (!tTopo.isLower(detid))
1386         continue;                             // loop on the stacks: choose the lower arbitrarily
1387       DetId stackDetid = tTopo.stack(detid);  // Stub module detid
1388 
1389       if (TTStubHandle->find(stackDetid) == TTStubHandle->end())
1390         continue;
1391 
1392       // Get the DetSets of the Clusters
1393       edmNew::DetSet<TTStub<Ref_Phase2TrackerDigi_>> stubs = (*TTStubHandle)[stackDetid];
1394       const GeomDetUnit* det0 = tGeom.idToDetUnit(detid);
1395       const auto* theGeomDet = dynamic_cast<const PixelGeomDetUnit*>(det0);
1396       const PixelTopology* topol = dynamic_cast<const PixelTopology*>(&(theGeomDet->specificTopology()));
1397 
1398       // loop over stubs
1399       for (auto stubIter = stubs.begin(); stubIter != stubs.end(); ++stubIter) {
1400         edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>> tempStubPtr =
1401             edmNew::makeRefTo(TTStubHandle, stubIter);
1402 
1403         int isBarrel = 0;
1404         int layer = -999999;
1405         if (detid.subdetId() == StripSubdetector::TOB) {
1406           isBarrel = 1;
1407           layer = static_cast<int>(tTopo.layer(detid));
1408         } else if (detid.subdetId() == StripSubdetector::TID) {
1409           isBarrel = 0;
1410           layer = static_cast<int>(tTopo.layer(detid));
1411         } else {
1412           edm::LogVerbatim("Tracklet") << "WARNING -- neither TOB or TID stub, shouldn't happen...";
1413           layer = -1;
1414         }
1415 
1416         int isPSmodule = 0;
1417         if (topol->nrows() == 960)
1418           isPSmodule = 1;
1419 
1420         MeasurementPoint coords = tempStubPtr->clusterRef(0)->findAverageLocalCoordinatesCentered();
1421         LocalPoint clustlp = topol->localPosition(coords);
1422         GlobalPoint posStub = theGeomDet->surface().toGlobal(clustlp);
1423 
1424         double tmp_stub_x = posStub.x();
1425         double tmp_stub_y = posStub.y();
1426         double tmp_stub_z = posStub.z();
1427 
1428         float trigDisplace = tempStubPtr->rawBend();
1429         float trigOffset = tempStubPtr->bendOffset();
1430         float trigPos = tempStubPtr->innerClusterPosition();
1431         float trigBend = tempStubPtr->bendFE();
1432 
1433         m_allstub_x->push_back(tmp_stub_x);
1434         m_allstub_y->push_back(tmp_stub_y);
1435         m_allstub_z->push_back(tmp_stub_z);
1436         m_allstub_isBarrel->push_back(isBarrel);
1437         m_allstub_layer->push_back(layer);
1438         m_allstub_isPSmodule->push_back(isPSmodule);
1439         m_allstub_trigDisplace->push_back(trigDisplace);
1440         m_allstub_trigOffset->push_back(trigOffset);
1441         m_allstub_trigPos->push_back(trigPos);
1442         m_allstub_trigBend->push_back(trigBend);
1443 
1444         // matched to tracking particle?
1445         edm::Ptr<TrackingParticle> my_tp = MCTruthTTStubHandle->findTrackingParticlePtr(tempStubPtr);
1446 
1447         int myTP_pdgid = -999;
1448         float myTP_pt = -999;
1449         float myTP_eta = -999;
1450         float myTP_phi = -999;
1451 
1452         if (my_tp.isNull() == false) {
1453           int tmp_eventid = my_tp->eventId().event();
1454           if (tmp_eventid > 0)
1455             continue;  // this means stub from pileup track
1456           myTP_pdgid = my_tp->pdgId();
1457           myTP_pt = my_tp->p4().pt();
1458           myTP_eta = my_tp->p4().eta();
1459           myTP_phi = my_tp->p4().phi();
1460         }
1461         int tmp_stub_genuine = 0;
1462         if (MCTruthTTStubHandle->isGenuine(tempStubPtr))
1463           tmp_stub_genuine = 1;
1464 
1465         m_allstub_matchTP_pdgid->push_back(myTP_pdgid);
1466         m_allstub_matchTP_pt->push_back(myTP_pt);
1467         m_allstub_matchTP_eta->push_back(myTP_eta);
1468         m_allstub_matchTP_phi->push_back(myTP_phi);
1469         m_allstub_genuine->push_back(tmp_stub_genuine);
1470       }
1471     }
1472   }
1473 
1474   // ----------------------------------------------------------------------------------------------
1475   // loop over (prompt) L1 tracks
1476   // ----------------------------------------------------------------------------------------------
1477   if (SaveAllTracks && (Displaced == "Prompt" || Displaced == "Both")) {
1478     if (DebugMode) {
1479       edm::LogVerbatim("Tracklet") << "\n Loop over L1 tracks!";
1480       edm::LogVerbatim("Tracklet") << "\n Looking at " << Displaced << " tracks!";
1481     }
1482 
1483     int this_l1track = 0;
1484     for (iterL1Track = TTTrackHandle->begin(); iterL1Track != TTTrackHandle->end(); iterL1Track++) {
1485       L1TrackPtr l1track_ptr(TTTrackHandle, this_l1track);
1486       L1TrackRef l1track_ref(TTTrackGTTHandle, this_l1track);
1487       this_l1track++;
1488 
1489       float tmp_trk_pt = iterL1Track->momentum().perp();
1490       float tmp_trk_eta = iterL1Track->momentum().eta();
1491       float tmp_trk_phi = iterL1Track->momentum().phi();
1492       float tmp_trk_phi_local = iterL1Track->localPhi();
1493       float tmp_trk_z0 = iterL1Track->z0();            //cm
1494       int tmp_trk_nFitPars = iterL1Track->nFitPars();  //4 or 5
1495 
1496       float tmp_trk_d0 = -999;
1497       if (tmp_trk_nFitPars == 5) {
1498         float tmp_trk_x0 = iterL1Track->POCA().x();
1499         float tmp_trk_y0 = iterL1Track->POCA().y();
1500         tmp_trk_d0 = -tmp_trk_x0 * sin(tmp_trk_phi) + tmp_trk_y0 * cos(tmp_trk_phi);
1501         // tmp_trk_d0 = iterL1Track->d0();
1502       }
1503 
1504       float tmp_trk_chi2 = iterL1Track->chi2();
1505       float tmp_trk_chi2dof = iterL1Track->chi2Red();
1506       float tmp_trk_chi2rphi = iterL1Track->chi2XYRed();
1507       float tmp_trk_chi2rz = iterL1Track->chi2ZRed();
1508       float tmp_trk_bendchi2 = iterL1Track->stubPtConsistency();
1509       float tmp_trk_MVA1 = -99.9;  //update with actual MVA when available
1510 
1511       std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
1512           stubRefs = iterL1Track->getStubRefs();
1513       int tmp_trk_nstub = (int)stubRefs.size();
1514       int tmp_trk_seed = 0;
1515       tmp_trk_seed = (int)iterL1Track->trackSeedType();
1516       int tmp_trk_hitpattern = 0;
1517       tmp_trk_hitpattern = (int)iterL1Track->hitPattern();
1518       unsigned int tmp_trk_phiSector = iterL1Track->phiSector();
1519 
1520       // ----------------------------------------------------------------------------------------------
1521       // loop over stubs on tracks
1522       int tmp_trk_dhits = 0;
1523       int tmp_trk_lhits = 0;
1524       if (true) {
1525         // loop over stubs
1526         for (int is = 0; is < tmp_trk_nstub; is++) {
1527           //detID of stub
1528           DetId detIdStub = tGeom.idToDet((stubRefs.at(is)->clusterRef(0))->getDetId())->geographicalId();
1529           MeasurementPoint coords = stubRefs.at(is)->clusterRef(0)->findAverageLocalCoordinatesCentered();
1530           const GeomDet* theGeomDet = tGeom.idToDet(detIdStub);
1531           Global3DPoint posStub = theGeomDet->surface().toGlobal(theGeomDet->topology().localPosition(coords));
1532 
1533           double x = posStub.x();
1534           double y = posStub.y();
1535           double z = posStub.z();
1536 
1537           int layer = -999999;
1538           if (detIdStub.subdetId() == StripSubdetector::TOB) {
1539             layer = static_cast<int>(tTopo.layer(detIdStub));
1540             if (DebugMode)
1541               edm::LogVerbatim("Tracklet")
1542                   << "   stub in layer " << layer << " at position x y z = " << x << " " << y << " " << z;
1543             tmp_trk_lhits += pow(10, layer - 1);
1544           } else if (detIdStub.subdetId() == StripSubdetector::TID) {
1545             layer = static_cast<int>(tTopo.layer(detIdStub));
1546             if (DebugMode)
1547               edm::LogVerbatim("Tracklet")
1548                   << "   stub in disk " << layer << " at position x y z = " << x << " " << y << " " << z;
1549             tmp_trk_dhits += pow(10, layer - 1);
1550           }
1551         }  //end loop over stubs
1552       }
1553       // ----------------------------------------------------------------------------------------------
1554 
1555       int tmp_trk_genuine = 0;
1556       int tmp_trk_loose = 0;
1557       int tmp_trk_unknown = 0;
1558       int tmp_trk_combinatoric = 0;
1559       if (MCTruthTTTrackHandle->isLooselyGenuine(l1track_ptr))
1560         tmp_trk_loose = 1;
1561       if (MCTruthTTTrackHandle->isGenuine(l1track_ptr))
1562         tmp_trk_genuine = 1;
1563       if (MCTruthTTTrackHandle->isUnknown(l1track_ptr))
1564         tmp_trk_unknown = 1;
1565       if (MCTruthTTTrackHandle->isCombinatoric(l1track_ptr))
1566         tmp_trk_combinatoric = 1;
1567 
1568       if (DebugMode) {
1569         edm::LogVerbatim("Tracklet") << "L1 track,"
1570                                      << " pt: " << tmp_trk_pt << " eta: " << tmp_trk_eta << " phi: " << tmp_trk_phi
1571                                      << " z0: " << tmp_trk_z0 << " chi2: " << tmp_trk_chi2
1572                                      << " chi2rphi: " << tmp_trk_chi2rphi << " chi2rz: " << tmp_trk_chi2rz
1573                                      << " nstub: " << tmp_trk_nstub;
1574         if (tmp_trk_genuine)
1575           edm::LogVerbatim("Tracklet") << "    (is genuine)";
1576         if (tmp_trk_unknown)
1577           edm::LogVerbatim("Tracklet") << "    (is unknown)";
1578         if (tmp_trk_combinatoric)
1579           edm::LogVerbatim("Tracklet") << "    (is combinatoric)";
1580       }
1581 
1582       m_trk_pt->push_back(tmp_trk_pt);
1583       m_trk_eta->push_back(tmp_trk_eta);
1584       m_trk_phi->push_back(tmp_trk_phi);
1585       m_trk_phi_local->push_back(tmp_trk_phi_local);
1586       m_trk_z0->push_back(tmp_trk_z0);
1587       if (tmp_trk_nFitPars == 5)
1588         m_trk_d0->push_back(tmp_trk_d0);
1589       else
1590         m_trk_d0->push_back(999.);
1591       m_trk_chi2->push_back(tmp_trk_chi2);
1592       m_trk_chi2dof->push_back(tmp_trk_chi2dof);
1593       m_trk_chi2rphi->push_back(tmp_trk_chi2rphi);
1594       m_trk_chi2rz->push_back(tmp_trk_chi2rz);
1595       m_trk_bendchi2->push_back(tmp_trk_bendchi2);
1596       m_trk_MVA1->push_back(tmp_trk_MVA1);
1597       m_trk_nstub->push_back(tmp_trk_nstub);
1598       m_trk_dhits->push_back(tmp_trk_dhits);
1599       m_trk_lhits->push_back(tmp_trk_lhits);
1600       m_trk_seed->push_back(tmp_trk_seed);
1601       m_trk_hitpattern->push_back(tmp_trk_hitpattern);
1602       m_trk_phiSector->push_back(tmp_trk_phiSector);
1603       m_trk_genuine->push_back(tmp_trk_genuine);
1604       m_trk_loose->push_back(tmp_trk_loose);
1605       m_trk_unknown->push_back(tmp_trk_unknown);
1606       m_trk_combinatoric->push_back(tmp_trk_combinatoric);
1607 
1608       // ----------------------------------------------------------------------------------------------
1609       // for studying the fake rate
1610       // ----------------------------------------------------------------------------------------------
1611       edm::Ptr<TrackingParticle> my_tp = MCTruthTTTrackHandle->findTrackingParticlePtr(l1track_ptr);
1612 
1613       int myFake = 0;
1614       int myTP_pdgid = -999;
1615       float myTP_pt = -999;
1616       float myTP_eta = -999;
1617       float myTP_phi = -999;
1618       float myTP_z0 = -999;
1619       float myTP_dxy = -999;
1620 
1621       if (my_tp.isNull())
1622         myFake = 0;
1623       else {
1624         int tmp_eventid = my_tp->eventId().event();
1625         if (tmp_eventid > 0)
1626           myFake = 2;
1627         else
1628           myFake = 1;
1629 
1630         myTP_pdgid = my_tp->pdgId();
1631         myTP_pt = my_tp->p4().pt();
1632         myTP_eta = my_tp->p4().eta();
1633         myTP_phi = my_tp->p4().phi();
1634         myTP_z0 = my_tp->vertex().z();
1635 
1636         float myTP_x0 = my_tp->vertex().x();
1637         float myTP_y0 = my_tp->vertex().y();
1638         myTP_dxy = sqrt(myTP_x0 * myTP_x0 + myTP_y0 * myTP_y0);
1639 
1640         if (DebugMode) {
1641           edm::LogVerbatim("Tracklet") << "TP matched to track has pt = " << my_tp->p4().pt()
1642                                        << " eta = " << my_tp->momentum().eta() << " phi = " << my_tp->momentum().phi()
1643                                        << " z0 = " << my_tp->vertex().z() << " pdgid = " << my_tp->pdgId()
1644                                        << " dxy = " << myTP_dxy;
1645         }
1646       }
1647 
1648       m_trk_fake->push_back(myFake);
1649       m_trk_matchtp_pdgid->push_back(myTP_pdgid);
1650       m_trk_matchtp_pt->push_back(myTP_pt);
1651       m_trk_matchtp_eta->push_back(myTP_eta);
1652       m_trk_matchtp_phi->push_back(myTP_phi);
1653       m_trk_matchtp_z0->push_back(myTP_z0);
1654       m_trk_matchtp_dxy->push_back(myTP_dxy);
1655 
1656       // ----------------------------------------------------------------------------------------------
1657       // store the index to the selected track or -1 if not selected
1658       // ----------------------------------------------------------------------------------------------
1659       m_trk_gtt_pt->push_back(l1track_ref->momentum().perp());
1660       m_trk_gtt_eta->push_back(l1track_ref->momentum().eta());
1661       m_trk_gtt_phi->push_back(l1track_ref->momentum().phi());
1662       m_trk_selected_index->push_back(getSelectedTrackIndex(l1track_ref, TTTrackSelectedHandle));
1663       m_trk_selected_emulation_index->push_back(getSelectedTrackIndex(l1track_ref, TTTrackSelectedEmulationHandle));
1664     }  //end track loop
1665   }    //end if SaveAllTracks
1666 
1667   // ----------------------------------------------------------------------------------------------
1668   // loop over (extended) L1 tracks
1669   // ----------------------------------------------------------------------------------------------
1670   if (SaveAllTracks && (Displaced == "Displaced" || Displaced == "Both")) {
1671     if (DebugMode) {
1672       edm::LogVerbatim("Tracklet") << "\n Loop over L1 tracks!";
1673       edm::LogVerbatim("Tracklet") << "\n Looking at " << Displaced << " tracks!";
1674     }
1675 
1676     int this_l1track = 0;
1677     for (iterL1Track = TTTrackExtendedHandle->begin(); iterL1Track != TTTrackExtendedHandle->end(); iterL1Track++) {
1678       L1TrackPtr l1track_ptr(TTTrackExtendedHandle, this_l1track);
1679       L1TrackRef l1track_ref(TTTrackExtendedGTTHandle, this_l1track);
1680       this_l1track++;
1681 
1682       float tmp_trk_pt = iterL1Track->momentum().perp();
1683       float tmp_trk_eta = iterL1Track->momentum().eta();
1684       float tmp_trk_phi = iterL1Track->momentum().phi();
1685       float tmp_trk_phi_local = iterL1Track->localPhi();
1686       float tmp_trk_z0 = iterL1Track->z0();            //cm
1687       int tmp_trk_nFitPars = iterL1Track->nFitPars();  //4 or 5
1688 
1689       float tmp_trk_d0 = -999;
1690       if (tmp_trk_nFitPars == 5) {
1691         float tmp_trk_x0 = iterL1Track->POCA().x();
1692         float tmp_trk_y0 = iterL1Track->POCA().y();
1693         tmp_trk_d0 = -tmp_trk_x0 * sin(tmp_trk_phi) + tmp_trk_y0 * cos(tmp_trk_phi);
1694         // tmp_trk_d0 = iterL1Track->d0();
1695       }
1696 
1697       float tmp_trk_chi2 = iterL1Track->chi2();
1698       float tmp_trk_chi2dof = iterL1Track->chi2Red();
1699       float tmp_trk_chi2rphi = iterL1Track->chi2XYRed();
1700       float tmp_trk_chi2rz = iterL1Track->chi2ZRed();
1701       float tmp_trk_bendchi2 = iterL1Track->stubPtConsistency();
1702       float tmp_trk_MVA1 = -99.9;  //update when actual MVA is available
1703 
1704       std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
1705           stubRefs = iterL1Track->getStubRefs();
1706       int tmp_trk_nstub = (int)stubRefs.size();
1707       int tmp_trk_seed = 0;
1708       tmp_trk_seed = (int)iterL1Track->trackSeedType();
1709       int tmp_trk_hitpattern = 0;
1710       tmp_trk_hitpattern = (int)iterL1Track->hitPattern();
1711       unsigned int tmp_trk_phiSector = iterL1Track->phiSector();
1712 
1713       // ----------------------------------------------------------------------------------------------
1714       // loop over stubs on tracks
1715       int tmp_trk_dhits = 0;
1716       int tmp_trk_lhits = 0;
1717       if (true) {
1718         // loop over stubs
1719         for (int is = 0; is < tmp_trk_nstub; is++) {
1720           //detID of stub
1721           DetId detIdStub = tGeom.idToDet((stubRefs.at(is)->clusterRef(0))->getDetId())->geographicalId();
1722           MeasurementPoint coords = stubRefs.at(is)->clusterRef(0)->findAverageLocalCoordinatesCentered();
1723           const GeomDet* theGeomDet = tGeom.idToDet(detIdStub);
1724           Global3DPoint posStub = theGeomDet->surface().toGlobal(theGeomDet->topology().localPosition(coords));
1725 
1726           double x = posStub.x();
1727           double y = posStub.y();
1728           double z = posStub.z();
1729 
1730           int layer = -999999;
1731           if (detIdStub.subdetId() == StripSubdetector::TOB) {
1732             layer = static_cast<int>(tTopo.layer(detIdStub));
1733             if (DebugMode)
1734               edm::LogVerbatim("Tracklet")
1735                   << "   stub in layer " << layer << " at position x y z = " << x << " " << y << " " << z;
1736             tmp_trk_lhits += pow(10, layer - 1);
1737           } else if (detIdStub.subdetId() == StripSubdetector::TID) {
1738             layer = static_cast<int>(tTopo.layer(detIdStub));
1739             if (DebugMode)
1740               edm::LogVerbatim("Tracklet")
1741                   << "   stub in disk " << layer << " at position x y z = " << x << " " << y << " " << z;
1742             tmp_trk_dhits += pow(10, layer - 1);
1743           }
1744         }  //end loop over stubs
1745       }
1746       // ----------------------------------------------------------------------------------------------
1747 
1748       int tmp_trk_genuine = 0;
1749       int tmp_trk_loose = 0;
1750       int tmp_trk_unknown = 0;
1751       int tmp_trk_combinatoric = 0;
1752       if (MCTruthTTTrackExtendedHandle->isLooselyGenuine(l1track_ptr))
1753         tmp_trk_loose = 1;
1754       if (MCTruthTTTrackExtendedHandle->isGenuine(l1track_ptr))
1755         tmp_trk_genuine = 1;
1756       if (MCTruthTTTrackExtendedHandle->isUnknown(l1track_ptr))
1757         tmp_trk_unknown = 1;
1758       if (MCTruthTTTrackExtendedHandle->isCombinatoric(l1track_ptr))
1759         tmp_trk_combinatoric = 1;
1760 
1761       if (DebugMode) {
1762         edm::LogVerbatim("Tracklet") << "L1 track,"
1763                                      << " pt: " << tmp_trk_pt << " eta: " << tmp_trk_eta << " phi: " << tmp_trk_phi
1764                                      << " z0: " << tmp_trk_z0 << " chi2: " << tmp_trk_chi2
1765                                      << " chi2rphi: " << tmp_trk_chi2rphi << " chi2rz: " << tmp_trk_chi2rz
1766                                      << " nstub: " << tmp_trk_nstub;
1767         if (tmp_trk_genuine)
1768           edm::LogVerbatim("Tracklet") << "    (is genuine)";
1769         if (tmp_trk_unknown)
1770           edm::LogVerbatim("Tracklet") << "    (is unknown)";
1771         if (tmp_trk_combinatoric)
1772           edm::LogVerbatim("Tracklet") << "    (is combinatoric)";
1773       }
1774 
1775       m_trkExt_pt->push_back(tmp_trk_pt);
1776       m_trkExt_eta->push_back(tmp_trk_eta);
1777       m_trkExt_phi->push_back(tmp_trk_phi);
1778       m_trkExt_phi_local->push_back(tmp_trk_phi_local);
1779       m_trkExt_z0->push_back(tmp_trk_z0);
1780       if (tmp_trk_nFitPars == 5)
1781         m_trkExt_d0->push_back(tmp_trk_d0);
1782       else
1783         m_trkExt_d0->push_back(999.);
1784       m_trkExt_chi2->push_back(tmp_trk_chi2);
1785       m_trkExt_chi2dof->push_back(tmp_trk_chi2dof);
1786       m_trkExt_chi2rphi->push_back(tmp_trk_chi2rphi);
1787       m_trkExt_chi2rz->push_back(tmp_trk_chi2rz);
1788       m_trkExt_bendchi2->push_back(tmp_trk_bendchi2);
1789       m_trkExt_MVA->push_back(tmp_trk_MVA1);
1790       m_trkExt_nstub->push_back(tmp_trk_nstub);
1791       m_trkExt_dhits->push_back(tmp_trk_dhits);
1792       m_trkExt_lhits->push_back(tmp_trk_lhits);
1793       m_trkExt_seed->push_back(tmp_trk_seed);
1794       m_trkExt_hitpattern->push_back(tmp_trk_hitpattern);
1795       m_trkExt_phiSector->push_back(tmp_trk_phiSector);
1796       m_trkExt_genuine->push_back(tmp_trk_genuine);
1797       m_trkExt_loose->push_back(tmp_trk_loose);
1798       m_trkExt_unknown->push_back(tmp_trk_unknown);
1799       m_trkExt_combinatoric->push_back(tmp_trk_combinatoric);
1800 
1801       // ----------------------------------------------------------------------------------------------
1802       // for studying the fake rate
1803       // ----------------------------------------------------------------------------------------------
1804       edm::Ptr<TrackingParticle> my_tp = MCTruthTTTrackExtendedHandle->findTrackingParticlePtr(l1track_ptr);
1805 
1806       int myFake = 0;
1807       int myTP_pdgid = -999;
1808       float myTP_pt = -999;
1809       float myTP_eta = -999;
1810       float myTP_phi = -999;
1811       float myTP_z0 = -999;
1812       float myTP_dxy = -999;
1813 
1814       if (my_tp.isNull())
1815         myFake = 0;
1816       else {
1817         int tmp_eventid = my_tp->eventId().event();
1818         if (tmp_eventid > 0)
1819           myFake = 2;
1820         else
1821           myFake = 1;
1822 
1823         myTP_pdgid = my_tp->pdgId();
1824         myTP_pt = my_tp->p4().pt();
1825         myTP_eta = my_tp->p4().eta();
1826         myTP_phi = my_tp->p4().phi();
1827         myTP_z0 = my_tp->vertex().z();
1828 
1829         float myTP_x0 = my_tp->vertex().x();
1830         float myTP_y0 = my_tp->vertex().y();
1831         myTP_dxy = sqrt(myTP_x0 * myTP_x0 + myTP_y0 * myTP_y0);
1832 
1833         if (DebugMode) {
1834           edm::LogVerbatim("Tracklet") << "TP matched to track has pt = " << my_tp->p4().pt()
1835                                        << " eta = " << my_tp->momentum().eta() << " phi = " << my_tp->momentum().phi()
1836                                        << " z0 = " << my_tp->vertex().z() << " pdgid = " << my_tp->pdgId()
1837                                        << " dxy = " << myTP_dxy;
1838         }
1839       }
1840 
1841       m_trkExt_fake->push_back(myFake);
1842       m_trkExt_matchtp_pdgid->push_back(myTP_pdgid);
1843       m_trkExt_matchtp_pt->push_back(myTP_pt);
1844       m_trkExt_matchtp_eta->push_back(myTP_eta);
1845       m_trkExt_matchtp_phi->push_back(myTP_phi);
1846       m_trkExt_matchtp_z0->push_back(myTP_z0);
1847       m_trkExt_matchtp_dxy->push_back(myTP_dxy);
1848 
1849       // ----------------------------------------------------------------------------------------------
1850       // store the index to the selected track or -1 if not selected
1851       // ----------------------------------------------------------------------------------------------
1852       m_trkExt_gtt_pt->push_back(l1track_ref->momentum().perp());
1853       m_trkExt_gtt_eta->push_back(l1track_ref->momentum().eta());
1854       m_trkExt_gtt_phi->push_back(l1track_ref->momentum().phi());
1855       m_trkExt_selected_index->push_back(getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedHandle));
1856       m_trkExt_selected_emulation_index->push_back(
1857           getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedEmulationHandle));
1858     }  //end track loop
1859   }    //end if SaveAllTracks (displaced)
1860 
1861   // ----------------------------------------------------------------------------------------------
1862   // loop over tracking particles
1863   // ----------------------------------------------------------------------------------------------
1864   if (DebugMode)
1865     edm::LogVerbatim("Tracklet") << "\n Loop over tracking particles!";
1866 
1867   trueTkMET = 0;
1868   float trueTkMETx = 0;
1869   float trueTkMETy = 0;
1870 
1871   int this_tp = 0;
1872   std::vector<TrackingParticle>::const_iterator iterTP;
1873   for (iterTP = TrackingParticleHandle->begin(); iterTP != TrackingParticleHandle->end(); ++iterTP) {
1874     edm::Ptr<TrackingParticle> tp_ptr(TrackingParticleHandle, this_tp);
1875     this_tp++;
1876 
1877     int tmp_eventid = iterTP->eventId().event();
1878     if (MyProcess != 1 && tmp_eventid > 0)
1879       continue;  //only care about primary interaction
1880 
1881     float tmp_tp_pt = iterTP->pt();
1882     float tmp_tp_eta = iterTP->eta();
1883     float tmp_tp_phi = iterTP->phi();
1884     float tmp_tp_vz = iterTP->vz();
1885     float tmp_tp_vx = iterTP->vx();
1886     float tmp_tp_vy = iterTP->vy();
1887     int tmp_tp_pdgid = iterTP->pdgId();
1888     float tmp_tp_z0_prod = tmp_tp_vz;
1889     float tmp_tp_d0_prod = tmp_tp_vx * sin(tmp_tp_phi) - tmp_tp_vy * cos(tmp_tp_phi);
1890 
1891     if (MyProcess == 13 && abs(tmp_tp_pdgid) != 13)
1892       continue;
1893     if (MyProcess == 11 && abs(tmp_tp_pdgid) != 11)
1894       continue;
1895     if ((MyProcess == 6 || MyProcess == 15 || MyProcess == 211) && abs(tmp_tp_pdgid) != 211)
1896       continue;
1897 
1898     if (tmp_tp_pt < TP_minPt)
1899       continue;
1900     if (std::abs(tmp_tp_eta) > TP_maxEta)
1901       continue;
1902 
1903     // ----------------------------------------------------------------------------------------------
1904     // get d0/z0 propagated back to the IP
1905     float tmp_tp_t = tan(2.0 * atan(1.0) - 2.0 * atan(exp(-tmp_tp_eta)));
1906     float delx = -tmp_tp_vx;
1907     float dely = -tmp_tp_vy;
1908 
1909     float A = 0.01 * 0.5696;
1910     float Kmagnitude = A / tmp_tp_pt;
1911     float tmp_tp_charge = tp_ptr->charge();
1912     float K = Kmagnitude * tmp_tp_charge;
1913     float d = 0;
1914     float tmp_tp_x0p = delx - (d + 1. / (2. * K) * sin(tmp_tp_phi));
1915     float tmp_tp_y0p = dely + (d + 1. / (2. * K) * cos(tmp_tp_phi));
1916     float tmp_tp_rp = sqrt(tmp_tp_x0p * tmp_tp_x0p + tmp_tp_y0p * tmp_tp_y0p);
1917     float tmp_tp_d0 = tmp_tp_charge * tmp_tp_rp - (1. / (2. * K));
1918     tmp_tp_d0 = tmp_tp_d0 * (-1);  //fix d0 sign
1919     const double pi = 4.0 * atan(1.0);
1920     float delphi = tmp_tp_phi - atan2(-K * tmp_tp_x0p, K * tmp_tp_y0p);
1921     if (delphi < -pi)
1922       delphi += 2.0 * pi;
1923     if (delphi > pi)
1924       delphi -= 2.0 * pi;
1925     float tmp_tp_z0 = tmp_tp_vz + tmp_tp_t * delphi / (2.0 * K);
1926     // ----------------------------------------------------------------------------------------------
1927 
1928     if (std::abs(tmp_tp_z0) > TP_maxZ0)
1929       continue;
1930 
1931     // for pions in ttbar, only consider TPs coming from near the IP!
1932     float dxy = sqrt(tmp_tp_vx * tmp_tp_vx + tmp_tp_vy * tmp_tp_vy);
1933     float tmp_tp_dxy = dxy;
1934     if (MyProcess == 6 && (dxy > 1.0))
1935       continue;
1936 
1937     if (DebugMode && (Displaced == "Prompt" || Displaced == "Both"))
1938       edm::LogVerbatim("Tracklet") << "Tracking particle, pt: " << tmp_tp_pt << " eta: " << tmp_tp_eta
1939                                    << " phi: " << tmp_tp_phi << " z0: " << tmp_tp_z0 << " d0: " << tmp_tp_d0
1940                                    << " z_prod: " << tmp_tp_z0_prod << " d_prod: " << tmp_tp_d0_prod
1941                                    << " pdgid: " << tmp_tp_pdgid << " eventID: " << iterTP->eventId().event()
1942                                    << " ttclusters " << MCTruthTTClusterHandle->findTTClusterRefs(tp_ptr).size()
1943                                    << " ttstubs " << MCTruthTTStubHandle->findTTStubRefs(tp_ptr).size() << " tttracks "
1944                                    << MCTruthTTTrackHandle->findTTTrackPtrs(tp_ptr).size();
1945 
1946     // ----------------------------------------------------------------------------------------------
1947     // only consider TPs associated with >= 1 cluster, or >= X stubs, or have stubs in >= X layers (configurable options)
1948     if (MCTruthTTClusterHandle->findTTClusterRefs(tp_ptr).empty()) {
1949       if (DebugMode)
1950         edm::LogVerbatim("Tracklet") << "No matching TTClusters for TP, continuing...";
1951       continue;
1952     }
1953 
1954     std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
1955         theStubRefs = MCTruthTTStubHandle->findTTStubRefs(tp_ptr);
1956     int nStubTP = (int)theStubRefs.size();
1957 
1958     // how many layers/disks have stubs?
1959     int hasStubInLayer[11] = {0};
1960     for (auto& theStubRef : theStubRefs) {
1961       DetId detid(theStubRef->getDetId());
1962 
1963       int layer = -1;
1964       if (detid.subdetId() == StripSubdetector::TOB) {
1965         layer = static_cast<int>(tTopo.layer(detid)) - 1;  //fill in array as entries 0-5
1966       } else if (detid.subdetId() == StripSubdetector::TID) {
1967         layer = static_cast<int>(tTopo.layer(detid)) + 5;  //fill in array as entries 6-10
1968       }
1969 
1970       //treat genuine stubs separately (==2 is genuine, ==1 is not)
1971       if (MCTruthTTStubHandle->findTrackingParticlePtr(theStubRef).isNull() && hasStubInLayer[layer] < 2)
1972         hasStubInLayer[layer] = 1;
1973       else
1974         hasStubInLayer[layer] = 2;
1975     }
1976 
1977     int nStubLayerTP = 0;
1978     int nStubLayerTP_g = 0;
1979     for (int isum : hasStubInLayer) {
1980       if (isum >= 1)
1981         nStubLayerTP += 1;
1982       if (isum == 2)
1983         nStubLayerTP_g += 1;
1984     }
1985 
1986     if (DebugMode)
1987       edm::LogVerbatim("Tracklet") << "TP is associated with " << nStubTP << " stubs, and has stubs in " << nStubLayerTP
1988                                    << " different layers/disks, and has GENUINE stubs in " << nStubLayerTP_g
1989                                    << " layers ";
1990 
1991     if (TP_minNStub > 0) {
1992       if (DebugMode)
1993         edm::LogVerbatim("Tracklet") << "Only consider TPs with >= " << TP_minNStub << " stubs";
1994       if (nStubTP < TP_minNStub) {
1995         if (DebugMode)
1996           edm::LogVerbatim("Tracklet") << "TP fails minimum nbr stubs requirement! Continuing...";
1997         continue;
1998       }
1999     }
2000     if (TP_minNStubLayer > 0) {
2001       if (DebugMode)
2002         edm::LogVerbatim("Tracklet") << "Only consider TPs with stubs in >= " << TP_minNStubLayer << " layers/disks";
2003       if (nStubLayerTP < TP_minNStubLayer) {
2004         if (DebugMode)
2005           edm::LogVerbatim("Tracklet") << "TP fails stubs in minimum nbr of layers/disks requirement! Continuing...";
2006         continue;
2007       }
2008     }
2009 
2010     if (tmp_eventid == 0) {
2011       trueTkMETx += tmp_tp_pt * cos(tmp_tp_phi);
2012       trueTkMETy += tmp_tp_pt * sin(tmp_tp_phi);
2013     }
2014 
2015     m_tp_pt->push_back(tmp_tp_pt);
2016     m_tp_eta->push_back(tmp_tp_eta);
2017     m_tp_phi->push_back(tmp_tp_phi);
2018     m_tp_dxy->push_back(tmp_tp_dxy);
2019     m_tp_z0->push_back(tmp_tp_z0);
2020     m_tp_d0->push_back(tmp_tp_d0);
2021     m_tp_z0_prod->push_back(tmp_tp_z0_prod);
2022     m_tp_d0_prod->push_back(tmp_tp_d0_prod);
2023     m_tp_pdgid->push_back(tmp_tp_pdgid);
2024     m_tp_nstub->push_back(nStubTP);
2025     m_tp_eventid->push_back(tmp_eventid);
2026     m_tp_charge->push_back(tmp_tp_charge);
2027 
2028     // ----------------------------------------------------------------------------------------------
2029     // look for L1 tracks (prompt) matched to the tracking particle
2030     if (Displaced == "Prompt" || Displaced == "Both") {
2031       std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>> matchedTracks =
2032           MCTruthTTTrackHandle->findTTTrackPtrs(tp_ptr);
2033 
2034       int nMatch = 0;
2035       int i_track = -1;
2036       float i_chi2dof = 99999;
2037 
2038       if (!matchedTracks.empty()) {
2039         if (DebugMode && (matchedTracks.size() > 1))
2040           edm::LogVerbatim("Tracklet") << "TrackingParticle has more than one matched L1 track!";
2041 
2042         // ----------------------------------------------------------------------------------------------
2043         // loop over matched L1 tracks
2044         // here, "match" means tracks that can be associated to a TrackingParticle with at least one hit of at least one of its clusters
2045         // https://twiki.cern.ch/twiki/bin/viewauth/CMS/SLHCTrackerTriggerSWTools#MC_truth_for_TTTrack
2046 
2047         for (int it = 0; it < (int)matchedTracks.size(); it++) {
2048           bool tmp_trk_genuine = false;
2049           bool tmp_trk_loosegenuine = false;
2050           if (MCTruthTTTrackHandle->isGenuine(matchedTracks.at(it)))
2051             tmp_trk_genuine = true;
2052           if (MCTruthTTTrackHandle->isLooselyGenuine(matchedTracks.at(it)))
2053             tmp_trk_loosegenuine = true;
2054           if (!tmp_trk_loosegenuine)
2055             continue;
2056 
2057           if (DebugMode) {
2058             if (MCTruthTTTrackHandle->findTrackingParticlePtr(matchedTracks.at(it)).isNull()) {
2059               edm::LogVerbatim("Tracklet") << "track matched to TP is NOT uniquely matched to a TP";
2060             } else {
2061               edm::Ptr<TrackingParticle> my_tp = MCTruthTTTrackHandle->findTrackingParticlePtr(matchedTracks.at(it));
2062               edm::LogVerbatim("Tracklet") << "TP matched to track matched to TP ... tp pt = " << my_tp->p4().pt()
2063                                            << " eta = " << my_tp->momentum().eta()
2064                                            << " phi = " << my_tp->momentum().phi() << " z0 = " << my_tp->vertex().z();
2065             }
2066             edm::LogVerbatim("Tracklet") << "   ... matched L1 track has pt = "
2067                                          << matchedTracks.at(it)->momentum().perp()
2068                                          << " eta = " << matchedTracks.at(it)->momentum().eta()
2069                                          << " phi = " << matchedTracks.at(it)->momentum().phi()
2070                                          << " chi2 = " << matchedTracks.at(it)->chi2()
2071                                          << " consistency = " << matchedTracks.at(it)->stubPtConsistency()
2072                                          << " z0 = " << matchedTracks.at(it)->z0()
2073                                          << " nstub = " << matchedTracks.at(it)->getStubRefs().size();
2074             if (tmp_trk_genuine)
2075               edm::LogVerbatim("Tracklet") << "    (genuine!) ";
2076             if (tmp_trk_loosegenuine)
2077               edm::LogVerbatim("Tracklet") << "    (loose genuine!) ";
2078           }
2079 
2080           std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
2081               stubRefs = matchedTracks.at(it)->getStubRefs();
2082           int tmp_trk_nstub = stubRefs.size();
2083 
2084           if (tmp_trk_nstub < L1Tk_minNStub)
2085             continue;
2086 
2087           float dmatch_pt = 999;
2088           float dmatch_eta = 999;
2089           float dmatch_phi = 999;
2090           int match_id = 999;
2091 
2092           edm::Ptr<TrackingParticle> my_tp = MCTruthTTTrackHandle->findTrackingParticlePtr(matchedTracks.at(it));
2093           dmatch_pt = std::abs(my_tp->p4().pt() - tmp_tp_pt);
2094           dmatch_eta = std::abs(my_tp->p4().eta() - tmp_tp_eta);
2095           dmatch_phi = std::abs(my_tp->p4().phi() - tmp_tp_phi);
2096           match_id = my_tp->pdgId();
2097           float tmp_trk_chi2dof = matchedTracks.at(it)->chi2Red();
2098 
2099           // ensure that track is uniquely matched to the TP we are looking at!
2100           if (dmatch_pt < 0.1 && dmatch_eta < 0.1 && dmatch_phi < 0.1 && tmp_tp_pdgid == match_id && tmp_trk_genuine) {
2101             nMatch++;
2102             if (i_track < 0 || tmp_trk_chi2dof < i_chi2dof) {
2103               i_track = it;
2104               i_chi2dof = tmp_trk_chi2dof;
2105             }
2106           }
2107 
2108         }  // end loop over matched L1 tracks
2109       }    // end has at least 1 matched L1 track
2110       // ----------------------------------------------------------------------------------------------
2111 
2112       float tmp_matchtrk_pt = -999;
2113       float tmp_matchtrk_eta = -999;
2114       float tmp_matchtrk_phi = -999;
2115       float tmp_matchtrk_z0 = -999;
2116       float tmp_matchtrk_d0 = -999;
2117       float tmp_matchtrk_chi2 = -999;
2118       float tmp_matchtrk_chi2dof = -999;
2119       float tmp_matchtrk_chi2rphi = -999;
2120       float tmp_matchtrk_chi2rz = -999;
2121       float tmp_matchtrk_bendchi2 = -999;
2122       float tmp_matchtrk_MVA1 = -999;
2123       int tmp_matchtrk_nstub = -999;
2124       int tmp_matchtrk_dhits = -999;
2125       int tmp_matchtrk_lhits = -999;
2126       int tmp_matchtrk_seed = -999;
2127       int tmp_matchtrk_hitpattern = -999;
2128       int tmp_matchtrk_nFitPars = -999;
2129 
2130       if (nMatch > 1 && DebugMode)
2131         edm::LogVerbatim("Tracklet") << "WARNING *** 2 or more matches to genuine L1 tracks ***";
2132 
2133       if (nMatch > 0) {
2134         tmp_matchtrk_pt = matchedTracks.at(i_track)->momentum().perp();
2135         tmp_matchtrk_eta = matchedTracks.at(i_track)->momentum().eta();
2136         tmp_matchtrk_phi = matchedTracks.at(i_track)->momentum().phi();
2137         tmp_matchtrk_z0 = matchedTracks.at(i_track)->z0();
2138         tmp_matchtrk_nFitPars = matchedTracks.at(i_track)->nFitPars();
2139 
2140         if (tmp_matchtrk_nFitPars == 5) {
2141           float tmp_matchtrk_x0 = matchedTracks.at(i_track)->POCA().x();
2142           float tmp_matchtrk_y0 = matchedTracks.at(i_track)->POCA().y();
2143           tmp_matchtrk_d0 = -tmp_matchtrk_x0 * sin(tmp_matchtrk_phi) + tmp_matchtrk_y0 * cos(tmp_matchtrk_phi);
2144           // tmp_matchtrk_d0 = matchedTracks.at(i_track)->d0();
2145         }
2146 
2147         tmp_matchtrk_chi2 = matchedTracks.at(i_track)->chi2();
2148         tmp_matchtrk_chi2dof = matchedTracks.at(i_track)->chi2Red();
2149         tmp_matchtrk_chi2rphi = matchedTracks.at(i_track)->chi2XYRed();
2150         tmp_matchtrk_chi2rz = matchedTracks.at(i_track)->chi2ZRed();
2151         tmp_matchtrk_bendchi2 = matchedTracks.at(i_track)->stubPtConsistency();
2152         tmp_matchtrk_MVA1 = -99.9;  //update when MVA is available
2153         tmp_matchtrk_nstub = (int)matchedTracks.at(i_track)->getStubRefs().size();
2154         tmp_matchtrk_seed = (int)matchedTracks.at(i_track)->trackSeedType();
2155         tmp_matchtrk_hitpattern = (int)matchedTracks.at(i_track)->hitPattern();
2156 
2157         // ------------------------------------------------------------------------------------------
2158         tmp_matchtrk_dhits = 0;
2159         tmp_matchtrk_lhits = 0;
2160 
2161         std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
2162             stubRefs = matchedTracks.at(i_track)->getStubRefs();
2163         int tmp_nstub = stubRefs.size();
2164 
2165         for (int is = 0; is < tmp_nstub; is++) {
2166           DetId detIdStub = tGeom.idToDet((stubRefs.at(is)->clusterRef(0))->getDetId())->geographicalId();
2167           int layer = -999999;
2168           if (detIdStub.subdetId() == StripSubdetector::TOB) {
2169             layer = static_cast<int>(tTopo.layer(detIdStub));
2170             tmp_matchtrk_lhits += pow(10, layer - 1);
2171           } else if (detIdStub.subdetId() == StripSubdetector::TID) {
2172             layer = static_cast<int>(tTopo.layer(detIdStub));
2173             tmp_matchtrk_dhits += pow(10, layer - 1);
2174           }
2175         }
2176       }
2177 
2178       m_tp_nmatch->push_back(nMatch);
2179 
2180       m_matchtrk_pt->push_back(tmp_matchtrk_pt);
2181       m_matchtrk_eta->push_back(tmp_matchtrk_eta);
2182       m_matchtrk_phi->push_back(tmp_matchtrk_phi);
2183       m_matchtrk_z0->push_back(tmp_matchtrk_z0);
2184       m_matchtrk_d0->push_back(tmp_matchtrk_d0);
2185       m_matchtrk_chi2->push_back(tmp_matchtrk_chi2);
2186       m_matchtrk_chi2dof->push_back(tmp_matchtrk_chi2dof);
2187       m_matchtrk_chi2rphi->push_back(tmp_matchtrk_chi2rphi);
2188       m_matchtrk_chi2rz->push_back(tmp_matchtrk_chi2rz);
2189       m_matchtrk_bendchi2->push_back(tmp_matchtrk_bendchi2);
2190       m_matchtrk_MVA1->push_back(tmp_matchtrk_MVA1);
2191       m_matchtrk_nstub->push_back(tmp_matchtrk_nstub);
2192       m_matchtrk_dhits->push_back(tmp_matchtrk_dhits);
2193       m_matchtrk_lhits->push_back(tmp_matchtrk_lhits);
2194       m_matchtrk_seed->push_back(tmp_matchtrk_seed);
2195       m_matchtrk_hitpattern->push_back(tmp_matchtrk_hitpattern);
2196     }
2197 
2198     // ----------------------------------------------------------------------------------------------
2199     // look for L1 tracks (extended) matched to the tracking particle
2200     if (Displaced == "Displaced" || Displaced == "Both") {
2201       L1TrackPtrCollection matchedTracks = MCTruthTTTrackExtendedHandle->findTTTrackPtrs(tp_ptr);
2202 
2203       int nMatch = 0;
2204       int i_track = -1;
2205       float i_chi2dof = 99999;
2206 
2207       if (!matchedTracks.empty()) {
2208         if (DebugMode && (matchedTracks.size() > 1))
2209           edm::LogVerbatim("Tracklet") << "TrackingParticle has more than one matched L1 track!";
2210 
2211         // ----------------------------------------------------------------------------------------------
2212         // loop over matched L1 tracks
2213         // here, "match" means tracks that can be associated to a TrackingParticle with at least one hit of at least one of its clusters
2214         // https://twiki.cern.ch/twiki/bin/viewauth/CMS/SLHCTrackerTriggerSWTools#MC_truth_for_TTTrack
2215 
2216         for (int it = 0; it < (int)matchedTracks.size(); it++) {
2217           bool tmp_trk_genuine = false;
2218           bool tmp_trk_loosegenuine = false;
2219           if (MCTruthTTTrackExtendedHandle->isGenuine(matchedTracks.at(it)))
2220             tmp_trk_genuine = true;
2221           if (MCTruthTTTrackExtendedHandle->isLooselyGenuine(matchedTracks.at(it)))
2222             tmp_trk_loosegenuine = true;
2223           if (!tmp_trk_loosegenuine)
2224             continue;
2225 
2226           if (DebugMode) {
2227             if (MCTruthTTTrackExtendedHandle->findTrackingParticlePtr(matchedTracks.at(it)).isNull()) {
2228               edm::LogVerbatim("Tracklet") << "track matched to TP is NOT uniquely matched to a TP";
2229             } else {
2230               edm::Ptr<TrackingParticle> my_tp =
2231                   MCTruthTTTrackExtendedHandle->findTrackingParticlePtr(matchedTracks.at(it));
2232               edm::LogVerbatim("Tracklet") << "TP matched to track matched to TP ... tp pt = " << my_tp->p4().pt()
2233                                            << " eta = " << my_tp->momentum().eta()
2234                                            << " phi = " << my_tp->momentum().phi() << " z0 = " << my_tp->vertex().z();
2235             }
2236             edm::LogVerbatim("Tracklet") << "   ... matched L1 track has pt = "
2237                                          << matchedTracks.at(it)->momentum().perp()
2238                                          << " eta = " << matchedTracks.at(it)->momentum().eta()
2239                                          << " phi = " << matchedTracks.at(it)->momentum().phi()
2240                                          << " chi2 = " << matchedTracks.at(it)->chi2()
2241                                          << " consistency = " << matchedTracks.at(it)->stubPtConsistency()
2242                                          << " z0 = " << matchedTracks.at(it)->z0()
2243                                          << " nstub = " << matchedTracks.at(it)->getStubRefs().size();
2244             if (tmp_trk_genuine)
2245               edm::LogVerbatim("Tracklet") << "    (genuine!) ";
2246             if (tmp_trk_loosegenuine)
2247               edm::LogVerbatim("Tracklet") << "    (loose genuine!) ";
2248           }
2249 
2250           std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
2251               stubRefs = matchedTracks.at(it)->getStubRefs();
2252           int tmp_trk_nstub = stubRefs.size();
2253 
2254           if (tmp_trk_nstub < L1Tk_minNStub)
2255             continue;
2256 
2257           float dmatch_pt = 999;
2258           float dmatch_eta = 999;
2259           float dmatch_phi = 999;
2260           int match_id = 999;
2261 
2262           edm::Ptr<TrackingParticle> my_tp =
2263               MCTruthTTTrackExtendedHandle->findTrackingParticlePtr(matchedTracks.at(it));
2264           dmatch_pt = std::abs(my_tp->p4().pt() - tmp_tp_pt);
2265           dmatch_eta = std::abs(my_tp->p4().eta() - tmp_tp_eta);
2266           dmatch_phi = std::abs(my_tp->p4().phi() - tmp_tp_phi);
2267           match_id = my_tp->pdgId();
2268           float tmp_trk_chi2dof = matchedTracks.at(it)->chi2Red();
2269 
2270           // ensure that track is uniquely matched to the TP we are looking at!
2271           if (dmatch_pt < 0.1 && dmatch_eta < 0.1 && dmatch_phi < 0.1 && tmp_tp_pdgid == match_id && tmp_trk_genuine) {
2272             nMatch++;
2273             if (i_track < 0 || tmp_trk_chi2dof < i_chi2dof) {
2274               i_track = it;
2275               i_chi2dof = tmp_trk_chi2dof;
2276             }
2277           }
2278 
2279         }  // end loop over matched L1 tracks
2280       }    // end has at least 1 matched L1 track
2281       // ----------------------------------------------------------------------------------------------
2282 
2283       float tmp_matchtrkExt_pt = -999;
2284       float tmp_matchtrkExt_eta = -999;
2285       float tmp_matchtrkExt_phi = -999;
2286       float tmp_matchtrkExt_z0 = -999;
2287       float tmp_matchtrkExt_d0 = -999;
2288       float tmp_matchtrkExt_chi2 = -999;
2289       float tmp_matchtrkExt_chi2dof = -999;
2290       float tmp_matchtrkExt_chi2rphi = -999;
2291       float tmp_matchtrkExt_chi2rz = -999;
2292       float tmp_matchtrkExt_bendchi2 = -999;
2293       float tmp_matchtrkExt_MVA = -999;
2294       int tmp_matchtrkExt_nstub = -999;
2295       int tmp_matchtrkExt_dhits = -999;
2296       int tmp_matchtrkExt_lhits = -999;
2297       int tmp_matchtrkExt_seed = -999;
2298       int tmp_matchtrkExt_hitpattern = -999;
2299       int tmp_matchtrkExt_nFitPars = -999;
2300 
2301       if (nMatch > 1 && DebugMode)
2302         edm::LogVerbatim("Tracklet") << "WARNING *** 2 or more matches to genuine L1 tracks ***";
2303 
2304       if (nMatch > 0) {
2305         tmp_matchtrkExt_pt = matchedTracks.at(i_track)->momentum().perp();
2306         tmp_matchtrkExt_eta = matchedTracks.at(i_track)->momentum().eta();
2307         tmp_matchtrkExt_phi = matchedTracks.at(i_track)->momentum().phi();
2308         tmp_matchtrkExt_z0 = matchedTracks.at(i_track)->z0();
2309         tmp_matchtrkExt_nFitPars = matchedTracks.at(i_track)->nFitPars();
2310 
2311         if (tmp_matchtrkExt_nFitPars == 5) {
2312           float tmp_matchtrkExt_x0 = matchedTracks.at(i_track)->POCA().x();
2313           float tmp_matchtrkExt_y0 = matchedTracks.at(i_track)->POCA().y();
2314           tmp_matchtrkExt_d0 =
2315               -tmp_matchtrkExt_x0 * sin(tmp_matchtrkExt_phi) + tmp_matchtrkExt_y0 * cos(tmp_matchtrkExt_phi);
2316           // tmp_matchtrkExt_d0 = matchedTracks.at(i_track)->d0();
2317         }
2318 
2319         tmp_matchtrkExt_chi2 = matchedTracks.at(i_track)->chi2();
2320         tmp_matchtrkExt_chi2dof = matchedTracks.at(i_track)->chi2Red();
2321         tmp_matchtrkExt_chi2rphi = matchedTracks.at(i_track)->chi2XYRed();
2322         tmp_matchtrkExt_chi2rz = matchedTracks.at(i_track)->chi2ZRed();
2323         tmp_matchtrkExt_bendchi2 = matchedTracks.at(i_track)->stubPtConsistency();
2324         tmp_matchtrkExt_MVA = -99.9;  //update when MVA is available
2325         tmp_matchtrkExt_nstub = (int)matchedTracks.at(i_track)->getStubRefs().size();
2326         tmp_matchtrkExt_seed = (int)matchedTracks.at(i_track)->trackSeedType();
2327         tmp_matchtrkExt_hitpattern = (int)matchedTracks.at(i_track)->hitPattern();
2328 
2329         // ------------------------------------------------------------------------------------------
2330         tmp_matchtrkExt_dhits = 0;
2331         tmp_matchtrkExt_lhits = 0;
2332 
2333         std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
2334             stubRefs = matchedTracks.at(i_track)->getStubRefs();
2335         int tmp_nstub = stubRefs.size();
2336 
2337         for (int is = 0; is < tmp_nstub; is++) {
2338           DetId detIdStub = tGeom.idToDet((stubRefs.at(is)->clusterRef(0))->getDetId())->geographicalId();
2339           int layer = -999999;
2340           if (detIdStub.subdetId() == StripSubdetector::TOB) {
2341             layer = static_cast<int>(tTopo.layer(detIdStub));
2342             tmp_matchtrkExt_lhits += pow(10, layer - 1);
2343           } else if (detIdStub.subdetId() == StripSubdetector::TID) {
2344             layer = static_cast<int>(tTopo.layer(detIdStub));
2345             tmp_matchtrkExt_dhits += pow(10, layer - 1);
2346           }
2347         }
2348       }
2349 
2350       // m_tp_nmatch->push_back(nMatch); //modify to be matches for ext
2351       m_matchtrkExt_pt->push_back(tmp_matchtrkExt_pt);
2352       m_matchtrkExt_eta->push_back(tmp_matchtrkExt_eta);
2353       m_matchtrkExt_phi->push_back(tmp_matchtrkExt_phi);
2354       m_matchtrkExt_z0->push_back(tmp_matchtrkExt_z0);
2355       m_matchtrkExt_d0->push_back(tmp_matchtrkExt_d0);
2356       m_matchtrkExt_chi2->push_back(tmp_matchtrkExt_chi2);
2357       m_matchtrkExt_chi2dof->push_back(tmp_matchtrkExt_chi2dof);
2358       m_matchtrkExt_chi2rphi->push_back(tmp_matchtrkExt_chi2rphi);
2359       m_matchtrkExt_chi2rz->push_back(tmp_matchtrkExt_chi2rz);
2360       m_matchtrkExt_bendchi2->push_back(tmp_matchtrkExt_bendchi2);
2361       m_matchtrkExt_MVA->push_back(tmp_matchtrkExt_MVA);
2362       m_matchtrkExt_nstub->push_back(tmp_matchtrkExt_nstub);
2363       m_matchtrkExt_dhits->push_back(tmp_matchtrkExt_dhits);
2364       m_matchtrkExt_lhits->push_back(tmp_matchtrkExt_lhits);
2365       m_matchtrkExt_seed->push_back(tmp_matchtrkExt_seed);
2366       m_matchtrkExt_hitpattern->push_back(tmp_matchtrkExt_hitpattern);
2367     }
2368   }  //end loop tracking particles
2369   trueTkMET = sqrt(trueTkMETx * trueTkMETx + trueTkMETy * trueTkMETy);
2370 
2371   if (L1TkPrimaryVertexHandle.isValid()) {
2372     for (vtxIter = L1TkPrimaryVertexHandle->begin(); vtxIter != L1TkPrimaryVertexHandle->end(); ++vtxIter) {
2373       m_pv_L1reco->push_back(vtxIter->z0());
2374       m_pv_L1reco_sum->push_back(vtxIter->pt());
2375     }
2376   } else
2377     edm::LogWarning("DataNotFound") << "\nWarning: L1TkPrimaryVertexHandle not found" << std::endl;
2378 
2379   if (L1TkPrimaryVertexEmuHandle.isValid()) {
2380     for (vtxEmuIter = L1TkPrimaryVertexEmuHandle->begin(); vtxEmuIter != L1TkPrimaryVertexEmuHandle->end();
2381          ++vtxEmuIter) {
2382       m_pv_L1reco_emu->push_back(vtxEmuIter->z0());
2383     }
2384   } else
2385     edm::LogWarning("DataNotFound") << "\nWarning: L1TkPrimaryVertexEmuHandle not found" << std::endl;
2386 
2387   if (SaveTrackSums) {
2388     if (Displaced == "Prompt" || Displaced == "Both") {
2389       if (L1TkMETHandle.isValid())
2390         trkMET = L1TkMETHandle->begin()->etMiss();
2391       else
2392         edm::LogWarning("DataNotFound") << "\nWarning: tkMET handle not found" << std::endl;
2393 
2394       if (L1TkMETEmuHandle.isValid())
2395         trkMETEmu = L1TkMETEmuHandle->begin()->hwPt() * l1tmetemu::kStepMET;
2396       else
2397         edm::LogWarning("DataNotFound") << "\nWarning: tkMETEmu handle not found" << std::endl;
2398 
2399       if (L1TkMHTHandle.isValid()) {
2400         trkMHT = L1TkMHTHandle->begin()->EtMiss();
2401         trkHT = L1TkMHTHandle->begin()->etTotal();
2402       } else
2403         edm::LogWarning("DataNotFound") << "\nWarning: tkMHT handle not found" << std::endl;
2404 
2405       if (L1TkMHTEmuHandle.isValid()) {
2406         trkMHTEmu = L1TkMHTEmuHandle->begin()->p4().energy() * l1tmhtemu::kStepMHT;
2407         trkHTEmu = L1TkMHTEmuHandle->begin()->hwPt() * l1tmhtemu::kStepPt;
2408         trkMHTEmuPhi = L1TkMHTEmuHandle->begin()->hwPhi() * l1tmhtemu::kStepMHTPhi - M_PI;
2409       } else
2410         edm::LogWarning("DataNotFound") << "\nWarning: tkMHTEmu handle not found" << std::endl;
2411     }  //end prompt-track quantities
2412 
2413     if (Displaced == "Displaced" || Displaced == "Both") {
2414       if (L1TkMETExtendedHandle.isValid())
2415         trkMETExt = L1TkMETExtendedHandle->begin()->etMiss();
2416       else
2417         edm::LogWarning("DataNotFound") << "\nWarning: tkMETExtended handle not found" << std::endl;
2418 
2419       if (L1TkMHTExtendedHandle.isValid()) {
2420         trkMHTExt = L1TkMHTExtendedHandle->begin()->EtMiss();
2421         trkHTExt = L1TkMHTExtendedHandle->begin()->etTotal();
2422       } else
2423         edm::LogWarning("DataNotFound") << "\nWarning: tkMHTExtended handle not found" << std::endl;
2424 
2425       if (L1TkMHTEmuExtendedHandle.isValid()) {
2426         trkMHTEmuExt = L1TkMHTEmuExtendedHandle->begin()->p4().energy() * l1tmhtemu::kStepMHT;
2427         trkHTEmuExt = L1TkMHTEmuExtendedHandle->begin()->hwPt() * l1tmhtemu::kStepPt;
2428         trkMHTEmuPhiExt = L1TkMHTEmuExtendedHandle->begin()->hwPhi() * l1tmhtemu::kStepMHTPhi - M_PI;
2429       } else
2430         edm::LogWarning("DataNotFound") << "\nWarning: tkMHTEmuExtended handle not found" << std::endl;
2431     }  //end displaced-track quantities
2432   }
2433 
2434   if (SaveTrackJets) {
2435     if (TrackFastJetsHandle.isValid() && (Displaced == "Prompt" || Displaced == "Both")) {
2436       for (jetIter = TrackFastJetsHandle->begin(); jetIter != TrackFastJetsHandle->end(); ++jetIter) {
2437         m_trkfastjet_vz->push_back(jetIter->jetVtx());
2438         m_trkfastjet_ntracks->push_back(jetIter->trkPtrs().size());
2439         m_trkfastjet_phi->push_back(jetIter->phi());
2440         m_trkfastjet_eta->push_back(jetIter->eta());
2441         m_trkfastjet_pt->push_back(jetIter->pt());
2442         m_trkfastjet_p->push_back(jetIter->p());
2443       }
2444     }
2445     if (TrackFastJetsExtendedHandle.isValid() && (Displaced == "Displaced" || Displaced == "Both")) {
2446       for (jetIter = TrackFastJetsExtendedHandle->begin(); jetIter != TrackFastJetsExtendedHandle->end(); ++jetIter) {
2447         m_trkfastjetExt_vz->push_back(jetIter->jetVtx());
2448         m_trkfastjetExt_ntracks->push_back(jetIter->trkPtrs().size());
2449         m_trkfastjetExt_phi->push_back(jetIter->phi());
2450         m_trkfastjetExt_eta->push_back(jetIter->eta());
2451         m_trkfastjetExt_pt->push_back(jetIter->pt());
2452         m_trkfastjetExt_p->push_back(jetIter->p());
2453       }
2454     }
2455     if (!TrackJetsHandle.isValid() && (Displaced == "Prompt" || Displaced == "Both"))
2456       edm::LogWarning("DataNotFound") << "\nWarning: TrackJetsHandle not found" << std::endl;
2457     if (!TrackJetsExtendedHandle.isValid() && (Displaced == "Displaced" || Displaced == "Both"))
2458       edm::LogWarning("DataNotFound") << "\nWarning: TrackJetsExtendedHandle not found" << std::endl;
2459     if (TrackJetsHandle.isValid() && (Displaced == "Prompt" || Displaced == "Both")) {
2460       for (jetIter = TrackJetsHandle->begin(); jetIter != TrackJetsHandle->end(); ++jetIter) {
2461         m_trkjet_vz->push_back(jetIter->jetVtx());
2462         m_trkjet_ntracks->push_back(jetIter->ntracks());
2463         m_trkjet_phi->push_back(jetIter->phi());
2464         m_trkjet_eta->push_back(jetIter->eta());
2465         m_trkjet_pt->push_back(jetIter->pt());
2466         m_trkjet_p->push_back(jetIter->p());
2467         m_trkjet_nDisplaced->push_back(jetIter->nDisptracks());
2468         m_trkjet_nTight->push_back(jetIter->nTighttracks());
2469         m_trkjet_nTightDisplaced->push_back(jetIter->nTightDisptracks());
2470       }
2471     }
2472     if (TrackJetsExtendedHandle.isValid() && (Displaced == "Displaced" || Displaced == "Both")) {
2473       for (jetIter = TrackJetsExtendedHandle->begin(); jetIter != TrackJetsExtendedHandle->end(); ++jetIter) {
2474         m_trkjetExt_vz->push_back(jetIter->jetVtx());
2475         m_trkjetExt_ntracks->push_back(jetIter->ntracks());
2476         m_trkjetExt_phi->push_back(jetIter->phi());
2477         m_trkjetExt_eta->push_back(jetIter->eta());
2478         m_trkjetExt_pt->push_back(jetIter->pt());
2479         m_trkjetExt_p->push_back(jetIter->p());
2480         m_trkjetExt_nDisplaced->push_back(jetIter->nDisptracks());
2481         m_trkjetExt_nTight->push_back(jetIter->nTighttracks());
2482         m_trkjetExt_nTightDisplaced->push_back(jetIter->nTightDisptracks());
2483       }
2484     }
2485 
2486     if (!TrackJetsEmuHandle.isValid() && (Displaced == "Prompt" || Displaced == "Both"))
2487       edm::LogWarning("DataNotFound") << "\nWarning: TrackJetsEmuHandle not found" << std::endl;
2488     else if (TrackJetsEmuHandle.isValid() && (Displaced == "Prompt" || Displaced == "Both")) {
2489       for (jetemIter = TrackJetsEmuHandle->begin(); jetemIter != TrackJetsEmuHandle->end(); ++jetemIter) {
2490         m_trkjetem_ntracks->push_back(jetemIter->nt());
2491         m_trkjetem_phi->push_back(jetemIter->glbphi());
2492         m_trkjetem_eta->push_back(jetemIter->glbeta());
2493         m_trkjetem_pt->push_back(jetemIter->pt());
2494         m_trkjetem_z->push_back(jetemIter->z0());
2495         m_trkjetem_nxtracks->push_back(jetemIter->xt());
2496       }
2497     }
2498     if (!TrackJetsExtendedEmuHandle.isValid() && (Displaced == "Displaced" || Displaced == "Both"))
2499       edm::LogWarning("DataNotFound") << "\nWarning: TrackJetsExtendedEmuHandle not found" << std::endl;
2500     else if (TrackJetsExtendedEmuHandle.isValid() && (Displaced == "Displaced" || Displaced == "Both")) {
2501       for (jetemIter = TrackJetsExtendedEmuHandle->begin(); jetemIter != TrackJetsExtendedEmuHandle->end();
2502            ++jetemIter) {
2503         m_trkjetemExt_ntracks->push_back(jetemIter->nt());
2504         m_trkjetemExt_phi->push_back(jetemIter->glbphi());
2505         m_trkjetemExt_eta->push_back(jetemIter->glbeta());
2506         m_trkjetemExt_pt->push_back(jetemIter->pt());
2507         m_trkjetemExt_z->push_back(jetemIter->z0());
2508         m_trkjetemExt_nxtracks->push_back(jetemIter->xt());
2509       }
2510     }
2511   }  // end track jets
2512 
2513   eventTree->Fill();
2514 }  // end of analyze()
2515 
2516 int L1TrackObjectNtupleMaker::getSelectedTrackIndex(const L1TrackRef& trackRef,
2517                                                     const edm::Handle<L1TrackRefCollection>& selectedTrackRefs) const {
2518   auto it = std::find_if(selectedTrackRefs->begin(), selectedTrackRefs->end(), [&trackRef](L1TrackRef const& obj) {
2519     return obj == trackRef;
2520   });
2521   if (it != selectedTrackRefs->end())
2522     return std::distance(selectedTrackRefs->begin(), it);
2523   else
2524     return -1;
2525 }
2526 
2527 ///////////////////////////
2528 // DEFINE THIS AS A PLUG-IN
2529 DEFINE_FWK_MODULE(L1TrackObjectNtupleMaker);