CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
7 #include <map>
15 //
16 //
18 
19 
20 using namespace std;
21 
22 namespace edm
23 {
24 
25  // Virtual constructor
26 
27  DataMixingSiPixelWorker::DataMixingSiPixelWorker() { }
28 
29  // Constructor
30  DataMixingSiPixelWorker::DataMixingSiPixelWorker(const edm::ParameterSet& ps) :
31  label_(ps.getParameter<std::string>("Label"))
32 
33  {
34 
35  // get the subdetector names
36  // this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
37 
38  // declare the products to produce
39 
40  pixeldigi_collectionSig_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionSig");
41  pixeldigi_collectionPile_ = ps.getParameter<edm::InputTag>("pixeldigiCollectionPile");
42  PixelDigiCollectionDM_ = ps.getParameter<std::string>("PixelDigiCollectionDM");
43 
44  // clear local storage for this event
45  SiHitStorage_.clear();
46 
47  }
48 
49 
50  // Virtual destructor needed.
52  }
53 
54 
55 
57  // fill in maps of hits
58 
59  LogDebug("DataMixingSiPixelWorker")<<"===============> adding MC signals for "<<e.id();
60 
62 
63  if( e.getByLabel(pixeldigi_collectionSig_,input) ) {
64 
65  //loop on all detsets (detectorIDs) inside the input collection
66  edm::DetSetVector<PixelDigi>::const_iterator DSViter=input->begin();
67  for (; DSViter!=input->end();DSViter++){
68 
69 #ifdef DEBUG
70  LogDebug("DataMixingSiPixelWorker") << "Processing DetID " << DSViter->id;
71 #endif
72 
73  uint32_t detID = DSViter->id;
77 
78  OneDetectorMap LocalMap;
79 
80  for (icopy=begin; icopy!=end; icopy++) {
81  LocalMap.insert(OneDetectorMap::value_type( (icopy->channel()), *icopy ));
82  }
83 
84  SiHitStorage_.insert( SiGlobalIndex::value_type( detID, LocalMap ) );
85  }
86 
87  }
88  } // end of addSiPixelSignals
89 
90 
91 
92  void DataMixingSiPixelWorker::addSiPixelPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr) {
93 
94  LogDebug("DataMixingSiPixelWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
95 
96  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
97 
98  boost::shared_ptr<Wrapper<edm::DetSetVector<PixelDigi> > const> inputPTR =
99  getProductByTag<edm::DetSetVector<PixelDigi> >(*ep, pixeldigi_collectionPile_ );
100 
101  if(inputPTR ) {
102 
103  const edm::DetSetVector<PixelDigi> *input = const_cast< edm::DetSetVector<PixelDigi> * >(inputPTR->product());
104 
105 
106 
107  // Handle< edm::DetSetVector<PixelDigi> > input;
108 
109  // if( e->getByLabel(pixeldigi_collectionPile_,input) ) {
110 
111  //loop on all detsets (detectorIDs) inside the input collection
113  for (; DSViter!=input->end();DSViter++){
114 
115 #ifdef DEBUG
116  LogDebug("DataMixingSiPixelWorker") << "Pileups: Processing DetID " << DSViter->id;
117 #endif
118 
119  uint32_t detID = DSViter->id;
123 
124  // find correct local map (or new one) for this detector ID
125 
126  SiGlobalIndex::const_iterator itest;
127 
128  itest = SiHitStorage_.find(detID);
129 
130  if(itest!=SiHitStorage_.end()) { // this detID already has hits, add to existing map
131 
132  OneDetectorMap LocalMap = itest->second;
133 
134  // fill in local map with extra channels
135  for (icopy=begin; icopy!=end; icopy++) {
136  LocalMap.insert(OneDetectorMap::value_type( (icopy->channel()), *icopy ));
137  }
138 
139  SiHitStorage_[detID]=LocalMap;
140 
141  }
142  else{ // fill local storage with this information, put in global collection
143 
144  OneDetectorMap LocalMap;
145 
146  for (icopy=begin; icopy!=end; icopy++) {
147  LocalMap.insert(OneDetectorMap::value_type( (icopy->channel()), *icopy ));
148  }
149 
150  SiHitStorage_.insert( SiGlobalIndex::value_type( detID, LocalMap ) );
151  }
152 
153  }
154  }
155  }
156 
157 
158 
160 
161  // collection of Digis to put in the event
162 
163  std::vector< edm::DetSet<PixelDigi> > vPixelDigi;
164 
165  // loop through our collection of detectors, merging hits and putting new ones in the output
166 
167  // big loop over Detector IDs:
168 
169  for(SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin();
170  IDet != SiHitStorage_.end(); IDet++) {
171 
172  edm::DetSet<PixelDigi> SPD(IDet->first); // Make empty collection with this detector ID
173 
174  OneDetectorMap LocalMap = IDet->second;
175 
176  //counter variables
177  int formerPixel = -1;
178  int currentPixel;
179  int ADCSum = 0;
180 
181 
182  OneDetectorMap::const_iterator iLocalchk;
183 
184  for(OneDetectorMap::const_iterator iLocal = LocalMap.begin();
185  iLocal != LocalMap.end(); ++iLocal) {
186 
187  currentPixel = iLocal->first;
188 
189  if (currentPixel == formerPixel) { // we have to add these digis together
190  ADCSum+=(iLocal->second).adc();
191  }
192  else{
193  if(formerPixel!=-1){ // ADC info stolen from SiStrips...
194  if (ADCSum > 511) ADCSum = 255;
195  else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
196  PixelDigi aHit(formerPixel, ADCSum);
197  SPD.push_back( aHit );
198  }
199  // save pointers for next iteration
200  formerPixel = currentPixel;
201  ADCSum = (iLocal->second).adc();
202  }
203 
204  iLocalchk = iLocal;
205  if((++iLocalchk) == LocalMap.end()) { //make sure not to lose the last one
206  if (ADCSum > 511) ADCSum = 255;
207  else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
208  SPD.push_back( PixelDigi(formerPixel, ADCSum) );
209  }
210 
211  }// end of loop over one detector
212 
213  // stick this into the global vector of detector info
214  vPixelDigi.push_back(SPD);
215 
216  } // end of big loop over all detector IDs
217 
218  // put the collection of digis in the event
219  LogInfo("DataMixingSiPixelWorker") << "total # Merged Pixels: " << vPixelDigi.size() ;
220 
221  // make new digi collection
222 
223  std::auto_ptr< edm::DetSetVector<PixelDigi> > MyPixelDigis(new edm::DetSetVector<PixelDigi>(vPixelDigi) );
224 
225  // put collection
226 
227  e.put( MyPixelDigis, PixelDigiCollectionDM_ );
228 
229  // clear local storage for this event
230  SiHitStorage_.clear();
231  }
232 
233 } //edm
int adc(sample_type sample)
get the ADC sample (12 bits)
#define LogDebug(id)
T getParameter(std::string const &) const
void push_back(const T &t)
Definition: DetSet.h:69
void addSiPixelPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId)
EventID const & id() const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
#define end
Definition: vmac.h:38
Container::value_type value_type
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:356
std::multimap< int, PixelDigi > OneDetectorMap
edm::EventID id() const
Definition: EventBase.h:56
#define begin
Definition: vmac.h:31
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:341
collection_type::const_iterator const_iterator
Definition: DetSet.h:34
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:106
void addSiPixelSignals(const edm::Event &e)