CMS 3D CMS Logo

PreMixingSiPixelWorker.cc
Go to the documentation of this file.
10 
11 //Data Formats
17 
21 
29 
30 #include "CLHEP/Random/RandFlat.h"
31 
34 
36 
37 #include <map>
38 #include <memory>
39 
41 public:
43  ~PreMixingSiPixelWorker() override = default;
44 
45  void initializeEvent(edm::Event const& e, edm::EventSetup const& c) override;
46  void addSignals(edm::Event const& e, edm::EventSetup const& es) override;
47  void addPileups(PileUpEventPrincipal const&, edm::EventSetup const& es) override;
48  void put(edm::Event& e, edm::EventSetup const& iSetup, std::vector<PileupSummaryInfo> const& ps, int bs) override;
49 
50 private:
51  edm::InputTag pixeldigi_collectionSig_; // secondary name given to collection of SiPixel digis
52  edm::InputTag pixeldigi_collectionPile_; // secondary name given to collection of SiPixel digis
53  std::string PixelDigiCollectionDM_; // secondary name to be given to new SiPixel digis
54 
59 
61 
62  //
63  // Internal typedefs
64 
65  typedef int Amplitude;
66  typedef std::map<int, Amplitude, std::less<int>> signal_map_type; // from Digi.Skel.
67  typedef std::map<uint32_t, signal_map_type> signalMaps;
68 
69  typedef std::multimap<int, PixelDigi>
70  OneDetectorMap; // maps by pixel ID for later combination - can have duplicate pixels
71  typedef std::map<uint32_t, OneDetectorMap> SiGlobalIndex; // map to all data for each detector ID
72 
74 
75  bool firstInitializeEvent_ = true;
76  bool firstFinalizeEvent_ = true;
77 };
78 
79 // Constructor
81  edm::ProducesCollector producesCollector,
83  : tTopoToken_(iC.esConsumes()),
84  pDDToken_(iC.esConsumes(edm::ESInputTag("", ps.getParameter<std::string>("PixGeometryType")))),
85  digitizer_(ps, iC) {
86  // declare the products to produce
87 
88  pixeldigi_collectionSig_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionSig");
89  pixeldigi_collectionPile_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionPile");
90  PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
91 
94 
97 
98  // clear local storage for this event
99  SiHitStorage_.clear();
100 }
101 
102 // Need an event initialization
103 
105  if (firstInitializeEvent_) {
106  digitizer_.init(iSetup);
107  firstInitializeEvent_ = false;
108  }
110 }
111 
113  // fill in maps of hits
114 
115  LogDebug("PreMixingSiPixelWorker") << "===============> adding MC signals for " << e.id();
116 
118 
119  if (e.getByToken(PixelDigiToken_, input)) {
120  //loop on all detsets (detectorIDs) inside the input collection
122  for (; DSViter != input->end(); DSViter++) {
123 #ifdef DEBUG
124  LogDebug("PreMixingSiPixelWorker") << "Processing DetID " << DSViter->id;
125 #endif
126 
127  uint32_t detID = DSViter->id;
128  edm::DetSet<PixelDigi>::const_iterator begin = (DSViter->data).begin();
129  edm::DetSet<PixelDigi>::const_iterator end = (DSViter->data).end();
131 
132  OneDetectorMap LocalMap;
133 
134  for (icopy = begin; icopy != end; icopy++) {
135  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
136  }
137 
138  SiHitStorage_.insert(SiGlobalIndex::value_type(detID, LocalMap));
139  }
140  }
141 } // end of addSiPixelSignals
142 
144  LogDebug("PreMixingSiPixelWorker") << "\n===============> adding pileups from event " << pep.principal().id()
145  << " for bunchcrossing " << pep.bunchCrossing();
146 
147  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
148 
150  pep.getByLabel(pixeldigi_collectionPile_, inputHandle);
151 
152  if (inputHandle.isValid()) {
153  const auto& input = *inputHandle;
154 
155  //loop on all detsets (detectorIDs) inside the input collection
157  for (; DSViter != input.end(); DSViter++) {
158 #ifdef DEBUG
159  LogDebug("PreMixingSiPixelWorker") << "Pileups: Processing DetID " << DSViter->id;
160 #endif
161 
162  uint32_t detID = DSViter->id;
163  edm::DetSet<PixelDigi>::const_iterator begin = (DSViter->data).begin();
164  edm::DetSet<PixelDigi>::const_iterator end = (DSViter->data).end();
166 
167  // find correct local map (or new one) for this detector ID
168 
169  SiGlobalIndex::const_iterator itest;
170 
171  itest = SiHitStorage_.find(detID);
172 
173  if (itest != SiHitStorage_.end()) { // this detID already has hits, add to existing map
174 
175  OneDetectorMap LocalMap = itest->second;
176 
177  // fill in local map with extra channels
178  for (icopy = begin; icopy != end; icopy++) {
179  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
180  }
181 
182  SiHitStorage_[detID] = LocalMap;
183 
184  } else { // fill local storage with this information, put in global collection
185 
186  OneDetectorMap LocalMap;
187 
188  for (icopy = begin; icopy != end; icopy++) {
189  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
190  }
191 
192  SiHitStorage_.insert(SiGlobalIndex::value_type(detID, LocalMap));
193  }
194  }
195  }
196 }
197 
199  edm::EventSetup const& iSetup,
200  std::vector<PileupSummaryInfo> const& ps,
201  int bs) {
202  // collection of Digis to put in the event
203 
204  std::vector<edm::DetSet<PixelDigi>> vPixelDigi;
205 
206  // loop through our collection of detectors, merging hits and putting new ones in the output
207  signalMaps signal;
208 
209  // big loop over Detector IDs:
210 
211  for (SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin(); IDet != SiHitStorage_.end(); IDet++) {
212  uint32_t detID = IDet->first;
213 
214  OneDetectorMap LocalMap = IDet->second;
215 
216  signal_map_type Signals;
217  Signals.clear();
218 
219  //counter variables
220  int formerPixel = -1;
221  int currentPixel;
222  int ADCSum = 0;
223 
224  OneDetectorMap::const_iterator iLocalchk;
225 
226  for (OneDetectorMap::const_iterator iLocal = LocalMap.begin(); iLocal != LocalMap.end(); ++iLocal) {
227  currentPixel = iLocal->first;
228 
229  if (currentPixel == formerPixel) { // we have to add these digis together
230  ADCSum += (iLocal->second).adc();
231  } else {
232  if (formerPixel != -1) { // ADC info stolen from SiStrips...
233  if (ADCSum > 511)
234  ADCSum = 255;
235  else if (ADCSum > 253 && ADCSum < 512)
236  ADCSum = 254;
237 
238  Signals.insert(std::make_pair(formerPixel, ADCSum));
239  }
240  // save pointers for next iteration
241  formerPixel = currentPixel;
242  ADCSum = (iLocal->second).adc();
243  }
244 
245  iLocalchk = iLocal;
246  if ((++iLocalchk) == LocalMap.end()) { //make sure not to lose the last one
247  if (ADCSum > 511)
248  ADCSum = 255;
249  else if (ADCSum > 253 && ADCSum < 512)
250  ADCSum = 254;
251  Signals.insert(std::make_pair(formerPixel, ADCSum));
252  }
253 
254  } // end of loop over one detector
255 
256  // stick this into the global vector of detector info
257  signal.insert(std::make_pair(detID, Signals));
258 
259  } // end of big loop over all detector IDs
260 
261  // put the collection of digis in the event
262  edm::LogInfo("PreMixingSiPixelWorker") << "total # Merged Pixels: " << signal.size();
263 
264  std::vector<edm::DetSet<PixelDigi>> theDigiVector;
265 
266  // Load inefficiency constants (1st pass), set pileup information.
267  if (firstFinalizeEvent_) {
268  digitizer_.init_DynIneffDB(iSetup);
269  firstFinalizeEvent_ = false;
270  }
271 
274 
276  CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
277 
278  auto const& pDD = iSetup.getData(pDDToken_);
279  const TrackerTopology* tTopo = &iSetup.getData(tTopoToken_);
280 
282  std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_ = digitizer_.chooseScenario(ps, engine);
283  if (PixelFEDChannelCollection_ == nullptr) {
284  throw cms::Exception("NullPointerError") << "PixelFEDChannelCollection not set in chooseScenario function.\n";
285  }
286  e.put(std::move(PixelFEDChannelCollection_), PixelDigiCollectionDM_);
287  }
288 
289  for (const auto& iu : pDD.detUnits()) {
290  if (iu->type().isTrackerPixel()) {
291  edm::DetSet<PixelDigi> collector(iu->geographicalId().rawId());
292  edm::DetSet<PixelDigiSimLink> linkcollector(
293  iu->geographicalId().rawId()); // ignored as DigiSimLinks are combined separately
294 
295  digitizer_.digitize(dynamic_cast<const PixelGeomDetUnit*>(iu), collector.data, linkcollector.data, tTopo, engine);
296  if (!collector.data.empty()) {
297  theDigiVector.push_back(std::move(collector));
298  }
299  }
300  }
301 
302  e.put(std::make_unique<edm::DetSetVector<PixelDigi>>(theDigiVector), PixelDigiCollectionDM_);
303 
304  // clear local storage for this event
305  SiHitStorage_.clear();
306 }
307 
edm::DetSetVector< PixelDigi >
PreMixingSiPixelWorker::digitizer_
SiPixelDigitizerAlgorithm digitizer_
Definition: PreMixingSiPixelWorker.cc:60
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
Handle.h
PileupSummaryInfo.h
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
PreMixingSiPixelWorker::PreMixingSiPixelWorker
PreMixingSiPixelWorker(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &&iC)
Definition: PreMixingSiPixelWorker.cc:80
TrackerGeometry.h
PixelTopology.h
SiPixelDigitizerAlgorithm::killBadFEDChannels
bool killBadFEDChannels() const
Definition: SiPixelDigitizerAlgorithm.cc:911
ESInputTag
SiPixelDigitizerAlgorithm
Definition: SiPixelDigitizerAlgorithm.h:56
edm::DetSet
Definition: DetSet.h:23
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
RandomNumberGenerator.h
gpuClustering::adc
uint16_t *__restrict__ uint16_t const *__restrict__ adc
Definition: gpuClusterChargeCut.h:20
TrackerTopology
Definition: TrackerTopology.h:16
PreMixingSiPixelWorker::~PreMixingSiPixelWorker
~PreMixingSiPixelWorker() override=default
GeomDetType.h
PileUpEventPrincipal::bunchCrossing
int bunchCrossing() const
Definition: PileUpEventPrincipal.h:30
PileUpEventPrincipal
Definition: PileUpEventPrincipal.h:19
PixelDigi.h
PreMixingSiPixelWorker::signalMaps
std::map< uint32_t, signal_map_type > signalMaps
Definition: PreMixingSiPixelWorker.cc:67
PreMixingSiPixelWorker::Amplitude
int Amplitude
Definition: PreMixingSiPixelWorker.cc:65
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::EventPrincipal::id
EventID const & id() const
Definition: EventPrincipal.h:96
ProducesCollector.h
PreMixingSiPixelWorker::pDDToken_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > pDDToken_
Definition: PreMixingSiPixelWorker.cc:58
TrackerTopology.h
cms::cuda::bs
bs
Definition: HistoContainer.h:76
PreMixingSiPixelWorker::addSignals
void addSignals(edm::Event const &e, edm::EventSetup const &es) override
Definition: PreMixingSiPixelWorker.cc:112
SiPixelDigitizerAlgorithm::init
void init(const edm::EventSetup &es)
Definition: SiPixelDigitizerAlgorithm.cc:107
PreMixingWorker.h
SiPixelDigitizerAlgorithm::init_DynIneffDB
void init_DynIneffDB(const edm::EventSetup &)
Definition: SiPixelDigitizerAlgorithm.cc:598
Service.h
PreMixingSiPixelWorker::pixeldigi_collectionSig_
edm::InputTag pixeldigi_collectionSig_
Definition: PreMixingSiPixelWorker.cc:51
mps_fire.end
end
Definition: mps_fire.py:242
PileUpEventPrincipal::principal
edm::EventPrincipal const & principal()
Definition: PileUpEventPrincipal.h:24
PileUpEventPrincipal.h
SiPixelDigitizerAlgorithm::chooseScenario
std::unique_ptr< PixelFEDChannelCollection > chooseScenario(PileupMixingContent *puInfo, CLHEP::HepRandomEngine *)
Definition: SiPixelDigitizerAlgorithm.cc:960
PreMixingSiPixelWorker::tTopoToken_
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
Definition: PreMixingSiPixelWorker.cc:57
PixelGeomDetType.h
PreMixingSiPixelWorker::addPileups
void addPileups(PileUpEventPrincipal const &, edm::EventSetup const &es) override
Definition: PreMixingSiPixelWorker.cc:143
PreMixingSiPixelWorker::initializeEvent
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
Definition: PreMixingSiPixelWorker.cc:104
TrackerDigiGeometryRecord.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
SiPixelDigitizerAlgorithm::calculateInstlumiFactor
void calculateInstlumiFactor(PileupMixingContent *puInfo)
Definition: SiPixelDigitizerAlgorithm.cc:848
Event.h
PreMixingSiPixelWorker::PixelDigiPToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiPToken_
Definition: PreMixingSiPixelWorker.cc:56
PreMixingSiPixelWorker::firstInitializeEvent_
bool firstInitializeEvent_
Definition: PreMixingSiPixelWorker.cc:75
edm::DetSetVector::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
edm::Service< edm::RandomNumberGenerator >
edm::ProducesCollector::produces
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
Definition: ProducesCollector.h:52
PreMixingSiPixelWorker::firstFinalizeEvent_
bool firstFinalizeEvent_
Definition: PreMixingSiPixelWorker.cc:76
edm::EventSetup
Definition: EventSetup.h:58
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
DetSetVector.h
PreMixingSiPixelWorker::PixelDigiToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiToken_
Definition: PreMixingSiPixelWorker.cc:55
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PreMixingSiPixelWorker::signal_map_type
std::map< int, Amplitude, std::less< int > > signal_map_type
Definition: PreMixingSiPixelWorker.cc:66
PixelIndices.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
PreMixingWorkerFactory.h
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
PreMixingSiPixelWorker::SiHitStorage_
SiGlobalIndex SiHitStorage_
Definition: PreMixingSiPixelWorker.cc:73
Exception
Definition: hltDiff.cc:245
DEFINE_PREMIXING_WORKER
#define DEFINE_PREMIXING_WORKER(TYPE)
Definition: PreMixingWorkerFactory.h:16
PixelGeomDetUnit.h
PreMixingSiPixelWorker::pixeldigi_collectionPile_
edm::InputTag pixeldigi_collectionPile_
Definition: PreMixingSiPixelWorker.cc:52
PreMixingSiPixelWorker::SiGlobalIndex
std::map< uint32_t, OneDetectorMap > SiGlobalIndex
Definition: PreMixingSiPixelWorker.cc:71
PreMixingSiPixelWorker::put
void put(edm::Event &e, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bs) override
Definition: PreMixingSiPixelWorker.cc:198
PreMixingSiPixelWorker::OneDetectorMap
std::multimap< int, PixelDigi > OneDetectorMap
Definition: PreMixingSiPixelWorker.cc:70
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
PreMixingWorker
Definition: PreMixingWorker.h:14
PreMixingSiPixelWorker::PixelDigiCollectionDM_
std::string PixelDigiCollectionDM_
Definition: PreMixingSiPixelWorker.cc:53
DetSet.h
ConsumesCollector.h
SiPixelDigitizerAlgorithm::setSimAccumulator
void setSimAccumulator(const std::map< uint32_t, std::map< int, int > > &signalMap)
Definition: SiPixelDigitizerAlgorithm.cc:1005
ParameterSet.h
PileUpEventPrincipal::getByLabel
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
Definition: PileUpEventPrincipal.h:33
PreMixingSiPixelWorker
Definition: PreMixingSiPixelWorker.cc:40
SiPixelDigitizerAlgorithm.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
SiPixelDigitizerAlgorithm::digitize
void digitize(const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
Definition: SiPixelDigitizerAlgorithm.cc:1016
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
SiPixelDigitizerAlgorithm::initializeEvent
void initializeEvent()
Definition: SiPixelDigitizerAlgorithm.h:64
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31