70 theCosmicFlag(par.getParameter<bool>(
"PropDirForCosmics")),
71 theDTRecHitLabel(par.getParameter<
InputTag>(
"DTRecSegmentLabel")),
72 theCSCRecHitLabel(par.getParameter<
InputTag>(
"CSCRecSegmentLabel")),
83 string refitDirectionName = par.
getParameter<
string>(
"RefitDirection");
89 <<
"Wrong refit direction chosen in TrackTransformer ParameterSet"
91 <<
"Possible choices are:"
93 <<
"RefitDirection = insideOut or RefitDirection = outsideIn";
113 if (par.
existsAs<
double>(
"RescaleErrorFactor")) {
173 const int theMuonHitsOption,
175 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
184 if ((*hit)->isValid()) {
186 allRecHitsTemp.push_back((**hit).cloneForFit(*tkbuilder->geometry()->idToDet( (**hit).geographicalId() ) ) );
187 else if ((*hit)->geographicalId().det() ==
DetId::Muon) {
188 if ((*hit)->geographicalId().subdetId() == 3 && !
theRPCInTheFit) {
195 vector<Trajectory> refitted =
refit(globalTrack,track,allRecHitsTemp,theMuonHitsOption, tTopo);
205 const int theMuonHitsOption,
214 vector<int> stationHits(4,0);
215 map<DetId, int> hitMap;
222 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
230 vector <Trajectory> outputTraj;
232 if ((theMuonHitsOption == 1) || (theMuonHitsOption == 3) || (theMuonHitsOption == 4) ) {
234 vector <Trajectory> globalTraj =
transform(globalTrack, track, allRecHits);
236 if (!globalTraj.size()) {
238 return vector<Trajectory>();
242 << globalTraj.front().lastMeasurement().updatedState().freeState()->parameters() << endl;
244 if (theMuonHitsOption == 1 )
245 outputTraj.push_back(globalTraj.front());
247 if (theMuonHitsOption == 3 ) {
251 outputTraj =
transform(globalTrack, track, selectedRecHits);
254 if (theMuonHitsOption == 4 ) {
264 DYTRecHits = dytRefit.
filter(globalTraj.front());
266 if ((DYTRecHits.size() > 1) && (DYTRecHits.front()->globalPosition().mag() > DYTRecHits.back()->globalPosition().mag()))
268 outputTraj =
transform(globalTrack, track, DYTRecHits);
271 }
else if (theMuonHitsOption == 2 ) {
273 outputTraj =
transform(globalTrack, track, fmsRecHits);
277 if (outputTraj.size()) {
278 LogTrace(
theCategory) <<
"Refitted pt: " << outputTraj.front().firstMeasurement().updatedState().globalParameters().momentum().perp() << endl;
282 return vector<Trajectory>();
293 map<DetId, int> &hitMap)
const {
300 for (ConstRecHitContainer::const_iterator imrh = all.begin(); imrh != all.end(); imrh++ ) {
302 if ( (*imrh != 0 ) && !(*imrh)->isValid() )
continue;
307 DetId id = (*imrh)->geographicalId();
317 if ((*imrh)->recHits().size()>1) {
318 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
319 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
320 if ((*imrh)->recHits().size()>1) {
321 std::vector <const TrackingRecHit*> hits1d = (*hit2d)->recHits();
322 for (std::vector <const TrackingRecHit*>::const_iterator hit1d = hits1d.begin(); hit1d!= hits1d.end(); hit1d++) {
323 DetId id1 = (*hit1d)->geographicalId();
329 double rhitDistance = fabs(ir->localPosition().x()-(**hit1d).localPosition().x());
330 if ( rhitDistance < coneSize ) layerHits++;
332 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits <<
" SL: " << lid.superLayer() << endl;
334 if (layerHits>detRecHits) detRecHits=layerHits;
346 double rhitDistance = fabs(ir->localPosition().x()-(**imrh).localPosition().x());
347 if ( rhitDistance < coneSize ) detRecHits++;
349 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
357 if ((*imrh)->recHits().size()>1) {
358 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
359 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
360 DetId id1 = (*hit2d)->geographicalId();
368 double rhitDistance = (ir->localPosition()-(**hit2d).localPosition()).
mag();
369 if ( rhitDistance < coneSize ) layerHits++;
371 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
373 if (layerHits>detRecHits) detRecHits=layerHits;
380 double rhitDistance = (ir->localPosition()-(**imrh).localPosition()).
mag();
381 if ( rhitDistance < coneSize ) detRecHits++;
383 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
392 map<DetId,int>::iterator imap=hitMap.find(chamberId);
393 if (imap!=hitMap.end()) {
394 if (detRecHits>imap->second) imap->second=detRecHits;
395 }
else hitMap[chamberId]=detRecHits;
399 for (map<DetId,int>::iterator imap=hitMap.begin(); imap!=hitMap.end(); imap++ )
400 LogTrace(
theCategory) <<
" Station " << imap->first.rawId() <<
": " << imap->second <<endl;
405 if ( (all.size() > 1) &&
406 ( all.front()->globalPosition().mag() >
407 all.back()->globalPosition().mag() ) ) {
421 LogTrace(
theCategory) <<
" GlobalMuonRefitter::getFirstHits\nall rechits length:" << all.size() << endl;
424 int station_to_keep = 999;
426 for (ConstRecHitContainer::const_iterator ihit = all.begin(); ihit != all.end(); ++ihit) {
430 DetId id = (*ihit)->geographicalId();
431 unsigned raw_id =
id.
rawId();
432 if (!(*ihit)->isValid()) station = -1;
435 switch (
id.subdetId()) {
443 if (use_it && station > 0 && station < station_to_keep) station_to_keep =
station;
444 stations.push_back(station);
446 LogTrace(
theCategory) <<
"rawId: " << raw_id <<
" station = " << station <<
" station_to_keep is now " << station_to_keep;
449 if (station_to_keep <= 0 || station_to_keep > 4 || stations.size() != all.size())
450 LogInfo(
theCategory) <<
"failed to getFirstHits (all muon hits are outliers/bad ?)! station_to_keep = "
451 << station_to_keep <<
" stations.size " << stations.size() <<
" all.size " << all.size();
453 for (
unsigned i = 0;
i < stations.size(); ++
i)
454 if (stations[
i] >= 0 && stations[
i] <= station_to_keep) first.push_back(all[
i]);
466 const map<DetId, int> &hitMap)
const {
469 const double globalChi2Cut = 200.0;
471 vector<TrajectoryMeasurement> muonMeasurements = traj.
measurements();
474 for (std::vector<TrajectoryMeasurement>::const_iterator im = muonMeasurements.begin(); im != muonMeasurements.end(); im++ ) {
476 if ( !(*im).recHit()->isValid() )
continue;
477 if ( (*im).recHit()->det()->geographicalId().det() !=
DetId::Muon ) {
479 muonRecHits.push_back((*im).recHit());
487 double chi2Cut = 0.0;
490 if ( (*immrh).isDT() ) {
497 else if ( (*immrh).isCSC() ) {
504 else if ( (*immrh).isRPC() ) {
512 double chi2ndf = (*im).estimate()/(*im).recHit()->dimension();
515 map<DetId,int>::const_iterator imap=hitMap.find(chamberId);
516 if ( imap!=hitMap.end() )
517 if (imap->second>threshold) keep =
false;
519 if ( (keep || (chi2ndf<chi2Cut)) && (chi2ndf<globalChi2Cut) ) {
520 muonRecHits.push_back((*im).recHit());
523 <<
"Skip hit: " <<
id.rawId() <<
" chi2="
524 << chi2ndf <<
" ( threshold: " << chi2Cut <<
") Det: "
525 << imap->second << endl;
530 reverse(muonRecHits.begin(),muonRecHits.end());
541 for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
542 if ( !(*ir)->isValid() ) {
550 <<
"r = " <<
sqrt(pos.
x() * pos.
x() + pos.
y() * pos.
y())
551 <<
" z = " << pos.
z()
552 <<
" dimension = " << (*ir)->dimension()
553 <<
" det = " << (*ir)->det()->geographicalId().det()
554 <<
" subdet = " << (*ir)->det()->subDetector()
555 <<
" raw id = " << (*ir)->det()->geographicalId().rawId();
567 if (!recHits.empty()){
568 ConstRecHitContainer::const_iterator frontHit = recHits.begin();
569 ConstRecHitContainer::const_iterator backHit = recHits.end() - 1;
570 while( !(*frontHit)->isValid() && frontHit != backHit) {frontHit++;}
571 while( !(*backHit)->isValid() && backHit != frontHit) {backHit--;}
573 double rFirst = (*frontHit)->globalPosition().mag();
574 double rLast = (*backHit) ->globalPosition().mag();
577 else if(rFirst > rLast)
return outsideIn;
597 LogTrace(
theCategory) <<
"GlobalMuonRefitter::transform: " << recHitsForReFit.size() <<
" hits:";
600 if(recHitsForReFit.size() < 2)
return vector<Trajectory>();
610 if(
theRefitDirection != recHitsOrder) reverse(recHitsForReFit.begin(),recHitsForReFit.end());
617 unsigned int innerId;
628 inner_is_first =
true;
635 inner_is_first =
false;
639 <<
" globalPosition is " << firstTSOS.globalPosition()
640 <<
" innerId is " << innerId;
642 if(!firstTSOS.isValid()){
644 return vector<Trajectory>();
668 PropagationDirection propDir_last = (lastTSOS .globalPosition().basicVector().dot(lastTSOS .globalMomentum().basicVector()) > 0) ?
alongMomentum : oppositeToMomentum;
669 LogTrace(
theCategory) <<
"propDir_first " << propDir_first <<
", propdir_last " << propDir_last
670 <<
" : they " << (propDir_first == propDir_last ?
"agree" :
"disagree");
673 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = recHitsForReFit.begin(); it != recHitsForReFit.end(); ++it) {
674 if ((*it)->globalPosition().y() > 0) ++y_count;
689 <<
"; based on geometrically-outermost TSOS, propDir is " << propDir <<
": "
690 << (propDir == propDir_ycount ?
"agrees" :
"disagrees")
691 <<
" with ycount determination";
693 if (propDir_first != propDir_last) {
695 propDir = propDir_ycount;
701 if(recHitsForReFit.front()->geographicalId() !=
DetId(innerId)){
704 <<
" to first rechit with surface pos " << recHitsForReFit.front()->det()->surface().toGlobal(
LocalPoint(0,0,0));
706 if(!firstTSOS.isValid()){
708 return vector<Trajectory>();
731 if(trajectories.empty()){
733 return vector<Trajectory>();
747 ConstRecHitContainer::const_iterator it = hits.begin();
748 for (; it!=hits.end(); it++) {
750 DetId id = (*it)->geographicalId();
808 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
std::string thePropagatorName
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
unsigned int pxfDisk(const DetId &id) const
std::string theFitterName
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
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
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.
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
virtual void setEvent(const edm::Event &)
pass the Event to the algo at each event
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 > &)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
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
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.