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 
81  //utilities for cabling etc...
83  };
84 
85 } // namespace sistrip
86 
87 namespace sistrip {
88 
89  //
90  // Constructors and destructor
91  //
92  const char* FEDEmulatorModule::messageLabel_ = "SiStripFEDEmulatorModule";
93 
95  : spyReorderedDigisTag_(iConfig.getParameter<edm::InputTag>("SpyReorderedDigisTag")),
96  spyVirginRawDigisTag_(iConfig.getParameter<edm::InputTag>("SpyVirginRawDigisTag")),
97  byModule_(iConfig.getParameter<bool>("ByModule")),
98  algorithms_(SiStripRawProcessingFactory::create(iConfig.getParameter<edm::ParameterSet>("Algorithms"))) {
99  spyReorderedDigisToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(spyReorderedDigisTag_);
100  spyVirginRawDigisToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(spyVirginRawDigisTag_);
101 
103 
104  if (!byModule_) { //if not by module
105  //the medians will be produced by fed id/channel
106  produces<std::map<uint32_t, std::vector<uint32_t> > >("Medians");
107  produces<edm::DetSetVector<SiStripRawDigi> >("PedestalsOrdered");
108  produces<edm::DetSetVector<SiStripProcessedRawDigi> >("NoisesOrdered");
109  produces<edm::DetSetVector<SiStripRawDigi> >("PedSubtrDigisOrdered");
110  produces<edm::DetSetVector<SiStripRawDigi> >("CMSubtrDigisOrdered");
111  } else { //by module
112  produces<edm::DetSetVector<SiStripRawDigi> >("ModulePedestals");
113  produces<edm::DetSetVector<SiStripProcessedRawDigi> >("ModuleNoises");
114  produces<edm::DetSetVector<SiStripRawDigi> >("PedSubtrModuleDigis");
115  produces<std::map<uint32_t, std::vector<uint32_t> > >("ModuleMedians");
116  produces<edm::DetSetVector<SiStripRawDigi> >("CMSubtrModuleDigis");
117  produces<edm::DetSetVector<SiStripDigi> >("ZSModuleDigis");
118  } //end of by module check
119 
120  } //end of FEDEmulatorModule constructor
121 
123 
124  // ------------ method called to for each event ------------
126  //update cabling and pedestals
127  const SiStripFedCabling* lCabling = utility_.getCabling(iSetup);
130 
131  //initialise the algorithms object for the zero suppression
132  algorithms_->initialize(iSetup);
133 
134  //retrieve the digis
136  try { //to get the digis from the event
137  if (!byModule_) {
138  iEvent.getByToken(spyReorderedDigisToken_, lDigisHandle);
139  } else { //digis supplied by module
140  iEvent.getByToken(spyVirginRawDigisToken_, lDigisHandle);
141  } //end of by module check
142  } catch (const cms::Exception& e) {
143  std::cout << e.what();
144  return;
145  } //end of get digis try
146 
147  const edm::DetSetVector<SiStripRawDigi>* lInputDigis = lDigisHandle.product();
148 
149  unsigned int lNDigis = lInputDigis->size();
150 
151  //define output containers
152  //reserve space, will push_back elements
153  std::vector<edm::DetSetVector<SiStripRawDigi>::detset> pedsData;
154  pedsData.reserve(lNDigis);
155  std::vector<edm::DetSetVector<SiStripProcessedRawDigi>::detset> noiseData;
156  noiseData.reserve(lNDigis);
157  std::vector<edm::DetSetVector<SiStripRawDigi>::detset> pedSubtrData;
158  pedSubtrData.reserve(lNDigis);
159  std::vector<edm::DetSetVector<SiStripRawDigi>::detset> cmSubtrData;
160  cmSubtrData.reserve(lNDigis);
161  //zero suppressed contained - no fixed size (could be empty) so no need to reserve elements.
162  std::vector<edm::DetSet<SiStripDigi> > zsData;
163 
164  //this is a map: no reserve/resize
165  std::map<uint32_t, std::vector<uint32_t> > medsData;
166 
167  edm::DetSetVector<SiStripRawDigi>::const_iterator inputChannel = lInputDigis->begin();
168 
169  for (; inputChannel != lInputDigis->end(); ++inputChannel) { //loop on input channels
170  uint32_t lDetId = inputChannel->detId(); //either fedIndex or detId
171 
172  pedsData.push_back(edm::DetSetVector<SiStripRawDigi>::detset(lDetId));
173  noiseData.push_back(edm::DetSetVector<SiStripProcessedRawDigi>::detset(lDetId));
174  pedSubtrData.push_back(edm::DetSetVector<SiStripRawDigi>::detset(lDetId));
175  cmSubtrData.push_back(edm::DetSetVector<SiStripRawDigi>::detset(lDetId));
176 
177  unsigned int lNStrips = inputChannel->size();
178 
179  //define output digi containers
180  std::vector<SiStripRawDigi>& pedsDetSetData = pedsData.back().data;
181  pedsDetSetData.reserve(lNStrips);
182  std::vector<SiStripProcessedRawDigi>& noiseDetSetData = noiseData.back().data;
183  noiseDetSetData.reserve(lNStrips);
184  std::vector<SiStripRawDigi>& pedSubtrDetSetData = pedSubtrData.back().data;
185  pedSubtrDetSetData.reserve(lNStrips);
186  std::vector<SiStripRawDigi>& cmSubtrDetSetData = cmSubtrData.back().data;
187  cmSubtrDetSetData.reserve(lNStrips);
188  //zero suppressed - slightly different procedure as not fixed size
189  edm::DetSet<SiStripDigi> zsDetSetData(lDetId);
190 
191  //determine the number of APV pairs in the channel
192  uint32_t lNPairs = static_cast<uint32_t>(lNStrips * 1. / sistrip::STRIPS_PER_FEDCH);
193  uint32_t lPair = 0;
194 
195  std::vector<uint32_t> medsDetSetData;
196  medsDetSetData.reserve(lNPairs * 2); //2*number of pairs per module. If not by module, lNPairs = 1...
197 
198  if (!byModule_) { //the input is not stored by module
199  //need to retrieve the proper detId from cabling
200  uint16_t lFedId = 0;
201  uint16_t lFedChannel = 0;
202  sistrip::SpyUtilities::fedIndex(lDetId, lFedId, lFedChannel);
203 
204  const FedChannelConnection& lConnection = lCabling->fedConnection(lFedId, lFedChannel);
205  lDetId = lConnection.detId();
206  lNPairs = lConnection.nApvPairs();
207  lPair = lConnection.apvPairNumber();
208  } //end of by module check
209 
210  fedEmulator_.initialiseModule(lDetId, lNPairs, lPair);
211 
212  //get the pedestal values
213  //stored by module in the database
214  fedEmulator_.retrievePedestals(lPedsHandle);
215  fedEmulator_.retrieveNoises(lNoiseHandle);
216 
217  //last option: fill medians from these ped subtr data
218  //if want something else, need to call a method to fill
219  //the data member medians_ of the class fedEmulator.
221  inputChannel, pedsDetSetData, noiseDetSetData, pedSubtrDetSetData, medsDetSetData, true);
222 
223  fedEmulator_.subtractCM(pedSubtrDetSetData, cmSubtrDetSetData);
224 
225  //fill the median map
226  medsData[inputChannel->detId()] = medsDetSetData;
227 
228  //zero suppress the digis
229  fedEmulator_.zeroSuppress(cmSubtrDetSetData, zsDetSetData, algorithms_);
230  if (!zsDetSetData.empty())
231  zsData.push_back(zsDetSetData);
232 
233  } //loop on input channels
234 
235  std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > lPeds(new edm::DetSetVector<SiStripRawDigi>(pedsData, true));
236  std::unique_ptr<edm::DetSetVector<SiStripProcessedRawDigi> > lNoises(
237  new edm::DetSetVector<SiStripProcessedRawDigi>(noiseData, true));
238 
239  std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > lOutputPedSubtr(
240  new edm::DetSetVector<SiStripRawDigi>(pedSubtrData, true));
241 
242  std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > lOutputCMSubtr(
243  new edm::DetSetVector<SiStripRawDigi>(cmSubtrData, true));
244 
245  std::unique_ptr<std::map<uint32_t, std::vector<uint32_t> > > lMedians(
246  new std::map<uint32_t, std::vector<uint32_t> >(medsData));
247 
248  //zero suppressed digis
249  std::unique_ptr<edm::DetSetVector<SiStripDigi> > lOutputZS(new edm::DetSetVector<SiStripDigi>(zsData));
250 
251  if (!byModule_) {
252  iEvent.put(std::move(lMedians), "Medians");
253  iEvent.put(std::move(lPeds), "PedestalsOrdered");
254  iEvent.put(std::move(lNoises), "NoisesOrdered");
255  iEvent.put(std::move(lOutputPedSubtr), "PedSubtrDigisOrdered");
256  iEvent.put(std::move(lOutputCMSubtr), "CMSubtrDigisOrdered");
257  } else {
258  iEvent.put(std::move(lPeds), "ModulePedestals");
259  iEvent.put(std::move(lNoises), "ModuleNoises");
260  iEvent.put(std::move(lOutputPedSubtr), "PedSubtrModuleDigis");
261  iEvent.put(std::move(lMedians), "ModuleMedians");
262  iEvent.put(std::move(lOutputCMSubtr), "CMSubtrModuleDigis");
263  iEvent.put(std::move(lOutputZS), "ZSModuleDigis");
264  }
265 
266  } //produce method
267 } //namespace sistrip
268 
269 //
270 // Define as a plug-in
271 //
272 
FedChannelConnection::nApvPairs
const uint16_t & nApvPairs() const
Definition: FedChannelConnection.h:214
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:372
MessageLogger.h
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
ESHandle.h
edm::DetSetVector::end
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
edm::DetSet
Definition: DetSet.h:23
SiStripRawProcessingFactory
Definition: SiStripRawProcessingFactory.h:14
edm::EDGetTokenT
Definition: EDGetToken.h:33
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
edm::LogInfo
Definition: MessageLogger.h:254
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::SpyUtilities::getNoiseHandle
edm::ESHandle< SiStripNoises > getNoiseHandle(const edm::EventSetup &eventSetup)
Definition: SiStripSpyUtilities.cc:98
SiStripNoises.h
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
ConstantsForHardwareSystems.h
Constants and enumerated types for FED/FEC systems.
sistrip::SpyUtilities::getPedestalHandle
edm::ESHandle< SiStripPedestals > getPedestalHandle(const edm::EventSetup &eventSetup)
Definition: SiStripSpyUtilities.cc:87
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
sistrip::FEDEmulator::initialiseModule
void initialiseModule(const uint32_t aDetId, const uint32_t aNPairs, const uint32_t aPair)
Definition: SiStripFEDEmulator.cc:37
SiStripSpyUtilities.h
edm::DetSet::empty
bool empty() const
Definition: DetSet.h:62
MakerMacros.h
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::SpyUtilities
Definition: SiStripSpyUtilities.h:24
sistrip::FEDEmulatorModule::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: SiStripFEDEmulatorModule.cc:125
SiStripDigi.h
edm::ESHandle< SiStripPedestals >
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:122
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
EDGetToken.h
edm::LogWarning
Definition: MessageLogger.h:141
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:212
sistrip::FEDEmulatorModule::utility_
SpyUtilities utility_
Definition: SiStripFEDEmulatorModule.cc:82
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
SiStripFedKey.h
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
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::FEDEmulator::retrieveNoises
void retrieveNoises(const edm::ESHandle< SiStripNoises > &aHandle)
Definition: SiStripFEDEmulator.cc:72
iEvent
int iEvent
Definition: GenABIO.cc:224
FEDRawDataCollection.h
SiStripRawProcessingAlgorithms.h
sistrip::FEDEmulatorModule::FEDEmulatorModule
FEDEmulatorModule(const edm::ParameterSet &)
Definition: SiStripFEDEmulatorModule.cc:94
edm::EventSetup
Definition: EventSetup.h:57
DetSetVector.h
sistrip::FEDEmulatorModule::messageLabel_
static const char * messageLabel_
Definition: SiStripFEDEmulatorModule.cc:77
sistrip::FEDEmulatorModule::spyVirginRawDigisTag_
edm::InputTag spyVirginRawDigisTag_
Definition: SiStripFEDEmulatorModule.cc:68
InputTag.h
sistrip::SpyUtilities::getCabling
const SiStripFedCabling * getCabling(const edm::EventSetup &)
Updates the cabling object from the DB.
Definition: SiStripSpyUtilities.cc:37
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
SiStripFEDEmulatorModule
sistrip::FEDEmulatorModule SiStripFEDEmulatorModule
Definition: SiStripFEDEmulatorModule.cc:274
SiStripPedestals.h
EventSetup.h
edm::EDProducer
Definition: EDProducer.h:36
Exception.h
FedChannelConnection::apvPairNumber
uint16_t apvPairNumber() const
Definition: FedChannelConnection.cc:125
cms::Exception
Definition: Exception.h:70
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ParameterSet.h
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
edm::Event
Definition: Event.h:73
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
sistrip::SpyUtilities::fedIndex
static void fedIndex(uint32_t aFedIndex, uint16_t &aFedId, uint16_t &aFedChannel)
Definition: SiStripSpyUtilities.cc:398