57 std::cout <<
"TrackCandidateProducer created" << std::endl;
61 produces<TrackCandidateCollection>();
65 produces<reco::TrackCollection>();
66 produces<TrackingRecHitCollection>();
67 produces<reco::TrackExtraCollection>();
68 produces<std::vector<Trajectory> >();
69 produces<TrajTrackAssociationCollection>();
112 std::cout <<
"TrackCandidateProducer destructed" << std::endl;
140 std::cout <<
"################################################################" << std::endl;
141 std::cout <<
" TrackCandidateProducer produce init " << std::endl;
145 typedef std::pair<reco::TrackRef,edm::Ref<std::vector<Trajectory> > > TrackPair;
146 typedef std::map<unsigned,TrackPair> TrackMap;
153 std::auto_ptr<std::vector<Trajectory> > recoTrajectories(
new std::vector<Trajectory> );
168 if(theSeeds->size() == 0) {
172 e.
put(recoTrackExtras);
173 e.
put(recoTrajectories);
174 e.
put(recoTrajTrackMap);
184 const std::vector<unsigned> theSimTrackIds = theGSRecHits->ids();
193 LogDebug(
"FastTracking")<<
"looking at: "<< theSimTrackIds.size()<<
" simtracks.";
205 std::vector<edm::Handle<reco::TrackCollection> > theTrackCollections;
206 std::vector<edm:: Handle<std::vector<Trajectory> > > theTrajectoryCollections;
207 std::vector<edm::Handle<TrajTrackAssociationCollection> > theAssoMaps;
208 std::vector<bool> isTrackCollections;
211 TrackMap theTrackMap;
213 unsigned nRecoHits = 0;
215 if ( nCollections ) {
216 theTrackCollections.resize(nCollections);
217 theTrajectoryCollections.resize(nCollections);
218 theAssoMaps.resize(nCollections);
219 isTrackCollections.resize(nCollections);
220 for (
unsigned tprod=0; tprod <
nCollections; ++tprod ) {
223 if ( isTrackCollections[tprod] ) {
225 reco::TrackCollection::const_iterator aTrack = theTrackCollections[tprod]->begin();
226 reco::TrackCollection::const_iterator lastTrack = theTrackCollections[tprod]->end();
228 for ( ; aTrack!=lastTrack; ++aTrack ) nRecoHits+= aTrack->recHitsSize();
232 anAssociation = theAssoMaps[tprod]->begin();
233 lastAssociation = theAssoMaps[tprod]->end();
236 std::cout <<
"List of tracks already reconstructed " << std::endl;
239 for ( ; anAssociation != lastAssociation; ++anAssociation ) {
243 int recoTrackId =
findId(*aTrackRef);
244 if ( recoTrackId < 0 )
continue;
249 theTrackMap[recoTrackId] = TrackPair(aTrackRef,aTrajectoryRef);
257 recoHits->reserve(nRecoHits);
262 int currentTrackId = -1;
272 std::cout <<
"Number of seeds : " << theSeeds->size() << std::endl;
274 unsigned seed_size = theSeeds->size();
275 for (
unsigned seednr = 0; seednr < seed_size; ++seednr){
277 LogDebug(
"FastTracking")<<
"looking at seed #:"<<seednr;
282 std::vector<int> simTrackIds;
283 std::map<int,TrajectoryStateOnSurface> seedStates;
284 std::map<int,TrajectoryStateOnSurface> simtkStates;
287 if (theSeeds->at(seednr).nHits()==0){
290 LogDebug(
"FastTracking")<<
" seed with no hits to be considered.";
299 const Surface * surface=&g->surface();
312 double minimunEst=1000000;
313 LogDebug(
"FastTracking")<<
"looking at: "<< theSimTrackIds.size()<<
" simtracks.";
314 for (
unsigned tkId=0; tkId != theSimTrackIds.size(); ++tkId ) {
316 const SimTrack & simtrack = (*theSimTracks)[theSimTrackIds[tkId]];
327 LogDebug(
"FastTracking")<<
"not on the same direction.";
342 if (!simtrack_comparestate.
isValid()){
343 LogDebug(
"FastTracking")<<
" ok this is a state-based seed. simtrack state does not propagate to the seed surface. skipping.";
347 LogDebug(
"FastTracking")<<
"not on the same direction.";
354 bool ierr = !
m.Invert();
356 edm::LogWarning(
"FastTracking") <<
" Candidate Producer cannot invert the error matrix! - Skipping...";
359 double est = ROOT::Math::Similarity(
v,
m);
360 LogDebug(
"FastTracking")<<
"comparing two state on the seed surface:\n"
361 <<
"seed: "<<seedState
362 <<
"sim: "<<simtrack_comparestate
363 <<
"\n estimator is: "<<est;
365 if (est<minimunEst) minimunEst=est;
367 simTrackIds.push_back(theSimTrackIds[tkId]);
378 LogDebug(
"FastTracking")<<
"the compatibility estimator is: "<<est<<
" for track id: "<<simTrackIds.back();
381 if (simTrackIds.size()==0)
LogDebug(
"FastTracking")<<
"could not find any simtrack within errors, closest was at: "<<minimunEst;
390 simTrackIds.push_back( theFirstSeedingRecHit->
simtrackId() );
396 for (
unsigned int iToMake=0;iToMake!=simTrackIds.size();++iToMake){
397 int simTrackId = simTrackIds[iToMake];
401 if (
seedCleaning && currentTrackId == simTrackId )
continue;
402 currentTrackId = simTrackId;
405 std::vector<TrackerRecHit> theTrackerRecHits;
406 unsigned theNumberOfCrossedLayers = 0;
409 TrackMap::const_iterator theTrackIt = theTrackMap.find(simTrackId);
410 if ( nCollections && theTrackIt != theTrackMap.end() ) {
413 LogDebug(
"FastTracking") <<
"Track " << simTrackId <<
" already reconstructed -> copy it";
420 recoTracks->push_back(aRecoTrack);
424 for (
unsigned ih=0; ih<nh; ++ih ) {
426 recoHits->push_back(hit);
430 recoTrajectories->push_back(*aTrajectoryRef);
434 LogDebug(
"FastTracking") <<
"Track " << simTrackId <<
" already reconstructed -> ignore it";
442 LogDebug(
"FastTracking")<<
"Track " << simTrackId <<
" is considered to return a track candidate" ;
450 LogDebug(
"FastTracking")<<
"counting: "<<theRecHitRangeIteratorEnd-theRecHitRangeIteratorBegin<<
" hits to be considered.";
452 bool firstRecHit =
true;
456 for ( iterRecHit = theRecHitRangeIteratorBegin;
457 iterRecHit != theRecHitRangeIteratorEnd;
464 if(!firstRecHit) thePreviousRecHit = theCurrentRecHit;
478 ++theNumberOfCrossedLayers;
485 else theTrackerRecHits.push_back(theCurrentRecHit);
498 else theTrackerRecHits.push_back(theCurrentRecHit);
506 theTrackerRecHits.pop_back();
514 theTrackerRecHits.back() = theCurrentRecHit;
520 theCurrentRecHit = thePreviousRecHit;
528 LogDebug(
"FastTracking")<<
" number of hits: " << theTrackerRecHits.size()<<
" after counting overlaps and splitting.";
532 unsigned nTrackerHits = theTrackerRecHits.
size();
536 LogDebug(
"FastTracking")<<
"reversing the order of the hits";
537 std::reverse(theTrackerRecHits.begin(),theTrackerRecHits.end());
540 for (
unsigned ih=0; ih<nTrackerHits; ++ih ) {
544 const DetId& detId = theTrackerRecHits[ih].hit()->geographicalId();
546 <<
"Added RecHit from detid " << detId.
rawId()
547 <<
" subdet = " << theTrackerRecHits[ih].subDetId()
548 <<
" layer = " << theTrackerRecHits[ih].layerNumber()
549 <<
" ring = " << theTrackerRecHits[ih].ringNumber()
550 <<
" error = " << theTrackerRecHits[ih].localError()
555 << theTrackerRecHits[ih].globalPosition().z() <<
" "
556 << theTrackerRecHits[ih].globalPosition().perp() << std::endl;
557 if ( theTrackerRecHits[ih].matchedHit() && theTrackerRecHits[ih].matchedHit()->
isMatched() )
558 LogTrace(
"FastTracking") <<
"Matched : " << theTrackerRecHits[ih].matchedHit()->isMatched()
559 <<
"Rphi Hit = " << theTrackerRecHits[ih].matchedHit()->monoHit()->simhitId()
560 <<
"Stereo Hit = " << theTrackerRecHits[ih].matchedHit()->stereoHit()->simhitId()
566 LogDebug(
"FastTracking")<<
"not enough layer crossed ("<<theNumberOfCrossedLayers<<
")";
577 if (aSeed->
nHits()==0){
585 int vertexIndex = (*theSimTracks)[currentTrackId].vertIndex();
588 (*theSimVtx)[vertexIndex].
position().
y(),
589 (*theSimVtx)[vertexIndex].
position().
z());
592 GlobalVector momentum( (*theSimTracks)[currentTrackId].momentum().
x() ,
593 (*theSimTracks)[currentTrackId].momentum().
y() ,
594 (*theSimTracks)[currentTrackId].momentum().
z() );
596 float charge = (*theSimTracks)[simTrackId].charge();
605 std::cout <<
"TrajectorySeedProducer: FTS momentum " << initialFTS.
momentum() << std::endl;
611 if (!initialTSOS.
isValid())
continue;
618 newTrackCandidate(recHits,
623 LogDebug(
"FastTracking")<<
"\tSeed Information " << std::endl
624 <<
"\tSeed Direction = " << aSeed->
direction() << std::endl
626 <<
"\tTrajectory Parameters " << std::endl
640 if (!newTrackCandidateIsDuplicate) output->push_back(newTrackCandidate);
641 LogDebug(
"FastTracking")<<
"filling a track candidate into the collection, now having: "<<output->size();
647 LogDebug(
"FastTracking") <<
"Saving "
648 << output->size() <<
" track candidates and "
649 << recoTracks->size() <<
" reco::Tracks ";
661 unsigned nTracks = recoTracks->size();
662 recoTrackExtras->reserve(nTracks);
680 for (
unsigned int ih=0; ih<nHits; ++ih) {
683 recoTrackExtras->push_back(aTrackExtra);
693 (recoTracks->at(
index)).setExtra(theTrackExtraRef);
706 recoTrajTrackMap->insert(trajRef,tkRef);
711 e.
put(recoTrajTrackMap);
720 for ( ; aHit!=lastHit; ++aHit ) {
721 if ( !aHit->get()->isValid() )
continue;
732 std::vector<TrackerRecHit>& theTrackerRecHits) {
740 theTrackerRecHits.push_back(
TrackerRecHit(mHit,theCurrentRecHit));
741 theTrackerRecHits.push_back(
TrackerRecHit(sHit,theCurrentRecHit));
745 theTrackerRecHits.push_back(
TrackerRecHit(sHit,theCurrentRecHit));
746 theTrackerRecHits.push_back(
TrackerRecHit(mHit,theCurrentRecHit));
753 typedef TrackCandidateCollection::const_iterator TCCI;
755 TCCI candsEnd = candidates.end();
760 for (TCCI iCand = candidates.begin(); iCand!= candsEnd; ++iCand){
762 double iQbp = iCand->trajectoryStateOnDet().parameters().qbp();
763 double iDxdz = iCand->trajectoryStateOnDet().parameters().dxdz();
764 if (newQbp == iQbp && newDxdz == iDxdz){
765 LogDebug(
"isDuplicateCandidate")<<
"Probably a duplicate "<<iQbp <<
" : "<<iDxdz;
767 unsigned int nHits = 0;
768 unsigned int nShared = 0;
769 unsigned int nnewHits = 0;
773 if (iiHit == iHits.first) nnewHits++;
777 LogDebug(
"isDuplicateCandidate") <<
"nHits "<<nHits<<
" nnewHits "<< nnewHits<<
" nShared "<<nShared;
778 if (nHits == nShared && nHits == nnewHits)
return true;
789 return localPointSame && localErrorSame;
PropagationDirection direction() const
const math::XYZVectorD & trackerSurfacePosition() const
T getParameter(std::string const &) const
unsigned int minNumberOfCrossedLayers
std::pair< const_iterator, const_iterator > range
iterator range
const int & simhitId() const
const LocalTrajectoryParameters & localParameters() const
friend struct const_iterator
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
TrackCandidateProducer(const edm::ParameterSet &conf)
int findId(const reco::Track &aTrack) const
const CurvilinearTrajectoryError & curvilinearError() const
std::vector< TrackCandidate > TrackCandidateCollection
std::vector< Track > TrackCollection
collection of Tracks
GlobalPoint globalPosition() const
bool innerOk() const
return true if the innermost hit is valid
const SiTrackerGSRecHit2D * stereoHit() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
std::pair< const_iterator, const_iterator > range
const math::XYZPoint & outerPosition() const
position of the outermost hit
float charge() const
charge
const MagneticField * theMagField
const Plane & surface() const
The nominal surface of the GeomDet.
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
unsigned int maxNumberOfCrossedLayers
edm::InputTag seedProducer
static int position[TOTALCHAMBERS][3]
bool isOnTheSameLayer(const TrackerRecHit &other) const
Check if two hits are on the same layer of the same subdetector.
virtual void produce(edm::Event &e, const edm::EventSetup &es) override
const math::XYZPoint & innerPosition() const
position of the innermost hit
uint32_t rawId() const
get the raw id
PTrajectoryStateOnDet const & trajectoryStateOnDet() const
virtual ~TrackCandidateProducer()
C::const_iterator const_iterator
constant access iterator type
AlgebraicVector5 vector() const
const int & simtrackId() const
const SurfaceType & surface() const
const SiTrackerGSMatchedRecHit2D * matchedHit() const
The Hit itself.
const SiTrackerGSRecHit2D * monoHit() const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
PropagatorWithMaterial * thePropagator
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
edm::InputTag hitProducer
std::vector< edm::InputTag > trackProducers
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
std::pair< const_iterator, const_iterator > range
bool isMatched(TrackingRecHit const &hit)
unsigned int detId() const
const AlgebraicSymMatrix55 & matrix() const
LocalVector momentum() const
Momentum vector in the local frame.
const LocalTrajectoryError & localError() const
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
virtual const GeomDet * idToDet(DetId) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
GlobalVector momentum() const
virtual TrackingRecHit * clone() const =0
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
edm::RefToBase< TrajectorySeed > seedRef() const
PTrajectoryStateOnDet const & startingState() const
const bool & isMatched() const
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
ROOT::Math::SVector< double, 5 > AlgebraicVector5
bool outerOk() const
return true if the outermost hit is valid
const GlobalTrajectoryParameters & globalParameters() const
virtual LocalError localPositionError() const =0
const math::XYZTLorentzVectorD & trackerSurfaceMomentum() const
virtual void beginRun(edm::Run const &run, const edm::EventSetup &es) override
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
key_type key() const
Accessor for product key.
T const * product() const
unsigned int layerNumber() const
The Layer Number.
ESHandle< TrackerGeometry > geometry
unsigned int nHits() const
const AlgebraicSymMatrix55 & matrix() const
GlobalVector globalMomentum() const
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
unsigned int subDetId() const
The subdet Id.
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
const TrackerGeometry * theGeometry
DetId geographicalId() const
bool sameLocalParameters(const TrackingRecHit *aH, const TrackingRecHit *bH) const
bool isDuplicateCandidate(const TrackCandidateCollection &candidates, const TrackCandidate &newCand) const
RecHitContainer::const_iterator const_iterator
virtual LocalPoint localPosition() const =0
const BasicVectorType & basicVector() const
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
std::vector< SimTrack > SimTrackContainer
const LocalTrajectoryParameters & parameters() const
void addSplitHits(const TrackerRecHit &, std::vector< TrackerRecHit > &)
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.