CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripFEDEmulatorModule.cc
Go to the documentation of this file.
1 // Original Author: Anne-Marie Magnan
2 // Created: 2010/01/21
3 // $Id: SiStripFEDEmulatorModule.cc,v 1.2 2013/03/04 07:53:45 davidlt Exp $
4 //
5 
6 #include <sstream>
7 #include <memory>
8 #include <list>
9 #include <algorithm>
10 #include <cassert>
11 #include <vector>
12 
23 
33 
37 
39 
40 //for the zero suppression algorithm(s)
43 
46 
47 using edm::LogError;
48 using edm::LogInfo;
49 using edm::LogWarning;
50 
51 namespace sistrip
52 {
53 
54  //
55  // Class declaration
56  //
57 
59  {
60  public:
61 
62  explicit FEDEmulatorModule(const edm::ParameterSet&);
64 
65  private:
66 
67  virtual void produce(edm::Event&, const edm::EventSetup&) override;
68  //virtual void endJob();
69 
70  //tag of spydata collection
73 
74  //by fedIndex or module detid
75  bool byModule_;
76 
78 
79  static const char* messageLabel_;
80 
81  std::auto_ptr<SiStripRawProcessingAlgorithms> algorithms_;
82 
83  //utilities for cabling etc...
85 
86  };
87 
88 }//~sistrip
89 
90 namespace sistrip {
91 
92  //
93  // Constructors and destructor
94  //
95  const char* FEDEmulatorModule::messageLabel_ = "SiStripFEDEmulatorModule";
96 
97 
99  spyReorderedDigisTag_(iConfig.getParameter<edm::InputTag>("SpyReorderedDigisTag")),
100  spyVirginRawDigisTag_(iConfig.getParameter<edm::InputTag>("SpyVirginRawDigisTag")),
101  byModule_(iConfig.getParameter<bool>("ByModule")),
102  algorithms_(SiStripRawProcessingFactory::create(iConfig.getParameter<edm::ParameterSet>("Algorithms")))
103  {
104 
106 
107  if (!byModule_) { //if not by module
108  //the medians will be produced by fed id/channel
109  produces<std::map<uint32_t,std::vector<uint32_t> > >("Medians");
110  produces<edm::DetSetVector<SiStripRawDigi> >("PedestalsOrdered");
111  produces<edm::DetSetVector<SiStripProcessedRawDigi> >("NoisesOrdered");
112  produces<edm::DetSetVector<SiStripRawDigi> >("PedSubtrDigisOrdered");
113  produces<edm::DetSetVector<SiStripRawDigi> >("CMSubtrDigisOrdered");
114  }
115  else { //by module
116  produces<edm::DetSetVector<SiStripRawDigi> >("ModulePedestals");
117  produces<edm::DetSetVector<SiStripProcessedRawDigi> >("ModuleNoises");
118  produces<edm::DetSetVector<SiStripRawDigi> >("PedSubtrModuleDigis");
119  produces<std::map<uint32_t,std::vector<uint32_t> > >("ModuleMedians");
120  produces<edm::DetSetVector<SiStripRawDigi> >("CMSubtrModuleDigis");
121  produces<edm::DetSetVector<SiStripDigi> >("ZSModuleDigis");
122  }//end of by module check
123 
124  }//end of FEDEmulatorModule constructor
125 
127  {
128  }
129 
130  // ------------ method called to for each event ------------
131  void
133  {
134  //update cabling and pedestals
135  const SiStripFedCabling* lCabling = utility_.getCabling( iSetup );
138 
139  //initialise the algorithms object for the zero suppression
140  algorithms_->initialize(iSetup);
141 
142  //retrieve the digis
144  try { //to get the digis from the event
145  if (!byModule_) {
146  iEvent.getByLabel(spyReorderedDigisTag_, lDigisHandle);
147  }
148  else { //digis supplied by module
149  iEvent.getByLabel(spyVirginRawDigisTag_, lDigisHandle);
150  }//end of by module check
151  } catch (const cms::Exception& e) {
152  std::cout << e.what() ;
153  return;
154  } //end of get digis try
155 
156  const edm::DetSetVector<SiStripRawDigi> * lInputDigis = lDigisHandle.product();
157 
158  unsigned int lNDigis = lInputDigis->size();
159 
160  //define output containers
161  //reserve space, will push_back elements
162  std::vector<edm::DetSetVector<SiStripRawDigi>::detset > pedsData;
163  pedsData.reserve(lNDigis);
164  std::vector<edm::DetSetVector<SiStripProcessedRawDigi>::detset > noiseData;
165  noiseData.reserve(lNDigis);
166  std::vector<edm::DetSetVector<SiStripRawDigi>::detset > pedSubtrData;
167  pedSubtrData.reserve(lNDigis);
168  std::vector<edm::DetSetVector<SiStripRawDigi>::detset > cmSubtrData;
169  cmSubtrData.reserve(lNDigis);
170  //zero suppressed contained - no fixed size (could be empty) so no need to reserve elements.
171  std::vector< edm::DetSet<SiStripDigi> > zsData;
172 
173  //this is a map: no reserve/resize
174  std::map<uint32_t,std::vector<uint32_t> > medsData;
175 
176  edm::DetSetVector<SiStripRawDigi>::const_iterator inputChannel = lInputDigis->begin();
177 
178  for ( ; inputChannel!=lInputDigis->end(); ++inputChannel){//loop on input channels
179  uint32_t lDetId = inputChannel->detId(); //either fedIndex or detId
180 
181  pedsData.push_back( edm::DetSetVector<SiStripRawDigi>::detset(lDetId) );
182  noiseData.push_back( edm::DetSetVector<SiStripProcessedRawDigi>::detset(lDetId) );
183  pedSubtrData.push_back(edm::DetSetVector<SiStripRawDigi>::detset(lDetId) );
184  cmSubtrData.push_back( edm::DetSetVector<SiStripRawDigi>::detset(lDetId) );
185 
186  unsigned int lNStrips = inputChannel->size();
187 
188  //define output digi containers
189  std::vector<SiStripRawDigi>& pedsDetSetData = pedsData.back().data;
190  pedsDetSetData.reserve(lNStrips);
191  std::vector<SiStripProcessedRawDigi>& noiseDetSetData = noiseData.back().data;
192  noiseDetSetData.reserve(lNStrips);
193  std::vector<SiStripRawDigi>& pedSubtrDetSetData = pedSubtrData.back().data;
194  pedSubtrDetSetData.reserve(lNStrips);
195  std::vector<SiStripRawDigi>& cmSubtrDetSetData = cmSubtrData.back().data;
196  cmSubtrDetSetData.reserve(lNStrips);
197  //zero suppressed - slightly different procedure as not fixed size
198  edm::DetSet<SiStripDigi> zsDetSetData(lDetId);
199 
200  //determine the number of APV pairs in the channel
201  uint32_t lNPairs = static_cast<uint32_t>(lNStrips*1./sistrip::STRIPS_PER_FEDCH);
202  uint32_t lPair = 0;
203 
204  std::vector<uint32_t> medsDetSetData;
205  medsDetSetData.reserve(lNPairs*2); //2*number of pairs per module. If not by module, lNPairs = 1...
206 
207  if (!byModule_) { //the input is not stored by module
208  //need to retrieve the proper detId from cabling
209  uint16_t lFedId = 0;
210  uint16_t lFedChannel = 0;
211  sistrip::SpyUtilities::fedIndex(lDetId, lFedId, lFedChannel);
212 
213  const FedChannelConnection & lConnection = lCabling->connection(lFedId,lFedChannel);
214  lDetId = lConnection.detId();
215  lNPairs = lConnection.nApvPairs();
216  lPair = lConnection.apvPairNumber();
217  }//end of by module check
218 
219  fedEmulator_.initialiseModule(lDetId,lNPairs,lPair);
220 
221  //get the pedestal values
222  //stored by module in the database
223  fedEmulator_.retrievePedestals(lPedsHandle);
224  fedEmulator_.retrieveNoises(lNoiseHandle);
225 
226  //last option: fill medians from these ped subtr data
227  //if want something else, need to call a method to fill
228  //the data member medians_ of the class fedEmulator.
229  fedEmulator_.subtractPedestals(inputChannel,
230  pedsDetSetData,
231  noiseDetSetData,
232  pedSubtrDetSetData,
233  medsDetSetData,
234  true);
235 
236  fedEmulator_.subtractCM(pedSubtrDetSetData,cmSubtrDetSetData);
237 
238  //fill the median map
239  medsData[inputChannel->detId()] = medsDetSetData;
240 
241  //zero suppress the digis
242  fedEmulator_.zeroSuppress(cmSubtrDetSetData, zsDetSetData, algorithms_);
243  if (zsDetSetData.size()) zsData.push_back( zsDetSetData );
244 
245  }//loop on input channels
246 
247 
248  std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > lPeds(new edm::DetSetVector<SiStripRawDigi>(pedsData,true));
249  std::auto_ptr<edm::DetSetVector<SiStripProcessedRawDigi> > lNoises(new edm::DetSetVector<SiStripProcessedRawDigi>(noiseData,true));
250 
251  std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > lOutputPedSubtr(new edm::DetSetVector<SiStripRawDigi>(pedSubtrData,true));
252 
253  std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > lOutputCMSubtr(new edm::DetSetVector<SiStripRawDigi>(cmSubtrData,true));
254 
255  std::auto_ptr<std::map<uint32_t,std::vector<uint32_t> > > lMedians(new std::map<uint32_t,std::vector<uint32_t> >(medsData));
256 
257  //zero suppressed digis
258  std::auto_ptr< edm::DetSetVector<SiStripDigi> > lOutputZS(new edm::DetSetVector<SiStripDigi>(zsData));
259 
260  if (!byModule_) {
261  iEvent.put(lMedians,"Medians");
262  iEvent.put(lPeds,"PedestalsOrdered");
263  iEvent.put(lNoises,"NoisesOrdered");
264  iEvent.put(lOutputPedSubtr,"PedSubtrDigisOrdered");
265  iEvent.put(lOutputCMSubtr,"CMSubtrDigisOrdered");
266  }
267  else {
268  iEvent.put(lPeds,"ModulePedestals");
269  iEvent.put(lNoises,"ModuleNoises");
270  iEvent.put(lOutputPedSubtr,"PedSubtrModuleDigis");
271  iEvent.put(lMedians,"ModuleMedians");
272  iEvent.put(lOutputCMSubtr,"CMSubtrModuleDigis");
273  iEvent.put(lOutputZS,"ZSModuleDigis");
274  }
275 
276  }//produce method
277 }//namespace sistrip
278 
279 //
280 // Define as a plug-in
281 //
282 
void zeroSuppress(const std::vector< SiStripRawDigi > &cmSubtrDetSetData, edm::DetSet< SiStripDigi > &zsDetSetData, const std::auto_ptr< SiStripRawProcessingAlgorithms > &algorithms)
virtual char const * what() const
Definition: Exception.cc:141
static void fedIndex(uint32_t aFedIndex, uint16_t &aFedId, uint16_t &aFedChannel)
void subtractPedestals(const edm::DetSetVector< SiStripRawDigi >::const_iterator &inputChannel, std::vector< SiStripRawDigi > &pedsDetSetData, std::vector< SiStripProcessedRawDigi > &noiseDetSetData, std::vector< SiStripRawDigi > &pedSubtrDetSetData, std::vector< uint32_t > &medsDetSetData, const bool fillApvsForCM)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::ESHandle< SiStripNoises > getNoiseHandle(const edm::EventSetup &eventSetup)
uint16_t apvPairNumber() const
std::auto_ptr< SiStripRawProcessingAlgorithms > algorithms_
object for zero-suppression
virtual void produce(edm::Event &, const edm::EventSetup &) override
edm::ESHandle< SiStripPedestals > getPedestalHandle(const edm::EventSetup &eventSetup)
const FedChannelConnection & connection(uint16_t fed_id, uint16_t fed_ch) const
void retrieveNoises(const edm::ESHandle< SiStripNoises > &aHandle)
dictionary map
Definition: Association.py:205
size_type size() const
Definition: DetSet.h:64
int iEvent
Definition: GenABIO.cc:243
const uint32_t & detId() const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
Class containning control, module, detector and connection information, at the level of a FED channel...
void initialiseModule(const uint32_t aDetId, const uint32_t aNPairs, const uint32_t aPair)
void subtractCM(const std::vector< SiStripRawDigi > &pedSubtrDetSetData, std::vector< SiStripRawDigi > &cmSubtrDetSetData)
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
size_type size() const
Return the number of contained DetSets.
Definition: DetSetVector.h:278
static const uint16_t STRIPS_PER_FEDCH
void initialise(const bool byModule)
Constants and enumerated types for FED/FEC systems.
const SiStripFedCabling * getCabling(const edm::EventSetup &)
Updates the cabling object from the DB.
const uint16_t & nApvPairs() const
T const * product() const
Definition: Handle.h:74
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
tuple cout
Definition: gather_cfg.py:121
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:341
void retrievePedestals(const edm::ESHandle< SiStripPedestals > &aHandle)
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:106
FEDEmulatorModule(const edm::ParameterSet &)
SurfaceDeformation * create(int type, const std::vector< double > &params)
sistrip::FEDEmulatorModule SiStripFEDEmulatorModule