CMS 3D CMS Logo

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