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 
65 
68 
70 
71 // Random Number
75 #include "CLHEP/Random/RandomEngine.h"
76 
77 namespace cms
78 {
79 
81  first_(true),
82  hitsProducer_(iConfig.getParameter<std::string>("hitsProducer")),
83  trackerContainers_(iConfig.getParameter<std::vector<std::string> >("ROUList")),
84  geometryType_(iConfig.getParameter<std::string>("GeometryType")),
85  iconfig_(iConfig)
86  {
87  //edm::LogInfo("Phase2TrackerDigitizer") << "Initialize Digitizer Algorithms";
88  const std::string alias1("simSiPixelDigis");
89  mixMod.produces<edm::DetSetVector<PixelDigi> >("Pixel").setBranchAlias(alias1);
90  mixMod.produces<edm::DetSetVector<PixelDigiSimLink> >("Pixel").setBranchAlias(alias1);
91 
92  const std::string alias2("simSiTrackerDigis");
93  mixMod.produces<edm::DetSetVector<Phase2TrackerDigi> >("Tracker").setBranchAlias(alias2);
94  mixMod.produces<edm::DetSetVector<PixelDigiSimLink> >("Tracker").setBranchAlias(alias2);
95 
96  }
97 
100  if (!rng.isAvailable()) {
101  throw cms::Exception("Configuration")
102  << "Phase2TrackerDigitizer requires the RandomNumberGeneratorService\n"
103  "which is not present in the configuration file. You must add the service\n"
104  "in the configuration file or remove the modules that require it.";
105  }
106  rndEngine_ = &(rng->getEngine(lumi.index()));
107 
108  iSetup.get<IdealMagneticFieldRecord>().get(pSetup_);
109  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
110 
111  if (theTkDigiGeomWatcher.check(iSetup)) {
113  //reset cache
115  detectorUnits_.clear();
116  for (auto const & det_u : pDD_->detUnits()) {
117  unsigned int detId_raw = det_u->geographicalId().rawId();
118  DetId detId = DetId(detId_raw);
119  if (DetId(detId).det() == DetId::Detector::Tracker) {
120  const Phase2TrackerGeomDetUnit* pixdet = dynamic_cast<const Phase2TrackerGeomDetUnit*>(det_u);
121  assert(pixdet);
122  detectorUnits_.insert(std::make_pair(detId_raw, pixdet));
123  }
124  }
125  }
126 
127  // one type of Digi and DigiSimLink suffices
128  // changes in future: InnerPixel -> Tracker
129  // creating algorithm objects and pushing them into the map
130  algomap_[AlgorithmType::InnerPixel] = std::unique_ptr<Phase2TrackerDigitizerAlgorithm>(new PixelDigitizerAlgorithm(iconfig_, (*rndEngine_)));
131  algomap_[AlgorithmType::PixelinPS] = std::unique_ptr<Phase2TrackerDigitizerAlgorithm>(new PSPDigitizerAlgorithm(iconfig_, (*rndEngine_)));
132  algomap_[AlgorithmType::StripinPS] = std::unique_ptr<Phase2TrackerDigitizerAlgorithm>(new PSSDigitizerAlgorithm(iconfig_, (*rndEngine_)));
133  algomap_[AlgorithmType::TwoStrip] = std::unique_ptr<Phase2TrackerDigitizerAlgorithm>(new SSDigitizerAlgorithm(iconfig_, (*rndEngine_)));
134  }
135 
137  algomap_.clear();
138  }
140  edm::LogInfo("Phase2TrackerDigitizer") << "Destroying the Digitizer";
141  }
142  void
144  size_t globalSimHitIndex,const unsigned int tofBin) {
145  if (hSimHits.isValid()) {
146  std::set<unsigned int> detIds;
147  std::vector<PSimHit> const& simHits = *hSimHits.product();
148  int indx = 0;
149  for (auto it = simHits.begin(), itEnd = simHits.end(); it != itEnd; ++it, ++globalSimHitIndex) {
150  unsigned int detId_raw = (*it).detUnitId();
151  if (detectorUnits_.find(detId_raw) == detectorUnits_.end()) continue;
152  if (detIds.insert(detId_raw).second) {
153  // The insert succeeded, so this detector element has not yet been processed.
154  AlgorithmType algotype = getAlgoType(detId_raw);
155  const Phase2TrackerGeomDetUnit* phase2det = detectorUnits_[detId_raw];
156  // access to magnetic field in global coordinates
157  GlobalVector bfield = pSetup_->inTesla(phase2det->surface().position());
158  LogDebug("PixelDigitizer") << "B-field(T) at " << phase2det->surface().position() << "(cm): "
159  << pSetup_->inTesla(phase2det->surface().position());
160  if (algomap_.find(algotype) != algomap_.end()) {
161  algomap_[algotype]->accumulateSimHits(it, itEnd, globalSimHitIndex, tofBin, phase2det, bfield);
162  } else
163  edm::LogInfo("Phase2TrackerDigitizer") << "Unsupported algorithm: ";
164  }
165  indx++;
166  }
167  }
168  }
169 
170  void
172 
173  // Must initialize all the algorithms
174  for (auto const & el : algomap_) {
175  if (first_) el.second->init(iSetup);
176  el.second->initializeEvent();
177  }
178  first_ = false;
179  // Make sure that the first crossing processed starts indexing the sim hits from zero.
180  // This variable is used so that the sim hits from all crossing frames have sequential
181  // indices used to create the digi-sim link (if configured to do so) rather than starting
182  // from zero for each crossing.
184  }
185  void
187  accumulate_local<edm::Event>(iEvent, iSetup);
188  }
189 
190  void
192  accumulate_local<PileUpEventPrincipal>(iEvent, iSetup);
193  }
194 
195  template <class T>
197  for (auto const & v : trackerContainers_) {
200  iEvent.getByLabel(tag, simHits);
201 
202  //edm::EDGetTokenT< std::vector<PSimHit> > simHitToken_(consumes< std::vector<PSimHit>(tag));
203  //iEvent.getByToken(simHitToken_, simHits);
204 
205  unsigned int tofBin = PixelDigiSimLink::LowTof;
206  if (v.find(std::string("HighTof")) != std::string::npos) tofBin = PixelDigiSimLink::HighTof;
207  accumulatePixelHits(simHits, crossingSimHitIndexOffset_[tag.encode()], tofBin);
208  // Now that the hits have been processed, I'll add the amount of hits in this crossing on to
209  // the global counter. Next time accumulateStripHits() is called it will count the sim hits
210  // as though they were on the end of this collection.
211  // Note that this is only used for creating digi-sim links (if configured to do so).
212  if (simHits.isValid()) crossingSimHitIndexOffset_[tag.encode()] += simHits->size();
213  }
214  }
216  const bool isOuterTrackerReadoutAnalog = iconfig_.getParameter<bool>("isOTreadoutAnalog");
217  //Decide if we want analog readout for Outer Tracker.
218  addPixelCollection(iEvent, iSetup, isOuterTrackerReadoutAnalog);
219  if(!isOuterTrackerReadoutAnalog)
220  addOuterTrackerCollection(iEvent, iSetup);
221  }
223  DetId detId(detId_raw);
224 
226 
227  //get mType either from the geometry or from our cache (faster)
229  auto itr = moduleTypeCache_.find(detId_raw);
230  if( itr != moduleTypeCache_.end() ) {
231  mType = itr->second;
232  } else {
233  mType = pDD_->getDetectorType(detId);
234  moduleTypeCache_.emplace(detId_raw,mType);
235  }
236 
237  switch(mType){
238 
240  algotype = AlgorithmType::InnerPixel;
241  break;
243  algotype = AlgorithmType::InnerPixel;
244  break;
246  algotype = AlgorithmType::InnerPixel;
247  break;
249  algotype = AlgorithmType::InnerPixel;
250  break;
252  algotype = AlgorithmType::PixelinPS;
253  break;
255  algotype = AlgorithmType::StripinPS;
256  break;
258  algotype = AlgorithmType::TwoStrip;
259  break;
260  default:
261  edm::LogError("Phase2TrackerDigitizer")<<"ERROR - Wrong Detector Type, No Algorithm available ";
262  }
263 
264  return algotype;
265  }
266  void Phase2TrackerDigitizer::addPixelCollection(edm::Event& iEvent, const edm::EventSetup& iSetup, const bool ot_analog) {
267  const TrackerTopology* tTopo = tTopoHand.product();
268  std::vector<edm::DetSet<PixelDigi> > digiVector;
269  std::vector<edm::DetSet<PixelDigiSimLink> > digiLinkVector;
270  for (auto const & det_u : pDD_->detUnits()) {
271  DetId detId_raw = DetId(det_u->geographicalId().rawId());
272  AlgorithmType algotype = getAlgoType(detId_raw);
273  if (algomap_.find(algotype) == algomap_.end()) continue;
274 
275  //Decide if we want analog readout for Outer Tracker.
276  if( !ot_analog && algotype != AlgorithmType::InnerPixel) continue;
277  std::map<int, DigitizerUtility::DigiSimInfo> digi_map;
278  algomap_[algotype]->digitize(dynamic_cast<const Phase2TrackerGeomDetUnit*>(det_u),
279  digi_map,tTopo);
280  edm::DetSet<PixelDigi> collector(det_u->geographicalId().rawId());
281  edm::DetSet<PixelDigiSimLink> linkcollector(det_u->geographicalId().rawId());
282  for (auto const & digi_p : digi_map) {
283  DigitizerUtility::DigiSimInfo info = digi_p.second;
284  std::pair<int,int> ip = PixelDigi::channelToPixel(digi_p.first);
285  collector.data.emplace_back(ip.first, ip.second, info.sig_tot);
286  for (auto const & sim_p : info.simInfoList) {
287  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);
288  }
289  }
290  if (!collector.data.empty()) digiVector.push_back(std::move(collector));
291  if (!linkcollector.data.empty()) digiLinkVector.push_back(std::move(linkcollector));
292  }
293 
294  // Step C: create collection with the cache vector of DetSet
295  std::unique_ptr<edm::DetSetVector<PixelDigi> >
296  output(new edm::DetSetVector<PixelDigi>(digiVector));
297  std::unique_ptr<edm::DetSetVector<PixelDigiSimLink> >
298  outputlink(new edm::DetSetVector<PixelDigiSimLink>(digiLinkVector));
299 
300  // Step D: write output to file
301  iEvent.put(std::move(output), "Pixel");
302  iEvent.put(std::move(outputlink), "Pixel");
303  }
305  const TrackerTopology* tTopo = tTopoHand.product();
306  std::vector<edm::DetSet<Phase2TrackerDigi> > digiVector;
307  std::vector<edm::DetSet<PixelDigiSimLink> > digiLinkVector;
308  for (auto const & det_u : pDD_->detUnits()) {
309  DetId detId_raw = DetId(det_u->geographicalId().rawId());
310  AlgorithmType algotype = getAlgoType(detId_raw);
311 
312  if (algomap_.find(algotype) == algomap_.end() || algotype == AlgorithmType::InnerPixel) continue;
313 
314  std::map<int, DigitizerUtility::DigiSimInfo> digi_map;
315  algomap_[algotype]->digitize(dynamic_cast<const Phase2TrackerGeomDetUnit*>(det_u),
316  digi_map, tTopo);
317  edm::DetSet<Phase2TrackerDigi> collector(det_u->geographicalId().rawId());
318  edm::DetSet<PixelDigiSimLink> linkcollector(det_u->geographicalId().rawId());
319 
320  for (auto const & digi_p : digi_map) {
321  DigitizerUtility::DigiSimInfo info = digi_p.second;
322  std::pair<int,int> ip = Phase2TrackerDigi::channelToPixel(digi_p.first);
323  collector.data.emplace_back(ip.first, ip.second, info.ot_bit);
324  for (auto const & sim_p : info.simInfoList) {
325 
326  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);
327  }
328  }
329 
330  if (!collector.data.empty()) digiVector.push_back(std::move(collector));
331  if (!linkcollector.data.empty()) digiLinkVector.push_back(std::move(linkcollector));
332  }
333 
334  // Step C: create collection with the cache vector of DetSet
335  std::unique_ptr<edm::DetSetVector<Phase2TrackerDigi> >
337  std::unique_ptr<edm::DetSetVector<PixelDigiSimLink> >
338  outputlink(new edm::DetSetVector<PixelDigiSimLink>(digiLinkVector));
339 
340  // Step D: write output to file
341  iEvent.put(std::move(output), "Tracker");
342  iEvent.put(std::move(outputlink), "Tracker");
343  }
344 }
345 
348 
#define LogDebug(id)
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
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:136
void accumulate(edm::Event const &e, edm::EventSetup const &c) override
edm::ESWatcher< TrackerDigiGeometryRecord > theTkDigiGeomWatcher
const edm::ParameterSet & iconfig_
LuminosityBlockIndex index() const
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
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:166
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)
void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &iSetup) override
const T & get() const
Definition: EventSetup.h:59
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::ProducerBase &mixMod, edm::ConsumesCollector &iC)
std::vector< std::pair< float, SimHitInfoForLinks * > > simInfoList
void addPixelCollection(edm::Event &iEvent, const edm::EventSetup &iSetup, const bool ot_analog)
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)