Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-08-09 23:47:30

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 "SimDataFormats/Vertex/interface/SimVertex.h"
0033 #include "SimDataFormats/Associations/interface/TTClusterAssociationMap.h"
0034 #include "SimDataFormats/Associations/interface/TTStubAssociationMap.h"
0035 #include "SimDataFormats/Associations/interface/TTTrackAssociationMap.h"
0036 #include "Geometry/Records/interface/StackedTrackerGeometryRecord.h"
0037 
0038 #include "DataFormats/JetReco/interface/GenJetCollection.h"
0039 #include "DataFormats/JetReco/interface/GenJet.h"
0040 
0041 ////////////////////////////
0042 // DETECTOR GEOMETRY HEADERS
0043 #include "MagneticField/Engine/interface/MagneticField.h"
0044 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0045 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0046 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.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/L1TCorrelator/interface/TkTriplet.h"
0064 #include "DataFormats/L1TCorrelator/interface/TkTripletFwd.h"
0065 #include "DataFormats/Math/interface/LorentzVector.h"
0066 #include "DataFormats/L1TCorrelator/interface/TkEtMiss.h"
0067 #include "DataFormats/L1TCorrelator/interface/TkEtMissFwd.h"
0068 #include "DataFormats/L1TCorrelator/interface/TkHTMiss.h"
0069 #include "DataFormats/L1TCorrelator/interface/TkHTMissFwd.h"
0070 #include "DataFormats/L1Trigger/interface/Vertex.h"
0071 #include "DataFormats/L1Trigger/interface/VertexWord.h"
0072 #include "DataFormats/L1Trigger/interface/EtSum.h"
0073 #include "L1Trigger/L1TTrackMatch/interface/L1TkEtMissEmuAlgo.h"
0074 #include "L1Trigger/L1TTrackMatch/interface/L1TkHTMissEmulatorProducer.h"
0075 
0076 ///////////////
0077 // ROOT HEADERS
0078 #include <TROOT.h>
0079 #include <TCanvas.h>
0080 #include <TTree.h>
0081 #include <TFile.h>
0082 #include <TF1.h>
0083 #include <TH2F.h>
0084 #include <TH1F.h>
0085 #include <TLorentzVector.h>
0086 
0087 //////////////
0088 // STD HEADERS
0089 #include <memory>
0090 #include <string>
0091 #include <iostream>
0092 
0093 //////////////
0094 // NAMESPACES
0095 using namespace std;
0096 using namespace edm;
0097 
0098 //////////////////////////////
0099 //                          //
0100 //     CLASS DEFINITION     //
0101 //                          //
0102 //////////////////////////////
0103 
0104 class L1TrackObjectNtupleMaker : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0105 private:
0106   // ----------constants, enums and typedefs ---------
0107   typedef TTTrack<Ref_Phase2TrackerDigi_> L1Track;
0108   typedef edm::Ptr<L1Track> L1TrackPtr;
0109   typedef std::vector<L1TrackPtr> L1TrackPtrCollection;
0110   typedef std::vector<L1Track> L1TrackCollection;
0111   typedef edm::Ref<L1TrackCollection> L1TrackRef;
0112   typedef edm::RefVector<L1TrackCollection> L1TrackRefCollection;
0113 
0114 public:
0115   // Constructor/destructor
0116   explicit L1TrackObjectNtupleMaker(const edm::ParameterSet& iConfig);
0117   ~L1TrackObjectNtupleMaker() override;
0118 
0119   // Mandatory methods
0120   void beginJob() override;
0121   void endJob() override;
0122   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0123 
0124   // Other member functions
0125   int getSelectedTrackIndex(const L1TrackRef& trackRef,
0126                             const edm::Handle<L1TrackRefCollection>& selectedTrackRefs) const;
0127 
0128 private:
0129   //-----------------------------------------------------------------------------------------------
0130   // Containers of parameters passed by python configuration file
0131   edm::ParameterSet config;
0132 
0133   int MyProcess;       // 11/13/211 for single electrons/muons/pions, 6/15 for pions from ttbar/taus, 1 for inclusive
0134   bool DebugMode;      // lots of debug printout statements
0135   bool SaveAllTracks;  // store in ntuples not only truth-matched tracks but ALL tracks
0136   bool SaveStubs;      // option to save also stubs in the ntuples (makes them large...)
0137   string Displaced;    // "Prompt", "Displaced", "Both"
0138   int TP_minNStub;  // require TPs to have >= minNStub (defining efficiency denominator) (==0 means to only require >= 1 cluster)
0139   int TP_minNStubLayer;  // require TPs to have stubs in >= minNStubLayer layers/disks (defining efficiency denominator)
0140   double TP_minPt;       // save TPs with pt > minPt
0141   double TP_maxEta;      // save TPs with |eta| < maxEta
0142   double TP_maxZ0;       // save TPs with |z0| < maxZ0
0143   int L1Tk_minNStub;     // require L1 tracks to have >= minNStub (this is mostly for tracklet purposes)
0144   bool SaveTrackJets;
0145   bool SaveTrackSums;
0146 
0147   edm::InputTag L1TrackInputTag;                                              // L1 track collection
0148   edm::InputTag MCTruthTrackInputTag;                                         // MC truth collection
0149   edm::InputTag SimVertexInputTag;                                            // MC truth vertex collection
0150   edm::InputTag L1TrackGTTInputTag;                                           // L1 track collection
0151   edm::InputTag L1TrackSelectedInputTag;                                      // L1 track collection
0152   edm::InputTag L1TrackSelectedEmulationInputTag;                             // L1 track collection
0153   edm::InputTag L1TrackSelectedAssociatedInputTag;                            // L1 track collection
0154   edm::InputTag L1TrackSelectedAssociatedEmulationInputTag;                   // L1 track collection
0155   edm::InputTag L1TrackSelectedForJetsInputTag;                               // L1 track collection
0156   edm::InputTag L1TrackSelectedEmulationForJetsInputTag;                      // L1 track collection
0157   edm::InputTag L1TrackSelectedAssociatedForJetsInputTag;                     // L1 track collection
0158   edm::InputTag L1TrackSelectedAssociatedEmulationForJetsInputTag;            // L1 track collection
0159   edm::InputTag L1TrackSelectedForEtMissInputTag;                             // L1 track collection
0160   edm::InputTag L1TrackSelectedEmulationForEtMissInputTag;                    // L1 track collection
0161   edm::InputTag L1TrackSelectedAssociatedForEtMissInputTag;                   // L1 track collection
0162   edm::InputTag L1TrackSelectedAssociatedEmulationForEtMissInputTag;          // L1 track collection
0163   edm::InputTag L1TrackExtendedInputTag;                                      // L1 track collection
0164   edm::InputTag MCTruthTrackExtendedInputTag;                                 // MC truth collection
0165   edm::InputTag L1TrackExtendedGTTInputTag;                                   // L1 track collection
0166   edm::InputTag L1TrackExtendedSelectedInputTag;                              // L1 track collection
0167   edm::InputTag L1TrackExtendedSelectedEmulationInputTag;                     // L1 track collection
0168   edm::InputTag L1TrackExtendedSelectedAssociatedInputTag;                    // L1 track collection
0169   edm::InputTag L1TrackExtendedSelectedAssociatedEmulationInputTag;           // L1 track collection
0170   edm::InputTag L1TrackExtendedSelectedForJetsInputTag;                       // L1 track collection
0171   edm::InputTag L1TrackExtendedSelectedEmulationForJetsInputTag;              // L1 track collection
0172   edm::InputTag L1TrackExtendedSelectedAssociatedForJetsInputTag;             // L1 track collection
0173   edm::InputTag L1TrackExtendedSelectedAssociatedEmulationForJetsInputTag;    // L1 track collection
0174   edm::InputTag L1TrackExtendedSelectedForEtMissInputTag;                     // L1 track collection
0175   edm::InputTag L1TrackExtendedSelectedEmulationForEtMissInputTag;            // L1 track collection
0176   edm::InputTag L1TrackExtendedSelectedAssociatedForEtMissInputTag;           // L1 track collection
0177   edm::InputTag L1TrackExtendedSelectedAssociatedEmulationForEtMissInputTag;  // L1 track collection
0178   edm::InputTag MCTruthClusterInputTag;
0179   edm::InputTag L1StubInputTag;
0180   edm::InputTag MCTruthStubInputTag;
0181   edm::InputTag TrackingParticleInputTag;
0182   edm::InputTag TrackingVertexInputTag;
0183   edm::InputTag GenJetInputTag;
0184   edm::InputTag RecoVertexInputTag;
0185   edm::InputTag RecoVertexEmuInputTag;
0186   edm::InputTag GenParticleInputTag;
0187 
0188   edm::InputTag TrackFastJetsInputTag;
0189   edm::InputTag TrackJetsInputTag;
0190   edm::InputTag TrackJetsEmuInputTag;
0191   edm::InputTag TrackTripletsInputTag;
0192 
0193   edm::InputTag TrackMETInputTag;
0194   edm::InputTag TrackMETEmuInputTag;
0195   edm::InputTag TrackMHTInputTag;
0196   edm::InputTag TrackMHTEmuInputTag;
0197 
0198   edm::InputTag TrackFastJetsExtendedInputTag;
0199   edm::InputTag TrackJetsExtendedInputTag;
0200   edm::InputTag TrackJetsExtendedEmuInputTag;
0201   edm::InputTag TrackMETExtendedInputTag;
0202   //edm::InputTag TrackMETEmuExtendedInputTag;
0203   edm::InputTag TrackMHTExtendedInputTag;
0204   edm::InputTag TrackMHTEmuExtendedInputTag;
0205 
0206   edm::EDGetTokenT<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>> ttClusterToken_;
0207   edm::EDGetTokenT<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>> ttStubToken_;
0208   edm::EDGetTokenT<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>> ttClusterMCTruthToken_;
0209   edm::EDGetTokenT<TTStubAssociationMap<Ref_Phase2TrackerDigi_>> ttStubMCTruthToken_;
0210 
0211   edm::EDGetTokenT<L1TrackCollection> ttTrackToken_;
0212   edm::EDGetTokenT<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> ttTrackMCTruthToken_;
0213   edm::EDGetTokenT<L1TrackCollection> ttTrackGTTToken_;
0214   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedToken_;
0215   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedEmulationToken_;
0216   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedAssociatedToken_;
0217   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedAssociatedEmulationToken_;
0218   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedForJetsToken_;
0219   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedEmulationForJetsToken_;
0220   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedAssociatedForJetsToken_;
0221   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedAssociatedEmulationForJetsToken_;
0222   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedForEtMissToken_;
0223   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedEmulationForEtMissToken_;
0224   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedAssociatedForEtMissToken_;
0225   edm::EDGetTokenT<L1TrackRefCollection> ttTrackSelectedAssociatedEmulationForEtMissToken_;
0226   edm::EDGetTokenT<L1TrackCollection> ttTrackExtendedToken_;
0227   edm::EDGetTokenT<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> ttTrackMCTruthExtendedToken_;
0228   edm::EDGetTokenT<L1TrackCollection> ttTrackExtendedGTTToken_;
0229   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedToken_;
0230   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedEmulationToken_;
0231   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedAssociatedToken_;
0232   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedAssociatedEmulationToken_;
0233   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedForJetsToken_;
0234   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedEmulationForJetsToken_;
0235   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedAssociatedForJetsToken_;
0236   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedAssociatedEmulationForJetsToken_;
0237   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedForEtMissToken_;
0238   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedEmulationForEtMissToken_;
0239   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedAssociatedForEtMissToken_;
0240   edm::EDGetTokenT<L1TrackRefCollection> ttTrackExtendedSelectedAssociatedEmulationForEtMissToken_;
0241 
0242   edm::EDGetTokenT<std::vector<TrackingParticle>> TrackingParticleToken_;
0243   edm::EDGetTokenT<std::vector<TrackingVertex>> TrackingVertexToken_;
0244   edm::EDGetTokenT<std::vector<reco::GenJet>> GenJetToken_;
0245   edm::EDGetTokenT<std::vector<reco::GenParticle>> GenParticleToken_;
0246   edm::EDGetTokenT<std::vector<SimVertex>> SimVertexToken_;
0247   edm::EDGetTokenT<l1t::VertexCollection> L1VertexToken_;
0248   edm::EDGetTokenT<l1t::VertexWordCollection> L1VertexEmuToken_;
0249 
0250   edm::EDGetTokenT<std::vector<l1t::TkJet>> TrackFastJetsToken_;
0251   edm::EDGetTokenT<std::vector<l1t::TkJet>> TrackFastJetsExtendedToken_;
0252   edm::EDGetTokenT<std::vector<l1t::TkEtMiss>> TrackMETToken_;
0253   edm::EDGetTokenT<std::vector<l1t::TkEtMiss>> TrackMETExtendedToken_;
0254   edm::EDGetTokenT<std::vector<l1t::EtSum>> TrackMETEmuToken_;
0255   //edm::EDGetTokenT<std::vector<l1t::TkEtMiss>> TrackMETEmuExtendedToken_;
0256   edm::EDGetTokenT<l1t::TkHTMissCollection> TrackMHTToken_;
0257   edm::EDGetTokenT<l1t::TkHTMissCollection> TrackMHTExtendedToken_;
0258   edm::EDGetTokenT<std::vector<l1t::EtSum>> TrackMHTEmuToken_;
0259   edm::EDGetTokenT<std::vector<l1t::EtSum>> TrackMHTEmuExtendedToken_;
0260   edm::EDGetTokenT<l1t::TkJetCollection> TrackJetsToken_;
0261   edm::EDGetTokenT<l1t::TkJetCollection> TrackJetsExtendedToken_;
0262   edm::EDGetTokenT<l1t::TkJetWordCollection> TrackJetsEmuToken_;
0263   edm::EDGetTokenT<l1t::TkJetWordCollection> TrackJetsExtendedEmuToken_;
0264   edm::EDGetTokenT<l1t::TkTripletCollection> TrackTripletsToken_;
0265 
0266   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0267   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tGeomToken_;
0268 
0269   //-----------------------------------------------------------------------------------------------
0270   // tree & branches for mini-ntuple
0271   bool available_;  // ROOT file for histograms is open.
0272   TTree* eventTree;
0273 
0274   // primary vertex
0275   std::vector<float>* m_pv_L1reco;
0276   std::vector<float>* m_pv_L1reco_sum;
0277   std::vector<float>* m_pv_L1reco_emu;
0278   std::vector<float>* m_pv_L1reco_sum_emu;
0279   std::vector<float>* m_pv_MC;
0280   std::vector<int>* m_MC_lep;
0281 
0282   //gen particles
0283   std::vector<float>* m_gen_pt;
0284   std::vector<float>* m_gen_phi;
0285   std::vector<float>* m_gen_pdgid;
0286   std::vector<float>* m_gen_z0;
0287   std::vector<float>* m_gen_mother_pdgid;
0288 
0289   // all L1 tracks (prompt)
0290   std::vector<float>* m_trk_pt;
0291   std::vector<float>* m_trk_eta;
0292   std::vector<float>* m_trk_phi;
0293   std::vector<float>* m_trk_phi_local;
0294   std::vector<float>* m_trk_d0;  // (filled if nFitPar==5, else 999)
0295   std::vector<float>* m_trk_z0;
0296   std::vector<float>* m_trk_chi2;
0297   std::vector<float>* m_trk_chi2dof;
0298   std::vector<float>* m_trk_chi2rphi;
0299   std::vector<float>* m_trk_chi2rz;
0300   std::vector<float>* m_trk_bendchi2;
0301   std::vector<float>* m_trk_MVA1;
0302   std::vector<int>* m_trk_nstub;
0303   std::vector<int>* m_trk_lhits;
0304   std::vector<int>* m_trk_dhits;
0305   std::vector<int>* m_trk_seed;
0306   std::vector<int>* m_trk_hitpattern;
0307   std::vector<unsigned int>* m_trk_phiSector;
0308   std::vector<int>* m_trk_genuine;
0309   std::vector<int>* m_trk_loose;
0310   std::vector<int>* m_trk_unknown;
0311   std::vector<int>* m_trk_combinatoric;
0312   std::vector<int>* m_trk_fake;  //0 fake, 1 track from primary interaction, 2 secondary track
0313   std::vector<int>* m_trk_matchtp_pdgid;
0314   std::vector<int>* m_trk_matchtp_mother_pdgid;
0315 
0316   std::vector<float>* m_trk_matchtp_pt;
0317   std::vector<float>* m_trk_matchtp_eta;
0318   std::vector<float>* m_trk_matchtp_phi;
0319   std::vector<float>* m_trk_matchtp_z0;
0320   std::vector<float>* m_trk_matchtp_dxy;
0321   std::vector<float>* m_trk_gtt_pt;
0322   std::vector<float>* m_trk_gtt_eta;
0323   std::vector<float>* m_trk_gtt_phi;
0324   std::vector<int>* m_trk_selected_index;
0325   std::vector<int>* m_trk_selected_emulation_index;
0326   std::vector<int>* m_trk_selected_associated_index;
0327   std::vector<int>* m_trk_selected_associated_emulation_index;
0328   std::vector<int>* m_trk_selected_forjets_index;
0329   std::vector<int>* m_trk_selected_emulation_forjets_index;
0330   std::vector<int>* m_trk_selected_associated_forjets_index;
0331   std::vector<int>* m_trk_selected_associated_emulation_forjets_index;
0332   std::vector<int>* m_trk_selected_foretmiss_index;
0333   std::vector<int>* m_trk_selected_emulation_foretmiss_index;
0334   std::vector<int>* m_trk_selected_associated_foretmiss_index;
0335   std::vector<int>* m_trk_selected_associated_emulation_foretmiss_index;
0336 
0337   // all L1 tracks (extended)
0338   std::vector<float>* m_trkExt_pt;
0339   std::vector<float>* m_trkExt_eta;
0340   std::vector<float>* m_trkExt_phi;
0341   std::vector<float>* m_trkExt_phi_local;
0342   std::vector<float>* m_trkExt_d0;  // (filled if nFitPar==5, else 999)
0343   std::vector<float>* m_trkExt_z0;
0344   std::vector<float>* m_trkExt_chi2;
0345   std::vector<float>* m_trkExt_chi2dof;
0346   std::vector<float>* m_trkExt_chi2rphi;
0347   std::vector<float>* m_trkExt_chi2rz;
0348   std::vector<float>* m_trkExt_bendchi2;
0349   std::vector<float>* m_trkExt_MVA;
0350   std::vector<int>* m_trkExt_nstub;
0351   std::vector<int>* m_trkExt_lhits;
0352   std::vector<int>* m_trkExt_dhits;
0353   std::vector<int>* m_trkExt_seed;
0354   std::vector<int>* m_trkExt_hitpattern;
0355   std::vector<unsigned int>* m_trkExt_phiSector;
0356   std::vector<int>* m_trkExt_genuine;
0357   std::vector<int>* m_trkExt_loose;
0358   std::vector<int>* m_trkExt_unknown;
0359   std::vector<int>* m_trkExt_combinatoric;
0360   std::vector<int>* m_trkExt_fake;  //0 fake, 1 track from primary interaction, 2 secondary track
0361   std::vector<int>* m_trkExt_matchtp_pdgid;
0362   std::vector<float>* m_trkExt_matchtp_pt;
0363   std::vector<float>* m_trkExt_matchtp_eta;
0364   std::vector<float>* m_trkExt_matchtp_phi;
0365   std::vector<float>* m_trkExt_matchtp_z0;
0366   std::vector<float>* m_trkExt_matchtp_dxy;
0367   std::vector<float>* m_trkExt_gtt_pt;
0368   std::vector<float>* m_trkExt_gtt_eta;
0369   std::vector<float>* m_trkExt_gtt_phi;
0370   std::vector<int>* m_trkExt_selected_index;
0371   std::vector<int>* m_trkExt_selected_emulation_index;
0372   std::vector<int>* m_trkExt_selected_associated_index;
0373   std::vector<int>* m_trkExt_selected_associated_emulation_index;
0374   std::vector<int>* m_trkExt_selected_forjets_index;
0375   std::vector<int>* m_trkExt_selected_emulation_forjets_index;
0376   std::vector<int>* m_trkExt_selected_associated_forjets_index;
0377   std::vector<int>* m_trkExt_selected_associated_emulation_forjets_index;
0378   std::vector<int>* m_trkExt_selected_foretmiss_index;
0379   std::vector<int>* m_trkExt_selected_emulation_foretmiss_index;
0380   std::vector<int>* m_trkExt_selected_associated_foretmiss_index;
0381   std::vector<int>* m_trkExt_selected_associated_emulation_foretmiss_index;
0382 
0383   // all tracking particles
0384   std::vector<float>* m_tp_pt;
0385   std::vector<float>* m_tp_eta;
0386   std::vector<float>* m_tp_phi;
0387   std::vector<float>* m_tp_dxy;
0388   std::vector<float>* m_tp_d0;
0389   std::vector<float>* m_tp_z0;
0390   std::vector<float>* m_tp_d0_prod;
0391   std::vector<float>* m_tp_z0_prod;
0392   std::vector<int>* m_tp_pdgid;
0393   std::vector<int>* m_tp_nmatch;
0394   std::vector<int>* m_tp_nstub;
0395   std::vector<int>* m_tp_eventid;
0396   std::vector<int>* m_tp_charge;
0397 
0398   // *L1 track* properties if m_tp_nmatch > 0 (prompt)
0399   std::vector<float>* m_matchtrk_pt;
0400   std::vector<float>* m_matchtrk_eta;
0401   std::vector<float>* m_matchtrk_phi;
0402   std::vector<float>* m_matchtrk_d0;  //this variable is only filled if nFitPar==5
0403   std::vector<float>* m_matchtrk_z0;
0404   std::vector<float>* m_matchtrk_chi2;
0405   std::vector<float>* m_matchtrk_chi2dof;
0406   std::vector<float>* m_matchtrk_chi2rphi;
0407   std::vector<float>* m_matchtrk_chi2rz;
0408   std::vector<float>* m_matchtrk_bendchi2;
0409   std::vector<float>* m_matchtrk_MVA1;
0410   std::vector<int>* m_matchtrk_nstub;
0411   std::vector<int>* m_matchtrk_lhits;
0412   std::vector<int>* m_matchtrk_dhits;
0413   std::vector<int>* m_matchtrk_seed;
0414   std::vector<int>* m_matchtrk_hitpattern;
0415 
0416   // *L1 track* properties if m_tp_nmatch > 0 (extended)
0417   std::vector<float>* m_matchtrkExt_pt;
0418   std::vector<float>* m_matchtrkExt_eta;
0419   std::vector<float>* m_matchtrkExt_phi;
0420   std::vector<float>* m_matchtrkExt_d0;  //this variable is only filled if nFitPar==5
0421   std::vector<float>* m_matchtrkExt_z0;
0422   std::vector<float>* m_matchtrkExt_chi2;
0423   std::vector<float>* m_matchtrkExt_chi2dof;
0424   std::vector<float>* m_matchtrkExt_chi2rphi;
0425   std::vector<float>* m_matchtrkExt_chi2rz;
0426   std::vector<float>* m_matchtrkExt_bendchi2;
0427   std::vector<float>* m_matchtrkExt_MVA;
0428   std::vector<int>* m_matchtrkExt_nstub;
0429   std::vector<int>* m_matchtrkExt_lhits;
0430   std::vector<int>* m_matchtrkExt_dhits;
0431   std::vector<int>* m_matchtrkExt_seed;
0432   std::vector<int>* m_matchtrkExt_hitpattern;
0433 
0434   // ALL stubs
0435   std::vector<float>* m_allstub_x;
0436   std::vector<float>* m_allstub_y;
0437   std::vector<float>* m_allstub_z;
0438   std::vector<int>* m_allstub_isBarrel;  // stub is in barrel (1) or in disk (0)
0439   std::vector<int>* m_allstub_layer;
0440   std::vector<int>* m_allstub_isPSmodule;
0441   std::vector<float>* m_allstub_trigDisplace;
0442   std::vector<float>* m_allstub_trigOffset;
0443   std::vector<float>* m_allstub_trigPos;
0444   std::vector<float>* m_allstub_trigBend;
0445 
0446   // stub associated with tracking particle ?
0447   std::vector<int>* m_allstub_matchTP_pdgid;  // -999 if not matched
0448   std::vector<float>* m_allstub_matchTP_pt;   // -999 if not matched
0449   std::vector<float>* m_allstub_matchTP_eta;  // -999 if not matched
0450   std::vector<float>* m_allstub_matchTP_phi;  // -999 if not matched
0451   std::vector<int>* m_allstub_genuine;
0452 
0453   //prompt
0454   float trueMET = 0;
0455   float trueTkMET = 0;
0456   float trkMET = 0;
0457   float trkMETPhi = 0;
0458   float trkMHT = 0;
0459   float trkHT = 0;
0460   float trkMHTEmu = 0;
0461   float trkMHTEmuPhi = 0;
0462   float trkHTEmu = 0;
0463   float trkMETEmu = 0;
0464   float trkMETEmuPhi = 0;
0465 
0466   //displaced
0467   float trkMETExt = 0;
0468   float trkMETPhiExt = 0;
0469   float trkMHTExt = 0;
0470   float trkHTExt = 0;
0471   float trkMHTEmuExt = 0;
0472   float trkMHTEmuPhiExt = 0;
0473   float trkHTEmuExt = 0;
0474 
0475   //fast track jet
0476   std::vector<float>* m_trkfastjet_vz;
0477   std::vector<float>* m_trkfastjet_p;
0478   std::vector<float>* m_trkfastjet_phi;
0479   std::vector<float>* m_trkfastjet_eta;
0480   std::vector<float>* m_trkfastjet_pt;
0481   std::vector<int>* m_trkfastjet_ntracks;
0482   std::vector<float>* m_trkfastjet_tp_sumpt;
0483   std::vector<float>* m_trkfastjet_truetp_sumpt;
0484 
0485   std::vector<float>* m_trkfastjetExt_vz;
0486   std::vector<float>* m_trkfastjetExt_p;
0487   std::vector<float>* m_trkfastjetExt_phi;
0488   std::vector<float>* m_trkfastjetExt_eta;
0489   std::vector<float>* m_trkfastjetExt_pt;
0490   std::vector<int>* m_trkfastjetExt_ntracks;
0491   std::vector<float>* m_trkfastjetExt_tp_sumpt;
0492   std::vector<float>* m_trkfastjetExt_truetp_sumpt;
0493 
0494   std::vector<float>* m_genjet_p;
0495   std::vector<float>* m_genjet_phi;
0496   std::vector<float>* m_genjet_eta;
0497   std::vector<float>* m_genjet_pt;
0498 
0499   std::vector<float>* m_trkjet_vz;
0500   std::vector<float>* m_trkjet_p;
0501   std::vector<float>* m_trkjet_phi;
0502   std::vector<float>* m_trkjet_eta;
0503   std::vector<float>* m_trkjet_pt;
0504   std::vector<int>* m_trkjet_ntracks;
0505   std::vector<int>* m_trkjet_nDisplaced;
0506   std::vector<int>* m_trkjet_nTight;
0507   std::vector<int>* m_trkjet_nTightDisplaced;
0508   std::vector<int>* m_trkjet_ntdtrk;
0509 
0510   std::vector<float>* m_trkjetem_pt;
0511   std::vector<float>* m_trkjetem_phi;
0512   std::vector<float>* m_trkjetem_eta;
0513   std::vector<float>* m_trkjetem_z;
0514   std::vector<int>* m_trkjetem_ntracks;
0515   std::vector<int>* m_trkjetem_nxtracks;
0516 
0517   std::vector<float>* m_triplet_phi;
0518   std::vector<float>* m_triplet_eta;
0519   std::vector<float>* m_triplet_pt;
0520   std::vector<float>* m_triplet_mass;
0521   std::vector<float>* m_triplet_charge;
0522   std::vector<float>* m_triplet_dmassmax;
0523   std::vector<float>* m_triplet_dmassmin;
0524   std::vector<float>* m_triplet_dzmax;
0525   std::vector<float>* m_triplet_dzmin;
0526   std::vector<float>* m_triplet_trk1pt;
0527   std::vector<float>* m_triplet_trk1eta;
0528   std::vector<float>* m_triplet_trk1phi;
0529   std::vector<float>* m_triplet_trk1z;
0530   std::vector<float>* m_triplet_trk1npar;
0531   std::vector<float>* m_triplet_trk1mva;
0532   std::vector<float>* m_triplet_trk2pt;
0533   std::vector<float>* m_triplet_trk2eta;
0534   std::vector<float>* m_triplet_trk2phi;
0535   std::vector<float>* m_triplet_trk2z;
0536   std::vector<float>* m_triplet_trk2npar;
0537   std::vector<float>* m_triplet_trk2mva;
0538   std::vector<float>* m_triplet_trk3pt;
0539   std::vector<float>* m_triplet_trk3eta;
0540   std::vector<float>* m_triplet_trk3phi;
0541   std::vector<float>* m_triplet_trk3z;
0542   std::vector<float>* m_triplet_trk3npar;
0543   std::vector<float>* m_triplet_trk3mva;
0544 
0545   std::vector<float>* m_trkjetExt_vz;
0546   std::vector<float>* m_trkjetExt_p;
0547   std::vector<float>* m_trkjetExt_phi;
0548   std::vector<float>* m_trkjetExt_eta;
0549   std::vector<float>* m_trkjetExt_pt;
0550   std::vector<int>* m_trkjetExt_ntracks;
0551   std::vector<int>* m_trkjetExt_nDisplaced;
0552   std::vector<int>* m_trkjetExt_nTight;
0553   std::vector<int>* m_trkjetExt_nTightDisplaced;
0554   std::vector<int>* m_trkjetExt_ntdtrk;
0555 
0556   std::vector<float>* m_trkjetemExt_pt;
0557   std::vector<float>* m_trkjetemExt_phi;
0558   std::vector<float>* m_trkjetemExt_eta;
0559   std::vector<float>* m_trkjetemExt_z;
0560   std::vector<int>* m_trkjetemExt_ntracks;
0561   std::vector<int>* m_trkjetemExt_nxtracks;
0562 };
0563 
0564 //////////////////////////////////
0565 //                              //
0566 //     CLASS IMPLEMENTATION     //
0567 //                              //
0568 //////////////////////////////////
0569 
0570 //////////////
0571 // CONSTRUCTOR
0572 L1TrackObjectNtupleMaker::L1TrackObjectNtupleMaker(edm::ParameterSet const& iConfig) : config(iConfig) {
0573   MyProcess = iConfig.getParameter<int>("MyProcess");
0574   DebugMode = iConfig.getParameter<bool>("DebugMode");
0575   SaveAllTracks = iConfig.getParameter<bool>("SaveAllTracks");
0576   SaveStubs = iConfig.getParameter<bool>("SaveStubs");
0577   Displaced = iConfig.getParameter<string>("Displaced");
0578   TP_minNStub = iConfig.getParameter<int>("TP_minNStub");
0579   TP_minNStubLayer = iConfig.getParameter<int>("TP_minNStubLayer");
0580   TP_minPt = iConfig.getParameter<double>("TP_minPt");
0581   TP_maxEta = iConfig.getParameter<double>("TP_maxEta");
0582   TP_maxZ0 = iConfig.getParameter<double>("TP_maxZ0");
0583   L1Tk_minNStub = iConfig.getParameter<int>("L1Tk_minNStub");
0584 
0585   SaveTrackJets = iConfig.getParameter<bool>("SaveTrackJets");
0586   SaveTrackSums = iConfig.getParameter<bool>("SaveTrackSums");
0587 
0588   L1StubInputTag = iConfig.getParameter<edm::InputTag>("L1StubInputTag");
0589   MCTruthClusterInputTag = iConfig.getParameter<edm::InputTag>("MCTruthClusterInputTag");
0590   MCTruthStubInputTag = iConfig.getParameter<edm::InputTag>("MCTruthStubInputTag");
0591   TrackingParticleInputTag = iConfig.getParameter<edm::InputTag>("TrackingParticleInputTag");
0592   TrackingVertexInputTag = iConfig.getParameter<edm::InputTag>("TrackingVertexInputTag");
0593   GenJetInputTag = iConfig.getParameter<edm::InputTag>("GenJetInputTag");
0594   RecoVertexInputTag = iConfig.getParameter<InputTag>("RecoVertexInputTag");
0595   RecoVertexEmuInputTag = iConfig.getParameter<InputTag>("RecoVertexEmuInputTag");
0596   GenParticleInputTag = iConfig.getParameter<InputTag>("GenParticleInputTag");
0597   SimVertexInputTag = iConfig.getParameter<InputTag>("SimVertexInputTag");
0598 
0599   if (Displaced == "Prompt" || Displaced == "Both") {
0600     L1TrackInputTag = iConfig.getParameter<edm::InputTag>("L1TrackInputTag");
0601     MCTruthTrackInputTag = iConfig.getParameter<edm::InputTag>("MCTruthTrackInputTag");
0602     L1TrackGTTInputTag = iConfig.getParameter<edm::InputTag>("L1TrackGTTInputTag");
0603     L1TrackSelectedInputTag = iConfig.getParameter<edm::InputTag>("L1TrackSelectedInputTag");
0604     L1TrackSelectedEmulationInputTag = iConfig.getParameter<edm::InputTag>("L1TrackSelectedEmulationInputTag");
0605     L1TrackSelectedAssociatedInputTag = iConfig.getParameter<edm::InputTag>("L1TrackSelectedAssociatedInputTag");
0606     L1TrackSelectedAssociatedEmulationInputTag =
0607         iConfig.getParameter<edm::InputTag>("L1TrackSelectedAssociatedEmulationInputTag");
0608     L1TrackSelectedForJetsInputTag = iConfig.getParameter<edm::InputTag>("L1TrackSelectedForJetsInputTag");
0609     L1TrackSelectedEmulationForJetsInputTag =
0610         iConfig.getParameter<edm::InputTag>("L1TrackSelectedEmulationForJetsInputTag");
0611     L1TrackSelectedAssociatedForJetsInputTag =
0612         iConfig.getParameter<edm::InputTag>("L1TrackSelectedAssociatedForJetsInputTag");
0613     L1TrackSelectedAssociatedEmulationForJetsInputTag =
0614         iConfig.getParameter<edm::InputTag>("L1TrackSelectedAssociatedEmulationForJetsInputTag");
0615     L1TrackSelectedForEtMissInputTag = iConfig.getParameter<edm::InputTag>("L1TrackSelectedForEtMissInputTag");
0616     L1TrackSelectedEmulationForEtMissInputTag =
0617         iConfig.getParameter<edm::InputTag>("L1TrackSelectedEmulationForEtMissInputTag");
0618     L1TrackSelectedAssociatedForEtMissInputTag =
0619         iConfig.getParameter<edm::InputTag>("L1TrackSelectedAssociatedForEtMissInputTag");
0620     L1TrackSelectedAssociatedEmulationForEtMissInputTag =
0621         iConfig.getParameter<edm::InputTag>("L1TrackSelectedAssociatedEmulationForEtMissInputTag");
0622     TrackFastJetsInputTag = iConfig.getParameter<InputTag>("TrackFastJetsInputTag");
0623     TrackJetsInputTag = iConfig.getParameter<InputTag>("TrackJetsInputTag");
0624     TrackJetsEmuInputTag = iConfig.getParameter<InputTag>("TrackJetsEmuInputTag");
0625     TrackTripletsInputTag = iConfig.getParameter<InputTag>("TrackTripletsInputTag");
0626     TrackMETInputTag = iConfig.getParameter<InputTag>("TrackMETInputTag");
0627     TrackMETEmuInputTag = iConfig.getParameter<InputTag>("TrackMETEmuInputTag");
0628     TrackMHTInputTag = iConfig.getParameter<InputTag>("TrackMHTInputTag");
0629     TrackMHTEmuInputTag = iConfig.getParameter<InputTag>("TrackMHTEmuInputTag");
0630 
0631     ttTrackToken_ = consumes<L1TrackCollection>(L1TrackInputTag);
0632     ttTrackMCTruthToken_ = consumes<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>(MCTruthTrackInputTag);
0633     ttTrackGTTToken_ = consumes<L1TrackCollection>(L1TrackGTTInputTag);
0634     ttTrackSelectedToken_ = consumes<L1TrackRefCollection>(L1TrackSelectedInputTag);
0635     ttTrackSelectedEmulationToken_ = consumes<L1TrackRefCollection>(L1TrackSelectedEmulationInputTag);
0636     ttTrackSelectedAssociatedToken_ = consumes<L1TrackRefCollection>(L1TrackSelectedAssociatedInputTag);
0637     ttTrackSelectedAssociatedEmulationToken_ =
0638         consumes<L1TrackRefCollection>(L1TrackSelectedAssociatedEmulationInputTag);
0639     ttTrackSelectedForJetsToken_ = consumes<L1TrackRefCollection>(L1TrackSelectedForJetsInputTag);
0640     ttTrackSelectedEmulationForJetsToken_ = consumes<L1TrackRefCollection>(L1TrackSelectedEmulationForJetsInputTag);
0641     ttTrackSelectedAssociatedForJetsToken_ = consumes<L1TrackRefCollection>(L1TrackSelectedAssociatedForJetsInputTag);
0642     ttTrackSelectedAssociatedEmulationForJetsToken_ =
0643         consumes<L1TrackRefCollection>(L1TrackSelectedAssociatedEmulationForJetsInputTag);
0644     ttTrackSelectedForEtMissToken_ = consumes<L1TrackRefCollection>(L1TrackSelectedForEtMissInputTag);
0645     ttTrackSelectedEmulationForEtMissToken_ = consumes<L1TrackRefCollection>(L1TrackSelectedEmulationForEtMissInputTag);
0646     ttTrackSelectedAssociatedForEtMissToken_ =
0647         consumes<L1TrackRefCollection>(L1TrackSelectedAssociatedForEtMissInputTag);
0648     ttTrackSelectedAssociatedEmulationForEtMissToken_ =
0649         consumes<L1TrackRefCollection>(L1TrackSelectedAssociatedEmulationForEtMissInputTag);
0650     TrackFastJetsToken_ = consumes<std::vector<l1t::TkJet>>(TrackFastJetsInputTag);
0651     TrackJetsToken_ = consumes<l1t::TkJetCollection>(TrackJetsInputTag);
0652     TrackJetsEmuToken_ = consumes<l1t::TkJetWordCollection>(TrackJetsEmuInputTag);
0653     TrackTripletsToken_ = consumes<l1t::TkTripletCollection>(TrackTripletsInputTag);
0654     TrackMETToken_ = consumes<std::vector<l1t::TkEtMiss>>(TrackMETInputTag);
0655     TrackMETEmuToken_ = consumes<std::vector<l1t::EtSum>>(TrackMETEmuInputTag);
0656     TrackMHTToken_ = consumes<l1t::TkHTMissCollection>(TrackMHTInputTag);
0657     TrackMHTEmuToken_ = consumes<std::vector<l1t::EtSum>>(TrackMHTEmuInputTag);
0658   }
0659 
0660   if (Displaced == "Displaced" || Displaced == "Both") {
0661     L1TrackExtendedInputTag = iConfig.getParameter<edm::InputTag>("L1TrackExtendedInputTag");
0662     MCTruthTrackExtendedInputTag = iConfig.getParameter<edm::InputTag>("MCTruthTrackExtendedInputTag");
0663     L1TrackExtendedGTTInputTag = iConfig.getParameter<edm::InputTag>("L1TrackExtendedGTTInputTag");
0664     L1TrackExtendedSelectedInputTag = iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedInputTag");
0665     L1TrackExtendedSelectedEmulationInputTag =
0666         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedEmulationInputTag");
0667     L1TrackExtendedSelectedAssociatedInputTag =
0668         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedAssociatedInputTag");
0669     L1TrackExtendedSelectedAssociatedEmulationInputTag =
0670         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedAssociatedEmulationInputTag");
0671     L1TrackExtendedSelectedForJetsInputTag =
0672         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedForJetsInputTag");
0673     L1TrackExtendedSelectedEmulationForJetsInputTag =
0674         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedEmulationForJetsInputTag");
0675     L1TrackExtendedSelectedAssociatedForJetsInputTag =
0676         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedAssociatedForJetsInputTag");
0677     L1TrackExtendedSelectedAssociatedEmulationForJetsInputTag =
0678         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedAssociatedEmulationForJetsInputTag");
0679     L1TrackExtendedSelectedForEtMissInputTag =
0680         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedForEtMissInputTag");
0681     L1TrackExtendedSelectedEmulationForEtMissInputTag =
0682         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedEmulationForEtMissInputTag");
0683     L1TrackExtendedSelectedAssociatedForEtMissInputTag =
0684         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedAssociatedForEtMissInputTag");
0685     L1TrackExtendedSelectedAssociatedEmulationForEtMissInputTag =
0686         iConfig.getParameter<edm::InputTag>("L1TrackExtendedSelectedAssociatedEmulationForEtMissInputTag");
0687     TrackFastJetsExtendedInputTag = iConfig.getParameter<InputTag>("TrackFastJetsExtendedInputTag");
0688     TrackJetsExtendedInputTag = iConfig.getParameter<InputTag>("TrackJetsExtendedInputTag");
0689     TrackJetsExtendedEmuInputTag = iConfig.getParameter<InputTag>("TrackJetsExtendedEmuInputTag");
0690     TrackMETExtendedInputTag = iConfig.getParameter<InputTag>("TrackMETExtendedInputTag");
0691     TrackMHTExtendedInputTag = iConfig.getParameter<InputTag>("TrackMHTExtendedInputTag");
0692     TrackMHTEmuInputTag = iConfig.getParameter<InputTag>("TrackMHTEmuInputTag");
0693     TrackMHTEmuExtendedInputTag = iConfig.getParameter<InputTag>("TrackMHTEmuExtendedInputTag");
0694 
0695     ttTrackExtendedToken_ = consumes<L1TrackCollection>(L1TrackExtendedInputTag);
0696     ttTrackMCTruthExtendedToken_ =
0697         consumes<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>(MCTruthTrackExtendedInputTag);
0698     ttTrackExtendedGTTToken_ = consumes<L1TrackCollection>(L1TrackExtendedGTTInputTag);
0699     ttTrackExtendedSelectedToken_ = consumes<L1TrackRefCollection>(L1TrackExtendedSelectedInputTag);
0700     ttTrackExtendedSelectedEmulationToken_ = consumes<L1TrackRefCollection>(L1TrackExtendedSelectedEmulationInputTag);
0701     ttTrackExtendedSelectedAssociatedToken_ = consumes<L1TrackRefCollection>(L1TrackExtendedSelectedAssociatedInputTag);
0702     ttTrackExtendedSelectedAssociatedEmulationToken_ =
0703         consumes<L1TrackRefCollection>(L1TrackExtendedSelectedAssociatedEmulationInputTag);
0704     ttTrackExtendedSelectedForJetsToken_ = consumes<L1TrackRefCollection>(L1TrackExtendedSelectedForJetsInputTag);
0705     ttTrackExtendedSelectedEmulationForJetsToken_ =
0706         consumes<L1TrackRefCollection>(L1TrackExtendedSelectedEmulationForJetsInputTag);
0707     ttTrackExtendedSelectedAssociatedForJetsToken_ =
0708         consumes<L1TrackRefCollection>(L1TrackExtendedSelectedAssociatedForJetsInputTag);
0709     ttTrackExtendedSelectedAssociatedEmulationForJetsToken_ =
0710         consumes<L1TrackRefCollection>(L1TrackExtendedSelectedAssociatedEmulationForJetsInputTag);
0711     ttTrackExtendedSelectedForEtMissToken_ = consumes<L1TrackRefCollection>(L1TrackExtendedSelectedForEtMissInputTag);
0712     ttTrackExtendedSelectedEmulationForEtMissToken_ =
0713         consumes<L1TrackRefCollection>(L1TrackExtendedSelectedEmulationForEtMissInputTag);
0714     ttTrackExtendedSelectedAssociatedForEtMissToken_ =
0715         consumes<L1TrackRefCollection>(L1TrackExtendedSelectedAssociatedForEtMissInputTag);
0716     ttTrackExtendedSelectedAssociatedEmulationForEtMissToken_ =
0717         consumes<L1TrackRefCollection>(L1TrackExtendedSelectedAssociatedEmulationForEtMissInputTag);
0718     TrackFastJetsExtendedToken_ = consumes<std::vector<l1t::TkJet>>(TrackFastJetsExtendedInputTag);
0719     TrackJetsExtendedToken_ = consumes<l1t::TkJetCollection>(TrackJetsExtendedInputTag);
0720     TrackJetsExtendedEmuToken_ = consumes<l1t::TkJetWordCollection>(TrackJetsExtendedEmuInputTag);
0721     TrackMETExtendedToken_ = consumes<std::vector<l1t::TkEtMiss>>(TrackMETExtendedInputTag);
0722     TrackMHTExtendedToken_ = consumes<l1t::TkHTMissCollection>(TrackMHTExtendedInputTag);
0723     TrackMHTEmuToken_ = consumes<std::vector<l1t::EtSum>>(TrackMHTEmuInputTag);
0724     TrackMHTEmuExtendedToken_ = consumes<std::vector<l1t::EtSum>>(TrackMHTEmuExtendedInputTag);
0725   }
0726 
0727   ttStubToken_ = consumes<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>(L1StubInputTag);
0728   ttClusterMCTruthToken_ = consumes<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>(MCTruthClusterInputTag);
0729   ttStubMCTruthToken_ = consumes<TTStubAssociationMap<Ref_Phase2TrackerDigi_>>(MCTruthStubInputTag);
0730   TrackingParticleToken_ = consumes<std::vector<TrackingParticle>>(TrackingParticleInputTag);
0731   TrackingVertexToken_ = consumes<std::vector<TrackingVertex>>(TrackingVertexInputTag);
0732   GenJetToken_ = consumes<std::vector<reco::GenJet>>(GenJetInputTag);
0733   GenParticleToken_ = consumes<std::vector<reco::GenParticle>>(GenParticleInputTag);
0734   SimVertexToken_ = consumes<std::vector<SimVertex>>(SimVertexInputTag);
0735   L1VertexToken_ = consumes<l1t::VertexCollection>(RecoVertexInputTag);
0736   L1VertexEmuToken_ = consumes<l1t::VertexWordCollection>(RecoVertexEmuInputTag);
0737   tTopoToken_ = esConsumes<TrackerTopology, TrackerTopologyRcd>(edm::ESInputTag("", ""));
0738   tGeomToken_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>(edm::ESInputTag("", ""));
0739 
0740   usesResource(TFileService::kSharedResource);
0741 }
0742 
0743 /////////////
0744 // DESTRUCTOR
0745 L1TrackObjectNtupleMaker::~L1TrackObjectNtupleMaker() {}
0746 
0747 //////////
0748 // END JOB
0749 void L1TrackObjectNtupleMaker::endJob() {
0750   // things to be done at the exit of the event Loop
0751   //  edm::LogVerbatim("Tracklet") << "L1TrackObjectNtupleMaker::endJob";
0752   // clean up raw pointers
0753   delete m_trk_pt;
0754   delete m_trk_eta;
0755   delete m_trk_phi;
0756   delete m_trk_phi_local;
0757   delete m_trk_z0;
0758   delete m_trk_d0;
0759   delete m_trk_chi2;
0760   delete m_trk_chi2dof;
0761   delete m_trk_chi2rphi;
0762   delete m_trk_chi2rz;
0763   delete m_trk_bendchi2;
0764   delete m_trk_MVA1;
0765   delete m_trk_nstub;
0766   delete m_trk_lhits;
0767   delete m_trk_dhits;
0768   delete m_trk_seed;
0769   delete m_trk_hitpattern;
0770   delete m_trk_phiSector;
0771   delete m_trk_genuine;
0772   delete m_trk_loose;
0773   delete m_trk_unknown;
0774   delete m_trk_combinatoric;
0775   delete m_trk_fake;
0776   delete m_trk_matchtp_pdgid;
0777   delete m_trk_matchtp_mother_pdgid;
0778 
0779   delete m_trk_matchtp_pt;
0780   delete m_trk_matchtp_eta;
0781   delete m_trk_matchtp_phi;
0782   delete m_trk_matchtp_z0;
0783   delete m_trk_matchtp_dxy;
0784   delete m_trk_gtt_pt;
0785   delete m_trk_gtt_eta;
0786   delete m_trk_gtt_phi;
0787   delete m_trk_selected_index;
0788   delete m_trk_selected_emulation_index;
0789   delete m_trk_selected_associated_index;
0790   delete m_trk_selected_associated_emulation_index;
0791   delete m_trk_selected_forjets_index;
0792   delete m_trk_selected_emulation_forjets_index;
0793   delete m_trk_selected_associated_forjets_index;
0794   delete m_trk_selected_associated_emulation_forjets_index;
0795   delete m_trk_selected_foretmiss_index;
0796   delete m_trk_selected_emulation_foretmiss_index;
0797   delete m_trk_selected_associated_foretmiss_index;
0798   delete m_trk_selected_associated_emulation_foretmiss_index;
0799 
0800   delete m_trkExt_pt;
0801   delete m_trkExt_eta;
0802   delete m_trkExt_phi;
0803   delete m_trkExt_phi_local;
0804   delete m_trkExt_z0;
0805   delete m_trkExt_d0;
0806   delete m_trkExt_chi2;
0807   delete m_trkExt_chi2dof;
0808   delete m_trkExt_chi2rphi;
0809   delete m_trkExt_chi2rz;
0810   delete m_trkExt_bendchi2;
0811   delete m_trkExt_MVA;
0812   delete m_trkExt_nstub;
0813   delete m_trkExt_lhits;
0814   delete m_trkExt_dhits;
0815   delete m_trkExt_seed;
0816   delete m_trkExt_hitpattern;
0817   delete m_trkExt_phiSector;
0818   delete m_trkExt_genuine;
0819   delete m_trkExt_loose;
0820   delete m_trkExt_unknown;
0821   delete m_trkExt_combinatoric;
0822   delete m_trkExt_fake;
0823   delete m_trkExt_matchtp_pdgid;
0824   delete m_trkExt_matchtp_pt;
0825   delete m_trkExt_matchtp_eta;
0826   delete m_trkExt_matchtp_phi;
0827   delete m_trkExt_matchtp_z0;
0828   delete m_trkExt_matchtp_dxy;
0829   delete m_trkExt_gtt_pt;
0830   delete m_trkExt_gtt_eta;
0831   delete m_trkExt_gtt_phi;
0832   delete m_trkExt_selected_index;
0833   delete m_trkExt_selected_emulation_index;
0834   delete m_trkExt_selected_associated_index;
0835   delete m_trkExt_selected_associated_emulation_index;
0836   delete m_trkExt_selected_forjets_index;
0837   delete m_trkExt_selected_emulation_forjets_index;
0838   delete m_trkExt_selected_associated_forjets_index;
0839   delete m_trkExt_selected_associated_emulation_forjets_index;
0840   delete m_trkExt_selected_foretmiss_index;
0841   delete m_trkExt_selected_emulation_foretmiss_index;
0842   delete m_trkExt_selected_associated_foretmiss_index;
0843   delete m_trkExt_selected_associated_emulation_foretmiss_index;
0844 
0845   delete m_tp_pt;
0846   delete m_tp_eta;
0847   delete m_tp_phi;
0848   delete m_tp_dxy;
0849   delete m_tp_d0;
0850   delete m_tp_z0;
0851   delete m_tp_d0_prod;
0852   delete m_tp_z0_prod;
0853   delete m_tp_pdgid;
0854   delete m_tp_nmatch;
0855   delete m_tp_nstub;
0856   delete m_tp_eventid;
0857   delete m_tp_charge;
0858 
0859   delete m_gen_pt;
0860   delete m_gen_phi;
0861   delete m_gen_pdgid;
0862   delete m_gen_mother_pdgid;
0863 
0864   delete m_gen_z0;
0865 
0866   delete m_matchtrk_pt;
0867   delete m_matchtrk_eta;
0868   delete m_matchtrk_phi;
0869   delete m_matchtrk_z0;
0870   delete m_matchtrk_d0;
0871   delete m_matchtrk_chi2;
0872   delete m_matchtrk_chi2dof;
0873   delete m_matchtrk_chi2rphi;
0874   delete m_matchtrk_chi2rz;
0875   delete m_matchtrk_bendchi2;
0876   delete m_matchtrk_MVA1;
0877   delete m_matchtrk_nstub;
0878   delete m_matchtrk_dhits;
0879   delete m_matchtrk_lhits;
0880   delete m_matchtrk_seed;
0881   delete m_matchtrk_hitpattern;
0882 
0883   delete m_matchtrkExt_pt;
0884   delete m_matchtrkExt_eta;
0885   delete m_matchtrkExt_phi;
0886   delete m_matchtrkExt_z0;
0887   delete m_matchtrkExt_d0;
0888   delete m_matchtrkExt_chi2;
0889   delete m_matchtrkExt_chi2dof;
0890   delete m_matchtrkExt_chi2rphi;
0891   delete m_matchtrkExt_chi2rz;
0892   delete m_matchtrkExt_bendchi2;
0893   delete m_matchtrkExt_MVA;
0894   delete m_matchtrkExt_nstub;
0895   delete m_matchtrkExt_dhits;
0896   delete m_matchtrkExt_lhits;
0897   delete m_matchtrkExt_seed;
0898   delete m_matchtrkExt_hitpattern;
0899 
0900   delete m_allstub_x;
0901   delete m_allstub_y;
0902   delete m_allstub_z;
0903   delete m_allstub_isBarrel;
0904   delete m_allstub_layer;
0905   delete m_allstub_isPSmodule;
0906   delete m_allstub_trigDisplace;
0907   delete m_allstub_trigOffset;
0908   delete m_allstub_trigPos;
0909   delete m_allstub_trigBend;
0910   delete m_allstub_matchTP_pdgid;
0911   delete m_allstub_matchTP_pt;
0912   delete m_allstub_matchTP_eta;
0913   delete m_allstub_matchTP_phi;
0914   delete m_allstub_genuine;
0915 
0916   delete m_pv_L1reco;
0917   delete m_pv_L1reco_sum;
0918   delete m_pv_L1reco_emu;
0919   delete m_pv_L1reco_sum_emu;
0920   delete m_pv_MC;
0921   delete m_MC_lep;
0922 
0923   delete m_trkjet_eta;
0924   delete m_trkjet_vz;
0925   delete m_trkjet_phi;
0926   delete m_trkjet_p;
0927   delete m_trkjet_pt;
0928   delete m_trkjet_ntracks;
0929   delete m_trkjet_nDisplaced;
0930   delete m_trkjet_nTight;
0931   delete m_trkjet_nTightDisplaced;
0932   delete m_trkjet_ntdtrk;
0933 
0934   delete m_trkjetem_pt;
0935   delete m_trkjetem_phi;
0936   delete m_trkjetem_eta;
0937   delete m_trkjetem_z;
0938   delete m_trkjetem_ntracks;
0939   delete m_trkjetem_nxtracks;
0940 
0941   delete m_triplet_eta;
0942   delete m_triplet_phi;
0943   delete m_triplet_pt;
0944   delete m_triplet_mass;
0945   delete m_triplet_charge;
0946   delete m_triplet_dmassmax;
0947   delete m_triplet_dmassmin;
0948   delete m_triplet_dzmax;
0949   delete m_triplet_dzmin;
0950   delete m_triplet_trk1pt;
0951   delete m_triplet_trk1eta;
0952   delete m_triplet_trk1phi;
0953   delete m_triplet_trk1z;
0954   delete m_triplet_trk1npar;
0955   delete m_triplet_trk1mva;
0956   delete m_triplet_trk2pt;
0957   delete m_triplet_trk2eta;
0958   delete m_triplet_trk2phi;
0959   delete m_triplet_trk2z;
0960   delete m_triplet_trk2npar;
0961   delete m_triplet_trk2mva;
0962   delete m_triplet_trk3pt;
0963   delete m_triplet_trk3eta;
0964   delete m_triplet_trk3phi;
0965   delete m_triplet_trk3z;
0966   delete m_triplet_trk3npar;
0967   delete m_triplet_trk3mva;
0968 
0969   delete m_trkfastjet_eta;
0970   delete m_trkfastjet_vz;
0971   delete m_trkfastjet_phi;
0972   delete m_trkfastjet_p;
0973   delete m_trkfastjet_pt;
0974   delete m_trkfastjet_ntracks;
0975   delete m_trkfastjet_tp_sumpt;
0976   delete m_trkfastjet_truetp_sumpt;
0977 
0978   delete m_trkjetExt_eta;
0979   delete m_trkjetExt_vz;
0980   delete m_trkjetExt_phi;
0981   delete m_trkjetExt_p;
0982   delete m_trkjetExt_pt;
0983   delete m_trkjetExt_ntracks;
0984   delete m_trkjetExt_nDisplaced;
0985   delete m_trkjetExt_nTight;
0986   delete m_trkjetExt_nTightDisplaced;
0987   delete m_trkjetExt_ntdtrk;
0988 
0989   delete m_trkjetemExt_pt;
0990   delete m_trkjetemExt_phi;
0991   delete m_trkjetemExt_eta;
0992   delete m_trkjetemExt_z;
0993   delete m_trkjetemExt_ntracks;
0994   delete m_trkjetemExt_nxtracks;
0995 
0996   delete m_trkfastjetExt_eta;
0997   delete m_trkfastjetExt_vz;
0998   delete m_trkfastjetExt_phi;
0999   delete m_trkfastjetExt_p;
1000   delete m_trkfastjetExt_pt;
1001   delete m_trkfastjetExt_ntracks;
1002   delete m_trkfastjetExt_tp_sumpt;
1003   delete m_trkfastjetExt_truetp_sumpt;
1004 }
1005 
1006 ////////////
1007 // BEGIN JOB
1008 void L1TrackObjectNtupleMaker::beginJob() {
1009   // things to be done before entering the event Loop
1010   //  edm::LogVerbatim("Tracklet") << "L1TrackObjectNtupleMaker::beginJob";
1011 
1012   //-----------------------------------------------------------------------------------------------
1013   // book histograms / make ntuple
1014   edm::Service<TFileService> fs;
1015   available_ = fs.isAvailable();
1016   if (not available_)
1017     return;  // No ROOT file open.
1018 
1019   // initilize
1020   m_trk_pt = new std::vector<float>;
1021   m_trk_eta = new std::vector<float>;
1022   m_trk_phi = new std::vector<float>;
1023   m_trk_phi_local = new std::vector<float>;
1024   m_trk_z0 = new std::vector<float>;
1025   m_trk_d0 = new std::vector<float>;
1026   m_trk_chi2 = new std::vector<float>;
1027   m_trk_chi2dof = new std::vector<float>;
1028   m_trk_chi2rphi = new std::vector<float>;
1029   m_trk_chi2rz = new std::vector<float>;
1030   m_trk_bendchi2 = new std::vector<float>;
1031   m_trk_MVA1 = new std::vector<float>;
1032   m_trk_nstub = new std::vector<int>;
1033   m_trk_lhits = new std::vector<int>;
1034   m_trk_dhits = new std::vector<int>;
1035   m_trk_seed = new std::vector<int>;
1036   m_trk_hitpattern = new std::vector<int>;
1037   m_trk_phiSector = new std::vector<unsigned int>;
1038   m_trk_genuine = new std::vector<int>;
1039   m_trk_loose = new std::vector<int>;
1040   m_trk_unknown = new std::vector<int>;
1041   m_trk_combinatoric = new std::vector<int>;
1042   m_trk_fake = new std::vector<int>;
1043   m_trk_matchtp_pdgid = new std::vector<int>;
1044   m_trk_matchtp_mother_pdgid = new std::vector<int>;
1045 
1046   m_trk_matchtp_pt = new std::vector<float>;
1047   m_trk_matchtp_eta = new std::vector<float>;
1048   m_trk_matchtp_phi = new std::vector<float>;
1049   m_trk_matchtp_z0 = new std::vector<float>;
1050   m_trk_matchtp_dxy = new std::vector<float>;
1051   m_trk_gtt_pt = new std::vector<float>;
1052   m_trk_gtt_eta = new std::vector<float>;
1053   m_trk_gtt_phi = new std::vector<float>;
1054   m_trk_selected_index = new std::vector<int>;
1055   m_trk_selected_emulation_index = new std::vector<int>;
1056   m_trk_selected_associated_index = new std::vector<int>;
1057   m_trk_selected_associated_emulation_index = new std::vector<int>;
1058   m_trk_selected_forjets_index = new std::vector<int>;
1059   m_trk_selected_emulation_forjets_index = new std::vector<int>;
1060   m_trk_selected_associated_forjets_index = new std::vector<int>;
1061   m_trk_selected_associated_emulation_forjets_index = new std::vector<int>;
1062   m_trk_selected_foretmiss_index = new std::vector<int>;
1063   m_trk_selected_emulation_foretmiss_index = new std::vector<int>;
1064   m_trk_selected_associated_foretmiss_index = new std::vector<int>;
1065   m_trk_selected_associated_emulation_foretmiss_index = new std::vector<int>;
1066 
1067   m_trkExt_pt = new std::vector<float>;
1068   m_trkExt_eta = new std::vector<float>;
1069   m_trkExt_phi = new std::vector<float>;
1070   m_trkExt_phi_local = new std::vector<float>;
1071   m_trkExt_z0 = new std::vector<float>;
1072   m_trkExt_d0 = new std::vector<float>;
1073   m_trkExt_chi2 = new std::vector<float>;
1074   m_trkExt_chi2dof = new std::vector<float>;
1075   m_trkExt_chi2rphi = new std::vector<float>;
1076   m_trkExt_chi2rz = new std::vector<float>;
1077   m_trkExt_bendchi2 = new std::vector<float>;
1078   m_trkExt_MVA = new std::vector<float>;
1079   m_trkExt_nstub = new std::vector<int>;
1080   m_trkExt_lhits = new std::vector<int>;
1081   m_trkExt_dhits = new std::vector<int>;
1082   m_trkExt_seed = new std::vector<int>;
1083   m_trkExt_hitpattern = new std::vector<int>;
1084   m_trkExt_phiSector = new std::vector<unsigned int>;
1085   m_trkExt_genuine = new std::vector<int>;
1086   m_trkExt_loose = new std::vector<int>;
1087   m_trkExt_unknown = new std::vector<int>;
1088   m_trkExt_combinatoric = new std::vector<int>;
1089   m_trkExt_fake = new std::vector<int>;
1090   m_trkExt_matchtp_pdgid = new std::vector<int>;
1091   m_trkExt_matchtp_pt = new std::vector<float>;
1092   m_trkExt_matchtp_eta = new std::vector<float>;
1093   m_trkExt_matchtp_phi = new std::vector<float>;
1094   m_trkExt_matchtp_z0 = new std::vector<float>;
1095   m_trkExt_matchtp_dxy = new std::vector<float>;
1096   m_trkExt_gtt_pt = new std::vector<float>;
1097   m_trkExt_gtt_eta = new std::vector<float>;
1098   m_trkExt_gtt_phi = new std::vector<float>;
1099   m_trkExt_selected_index = new std::vector<int>;
1100   m_trkExt_selected_emulation_index = new std::vector<int>;
1101   m_trkExt_selected_associated_index = new std::vector<int>;
1102   m_trkExt_selected_associated_emulation_index = new std::vector<int>;
1103   m_trkExt_selected_forjets_index = new std::vector<int>;
1104   m_trkExt_selected_emulation_forjets_index = new std::vector<int>;
1105   m_trkExt_selected_associated_forjets_index = new std::vector<int>;
1106   m_trkExt_selected_associated_emulation_forjets_index = new std::vector<int>;
1107   m_trkExt_selected_foretmiss_index = new std::vector<int>;
1108   m_trkExt_selected_emulation_foretmiss_index = new std::vector<int>;
1109   m_trkExt_selected_associated_foretmiss_index = new std::vector<int>;
1110   m_trkExt_selected_associated_emulation_foretmiss_index = new std::vector<int>;
1111 
1112   m_tp_pt = new std::vector<float>;
1113   m_tp_eta = new std::vector<float>;
1114   m_tp_phi = new std::vector<float>;
1115   m_tp_dxy = new std::vector<float>;
1116   m_tp_d0 = new std::vector<float>;
1117   m_tp_z0 = new std::vector<float>;
1118   m_tp_d0_prod = new std::vector<float>;
1119   m_tp_z0_prod = new std::vector<float>;
1120   m_tp_pdgid = new std::vector<int>;
1121   m_tp_nmatch = new std::vector<int>;
1122   m_tp_nstub = new std::vector<int>;
1123   m_tp_eventid = new std::vector<int>;
1124   m_tp_charge = new std::vector<int>;
1125 
1126   m_gen_pt = new std::vector<float>;
1127   m_gen_phi = new std::vector<float>;
1128   m_gen_pdgid = new std::vector<float>;
1129   m_gen_mother_pdgid = new std::vector<float>;
1130 
1131   m_gen_z0 = new std::vector<float>;
1132 
1133   m_matchtrk_pt = new std::vector<float>;
1134   m_matchtrk_eta = new std::vector<float>;
1135   m_matchtrk_phi = new std::vector<float>;
1136   m_matchtrk_z0 = new std::vector<float>;
1137   m_matchtrk_d0 = new std::vector<float>;
1138   m_matchtrk_chi2 = new std::vector<float>;
1139   m_matchtrk_chi2dof = new std::vector<float>;
1140   m_matchtrk_chi2rphi = new std::vector<float>;
1141   m_matchtrk_chi2rz = new std::vector<float>;
1142   m_matchtrk_bendchi2 = new std::vector<float>;
1143   m_matchtrk_MVA1 = new std::vector<float>;
1144   m_matchtrk_nstub = new std::vector<int>;
1145   m_matchtrk_dhits = new std::vector<int>;
1146   m_matchtrk_lhits = new std::vector<int>;
1147   m_matchtrk_seed = new std::vector<int>;
1148   m_matchtrk_hitpattern = new std::vector<int>;
1149 
1150   m_matchtrkExt_pt = new std::vector<float>;
1151   m_matchtrkExt_eta = new std::vector<float>;
1152   m_matchtrkExt_phi = new std::vector<float>;
1153   m_matchtrkExt_z0 = new std::vector<float>;
1154   m_matchtrkExt_d0 = new std::vector<float>;
1155   m_matchtrkExt_chi2 = new std::vector<float>;
1156   m_matchtrkExt_chi2dof = new std::vector<float>;
1157   m_matchtrkExt_chi2rphi = new std::vector<float>;
1158   m_matchtrkExt_chi2rz = new std::vector<float>;
1159   m_matchtrkExt_bendchi2 = new std::vector<float>;
1160   m_matchtrkExt_MVA = new std::vector<float>;
1161   m_matchtrkExt_nstub = new std::vector<int>;
1162   m_matchtrkExt_dhits = new std::vector<int>;
1163   m_matchtrkExt_lhits = new std::vector<int>;
1164   m_matchtrkExt_seed = new std::vector<int>;
1165   m_matchtrkExt_hitpattern = new std::vector<int>;
1166 
1167   m_allstub_x = new std::vector<float>;
1168   m_allstub_y = new std::vector<float>;
1169   m_allstub_z = new std::vector<float>;
1170   m_allstub_isBarrel = new std::vector<int>;
1171   m_allstub_layer = new std::vector<int>;
1172   m_allstub_isPSmodule = new std::vector<int>;
1173   m_allstub_trigDisplace = new std::vector<float>;
1174   m_allstub_trigOffset = new std::vector<float>;
1175   m_allstub_trigPos = new std::vector<float>;
1176   m_allstub_trigBend = new std::vector<float>;
1177   m_allstub_matchTP_pdgid = new std::vector<int>;
1178   m_allstub_matchTP_pt = new std::vector<float>;
1179   m_allstub_matchTP_eta = new std::vector<float>;
1180   m_allstub_matchTP_phi = new std::vector<float>;
1181   m_allstub_genuine = new std::vector<int>;
1182 
1183   m_pv_L1reco = new std::vector<float>;
1184   m_pv_L1reco_sum = new std::vector<float>;
1185   m_pv_L1reco_emu = new std::vector<float>;
1186   m_pv_L1reco_sum_emu = new std::vector<float>;
1187   m_pv_MC = new std::vector<float>;
1188   m_MC_lep = new std::vector<int>;
1189 
1190   m_genjet_eta = new std::vector<float>;
1191   m_genjet_phi = new std::vector<float>;
1192   m_genjet_p = new std::vector<float>;
1193   m_genjet_pt = new std::vector<float>;
1194 
1195   m_trkjet_eta = new std::vector<float>;
1196   m_trkjet_vz = new std::vector<float>;
1197   m_trkjet_phi = new std::vector<float>;
1198   m_trkjet_p = new std::vector<float>;
1199   m_trkjet_pt = new std::vector<float>;
1200   m_trkjet_ntracks = new std::vector<int>;
1201   m_trkjet_nDisplaced = new std::vector<int>;
1202   m_trkjet_nTight = new std::vector<int>;
1203   m_trkjet_nTightDisplaced = new std::vector<int>;
1204   m_trkjet_ntdtrk = new std::vector<int>;
1205 
1206   m_triplet_eta = new std::vector<float>;
1207   m_triplet_phi = new std::vector<float>;
1208   m_triplet_pt = new std::vector<float>;
1209   m_triplet_mass = new std::vector<float>;
1210   m_triplet_charge = new std::vector<float>;
1211   m_triplet_dmassmax = new std::vector<float>;
1212   m_triplet_dmassmin = new std::vector<float>;
1213   m_triplet_dzmax = new std::vector<float>;
1214   m_triplet_dzmin = new std::vector<float>;
1215   m_triplet_trk1pt = new std::vector<float>;
1216   m_triplet_trk1eta = new std::vector<float>;
1217   m_triplet_trk1phi = new std::vector<float>;
1218   m_triplet_trk1z = new std::vector<float>;
1219   m_triplet_trk1npar = new std::vector<float>;
1220   m_triplet_trk1mva = new std::vector<float>;
1221   m_triplet_trk2pt = new std::vector<float>;
1222   m_triplet_trk2eta = new std::vector<float>;
1223   m_triplet_trk2phi = new std::vector<float>;
1224   m_triplet_trk2z = new std::vector<float>;
1225   m_triplet_trk2npar = new std::vector<float>;
1226   m_triplet_trk2mva = new std::vector<float>;
1227   m_triplet_trk3pt = new std::vector<float>;
1228   m_triplet_trk3eta = new std::vector<float>;
1229   m_triplet_trk3phi = new std::vector<float>;
1230   m_triplet_trk3z = new std::vector<float>;
1231   m_triplet_trk3npar = new std::vector<float>;
1232   m_triplet_trk3mva = new std::vector<float>;
1233 
1234   m_trkjetem_pt = new std::vector<float>;
1235   m_trkjetem_phi = new std::vector<float>;
1236   m_trkjetem_eta = new std::vector<float>;
1237   m_trkjetem_z = new std::vector<float>;
1238   m_trkjetem_ntracks = new std::vector<int>;
1239   m_trkjetem_nxtracks = new std::vector<int>;
1240 
1241   m_trkfastjet_eta = new std::vector<float>;
1242   m_trkfastjet_vz = new std::vector<float>;
1243   m_trkfastjet_phi = new std::vector<float>;
1244   m_trkfastjet_p = new std::vector<float>;
1245   m_trkfastjet_pt = new std::vector<float>;
1246   m_trkfastjet_ntracks = new std::vector<int>;
1247   m_trkfastjet_tp_sumpt = new std::vector<float>;
1248   m_trkfastjet_truetp_sumpt = new std::vector<float>;
1249 
1250   m_trkjetExt_eta = new std::vector<float>;
1251   m_trkjetExt_vz = new std::vector<float>;
1252   m_trkjetExt_phi = new std::vector<float>;
1253   m_trkjetExt_p = new std::vector<float>;
1254   m_trkjetExt_pt = new std::vector<float>;
1255   m_trkjetExt_ntracks = new std::vector<int>;
1256   m_trkjetExt_nDisplaced = new std::vector<int>;
1257   m_trkjetExt_nTight = new std::vector<int>;
1258   m_trkjetExt_nTightDisplaced = new std::vector<int>;
1259   m_trkjetExt_ntdtrk = new std::vector<int>;
1260 
1261   m_trkjetemExt_pt = new std::vector<float>;
1262   m_trkjetemExt_phi = new std::vector<float>;
1263   m_trkjetemExt_eta = new std::vector<float>;
1264   m_trkjetemExt_z = new std::vector<float>;
1265   m_trkjetemExt_ntracks = new std::vector<int>;
1266   m_trkjetemExt_nxtracks = new std::vector<int>;
1267 
1268   m_trkfastjetExt_eta = new std::vector<float>;
1269   m_trkfastjetExt_vz = new std::vector<float>;
1270   m_trkfastjetExt_phi = new std::vector<float>;
1271   m_trkfastjetExt_p = new std::vector<float>;
1272   m_trkfastjetExt_pt = new std::vector<float>;
1273   m_trkfastjetExt_ntracks = new std::vector<int>;
1274   m_trkfastjetExt_tp_sumpt = new std::vector<float>;
1275   m_trkfastjetExt_truetp_sumpt = new std::vector<float>;
1276 
1277   // ntuple
1278   eventTree = fs->make<TTree>("eventTree", "Event tree");
1279   if (SaveAllTracks && (Displaced == "Prompt" || Displaced == "Both")) {
1280     eventTree->Branch("trk_pt", &m_trk_pt);
1281     eventTree->Branch("trk_eta", &m_trk_eta);
1282     eventTree->Branch("trk_phi", &m_trk_phi);
1283     eventTree->Branch("trk_phi_local", &m_trk_phi_local);
1284     eventTree->Branch("trk_d0", &m_trk_d0);
1285     eventTree->Branch("trk_z0", &m_trk_z0);
1286     eventTree->Branch("trk_chi2", &m_trk_chi2);
1287     eventTree->Branch("trk_chi2dof", &m_trk_chi2dof);
1288     eventTree->Branch("trk_chi2rphi", &m_trk_chi2rphi);
1289     eventTree->Branch("trk_chi2rz", &m_trk_chi2rz);
1290     eventTree->Branch("trk_bendchi2", &m_trk_bendchi2);
1291     eventTree->Branch("trk_MVA1", &m_trk_MVA1);
1292     eventTree->Branch("trk_nstub", &m_trk_nstub);
1293     eventTree->Branch("trk_lhits", &m_trk_lhits);
1294     eventTree->Branch("trk_dhits", &m_trk_dhits);
1295     eventTree->Branch("trk_seed", &m_trk_seed);
1296     eventTree->Branch("trk_hitpattern", &m_trk_hitpattern);
1297     eventTree->Branch("trk_phiSector", &m_trk_phiSector);
1298     eventTree->Branch("trk_genuine", &m_trk_genuine);
1299     eventTree->Branch("trk_loose", &m_trk_loose);
1300     eventTree->Branch("trk_unknown", &m_trk_unknown);
1301     eventTree->Branch("trk_combinatoric", &m_trk_combinatoric);
1302     eventTree->Branch("trk_fake", &m_trk_fake);
1303     eventTree->Branch("trk_matchtp_pdgid", &m_trk_matchtp_pdgid);
1304     eventTree->Branch("trk_matchtp_mother_pdgid", &m_trk_matchtp_mother_pdgid);
1305 
1306     eventTree->Branch("trk_matchtp_pt", &m_trk_matchtp_pt);
1307     eventTree->Branch("trk_matchtp_eta", &m_trk_matchtp_eta);
1308     eventTree->Branch("trk_matchtp_phi", &m_trk_matchtp_phi);
1309     eventTree->Branch("trk_matchtp_z0", &m_trk_matchtp_z0);
1310     eventTree->Branch("trk_matchtp_dxy", &m_trk_matchtp_dxy);
1311     eventTree->Branch("trk_gtt_pt", &m_trk_gtt_pt);
1312     eventTree->Branch("trk_gtt_eta", &m_trk_gtt_eta);
1313     eventTree->Branch("trk_gtt_phi", &m_trk_gtt_phi);
1314     eventTree->Branch("trk_gtt_selected_index", &m_trk_selected_index);
1315     eventTree->Branch("trk_gtt_selected_emulation_index", &m_trk_selected_emulation_index);
1316     eventTree->Branch("trk_gtt_selected_associated_index", &m_trk_selected_associated_index);
1317     eventTree->Branch("trk_gtt_selected_associated_emulation_index", &m_trk_selected_associated_emulation_index);
1318     eventTree->Branch("trk_gtt_selected_forjets_index", &m_trk_selected_forjets_index);
1319     eventTree->Branch("trk_gtt_selected_emulation_forjets_index", &m_trk_selected_emulation_forjets_index);
1320     eventTree->Branch("trk_gtt_selected_associated_forjets_index", &m_trk_selected_associated_forjets_index);
1321     eventTree->Branch("trk_gtt_selected_associated_emulation_forjets_index",
1322                       &m_trk_selected_associated_emulation_forjets_index);
1323     eventTree->Branch("trk_gtt_selected_foretmiss_index", &m_trk_selected_foretmiss_index);
1324     eventTree->Branch("trk_gtt_selected_emulation_foretmiss_index", &m_trk_selected_emulation_foretmiss_index);
1325     eventTree->Branch("trk_gtt_selected_associated_foretmiss_index", &m_trk_selected_associated_foretmiss_index);
1326     eventTree->Branch("trk_gtt_selected_associated_emulation_foretmiss_index",
1327                       &m_trk_selected_associated_emulation_foretmiss_index);
1328   }
1329 
1330   if (SaveAllTracks && (Displaced == "Displaced" || Displaced == "Both")) {
1331     eventTree->Branch("trkExt_pt", &m_trkExt_pt);
1332     eventTree->Branch("trkExt_eta", &m_trkExt_eta);
1333     eventTree->Branch("trkExt_phi", &m_trkExt_phi);
1334     eventTree->Branch("trkExt_phi_local", &m_trkExt_phi_local);
1335     eventTree->Branch("trkExt_d0", &m_trkExt_d0);
1336     eventTree->Branch("trkExt_z0", &m_trkExt_z0);
1337     eventTree->Branch("trkExt_chi2", &m_trkExt_chi2);
1338     eventTree->Branch("trkExt_chi2dof", &m_trkExt_chi2dof);
1339     eventTree->Branch("trkExt_chi2rphi", &m_trkExt_chi2rphi);
1340     eventTree->Branch("trkExt_chi2rz", &m_trkExt_chi2rz);
1341     eventTree->Branch("trkExt_bendchi2", &m_trkExt_bendchi2);
1342     eventTree->Branch("trkExt_MVA", &m_trkExt_MVA);
1343     eventTree->Branch("trkExt_nstub", &m_trkExt_nstub);
1344     eventTree->Branch("trkExt_lhits", &m_trkExt_lhits);
1345     eventTree->Branch("trkExt_dhits", &m_trkExt_dhits);
1346     eventTree->Branch("trkExt_seed", &m_trkExt_seed);
1347     eventTree->Branch("trkExt_hitpattern", &m_trkExt_hitpattern);
1348     eventTree->Branch("trkExt_phiSector", &m_trkExt_phiSector);
1349     eventTree->Branch("trkExt_genuine", &m_trkExt_genuine);
1350     eventTree->Branch("trkExt_loose", &m_trkExt_loose);
1351     eventTree->Branch("trkExt_unknown", &m_trkExt_unknown);
1352     eventTree->Branch("trkExt_combinatoric", &m_trkExt_combinatoric);
1353     eventTree->Branch("trkExt_fake", &m_trkExt_fake);
1354     eventTree->Branch("trkExt_matchtp_pdgid", &m_trkExt_matchtp_pdgid);
1355     eventTree->Branch("trkExt_matchtp_pt", &m_trkExt_matchtp_pt);
1356     eventTree->Branch("trkExt_matchtp_eta", &m_trkExt_matchtp_eta);
1357     eventTree->Branch("trkExt_matchtp_phi", &m_trkExt_matchtp_phi);
1358     eventTree->Branch("trkExt_matchtp_z0", &m_trkExt_matchtp_z0);
1359     eventTree->Branch("trkExt_matchtp_dxy", &m_trkExt_matchtp_dxy);
1360     eventTree->Branch("trkExt_gtt_pt", &m_trkExt_gtt_pt);
1361     eventTree->Branch("trkExt_gtt_eta", &m_trkExt_gtt_eta);
1362     eventTree->Branch("trkExt_gtt_phi", &m_trkExt_gtt_phi);
1363     eventTree->Branch("trkExt_gtt_selected_index", &m_trkExt_selected_index);
1364     eventTree->Branch("trkExt_gtt_selected_emulation_index", &m_trkExt_selected_emulation_index);
1365     eventTree->Branch("trkExt_gtt_selected_associated_index", &m_trkExt_selected_associated_index);
1366     eventTree->Branch("trkExt_gtt_selected_associated_emulation_index", &m_trkExt_selected_associated_emulation_index);
1367     eventTree->Branch("trkExt_gtt_selected_forjets_index", &m_trkExt_selected_forjets_index);
1368     eventTree->Branch("trkExt_gtt_selected_emulation_forjets_index", &m_trkExt_selected_emulation_forjets_index);
1369     eventTree->Branch("trkExt_gtt_selected_associated_forjets_index", &m_trkExt_selected_associated_forjets_index);
1370     eventTree->Branch("trkExt_gtt_selected_associated_emulation_forjets_index",
1371                       &m_trkExt_selected_associated_emulation_forjets_index);
1372     eventTree->Branch("trkExt_gtt_selected_foretmiss_index", &m_trkExt_selected_foretmiss_index);
1373     eventTree->Branch("trkExt_gtt_selected_emulation_foretmiss_index", &m_trkExt_selected_emulation_foretmiss_index);
1374     eventTree->Branch("trkExt_gtt_selected_associated_foretmiss_index", &m_trkExt_selected_associated_foretmiss_index);
1375     eventTree->Branch("trkExt_gtt_selected_associated_emulation_foretmiss_index",
1376                       &m_trkExt_selected_associated_emulation_foretmiss_index);
1377   }
1378   eventTree->Branch("tp_pt", &m_tp_pt);
1379   eventTree->Branch("tp_eta", &m_tp_eta);
1380   eventTree->Branch("tp_phi", &m_tp_phi);
1381   eventTree->Branch("tp_dxy", &m_tp_dxy);
1382   eventTree->Branch("tp_d0", &m_tp_d0);
1383   eventTree->Branch("tp_z0", &m_tp_z0);
1384   eventTree->Branch("tp_d0_prod", &m_tp_d0_prod);
1385   eventTree->Branch("tp_z0_prod", &m_tp_z0_prod);
1386   eventTree->Branch("tp_pdgid", &m_tp_pdgid);
1387   eventTree->Branch("tp_nmatch", &m_tp_nmatch);
1388   eventTree->Branch("tp_nstub", &m_tp_nstub);
1389   eventTree->Branch("tp_eventid", &m_tp_eventid);
1390   eventTree->Branch("tp_charge", &m_tp_charge);
1391 
1392   if (Displaced == "Prompt" || Displaced == "Both") {
1393     eventTree->Branch("matchtrk_pt", &m_matchtrk_pt);
1394     eventTree->Branch("matchtrk_eta", &m_matchtrk_eta);
1395     eventTree->Branch("matchtrk_phi", &m_matchtrk_phi);
1396     eventTree->Branch("matchtrk_z0", &m_matchtrk_z0);
1397     eventTree->Branch("matchtrk_d0", &m_matchtrk_d0);
1398     eventTree->Branch("matchtrk_chi2", &m_matchtrk_chi2);
1399     eventTree->Branch("matchtrk_chi2dof", &m_matchtrk_chi2dof);
1400     eventTree->Branch("matchtrk_chi2rphi", &m_matchtrk_chi2rphi);
1401     eventTree->Branch("matchtrk_chi2rz", &m_matchtrk_chi2rz);
1402     eventTree->Branch("matchtrk_bendchi2", &m_matchtrk_bendchi2);
1403     eventTree->Branch("matchtrk_MVA1", &m_matchtrk_MVA1);
1404     eventTree->Branch("matchtrk_nstub", &m_matchtrk_nstub);
1405     eventTree->Branch("matchtrk_lhits", &m_matchtrk_lhits);
1406     eventTree->Branch("matchtrk_dhits", &m_matchtrk_dhits);
1407     eventTree->Branch("matchtrk_seed", &m_matchtrk_seed);
1408     eventTree->Branch("matchtrk_hitpattern", &m_matchtrk_hitpattern);
1409   }
1410 
1411   if (Displaced == "Displaced" || Displaced == "Both") {
1412     eventTree->Branch("matchtrkExt_pt", &m_matchtrkExt_pt);
1413     eventTree->Branch("matchtrkExt_eta", &m_matchtrkExt_eta);
1414     eventTree->Branch("matchtrkExt_phi", &m_matchtrkExt_phi);
1415     eventTree->Branch("matchtrkExt_z0", &m_matchtrkExt_z0);
1416     eventTree->Branch("matchtrkExt_d0", &m_matchtrkExt_d0);
1417     eventTree->Branch("matchtrkExt_chi2", &m_matchtrkExt_chi2);
1418     eventTree->Branch("matchtrkExt_chi2dof", &m_matchtrkExt_chi2dof);
1419     eventTree->Branch("matchtrkExt_chi2rphi", &m_matchtrkExt_chi2rphi);
1420     eventTree->Branch("matchtrkExt_chi2rz", &m_matchtrkExt_chi2rz);
1421     eventTree->Branch("matchtrkExt_bendchi2", &m_matchtrkExt_bendchi2);
1422     eventTree->Branch("matchtrkExt_MVA", &m_matchtrkExt_MVA);
1423     eventTree->Branch("matchtrkExt_nstub", &m_matchtrkExt_nstub);
1424     eventTree->Branch("matchtrkExt_lhits", &m_matchtrkExt_lhits);
1425     eventTree->Branch("matchtrkExt_dhits", &m_matchtrkExt_dhits);
1426     eventTree->Branch("matchtrkExt_seed", &m_matchtrkExt_seed);
1427     eventTree->Branch("matchtrkExt_hitpattern", &m_matchtrkExt_hitpattern);
1428   }
1429 
1430   if (SaveStubs) {
1431     eventTree->Branch("allstub_x", &m_allstub_x);
1432     eventTree->Branch("allstub_y", &m_allstub_y);
1433     eventTree->Branch("allstub_z", &m_allstub_z);
1434     eventTree->Branch("allstub_isBarrel", &m_allstub_isBarrel);
1435     eventTree->Branch("allstub_layer", &m_allstub_layer);
1436     eventTree->Branch("allstub_isPSmodule", &m_allstub_isPSmodule);
1437     eventTree->Branch("allstub_trigDisplace", &m_allstub_trigDisplace);
1438     eventTree->Branch("allstub_trigOffset", &m_allstub_trigOffset);
1439     eventTree->Branch("allstub_trigPos", &m_allstub_trigPos);
1440     eventTree->Branch("allstub_trigBend", &m_allstub_trigBend);
1441     eventTree->Branch("allstub_matchTP_pdgid", &m_allstub_matchTP_pdgid);
1442     eventTree->Branch("allstub_matchTP_pt", &m_allstub_matchTP_pt);
1443     eventTree->Branch("allstub_matchTP_eta", &m_allstub_matchTP_eta);
1444     eventTree->Branch("allstub_matchTP_phi", &m_allstub_matchTP_phi);
1445     eventTree->Branch("allstub_genuine", &m_allstub_genuine);
1446   }
1447 
1448   eventTree->Branch("pv_L1reco", &m_pv_L1reco);
1449   eventTree->Branch("pv_L1reco_sum", &m_pv_L1reco_sum);
1450   eventTree->Branch("pv_L1reco_emu", &m_pv_L1reco_emu);
1451   eventTree->Branch("pv_L1reco_sum_emu", &m_pv_L1reco_sum_emu);
1452   eventTree->Branch("MC_lep", &m_MC_lep);
1453   eventTree->Branch("pv_MC", &m_pv_MC);
1454   eventTree->Branch("gen_pt", &m_gen_pt);
1455   eventTree->Branch("gen_phi", &m_gen_phi);
1456   eventTree->Branch("gen_pdgid", &m_gen_pdgid);
1457   eventTree->Branch("gen_mother_pdgid", &m_gen_mother_pdgid);
1458 
1459   eventTree->Branch("gen_z0", &m_gen_z0);
1460 
1461   if (SaveTrackJets) {
1462     eventTree->Branch("genjet_eta", &m_genjet_eta);
1463     eventTree->Branch("genjet_p", &m_genjet_p);
1464     eventTree->Branch("genjet_pt", &m_genjet_pt);
1465     eventTree->Branch("genjet_phi", &m_genjet_phi);
1466     if (Displaced == "Prompt" || Displaced == "Both") {
1467       eventTree->Branch("trkfastjet_eta", &m_trkfastjet_eta);
1468       eventTree->Branch("trkfastjet_vz", &m_trkfastjet_vz);
1469       eventTree->Branch("trkfastjet_p", &m_trkfastjet_p);
1470       eventTree->Branch("trkfastjet_pt", &m_trkfastjet_pt);
1471       eventTree->Branch("trkfastjet_phi", &m_trkfastjet_phi);
1472       eventTree->Branch("trkfastjet_ntracks", &m_trkfastjet_ntracks);
1473       eventTree->Branch("trkfastjet_truetp_sumpt", m_trkfastjet_truetp_sumpt);
1474 
1475       eventTree->Branch("trkjet_eta", &m_trkjet_eta);
1476       eventTree->Branch("trkjet_vz", &m_trkjet_vz);
1477       eventTree->Branch("trkjet_p", &m_trkjet_p);
1478       eventTree->Branch("trkjet_pt", &m_trkjet_pt);
1479       eventTree->Branch("trkjet_phi", &m_trkjet_phi);
1480       eventTree->Branch("trkjet_ntracks", &m_trkjet_ntracks);
1481       eventTree->Branch("trkjet_nDisplaced", &m_trkjet_nDisplaced);
1482       eventTree->Branch("trkjet_nTight", &m_trkjet_nTight);
1483       eventTree->Branch("trkjet_nTightDisplaced", &m_trkjet_nTightDisplaced);
1484 
1485       eventTree->Branch("trkjetem_eta", &m_trkjetem_eta);
1486       eventTree->Branch("trkjetem_pt", &m_trkjetem_pt);
1487       eventTree->Branch("trkjetem_phi", &m_trkjetem_phi);
1488       eventTree->Branch("trkjetem_z", &m_trkjetem_z);
1489       eventTree->Branch("trkjetem_ntracks", &m_trkjetem_ntracks);
1490       eventTree->Branch("trkjetem_nxtracks", &m_trkjetem_nxtracks);
1491     }
1492     eventTree->Branch("triplet_eta", &m_triplet_eta);
1493     eventTree->Branch("triplet_pt", &m_triplet_pt);
1494     eventTree->Branch("triplet_phi", &m_triplet_phi);
1495     eventTree->Branch("triplet_mass", &m_triplet_mass);
1496     eventTree->Branch("triplet_charge", &m_triplet_charge);
1497     eventTree->Branch("triplet_dmassmax", &m_triplet_dmassmax);
1498     eventTree->Branch("triplet_dmassmin", &m_triplet_dmassmin);
1499     eventTree->Branch("triplet_dzmax", &m_triplet_dzmax);
1500     eventTree->Branch("triplet_dzmin", &m_triplet_dzmin);
1501     eventTree->Branch("triplet_trk1pt", &m_triplet_trk1pt);
1502     eventTree->Branch("triplet_trk1eta", &m_triplet_trk1eta);
1503     eventTree->Branch("triplet_trk1phi", &m_triplet_trk1phi);
1504     eventTree->Branch("triplet_trk1z", &m_triplet_trk1z);
1505     eventTree->Branch("triplet_trk1npar", &m_triplet_trk1npar);
1506     eventTree->Branch("triplet_trk1mva", &m_triplet_trk1mva);
1507     eventTree->Branch("triplet_trk2pt", &m_triplet_trk2pt);
1508     eventTree->Branch("triplet_trk2eta", &m_triplet_trk2eta);
1509     eventTree->Branch("triplet_trk2phi", &m_triplet_trk2phi);
1510     eventTree->Branch("triplet_trk2z", &m_triplet_trk2z);
1511     eventTree->Branch("triplet_trk2npar", &m_triplet_trk2npar);
1512     eventTree->Branch("triplet_trk2mva", &m_triplet_trk2mva);
1513     eventTree->Branch("triplet_trk3pt", &m_triplet_trk3pt);
1514     eventTree->Branch("triplet_trk3eta", &m_triplet_trk3eta);
1515     eventTree->Branch("triplet_trk3phi", &m_triplet_trk3phi);
1516     eventTree->Branch("triplet_trk3z", &m_triplet_trk3z);
1517     eventTree->Branch("triplet_trk3npar", &m_triplet_trk3npar);
1518     eventTree->Branch("triplet_trk3mva", &m_triplet_trk3mva);
1519 
1520     if (Displaced == "Displaced" || Displaced == "Both") {
1521       eventTree->Branch("trkfastjetExt_eta", &m_trkfastjetExt_eta);
1522       eventTree->Branch("trkfastjetExt_vz", &m_trkfastjetExt_vz);
1523       eventTree->Branch("trkfastjetExt_p", &m_trkfastjetExt_p);
1524       eventTree->Branch("trkfastjetExt_pt", &m_trkfastjetExt_pt);
1525       eventTree->Branch("trkfastjetExt_phi", &m_trkfastjetExt_phi);
1526       eventTree->Branch("trkfastjetExt_ntracks", &m_trkfastjetExt_ntracks);
1527       eventTree->Branch("trkfastjetExt_truetp_sumpt", m_trkfastjetExt_truetp_sumpt);
1528 
1529       eventTree->Branch("trkjetExt_eta", &m_trkjetExt_eta);
1530       eventTree->Branch("trkjetExt_vz", &m_trkjetExt_vz);
1531       eventTree->Branch("trkjetExt_p", &m_trkjetExt_p);
1532       eventTree->Branch("trkjetExt_pt", &m_trkjetExt_pt);
1533       eventTree->Branch("trkjetExt_phi", &m_trkjetExt_phi);
1534       eventTree->Branch("trkjetExt_ntracks", &m_trkjetExt_ntracks);
1535       eventTree->Branch("trkjetExt_nDisplaced", &m_trkjetExt_nDisplaced);
1536       eventTree->Branch("trkjetExt_nTight", &m_trkjetExt_nTight);
1537       eventTree->Branch("trkjetExt_nTightDisplaced", &m_trkjetExt_nTightDisplaced);
1538 
1539       eventTree->Branch("trkjetemExt_eta", &m_trkjetemExt_eta);
1540       eventTree->Branch("trkjetemExt_pt", &m_trkjetemExt_pt);
1541       eventTree->Branch("trkjetemExt_phi", &m_trkjetemExt_phi);
1542       eventTree->Branch("trkjetemExt_z", &m_trkjetemExt_z);
1543       eventTree->Branch("trkjetemExt_ntracks", &m_trkjetemExt_ntracks);
1544       eventTree->Branch("trkjetemExt_nxtracks", &m_trkjetemExt_nxtracks);
1545     }
1546   }
1547 
1548   if (SaveTrackSums) {
1549     eventTree->Branch("trueMET", &trueMET, "trueMET/F");
1550     eventTree->Branch("trueTkMET", &trueTkMET, "trueTkMET/F");
1551 
1552     if (Displaced == "Prompt" || Displaced == "Both") {
1553       eventTree->Branch("trkMET", &trkMET, "trkMET/F");
1554       eventTree->Branch("trkMETPhi", &trkMETPhi, "trkMETPhi/F");
1555       eventTree->Branch("trkMETEmu", &trkMETEmu, "trkMETEmu/F");
1556       eventTree->Branch("trkMETEmuPhi", &trkMETEmuPhi, "trkMETEmuPhi/F");
1557       eventTree->Branch("trkMHT", &trkMHT, "trkMHT/F");
1558       eventTree->Branch("trkHT", &trkHT, "trkHT/F");
1559       eventTree->Branch("trkMHTEmu", &trkMHTEmu, "trkMHTEmu/F");
1560       eventTree->Branch("trkMHTEmuPhi", &trkMHTEmuPhi, "trkMHTEmuPhi/F");
1561       eventTree->Branch("trkHTEmu", &trkHTEmu, "trkHTEmu/F");
1562     }
1563     if (Displaced == "Displaced" || Displaced == "Both") {
1564       eventTree->Branch("trkMETExt", &trkMETExt, "trkMETExt/F");
1565       eventTree->Branch("trkMETPhiExt", &trkMETPhiExt, "trkMETPhiExt/F");
1566       eventTree->Branch("trkMHTExt", &trkMHTExt, "trkMHTExt/F");
1567       eventTree->Branch("trkHTExt", &trkHTExt, "trkHTExt/F");
1568       eventTree->Branch("trkMHTEmuExt", &trkMHTEmuExt, "trkMHTEmuExt/F");
1569       eventTree->Branch("trkMHTEmuPhiExt", &trkMHTEmuPhiExt, "trkMHTEmuPhiExt/F");
1570       eventTree->Branch("trkHTEmuExt", &trkHTEmuExt, "trkHTEmuExt/F");
1571     }
1572   }
1573 }
1574 
1575 //////////
1576 // ANALYZE
1577 void L1TrackObjectNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
1578   if (not available_)
1579     return;  // No ROOT file open.
1580 
1581   if (!(MyProcess == 13 || MyProcess == 11 || MyProcess == 211 || MyProcess == 6 || MyProcess == 15 ||
1582         MyProcess == 1)) {
1583     edm::LogVerbatim("Tracklet") << "The specified MyProcess is invalid! Exiting...";
1584     return;
1585   }
1586 
1587   // clear variables
1588   if (SaveAllTracks && (Displaced == "Prompt" || Displaced == "Both")) {
1589     m_trk_pt->clear();
1590     m_trk_eta->clear();
1591     m_trk_phi->clear();
1592     m_trk_phi_local->clear();
1593     m_trk_d0->clear();
1594     m_trk_z0->clear();
1595     m_trk_chi2->clear();
1596     m_trk_chi2dof->clear();
1597     m_trk_chi2rphi->clear();
1598     m_trk_chi2rz->clear();
1599     m_trk_bendchi2->clear();
1600     m_trk_MVA1->clear();
1601     m_trk_nstub->clear();
1602     m_trk_lhits->clear();
1603     m_trk_dhits->clear();
1604     m_trk_seed->clear();
1605     m_trk_hitpattern->clear();
1606     m_trk_phiSector->clear();
1607     m_trk_genuine->clear();
1608     m_trk_loose->clear();
1609     m_trk_unknown->clear();
1610     m_trk_combinatoric->clear();
1611     m_trk_fake->clear();
1612     m_trk_matchtp_pdgid->clear();
1613     m_trk_matchtp_mother_pdgid->clear();
1614 
1615     m_trk_matchtp_pt->clear();
1616     m_trk_matchtp_eta->clear();
1617     m_trk_matchtp_phi->clear();
1618     m_trk_matchtp_z0->clear();
1619     m_trk_matchtp_dxy->clear();
1620     m_trk_gtt_pt->clear();
1621     m_trk_gtt_eta->clear();
1622     m_trk_gtt_phi->clear();
1623     m_trk_selected_index->clear();
1624     m_trk_selected_emulation_index->clear();
1625     m_trk_selected_associated_index->clear();
1626     m_trk_selected_associated_emulation_index->clear();
1627     m_trk_selected_forjets_index->clear();
1628     m_trk_selected_emulation_forjets_index->clear();
1629     m_trk_selected_associated_forjets_index->clear();
1630     m_trk_selected_associated_emulation_forjets_index->clear();
1631     m_trk_selected_foretmiss_index->clear();
1632     m_trk_selected_emulation_foretmiss_index->clear();
1633     m_trk_selected_associated_foretmiss_index->clear();
1634     m_trk_selected_associated_emulation_foretmiss_index->clear();
1635   }
1636   if (SaveAllTracks && (Displaced == "Displaced" || Displaced == "Both")) {
1637     m_trkExt_pt->clear();
1638     m_trkExt_eta->clear();
1639     m_trkExt_phi->clear();
1640     m_trkExt_phi_local->clear();
1641     m_trkExt_d0->clear();
1642     m_trkExt_z0->clear();
1643     m_trkExt_chi2->clear();
1644     m_trkExt_chi2dof->clear();
1645     m_trkExt_chi2rphi->clear();
1646     m_trkExt_chi2rz->clear();
1647     m_trkExt_bendchi2->clear();
1648     m_trkExt_MVA->clear();
1649     m_trkExt_nstub->clear();
1650     m_trkExt_lhits->clear();
1651     m_trkExt_dhits->clear();
1652     m_trkExt_seed->clear();
1653     m_trkExt_hitpattern->clear();
1654     m_trkExt_phiSector->clear();
1655     m_trkExt_genuine->clear();
1656     m_trkExt_loose->clear();
1657     m_trkExt_unknown->clear();
1658     m_trkExt_combinatoric->clear();
1659     m_trkExt_fake->clear();
1660     m_trkExt_matchtp_pdgid->clear();
1661     m_trkExt_matchtp_pt->clear();
1662     m_trkExt_matchtp_eta->clear();
1663     m_trkExt_matchtp_phi->clear();
1664     m_trkExt_matchtp_z0->clear();
1665     m_trkExt_matchtp_dxy->clear();
1666     m_trkExt_gtt_pt->clear();
1667     m_trkExt_gtt_eta->clear();
1668     m_trkExt_gtt_phi->clear();
1669     m_trkExt_selected_index->clear();
1670     m_trkExt_selected_emulation_index->clear();
1671     m_trkExt_selected_associated_index->clear();
1672     m_trkExt_selected_associated_emulation_index->clear();
1673     m_trkExt_selected_forjets_index->clear();
1674     m_trkExt_selected_emulation_forjets_index->clear();
1675     m_trkExt_selected_associated_forjets_index->clear();
1676     m_trkExt_selected_associated_emulation_forjets_index->clear();
1677     m_trkExt_selected_foretmiss_index->clear();
1678     m_trkExt_selected_emulation_foretmiss_index->clear();
1679     m_trkExt_selected_associated_foretmiss_index->clear();
1680     m_trkExt_selected_associated_emulation_foretmiss_index->clear();
1681   }
1682   m_tp_pt->clear();
1683   m_tp_eta->clear();
1684   m_tp_phi->clear();
1685   m_tp_dxy->clear();
1686   m_tp_d0->clear();
1687   m_tp_z0->clear();
1688   m_tp_d0_prod->clear();
1689   m_tp_z0_prod->clear();
1690   m_tp_pdgid->clear();
1691   m_tp_nmatch->clear();
1692   m_tp_nstub->clear();
1693   m_tp_eventid->clear();
1694   m_tp_charge->clear();
1695 
1696   m_gen_pt->clear();
1697   m_gen_phi->clear();
1698   m_gen_pdgid->clear();
1699   m_gen_mother_pdgid->clear();
1700 
1701   m_gen_z0->clear();
1702 
1703   if (Displaced == "Prompt" || Displaced == "Both") {
1704     m_matchtrk_pt->clear();
1705     m_matchtrk_eta->clear();
1706     m_matchtrk_phi->clear();
1707     m_matchtrk_z0->clear();
1708     m_matchtrk_d0->clear();
1709     m_matchtrk_chi2->clear();
1710     m_matchtrk_chi2dof->clear();
1711     m_matchtrk_chi2rphi->clear();
1712     m_matchtrk_chi2rz->clear();
1713     m_matchtrk_bendchi2->clear();
1714     m_matchtrk_MVA1->clear();
1715     m_matchtrk_nstub->clear();
1716     m_matchtrk_lhits->clear();
1717     m_matchtrk_dhits->clear();
1718     m_matchtrk_seed->clear();
1719     m_matchtrk_hitpattern->clear();
1720   }
1721 
1722   if (Displaced == "Displaced" || Displaced == "Both") {
1723     m_matchtrkExt_pt->clear();
1724     m_matchtrkExt_eta->clear();
1725     m_matchtrkExt_phi->clear();
1726     m_matchtrkExt_z0->clear();
1727     m_matchtrkExt_d0->clear();
1728     m_matchtrkExt_chi2->clear();
1729     m_matchtrkExt_chi2dof->clear();
1730     m_matchtrkExt_chi2rphi->clear();
1731     m_matchtrkExt_chi2rz->clear();
1732     m_matchtrkExt_bendchi2->clear();
1733     m_matchtrkExt_MVA->clear();
1734     m_matchtrkExt_nstub->clear();
1735     m_matchtrkExt_lhits->clear();
1736     m_matchtrkExt_dhits->clear();
1737     m_matchtrkExt_seed->clear();
1738     m_matchtrkExt_hitpattern->clear();
1739   }
1740 
1741   if (SaveStubs) {
1742     m_allstub_x->clear();
1743     m_allstub_y->clear();
1744     m_allstub_z->clear();
1745     m_allstub_isBarrel->clear();
1746     m_allstub_layer->clear();
1747     m_allstub_isPSmodule->clear();
1748     m_allstub_trigDisplace->clear();
1749     m_allstub_trigOffset->clear();
1750     m_allstub_trigPos->clear();
1751     m_allstub_trigBend->clear();
1752     m_allstub_matchTP_pdgid->clear();
1753     m_allstub_matchTP_pt->clear();
1754     m_allstub_matchTP_eta->clear();
1755     m_allstub_matchTP_phi->clear();
1756     m_allstub_genuine->clear();
1757   }
1758 
1759   if (SaveTrackJets) {
1760     m_genjet_eta->clear();
1761     m_genjet_pt->clear();
1762     m_genjet_phi->clear();
1763     m_genjet_p->clear();
1764     if (Displaced == "Prompt" || Displaced == "Both") {
1765       m_trkjet_eta->clear();
1766       m_trkjet_pt->clear();
1767       m_trkjet_vz->clear();
1768       m_trkjet_phi->clear();
1769       m_trkjet_p->clear();
1770       m_trkjet_ntracks->clear();
1771       m_trkjet_nDisplaced->clear();
1772       m_trkjet_nTight->clear();
1773       m_trkjet_nTightDisplaced->clear();
1774       m_trkjet_ntdtrk->clear();
1775       m_trkfastjet_eta->clear();
1776       m_trkfastjet_pt->clear();
1777       m_trkfastjet_vz->clear();
1778       m_trkfastjet_phi->clear();
1779       m_trkfastjet_p->clear();
1780       m_trkfastjet_ntracks->clear();
1781       m_trkfastjet_truetp_sumpt->clear();
1782       m_trkfastjet_tp_sumpt->clear();
1783       m_trkjetem_eta->clear();
1784       m_trkjetem_pt->clear();
1785       m_trkjetem_phi->clear();
1786       m_trkjetem_z->clear();
1787       m_trkjetem_ntracks->clear();
1788       m_trkjetem_nxtracks->clear();
1789     }
1790     m_triplet_eta->clear();
1791     m_triplet_pt->clear();
1792     m_triplet_phi->clear();
1793     m_triplet_mass->clear();
1794     m_triplet_charge->clear();
1795     m_triplet_dmassmax->clear();
1796     m_triplet_dmassmin->clear();
1797     m_triplet_dzmax->clear();
1798     m_triplet_dzmin->clear();
1799     m_triplet_trk1pt->clear();
1800     m_triplet_trk1eta->clear();
1801     m_triplet_trk1phi->clear();
1802     m_triplet_trk1z->clear();
1803     m_triplet_trk1npar->clear();
1804     m_triplet_trk1mva->clear();
1805     m_triplet_trk2pt->clear();
1806     m_triplet_trk2eta->clear();
1807     m_triplet_trk2phi->clear();
1808     m_triplet_trk2z->clear();
1809     m_triplet_trk2npar->clear();
1810     m_triplet_trk2mva->clear();
1811     m_triplet_trk3pt->clear();
1812     m_triplet_trk3eta->clear();
1813     m_triplet_trk3phi->clear();
1814     m_triplet_trk3z->clear();
1815     m_triplet_trk3npar->clear();
1816     m_triplet_trk3mva->clear();
1817 
1818     if (Displaced == "Displaced" || Displaced == "Both") {
1819       m_trkjetExt_eta->clear();
1820       m_trkjetExt_pt->clear();
1821       m_trkjetExt_vz->clear();
1822       m_trkjetExt_phi->clear();
1823       m_trkjetExt_p->clear();
1824       m_trkjetExt_ntracks->clear();
1825       m_trkjetExt_nDisplaced->clear();
1826       m_trkjetExt_nTight->clear();
1827       m_trkjetExt_nTightDisplaced->clear();
1828       m_trkjetExt_ntdtrk->clear();
1829       m_trkfastjetExt_eta->clear();
1830       m_trkfastjetExt_pt->clear();
1831       m_trkfastjetExt_vz->clear();
1832       m_trkfastjetExt_phi->clear();
1833       m_trkfastjetExt_p->clear();
1834       m_trkfastjetExt_ntracks->clear();
1835       m_trkfastjetExt_truetp_sumpt->clear();
1836       m_trkfastjetExt_tp_sumpt->clear();
1837       m_trkjetemExt_eta->clear();
1838       m_trkjetemExt_pt->clear();
1839       m_trkjetemExt_phi->clear();
1840       m_trkjetemExt_z->clear();
1841       m_trkjetemExt_ntracks->clear();
1842       m_trkjetemExt_nxtracks->clear();
1843     }
1844   }
1845 
1846   m_pv_L1reco->clear();
1847   m_pv_L1reco_sum->clear();
1848   m_pv_L1reco_emu->clear();
1849   m_pv_L1reco_sum_emu->clear();
1850   m_pv_MC->clear();
1851   m_MC_lep->clear();
1852 
1853   // -----------------------------------------------------------------------------------------------
1854   // retrieve various containers
1855   // -----------------------------------------------------------------------------------------------
1856 
1857   // L1 stubs
1858   edm::Handle<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>> TTStubHandle;
1859   if (SaveStubs)
1860     iEvent.getByToken(ttStubToken_, TTStubHandle);
1861 
1862   // MC truth association maps
1863   edm::Handle<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>> MCTruthTTClusterHandle;
1864   iEvent.getByToken(ttClusterMCTruthToken_, MCTruthTTClusterHandle);
1865   edm::Handle<TTStubAssociationMap<Ref_Phase2TrackerDigi_>> MCTruthTTStubHandle;
1866   iEvent.getByToken(ttStubMCTruthToken_, MCTruthTTStubHandle);
1867 
1868   // tracking particles
1869   edm::Handle<std::vector<TrackingParticle>> TrackingParticleHandle;
1870   edm::Handle<std::vector<TrackingVertex>> TrackingVertexHandle;
1871   iEvent.getByToken(TrackingParticleToken_, TrackingParticleHandle);
1872   iEvent.getByToken(TrackingVertexToken_, TrackingVertexHandle);
1873 
1874   // -----------------------------------------------------------------------------------------------
1875   // more for TTStubs
1876   const TrackerTopology& tTopo = iSetup.getData(tTopoToken_);
1877   const TrackerGeometry& tGeom = iSetup.getData(tGeomToken_);
1878 
1879   //Gen particles
1880   edm::Handle<std::vector<reco::GenParticle>> GenParticleHandle;
1881   iEvent.getByToken(GenParticleToken_, GenParticleHandle);
1882   edm::Handle<std::vector<SimVertex>> SimVertexHandle;
1883   iEvent.getByToken(SimVertexToken_, SimVertexHandle);
1884   edm::Handle<std::vector<reco::GenJet>> GenJetHandle;
1885   iEvent.getByToken(GenJetToken_, GenJetHandle);
1886 
1887   //Vertex
1888   edm::Handle<l1t::VertexCollection> L1PrimaryVertexHandle;
1889   iEvent.getByToken(L1VertexToken_, L1PrimaryVertexHandle);
1890   std::vector<l1t::Vertex>::const_iterator vtxIter;
1891 
1892   edm::Handle<l1t::VertexWordCollection> L1PrimaryVertexEmuHandle;
1893   iEvent.getByToken(L1VertexEmuToken_, L1PrimaryVertexEmuHandle);
1894   std::vector<l1t::VertexWord>::const_iterator vtxEmuIter;
1895 
1896   // Track jets
1897   edm::Handle<std::vector<l1t::TkJet>> TrackFastJetsHandle;
1898   edm::Handle<std::vector<l1t::TkJet>> TrackFastJetsExtendedHandle;
1899   edm::Handle<l1t::TkJetCollection> TrackJetsHandle;
1900   edm::Handle<l1t::TkJetCollection> TrackJetsExtendedHandle;
1901   edm::Handle<l1t::TkJetWordCollection> TrackJetsEmuHandle;
1902   edm::Handle<l1t::TkJetWordCollection> TrackJetsExtendedEmuHandle;
1903   std::vector<l1t::TkJet>::const_iterator jetIter;
1904   std::vector<l1t::TkJetWord>::const_iterator jetemIter;
1905   edm::Handle<l1t::TkTripletCollection> TrackTripletsHandle;
1906   std::vector<l1t::TkTriplet>::const_iterator tripletIter;
1907 
1908   // Track Sums
1909   edm::Handle<std::vector<l1t::TkEtMiss>> L1TkMETHandle;
1910   edm::Handle<std::vector<l1t::TkEtMiss>> L1TkMETExtendedHandle;
1911   edm::Handle<std::vector<l1t::EtSum>> L1TkMETEmuHandle;
1912   edm::Handle<std::vector<l1t::TkHTMiss>> L1TkMHTHandle;
1913   edm::Handle<std::vector<l1t::TkHTMiss>> L1TkMHTExtendedHandle;
1914   edm::Handle<std::vector<l1t::EtSum>> L1TkMHTEmuHandle;
1915   edm::Handle<std::vector<l1t::EtSum>> L1TkMHTEmuExtendedHandle;
1916 
1917   // L1 tracks
1918   edm::Handle<L1TrackCollection> TTTrackHandle;
1919   edm::Handle<L1TrackCollection> TTTrackExtendedHandle;
1920   edm::Handle<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> MCTruthTTTrackHandle;
1921   edm::Handle<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> MCTruthTTTrackExtendedHandle;
1922   edm::Handle<L1TrackCollection> TTTrackGTTHandle;
1923   edm::Handle<L1TrackCollection> TTTrackExtendedGTTHandle;
1924   edm::Handle<L1TrackRefCollection> TTTrackSelectedHandle;
1925   edm::Handle<L1TrackRefCollection> TTTrackSelectedEmulationHandle;
1926   edm::Handle<L1TrackRefCollection> TTTrackSelectedAssociatedHandle;
1927   edm::Handle<L1TrackRefCollection> TTTrackSelectedAssociatedEmulationHandle;
1928   edm::Handle<L1TrackRefCollection> TTTrackSelectedForJetsHandle;
1929   edm::Handle<L1TrackRefCollection> TTTrackSelectedEmulationForJetsHandle;
1930   edm::Handle<L1TrackRefCollection> TTTrackSelectedAssociatedForJetsHandle;
1931   edm::Handle<L1TrackRefCollection> TTTrackSelectedAssociatedEmulationForJetsHandle;
1932   edm::Handle<L1TrackRefCollection> TTTrackSelectedForEtMissHandle;
1933   edm::Handle<L1TrackRefCollection> TTTrackSelectedEmulationForEtMissHandle;
1934   edm::Handle<L1TrackRefCollection> TTTrackSelectedAssociatedForEtMissHandle;
1935   edm::Handle<L1TrackRefCollection> TTTrackSelectedAssociatedEmulationForEtMissHandle;
1936   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedAssociatedHandle;
1937   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedAssociatedEmulationHandle;
1938   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedHandle;
1939   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedEmulationHandle;
1940   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedAssociatedForJetsHandle;
1941   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedAssociatedEmulationForJetsHandle;
1942   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedForJetsHandle;
1943   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedEmulationForJetsHandle;
1944   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedAssociatedForEtMissHandle;
1945   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedAssociatedEmulationForEtMissHandle;
1946   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedForEtMissHandle;
1947   edm::Handle<L1TrackRefCollection> TTTrackExtendedSelectedEmulationForEtMissHandle;
1948   L1TrackCollection::const_iterator iterL1Track;
1949 
1950   if (Displaced == "Prompt" || Displaced == "Both") {
1951     iEvent.getByToken(TrackFastJetsToken_, TrackFastJetsHandle);
1952     iEvent.getByToken(TrackJetsToken_, TrackJetsHandle);
1953     iEvent.getByToken(TrackJetsEmuToken_, TrackJetsEmuHandle);
1954     iEvent.getByToken(TrackTripletsToken_, TrackTripletsHandle);
1955     iEvent.getByToken(TrackMETToken_, L1TkMETHandle);
1956     iEvent.getByToken(TrackMETEmuToken_, L1TkMETEmuHandle);
1957     iEvent.getByToken(TrackMHTToken_, L1TkMHTHandle);
1958     iEvent.getByToken(TrackMHTEmuToken_, L1TkMHTEmuHandle);
1959     iEvent.getByToken(ttTrackToken_, TTTrackHandle);
1960     iEvent.getByToken(ttTrackMCTruthToken_, MCTruthTTTrackHandle);
1961     iEvent.getByToken(ttTrackGTTToken_, TTTrackGTTHandle);
1962     iEvent.getByToken(ttTrackSelectedToken_, TTTrackSelectedHandle);
1963     iEvent.getByToken(ttTrackSelectedEmulationToken_, TTTrackSelectedEmulationHandle);
1964     iEvent.getByToken(ttTrackSelectedAssociatedToken_, TTTrackSelectedAssociatedHandle);
1965     iEvent.getByToken(ttTrackSelectedAssociatedEmulationToken_, TTTrackSelectedAssociatedEmulationHandle);
1966     iEvent.getByToken(ttTrackSelectedForJetsToken_, TTTrackSelectedForJetsHandle);
1967     iEvent.getByToken(ttTrackSelectedEmulationForJetsToken_, TTTrackSelectedEmulationForJetsHandle);
1968     iEvent.getByToken(ttTrackSelectedAssociatedForJetsToken_, TTTrackSelectedAssociatedForJetsHandle);
1969     iEvent.getByToken(ttTrackSelectedAssociatedEmulationForJetsToken_, TTTrackSelectedAssociatedEmulationForJetsHandle);
1970     iEvent.getByToken(ttTrackSelectedForEtMissToken_, TTTrackSelectedForEtMissHandle);
1971     iEvent.getByToken(ttTrackSelectedEmulationForEtMissToken_, TTTrackSelectedEmulationForEtMissHandle);
1972     iEvent.getByToken(ttTrackSelectedAssociatedForEtMissToken_, TTTrackSelectedAssociatedForEtMissHandle);
1973     iEvent.getByToken(ttTrackSelectedAssociatedEmulationForEtMissToken_,
1974                       TTTrackSelectedAssociatedEmulationForEtMissHandle);
1975   }
1976   if (Displaced == "Displaced" || Displaced == "Both") {
1977     iEvent.getByToken(TrackFastJetsExtendedToken_, TrackFastJetsExtendedHandle);
1978     iEvent.getByToken(TrackJetsExtendedToken_, TrackJetsExtendedHandle);
1979     iEvent.getByToken(TrackJetsExtendedEmuToken_, TrackJetsExtendedEmuHandle);
1980     iEvent.getByToken(TrackMETExtendedToken_, L1TkMETExtendedHandle);
1981     iEvent.getByToken(TrackMHTExtendedToken_, L1TkMHTExtendedHandle);
1982     iEvent.getByToken(TrackMHTEmuExtendedToken_, L1TkMHTEmuExtendedHandle);
1983     iEvent.getByToken(ttTrackExtendedToken_, TTTrackExtendedHandle);
1984     iEvent.getByToken(ttTrackMCTruthExtendedToken_, MCTruthTTTrackExtendedHandle);
1985     iEvent.getByToken(ttTrackExtendedGTTToken_, TTTrackExtendedGTTHandle);
1986     iEvent.getByToken(ttTrackExtendedSelectedToken_, TTTrackExtendedSelectedHandle);
1987     iEvent.getByToken(ttTrackExtendedSelectedEmulationToken_, TTTrackExtendedSelectedEmulationHandle);
1988     iEvent.getByToken(ttTrackExtendedSelectedAssociatedToken_, TTTrackExtendedSelectedAssociatedHandle);
1989     iEvent.getByToken(ttTrackExtendedSelectedAssociatedEmulationToken_,
1990                       TTTrackExtendedSelectedAssociatedEmulationHandle);
1991     iEvent.getByToken(ttTrackExtendedSelectedForJetsToken_, TTTrackExtendedSelectedForJetsHandle);
1992     iEvent.getByToken(ttTrackExtendedSelectedEmulationForJetsToken_, TTTrackExtendedSelectedEmulationForJetsHandle);
1993     iEvent.getByToken(ttTrackExtendedSelectedAssociatedForJetsToken_, TTTrackExtendedSelectedAssociatedForJetsHandle);
1994     iEvent.getByToken(ttTrackExtendedSelectedAssociatedEmulationForJetsToken_,
1995                       TTTrackExtendedSelectedAssociatedEmulationForJetsHandle);
1996     iEvent.getByToken(ttTrackExtendedSelectedForEtMissToken_, TTTrackExtendedSelectedForEtMissHandle);
1997     iEvent.getByToken(ttTrackExtendedSelectedEmulationForEtMissToken_, TTTrackExtendedSelectedEmulationForEtMissHandle);
1998     iEvent.getByToken(ttTrackExtendedSelectedAssociatedForEtMissToken_,
1999                       TTTrackExtendedSelectedAssociatedForEtMissHandle);
2000     iEvent.getByToken(ttTrackExtendedSelectedAssociatedEmulationForEtMissToken_,
2001                       TTTrackExtendedSelectedAssociatedEmulationForEtMissHandle);
2002   }
2003 
2004   //Loop over gen particles
2005   if (GenParticleHandle.isValid()) {
2006     vector<reco::GenParticle>::const_iterator genpartIter;
2007 
2008     float zvtx_gen = -999;
2009     float trueMETx = 0;
2010     float trueMETy = 0;
2011     trueMET = 0;
2012     for (genpartIter = GenParticleHandle->begin(); genpartIter != GenParticleHandle->end(); ++genpartIter) {
2013       int status = genpartIter->status();
2014       if (status != 1)
2015         continue;
2016       zvtx_gen = genpartIter->vz();  //for gen vertex
2017       int id = genpartIter->pdgId();
2018       bool isNeutrino = false;
2019       if ((std::abs(id) == 12 || std::abs(id) == 14 || std::abs(id) == 16))
2020         isNeutrino = true;
2021       if (isNeutrino || id == 1000022) {
2022         trueMETx += genpartIter->pt() * cos(genpartIter->phi());
2023         trueMETy += genpartIter->pt() * sin(genpartIter->phi());
2024       }
2025 
2026       m_gen_pt->push_back(genpartIter->pt());
2027       m_gen_phi->push_back(genpartIter->phi());
2028       m_gen_pdgid->push_back(genpartIter->pdgId());
2029       if (genpartIter->numberOfMothers() > 0) {
2030         m_gen_mother_pdgid->push_back(genpartIter->mother(0)->pdgId());
2031       } else {
2032         m_gen_mother_pdgid->push_back(-999);
2033       }
2034 
2035       m_gen_z0->push_back(zvtx_gen);
2036     }
2037 
2038     trueMET = sqrt(trueMETx * trueMETx + trueMETy * trueMETy);
2039   } else {
2040     edm::LogWarning("DataNotFound") << "\nWarning: GenParticleHandle not found in the event" << std::endl;
2041   }
2042 
2043   if (SimVertexHandle.isValid()) {
2044     const SimVertex simPVh = *(SimVertexHandle->begin());
2045     m_pv_MC->push_back(simPVh.position().z());
2046   } else {
2047     edm::LogWarning("DataNotFound") << "\nWarning: SimVertexHandle not found in the event" << std::endl;
2048   }
2049 
2050   // ----------------------------------------------------------------------------------------------
2051   // loop over L1 stubs
2052   // ----------------------------------------------------------------------------------------------
2053   if (SaveStubs) {
2054     for (auto gd = tGeom.dets().begin(); gd != tGeom.dets().end(); gd++) {
2055       DetId detid = (*gd)->geographicalId();
2056       if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
2057         continue;
2058       if (!tTopo.isLower(detid))
2059         continue;                             // loop on the stacks: choose the lower arbitrarily
2060       DetId stackDetid = tTopo.stack(detid);  // Stub module detid
2061 
2062       if (TTStubHandle->find(stackDetid) == TTStubHandle->end())
2063         continue;
2064 
2065       // Get the DetSets of the Clusters
2066       edmNew::DetSet<TTStub<Ref_Phase2TrackerDigi_>> stubs = (*TTStubHandle)[stackDetid];
2067       const GeomDetUnit* det0 = tGeom.idToDetUnit(detid);
2068       const auto* theGeomDet = dynamic_cast<const PixelGeomDetUnit*>(det0);
2069       const PixelTopology* topol = dynamic_cast<const PixelTopology*>(&(theGeomDet->specificTopology()));
2070 
2071       // loop over stubs
2072       for (auto stubIter = stubs.begin(); stubIter != stubs.end(); ++stubIter) {
2073         edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>> tempStubPtr =
2074             edmNew::makeRefTo(TTStubHandle, stubIter);
2075 
2076         int isBarrel = 0;
2077         int layer = -999999;
2078         if (detid.subdetId() == StripSubdetector::TOB) {
2079           isBarrel = 1;
2080           layer = static_cast<int>(tTopo.layer(detid));
2081         } else if (detid.subdetId() == StripSubdetector::TID) {
2082           isBarrel = 0;
2083           layer = static_cast<int>(tTopo.layer(detid));
2084         } else {
2085           edm::LogVerbatim("Tracklet") << "WARNING -- neither TOB or TID stub, shouldn't happen...";
2086           layer = -1;
2087         }
2088 
2089         int isPSmodule = 0;
2090         if (topol->nrows() == 960)
2091           isPSmodule = 1;
2092 
2093         MeasurementPoint coords = tempStubPtr->clusterRef(0)->findAverageLocalCoordinatesCentered();
2094         LocalPoint clustlp = topol->localPosition(coords);
2095         GlobalPoint posStub = theGeomDet->surface().toGlobal(clustlp);
2096 
2097         double tmp_stub_x = posStub.x();
2098         double tmp_stub_y = posStub.y();
2099         double tmp_stub_z = posStub.z();
2100 
2101         float trigDisplace = tempStubPtr->rawBend();
2102         float trigOffset = tempStubPtr->bendOffset();
2103         float trigPos = tempStubPtr->innerClusterPosition();
2104         float trigBend = tempStubPtr->bendFE();
2105 
2106         m_allstub_x->push_back(tmp_stub_x);
2107         m_allstub_y->push_back(tmp_stub_y);
2108         m_allstub_z->push_back(tmp_stub_z);
2109         m_allstub_isBarrel->push_back(isBarrel);
2110         m_allstub_layer->push_back(layer);
2111         m_allstub_isPSmodule->push_back(isPSmodule);
2112         m_allstub_trigDisplace->push_back(trigDisplace);
2113         m_allstub_trigOffset->push_back(trigOffset);
2114         m_allstub_trigPos->push_back(trigPos);
2115         m_allstub_trigBend->push_back(trigBend);
2116 
2117         // matched to tracking particle?
2118         edm::Ptr<TrackingParticle> my_tp = MCTruthTTStubHandle->findTrackingParticlePtr(tempStubPtr);
2119 
2120         int myTP_pdgid = -999;
2121         float myTP_pt = -999;
2122         float myTP_eta = -999;
2123         float myTP_phi = -999;
2124 
2125         if (my_tp.isNull() == false) {
2126           int tmp_eventid = my_tp->eventId().event();
2127           if (tmp_eventid > 0)
2128             continue;  // this means stub from pileup track
2129           myTP_pdgid = my_tp->pdgId();
2130           myTP_pt = my_tp->p4().pt();
2131           myTP_eta = my_tp->p4().eta();
2132           myTP_phi = my_tp->p4().phi();
2133         }
2134         int tmp_stub_genuine = 0;
2135         if (MCTruthTTStubHandle->isGenuine(tempStubPtr))
2136           tmp_stub_genuine = 1;
2137 
2138         m_allstub_matchTP_pdgid->push_back(myTP_pdgid);
2139         m_allstub_matchTP_pt->push_back(myTP_pt);
2140         m_allstub_matchTP_eta->push_back(myTP_eta);
2141         m_allstub_matchTP_phi->push_back(myTP_phi);
2142         m_allstub_genuine->push_back(tmp_stub_genuine);
2143       }
2144     }
2145   }
2146 
2147   // ----------------------------------------------------------------------------------------------
2148   // loop over (prompt) L1 tracks
2149   // ----------------------------------------------------------------------------------------------
2150   if (SaveAllTracks && (Displaced == "Prompt" || Displaced == "Both")) {
2151     if (DebugMode) {
2152       edm::LogVerbatim("Tracklet") << "\n Loop over L1 tracks!";
2153       edm::LogVerbatim("Tracklet") << "\n Looking at " << Displaced << " tracks!";
2154     }
2155 
2156     int this_l1track = 0;
2157     for (iterL1Track = TTTrackHandle->begin(); iterL1Track != TTTrackHandle->end(); iterL1Track++) {
2158       L1TrackPtr l1track_ptr(TTTrackHandle, this_l1track);
2159       L1TrackRef l1track_ref(TTTrackGTTHandle, this_l1track);
2160 
2161       float tmp_trk_pt = iterL1Track->momentum().perp();
2162       float tmp_trk_eta = iterL1Track->momentum().eta();
2163       float tmp_trk_phi = iterL1Track->momentum().phi();
2164       float tmp_trk_phi_local = iterL1Track->localPhi();
2165       float tmp_trk_z0 = iterL1Track->z0();            //cm
2166       int tmp_trk_nFitPars = iterL1Track->nFitPars();  //4 or 5
2167 
2168       float tmp_trk_d0 = -999;
2169       if (tmp_trk_nFitPars == 5) {
2170         float tmp_trk_x0 = iterL1Track->POCA().x();
2171         float tmp_trk_y0 = iterL1Track->POCA().y();
2172         tmp_trk_d0 = -tmp_trk_x0 * sin(tmp_trk_phi) + tmp_trk_y0 * cos(tmp_trk_phi);
2173         // tmp_trk_d0 = iterL1Track->d0();
2174       }
2175 
2176       float tmp_trk_chi2 = iterL1Track->chi2();
2177       float tmp_trk_chi2dof = iterL1Track->chi2Red();
2178       float tmp_trk_chi2rphi = iterL1Track->chi2XYRed();
2179       float tmp_trk_chi2rz = iterL1Track->chi2ZRed();
2180       float tmp_trk_bendchi2 = iterL1Track->stubPtConsistency();
2181       float tmp_trk_MVA1 = iterL1Track->trkMVA1();
2182 
2183       std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
2184           stubRefs = iterL1Track->getStubRefs();
2185       int tmp_trk_nstub = (int)stubRefs.size();
2186       int tmp_trk_seed = 0;
2187       tmp_trk_seed = (int)iterL1Track->trackSeedType();
2188       int tmp_trk_hitpattern = 0;
2189       tmp_trk_hitpattern = (int)iterL1Track->hitPattern();
2190       unsigned int tmp_trk_phiSector = iterL1Track->phiSector();
2191 
2192       // ----------------------------------------------------------------------------------------------
2193       // loop over stubs on tracks
2194       int tmp_trk_dhits = 0;
2195       int tmp_trk_lhits = 0;
2196       if (true) {
2197         // loop over stubs
2198         for (int is = 0; is < tmp_trk_nstub; is++) {
2199           //detID of stub
2200           DetId detIdStub = tGeom.idToDet((stubRefs.at(is)->clusterRef(0))->getDetId())->geographicalId();
2201           MeasurementPoint coords = stubRefs.at(is)->clusterRef(0)->findAverageLocalCoordinatesCentered();
2202           const GeomDet* theGeomDet = tGeom.idToDet(detIdStub);
2203           Global3DPoint posStub = theGeomDet->surface().toGlobal(theGeomDet->topology().localPosition(coords));
2204 
2205           double x = posStub.x();
2206           double y = posStub.y();
2207           double z = posStub.z();
2208 
2209           int layer = -999999;
2210           if (detIdStub.subdetId() == StripSubdetector::TOB) {
2211             layer = static_cast<int>(tTopo.layer(detIdStub));
2212             if (DebugMode)
2213               edm::LogVerbatim("Tracklet")
2214                   << "   stub in layer " << layer << " at position x y z = " << x << " " << y << " " << z;
2215             tmp_trk_lhits += pow(10, layer - 1);
2216           } else if (detIdStub.subdetId() == StripSubdetector::TID) {
2217             layer = static_cast<int>(tTopo.layer(detIdStub));
2218             if (DebugMode)
2219               edm::LogVerbatim("Tracklet")
2220                   << "   stub in disk " << layer << " at position x y z = " << x << " " << y << " " << z;
2221             tmp_trk_dhits += pow(10, layer - 1);
2222           }
2223         }  //end loop over stubs
2224       }
2225       // ----------------------------------------------------------------------------------------------
2226 
2227       int tmp_trk_genuine = 0;
2228       int tmp_trk_loose = 0;
2229       int tmp_trk_unknown = 0;
2230       int tmp_trk_combinatoric = 0;
2231       if (MCTruthTTTrackHandle->isLooselyGenuine(l1track_ptr))
2232         tmp_trk_loose = 1;
2233       if (MCTruthTTTrackHandle->isGenuine(l1track_ptr))
2234         tmp_trk_genuine = 1;
2235       if (MCTruthTTTrackHandle->isUnknown(l1track_ptr))
2236         tmp_trk_unknown = 1;
2237       if (MCTruthTTTrackHandle->isCombinatoric(l1track_ptr))
2238         tmp_trk_combinatoric = 1;
2239 
2240       if (DebugMode) {
2241         edm::LogVerbatim("Tracklet") << "L1 track,"
2242                                      << " pt: " << tmp_trk_pt << " eta: " << tmp_trk_eta << " phi: " << tmp_trk_phi
2243                                      << " z0: " << tmp_trk_z0 << " chi2: " << tmp_trk_chi2
2244                                      << " chi2rphi: " << tmp_trk_chi2rphi << " chi2rz: " << tmp_trk_chi2rz
2245                                      << " nstub: " << tmp_trk_nstub;
2246         if (tmp_trk_genuine)
2247           edm::LogVerbatim("Tracklet") << "    (is genuine)";
2248         if (tmp_trk_unknown)
2249           edm::LogVerbatim("Tracklet") << "    (is unknown)";
2250         if (tmp_trk_combinatoric)
2251           edm::LogVerbatim("Tracklet") << "    (is combinatoric)";
2252       }
2253 
2254       m_trk_pt->push_back(tmp_trk_pt);
2255       m_trk_eta->push_back(tmp_trk_eta);
2256       m_trk_phi->push_back(tmp_trk_phi);
2257       m_trk_phi_local->push_back(tmp_trk_phi_local);
2258       m_trk_z0->push_back(tmp_trk_z0);
2259       if (tmp_trk_nFitPars == 5)
2260         m_trk_d0->push_back(tmp_trk_d0);
2261       else
2262         m_trk_d0->push_back(999.);
2263       m_trk_chi2->push_back(tmp_trk_chi2);
2264       m_trk_chi2dof->push_back(tmp_trk_chi2dof);
2265       m_trk_chi2rphi->push_back(tmp_trk_chi2rphi);
2266       m_trk_chi2rz->push_back(tmp_trk_chi2rz);
2267       m_trk_bendchi2->push_back(tmp_trk_bendchi2);
2268       m_trk_MVA1->push_back(tmp_trk_MVA1);
2269       m_trk_nstub->push_back(tmp_trk_nstub);
2270       m_trk_dhits->push_back(tmp_trk_dhits);
2271       m_trk_lhits->push_back(tmp_trk_lhits);
2272       m_trk_seed->push_back(tmp_trk_seed);
2273       m_trk_hitpattern->push_back(tmp_trk_hitpattern);
2274       m_trk_phiSector->push_back(tmp_trk_phiSector);
2275       m_trk_genuine->push_back(tmp_trk_genuine);
2276       m_trk_loose->push_back(tmp_trk_loose);
2277       m_trk_unknown->push_back(tmp_trk_unknown);
2278       m_trk_combinatoric->push_back(tmp_trk_combinatoric);
2279 
2280       // ----------------------------------------------------------------------------------------------
2281       // for studying the fake rate
2282       // ----------------------------------------------------------------------------------------------
2283       edm::Ptr<TrackingParticle> my_tp = MCTruthTTTrackHandle->findTrackingParticlePtr(l1track_ptr);
2284 
2285       int myFake = 0;
2286       int myTP_pdgid = -999;
2287       int myTP_mother_pdgid = -999;
2288 
2289       float myTP_pt = -999;
2290       float myTP_eta = -999;
2291       float myTP_phi = -999;
2292       float myTP_z0 = -999;
2293       float myTP_dxy = -999;
2294 
2295       if (my_tp.isNull())
2296         myFake = 0;
2297       else {
2298         int tmp_eventid = my_tp->eventId().event();
2299         if (tmp_eventid > 0)
2300           myFake = 2;
2301         else
2302           myFake = 1;
2303 
2304         myTP_pdgid = my_tp->pdgId();
2305         if (my_tp->genParticles().size() > 0) {
2306           myTP_mother_pdgid = my_tp->genParticles().at(0)->mother(0)->pdgId();
2307         }
2308         myTP_pt = my_tp->p4().pt();
2309         myTP_eta = my_tp->p4().eta();
2310         myTP_phi = my_tp->p4().phi();
2311         myTP_z0 = my_tp->vertex().z();
2312 
2313         float myTP_x0 = my_tp->vertex().x();
2314         float myTP_y0 = my_tp->vertex().y();
2315         myTP_dxy = sqrt(myTP_x0 * myTP_x0 + myTP_y0 * myTP_y0);
2316 
2317         if (DebugMode) {
2318           edm::LogVerbatim("Tracklet") << "TP matched to track has pt = " << my_tp->p4().pt()
2319                                        << " eta = " << my_tp->momentum().eta() << " phi = " << my_tp->momentum().phi()
2320                                        << " z0 = " << my_tp->vertex().z() << " pdgid = " << my_tp->pdgId()
2321                                        << " dxy = " << myTP_dxy;
2322         }
2323       }
2324 
2325       m_trk_fake->push_back(myFake);
2326       m_trk_matchtp_pdgid->push_back(myTP_pdgid);
2327       m_trk_matchtp_mother_pdgid->push_back(myTP_mother_pdgid);
2328 
2329       m_trk_matchtp_pt->push_back(myTP_pt);
2330       m_trk_matchtp_eta->push_back(myTP_eta);
2331       m_trk_matchtp_phi->push_back(myTP_phi);
2332       m_trk_matchtp_z0->push_back(myTP_z0);
2333       m_trk_matchtp_dxy->push_back(myTP_dxy);
2334 
2335       // ----------------------------------------------------------------------------------------------
2336       // store the index to the selected track or -1 if not selected
2337       // ----------------------------------------------------------------------------------------------
2338       m_trk_gtt_pt->push_back(l1track_ref->momentum().perp());
2339       m_trk_gtt_eta->push_back(l1track_ref->momentum().eta());
2340       m_trk_gtt_phi->push_back(l1track_ref->momentum().phi());
2341       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedHandle) >= 0)
2342         m_trk_selected_index->push_back(this_l1track);
2343       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedEmulationHandle) >= 0)
2344         m_trk_selected_emulation_index->push_back(this_l1track);
2345       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedAssociatedHandle) >= 0)
2346         m_trk_selected_associated_index->push_back(this_l1track);
2347       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedAssociatedEmulationHandle) >= 0)
2348         m_trk_selected_associated_emulation_index->push_back(this_l1track);
2349       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedForJetsHandle) >= 0)
2350         m_trk_selected_forjets_index->push_back(this_l1track);
2351       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedEmulationForJetsHandle) >= 0)
2352         m_trk_selected_emulation_forjets_index->push_back(this_l1track);
2353       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedAssociatedForJetsHandle) >= 0)
2354         m_trk_selected_associated_forjets_index->push_back(this_l1track);
2355       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedAssociatedEmulationForJetsHandle) >= 0)
2356         m_trk_selected_associated_emulation_forjets_index->push_back(this_l1track);
2357       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedForEtMissHandle) >= 0)
2358         m_trk_selected_foretmiss_index->push_back(this_l1track);
2359       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedEmulationForEtMissHandle) >= 0)
2360         m_trk_selected_emulation_foretmiss_index->push_back(this_l1track);
2361       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedAssociatedForEtMissHandle) >= 0)
2362         m_trk_selected_associated_foretmiss_index->push_back(this_l1track);
2363       if (getSelectedTrackIndex(l1track_ref, TTTrackSelectedAssociatedEmulationForEtMissHandle) >= 0)
2364         m_trk_selected_associated_emulation_foretmiss_index->push_back(this_l1track);
2365 
2366       this_l1track++;
2367     }  //end track loop
2368   }    //end if SaveAllTracks
2369 
2370   // ----------------------------------------------------------------------------------------------
2371   // loop over (extended) L1 tracks
2372   // ----------------------------------------------------------------------------------------------
2373   if (SaveAllTracks && (Displaced == "Displaced" || Displaced == "Both")) {
2374     if (DebugMode) {
2375       edm::LogVerbatim("Tracklet") << "\n Loop over L1 tracks!";
2376       edm::LogVerbatim("Tracklet") << "\n Looking at " << Displaced << " tracks!";
2377     }
2378 
2379     int this_l1track = 0;
2380     for (iterL1Track = TTTrackExtendedHandle->begin(); iterL1Track != TTTrackExtendedHandle->end(); iterL1Track++) {
2381       L1TrackPtr l1track_ptr(TTTrackExtendedHandle, this_l1track);
2382       L1TrackRef l1track_ref(TTTrackExtendedGTTHandle, this_l1track);
2383 
2384       float tmp_trk_pt = iterL1Track->momentum().perp();
2385       float tmp_trk_eta = iterL1Track->momentum().eta();
2386       float tmp_trk_phi = iterL1Track->momentum().phi();
2387       float tmp_trk_phi_local = iterL1Track->localPhi();
2388       float tmp_trk_z0 = iterL1Track->z0();            //cm
2389       int tmp_trk_nFitPars = iterL1Track->nFitPars();  //4 or 5
2390 
2391       float tmp_trk_d0 = -999;
2392       if (tmp_trk_nFitPars == 5) {
2393         float tmp_trk_x0 = iterL1Track->POCA().x();
2394         float tmp_trk_y0 = iterL1Track->POCA().y();
2395         tmp_trk_d0 = -tmp_trk_x0 * sin(tmp_trk_phi) + tmp_trk_y0 * cos(tmp_trk_phi);
2396         // tmp_trk_d0 = iterL1Track->d0();
2397       }
2398 
2399       float tmp_trk_chi2 = iterL1Track->chi2();
2400       float tmp_trk_chi2dof = iterL1Track->chi2Red();
2401       float tmp_trk_chi2rphi = iterL1Track->chi2XYRed();
2402       float tmp_trk_chi2rz = iterL1Track->chi2ZRed();
2403       float tmp_trk_bendchi2 = iterL1Track->stubPtConsistency();
2404       float tmp_trk_MVA1 = iterL1Track->trkMVA1();
2405 
2406       std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
2407           stubRefs = iterL1Track->getStubRefs();
2408       int tmp_trk_nstub = (int)stubRefs.size();
2409       int tmp_trk_seed = 0;
2410       tmp_trk_seed = (int)iterL1Track->trackSeedType();
2411       int tmp_trk_hitpattern = 0;
2412       tmp_trk_hitpattern = (int)iterL1Track->hitPattern();
2413       unsigned int tmp_trk_phiSector = iterL1Track->phiSector();
2414 
2415       // ----------------------------------------------------------------------------------------------
2416       // loop over stubs on tracks
2417       int tmp_trk_dhits = 0;
2418       int tmp_trk_lhits = 0;
2419       if (true) {
2420         // loop over stubs
2421         for (int is = 0; is < tmp_trk_nstub; is++) {
2422           //detID of stub
2423           DetId detIdStub = tGeom.idToDet((stubRefs.at(is)->clusterRef(0))->getDetId())->geographicalId();
2424           MeasurementPoint coords = stubRefs.at(is)->clusterRef(0)->findAverageLocalCoordinatesCentered();
2425           const GeomDet* theGeomDet = tGeom.idToDet(detIdStub);
2426           Global3DPoint posStub = theGeomDet->surface().toGlobal(theGeomDet->topology().localPosition(coords));
2427 
2428           double x = posStub.x();
2429           double y = posStub.y();
2430           double z = posStub.z();
2431 
2432           int layer = -999999;
2433           if (detIdStub.subdetId() == StripSubdetector::TOB) {
2434             layer = static_cast<int>(tTopo.layer(detIdStub));
2435             if (DebugMode)
2436               edm::LogVerbatim("Tracklet")
2437                   << "   stub in layer " << layer << " at position x y z = " << x << " " << y << " " << z;
2438             tmp_trk_lhits += pow(10, layer - 1);
2439           } else if (detIdStub.subdetId() == StripSubdetector::TID) {
2440             layer = static_cast<int>(tTopo.layer(detIdStub));
2441             if (DebugMode)
2442               edm::LogVerbatim("Tracklet")
2443                   << "   stub in disk " << layer << " at position x y z = " << x << " " << y << " " << z;
2444             tmp_trk_dhits += pow(10, layer - 1);
2445           }
2446         }  //end loop over stubs
2447       }
2448       // ----------------------------------------------------------------------------------------------
2449 
2450       int tmp_trk_genuine = 0;
2451       int tmp_trk_loose = 0;
2452       int tmp_trk_unknown = 0;
2453       int tmp_trk_combinatoric = 0;
2454       if (MCTruthTTTrackExtendedHandle->isLooselyGenuine(l1track_ptr))
2455         tmp_trk_loose = 1;
2456       if (MCTruthTTTrackExtendedHandle->isGenuine(l1track_ptr))
2457         tmp_trk_genuine = 1;
2458       if (MCTruthTTTrackExtendedHandle->isUnknown(l1track_ptr))
2459         tmp_trk_unknown = 1;
2460       if (MCTruthTTTrackExtendedHandle->isCombinatoric(l1track_ptr))
2461         tmp_trk_combinatoric = 1;
2462 
2463       if (DebugMode) {
2464         edm::LogVerbatim("Tracklet") << "L1 track,"
2465                                      << " pt: " << tmp_trk_pt << " eta: " << tmp_trk_eta << " phi: " << tmp_trk_phi
2466                                      << " z0: " << tmp_trk_z0 << " chi2: " << tmp_trk_chi2
2467                                      << " chi2rphi: " << tmp_trk_chi2rphi << " chi2rz: " << tmp_trk_chi2rz
2468                                      << " nstub: " << tmp_trk_nstub;
2469         if (tmp_trk_genuine)
2470           edm::LogVerbatim("Tracklet") << "    (is genuine)";
2471         if (tmp_trk_unknown)
2472           edm::LogVerbatim("Tracklet") << "    (is unknown)";
2473         if (tmp_trk_combinatoric)
2474           edm::LogVerbatim("Tracklet") << "    (is combinatoric)";
2475       }
2476 
2477       m_trkExt_pt->push_back(tmp_trk_pt);
2478       m_trkExt_eta->push_back(tmp_trk_eta);
2479       m_trkExt_phi->push_back(tmp_trk_phi);
2480       m_trkExt_phi_local->push_back(tmp_trk_phi_local);
2481       m_trkExt_z0->push_back(tmp_trk_z0);
2482       if (tmp_trk_nFitPars == 5)
2483         m_trkExt_d0->push_back(tmp_trk_d0);
2484       else
2485         m_trkExt_d0->push_back(999.);
2486       m_trkExt_chi2->push_back(tmp_trk_chi2);
2487       m_trkExt_chi2dof->push_back(tmp_trk_chi2dof);
2488       m_trkExt_chi2rphi->push_back(tmp_trk_chi2rphi);
2489       m_trkExt_chi2rz->push_back(tmp_trk_chi2rz);
2490       m_trkExt_bendchi2->push_back(tmp_trk_bendchi2);
2491       m_trkExt_MVA->push_back(tmp_trk_MVA1);
2492       m_trkExt_nstub->push_back(tmp_trk_nstub);
2493       m_trkExt_dhits->push_back(tmp_trk_dhits);
2494       m_trkExt_lhits->push_back(tmp_trk_lhits);
2495       m_trkExt_seed->push_back(tmp_trk_seed);
2496       m_trkExt_hitpattern->push_back(tmp_trk_hitpattern);
2497       m_trkExt_phiSector->push_back(tmp_trk_phiSector);
2498       m_trkExt_genuine->push_back(tmp_trk_genuine);
2499       m_trkExt_loose->push_back(tmp_trk_loose);
2500       m_trkExt_unknown->push_back(tmp_trk_unknown);
2501       m_trkExt_combinatoric->push_back(tmp_trk_combinatoric);
2502 
2503       // ----------------------------------------------------------------------------------------------
2504       // for studying the fake rate
2505       // ----------------------------------------------------------------------------------------------
2506       edm::Ptr<TrackingParticle> my_tp = MCTruthTTTrackExtendedHandle->findTrackingParticlePtr(l1track_ptr);
2507 
2508       int myFake = 0;
2509       int myTP_pdgid = -999;
2510       float myTP_pt = -999;
2511       float myTP_eta = -999;
2512       float myTP_phi = -999;
2513       float myTP_z0 = -999;
2514       float myTP_dxy = -999;
2515 
2516       if (my_tp.isNull())
2517         myFake = 0;
2518       else {
2519         int tmp_eventid = my_tp->eventId().event();
2520         if (tmp_eventid > 0)
2521           myFake = 2;
2522         else
2523           myFake = 1;
2524 
2525         myTP_pdgid = my_tp->pdgId();
2526         myTP_pt = my_tp->p4().pt();
2527         myTP_eta = my_tp->p4().eta();
2528         myTP_phi = my_tp->p4().phi();
2529         myTP_z0 = my_tp->vertex().z();
2530 
2531         float myTP_x0 = my_tp->vertex().x();
2532         float myTP_y0 = my_tp->vertex().y();
2533         myTP_dxy = sqrt(myTP_x0 * myTP_x0 + myTP_y0 * myTP_y0);
2534 
2535         if (DebugMode) {
2536           edm::LogVerbatim("Tracklet") << "TP matched to track has pt = " << my_tp->p4().pt()
2537                                        << " eta = " << my_tp->momentum().eta() << " phi = " << my_tp->momentum().phi()
2538                                        << " z0 = " << my_tp->vertex().z() << " pdgid = " << my_tp->pdgId()
2539                                        << " dxy = " << myTP_dxy;
2540         }
2541       }
2542 
2543       m_trkExt_fake->push_back(myFake);
2544       m_trkExt_matchtp_pdgid->push_back(myTP_pdgid);
2545       m_trkExt_matchtp_pt->push_back(myTP_pt);
2546       m_trkExt_matchtp_eta->push_back(myTP_eta);
2547       m_trkExt_matchtp_phi->push_back(myTP_phi);
2548       m_trkExt_matchtp_z0->push_back(myTP_z0);
2549       m_trkExt_matchtp_dxy->push_back(myTP_dxy);
2550 
2551       // ----------------------------------------------------------------------------------------------
2552       // store the index to the selected track or -1 if not selected
2553       // ----------------------------------------------------------------------------------------------
2554       m_trkExt_gtt_pt->push_back(l1track_ref->momentum().perp());
2555       m_trkExt_gtt_eta->push_back(l1track_ref->momentum().eta());
2556       m_trkExt_gtt_phi->push_back(l1track_ref->momentum().phi());
2557       m_trkExt_selected_index->push_back(getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedHandle));
2558       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedEmulationHandle) >= 0)
2559         m_trkExt_selected_emulation_index->push_back(this_l1track);
2560       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedAssociatedHandle) >= 0)
2561         m_trkExt_selected_associated_index->push_back(this_l1track);
2562       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedAssociatedEmulationHandle) >= 0)
2563         m_trkExt_selected_associated_emulation_index->push_back(this_l1track);
2564       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedForJetsHandle) >= 0)
2565         m_trkExt_selected_forjets_index->push_back(this_l1track);
2566       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedEmulationForJetsHandle) >= 0)
2567         m_trkExt_selected_emulation_forjets_index->push_back(this_l1track);
2568       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedAssociatedForJetsHandle) >= 0)
2569         m_trkExt_selected_associated_forjets_index->push_back(this_l1track);
2570       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedAssociatedEmulationForJetsHandle) >= 0)
2571         m_trkExt_selected_associated_emulation_forjets_index->push_back(this_l1track);
2572       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedForEtMissHandle) >= 0)
2573         m_trkExt_selected_foretmiss_index->push_back(this_l1track);
2574       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedEmulationForEtMissHandle) >= 0)
2575         m_trkExt_selected_emulation_foretmiss_index->push_back(this_l1track);
2576       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedAssociatedForEtMissHandle) >= 0)
2577         m_trkExt_selected_associated_foretmiss_index->push_back(this_l1track);
2578       if (getSelectedTrackIndex(l1track_ref, TTTrackExtendedSelectedAssociatedEmulationForEtMissHandle) >= 0)
2579         m_trkExt_selected_associated_emulation_foretmiss_index->push_back(this_l1track);
2580       this_l1track++;
2581     }  //end track loop
2582   }    //end if SaveAllTracks (displaced)
2583 
2584   // ----------------------------------------------------------------------------------------------
2585   // loop over tracking particles
2586   // ----------------------------------------------------------------------------------------------
2587   if (DebugMode)
2588     edm::LogVerbatim("Tracklet") << "\n Loop over tracking particles!";
2589 
2590   trueTkMET = 0;
2591   float trueTkMETx = 0;
2592   float trueTkMETy = 0;
2593 
2594   int this_tp = 0;
2595   std::vector<TrackingParticle>::const_iterator iterTP;
2596   for (iterTP = TrackingParticleHandle->begin(); iterTP != TrackingParticleHandle->end(); ++iterTP) {
2597     edm::Ptr<TrackingParticle> tp_ptr(TrackingParticleHandle, this_tp);
2598     this_tp++;
2599 
2600     int tmp_eventid = iterTP->eventId().event();
2601     if (MyProcess != 1 && tmp_eventid > 0)
2602       continue;  //only care about primary interaction
2603 
2604     float tmp_tp_pt = iterTP->pt();
2605     float tmp_tp_eta = iterTP->eta();
2606     float tmp_tp_phi = iterTP->phi();
2607     float tmp_tp_vz = iterTP->vz();
2608     float tmp_tp_vx = iterTP->vx();
2609     float tmp_tp_vy = iterTP->vy();
2610     int tmp_tp_pdgid = iterTP->pdgId();
2611     float tmp_tp_z0_prod = tmp_tp_vz;
2612     float tmp_tp_d0_prod = tmp_tp_vx * sin(tmp_tp_phi) - tmp_tp_vy * cos(tmp_tp_phi);
2613 
2614     if (MyProcess == 13 && abs(tmp_tp_pdgid) != 13)
2615       continue;
2616     if (MyProcess == 11 && abs(tmp_tp_pdgid) != 11)
2617       continue;
2618     if ((MyProcess == 6 || MyProcess == 15 || MyProcess == 211) && abs(tmp_tp_pdgid) != 211)
2619       continue;
2620 
2621     if (tmp_tp_pt < TP_minPt)
2622       continue;
2623     if (std::abs(tmp_tp_eta) > TP_maxEta)
2624       continue;
2625 
2626     // ----------------------------------------------------------------------------------------------
2627     // get d0/z0 propagated back to the IP
2628     float tmp_tp_t = tan(2.0 * atan(1.0) - 2.0 * atan(exp(-tmp_tp_eta)));
2629     float delx = -tmp_tp_vx;
2630     float dely = -tmp_tp_vy;
2631 
2632     float A = 0.01 * 0.5696;
2633     float Kmagnitude = A / tmp_tp_pt;
2634     float tmp_tp_charge = tp_ptr->charge();
2635     float K = Kmagnitude * tmp_tp_charge;
2636     float d = 0;
2637     float tmp_tp_x0p = delx - (d + 1. / (2. * K) * sin(tmp_tp_phi));
2638     float tmp_tp_y0p = dely + (d + 1. / (2. * K) * cos(tmp_tp_phi));
2639     float tmp_tp_rp = sqrt(tmp_tp_x0p * tmp_tp_x0p + tmp_tp_y0p * tmp_tp_y0p);
2640     float tmp_tp_d0 = tmp_tp_charge * tmp_tp_rp - (1. / (2. * K));
2641     tmp_tp_d0 = tmp_tp_d0 * (-1);  //fix d0 sign
2642     const double pi = 4.0 * atan(1.0);
2643     float delphi = tmp_tp_phi - atan2(-K * tmp_tp_x0p, K * tmp_tp_y0p);
2644     if (delphi < -pi)
2645       delphi += 2.0 * pi;
2646     if (delphi > pi)
2647       delphi -= 2.0 * pi;
2648     float tmp_tp_z0 = tmp_tp_vz + tmp_tp_t * delphi / (2.0 * K);
2649     // ----------------------------------------------------------------------------------------------
2650 
2651     if (std::abs(tmp_tp_z0) > TP_maxZ0)
2652       continue;
2653 
2654     // for pions in ttbar, only consider TPs coming from near the IP!
2655     float dxy = sqrt(tmp_tp_vx * tmp_tp_vx + tmp_tp_vy * tmp_tp_vy);
2656     float tmp_tp_dxy = dxy;
2657     if (MyProcess == 6 && (dxy > 1.0))
2658       continue;
2659 
2660     if (DebugMode && (Displaced == "Prompt" || Displaced == "Both"))
2661       edm::LogVerbatim("Tracklet") << "Tracking particle, pt: " << tmp_tp_pt << " eta: " << tmp_tp_eta
2662                                    << " phi: " << tmp_tp_phi << " z0: " << tmp_tp_z0 << " d0: " << tmp_tp_d0
2663                                    << " z_prod: " << tmp_tp_z0_prod << " d_prod: " << tmp_tp_d0_prod
2664                                    << " pdgid: " << tmp_tp_pdgid << " eventID: " << iterTP->eventId().event()
2665                                    << " ttclusters " << MCTruthTTClusterHandle->findTTClusterRefs(tp_ptr).size()
2666                                    << " ttstubs " << MCTruthTTStubHandle->findTTStubRefs(tp_ptr).size() << " tttracks "
2667                                    << MCTruthTTTrackHandle->findTTTrackPtrs(tp_ptr).size();
2668 
2669     // ----------------------------------------------------------------------------------------------
2670     // only consider TPs associated with >= 1 cluster, or >= X stubs, or have stubs in >= X layers (configurable options)
2671     if (MCTruthTTClusterHandle->findTTClusterRefs(tp_ptr).empty()) {
2672       if (DebugMode)
2673         edm::LogVerbatim("Tracklet") << "No matching TTClusters for TP, continuing...";
2674       continue;
2675     }
2676 
2677     std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
2678         theStubRefs = MCTruthTTStubHandle->findTTStubRefs(tp_ptr);
2679     int nStubTP = (int)theStubRefs.size();
2680 
2681     // how many layers/disks have stubs?
2682     int hasStubInLayer[11] = {0};
2683     for (auto& theStubRef : theStubRefs) {
2684       DetId detid(theStubRef->getDetId());
2685 
2686       int layer = -1;
2687       if (detid.subdetId() == StripSubdetector::TOB) {
2688         layer = static_cast<int>(tTopo.layer(detid)) - 1;  //fill in array as entries 0-5
2689       } else if (detid.subdetId() == StripSubdetector::TID) {
2690         layer = static_cast<int>(tTopo.layer(detid)) + 5;  //fill in array as entries 6-10
2691       }
2692 
2693       //treat genuine stubs separately (==2 is genuine, ==1 is not)
2694       if (MCTruthTTStubHandle->findTrackingParticlePtr(theStubRef).isNull() && hasStubInLayer[layer] < 2)
2695         hasStubInLayer[layer] = 1;
2696       else
2697         hasStubInLayer[layer] = 2;
2698     }
2699 
2700     int nStubLayerTP = 0;
2701     int nStubLayerTP_g = 0;
2702     for (int isum : hasStubInLayer) {
2703       if (isum >= 1)
2704         nStubLayerTP += 1;
2705       if (isum == 2)
2706         nStubLayerTP_g += 1;
2707     }
2708 
2709     if (DebugMode)
2710       edm::LogVerbatim("Tracklet") << "TP is associated with " << nStubTP << " stubs, and has stubs in " << nStubLayerTP
2711                                    << " different layers/disks, and has GENUINE stubs in " << nStubLayerTP_g
2712                                    << " layers ";
2713 
2714     if (TP_minNStub > 0) {
2715       if (DebugMode)
2716         edm::LogVerbatim("Tracklet") << "Only consider TPs with >= " << TP_minNStub << " stubs";
2717       if (nStubTP < TP_minNStub) {
2718         if (DebugMode)
2719           edm::LogVerbatim("Tracklet") << "TP fails minimum nbr stubs requirement! Continuing...";
2720         continue;
2721       }
2722     }
2723     if (TP_minNStubLayer > 0) {
2724       if (DebugMode)
2725         edm::LogVerbatim("Tracklet") << "Only consider TPs with stubs in >= " << TP_minNStubLayer << " layers/disks";
2726       if (nStubLayerTP < TP_minNStubLayer) {
2727         if (DebugMode)
2728           edm::LogVerbatim("Tracklet") << "TP fails stubs in minimum nbr of layers/disks requirement! Continuing...";
2729         continue;
2730       }
2731     }
2732 
2733     if (tmp_eventid == 0) {
2734       trueTkMETx += tmp_tp_pt * cos(tmp_tp_phi);
2735       trueTkMETy += tmp_tp_pt * sin(tmp_tp_phi);
2736     }
2737 
2738     m_tp_pt->push_back(tmp_tp_pt);
2739     m_tp_eta->push_back(tmp_tp_eta);
2740     m_tp_phi->push_back(tmp_tp_phi);
2741     m_tp_dxy->push_back(tmp_tp_dxy);
2742     m_tp_z0->push_back(tmp_tp_z0);
2743     m_tp_d0->push_back(tmp_tp_d0);
2744     m_tp_z0_prod->push_back(tmp_tp_z0_prod);
2745     m_tp_d0_prod->push_back(tmp_tp_d0_prod);
2746     m_tp_pdgid->push_back(tmp_tp_pdgid);
2747     m_tp_nstub->push_back(nStubTP);
2748     m_tp_eventid->push_back(tmp_eventid);
2749     m_tp_charge->push_back(tmp_tp_charge);
2750 
2751     // ----------------------------------------------------------------------------------------------
2752     // look for L1 tracks (prompt) matched to the tracking particle
2753     if (Displaced == "Prompt" || Displaced == "Both") {
2754       std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>> matchedTracks =
2755           MCTruthTTTrackHandle->findTTTrackPtrs(tp_ptr);
2756 
2757       int nMatch = 0;
2758       int i_track = -1;
2759       float i_chi2dof = 99999;
2760 
2761       if (!matchedTracks.empty()) {
2762         if (DebugMode && (matchedTracks.size() > 1))
2763           edm::LogVerbatim("Tracklet") << "TrackingParticle has more than one matched L1 track!";
2764 
2765         // ----------------------------------------------------------------------------------------------
2766         // loop over matched L1 tracks
2767         // here, "match" means tracks that can be associated to a TrackingParticle with at least one hit of at least one of its clusters
2768         // https://twiki.cern.ch/twiki/bin/viewauth/CMS/SLHCTrackerTriggerSWTools#MC_truth_for_TTTrack
2769 
2770         for (int it = 0; it < (int)matchedTracks.size(); it++) {
2771           bool tmp_trk_genuine = false;
2772           bool tmp_trk_loosegenuine = false;
2773           if (MCTruthTTTrackHandle->isGenuine(matchedTracks.at(it)))
2774             tmp_trk_genuine = true;
2775           if (MCTruthTTTrackHandle->isLooselyGenuine(matchedTracks.at(it)))
2776             tmp_trk_loosegenuine = true;
2777           if (!tmp_trk_loosegenuine)
2778             continue;
2779 
2780           if (DebugMode) {
2781             if (MCTruthTTTrackHandle->findTrackingParticlePtr(matchedTracks.at(it)).isNull()) {
2782               edm::LogVerbatim("Tracklet") << "track matched to TP is NOT uniquely matched to a TP";
2783             } else {
2784               edm::Ptr<TrackingParticle> my_tp = MCTruthTTTrackHandle->findTrackingParticlePtr(matchedTracks.at(it));
2785               edm::LogVerbatim("Tracklet") << "TP matched to track matched to TP ... tp pt = " << my_tp->p4().pt()
2786                                            << " eta = " << my_tp->momentum().eta()
2787                                            << " phi = " << my_tp->momentum().phi() << " z0 = " << my_tp->vertex().z();
2788             }
2789             edm::LogVerbatim("Tracklet") << "   ... matched L1 track has pt = "
2790                                          << matchedTracks.at(it)->momentum().perp()
2791                                          << " eta = " << matchedTracks.at(it)->momentum().eta()
2792                                          << " phi = " << matchedTracks.at(it)->momentum().phi()
2793                                          << " chi2 = " << matchedTracks.at(it)->chi2()
2794                                          << " consistency = " << matchedTracks.at(it)->stubPtConsistency()
2795                                          << " z0 = " << matchedTracks.at(it)->z0()
2796                                          << " nstub = " << matchedTracks.at(it)->getStubRefs().size();
2797             if (tmp_trk_genuine)
2798               edm::LogVerbatim("Tracklet") << "    (genuine!) ";
2799             if (tmp_trk_loosegenuine)
2800               edm::LogVerbatim("Tracklet") << "    (loose genuine!) ";
2801           }
2802 
2803           std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
2804               stubRefs = matchedTracks.at(it)->getStubRefs();
2805           int tmp_trk_nstub = stubRefs.size();
2806 
2807           if (tmp_trk_nstub < L1Tk_minNStub)
2808             continue;
2809 
2810           float dmatch_pt = 999;
2811           float dmatch_eta = 999;
2812           float dmatch_phi = 999;
2813           int match_id = 999;
2814 
2815           edm::Ptr<TrackingParticle> my_tp = MCTruthTTTrackHandle->findTrackingParticlePtr(matchedTracks.at(it));
2816           dmatch_pt = std::abs(my_tp->p4().pt() - tmp_tp_pt);
2817           dmatch_eta = std::abs(my_tp->p4().eta() - tmp_tp_eta);
2818           dmatch_phi = std::abs(my_tp->p4().phi() - tmp_tp_phi);
2819           match_id = my_tp->pdgId();
2820           float tmp_trk_chi2dof = matchedTracks.at(it)->chi2Red();
2821 
2822           // ensure that track is uniquely matched to the TP we are looking at!
2823           if (dmatch_pt < 0.1 && dmatch_eta < 0.1 && dmatch_phi < 0.1 && tmp_tp_pdgid == match_id && tmp_trk_genuine) {
2824             nMatch++;
2825             if (i_track < 0 || tmp_trk_chi2dof < i_chi2dof) {
2826               i_track = it;
2827               i_chi2dof = tmp_trk_chi2dof;
2828             }
2829           }
2830 
2831         }  // end loop over matched L1 tracks
2832       }    // end has at least 1 matched L1 track
2833       // ----------------------------------------------------------------------------------------------
2834 
2835       float tmp_matchtrk_pt = -999;
2836       float tmp_matchtrk_eta = -999;
2837       float tmp_matchtrk_phi = -999;
2838       float tmp_matchtrk_z0 = -999;
2839       float tmp_matchtrk_d0 = -999;
2840       float tmp_matchtrk_chi2 = -999;
2841       float tmp_matchtrk_chi2dof = -999;
2842       float tmp_matchtrk_chi2rphi = -999;
2843       float tmp_matchtrk_chi2rz = -999;
2844       float tmp_matchtrk_bendchi2 = -999;
2845       float tmp_matchtrk_MVA1 = -999;
2846       int tmp_matchtrk_nstub = -999;
2847       int tmp_matchtrk_dhits = -999;
2848       int tmp_matchtrk_lhits = -999;
2849       int tmp_matchtrk_seed = -999;
2850       int tmp_matchtrk_hitpattern = -999;
2851       int tmp_matchtrk_nFitPars = -999;
2852 
2853       if (nMatch > 1 && DebugMode)
2854         edm::LogVerbatim("Tracklet") << "WARNING *** 2 or more matches to genuine L1 tracks ***";
2855 
2856       if (nMatch > 0) {
2857         tmp_matchtrk_pt = matchedTracks.at(i_track)->momentum().perp();
2858         tmp_matchtrk_eta = matchedTracks.at(i_track)->momentum().eta();
2859         tmp_matchtrk_phi = matchedTracks.at(i_track)->momentum().phi();
2860         tmp_matchtrk_z0 = matchedTracks.at(i_track)->z0();
2861         tmp_matchtrk_nFitPars = matchedTracks.at(i_track)->nFitPars();
2862 
2863         if (tmp_matchtrk_nFitPars == 5) {
2864           float tmp_matchtrk_x0 = matchedTracks.at(i_track)->POCA().x();
2865           float tmp_matchtrk_y0 = matchedTracks.at(i_track)->POCA().y();
2866           tmp_matchtrk_d0 = -tmp_matchtrk_x0 * sin(tmp_matchtrk_phi) + tmp_matchtrk_y0 * cos(tmp_matchtrk_phi);
2867           // tmp_matchtrk_d0 = matchedTracks.at(i_track)->d0();
2868         }
2869 
2870         tmp_matchtrk_chi2 = matchedTracks.at(i_track)->chi2();
2871         tmp_matchtrk_chi2dof = matchedTracks.at(i_track)->chi2Red();
2872         tmp_matchtrk_chi2rphi = matchedTracks.at(i_track)->chi2XYRed();
2873         tmp_matchtrk_chi2rz = matchedTracks.at(i_track)->chi2ZRed();
2874         tmp_matchtrk_bendchi2 = matchedTracks.at(i_track)->stubPtConsistency();
2875         tmp_matchtrk_MVA1 = matchedTracks.at(i_track)->trkMVA1();
2876         tmp_matchtrk_nstub = (int)matchedTracks.at(i_track)->getStubRefs().size();
2877         tmp_matchtrk_seed = (int)matchedTracks.at(i_track)->trackSeedType();
2878         tmp_matchtrk_hitpattern = (int)matchedTracks.at(i_track)->hitPattern();
2879 
2880         // ------------------------------------------------------------------------------------------
2881         tmp_matchtrk_dhits = 0;
2882         tmp_matchtrk_lhits = 0;
2883 
2884         std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
2885             stubRefs = matchedTracks.at(i_track)->getStubRefs();
2886         int tmp_nstub = stubRefs.size();
2887 
2888         for (int is = 0; is < tmp_nstub; is++) {
2889           DetId detIdStub = tGeom.idToDet((stubRefs.at(is)->clusterRef(0))->getDetId())->geographicalId();
2890           int layer = -999999;
2891           if (detIdStub.subdetId() == StripSubdetector::TOB) {
2892             layer = static_cast<int>(tTopo.layer(detIdStub));
2893             tmp_matchtrk_lhits += pow(10, layer - 1);
2894           } else if (detIdStub.subdetId() == StripSubdetector::TID) {
2895             layer = static_cast<int>(tTopo.layer(detIdStub));
2896             tmp_matchtrk_dhits += pow(10, layer - 1);
2897           }
2898         }
2899       }
2900 
2901       m_tp_nmatch->push_back(nMatch);
2902 
2903       m_matchtrk_pt->push_back(tmp_matchtrk_pt);
2904       m_matchtrk_eta->push_back(tmp_matchtrk_eta);
2905       m_matchtrk_phi->push_back(tmp_matchtrk_phi);
2906       m_matchtrk_z0->push_back(tmp_matchtrk_z0);
2907       m_matchtrk_d0->push_back(tmp_matchtrk_d0);
2908       m_matchtrk_chi2->push_back(tmp_matchtrk_chi2);
2909       m_matchtrk_chi2dof->push_back(tmp_matchtrk_chi2dof);
2910       m_matchtrk_chi2rphi->push_back(tmp_matchtrk_chi2rphi);
2911       m_matchtrk_chi2rz->push_back(tmp_matchtrk_chi2rz);
2912       m_matchtrk_bendchi2->push_back(tmp_matchtrk_bendchi2);
2913       m_matchtrk_MVA1->push_back(tmp_matchtrk_MVA1);
2914       m_matchtrk_nstub->push_back(tmp_matchtrk_nstub);
2915       m_matchtrk_dhits->push_back(tmp_matchtrk_dhits);
2916       m_matchtrk_lhits->push_back(tmp_matchtrk_lhits);
2917       m_matchtrk_seed->push_back(tmp_matchtrk_seed);
2918       m_matchtrk_hitpattern->push_back(tmp_matchtrk_hitpattern);
2919     }
2920 
2921     // ----------------------------------------------------------------------------------------------
2922     // look for L1 tracks (extended) matched to the tracking particle
2923     if (Displaced == "Displaced" || Displaced == "Both") {
2924       L1TrackPtrCollection matchedTracks = MCTruthTTTrackExtendedHandle->findTTTrackPtrs(tp_ptr);
2925 
2926       int nMatch = 0;
2927       int i_track = -1;
2928       float i_chi2dof = 99999;
2929 
2930       if (!matchedTracks.empty()) {
2931         if (DebugMode && (matchedTracks.size() > 1))
2932           edm::LogVerbatim("Tracklet") << "TrackingParticle has more than one matched L1 track!";
2933 
2934         // ----------------------------------------------------------------------------------------------
2935         // loop over matched L1 tracks
2936         // here, "match" means tracks that can be associated to a TrackingParticle with at least one hit of at least one of its clusters
2937         // https://twiki.cern.ch/twiki/bin/viewauth/CMS/SLHCTrackerTriggerSWTools#MC_truth_for_TTTrack
2938 
2939         for (int it = 0; it < (int)matchedTracks.size(); it++) {
2940           bool tmp_trk_genuine = false;
2941           bool tmp_trk_loosegenuine = false;
2942           if (MCTruthTTTrackExtendedHandle->isGenuine(matchedTracks.at(it)))
2943             tmp_trk_genuine = true;
2944           if (MCTruthTTTrackExtendedHandle->isLooselyGenuine(matchedTracks.at(it)))
2945             tmp_trk_loosegenuine = true;
2946           if (!tmp_trk_loosegenuine)
2947             continue;
2948 
2949           if (DebugMode) {
2950             if (MCTruthTTTrackExtendedHandle->findTrackingParticlePtr(matchedTracks.at(it)).isNull()) {
2951               edm::LogVerbatim("Tracklet") << "track matched to TP is NOT uniquely matched to a TP";
2952             } else {
2953               edm::Ptr<TrackingParticle> my_tp =
2954                   MCTruthTTTrackExtendedHandle->findTrackingParticlePtr(matchedTracks.at(it));
2955               edm::LogVerbatim("Tracklet") << "TP matched to track matched to TP ... tp pt = " << my_tp->p4().pt()
2956                                            << " eta = " << my_tp->momentum().eta()
2957                                            << " phi = " << my_tp->momentum().phi() << " z0 = " << my_tp->vertex().z();
2958             }
2959             edm::LogVerbatim("Tracklet") << "   ... matched L1 track has pt = "
2960                                          << matchedTracks.at(it)->momentum().perp()
2961                                          << " eta = " << matchedTracks.at(it)->momentum().eta()
2962                                          << " phi = " << matchedTracks.at(it)->momentum().phi()
2963                                          << " chi2 = " << matchedTracks.at(it)->chi2()
2964                                          << " consistency = " << matchedTracks.at(it)->stubPtConsistency()
2965                                          << " z0 = " << matchedTracks.at(it)->z0()
2966                                          << " nstub = " << matchedTracks.at(it)->getStubRefs().size();
2967             if (tmp_trk_genuine)
2968               edm::LogVerbatim("Tracklet") << "    (genuine!) ";
2969             if (tmp_trk_loosegenuine)
2970               edm::LogVerbatim("Tracklet") << "    (loose genuine!) ";
2971           }
2972 
2973           std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
2974               stubRefs = matchedTracks.at(it)->getStubRefs();
2975           int tmp_trk_nstub = stubRefs.size();
2976 
2977           if (tmp_trk_nstub < L1Tk_minNStub)
2978             continue;
2979 
2980           float dmatch_pt = 999;
2981           float dmatch_eta = 999;
2982           float dmatch_phi = 999;
2983           int match_id = 999;
2984 
2985           edm::Ptr<TrackingParticle> my_tp =
2986               MCTruthTTTrackExtendedHandle->findTrackingParticlePtr(matchedTracks.at(it));
2987           dmatch_pt = std::abs(my_tp->p4().pt() - tmp_tp_pt);
2988           dmatch_eta = std::abs(my_tp->p4().eta() - tmp_tp_eta);
2989           dmatch_phi = std::abs(my_tp->p4().phi() - tmp_tp_phi);
2990           match_id = my_tp->pdgId();
2991           float tmp_trk_chi2dof = matchedTracks.at(it)->chi2Red();
2992 
2993           // ensure that track is uniquely matched to the TP we are looking at!
2994           if (dmatch_pt < 0.1 && dmatch_eta < 0.1 && dmatch_phi < 0.1 && tmp_tp_pdgid == match_id && tmp_trk_genuine) {
2995             nMatch++;
2996             if (i_track < 0 || tmp_trk_chi2dof < i_chi2dof) {
2997               i_track = it;
2998               i_chi2dof = tmp_trk_chi2dof;
2999             }
3000           }
3001 
3002         }  // end loop over matched L1 tracks
3003       }    // end has at least 1 matched L1 track
3004       // ----------------------------------------------------------------------------------------------
3005 
3006       float tmp_matchtrkExt_pt = -999;
3007       float tmp_matchtrkExt_eta = -999;
3008       float tmp_matchtrkExt_phi = -999;
3009       float tmp_matchtrkExt_z0 = -999;
3010       float tmp_matchtrkExt_d0 = -999;
3011       float tmp_matchtrkExt_chi2 = -999;
3012       float tmp_matchtrkExt_chi2dof = -999;
3013       float tmp_matchtrkExt_chi2rphi = -999;
3014       float tmp_matchtrkExt_chi2rz = -999;
3015       float tmp_matchtrkExt_bendchi2 = -999;
3016       float tmp_matchtrkExt_MVA = -999;
3017       int tmp_matchtrkExt_nstub = -999;
3018       int tmp_matchtrkExt_dhits = -999;
3019       int tmp_matchtrkExt_lhits = -999;
3020       int tmp_matchtrkExt_seed = -999;
3021       int tmp_matchtrkExt_hitpattern = -999;
3022       int tmp_matchtrkExt_nFitPars = -999;
3023 
3024       if (nMatch > 1 && DebugMode)
3025         edm::LogVerbatim("Tracklet") << "WARNING *** 2 or more matches to genuine L1 tracks ***";
3026 
3027       if (nMatch > 0) {
3028         tmp_matchtrkExt_pt = matchedTracks.at(i_track)->momentum().perp();
3029         tmp_matchtrkExt_eta = matchedTracks.at(i_track)->momentum().eta();
3030         tmp_matchtrkExt_phi = matchedTracks.at(i_track)->momentum().phi();
3031         tmp_matchtrkExt_z0 = matchedTracks.at(i_track)->z0();
3032         tmp_matchtrkExt_nFitPars = matchedTracks.at(i_track)->nFitPars();
3033 
3034         if (tmp_matchtrkExt_nFitPars == 5) {
3035           float tmp_matchtrkExt_x0 = matchedTracks.at(i_track)->POCA().x();
3036           float tmp_matchtrkExt_y0 = matchedTracks.at(i_track)->POCA().y();
3037           tmp_matchtrkExt_d0 =
3038               -tmp_matchtrkExt_x0 * sin(tmp_matchtrkExt_phi) + tmp_matchtrkExt_y0 * cos(tmp_matchtrkExt_phi);
3039           // tmp_matchtrkExt_d0 = matchedTracks.at(i_track)->d0();
3040         }
3041 
3042         tmp_matchtrkExt_chi2 = matchedTracks.at(i_track)->chi2();
3043         tmp_matchtrkExt_chi2dof = matchedTracks.at(i_track)->chi2Red();
3044         tmp_matchtrkExt_chi2rphi = matchedTracks.at(i_track)->chi2XYRed();
3045         tmp_matchtrkExt_chi2rz = matchedTracks.at(i_track)->chi2ZRed();
3046         tmp_matchtrkExt_bendchi2 = matchedTracks.at(i_track)->stubPtConsistency();
3047         tmp_matchtrkExt_MVA = matchedTracks.at(i_track)->trkMVA1();
3048         tmp_matchtrkExt_nstub = (int)matchedTracks.at(i_track)->getStubRefs().size();
3049         tmp_matchtrkExt_seed = (int)matchedTracks.at(i_track)->trackSeedType();
3050         tmp_matchtrkExt_hitpattern = (int)matchedTracks.at(i_track)->hitPattern();
3051 
3052         // ------------------------------------------------------------------------------------------
3053         tmp_matchtrkExt_dhits = 0;
3054         tmp_matchtrkExt_lhits = 0;
3055 
3056         std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
3057             stubRefs = matchedTracks.at(i_track)->getStubRefs();
3058         int tmp_nstub = stubRefs.size();
3059 
3060         for (int is = 0; is < tmp_nstub; is++) {
3061           DetId detIdStub = tGeom.idToDet((stubRefs.at(is)->clusterRef(0))->getDetId())->geographicalId();
3062           int layer = -999999;
3063           if (detIdStub.subdetId() == StripSubdetector::TOB) {
3064             layer = static_cast<int>(tTopo.layer(detIdStub));
3065             tmp_matchtrkExt_lhits += pow(10, layer - 1);
3066           } else if (detIdStub.subdetId() == StripSubdetector::TID) {
3067             layer = static_cast<int>(tTopo.layer(detIdStub));
3068             tmp_matchtrkExt_dhits += pow(10, layer - 1);
3069           }
3070         }
3071       }
3072 
3073       // m_tp_nmatch->push_back(nMatch); //modify to be matches for ext
3074       m_matchtrkExt_pt->push_back(tmp_matchtrkExt_pt);
3075       m_matchtrkExt_eta->push_back(tmp_matchtrkExt_eta);
3076       m_matchtrkExt_phi->push_back(tmp_matchtrkExt_phi);
3077       m_matchtrkExt_z0->push_back(tmp_matchtrkExt_z0);
3078       m_matchtrkExt_d0->push_back(tmp_matchtrkExt_d0);
3079       m_matchtrkExt_chi2->push_back(tmp_matchtrkExt_chi2);
3080       m_matchtrkExt_chi2dof->push_back(tmp_matchtrkExt_chi2dof);
3081       m_matchtrkExt_chi2rphi->push_back(tmp_matchtrkExt_chi2rphi);
3082       m_matchtrkExt_chi2rz->push_back(tmp_matchtrkExt_chi2rz);
3083       m_matchtrkExt_bendchi2->push_back(tmp_matchtrkExt_bendchi2);
3084       m_matchtrkExt_MVA->push_back(tmp_matchtrkExt_MVA);
3085       m_matchtrkExt_nstub->push_back(tmp_matchtrkExt_nstub);
3086       m_matchtrkExt_dhits->push_back(tmp_matchtrkExt_dhits);
3087       m_matchtrkExt_lhits->push_back(tmp_matchtrkExt_lhits);
3088       m_matchtrkExt_seed->push_back(tmp_matchtrkExt_seed);
3089       m_matchtrkExt_hitpattern->push_back(tmp_matchtrkExt_hitpattern);
3090     }
3091   }  //end loop tracking particles
3092   trueTkMET = sqrt(trueTkMETx * trueTkMETx + trueTkMETy * trueTkMETy);
3093 
3094   if (L1PrimaryVertexHandle.isValid()) {
3095     for (vtxIter = L1PrimaryVertexHandle->begin(); vtxIter != L1PrimaryVertexHandle->end(); ++vtxIter) {
3096       m_pv_L1reco->push_back(vtxIter->z0());
3097       m_pv_L1reco_sum->push_back(vtxIter->pt());
3098     }
3099   } else
3100     edm::LogWarning("DataNotFound") << "\nWarning: L1PrimaryVertexHandle not found" << std::endl;
3101 
3102   if (L1PrimaryVertexEmuHandle.isValid()) {
3103     for (vtxEmuIter = L1PrimaryVertexEmuHandle->begin(); vtxEmuIter != L1PrimaryVertexEmuHandle->end(); ++vtxEmuIter) {
3104       m_pv_L1reco_emu->push_back(vtxEmuIter->z0());
3105       m_pv_L1reco_sum_emu->push_back(vtxEmuIter->pt());
3106     }
3107   } else
3108     edm::LogWarning("DataNotFound") << "\nWarning: L1PrimaryVertexEmuHandle not found" << std::endl;
3109 
3110   if (SaveTrackSums) {
3111     if (Displaced == "Prompt" || Displaced == "Both") {
3112       if (L1TkMETHandle.isValid()) {
3113         trkMET = L1TkMETHandle->begin()->etMiss();
3114         trkMETPhi = L1TkMETHandle->begin()->p4().phi();
3115       } else {
3116         edm::LogWarning("DataNotFound") << "\nWarning: tkMET handle not found" << std::endl;
3117       }
3118 
3119       if (L1TkMETEmuHandle.isValid()) {
3120         trkMETEmu = L1TkMETEmuHandle->begin()->hwPt() * l1tmetemu::kStepMETwordEt;
3121         trkMETEmuPhi = L1TkMETEmuHandle->begin()->hwPhi() * l1tmetemu::kStepMETwordPhi;
3122       } else {
3123         edm::LogWarning("DataNotFound") << "\nWarning: tkMETEmu handle not found" << std::endl;
3124       }
3125 
3126       if (L1TkMHTHandle.isValid()) {
3127         trkMHT = L1TkMHTHandle->begin()->EtMiss();
3128         trkHT = L1TkMHTHandle->begin()->etTotal();
3129       } else
3130         edm::LogWarning("DataNotFound") << "\nWarning: tkMHT handle not found" << std::endl;
3131 
3132       if (L1TkMHTEmuHandle.isValid()) {
3133         trkMHTEmu = L1TkMHTEmuHandle->begin()->p4().energy();
3134         trkHTEmu = L1TkMHTEmuHandle->begin()->hwPt() * l1tmhtemu::kStepMHT;
3135         trkMHTEmuPhi = L1TkMHTEmuHandle->begin()->hwPhi() * l1tmhtemu::kStepMHTPhi - M_PI;
3136       } else
3137         edm::LogWarning("DataNotFound") << "\nWarning: tkMHTEmu handle not found" << std::endl;
3138     }  //end prompt-track quantities
3139 
3140     if (Displaced == "Displaced" || Displaced == "Both") {
3141       if (L1TkMETExtendedHandle.isValid()) {
3142         trkMETExt = L1TkMETExtendedHandle->begin()->etMiss();
3143         trkMETPhiExt = L1TkMETExtendedHandle->begin()->p4().phi();
3144       } else {
3145         edm::LogWarning("DataNotFound") << "\nWarning: tkMETExtended handle not found" << std::endl;
3146       }
3147 
3148       if (L1TkMHTExtendedHandle.isValid()) {
3149         trkMHTExt = L1TkMHTExtendedHandle->begin()->EtMiss();
3150         trkHTExt = L1TkMHTExtendedHandle->begin()->etTotal();
3151       } else {
3152         edm::LogWarning("DataNotFound") << "\nWarning: tkMHTExtended handle not found" << std::endl;
3153       }
3154 
3155       if (L1TkMHTEmuExtendedHandle.isValid()) {
3156         trkMHTEmuExt = L1TkMHTEmuExtendedHandle->begin()->p4().energy();
3157         trkHTEmuExt = L1TkMHTEmuExtendedHandle->begin()->hwPt() * l1tmhtemu::kStepMHT;
3158         trkMHTEmuPhiExt = L1TkMHTEmuExtendedHandle->begin()->hwPhi() * l1tmhtemu::kStepMHTPhi;
3159       } else
3160         edm::LogWarning("DataNotFound") << "\nWarning: tkMHTEmuExtended handle not found" << std::endl;
3161     }  //end displaced-track quantities
3162   }
3163 
3164   if (SaveTrackJets) {
3165     if (GenJetHandle.isValid()) {
3166       for (auto jetIter = GenJetHandle->begin(); jetIter != GenJetHandle->end(); ++jetIter) {
3167         m_genjet_phi->push_back(jetIter->phi());
3168         m_genjet_eta->push_back(jetIter->eta());
3169         m_genjet_pt->push_back(jetIter->pt());
3170         m_genjet_p->push_back(jetIter->p());
3171       }
3172     }
3173     if (TrackFastJetsHandle.isValid() && (Displaced == "Prompt" || Displaced == "Both")) {
3174       for (jetIter = TrackFastJetsHandle->begin(); jetIter != TrackFastJetsHandle->end(); ++jetIter) {
3175         m_trkfastjet_vz->push_back(jetIter->jetVtx());
3176         m_trkfastjet_ntracks->push_back(jetIter->trkPtrs().size());
3177         m_trkfastjet_phi->push_back(jetIter->phi());
3178         m_trkfastjet_eta->push_back(jetIter->eta());
3179         m_trkfastjet_pt->push_back(jetIter->pt());
3180         m_trkfastjet_p->push_back(jetIter->p());
3181       }
3182     }
3183     if (TrackFastJetsExtendedHandle.isValid() && (Displaced == "Displaced" || Displaced == "Both")) {
3184       for (jetIter = TrackFastJetsExtendedHandle->begin(); jetIter != TrackFastJetsExtendedHandle->end(); ++jetIter) {
3185         m_trkfastjetExt_vz->push_back(jetIter->jetVtx());
3186         m_trkfastjetExt_ntracks->push_back(jetIter->trkPtrs().size());
3187         m_trkfastjetExt_phi->push_back(jetIter->phi());
3188         m_trkfastjetExt_eta->push_back(jetIter->eta());
3189         m_trkfastjetExt_pt->push_back(jetIter->pt());
3190         m_trkfastjetExt_p->push_back(jetIter->p());
3191       }
3192     }
3193     if (!TrackJetsHandle.isValid() && (Displaced == "Prompt" || Displaced == "Both"))
3194       edm::LogWarning("DataNotFound") << "\nWarning: TrackJetsHandle not found" << std::endl;
3195     if (!TrackJetsExtendedHandle.isValid() && (Displaced == "Displaced" || Displaced == "Both"))
3196       edm::LogWarning("DataNotFound") << "\nWarning: TrackJetsExtendedHandle not found" << std::endl;
3197     if (TrackJetsHandle.isValid() && (Displaced == "Prompt" || Displaced == "Both")) {
3198       for (jetIter = TrackJetsHandle->begin(); jetIter != TrackJetsHandle->end(); ++jetIter) {
3199         m_trkjet_vz->push_back(jetIter->jetVtx());
3200         m_trkjet_ntracks->push_back(jetIter->ntracks());
3201         m_trkjet_phi->push_back(jetIter->phi());
3202         m_trkjet_eta->push_back(jetIter->eta());
3203         m_trkjet_pt->push_back(jetIter->pt());
3204         m_trkjet_p->push_back(jetIter->p());
3205         m_trkjet_nDisplaced->push_back(jetIter->nDisptracks());
3206         m_trkjet_nTight->push_back(jetIter->nTighttracks());
3207         m_trkjet_nTightDisplaced->push_back(jetIter->nTightDisptracks());
3208       }
3209     }
3210     for (tripletIter = TrackTripletsHandle->begin(); tripletIter != TrackTripletsHandle->end(); ++tripletIter) {
3211       m_triplet_phi->push_back(tripletIter->phi());
3212       m_triplet_eta->push_back(tripletIter->eta());
3213       m_triplet_pt->push_back(tripletIter->pt());
3214       m_triplet_mass->push_back(tripletIter->mass());
3215       m_triplet_charge->push_back(tripletIter->getTripletCharge());
3216       m_triplet_dmassmax->push_back(tripletIter->getPairMassMax());
3217       m_triplet_dmassmin->push_back(tripletIter->getPairMassMin());
3218       m_triplet_dzmax->push_back(tripletIter->getPairDzMax());
3219       m_triplet_dzmin->push_back(tripletIter->getPairDzMin());
3220       m_triplet_trk1pt->push_back(tripletIter->trkPtr(0)->momentum().perp());
3221       m_triplet_trk1eta->push_back(tripletIter->trkPtr(0)->momentum().eta());
3222       m_triplet_trk1phi->push_back(tripletIter->trkPtr(0)->momentum().phi());
3223       m_triplet_trk1z->push_back(tripletIter->trkPtr(0)->z0());
3224       m_triplet_trk1npar->push_back(tripletIter->trkPtr(0)->nFitPars());
3225       m_triplet_trk1mva->push_back(tripletIter->trkPtr(0)->trkMVA1());
3226       m_triplet_trk2pt->push_back(tripletIter->trkPtr(1)->momentum().perp());
3227       m_triplet_trk2eta->push_back(tripletIter->trkPtr(1)->momentum().eta());
3228       m_triplet_trk2phi->push_back(tripletIter->trkPtr(1)->momentum().phi());
3229       m_triplet_trk2z->push_back(tripletIter->trkPtr(1)->z0());
3230       m_triplet_trk2npar->push_back(tripletIter->trkPtr(1)->nFitPars());
3231       m_triplet_trk2mva->push_back(tripletIter->trkPtr(1)->trkMVA1());
3232       m_triplet_trk3pt->push_back(tripletIter->trkPtr(2)->momentum().perp());
3233       m_triplet_trk3eta->push_back(tripletIter->trkPtr(2)->momentum().eta());
3234       m_triplet_trk3phi->push_back(tripletIter->trkPtr(2)->momentum().phi());
3235       m_triplet_trk3z->push_back(tripletIter->trkPtr(2)->z0());
3236       m_triplet_trk3npar->push_back(tripletIter->trkPtr(2)->nFitPars());
3237       m_triplet_trk3mva->push_back(tripletIter->trkPtr(2)->trkMVA1());
3238     }
3239     if (TrackJetsExtendedHandle.isValid() && (Displaced == "Displaced" || Displaced == "Both")) {
3240       for (jetIter = TrackJetsExtendedHandle->begin(); jetIter != TrackJetsExtendedHandle->end(); ++jetIter) {
3241         m_trkjetExt_vz->push_back(jetIter->jetVtx());
3242         m_trkjetExt_ntracks->push_back(jetIter->ntracks());
3243         m_trkjetExt_phi->push_back(jetIter->phi());
3244         m_trkjetExt_eta->push_back(jetIter->eta());
3245         m_trkjetExt_pt->push_back(jetIter->pt());
3246         m_trkjetExt_p->push_back(jetIter->p());
3247         m_trkjetExt_nDisplaced->push_back(jetIter->nDisptracks());
3248         m_trkjetExt_nTight->push_back(jetIter->nTighttracks());
3249         m_trkjetExt_nTightDisplaced->push_back(jetIter->nTightDisptracks());
3250       }
3251     }
3252 
3253     if (!TrackJetsEmuHandle.isValid() && (Displaced == "Prompt" || Displaced == "Both"))
3254       edm::LogWarning("DataNotFound") << "\nWarning: TrackJetsEmuHandle not found" << std::endl;
3255     else if (TrackJetsEmuHandle.isValid() && (Displaced == "Prompt" || Displaced == "Both")) {
3256       for (jetemIter = TrackJetsEmuHandle->begin(); jetemIter != TrackJetsEmuHandle->end(); ++jetemIter) {
3257         m_trkjetem_ntracks->push_back(jetemIter->nt());
3258         m_trkjetem_phi->push_back(jetemIter->glbphi());
3259         m_trkjetem_eta->push_back(jetemIter->glbeta());
3260         m_trkjetem_pt->push_back(jetemIter->pt());
3261         m_trkjetem_z->push_back(jetemIter->z0());
3262         m_trkjetem_nxtracks->push_back(jetemIter->xt());
3263       }
3264     }
3265     if (!TrackJetsExtendedEmuHandle.isValid() && (Displaced == "Displaced" || Displaced == "Both"))
3266       edm::LogWarning("DataNotFound") << "\nWarning: TrackJetsExtendedEmuHandle not found" << std::endl;
3267     else if (TrackJetsExtendedEmuHandle.isValid() && (Displaced == "Displaced" || Displaced == "Both")) {
3268       for (jetemIter = TrackJetsExtendedEmuHandle->begin(); jetemIter != TrackJetsExtendedEmuHandle->end();
3269            ++jetemIter) {
3270         m_trkjetemExt_ntracks->push_back(jetemIter->nt());
3271         m_trkjetemExt_phi->push_back(jetemIter->glbphi());
3272         m_trkjetemExt_eta->push_back(jetemIter->glbeta());
3273         m_trkjetemExt_pt->push_back(jetemIter->pt());
3274         m_trkjetemExt_z->push_back(jetemIter->z0());
3275         m_trkjetemExt_nxtracks->push_back(jetemIter->xt());
3276       }
3277     }
3278   }  // end track jets
3279 
3280   eventTree->Fill();
3281 }  // end of analyze()
3282 
3283 int L1TrackObjectNtupleMaker::getSelectedTrackIndex(const L1TrackRef& trackRef,
3284                                                     const edm::Handle<L1TrackRefCollection>& selectedTrackRefs) const {
3285   auto it = std::find_if(selectedTrackRefs->begin(), selectedTrackRefs->end(), [&trackRef](L1TrackRef const& obj) {
3286     return obj == trackRef;
3287   });
3288   if (it != selectedTrackRefs->end())
3289     return std::distance(selectedTrackRefs->begin(), it);
3290   else
3291     return -1;
3292 }
3293 
3294 ///////////////////////////
3295 // DEFINE THIS AS A PLUG-IN
3296 DEFINE_FWK_MODULE(L1TrackObjectNtupleMaker);