Skip to content

Commit

Permalink
Merge pull request #18278 from fioriNTU/FixResidualsCosmics91X
Browse files Browse the repository at this point in the history
Fix residuals cosmics91X
  • Loading branch information
davidlange6 committed Apr 12, 2017
2 parents ce616fe + cf137c3 commit 44bc494
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 32 deletions.
Expand Up @@ -39,6 +39,15 @@
SiPixelPhase1TrackResidualsAnalyzer_cosmics = SiPixelPhase1TrackResidualsAnalyzer.clone()
SiPixelPhase1TrackResidualsAnalyzer_cosmics.Tracks = "ctfWithMaterialTracksP5"
SiPixelPhase1TrackResidualsAnalyzer_cosmics.trajectoryInput = "ctfWithMaterialTracksP5"
SiPixelPhase1TrackResidualsAnalyzer_cosmics.VertexCut = False # don't cuts based on the primary vertex position for cosmics


siPixelPhase1OfflineDQM_source_cosmics.replace(SiPixelPhase1TrackResidualsAnalyzer,
SiPixelPhase1TrackResidualsAnalyzer_cosmics)

SiPixelPhase1RecHitsAnalyzer_cosmics = SiPixelPhase1RecHitsAnalyzer.clone()
SiPixelPhase1RecHitsAnalyzer_cosmics.onlyValidHits = True # In Cosmics the efficiency plugin will not run, so we monitor only valid hits
SiPixelPhase1RecHitsAnalyzer_cosmics.src = "ctfWithMaterialTracksP5"

siPixelPhase1OfflineDQM_source_cosmics.replace(SiPixelPhase1RecHitsAnalyzer,
SiPixelPhase1RecHitsAnalyzer_cosmics)
2 changes: 2 additions & 0 deletions DQM/SiPixelPhase1RecHits/BuildFile.xml
@@ -1,3 +1,5 @@
<use name="DQM/SiPixelPhase1Common"/>
<use name="DataFormats/TrackerRecHit2D"/>
<use name="TrackingTools/TrackFitters"/>

<flags EDM_PLUGIN="1"/>
7 changes: 5 additions & 2 deletions DQM/SiPixelPhase1RecHits/interface/SiPixelPhase1RecHits.h
Expand Up @@ -9,7 +9,8 @@
// Original Author: Marcel Schneider

#include "DQM/SiPixelPhase1Common/interface/SiPixelPhase1Base.h"
#include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"

class SiPixelPhase1RecHits : public SiPixelPhase1Base {
enum {
Expand All @@ -22,12 +23,14 @@ class SiPixelPhase1RecHits : public SiPixelPhase1Base {
CLUSTER_PROB
};

bool onlyValid_;

public:
explicit SiPixelPhase1RecHits(const edm::ParameterSet& conf);
void analyze(const edm::Event&, const edm::EventSetup&);

private:
edm::EDGetTokenT<SiPixelRecHitCollection> srcToken_;
edm::EDGetTokenT<reco::TrackCollection> srcToken_;
};

#endif
6 changes: 4 additions & 2 deletions DQM/SiPixelPhase1RecHits/python/SiPixelPhase1RecHits_cfi.py
Expand Up @@ -90,9 +90,11 @@
)

SiPixelPhase1RecHitsAnalyzer = cms.EDAnalyzer("SiPixelPhase1RecHits",
src = cms.InputTag("siPixelRecHits"),
src = cms.InputTag("generalTracks"),
histograms = SiPixelPhase1RecHitsConf,
geometry = SiPixelPhase1Geometry
geometry = SiPixelPhase1Geometry,
onlyValidHits = cms.bool(False)

)

SiPixelPhase1RecHitsHarvester = cms.EDAnalyzer("SiPixelPhase1Harvester",
Expand Down
91 changes: 69 additions & 22 deletions DQM/SiPixelPhase1RecHits/src/SiPixelPhase1RecHits.cc
Expand Up @@ -6,7 +6,6 @@

// Original Author: Marcel Schneider

#include "DQM/SiPixelPhase1RecHits/interface/SiPixelPhase1RecHits.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/Framework/interface/ESHandle.h"
Expand All @@ -16,12 +15,20 @@
#include "Geometry/CommonTopologies/interface/PixelTopology.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"

#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"

#include "DataFormats/TrackReco/interface/Track.h"

#include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"

#include "DQM/SiPixelPhase1RecHits/interface/SiPixelPhase1RecHits.h"

SiPixelPhase1RecHits::SiPixelPhase1RecHits(const edm::ParameterSet& iConfig) :
SiPixelPhase1Base(iConfig)
{
srcToken_ = consumes<SiPixelRecHitCollection>(iConfig.getParameter<edm::InputTag>("src"));
srcToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("src"));
onlyValid_=iConfig.getParameter<bool>("onlyValidHits");
}

void SiPixelPhase1RecHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
Expand All @@ -30,24 +37,60 @@ void SiPixelPhase1RecHits::analyze(const edm::Event& iEvent, const edm::EventSet
iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
assert(tracker.isValid());

edm::Handle<SiPixelRecHitCollection> input;
iEvent.getByToken(srcToken_, input);
if (!input.isValid()) return;
edm::Handle<reco::TrackCollection> tracks;
iEvent.getByToken( srcToken_, tracks);
if (!tracks.isValid()) return;

for (auto const & track : *tracks) {

bool isBpixtrack = false, isFpixtrack = false;

auto const & trajParams = track.extra()->trajParams();
auto hb = track.recHitsBegin();
for(unsigned int h=0;h<track.recHitsSize();h++){

auto hit = *(hb+h);
if(!hit->isValid()) continue;

DetId id = hit->geographicalId();
uint32_t subdetid = (id.subdetId());

if (subdetid == PixelSubdetector::PixelBarrel) isBpixtrack = true;
if (subdetid == PixelSubdetector::PixelEndcap) isFpixtrack = true;
}

if (!isBpixtrack && !isFpixtrack) continue;

// then, look at each hit
for(unsigned int h=0;h<track.recHitsSize();h++){
auto rechit = *(hb+h);

if(!rechit->isValid()) continue;

SiPixelRecHitCollection::const_iterator it;
for (it = input->begin(); it != input->end(); ++it) {
auto id = DetId(it->detId());
//continue if not a Pixel recHit
DetId id = rechit->geographicalId();
uint32_t subdetid = (id.subdetId());

for(SiPixelRecHit const& rechit : *it) {
SiPixelRecHit::ClusterRef const& clust = rechit.cluster();
if ( subdetid != PixelSubdetector::PixelBarrel
&& subdetid != PixelSubdetector::PixelEndcap) continue;

int sizeX = (*clust).sizeX();
int sizeY = (*clust).sizeY();
bool isHitValid = rechit->getType()==TrackingRecHit::valid;
if (onlyValid_ && !isHitValid) continue; //useful to run on cosmics where the TrackEfficiency plugin is not used

const SiPixelRecHit* prechit = dynamic_cast<const SiPixelRecHit*>(rechit);//to be used to get the associated cluster and the cluster probability

int sizeX=0, sizeY=0;

if (isHitValid){
SiPixelRecHit::ClusterRef const& clust = prechit->cluster();
sizeX = (*clust).sizeX();
sizeY = (*clust).sizeY();
}

const PixelGeomDetUnit* geomdetunit = dynamic_cast<const PixelGeomDetUnit*> ( tracker->idToDet(id) );
const PixelTopology& topol = geomdetunit->specificTopology();

LocalPoint lp = rechit.localPosition();
LocalPoint lp = trajParams[h].position();
MeasurementPoint mp = topol.measurementPosition(lp);

int row = (int) mp.x();
Expand All @@ -56,23 +99,27 @@ void SiPixelPhase1RecHits::analyze(const edm::Event& iEvent, const edm::EventSet
float rechit_x = lp.x();
float rechit_y = lp.y();

LocalError lerr = rechit.localPositionError();
LocalError lerr = rechit->localPositionError();
float lerr_x = sqrt(lerr.xx());
float lerr_y = sqrt(lerr.yy());

histo[NRECHITS].fill(id, &iEvent, col, row);
histo[NRECHITS].fill(id, &iEvent, col, row); //in general a inclusive counter of missing/valid/inactive hits

histo[CLUST_X].fill(sizeX, id, &iEvent, col, row);
histo[CLUST_Y].fill(sizeY, id, &iEvent, col, row);
if (isHitValid){
histo[CLUST_X].fill(sizeX, id, &iEvent, col, row);
histo[CLUST_Y].fill(sizeY, id, &iEvent, col, row);
}

histo[ERROR_X].fill(lerr_x, id, &iEvent);
histo[ERROR_Y].fill(lerr_y, id, &iEvent);

histo[POS].fill(rechit_x, rechit_y, id, &iEvent);

double clusterProbability = rechit.clusterProbability(0);
if (clusterProbability > 0)
histo[CLUSTER_PROB].fill(log10(clusterProbability), id, &iEvent);

if (isHitValid){
double clusterProbability= prechit->clusterProbability(0);
if (clusterProbability > 0)
histo[CLUSTER_PROB].fill(log10(clusterProbability), id, &iEvent);
}
}
}

Expand Down
Expand Up @@ -49,6 +49,7 @@ void SiPixelPhase1TrackEfficiency::analyze(const edm::Event& iEvent, const edm::
// get the map
edm::Handle<reco::TrackCollection> tracks;
iEvent.getByToken( tracksToken_, tracks);
if (!tracks.isValid()) return;

for (auto const & track : *tracks) {

Expand All @@ -59,7 +60,8 @@ void SiPixelPhase1TrackEfficiency::analyze(const edm::Event& iEvent, const edm::
auto const & trajParams = track.extra()->trajParams();
auto hb = track.recHitsBegin();
for(unsigned int h=0;h<track.recHitsSize();h++){
auto hit = *(hb+h);

auto hit = *(hb+h);
if(!hit->isValid()) continue;

DetId id = hit->geographicalId();
Expand Down Expand Up @@ -104,7 +106,6 @@ void SiPixelPhase1TrackEfficiency::analyze(const edm::Event& iEvent, const edm::
int row = (int) mp.x();
int col = (int) mp.y();


if (isHitValid) {
histo[VALID].fill(id, &iEvent, col, row);
histo[EFFICIENCY].fill(1, id, &iEvent, col, row);
Expand Down
Expand Up @@ -18,6 +18,8 @@ class SiPixelPhase1TrackResiduals : public SiPixelPhase1Base {
RESIDUAL_Y
};

bool ApplyVertexCut_;

public:
explicit SiPixelPhase1TrackResiduals(const edm::ParameterSet& conf);
void analyze(const edm::Event&, const edm::EventSetup&);
Expand Down
Expand Up @@ -27,6 +27,7 @@
SiPixelPhase1TrackResidualsAnalyzer = cms.EDAnalyzer("SiPixelPhase1TrackResiduals",
trajectoryInput = cms.string("generalTracks"),
Tracks = cms.InputTag("generalTracks"),
VertexCut = cms.bool(True), # Will not apply the vertex cuts on cosmics
histograms = SiPixelPhase1TrackResidualsConf,
geometry = SiPixelPhase1Geometry
)
Expand Down
Expand Up @@ -23,6 +23,7 @@ SiPixelPhase1TrackResiduals::SiPixelPhase1TrackResiduals(const edm::ParameterSet
validator(iConfig, consumesCollector())
{
offlinePrimaryVerticesToken_ = consumes<reco::VertexCollection>(std::string("offlinePrimaryVertices"));
ApplyVertexCut_=iConfig.getParameter<bool>("VertexCut");
}

void SiPixelPhase1TrackResiduals::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
Expand All @@ -33,15 +34,16 @@ void SiPixelPhase1TrackResiduals::analyze(const edm::Event& iEvent, const edm::E

edm::Handle<reco::VertexCollection> vertices;
iEvent.getByToken(offlinePrimaryVerticesToken_, vertices);
if (!vertices.isValid() || vertices->size() == 0) return;
const auto primaryVertex = vertices->at(0);

if (ApplyVertexCut_ && (!vertices.isValid() || vertices->size() == 0)) return;

std::vector<TrackerValidationVariables::AVTrackStruct> vtracks;

validator.fillTrackQuantities(iEvent, iSetup,
// tell the validator to only look at good tracks
[&](const reco::Track& track) -> bool {
return track.pt() > 0.75
&& std::abs( track.dxy(primaryVertex.position()) ) < 5*track.dxyError();
return (!ApplyVertexCut_ || (track.pt() > 0.75
&& std::abs( track.dxy(vertices->at(0).position()) ) < 5*track.dxyError())) ;
}, vtracks);

for (auto& track : vtracks) {
Expand Down

0 comments on commit 44bc494

Please sign in to comment.