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 // $Id: SiPixelDigitizer.cc,v 1.9 2013/01/06 19:27:01 dlange Exp $
18 //
19 //
20 
21 
22 // system include files
23 #include <memory>
24 #include <set>
25 
26 // user include files
27 #include "SiPixelDigitizer.h"
29 
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");
103  if ( ! rng.isAvailable()) {
104  throw cms::Exception("Configuration")
105  << "SiPixelDigitizer requires the RandomNumberGeneratorService\n"
106  "which is not present in the configuration file. You must add the service\n"
107  "in the configuration file or remove the modules that require it.";
108  }
109 
110  rndEngine = &(rng->getEngine());
111  _pixeldigialgo.reset(new SiPixelDigitizerAlgorithm(iConfig,(*rndEngine)));
112 
113  }
114 
116  edm::LogInfo ("PixelDigitizer ") <<"Destruct the Pixel Digitizer";
117  }
118 
119 
120  //
121  // member functions
122  //
123 
124  void
125  SiPixelDigitizer::accumulatePixelHits(edm::Handle<std::vector<PSimHit> > hSimHits) {
126  if(hSimHits.isValid()) {
127  std::set<unsigned int> detIds;
128  std::vector<PSimHit> const& simHits = *hSimHits.product();
129  for(std::vector<PSimHit>::const_iterator it = simHits.begin(), itEnd = simHits.end(); it != itEnd; ++it) {
130  unsigned int detId = (*it).detUnitId();
131  if(detIds.insert(detId).second) {
132  // The insert succeeded, so this detector element has not yet been processed.
133  unsigned int isub = DetId(detId).subdetId();
135  PixelGeomDetUnit* pixdet = detectorUnits[detId];
136  //access to magnetic field in global coordinates
137  GlobalVector bfield = pSetup->inTesla(pixdet->surface().position());
138  LogDebug ("PixelDigitizer ") << "B-field(T) at " << pixdet->surface().position() << "(cm): "
139  << pSetup->inTesla(pixdet->surface().position());
140  _pixeldigialgo->accumulateSimHits(it, itEnd, pixdet, bfield);
141  }
142  }
143  }
144  }
145  }
146 
147  void
149  if(first){
150  _pixeldigialgo->init(iSetup);
151  first = false;
152  }
153  _pixeldigialgo->initializeEvent();
155  iSetup.get<IdealMagneticFieldRecord>().get(pSetup);
156 
157  // FIX THIS! We only need to clear and (re)fill this map when the geometry type IOV changes. Use ESWatcher to determine this.
158  if(true) { // Replace with ESWatcher
159  detectorUnits.clear();
160  for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); ++iu) {
161  unsigned int detId = (*iu)->geographicalId().rawId();
162  DetId idet=DetId(detId);
163  unsigned int isub=idet.subdetId();
165  PixelGeomDetUnit* pixdet = dynamic_cast<PixelGeomDetUnit*>((*iu));
166  assert(pixdet != 0);
167  detectorUnits.insert(std::make_pair(detId, pixdet));
168  }
169  }
170  }
171  }
172 
173  void
175  // Step A: Get Inputs
176  for(vstring::const_iterator i = trackerContainers.begin(), iEnd = trackerContainers.end(); i != iEnd; ++i) {
179 
180  iEvent.getByLabel(tag, simHits);
181  accumulatePixelHits(simHits);
182  }
183  }
184 
185  void
187  // Step A: Get Inputs
188  for(vstring::const_iterator i = trackerContainers.begin(), iEnd = trackerContainers.end(); i != iEnd; ++i) {
191 
192  iEvent.getByLabel(tag, simHits);
193  accumulatePixelHits(simHits);
194  }
195  }
196 
197  // ------------ method called to produce the data ------------
198  void
200 
202  iSetup.get<IdealGeometryRecord>().get(tTopoHand);
203  const TrackerTopology *tTopo=tTopoHand.product();
204 
205  std::vector<edm::DetSet<PixelDigi> > theDigiVector;
206  std::vector<edm::DetSet<PixelDigiSimLink> > theDigiLinkVector;
207 
208  for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); iu ++){
209  DetId idet=DetId((*iu)->geographicalId().rawId());
210  unsigned int isub=idet.subdetId();
211 
213 
214  //
215 
216  edm::DetSet<PixelDigi> collector((*iu)->geographicalId().rawId());
217  edm::DetSet<PixelDigiSimLink> linkcollector((*iu)->geographicalId().rawId());
218 
219 
220  _pixeldigialgo->digitize(dynamic_cast<PixelGeomDetUnit*>((*iu)),
221  collector.data,
222  linkcollector.data,
223  tTopo);
224  if(collector.data.size() > 0) {
225  theDigiVector.push_back(std::move(collector));
226  }
227  if(linkcollector.data.size() > 0) {
228  theDigiLinkVector.push_back(std::move(linkcollector));
229  }
230  }
231  }
232 
233  // Step C: create collection with the cache vector of DetSet
234  std::auto_ptr<edm::DetSetVector<PixelDigi> >
235  output(new edm::DetSetVector<PixelDigi>(theDigiVector) );
236  std::auto_ptr<edm::DetSetVector<PixelDigiSimLink> >
237  outputlink(new edm::DetSetVector<PixelDigiSimLink>(theDigiLinkVector) );
238 
239  // Step D: write output to file
240  iEvent.put(output);
241  iEvent.put(outputlink);
242  }
243 
244 
245 
246 
247 }// end namespace cms::
248 
#define LogDebug(id)
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
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:94
virtual void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
bool isAvailable() const
Definition: Service.h:47
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:94
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
std::unique_ptr< SiPixelDigitizerAlgorithm > _pixeldigialgo
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual void accumulate(edm::Event const &e, edm::EventSetup const &c) override
Definition: DetId.h:20
SiPixelDigitizer(const edm::ParameterSet &conf, edm::EDProducer &mixMod)
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