Skip to content

Commit

Permalink
addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Harper committed May 3, 2017
1 parent 44f047e commit 7399f9b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 33 deletions.
33 changes: 15 additions & 18 deletions DataFormats/EgammaReco/interface/ElectronSeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ namespace reco
int layerOrDiskNr;//redundant as stored in detId but its a huge pain to hence why its saved here

PMVars();
void setDPhi(float pos,float neg){dPhiPos=pos;dPhiNeg=neg;}
void setDRZ(float pos,float neg){dRZPos=pos;dRZNeg=neg;}
void setDet(int iDetId,int iLayerOrDiskNr){detId=iDetId;layerOrDiskNr=iLayerOrDiskNr;}


void setDPhi(float pos,float neg);
void setDRZ(float pos,float neg);
void setDet(int iDetId,int iLayerOrDiskNr);

};


typedef edm::OwnVector<TrackingRecHit> RecHitContainer ;
typedef edm::RefToBase<CaloCluster> CaloClusterRef ;
typedef edm::Ref<TrackCollection> CtfTrackRef ;

static std::string const & name()
{
static std::string const name_("ElectronSeed") ;
Expand Down Expand Up @@ -126,8 +127,8 @@ namespace reco
float dRz2Pos()const{return dRZPos(1);}
int subDet1()const{return subDet(0);}
int subDet2()const{return subDet(1);}
int hitsMask()const;
void initTwoHitSeed(const char hitMask);
unsigned int hitsMask()const;
void initTwoHitSeed(const unsigned char hitMask);
void setNegAttributes(const float dRZ2=std::numeric_limits<float>::infinity(),
const float dPhi2=std::numeric_limits<float>::infinity(),
const float dRZ1=std::numeric_limits<float>::infinity(),
Expand All @@ -137,16 +138,6 @@ namespace reco
const float dRZ1=std::numeric_limits<float>::infinity(),
const float dPhi1=std::numeric_limits<float>::infinity());



private:
static float bestVal(float val1,float val2){return std::abs(val1)<std::abs(val2) ? val1 : val2;}
template<typename T>
T getVal(size_t hitNr,T PMVars::*val)const{
return hitNr<hitInfo_.size() ? hitInfo_[hitNr].*val : std::numeric_limits<T>::infinity();
}
static std::vector<size_t> hitNrsFromMask(size_t hitMask);
public:
//this is a backwards compatible function designed to
//convert old format ElectronSeeds to the new format
//only public due to root io rules, not intended for any other use
Expand All @@ -156,9 +147,15 @@ namespace reco
const float dPhi2Pos,const float dPhi2Neg,
const float dRZ2Pos,const float dRZ2Neg,
const char hitMask,const TrajectorySeed::range recHits);
private:
static float bestVal(float val1,float val2){return std::abs(val1)<std::abs(val2) ? val1 : val2;}
template<typename T>
T getVal(unsigned int hitNr,T PMVars::*val)const{
return hitNr<hitInfo_.size() ? hitInfo_[hitNr].*val : std::numeric_limits<T>::infinity();
}
static std::vector<unsigned int> hitNrsFromMask(unsigned int hitMask);

private:

CtfTrackRef ctfTrack_;
CaloClusterRef caloCluster_;
std::vector<PMVars> hitInfo_;
Expand Down
66 changes: 53 additions & 13 deletions DataFormats/EgammaReco/src/ElectronSeed.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include "DataFormats/EgammaReco/interface/ElectronSeed.h"

#include <climits>

using namespace reco ;

Expand Down Expand Up @@ -38,8 +39,9 @@ void ElectronSeed::setCtfTrack
}

//the hit mask tells us which hits were used in the seed
//typically all are used but this could change in the future
int ElectronSeed::hitsMask()const
//typically all are used at the HLT but this could change in the future
//RECO only uses some of them
unsigned int ElectronSeed::hitsMask()const
{
int mask=0;
for(size_t hitNr=0;hitNr<nHits();hitNr++){
Expand All @@ -53,16 +55,25 @@ int ElectronSeed::hitsMask()const
return mask;
}

void ElectronSeed::initTwoHitSeed(const char hitMask)
void ElectronSeed::initTwoHitSeed(const unsigned char hitMask)
{
hitInfo_.resize(2);

std::vector<size_t> hitNrs = hitNrsFromMask(hitMask);
std::vector<unsigned int> hitNrs = hitNrsFromMask(hitMask);
if(hitNrs.size()!=2){
throw cms::Exception("LogicError") <<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__<<": number of hits in hit mask is "<<hitNrs.size()<<", pre-2017 pixel upgrade ecalDriven ElectronSeeds should have exactly 2"<<" mask "<<static_cast<int>(hitMask)<<std::endl;
throw cms::Exception("LogicError")
<<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__
<<": number of hits in hit mask is "<<hitNrs.size()<<"\n"
<<"pre-2017 pixel upgrade ecalDriven ElectronSeeds should have exactly 2 hits\n "
<<"mask "<<static_cast<unsigned int>(hitMask)<<std::endl;
}
if(hitNrs[0]>=nHits() || hitNrs[1]>=nHits()){
throw cms::Exception("LogicError") <<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__<<": hits are "<<hitNrs[0]<<" and "<<hitNrs[1]<<" while number of hits are, this means there was a bug in storing or creating the electron seeds "<<nHits();
throw cms::Exception("LogicError")
<<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__
<<": hits are "<<hitNrs[0]<<" and "<<hitNrs[1]
<<" while number of hits are "<<nHits()<<"\n"
<<"this means there was a bug in storing or creating the electron seeds "
<<"mask "<<static_cast<unsigned int>(hitMask)<<std::endl;
}
for(size_t hitNr=0;hitNr<hitInfo_.size();hitNr++){
auto& info = hitInfo_[hitNr];
Expand Down Expand Up @@ -96,11 +107,11 @@ void ElectronSeed::setPosAttributes(float dRZ2,float dPhi2,float dRZ1,float dPhi
hitInfo_[1].dPhiPos = dPhi2;
}

std::vector<size_t>
ElectronSeed::hitNrsFromMask(size_t hitMask)
std::vector<unsigned int>
ElectronSeed::hitNrsFromMask(unsigned int hitMask)
{
std::vector<size_t> hitNrs;
for(size_t bitNr=0;bitNr<sizeof(hitMask);bitNr++){
std::vector<unsigned int> hitNrs;
for(size_t bitNr=0; bitNr<sizeof(hitMask)*CHAR_BIT ; bitNr++){
char bit = 0x1 << bitNr;
if((hitMask&bit)!=0) hitNrs.push_back(bitNr);
}
Expand All @@ -117,13 +128,22 @@ ElectronSeed::createHitInfo(const float dPhi1Pos,const float dPhi1Neg,
if(hitMask==0) return std::vector<ElectronSeed::PMVars>(); //was trackerDriven so no matched hits

size_t nrRecHits = std::distance(recHits.first,recHits.second);
std::vector<size_t> hitNrs = hitNrsFromMask(hitMask);
std::vector<unsigned int> hitNrs = hitNrsFromMask(hitMask);

if(hitNrs.size()!=2){
throw cms::Exception("LogicError") <<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__<<": number of hits in hit mask is "<<nrRecHits<<", pre-2017 pixel upgrade ecalDriven ElectronSeeds should have exactly 2, mask "<<static_cast<int>(hitMask)<<std::endl;
throw cms::Exception("LogicError")
<<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__
<<": number of hits in hit mask is "<<nrRecHits<<"\n"
<<"pre-2017 pixel upgrade ecalDriven ElectronSeeds should have exactly 2 hits\n"
<<"mask "<<static_cast<unsigned int>(hitMask)<<std::endl;
}
if(hitNrs[0]>=nrRecHits || hitNrs[1]>=nrRecHits){
throw cms::Exception("LogicError") <<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__<<": hits are "<<hitNrs[0]<<" and "<<hitNrs[1]<<" while number of hits are "<<nrRecHits<<" this means there was a bug in storing or creating the electron seeds, hit mask :"<<static_cast<int>(hitMask)<<std::endl;
throw cms::Exception("LogicError")
<<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__
<<": hits are "<<hitNrs[0]<<" and "<<hitNrs[1]
<<" while number of hits are "<<nrRecHits<<"\n"
<<"this means there was a bug in storing or creating the electron seeds "
<<"mask "<<static_cast<unsigned int>(hitMask)<<std::endl;
}

std::vector<PMVars> hitInfo(2);
Expand All @@ -147,4 +167,24 @@ ElectronSeed::PMVars::PMVars():
layerOrDiskNr(-1)
{}

void ElectronSeed::PMVars::setDPhi(float pos,float neg)
{
dPhiPos = pos;
dPhiNeg = neg;
}

void ElectronSeed::PMVars::setDRZ(float pos,float neg)
{
dRZPos = pos;
dRZNeg = neg;
}

void ElectronSeed::PMVars::setDet(int iDetId,int iLayerOrDiskNr)
{
detId = iDetId;
layerOrDiskNr = iLayerOrDiskNr;
}




4 changes: 2 additions & 2 deletions DataFormats/EgammaReco/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
<ioread sourceClass="reco::ElectronSeed" version="[1-12]" targetClass="reco::ElectronSeed" source="float dRz2_; float dPhi2_; float dRz2Pos_; float dPhi2Pos_; float dRz1_; float dPhi1_; float dRz1Pos_; float dPhi1Pos_; unsigned char hitsMask_;" target="hitInfo_">
<![CDATA[hitInfo_ = reco::ElectronSeed::createHitInfo(onfile.dPhi1Pos_,onfile.dPhi1_,onfile.dRz1Pos_,onfile.dRz1_,onfile.dPhi2Pos_,onfile.dPhi2_,onfile.dRz2Pos_,onfile.dRz2_,onfile.hitsMask_,newObj->recHits());]]>
</ioread>
<class name="reco::ElectronSeed::PMVars" ClassVersion="10">
<version ClassVersion="10" checksum="1322802316"/>
<class name="reco::ElectronSeed::PMVars" ClassVersion="3">
<version ClassVersion="3" checksum="1322802316"/>
</class>

<class name="std::vector<reco::ElectronSeed>"/>
Expand Down

0 comments on commit 7399f9b

Please sign in to comment.