26 :nPhi_(nPhi),nEta_(nEta),
27 lookupMap_(nPhi_*nEta_,std::pair<unsigned int, unsigned int>(0,0)),
28 theMapIsValid_(
false),etaBinSize_(etaBinSize),ivProp_(0)
30 if (
nEta_ <= 0 ||
nPhi_ <= 0)
throw cms::Exception(
"FatalError") <<
"incorrect look-up map size. Cannot initialize such a map.";
44 const unsigned int iNEtaPlus,
45 const unsigned int iNEtaMinus,
46 const unsigned int iNPhiPlus,
47 const unsigned int iNPhiMinus)
const
52 LogTrace(
"TrackAssociator") <<
"(iNEtaPlus, iNEtaMinus, iNPhiPlus, iNPhiMinus): " <<
53 iNEtaPlus <<
", " << iNEtaMinus <<
", " << iNPhiPlus <<
", " << iNPhiMinus;
54 LogTrace(
"TrackAssociator") <<
"point (eta,phi): " << direction.
eta() <<
"," << direction.
phi();
55 int ieta =
iEta(direction);
56 int iphi =
iPhi(direction);
57 LogTrace(
"TrackAssociator") <<
"(ieta,iphi): " << ieta <<
"," << iphi <<
"\n";
58 if (ieta>=0 && ieta<nEta_ && iphi>=0 && iphi<
nPhi_){
62 if (iNEtaPlus + iNEtaMinus + iNPhiPlus + iNPhiMinus >0 ){
63 LogTrace(
"TrackAssociator") <<
"Add neighbors (ieta,iphi): " << ieta <<
"," << iphi;
65 int maxIEta = ieta+iNEtaPlus;
66 int minIEta = ieta-iNEtaMinus;
68 if (minIEta<0) minIEta = 0;
70 int maxIPhi = iphi+iNPhiPlus;
71 int minIPhi = iphi-iNPhiMinus;
72 if (maxIPhi-minIPhi>=
nPhi_){
80 LogTrace(
"TrackAssociator") <<
"\tieta (min,max): " << minIEta <<
"," << maxIEta;
81 LogTrace(
"TrackAssociator") <<
"\tiphi (min,max): " << minIPhi <<
"," << maxIPhi<<
"\n";
83 for (
int i=minIEta;
i<=maxIEta;
i++)
84 for (
int j=minIPhi;
j<=maxIPhi;
j++) {
85 if(
i==ieta &&
j==iphi)
continue;
101 const double dThetaPlus,
102 const double dThetaMinus,
103 const double dPhiPlus,
104 const double dPhiMinus)
const
106 LogTrace(
"TrackAssociator") <<
"(dThetaPlus,dThetaMinus,dPhiPlus,dPhiMinus): " <<
107 dThetaPlus <<
", " << dThetaMinus <<
", " << dPhiPlus <<
", " << dPhiMinus;
109 if ( dThetaPlus<0 || dThetaMinus<0 || dPhiPlus<0 || dPhiMinus<0)
112 double maxTheta = point.
theta()+dThetaPlus;
114 double minTheta = point.
theta()-dThetaMinus;
115 if (minTheta < minTheta_) minTheta =
minTheta_;
116 if ( maxTheta < minTheta_ || minTheta >
M_PI-minTheta_)
return std::set<DetId>();
124 unsigned int iNPhiPlus =
abs(
int( dPhiPlus/(2*
M_PI)*
nPhi_ ));
125 unsigned int iNPhiMinus =
abs(
int( dPhiMinus/(2*
M_PI)*nPhi_ ));
148 LogTrace(
"TrackAssociator")<<
"building map for " <<
name() <<
"\n";
150 if (
nEta_ <= 0 ||
nPhi_ <= 0)
throw cms::Exception(
"FatalError") <<
"incorrect look-up map size. Cannot build such a map.";
152 unsigned totalNumberOfElementsInTheContainer(0);
154 unsigned int numberOfDetIdsOutsideEtaRange = 0;
155 unsigned int numberOfDetIdsActive = 0;
157 for (
unsigned int subDetectorIndex = 0; subDetectorIndex < numberOfSubDetectors; ++subDetectorIndex ){
158 const std::vector<DetId>& validIds =
getValidDetIds(subDetectorIndex);
159 LogTrace(
"TrackAssociator")<<
"Number of valid DetIds for subdetector: " << subDetectorIndex <<
" is " << validIds.size();
160 for (std::vector<DetId>::const_iterator id_itr = validIds.begin(); id_itr!=validIds.end(); id_itr++) {
161 std::pair<const_iterator,const_iterator> points =
getDetIdPoints(*id_itr);
162 LogTrace(
"TrackAssociatorVerbose")<<
"Found " << points.second-points.first <<
" global points to describe geometry of DetId: "
169 for(std::vector<GlobalPoint>::const_iterator iter = points.first; iter != points.second; iter++)
171 LogTrace(
"TrackAssociatorVerbose")<<
"\tpoint (rho,phi,z): " << iter->perp() <<
", " <<
172 iter->phi() <<
", " << iter->z();
174 if(
std::isnan(iter->mag())||iter->mag()>1e5) {
175 edm::LogWarning(
"TrackAssociator") <<
"Critical error! Bad detector unit geometry:\n\tDetId:"
176 << id_itr->rawId() <<
"\t mag(): " << iter->mag() <<
"\n" <<
DetIdInfo::info( *id_itr )
177 <<
"\nSkipped the element";
181 int ieta =
iEta(*iter);
182 int iphi =
iPhi(*iter);
183 if (ieta<0 || ieta>=
nEta_) {
184 LogTrace(
"TrackAssociator")<<
"Out of range: DetId:" << id_itr->rawId() <<
"\t (ieta,iphi): "
185 << ieta <<
"," << iphi <<
"\n" <<
"Point: " << *iter <<
"\t(eta,phi): " << (*iter).eta()
186 <<
"," << (*iter).phi() <<
"\n center: " <<
getPosition(*id_itr);
197 int deltaMin =
abs(phiMin -iphi);
198 int deltaMax =
abs(phiMax -iphi);
201 if ( deltaMax >
nPhi_/2 ) {
202 if (phiMax <
nPhi_/2 )
208 if ( etaMin > ieta) etaMin = ieta;
209 if ( etaMax < ieta) etaMax = ieta;
210 if ( phiMin > iphi) phiMin = iphi;
211 if ( phiMax < iphi) phiMax = iphi;
214 if (etaMax<0||phiMax<0||etaMin>=
nEta_||phiMin>=
nPhi_) {
215 LogTrace(
"TrackAssociatorVerbose")<<
"Out of range or no geometry: DetId:" << id_itr->rawId() <<
216 "\n\teta (min,max): " << etaMin <<
"," << etaMax <<
217 "\n\tphi (min,max): " << phiMin <<
"," << phiMax <<
218 "\nTower id: " << id_itr->rawId() <<
"\n";
219 numberOfDetIdsOutsideEtaRange++;
222 numberOfDetIdsActive++;
224 LogTrace(
"TrackAssociatorVerbose") <<
"DetId (ieta_min,ieta_max,iphi_min,iphi_max): " << id_itr->rawId() <<
225 ", " << etaMin <<
", " << etaMax <<
", " << phiMin <<
", " <<
phiMax;
226 for(
int ieta = etaMin; ieta <=
etaMax; ieta++)
227 for(
int iphi = phiMin; iphi <=
phiMax; iphi++)
230 totalNumberOfElementsInTheContainer++;
234 totalNumberOfElementsInTheContainer--;
238 LogTrace(
"TrackAssociator") <<
"Number of elements outside the allowed range ( |eta|>"<<
240 LogTrace(
"TrackAssociator") <<
"Number of active DetId's mapped: " <<
241 numberOfDetIdsActive <<
"\n";
244 container_.resize(totalNumberOfElementsInTheContainer);
246 unsigned int index(0);
247 for ( std::vector<std::pair<unsigned int,unsigned int> >::iterator
bin =
lookupMap_.begin();
250 if (
bin->second==0)
continue;
251 index +=
bin->second;
252 bin->first = index-1;
256 if ( totalNumberOfElementsInTheContainer != 0 )
257 throw cms::Exception(
"FatalError") <<
"Look-up map filled incorrectly. Structural problem. Get in touch with the developer.";
259 edm::LogVerbatim(
"TrackAssociator") <<
"Fiducial volume for " <<
name() <<
" (minR, maxR, minZ, maxZ): " <<
265 const std::vector<GlobalPoint>& trajectory,
266 const double dR)
const
270 std::set<DetId> outset;
271 for(std::set<DetId>::const_iterator id_iter = inset.begin(); id_iter != inset.end(); id_iter++)
272 for(std::vector<GlobalPoint>::const_iterator point_iter = trajectory.begin(); point_iter != trajectory.end(); point_iter++)
274 outset.insert(*id_iter);
281 const std::vector<GlobalPoint>& trajectory)
const
284 std::vector<DetId>
output;
285 std::set<DetId> ids(inset);
286 for (
unsigned int i=0;
i+1 < trajectory.size(); ++
i ) {
287 std::set<DetId>::const_iterator id_iter = ids.begin();
288 while ( id_iter != ids.end() ) {
290 output.push_back(*id_iter);
291 ids.erase(id_iter++);
300 const std::vector<SteppingHelixStateInfo>& trajectory,
301 const double tolerance)
const
304 std::vector<DetId>
output;
305 std::set<DetId> ids(inset);
306 for (
unsigned int i=0;
i+1 < trajectory.size(); ++
i ) {
307 std::set<DetId>::const_iterator id_iter = ids.begin();
308 while ( id_iter != ids.end() ) {
310 output.push_back(*id_iter);
311 ids.erase(id_iter++);
322 if (! (ieta>=0 && ieta<nEta_ && iphi>=0) )
324 edm::LogWarning(
"TrackAssociator") <<
"ieta or iphi is out of range. Skipped.";
330 LogTrace(
"TrackAssociator") <<
"Map content for cell (ieta,iphi): " << ieta <<
", " << iphi%
nPhi_;
331 for(std::set<DetId>::const_iterator itr = set.begin(); itr!=set.end(); itr++)
333 LogTrace(
"TrackAssociator") <<
"\tDetId " << itr->rawId() <<
", geometry (x,y,z,rho,eta,phi):";
334 std::pair<const_iterator,const_iterator> points =
getDetIdPoints(*itr);
335 for(std::vector<GlobalPoint>::const_iterator
point = points.first;
point != points.second;
point++)
343 for(
int i=ieta_min;
i<=ieta_max;
i++)
344 for(
int j=iphi_min;
j<=iphi_max;
j++)
364 const double distance)
const
368 if(deltaPhi>
M_PI) deltaPhi = fabs(deltaPhi-
M_PI*2.);
369 return (point.
eta()-center.
eta())*(point.
eta()-center.
eta()) + deltaPhi*deltaPhi < distance*distance;
382 unsigned int i =
index(iEta,iPhi);
385 for ( i = i0; i < i0+
size; ++
i )
virtual std::set< DetId > getDetIdsInACone(const std::set< DetId > &, const std::vector< GlobalPoint > &trajectory, const double dR) const
void determinInnerDimensions()
virtual bool crossedElement(const GlobalPoint &, const GlobalPoint &, const DetId &, const double toleranceInSigmas=-1, const SteppingHelixStateInfo *=0) const
double maxZ(bool withTolerance=true) const
Geom::Phi< T > phi() const
virtual bool nearElement(const GlobalPoint &point, const DetId &id, const double distance) const
unsigned int index(unsigned int iEta, unsigned int iPhi) const
virtual int iEta(const GlobalPoint &) const
look-up map eta index
virtual std::vector< DetId > getCrossedDetIds(const std::set< DetId > &, const std::vector< GlobalPoint > &trajectory) const
std::vector< std::pair< unsigned int, unsigned int > > lookupMap_
double minZ(bool withTolerance=true) const
std::vector< DetId > container_
virtual void dumpMapContent(int, int) const
Geom::Theta< T > theta() const
virtual int iPhi(const GlobalPoint &) const
look-up map phi index
void fillSet(std::set< DetId > &set, unsigned int iEta, unsigned int iPhi) const
void addActivePoint(const GlobalPoint &point)
add a point that belongs to the active volume
virtual const unsigned int getNumberOfSubdetectors() const
virtual const char * name() const =0
Tan< T >::type tan(const T &t)
virtual void check_setup() const
static std::string info(const DetId &)
#define TYPELOOKUP_DATA_REG(_dataclass_)
double minR(bool withTolerance=true) const
virtual const std::vector< DetId > & getValidDetIds(unsigned int subDetectorIndex) const =0
DetIdAssociator(const int nPhi, const int nEta, const double etaBinSize)
virtual void buildMap()
make the look-up map
virtual GlobalPoint getPosition(const DetId &) const =0
static int position[264][3]
const FiducialVolume & volume() const
get active detector volume
virtual std::set< DetId > getDetIdsCloseToAPoint(const GlobalPoint &, const int iN=0) const
double maxR(bool withTolerance=true) const
tuple size
Write out results.
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
virtual std::pair< const_iterator, const_iterator > getDetIdPoints(const DetId &) const =0
void set(const std::string &name, int value)
set the flag, with a run-time name