Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SiStripApproximateCluster reduced data format for HI #33546

Merged
merged 19 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef DATAFORMATS_SISTRIPAPPROXIMATECLUSTER_H
#define DATAFORMATS_SISTRIPAPPROXIMATECLUSTER_H

#include <numeric>
#include <cmath>
#include <iostream>
#include <iomanip>

#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"

class SiStripApproximateCluster {
public:
SiStripApproximateCluster() {}

explicit SiStripApproximateCluster(float barycenter, uint8_t width, float avgCharge) {
barycenter_ = barycenter;
width_ = width;
avgCharge_ = avgCharge;
}

explicit SiStripApproximateCluster(const SiStripCluster& cluster) {
barycenter_ = cluster.barycenter();
width_ = cluster.size();
avgCharge_ = cluster.charge() / cluster.size();
}

float barycenter() const { return barycenter_; }
uint8_t width() const { return width_; }
float avgCharge() const { return avgCharge_; }

private:
float barycenter_ = 0;
uint8_t width_ = 0;
float avgCharge_ = 0;
};
#endif // DATAFORMATS_SiStripApproximateCluster_H
1 change: 1 addition & 0 deletions DataFormats/SiStripCluster/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
#include "DataFormats/Common/interface/ContainerMask.h"

#endif // SISTRIPCLUSTER_CLASSES_H
20 changes: 20 additions & 0 deletions DataFormats/SiStripCluster/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,24 @@
<class name="edm::Wrapper<edmNew::DetSetVector<edm::Ref<edmNew::DetSetVector<SiStripCluster>,SiStripCluster,edmNew::DetSetVector<SiStripCluster>::FindForDetSetVector> > >" />


<class name="SiStripApproximateCluster" ClassVersion="3">
<version ClassVersion="3" checksum="2041370183"/>
</class>

<class name="edmNew::DetSetVector<SiStripApproximateCluster>"/>
<class name="edm::Wrapper<edmNew::DetSetVector<SiStripApproximateCluster>>"/>

<class name="std::vector<SiStripApproximateCluster>"/>

<class name="edm::Ref<edmNew::DetSetVector<SiStripApproximateCluster>, SiStripApproximateCluster, edmNew::DetSetVector<SiStripApproximateCluster>::FindForDetSetVector>"/>


<class name="edm::ContainerMask<edmNew::DetSetVector<SiStripApproximateCluster> >"/>
<class name="edm::Wrapper<edm::ContainerMask<edmNew::DetSetVector<SiStripApproximateCluster> > >"/>


<class name="std::vector<edm::Ref<edmNew::DetSetVector<SiStripApproximateCluster>,SiStripApproximateCluster,edmNew::DetSetVector<SiStripApproximateCluster>::FindForDetSetVector> >" />
<class name="edmNew::DetSetVector<edm::Ref<edmNew::DetSetVector<SiStripApproximateCluster>,SiStripApproximateCluster,edmNew::DetSetVector<SiStripApproximateCluster>::FindForDetSetVector> >" />
<class name="edm::Wrapper<edmNew::DetSetVector<edm::Ref<edmNew::DetSetVector<SiStripApproximateCluster>,SiStripApproximateCluster,edmNew::DetSetVector<SiStripApproximateCluster>::FindForDetSetVector> > >" />

</lcgdict>
7 changes: 6 additions & 1 deletion RecoLocalTracker/SiStripClusterizer/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<use name="DataFormats/Common"/>
<use name="FWCore/Framework"/>
<use name="FWCore/ParameterSet"/>
<use name="FWCore/Utilities"/>
<use name="DataFormats/SiStripDigi"/>
<use name="DataFormats/SiStripCluster"/>
<use name="DataFormats/Common"/>
<use name="CondFormats/DataRecord"/>
<use name="CondFormats/SiStripObjects"/>
<use name="CalibFormats/SiStripObjects"/>
<use name="CalibTracker/Records"/>
<use name="RecoLocalTracker/Records"/>
<use name="CommonTools/UtilAlgos"/>
<use name="CommonTools/Utils"/>
<use name="root"/>
icali marked this conversation as resolved.
Show resolved Hide resolved
<export>
<lib name="1"/>
</export>
</export>
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@


#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/Common/interface/DetSetVector.h"

#include <vector>
#include <memory>

class SiStripApprox2ApproxClusters : public edm::stream::EDProducer<> {
public:
explicit SiStripApprox2ApproxClusters(const edm::ParameterSet& conf);
void produce(edm::Event&, const edm::EventSetup&) override;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
edm::InputTag inputApproxClusters;
uint8_t approxVersion;
std::string approxVersionS;
edm::EDGetTokenT<edmNew::DetSetVector<SiStripApproximateCluster>> clusterToken;
};

SiStripApprox2ApproxClusters::SiStripApprox2ApproxClusters(const edm::ParameterSet& conf) {
inputApproxClusters = conf.getParameter<edm::InputTag>("inputApproxClusters");
approxVersionS = conf.getParameter<std::string>("approxVersion");

approxVersion = -1;

if (approxVersionS == "ORIGINAL")
approxVersion = 0;
else if (approxVersionS == "FULL_WIDTH")
approxVersion = 1;
else if (approxVersionS == "BARY_RES_0.1")
approxVersion = 2;
else if (approxVersionS == "BARY_CHARGE_RES_0.1")
approxVersion = 3;

clusterToken = consumes<edmNew::DetSetVector<SiStripApproximateCluster>>(inputApproxClusters);
produces<edmNew::DetSetVector<SiStripApproximateCluster>>();
}

void SiStripApprox2ApproxClusters::produce(edm::Event& event, edm::EventSetup const&) {
auto result = std::make_unique<edmNew::DetSetVector<SiStripApproximateCluster>>();
const auto& clusterCollection = event.get(clusterToken);

for (const auto& detClusters : clusterCollection) {
edmNew::DetSetVector<SiStripApproximateCluster>::FastFiller ff{*result, detClusters.id()};

for (const auto& cluster : detClusters) {
float barycenter = cluster.barycenter();
uint8_t width = cluster.width();
float avgCharge = cluster.avgCharge();

switch (approxVersion) {
case 0: //ORIGINAL
barycenter = std::round(barycenter);
if (width > 0x3F)
width = 0x3F;
avgCharge = std::round(avgCharge);
break;
case 1: //FULL_WIDTH
barycenter = std::round(barycenter);
avgCharge = std::round(avgCharge);
break;
case 2: //BARY_RES_0.1
barycenter = std::round(barycenter * 10) / 10;
if (width > 0x3F)
width = 0x3F;
avgCharge = std::round(avgCharge);
break;
case 3: //BARY_CHARGE_RES_0.1
barycenter = std::round(barycenter * 10) / 10;
if (width > 0x3F)
width = 0x3F;
avgCharge = std::round(avgCharge * 10) / 10;
break;
}

ff.push_back(SiStripApproximateCluster(barycenter, width, avgCharge));
}
}

event.put(std::move(result));
}

void SiStripApprox2ApproxClusters::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("inputApproxClusters", edm::InputTag("siStripClusters"));
desc.add<std::string>("approxVersion", std::string("ORIGINAL"));

descriptions.add("SiStripApprox2ApproxClusters", desc);
}

DEFINE_FWK_MODULE(SiStripApprox2ApproxClusters);
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@


#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/Common/interface/DetSetVector.h"

#include <vector>
#include <memory>

class SiStripClusters2ApproxClusters : public edm::stream::EDProducer<> {
public:
explicit SiStripClusters2ApproxClusters(const edm::ParameterSet& conf);
void produce(edm::Event&, const edm::EventSetup&) override;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
edm::InputTag inputClusters;
edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > clusterToken;
};

SiStripClusters2ApproxClusters::SiStripClusters2ApproxClusters(const edm::ParameterSet& conf) {
inputClusters = conf.getParameter<edm::InputTag>("inputClusters");

clusterToken = consumes<edmNew::DetSetVector<SiStripCluster> >(inputClusters);
produces<edmNew::DetSetVector<SiStripApproximateCluster> >();
}

void SiStripClusters2ApproxClusters::produce(edm::Event& event, edm::EventSetup const&) {
auto result = std::make_unique<edmNew::DetSetVector<SiStripApproximateCluster> >();
const auto& clusterCollection = event.get(clusterToken);

for (const auto& detClusters : clusterCollection) {
edmNew::DetSetVector<SiStripApproximateCluster>::FastFiller ff{*result, detClusters.id()};

for (const auto& cluster : detClusters)
ff.push_back(SiStripApproximateCluster(cluster));
}

event.put(std::move(result));
}

void SiStripClusters2ApproxClusters::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("inputClusters", edm::InputTag("siStripClusters"));
descriptions.add("SiStripClusters2ApproxClusters", desc);
}

DEFINE_FWK_MODULE(SiStripClusters2ApproxClusters);
2 changes: 2 additions & 0 deletions RecoLocalTracker/SiStripClusterizer/test/SealModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#include "RecoLocalTracker/SiStripClusterizer/test/StripByStripTestDriver.h"
#include "RecoLocalTracker/SiStripClusterizer/test/ClusterizerUnitTesterESProducer.h"
#include "RecoLocalTracker/SiStripClusterizer/test/ClusterRefinerTagMCmerged.h"
#include "RecoLocalTracker/SiStripClusterizer/test/SiStripApproximatedClustersDump.h"

DEFINE_FWK_MODULE(CompareClusters);
DEFINE_FWK_MODULE(ClusterizerUnitTester);
DEFINE_FWK_MODULE(StripByStripTestDriver);
DEFINE_FWK_EVENTSETUP_MODULE(ClusterizerUnitTesterESProducer);
DEFINE_FWK_MODULE(ClusterRefinerTagMCmerged);
DEFINE_FWK_MODULE(SiStripApproximatedClustersDump);
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "RecoLocalTracker/SiStripClusterizer/test/SiStripApproximatedClustersDump.h"

SiStripApproximatedClustersDump::SiStripApproximatedClustersDump(const edm::ParameterSet& conf) {
inputTagClusters = conf.getParameter<edm::InputTag>("approximatedClustersTag");
clusterToken = consumes<edmNew::DetSetVector<SiStripApproximateCluster>>(inputTagClusters);

usesResource("TFileService");

outNtuple = fs->make<TTree>("ApproxClusters", "ApproxClusters");
outNtuple->Branch("event", &eventN, "event/i");
outNtuple->Branch("detId", &detId, "detId/i");
outNtuple->Branch("barycenter", &barycenter, "barycenter/F");
outNtuple->Branch("width", &width, "width/b");
outNtuple->Branch("charge", &avCharge, "charge/b");
}

SiStripApproximatedClustersDump::~SiStripApproximatedClustersDump() {}

void SiStripApproximatedClustersDump::analyze(const edm::Event& event, const edm::EventSetup& es) {
edm::Handle<edmNew::DetSetVector<SiStripApproximateCluster>> clusterCollection = event.getHandle(clusterToken);

for (const auto& detClusters : *clusterCollection) {
detId = detClusters.detId();
eventN = event.id().event();

for (const auto& cluster : detClusters) {
barycenter = cluster.barycenter();
width = cluster.width();
avCharge = cluster.avgCharge();
outNtuple->Fill();
}
}
}

void SiStripApproximatedClustersDump::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("approximatedClustersTag", edm::InputTag("SiStripClusters2ApproxClusters"));
descriptions.add("SiStripApproximatedClustersDump", desc);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef RecoLocalTracker_SiStripApproximatedClustersDump_h
#define RecoLocalTracker_SiStripApproximatedClustersDump_h

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/Common/interface/DetSet.h"
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"

#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "CommonTools/Utils/interface/TFileDirectory.h"

#include <memory>
#include <iostream>

//ROOT inclusion
#include "TROOT.h"
#include "TFile.h"
#include "TNtuple.h"
#include "TTree.h"
#include "TMath.h"
#include "TList.h"
#include "TString.h"

//
// class decleration
//

class SiStripApproximatedClustersDump : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit SiStripApproximatedClustersDump(const edm::ParameterSet&);
~SiStripApproximatedClustersDump() override;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
void analyze(const edm::Event&, const edm::EventSetup&) override;

edm::InputTag inputTagClusters;
edm::EDGetTokenT<edmNew::DetSetVector<SiStripApproximateCluster> > clusterToken;

TTree* outNtuple;
edm::Service<TFileService> fs;

uint32_t detId;
uint16_t barycenter;
uint16_t width;
uint8_t avCharge;
edm::EventNumber_t eventN;
};
#endif
Loading