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() { }
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  // declare the products to produce
38 
39  SistripLabelSig_ = ps.getParameter<edm::InputTag>("SistripLabelSig");
40  SiStripPileInputTag_ = ps.getParameter<edm::InputTag>("SiStripPileInputTag");
41 
42  SiStripDigiCollectionDM_ = ps.getParameter<std::string>("SiStripDigiCollectionDM");
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 
60 
61  if( e.getByLabel(SistripLabelSig_,input) ) {
62  OneDetectorMap LocalMap;
63 
64  //loop on all detsets (detectorIDs) inside the input collection
66  for (; DSViter!=input->end();DSViter++){
67 
68 #ifdef DEBUG
69  LogDebug("DataMixingSiStripWorker") << "Processing DetID " << DSViter->id;
70 #endif
71 
72  LocalMap.clear();
73  LocalMap.reserve((DSViter->data).size());
74  LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
75 
76  SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
77  }
78 
79  }
80  } // end of addSiStripSignals
81 
82 
83 
84  void DataMixingSiStripWorker::addSiStripPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr,
85  ModuleCallingContext const* mcc) {
86  LogDebug("DataMixingSiStripWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
87 
88  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
89 
90  boost::shared_ptr<Wrapper<edm::DetSetVector<SiStripDigi> > const> inputPTR =
91  getProductByTag<edm::DetSetVector<SiStripDigi> >(*ep, SiStripPileInputTag_, mcc);
92 
93  if(inputPTR ) {
94 
95  const edm::DetSetVector<SiStripDigi> *input = const_cast< edm::DetSetVector<SiStripDigi> * >(inputPTR->product());
96 
97  // Handle< edm::DetSetVector<SiStripDigi> > input;
98 
99  // if( e->getByLabel(Sistripdigi_collectionPile_.label(),SistripLabelPile_.label(),input) ) {
100 
101  OneDetectorMap LocalMap;
102 
103  //loop on all detsets (detectorIDs) inside the input collection
105  for (; DSViter!=input->end();DSViter++){
106 
107 #ifdef DEBUG
108  LogDebug("DataMixingSiStripWorker") << "Pileups: Processing DetID " << DSViter->id;
109 #endif
110 
111  // find correct local map (or new one) for this detector ID
112 
113  SiGlobalIndex::const_iterator itest;
114 
115  itest = SiHitStorage_.find(DSViter->id);
116 
117  if(itest!=SiHitStorage_.end()) { // this detID already has hits, add to existing map
118 
119  LocalMap = itest->second;
120 
121  // fill in local map with extra channels
122  LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
123  std::stable_sort(LocalMap.begin(),LocalMap.end(),DataMixingSiStripWorker::StrictWeakOrdering());
124  SiHitStorage_[DSViter->id]=LocalMap;
125 
126  }
127  else{ // fill local storage with this information, put in global collection
128 
129  LocalMap.clear();
130  LocalMap.reserve((DSViter->data).size());
131  LocalMap.insert(LocalMap.end(),(DSViter->data).begin(),(DSViter->data).end());
132 
133  SiHitStorage_.insert( SiGlobalIndex::value_type( DSViter->id, LocalMap ) );
134  }
135  }
136  }
137  }
138 
139 
140 
142 
143  // collection of Digis to put in the event
144  std::vector< edm::DetSet<SiStripDigi> > vSiStripDigi;
145 
146  // loop through our collection of detectors, merging hits and putting new ones in the output
147 
148  // big loop over Detector IDs:
149 
150  for(SiGlobalIndex::const_iterator IDet = SiHitStorage_.begin();
151  IDet != SiHitStorage_.end(); IDet++) {
152 
153  edm::DetSet<SiStripDigi> SSD(IDet->first); // Make empty collection with this detector ID
154 
155  OneDetectorMap LocalMap = IDet->second;
156 
157  //counter variables
158  int formerStrip = -1;
159  int currentStrip;
160  int ADCSum = 0;
161 
162  OneDetectorMap::const_iterator iLocalchk;
163  OneDetectorMap::const_iterator iLocal = LocalMap.begin();
164  for(;iLocal != LocalMap.end(); ++iLocal) {
165 
166  currentStrip = iLocal->strip();
167 
168  if (currentStrip == formerStrip) { // we have to add these digis together
169  ADCSum+=iLocal->adc(); // on every element...
170  }
171  else{
172  if(formerStrip!=-1){
173  if (ADCSum > 511) ADCSum = 255;
174  else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
175  SiStripDigi aHit(formerStrip, ADCSum);
176  SSD.push_back( aHit );
177  }
178  // save pointers for next iteration
179  formerStrip = currentStrip;
180  ADCSum = iLocal->adc();
181  }
182 
183  iLocalchk = iLocal;
184  if((++iLocalchk) == LocalMap.end()) { //make sure not to lose the last one
185  if (ADCSum > 511) ADCSum = 255;
186  else if (ADCSum > 253 && ADCSum < 512) ADCSum = 254;
187  SSD.push_back( SiStripDigi(formerStrip, ADCSum) );
188  } // end of loop over one detector
189 
190  }
191  // stick this into the global vector of detector info
192  vSiStripDigi.push_back(SSD);
193 
194  } // end of big loop over all detector IDs
195 
196  // put the collection of digis in the event
197  LogInfo("DataMixingSiStripWorker") << "total # Merged strips: " << vSiStripDigi.size() ;
198 
199  // make new digi collection
200 
201  std::auto_ptr< edm::DetSetVector<SiStripDigi> > MySiStripDigis(new edm::DetSetVector<SiStripDigi>(vSiStripDigi) );
202 
203  // put collection
204 
205  e.put( MySiStripDigis, SiStripDigiCollectionDM_ );
206 
207  // clear local storage for this event
208  SiHitStorage_.clear();
209  }
210 
211 } //edm
#define LogDebug(id)
T getParameter(std::string const &) const
void push_back(const T &t)
Definition: DetSet.h:68
EventID const & id() const
std::vector< SiStripDigi > OneDetectorMap
static std::string const input
Definition: EdmProvDump.cc:44
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
#define end
Definition: vmac.h:37
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:390
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:356
void addSiStripPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
void insert(detset const &s)
Insert the given DetSet.
Definition: DetSetVector.h:234
#define begin
Definition: vmac.h:30
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