Skip to content

Commit

Permalink
Merge pull request cms-sw#10166 from lveldere/newRecHitContainers_hit…
Browse files Browse the repository at this point in the history
…Mask

New FastSim Tracker RecHit Masking
  • Loading branch information
cmsbuild committed Jul 24, 2015
2 parents a0ff4eb + d6db543 commit 29eb268
Show file tree
Hide file tree
Showing 24 changed files with 597 additions and 476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GSSiTrackerRecHit2DLocalPos : public BaseTrackerRecHit {

void setId(int32_t id) {id_ = id;}
void setEeId(int32_t eeId) {eeId_ = eeId;}
void setHitCombinationId(int32_t hitCombinationId) {hitCombinationId_ = hitCombinationId;}
virtual void setHitCombinationId(int32_t hitCombinationId) {hitCombinationId_ = hitCombinationId;}
void addSimTrackId(int32_t simTrackId) {simTrackIds_.push_back(simTrackId);}
void addSimTrackIds(const std::vector<int32_t> & simTrackIds) {simTrackIds_.insert(simTrackIds_.end(),simTrackIds.begin(),simTrackIds.end());}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class SiTrackerGSMatchedRecHit2D : public GSSiTrackerRecHit2DLocalPos{
const SiTrackerGSRecHit2D & secondHit() const { return stereoHitFirst_ ? componentMono_ : componentStereo_;}
void setStereoLayerFirst(bool stereoHitFirst = true){stereoHitFirst_ = stereoHitFirst;}

void setHitCombinationId(int32_t hitCombinationId){
GSSiTrackerRecHit2DLocalPos::setHitCombinationId(hitCombinationId);
componentMono_.setHitCombinationId(hitCombinationId);
componentStereo_.setHitCombinationId(hitCombinationId);
}

private:

bool isMatched_;
Expand Down
175 changes: 175 additions & 0 deletions FastSimulation/Tracking/plugins/FastTrackingMaskProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// -*- C++ -*-
//
// Package: FastSimulation/FastTrackingMaskProducer
// Class: FastTrackingMaskProducer
//
/**\class FastTrackingMaskProducer FastTrackingMaskProducer.cc FastSimulation/Tracking/plugins/FastTrackingMaskProducer.cc
Description: The class creates two vectors with booleans - hitMasks and hitCombinationMasks. Both of the vectors are filled
with 'false' values unless the id of a specific rechit has to be masked. The number of entry inside a vector represents the
id of a hit.
TODO: Consider implementing Chi2 method ascit is done in the FullSim
*/
//
// Original Author: Vilius Kripas
// Created: Mon, 22 Jun 2015 15:08:57 GMT
//
//
#include <memory>
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/OwnVector.h"
#include "DataFormats/TrackerRecHit2D/interface/SiTrackerGSRecHit2DCollection.h"
#include "DataFormats/TrackerRecHit2D/interface/SiTrackerGSMatchedRecHit2DCollection.h"
#include "DataFormats/TrackerRecHit2D/interface/SiTrackerGSRecHit2D.h"
#include "DataFormats/TrackerRecHit2D/interface/SiTrackerGSMatchedRecHit2D.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "FastSimulation/Tracking/plugins/FastTrackingMaskProducer.h"
#include <vector>
#include <stdio.h>

FastTrackingMaskProducer::FastTrackingMaskProducer(const edm::ParameterSet& conf)
: oldHitMasks_exists_(false)
, oldHitCombinationMasks_exists_(false)
, overRideTrkQuals_(false)
, filterTracks_(false)
{
// Main products
produces<std::vector<bool> >("hitMasks");
produces<std::vector<bool> >("hitCombinationMasks");

// Track collection
edm::InputTag trackCollectionTag = conf.getParameter<edm::InputTag>("trackCollection");
trackToken_ = consumes<reco::TrackCollection>(trackCollectionTag);

// old hit masks
oldHitMasks_exists_ = conf.exists("oldHitMasks");
if (oldHitMasks_exists_){
edm::InputTag hitMasksTag = conf.getParameter<edm::InputTag>("oldHitMasks");
hitMasksToken_ = consumes<std::vector<bool> >(hitMasksTag);
}

// old hit combination masks
oldHitCombinationMasks_exists_ = conf.exists("oldHitCombinationMasks");
if ( oldHitCombinationMasks_exists_){
edm::InputTag hitCombinationMasksTag = conf.getParameter<edm::InputTag>("oldHitCombinationMasks");
hitCombinationMasksToken_ = consumes<std::vector<bool> >(hitCombinationMasksTag);
}

// read track quality from value map rather than from track itself
overRideTrkQuals_ = conf.exists("overrideTrkQuals");
if( overRideTrkQuals_ ){
edm::InputTag trkQualsTag = conf.getParameter<edm::InputTag>("overrideTrkQuals");
if(trkQualsTag == edm::InputTag(""))
overRideTrkQuals_ = false;
else
trkQualsToken_ = consumes<edm::ValueMap<int> >(trkQualsTag);
}

// required track quality
trackQuality_=reco::TrackBase::undefQuality;
if (conf.exists("TrackQuality")){
filterTracks_=true;
std::string trackQualityStr = conf.getParameter<std::string>("TrackQuality");
if ( !trackQualityStr.empty() ) {
trackQuality_=reco::TrackBase::qualityByName(trackQualityStr);
}
}
}

void
FastTrackingMaskProducer::produce(edm::Event& e, const edm::EventSetup& es)
{
// the products
std::auto_ptr<std::vector<bool> > hitMasks(new std::vector<bool>());
std::auto_ptr<std::vector<bool> > hitCombinationMasks(new std::vector<bool>());

// The input track collection handle
edm::Handle<reco::TrackCollection> trackCollection;
e.getByToken(trackToken_,trackCollection);

// the track quality collection
edm::Handle<edm::ValueMap<int> > quals;
if ( overRideTrkQuals_ ) {
e.getByToken(trkQualsToken_,quals);
}

// The input hitMasks handle
if (oldHitMasks_exists_ == true){
edm::Handle<std::vector<bool> > oldHitMasks;
e.getByToken(hitMasksToken_,oldHitMasks);
hitMasks->insert(hitMasks->begin(),oldHitMasks->begin(),oldHitMasks->end());
}

// The input hitCombinationMasks handle
if (oldHitCombinationMasks_exists_ == true){
edm::Handle<std::vector<bool> > oldHitCombinationMasks;
e.getByToken(hitCombinationMasksToken_,oldHitCombinationMasks);
hitCombinationMasks->insert(hitCombinationMasks->begin(),oldHitCombinationMasks->begin(),oldHitCombinationMasks->end());
}

int ngood = 0;
for (size_t i = 0 ; i!=trackCollection->size();++i)
{


const reco::Track & track = trackCollection->at(i);
reco::TrackRef trackRef(trackCollection,i);
if (filterTracks_) {
bool goodTk = true;

if ( overRideTrkQuals_ ) {
int qual= (*quals)[trackRef];
if ( qual < 0 ){
goodTk=false;
}
else
goodTk = ( qual & (1<<trackQuality_))>>trackQuality_;
}
else {
goodTk=(track.quality(trackQuality_));
}
if ( !goodTk) continue;
}
ngood++;


// Loop over the recHits
// todo: implement the minimum number of measurements criterium
// see http://cmslxr.fnal.gov/lxr/source/RecoLocalTracker/SubCollectionProducers/src/TrackClusterRemover.cc#0166
for (auto hitIt = track.recHitsBegin() ; hitIt != track.recHitsEnd(); ++hitIt) {

if(!(*hitIt)->isValid())
continue;

const GSSiTrackerRecHit2DLocalPos * hit = dynamic_cast<const GSSiTrackerRecHit2DLocalPos*>(*hitIt);
if(hit){
uint32_t hitCombination_id = hit->hitCombinationId();
if (hitCombination_id >= hitCombinationMasks->size()) {
hitCombinationMasks->resize(hitCombination_id+1,false);
}
hitCombinationMasks->at(hitCombination_id) = true;

/* TODO implement hit id properly
uint32_t hit_id = hit->id();
if (hit_id >= hitMasks->size()) {
hitMasks->resize(hit_id+1,false);
}
hitMasks->at(hit_id) = true;
*/
}

else{
continue;
// TODO: find out why the cast doesn't work every so many hits
}
}
}

e.put(hitMasks,"hitMasks");
e.put(hitCombinationMasks,"hitCombinationMasks");
}

54 changes: 54 additions & 0 deletions FastSimulation/Tracking/plugins/FastTrackingMaskProducer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef FastSimulation_Tracking_FastTrackingMaskProducer_h
#define FastSimulation_Tracking_FastTrackingMaskProducer_h

#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/TrackReco/interface/Track.h"


#include <vector>
#include <string>

namespace edm {
class ParameterSet;
class Event;
class EventSetup;
}

class FastTrackingMaskProducer : public edm::stream::EDProducer <>
{
public:

explicit FastTrackingMaskProducer(const edm::ParameterSet& conf);

virtual ~FastTrackingMaskProducer() {}

virtual void produce(edm::Event& e, const edm::EventSetup& es) override;


private:



// consumes
edm::EDGetTokenT<reco::TrackCollection> trackToken_;
edm::EDGetTokenT<std::vector<bool> > hitMasksToken_;
edm::EDGetTokenT<std::vector<bool> > hitCombinationMasksToken_;
edm::EDGetTokenT<edm::ValueMap<int> > trkQualsToken_;
// set value in constructor
bool oldHitMasks_exists_;
bool oldHitCombinationMasks_exists_;
bool overRideTrkQuals_;
bool filterTracks_;
reco::TrackBase::TrackQuality trackQuality_;

};

#endif






5 changes: 2 additions & 3 deletions FastSimulation/Tracking/plugins/SealModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
#include "FastSimulation/Tracking/plugins/TrajectorySeedProducer.h"
#include "FastSimulation/Tracking/plugins/TrackCandidateProducer.h"
#include "FastSimulation/Tracking/plugins/PixelTracksProducer.h"
#include "FastSimulation/Tracking/plugins/SimTrackIdProducer.h"
#include "FastSimulation/Tracking/plugins/FastTrackingMaskProducer.h"
#include "FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h"
#include "FastSimulation/Tracking/plugins/ConversionTrackRefFix.h"
// reco::Track accumulator:
#include "SimGeneral/MixingModule/interface/DigiAccumulatorMixModFactory.h"
#include "FastSimulation/Tracking/plugins/RecoTrackAccumulator.h"


DEFINE_FWK_MODULE(FastTrackingMaskProducer);
DEFINE_FWK_MODULE(TrajectorySeedProducer);
DEFINE_FWK_MODULE(ElectronSeedTrackRefFix);
DEFINE_FWK_MODULE(TrackCandidateProducer);
DEFINE_FWK_MODULE(PixelTracksProducer);
DEFINE_FWK_MODULE(SimTrackIdProducer);
DEFINE_FWK_MODULE(ConversionTrackRefFix);
DEFINE_DIGI_ACCUMULATOR(RecoTrackAccumulator);
109 changes: 0 additions & 109 deletions FastSimulation/Tracking/plugins/SimTrackIdProducer.cc

This file was deleted.

Loading

0 comments on commit 29eb268

Please sign in to comment.