CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackingRecHitProducer.cc
Go to the documentation of this file.
12 
16 
19 
21 
24 
27 
30 
32 
35 
36 #include <map>
37 #include <memory>
38 #include <vector>
39 
42 {
43  private:
45  std::vector<TrackingRecHitAlgorithm*> _recHitAlgorithms;
47  std::map<unsigned int, TrackingRecHitPipe> _detIdPipes;
48  void setupDetIdPipes(const edm::EventSetup& eventSetup);
49 
50  public:
52 
53  virtual void beginRun(edm::Run const&, const edm::EventSetup& eventSetup);
54 
55  virtual void beginStream(edm::StreamID id);
56 
57  virtual void produce(edm::Event& event, const edm::EventSetup& eventSetup);
58 
59  virtual void endStream();
60 
61  virtual ~TrackingRecHitProducer();
62 };
63 
64 
66 {
67  edm::ConsumesCollector consumeCollector = consumesCollector();
68  const std::vector<edm::ParameterSet>& pluginConfigs = config.getParameter<std::vector<edm::ParameterSet>>("plugins");
69 
70  for (unsigned int iplugin = 0; iplugin<pluginConfigs.size(); ++iplugin)
71  {
72  const edm::ParameterSet& pluginConfig = pluginConfigs[iplugin];
73  const std::string pluginType = pluginConfig.getParameter<std::string>("type");
74  const std::string pluginName = pluginConfig.getParameter<std::string>("name");
75 
76  TrackingRecHitAlgorithm* recHitAlgorithm = TrackingRecHitAlgorithmFactory::get()->tryToCreate(pluginType,pluginName,pluginConfig,consumeCollector);
77  if (recHitAlgorithm)
78  {
79  edm::LogInfo("TrackingRecHitProducer: ")<< "adding plugin type '"<<pluginType<<"' as '"<<pluginName<<"'"<<std::endl;
80  _recHitAlgorithms.push_back(recHitAlgorithm);
81  }
82  else
83  {
84  throw cms::Exception("TrackingRecHitAlgorithm plugin not found: ") << "plugin type = "<<pluginType<<"\nconfiguration=\n"<<pluginConfig.dump();
85  }
86  }
87 
88  edm::InputTag simHitTag = config.getParameter<edm::InputTag>("simHits");
89  _simHitToken = consumes<std::vector<PSimHit>>(simHitTag);
90 
91  produces<FastTrackerRecHitCollection>();
92  produces<FastTrackerRecHitRefCollection>("simHit2RecHitMap");
93 }
94 
96 {
98  {
99  delete algo;
100  }
101  _recHitAlgorithms.clear();
102 }
103 
105 {
107  {
108  algo->beginStream(id);
109  }
110 }
111 
113 {
114 
115 }
116 
118 {
119  if (_iovSyncValue!=eventSetup.iovSyncValue())
120  {
121  _iovSyncValue=eventSetup.iovSyncValue();
122  edm::ESHandle<TrackerGeometry> trackerGeometryHandle;
123  edm::ESHandle<TrackerTopology> trackerTopologyHandle;
124  eventSetup.get<TrackerDigiGeometryRecord>().get(trackerGeometryHandle);
125  eventSetup.get<TrackerTopologyRcd>().get(trackerTopologyHandle);
126  const TrackerGeometry* trackerGeometry = trackerGeometryHandle.product();
127  const TrackerTopology* trackerTopology = trackerTopologyHandle.product();
128 
129  _detIdPipes.clear();
130 
131  //build pipes for all detIds
132  const std::vector<DetId>& detIds = trackerGeometry->detIds();
133  std::vector<unsigned int> numberOfDetIdsPerAlgorithm(_recHitAlgorithms.size(),0);
134 
135  for (const DetId& detId: detIds)
136  {
137  TrackerDetIdSelector selector(detId,*trackerTopology);
138 
140  for (unsigned int ialgo = 0; ialgo < _recHitAlgorithms.size(); ++ialgo)
141  {
143  if (selector.passSelection(algo->getSelectionString()))
144  {
145  numberOfDetIdsPerAlgorithm[ialgo]+=1;
146  pipe.addAlgorithm(algo);
147  }
148  }
149  if (pipe.size()==0)
150  {
151  throw cms::Exception("FastSimulation/TrackingRecHitProducer: DetId not configured! ("+trackerTopology->print(detId)+")");
152  }
153  _detIdPipes[detId.rawId()]=pipe;
154  }
155  }
156 }
157 
159 {
160 
161 
162  //resetup pipes if new iov
163  setupDetIdPipes(eventSetup);
164  //begin event
166  {
167  algo->beginEvent(event,eventSetup);
168  }
169 
170  //build DetId -> PSimHit map
172  event.getByToken(_simHitToken,simHits);
173 
174  std::unique_ptr<FastTrackerRecHitCollection> output_recHits(new FastTrackerRecHitCollection);
175  output_recHits->reserve(simHits->size());
176 
177  edm::RefProd<FastTrackerRecHitCollection> output_recHits_refProd = event.getRefBeforePut<FastTrackerRecHitCollection>();
178  std::unique_ptr<FastTrackerRecHitRefCollection> output_recHitRefs(new FastTrackerRecHitRefCollection(simHits->size(),FastTrackerRecHitRef()));
179 
180  std::map<unsigned int,std::vector<std::pair<unsigned int,const PSimHit*>>> simHitsIdPairPerDetId;
181  for (unsigned int ihit = 0; ihit < simHits->size(); ++ihit)
182  {
183  const PSimHit* simHit = &(*simHits)[ihit];
184  simHitsIdPairPerDetId[simHit->detUnitId()].push_back(std::make_pair(ihit,simHit));
185  }
186 
187  for (auto simHitsIdPairIt = simHitsIdPairPerDetId.begin(); simHitsIdPairIt != simHitsIdPairPerDetId.end(); ++simHitsIdPairIt)
188  {
189  const DetId& detId = simHitsIdPairIt->first;
190  std::map<unsigned int, TrackingRecHitPipe>::const_iterator pipeIt = _detIdPipes.find(detId);
191  if (pipeIt!=_detIdPipes.cend())
192  {
193  auto& simHitIdPairList = simHitsIdPairIt->second;
194  const TrackingRecHitPipe& pipe = pipeIt->second;
195 
196  TrackingRecHitProductPtr product = std::make_shared<TrackingRecHitProduct>(detId,simHitIdPairList);
197 
198  product = pipe.produce(product);
199 
200  const std::vector<TrackingRecHitProduct::RecHitToSimHitIdPairs>& recHitToSimHitIdPairsList = product->getRecHitToSimHitIdPairs();
201 
202 
203  for (unsigned int irecHit = 0; irecHit < recHitToSimHitIdPairsList.size(); ++irecHit)
204  {
205  output_recHits->push_back(recHitToSimHitIdPairsList[irecHit].first);
206  const std::vector<TrackingRecHitProduct::SimHitIdPair>& simHitIdPairList = recHitToSimHitIdPairsList[irecHit].second;
207  for (unsigned int isimHit = 0; isimHit < simHitIdPairList.size(); ++isimHit)
208  {
209  unsigned int simHitId = simHitIdPairList[isimHit].first;
210  if (not (*output_recHitRefs)[simHitId].isNull())
211  {
212  throw cms::Exception("FastSimulation/TrackingRecHitProducer","A PSimHit cannot lead to multiple FastTrackerRecHits");
213  }
214  (*output_recHitRefs)[simHitId] = FastTrackerRecHitRef(output_recHits_refProd,output_recHits->size()-1);
215  }
216  }
217  }
218  else
219  {
220  //there should be at least an empty pipe for each DetId
221  throw cms::Exception("FastSimulation/TrackingRecHitProducer","A PSimHit carries a DetId which does not belong to the TrackerGeometry: "+std::to_string(detId));
222  }
223  }
224 
225  //end event
226  for (TrackingRecHitAlgorithm* algo: _recHitAlgorithms)
227  {
228  algo->endEvent(event,eventSetup);
229  }
230 
231  // note from lukas:
232  // all rechits need a unique id numbers
233  for(unsigned recHitIndex = 0; recHitIndex < output_recHits->size(); ++recHitIndex)
234  {
235  ((FastSingleTrackerRecHit*)&(*output_recHits)[recHitIndex])->setId(recHitIndex);
236  }
237 
238  event.put(std::move(output_recHits));
239  event.put(std::move(output_recHitRefs),"simHit2RecHitMap");
240 
241 }
242 
244 {
246  {
247  algo->endStream();
248  }
249 }
250 
T getParameter(std::string const &) const
virtual void beginRun(edm::Run const &, const edm::EventSetup &eventSetup)
std::string dump(unsigned int indent=0) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setupDetIdPipes(const edm::EventSetup &eventSetup)
std::map< unsigned int, TrackingRecHitPipe > _detIdPipes
virtual void beginStream(edm::StreamID id)
def pipe
Definition: pipe.py:5
void addAlgorithm(TrackingRecHitAlgorithm *algorithm)
edm::EDGetTokenT< std::vector< PSimHit > > _simHitToken
std::string print(DetId detid) const
edm::Ref< FastTrackerRecHitCollection > FastTrackerRecHitRef
bool passSelection(std::string selectionStr) const
const std::string & getSelectionString() const
std::vector< TrackingRecHitAlgorithm * > _recHitAlgorithms
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
unsigned int size() const
def move
Definition: eostools.py:510
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::shared_ptr< TrackingRecHitProduct > TrackingRecHitProductPtr
virtual void produce(edm::Event &event, const edm::EventSetup &eventSetup)
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
tuple simHits
Definition: trackerHits.py:16
const IOVSyncValue & iovSyncValue() const
Definition: EventSetup.h:101
std::vector< FastTrackerRecHitRef > FastTrackerRecHitRefCollection
TrackingRecHitProducer(const edm::ParameterSet &config)
const DetIdContainer & detIds() const
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
TrackingRecHitProductPtr produce(TrackingRecHitProductPtr product) const
T get(const Candidate &c)
Definition: component.h:55
unsigned int detUnitId() const
Definition: PSimHit.h:93
Definition: Run.h:42