CMS 3D CMS Logo

ElectronSeed.cc
Go to the documentation of this file.
1 
3 
4 #include <climits>
5 
6 using namespace reco ;
7 
8 
10  : TrajectorySeed(), ctfTrack_(), caloCluster_(), hitInfo_(),
11  nrLayersAlongTraj_(0),
12  isEcalDriven_(false), isTrackerDriven_(false)
13 
14 {}
15 
17 ( const TrajectorySeed & seed )
18  : TrajectorySeed(seed),
21  isEcalDriven_(false), isTrackerDriven_(false)
22 {}
23 
26  : TrajectorySeed(pts,rh,dir),
29  isEcalDriven_(false), isTrackerDriven_(false)
30 {}
31 
33 
35 ( const CtfTrackRef & ctfTrack )
36 {
39 }
40 
41 //the hit mask tells us which hits were used in the seed
42 //typically all are used at the HLT but this could change in the future
43 //RECO only uses some of them
44 unsigned int ElectronSeed::hitsMask()const
45 {
46  int mask=0;
47  for(size_t hitNr=0;hitNr<nHits();hitNr++){
48  int bitNr = 0x1 << hitNr;
49  int hitDetId = (recHits().first+hitNr)->geographicalId().rawId();
50  auto detIdMatcher = [hitDetId](const ElectronSeed::PMVars& var){return hitDetId==var.detId;};
51  if(std::find_if(hitInfo_.begin(),hitInfo_.end(),detIdMatcher)!=hitInfo_.end()){
52  mask|=bitNr;
53  }
54  }
55  return mask;
56 }
57 
58 void ElectronSeed::initTwoHitSeed(const unsigned char hitMask)
59 {
60  hitInfo_.resize(2);
61 
62  std::vector<unsigned int> hitNrs = hitNrsFromMask(hitMask);
63  if(hitNrs.size()!=2){
64  throw cms::Exception("LogicError")
65  <<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__
66  <<": number of hits in hit mask is "<<hitNrs.size()<<"\n"
67  <<"pre-2017 pixel upgrade ecalDriven ElectronSeeds should have exactly 2 hits\n "
68  <<"mask "<<static_cast<unsigned int>(hitMask)<<std::endl;
69  }
70  if(hitNrs[0]>=nHits() || hitNrs[1]>=nHits()){
71  throw cms::Exception("LogicError")
72  <<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__
73  <<": hits are "<<hitNrs[0]<<" and "<<hitNrs[1]
74  <<" while number of hits are "<<nHits()<<"\n"
75  <<"this means there was a bug in storing or creating the electron seeds "
76  <<"mask "<<static_cast<unsigned int>(hitMask)<<std::endl;
77  }
78  for(size_t hitNr=0;hitNr<hitInfo_.size();hitNr++){
79  auto& info = hitInfo_[hitNr];
82  info.setDet((recHits().first+hitNrs[hitNr])->geographicalId(),-1);
83  }
84 
85 }
86 
87 void ElectronSeed::setNegAttributes(float dRZ2,float dPhi2,float dRZ1,float dPhi1)
88 {
89  if(hitInfo_.size()!=2){
90  throw cms::Exception("LogicError") <<"ElectronSeed::setNegAttributes should only operate on seeds with exactly two hits. This is because it is a legacy function to preverse backwards compatiblity and should not be used on new code which matches variable number of hits";
91  }
92  hitInfo_[0].dRZNeg = dRZ1;
93  hitInfo_[1].dRZNeg = dRZ2;
94  hitInfo_[0].dPhiNeg = dPhi1;
95  hitInfo_[1].dPhiNeg = dPhi2;
96 
97 }
98 
99 void ElectronSeed::setPosAttributes(float dRZ2,float dPhi2,float dRZ1,float dPhi1)
100 {
101  if(hitInfo_.size()!=2){
102  throw cms::Exception("LogicError") <<"ElectronSeed::setPosAttributes should only operate on seeds with exactly two hits. This is because it is a legacy function to preverse backwards compatiblity and should not be used on new code which matches variable number of hits";
103  }
104  hitInfo_[0].dRZPos = dRZ1;
105  hitInfo_[1].dRZPos = dRZ2;
106  hitInfo_[0].dPhiPos = dPhi1;
107  hitInfo_[1].dPhiPos = dPhi2;
108 }
109 
110 std::vector<unsigned int>
111 ElectronSeed::hitNrsFromMask(unsigned int hitMask)
112 {
113  std::vector<unsigned int> hitNrs;
114  for(size_t bitNr=0; bitNr<sizeof(hitMask)*CHAR_BIT ; bitNr++){
115  char bit = 0x1 << bitNr;
116  if((hitMask&bit)!=0) hitNrs.push_back(bitNr);
117  }
118  return hitNrs;
119 }
120 
121 std::vector<ElectronSeed::PMVars>
122 ElectronSeed::createHitInfo(const float dPhi1Pos,const float dPhi1Neg,
123  const float dRZ1Pos,const float dRZ1Neg,
124  const float dPhi2Pos,const float dPhi2Neg,
125  const float dRZ2Pos,const float dRZ2Neg,
126  const char hitMask,const TrajectorySeed::range recHits)
127 {
128  if(hitMask==0) return std::vector<ElectronSeed::PMVars>(); //was trackerDriven so no matched hits
129 
130  size_t nrRecHits = std::distance(recHits.first,recHits.second);
131  std::vector<unsigned int> hitNrs = hitNrsFromMask(hitMask);
132 
133  if(hitNrs.size()!=2){
134  throw cms::Exception("LogicError")
135  <<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__
136  <<": number of hits in hit mask is "<<nrRecHits<<"\n"
137  <<"pre-2017 pixel upgrade ecalDriven ElectronSeeds should have exactly 2 hits\n"
138  <<"mask "<<static_cast<unsigned int>(hitMask)<<std::endl;
139  }
140  if(hitNrs[0]>=nrRecHits || hitNrs[1]>=nrRecHits){
141  throw cms::Exception("LogicError")
142  <<"in ElectronSeed::"<<__FUNCTION__<<","<<__LINE__
143  <<": hits are "<<hitNrs[0]<<" and "<<hitNrs[1]
144  <<" while number of hits are "<<nrRecHits<<"\n"
145  <<"this means there was a bug in storing or creating the electron seeds "
146  <<"mask "<<static_cast<unsigned int>(hitMask)<<std::endl;
147  }
148 
149  std::vector<PMVars> hitInfo(2);
150  hitInfo[0].setDPhi(dPhi1Pos,dPhi1Neg);
151  hitInfo[0].setDRZ(dRZ1Pos,dRZ1Neg);
152  hitInfo[0].setDet((recHits.first+hitNrs[0])->geographicalId(),-1); //getting the layer information needs tracker topo, hence why its stored in the first as its a pain to access
153  hitInfo[1].setDPhi(dPhi2Pos,dPhi2Neg);
154  hitInfo[1].setDRZ(dRZ2Pos,dRZ2Neg);
155  hitInfo[1].setDet((recHits.first+hitNrs[1])->geographicalId(),-1); //getting the layer information needs tracker topo, hence why its stored in the first as its a pain to access
156  return hitInfo;
157 
158 }
159 
160 
162  dRZPos(std::numeric_limits<float>::infinity()),
163  dRZNeg(std::numeric_limits<float>::infinity()),
164  dPhiPos(std::numeric_limits<float>::infinity()),
165  dPhiNeg(std::numeric_limits<float>::infinity()),
166  detId(0),
167  layerOrDiskNr(-1)
168 {}
169 
170 void ElectronSeed::PMVars::setDPhi(float pos,float neg)
171 {
172  dPhiPos = pos;
173  dPhiNeg = neg;
174 }
175 
176 void ElectronSeed::PMVars::setDRZ(float pos,float neg)
177 {
178  dRZPos = pos;
179  dRZNeg = neg;
180 }
181 
182 void ElectronSeed::PMVars::setDet(int iDetId,int iLayerOrDiskNr)
183 {
184  detId = iDetId;
185  layerOrDiskNr = iLayerOrDiskNr;
186 }
187 
188 
189 
190 
static const TGPicture * info(bool iBackgroundIsBlack)
std::vector< PMVars > hitInfo_
Definition: ElectronSeed.h:161
float dPhi1() const
Definition: ElectronSeed.h:120
void setPosAttributes(const float dRZ2=std::numeric_limits< float >::infinity(), const float dPhi2=std::numeric_limits< float >::infinity(), const float dRZ1=std::numeric_limits< float >::infinity(), const float dPhi1=std::numeric_limits< float >::infinity())
Definition: ElectronSeed.cc:99
void setDPhi(float pos, float neg)
float dPhi1Pos() const
Definition: ElectronSeed.h:121
PropagationDirection
float dRZPos(size_t hitNr) const
Definition: ElectronSeed.h:106
void setCtfTrack(const CtfTrackRef &)
Set additional info.
Definition: ElectronSeed.cc:35
static const double pts[33]
Definition: Constants.h:30
float dPhi2() const
Definition: ElectronSeed.h:122
ElectronSeed()
Construction of base attributes.
Definition: ElectronSeed.cc:9
void setDet(int iDetId, int iLayerOrDiskNr)
const double infinity
std::pair< const_iterator, const_iterator > range
CaloClusterRef caloCluster_
Definition: ElectronSeed.h:160
float dPhi2Pos() const
Definition: ElectronSeed.h:123
int layerOrDiskNr(size_t hitNr) const
Definition: ElectronSeed.h:111
int detId(size_t hitNr) const
Definition: ElectronSeed.h:109
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(), const float dPhi1=std::numeric_limits< float >::infinity())
Definition: ElectronSeed.cc:87
const std::vector< PMVars > & hitInfo() const
Definition: ElectronSeed.h:102
range recHits() const
virtual ~ElectronSeed()
unsigned int nHits() const
fixed size matrix
unsigned int hitsMask() const
Definition: ElectronSeed.cc:44
float dRZNeg(size_t hitNr) const
Definition: ElectronSeed.h:107
static std::vector< PMVars > createHitInfo(const float dPhi1Pos, const float dPhi1Neg, const float dRZ1Pos, const float dRZ1Neg, const float dPhi2Pos, const float dPhi2Neg, const float dRZ2Pos, const float dRZ2Neg, const char hitMask, const TrajectorySeed::range recHits)
dbl *** dir
Definition: mlp_gen.cc:35
float dPhiNeg(size_t hitNr) const
Definition: ElectronSeed.h:103
CtfTrackRef ctfTrack_
Definition: ElectronSeed.h:159
void setDRZ(float pos, float neg)
float dPhiPos(size_t hitNr) const
Definition: ElectronSeed.h:104
static std::vector< unsigned int > hitNrsFromMask(unsigned int hitMask)
const CtfTrackRef & ctfTrack() const
Accessors.
Definition: ElectronSeed.h:93
void initTwoHitSeed(const unsigned char hitMask)
Definition: ElectronSeed.cc:58