#include <RecoMuon/TrackingTools/plugins/MuonErrorMatrixAdjuster.h>
Public Member Functions | |
MuonErrorMatrixAdjuster (const edm::ParameterSet &) | |
constructor | |
~MuonErrorMatrixAdjuster () | |
destructor | |
Private Member Functions | |
bool | attachRecHits (const reco::Track &recotrack_orig, reco::Track &recotrack, reco::TrackExtra &trackextra, TrackingRecHitCollection &RHcol) |
attached rechits to the newly created reco::Track and reco::TrackExtra | |
virtual void | beginJob (const edm::EventSetup &) |
framework method | |
bool | divide (reco::TrackBase::CovarianceMatrix &num_matrix, const reco::TrackBase::CovarianceMatrix &denom_matrix) |
divide the num_matrix (first argument) by second matrix, TERM by TERM | |
virtual void | endJob () |
reco::TrackBase::CovarianceMatrix | fix_cov_matrix (const reco::TrackBase::CovarianceMatrix &error_matrix, const GlobalVector &momentum) |
return a corrected error matrix | |
reco::Track | makeTrack (const reco::Track &recotrack_orig, const FreeTrajectoryState &PCAstate) |
create a corrected reco::Track from itself and trajectory state (redundant information) | |
reco::TrackExtra * | makeTrackExtra (const reco::Track &recotrack_orig, reco::Track &recotrack, reco::TrackExtraCollection &TEcol) |
create a track extra for the newly created recotrack, scaling the outer/inner measurment error matrix by the scale matrix recotrack/recotrack_orig | |
void | multiply (reco::TrackBase::CovarianceMatrix &revised_matrix, const reco::TrackBase::CovarianceMatrix &scale_matrix) |
mutliply revised_matrix (first argument) by second matrix TERM by TERM | |
virtual void | produce (edm::Event &, const edm::EventSetup &) |
bool | selectTrack (const reco::Track &recotrack_orig) |
make a selection on the reco:Track. (dummy for the moment) | |
Private Attributes | |
std::string | theCategory |
log category: MuonErrorMatrixAdjuster | |
edm::ESHandle< MagneticField > | theField |
hold on to the magnetic field | |
std::string | theInstanceName |
instrance name of the created track collecion. rechit and trackextra have no instance name | |
MuonErrorMatrix * | theMatrixProvider |
edm::ParameterSet | theMatrixProvider_pset |
holds the error matrix parametrization | |
edm::RefProd < TrackingRecHitCollection > | theRefprodRH |
get reference before put rechit to the event, in order to create edm::Ref | |
edm::RefProd < reco::TrackExtraCollection > | theRefprodTE |
get reference before put track extra to the event, in order to create edm::Ref | |
bool | theRescale |
select the rescaling or replacing method to correct the error matrix | |
edm::Ref < TrackingRecHitCollection > ::key_type | theRHi |
edm::Ref < reco::TrackExtraCollection > ::key_type | theTEi |
edm::InputTag | theTrackLabel |
input tag of the reco::Track collection to be corrected |
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
Definition at line 47 of file MuonErrorMatrixAdjuster.h.
MuonErrorMatrixAdjuster::MuonErrorMatrixAdjuster | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
constructor
Definition at line 16 of file MuonErrorMatrixAdjuster.cc.
References edm::ParameterSet::getParameter(), theCategory, theInstanceName, theMatrixProvider_pset, theRescale, and theTrackLabel.
00017 { 00018 theCategory="MuonErrorMatrixAdjuster"; 00019 theInstanceName = iConfig.getParameter<std::string>("instanceName"); 00020 //register your products 00021 produces<reco::TrackCollection>( theInstanceName); 00022 produces<TrackingRecHitCollection>(); 00023 produces<reco::TrackExtraCollection>(); 00024 00025 theTrackLabel = iConfig.getParameter<edm::InputTag>("trackLabel"); 00026 theRescale = iConfig.getParameter<bool>("rescale"); 00027 00028 theMatrixProvider_pset = iConfig.getParameter<edm::ParameterSet>("errorMatrix_pset"); 00029 }
MuonErrorMatrixAdjuster::~MuonErrorMatrixAdjuster | ( | ) |
destructor
Definition at line 32 of file MuonErrorMatrixAdjuster.cc.
00033 { 00034 00035 // do anything here that needs to be done at desctruction time 00036 // (e.g. close files, deallocate resources etc.) 00037 00038 }
bool MuonErrorMatrixAdjuster::attachRecHits | ( | const reco::Track & | recotrack_orig, | |
reco::Track & | recotrack, | |||
reco::TrackExtra & | trackextra, | |||
TrackingRecHitCollection & | RHcol | |||
) | [private] |
attached rechits to the newly created reco::Track and reco::TrackExtra
Definition at line 136 of file MuonErrorMatrixAdjuster.cc.
References reco::TrackExtraBase::add(), edm::OwnVector< T, P >::push_back(), reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), reco::TrackBase::setHitPattern(), theRefprodRH, and theRHi.
Referenced by produce().
00139 { 00140 //loop over the hits of the original track 00141 trackingRecHit_iterator recHit = recotrack_orig.recHitsBegin(); 00142 uint irh=0; 00143 for (; recHit!=recotrack_orig.recHitsEnd();++recHit){ 00144 //clone it. this is meandatory 00145 TrackingRecHit * hit = (*recHit)->clone(); 00146 00147 //put it on the new track 00148 recotrack.setHitPattern(*hit,irh++); 00149 //copy them in the new collection 00150 RHcol.push_back(hit); 00151 //do something with the trackextra 00152 trackextra.add(TrackingRecHitRef( theRefprodRH, theRHi++)); 00153 00154 }//loop over original rechits 00155 00156 return true; //if nothing fails 00157 }
void MuonErrorMatrixAdjuster::beginJob | ( | const edm::EventSetup & | ) | [private, virtual] |
framework method
Reimplemented from edm::EDProducer.
Definition at line 232 of file MuonErrorMatrixAdjuster.cc.
References theMatrixProvider, and theMatrixProvider_pset.
00233 { 00234 theMatrixProvider = new MuonErrorMatrix(theMatrixProvider_pset); 00235 }
bool MuonErrorMatrixAdjuster::divide | ( | reco::TrackBase::CovarianceMatrix & | num_matrix, | |
const reco::TrackBase::CovarianceMatrix & | denom_matrix | |||
) | [private] |
divide the num_matrix (first argument) by second matrix, TERM by TERM
Definition at line 66 of file MuonErrorMatrixAdjuster.cc.
Referenced by makeTrackExtra().
00066 { 00067 //divide term by term the matrix 00068 // 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 00069 // need to loop only on i:0-5, j:i-5 00070 for(int i = 0;i!=5;i++){for(int j = i;j!=5;j++){ 00071 if (denom_matrix(i,j)==0) return false; 00072 num_matrix(i,j)/=denom_matrix(i,j); 00073 }} 00074 return true; 00075 }
Reimplemented from edm::EDProducer.
Definition at line 239 of file MuonErrorMatrixAdjuster.cc.
References theMatrixProvider.
00239 { 00240 if ( theMatrixProvider) delete theMatrixProvider; 00241 }
reco::TrackBase::CovarianceMatrix MuonErrorMatrixAdjuster::fix_cov_matrix | ( | const reco::TrackBase::CovarianceMatrix & | error_matrix, | |
const GlobalVector & | momentum | |||
) | [private] |
return a corrected error matrix
Definition at line 46 of file MuonErrorMatrixAdjuster.cc.
References MuonErrorMatrix::get(), multiply(), theMatrixProvider, and theRescale.
Referenced by makeTrack().
00047 { 00048 //CovarianceMatrix is template for SMatrix 00049 reco::TrackBase::CovarianceMatrix revised_matrix( theMatrixProvider->get(momentum)); 00050 00051 if( theRescale){ 00052 //rescale old error matrix up by a factor 00053 multiply(revised_matrix,error_matrix); 00054 } 00055 return revised_matrix; 00056 }
reco::Track MuonErrorMatrixAdjuster::makeTrack | ( | const reco::Track & | recotrack_orig, | |
const FreeTrajectoryState & | PCAstate | |||
) | [private] |
create a corrected reco::Track from itself and trajectory state (redundant information)
Definition at line 77 of file MuonErrorMatrixAdjuster.cc.
References reco::TrackBase::charge(), reco::TrackBase::chi2(), reco::TrackBase::covariance(), fix_cov_matrix(), LogDebug, reco::TrackBase::momentum(), FreeTrajectoryState::momentum(), reco::TrackBase::ndof(), reco::TrackBase::referencePoint(), and theCategory.
Referenced by produce().
00078 { 00079 //get the parameters of the track so I can reconstruct it 00080 double chi2 = recotrack_orig.chi2(); 00081 double ndof = recotrack_orig.ndof(); 00082 math::XYZPoint refpos = recotrack_orig.referencePoint(); 00083 math::XYZVector mom = recotrack_orig.momentum(); 00084 int charge = recotrack_orig.charge(); 00085 00086 reco::TrackBase::CovarianceMatrix covariance_matrix = fix_cov_matrix(recotrack_orig.covariance(),PCAstate.momentum()); 00087 00088 LogDebug(theCategory)<<"chi2: "<<chi2 00089 <<"\n ndof: "<<ndof 00090 <<"\n refpos: "<<refpos 00091 <<"\n mom: "<<mom 00092 <<"\n charge: "<<charge 00093 <<"\n covariance:\n"<<recotrack_orig.covariance() 00094 <<"\n replaced by:\n"<<covariance_matrix; 00095 00096 return reco::Track(chi2,ndof,refpos,mom,charge,covariance_matrix); 00097 }
reco::TrackExtra * MuonErrorMatrixAdjuster::makeTrackExtra | ( | const reco::Track & | recotrack_orig, | |
reco::Track & | recotrack, | |||
reco::TrackExtraCollection & | TEcol | |||
) | [private] |
create a track extra for the newly created recotrack, scaling the outer/inner measurment error matrix by the scale matrix recotrack/recotrack_orig
Definition at line 99 of file MuonErrorMatrixAdjuster.cc.
References reco::TrackBase::covariance(), divide(), reco::Track::extra(), edm::Ref< C, T, F >::isNull(), multiply(), reco::Track::setExtra(), theCategory, theRefprodTE, and theTEi.
Referenced by produce().
00101 { 00102 //get the 5x5 matrix of recotrack/recotrack_orig 00103 reco::TrackBase::CovarianceMatrix scale_matrix(recotrack.covariance()); 00104 if (!divide(scale_matrix,recotrack_orig.covariance())){ 00105 edm::LogError( theCategory)<<"original track error matrix has term ==0... skipping."; 00106 return 0; } 00107 00108 const reco::TrackExtraRef & trackExtra_orig = recotrack_orig.extra(); 00109 if (trackExtra_orig.isNull()) { 00110 edm::LogError( theCategory)<<"original track has no track extra... skipping."; 00111 return 0;} 00112 00113 //copy the outer state. rescaling the error matrix 00114 reco::TrackBase::CovarianceMatrix outerCov(trackExtra_orig->outerStateCovariance()); 00115 multiply(outerCov,scale_matrix); 00116 00117 //copy the inner state, rescaling the error matrix 00118 reco::TrackBase::CovarianceMatrix innerCov(trackExtra_orig->innerStateCovariance()); 00119 multiply(innerCov,scale_matrix); 00120 00121 //put the trackExtra 00122 TEcol.push_back(reco::TrackExtra (trackExtra_orig->outerPosition(), trackExtra_orig->outerMomentum(), true, 00123 trackExtra_orig->innerPosition(), trackExtra_orig->innerMomentum(), true, 00124 outerCov, trackExtra_orig->outerDetId(), 00125 innerCov, trackExtra_orig->innerDetId(), 00126 trackExtra_orig->seedDirection())); 00127 00128 //add a reference to the trackextra on the track 00129 recotrack.setExtra(edm::Ref<reco::TrackExtraCollection>( theRefprodTE, theTEi++)); 00130 00131 //return the reference to the last inserted then 00132 return &(TEcol.back()); 00133 }
void MuonErrorMatrixAdjuster::multiply | ( | reco::TrackBase::CovarianceMatrix & | revised_matrix, | |
const reco::TrackBase::CovarianceMatrix & | scale_matrix | |||
) | [private] |
mutliply revised_matrix (first argument) by second matrix TERM by TERM
Definition at line 58 of file MuonErrorMatrixAdjuster.cc.
Referenced by fix_cov_matrix(), and makeTrackExtra().
00058 { 00059 //scale term by term the matrix 00060 // 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 00061 // need to loop only on i:0-5, j:i-5 00062 for(int i = 0;i!=5;i++){for(int j = i;j!=5;j++){ 00063 revised_matrix(i,j)*=scale_matrix(i,j); 00064 }} 00065 }
void MuonErrorMatrixAdjuster::produce | ( | edm::Event & | iEvent, | |
const edm::EventSetup & | iSetup | |||
) | [private, virtual] |
Implements edm::EDProducer.
Definition at line 163 of file MuonErrorMatrixAdjuster.cc.
References attachRecHits(), edm::EventSetup::get(), edm::Event::getByLabel(), edm::Event::getRefBeforePut(), TrajectoryStateTransform::initialFreeState(), it, LogDebug, PV3DBase< T, PVType, FrameType >::mag(), makeTrack(), makeTrackExtra(), FreeTrajectoryState::position(), edm::ESHandle< T >::product(), edm::Event::put(), selectTrack(), theCategory, theField, theInstanceName, theRefprodRH, theRefprodTE, theRHi, theTEi, theTrackLabel, and tracks.
00164 { 00165 using namespace edm; 00166 00167 //open a collection of track 00168 edm::Handle<reco::TrackCollection> tracks; 00169 iEvent.getByLabel( theTrackLabel,tracks); 00170 LogDebug( theCategory)<<"considering: "<<tracks->size()<<" uncorrected reco::Track from the event.("<< theTrackLabel<<")"; 00171 00172 //get the mag field 00173 iSetup.get<IdealMagneticFieldRecord>().get( theField); 00174 00175 //prepare the output collection 00176 std::auto_ptr<reco::TrackCollection> Toutput(new reco::TrackCollection()); 00177 std::auto_ptr<TrackingRecHitCollection> TRHoutput(new TrackingRecHitCollection()); 00178 std::auto_ptr<reco::TrackExtraCollection> TEoutput(new reco::TrackExtraCollection()); 00179 theRefprodTE = iEvent.getRefBeforePut<reco::TrackExtraCollection>(); 00180 theTEi=0; 00181 theRefprodRH =iEvent.getRefBeforePut<TrackingRecHitCollection>(); 00182 theRHi=0; 00183 00184 TrajectoryStateTransform transformer; 00185 00186 for(uint it=0;it!=tracks->size();it++) 00187 { 00188 const reco::Track & recotrack_orig = (*tracks)[it]; 00189 FreeTrajectoryState PCAstate = transformer.initialFreeState(recotrack_orig, theField.product()); 00190 if (PCAstate.position().mag()==0) 00191 {edm::LogError( theCategory)<<"invalid state from track initial state in "<< theTrackLabel <<". skipping.";continue;} 00192 00193 //create a reco::Track 00194 reco::Track recotrack = makeTrack(recotrack_orig,PCAstate); 00195 00196 //make a selection on the create reco::Track 00197 if (!selectTrack(recotrack)) continue; 00198 00199 Toutput->push_back(recotrack); 00200 reco::Track & recotrackref = Toutput->back(); 00201 00202 //build the track extra 00203 reco::TrackExtra * extra = makeTrackExtra(recotrack_orig,recotrackref,*TEoutput); 00204 if (!extra){ 00205 edm::LogError( theCategory)<<"cannot create the track extra for this track."; 00206 //pop the inserted track 00207 Toutput->pop_back(); 00208 continue;} 00209 00210 //attach the collection of rechits 00211 if (!attachRecHits(recotrack_orig,recotrackref,*extra,*TRHoutput)){ 00212 edm::LogError( theCategory)<<"cannot attach any rechits on this track"; 00213 //pop the inserted track 00214 Toutput->pop_back(); 00215 //pop the track extra 00216 TEoutput->pop_back(); 00217 theTEi--; 00218 continue;} 00219 00220 }//loop over the original reco tracks 00221 00222 LogDebug( theCategory)<<"writing: "<<Toutput->size()<<" corrected reco::Track to the event."; 00223 00224 iEvent.put(Toutput, theInstanceName); 00225 iEvent.put(TEoutput); 00226 iEvent.put(TRHoutput); 00227 00228 }
bool MuonErrorMatrixAdjuster::selectTrack | ( | const reco::Track & | recotrack_orig | ) | [private] |
make a selection on the reco:Track. (dummy for the moment)
Definition at line 159 of file MuonErrorMatrixAdjuster.cc.
Referenced by produce().
std::string MuonErrorMatrixAdjuster::theCategory [private] |
log category: MuonErrorMatrixAdjuster
Definition at line 87 of file MuonErrorMatrixAdjuster.h.
Referenced by makeTrack(), makeTrackExtra(), MuonErrorMatrixAdjuster(), and produce().
hold on to the magnetic field
Definition at line 104 of file MuonErrorMatrixAdjuster.h.
Referenced by produce().
std::string MuonErrorMatrixAdjuster::theInstanceName [private] |
instrance name of the created track collecion. rechit and trackextra have no instance name
Definition at line 93 of file MuonErrorMatrixAdjuster.h.
Referenced by MuonErrorMatrixAdjuster(), and produce().
Definition at line 100 of file MuonErrorMatrixAdjuster.h.
Referenced by beginJob(), endJob(), and fix_cov_matrix().
holds the error matrix parametrization
Definition at line 99 of file MuonErrorMatrixAdjuster.h.
Referenced by beginJob(), and MuonErrorMatrixAdjuster().
get reference before put rechit to the event, in order to create edm::Ref
Definition at line 111 of file MuonErrorMatrixAdjuster.h.
Referenced by attachRecHits(), and produce().
get reference before put track extra to the event, in order to create edm::Ref
Definition at line 107 of file MuonErrorMatrixAdjuster.h.
Referenced by makeTrackExtra(), and produce().
bool MuonErrorMatrixAdjuster::theRescale [private] |
select the rescaling or replacing method to correct the error matrix
Definition at line 96 of file MuonErrorMatrixAdjuster.h.
Referenced by fix_cov_matrix(), and MuonErrorMatrixAdjuster().
edm::Ref<TrackingRecHitCollection>::key_type MuonErrorMatrixAdjuster::theRHi [private] |
Definition at line 112 of file MuonErrorMatrixAdjuster.h.
Referenced by attachRecHits(), and produce().
edm::Ref<reco::TrackExtraCollection>::key_type MuonErrorMatrixAdjuster::theTEi [private] |
Definition at line 108 of file MuonErrorMatrixAdjuster.h.
Referenced by makeTrackExtra(), and produce().
input tag of the reco::Track collection to be corrected
Definition at line 90 of file MuonErrorMatrixAdjuster.h.
Referenced by MuonErrorMatrixAdjuster(), and produce().