CMS 3D CMS Logo

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 // system include files
21 #include <memory>
22 #include <set>
23 
24 // user include files
25 #include "SiPixelDigitizer.h"
27 
47 
50 
52 // user include files
55 
58 
61 
65 //Random Number
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
82 //using namespace std;
83 
84 namespace cms {
86  edm::ProducesCollector producesCollector,
88  : firstInitializeEvent_(true),
89  firstFinalizeEvent_(true),
90  _pixeldigialgo(),
91  hitsProducer(iConfig.getParameter<std::string>("hitsProducer")),
92  trackerContainers(iConfig.getParameter<std::vector<std::string> >("RoutList")),
93  geometryType(iConfig.getParameter<std::string>("PixGeometryType")),
94  pilotBlades(iConfig.exists("enablePilotBlades") ? iConfig.getParameter<bool>("enablePilotBlades") : false),
95  NumberOfEndcapDisks(iConfig.exists("NumPixelEndcap") ? iConfig.getParameter<int>("NumPixelEndcap") : 2) {
96  edm::LogInfo("PixelDigitizer ") << "Enter the Pixel Digitizer";
97 
98  const std::string alias("simSiPixelDigis");
99 
100  producesCollector.produces<edm::DetSetVector<PixelDigi> >().setBranchAlias(alias);
101  producesCollector.produces<edm::DetSetVector<PixelDigiSimLink> >().setBranchAlias(alias + "siPixelDigiSimLink");
102 
103  for (auto const& trackerContainer : trackerContainers) {
104  edm::InputTag tag(hitsProducer, trackerContainer);
105  iC.consumes<std::vector<PSimHit> >(edm::InputTag(hitsProducer, trackerContainer));
106  }
108  if (!rng.isAvailable()) {
109  throw cms::Exception("Configuration")
110  << "SiPixelDigitizer requires the RandomNumberGeneratorService\n"
111  "which is not present in the configuration file. You must add the service\n"
112  "in the configuration file or remove the modules that require it.";
113  }
114 
115  _pixeldigialgo = std::make_unique<SiPixelDigitizerAlgorithm>(iConfig);
116  if (NumberOfEndcapDisks != 2)
117  producesCollector.produces<PixelFEDChannelCollection>();
118  }
119 
120  SiPixelDigitizer::~SiPixelDigitizer() { edm::LogInfo("PixelDigitizer ") << "Destruct the Pixel Digitizer"; }
121 
122  //
123  // member functions
124  //
125 
126  void SiPixelDigitizer::accumulatePixelHits(edm::Handle<std::vector<PSimHit> > hSimHits,
127  size_t globalSimHitIndex,
128  const unsigned int tofBin,
129  edm::EventSetup const& iSetup) {
130  if (hSimHits.isValid()) {
131  std::set<unsigned int> detIds;
132  std::vector<PSimHit> const& simHits = *hSimHits.product();
134  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
135  const TrackerTopology* tTopo = tTopoHand.product();
136  for (std::vector<PSimHit>::const_iterator it = simHits.begin(), itEnd = simHits.end(); it != itEnd;
137  ++it, ++globalSimHitIndex) {
138  unsigned int detId = (*it).detUnitId();
139  if (detIds.insert(detId).second) {
140  // The insert succeeded, so this detector element has not yet been processed.
141  assert(detectorUnits[detId]);
142  if (detectorUnits[detId] &&
143  detectorUnits[detId]
144  ->type()
145  .isTrackerPixel()) { // this test could be avoided and changed into a check of pixdet!=0
146  std::map<unsigned int, PixelGeomDetUnit const*>::iterator itDet = detectorUnits.find(detId);
147  if (itDet == detectorUnits.end())
148  continue;
149  auto pixdet = itDet->second;
150  assert(pixdet != nullptr);
151  //access to magnetic field in global coordinates
152  GlobalVector bfield = pSetup->inTesla(pixdet->surface().position());
153  LogDebug("PixelDigitizer ") << "B-field(T) at " << pixdet->surface().position()
154  << "(cm): " << pSetup->inTesla(pixdet->surface().position());
155  _pixeldigialgo->accumulateSimHits(
156  it, itEnd, globalSimHitIndex, tofBin, pixdet, bfield, tTopo, randomEngine_);
157  }
158  }
159  }
160  }
161  }
162 
164  if (firstInitializeEvent_) {
165  _pixeldigialgo->init(iSetup);
166  firstInitializeEvent_ = false;
167  }
168 
169  // Make sure that the first crossing processed starts indexing the sim hits from zero.
170  // This variable is used so that the sim hits from all crossing frames have sequential
171  // indices used to create the digi-sim link (if configured to do so) rather than starting
172  // from zero for each crossing.
174 
175  // Cache random number engine
177  randomEngine_ = &rng->getEngine(e.streamID());
178 
179  _pixeldigialgo->initializeEvent();
183  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
184  const TrackerTopology* tTopo = tTopoHand.product();
185 
186  // FIX THIS! We only need to clear and (re)fill this map when the geometry type IOV changes. Use ESWatcher to determine this.
187  if (true) { // Replace with ESWatcher
188  detectorUnits.clear();
189  for (const auto& iu : pDD->detUnits()) {
190  unsigned int detId = iu->geographicalId().rawId();
191  if (iu->type().isTrackerPixel()) {
192  auto pixdet = dynamic_cast<const PixelGeomDetUnit*>(iu);
193  assert(pixdet != nullptr);
194  if (iu->subDetector() ==
195  GeomDetEnumerators::SubDetector::PixelEndcap) { // true ONLY for the phase 0 pixel deetctor
196  unsigned int disk = tTopo->layer(detId); // using the generic layer method
197  //if using pilot blades, then allowing it for current detector only
198  if ((disk == 3) && ((!pilotBlades) && (NumberOfEndcapDisks == 2)))
199  continue;
200  }
201  detectorUnits.insert(std::make_pair(detId, pixdet));
202  }
203  }
204  }
205  }
206 
208  // Step A: Get Inputs
209  for (vstring::const_iterator i = trackerContainers.begin(), iEnd = trackerContainers.end(); i != iEnd; ++i) {
212 
213  iEvent.getByLabel(tag, simHits);
214  unsigned int tofBin = PixelDigiSimLink::LowTof;
215  if ((*i).find(std::string("HighTof")) != std::string::npos)
216  tofBin = PixelDigiSimLink::HighTof;
217  accumulatePixelHits(simHits, crossingSimHitIndexOffset_[tag.encode()], tofBin, iSetup);
218  // Now that the hits have been processed, I'll add the amount of hits in this crossing on to
219  // the global counter. Next time accumulateStripHits() is called it will count the sim hits
220  // as though they were on the end of this collection.
221  // Note that this is only used for creating digi-sim links (if configured to do so).
222  // std::cout << "index offset, current hit count = " << crossingSimHitIndexOffset_[tag.encode()] << ", " << simHits->size() << std::endl;
223  if (simHits.isValid())
224  crossingSimHitIndexOffset_[tag.encode()] += simHits->size();
225  }
226  }
227 
229  edm::EventSetup const& iSetup,
230  edm::StreamID const& streamID) {
231  // Step A: Get Inputs
232  for (vstring::const_iterator i = trackerContainers.begin(), iEnd = trackerContainers.end(); i != iEnd; ++i) {
235 
236  iEvent.getByLabel(tag, simHits);
237  unsigned int tofBin = PixelDigiSimLink::LowTof;
238  if ((*i).find(std::string("HighTof")) != std::string::npos)
239  tofBin = PixelDigiSimLink::HighTof;
240  accumulatePixelHits(simHits, crossingSimHitIndexOffset_[tag.encode()], tofBin, iSetup);
241  // Now that the hits have been processed, I'll add the amount of hits in this crossing on to
242  // the global counter. Next time accumulateStripHits() is called it will count the sim hits
243  // as though they were on the end of this collection.
244  // Note that this is only used for creating digi-sim links (if configured to do so).
245  // std::cout << "index offset, current hit count = " << crossingSimHitIndexOffset_[tag.encode()] << ", " << simHits->size() << std::endl;
246  if (simHits.isValid())
247  crossingSimHitIndexOffset_[tag.encode()] += simHits->size();
248  }
249  }
250 
251  // ------------ method called to produce the data ------------
254  iSetup.get<TrackerTopologyRcd>().get(tTopoHand);
255  const TrackerTopology* tTopo = tTopoHand.product();
256 
257  std::vector<edm::DetSet<PixelDigi> > theDigiVector;
258  std::vector<edm::DetSet<PixelDigiSimLink> > theDigiLinkVector;
259 
260  if (firstFinalizeEvent_) {
261  const unsigned int bunchspace = PileupInfo_->getMix_bunchSpacing();
262  _pixeldigialgo->init_DynIneffDB(iSetup, bunchspace);
263  firstFinalizeEvent_ = false;
264  }
265  _pixeldigialgo->calculateInstlumiFactor(PileupInfo_.get());
266 
267  if (_pixeldigialgo->killBadFEDChannels()) {
268  std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_ =
269  _pixeldigialgo->chooseScenario(PileupInfo_.get(), randomEngine_);
270  if (PixelFEDChannelCollection_ == nullptr) {
271  throw cms::Exception("NullPointerError") << "PixelFEDChannelCollection not set in chooseScenario function.\n";
272  }
273  iEvent.put(std::move(PixelFEDChannelCollection_));
274  }
275 
276  for (const auto& iu : pDD->detUnits()) {
277  if (iu->type().isTrackerPixel()) {
278  //
279 
280  edm::DetSet<PixelDigi> collector(iu->geographicalId().rawId());
281  edm::DetSet<PixelDigiSimLink> linkcollector(iu->geographicalId().rawId());
282 
283  _pixeldigialgo->digitize(
284  dynamic_cast<const PixelGeomDetUnit*>(iu), collector.data, linkcollector.data, tTopo, randomEngine_);
285  if (!collector.data.empty()) {
286  theDigiVector.push_back(std::move(collector));
287  }
288  if (!linkcollector.data.empty()) {
289  theDigiLinkVector.push_back(std::move(linkcollector));
290  }
291  }
292  }
293 
294  // Step C: create collection with the cache vector of DetSet
295  std::unique_ptr<edm::DetSetVector<PixelDigi> > output(new edm::DetSetVector<PixelDigi>(theDigiVector));
296  std::unique_ptr<edm::DetSetVector<PixelDigiSimLink> > outputlink(
297  new edm::DetSetVector<PixelDigiSimLink>(theDigiLinkVector));
298 
299  // Step D: write output to file
300  iEvent.put(std::move(output));
301  iEvent.put(std::move(outputlink));
302 
303  randomEngine_ = nullptr; // to prevent access outside event
304  }
305 } // namespace cms
Vector3DBase
Definition: Vector3DBase.h:8
RPCChamberQuality_cfi.NumberOfEndcapDisks
NumberOfEndcapDisks
Definition: RPCChamberQuality_cfi.py:7
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
edm::DetSetVector
Definition: DetSetVector.h:61
edm::StreamID
Definition: StreamID.h:30
PixelDigiCollection.h
cms::SiPixelDigitizer::crossingSimHitIndexOffset_
std::map< std::string, size_t > crossingSimHitIndexOffset_
Offset to add to the index of each sim hit to account for which crossing it's in.
Definition: SiPixelDigitizer.h:89
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
Handle.h
cms::SiPixelDigitizer::NumberOfEndcapDisks
const int NumberOfEndcapDisks
Definition: SiPixelDigitizer.h:103
cms::SiPixelDigitizer::firstInitializeEvent_
bool firstInitializeEvent_
Definition: SiPixelDigitizer.h:78
MagneticField::inTesla
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
TrackerGeometry.h
PixelTopology.h
ESHandle.h
cms::SiPixelDigitizer::pilotBlades
const bool pilotBlades
Definition: SiPixelDigitizer.h:102
edm::DetSet
Definition: DetSet.h:23
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
RandomNumberGenerator.h
TrackerTopology
Definition: TrackerTopology.h:16
cms::SiPixelDigitizer::~SiPixelDigitizer
~SiPixelDigitizer() override
Definition: SiPixelDigitizer.cc:120
PSimHitContainer.h
PixelFEDChannel.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
cms::cuda::assert
assert(be >=bs)
FastTrackerRecHitCombiner_cfi.simHits
simHits
Definition: FastTrackerRecHitCombiner_cfi.py:5
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
PileUpEventPrincipal
Definition: PileUpEventPrincipal.h:19
EDAnalyzer.h
PixelDigi.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
hcalUnsuppressedDigis_cfi.hitsProducer
hitsProducer
Definition: hcalUnsuppressedDigis_cfi.py:22
cms::SiPixelDigitizer::pSetup
edm::ESHandle< MagneticField > pSetup
Definition: SiPixelDigitizer.h:96
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
MakerMacros.h
TrackerTopology.h
hgcalDigitizer_cfi.geometryType
geometryType
Definition: hgcalDigitizer_cfi.py:83
PSimHit.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
TrackerGeometry::detUnits
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
Definition: TrackerGeometry.h:61
cms::SiPixelDigitizer::PileupInfo_
std::unique_ptr< PileupMixingContent > PileupInfo_
Definition: SiPixelDigitizer.h:100
SiPixelDigitizer.h
Service.h
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
IdealMagneticFieldRecord.h
edm::ESHandle< TrackerTopology >
PileUpEventPrincipal.h
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:55
cms::SiPixelDigitizer::hitsProducer
const std::string hitsProducer
Definition: SiPixelDigitizer.h:92
PixelGeomDetType.h
cms::SiPixelDigitizer::accumulate
void accumulate(edm::Event const &e, edm::EventSetup const &c) override
Definition: SiPixelDigitizer.cc:207
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
funct::true
true
Definition: Factorize.h:173
TrackerDigiGeometryRecord.h
cms::SiPixelDigitizer::_pixeldigialgo
std::unique_ptr< SiPixelDigitizerAlgorithm > _pixeldigialgo
Definition: SiPixelDigitizer.h:80
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
cms::SiPixelDigitizer::detectorUnits
std::map< unsigned int, PixelGeomDetUnit const * > detectorUnits
Definition: SiPixelDigitizer.h:97
cms::SiPixelDigitizer::SiPixelDigitizer
SiPixelDigitizer(const edm::ParameterSet &conf, edm::ProducesCollector, edm::ConsumesCollector &iC)
Definition: SiPixelDigitizer.cc:85
Event.h
cms::SiPixelDigitizer::initializeEvent
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
Definition: SiPixelDigitizer.cc:163
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:39
edm::Service< edm::RandomNumberGenerator >
createfilelist.int
int
Definition: createfilelist.py:10
GeomDetEnumerators::isTrackerPixel
bool isTrackerPixel(GeomDetEnumerators::SubDetector m)
Definition: GeomDetEnumerators.cc:68
iEvent
int iEvent
Definition: GenABIO.cc:224
cms::SiPixelDigitizer::pDD
edm::ESHandle< TrackerGeometry > pDD
Definition: SiPixelDigitizer.h:95
cms::SiPixelDigitizer::accumulatePixelHits
void accumulatePixelHits(edm::Handle< std::vector< PSimHit > >, size_t globalSimHitIndex, const unsigned int tofBin, edm::EventSetup const &c)
Definition: SiPixelDigitizer.cc:126
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::ProducesCollector::produces
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
Definition: ProducesCollector.h:52
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:57
DetSetVector.h
cms::SiPixelDigitizer::trackerContainers
const vstring trackerContainers
Definition: SiPixelDigitizer.h:93
get
#define get
MixingModule_cfi.bunchspace
bunchspace
Definition: MixingModule_cfi.py:41
GeomDet.h
edmNew::DetSetVector
Definition: DetSetNew.h:13
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ProducesCollector
Definition: ProducesCollector.h:43
Frameworkfwd.h
LocalPoint.h
cms::SiPixelDigitizer::randomEngine_
CLHEP::HepRandomEngine * randomEngine_
Definition: SiPixelDigitizer.h:98
SiStripOfflineCRack_cfg.alias
alias
Definition: SiStripOfflineCRack_cfg.py:128
Exception
Definition: hltDiff.cc:246
PixelGeomDetUnit.h
EventSetup.h
cms::SiPixelDigitizer::geometryType
const std::string geometryType
Definition: SiPixelDigitizer.h:94
Exception.h
GeomDetEnumerators::PixelEndcap
Definition: GeomDetEnumerators.h:12
cms::SiPixelDigitizer::finalizeEvent
void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
Definition: SiPixelDigitizer.cc:252
DetSet.h
ConsumesCollector.h
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
ParameterSet.h
SiPixelDigitizerAlgorithm.h
edm::Event
Definition: Event.h:73
LocalVector.h
StreamID.h
cms::SiPixelDigitizer::firstFinalizeEvent_
bool firstFinalizeEvent_
Definition: SiPixelDigitizer.h:79
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37