Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:56

0001 // -*- C++ -*-
0002 //
0003 // Package:    EventFilter/OnlineMetaDataRawToDigi
0004 // Class:      OnlineMetaDataRawToDigi
0005 //
0006 /**\class OnlineMetaDataRawToDigi OnlineMetaDataRawToDigi.cc EventFilter/OnlineMetaDataRawToDigi/plugins/OnlineMetaDataRawToDigi.cc
0007 
0008  Description:  Producer to unpack event meta-data from soft-FED 1022
0009 
0010 */
0011 //
0012 // Original Author:  Remigius K Mommsen (Fermilab)
0013 //         Created:  Wed, 22 Nov 2017 18:19:56 GMT
0014 //
0015 //
0016 
0017 // system include files
0018 #include <memory>
0019 #include <iostream>
0020 
0021 // user include files
0022 #include "FWCore/Framework/interface/Frameworkfwd.h"
0023 #include "FWCore/Framework/interface/stream/EDProducer.h"
0024 
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 
0030 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0031 
0032 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0033 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0034 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0035 
0036 #include "DataFormats/OnlineMetaData/interface/CTPPSRecord.h"
0037 #include "DataFormats/OnlineMetaData/interface/DCSRecord.h"
0038 #include "DataFormats/OnlineMetaData/interface/OnlineLuminosityRecord.h"
0039 #include "DataFormats/OnlineMetaData/interface/OnlineMetaDataRaw.h"
0040 
0041 //
0042 // class declaration
0043 //
0044 
0045 class OnlineMetaDataRawToDigi : public edm::stream::EDProducer<> {
0046 public:
0047   explicit OnlineMetaDataRawToDigi(const edm::ParameterSet&);
0048   ~OnlineMetaDataRawToDigi() override;
0049 
0050   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0051 
0052 private:
0053   void produce(edm::Event&, const edm::EventSetup&) override;
0054   reco::BeamSpot getBeamSpot(const online::BeamSpot_v1&) const;
0055 
0056   edm::EDGetTokenT<FEDRawDataCollection> dataToken_;
0057 };
0058 
0059 OnlineMetaDataRawToDigi::OnlineMetaDataRawToDigi(const edm::ParameterSet& iConfig) {
0060   edm::InputTag dataLabel = iConfig.getParameter<edm::InputTag>("onlineMetaDataInputLabel");
0061   dataToken_ = consumes<FEDRawDataCollection>(dataLabel);
0062 
0063   produces<CTPPSRecord>();
0064   produces<DCSRecord>();
0065   produces<OnlineLuminosityRecord>();
0066   produces<reco::BeamSpot>();
0067 }
0068 
0069 OnlineMetaDataRawToDigi::~OnlineMetaDataRawToDigi() {}
0070 
0071 //
0072 // member functions
0073 //
0074 
0075 // ------------ method called to produce the data  ------------
0076 void OnlineMetaDataRawToDigi::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0077   using namespace edm;
0078 
0079   edm::Handle<FEDRawDataCollection> rawdata;
0080   iEvent.getByToken(dataToken_, rawdata);
0081 
0082   DCSRecord dcsRecord;
0083   CTPPSRecord ctppsRecord;
0084   OnlineLuminosityRecord onlineLuminosityRecord;
0085   reco::BeamSpot onlineBeamSpot;
0086 
0087   if (rawdata.isValid()) {
0088     const FEDRawData& onlineMetaDataRaw = rawdata->FEDData(FEDNumbering::MINMetaDataSoftFEDID);
0089     const unsigned char* payload = onlineMetaDataRaw.data() + FEDHeader::length;
0090 
0091     if (onlineMetaDataRaw.size() >= FEDHeader::length + sizeof(uint8_t)) {
0092       const uint8_t version = *(reinterpret_cast<uint8_t const*>(payload));
0093       if (version == 1 && onlineMetaDataRaw.size() >= FEDHeader::length + sizeof(online::Data_v1)) {
0094         online::Data_v1 const* onlineMetaData = reinterpret_cast<online::Data_v1 const*>(payload);
0095         dcsRecord = DCSRecord(onlineMetaData->dcs);
0096         onlineLuminosityRecord = OnlineLuminosityRecord(onlineMetaData->luminosity);
0097         onlineBeamSpot = getBeamSpot(onlineMetaData->beamSpot);
0098       } else if (version == 2 && onlineMetaDataRaw.size() >= FEDHeader::length + sizeof(online::Data_v2)) {
0099         online::Data_v2 const* onlineMetaData = reinterpret_cast<online::Data_v2 const*>(payload);
0100         ctppsRecord = CTPPSRecord(onlineMetaData->ctpps);
0101         dcsRecord = DCSRecord(onlineMetaData->dcs);
0102         onlineLuminosityRecord = OnlineLuminosityRecord(onlineMetaData->luminosity);
0103         onlineBeamSpot = getBeamSpot(onlineMetaData->beamSpot);
0104       } else if (version == 3 && onlineMetaDataRaw.size() >= FEDHeader::length + sizeof(online::Data_v3)) {
0105         online::Data_v3 const* onlineMetaData = reinterpret_cast<online::Data_v3 const*>(payload);
0106         ctppsRecord = CTPPSRecord(onlineMetaData->ctpps);
0107         dcsRecord = DCSRecord(onlineMetaData->dcs);
0108         onlineLuminosityRecord = OnlineLuminosityRecord(onlineMetaData->luminosity);
0109         onlineBeamSpot = getBeamSpot(onlineMetaData->beamSpot);
0110       }
0111     }
0112   }
0113 
0114   iEvent.put(std::make_unique<CTPPSRecord>(ctppsRecord));
0115   iEvent.put(std::make_unique<DCSRecord>(dcsRecord));
0116   iEvent.put(std::make_unique<OnlineLuminosityRecord>(onlineLuminosityRecord));
0117   iEvent.put(std::make_unique<reco::BeamSpot>(onlineBeamSpot));
0118 }
0119 
0120 reco::BeamSpot OnlineMetaDataRawToDigi::getBeamSpot(const online::BeamSpot_v1& beamSpot) const {
0121   reco::BeamSpot::Point point(beamSpot.x, beamSpot.y, beamSpot.z);
0122 
0123   reco::BeamSpot::CovarianceMatrix matrix;
0124   matrix(0, 0) = beamSpot.errX * beamSpot.errX;
0125   matrix(1, 1) = beamSpot.errY * beamSpot.errY;
0126   matrix(2, 2) = beamSpot.errZ * beamSpot.errZ;
0127   matrix(3, 3) = beamSpot.errSigmaZ * beamSpot.errSigmaZ;
0128   matrix(4, 4) = beamSpot.errDxdz * beamSpot.errDxdz;
0129   matrix(5, 5) = beamSpot.errDydz * beamSpot.errDydz;
0130   matrix(6, 6) = beamSpot.errWidthX * beamSpot.errWidthX;
0131   // Note: errWidthY is not part of the CovarianceMatrix
0132 
0133   reco::BeamSpot bs(
0134       point, beamSpot.sigmaZ, beamSpot.dxdz, beamSpot.dydz, beamSpot.widthX, matrix, reco::BeamSpot::BeamType::LHC);
0135 
0136   bs.setBeamWidthY(beamSpot.widthY);
0137 
0138   return bs;
0139 }
0140 
0141 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0142 void OnlineMetaDataRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0143   edm::ParameterSetDescription desc;
0144   desc.add<edm::InputTag>("onlineMetaDataInputLabel", edm::InputTag("rawDataCollector"));
0145   descriptions.add("onlineMetaDataRawToDigi", desc);
0146 }
0147 
0148 //define this as a plug-in
0149 DEFINE_FWK_MODULE(OnlineMetaDataRawToDigi);