CMS 3D CMS Logo

DataMixingSiPixelWorker.cc
Go to the documentation of this file.
1 // File: DataMixingSiPixelWorker.cc
2 // Description: see DataMixingSiPixelWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
9 #include <map>
10 #include <memory>
11 //
12 //
14 
15 using namespace std;
16 
17 namespace edm {
18 
19  // Virtual constructor
20 
21  DataMixingSiPixelWorker::DataMixingSiPixelWorker() {}
22 
23  // Constructor
24  DataMixingSiPixelWorker::DataMixingSiPixelWorker(const edm::ParameterSet &ps, edm::ConsumesCollector &&iC)
25  : label_(ps.getParameter<std::string>("Label"))
26 
27  {
28  // get the subdetector names
29  // this->getSubdetectorNames(); //something like this may be useful to
30  // check what we are supposed to do...
31 
32  // declare the products to produce
33 
34  pixeldigi_collectionSig_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionSig");
35  pixeldigi_collectionPile_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionPile");
36  PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
37 
40 
41  // clear local storage for this event
42  SiHitStorage_.clear();
43  }
44 
45  // Virtual destructor needed.
47 
49  // fill in maps of hits
50 
51  LogDebug("DataMixingSiPixelWorker") << "===============> adding MC signals for " << e.id();
52 
54 
55  if (e.getByToken(PixelDigiToken_, input)) {
56  // loop on all detsets (detectorIDs) inside the input collection
58  for (; DSViter != input->end(); DSViter++) {
59 #ifdef DEBUG
60  LogDebug("DataMixingSiPixelWorker") << "Processing DetID " << DSViter->id;
61 #endif
62 
63  uint32_t detID = DSViter->id;
64  edm::DetSet<PixelDigi>::const_iterator begin = (DSViter->data).begin();
67 
68  OneDetectorMap LocalMap;
69 
70  for (icopy = begin; icopy != end; icopy++) {
71  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
72  }
73 
74  SiHitStorage_.insert(SiGlobalIndex::value_type(detID, LocalMap));
75  }
76  }
77  } // end of addSiPixelSignals
78 
80  const EventPrincipal *ep,
81  unsigned int eventNr,
82  ModuleCallingContext const *mcc) {
83  LogDebug("DataMixingSiPixelWorker") << "\n===============> adding pileups from event " << ep->id()
84  << " for bunchcrossing " << bcr;
85 
86  // fill in maps of hits; same code as addSignals, except now applied to the
87  // pileup events
88 
89  std::shared_ptr<Wrapper<edm::DetSetVector<PixelDigi>> const> inputPTR =
90  getProductByTag<edm::DetSetVector<PixelDigi>>(*ep, pixeldigi_collectionPile_, mcc);
91 
92  if (inputPTR) {
93  const edm::DetSetVector<PixelDigi> *input = const_cast<edm::DetSetVector<PixelDigi> *>(inputPTR->product());
94 
95  // Handle< edm::DetSetVector<PixelDigi> > input;
96 
97  // if( e->getByLabel(pixeldigi_collectionPile_,input) ) {
98 
99  // loop on all detsets (detectorIDs) inside the input collection
101  for (; DSViter != input->end(); DSViter++) {
102 #ifdef DEBUG
103  LogDebug("DataMixingSiPixelWorker") << "Pileups: Processing DetID " << DSViter->id;
104 #endif
105 
106  uint32_t detID = DSViter->id;
107  edm::DetSet<PixelDigi>::const_iterator begin = (DSViter->data).begin();
108  edm::DetSet<PixelDigi>::const_iterator end = (DSViter->data).end();
110 
111  // find correct local map (or new one) for this detector ID
112 
113  SiGlobalIndex::const_iterator itest;
114 
115  itest = SiHitStorage_.find(detID);
116 
117  if (itest != SiHitStorage_.end()) { // this detID already has hits, add to existing map
118 
119  OneDetectorMap LocalMap = itest->second;
120 
121  // fill in local map with extra channels
122  for (icopy = begin; icopy != end; icopy++) {
123  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
124  }
125 
126  SiHitStorage_[detID] = LocalMap;
127 
128  } else { // fill local storage with this information, put in global
129  // collection
130 
131  OneDetectorMap LocalMap;
132 
133  for (icopy = begin; icopy != end; icopy++) {
134  LocalMap.insert(OneDetectorMap::value_type((icopy->channel()), *icopy));
135  }
136 
137  SiHitStorage_.insert(SiGlobalIndex::value_type(detID, LocalMap));
138  }
139  }
140  }
141  }
142 
144  // collection of Digis to put in the event
145 
146  std::vector<edm::DetSet<PixelDigi>> vPixelDigi;
147 
148  // loop through our collection of detectors, merging hits and putting new ones
149  // in the output
150 
151  // big loop over Detector IDs:
152 
153  for (SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin(); IDet != SiHitStorage_.end(); IDet++) {
154  edm::DetSet<PixelDigi> SPD(IDet->first); // Make empty collection with this detector ID
155 
156  OneDetectorMap LocalMap = IDet->second;
157 
158  // counter variables
159  int formerPixel = -1;
160  int currentPixel;
161  int ADCSum = 0;
162 
163  OneDetectorMap::const_iterator iLocalchk;
164 
165  for (OneDetectorMap::const_iterator iLocal = LocalMap.begin(); iLocal != LocalMap.end(); ++iLocal) {
166  currentPixel = iLocal->first;
167 
168  if (currentPixel == formerPixel) { // we have to add these digis together
169  ADCSum += (iLocal->second).adc();
170  } else {
171  if (formerPixel != -1) { // ADC info stolen from SiStrips...
172  if (ADCSum > 511)
173  ADCSum = 255;
174  else if (ADCSum > 253 && ADCSum < 512)
175  ADCSum = 254;
176  PixelDigi aHit(formerPixel, ADCSum);
177  SPD.push_back(aHit);
178  }
179  // save pointers for next iteration
180  formerPixel = currentPixel;
181  ADCSum = (iLocal->second).adc();
182  }
183 
184  iLocalchk = iLocal;
185  if ((++iLocalchk) == LocalMap.end()) { // make sure not to lose the last one
186  if (ADCSum > 511)
187  ADCSum = 255;
188  else if (ADCSum > 253 && ADCSum < 512)
189  ADCSum = 254;
190  SPD.push_back(PixelDigi(formerPixel, ADCSum));
191  }
192 
193  } // end of loop over one detector
194 
195  // stick this into the global vector of detector info
196  vPixelDigi.push_back(SPD);
197 
198  } // end of big loop over all detector IDs
199 
200  // put the collection of digis in the event
201  LogInfo("DataMixingSiPixelWorker") << "total # Merged Pixels: " << vPixelDigi.size();
202 
203  // make new digi collection
204 
205  std::unique_ptr<edm::DetSetVector<PixelDigi>> MyPixelDigis(new edm::DetSetVector<PixelDigi>(vPixelDigi));
206 
207  // put collection
208 
209  e.put(std::move(MyPixelDigis), PixelDigiCollectionDM_);
210 
211  // clear local storage for this event
212  SiHitStorage_.clear();
213  }
214 
215 } // namespace edm
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void push_back(const T &t)
Definition: DetSet.h:66
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiToken_
void addSiPixelPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
static std::string const input
Definition: EdmProvDump.cc:47
edm::EDGetTokenT< edm::DetSetVector< PixelDigi > > PixelDigiPToken_
Log< level::Info, false > LogInfo
std::multimap< int, PixelDigi > OneDetectorMap
HLT enums.
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
def move(src, dest)
Definition: eostools.py:511
void addSiPixelSignals(const edm::Event &e)
uint16_t *__restrict__ uint16_t const *__restrict__ adc
#define LogDebug(id)