CMS 3D CMS Logo

MkFitProducer.cc
Go to the documentation of this file.
2 
7 
10 
13 
16 
17 // mkFit includes
18 #include "ConfigWrapper.h"
19 #include "Event.h"
20 #include "mkFit/buildtestMPlex.h"
21 #include "mkFit/MkBuilderWrapper.h"
22 
23 // TBB includes
24 #include "tbb/task_arena.h"
25 
26 // std includes
27 #include <functional>
28 
29 class MkFitProducer : public edm::global::EDProducer<edm::StreamCache<mkfit::MkBuilderWrapper> > {
30 public:
31  explicit MkFitProducer(edm::ParameterSet const& iConfig);
32  ~MkFitProducer() override = default;
33 
34  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
35 
36  std::unique_ptr<mkfit::MkBuilderWrapper> beginStream(edm::StreamID) const override;
37 
38 private:
39  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
40 
44  std::function<double(mkfit::Event&, mkfit::MkBuilder&)> buildFunction_;
47 };
48 
50  : hitsSeedsToken_{consumes<MkFitInputWrapper>(iConfig.getParameter<edm::InputTag>("hitsSeeds"))},
51  geomToken_{esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()},
52  putToken_{produces<MkFitOutputWrapper>()},
53  backwardFitInCMSSW_{iConfig.getParameter<bool>("backwardFitInCMSSW")},
54  mkFitSilent_{iConfig.getUntrackedParameter<bool>("mkFitSilent")} {
55  const auto build = iConfig.getParameter<std::string>("buildingRoutine");
56  bool isFV = false;
57  if (build == "bestHit") {
58  buildFunction_ = mkfit::runBuildingTestPlexBestHit;
59  } else if (build == "standard") {
60  buildFunction_ = mkfit::runBuildingTestPlexStandard;
61  } else if (build == "cloneEngine") {
62  buildFunction_ = mkfit::runBuildingTestPlexCloneEngine;
63  } else if (build == "fullVector") {
64  isFV = true;
65  buildFunction_ = mkfit::runBuildingTestPlexFV;
66  } else {
67  throw cms::Exception("Configuration") << "Invalid value for parameter 'buildingRoutine' " << build
68  << ", allowed are bestHit, standard, cloneEngine, fullVector";
69  }
70 
71  const auto seedClean = iConfig.getParameter<std::string>("seedCleaning");
72  auto seedCleanOpt = mkfit::ConfigWrapper::SeedCleaningOpts::noCleaning;
73  if (seedClean == "none") {
74  seedCleanOpt = mkfit::ConfigWrapper::SeedCleaningOpts::noCleaning;
75  } else if (seedClean == "N2") {
76  seedCleanOpt = mkfit::ConfigWrapper::SeedCleaningOpts::cleanSeedsN2;
77  } else {
78  throw cms::Exception("Configuration")
79  << "Invalida value for parameter 'seedCleaning' " << seedClean << ", allowed are none, N2";
80  }
81 
82  auto backwardFitOpt =
83  backwardFitInCMSSW_ ? mkfit::ConfigWrapper::BackwardFit::noFit : mkfit::ConfigWrapper::BackwardFit::toFirstLayer;
84 
85  // TODO: what to do when we have multiple instances of MkFitProducer in a job?
86  mkfit::MkBuilderWrapper::populate(isFV);
87  mkfit::ConfigWrapper::initializeForCMSSW(seedCleanOpt, backwardFitOpt, mkFitSilent_);
88 }
89 
92 
93  desc.add("hitsSeeds", edm::InputTag("mkFitInputConverter"));
94  desc.add<std::string>("buildingRoutine", "cloneEngine")
95  ->setComment("Valid values are: 'bestHit', 'standard', 'cloneEngine', 'fullVector'");
96  desc.add<std::string>("seedCleaning", "N2")->setComment("Valid values are: 'none', 'N2'");
97  desc.add("backwardFitInCMSSW", false)
98  ->setComment("Do backward fit (to innermost hit) in CMSSW (true) or mkFit (false)");
99  desc.addUntracked("mkFitSilent", true)->setComment("Allows to enables printouts from mkFit with 'False'");
100 
101  descriptions.add("mkFitProducer", desc);
102 }
103 
104 std::unique_ptr<mkfit::MkBuilderWrapper> MkFitProducer::beginStream(edm::StreamID iID) const {
105  return std::make_unique<mkfit::MkBuilderWrapper>();
106 }
107 
108 namespace {
109  std::once_flag geometryFlag;
110 }
112  const auto& hitsSeeds = iEvent.get(hitsSeedsToken_);
113  const auto& geom = iSetup.getData(geomToken_);
114 
115  if (geom.numberOfLayers(PixelSubdetector::PixelBarrel) != 4 ||
116  geom.numberOfLayers(PixelSubdetector::PixelEndcap) != 3) {
117  throw cms::Exception("Assert") << "For now this code works only with phase1 tracker, you have something else";
118  }
119 
120  // Initialize the number of layers, has to be done exactly once in
121  // the whole program.
122  // TODO: the mechanism needs to be improved...
123  std::call_once(geometryFlag, [nlayers = hitsSeeds.nlayers()]() { mkfit::ConfigWrapper::setNTotalLayers(nlayers); });
124 
125  // CMSSW event ID (64-bit unsigned) does not fit in int
126  // In addition, unique ID requires also lumi and run
127  // But does the event ID really matter within mkFit?
128  mkfit::Event ev(iEvent.id().event());
129 
130  ev.setInputFromCMSSW(hitsSeeds.hits(), hitsSeeds.seeds());
131 
132  tbb::this_task_arena::isolate([&]() { buildFunction_(ev, streamCache(iID)->get()); });
133 
134  iEvent.emplace(putToken_, std::move(ev.candidateTracks_), std::move(ev.fitTracks_));
135 }
136 
edm::StreamID
Definition: StreamID.h:30
PixelSubdetector.h
MkFitProducer::mkFitSilent_
bool mkFitSilent_
Definition: MkFitProducer.cc:46
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
TrackerGeometry.h
MkFitProducer
Definition: MkFitProducer.cc:29
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
ESHandle.h
edm::EDGetTokenT< MkFitInputWrapper >
edm::EDPutTokenT< MkFitOutputWrapper >
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
MkFitProducer::putToken_
edm::EDPutTokenT< MkFitOutputWrapper > putToken_
Definition: MkFitProducer.cc:43
MkFitOutputWrapper.h
InitialStep_cff.hitsSeeds
hitsSeeds
Definition: InitialStep_cff.py:233
newFWLiteAna.build
build
Definition: newFWLiteAna.py:126
MakerMacros.h
MkFitProducer::buildFunction_
std::function< double(mkfit::Event &, mkfit::MkBuilder &)> buildFunction_
Definition: MkFitProducer.cc:44
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
MkFitProducer::backwardFitInCMSSW_
bool backwardFitInCMSSW_
Definition: MkFitProducer.cc:45
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
MkFitProducer::produce
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: MkFitProducer.cc:111
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TrackerDigiGeometryRecord.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
MkFitProducer::beginStream
std::unique_ptr< mkfit::MkBuilderWrapper > beginStream(edm::StreamID) const override
Definition: MkFitProducer.cc:104
iEvent
int iEvent
Definition: GenABIO.cc:224
MkFitInputWrapper.h
MkFitProducer::geomToken_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
Definition: MkFitProducer.cc:42
edm::EventSetup
Definition: EventSetup.h:57
MkFitProducer::~MkFitProducer
~MkFitProducer() override=default
get
#define get
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:120
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
MkFitProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: MkFitProducer.cc:90
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
Exception
Definition: hltDiff.cc:246
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
MkFitProducer::hitsSeedsToken_
edm::EDGetTokenT< MkFitInputWrapper > hitsSeedsToken_
Definition: MkFitProducer.cc:41
StripSubdetector.h
edm::InputTag
Definition: InputTag.h:15
MkFitProducer::MkFitProducer
MkFitProducer(edm::ParameterSet const &iConfig)
Definition: MkFitProducer.cc:49
nlayers
Definition: HIMultiTrackSelector.h:48