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 
54 // user include files
57 
60 
63 
66 
67 //Random Number
71 #include "CLHEP/Random/RandomEngine.h"
72 
73 //
74 // constants, enums and typedefs
75 //
76 
77 //
78 // static data member definitions
79 //
80 
81 //
82 // constructors and destructor
83 //
84 //using namespace std;
85 
86 
87 namespace cms
88 {
90  first(true),
91  _pixeldigialgo(),
92  hitsProducer(iConfig.getParameter<std::string>("hitsProducer")),
93  trackerContainers(iConfig.getParameter<std::vector<std::string> >("ROUList")),
94  geometryType(iConfig.getParameter<std::string>("GeometryType"))
95  {
96  edm::LogInfo ("PixelDigitizer ") <<"Enter the Pixel Digitizer";
97 
98  const std::string alias ("simSiPixelDigis");
99 
100  mixMod.produces<edm::DetSetVector<PixelDigi> >().setBranchAlias(alias);
101  mixMod.produces<edm::DetSetVector<PixelDigiSimLink> >().setBranchAlias(alias + "siPixelDigiSimLink");
102  for(auto const& trackerContainer : trackerContainers) {
103  edm::InputTag tag(hitsProducer, trackerContainer);
104  iC.consumes<std::vector<PSimHit> >(edm::InputTag(hitsProducer, trackerContainer));
105  }
107  if ( ! rng.isAvailable()) {
108  throw cms::Exception("Configuration")
109  << "SiPixelDigitizer requires the RandomNumberGeneratorService\n"
110  "which is not present in the configuration file. You must add the service\n"
111  "in the configuration file or remove the modules that require it.";
112  }
113 
114  rndEngine = &(rng->getEngine());
115  _pixeldigialgo.reset(new SiPixelDigitizerAlgorithm(iConfig,(*rndEngine)));
116 
117  }
118 
120  edm::LogInfo ("PixelDigitizer ") <<"Destruct the Pixel Digitizer";
121  }
122 
123 
124  //
125  // member functions
126  //
127 
128  void
129  SiPixelDigitizer::accumulatePixelHits(edm::Handle<std::vector<PSimHit> > hSimHits) {
130  if(hSimHits.isValid()) {
131  std::set<unsigned int> detIds;
132  std::vector<PSimHit> const& simHits = *hSimHits.product();
133  for(std::vector<PSimHit>::const_iterator it = simHits.begin(), itEnd = simHits.end(); it != itEnd; ++it) {
134  unsigned int detId = (*it).detUnitId();
135  if(detIds.insert(detId).second) {
136  // The insert succeeded, so this detector element has not yet been processed.
137  unsigned int isub = DetId(detId).subdetId();
139  PixelGeomDetUnit* pixdet = detectorUnits[detId];
140  //access to magnetic field in global coordinates
141  GlobalVector bfield = pSetup->inTesla(pixdet->surface().position());
142  LogDebug ("PixelDigitizer ") << "B-field(T) at " << pixdet->surface().position() << "(cm): "
143  << pSetup->inTesla(pixdet->surface().position());
144  _pixeldigialgo->accumulateSimHits(it, itEnd, pixdet, bfield);
145  }
146  }
147  }
148  }
149  }
150 
151  void
153  if(first){
154  _pixeldigialgo->init(iSetup);
155  first = false;
156  }
157  _pixeldigialgo->initializeEvent();
159  iSetup.get<IdealMagneticFieldRecord>().get(pSetup);
160 
161  // FIX THIS! We only need to clear and (re)fill this map when the geometry type IOV changes. Use ESWatcher to determine this.
162  if(true) { // Replace with ESWatcher
163  detectorUnits.clear();
164  for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); ++iu) {
165  unsigned int detId = (*iu)->geographicalId().rawId();
166  DetId idet=DetId(detId);
167  unsigned int isub=idet.subdetId();
169  PixelGeomDetUnit* pixdet = dynamic_cast<PixelGeomDetUnit*>((*iu));
170  assert(pixdet != 0);
171  detectorUnits.insert(std::make_pair(detId, pixdet));
172  }
173  }
174  }
175  }
176 
177  void
179  // Step A: Get Inputs
180  for(vstring::const_iterator i = trackerContainers.begin(), iEnd = trackerContainers.end(); i != iEnd; ++i) {
183 
184  iEvent.getByLabel(tag, simHits);
185  accumulatePixelHits(simHits);
186  }
187  }
188 
189  void
191  // Step A: Get Inputs
192  for(vstring::const_iterator i = trackerContainers.begin(), iEnd = trackerContainers.end(); i != iEnd; ++i) {
195 
196  iEvent.getByLabel(tag, simHits);
197  accumulatePixelHits(simHits);
198  }
199  }
200 
201  // ------------ method called to produce the data ------------
202  void
204 
206  iSetup.get<IdealGeometryRecord>().get(tTopoHand);
207  const TrackerTopology *tTopo=tTopoHand.product();
208 
209  std::vector<edm::DetSet<PixelDigi> > theDigiVector;
210  std::vector<edm::DetSet<PixelDigiSimLink> > theDigiLinkVector;
211 
212  for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); iu ++){
213  DetId idet=DetId((*iu)->geographicalId().rawId());
214  unsigned int isub=idet.subdetId();
215 
217 
218  //
219 
220  edm::DetSet<PixelDigi> collector((*iu)->geographicalId().rawId());
221  edm::DetSet<PixelDigiSimLink> linkcollector((*iu)->geographicalId().rawId());
222 
223 
224  _pixeldigialgo->digitize(dynamic_cast<PixelGeomDetUnit*>((*iu)),
225  collector.data,
226  linkcollector.data,
227  tTopo);
228  if(collector.data.size() > 0) {
229  theDigiVector.push_back(std::move(collector));
230  }
231  if(linkcollector.data.size() > 0) {
232  theDigiLinkVector.push_back(std::move(linkcollector));
233  }
234  }
235  }
236 
237  // Step C: create collection with the cache vector of DetSet
238  std::auto_ptr<edm::DetSetVector<PixelDigi> >
239  output(new edm::DetSetVector<PixelDigi>(theDigiVector) );
240  std::auto_ptr<edm::DetSetVector<PixelDigiSimLink> >
241  outputlink(new edm::DetSetVector<PixelDigiSimLink>(theDigiLinkVector) );
242 
243  // Step D: write output to file
244  iEvent.put(output);
245  iEvent.put(outputlink);
246  }
247 
248 
249 
250 
251 }// end namespace cms::
252 
#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 * rndEngine
edm::ESHandle< MagneticField > pSetup
void accumulatePixelHits(edm::Handle< std::vector< PSimHit > >)
std::map< unsigned int, PixelGeomDetUnit * > detectorUnits
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
SiPixelDigitizer(const edm::ParameterSet &conf, edm::one::EDProducerBase &mixMod, edm::ConsumesCollector &iC)
const std::string hitsProducer
int iEvent
Definition: GenABIO.cc:243
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
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
edm::ESHandle< TrackerGeometry > pDD
bool first
Definition: L1TdeRCT.cc:79
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
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
const vstring trackerContainers
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
const PositionType & position() const