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