CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelDigitizer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelDigitizer
4 // Class: SiPixelDigitizer
5 //
13 //
14 // Original Author: Michele Pioppi-INFN perugia
15 // Modifications: Freya Blekman - Cornell University
16 // Created: Mon Sep 26 11:08:32 CEST 2005
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 #include <set>
24 
25 // user include files
26 #include "SiPixelDigitizer.h"
28 
49 
52 
55 // user include files
58 
61 
64 
67 
68 //Random Number
73 
74 namespace CLHEP {
75  class HepRandomEngine;
76 }
77 
78 
79 //
80 // constants, enums and typedefs
81 //
82 
83 //
84 // static data member definitions
85 //
86 
87 //
88 // constructors and destructor
89 //
90 //using namespace std;
91 
92 
93 namespace cms
94 {
96  first(true),
97  _pixeldigialgo(),
98  hitsProducer(iConfig.getParameter<std::string>("hitsProducer")),
99  trackerContainers(iConfig.getParameter<std::vector<std::string> >("ROUList")),
100  geometryType(iConfig.getParameter<std::string>("GeometryType")),
101  pilotBlades(iConfig.exists("enablePilotBlades")?iConfig.getParameter<bool>("enablePilotBlades"):false),
102  NumberOfEndcapDisks(iConfig.exists("NumPixelEndcap")?iConfig.getParameter<int>("NumPixelEndcap"):2)
103  {
104  edm::LogInfo ("PixelDigitizer ") <<"Enter the Pixel Digitizer";
105 
106  const std::string alias ("simSiPixelDigis");
107 
108  mixMod.produces<edm::DetSetVector<PixelDigi> >().setBranchAlias(alias);
109  mixMod.produces<edm::DetSetVector<PixelDigiSimLink> >().setBranchAlias(alias + "siPixelDigiSimLink");
110  for(auto const& trackerContainer : trackerContainers) {
111  edm::InputTag tag(hitsProducer, trackerContainer);
112  iC.consumes<std::vector<PSimHit> >(edm::InputTag(hitsProducer, trackerContainer));
113  }
115  if ( ! rng.isAvailable()) {
116  throw cms::Exception("Configuration")
117  << "SiPixelDigitizer requires the RandomNumberGeneratorService\n"
118  "which is not present in the configuration file. You must add the service\n"
119  "in the configuration file or remove the modules that require it.";
120  }
121 
122  _pixeldigialgo.reset(new SiPixelDigitizerAlgorithm(iConfig));
123  }
124 
126  edm::LogInfo ("PixelDigitizer ") <<"Destruct the Pixel Digitizer";
127  }
128 
129 
130  //
131  // member functions
132  //
133 
134  void
135  SiPixelDigitizer::accumulatePixelHits(edm::Handle<std::vector<PSimHit> > hSimHits, CLHEP::HepRandomEngine* engine) {
136  if(hSimHits.isValid()) {
137  std::set<unsigned int> detIds;
138  std::vector<PSimHit> const& simHits = *hSimHits.product();
139  for(std::vector<PSimHit>::const_iterator it = simHits.begin(), itEnd = simHits.end(); it != itEnd; ++it) {
140  unsigned int detId = (*it).detUnitId();
141  if(detIds.insert(detId).second) {
142  // The insert succeeded, so this detector element has not yet been processed.
143  unsigned int isub = DetId(detId).subdetId();
145  std::map<unsigned int, PixelGeomDetUnit const *>::iterator itDet = detectorUnits.find(detId);
146  if (itDet == detectorUnits.end()) continue;
147  auto pixdet = itDet->second;
148  //access to magnetic field in global coordinates
149  GlobalVector bfield = pSetup->inTesla(pixdet->surface().position());
150  LogDebug ("PixelDigitizer ") << "B-field(T) at " << pixdet->surface().position() << "(cm): "
151  << pSetup->inTesla(pixdet->surface().position());
152  _pixeldigialgo->accumulateSimHits(it, itEnd, pixdet, bfield, engine);
153  }
154  }
155  }
156  }
157  }
158 
159  void
161  if(first){
162  _pixeldigialgo->init(iSetup);
163  first = false;
164  }
165  _pixeldigialgo->initializeEvent();
167  iSetup.get<IdealMagneticFieldRecord>().get(pSetup);
169  iSetup.get<IdealGeometryRecord>().get(tTopoHand);
170  const TrackerTopology *tTopo=tTopoHand.product();
171 
172  // FIX THIS! We only need to clear and (re)fill this map when the geometry type IOV changes. Use ESWatcher to determine this.
173  if(true) { // Replace with ESWatcher
174  detectorUnits.clear();
175  for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); ++iu) {
176  unsigned int detId = (*iu)->geographicalId().rawId();
177  DetId idet=DetId(detId);
178  unsigned int isub=idet.subdetId();
180  auto pixdet = dynamic_cast<const PixelGeomDetUnit*>((*iu));
181  assert(pixdet != 0);
182  if (isub==PixelSubdetector::PixelEndcap) {
183  unsigned int disk = tTopo->pxfDisk(detId);
184  //if using pilot blades, then allowing it for current detector only
185  if ((disk == 3)&&((!pilotBlades)&&(NumberOfEndcapDisks == 2))) continue;
186  }
187  detectorUnits.insert(std::make_pair(detId, pixdet));
188  }
189  }
190  }
191  }
192 
193  void
195  // Step A: Get Inputs
196  for(vstring::const_iterator i = trackerContainers.begin(), iEnd = trackerContainers.end(); i != iEnd; ++i) {
199 
200  iEvent.getByLabel(tag, simHits);
201  accumulatePixelHits(simHits, randomEngine(iEvent.streamID()));
202  }
203  }
204 
205  void
207  // Step A: Get Inputs
208  for(vstring::const_iterator i = trackerContainers.begin(), iEnd = trackerContainers.end(); i != iEnd; ++i) {
211 
212  iEvent.getByLabel(tag, simHits);
213  accumulatePixelHits(simHits, randomEngine(streamID));
214  }
215  }
216 
217  // ------------ method called to produce the data ------------
218  void
220 
222  CLHEP::HepRandomEngine* engine = &rng->getEngine(iEvent.streamID());
223 
225  iSetup.get<IdealGeometryRecord>().get(tTopoHand);
226  const TrackerTopology *tTopo=tTopoHand.product();
227 
228  std::vector<edm::DetSet<PixelDigi> > theDigiVector;
229  std::vector<edm::DetSet<PixelDigiSimLink> > theDigiLinkVector;
230 
232  _pixeldigialgo->calculateInstlumiFactor(PileupInfo_);
233 
234  for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); iu ++){
235  DetId idet=DetId((*iu)->geographicalId().rawId());
236  unsigned int isub=idet.subdetId();
237 
239 
240  //
241 
242  edm::DetSet<PixelDigi> collector((*iu)->geographicalId().rawId());
243  edm::DetSet<PixelDigiSimLink> linkcollector((*iu)->geographicalId().rawId());
244 
245 
246  _pixeldigialgo->digitize(dynamic_cast<const PixelGeomDetUnit*>((*iu)),
247  collector.data,
248  linkcollector.data,
249  tTopo,
250  engine);
251  if(collector.data.size() > 0) {
252  theDigiVector.push_back(std::move(collector));
253  }
254  if(linkcollector.data.size() > 0) {
255  theDigiLinkVector.push_back(std::move(linkcollector));
256  }
257  }
258  }
259 
260  // Step C: create collection with the cache vector of DetSet
261  std::auto_ptr<edm::DetSetVector<PixelDigi> >
262  output(new edm::DetSetVector<PixelDigi>(theDigiVector) );
263  std::auto_ptr<edm::DetSetVector<PixelDigiSimLink> >
264  outputlink(new edm::DetSetVector<PixelDigiSimLink>(theDigiLinkVector) );
265 
266  // Step D: write output to file
267  iEvent.put(output);
268  iEvent.put(outputlink);
269  }
270 
271  CLHEP::HepRandomEngine* SiPixelDigitizer::randomEngine(edm::StreamID const& streamID) {
272  unsigned int index = streamID.value();
273  if(index >= randomEngines_.size()) {
274  randomEngines_.resize(index + 1, nullptr);
275  }
276  CLHEP::HepRandomEngine* ptr = randomEngines_[index];
277  if(!ptr) {
279  ptr = &rng->getEngine(streamID);
280  randomEngines_[index] = ptr;
281  }
282  return ptr;
283  }
284 
285 }// end namespace cms::
286 
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
virtual void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
int i
Definition: DBlmapReader.cc:9
CLHEP::HepRandomEngine * randomEngine(edm::StreamID const &streamID)
std::vector< CLHEP::HepRandomEngine * > randomEngines_
unsigned int pxfDisk(const DetId &id) const
std::map< unsigned int, PixelGeomDetUnit const * > detectorUnits
edm::ESHandle< MagneticField > pSetup
SiPixelDigitizer(const edm::ParameterSet &conf, edm::one::EDProducerBase &mixMod, edm::ConsumesCollector &iC)
const std::string hitsProducer
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
bool isAvailable() const
Definition: Service.h:46
edm::ESHandle< TrackerGeometry > pDD
bool first
Definition: L1TdeRCT.cc:75
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
std::unique_ptr< SiPixelDigitizerAlgorithm > _pixeldigialgo
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual void accumulate(edm::Event const &e, edm::EventSetup const &c) override
Definition: DetId.h:18
unsigned int value() const
Definition: StreamID.h:46
void accumulatePixelHits(edm::Handle< std::vector< PSimHit > >, CLHEP::HepRandomEngine *)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
tuple simHits
Definition: trackerHits.py:16
const std::string geometryType
PileupMixingContent * PileupInfo_
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &) const =0
Use this engine in event methods.
virtual PileupMixingContent * getEventPileupInfo()
const vstring trackerContainers
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
StreamID streamID() const
Definition: Event.h:75
volatile std::atomic< bool > shutdown_flag false