File indexing completed on 2023-06-11 22:42:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "FWCore/Framework/interface/stream/EDProducer.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "FWCore/Utilities/interface/InputTag.h"
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Utilities/interface/ESGetToken.h"
0018
0019 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0020 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0021 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0022
0023 #include "DataFormats/CTPPSDigi/interface/TotemRPDigi.h"
0024 #include "DataFormats/CTPPSDigi/interface/TotemVFATStatus.h"
0025 #include "DataFormats/CTPPSDigi/interface/TotemFEDInfo.h"
0026
0027 #include "CondFormats/DataRecord/interface/TotemReadoutRcd.h"
0028 #include "CondFormats/PPSObjects/interface/TotemDAQMapping.h"
0029 #include "CondFormats/PPSObjects/interface/TotemAnalysisMask.h"
0030
0031 #include "EventFilter/CTPPSRawToDigi/interface/SimpleVFATFrameCollection.h"
0032 #include "EventFilter/CTPPSRawToDigi/interface/RawDataUnpacker.h"
0033 #include "EventFilter/CTPPSRawToDigi/interface/RawToDigiConverter.h"
0034
0035 #include "DataFormats/CTPPSDigi/interface/TotemTimingDigi.h"
0036 #include "DataFormats/TotemReco/interface/TotemT2Digi.h"
0037
0038 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0039 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0040
0041 #include <string>
0042
0043 class TotemVFATRawToDigi : public edm::stream::EDProducer<> {
0044 public:
0045 explicit TotemVFATRawToDigi(const edm::ParameterSet &);
0046 ~TotemVFATRawToDigi() override;
0047
0048 void produce(edm::Event &, const edm::EventSetup &) override;
0049 void endStream() override;
0050 static void fillDescriptions(edm::ConfigurationDescriptions &);
0051
0052 private:
0053 std::string subSystemName;
0054
0055 enum { ssUndefined, ssTrackingStrip, ssTimingDiamond, ssTotemTiming, ssTotemT2 } subSystem;
0056
0057 std::vector<unsigned int> fedIds;
0058
0059 edm::EDGetTokenT<FEDRawDataCollection> fedDataToken;
0060 edm::ESGetToken<TotemDAQMapping, TotemReadoutRcd> totemMappingToken;
0061 edm::ESGetToken<TotemAnalysisMask, TotemReadoutRcd> analysisMaskToken;
0062
0063 pps::RawDataUnpacker rawDataUnpacker;
0064 RawToDigiConverter rawToDigiConverter;
0065
0066 template <typename DigiType>
0067 void run(edm::Event &, const edm::EventSetup &);
0068 };
0069
0070 using namespace edm;
0071 using namespace std;
0072
0073 TotemVFATRawToDigi::TotemVFATRawToDigi(const edm::ParameterSet &conf)
0074 : subSystemName(conf.getParameter<string>("subSystem")),
0075 subSystem(ssUndefined),
0076 fedIds(conf.getParameter<vector<unsigned int>>("fedIds")),
0077 rawDataUnpacker(conf.getParameterSet("RawUnpacking")),
0078 rawToDigiConverter(conf.getParameterSet("RawToDigi")) {
0079 fedDataToken = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("rawDataTag"));
0080
0081
0082 if (subSystemName == "TrackingStrip")
0083 subSystem = ssTrackingStrip;
0084 else if (subSystemName == "TimingDiamond")
0085 subSystem = ssTimingDiamond;
0086 else if (subSystemName == "TotemTiming")
0087 subSystem = ssTotemTiming;
0088 else if (subSystemName == "TotemT2")
0089 subSystem = ssTotemT2;
0090
0091 if (subSystem == ssUndefined)
0092 throw cms::Exception("TotemVFATRawToDigi::TotemVFATRawToDigi")
0093 << "Unknown sub-system string " << subSystemName << "." << endl;
0094
0095
0096 produces<vector<TotemFEDInfo>>(subSystemName);
0097
0098
0099 if (subSystem == ssTrackingStrip)
0100 produces<DetSetVector<TotemRPDigi>>(subSystemName);
0101
0102 else if (subSystem == ssTimingDiamond)
0103 produces<DetSetVector<CTPPSDiamondDigi>>(subSystemName);
0104
0105 else if (subSystem == ssTotemTiming)
0106 produces<DetSetVector<TotemTimingDigi>>(subSystemName);
0107
0108 else if (subSystem == ssTotemT2)
0109 produces<edmNew::DetSetVector<TotemT2Digi>>(subSystemName);
0110
0111
0112 if (fedIds.empty()) {
0113 if (subSystem == ssTrackingStrip) {
0114 for (int id = FEDNumbering::MINTotemRPHorizontalFEDID; id <= FEDNumbering::MAXTotemRPHorizontalFEDID; ++id)
0115 fedIds.push_back(id);
0116
0117 for (int id = FEDNumbering::MINTotemRPVerticalFEDID; id <= FEDNumbering::MAXTotemRPVerticalFEDID; ++id)
0118 fedIds.push_back(id);
0119 }
0120
0121 else if (subSystem == ssTimingDiamond) {
0122 for (int id = FEDNumbering::MINCTPPSDiamondFEDID; id <= FEDNumbering::MAXCTPPSDiamondFEDID; ++id)
0123 fedIds.push_back(id);
0124 }
0125
0126 else if (subSystem == ssTotemTiming) {
0127 for (int id = FEDNumbering::MINTotemRPTimingVerticalFEDID; id <= FEDNumbering::MAXTotemRPTimingVerticalFEDID;
0128 ++id)
0129 fedIds.push_back(id);
0130 }
0131
0132 else if (subSystem == ssTotemT2) {
0133 for (int id = FEDNumbering::MINTotemT2FEDID; id <= FEDNumbering::MAXTotemT2FEDID; ++id)
0134 fedIds.push_back(id);
0135 }
0136 }
0137 LogDebug("TotemVFATRawToDigi").log([this](auto &log) {
0138 log << "List of FEDs handled by this instance: ";
0139 string sep;
0140 for (const auto &fedId : fedIds)
0141 log << sep << fedId, sep = ", ";
0142 });
0143
0144
0145 produces<DetSetVector<TotemVFATStatus>>(subSystemName);
0146
0147 totemMappingToken = esConsumes<TotemDAQMapping, TotemReadoutRcd>(ESInputTag("", subSystemName));
0148 analysisMaskToken = esConsumes<TotemAnalysisMask, TotemReadoutRcd>(ESInputTag("", subSystemName));
0149 }
0150
0151 TotemVFATRawToDigi::~TotemVFATRawToDigi() {}
0152
0153 void TotemVFATRawToDigi::produce(edm::Event &event, const edm::EventSetup &es) {
0154 if (subSystem == ssTrackingStrip)
0155 run<DetSetVector<TotemRPDigi>>(event, es);
0156
0157 else if (subSystem == ssTimingDiamond)
0158 run<DetSetVector<CTPPSDiamondDigi>>(event, es);
0159
0160 else if (subSystem == ssTotemTiming)
0161 run<DetSetVector<TotemTimingDigi>>(event, es);
0162
0163 else if (subSystem == ssTotemT2)
0164 run<edmNew::DetSetVector<TotemT2Digi>>(event, es);
0165 }
0166
0167 template <typename DigiType>
0168 void TotemVFATRawToDigi::run(edm::Event &event, const edm::EventSetup &es) {
0169
0170 ESHandle<TotemDAQMapping> mapping = es.getHandle(totemMappingToken);
0171
0172
0173 ESHandle<TotemAnalysisMask> analysisMask = es.getHandle(analysisMaskToken);
0174
0175
0176 edm::Handle<FEDRawDataCollection> rawData;
0177 event.getByToken(fedDataToken, rawData);
0178
0179
0180 vector<TotemFEDInfo> fedInfo;
0181 DigiType digi;
0182 DetSetVector<TotemVFATStatus> conversionStatus;
0183
0184
0185 SimpleVFATFrameCollection vfatCollection;
0186 for (const auto &fedId : fedIds) {
0187 const FEDRawData &data = rawData->FEDData(fedId);
0188 if (data.size() > 0)
0189 rawDataUnpacker.run(fedId, data, fedInfo, vfatCollection);
0190 }
0191
0192
0193 rawToDigiConverter.run(vfatCollection, *mapping, *analysisMask, digi, conversionStatus);
0194
0195
0196 event.put(make_unique<vector<TotemFEDInfo>>(fedInfo), subSystemName);
0197 event.put(make_unique<DigiType>(digi), subSystemName);
0198 event.put(make_unique<DetSetVector<TotemVFATStatus>>(conversionStatus), subSystemName);
0199 }
0200
0201 void TotemVFATRawToDigi::endStream() { rawToDigiConverter.printSummaries(); }
0202
0203 void TotemVFATRawToDigi::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0204
0205 edm::ParameterSetDescription desc;
0206 desc.add<edm::InputTag>("rawDataTag", edm::InputTag(""));
0207 desc.add<std::string>("subSystem", "")->setComment("options: RP");
0208 desc.add<std::vector<unsigned int>>("fedIds", {})
0209 ->setComment(
0210 "IMPORTANT: leave empty to load the default configuration from "
0211 "DataFormats/FEDRawData/interface/FEDNumbering.h");
0212 {
0213 edm::ParameterSetDescription psd0;
0214 psd0.addUntracked<unsigned int>("verbosity", 0);
0215 desc.add<edm::ParameterSetDescription>("RawUnpacking", psd0);
0216 }
0217 {
0218 edm::ParameterSetDescription psd0;
0219 psd0.addUntracked<unsigned int>("verbosity", 0)
0220 ->setComment(
0221 "0-3: 1=one line/event with some corrupted VFAT frame, 2=list all corrupt VFAT frames/event, 3=all "
0222 "problems with every corrupt frame");
0223 psd0.add<unsigned int>("testFootprint", 2)->setComment("0=no test, 1=warn only, 2=warn and skip");
0224 psd0.add<unsigned int>("testCRC", 2);
0225 psd0.add<unsigned int>("testID", 2)->setComment("compare the ID from data and mapping");
0226 psd0.add<unsigned int>("testECMostFrequent", 2)
0227 ->setComment("compare frame EC with the most frequent value in the event");
0228 psd0.add<unsigned int>("testBCMostFrequent", 2);
0229 psd0.addUntracked<unsigned int>("EC_min", 10)
0230 ->setComment("minimal number of frames to search for the most frequent counter value");
0231 psd0.addUntracked<unsigned int>("BC_min", 10);
0232 psd0.addUntracked<double>("EC_fraction", 0.6)
0233 ->setComment(
0234 "the most frequent counter value is accepted provided its relative occupancy is higher than this fraction");
0235 psd0.addUntracked<double>("BC_fraction", 0.6);
0236 psd0.add<bool>("useOlderT2TestFile", false)
0237 ->setComment("treat hwID field as two separate 8-bit fields instead of one 16-bit");
0238 psd0.addUntracked<bool>("printErrorSummary", false)->setComment("per-VFAT error summary at the end of the job");
0239 psd0.addUntracked<bool>("printUnknownFrameSummary", false)
0240 ->setComment("summary of frames found in data, but not in the mapping");
0241 desc.add<edm::ParameterSetDescription>("RawToDigi", psd0);
0242 }
0243 descriptions.add("totemVFATRawToDigi", desc);
0244
0245
0246 }
0247
0248 DEFINE_FWK_MODULE(TotemVFATRawToDigi);