Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-12 23:04:00

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