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

Add EDProducers for mkFit #27895

Merged
merged 20 commits into from Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 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
2 changes: 2 additions & 0 deletions Configuration/PyReleaseValidation/python/relval_2017.py
Expand Up @@ -23,6 +23,7 @@
# he collapse: TTbar, TTbar PU, TTbar design
# ParkingBPH: TTbar
# 2021 (ZMM, TTbar, ZEE, MinBias, TTbar PU, TTbar PU premix, ZEE PU, TTbar design)
# (TTbar trackingMkFit)
# 2023 (TTbar, TTbar PU, TTbar PU premix)
# 2024 (TTbar, TTbar PU, TTbar PU premix)
numWFIB = [10001.0,10002.0,10003.0,10004.0,10005.0,10006.0,10007.0,10008.0,10009.0,10059.0,10071.0,
Expand All @@ -34,6 +35,7 @@
10824.6,11024.6,11224.6,
10824.8,
11650.0,11634.0,11646.0,11640.0,11834.0,11834.99,11846.0,12024.0,
11634.7,
12434.0,12634.0,12634.99,
12834.0,13034.0,13034.99]
for numWF in numWFIB:
Expand Down
7 changes: 7 additions & 0 deletions Configuration/PyReleaseValidation/python/relval_steps.py
Expand Up @@ -2090,6 +2090,9 @@ def gen2018HiMix(fragment,howMuch):
step3_trackingLowPU = {
'--era': 'Run2_2016_trackingLowPU'
}
step3_trackingMkFit = {
'--customise': 'RecoTracker/MkFit/customizeInitialStepToMkFit.customizeInitialStepToMkFit'
}
step3_HIPM = {
'--era': 'Run2_2016_HIPM'
}
Expand Down Expand Up @@ -3240,6 +3243,10 @@ def gen2018HiMix(fragment,howMuch):
if 'Reco' in step and upgradeStepDict[step][k]['--era']=='Run2_2017':
upgradeStepDict[stepName][k] = merge([{'--era': 'Run2_2017_trackingLowPU'}, upgradeStepDict[step][k]])

for step in upgradeSteps['trackingMkFit']['steps']:
stepName = step + upgradeSteps['trackingMkFit']['suffix']
if 'Reco' in step: upgradeStepDict[stepName][k] = merge([step3_trackingMkFit, upgradeStepDict[step][k]])

for step in upgradeSteps['Neutron']['steps']:
if 'GenSim' in step:
custNew = "SimG4Core/Application/NeutronBGforMuonsXS_cff.customise"
Expand Down
4 changes: 3 additions & 1 deletion Configuration/PyReleaseValidation/python/relval_upgrade.py
Expand Up @@ -73,7 +73,7 @@ def makeStepName(key,frag,step,suffix):
# special workflows for tracker
if (upgradeDatasetFromFragment[frag]=="TTbar_13" or upgradeDatasetFromFragment[frag]=="TTbar_14TeV") and not 'PU' in key and hasHarvest:
# skip ALCA and Nano
trackingVariations = ['trackingOnly','trackingRun2','trackingOnlyRun2','trackingLowPU','pixelTrackingOnly']
trackingVariations = ['trackingOnly','trackingRun2','trackingOnlyRun2','trackingLowPU','pixelTrackingOnly','trackingMkFit']
for tv in trackingVariations:
stepList[tv] = [s for s in stepList[tv] if (("ALCA" not in s) and ("Nano" not in s))]
workflows[numWF+upgradeSteps['trackingOnly']['offset']] = [ upgradeDatasetFromFragment[frag], stepList['trackingOnly']]
Expand All @@ -82,6 +82,8 @@ def makeStepName(key,frag,step,suffix):
workflows[numWF+upgradeSteps[tv]['offset']] = [ upgradeDatasetFromFragment[frag], stepList[tv]]
elif '2018' in key:
workflows[numWF+upgradeSteps['pixelTrackingOnly']['offset']] = [ upgradeDatasetFromFragment[frag], stepList['pixelTrackingOnly']]
elif '2021' in key:
workflows[numWF+upgradeSteps['trackingMkFit']['offset']] = [ upgradeDatasetFromFragment[frag], stepList['trackingMkFit']]

# special workflows for HGCAL/TICL
if (upgradeDatasetFromFragment[frag]=="CloseByParticleGun") and ('2026' in key):
Expand Down
Expand Up @@ -188,6 +188,15 @@
'suffix' : '_heCollapse',
'offset' : 0.6,
}
upgradeSteps['trackingMkFit'] = {
'steps' : [
'RecoFull',
'RecoFullGlobal',
],
'PU' : [],
'suffix' : '_trackingMkFit',
'offset' : 0.7,
}
upgradeSteps['ParkingBPH'] = {
'steps' : [
'RecoFull',
Expand Down
8 changes: 8 additions & 0 deletions RecoTracker/MkFit/BuildFile.xml
@@ -0,0 +1,8 @@
<use name="DataFormats/Provenance"/>
<use name="FWCore/Framework"/>
<use name="FWCore/MessageLogger"/>
<use name="mkfit"/>
makortel marked this conversation as resolved.
Show resolved Hide resolved
<use name="rootcore"/>
<export>
<lib name="RecoTrackerMkFit"/>
</export>
30 changes: 30 additions & 0 deletions RecoTracker/MkFit/README.md
@@ -0,0 +1,30 @@
# mkFit

This package holds the glue modules for running
[mkFit](http://trackreco.github.io/) within CMSSW.

Note that at the moment there may be only one `MkFitProducer` in a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the cause of this restriction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are non-const global variables that are used during the initialization (the pattern recognition part is thread safe). This restriction is something that will be addressed (I hope rather sooner than later).

single job. This restriction will be removed in the future.

Also note that at the moment the mkFit works only with the CMS phase1
tracker detector. Support for the phase2 tracker will be added later.

## Customize functions for runTheMatrix workflows (offline reconstruction)

* `RecoTracker/MkFit/customizeInitialStepToMkFit.customizeInitialStepToMkFit`
* Replaces initialStep track building module with `mkFit`.
* `RecoTracker/MkFit/customizeInitialStepOnly.customizeInitialStepOnly`
* Run only the initialStep tracking. In practice this configuration
runs the initialStepPreSplitting iteration, but named as
initialStep. MultiTrackValidator is included, and configured to
monitor initialStep. Intended to provide the minimal configuration
for CMSSW tests.
* `RecoTracker/MkFit/customizeInitialStepOnly.customizeInitialStepOnlyNoMTV`
* Otherwise same as `customizeInitialStepOnly` except drops
MultiTrackValidator. Intended for profiling.


These can be used with e.g.
```bash
$ runTheMatrix.py -l <workflow(s)> --apply 2 --command "--customise RecoTracker/MkFit/customizeInitialStepToMkFit.customizeInitialStepToMkFit"
```
86 changes: 86 additions & 0 deletions RecoTracker/MkFit/interface/MkFitHitIndexMap.h
@@ -0,0 +1,86 @@
#ifndef RecoTracker_MkFit_MkFitHitIndexMap_h
#define RecoTracker_MkFit_MkFitHitIndexMap_h

#include "DataFormats/Provenance/interface/ProductID.h"

#include <vector>

class TrackingRecHit;

/**
* This class provides mappings
* - from CMSSW(ProductID, cluster index) to mkFit(layer index, hit index)
* - from mkFit(layer index, hit index) to pointer to CMSSW hit
*/
class MkFitHitIndexMap {
public:
// This class holds the index and layer of a hit in the hit data
// structure passed to mkFit
class MkFitHit {
public:
MkFitHit() = default;
explicit MkFitHit(int i, int l) : index_{i}, layer_{l} {}

int index() const { return index_; }
int layer() const { return layer_; }

private:
int index_ = -1;
int layer_ = -1;
};

MkFitHitIndexMap() = default;

/**
* Can be used to preallocate the internal vectors for CMSSW->mkFit mapping
*/
void resizeByClusterIndex(edm::ProductID id, size_t clusterIndex);

/**
* Can be used to preallocate the internal vectors for mkFit->CMSSW mapping
*
* \param layer Layer index (in mkFit convention)
* \param additionalSize Number of additional elements to make space for
*/
void increaseLayerSize(int layer, size_t additionalSize);

/**
* Inserts a new hit in the mapping
*
* \param id ProductID of the cluster collection
* \param clusterIndex Index of the cluster in the cluster collection
* \param hit Index and layer of the hit in the mkFit hit data structure
* \param hitPtr Pointer to the TrackingRecHit
*/
void insert(edm::ProductID id, size_t clusterIndex, MkFitHit hit, const TrackingRecHit* hitPtr);

/// Get mkFit hit index and layer
const MkFitHit& mkFitHit(edm::ProductID id, size_t clusterIndex) const;

/// Get CMSSW hit pointer
const TrackingRecHit* hitPtr(MkFitHit hit) const { return mkFitToCMSSW_.at(hit.layer()).at(hit.index()).ptr; }

/// Get CMSSW cluster index (currently used only for debugging)
size_t clusterIndex(MkFitHit hit) const { return mkFitToCMSSW_.at(hit.layer()).at(hit.index()).clusterIndex; }

private:
// Helper struct to map (edm::ProductID, cluster index) to MkFitHit
struct ClusterToMkFitHit {
explicit ClusterToMkFitHit(edm::ProductID id) : productID(id) {}
edm::ProductID productID;
std::vector<MkFitHit> mkFitHits; // indexed by cluster index
};

// Helper struct to map MkFitHit to (TrackingRecHit *, cluster index)
struct CMSSWHit {
CMSSWHit() = default;
explicit CMSSWHit(const TrackingRecHit* p, size_t i) : ptr{p}, clusterIndex{i} {}
const TrackingRecHit* ptr = nullptr;
size_t clusterIndex = 0;
};

std::vector<ClusterToMkFitHit> cmsswToMkFit_; // mapping from CMSSW(ProductID, cluster index) -> mkFit(index, layer)
std::vector<std::vector<CMSSWHit> > mkFitToCMSSW_; // reverse mapping, mkFit(layer, index) -> CMSSW hit
};

#endif
44 changes: 44 additions & 0 deletions RecoTracker/MkFit/interface/MkFitInputWrapper.h
@@ -0,0 +1,44 @@
#ifndef RecoTracker_MkFit_MkFitInputWrapper_h
#define RecoTracker_MkFit_MkFitInputWrapper_h

#include "RecoTracker/MkFit/interface/MkFitHitIndexMap.h"

#include <memory>
#include <vector>

namespace mkfit {
class Hit;
class Track;
class LayerNumberConverter;
using HitVec = std::vector<Hit>;
using TrackVec = std::vector<Track>;
} // namespace mkfit

class MkFitInputWrapper {
public:
MkFitInputWrapper();
MkFitInputWrapper(MkFitHitIndexMap&& hitIndexMap,
std::vector<mkfit::HitVec>&& hits,
mkfit::TrackVec&& seeds,
mkfit::LayerNumberConverter&& lnc);
~MkFitInputWrapper();

MkFitInputWrapper(MkFitInputWrapper const&) = delete;
MkFitInputWrapper& operator=(MkFitInputWrapper const&) = delete;
MkFitInputWrapper(MkFitInputWrapper&&);
MkFitInputWrapper& operator=(MkFitInputWrapper&&);

MkFitHitIndexMap const& hitIndexMap() const { return hitIndexMap_; }
mkfit::TrackVec const& seeds() const { return *seeds_; }
std::vector<mkfit::HitVec> const& hits() const { return hits_; }
mkfit::LayerNumberConverter const& layerNumberConverter() const { return *lnc_; }
unsigned int nlayers() const;

private:
MkFitHitIndexMap hitIndexMap_;
std::vector<mkfit::HitVec> hits_;
std::unique_ptr<mkfit::TrackVec> seeds_; // for pimpl pattern
std::unique_ptr<mkfit::LayerNumberConverter> lnc_; // for pimpl pattern
};

#endif
30 changes: 30 additions & 0 deletions RecoTracker/MkFit/interface/MkFitOutputWrapper.h
@@ -0,0 +1,30 @@
#ifndef RecoTracker_MkFit_MkFitOutputWrapper_h
#define RecoTracker_MkFit_MkFitOutputWrapper_h

#include <vector>

namespace mkfit {
class Track;
using TrackVec = std::vector<Track>;
} // namespace mkfit

class MkFitOutputWrapper {
public:
MkFitOutputWrapper();
MkFitOutputWrapper(mkfit::TrackVec&& candidateTracks, mkfit::TrackVec&& fitTracks);
~MkFitOutputWrapper();

MkFitOutputWrapper(MkFitOutputWrapper const&) = delete;
MkFitOutputWrapper& operator=(MkFitOutputWrapper const&) = delete;
MkFitOutputWrapper(MkFitOutputWrapper&&);
MkFitOutputWrapper& operator=(MkFitOutputWrapper&&);

mkfit::TrackVec const& candidateTracks() const { return candidateTracks_; }
mkfit::TrackVec const& fitTracks() const { return fitTracks_; }

private:
mkfit::TrackVec candidateTracks_;
mkfit::TrackVec fitTracks_;
};

#endif
27 changes: 27 additions & 0 deletions RecoTracker/MkFit/plugins/BuildFile.xml
@@ -0,0 +1,27 @@
<library file="*.cc" name="RecoTrackerMkFitPlugins">
<use name="DataFormats/TrackCandidate"/>
<use name="DataFormats/TrackReco"/>
<use name="DataFormats/TrackerCommon"/>
<use name="DataFormats/TrackerRecHit2D"/>
<use name="DataFormats/TrajectorySeed"/>
<use name="FWCore/Framework"/>
<use name="FWCore/MessageLogger"/>
<use name="FWCore/ParameterSet"/>
<use name="FWCore/PluginManager"/>
<use name="Geometry/Records"/>
<use name="Geometry/TrackerGeometryBuilder"/>
<use name="RecoTracker/MeasurementDet"/>
<use name="RecoTracker/MkFit"/>
<use name="RecoTracker/TkDetLayers"/>
<use name="RecoTracker/TransientTrackingRecHit"/>
<use name="TrackingTools/GeomPropagators"/>
<use name="TrackingTools/KalmanUpdators"/>
<use name="TrackingTools/MaterialEffects"/>
<use name="TrackingTools/Records"/>
<use name="TrackingTools/TrackFitters"/>
<use name="TrackingTools/TrajectoryState"/>
<use name="TrackingTools/TransientTrackingRecHit"/>
<use name="mkfit"/>
<use name="rootmath"/>
<flags EDM_PLUGIN="1"/>
</library>