78 theCosmicFlag(par.getParameter<bool>(
"PropDirForCosmics")),
79 theDTRecHitLabel(par.getParameter<
InputTag>(
"DTRecSegmentLabel")),
80 theCSCRecHitLabel(par.getParameter<
InputTag>(
"CSCRecSegmentLabel")),
81 theGEMRecHitLabel(par.getParameter<
InputTag>(
"GEMRecHitLabel")),
82 theME0RecHitLabel(par.getParameter<
InputTag>(
"ME0RecHitLabel")),
95 string refitDirectionName = par.
getParameter<
string>(
"RefitDirection");
101 <<
"Wrong refit direction chosen in TrackTransformer ParameterSet"
103 <<
"Possible choices are:"
105 <<
"RefitDirection = insideOut or RefitDirection = outsideIn";
125 if (par.
existsAs<
double>(
"RescaleErrorFactor")) {
189 const int theMuonHitsOption,
191 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
200 if ((*hit)->isValid()) {
202 allRecHitsTemp.push_back((**hit).cloneForFit(*tkbuilder->geometry()->idToDet( (**hit).geographicalId() ) ) );
203 else if ((*hit)->geographicalId().det() ==
DetId::Muon) {
204 if ((*hit)->geographicalId().subdetId() == 3 && !
theRPCInTheFit) {
211 vector<Trajectory> refitted =
refit(globalTrack,track,allRecHitsTemp,theMuonHitsOption, tTopo);
221 const int theMuonHitsOption,
230 vector<int> stationHits(4,0);
231 map<DetId, int> hitMap;
238 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
246 vector <Trajectory> outputTraj;
248 if ((theMuonHitsOption == 1) || (theMuonHitsOption == 3) || (theMuonHitsOption == 4) ) {
250 vector <Trajectory> globalTraj =
transform(globalTrack, track, allRecHits);
252 if (!globalTraj.size()) {
254 return vector<Trajectory>();
258 << globalTraj.front().lastMeasurement().updatedState().freeState()->parameters() << endl;
260 if (theMuonHitsOption == 1 )
261 outputTraj.push_back(globalTraj.front());
263 if (theMuonHitsOption == 3 ) {
267 outputTraj =
transform(globalTrack, track, selectedRecHits);
270 if (theMuonHitsOption == 4 ) {
280 DYTRecHits = dytRefit.
filter(globalTraj.front());
282 if ((DYTRecHits.size() > 1) && (DYTRecHits.front()->globalPosition().mag() > DYTRecHits.back()->globalPosition().mag()))
284 outputTraj =
transform(globalTrack, track, DYTRecHits);
287 }
else if (theMuonHitsOption == 2 ) {
289 outputTraj =
transform(globalTrack, track, fmsRecHits);
293 if (outputTraj.size()) {
294 LogTrace(
theCategory) <<
"Refitted pt: " << outputTraj.front().firstMeasurement().updatedState().globalParameters().momentum().perp() << endl;
298 return vector<Trajectory>();
309 map<DetId, int> &hitMap)
const {
316 for (ConstRecHitContainer::const_iterator imrh = all.begin(); imrh != all.end(); imrh++ ) {
318 if ( (*imrh != 0 ) && !(*imrh)->isValid() )
continue;
323 DetId id = (*imrh)->geographicalId();
333 if ((*imrh)->recHits().size()>1) {
334 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
335 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
336 if ((*imrh)->recHits().size()>1) {
337 std::vector <const TrackingRecHit*> hits1d = (*hit2d)->recHits();
338 for (std::vector <const TrackingRecHit*>::const_iterator hit1d = hits1d.begin(); hit1d!= hits1d.end(); hit1d++) {
339 DetId id1 = (*hit1d)->geographicalId();
345 double rhitDistance = fabs(ir->localPosition().x()-(**hit1d).localPosition().x());
346 if ( rhitDistance < coneSize ) layerHits++;
348 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits <<
" SL: " << lid.superLayer() << endl;
350 if (layerHits>detRecHits) detRecHits=layerHits;
362 double rhitDistance = fabs(ir->localPosition().x()-(**imrh).localPosition().x());
363 if ( rhitDistance < coneSize ) detRecHits++;
365 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
373 if ((*imrh)->recHits().size()>1) {
374 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
375 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
376 DetId id1 = (*hit2d)->geographicalId();
384 double rhitDistance = (ir->localPosition()-(**hit2d).localPosition()).
mag();
385 if ( rhitDistance < coneSize ) layerHits++;
387 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
389 if (layerHits>detRecHits) detRecHits=layerHits;
396 double rhitDistance = (ir->localPosition()-(**imrh).localPosition()).
mag();
397 if ( rhitDistance < coneSize ) detRecHits++;
399 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
407 if ((*imrh)->recHits().size()>1) {
408 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
409 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
410 DetId id1 = (*hit2d)->geographicalId();
418 double rhitDistance = (ir->localPosition()-(**hit2d).localPosition()).
mag();
419 if ( rhitDistance < coneSize ) layerHits++;
421 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
423 if (layerHits>detRecHits) detRecHits=layerHits;
430 double rhitDistance = (ir->localPosition()-(**imrh).localPosition()).
mag();
431 if ( rhitDistance < coneSize ) detRecHits++;
433 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
441 if ((*imrh)->recHits().size()>1) {
442 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
443 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
444 DetId id1 = (*hit2d)->geographicalId();
452 double rhitDistance = (ir->localPosition()-(**hit2d).localPosition()).
mag();
453 if ( rhitDistance < coneSize ) layerHits++;
455 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
457 if (layerHits>detRecHits) detRecHits=layerHits;
464 double rhitDistance = (ir->localPosition()-(**imrh).localPosition()).
mag();
465 if ( rhitDistance < coneSize ) detRecHits++;
467 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
476 map<DetId,int>::iterator imap=hitMap.find(chamberId);
477 if (imap!=hitMap.end()) {
478 if (detRecHits>imap->second) imap->second=detRecHits;
479 }
else hitMap[chamberId]=detRecHits;
483 for (map<DetId,int>::iterator imap=hitMap.begin(); imap!=hitMap.end(); imap++ )
484 LogTrace(
theCategory) <<
" Station " << imap->first.rawId() <<
": " << imap->second <<endl;
489 if ( (all.size() > 1) &&
490 ( all.front()->globalPosition().mag() >
491 all.back()->globalPosition().mag() ) ) {
505 LogTrace(
theCategory) <<
" GlobalMuonRefitter::getFirstHits\nall rechits length:" << all.size() << endl;
508 int station_to_keep = 999;
510 for (ConstRecHitContainer::const_iterator ihit = all.begin(); ihit != all.end(); ++ihit) {
514 DetId id = (*ihit)->geographicalId();
515 unsigned raw_id =
id.
rawId();
516 if (!(*ihit)->isValid()) station = -1;
519 switch (
id.subdetId()) {
530 if (use_it && station > 0 && station < station_to_keep) station_to_keep =
station;
531 stations.push_back(station);
532 LogTrace(
theCategory) <<
"rawId: " << raw_id <<
" station = " << station <<
" station_to_keep is now " << station_to_keep;
535 if (station_to_keep <= 0 || station_to_keep > 4 || stations.size() != all.size())
536 LogInfo(
theCategory) <<
"failed to getFirstHits (all muon hits are outliers/bad ?)! station_to_keep = "
537 << station_to_keep <<
" stations.size " << stations.size() <<
" all.size " << all.size();
539 for (
unsigned i = 0;
i < stations.size(); ++
i)
540 if (stations[
i] >= 0 && stations[
i] <= station_to_keep) first.push_back(all[
i]);
552 const map<DetId, int> &hitMap)
const {
555 const double globalChi2Cut = 200.0;
557 vector<TrajectoryMeasurement> muonMeasurements = traj.
measurements();
560 for (std::vector<TrajectoryMeasurement>::const_iterator im = muonMeasurements.begin(); im != muonMeasurements.end(); im++ ) {
562 if ( !(*im).recHit()->isValid() )
continue;
563 if ( (*im).recHit()->det()->geographicalId().det() !=
DetId::Muon ) {
565 muonRecHits.push_back((*im).recHit());
573 double chi2Cut = 0.0;
576 if ( (*immrh).isDT() ) {
583 else if ( (*immrh).isCSC() ) {
590 else if ( (*immrh).isGEM() ) {
597 else if ( (*immrh).isME0() ) {
604 else if ( (*immrh).isRPC() ) {
612 double chi2ndf = (*im).estimate()/(*im).recHit()->dimension();
615 map<DetId,int>::const_iterator imap=hitMap.find(chamberId);
616 if ( imap!=hitMap.end() )
617 if (imap->second>threshold) keep =
false;
619 if ( (keep || (chi2ndf<chi2Cut)) && (chi2ndf<globalChi2Cut) ) {
620 muonRecHits.push_back((*im).recHit());
623 <<
"Skip hit: " <<
id.rawId() <<
" chi2="
624 << chi2ndf <<
" ( threshold: " << chi2Cut <<
") Det: "
625 << imap->second << endl;
630 reverse(muonRecHits.begin(),muonRecHits.end());
641 for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
642 if ( !(*ir)->isValid() ) {
650 <<
"r = " <<
sqrt(pos.
x() * pos.
x() + pos.
y() * pos.
y())
651 <<
" z = " << pos.
z()
652 <<
" dimension = " << (*ir)->dimension()
653 <<
" det = " << (*ir)->det()->geographicalId().det()
654 <<
" subdet = " << (*ir)->det()->subDetector()
655 <<
" raw id = " << (*ir)->det()->geographicalId().rawId();
667 if (!recHits.empty()){
668 ConstRecHitContainer::const_iterator frontHit = recHits.begin();
669 ConstRecHitContainer::const_iterator backHit = recHits.end() - 1;
670 while( !(*frontHit)->isValid() && frontHit != backHit) {frontHit++;}
671 while( !(*backHit)->isValid() && backHit != frontHit) {backHit--;}
673 double rFirst = (*frontHit)->globalPosition().mag();
674 double rLast = (*backHit) ->globalPosition().mag();
677 else if(rFirst > rLast)
return outsideIn;
697 LogTrace(
theCategory) <<
"GlobalMuonRefitter::transform: " << recHitsForReFit.size() <<
" hits:";
700 if(recHitsForReFit.size() < 2)
return vector<Trajectory>();
710 if(
theRefitDirection != recHitsOrder) reverse(recHitsForReFit.begin(),recHitsForReFit.end());
717 unsigned int innerId;
728 inner_is_first =
true;
735 inner_is_first =
false;
739 <<
" globalPosition is " << firstTSOS.globalPosition()
740 <<
" innerId is " << innerId;
742 if(!firstTSOS.isValid()){
744 return vector<Trajectory>();
768 PropagationDirection propDir_last = (lastTSOS .globalPosition().basicVector().dot(lastTSOS .globalMomentum().basicVector()) > 0) ?
alongMomentum : oppositeToMomentum;
769 LogTrace(
theCategory) <<
"propDir_first " << propDir_first <<
", propdir_last " << propDir_last
770 <<
" : they " << (propDir_first == propDir_last ?
"agree" :
"disagree");
773 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = recHitsForReFit.begin(); it != recHitsForReFit.end(); ++it) {
774 if ((*it)->globalPosition().y() > 0) ++y_count;
789 <<
"; based on geometrically-outermost TSOS, propDir is " << propDir <<
": "
790 << (propDir == propDir_ycount ?
"agrees" :
"disagrees")
791 <<
" with ycount determination";
793 if (propDir_first != propDir_last) {
795 propDir = propDir_ycount;
801 if(recHitsForReFit.front()->geographicalId() !=
DetId(innerId)){
804 <<
" to first rechit with surface pos " << recHitsForReFit.front()->det()->surface().toGlobal(
LocalPoint(0,0,0));
806 if(!firstTSOS.isValid()){
808 return vector<Trajectory>();
831 if(trajectories.empty()){
833 return vector<Trajectory>();
846 ConstRecHitContainer::const_iterator it = hits.begin();
847 for (; it!=hits.end(); it++) {
849 DetId id = (*it)->geographicalId();
913 results.push_back(*it);
std::string theMuonRecHitBuilderName
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void printHits(const ConstRecHitContainer &) const
print all RecHits of a trajectory
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::Handle< DTRecHitCollection > theDTRecHits
void setProd(const edm::Handle< DTRecSegment4DCollection > &DTSegProd, const edm::Handle< CSCSegmentCollection > &CSCSegProd)
std::pair< const_iterator, const_iterator > range
iterator range
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
const MuonServiceProxy * theService
unsigned int tibLayer(const DetId &id) const
RefitDirection theRefitDirection
edm::ESHandle< TransientTrackingRecHitBuilder > theTrackerRecHitBuilder
edm::Handle< CSCSegmentCollection > CSCSegments
ME0DetId chamberId() const
Return the corresponding ChamberId (mask layers)
std::string thePropagatorName
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
unsigned int pxfDisk(const DetId &id) const
std::string theFitterName
edm::Handle< GEMRecHitCollection > theGEMRecHits
GlobalPoint globalPosition() const
void setServices(const edm::EventSetup &)
set the services needed by the TrackTransformer
unsigned int tidWheel(const DetId &id) const
void CopyFrom(const DYTInfo &)
copy from another DYTInfo
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
edm::EDGetTokenT< CSCSegmentCollection > CSCSegmentsToken
std::unique_ptr< TrajectoryFitter > theFitter
edm::ESHandle< TransientTrackingRecHitBuilder > theMuonRecHitBuilder
edm::Handle< ME0SegmentCollection > theME0RecHits
void checkMuonHits(const reco::Track &, ConstRecHitContainer &, std::map< DetId, int > &) const
check muon RecHits, calculate chamber occupancy and select hits to be used in the final fit ...
TrajectoryStateOnSurface innermostMeasurementState() const
std::vector< int > theDYTthrs
GEMDetId chamberId() const
Return the corresponding ChamberId.
void getFirstHits(const reco::Track &, ConstRecHitContainer &, ConstRecHitContainer &) const
get the RecHits in the tracker and the first muon chamber with hits
const edm::Event * theEvent
uint32_t rawId() const
get the raw id
DataContainer const & measurements() const
edm::Handle< DTRecSegment4DCollection > all4DSegments
ConstRecHitContainer selectMuonHits(const Trajectory &, const std::map< DetId, int > &) const
select muon hits compatible with trajectory; check hits in chambers with showers
ConstRecHitContainer getRidOfSelectStationHits(const ConstRecHitContainer &hits, const TrackerTopology *tTopo) const
double theRescaleErrorFactor
double pt() const
track transverse momentum
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
int station() const
Station id : the station is the pair of chambers at same disk.
edm::EDGetTokenT< ME0SegmentCollection > theME0RecHitToken
CSCDetId chamberId() const
edm::Handle< CSCRecHit2DCollection > theCSCRecHits
int theTrackerSkipSection
RefitDirection checkRecHitsOrdering(const ConstRecHitContainer &) const
edm::EDGetTokenT< DTRecHitCollection > theDTRecHitToken
edm::EDGetTokenT< CSCRecHit2DCollection > theCSCRecHitToken
TrajectoryStateOnSurface outermostMeasurementState() const
TransientTrackingRecHit::ConstRecHitContainer filter(const Trajectory &)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
edm::InputTag theDTRecHitLabel
std::vector< ConstRecHitPointer > ConstRecHitContainer
unsigned int pxbLayer(const DetId &id) const
edm::InputTag theGEMRecHitLabel
virtual void setEvent(const edm::Event &)
pass the Event to the algo at each event
edm::InputTag theME0RecHitLabel
GlobalMuonRefitter(const edm::ParameterSet &, const MuonServiceProxy *, edm::ConsumesCollector &)
constructor with Parameter Set and MuonServiceProxy
edm::EDGetTokenT< DTRecSegment4DCollection > all4DSegmentsToken
T const * product() const
reco::DYTInfo getDYTInfo()
GlobalVector globalMomentum() const
virtual ~GlobalMuonRefitter()
destructor
DetId geographicalId() const
unsigned long long theCacheId_TRH
int station() const
Return the station number.
std::string theTrackerRecHitBuilderName
const BasicVectorType & basicVector() const
unsigned int tecWheel(const DetId &id) const
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
void setThr(const std::vector< int > &)
std::vector< Trajectory > refit(const reco::Track &globalTrack, const int theMuonHitsOption, const TrackerTopology *tTopo) const
build combined trajectory from sta Track and tracker RecHits
void setUpdateState(bool)
unsigned int tobLayer(const DetId &id) const
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
edm::InputTag theCSCRecHitLabel
edm::EDGetTokenT< GEMRecHitCollection > theGEMRecHitToken
std::vector< Trajectory > transform(const reco::Track &newTrack, const reco::TransientTrack track, const TransientTrackingRecHit::ConstRecHitContainer &recHitsForReFit) const
refit the track with a new set of RecHits
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.