CMS 3D CMS Logo

TrackingRecHitProducer.cc
Go to the documentation of this file.
11 
16 
19 
21 
24 
27 
30 // Pixel-related stuff:
34 
36 
39 
40 #include <map>
41 #include <memory>
42 #include <vector>
43 
45 private:
47  std::vector<std::unique_ptr<TrackingRecHitAlgorithm>> _recHitAlgorithms;
48  unsigned long long _trackerGeometryCacheID = 0;
49  unsigned long long _trackerTopologyCacheID = 0;
50  std::map<unsigned int, TrackingRecHitPipe> _detIdPipes;
51  void setupDetIdPipes(const edm::EventSetup& eventSetup);
52  std::vector<SiPixelTemplateStore> _pixelTempStore; // pixel template storage
53 
54 public:
56 
57  void beginRun(edm::Run const&, const edm::EventSetup& eventSetup) override;
58 
59  void beginStream(edm::StreamID id) override;
60 
61  void produce(edm::Event& event, const edm::EventSetup& eventSetup) override;
62 
63  void endStream() override;
64 
65  ~TrackingRecHitProducer() override;
66 };
67 
69  edm::ConsumesCollector consumeCollector = consumesCollector();
70  const std::vector<edm::ParameterSet>& pluginConfigs = config.getParameter<std::vector<edm::ParameterSet>>("plugins");
71 
72  for (unsigned int iplugin = 0; iplugin < pluginConfigs.size(); ++iplugin) {
73  const edm::ParameterSet& pluginConfig = pluginConfigs[iplugin];
74  const std::string pluginType = pluginConfig.getParameter<std::string>("type");
75  const std::string pluginName = pluginConfig.getParameter<std::string>("name");
76 
77  std::unique_ptr<TrackingRecHitAlgorithm> recHitAlgorithm{
78  TrackingRecHitAlgorithmFactory::get()->tryToCreate(pluginType, pluginName, pluginConfig, consumeCollector)};
79  if (recHitAlgorithm) {
80  edm::LogInfo("TrackingRecHitProducer: ")
81  << "adding plugin type '" << pluginType << "' as '" << pluginName << "'" << std::endl;
82  _recHitAlgorithms.push_back(std::move(recHitAlgorithm));
83  } else {
84  throw cms::Exception("TrackingRecHitAlgorithm plugin not found: ")
85  << "plugin type = " << pluginType << "\nconfiguration=\n"
86  << pluginConfig.dump();
87  }
88  }
89 
90  edm::InputTag simHitTag = config.getParameter<edm::InputTag>("simHits");
91  _simHitToken = consumes<std::vector<PSimHit>>(simHitTag);
92 
93  produces<FastTrackerRecHitCollection>();
94  produces<FastTrackerRecHitRefCollection>("simHit2RecHitMap");
95 }
96 
98 
100  for (auto& algo : _recHitAlgorithms) {
101  algo->beginStream(id);
102  }
103 }
104 
106  //--- Since all pixel algorithms (of which there could be several) use the same
107  // templateStore, filled out from the same DB Object, we need to it centrally
108  // (namely here), and then distribute it to the algorithms. Note that only
109  // the pixel algorithms implement beginRun(), for the strip tracker this defaults
110  // to a no-op.
111 
113  eventSetup.get<SiPixelTemplateDBObjectESProducerRcd>().get(templateDBobject);
114  const SiPixelTemplateDBObject* pixelTemplateDBObject = templateDBobject.product();
115 
116  //--- Now that we have the DB object, load the correct templates from the DB.
117  // (They are needed for data and full sim MC, so in a production FastSim
118  // run, everything should already be in the DB.)
119  if (!SiPixelTemplate::pushfile(*pixelTemplateDBObject, _pixelTempStore)) {
120  throw cms::Exception("TrackingRecHitProducer:")
121  << "SiPixel Templates not loaded correctly from the DB object!" << std::endl;
122  }
123 
124  for (auto& algo : _recHitAlgorithms) {
125  algo->beginRun(run, eventSetup, pixelTemplateDBObject, _pixelTempStore);
126  }
127 }
128 
130  auto const& trackerGeomRec = eventSetup.get<TrackerDigiGeometryRecord>();
131  auto const& trackerTopoRec = eventSetup.get<TrackerTopologyRcd>();
132  if (trackerGeomRec.cacheIdentifier() != _trackerGeometryCacheID or
133  trackerTopoRec.cacheIdentifier() != _trackerTopologyCacheID) {
134  _trackerGeometryCacheID = trackerGeomRec.cacheIdentifier();
135  _trackerTopologyCacheID = trackerTopoRec.cacheIdentifier();
136  edm::ESHandle<TrackerGeometry> trackerGeometryHandle;
137  edm::ESHandle<TrackerTopology> trackerTopologyHandle;
138  trackerGeomRec.get(trackerGeometryHandle);
139  trackerTopoRec.get(trackerTopologyHandle);
140  const TrackerGeometry* trackerGeometry = trackerGeometryHandle.product();
141  const TrackerTopology* trackerTopology = trackerTopologyHandle.product();
142 
143  _detIdPipes.clear();
144 
145  //build pipes for all detIds
146  const std::vector<DetId>& detIds = trackerGeometry->detIds();
147  std::vector<unsigned int> numberOfDetIdsPerAlgorithm(_recHitAlgorithms.size(), 0);
148 
149  for (const DetId& detId : detIds) {
150  TrackerDetIdSelector selector(detId, *trackerTopology);
151 
153  for (unsigned int ialgo = 0; ialgo < _recHitAlgorithms.size(); ++ialgo) {
154  auto& algo = _recHitAlgorithms[ialgo];
155  if (selector.passSelection(algo->getSelectionString())) {
156  numberOfDetIdsPerAlgorithm[ialgo] += 1;
157  pipe.addAlgorithm(algo.get());
158  }
159  }
160  if (pipe.size() == 0) {
161  throw cms::Exception("FastSimulation/TrackingRecHitProducer: DetId not configured! (" +
162  trackerTopology->print(detId) + ")");
163  }
164  _detIdPipes[detId.rawId()] = pipe;
165  }
166  }
167 }
168 
170  //resetup pipes if new iov
171  setupDetIdPipes(eventSetup);
172  //begin event
173  for (auto& algo : _recHitAlgorithms) {
174  algo->beginEvent(event, eventSetup);
175  }
176 
177  //build DetId -> PSimHit map
179  event.getByToken(_simHitToken, simHits);
180 
181  auto output_recHits = std::make_unique<FastTrackerRecHitCollection>();
182  output_recHits->reserve(simHits->size());
183 
184  edm::RefProd<FastTrackerRecHitCollection> output_recHits_refProd =
185  event.getRefBeforePut<FastTrackerRecHitCollection>();
186  auto output_recHitRefs = std::make_unique<FastTrackerRecHitRefCollection>(simHits->size(), FastTrackerRecHitRef());
187 
188  std::map<unsigned int, std::vector<std::pair<unsigned int, const PSimHit*>>> simHitsIdPairPerDetId;
189  for (unsigned int ihit = 0; ihit < simHits->size(); ++ihit) {
190  const PSimHit* simHit = &(*simHits)[ihit];
191  simHitsIdPairPerDetId[simHit->detUnitId()].push_back(std::make_pair(ihit, simHit));
192  }
193 
194  for (auto simHitsIdPairIt = simHitsIdPairPerDetId.begin(); simHitsIdPairIt != simHitsIdPairPerDetId.end();
195  ++simHitsIdPairIt) {
196  const DetId& detId = simHitsIdPairIt->first;
197  std::map<unsigned int, TrackingRecHitPipe>::const_iterator pipeIt = _detIdPipes.find(detId);
198  if (pipeIt != _detIdPipes.cend()) {
199  auto& simHitIdPairList = simHitsIdPairIt->second;
200  const TrackingRecHitPipe& pipe = pipeIt->second;
201 
202  TrackingRecHitProductPtr product = std::make_shared<TrackingRecHitProduct>(detId, simHitIdPairList);
203 
204  product = pipe.produce(product);
205 
206  const std::vector<TrackingRecHitProduct::RecHitToSimHitIdPairs>& recHitToSimHitIdPairsList =
207  product->getRecHitToSimHitIdPairs();
208 
209  for (unsigned int irecHit = 0; irecHit < recHitToSimHitIdPairsList.size(); ++irecHit) {
210  output_recHits->push_back(recHitToSimHitIdPairsList[irecHit].first);
211  const std::vector<TrackingRecHitProduct::SimHitIdPair>& simHitIdPairList =
212  recHitToSimHitIdPairsList[irecHit].second;
213  double energyLoss_tot = 0; //
214  for (unsigned int isimHit = 0; isimHit < simHitIdPairList.size(); ++isimHit) {
215  unsigned int simHitId = simHitIdPairList[isimHit].first;
216  const PSimHit* simHit = simHitIdPairList[isimHit].second;
217  energyLoss_tot +=
218  simHit
219  ->energyLoss(); //energy loss of sim hit in GeV std::cout << "energyLoss_tot" << energyLoss_tot << std::endl;
220  if (not(*output_recHitRefs)[simHitId].isNull()) {
221  throw cms::Exception("FastSimulation/TrackingRecHitProducer",
222  "A PSimHit cannot lead to multiple FastTrackerRecHits");
223  }
224  (*output_recHitRefs)[simHitId] = FastTrackerRecHitRef(output_recHits_refProd, output_recHits->size() - 1);
225  }
226  static_cast<FastSingleTrackerRecHit&>(output_recHits->back()).setEnergyLoss(energyLoss_tot);
227  }
228  } else {
229  //there should be at least an empty pipe for each DetId
230  throw cms::Exception(
231  "FastSimulation/TrackingRecHitProducer",
232  "A PSimHit carries a DetId which does not belong to the TrackerGeometry: " + std::to_string(detId));
233  }
234  }
235 
236  //end event
237  for (auto& algo : _recHitAlgorithms) {
238  algo->endEvent(event, eventSetup);
239  }
240 
241  // note from lukas:
242  // all rechits need a unique id numbers
243  for (unsigned recHitIndex = 0; recHitIndex < output_recHits->size(); ++recHitIndex) {
244  ((FastSingleTrackerRecHit*)&(*output_recHits)[recHitIndex])->setId(recHitIndex);
245  }
246 
247  event.put(std::move(output_recHits));
248  event.put(std::move(output_recHitRefs), "simHit2RecHitMap");
249 }
250 
252  for (auto& algo : _recHitAlgorithms) {
253  algo->endStream();
254  }
255 }
256 
edm::RefProd
Definition: EDProductfwd.h:25
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
edm::StreamID
Definition: StreamID.h:30
validationMuonRPCDigis_cfi.simHitTag
simHitTag
Definition: validationMuonRPCDigis_cfi.py:9
PixelTemplateSmearerBase.h
SiPixelTemplate::pushfile
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore > &pixelTemp, std::string dir="CalibTracker/SiPixelESProducers/data/")
Definition: SiPixelTemplate.cc:129
TrackerGeometry.h
TrackerDetIdSelector.h
ESHandle.h
edm::Run
Definition: Run.h:45
TrackingRecHitProducer::TrackingRecHitProducer
TrackingRecHitProducer(const edm::ParameterSet &config)
Definition: TrackingRecHitProducer.cc:68
edm::EDGetTokenT
Definition: EDGetToken.h:33
TrackerTopology
Definition: TrackerTopology.h:16
TrackingRecHitProducer::produce
void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
Definition: TrackingRecHitProducer.cc:169
EDProducer.h
FastTrackerRecHitCombiner_cfi.simHits
simHits
Definition: FastTrackerRecHitCombiner_cfi.py:5
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
TrackingRecHitProducer::_trackerTopologyCacheID
unsigned long long _trackerTopologyCacheID
Definition: TrackingRecHitProducer.cc:49
TrackingRecHitProducer::beginRun
void beginRun(edm::Run const &, const edm::EventSetup &eventSetup) override
Definition: TrackingRecHitProducer.cc:105
edm::Handle
Definition: AssociativeIterator.h:50
config
Definition: config.py:1
DetId
Definition: DetId.h:17
cmsdt::algo
algo
Definition: constants.h:165
MakerMacros.h
TrackerTopology.h
SiPixelTemplate.h
TrackingRecHitPipe
Definition: TrackingRecHitPipe.h:9
PSimHit.h
TrackerTopologyRcd.h
TrackingRecHitProductPtr
std::shared_ptr< TrackingRecHitProduct > TrackingRecHitProductPtr
Definition: TrackingRecHitProduct.h:47
TrackingRecHitProducer::_recHitAlgorithms
std::vector< std::unique_ptr< TrackingRecHitAlgorithm > > _recHitAlgorithms
Definition: TrackingRecHitProducer.cc:47
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrackingRecHitProducer::endStream
void endStream() override
Definition: TrackingRecHitProducer.cc:251
rpcPointValidation_cfi.simHit
simHit
Definition: rpcPointValidation_cfi.py:24
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
TrackerDetIdSelector
Definition: TrackerDetIdSelector.h:94
Run.h
FastTrackerRecHitRef
edm::Ref< FastTrackerRecHitCollection > FastTrackerRecHitRef
Definition: FastTrackerRecHitCollection.h:9
edm::ESHandle
Definition: DTSurvey.h:22
TrackerTopology::print
std::string print(DetId detid) const
Definition: TrackerTopology.cc:252
SiPixelTemplateDBObjectESProducerRcd.h
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:109
EDGetToken.h
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
pipe
Definition: pipe.py:1
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TrackerDigiGeometryRecord.h
edm::ParameterSet
Definition: ParameterSet.h:47
TrackingRecHitProducer
Definition: TrackingRecHitProducer.cc:44
SiPixelTemplateDBObject.h
RefVector.h
Event.h
FastSingleTrackerRecHit.h
FastSingleTrackerRecHit
Definition: FastSingleTrackerRecHit.h:7
SiPixelTemplateDBObject
Definition: SiPixelTemplateDBObject.h:16
TrackingRecHitProducer::setupDetIdPipes
void setupDetIdPipes(const edm::EventSetup &eventSetup)
Definition: TrackingRecHitProducer.cc:129
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
FastTrackerRecHitCollection.h
TrackingRecHitProducer::~TrackingRecHitProducer
~TrackingRecHitProducer() override
Definition: TrackingRecHitProducer.cc:97
TrackingRecHitProducer::_pixelTempStore
std::vector< SiPixelTemplateStore > _pixelTempStore
Definition: TrackingRecHitProducer.cc:52
get
#define get
TrackingRecHitPipe.h
InputTag.h
SiPixelTemplateDBObjectESProducerRcd
Definition: SiPixelTemplateDBObjectESProducerRcd.h:11
TrackingRecHitProducer::_detIdPipes
std::map< unsigned int, TrackingRecHitPipe > _detIdPipes
Definition: TrackingRecHitProducer.cc:50
TrackingRecHitAlgorithmFactory.h
TrackingRecHitProducer_cfi.pluginConfig
pluginConfig
Definition: TrackingRecHitProducer_cfi.py:66
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
TrackingRecHitProducer::_trackerGeometryCacheID
unsigned long long _trackerGeometryCacheID
Definition: TrackingRecHitProducer.cc:48
TrackingRecHitAlgorithm.h
TrackerDetIdSelector::passSelection
bool passSelection(const std::string &selectionStr) const
Definition: TrackerDetIdSelector.cc:166
DetId.h
Exception
Definition: hltDiff.cc:245
EventSetup.h
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
TrackerGeometry::detIds
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
Definition: TrackerGeometry.h:64
DetSetNew.h
TrackingRecHitProducer::beginStream
void beginStream(edm::StreamID id) override
Definition: TrackingRecHitProducer.cc:99
TrackingRecHitProducer::_simHitToken
edm::EDGetTokenT< std::vector< PSimHit > > _simHitToken
Definition: TrackingRecHitProducer.cc:46
ConsumesCollector.h
edm::eventsetup::EventSetupRecord::cacheIdentifier
unsigned long long cacheIdentifier() const
Definition: EventSetupRecord.h:187
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
pipe.pipe
def pipe(cmdline, input=None)
Definition: pipe.py:5
ParameterSet.h
PSimHit
Definition: PSimHit.h:15
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::OwnVector::size
size_type size() const
Definition: OwnVector.h:300
DetSetVectorNew.h
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
edm::OwnVector
Definition: OwnVector.h:24
TrackerGeometry
Definition: TrackerGeometry.h:14