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

Modernize modules in CalibTracker/SiStripCommon #31002

Merged
merged 1 commit into from Sep 28, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CalibTracker/SiStripCommon/BuildFile.xml
Expand Up @@ -4,6 +4,7 @@
<use name="DataFormats/SiStripDetId"/>
<use name="DataFormats/Scalers"/>
<use name="DataFormats/OnlineMetaData"/>
<use name="SimDataFormats/TrackingAnalysis"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you move SimDataFormats/TrackingAnalysis from CalibTracker/SiStripCommon/plugins/BuildFile.xml to CalibTracker/SiStripCommon/BuildFile.xml?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@silviodonato in an earlier iteration before rebasing I had moved some headers to the interface directory, and that required this change. For the final version I dropped that change, so shall I put SimDataFormats/TrackingAnalysis back to where it was?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already seen a similar discussion in a @guitargeek's PR #31533 (comment)

Rule 6.6 of https://cms-sw.github.io/cms_coding_rules.html suggests to have a dedicated BuildFile.xml for plugins.
I think this prevents to have cyclic dependencies, but I'm not 100% sure.

shall I put SimDataFormats/TrackingAnalysis back to where it was?

it is not urgent, but you can include it in your next PR

<use name="FWCore/Framework"/>
<use name="FWCore/MessageLogger"/>
<use name="FWCore/ServiceRegistry"/>
Expand Down
Empty file.
1 change: 0 additions & 1 deletion CalibTracker/SiStripCommon/plugins/BuildFile.xml
Expand Up @@ -7,7 +7,6 @@
<use name="CondFormats/DataRecord"/>
<use name="CondFormats/RunInfo"/>
<use name="RecoLocalTracker/SiStripClusterizer"/>
<use name="SimDataFormats/TrackingAnalysis"/>
<library file="*.cc" name="CalibTrackerSiStripCommonPlugins">
<flags EDM_PLUGIN="1"/>
</library>
14 changes: 8 additions & 6 deletions CalibTracker/SiStripCommon/plugins/ShallowClustersProducer.cc
Expand Up @@ -6,7 +6,7 @@
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "Geometry/Records/interface/TrackerTopologyRcd.h"
#include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
Expand All @@ -15,14 +15,14 @@
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "RecoLocalTracker/SiStripClusterizer/interface/SiStripClusterInfo.h"

class ShallowClustersProducer : public edm::EDProducer {
class ShallowClustersProducer : public edm::stream::EDProducer<> {
public:
explicit ShallowClustersProducer(const edm::ParameterSet&);

private:
edm::InputTag theClustersLabel;
std::string Prefix;
void produce(edm::Event&, const edm::EventSetup&) override;
void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;

struct moduleVars {
moduleVars(uint32_t, const TrackerTopology*);
Expand All @@ -40,6 +40,7 @@ class ShallowClustersProducer : public edm::EDProducer {
float outsideasymm() const { return (last - first) / (last + first); }
};

const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster>> theClustersToken_;
edm::EDGetTokenT<edm::DetSetVector<SiStripProcessedRawDigi>> theDigisToken_;
SiStripClusterInfo siStripClusterInfo_;
Expand All @@ -49,7 +50,9 @@ class ShallowClustersProducer : public edm::EDProducer {
DEFINE_FWK_MODULE(ShallowClustersProducer);

ShallowClustersProducer::ShallowClustersProducer(const edm::ParameterSet& iConfig)
: Prefix(iConfig.getParameter<std::string>("Prefix")), siStripClusterInfo_(consumesCollector()) {
: Prefix(iConfig.getParameter<std::string>("Prefix")),
topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd>()),
siStripClusterInfo_(consumesCollector()) {
produces<std::vector<unsigned>>(Prefix + "number");
produces<std::vector<unsigned>>(Prefix + "width");
produces<std::vector<float>>(Prefix + "variance");
Expand Down Expand Up @@ -93,8 +96,7 @@ ShallowClustersProducer::ShallowClustersProducer(const edm::ParameterSet& iConfi

void ShallowClustersProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
//Retrieve tracker topology from geometry
edm::ESHandle<TrackerTopology> tTopoHandle;
iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
edm::ESHandle<TrackerTopology> tTopoHandle = iSetup.getHandle(topoToken_);
const TrackerTopology* const tTopo = tTopoHandle.product();

siStripClusterInfo_.initEvent(iSetup);
Expand Down
4 changes: 2 additions & 2 deletions CalibTracker/SiStripCommon/plugins/ShallowDigisProducer.h
@@ -1,13 +1,13 @@
#ifndef SHALLOW_DIGIS_PRODUCER
#define SHALLOW_DIGIS_PRODUCER

#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Utilities/interface/InputTag.h"
class SiStripNoises;

class ShallowDigisProducer : public edm::EDProducer {
class ShallowDigisProducer : public edm::stream::EDProducer<> {
public:
explicit ShallowDigisProducer(const edm::ParameterSet &);

Expand Down
109 changes: 27 additions & 82 deletions CalibTracker/SiStripCommon/plugins/ShallowGainCalibration.cc
@@ -1,3 +1,4 @@
#include <memory>
#include "ShallowGainCalibration.h"

using namespace edm;
Expand All @@ -7,9 +8,8 @@ using namespace std;
ShallowGainCalibration::ShallowGainCalibration(const edm::ParameterSet& iConfig)
: tracks_token_(consumes<edm::View<reco::Track>>(iConfig.getParameter<edm::InputTag>("Tracks"))),
association_token_(consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("Tracks"))),
trackerGeometry_token_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
gain_token_(esConsumes<SiStripGain, SiStripGainRcd>()),
tkGeom_token_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
gainToken_(esConsumes<SiStripGain, SiStripGainRcd>()),
Suffix(iConfig.getParameter<std::string>("Suffix")),
Prefix(iConfig.getParameter<std::string>("Prefix")) {
produces<std::vector<int>>(Prefix + "trackindex" + Suffix);
Expand All @@ -32,7 +32,7 @@ ShallowGainCalibration::ShallowGainCalibration(const edm::ParameterSet& iConfig)
produces<std::vector<double>>(Prefix + "gainusedTick" + Suffix);
}

void ShallowGainCalibration::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
void ShallowGainCalibration::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
auto trackindex = std::make_unique<std::vector<int>>();
auto rawid = std::make_unique<std::vector<unsigned int>>();
auto localdirx = std::make_unique<std::vector<double>>();
Expand All @@ -52,13 +52,14 @@ void ShallowGainCalibration::produce(edm::Event& iEvent, const edm::EventSetup&
auto gainused = std::make_unique<std::vector<double>>();
auto gainusedTick = std::make_unique<std::vector<double>>();

m_tracker = &iSetup.getData(trackerGeometry_token_);
edm::ESHandle<SiStripGain> gainHandle = iSetup.getHandle(gain_token_);
edm::ESHandle<SiStripGain> gainHandle = iSetup.getHandle(gainToken_);
edm::Handle<edm::View<reco::Track>> tracks;
iEvent.getByToken(tracks_token_, tracks);
edm::Handle<TrajTrackAssociationCollection> associations;
iEvent.getByToken(association_token_, associations);

auto bundle = *runCache(iEvent.getRun().index());

for (TrajTrackAssociationCollection::const_iterator association = associations->begin();
association != associations->end();
association++) {
Expand Down Expand Up @@ -111,7 +112,8 @@ void ShallowGainCalibration::produce(edm::Event& iEvent, const edm::EventSetup&
bool Saturation = false;
bool Overlapping = false;
unsigned int Charge = 0;
double Path = (10.0 * thickness(DetId)) / fabs(cosine);
auto thicknessMap = bundle.getThicknessMap();
double Path = (10.0 * thicknessMap[DetId]) / fabs(cosine);
double PrevGain = -1;
double PrevGainTick = -1;
int FirstStrip = 0;
Expand Down Expand Up @@ -199,7 +201,7 @@ void ShallowGainCalibration::produce(edm::Event& iEvent, const edm::EventSetup&
nstrips->push_back(NStrips);
saturation->push_back(Saturation);
overlapping->push_back(Overlapping);
farfromedge->push_back(StripCluster ? IsFarFromBorder(&trajState, DetId, &iSetup) : true);
farfromedge->push_back(StripCluster ? isFarFromBorder(&trajState, DetId, bundle.getTrackerGeometry()) : true);
charge->push_back(Charge);
path->push_back(Path);
#ifdef ExtendedCALIBTree
Expand Down Expand Up @@ -231,73 +233,15 @@ void ShallowGainCalibration::produce(edm::Event& iEvent, const edm::EventSetup&
iEvent.put(std::move(gainusedTick), Prefix + "gainusedTick" + Suffix);
}

/*
void ShallowGainCalibration::beginJob(const edm::EventSetup& iSetup)
{
printf("Befin JOB\n");

edm::ESHandle<TrackerGeometry> tkGeom;
iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
vector<GeomDet*> Det = tkGeom->dets();

edm::ESHandle<SiStripGain> gainHandle;
iSetup.get<SiStripGainRcd>().get(gainHandle);
if(!gainHandle.isValid()){printf("\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");exit(0);}

for(unsigned int i=0;i<Det.size();i++){
DetId Detid = Det[i]->geographicalId();
int SubDet = Detid.subdetId();

if( SubDet == StripSubdetector::TIB || SubDet == StripSubdetector::TID ||
SubDet == StripSubdetector::TOB || SubDet == StripSubdetector::TEC ){

StripGeomDetUnit* DetUnit = dynamic_cast<StripGeomDetUnit*> (Det[i]);
if(!DetUnit)continue;

const StripTopology& Topo = DetUnit->specificTopology();
unsigned int NAPV = Topo.nstrips()/128;

for(unsigned int j=0;j<NAPV;j++){
stAPVGain* APV = new stAPVGain;
APV->DetId = Detid.rawId();
APV->APVId = j;
APV->PreviousGain = 1;

APVsCollOrdered.push_back(APV);
APVsColl[(APV->DetId<<3) | APV->APVId] = APV;
}
}
}
}


void ShallowGainCalibration::beginRun(edm::Run &, const edm::EventSetup &iSetup){
printf("BEFIN RUN\n");

edm::ESHandle<SiStripGain> gainHandle;
iSetup.get<SiStripGainRcd>().get(gainHandle);
if(!gainHandle.isValid()){printf("\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");exit(0);}

for(std::vector<stAPVGain*>::iterator it = APVsCollOrdered.begin();it!=APVsCollOrdered.end();it++){
stAPVGain* APV = *it;
SiStripApvGain::Range detGainRange = gainHandle->getRange(APV->DetId);
APV->PreviousGain = *(detGainRange.first + APV->APVId);
}
}
*/

bool ShallowGainCalibration::IsFarFromBorder(TrajectoryStateOnSurface* trajState,
bool ShallowGainCalibration::isFarFromBorder(TrajectoryStateOnSurface* trajState,
const uint32_t detid,
const edm::EventSetup* iSetup) {
edm::ESHandle<TrackerGeometry> tkGeom = iSetup->getHandle(tkGeom_token_);

const TrackerGeometry* tkGeom) const {
LocalPoint HitLocalPos = trajState->localPosition();
LocalError HitLocalError = trajState->localError().positionError();

const GeomDetUnit* it = tkGeom->idToDetUnit(DetId(detid));
if (dynamic_cast<const StripGeomDetUnit*>(it) == nullptr && dynamic_cast<const PixelGeomDetUnit*>(it) == nullptr) {
std::cout << "this detID doesn't seem to belong to the Tracker" << std::endl;
return false;
throw cms::Exception("Logic Error") << "\t\t this detID doesn't seem to belong to the Tracker";
}

const BoundPlane plane = it->surface();
Expand All @@ -322,25 +266,26 @@ bool ShallowGainCalibration::IsFarFromBorder(TrajectoryStateOnSurface* trajState
return true;
}

double ShallowGainCalibration::thickness(DetId id) {
map<DetId, double>::iterator th = m_thicknessMap.find(id);
if (th != m_thicknessMap.end())
return (*th).second;
else {
std::shared_ptr<shallowGainCalibration::bundle> ShallowGainCalibration::globalBeginRun(
edm::Run const& iRun, edm::EventSetup const& iSetup) const {
edm::ESHandle<TrackerGeometry> theTrackerGeometry = iSetup.getHandle(geomToken_);
auto bundle = std::make_shared<shallowGainCalibration::bundle>(theTrackerGeometry.product());

for (const auto& it : theTrackerGeometry->detUnits()) {
double detThickness = 1.;
//compute thickness normalization
const GeomDetUnit* it = m_tracker->idToDetUnit(DetId(id));
auto id = (it->geographicalId()).rawId();

bool isPixel = dynamic_cast<const PixelGeomDetUnit*>(it) != nullptr;
bool isStrip = dynamic_cast<const StripGeomDetUnit*>(it) != nullptr;

if (!isPixel && !isStrip) {
//FIXME throw exception
edm::LogWarning("DeDxHitsProducer") << "\t\t this detID doesn't seem to belong to the Tracker";
detThickness = 1.;
throw cms::Exception("Logic Error") << "\t\t this detID doesn't seem to belong to the Tracker";
} else {
detThickness = it->surface().bounds().thickness();
}

m_thicknessMap[id] = detThickness; //computed value
return detThickness;
bundle.get()->updateMap(id, detThickness);
}
return bundle;
}

void ShallowGainCalibration::globalEndRun(edm::Run const&, edm::EventSetup const&) const {}
56 changes: 28 additions & 28 deletions CalibTracker/SiStripCommon/plugins/ShallowGainCalibration.h
@@ -1,7 +1,7 @@
#ifndef SHALLOW_GAINCALIBRATION_PRODUCER
#define SHALLOW_GAINCALIBRATION_PRODUCER

#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"

#include "CalibTracker/SiStripCommon/interface/ShallowTools.h"
Expand All @@ -16,6 +16,8 @@
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
#include "CondFormats/DataRecord/interface/SiStripLorentzAngleRcd.h"
#include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
#include "CalibTracker/Records/interface/SiStripGainRcd.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
Expand Down Expand Up @@ -48,43 +50,41 @@
#include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
#include "DataFormats/TrackReco/interface/DeDxHit.h"
#include "DataFormats/TrackReco/interface/TrackDeDxHits.h"
#include "FWCore/Utilities/interface/ESGetToken.h"

using DetIdMap = std::map<uint32_t, double>;

#include <ext/hash_map>
namespace shallowGainCalibration {
struct bundle {
bundle(const TrackerGeometry* trackerG) : tkGeo_(trackerG), value_({{0, 0.}}) {}
void updateMap(uint32_t id, double thickness) { value_.insert(std::make_pair(id, thickness)); }
DetIdMap getThicknessMap() { return value_; }
const TrackerGeometry* getTrackerGeometry() { return tkGeo_; }

private:
const TrackerGeometry* tkGeo_;
DetIdMap value_;
};
} // namespace shallowGainCalibration

class ShallowGainCalibration : public edm::stream::EDProducer<> {
class ShallowGainCalibration : public edm::global::EDProducer<edm::RunCache<shallowGainCalibration::bundle> > {
public:
explicit ShallowGainCalibration(const edm::ParameterSet&);
std::shared_ptr<shallowGainCalibration::bundle> globalBeginRun(edm::Run const&,
edm::EventSetup const&) const override;
void globalEndRun(edm::Run const&, edm::EventSetup const&) const override;

private:
const edm::EDGetTokenT<edm::View<reco::Track> > tracks_token_;
const edm::EDGetTokenT<TrajTrackAssociationCollection> association_token_;

const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeometry_token_;
const edm::ESGetToken<SiStripGain, SiStripGainRcd> gain_token_;
const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeom_token_;

const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
const edm::ESGetToken<SiStripGain, SiStripGainRcd> gainToken_;
std::string Suffix;
std::string Prefix;

void produce(edm::Event&, const edm::EventSetup&) override;
// virtual void beginJob(EventSetup const&);
// virtual void beginRun(Run&, EventSetup const&);
bool IsFarFromBorder(TrajectoryStateOnSurface* trajState, const uint32_t detid, const edm::EventSetup* iSetup);
double thickness(DetId id);

const TrackerGeometry* m_tracker;
std::map<DetId, double> m_thicknessMap;

/*
struct stAPVGain{int DetId; int APVId; double PreviousGain;};
class isEqual{
public:
template <class T> bool operator () (const T& PseudoDetId1, const T& PseudoDetId2) { return PseudoDetId1==PseudoDetId2; }
};
std::vector<stAPVGain*> APVsCollOrdered;
hash_map<unsigned int, stAPVGain*, hash<unsigned int>, isEqual > APVsColl;
*/
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
bool isFarFromBorder(TrajectoryStateOnSurface* trajState,
const uint32_t detid,
const TrackerGeometry* trackerG) const;
};
#endif
@@ -1,7 +1,5 @@
#include "ShallowRechitClustersProducer.h"

#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
#include "Geometry/CommonTopologies/interface/StripTopology.h"
#include "FWCore/Framework/interface/ESHandle.h"
Expand All @@ -13,6 +11,7 @@
ShallowRechitClustersProducer::ShallowRechitClustersProducer(const edm::ParameterSet& iConfig)
: Suffix(iConfig.getParameter<std::string>("Suffix")),
Prefix(iConfig.getParameter<std::string>("Prefix")),
geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
clusters_token_(consumes<edmNew::DetSetVector<SiStripCluster>>(iConfig.getParameter<edm::InputTag>("Clusters"))) {
std::vector<edm::InputTag> rec_hits_tags = iConfig.getParameter<std::vector<edm::InputTag>>("InputTags");
for (const auto& itag : rec_hits_tags) {
Expand Down Expand Up @@ -44,8 +43,7 @@ void ShallowRechitClustersProducer::produce(edm::Event& iEvent, const edm::Event
auto globaly = std::make_unique<std::vector<float>>(size, -10000);
auto globalz = std::make_unique<std::vector<float>>(size, -10000);

edm::ESHandle<TrackerGeometry> theTrackerGeometry;
iSetup.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
edm::ESHandle<TrackerGeometry> theTrackerGeometry = iSetup.getHandle(geomToken_);

for (auto recHit_token : rec_hits_tokens_) {
edm::Handle<SiStripRecHit2DCollection> recHits;
Expand Down