Skip to content

Commit

Permalink
edm::Ref implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin committed Oct 25, 2021
1 parent ad3445c commit 16d833a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
20 changes: 13 additions & 7 deletions DataFormats/MuonReco/interface/MuonShowerRechitCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@

#include <vector>
#include "DataFormats/Common/interface/SortedCollection.h"
#include "DataFormats/Common/interface/Ptr.h"
#include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
#include "DataFormats/Common/interface/RangeMap.h"

#include <DataFormats/MuonDetId/interface/CSCDetId.h>
#include <DataFormats/CSCRecHit/interface/CSCRecHit2D.h>
#include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
#include "DataFormats/DetId/interface/DetId.h"

namespace reco {

class MuonShowerRechitCluster {
public:
//TODO: think about how to keep the constituents for both CSC/DT rechits
typedef edm::Ptr<TrackingRecHit> Constituent;
typedef std::vector<Constituent> Constituents;
typedef edm::RangeMap <CSCDetId, edm::OwnVector<CSCRecHit2D> > rechitCollection;
typedef edm::Ref<rechitCollection> rechitRef;
typedef std::vector<rechitRef> rechits;

//default constructor
MuonShowerRechitCluster():eta_(0.),phi_(0.),x_(0.),y_(0.),z_(0.),time_(-999.),size_(0),nME11_12_(0){}
Expand All @@ -31,7 +35,8 @@ namespace reco {
float time() const {return time_;}
int size() const {return size_;}
int nME11_12() const {return nME11_12_;}
void addDaughter(const Constituent &);
void addDaughter(const rechitRef &);
rechits getConstituents(){return rechits_;}

private:
double eta_;
Expand All @@ -42,12 +47,13 @@ namespace reco {
float time_;
int size_;
int nME11_12_;
Constituents rechits_;
rechits rechits_;

};
inline void MuonShowerRechitCluster::addDaughter( const Constituent & cand ) {
inline void MuonShowerRechitCluster::addDaughter( const rechitRef & cand ) {
rechits_.push_back( cand );
}

typedef std::vector<MuonShowerRechitCluster> MuonShowerRechitClusterCollection;
}
#endif
46 changes: 19 additions & 27 deletions RecoMuon/MuonShowerProducer/plugins/CSCRechitClusterProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
//
// class declaration
//
typedef edm::Ref<CSCRecHit2DCollection> rechitRef;
typedef std::vector<rechitRef> rechits;

class CSCRechitClusterProducer : public edm::stream::EDProducer<> {
public:
Expand All @@ -66,12 +68,9 @@ class CSCRechitClusterProducer : public edm::stream::EDProducer<> {
protected:

double rParam_ ; // distance paramter
//std::string jetAlgorithm_; // jetAlgorithm
int nRechitMin_; // min number of rechits
//std::vector<edm::Ptr<CSCRecHit2D> > inputs_;
//std::vector<edm::Ptr<CSCRecHit2D> > getConstituents(const std::vector<fastjet::PseudoJet>& fjConstituents);
std::vector<CSCRecHit2D > inputs_;
std::vector<CSCRecHit2D > getConstituents(const std::vector<fastjet::PseudoJet>& fjConstituents);
std::vector<rechitRef> inputs_;
std::vector<rechitRef> getConstituents(const std::vector<fastjet::PseudoJet>& fjConstituents);

};

Expand All @@ -91,7 +90,6 @@ CSCRechitClusterProducer::CSCRechitClusterProducer(const edm::ParameterSet& iCon
{

rParam_ = iConfig.getParameter<double>("rParam");
//jetAlgorithm_ = iConfig.getParameter<std::string>("jetAlgorithm");
nRechitMin_ = iConfig.getParameter<int>("nRechitMin");

cscRechitInputToken_ = consumes<CSCRecHit2DCollection>(edm::InputTag("csc2DRecHits")),
Expand Down Expand Up @@ -126,9 +124,10 @@ CSCRechitClusterProducer::produce(edm::Event& ev, const edm::EventSetup& iSetup)
int nRecHits = cscRechits->size();
CSCRecHit2DCollection::const_iterator recIt;

// for (size_t i=0; i< cscRechits->size(); ++i) {
// inputs_.push_back( (*cscRechits)[i] );
// }

inputs_.clear();
fjInput.clear();

for (recIt = cscRechits->begin(); recIt != cscRechits->end(); recIt++) {
auto cscRechit = (*recIt);
LocalPoint cscRecHitLocalPosition = cscRechit.localPosition();
Expand All @@ -139,10 +138,8 @@ CSCRechitClusterProducer::produce(edm::Event& ev, const edm::EventSetup& iSetup)
float x = globalPosition.x();
float y = globalPosition.y();
float z = globalPosition.z();
//TODO: Find a way to construct edm::Ptr
//edm::Ptr<CSCRecHit2D> ptr = edm::Ptr<CSCRecHit2D>(&cscRechit);
//inputs_.push_back( ptr );
inputs_.push_back( cscRechit );
rechitRef csc_ref = rechitRef(cscRechits, recIt-cscRechits->begin());
inputs_.push_back( csc_ref );
fjInput.push_back(fastjet::PseudoJet( x, y, z, 1.0));
fjInput.back().set_user_index(recIt-cscRechits->begin());
}
Expand All @@ -159,25 +156,23 @@ CSCRechitClusterProducer::produce(edm::Event& ev, const edm::EventSetup& iSetup)
// get the fastjet jet
const fastjet::PseudoJet& fjJet = fjJets[ijet];

//std::cout<<"CSCrechitCluster" << " fjJet size = " << (fjJet.constituents().size()) <<std::endl;
// skip if the cluster has too few rechits
if (int(fjJet.constituents().size()) < nRechitMin_) continue;
// get the constituents from fastjet
std::vector<fastjet::PseudoJet> const& fjConstituents = fastjet::sorted_by_pt(fjJet.constituents());

std::vector<CSCRecHit2D > const& rechits = getConstituents(fjConstituents);
std::vector<rechitRef > const& rechits = getConstituents(fjConstituents);

//Derive cluster properties
float time=0.0;float eta=0.0;float phi=0.0;
float x=0.0;float y=0.0;float z=0.0;
int nME11_12 =0;
//std::cout<<"CSCrechitCluster" << " rec time = [" ;
for (auto & rechit : rechits){

//LocalPoint cscRecHitLocalPosition = (*rechit).localPosition();
//CSCDetId cscdetid = (*rechit).cscDetId();
LocalPoint cscRecHitLocalPosition = rechit.localPosition();
CSCDetId cscdetid = rechit.cscDetId();
LocalPoint cscRecHitLocalPosition = rechit->localPosition();
CSCDetId cscdetid = rechit->cscDetId();
const CSCChamber* cscchamber = cscG->chamber(cscdetid());
int endcap = CSCDetId::endcap(cscdetid) == 1 ? 1 : -1;
GlobalPoint globalPosition = cscchamber->toGlobal(cscRecHitLocalPosition);
Expand All @@ -186,10 +181,8 @@ CSCRechitClusterProducer::produce(edm::Event& ev, const edm::EventSetup& iSetup)
z += globalPosition.z();
int chamber = endcap * (CSCDetId::station(cscdetid)*10 + CSCDetId::ring(cscdetid));
if( abs(chamber)==11 || abs(chamber)==12) nME11_12++;
time+= (rechit.tpeak() + rechit.wireTime());
//std::cout<< "("<<rechit.tpeak() <<","<< rechit.wireTime()<<") ";
time+= (rechit->tpeak() + rechit->wireTime());
}
//std::cout<< "] ";
x = x/rechits.size();
y = y/rechits.size();
z = z/rechits.size();
Expand All @@ -210,9 +203,9 @@ CSCRechitClusterProducer::produce(edm::Event& ev, const edm::EventSetup& iSetup)
//std::cout<<"CSCrechitCluster" << " cls eta = " << (cls.eta()) <<std::endl;
//std::cout<<"CSCrechitCluster" << " cls phi = " << (cls.phi()) <<std::endl;

//for (auto & rechit : rechits){
// cls.addDaughter(rechit);
//}
for (auto & rechit : rechits){
cls.addDaughter(rechit);
}

CSCclusters->push_back(cls);
}
Expand All @@ -221,10 +214,9 @@ CSCRechitClusterProducer::produce(edm::Event& ev, const edm::EventSetup& iSetup)

}

std::vector<CSCRecHit2D > CSCRechitClusterProducer::getConstituents(const std::vector<fastjet::PseudoJet>& fjConstituents) {
std::vector<rechitRef > CSCRechitClusterProducer::getConstituents(const std::vector<fastjet::PseudoJet>& fjConstituents) {

std::vector<CSCRecHit2D> result;
//result.reserve(fjConstituents.size() / 2);
std::vector<rechitRef> result;
for (unsigned int i = 0; i < fjConstituents.size(); i++) {
auto index = fjConstituents[i].user_index();
if (index >= 0 && static_cast<unsigned int>(index) < inputs_.size()) {
Expand Down

0 comments on commit 16d833a

Please sign in to comment.