diff --git a/RecoMuon/TrackingTools/plugins/BuildFile.xml b/RecoMuon/TrackingTools/plugins/BuildFile.xml deleted file mode 100644 index e3eab33255278..0000000000000 --- a/RecoMuon/TrackingTools/plugins/BuildFile.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/RecoMuon/TrackingTools/plugins/MuonErrorMatrixAdjuster.cc b/RecoMuon/TrackingTools/plugins/MuonErrorMatrixAdjuster.cc deleted file mode 100644 index a7755f460fa38..0000000000000 --- a/RecoMuon/TrackingTools/plugins/MuonErrorMatrixAdjuster.cc +++ /dev/null @@ -1,244 +0,0 @@ -#include "RecoMuon/TrackingTools/plugins/MuonErrorMatrixAdjuster.h" - -#include "TString.h" -#include "TMath.h" -#include -#include - -#include -#include "RecoMuon/TrackingTools/interface/MuonErrorMatrix.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include -#include "DataFormats/TrackReco/interface/TrackFwd.h" - -#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" -#include "Geometry/Records/interface/TrackerTopologyRcd.h" - -MuonErrorMatrixAdjuster::MuonErrorMatrixAdjuster(const edm::ParameterSet& iConfig) - : theFieldToken{esConsumes()}, theHttopoToken{esConsumes()} { - theCategory = "MuonErrorMatrixAdjuster"; - theInstanceName = iConfig.getParameter("instanceName"); - //register your products - produces(theInstanceName); - produces(); - produces(); - - theTrackLabel = iConfig.getParameter("trackLabel"); - consumes(theTrackLabel); - theRescale = iConfig.getParameter("rescale"); - - auto matrixProvider_pset = iConfig.getParameter("errorMatrix_pset"); - - theMatrixProvider = std::make_unique(matrixProvider_pset); -} - -MuonErrorMatrixAdjuster::~MuonErrorMatrixAdjuster() { - // do anything here that needs to be done at desctruction time - // (e.g. close files, deallocate resources etc.) -} - -// -// member functions -// - -//take the error matrix and rescale it or just replace it -reco::TrackBase::CovarianceMatrix MuonErrorMatrixAdjuster::fix_cov_matrix( - const reco::TrackBase::CovarianceMatrix& error_matrix, const GlobalVector& momentum) { - //CovarianceMatrix is template for SMatrix - reco::TrackBase::CovarianceMatrix revised_matrix(theMatrixProvider->get(momentum)); - - if (theRescale) { - //rescale old error matrix up by a factor - multiply(revised_matrix, error_matrix); - } - return revised_matrix; -} - -void MuonErrorMatrixAdjuster::multiply(reco::TrackBase::CovarianceMatrix& revised_matrix, - const reco::TrackBase::CovarianceMatrix& scale_matrix) { - //scale term by term the matrix - // the true type of the matrix is such that [i][j] is the same memory object as [j][i]: looping i:0-5, j:0-5 double multiply the terms - // need to loop only on i:0-5, j:i-5 - for (int i = 0; i != 5; i++) { - for (int j = i; j != 5; j++) { - revised_matrix(i, j) *= scale_matrix(i, j); - } - } -} -bool MuonErrorMatrixAdjuster::divide(reco::TrackBase::CovarianceMatrix& num_matrix, - const reco::TrackBase::CovarianceMatrix& denom_matrix) { - //divide term by term the matrix - // the true type of the matrix is such that [i][j] is the same memory object as [j][i]: looping i:0-5, j:0-5 double multiply the terms - // need to loop only on i:0-5, j:i-5 - for (int i = 0; i != 5; i++) { - for (int j = i; j != 5; j++) { - if (denom_matrix(i, j) == 0) - return false; - num_matrix(i, j) /= denom_matrix(i, j); - } - } - return true; -} - -reco::Track MuonErrorMatrixAdjuster::makeTrack(const reco::Track& recotrack_orig, const FreeTrajectoryState& PCAstate) { - //get the parameters of the track so I can reconstruct it - double chi2 = recotrack_orig.chi2(); - double ndof = recotrack_orig.ndof(); - const math::XYZPoint& refpos = recotrack_orig.referencePoint(); - const math::XYZVector& mom = recotrack_orig.momentum(); - int charge = recotrack_orig.charge(); - - reco::TrackBase::CovarianceMatrix covariance_matrix = - fix_cov_matrix(recotrack_orig.covariance(), PCAstate.momentum()); - - LogDebug(theCategory) << "chi2: " << chi2 << "\n ndof: " << ndof << "\n refpos: " << refpos << "\n mom: " << mom - << "\n charge: " << charge << "\n covariance:\n" - << recotrack_orig.covariance() << "\n replaced by:\n" - << covariance_matrix; - - return reco::Track(chi2, ndof, refpos, mom, charge, covariance_matrix); -} - -reco::TrackExtra* MuonErrorMatrixAdjuster::makeTrackExtra(const reco::Track& recotrack_orig, - reco::Track& recotrack, - reco::TrackExtraCollection& TEcol) { - //get the 5x5 matrix of recotrack/recotrack_orig - reco::TrackBase::CovarianceMatrix scale_matrix(recotrack.covariance()); - if (!divide(scale_matrix, recotrack_orig.covariance())) { - edm::LogError(theCategory) << "original track error matrix has term ==0... skipping."; - return nullptr; - } - - const reco::TrackExtraRef& trackExtra_orig = recotrack_orig.extra(); - if (trackExtra_orig.isNull()) { - edm::LogError(theCategory) << "original track has no track extra... skipping."; - return nullptr; - } - - //copy the outer state. rescaling the error matrix - reco::TrackBase::CovarianceMatrix outerCov(trackExtra_orig->outerStateCovariance()); - multiply(outerCov, scale_matrix); - - //copy the inner state, rescaling the error matrix - reco::TrackBase::CovarianceMatrix innerCov(trackExtra_orig->innerStateCovariance()); - multiply(innerCov, scale_matrix); - - //put the trackExtra - TEcol.push_back(reco::TrackExtra(trackExtra_orig->outerPosition(), - trackExtra_orig->outerMomentum(), - true, - trackExtra_orig->innerPosition(), - trackExtra_orig->innerMomentum(), - true, - outerCov, - trackExtra_orig->outerDetId(), - innerCov, - trackExtra_orig->innerDetId(), - trackExtra_orig->seedDirection())); - - //add a reference to the trackextra on the track - recotrack.setExtra(edm::Ref(theRefprodTE, theTEi++)); - - //return the reference to the last inserted then - return &(TEcol.back()); -} - -bool MuonErrorMatrixAdjuster::attachRecHits(const reco::Track& recotrack_orig, - reco::Track& recotrack, - reco::TrackExtra& trackextra, - TrackingRecHitCollection& RHcol, - const TrackerTopology& ttopo) { - //loop over the hits of the original track - trackingRecHit_iterator recHit = recotrack_orig.recHitsBegin(); - auto const firstHitIndex = theRHi; - for (; recHit != recotrack_orig.recHitsEnd(); ++recHit) { - //clone it. this is meandatory - TrackingRecHit* hit = (*recHit)->clone(); - - //put it on the new track - recotrack.appendHitPattern(*hit, ttopo); - //copy them in the new collection - RHcol.push_back(hit); - ++theRHi; - - } //loop over original rechits - //do something with the trackextra - trackextra.setHits(theRefprodRH, firstHitIndex, theRHi - firstHitIndex); - - return true; //if nothing fails -} - -bool MuonErrorMatrixAdjuster::selectTrack(const reco::Track& recotrack_orig) { return true; } - -// ------------ method called to produce the data ------------ -void MuonErrorMatrixAdjuster::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - using namespace edm; - - //open a collection of track - edm::Handle tracks; - iEvent.getByLabel(theTrackLabel, tracks); - LogDebug(theCategory) << "considering: " << tracks->size() << " uncorrected reco::Track from the event.(" - << theTrackLabel << ")"; - - //get the mag field - theField = iSetup.getHandle(theFieldToken); - - const TrackerTopology& ttopo = iSetup.getData(theHttopoToken); - - //prepare the output collection - auto Toutput = std::make_unique(); - auto TRHoutput = std::make_unique(); - auto TEoutput = std::make_unique(); - theRefprodTE = iEvent.getRefBeforePut(); - theTEi = 0; - theRefprodRH = iEvent.getRefBeforePut(); - theRHi = 0; - - for (unsigned int it = 0; it != tracks->size(); it++) { - const reco::Track& recotrack_orig = (*tracks)[it]; - FreeTrajectoryState PCAstate = trajectoryStateTransform::initialFreeState(recotrack_orig, theField.product()); - if (PCAstate.position().mag() == 0) { - edm::LogError(theCategory) << "invalid state from track initial state in " << theTrackLabel << ". skipping."; - continue; - } - - //create a reco::Track - reco::Track recotrack = makeTrack(recotrack_orig, PCAstate); - - //make a selection on the create reco::Track - if (!selectTrack(recotrack)) - continue; - - Toutput->push_back(recotrack); - reco::Track& recotrackref = Toutput->back(); - - //build the track extra - reco::TrackExtra* extra = makeTrackExtra(recotrack_orig, recotrackref, *TEoutput); - if (!extra) { - edm::LogError(theCategory) << "cannot create the track extra for this track."; - //pop the inserted track - Toutput->pop_back(); - continue; - } - - //attach the collection of rechits - if (!attachRecHits(recotrack_orig, recotrackref, *extra, *TRHoutput, ttopo)) { - edm::LogError(theCategory) << "cannot attach any rechits on this track"; - //pop the inserted track - Toutput->pop_back(); - //pop the track extra - TEoutput->pop_back(); - theTEi--; - continue; - } - - } //loop over the original reco tracks - - LogDebug(theCategory) << "writing: " << Toutput->size() << " corrected reco::Track to the event."; - - iEvent.put(std::move(Toutput), theInstanceName); - iEvent.put(std::move(TEoutput)); - iEvent.put(std::move(TRHoutput)); -} diff --git a/RecoMuon/TrackingTools/plugins/MuonErrorMatrixAdjuster.h b/RecoMuon/TrackingTools/plugins/MuonErrorMatrixAdjuster.h deleted file mode 100644 index 6cdc1cb8cdc3f..0000000000000 --- a/RecoMuon/TrackingTools/plugins/MuonErrorMatrixAdjuster.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef RecoMuon_TrackingTools_MuonErrorMatrixAdjuster_H -#define RecoMuon_TrackingTools_MuonErrorMatrixAdjuster_H - -/** \class MuonErrorMatrixAdjuster - * - * EDProducer which duplicatesa collection of track, adjusting their error matrix - * - * track collection is retrieve from the event, duplicated, while the error matrix is corrected - * rechit are copied into a new collection - * track extra is also copied and error matrix are corrected by the same scale factors - * - * - * \author Jean-Roch Vlimant UCSB - * \author Finn Rebassoo UCSB - */ - -#include -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/TrackReco/interface/TrackExtra.h" -#include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h" - -#include "FWCore/Utilities/interface/InputTag.h" - -class FreeTrajectoryState; -class MuonErroMatrix; -class MagneticField; -class IdealMagneticFieldRecord; -class MuonErrorMatrix; -class TrackerTopologyRcd; -#include "DataFormats/GeometryVector/interface/GlobalVector.h" - -#include "FWCore/Framework/interface/ESHandle.h" - -// -// class decleration -// - -class MuonErrorMatrixAdjuster : public edm::stream::EDProducer<> { -public: - /// constructor - explicit MuonErrorMatrixAdjuster(const edm::ParameterSet&); - /// destructor - ~MuonErrorMatrixAdjuster() override; - -private: - /// framework method - void produce(edm::Event&, const edm::EventSetup&) override; - - /// return a corrected error matrix - reco::TrackBase::CovarianceMatrix fix_cov_matrix(const reco::TrackBase::CovarianceMatrix& error_matrix, - const GlobalVector& momentum); - /// mutliply revised_matrix (first argument) by second matrix TERM by TERM - void multiply(reco::TrackBase::CovarianceMatrix& revised_matrix, - const reco::TrackBase::CovarianceMatrix& scale_matrix); - /// divide the num_matrix (first argument) by second matrix, TERM by TERM - bool divide(reco::TrackBase::CovarianceMatrix& num_matrix, const reco::TrackBase::CovarianceMatrix& denom_matrix); - - /// create a corrected reco::Track from itself and trajectory state (redundant information) - reco::Track makeTrack(const reco::Track& recotrack_orig, const FreeTrajectoryState& PCAstate); - - /// make a selection on the reco:Track. (dummy for the moment) - bool selectTrack(const reco::Track& recotrack_orig); - - /// create a track extra for the newly created recotrack, scaling the outer/inner measurment error matrix by the scale matrix recotrack/recotrack_orig - reco::TrackExtra* makeTrackExtra(const reco::Track& recotrack_orig, - reco::Track& recotrack, - reco::TrackExtraCollection& TEcol); - - /// attached rechits to the newly created reco::Track and reco::TrackExtra - bool attachRecHits(const reco::Track& recotrack_orig, - reco::Track& recotrack, - reco::TrackExtra& trackextra, - TrackingRecHitCollection& RHcol, - const TrackerTopology& ttopo); - - // ----------member data --------------------------- - /// log category: MuonErrorMatrixAdjuster - std::string theCategory; - - /// input tag of the reco::Track collection to be corrected - edm::InputTag theTrackLabel; - - /// instrance name of the created track collecion. rechit and trackextra have no instance name - std::string theInstanceName; - - /// select the rescaling or replacing method to correct the error matrix - bool theRescale; - - /// holds the error matrix parametrization - std::unique_ptr theMatrixProvider; - - /// hold on to the magnetic field - edm::ESHandle theField; - const edm::ESGetToken theFieldToken; - const edm::ESGetToken theHttopoToken; - - /// get reference before put track extra to the event, in order to create edm::Ref - edm::RefProd theRefprodTE; - edm::Ref::key_type theTEi; - - /// get reference before put rechit to the event, in order to create edm::Ref - edm::RefProd theRefprodRH; - edm::Ref::key_type theRHi; -}; - -#endif diff --git a/RecoMuon/TrackingTools/plugins/SealModules.cc b/RecoMuon/TrackingTools/plugins/SealModules.cc deleted file mode 100644 index 785192f9098b0..0000000000000 --- a/RecoMuon/TrackingTools/plugins/SealModules.cc +++ /dev/null @@ -1,10 +0,0 @@ -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/ModuleFactory.h" -#include "FWCore/Framework/interface/ESProducer.h" -#include "FWCore/Utilities/interface/typelookup.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "RecoMuon/TrackingTools/plugins/MuonErrorMatrixAdjuster.h" - -DEFINE_FWK_MODULE(MuonErrorMatrixAdjuster); diff --git a/RecoMuon/TrackingTools/python/MuonErrorMatrixAdjuster_cff.py b/RecoMuon/TrackingTools/python/MuonErrorMatrixAdjuster_cff.py deleted file mode 100644 index 4ec4ed472863b..0000000000000 --- a/RecoMuon/TrackingTools/python/MuonErrorMatrixAdjuster_cff.py +++ /dev/null @@ -1,7 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -#produce the mag field -#produce the module -from RecoMuon.TrackingTools.MuonErrorMatrixAdjuster_cfi import * - - diff --git a/RecoMuon/TrackingTools/python/MuonErrorMatrixAdjuster_cfi.py b/RecoMuon/TrackingTools/python/MuonErrorMatrixAdjuster_cfi.py deleted file mode 100644 index 74e04df38d822..0000000000000 --- a/RecoMuon/TrackingTools/python/MuonErrorMatrixAdjuster_cfi.py +++ /dev/null @@ -1,22 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -#values for correction -from RecoMuon.TrackingTools.MuonErrorMatrixValues_cff import * -muonErrorMatrixAdjuster = cms.EDProducer("MuonErrorMatrixAdjuster", - #if replace is true this means error matrix from reco is replaced by new method of error matrix (reco minus sim of parameters to get the error) - #if replace is false this means the error matrix from reco is rescaled by a factor - rescale = cms.bool(True), - #this is the root file with the TProfile 3D in it of the track collection. Make sure it corresponds to the boolean above - errorMatrix_pset = cms.PSet( - # use either one of the two following lines - #string rootFileName = "errorMatrix_ScaleFactor.root" - MuonErrorMatrixValues, - action = cms.string('use') - ), - instanceName = cms.string(''), - rechitLabel = cms.InputTag("standAloneMuons"), - trackLabel = cms.InputTag("standAloneMuons","UpdatedAtVtx") -) - - -