Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport of #13831: Speedup Gsf component merging, return components by const reference #15279

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions CommonTools/Utils/test/testDynArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@ int main(int s, char **) {
assert(c.size()==sn);
assert(c.front().i==0);
assert(c.back().i==int(sn-1));
c[1].k=3.14;

c = std::move(a);
a = std::move(c);

assert(c.size()==n);
assert(a.empty());
assert(c[1].k==0.3);
assert(a.size()==sn);
assert(c.empty());
assert(a[1].k==3.14);

std::swap(a,b);
assert(b.size()==sn);
assert(a.size()==n);

auto cmp = [](int i, int j){return i<j;};

unInitDynArray(int,sn,qst); // queue storage
auto cmp = [](int i, int j){return i<j;};
std::priority_queue<int,DynArray<int>,decltype(cmp)> qq(cmp,std::move(qst));
assert(qq.empty());
for(int i=0;i<int(sn);++i) qq.push(i+1);
Expand Down
11 changes: 11 additions & 0 deletions DataFormats/Math/interface/invertPosDefMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ inline bool invertPosDefMatrix(ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T

}

template<>
inline bool invertPosDefMatrix<double,1>(ROOT::Math::SMatrix<double,1,1,ROOT::Math::MatRepSym<double,1> > & m) {
m(0,0) = 1./m(0,0);
return true;
}
template<>
inline bool invertPosDefMatrix<float,1>(ROOT::Math::SMatrix<float,1,1,ROOT::Math::MatRepSym<float,1> > & m) {
m(0,0) = 1.f/m(0,0);
return true;
}

template<typename T,unsigned int N>
inline bool invertPosDefMatrix(ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> > const & mIn,
ROOT::Math::SMatrix<T,N,N,ROOT::Math::MatRepSym<T,N> > & mOut) {
Expand Down
9 changes: 6 additions & 3 deletions RecoParticleFlow/PFTracking/plugins/GoodSeedProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ GoodSeedProducer::produce(Event& iEvent, const EventSetup& iSetup)
auto const & Tj=*(tjCollection.product());

LogDebug("GoodSeedProducer")<<"Number of tracks in collection "
<<tracksContainers_[istr] <<" to be analyzed "
<<"tracksContainers_[" << istr << "] to be analyzed "
<<Tj.size();

//loop over the track collection
Expand Down Expand Up @@ -423,7 +423,8 @@ GoodSeedProducer::produce(Event& iEvent, const EventSetup& iSetup)
GoodPreId= GoodTkId | GoodMatching;

myPreId.setFinalDecision(GoodPreId);


#ifdef EDM_ML_DEBUG
if(GoodPreId)
LogDebug("GoodSeedProducer")<<"Track (pt= "<<Tk[i].pt()<<
"GeV/c, eta= "<<Tk[i].eta() <<
Expand All @@ -432,8 +433,10 @@ GoodSeedProducer::produce(Event& iEvent, const EventSetup& iSetup)
LogDebug("GoodSeedProducer")<<"Track (pt= "<<Tk[i].pt()<<
"GeV/c, eta= "<<Tk[i].eta() <<
") preidentified only for track properties";

#endif

} // end of !disablePreId_


if (GoodPreId){
//NEW SEED with n hits
Expand Down
2 changes: 1 addition & 1 deletion RecoParticleFlow/PFTracking/plugins/PFV0Producer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PFV0Producer::produce(Event& iEvent, const EventSetup& iSetup)
for (unsigned int il=0; il<V0list_.size(); il++){
Handle<VertexCompositeCandidateCollection> V0coll;
iEvent.getByToken(V0list_[il],V0coll);
LogDebug("PFV0Producer")<<V0list_[il]<<" contains "<<V0coll->size()<<" V0 candidates ";
LogDebug("PFV0Producer")<< "V0list_[" << il <<"] contains "<<V0coll->size()<<" V0 candidates ";
for (unsigned int iv=0;iv<V0coll->size();iv++){
VertexCompositeCandidateRef V0(V0coll, iv);
vector<TrackRef> Tracks;
Expand Down
10 changes: 6 additions & 4 deletions RecoParticleFlow/PFTracking/src/PFGsfHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "TrackingTools/GsfTools/interface/MultiGaussianState1D.h"
#include "TrackingTools/GsfTools/interface/GaussianSumUtilities1D.h"
#include "RecoParticleFlow/PFTracking/interface/CollinearFitAtTM.h"
#include "TrackingTools/GsfTools/interface/GetComponents.h"

using namespace std;
using namespace reco;
using namespace edm;
Expand All @@ -49,13 +51,13 @@ PFGsfHelper::PFGsfHelper(const TrajectoryMeasurement& tm){
mode_Px = 0.;
mode_Py = 0.;
mode_Pz = 0.;
std::vector<TrajectoryStateOnSurface> components(theUpdateState.components());
unsigned int numb = components.size();

GetComponents comps(theUpdateState);
auto const & components = comps();
auto numb=components.size();
std::vector<SingleGaussianState1D> pxStates; pxStates.reserve(numb);
std::vector<SingleGaussianState1D> pyStates; pyStates.reserve(numb);
std::vector<SingleGaussianState1D> pzStates; pzStates.reserve(numb);
for ( std::vector<TrajectoryStateOnSurface>::const_iterator ic=components.begin();
for (auto ic=components.begin();
ic!=components.end(); ++ic ) {
GlobalVector momentum(ic->globalMomentum());
AlgebraicSymMatrix66 cov(ic->cartesianError().matrix());
Expand Down
14 changes: 7 additions & 7 deletions RecoTracker/TrackProducer/src/GsfTrackProducerBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "TrackingTools/GsfTracking/interface/TrajGsfTrackAssociation.h"

#include "TrackingTools/GsfTools/interface/GetComponents.h"

#include "RecoTracker/TransientTrackingRecHit/interface/Traj2TrackHits.h"

#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
Expand Down Expand Up @@ -208,10 +210,8 @@ GsfTrackProducerBase::putInEvt(edm::Event& evt,

//build the GsfTrackExtra
std::vector<reco::GsfComponent5D> outerStates;
outerStates.reserve(outertsos.components().size());
fillStates(outertsos,outerStates);
std::vector<reco::GsfComponent5D> innerStates;
innerStates.reserve(innertsos.components().size());
fillStates(innertsos,innerStates);


Expand Down Expand Up @@ -271,11 +271,11 @@ GsfTrackProducerBase::fillStates (TrajectoryStateOnSurface tsos,
{
reco::GsfComponent5D::ParameterVector pLocS;
reco::GsfComponent5D::CovarianceMatrix cLocS;
std::vector<TrajectoryStateOnSurface> components(tsos.components());
for ( std::vector<TrajectoryStateOnSurface>::const_iterator i=components.begin();
i!=components.end(); ++i ) {
states.push_back(reco::GsfComponent5D(i->weight(),i->localParameters().vector(),i->localError().matrix()));
}
GetComponents comps(tsos);
auto const & components = comps();
states.reserve(components.size());
for (auto const & st : components)
states.emplace_back(st.weight(),st.localParameters().vector(),st.localError().matrix());
}

void
Expand Down
57 changes: 31 additions & 26 deletions RecoTracker/TrackProducer/src/TrackProducerAlgorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "TrackingTools/TrackFitters/interface/RecHitSorter.h"
#include "DataFormats/TrackReco/interface/TrackBase.h"

#include<sstream>

// #define VI_DEBUG
// #define STAT_TSB

Expand Down Expand Up @@ -250,33 +252,36 @@ TrackProducerAlgorithm<reco::GsfTrack>::buildTrack (const TrajectoryFitter * the

auto theTraj = new Trajectory( std::move(trajTmp) );
theTraj->setSeedRef(seedRef);

// TrajectoryStateOnSurface innertsos;
// TrajectoryStateOnSurface outertsos;

// if (theTraj->direction() == alongMomentum) {
// innertsos = theTraj->firstMeasurement().updatedState();
// outertsos = theTraj->lastMeasurement().updatedState();
// } else {
// innertsos = theTraj->lastMeasurement().updatedState();
// outertsos = theTraj->firstMeasurement().updatedState();
// }
// std::cout
// << "Nr. of first / last states = "
// << innertsos.components().size() << " "
// << outertsos.components().size() << std::endl;
// std::vector<TrajectoryStateOnSurface> components =
// innertsos.components();
// double sinTheta =
// sin(innertsos.globalMomentum().theta());
// for ( std::vector<TrajectoryStateOnSurface>::const_iterator ic=components.begin();
// ic!=components.end(); ic++ ) {
// std::cout << " comp " << ic-components.begin() << " "
// << (*ic).weight() << " "
// << (*ic).localParameters().vector()[0]/sinTheta << " "
// << sqrt((*ic).localError().matrix()[0][0])/sinTheta << std::endl;
// }

#ifdef EDM_ML_DEBUG
TrajectoryStateOnSurface innertsos;
TrajectoryStateOnSurface outertsos;

if (theTraj->direction() == alongMomentum) {
innertsos = theTraj->firstMeasurement().updatedState();
outertsos = theTraj->lastMeasurement().updatedState();
} else {
innertsos = theTraj->lastMeasurement().updatedState();
outertsos = theTraj->firstMeasurement().updatedState();
}
std::ostringstream ss;
auto dc = [&](TrajectoryStateOnSurface const & tsos){
std::vector<TrajectoryStateOnSurface> const & components = tsos.components();
auto sinTheta = std::sin(tsos.globalMomentum().theta());
for (auto const & ic : components) ss << ic.weight() << "/"; ss << "\n";
for (auto const & ic : components) ss << ic.localParameters().vector()[0]/sinTheta << "/"; ss << "\n";
for (auto const & ic : components) ss << std::sqrt(ic.localError().matrix()(0,0))/sinTheta << "/";
};
ss << "\ninner comps\n";
dc(innertsos);
ss << "\nouter comps\n";
dc(outertsos);
LogDebug("TrackProducer")
<< "Nr. of first / last states = "
<< innertsos.components().size() << " "
<< outertsos.components().size() << ss.str();
#endif

ndof = 0;
for (auto const & tm : theTraj->measurements()) {
auto const & h = tm.recHitR();
Expand Down
99 changes: 30 additions & 69 deletions RecoTracker/TrackProducer/test/TrackRefit.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,41 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("Refitting")

### standard MessageLoggerConfiguration
process.load("FWCore.MessageService.MessageLogger_cfi")
process = cms.Process("Refitting")

### Standard Configurations
process.load("Configuration.StandardSequences.Services_cff")
process.load('Configuration/StandardSequences/GeometryIdeal_cff')
process.load('Configuration/StandardSequences/Reconstruction_cff')
process.load('Configuration/StandardSequences/MagneticField_AutoFromDBCurrent_cff')


## Fitter-smoother: loosen outlier rejection as for first data-taking with LHC "collisions"
process.KFFittingSmootherWithOutliersRejectionAndRK.BreakTrajWith2ConsecutiveMissing = False
process.KFFittingSmootherWithOutliersRejectionAndRK.EstimateCut = 1000
#process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")
#process.load("Configuration.StandardSequences.MagneticField_cff")
#process.load('Configuration.Geometry.GeometryRecoDB_cff')
#process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")

process.load('Configuration.StandardSequences.Services_cff')
process.load('FWCore.MessageService.MessageLogger_cfi')
process.load('Configuration.EventContent.EventContent_cff')
process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
process.load('Configuration.StandardSequences.MagneticField_cff')
process.load('Configuration.StandardSequences.RawToDigi_cff')
process.load('Configuration.StandardSequences.L1Reco_cff')
process.load('Configuration.StandardSequences.Reconstruction_cff')

process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
from Configuration.AlCa.GlobalTag import GlobalTag
# choose!
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data_GRun', '')
# process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc_GRun', '')



### Conditions
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
#process.GlobalTag.globaltag = "IDEAL_V5::All"
process.GlobalTag.globaltag = 'GR09_P_V6::All'

### Track refitter specific stuff
process.load("RecoTracker.TrackProducer.TrackRefitters_cff") #the correct one
#process.load("RecoTracker.TrackProducer.RefitterWithMaterial_cff") #the one for backward compatibility


process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1)
)

process.source = cms.Source("PoolSource",
### tracks from collisions
fileNames = cms.untracked.vstring(
'rfio:/castor/cern.ch/user/c/chiochia/09_beam_commissioning/BSCskim_123151_Express.root')
#'/store/relval/CMSSW_2_1_10/RelValTTbar/GEN-SIM-DIGI-RAW-HLTDEBUG-RECO/IDEAL_V9_v1/0001/1E04FC31-F99A-DD11-94EE-0018F3D096DE.root')

### tracks from cosmics
# fileNames = cms.untracked.vstring(
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/005F51E5-0373-DD11-B6FA-001731AF6B7D.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/005F51E5-0373-DD11-B6FA-001731AF6B7D.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/006F3A6A-0373-DD11-A8E7-00304876A0FF.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/02CF5B1E-6476-DD11-A034-003048769E65.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/02DF31C3-A775-DD11-91C2-001A92971BB8.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/02F71F56-CE74-DD11-9DD0-001A92810AE4.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/0446C89C-E072-DD11-A341-0018F3D0960C.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/04750FC3-3E73-DD11-B054-00304876A147.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/04DFD531-0473-DD11-964E-0018F3D096AE.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/067111FB-3873-DD11-AD86-00304875A9C5.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/067982F4-E175-DD11-99F7-001731AF6AC5.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/0680EB9B-4F73-DD11-83F8-0018F3D0962E.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/06BF1AF3-E175-DD11-B467-00304876A147.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/0A3843F3-E175-DD11-8419-003048767EE7.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/0A5AAABA-3973-DD11-B949-003048767FA1.root',
# '/store/data/CRUZET4_v1/Cosmics/RECO/CRZT210_V1_SuperPointing_v1/0000/0A911B18-0273-DD11-A5A6-001731A283E1.root')

### tracks from beam halo muons
)

process.TRACKS = cms.OutputModule("PoolOutputModule",
outputCommands = cms.untracked.vstring('drop *_*_*_*',
'keep recoTracks_*_*_*',
'keep recoTrackExtras_*_*_*',
'keep TrackingRecHitsOwned_*_*_*'),

fileName = cms.untracked.string('refitting.root')
)
process.load("RecoTracker.TrackProducer.TrackRefitter_cfi")
process.TrackRefitter.NavigationSchool = ''
process.TrackRefitter.Fitter = 'FlexibleKFFittingSmoother'

process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) )
process.source = cms.Source ("PoolSource",
fileNames=cms.untracked.vstring('file:pickevents_1.root',
),
skipEvents=cms.untracked.uint32(0)
)

process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(-1))

process.p1 = cms.Path(process.TrackRefitter
#process.TrackRefitterP5
#process.TrackRefitterBHM
)
process.outpath = cms.EndPath(process.TRACKS)
process.Path = cms.Path(process.TrackRefitter)