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