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> );
162 if(theSeeds->size() == 0) {
166 e.
put(recoTrackExtras);
167 e.
put(recoTrajectories);
168 e.
put(recoTrajTrackMap);
178 const std::vector<unsigned> theSimTrackIds = theGSRecHits->ids();
187 LogDebug(
"FastTracking")<<
"looking at: "<< theSimTrackIds.size()<<
" simtracks.";
199 std::vector<edm::Handle<reco::TrackCollection> > theTrackCollections;
200 std::vector<edm:: Handle<std::vector<Trajectory> > > theTrajectoryCollections;
201 std::vector<edm::Handle<TrajTrackAssociationCollection> > theAssoMaps;
202 std::vector<bool> isTrackCollections;
205 TrackMap theTrackMap;
207 unsigned nRecoHits = 0;
209 if ( nCollections ) {
210 theTrackCollections.resize(nCollections);
211 theTrajectoryCollections.resize(nCollections);
212 theAssoMaps.resize(nCollections);
213 isTrackCollections.resize(nCollections);
214 for (
unsigned tprod=0; tprod <
nCollections; ++tprod ) {
217 if ( isTrackCollections[tprod] ) {
219 reco::TrackCollection::const_iterator aTrack = theTrackCollections[tprod]->begin();
220 reco::TrackCollection::const_iterator lastTrack = theTrackCollections[tprod]->end();
222 for ( ; aTrack!=lastTrack; ++aTrack ) nRecoHits+= aTrack->recHitsSize();
226 anAssociation = theAssoMaps[tprod]->begin();
227 lastAssociation = theAssoMaps[tprod]->end();
230 std::cout <<
"List of tracks already reconstructed " << std::endl;
233 for ( ; anAssociation != lastAssociation; ++anAssociation ) {
237 int recoTrackId =
findId(*aTrackRef);
238 if ( recoTrackId < 0 )
continue;
243 theTrackMap[recoTrackId] = TrackPair(aTrackRef,aTrajectoryRef);
251 recoHits->reserve(nRecoHits);
256 int currentTrackId = -1;
266 std::cout <<
"Number of seeds : " << theSeeds->size() << std::endl;
268 unsigned seed_size = theSeeds->size();
269 for (
unsigned seednr = 0; seednr < seed_size; ++seednr){
271 LogDebug(
"FastTracking")<<
"looking at seed #:"<<seednr;
276 std::vector<int> simTrackIds;
277 std::map<int,TrajectoryStateOnSurface> seedStates;
278 std::map<int,TrajectoryStateOnSurface> simtkStates;
281 if (theSeeds->at(seednr).nHits()==0){
284 LogDebug(
"FastTracking")<<
" seed with no hits to be considered.";
293 const Surface * surface=&g->surface();
306 double minimunEst=1000000;
307 LogDebug(
"FastTracking")<<
"looking at: "<< theSimTrackIds.size()<<
" simtracks.";
308 for (
unsigned tkId=0; tkId != theSimTrackIds.size(); ++tkId ) {
310 const SimTrack & simtrack = (*theSimTracks)[theSimTrackIds[tkId]];
321 LogDebug(
"FastTracking")<<
"not on the same direction.";
336 if (!simtrack_comparestate.
isValid()){
337 LogDebug(
"FastTracking")<<
" ok this is a state-based seed. simtrack state does not propagate to the seed surface. skipping.";
341 LogDebug(
"FastTracking")<<
"not on the same direction.";
348 bool ierr = !
m.Invert();
350 edm::LogWarning(
"FastTracking") <<
" Candidate Producer cannot invert the error matrix! - Skipping...";
353 double est = ROOT::Math::Similarity(
v,
m);
354 LogDebug(
"FastTracking")<<
"comparing two state on the seed surface:\n"
355 <<
"seed: "<<seedState
356 <<
"sim: "<<simtrack_comparestate
357 <<
"\n estimator is: "<<est;
359 if (est<minimunEst) minimunEst=est;
361 simTrackIds.push_back(theSimTrackIds[tkId]);
372 LogDebug(
"FastTracking")<<
"the compatibility estimator is: "<<est<<
" for track id: "<<simTrackIds.back();
375 if (simTrackIds.size()==0)
LogDebug(
"FastTracking")<<
"could not find any simtrack within errors, closest was at: "<<minimunEst;
384 simTrackIds.push_back( theFirstSeedingRecHit->
simtrackId() );
390 for (
unsigned int iToMake=0;iToMake!=simTrackIds.size();++iToMake){
391 int simTrackId = simTrackIds[iToMake];
395 if (
seedCleaning && currentTrackId == simTrackId )
continue;
396 currentTrackId = simTrackId;
399 std::vector<TrackerRecHit> theTrackerRecHits;
400 unsigned theNumberOfCrossedLayers = 0;
403 TrackMap::const_iterator theTrackIt = theTrackMap.find(simTrackId);
404 if ( nCollections && theTrackIt != theTrackMap.end() ) {
407 LogDebug(
"FastTracking") <<
"Track " << simTrackId <<
" already reconstructed -> copy it";
414 recoTracks->push_back(aRecoTrack);
418 for (
unsigned ih=0; ih<nh; ++ih ) {
420 recoHits->push_back(hit);
424 recoTrajectories->push_back(*aTrajectoryRef);
428 LogDebug(
"FastTracking") <<
"Track " << simTrackId <<
" already reconstructed -> ignore it";
436 LogDebug(
"FastTracking")<<
"Track " << simTrackId <<
" is considered to return a track candidate" ;
444 LogDebug(
"FastTracking")<<
"counting: "<<theRecHitRangeIteratorEnd-theRecHitRangeIteratorBegin<<
" hits to be considered.";
446 bool firstRecHit =
true;
450 for ( iterRecHit = theRecHitRangeIteratorBegin;
451 iterRecHit != theRecHitRangeIteratorEnd;
458 if(!firstRecHit) thePreviousRecHit = theCurrentRecHit;
472 ++theNumberOfCrossedLayers;
479 else theTrackerRecHits.push_back(theCurrentRecHit);
492 else theTrackerRecHits.push_back(theCurrentRecHit);
500 theTrackerRecHits.pop_back();
508 theTrackerRecHits.back() = theCurrentRecHit;
514 theCurrentRecHit = thePreviousRecHit;
522 LogDebug(
"FastTracking")<<
" number of hits: " << theTrackerRecHits.size()<<
" after counting overlaps and splitting.";
526 unsigned nTrackerHits = theTrackerRecHits.
size();
530 LogDebug(
"FastTracking")<<
"reversing the order of the hits";
531 std::reverse(theTrackerRecHits.begin(),theTrackerRecHits.end());
534 for (
unsigned ih=0; ih<nTrackerHits; ++ih ) {
538 const DetId& detId = theTrackerRecHits[ih].hit()->geographicalId();
540 <<
"Added RecHit from detid " << detId.
rawId()
541 <<
" subdet = " << theTrackerRecHits[ih].subDetId()
542 <<
" layer = " << theTrackerRecHits[ih].layerNumber()
543 <<
" ring = " << theTrackerRecHits[ih].ringNumber()
544 <<
" error = " << theTrackerRecHits[ih].localError()
549 << theTrackerRecHits[ih].globalPosition().z() <<
" "
550 << theTrackerRecHits[ih].globalPosition().perp() << std::endl;
551 if ( theTrackerRecHits[ih].matchedHit() && theTrackerRecHits[ih].matchedHit()->
isMatched() )
552 LogTrace(
"FastTracking") <<
"Matched : " << theTrackerRecHits[ih].matchedHit()->isMatched()
553 <<
"Rphi Hit = " << theTrackerRecHits[ih].matchedHit()->monoHit()->simhitId()
554 <<
"Stereo Hit = " << theTrackerRecHits[ih].matchedHit()->stereoHit()->simhitId()
560 LogDebug(
"FastTracking")<<
"not enough layer crossed ("<<theNumberOfCrossedLayers<<
")";
571 if (aSeed->
nHits()==0){
579 int vertexIndex = (*theSimTracks)[currentTrackId].vertIndex();
582 (*theSimVtx)[vertexIndex].
position().
y(),
583 (*theSimVtx)[vertexIndex].
position().
z());
586 GlobalVector momentum( (*theSimTracks)[currentTrackId].momentum().
x() ,
587 (*theSimTracks)[currentTrackId].momentum().
y() ,
588 (*theSimTracks)[currentTrackId].momentum().
z() );
590 float charge = (*theSimTracks)[simTrackId].charge();
599 std::cout <<
"TrajectorySeedProducer: FTS momentum " << initialFTS.
momentum() << std::endl;
605 if (!initialTSOS.
isValid())
continue;
612 newTrackCandidate(recHits,
617 LogDebug(
"FastTracking")<<
"\tSeed Information " << std::endl
618 <<
"\tSeed Direction = " << aSeed->
direction() << std::endl
620 <<
"\tTrajectory Parameters " << std::endl
634 if (!newTrackCandidateIsDuplicate) output->push_back(newTrackCandidate);
635 LogDebug(
"FastTracking")<<
"filling a track candidate into the collection, now having: "<<output->size();
641 LogDebug(
"FastTracking") <<
"Saving "
642 << output->size() <<
" track candidates and "
643 << recoTracks->size() <<
" reco::Tracks ";
655 unsigned nTracks = recoTracks->size();
656 recoTrackExtras->reserve(nTracks);
674 for (
unsigned int ih=0; ih<nHits; ++ih) {
677 recoTrackExtras->push_back(aTrackExtra);
687 (recoTracks->at(
index)).setExtra(theTrackExtraRef);
700 recoTrajTrackMap->insert(trajRef,tkRef);
705 e.
put(recoTrajTrackMap);
714 for ( ; aHit!=lastHit; ++aHit ) {
715 if ( !aHit->get()->isValid() )
continue;
726 std::vector<TrackerRecHit>& theTrackerRecHits) {
734 theTrackerRecHits.push_back(
TrackerRecHit(mHit,theCurrentRecHit));
735 theTrackerRecHits.push_back(
TrackerRecHit(sHit,theCurrentRecHit));
739 theTrackerRecHits.push_back(
TrackerRecHit(sHit,theCurrentRecHit));
740 theTrackerRecHits.push_back(
TrackerRecHit(mHit,theCurrentRecHit));
747 typedef TrackCandidateCollection::const_iterator TCCI;
749 TCCI candsEnd = candidates.end();
754 for (TCCI iCand = candidates.begin(); iCand!= candsEnd; ++iCand){
756 double iQbp = iCand->trajectoryStateOnDet().parameters().qbp();
757 double iDxdz = iCand->trajectoryStateOnDet().parameters().dxdz();
758 if (newQbp == iQbp && newDxdz == iDxdz){
759 LogDebug(
"isDuplicateCandidate")<<
"Probably a duplicate "<<iQbp <<
" : "<<iDxdz;
761 unsigned int nHits = 0;
762 unsigned int nShared = 0;
763 unsigned int nnewHits = 0;
767 if (iiHit == iHits.first) nnewHits++;
771 LogDebug(
"isDuplicateCandidate") <<
"nHits "<<nHits<<
" nnewHits "<< nnewHits<<
" nShared "<<nShared;
772 if (nHits == nShared && nHits == nnewHits)
return true;
783 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
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
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
bool isOnTheSameLayer(const TrackerRecHit &other) const
Check if two hits are on the same layer of the same subdetector.
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
virtual void beginRun(edm::Run &run, const edm::EventSetup &es)
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
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
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
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
unsigned int layerNumber() const
The Layer Number.
ESHandle< TrackerGeometry > geometry
unsigned int nHits() const
const AlgebraicSymMatrix55 & matrix() const
GlobalVector globalMomentum() const
const BoundPlane & surface() const
The nominal surface of the GeomDet.
virtual void produce(edm::Event &e, const edm::EventSetup &es)
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
static int position[264][3]
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
unsigned int subDetId() const
The subdet Id.
const Surface & surface() const
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.