42 const std::pair<SeedingHitSet::ConstRecHitPointer,SeedingHitSet::ConstRecHitPointer>& hits,
44 DetId firstHitId = hits.first->geographicalId();
45 DetId secondHitId = hits.second->geographicalId();
78 theLayerBuilder_(iConfig, iC),
79 theSeedCreator_(seedCreator)
129 std::vector<std::pair<double,double> > phiEtaCache;
130 std::vector<SeedingHitSet> tripletCache;
132 const unsigned int nInputTriplets = inputTriplets.
size();
133 phiEtaCache.reserve(nInputTriplets);
134 tripletCache.reserve(nInputTriplets);
136 for(
unsigned int it = 0; it < nInputTriplets; ++it ) {
137 tripletCache.push_back((inputTriplets[it]));
148 bool isAllTriplets =
true;
149 for(
unsigned int it = 0; it < nInputTriplets; ++it ) {
150 if( tripletCache[it].
size() != 3 ) {
151 isAllTriplets =
false;
157 std::cout <<
"[QuadrupletSeedMerger::mergeTriplets] (in HLT) ** bailing out since non-triplets in input." << std::endl;
160 quads_.reserve(nInputTriplets);
161 for(
unsigned int it = 0; it < nInputTriplets; ++it ) {
162 quads_.push_back( (tripletCache[it]));
169 quads_.reserve(0.2*nInputTriplets);
174 std::vector<bool> usedTriplets(nInputTriplets,
false);
175 std::pair<SeedingHitSet::ConstRecHitPointer,SeedingHitSet::ConstRecHitPointer>
sharedHits;
176 std::pair<SeedingHitSet::ConstRecHitPointer,SeedingHitSet::ConstRecHitPointer> nonSharedHits;
180 std::vector<KDTreeNodeInfo<unsigned int> > nodes;
181 std::vector<unsigned int> foundNodes;
182 nodes.reserve(2*nInputTriplets);
183 foundNodes.reserve(100);
186 for(
unsigned int it=0; it < nInputTriplets; ++it) {
187 double phi = phiEtaCache[it].first;
188 double eta = phiEtaCache[it].second;
199 kdtree.
build(nodes, kdEtaPhi);
205 std::vector<unsigned int> t1List;
206 std::vector<unsigned int> t2List;
207 std::vector<short> t1NonSharedHitList;
208 std::vector<short> t2NonSharedHitList;
209 constexpr short sharedToNonShared[7] = {-1, -1, -1,
214 constexpr short nonSharedToShared[3][2] = {
220 typedef std::tuple<unsigned int, short, short> T2NonSharedTuple;
221 std::vector<T2NonSharedTuple> t2Tmp;
222 for(
unsigned int t1=0; t1<nInputTriplets; ++t1) {
223 double phi = phiEtaCache[t1].first;
224 double eta = phiEtaCache[t1].second;
226 KDTreeBox box(eta-0.05, eta+0.05, phi-0.15, phi+0.15);
228 kdtree.
search(box, foundNodes);
229 if(foundNodes.empty())
234 for(
unsigned int t2: foundNodes) {
248 unsigned int t1Shared = 0;
249 unsigned int t2Shared = 0;
250 for(
unsigned int i=0;
i<2; ++
i) {
251 for(
unsigned int j=0;
j<3; ++
j) {
252 if(areHitsEqual(*tr1[
i], *tr2[
j])) {
265 for(
unsigned int j=0;
j<3; ++
j) {
266 if(areHitsEqual(*tr1[2], *tr2[
j])) {
277 assert(t1Shared <= 6 && t2Shared <= 6);
278 short t1NonShared = sharedToNonShared[t1Shared];
279 short t2NonShared = sharedToNonShared[t2Shared];
280 assert(t1NonShared >= 0 && t2NonShared >= 0);
282 t2Tmp.emplace_back(
t2, t1NonShared, t2NonShared);
286 std::sort(t2Tmp.begin(), t2Tmp.end(), [](
const T2NonSharedTuple&
a,
const T2NonSharedTuple&
b){
287 return std::get<0>(
a) < std::get<0>(
b);
289 for(T2NonSharedTuple& t2tpl: t2Tmp) {
290 t1List.push_back(t1);
291 t2List.push_back(std::get<0>(t2tpl));
292 t1NonSharedHitList.push_back(std::get<1>(t2tpl));
293 t2NonSharedHitList.push_back(std::get<2>(t2tpl));
302 std::vector<SeedMergerPixelLayer> currentLayers;
303 currentLayers.reserve(lsIt->size());
304 for( ctfseeding::SeedingLayers::const_iterator layIt = lsIt->begin(); layIt < lsIt->end(); ++layIt ) {
312 for(
unsigned int s1=0; s1<currentLayers.size()-1; s1++) {
314 for(
unsigned int s2=s1+1;
s2<currentLayers.size();
s2++) {
316 std::vector<unsigned int> nonSharedLayerNums;
317 for (
unsigned int us1=0; us1<currentLayers.size(); us1++) {
318 if ( s1!=us1 &&
s2!=us1) nonSharedLayerNums.push_back(us1);
322 for (
unsigned int t12=0; t12<t1List.size(); t12++) {
323 unsigned int t1=t1List[t12];
324 unsigned int t2=t2List[t12];
326 if (usedTriplets[t1] || usedTriplets[t2] )
continue;
330 short t1NonShared = t1NonSharedHitList[t12];
331 sharedHits.first = firstTriplet[nonSharedToShared[t1NonShared][0]];
332 sharedHits.second = firstTriplet[nonSharedToShared[t1NonShared][1]];
335 if(areHitsOnLayers(currentLayers[s1], currentLayers[
s2], sharedHits, tTopo)) {
336 short t2NonShared = t2NonSharedHitList[t12];
338 nonSharedHits.first = firstTriplet[t1NonShared];
339 nonSharedHits.second = secondTriplet[t2NonShared];
342 if(areHitsOnLayers(currentLayers[nonSharedLayerNums[0]], currentLayers[nonSharedLayerNums[1]], nonSharedHits, tTopo)) {
343 QuadrupletHits unsortedHits{ {sharedHits.first, sharedHits.second,
344 nonSharedHits.first, nonSharedHits.second} };
351 SeedingHitSet quadruplet(unsortedHits[0],unsortedHits[1],unsortedHits[2],unsortedHits[3]);
354 quads_.push_back( quadruplet );
357 usedTriplets[t1]=
true;
358 usedTriplets[
t2]=
true;
372 for(
unsigned int it = 0; it < nInputTriplets; ++it ) {
373 if ( !usedTriplets[it] )
374 quads_.push_back( tripletCache[it]);
418 bool isAllTriplets =
true;
419 for( TrajectorySeedCollection::const_iterator aTrajectorySeed = seedCollection.begin();
420 aTrajectorySeed < seedCollection.end(); ++aTrajectorySeed ) {
421 if( 3 != aTrajectorySeed->nHits() ) isAllTriplets =
false;
425 std::cout <<
" [QuadrupletSeedMerger::mergeTriplets] (in RECO) -- bailing out since non-triplets in input." << std::endl;
428 for( TrajectorySeedCollection::const_iterator aTrajectorySeed = seedCollection.begin();
429 aTrajectorySeed < seedCollection.end(); ++aTrajectorySeed ) {
430 theResult.push_back( *aTrajectorySeed );
444 for( TrajectorySeedCollection::const_iterator aTrajectorySeed = seedCollection.begin();
445 aTrajectorySeed < seedCollection.end(); ++aTrajectorySeed ) {
447 std::vector<SeedingHitSet::ConstRecHitPointer> recHitPointers;
452 aHit < theHitsRange.second; ++aHit ) {
460 inputTriplets.push_back(
OrderedHitTriplet( recHitPointers.at( 0 ), recHitPointers.at( 1 ), recHitPointers.at( 2 ) ) );
473 for (
unsigned int i=0;
i< quadrupletHitSets.
size();
i++) {
496 const double x1 = p1.
x();
497 const double x2 = p2.
x();
498 const double y1 = p1.
y();
499 const double y2 = p2.
y();
500 const double z1 = p1.
z();
501 const double z2 = p2.
z();
503 const double phi = atan2( x2 - x1, y2 -y1 );
504 const double eta = acos( (z2 - z1) /
sqrt(
sqr( x2 - x1 ) +
sqr( y2 - y1 ) +
sqr( z2 - z1 ) ) );
506 std::pair<double,double> retVal;
507 retVal=std::make_pair (phi,eta);
526 std::cout <<
"<RecHit> x: " << x <<
" y: " << y <<
" z: " << z <<
" r: " << r << std::endl;
538 for(
unsigned int aHit = 0; aHit < aNtuplet.
size(); ++aHit ) {
545 const double r =
sqrt( x*x + y*y );
556 if( z > 0 ) detName +=
"+";
563 std::cout <<
"<NtupletHit> D: " << detName <<
" L: " << layer <<
" x: " << x <<
" y: " << y <<
" z: " << z <<
" r: " << r << std::endl;
567 std::cout <<
"<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
609 const unsigned int quadrupletSize = quadruplet.size();
612 if( quadrupletSize != layers.size() ) {
613 std::cout <<
" [QuadrupletSeedMerger::isValidQuadruplet] ** WARNING: size mismatch: "
614 << quadrupletSize <<
"/" << layers.size() << std::endl;
620 if( ! layers[
index].isContainsDetector( quadruplet[
index]->geographicalId(), tTopo ) ) {
636 std::cerr <<
" [SeedMergerPixelLayer::SeedMergerPixelLayer] ** ERROR: illegal name: \"" << name <<
"\"." << std::endl;
645 if( std::string::npos !=
name_.find(
"BPix" ) )
647 else if( std::string::npos !=
name_.find(
"FPix" ) )
652 std::cerr <<
" [PixelLayerNameParser::side] ** ERROR: something's wrong here.." << std::endl;
657 std::cerr <<
" [PixelLayerNameParser::subdetector] ** ERROR: something's wrong here.." << std::endl;
672 const int layer = atoi( name.substr( 4, 1 ).c_str() );
674 if( std::string::npos != name.find(
"BPix" ) ) {
675 if( layer > 0 && layer < 5 )
return true;
678 else if( std::string::npos != name.find(
"FPix" ) ) {
679 if( layer > 0 && layer < 4 ) {
680 if( std::string::npos != name.find(
"pos", 6 ) || std::string::npos != name.find(
"neg", 6 ) )
return true;
685 std::cerr <<
" [SeedMergerPixelLayer::isValidName] ** WARNING: invalid name: \"" << name <<
"\"." << std::endl;
729 for (
unsigned int iR=0; iR<4; iR++){
731 radiiSq[iR]=( p1.
x()*p1.
x()+p1.
y()*p1.
y());
735 for (
unsigned int iR1=0; iR1<3; iR1++) {
736 for (
unsigned int iR2=iR1+1; iR2<4; iR2++) {
737 if (radiiSq[iR1]>radiiSq[iR2]) {
738 tempRHP=unsortedHits[iR1];
739 unsortedHits[iR1]=unsortedHits[iR2];
740 unsortedHits[iR2]=tempRHP;
741 tempFloat=radiiSq[iR1];
742 radiiSq[iR1]=radiiSq[iR2];
743 radiiSq[iR2]=tempFloat;
edm::ESHandle< TrackerGeometry > theTrackerGeometry_
T getParameter(std::string const &) const
ctfseeding::SeedingLayerSets layers(const edm::EventSetup &es)
void build(std::vector< KDTreeNodeInfo > &eltList, const KDTreeBox ®ion)
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
void setTTRHBuilderLabel(std::string)
void printNtuplet(const SeedingHitSet &) const
SeedMergerPixelLayer(const std::string &)
unsigned int pxfDisk(const DetId &id) const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
unsigned getLayerNumber(void) const
QuadrupletSeedMerger(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
virtual unsigned int size() const =0
bool check(const edm::EventSetup &es)
void setMergeTriplets(bool)
bool isAddRemainingTriplets_
ctfseeding::SeedingLayerSets theLayerSets_
void search(const KDTreeBox &searchBox, std::vector< KDTreeNodeInfo > &resRecHitList)
const Plane & surface() const
The nominal surface of the GeomDet.
std::pair< double, double > calculatePhiEta(SeedingHitSet const &) const
PixelSubdetector::SubDetector subdet_
void mySort(QuadrupletHits &unsortedHits)
BaseTrackerRecHit const * ConstRecHitPointer
std::vector< TrajectorySeed > TrajectorySeedCollection
const T & max(const T &a, const T &b)
auto const T2 &decltype(t1.eta()) t2
PixelSubdetector::SubDetector getSubdet(void) const
Abs< T >::type abs(const T &t)
std::pair< const_iterator, const_iterator > range
std::array< SeedingHitSet::ConstRecHitPointer, 4 > QuadrupletHits
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
unsigned int pxbLayer(const DetId &id) const
void update(const edm::EventSetup &)
const OrderedSeedingHits & mergeTriplets(const OrderedSeedingHits &, const edm::EventSetup &)
int layerName() const
layer id
T const * product() const
bool isContainsDetector(const DetId &, const TrackerTopology *tTopo) const
edm::ESHandle< TransientTrackingRecHitBuilder > theTTRHBuilder_
void setAddRemainingTriplets(bool)
Square< F >::type sqr(const F &f)
std::string theTTRHBuilderLabel_
unsigned int size() const
void printHit(const TrackingRecHit *) const
bool isValidQuadruplet(const QuadrupletHits &quadruplet, const std::vector< SeedMergerPixelLayer > &layers, const TrackerTopology *tTopo) const
unsigned int pxfSide(const DetId &id) const
std::unique_ptr< SeedCreator > theSeedCreator_
SeedingLayerSetsBuilder theLayerBuilder_
int diskName() const
disk id
SeedMergerPixelLayer::Side side_
DetId geographicalId() const
virtual LocalPoint localPosition() const =0
const PositionType & position() const
tuple size
Write out results.
T get(const Candidate &c)
bool isValidName(const std::string &)