File indexing completed on 2024-04-06 12:05:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
0019 #include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0027 #include "FWCore/Utilities/interface/EDGetToken.h"
0028 #include "FWCore/Utilities/interface/Exception.h"
0029 #include "FWCore/Utilities/interface/InputTag.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031
0032 #include <vector>
0033
0034 namespace edmtest {
0035
0036 class TestReadSiStripApproximateClusterCollection : public edm::global::EDAnalyzer<> {
0037 public:
0038 TestReadSiStripApproximateClusterCollection(edm::ParameterSet const&);
0039 void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0040 void throwWithMessage(const char*) const;
0041 static void fillDescriptions(edm::ConfigurationDescriptions&);
0042
0043 private:
0044
0045
0046
0047 std::vector<unsigned int> expectedIntegralValues_;
0048
0049 edm::EDGetTokenT<SiStripApproximateClusterCollection> collectionToken_;
0050 };
0051
0052 TestReadSiStripApproximateClusterCollection::TestReadSiStripApproximateClusterCollection(
0053 edm::ParameterSet const& iPSet)
0054 : expectedIntegralValues_(iPSet.getParameter<std::vector<unsigned int>>("expectedIntegralValues")),
0055 collectionToken_(consumes(iPSet.getParameter<edm::InputTag>("collectionTag"))) {
0056 if (expectedIntegralValues_.size() != 7) {
0057 throw cms::Exception("TestFailure") << "TestReadSiStripApproximateClusterCollection, test configuration error: "
0058 "expectedIntegralValues should have size 7.";
0059 }
0060 }
0061
0062 void TestReadSiStripApproximateClusterCollection::analyze(edm::StreamID,
0063 edm::Event const& iEvent,
0064 edm::EventSetup const&) const {
0065 auto const& siStripApproximateClusterCollection = iEvent.get(collectionToken_);
0066
0067 unsigned int expectedNumberOfDetIds = (iEvent.id().event() - 1) % 10;
0068 unsigned int expectedDetId = expectedIntegralValues_[0] + iEvent.id().event();
0069 unsigned int numberOfDetIds = 0;
0070 for (const auto& detClusters : siStripApproximateClusterCollection) {
0071 ++numberOfDetIds;
0072 expectedDetId += iEvent.id().event();
0073 if (detClusters.id() != expectedDetId) {
0074 throwWithMessage("DetId in detClusters does not have expected value");
0075 }
0076 unsigned int expectedNumberOfClustersPerDetId = (iEvent.id().event() - 1) % 10;
0077 unsigned int j = 0;
0078 for (const auto& cluster : detClusters) {
0079 unsigned int iOffset = j + iEvent.id().event();
0080 if (cluster.barycenter() != expectedIntegralValues_[1] + iOffset) {
0081 throwWithMessage("barycenter does not have expected value");
0082 }
0083 if (cluster.width() != expectedIntegralValues_[2] + iOffset) {
0084 throwWithMessage("width does not have expected value");
0085 }
0086 if (cluster.avgCharge() != expectedIntegralValues_[3] + iOffset) {
0087 throwWithMessage("avgCharge does not have expected value");
0088 }
0089 if (cluster.filter() != (j < (expectedIntegralValues_[4] + iEvent.id().event()) % 10)) {
0090 throwWithMessage("filter does not have expected value");
0091 }
0092 if (cluster.isSaturated() != (j < (expectedIntegralValues_[5] + iEvent.id().event()) % 10)) {
0093 throwWithMessage("isSaturated does not have expected value");
0094 }
0095 if (cluster.peakFilter() != (j < (expectedIntegralValues_[6] + iEvent.id().event()) % 10)) {
0096 throwWithMessage("peakFilter does not have expected value");
0097 }
0098 ++j;
0099 }
0100 if (j != expectedNumberOfClustersPerDetId) {
0101 throwWithMessage("Number of cluster for DetId does not have expected value");
0102 }
0103 }
0104 if (numberOfDetIds != expectedNumberOfDetIds) {
0105 throwWithMessage("Number of DetIds does not match expected value");
0106 }
0107 }
0108
0109 void TestReadSiStripApproximateClusterCollection::throwWithMessage(const char* msg) const {
0110 throw cms::Exception("TestFailure") << "TestReadSiStripApproximateClusterCollection::analyze, " << msg;
0111 }
0112
0113 void TestReadSiStripApproximateClusterCollection::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0114 edm::ParameterSetDescription desc;
0115 desc.add<std::vector<unsigned int>>("expectedIntegralValues");
0116 desc.add<edm::InputTag>("collectionTag");
0117 descriptions.addDefault(desc);
0118 }
0119 }
0120
0121 using edmtest::TestReadSiStripApproximateClusterCollection;
0122 DEFINE_FWK_MODULE(TestReadSiStripApproximateClusterCollection);