Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:01

0001 // -*- C++ -*-
0002 //
0003 // Package:    CosmicSplitterValidation
0004 // Class:      CosmicSplitterValidation
0005 //
0006 /**\class CosmicSplitterValidation CosmicSplitterValidation.cc
0007 
0008  Description: Takes a set of alignment constants and turns them into a ROOT file
0009 
0010  Implementation:
0011  <Notes on implementation>
0012  */
0013 //
0014 // Original Author:  Nhan Tran
0015 //         Created:  Mon Jul 16m 16:56:34 CDT 2007
0016 // $Id: CosmicSplitterValidation.cc,v 1.11 2010/03/29 13:18:43 mussgill Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <algorithm>
0022 #include <TTree.h>
0023 
0024 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0025 
0026 #include "DataFormats/Common/interface/RefToBase.h"
0027 #include "DataFormats/Common/interface/View.h"
0028 #include "DataFormats/MuonReco/interface/Muon.h"
0029 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0030 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
0031 #include "DataFormats/TrackingRecHit/interface/InvalidTrackingRecHit.h"
0032 #include "DataFormats/TrackReco/interface/Track.h"
0033 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0034 
0035 #include "FWCore/Framework/interface/ConsumesCollector.h"
0036 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0037 #include "FWCore/Framework/interface/Event.h"
0038 #include "FWCore/Framework/interface/EventSetup.h"
0039 #include "FWCore/Framework/interface/MakerMacros.h"
0040 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0041 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0042 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0043 #include "FWCore/ServiceRegistry/interface/Service.h"
0044 #include "FWCore/Utilities/interface/InputTag.h"
0045 
0046 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0047 
0048 #include "RecoVertex/VertexTools/interface/PerigeeLinearizedTrackState.h"
0049 
0050 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0051 #include "TrackingTools/TransientTrack/interface/BasicTransientTrack.h"
0052 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0053 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0054 
0055 //
0056 // class decleration
0057 //
0058 
0059 class CosmicSplitterValidation : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0060 public:
0061   explicit CosmicSplitterValidation(const edm::ParameterSet&);
0062   ~CosmicSplitterValidation() override = default;
0063 
0064   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0065 
0066 private:
0067   void beginJob() override;
0068   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0069   void endJob() override;
0070 
0071   bool is_gold_muon(const edm::Event& e);
0072 
0073   const int compressionSettings_;
0074   edm::InputTag splitTracks_;
0075   edm::InputTag splitGlobalMuons_;
0076   edm::InputTag originalTracks_;
0077   edm::InputTag originalGlobalMuons_;
0078 
0079   bool checkIfGolden_;
0080   bool splitMuons_;
0081   int totalTracksToAnalyzer_;
0082   int goldenCtr;
0083   int twoTracksCtr;
0084   int goldenPlusTwoTracksCtr;
0085   int _passesTracksPlusMuonsCuts;
0086 
0087   edm::Service<TFileService> tfile;
0088   // ----------member data ---------------------------
0089   //std::vector<AlignTransform> m_align;
0090   // tree
0091   TTree* splitterTree_;
0092   // tree vars
0093   int runNumber_, eventNumber_, luminosityBlock_;
0094   // split track variables
0095   double dcaX1_spl_, dcaY1_spl_, dcaZ1_spl_;
0096   double dcaX2_spl_, dcaY2_spl_, dcaZ2_spl_;
0097   double dxy1_spl_, dxy2_spl_, ddxy_spl_;
0098   double dz1_spl_, dz2_spl_, ddz_spl_;
0099   double theta1_spl_, theta2_spl_, dtheta_spl_;
0100   double eta1_spl_, eta2_spl_, deta_spl_;
0101   double phi1_spl_, phi2_spl_, dphi_spl_;
0102   double pt1_spl_, pt2_spl_, dpt_spl_;
0103   double p1_spl_, p2_spl_, dp_spl_;
0104   double qoverpt1_spl_, qoverpt2_spl_, dqoverpt_spl_;
0105   int nHits1_spl_, nHitsPXB1_spl_, nHitsPXF1_spl_, nHitsTIB1_spl_;
0106   int nHitsTOB1_spl_, nHitsTID1_spl_, nHitsTEC1_spl_;
0107   int nHits2_spl_, nHitsPXB2_spl_, nHitsPXF2_spl_, nHitsTIB2_spl_;
0108   int nHitsTOB2_spl_, nHitsTID2_spl_, nHitsTEC2_spl_;
0109   // split track errors
0110   double dxy1Err_spl_, dxy2Err_spl_;
0111   double dz1Err_spl_, dz2Err_spl_;
0112   double theta1Err_spl_, theta2Err_spl_;
0113   double eta1Err_spl_, eta2Err_spl_;
0114   double phi1Err_spl_, phi2Err_spl_;
0115   double pt1Err_spl_, pt2Err_spl_;
0116   double qoverpt1Err_spl_, qoverpt2Err_spl_;
0117 
0118   // original track variables
0119   double dcaX_org_, dcaY_org_, dcaZ_org_;
0120   double dxy_org_, dz_org_;
0121   double theta_org_, eta_org_, phi_org_;
0122   double pt_org_, p_org_, qoverpt_org_;
0123   double norchi2_org_;
0124   int nHits_org_, nHitsPXB_org_, nHitsPXF_org_, nHitsTIB_org_;
0125   int nHitsTOB_org_, nHitsTID_org_, nHitsTEC_org_;
0126   // original track errors
0127   double dxyErr_org_, dzErr_org_;
0128   double thetaErr_org_, etaErr_org_, phiErr_org_;
0129   double ptErr_org_, qoverptErr_org_;
0130 
0131   // split sta variables
0132   double dcaX1_sta_, dcaY1_sta_, dcaZ1_sta_;
0133   double dcaX2_sta_, dcaY2_sta_, dcaZ2_sta_;
0134   double dxy1_sta_, dxy2_sta_, ddxy_sta_;
0135   double dz1_sta_, dz2_sta_, ddz_sta_;
0136   double theta1_sta_, theta2_sta_, dtheta_sta_;
0137   double eta1_sta_, eta2_sta_, deta_sta_;
0138   double phi1_sta_, phi2_sta_, dphi_sta_;
0139   double pt1_sta_, pt2_sta_, dpt_sta_;
0140   double p1_sta_, p2_sta_, dp_sta_;
0141   double qoverpt1_sta_, qoverpt2_sta_, dqoverpt_sta_;
0142   // split sta_ errors
0143   double dxy1Err_sta_, dxy2Err_sta_;
0144   double dz1Err_sta_, dz2Err_sta_;
0145   double theta1Err_sta_, theta2Err_sta_;
0146   double eta1Err_sta_, eta2Err_sta_;
0147   double phi1Err_sta_, phi2Err_sta_;
0148   double pt1Err_sta_, pt2Err_sta_;
0149   double qoverpt1Err_sta_, qoverpt2Err_sta_;
0150 
0151   // split glb_ variables
0152   double dcaX1_glb_, dcaY1_glb_, dcaZ1_glb_;
0153   double dcaX2_glb_, dcaY2_glb_, dcaZ2_glb_;
0154   double dxy1_glb_, dxy2_glb_, ddxy_glb_;
0155   double dz1_glb_, dz2_glb_, ddz_glb_;
0156   double theta1_glb_, theta2_glb_, dtheta_glb_;
0157   double eta1_glb_, eta2_glb_, deta_glb_;
0158   double phi1_glb_, phi2_glb_, dphi_glb_;
0159   double pt1_glb_, pt2_glb_, dpt_glb_;
0160   double p1_glb_, p2_glb_, dp_glb_;
0161   double qoverpt1_glb_, qoverpt2_glb_, dqoverpt_glb_;
0162   double norchi1_glb_, norchi2_glb_;
0163   // split glb_ errors
0164   double dxy1Err_glb_, dxy2Err_glb_;
0165   double dz1Err_glb_, dz2Err_glb_;
0166   double theta1Err_glb_, theta2Err_glb_;
0167   double eta1Err_glb_, eta2Err_glb_;
0168   double phi1Err_glb_, phi2Err_glb_;
0169   double pt1Err_glb_, pt2Err_glb_;
0170   double qoverpt1Err_glb_, qoverpt2Err_glb_;
0171   // original glb muon variables
0172   double dcaX_orm_, dcaY_orm_, dcaZ_orm_;
0173   double dxy_orm_, dz_orm_;
0174   double theta_orm_, eta_orm_, phi_orm_;
0175   double pt_orm_, p_orm_, qoverpt_orm_;
0176   double norchi2_orm_;
0177   // original glb muon errors
0178   double dxyErr_orm_, dzErr_orm_;
0179   double thetaErr_orm_, etaErr_orm_, phiErr_orm_;
0180   double ptErr_orm_, qoverptErr_orm_;
0181 
0182   //consumes tokens
0183   edm::EDGetTokenT<std::vector<reco::Track>> splitTracksToken_;
0184   edm::EDGetTokenT<std::vector<reco::Track>> originalTracksToken_;
0185   edm::EDGetTokenT<reco::MuonCollection> splitGlobalMuonsToken_;
0186   edm::EDGetTokenT<reco::MuonCollection> originalGlobalMuonsToken_;
0187   edm::EDGetTokenT<reco::MuonCollection> STAMuonsToken_;
0188 };
0189 
0190 //
0191 // constants, enums and typedefs
0192 //
0193 
0194 //
0195 // static data member definitions
0196 //
0197 
0198 //
0199 // constructors and destructor
0200 //
0201 CosmicSplitterValidation::CosmicSplitterValidation(const edm::ParameterSet& iConfig)
0202     : compressionSettings_(iConfig.getUntrackedParameter<int>("compressionSettings", -1)),
0203       splitTracks_(iConfig.getParameter<edm::InputTag>("splitTracks")),
0204       splitGlobalMuons_(iConfig.getParameter<edm::InputTag>("splitGlobalMuons")),
0205       originalTracks_(iConfig.getParameter<edm::InputTag>("originalTracks")),
0206       originalGlobalMuons_(iConfig.getParameter<edm::InputTag>("originalGlobalMuons")),
0207       checkIfGolden_(iConfig.getParameter<bool>("checkIfGolden")),
0208       splitMuons_(iConfig.getParameter<bool>("ifSplitMuons")),
0209       totalTracksToAnalyzer_(0),
0210       goldenCtr(0),
0211       twoTracksCtr(0),
0212       goldenPlusTwoTracksCtr(0),
0213       _passesTracksPlusMuonsCuts(0),
0214       splitterTree_(nullptr),
0215       runNumber_(0),
0216       eventNumber_(0),
0217       luminosityBlock_(0),
0218       dcaX1_spl_(0),
0219       dcaY1_spl_(0),
0220       dcaZ1_spl_(0),
0221       dcaX2_spl_(0),
0222       dcaY2_spl_(0),
0223       dcaZ2_spl_(0),
0224       dxy1_spl_(0),
0225       dxy2_spl_(0),
0226       ddxy_spl_(0),
0227       dz1_spl_(0),
0228       dz2_spl_(0),
0229       ddz_spl_(0),
0230       theta1_spl_(0),
0231       theta2_spl_(0),
0232       dtheta_spl_(0),
0233       eta1_spl_(0),
0234       eta2_spl_(0),
0235       deta_spl_(0),
0236       phi1_spl_(0),
0237       phi2_spl_(0),
0238       dphi_spl_(0),
0239       pt1_spl_(0),
0240       pt2_spl_(0),
0241       dpt_spl_(0),
0242       p1_spl_(0),
0243       p2_spl_(0),
0244       dp_spl_(0),
0245       qoverpt1_spl_(0),
0246       qoverpt2_spl_(0),
0247       dqoverpt_spl_(0),
0248       nHits1_spl_(0),
0249       nHitsPXB1_spl_(0),
0250       nHitsPXF1_spl_(0),
0251       nHitsTIB1_spl_(0),
0252       nHitsTOB1_spl_(0),
0253       nHitsTID1_spl_(0),
0254       nHitsTEC1_spl_(0),
0255       nHits2_spl_(0),
0256       nHitsPXB2_spl_(0),
0257       nHitsPXF2_spl_(0),
0258       nHitsTIB2_spl_(0),
0259       nHitsTOB2_spl_(0),
0260       nHitsTID2_spl_(0),
0261       nHitsTEC2_spl_(0),
0262 
0263       dxy1Err_spl_(0),
0264       dxy2Err_spl_(0),
0265       dz1Err_spl_(0),
0266       dz2Err_spl_(0),
0267       theta1Err_spl_(0),
0268       theta2Err_spl_(0),
0269       eta1Err_spl_(0),
0270       eta2Err_spl_(0),
0271       phi1Err_spl_(0),
0272       phi2Err_spl_(0),
0273       pt1Err_spl_(0),
0274       pt2Err_spl_(0),
0275       qoverpt1Err_spl_(0),
0276       qoverpt2Err_spl_(0),
0277 
0278       dcaX_org_(0),
0279       dcaY_org_(0),
0280       dcaZ_org_(0),
0281       dxy_org_(0),
0282       dz_org_(0),
0283       theta_org_(0),
0284       eta_org_(0),
0285       phi_org_(0),
0286       pt_org_(0),
0287       p_org_(0),
0288       qoverpt_org_(0),
0289       norchi2_org_(0),
0290       nHits_org_(0),
0291       nHitsPXB_org_(0),
0292       nHitsPXF_org_(0),
0293       nHitsTIB_org_(0),
0294       nHitsTOB_org_(0),
0295       nHitsTID_org_(0),
0296       nHitsTEC_org_(0),
0297 
0298       dxyErr_org_(0),
0299       dzErr_org_(0),
0300       thetaErr_org_(0),
0301       etaErr_org_(0),
0302       phiErr_org_(0),
0303       ptErr_org_(0),
0304       qoverptErr_org_(0),
0305 
0306       dcaX1_sta_(0),
0307       dcaY1_sta_(0),
0308       dcaZ1_sta_(0),
0309       dcaX2_sta_(0),
0310       dcaY2_sta_(0),
0311       dcaZ2_sta_(0),
0312       dxy1_sta_(0),
0313       dxy2_sta_(0),
0314       ddxy_sta_(0),
0315       dz1_sta_(0),
0316       dz2_sta_(0),
0317       ddz_sta_(0),
0318       theta1_sta_(0),
0319       theta2_sta_(0),
0320       dtheta_sta_(0),
0321       eta1_sta_(0),
0322       eta2_sta_(0),
0323       deta_sta_(0),
0324       phi1_sta_(0),
0325       phi2_sta_(0),
0326       dphi_sta_(0),
0327       pt1_sta_(0),
0328       pt2_sta_(0),
0329       dpt_sta_(0),
0330       p1_sta_(0),
0331       p2_sta_(0),
0332       dp_sta_(0),
0333       qoverpt1_sta_(0),
0334       qoverpt2_sta_(0),
0335       dqoverpt_sta_(0),
0336 
0337       dxy1Err_sta_(0),
0338       dxy2Err_sta_(0),
0339       dz1Err_sta_(0),
0340       dz2Err_sta_(0),
0341       theta1Err_sta_(0),
0342       theta2Err_sta_(0),
0343       eta1Err_sta_(0),
0344       eta2Err_sta_(0),
0345       phi1Err_sta_(0),
0346       phi2Err_sta_(0),
0347       pt1Err_sta_(0),
0348       pt2Err_sta_(0),
0349       qoverpt1Err_sta_(0),
0350       qoverpt2Err_sta_(0),
0351 
0352       dcaX1_glb_(0),
0353       dcaY1_glb_(0),
0354       dcaZ1_glb_(0),
0355       dcaX2_glb_(0),
0356       dcaY2_glb_(0),
0357       dcaZ2_glb_(0),
0358       dxy1_glb_(0),
0359       dxy2_glb_(0),
0360       ddxy_glb_(0),
0361       dz1_glb_(0),
0362       dz2_glb_(0),
0363       ddz_glb_(0),
0364       theta1_glb_(0),
0365       theta2_glb_(0),
0366       dtheta_glb_(0),
0367       eta1_glb_(0),
0368       eta2_glb_(0),
0369       deta_glb_(0),
0370       phi1_glb_(0),
0371       phi2_glb_(0),
0372       dphi_glb_(0),
0373       pt1_glb_(0),
0374       pt2_glb_(0),
0375       dpt_glb_(0),
0376       p1_glb_(0),
0377       p2_glb_(0),
0378       dp_glb_(0),
0379       qoverpt1_glb_(0),
0380       qoverpt2_glb_(0),
0381       dqoverpt_glb_(0),
0382       norchi1_glb_(0),
0383       norchi2_glb_(0),
0384 
0385       dxy1Err_glb_(0),
0386       dxy2Err_glb_(0),
0387       dz1Err_glb_(0),
0388       dz2Err_glb_(0),
0389       theta1Err_glb_(0),
0390       theta2Err_glb_(0),
0391       eta1Err_glb_(0),
0392       eta2Err_glb_(0),
0393       phi1Err_glb_(0),
0394       phi2Err_glb_(0),
0395       pt1Err_glb_(0),
0396       pt2Err_glb_(0),
0397       qoverpt1Err_glb_(0),
0398       qoverpt2Err_glb_(0),
0399 
0400       dcaX_orm_(0),
0401       dcaY_orm_(0),
0402       dcaZ_orm_(0),
0403       dxy_orm_(0),
0404       dz_orm_(0),
0405       theta_orm_(0),
0406       eta_orm_(0),
0407       phi_orm_(0),
0408       pt_orm_(0),
0409       p_orm_(0),
0410       qoverpt_orm_(0),
0411       norchi2_orm_(0),
0412       dxyErr_orm_(0),
0413       dzErr_orm_(0),
0414       thetaErr_orm_(0),
0415       etaErr_orm_(0),
0416       phiErr_orm_(0),
0417       ptErr_orm_(0),
0418       qoverptErr_orm_(0) {
0419   usesResource(TFileService::kSharedResource);
0420   edm::ConsumesCollector&& iC = consumesCollector();
0421   splitTracksToken_ = iC.consumes<std::vector<reco::Track>>(splitTracks_);
0422   originalTracksToken_ = iC.consumes<std::vector<reco::Track>>(originalTracks_);
0423   if (splitMuons_) {
0424     splitGlobalMuonsToken_ = iC.consumes<reco::MuonCollection>(splitGlobalMuons_);
0425     originalGlobalMuonsToken_ = iC.consumes<reco::MuonCollection>(originalGlobalMuons_);
0426   }
0427   if (checkIfGolden_)
0428     STAMuonsToken_ = iC.consumes<reco::MuonCollection>(edm::InputTag("STAMuons"));
0429 }
0430 
0431 void CosmicSplitterValidation::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0432   edm::ParameterSetDescription desc;
0433   desc.setComment("Validates alignment payloads by comparing split cosmic tracks parameters");
0434   desc.addUntracked<int>("compressionSettings", -1);
0435   desc.add<edm::InputTag>("splitTracks", edm::InputTag("FinalTrackRefitter", "", "splitter"));
0436   desc.add<edm::InputTag>("splitGlobalMuons", edm::InputTag("muons", "", "splitter"));
0437   desc.add<edm::InputTag>("originalTracks", edm::InputTag("FirstTrackRefitter", "", "splitter"));
0438   desc.add<edm::InputTag>("originalGlobalMuons", edm::InputTag("muons", "", "Rec"));
0439   desc.add<bool>("checkIfGolden", false);
0440   desc.add<bool>("ifSplitMuons", false);
0441   descriptions.addWithDefaultLabel(desc);
0442 }
0443 
0444 //
0445 // member functions
0446 //
0447 
0448 // ------------ method called to for each event  ------------
0449 void CosmicSplitterValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0450   // check if golden muon
0451   bool isGolden = true;
0452   if (checkIfGolden_)
0453     isGolden = is_gold_muon(iEvent);
0454 
0455   // grab collections
0456   edm::Handle<std::vector<reco::Track>> tracks;
0457   edm::Handle<std::vector<reco::Track>> originalTracks;
0458   edm::Handle<reco::MuonCollection> globalMuons;
0459   edm::Handle<reco::MuonCollection> originalGlobalMuons;
0460   iEvent.getByToken(splitTracksToken_, tracks);
0461   iEvent.getByToken(originalTracksToken_, originalTracks);
0462   if (splitMuons_) {
0463     iEvent.getByToken(splitGlobalMuonsToken_, globalMuons);
0464     iEvent.getByToken(originalGlobalMuonsToken_, originalGlobalMuons);
0465   }
0466 
0467   const int kBPIX = PixelSubdetector::PixelBarrel;
0468   const int kFPIX = PixelSubdetector::PixelEndcap;
0469 
0470   totalTracksToAnalyzer_ = totalTracksToAnalyzer_ + tracks->size();
0471   if (isGolden)
0472     goldenCtr++;
0473   if (tracks->size() == 2)
0474     twoTracksCtr++;
0475   if (tracks->size() == 2 && originalTracks->size() == 1 && isGolden) {
0476     goldenPlusTwoTracksCtr++;
0477 
0478     int gmCtr = 0;
0479     bool topGlobalMuonFlag = false;
0480     bool bottomGlobalMuonFlag = false;
0481     int topGlobalMuon = -1;
0482     int bottomGlobalMuon = -1;
0483     double topGlobalMuonNorchi2 = 1e10;
0484     double bottomGlobalMuonNorchi2 = 1e10;
0485 
0486     if (splitMuons_) {
0487       // check if split global muons are good
0488       for (std::vector<reco::Muon>::const_iterator gmI = globalMuons->begin(); gmI != globalMuons->end(); gmI++) {
0489         if (gmI->isTrackerMuon() && gmI->isStandAloneMuon() && gmI->isGlobalMuon()) {
0490           reco::TrackRef trackerTrackRef1(tracks, 0);
0491           reco::TrackRef trackerTrackRef2(tracks, 1);
0492 
0493           if (gmI->innerTrack() == trackerTrackRef1) {
0494             if (gmI->globalTrack()->normalizedChi2() < topGlobalMuonNorchi2) {
0495               topGlobalMuonFlag = true;
0496               topGlobalMuonNorchi2 = gmI->globalTrack()->normalizedChi2();
0497               topGlobalMuon = gmCtr;
0498             }
0499           }
0500           if (gmI->innerTrack() == trackerTrackRef2) {
0501             if (gmI->globalTrack()->normalizedChi2() < bottomGlobalMuonNorchi2) {
0502               bottomGlobalMuonFlag = true;
0503               bottomGlobalMuonNorchi2 = gmI->globalTrack()->normalizedChi2();
0504               bottomGlobalMuon = gmCtr;
0505             }
0506           }
0507         }
0508         gmCtr++;
0509       }
0510     }
0511 
0512     if ((!splitMuons_) || (splitMuons_ && bottomGlobalMuonFlag && topGlobalMuonFlag)) {
0513       _passesTracksPlusMuonsCuts++;
0514 
0515       // split tracks calculations
0516       reco::Track track1 = tracks->at(0);
0517       reco::Track track2 = tracks->at(1);
0518 
0519       const math::XYZPoint& dca1 = track1.referencePoint();
0520       const math::XYZPoint& dca2 = track2.referencePoint();
0521 
0522       // looping through the hits for track 1
0523       int Nrechits1 = 0;
0524       int nhitinTIB1 = 0;
0525       int nhitinTOB1 = 0;
0526       int nhitinTID1 = 0;
0527       int nhitinTEC1 = 0;
0528       int nhitinBPIX1 = 0;
0529       int nhitinFPIX1 = 0;
0530       for (auto const& hit : track1.recHits()) {
0531         if (hit->isValid()) {
0532           Nrechits1++;
0533 
0534           int type = hit->geographicalId().subdetId();
0535 
0536           if (type == int(StripSubdetector::TIB)) {
0537             ++nhitinTIB1;
0538           }
0539           if (type == int(StripSubdetector::TOB)) {
0540             ++nhitinTOB1;
0541           }
0542           if (type == int(StripSubdetector::TID)) {
0543             ++nhitinTID1;
0544           }
0545           if (type == int(StripSubdetector::TEC)) {
0546             ++nhitinTEC1;
0547           }
0548           if (type == int(kBPIX)) {
0549             ++nhitinBPIX1;
0550           }
0551           if (type == int(kFPIX)) {
0552             ++nhitinFPIX1;
0553           }
0554         }
0555       }
0556       nHits1_spl_ = Nrechits1;
0557       nHitsTIB1_spl_ = nhitinTIB1;
0558       nHitsTOB1_spl_ = nhitinTOB1;
0559       nHitsTID1_spl_ = nhitinTID1;
0560       nHitsTEC1_spl_ = nhitinTEC1;
0561       nHitsPXB1_spl_ = nhitinBPIX1;
0562       nHitsPXF1_spl_ = nhitinFPIX1;
0563 
0564       // looping through the hits for track 2
0565       int Nrechits2 = 0;
0566       int nhitinTIB2 = 0;
0567       int nhitinTOB2 = 0;
0568       int nhitinTID2 = 0;
0569       int nhitinTEC2 = 0;
0570       int nhitinBPIX2 = 0;
0571       int nhitinFPIX2 = 0;
0572       for (auto const& hit : track2.recHits()) {
0573         if (hit->isValid()) {
0574           Nrechits2++;
0575 
0576           int type = hit->geographicalId().subdetId();
0577 
0578           if (type == int(StripSubdetector::TIB)) {
0579             ++nhitinTIB2;
0580           }
0581           if (type == int(StripSubdetector::TOB)) {
0582             ++nhitinTOB2;
0583           }
0584           if (type == int(StripSubdetector::TID)) {
0585             ++nhitinTID2;
0586           }
0587           if (type == int(StripSubdetector::TEC)) {
0588             ++nhitinTEC2;
0589           }
0590           if (type == int(kBPIX)) {
0591             ++nhitinBPIX2;
0592           }
0593           if (type == int(kFPIX)) {
0594             ++nhitinFPIX2;
0595           }
0596         }
0597       }
0598       nHits2_spl_ = Nrechits2;
0599       nHitsTIB2_spl_ = nhitinTIB2;
0600       nHitsTOB2_spl_ = nhitinTOB2;
0601       nHitsTID2_spl_ = nhitinTID2;
0602       nHitsTEC2_spl_ = nhitinTEC2;
0603       nHitsPXB2_spl_ = nhitinBPIX2;
0604       nHitsPXF2_spl_ = nhitinFPIX2;
0605 
0606       double ddxy_Val = track1.d0() - track2.d0();
0607       double ddz_Val = track1.dz() - track2.dz();
0608       double dtheta_Val = track1.theta() - track2.theta();
0609       double deta_Val = track1.eta() - track2.eta();
0610       double dphi_Val = track1.phi() - track2.phi();
0611       double dpt_Val = track1.pt() - track2.pt();
0612       double dp_Val = track1.p() - track2.p();
0613       double dqoverpt_Val = track1.charge() / track1.pt() - track2.charge() / track2.pt();
0614 
0615       // original tracks calculations
0616       reco::Track origTrack = originalTracks->at(0);
0617       const math::XYZPoint& dca_org = origTrack.referencePoint();
0618 
0619       // looping through the hits for the original track
0620       int Nrechitsorg = 0;
0621       int nhitinTIBorg = 0;
0622       int nhitinTOBorg = 0;
0623       int nhitinTIDorg = 0;
0624       int nhitinTECorg = 0;
0625       int nhitinBPIXorg = 0;
0626       int nhitinFPIXorg = 0;
0627       for (auto const& hit : origTrack.recHits()) {
0628         if (hit->isValid()) {
0629           Nrechitsorg++;
0630 
0631           int type = hit->geographicalId().subdetId();
0632 
0633           if (type == int(StripSubdetector::TIB)) {
0634             ++nhitinTIBorg;
0635           }
0636           if (type == int(StripSubdetector::TOB)) {
0637             ++nhitinTOBorg;
0638           }
0639           if (type == int(StripSubdetector::TID)) {
0640             ++nhitinTIDorg;
0641           }
0642           if (type == int(StripSubdetector::TEC)) {
0643             ++nhitinTECorg;
0644           }
0645           if (type == int(kBPIX)) {
0646             ++nhitinBPIXorg;
0647           }
0648           if (type == int(kFPIX)) {
0649             ++nhitinFPIXorg;
0650           }
0651         }
0652       }
0653       nHits_org_ = Nrechitsorg;
0654       nHitsTIB_org_ = nhitinTIBorg;
0655       nHitsTOB_org_ = nhitinTOBorg;
0656       nHitsTID_org_ = nhitinTIDorg;
0657       nHitsTEC_org_ = nhitinTECorg;
0658       nHitsPXB_org_ = nhitinBPIXorg;
0659       nHitsPXF_org_ = nhitinFPIXorg;
0660 
0661       // fill tree
0662       runNumber_ = iEvent.id().run();
0663       luminosityBlock_ = iEvent.id().luminosityBlock();
0664       eventNumber_ = iEvent.id().event();
0665       // split tracks
0666       dcaX1_spl_ = dca1.x();
0667       dcaY1_spl_ = dca1.y();
0668       dcaZ1_spl_ = dca1.z();
0669       dcaX2_spl_ = dca2.x();
0670       dcaY2_spl_ = dca2.y();
0671       dcaZ2_spl_ = dca2.z();
0672       dxy1_spl_ = track1.d0();
0673       dxy2_spl_ = track2.d0();
0674       ddxy_spl_ = ddxy_Val;
0675       dz1_spl_ = track1.dz();
0676       dz2_spl_ = track2.dz();
0677       ddz_spl_ = ddz_Val;
0678       theta1_spl_ = track1.theta();
0679       theta2_spl_ = track2.theta();
0680       dtheta_spl_ = dtheta_Val;
0681       eta1_spl_ = track1.eta();
0682       eta2_spl_ = track2.eta();
0683       deta_spl_ = deta_Val;
0684       phi1_spl_ = track1.phi();
0685       phi2_spl_ = track2.phi();
0686       dphi_spl_ = dphi_Val;
0687       pt1_spl_ = track1.pt();
0688       pt2_spl_ = track2.pt();
0689       dpt_spl_ = dpt_Val;
0690       p1_spl_ = track1.p();
0691       p2_spl_ = track2.p();
0692       dp_spl_ = dp_Val;
0693       qoverpt1_spl_ = track1.charge() / track1.pt();
0694       qoverpt2_spl_ = track2.charge() / track2.pt();
0695       dqoverpt_spl_ = dqoverpt_Val;
0696       dxy1Err_spl_ = track1.d0Error();
0697       dxy2Err_spl_ = track2.d0Error();
0698       dz1Err_spl_ = track1.dzError();
0699       dz2Err_spl_ = track2.dzError();
0700       theta1Err_spl_ = track1.thetaError();
0701       theta2Err_spl_ = track2.thetaError();
0702       eta1Err_spl_ = track1.etaError();
0703       eta2Err_spl_ = track2.etaError();
0704       phi1Err_spl_ = track1.phiError();
0705       phi2Err_spl_ = track2.phiError();
0706       pt1Err_spl_ = track1.ptError();
0707       pt2Err_spl_ = track2.ptError();
0708       qoverpt1Err_spl_ = qoverpt1_spl_ * pt1Err_spl_ / pt1_spl_;
0709       qoverpt2Err_spl_ = qoverpt2_spl_ * pt2Err_spl_ / pt2_spl_;
0710 
0711       // original tracks
0712       dcaX_org_ = dca_org.x();
0713       dcaY_org_ = dca_org.y();
0714       dcaZ_org_ = dca_org.z();
0715       dxy_org_ = origTrack.d0();
0716       dz_org_ = origTrack.dz();
0717       theta_org_ = origTrack.theta();
0718       eta_org_ = origTrack.eta();
0719       phi_org_ = origTrack.phi();
0720       pt_org_ = origTrack.pt();
0721       p_org_ = origTrack.p();
0722       qoverpt_org_ = origTrack.charge() / origTrack.pt();
0723       norchi2_org_ = origTrack.normalizedChi2();
0724 
0725       dxyErr_org_ = origTrack.d0Error();
0726       dzErr_org_ = origTrack.dzError();
0727       thetaErr_org_ = origTrack.thetaError();
0728       etaErr_org_ = origTrack.etaError();
0729       phiErr_org_ = origTrack.phiError();
0730       ptErr_org_ = origTrack.ptError();
0731       qoverptErr_org_ = qoverpt_org_ * ptErr_org_ / pt_org_;
0732 
0733       // split muons calculations
0734       if (splitMuons_) {
0735         reco::Muon muonTop = globalMuons->at(topGlobalMuon);
0736         reco::Muon muonBottom = globalMuons->at(bottomGlobalMuon);
0737 
0738         reco::TrackRef glb1 = muonTop.globalTrack();
0739         reco::TrackRef glb2 = muonBottom.globalTrack();
0740         reco::TrackRef sta1 = muonTop.outerTrack();
0741         reco::TrackRef sta2 = muonBottom.outerTrack();
0742 
0743         // standalone muon variables
0744         dcaX1_sta_ = sta1->referencePoint().x();
0745         dcaY1_sta_ = sta1->referencePoint().y();
0746         dcaZ1_sta_ = sta1->referencePoint().z();
0747         dcaX2_sta_ = sta2->referencePoint().x();
0748         dcaY2_sta_ = sta2->referencePoint().y();
0749         dcaZ2_sta_ = sta2->referencePoint().z();
0750         dxy1_sta_ = sta1->d0();
0751         dxy2_sta_ = sta2->d0();
0752         ddxy_sta_ = sta1->d0() - sta2->d0();
0753         dz1_sta_ = sta1->dz();
0754         dz2_sta_ = sta2->dz();
0755         ddz_sta_ = sta1->dz() - sta2->dz();
0756         theta1_sta_ = sta1->theta();
0757         theta2_sta_ = sta2->theta();
0758         dtheta_sta_ = sta1->theta() - sta2->theta();
0759         eta1_sta_ = sta1->eta();
0760         eta2_sta_ = sta2->eta();
0761         deta_sta_ = eta1_sta_ - eta2_sta_;
0762         phi1_sta_ = sta1->phi();
0763         phi2_sta_ = sta2->phi();
0764         dphi_sta_ = sta1->phi() - sta2->phi();
0765         pt1_sta_ = sta1->pt();
0766         pt2_sta_ = sta2->pt();
0767         dpt_sta_ = sta1->pt() - sta2->pt();
0768         p1_sta_ = sta1->p();
0769         p2_sta_ = sta2->p();
0770         dp_sta_ = sta1->p() - sta2->p();
0771         qoverpt1_sta_ = sta1->charge() / sta1->pt();
0772         qoverpt2_sta_ = sta2->charge() / sta2->pt();
0773         dqoverpt_sta_ = qoverpt1_sta_ - qoverpt2_sta_;
0774         dxy1Err_sta_ = sta1->dxyError();
0775         dxy2Err_sta_ = sta2->dxyError();
0776         dz1Err_sta_ = sta1->dzError();
0777         dz2Err_sta_ = sta2->dzError();
0778         theta1Err_sta_ = sta1->thetaError();
0779         theta2Err_sta_ = sta2->thetaError();
0780         eta1Err_sta_ = sta1->etaError();
0781         eta2Err_sta_ = sta2->etaError();
0782         phi1Err_sta_ = sta1->phiError();
0783         phi2Err_sta_ = sta2->phiError();
0784         pt1Err_sta_ = sta1->ptError();
0785         pt2Err_sta_ = sta2->ptError();
0786         qoverpt1Err_sta_ = qoverpt1_sta_ * pt1Err_sta_ / pt1_sta_;
0787         qoverpt2Err_sta_ = qoverpt2_sta_ * pt2Err_sta_ / pt2_sta_;
0788 
0789         // global muon variables
0790         dcaX1_glb_ = glb1->referencePoint().x();
0791         dcaY1_glb_ = glb1->referencePoint().y();
0792         dcaZ1_glb_ = glb1->referencePoint().z();
0793         dcaX2_glb_ = glb2->referencePoint().x();
0794         dcaY2_glb_ = glb2->referencePoint().y();
0795         dcaZ2_glb_ = glb2->referencePoint().z();
0796         dxy1_glb_ = glb1->d0();
0797         dxy2_glb_ = glb2->d0();
0798         ddxy_glb_ = glb1->d0() - glb2->d0();
0799         dz1_glb_ = glb1->dz();
0800         dz2_glb_ = glb2->dz();
0801         ddz_glb_ = glb1->dz() - glb2->dz();
0802         theta1_glb_ = glb1->theta();
0803         theta2_glb_ = glb2->theta();
0804         dtheta_glb_ = glb1->theta() - glb2->theta();
0805         eta1_glb_ = glb1->eta();
0806         eta2_glb_ = glb2->eta();
0807         deta_glb_ = eta1_glb_ - eta2_glb_;
0808         phi1_glb_ = glb1->phi();
0809         phi2_glb_ = glb2->phi();
0810         dphi_glb_ = glb1->phi() - glb2->phi();
0811         pt1_glb_ = glb1->pt();
0812         pt2_glb_ = glb2->pt();
0813         dpt_glb_ = glb1->pt() - glb2->pt();
0814         p1_glb_ = glb1->p();
0815         p2_glb_ = glb2->p();
0816         dp_glb_ = glb1->p() - glb2->p();
0817         qoverpt1_glb_ = glb1->charge() / glb1->pt();
0818         qoverpt2_glb_ = glb2->charge() / glb2->pt();
0819         dqoverpt_glb_ = qoverpt1_glb_ - qoverpt2_glb_;
0820         norchi1_glb_ = glb1->normalizedChi2();
0821         norchi2_glb_ = glb2->normalizedChi2();
0822 
0823         dxy1Err_glb_ = glb1->d0Error();
0824         dxy2Err_glb_ = glb2->d0Error();
0825         dz1Err_glb_ = glb1->dzError();
0826         dz2Err_glb_ = glb2->dzError();
0827         theta1Err_glb_ = glb1->thetaError();
0828         theta2Err_glb_ = glb2->thetaError();
0829         eta1Err_glb_ = glb1->etaError();
0830         eta2Err_glb_ = glb2->etaError();
0831         phi1Err_glb_ = glb1->phiError();
0832         phi2Err_glb_ = glb2->phiError();
0833         pt1Err_glb_ = glb1->ptError();
0834         pt2Err_glb_ = glb2->ptError();
0835         qoverpt1Err_glb_ = qoverpt1_glb_ * pt1Err_glb_ / pt1_glb_;
0836         qoverpt2Err_glb_ = qoverpt2_glb_ * pt2Err_glb_ / pt2_glb_;
0837       }
0838 
0839       splitterTree_->Fill();
0840     }
0841   }
0842 }
0843 
0844 // ------------ method called once each job just before starting event loop  ------------
0845 void CosmicSplitterValidation::beginJob() {
0846   edm::LogInfo("beginJob") << "Begin Job" << std::endl;
0847 
0848   if (compressionSettings_ > 0) {
0849     tfile->file().SetCompressionSettings(compressionSettings_);
0850   }
0851 
0852   splitterTree_ = tfile->make<TTree>("splitterTree", "splitterTree");
0853 
0854   splitterTree_->Branch("runNumber", &runNumber_, "runNumber/I");
0855   splitterTree_->Branch("eventNumber", &eventNumber_, "eventNumber/I");
0856   splitterTree_->Branch("luminosityBlock", &luminosityBlock_, "luminosityBlock/I");
0857 
0858   // split track variables
0859   splitterTree_->Branch("dcaX1_spl", &dcaX1_spl_, "dcaX1_spl/D");
0860   splitterTree_->Branch("dcaY1_spl", &dcaY1_spl_, "dcaY1_spl/D");
0861   splitterTree_->Branch("dcaZ1_spl", &dcaZ1_spl_, "dcaZ1_spl/D");
0862   splitterTree_->Branch("dcaX2_spl", &dcaX2_spl_, "dcaX2_spl/D");
0863   splitterTree_->Branch("dcaY2_spl", &dcaY2_spl_, "dcaY2_spl/D");
0864   splitterTree_->Branch("dcaZ2_spl", &dcaZ2_spl_, "dcaZ2_spl/D");
0865   splitterTree_->Branch("dxy1_spl", &dxy1_spl_, "dxy1_spl/D");
0866   splitterTree_->Branch("dxy2_spl", &dxy2_spl_, "dxy2_spl/D");
0867   splitterTree_->Branch("dz1_spl", &dz1_spl_, "dz1_spl/D");
0868   splitterTree_->Branch("dz2_spl", &dz2_spl_, "dz2_spl/D");
0869   splitterTree_->Branch("theta1_spl", &theta1_spl_, "theta1_spl/D");
0870   splitterTree_->Branch("theta2_spl", &theta2_spl_, "theta2_spl/D");
0871   splitterTree_->Branch("eta1_spl", &eta1_spl_, "eta1_spl/D");
0872   splitterTree_->Branch("eta2_spl", &eta2_spl_, "eta2_spl/D");
0873   splitterTree_->Branch("phi1_spl", &phi1_spl_, "phi1_spl/D");
0874   splitterTree_->Branch("phi2_spl", &phi2_spl_, "phi2_spl/D");
0875   splitterTree_->Branch("pt1_spl", &pt1_spl_, "pt1_spl/D");
0876   splitterTree_->Branch("pt2_spl", &pt2_spl_, "pt2_spl/D");
0877   splitterTree_->Branch("p1_spl", &p1_spl_, "p1_spl/D");
0878   splitterTree_->Branch("p2_spl", &p2_spl_, "p2_spl/D");
0879   splitterTree_->Branch("qoverpt1_spl", &qoverpt1_spl_, "qoverpt1_spl/D");
0880   splitterTree_->Branch("qoverpt2_spl", &qoverpt2_spl_, "qoverpt2_spl/D");
0881   splitterTree_->Branch("nHits1_spl", &nHits1_spl_, "nHits1_spl/I");
0882   splitterTree_->Branch("nHitsPXB1_spl", &nHitsPXB1_spl_, "nHitsPXB1_spl/I");
0883   splitterTree_->Branch("nHitsPXF1_spl", &nHitsPXF1_spl_, "nHitsPXF1_spl/I");
0884   splitterTree_->Branch("nHitsTIB1_spl", &nHitsTIB1_spl_, "nHitsTIB1_spl/I");
0885   splitterTree_->Branch("nHitsTOB1_spl", &nHitsTOB1_spl_, "nHitsTOB1_spl/I");
0886   splitterTree_->Branch("nHitsTID1_spl", &nHitsTID1_spl_, "nHitsTID1_spl/I");
0887   splitterTree_->Branch("nHitsTEC1_spl", &nHitsTEC1_spl_, "nHitsTEC1_spl/I");
0888   splitterTree_->Branch("nHits2_spl", &nHits2_spl_, "nHits2_spl/I");
0889   splitterTree_->Branch("nHitsPXB2_spl", &nHitsPXB2_spl_, "nHitsPXB2_spl/I");
0890   splitterTree_->Branch("nHitsPXF2_spl", &nHitsPXF2_spl_, "nHitsPXF2_spl/I");
0891   splitterTree_->Branch("nHitsTIB2_spl", &nHitsTIB2_spl_, "nHitsTIB2_spl/I");
0892   splitterTree_->Branch("nHitsTOB2_spl", &nHitsTOB2_spl_, "nHitsTOB2_spl/I");
0893   splitterTree_->Branch("nHitsTID2_spl", &nHitsTID2_spl_, "nHitsTID2_spl/I");
0894   splitterTree_->Branch("nHitsTEC2_spl", &nHitsTEC2_spl_, "nHitsTEC2_spl/I");
0895 
0896   splitterTree_->Branch("dxy1Err_spl", &dxy1Err_spl_, "dxy1Err_spl/D");
0897   splitterTree_->Branch("dxy2Err_spl", &dxy2Err_spl_, "dxy2Err_spl/D");
0898   splitterTree_->Branch("dz1Err_spl", &dz1Err_spl_, "dz1Err_spl/D");
0899   splitterTree_->Branch("dz2Err_spl", &dz2Err_spl_, "dz2Err_spl/D");
0900   splitterTree_->Branch("theta1Err_spl", &theta1Err_spl_, "theta1Err_spl/D");
0901   splitterTree_->Branch("theta2Err_spl", &theta2Err_spl_, "theta2Err_spl/D");
0902   splitterTree_->Branch("eta1Err_spl", &eta1Err_spl_, "eta1Err_spl/D");
0903   splitterTree_->Branch("eta2Err_spl", &eta2Err_spl_, "eta2Err_spl/D");
0904   splitterTree_->Branch("phi1Err_spl", &phi1Err_spl_, "phi1Err_spl/D");
0905   splitterTree_->Branch("phi2Err_spl", &phi2Err_spl_, "phi2Err_spl/D");
0906   splitterTree_->Branch("pt1Err_spl", &pt1Err_spl_, "pt1Err_spl/D");
0907   splitterTree_->Branch("pt2Err_spl", &pt2Err_spl_, "pt2Err_spl/D");
0908   splitterTree_->Branch("qoverpt1Err_spl", &qoverpt1Err_spl_, "qoverpt1Err_spl/D");
0909   splitterTree_->Branch("qoverpt2Err_spl", &qoverpt2Err_spl_, "qoverpt2Err_spl/D");
0910 
0911   splitterTree_->Branch("dcaX_org", &dcaX_org_, "dcaX_org/D");
0912   splitterTree_->Branch("dcaY_org", &dcaY_org_, "dcaY_org/D");
0913   splitterTree_->Branch("dcaZ_org", &dcaZ_org_, "dcaZ_org/D");
0914   splitterTree_->Branch("dxy_org", &dxy_org_, "dxy_org/D");
0915   splitterTree_->Branch("dz_org", &dz_org_, "dz_org/D");
0916   splitterTree_->Branch("theta_org", &theta_org_, "theta_org/D");
0917   splitterTree_->Branch("eta_org", &eta_org_, "eta_org/D");
0918   splitterTree_->Branch("phi_org", &phi_org_, "phi_org/D");
0919   splitterTree_->Branch("pt_org", &pt_org_, "pt_org/D");
0920   splitterTree_->Branch("p_org", &p_org_, "p_org/D");
0921   splitterTree_->Branch("qoverpt_org", &qoverpt_org_, "qoverpt_org/D");
0922   splitterTree_->Branch("norchi2_org", &norchi2_org_, "norchi2_org/D");
0923 
0924   splitterTree_->Branch("nHits_org", &nHits_org_, "nHits_org/I");
0925   splitterTree_->Branch("nHitsPXB_org", &nHitsPXB_org_, "nHitsPXB_org/I");
0926   splitterTree_->Branch("nHitsPXF_org", &nHitsPXF_org_, "nHitsPXF_org/I");
0927   splitterTree_->Branch("nHitsTIB_org", &nHitsTIB_org_, "nHitsTIB_org/I");
0928   splitterTree_->Branch("nHitsTOB_org", &nHitsTOB_org_, "nHitsTOB_org/I");
0929   splitterTree_->Branch("nHitsTID_org", &nHitsTID_org_, "nHitsTID_org/I");
0930   splitterTree_->Branch("nHitsTEC_org", &nHitsTEC_org_, "nHitsTEC_org/I");
0931 
0932   splitterTree_->Branch("dxyErr_org", &dxyErr_org_, "dxyErr_org/D");
0933   splitterTree_->Branch("dzErr_org", &dzErr_org_, "dzErr_org/D");
0934   splitterTree_->Branch("thetaErr_org", &thetaErr_org_, "thetaErr_org/D");
0935   splitterTree_->Branch("etaErr_org", &etaErr_org_, "etaErr_org/D");
0936   splitterTree_->Branch("phiErr_org", &phiErr_org_, "phiErr_org/D");
0937   splitterTree_->Branch("ptErr_org", &ptErr_org_, "ptErr_org/D");
0938   splitterTree_->Branch("qoverptErr_org", &qoverptErr_org_, "qoverptErr_org/D");
0939 
0940   //put the Deltas at the end of the tree, since they're the focus of the validation.
0941   //this way, if you use splitterTree->Show(), they are immediately visible
0942   splitterTree_->Branch("Delta_dxy", &ddxy_spl_, "Delta_dxy/D");
0943   splitterTree_->Branch("Delta_dz", &ddz_spl_, "Delta_dz/D");
0944   splitterTree_->Branch("Delta_theta", &dtheta_spl_, "Delta_theta/D");
0945   splitterTree_->Branch("Delta_eta", &deta_spl_, "Delta_eta/D");
0946   splitterTree_->Branch("Delta_phi", &dphi_spl_, "Delta_phi/D");
0947   splitterTree_->Branch("Delta_pt", &dpt_spl_, "Delta_pt/D");
0948   splitterTree_->Branch("Delta_p", &dp_spl_, "Delta_p/D");
0949   splitterTree_->Branch("Delta_qoverpt", &dqoverpt_spl_, "Delta_qoverpt/D");
0950 
0951   if (splitMuons_) {
0952     // standalone split
0953     splitterTree_->Branch("dcaX1_sta", &dcaX1_sta_, "dcaX1_sta/D");
0954     splitterTree_->Branch("dcaY1_sta", &dcaY1_sta_, "dcaY1_sta/D");
0955     splitterTree_->Branch("dcaZ1_sta", &dcaZ1_sta_, "dcaZ1_sta/D");
0956     splitterTree_->Branch("dcaX2_sta", &dcaX2_sta_, "dcaX2_sta/D");
0957     splitterTree_->Branch("dcaY2_sta", &dcaY2_sta_, "dcaY2_sta/D");
0958     splitterTree_->Branch("dcaZ2_sta", &dcaZ2_sta_, "dcaZ2_sta/D");
0959     splitterTree_->Branch("dxy1_sta", &dxy1_sta_, "dxy1_sta/D");
0960     splitterTree_->Branch("dxy2_sta", &dxy2_sta_, "dxy2_sta/D");
0961     splitterTree_->Branch("ddxy_sta", &ddxy_sta_, "ddxy_sta/D");
0962     splitterTree_->Branch("dz1_sta", &dz1_sta_, "dz1_sta/D");
0963     splitterTree_->Branch("dz2_sta", &dz2_sta_, "dz2_sta/D");
0964     splitterTree_->Branch("ddz_sta", &ddz_sta_, "ddz_sta/D");
0965     splitterTree_->Branch("theta1_sta", &theta1_sta_, "theta1_sta/D");
0966     splitterTree_->Branch("theta2_sta", &theta2_sta_, "theta2_sta/D");
0967     splitterTree_->Branch("dtheta_sta", &dtheta_sta_, "dtheta_sta/D");
0968     splitterTree_->Branch("eta1_sta", &eta1_sta_, "eta1_sta/D");
0969     splitterTree_->Branch("eta2_sta", &eta2_sta_, "eta2_sta/D");
0970     splitterTree_->Branch("deta_sta", &deta_sta_, "deta_sta/D");
0971     splitterTree_->Branch("phi1_sta", &phi1_sta_, "phi1_sta/D");
0972     splitterTree_->Branch("phi2_sta", &phi2_sta_, "phi2_sta/D");
0973     splitterTree_->Branch("dphi_sta", &dphi_sta_, "dphi_sta/D");
0974     splitterTree_->Branch("pt1_sta", &pt1_sta_, "pt1_sta/D");
0975     splitterTree_->Branch("pt2_sta", &pt2_sta_, "pt2_sta/D");
0976     splitterTree_->Branch("dpt_sta", &dpt_sta_, "dpt_sta/D");
0977     splitterTree_->Branch("p1_sta", &p1_sta_, "p1_sta/D");
0978     splitterTree_->Branch("p2_sta", &p2_sta_, "p2_sta/D");
0979     splitterTree_->Branch("dp_sta", &dp_sta_, "dp_sta/D");
0980 
0981     splitterTree_->Branch("dxy1Err_sta", &dxy1Err_sta_, "dxy1Err_sta/D");
0982     splitterTree_->Branch("dxy2Err_sta", &dxy2Err_sta_, "dxy2Err_sta/D");
0983     splitterTree_->Branch("dz1Err_sta", &dz1Err_sta_, "dz1Err_sta/D");
0984     splitterTree_->Branch("dz2Err_sta", &dz2Err_sta_, "dz2Err_sta/D");
0985     splitterTree_->Branch("theta1Err_sta", &theta1Err_sta_, "theta1Err_sta/D");
0986     splitterTree_->Branch("theta2Err_sta", &theta2Err_sta_, "theta2Err_sta/D");
0987     splitterTree_->Branch("eta1Err_sta", &eta1Err_sta_, "eta1Err_sta/D");
0988     splitterTree_->Branch("eta2Err_sta", &eta2Err_sta_, "eta2Err_sta/D");
0989     splitterTree_->Branch("phi1Err_sta", &phi1Err_sta_, "phi1Err_sta/D");
0990     splitterTree_->Branch("phi2Err_sta", &phi2Err_sta_, "phi2Err_sta/D");
0991     splitterTree_->Branch("pt1Err_sta", &pt1Err_sta_, "pt1Err_sta/D");
0992     splitterTree_->Branch("pt2Err_sta", &pt2Err_sta_, "pt2Err_sta/D");
0993     splitterTree_->Branch("qoverpt1Err_sta", &qoverpt1Err_sta_, "qoverpt1Err_sta/D");
0994     splitterTree_->Branch("qoverpt2Err_sta", &qoverpt2Err_sta_, "qoverpt2Err_sta/D");
0995 
0996     // global split
0997     splitterTree_->Branch("dcaX1_glb", &dcaX1_glb_, "dcaX1_glb/D");
0998     splitterTree_->Branch("dcaY1_glb", &dcaY1_glb_, "dcaY1_glb/D");
0999     splitterTree_->Branch("dcaZ1_glb", &dcaZ1_glb_, "dcaZ1_glb/D");
1000     splitterTree_->Branch("dcaX2_glb", &dcaX2_glb_, "dcaX2_glb/D");
1001     splitterTree_->Branch("dcaY2_glb", &dcaY2_glb_, "dcaY2_glb/D");
1002     splitterTree_->Branch("dcaZ2_glb", &dcaZ2_glb_, "dcaZ2_glb/D");
1003     splitterTree_->Branch("dxy1_glb", &dxy1_glb_, "dxy1_glb/D");
1004     splitterTree_->Branch("dxy2_glb", &dxy2_glb_, "dxy2_glb/D");
1005     splitterTree_->Branch("ddxy_glb", &ddxy_glb_, "ddxy_glb/D");
1006     splitterTree_->Branch("dz1_glb", &dz1_glb_, "dz1_glb/D");
1007     splitterTree_->Branch("dz2_glb", &dz2_glb_, "dz2_glb/D");
1008     splitterTree_->Branch("ddz_glb", &ddz_glb_, "ddz_glb/D");
1009     splitterTree_->Branch("theta1_glb", &theta1_glb_, "theta1_glb/D");
1010     splitterTree_->Branch("theta2_glb", &theta2_glb_, "theta2_glb/D");
1011     splitterTree_->Branch("dtheta_glb", &dtheta_glb_, "dtheta_glb/D");
1012     splitterTree_->Branch("eta1_glb", &eta1_glb_, "eta1_glb/D");
1013     splitterTree_->Branch("eta2_glb", &eta2_glb_, "eta2_glb/D");
1014     splitterTree_->Branch("deta_glb", &deta_glb_, "deta_glb/D");
1015     splitterTree_->Branch("phi1_glb", &phi1_glb_, "phi1_glb/D");
1016     splitterTree_->Branch("phi2_glb", &phi2_glb_, "phi2_glb/D");
1017     splitterTree_->Branch("dphi_glb", &dphi_glb_, "dphi_glb/D");
1018     splitterTree_->Branch("pt1_glb", &pt1_glb_, "pt1_glb/D");
1019     splitterTree_->Branch("pt2_glb", &pt2_glb_, "pt2_glb/D");
1020     splitterTree_->Branch("dpt_glb", &dpt_glb_, "dpt_glb/D");
1021     splitterTree_->Branch("p1_glb", &p1_glb_, "p1_glb/D");
1022     splitterTree_->Branch("p2_glb", &p2_glb_, "p2_glb/D");
1023     splitterTree_->Branch("dp_glb", &dp_glb_, "dp_glb/D");
1024     splitterTree_->Branch("qoverpt1_glb", &qoverpt1_glb_, "qoverpt1_glb/D");
1025     splitterTree_->Branch("qoverpt2_glb", &qoverpt2_glb_, "qoverpt2_glb/D");
1026     splitterTree_->Branch("dqoverpt_glb", &dqoverpt_glb_, "dqoverpt_glb/D");
1027     splitterTree_->Branch("norchi1_glb", &norchi1_glb_, "norchi1_glb/D");
1028     splitterTree_->Branch("norchi2_glb", &norchi2_glb_, "norchi2_glb/D");
1029 
1030     splitterTree_->Branch("dxy1Err_glb", &dxy1Err_glb_, "dxy1Err_glb/D");
1031     splitterTree_->Branch("dxy2Err_glb", &dxy2Err_glb_, "dxy2Err_glb/D");
1032     splitterTree_->Branch("dz1Err_glb", &dz1Err_glb_, "dz1Err_glb/D");
1033     splitterTree_->Branch("dz2Err_glb", &dz2Err_glb_, "dz2Err_glb/D");
1034     splitterTree_->Branch("theta1Err_glb", &theta1Err_glb_, "theta1Err_glb/D");
1035     splitterTree_->Branch("theta2Err_glb", &theta2Err_glb_, "theta2Err_glb/D");
1036     splitterTree_->Branch("eta1Err_glb", &eta1Err_glb_, "eta1Err_glb/D");
1037     splitterTree_->Branch("eta2Err_glb", &eta2Err_glb_, "eta2Err_glb/D");
1038     splitterTree_->Branch("phi1Err_glb", &phi1Err_glb_, "phi1Err_glb/D");
1039     splitterTree_->Branch("phi2Err_glb", &phi2Err_glb_, "phi2Err_glb/D");
1040     splitterTree_->Branch("pt1Err_glb", &pt1Err_glb_, "pt1Err_glb/D");
1041     splitterTree_->Branch("pt2Err_glb", &pt2Err_glb_, "pt2Err_glb/D");
1042     splitterTree_->Branch("qoverpt1Err_glb", &qoverpt1Err_glb_, "qoverpt1Err_glb/D");
1043     splitterTree_->Branch("qoverpt2Err_glb", &qoverpt2Err_glb_, "qoverpt2Err_glb/D");
1044   }
1045 
1046   totalTracksToAnalyzer_ = 0;
1047   goldenCtr = 0;
1048   twoTracksCtr = 0;
1049   goldenPlusTwoTracksCtr = 0;
1050   _passesTracksPlusMuonsCuts = 0;
1051 }
1052 
1053 // ------------ method called once each job just after ending the event loop  ------------
1054 void CosmicSplitterValidation::endJob() {
1055   //std::cout << "totalTracksToAnalyzer: " << totalTracksToAnalyzer_ << std::endl;
1056   std::cout << "golden: " << goldenCtr << ", two tracks: " << twoTracksCtr << ", "
1057             << "golden+twotracks: " << goldenPlusTwoTracksCtr << ", "
1058             << "tracks+muons cuts: " << _passesTracksPlusMuonsCuts << std::endl;
1059 }
1060 
1061 bool CosmicSplitterValidation::is_gold_muon(const edm::Event& e) {
1062   edm::Handle<reco::MuonCollection> muHandle;
1063   e.getByToken(STAMuonsToken_, muHandle);
1064   const reco::MuonCollection& muons = *(muHandle.product());
1065   // make sure there are 2 muons
1066   if (2 != muons.size())
1067     return false;
1068 
1069   double mudd0 = 0., mudphi = 0., muddsz = 0., mudeta = 0.;
1070   for (unsigned int bindex = 0; bindex < muons.size(); ++bindex) {
1071     reco::Muon mymuon = muons[bindex];
1072     // deprecated in 21x (now outerTrack)
1073     //reco::TrackRef mutrackref = mymuon.standAloneMuon();
1074     reco::TrackRef mutrackref = mymuon.outerTrack();
1075     const reco::Track* mutrack = mutrackref.get();
1076     if (0 == bindex) {
1077       mudd0 += mutrack->d0();
1078       mudphi += mutrack->phi();
1079       muddsz += mutrack->dsz();
1080       mudeta += mymuon.eta();
1081     }
1082     if (1 == bindex) {
1083       mudd0 -= mutrack->d0();
1084       mudphi -= mutrack->phi();
1085       muddsz -= mutrack->dsz();
1086       mudeta -= mymuon.eta();
1087     }
1088   }
1089   if ((fabs(mudd0) < 15.0) && (fabs(mudphi) < 0.045) && (fabs(muddsz) < 20.0) && (fabs(mudeta) < 0.060))
1090     return true;
1091   return false;
1092 }
1093 
1094 //define this as a plug-in
1095 DEFINE_FWK_MODULE(CosmicSplitterValidation);