CMS 3D CMS Logo

SiStripFEDEmulatorModule.cc
Go to the documentation of this file.
1 // Original Author: Anne-Marie Magnan
2 // Created: 2010/01/21
3 //
4 
5 #include <sstream>
6 #include <memory>
7 #include <list>
8 #include <algorithm>
9 #include <cassert>
10 #include <vector>
11 
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  // Class declaration
55  //
56 
58  public:
59  explicit FEDEmulatorModule(const edm::ParameterSet&);
60  ~FEDEmulatorModule() override;
61 
62  private:
63  void produce(edm::Event&, const edm::EventSetup&) override;
64  //virtual void endJob();
65 
66  //tag of spydata collection
71 
72  //by fedIndex or module detid
73  bool byModule_;
74 
76 
77  static const char* messageLabel_;
78 
79  std::unique_ptr<SiStripRawProcessingAlgorithms> algorithms_;
80 
87 
91  void updateFedCabling(const SiStripFedCablingRcd& rcd);
92  void updatePedestals(const SiStripPedestalsRcd& rcd);
93  void updateNoises(const SiStripNoisesRcd& rcd);
94  };
95 
96 } // namespace sistrip
97 
98 namespace sistrip {
99 
100  //
101  // Constructors and destructor
102  //
103  const char* FEDEmulatorModule::messageLabel_ = "SiStripFEDEmulatorModule";
104 
106  : spyReorderedDigisTag_(iConfig.getParameter<edm::InputTag>("SpyReorderedDigisTag")),
107  spyVirginRawDigisTag_(iConfig.getParameter<edm::InputTag>("SpyVirginRawDigisTag")),
108  byModule_(iConfig.getParameter<bool>("ByModule")),
109  algorithms_(SiStripRawProcessingFactory::create(iConfig.getParameter<edm::ParameterSet>("Algorithms"),
110  consumesCollector())),
111  fedCablingToken_(esConsumes<>()),
112  pedestalsToken_(esConsumes<>()),
113  noisesToken_(esConsumes<>()),
114  cablingWatcher_(this, &sistrip::FEDEmulatorModule::updateFedCabling),
115  pedestalsWatcher_(this, &sistrip::FEDEmulatorModule::updatePedestals),
116  noisesWatcher_(this, &sistrip::FEDEmulatorModule::updateNoises) {
117  spyReorderedDigisToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(spyReorderedDigisTag_);
118  spyVirginRawDigisToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(spyVirginRawDigisTag_);
119 
121 
122  if (!byModule_) { //if not by module
123  //the medians will be produced by fed id/channel
124  produces<std::map<uint32_t, std::vector<uint32_t> > >("Medians");
125  produces<edm::DetSetVector<SiStripRawDigi> >("PedestalsOrdered");
126  produces<edm::DetSetVector<SiStripProcessedRawDigi> >("NoisesOrdered");
127  produces<edm::DetSetVector<SiStripRawDigi> >("PedSubtrDigisOrdered");
128  produces<edm::DetSetVector<SiStripRawDigi> >("CMSubtrDigisOrdered");
129  } else { //by module
130  produces<edm::DetSetVector<SiStripRawDigi> >("ModulePedestals");
131  produces<edm::DetSetVector<SiStripProcessedRawDigi> >("ModuleNoises");
132  produces<edm::DetSetVector<SiStripRawDigi> >("PedSubtrModuleDigis");
133  produces<std::map<uint32_t, std::vector<uint32_t> > >("ModuleMedians");
134  produces<edm::DetSetVector<SiStripRawDigi> >("CMSubtrModuleDigis");
135  produces<edm::DetSetVector<SiStripDigi> >("ZSModuleDigis");
136  } //end of by module check
137 
138  } //end of FEDEmulatorModule constructor
139 
141 
144  }
147 
148  // ------------ method called to for each event ------------
150  cablingWatcher_.check(iSetup);
151  pedestalsWatcher_.check(iSetup);
152  noisesWatcher_.check(iSetup);
153 
154  //initialise the algorithms object for the zero suppression
155  algorithms_->initialize(iSetup);
156 
157  //retrieve the digis
159  try { //to get the digis from the event
160  if (!byModule_) {
161  iEvent.getByToken(spyReorderedDigisToken_, lDigisHandle);
162  } else { //digis supplied by module
163  iEvent.getByToken(spyVirginRawDigisToken_, lDigisHandle);
164  } //end of by module check
165  } catch (const cms::Exception& e) {
166  std::cout << e.what();
167  return;
168  } //end of get digis try
169 
170  const edm::DetSetVector<SiStripRawDigi>* lInputDigis = lDigisHandle.product();
171 
172  unsigned int lNDigis = lInputDigis->size();
173 
174  //define output containers
175  //reserve space, will push_back elements
176  std::vector<edm::DetSetVector<SiStripRawDigi>::detset> pedsData;
177  pedsData.reserve(lNDigis);
178  std::vector<edm::DetSetVector<SiStripProcessedRawDigi>::detset> noiseData;
179  noiseData.reserve(lNDigis);
180  std::vector<edm::DetSetVector<SiStripRawDigi>::detset> pedSubtrData;
181  pedSubtrData.reserve(lNDigis);
182  std::vector<edm::DetSetVector<SiStripRawDigi>::detset> cmSubtrData;
183  cmSubtrData.reserve(lNDigis);
184  //zero suppressed contained - no fixed size (could be empty) so no need to reserve elements.
185  std::vector<edm::DetSet<SiStripDigi> > zsData;
186 
187  //this is a map: no reserve/resize
188  std::map<uint32_t, std::vector<uint32_t> > medsData;
189 
190  edm::DetSetVector<SiStripRawDigi>::const_iterator inputChannel = lInputDigis->begin();
191 
192  for (; inputChannel != lInputDigis->end(); ++inputChannel) { //loop on input channels
193  uint32_t lDetId = inputChannel->detId(); //either fedIndex or detId
194 
195  pedsData.push_back(edm::DetSetVector<SiStripRawDigi>::detset(lDetId));
196  noiseData.push_back(edm::DetSetVector<SiStripProcessedRawDigi>::detset(lDetId));
197  pedSubtrData.push_back(edm::DetSetVector<SiStripRawDigi>::detset(lDetId));
198  cmSubtrData.push_back(edm::DetSetVector<SiStripRawDigi>::detset(lDetId));
199 
200  unsigned int lNStrips = inputChannel->size();
201 
202  //define output digi containers
203  std::vector<SiStripRawDigi>& pedsDetSetData = pedsData.back().data;
204  pedsDetSetData.reserve(lNStrips);
205  std::vector<SiStripProcessedRawDigi>& noiseDetSetData = noiseData.back().data;
206  noiseDetSetData.reserve(lNStrips);
207  std::vector<SiStripRawDigi>& pedSubtrDetSetData = pedSubtrData.back().data;
208  pedSubtrDetSetData.reserve(lNStrips);
209  std::vector<SiStripRawDigi>& cmSubtrDetSetData = cmSubtrData.back().data;
210  cmSubtrDetSetData.reserve(lNStrips);
211  //zero suppressed - slightly different procedure as not fixed size
212  edm::DetSet<SiStripDigi> zsDetSetData(lDetId);
213 
214  //determine the number of APV pairs in the channel
215  uint32_t lNPairs = static_cast<uint32_t>(lNStrips * 1. / sistrip::STRIPS_PER_FEDCH);
216  uint32_t lPair = 0;
217 
218  std::vector<uint32_t> medsDetSetData;
219  medsDetSetData.reserve(lNPairs * 2); //2*number of pairs per module. If not by module, lNPairs = 1...
220 
221  if (!byModule_) { //the input is not stored by module
222  //need to retrieve the proper detId from cabling
223  uint16_t lFedId = 0;
224  uint16_t lFedChannel = 0;
225  sistrip::SpyUtilities::fedIndex(lDetId, lFedId, lFedChannel);
226 
227  const FedChannelConnection& lConnection = fedCabling_->fedConnection(lFedId, lFedChannel);
228  lDetId = lConnection.detId();
229  lNPairs = lConnection.nApvPairs();
230  lPair = lConnection.apvPairNumber();
231  } //end of by module check
232 
233  fedEmulator_.initialiseModule(lDetId, lNPairs, lPair);
234 
235  //get the pedestal values
236  //stored by module in the database
237  fedEmulator_.retrievePedestals(pedestals_); // FIXME maybe move into FEDEmulator then?
239 
240  //last option: fill medians from these ped subtr data
241  //if want something else, need to call a method to fill
242  //the data member medians_ of the class fedEmulator.
244  inputChannel, pedsDetSetData, noiseDetSetData, pedSubtrDetSetData, medsDetSetData, true);
245 
246  fedEmulator_.subtractCM(pedSubtrDetSetData, cmSubtrDetSetData);
247 
248  //fill the median map
249  medsData[inputChannel->detId()] = medsDetSetData;
250 
251  //zero suppress the digis
252  fedEmulator_.zeroSuppress(cmSubtrDetSetData, zsDetSetData, algorithms_);
253  if (!zsDetSetData.empty())
254  zsData.push_back(zsDetSetData);
255 
256  } //loop on input channels
257 
258  std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > lPeds(new edm::DetSetVector<SiStripRawDigi>(pedsData, true));
259  std::unique_ptr<edm::DetSetVector<SiStripProcessedRawDigi> > lNoises(
260  new edm::DetSetVector<SiStripProcessedRawDigi>(noiseData, true));
261 
262  std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > lOutputPedSubtr(
263  new edm::DetSetVector<SiStripRawDigi>(pedSubtrData, true));
264 
265  std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > lOutputCMSubtr(
266  new edm::DetSetVector<SiStripRawDigi>(cmSubtrData, true));
267 
268  std::unique_ptr<std::map<uint32_t, std::vector<uint32_t> > > lMedians(
269  new std::map<uint32_t, std::vector<uint32_t> >(medsData));
270 
271  //zero suppressed digis
272  std::unique_ptr<edm::DetSetVector<SiStripDigi> > lOutputZS(new edm::DetSetVector<SiStripDigi>(zsData));
273 
274  if (!byModule_) {
275  iEvent.put(std::move(lMedians), "Medians");
276  iEvent.put(std::move(lPeds), "PedestalsOrdered");
277  iEvent.put(std::move(lNoises), "NoisesOrdered");
278  iEvent.put(std::move(lOutputPedSubtr), "PedSubtrDigisOrdered");
279  iEvent.put(std::move(lOutputCMSubtr), "CMSubtrDigisOrdered");
280  } else {
281  iEvent.put(std::move(lPeds), "ModulePedestals");
282  iEvent.put(std::move(lNoises), "ModuleNoises");
283  iEvent.put(std::move(lOutputPedSubtr), "PedSubtrModuleDigis");
284  iEvent.put(std::move(lMedians), "ModuleMedians");
285  iEvent.put(std::move(lOutputCMSubtr), "CMSubtrModuleDigis");
286  iEvent.put(std::move(lOutputZS), "ZSModuleDigis");
287  }
288 
289  } //produce method
290 } //namespace sistrip
291 
292 //
293 // Define as a plug-in
294 //
295 
FedChannelConnection::nApvPairs
const uint16_t & nApvPairs() const
Definition: FedChannelConnection.h:215
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
sistrip::FEDEmulatorModule::spyVirginRawDigisToken_
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > spyVirginRawDigisToken_
Definition: SiStripFEDEmulatorModule.cc:70
FEDNumbering.h
edm::DetSetVector< SiStripRawDigi >
SiStripRawProcessingFactory.h
sistrip::FEDEmulator::retrievePedestals
void retrievePedestals(const edm::ESHandle< SiStripPedestals > &aHandle)
Definition: SiStripFEDEmulator.cc:60
electrons_cff.bool
bool
Definition: electrons_cff.py:366
MessageLogger.h
sistrip::FEDEmulatorModule::pedestals_
const SiStripPedestals * pedestals_
Definition: SiStripFEDEmulatorModule.cc:85
sistrip::SpyUtilities::fedIndex
void fedIndex(uint32_t aFedIndex, uint16_t &aFedId, uint16_t &aFedChannel)
Definition: SiStripSpyUtilities.cc:300
sistrip::FEDEmulator::subtractPedestals
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)
Definition: SiStripFEDEmulator.cc:84
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EDProducer.h
edm::ESWatcher< SiStripFedCablingRcd >
edm::DetSetVector::end
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
SiStripNoises
Definition: SiStripNoises.h:25
edm::DetSet
Definition: DetSet.h:23
SiStripRawProcessingFactory
Definition: SiStripRawProcessingFactory.h:15
edm::EDGetTokenT
Definition: EDGetToken.h:33
sistrip::FEDEmulatorModule::cablingWatcher_
edm::ESWatcher< SiStripFedCablingRcd > cablingWatcher_
Definition: SiStripFEDEmulatorModule.cc:88
sistrip::FEDEmulatorModule::byModule_
bool byModule_
Definition: SiStripFEDEmulatorModule.cc:73
edm
HLT enums.
Definition: AlignableModifier.h:19
SiStripRawDigi.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
SiStripFedCabling.h
edm::DetSetVector::begin
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:314
SiStripFedCabling::fedConnection
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
Definition: SiStripFedCabling.cc:171
sistrip::FEDEmulatorModule::fedCabling_
const SiStripFedCabling * fedCabling_
Definition: SiStripFEDEmulatorModule.cc:84
sistrip::FEDEmulatorModule::noises_
const SiStripNoises * noises_
Definition: SiStripFEDEmulatorModule.cc:86
SiStripNoises.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
ConstantsForHardwareSystems.h
Constants and enumerated types for FED/FEC systems.
SiStripFedCabling
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses,...
Definition: SiStripFedCabling.h:25
FEDRawData.h
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
sistrip::FEDEmulator::initialiseModule
void initialiseModule(const uint32_t aDetId, const uint32_t aNPairs, const uint32_t aPair)
Definition: SiStripFEDEmulator.cc:37
SiStripPedestalsRcd
Definition: SiStripCondDataRecords.h:43
SiStripNoisesRcd
Definition: SiStripCondDataRecords.h:40
SiStripSpyUtilities.h
edm::DetSet::empty
bool empty() const
Definition: DetSet.h:62
sistrip::FEDEmulatorModule::noisesToken_
edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > noisesToken_
Definition: SiStripFEDEmulatorModule.cc:83
MakerMacros.h
SiStripFedCablingRcd
Definition: SiStripCondDataRecords.h:22
sistrip::FEDEmulator::subtractCM
void subtractCM(const std::vector< SiStripRawDigi > &pedSubtrDetSetData, std::vector< SiStripRawDigi > &cmSubtrDetSetData)
Definition: SiStripFEDEmulator.cc:169
SiStripFEDEmulator.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiStripProcessedRawDigi.h
sistrip::FEDEmulatorModule::spyReorderedDigisTag_
edm::InputTag spyReorderedDigisTag_
Definition: SiStripFEDEmulatorModule.cc:67
sistrip::FEDEmulatorModule
Definition: SiStripFEDEmulatorModule.cc:57
SiStripFEDBuffer.h
Service.h
sistrip::FEDEmulatorModule::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: SiStripFEDEmulatorModule.cc:149
SiStripDigi.h
sistrip::FEDEmulator::zeroSuppress
void zeroSuppress(const std::vector< SiStripRawDigi > &cmSubtrDetSetData, edm::DetSet< SiStripDigi > &zsDetSetData, const std::unique_ptr< SiStripRawProcessingAlgorithms > &algorithms)
Definition: SiStripFEDEmulator.cc:190
sistrip::FEDEmulatorModule::~FEDEmulatorModule
~FEDEmulatorModule() override
Definition: SiStripFEDEmulatorModule.cc:140
edm::DetSetVector::size
size_type size() const
Return the number of contained DetSets.
Definition: DetSetVector.h:259
sistrip::FEDEmulatorModule::spyReorderedDigisToken_
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > spyReorderedDigisToken_
Definition: SiStripFEDEmulatorModule.cc:69
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:109
EDGetToken.h
sistrip::FEDEmulator::initialise
void initialise(const bool byModule)
Definition: SiStripFEDEmulator.cc:30
FedChannelConnection
Class containning control, module, detector and connection information, at the level of a FED channel...
Definition: FedChannelConnection.h:26
FedChannelConnection::detId
const uint32_t & detId() const
Definition: FedChannelConnection.h:213
SiStripFedKey.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
ParameterSet
Definition: Functions.h:16
sistrip::FEDEmulator
Definition: SiStripFEDEmulator.h:35
edm::DetSetVector::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
sistrip::STRIPS_PER_FEDCH
static const uint16_t STRIPS_PER_FEDCH
Definition: ConstantsForHardwareSystems.h:44
sistrip::FEDEmulatorModule::updateNoises
void updateNoises(const SiStripNoisesRcd &rcd)
Definition: SiStripFEDEmulatorModule.cc:146
sistrip::FEDEmulator::retrieveNoises
void retrieveNoises(const edm::ESHandle< SiStripNoises > &aHandle)
Definition: SiStripFEDEmulator.cc:72
iEvent
int iEvent
Definition: GenABIO.cc:224
FEDRawDataCollection.h
sistrip::FEDEmulatorModule::updateFedCabling
void updateFedCabling(const SiStripFedCablingRcd &rcd)
Definition: SiStripFEDEmulatorModule.cc:142
SiStripRawProcessingAlgorithms.h
sistrip::FEDEmulatorModule::FEDEmulatorModule
FEDEmulatorModule(const edm::ParameterSet &)
Definition: SiStripFEDEmulatorModule.cc:105
edm::EventSetup
Definition: EventSetup.h:58
DetSetVector.h
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
sistrip::FEDEmulatorModule::messageLabel_
static const char * messageLabel_
Definition: SiStripFEDEmulatorModule.cc:77
sistrip::FEDEmulatorModule::spyVirginRawDigisTag_
edm::InputTag spyVirginRawDigisTag_
Definition: SiStripFEDEmulatorModule.cc:68
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd >
InputTag.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
sistrip::FEDEmulatorModule::pedestalsWatcher_
edm::ESWatcher< SiStripPedestalsRcd > pedestalsWatcher_
Definition: SiStripFEDEmulatorModule.cc:89
ESWatcher.h
SiStripFEDEmulatorModule
sistrip::FEDEmulatorModule SiStripFEDEmulatorModule
Definition: SiStripFEDEmulatorModule.cc:297
SiStripPedestals.h
EventSetup.h
edm::EDProducer
Definition: EDProducer.h:35
Exception.h
FedChannelConnection::apvPairNumber
uint16_t apvPairNumber() const
Definition: FedChannelConnection.h:230
edm::eventsetup::EventSetupRecordImplementation::get
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
Definition: EventSetupRecordImplementation.h:74
sistrip::FEDEmulatorModule::noisesWatcher_
edm::ESWatcher< SiStripNoisesRcd > noisesWatcher_
Definition: SiStripFEDEmulatorModule.cc:90
SiStripPedestals
Definition: SiStripPedestals.h:27
cms::Exception
Definition: Exception.h:70
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ParameterSet.h
sistrip
sistrip classes
Definition: EnsembleCalibrationLA.cc:10
sistrip::FEDEmulatorModule::fedCablingToken_
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > fedCablingToken_
Definition: SiStripFEDEmulatorModule.cc:81
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
sistrip::FEDEmulatorModule::pedestalsToken_
edm::ESGetToken< SiStripPedestals, SiStripPedestalsRcd > pedestalsToken_
Definition: SiStripFEDEmulatorModule.cc:82
sistrip::FEDEmulatorModule::updatePedestals
void updatePedestals(const SiStripPedestalsRcd &rcd)
Definition: SiStripFEDEmulatorModule.cc:145
sistrip::FEDEmulatorModule::algorithms_
std::unique_ptr< SiStripRawProcessingAlgorithms > algorithms_
object for zero-suppression
Definition: SiStripFEDEmulatorModule.cc:79
edm::InputTag
Definition: InputTag.h:15
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
sistrip::FEDEmulatorModule::fedEmulator_
sistrip::FEDEmulator fedEmulator_
Definition: SiStripFEDEmulatorModule.cc:75