Skip to content

Commit

Permalink
updated to consumes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shervin committed May 2, 2015
1 parent f699022 commit e954882
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 116 deletions.
172 changes: 74 additions & 98 deletions Calibration/EcalAlCaRecoProducers/plugins/AlCaElectronTracksReducer.cc
Original file line number Diff line number Diff line change
@@ -1,98 +1,74 @@
#include "Calibration/EcalAlCaRecoProducers/plugins/AlCaElectronTracksReducer.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"

#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"

//#define ALLrecHits
//#define DEBUG

//#define QUICK -> if commented loop over the recHits of the SC and add them to the list of recHits to be saved
// comment it if you want a faster module but be sure the window is large enough

AlCaElectronTracksReducer::AlCaElectronTracksReducer(const edm::ParameterSet& iConfig)
{

//gsfTracksLabel_ = iConfig.getParameter< edm::InputTag > ("gsfTracksLabel");
generalTracksLabel_ = iConfig.getParameter< edm::InputTag > ("generalTracksLabel");
generalTracksExtraLabel_ = iConfig.getParameter< edm::InputTag > ("generalTracksExtraLabel");
electronLabel_ = iConfig.getParameter< edm::InputTag > ("electronLabel");

// name of the output collection
//gsfTracksCollection_ = iConfig.getParameter<std::string>("gsfTracksCollection");
alcaTrackExtraCollection_ = iConfig.getParameter<std::string>("alcaTrackExtraCollection");

//register your products
produces< reco::TrackCollection > (alcaTrackCollection_) ;
produces< reco::TrackExtraCollection > (alcaTrackExtraCollection_) ;

}


AlCaElectronTracksReducer::~AlCaElectronTracksReducer()
{}


// ------------ method called to produce the data ------------
void AlCaElectronTracksReducer::produce (edm::Event& iEvent,
const edm::EventSetup& iSetup)
{
using namespace edm;
using namespace std;
using namespace reco;

// get the ECAL geometry:
// ESHandle<CaloGeometry> geoHandle;
// iSetup.get<CaloGeometryRecord>().get(geoHandle);

// edm::ESHandle<CaloTopology> theCaloTopology;
// iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
// const CaloTopology *caloTopology = theCaloTopology.product();

// Get GSFElectrons
Handle<reco::GsfElectronCollection> pElectrons;
iEvent.getByLabel(electronLabel_, pElectrons);
// if (!pElectrons.isValid()) {
// edm::LogError ("reading") << electronLabel_ << " not found" ;
// return ;
// }

const reco::GsfElectronCollection * electronCollection =
pElectrons.product();

Handle<TrackCollection> generalTracksHandle;
iEvent.getByLabel(generalTracksLabel_,generalTracksHandle);

Handle<TrackExtraCollection> generalTracksExtraHandle;
iEvent.getByLabel(generalTracksExtraLabel_,generalTracksExtraHandle);

//Create empty output collections
std::auto_ptr< TrackCollection > redGeneralTracksCollection (new TrackCollection) ;
std::auto_ptr< TrackExtraCollection > redGeneralTracksExtraCollection (new TrackExtraCollection) ;

reco::GsfElectronCollection::const_iterator eleIt;

for (eleIt=electronCollection->begin(); eleIt!=electronCollection->end(); eleIt++) {
// barrel
#ifndef CMSSW42X
TrackRef track = (eleIt-> closestTrack() ) ;
#else
TrackRef track = (eleIt-> closestCtfTrackRef());
#endif
if(track.isNull()){
// edm::LogError("track") << "Track Ref not found " << eleIt->energy() << "\t" << eleIt->eta();
continue;
}
redGeneralTracksCollection->push_back(*track);
if(generalTracksExtraHandle.isValid()) redGeneralTracksExtraCollection->push_back(*(track->extra()));
}

//Put selected information in the event
iEvent.put( redGeneralTracksCollection, alcaTrackCollection_ );
iEvent.put( redGeneralTracksExtraCollection, alcaTrackExtraCollection_ );
}


DEFINE_FWK_MODULE(AlCaElectronTracksReducer);

#include "Calibration/EcalAlCaRecoProducers/plugins/AlCaElectronTracksReducer.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"

AlCaElectronTracksReducer::AlCaElectronTracksReducer(const edm::ParameterSet& iConfig)
{
generalTracksToken_ = consumes<reco::TrackCollection>(iConfig.getParameter< edm::InputTag > ("generalTracksLabel"));
generalTracksExtraToken_ = consumes<reco::TrackExtraCollection>(iConfig.getParameter< edm::InputTag > ("generalTracksExtraLabel"));
electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter< edm::InputTag > ("electronLabel"));

// name of the output collection
alcaTrackExtraCollection_ = iConfig.getParameter<std::string>("alcaTrackExtraCollection");

//register your products
produces< reco::TrackCollection > (alcaTrackCollection_) ;
produces< reco::TrackExtraCollection > (alcaTrackExtraCollection_) ;

}


AlCaElectronTracksReducer::~AlCaElectronTracksReducer()
{}


// ------------ method called to produce the data ------------
void AlCaElectronTracksReducer::produce (edm::Event& iEvent,
const edm::EventSetup& iSetup)
{
using namespace edm;
using namespace std;
using namespace reco;


// Get GSFElectrons
Handle<reco::GsfElectronCollection> pElectrons;
iEvent.getByToken(electronToken_, pElectrons);

const reco::GsfElectronCollection * electronCollection = pElectrons.product();

Handle<TrackCollection> generalTracksHandle;
iEvent.getByToken(generalTracksToken_,generalTracksHandle);

Handle<TrackExtraCollection> generalTracksExtraHandle;
iEvent.getByToken(generalTracksExtraToken_,generalTracksExtraHandle);

//Create empty output collections
std::auto_ptr< TrackCollection > redGeneralTracksCollection (new TrackCollection) ;
std::auto_ptr< TrackExtraCollection > redGeneralTracksExtraCollection (new TrackExtraCollection) ;

reco::GsfElectronCollection::const_iterator eleIt;

for (eleIt=electronCollection->begin(); eleIt!=electronCollection->end(); eleIt++) {
// barrel
#ifndef CMSSW42X
TrackRef track = (eleIt-> closestTrack() ) ;
#else
TrackRef track = (eleIt-> closestCtfTrackRef());
#endif
if(track.isNull()){
// edm::LogError("track") << "Track Ref not found " << eleIt->energy() << "\t" << eleIt->eta();
continue;
}
redGeneralTracksCollection->push_back(*track);
if(generalTracksExtraHandle.isValid()) redGeneralTracksExtraCollection->push_back(*(track->extra()));
}

//Put selected information in the event
iEvent.put( redGeneralTracksCollection, alcaTrackCollection_ );
iEvent.put( redGeneralTracksExtraCollection, alcaTrackExtraCollection_ );
}


DEFINE_FWK_MODULE(AlCaElectronTracksReducer);

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
//
/**\class AlCaECALRecHitReducer AlCaECALRecHitReducer.cc Calibration/EcalAlCaRecoProducers/src/AlCaECALRecHitReducer.cc
Description: Example of a producer of AlCa electrons
Implementation:
<Notes on implementation>
Description: This plugin saves tracks and trackExtras that are associated to an electron creating two new track and track extra collections
*/
//
// Original Author: Shervin Nourbakhsh
// Created: Sat Feb 23 10:07:01 CEST 2013
// $Id: AlCaElectronTracksReducer.h,v 1.00 2013/02/23 10:10:34 shervin Exp $
//
//


// system include files
Expand All @@ -34,21 +30,28 @@
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

// input collections
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/TrackReco/interface/TrackExtraFwd.h"

class AlCaElectronTracksReducer : public edm::EDProducer {
public:
//! ctor

explicit AlCaElectronTracksReducer(const edm::ParameterSet&);
~AlCaElectronTracksReducer();

virtual void produce(edm::Event &, const edm::EventSetup&);
private:

private:
// ----------member data ---------------------------
// input collections
edm::EDGetTokenT<reco::GsfElectronCollection> electronToken_;
edm::EDGetTokenT<reco::TrackCollection> generalTracksToken_;
edm::EDGetTokenT<reco::TrackExtraCollection> generalTracksExtraToken_;

edm::InputTag electronLabel_;
edm::InputTag generalTracksLabel_;
// output collection' names
std::string alcaTrackCollection_;
edm::InputTag generalTracksExtraLabel_;
std::string alcaTrackExtraCollection_;

};
Expand Down
6 changes: 3 additions & 3 deletions Calibration/EcalAlCaRecoProducers/plugins/PUDumper.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "Calibration/EcalAlCaRecoProducers/plugins/PUDumper.h"



//! ctor
PUDumper::PUDumper(const edm::ParameterSet& iConfig)
{
// MCPileupTag_ = iConfig.getParameter<edm::InputTag>("MCPileupTag");

pileupSummaryToken_ = consumes<std::vector<PileupSummaryInfo> >(iConfig.getParameter<edm::InputTag>("pileupSummary"));

// create TTree
edm::Service<TFileService> fs;
PUTree_ = fs -> make<TTree>("pileup","pileup");
Expand Down Expand Up @@ -39,7 +39,7 @@ void PUDumper::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
// get the PU collection
edm::Handle<std::vector<PileupSummaryInfo> > PupInfo;
if( !iEvent.isRealData() ){
iEvent.getByLabel(edm::InputTag("addPileupInfo"), PupInfo); ///\todo put it in the cfi!
iEvent.getByToken(pileupSummaryToken_, PupInfo);
} else return;


Expand Down
11 changes: 7 additions & 4 deletions Calibration/EcalAlCaRecoProducers/plugins/PUDumper.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#ifndef PUDumper_h
#define PUDumper_h

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"

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

#include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"

#include "TTree.h"



class PUDumper : public edm::EDAnalyzer
{
public:
Expand All @@ -36,7 +37,9 @@ class PUDumper : public edm::EDAnalyzer


private:


edm::EDGetTokenT< std::vector<PileupSummaryInfo> > pileupSummaryToken_;

//edm::InputTag MCPileupTag_;

TTree* PUTree_;
Expand Down
1 change: 1 addition & 0 deletions Calibration/EcalAlCaRecoProducers/python/PUDumper_cfi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import FWCore.ParameterSet.Config as cms

PUDumper = cms.EDAnalyzer('PUDumper',
pileupSummary = cms.InputTag("addPileupInfo"),
# vertexCollection = cms.InputTag('offlinePrimaryVertices'),
# foutName = cms.string("ZShervinNtuple.root"),
)

0 comments on commit e954882

Please sign in to comment.