51 std::cout <<
"TrackCandidateProducer created" << std::endl;
55 produces<TrackCandidateCollection>();
59 produces<reco::TrackCollection>();
60 produces<TrackingRecHitCollection>();
61 produces<reco::TrackExtraCollection>();
62 produces<std::vector<Trajectory> >();
63 produces<TrajTrackAssociationCollection>();
103 for(
unsigned tprod=0; tprod < trackProducers.size(); ++tprod){
104 trackTokens.push_back(consumes<reco::TrackCollection>(trackProducers[tprod]));
106 assoMapTokens.push_back(consumes<TrajTrackAssociationCollection>(trackProducers[tprod]));
118 std::cout <<
"TrackCandidateProducer destructed" << std::endl;
146 std::cout <<
"################################################################" << std::endl;
147 std::cout <<
" TrackCandidateProducer produce init " << std::endl;
151 typedef std::pair<reco::TrackRef,edm::Ref<std::vector<Trajectory> > > TrackPair;
152 typedef std::map<unsigned,TrackPair> TrackMap;
159 std::auto_ptr<std::vector<Trajectory> > recoTrajectories(
new std::vector<Trajectory> );
174 if(theSeeds->size() == 0) {
178 e.
put(recoTrackExtras);
179 e.
put(recoTrajectories);
180 e.
put(recoTrajTrackMap);
190 const std::vector<unsigned> theSimTrackIds = theGSRecHits->ids();
199 LogDebug(
"FastTracking")<<
"looking at: "<< theSimTrackIds.size()<<
" simtracks.";
211 std::vector<edm::Handle<reco::TrackCollection> > theTrackCollections;
212 std::vector<edm:: Handle<std::vector<Trajectory> > > theTrajectoryCollections;
213 std::vector<edm::Handle<TrajTrackAssociationCollection> > theAssoMaps;
214 std::vector<bool> isTrackCollections;
217 TrackMap theTrackMap;
219 unsigned nRecoHits = 0;
221 if ( nCollections ) {
222 theTrackCollections.resize(nCollections);
223 theTrajectoryCollections.resize(nCollections);
224 theAssoMaps.resize(nCollections);
225 isTrackCollections.resize(nCollections);
226 for (
unsigned tprod=0; tprod <
nCollections; ++tprod ) {
229 if ( isTrackCollections[tprod] ) {
231 reco::TrackCollection::const_iterator aTrack = theTrackCollections[tprod]->begin();
232 reco::TrackCollection::const_iterator lastTrack = theTrackCollections[tprod]->end();
234 for ( ; aTrack!=lastTrack; ++aTrack ) nRecoHits+= aTrack->recHitsSize();
238 anAssociation = theAssoMaps[tprod]->begin();
239 lastAssociation = theAssoMaps[tprod]->end();
242 std::cout <<
"List of tracks already reconstructed " << std::endl;
245 for ( ; anAssociation != lastAssociation; ++anAssociation ) {
249 int recoTrackId =
findId(*aTrackRef);
250 if ( recoTrackId < 0 )
continue;
255 theTrackMap[recoTrackId] = TrackPair(aTrackRef,aTrajectoryRef);
263 recoHits->reserve(nRecoHits);
268 int currentTrackId = -1;
278 std::cout <<
"Number of seeds : " << theSeeds->size() << std::endl;
280 unsigned seed_size = theSeeds->size();
281 for (
unsigned seednr = 0; seednr < seed_size; ++seednr){
283 LogDebug(
"FastTracking")<<
"looking at seed #:"<<seednr;
288 std::vector<int> simTrackIds;
289 std::map<int,TrajectoryStateOnSurface> seedStates;
290 std::map<int,TrajectoryStateOnSurface> simtkStates;
293 if (theSeeds->at(seednr).nHits()==0){
296 LogDebug(
"FastTracking")<<
" seed with no hits to be considered.";
305 const Surface * surface=&g->surface();
318 double minimunEst=1000000;
319 LogDebug(
"FastTracking")<<
"looking at: "<< theSimTrackIds.size()<<
" simtracks.";
320 for (
unsigned tkId=0; tkId != theSimTrackIds.size(); ++tkId ) {
322 const SimTrack & simtrack = (*theSimTracks)[theSimTrackIds[tkId]];
333 LogDebug(
"FastTracking")<<
"not on the same direction.";
348 if (!simtrack_comparestate.
isValid()){
349 LogDebug(
"FastTracking")<<
" ok this is a state-based seed. simtrack state does not propagate to the seed surface. skipping.";
353 LogDebug(
"FastTracking")<<
"not on the same direction.";
360 bool ierr = !
m.Invert();
362 edm::LogWarning(
"FastTracking") <<
" Candidate Producer cannot invert the error matrix! - Skipping...";
365 double est = ROOT::Math::Similarity(
v,
m);
366 LogDebug(
"FastTracking")<<
"comparing two state on the seed surface:\n"
367 <<
"seed: "<<seedState
368 <<
"sim: "<<simtrack_comparestate
369 <<
"\n estimator is: "<<est;
371 if (est<minimunEst) minimunEst=est;
373 simTrackIds.push_back(theSimTrackIds[tkId]);
384 LogDebug(
"FastTracking")<<
"the compatibility estimator is: "<<est<<
" for track id: "<<simTrackIds.back();
387 if (simTrackIds.size()==0)
LogDebug(
"FastTracking")<<
"could not find any simtrack within errors, closest was at: "<<minimunEst;
396 simTrackIds.push_back( theFirstSeedingRecHit->
simtrackId() );
402 for (
unsigned int iToMake=0;iToMake!=simTrackIds.size();++iToMake){
403 int simTrackId = simTrackIds[iToMake];
407 if (
seedCleaning && currentTrackId == simTrackId )
continue;
408 currentTrackId = simTrackId;
411 std::vector<TrackerRecHit> theTrackerRecHits;
412 unsigned theNumberOfCrossedLayers = 0;
415 TrackMap::const_iterator theTrackIt = theTrackMap.find(simTrackId);
416 if ( nCollections && theTrackIt != theTrackMap.end() ) {
419 LogDebug(
"FastTracking") <<
"Track " << simTrackId <<
" already reconstructed -> copy it";
426 recoTracks->push_back(aRecoTrack);
430 for (
unsigned ih=0; ih<nh; ++ih ) {
432 recoHits->push_back(hit);
436 recoTrajectories->push_back(*aTrajectoryRef);
440 LogDebug(
"FastTracking") <<
"Track " << simTrackId <<
" already reconstructed -> ignore it";
448 LogDebug(
"FastTracking")<<
"Track " << simTrackId <<
" is considered to return a track candidate" ;
456 LogDebug(
"FastTracking")<<
"counting: "<<theRecHitRangeIteratorEnd-theRecHitRangeIteratorBegin<<
" hits to be considered.";
458 bool firstRecHit =
true;
462 for ( iterRecHit = theRecHitRangeIteratorBegin;
463 iterRecHit != theRecHitRangeIteratorEnd;
470 if(!firstRecHit) thePreviousRecHit = theCurrentRecHit;
484 ++theNumberOfCrossedLayers;
491 else theTrackerRecHits.push_back(theCurrentRecHit);
504 else theTrackerRecHits.push_back(theCurrentRecHit);
512 theTrackerRecHits.pop_back();
520 theTrackerRecHits.back() = theCurrentRecHit;
526 theCurrentRecHit = thePreviousRecHit;
534 LogDebug(
"FastTracking")<<
" number of hits: " << theTrackerRecHits.size()<<
" after counting overlaps and splitting.";
538 unsigned nTrackerHits = theTrackerRecHits.
size();
542 LogDebug(
"FastTracking")<<
"reversing the order of the hits";
543 std::reverse(theTrackerRecHits.begin(),theTrackerRecHits.end());
546 for (
unsigned ih=0; ih<nTrackerHits; ++ih ) {
550 const DetId& detId = theTrackerRecHits[ih].hit()->geographicalId();
552 <<
"Added RecHit from detid " << detId.
rawId()
553 <<
" subdet = " << theTrackerRecHits[ih].subDetId()
554 <<
" layer = " << theTrackerRecHits[ih].layerNumber()
555 <<
" ring = " << theTrackerRecHits[ih].ringNumber()
556 <<
" error = " << theTrackerRecHits[ih].localError()
561 << theTrackerRecHits[ih].globalPosition().z() <<
" "
562 << theTrackerRecHits[ih].globalPosition().perp() << std::endl;
563 if ( theTrackerRecHits[ih].matchedHit() && theTrackerRecHits[ih].matchedHit()->
isMatched() )
564 LogTrace(
"FastTracking") <<
"Matched : " << theTrackerRecHits[ih].matchedHit()->isMatched()
565 <<
"Rphi Hit = " << theTrackerRecHits[ih].matchedHit()->monoHit()->simhitId()
566 <<
"Stereo Hit = " << theTrackerRecHits[ih].matchedHit()->stereoHit()->simhitId()
572 LogDebug(
"FastTracking")<<
"not enough layer crossed ("<<theNumberOfCrossedLayers<<
")";
583 if (aSeed->
nHits()==0){
591 int vertexIndex = (*theSimTracks)[currentTrackId].vertIndex();
594 (*theSimVtx)[vertexIndex].
position().
y(),
595 (*theSimVtx)[vertexIndex].
position().
z());
598 GlobalVector momentum( (*theSimTracks)[currentTrackId].momentum().
x() ,
599 (*theSimTracks)[currentTrackId].momentum().
y() ,
600 (*theSimTracks)[currentTrackId].momentum().
z() );
602 float charge = (*theSimTracks)[simTrackId].charge();
611 std::cout <<
"TrajectorySeedProducer: FTS momentum " << initialFTS.
momentum() << std::endl;
617 if (!initialTSOS.
isValid())
continue;
624 newTrackCandidate(recHits,
629 LogDebug(
"FastTracking")<<
"\tSeed Information " << std::endl
630 <<
"\tSeed Direction = " << aSeed->
direction() << std::endl
632 <<
"\tTrajectory Parameters " << std::endl
646 if (!newTrackCandidateIsDuplicate) output->push_back(newTrackCandidate);
647 LogDebug(
"FastTracking")<<
"filling a track candidate into the collection, now having: "<<output->size();
653 LogDebug(
"FastTracking") <<
"Saving "
654 << output->size() <<
" track candidates and "
655 << recoTracks->size() <<
" reco::Tracks ";
667 unsigned nTracks = recoTracks->size();
668 recoTrackExtras->reserve(nTracks);
686 for (
unsigned int ih=0; ih<nHits; ++ih) {
689 recoTrackExtras->push_back(aTrackExtra);
699 (recoTracks->at(
index)).setExtra(theTrackExtraRef);
712 recoTrajTrackMap->insert(trajRef,tkRef);
717 e.
put(recoTrajTrackMap);
726 for ( ; aHit!=lastHit; ++aHit ) {
727 if ( !aHit->get()->isValid() )
continue;
738 std::vector<TrackerRecHit>& theTrackerRecHits) {
746 theTrackerRecHits.push_back(
TrackerRecHit(mHit,theCurrentRecHit));
747 theTrackerRecHits.push_back(
TrackerRecHit(sHit,theCurrentRecHit));
751 theTrackerRecHits.push_back(
TrackerRecHit(sHit,theCurrentRecHit));
752 theTrackerRecHits.push_back(
TrackerRecHit(mHit,theCurrentRecHit));
759 typedef TrackCandidateCollection::const_iterator TCCI;
761 TCCI candsEnd = candidates.end();
766 for (TCCI iCand = candidates.begin(); iCand!= candsEnd; ++iCand){
768 double iQbp = iCand->trajectoryStateOnDet().parameters().qbp();
769 double iDxdz = iCand->trajectoryStateOnDet().parameters().dxdz();
770 if (newQbp == iQbp && newDxdz == iDxdz){
771 LogDebug(
"isDuplicateCandidate")<<
"Probably a duplicate "<<iQbp <<
" : "<<iDxdz;
773 unsigned int nHits = 0;
774 unsigned int nShared = 0;
775 unsigned int nnewHits = 0;
779 if (iiHit == iHits.first) nnewHits++;
783 LogDebug(
"isDuplicateCandidate") <<
"nHits "<<nHits<<
" nnewHits "<< nnewHits<<
" nShared "<<nShared;
784 if (nHits == nShared && nHits == nnewHits)
return true;
795 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
std::vector< edm::EDGetTokenT< reco::TrackCollection > > trackTokens
const LocalTrajectoryParameters & localParameters() const
friend struct const_iterator
edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::EDGetTokenT< edm::SimVertexContainer > simVertexToken
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
edm::EDGetTokenT< edm::SimTrackContainer > simTrackToken
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.
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
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
edm::EDGetTokenT< SiTrackerGSMatchedRecHit2DCollection > recHitToken
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
GlobalVector momentum() const
virtual TrackingRecHit * clone() const =0
virtual TrackingRecHit const * hit() 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
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.
std::vector< edm::EDGetTokenT< std::vector< Trajectory > > > trajectoryTokens
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
std::vector< edm::EDGetTokenT< TrajTrackAssociationCollection > > assoMapTokens
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.