Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-22 06:26:41

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