CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataMixingSiStripWorker.cc
Go to the documentation of this file.
1 // File: DataMixingSiStripWorker.cc
2 // Description: see DataMixingSiStripWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
7 #include <map>
15 //
16 //
18 
19 using namespace std;
20 
21 namespace edm
22 {
23 
24  // Virtual constructor
25 
26  DataMixingSiStripWorker::DataMixingSiStripWorker() { sel_=0;}
27 
28  // Constructor
29  DataMixingSiStripWorker::DataMixingSiStripWorker(const edm::ParameterSet& ps) :
30  label_(ps.getParameter<std::string>("Label"))
31 
32  {
33 
34  // get the subdetector names
35  // this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
36 
37  // create input selector
38  if (label_.size()>0){
40  }
41  else {
43  }
44 
45  // declare the products to produce
46 
47  SistripLabelSig_ = ps.getParameter<edm::InputTag>("SistripLabelSig");
48  SiStripPileInputTag_ = ps.getParameter<edm::InputTag>("SiStripPileInputTag");
49 
50  SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
51 
52  // clear local storage for this event
53  SiHitStorage_.clear();
54 
55  }
56 
57 
58  // Virtual destructor needed.
60  delete sel_;
61  sel_=0;
62  }
63 
64 
65 
67  // fill in maps of hits
68 
70 
71  if( e.getByLabel(SistripLabelSig_,input) ) {
72  OneDetectorMap LocalMap;
73 
74  //loop on all detsets (detectorIDs) inside the input collection
76  for (; DSViter!=input->end();DSViter++){
77 
78 #ifdef DEBUG
79  LogDebug("DataMixingSiStripWorker") << "Processing DetID " << DSViter->id;
80 #endif
81 
82  LocalMap.clear();
83  LocalMap.reserve((DSViter->data).size());
84  LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
85 
86  SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
87  }
88 
89  }
90  } // end of addSiStripSignals
91 
92 
93 
94  void DataMixingSiStripWorker::addSiStripPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr) {
95  LogDebug("DataMixingSiStripWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
96 
97  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
98 
99  boost::shared_ptr<Wrapper<edm::DetSetVector<SiStripDigi> > const> inputPTR =
100  getProductByTag<edm::DetSetVector<SiStripDigi> >(*ep, SiStripPileInputTag_ );
101 
102  if(inputPTR ) {
103 
104  const edm::DetSetVector<SiStripDigi> *input = const_cast< edm::DetSetVector<SiStripDigi> * >(inputPTR->product());
105 
106  // Handle< edm::DetSetVector<SiStripDigi> > input;
107 
108  // if( e->getByLabel(Sistripdigi_collectionPile_.label(),SistripLabelPile_.label(),input) ) {
109 
110  OneDetectorMap LocalMap;
111 
112  //loop on all detsets (detectorIDs) inside the input collection
114  for (; DSViter!=input->end();DSViter++){
115 
116 #ifdef DEBUG
117  LogDebug("DataMixingSiStripWorker") << "Pileups: Processing DetID " << DSViter->id;
118 #endif
119 
120  // find correct local map (or new one) for this detector ID
121 
122  SiGlobalIndex::const_iterator itest;
123 
124  itest = SiHitStorage_.find(DSViter->id);
125 
126  if(itest!=SiHitStorage_.end()) { // this detID already has hits, add to existing map
127 
128  LocalMap = itest->second;
129 
130  // fill in local map with extra channels
131  LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
132  std::stable_sort(LocalMap.begin(),LocalMap.end(),DataMixingSiStripWorker::StrictWeakOrdering());
133  SiHitStorage_[DSViter->id]=LocalMap;
134 
135  }
136  else{ // fill local storage with this information, put in global collection
137 
138  LocalMap.clear();
139  LocalMap.reserve((DSViter->data).size());
140  LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
141 
142  SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
143  }
144  }
145  }
146  }
147 
148 
149 
151 
152  // collection of Digis to put in the event
153  std::vector< edm::DetSet<SiStripDigi> > vSiStripDigi;
154 
155  // loop through our collection of detectors, merging hits and putting new ones in the output
156 
157  // big loop over Detector IDs:
158 
159  for(SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin();
160  IDet != SiHitStorage_.end(); IDet++) {
161 
162  edm::DetSet<SiStripDigi> SSD(IDet->first); // Make empty collection with this detector ID
163 
164  OneDetectorMap LocalMap = IDet->second;
165 
166  //counter variables
167  int formerStrip = -1;
168  int currentStrip;
169  int ADCSum = 0;
170 
171  OneDetectorMap::const_iterator iLocalchk;
172  OneDetectorMap::const_iterator iLocal = LocalMap.begin();
173  for(;iLocal != LocalMap.end(); ++iLocal) {
174 
175  currentStrip = iLocal->strip();
176 
177  if (currentStrip == formerStrip) { // we have to add these digis together
178  ADCSum+=iLocal->adc(); // on every element...
179  }
180  else{
181  if(formerStrip!=-1){
182  if (ADCSum > 511) ADCSum = 255;
183  else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
184  SiStripDigi aHit(formerStrip, ADCSum);
185  SSD.push_back( aHit );
186  }
187  // save pointers for next iteration
188  formerStrip = currentStrip;
189  ADCSum = iLocal->adc();
190  }
191 
192  iLocalchk = iLocal;
193  if((++iLocalchk) == LocalMap.end()) { //make sure not to lose the last one
194  if (ADCSum > 511) ADCSum = 255;
195  else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
196  SSD.push_back( SiStripDigi(formerStrip, ADCSum) );
197  } // end of loop over one detector
198 
199  }
200  // stick this into the global vector of detector info
201  vSiStripDigi.push_back(SSD);
202 
203  } // end of big loop over all detector IDs
204 
205  // put the collection of digis in the event
206  LogInfo("DataMixingSiStripWorker") << "total # Merged strips: " << vSiStripDigi.size() ;
207 
208  // make new digi collection
209 
210  std::auto_ptr< edm::DetSetVector<SiStripDigi> > MySiStripDigis(new edm::DetSetVector<SiStripDigi>(vSiStripDigi) );
211 
212  // put collection
213 
214  e.put( MySiStripDigis, SiStripDigiCollectionDM_ );
215 
216  // clear local storage for this event
217  SiHitStorage_.clear();
218  }
219 
220 } //edm
#define LogDebug(id)
T getParameter(std::string const &) const
void push_back(const T &t)
Definition: DetSet.h:69
EventID const & id() const
std::vector< SiStripDigi > OneDetectorMap
void addSiStripPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
#define end
Definition: vmac.h:38
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
Container::value_type value_type
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:356
void insert(detset const &s)
Insert the given DetSet.
Definition: DetSetVector.h:234
#define begin
Definition: vmac.h:31
void addSiStripSignals(const edm::Event &e)
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:341
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:106