CMS 3D CMS Logo

Phase2TrackerDigitizer.cc
Go to the documentation of this file.
1 //
2 //
3 // Package: Phase2TrackerDigitizer
4 // Class: Phase2TrackerDigitizer
5 //
6 // *\class SiPhase2TrackerDigitizer Phase2TrackerDigitizer.cc SimTracker/SiPhase2Digitizer/src/Phase2TrackerDigitizer.cc
7 //
8 // Author: Suchandra Dutta, Suvankar Roy Chowdhury, Subir Sarkar
9 // Date: January 29, 2016
10 // Description: <one line class summary>
11 //
12 // Implementation:
13 // <Notes on implementation>
14 //
15 
16 #include <memory>
17 #include <set>
18 #include <iostream>
26 
34 
45 
49 
53 
56 
60 
64 
67 
69 
70 // Random Number
74 #include "CLHEP/Random/RandomEngine.h"
75 
76 namespace cms
77 {
78 
80  first_(true),
81  hitsProducer_(iConfig.getParameter<std::string>("hitsProducer")),
82  trackerContainers_(iConfig.getParameter<std::vector<std::string> >("ROUList")),
83  geometryType_(iConfig.getParameter<std::string>("GeometryType")),
84  iconfig_(iConfig)
85  {
86  //edm::LogInfo("Phase2TrackerDigitizer") << "Initialize Digitizer Algorithms";
87  const std::string alias1("simSiPixelDigis");
88  mixMod.produces<edm::DetSetVector<PixelDigi> >("Pixel").setBranchAlias(alias1);
89  mixMod.produces<edm::DetSetVector<PixelDigiSimLink> >("Pixel").setBranchAlias(alias1);
90 
91  const std::string alias2("simSiTrackerDigis");
92  mixMod.produces<edm::DetSetVector<Phase2TrackerDigi> >("Tracker").setBranchAlias(alias2);
93  mixMod.produces<edm::DetSetVector<PixelDigiSimLink> >("Tracker").setBranchAlias(alias2);
94 
95  }
96 
99  if (!rng.isAvailable()) {
100  throw cms::Exception("Configuration")
101  << "Phase2TrackerDigitizer requires the RandomNumberGeneratorService\n"
102  "which is not present in the configuration file. You must add the service\n"
103  "in the configuration file or remove the modules that require it.";
104  }
105  rndEngine_ = &(rng->getEngine(lumi.index()));
106 
107  iSetup.get<IdealMagneticFieldRecord>().get(pSetup_);
108  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
109 
110  if (theTkDigiGeomWatcher.check(iSetup)) {
112  //reset cache
114  detectorUnits_.clear();
115  for (auto const & det_u : pDD_->detUnits()) {
116  unsigned int detId_raw = det_u->geographicalId().rawId();
117  DetId detId = DetId(detId_raw);
118  if (DetId(detId).det() == DetId::Detector::Tracker) {
119  const Phase2TrackerGeomDetUnit* pixdet = dynamic_cast<const Phase2TrackerGeomDetUnit*>(det_u);
120  assert(pixdet);
121  detectorUnits_.insert(std::make_pair(detId_raw, pixdet));
122  }
123  }
124  }
125 
126  // one type of Digi and DigiSimLink suffices
127  // changes in future: InnerPixel -> Tracker
128  // creating algorithm objects and pushing them into the map
129  algomap_[AlgorithmType::InnerPixel] = std::unique_ptr<Phase2TrackerDigitizerAlgorithm>(new PixelDigitizerAlgorithm(iconfig_, (*rndEngine_)));
130  algomap_[AlgorithmType::PixelinPS] = std::unique_ptr<Phase2TrackerDigitizerAlgorithm>(new PSPDigitizerAlgorithm(iconfig_, (*rndEngine_)));
131  algomap_[AlgorithmType::StripinPS] = std::unique_ptr<Phase2TrackerDigitizerAlgorithm>(new PSSDigitizerAlgorithm(iconfig_, (*rndEngine_)));
132  algomap_[AlgorithmType::TwoStrip] = std::unique_ptr<Phase2TrackerDigitizerAlgorithm>(new SSDigitizerAlgorithm(iconfig_, (*rndEngine_)));
133  }
134 
136  algomap_.clear();
137  }
139  edm::LogInfo("Phase2TrackerDigitizer") << "Destroying the Digitizer";
140  }
141  void
143  size_t globalSimHitIndex,const unsigned int tofBin) {
144  if (hSimHits.isValid()) {
145  std::set<unsigned int> detIds;
146  std::vector<PSimHit> const& simHits = *hSimHits.product();
147  int indx = 0;
148  for (auto it = simHits.begin(), itEnd = simHits.end(); it != itEnd; ++it, ++globalSimHitIndex) {
149  unsigned int detId_raw = (*it).detUnitId();
150  if (detectorUnits_.find(detId_raw) == detectorUnits_.end()) continue;
151  if (detIds.insert(detId_raw).second) {
152  // The insert succeeded, so this detector element has not yet been processed.
153  AlgorithmType algotype = getAlgoType(detId_raw);
154  const Phase2TrackerGeomDetUnit* phase2det = detectorUnits_[detId_raw];
155  // access to magnetic field in global coordinates
156  GlobalVector bfield = pSetup_->inTesla(phase2det->surface().position());
157  LogDebug("PixelDigitizer") << "B-field(T) at " << phase2det->surface().position() << "(cm): "
158  << pSetup_->inTesla(phase2det->surface().position());
159  if (algomap_.find(algotype) != algomap_.end()) {
160  algomap_[algotype]->accumulateSimHits(it, itEnd, globalSimHitIndex, tofBin, phase2det, bfield);
161  } else
162  edm::LogInfo("Phase2TrackerDigitizer") << "Unsupported algorithm: ";
163  }
164  indx++;
165  }
166  }
167  }
168 
169  void
171 
172  // Must initialize all the algorithms
173  for (auto const & el : algomap_) {
174  if (first_) el.second->init(iSetup);
175  el.second->initializeEvent();
176  }
177  first_ = false;
178  // Make sure that the first crossing processed starts indexing the sim hits from zero.
179  // This variable is used so that the sim hits from all crossing frames have sequential
180  // indices used to create the digi-sim link (if configured to do so) rather than starting
181  // from zero for each crossing.
183  }
184  void
186  accumulate_local<edm::Event>(iEvent, iSetup);
187  }
188 
189  void
191  accumulate_local<PileUpEventPrincipal>(iEvent, iSetup);
192  }
193 
194  template <class T>
196  for (auto const & v : trackerContainers_) {
199  iEvent.getByLabel(tag, simHits);
200 
201  //edm::EDGetTokenT< std::vector<PSimHit> > simHitToken_(consumes< std::vector<PSimHit>(tag));
202  //iEvent.getByToken(simHitToken_, simHits);
203 
204  unsigned int tofBin = PixelDigiSimLink::LowTof;
205  if (v.find(std::string("HighTof")) != std::string::npos) tofBin = PixelDigiSimLink::HighTof;
206  accumulatePixelHits(simHits, crossingSimHitIndexOffset_[tag.encode()], tofBin);
207  // Now that the hits have been processed, I'll add the amount of hits in this crossing on to
208  // the global counter. Next time accumulateStripHits() is called it will count the sim hits
209  // as though they were on the end of this collection.
210  // Note that this is only used for creating digi-sim links (if configured to do so).
211  if (simHits.isValid()) crossingSimHitIndexOffset_[tag.encode()] += simHits->size();
212  }
213  }
215  const bool isOuterTrackerReadoutAnalog = iconfig_.getParameter<bool>("isOTreadoutAnalog");
216  //Decide if we want analog readout for Outer Tracker.
217  addPixelCollection(iEvent, iSetup, isOuterTrackerReadoutAnalog);
218  if(!isOuterTrackerReadoutAnalog)
219  addOuterTrackerCollection(iEvent, iSetup);
220  }
222  DetId detId(detId_raw);
223 
225 
226  //get mType either from the geometry or from our cache (faster)
228  auto itr = moduleTypeCache_.find(detId_raw);
229  if( itr != moduleTypeCache_.end() ) {
230  mType = itr->second;
231  } else {
232  mType = pDD_->getDetectorType(detId);
233  moduleTypeCache_.emplace(detId_raw,mType);
234  }
235 
236  switch(mType){
237 
239  algotype = AlgorithmType::InnerPixel;
240  break;
242  algotype = AlgorithmType::InnerPixel;
243  break;
245  algotype = AlgorithmType::InnerPixel;
246  break;
248  algotype = AlgorithmType::InnerPixel;
249  break;
251  algotype = AlgorithmType::PixelinPS;
252  break;
254  algotype = AlgorithmType::StripinPS;
255  break;
257  algotype = AlgorithmType::TwoStrip;
258  break;
259  default:
260  edm::LogError("Phase2TrackerDigitizer")<<"ERROR - Wrong Detector Type, No Algorithm available ";
261  }
262 
263  return algotype;
264  }
265  void Phase2TrackerDigitizer::addPixelCollection(edm::Event& iEvent, const edm::EventSetup& iSetup, const bool ot_analog) {
266  const TrackerTopology* tTopo = tTopoHand.product();
267  std::vector<edm::DetSet<PixelDigi> > digiVector;
268  std::vector<edm::DetSet<PixelDigiSimLink> > digiLinkVector;
269  for (auto const & det_u : pDD_->detUnits()) {
270  DetId detId_raw = DetId(det_u->geographicalId().rawId());
271  AlgorithmType algotype = getAlgoType(detId_raw);
272  if (algomap_.find(algotype) == algomap_.end()) continue;
273 
274  //Decide if we want analog readout for Outer Tracker.
275  if( !ot_analog && algotype != AlgorithmType::InnerPixel) continue;
276  std::map<int, DigitizerUtility::DigiSimInfo> digi_map;
277  algomap_[algotype]->digitize(dynamic_cast<const Phase2TrackerGeomDetUnit*>(det_u),
278  digi_map,tTopo);
279  edm::DetSet<PixelDigi> collector(det_u->geographicalId().rawId());
280  edm::DetSet<PixelDigiSimLink> linkcollector(det_u->geographicalId().rawId());
281  for (auto const & digi_p : digi_map) {
282  DigitizerUtility::DigiSimInfo info = digi_p.second;
283  std::pair<int,int> ip = PixelDigi::channelToPixel(digi_p.first);
284  collector.data.emplace_back(ip.first, ip.second, info.sig_tot);
285  for (auto const & sim_p : info.simInfoList) {
286  linkcollector.data.emplace_back(digi_p.first, sim_p.second->trackId(), sim_p.second->hitIndex(), sim_p.second->tofBin(), sim_p.second->eventId(), sim_p.first);
287  }
288  }
289  if (collector.data.size() > 0) digiVector.push_back(std::move(collector));
290  if (linkcollector.data.size() > 0) digiLinkVector.push_back(std::move(linkcollector));
291  }
292 
293  // Step C: create collection with the cache vector of DetSet
294  std::unique_ptr<edm::DetSetVector<PixelDigi> >
295  output(new edm::DetSetVector<PixelDigi>(digiVector));
296  std::unique_ptr<edm::DetSetVector<PixelDigiSimLink> >
297  outputlink(new edm::DetSetVector<PixelDigiSimLink>(digiLinkVector));
298 
299  // Step D: write output to file
300  iEvent.put(std::move(output), "Pixel");
301  iEvent.put(std::move(outputlink), "Pixel");
302  }
304  const TrackerTopology* tTopo = tTopoHand.product();
305  std::vector<edm::DetSet<Phase2TrackerDigi> > digiVector;
306  std::vector<edm::DetSet<PixelDigiSimLink> > digiLinkVector;
307  for (auto const & det_u : pDD_->detUnits()) {
308  DetId detId_raw = DetId(det_u->geographicalId().rawId());
309  AlgorithmType algotype = getAlgoType(detId_raw);
310 
311  if (algomap_.find(algotype) == algomap_.end() || algotype == AlgorithmType::InnerPixel) continue;
312 
313  std::map<int, DigitizerUtility::DigiSimInfo> digi_map;
314  algomap_[algotype]->digitize(dynamic_cast<const Phase2TrackerGeomDetUnit*>(det_u),
315  digi_map, tTopo);
316  edm::DetSet<Phase2TrackerDigi> collector(det_u->geographicalId().rawId());
317  edm::DetSet<PixelDigiSimLink> linkcollector(det_u->geographicalId().rawId());
318 
319  for (auto const & digi_p : digi_map) {
320  DigitizerUtility::DigiSimInfo info = digi_p.second;
321  std::pair<int,int> ip = Phase2TrackerDigi::channelToPixel(digi_p.first);
322  collector.data.emplace_back(ip.first, ip.second, info.ot_bit);
323  for (auto const & sim_p : info.simInfoList) {
324 
325  linkcollector.data.emplace_back(digi_p.first, sim_p.second->trackId(), sim_p.second->hitIndex(), sim_p.second->tofBin(), sim_p.second->eventId(), sim_p.first);
326  }
327  }
328 
329  if (collector.data.size() > 0) digiVector.push_back(std::move(collector));
330  if (linkcollector.data.size() > 0) digiLinkVector.push_back(std::move(linkcollector));
331  }
332 
333  // Step C: create collection with the cache vector of DetSet
334  std::unique_ptr<edm::DetSetVector<Phase2TrackerDigi> >
336  std::unique_ptr<edm::DetSetVector<PixelDigiSimLink> >
337  outputlink(new edm::DetSetVector<PixelDigiSimLink>(digiLinkVector));
338 
339  // Step D: write output to file
340  iEvent.put(std::move(output), "Tracker");
341  iEvent.put(std::move(outputlink), "Tracker");
342  }
343 }
344 
347 
#define LogDebug(id)
T getParameter(std::string const &) const
static const TGPicture * info(bool iBackgroundIsBlack)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
virtual void accumulate(edm::Event const &e, edm::EventSetup const &c) override
edm::ESWatcher< TrackerDigiGeometryRecord > theTkDigiGeomWatcher
const edm::ParameterSet & iconfig_
LuminosityBlockIndex index() const
virtual void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
virtual void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
void accumulatePixelHits(edm::Handle< std::vector< PSimHit > >, size_t globalSimHitIndex, const unsigned int tofBin)
void accumulate_local(T const &iEvent, edm::EventSetup const &iSetup)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
std::unordered_map< unsigned, TrackerGeometry::ModuleType > ModuleTypeCache
std::string encode() const
Definition: InputTag.cc:165
std::map< unsigned int, const Phase2TrackerGeomDetUnit * > detectorUnits_
int iEvent
Definition: GenABIO.cc:230
CLHEP::HepRandomEngine * rndEngine_
edm::ESHandle< TrackerTopology > tTopoHand
edm::ESHandle< TrackerGeometry > pDD_
bool isAvailable() const
Definition: Service.h:46
std::map< std::string, size_t > crossingSimHitIndexOffset_
Offset to add to the index of each sim hit to account for which crossing it&#39;s in. ...
ModuleType getDetectorType(DetId) const
bool isValid() const
Definition: HandleBase.h:74
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
Definition: DetId.h:18
void addOuterTrackerCollection(edm::Event &iEvent, const edm::EventSetup &iSetup)
AlgorithmType getAlgoType(unsigned int idet)
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &iSetup) override
const T & get() const
Definition: EventSetup.h:56
static std::pair< int, int > channelToPixel(int ch)
Definition: PixelDigi.h:62
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::ESHandle< MagneticField > pSetup_
std::map< AlgorithmType, std::unique_ptr< Phase2TrackerDigitizerAlgorithm > > algomap_
#define DEFINE_DIGI_ACCUMULATOR(type)
Phase2TrackerDigitizer(const edm::ParameterSet &iConfig, edm::stream::EDProducerBase &mixMod, edm::ConsumesCollector &iC)
std::vector< std::pair< float, SimHitInfoForLinks * > > simInfoList
void addPixelCollection(edm::Event &iEvent, const edm::EventSetup &iSetup, const bool ot_analog)
virtual void endLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &iSetup) override
long double T
const PositionType & position() const
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510
static std::pair< unsigned int, unsigned int > channelToPixel(unsigned int ch)
const DetUnitContainer & detUnits() const
Returm a vector of all GeomDetUnit.