75 theCosmicFlag(par.getParameter<bool>(
"PropDirForCosmics")),
76 theDTRecHitLabel(par.getParameter<
InputTag>(
"DTRecSegmentLabel")),
77 theCSCRecHitLabel(par.getParameter<
InputTag>(
"CSCRecSegmentLabel")),
78 theGEMRecHitLabel(par.getParameter<
InputTag>(
"GEMRecHitLabel")),
90 string refitDirectionName = par.
getParameter<
string>(
"RefitDirection");
96 <<
"Wrong refit direction chosen in TrackTransformer ParameterSet"
98 <<
"Possible choices are:"
100 <<
"RefitDirection = insideOut or RefitDirection = outsideIn";
120 if (par.
existsAs<
double>(
"RescaleErrorFactor")) {
182 const int theMuonHitsOption,
184 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
193 if ((*hit)->isValid()) {
195 allRecHitsTemp.push_back((**hit).cloneForFit(*tkbuilder->geometry()->idToDet( (**hit).geographicalId() ) ) );
196 else if ((*hit)->geographicalId().det() ==
DetId::Muon) {
197 if ((*hit)->geographicalId().subdetId() == 3 && !
theRPCInTheFit) {
204 vector<Trajectory> refitted =
refit(globalTrack,track,allRecHitsTemp,theMuonHitsOption, tTopo);
214 const int theMuonHitsOption,
223 vector<int> stationHits(4,0);
224 map<DetId, int> hitMap;
231 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
239 vector <Trajectory> outputTraj;
241 if ((theMuonHitsOption == 1) || (theMuonHitsOption == 3) || (theMuonHitsOption == 4) ) {
243 vector <Trajectory> globalTraj =
transform(globalTrack, track, allRecHits);
245 if (!globalTraj.size()) {
247 return vector<Trajectory>();
251 << globalTraj.front().lastMeasurement().updatedState().freeState()->parameters() << endl;
253 if (theMuonHitsOption == 1 )
254 outputTraj.push_back(globalTraj.front());
256 if (theMuonHitsOption == 3 ) {
260 outputTraj =
transform(globalTrack, track, selectedRecHits);
263 if (theMuonHitsOption == 4 ) {
273 DYTRecHits = dytRefit.
filter(globalTraj.front());
275 if ((DYTRecHits.size() > 1) && (DYTRecHits.front()->globalPosition().mag() > DYTRecHits.back()->globalPosition().mag()))
277 outputTraj =
transform(globalTrack, track, DYTRecHits);
280 }
else if (theMuonHitsOption == 2 ) {
282 outputTraj =
transform(globalTrack, track, fmsRecHits);
286 if (outputTraj.size()) {
287 LogTrace(
theCategory) <<
"Refitted pt: " << outputTraj.front().firstMeasurement().updatedState().globalParameters().momentum().perp() << endl;
291 return vector<Trajectory>();
302 map<DetId, int> &hitMap)
const {
309 for (ConstRecHitContainer::const_iterator imrh = all.begin(); imrh != all.end(); imrh++ ) {
311 if ( (*imrh != 0 ) && !(*imrh)->isValid() )
continue;
316 DetId id = (*imrh)->geographicalId();
326 if ((*imrh)->recHits().size()>1) {
327 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
328 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
329 if ((*imrh)->recHits().size()>1) {
330 std::vector <const TrackingRecHit*> hits1d = (*hit2d)->recHits();
331 for (std::vector <const TrackingRecHit*>::const_iterator hit1d = hits1d.begin(); hit1d!= hits1d.end(); hit1d++) {
332 DetId id1 = (*hit1d)->geographicalId();
338 double rhitDistance = fabs(ir->localPosition().x()-(**hit1d).localPosition().x());
339 if ( rhitDistance < coneSize ) layerHits++;
341 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits <<
" SL: " << lid.superLayer() << endl;
343 if (layerHits>detRecHits) detRecHits=layerHits;
355 double rhitDistance = fabs(ir->localPosition().x()-(**imrh).localPosition().x());
356 if ( rhitDistance < coneSize ) detRecHits++;
358 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
366 if ((*imrh)->recHits().size()>1) {
367 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
368 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
369 DetId id1 = (*hit2d)->geographicalId();
377 double rhitDistance = (ir->localPosition()-(**hit2d).localPosition()).
mag();
378 if ( rhitDistance < coneSize ) layerHits++;
380 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
382 if (layerHits>detRecHits) detRecHits=layerHits;
389 double rhitDistance = (ir->localPosition()-(**imrh).localPosition()).
mag();
390 if ( rhitDistance < coneSize ) detRecHits++;
392 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
400 if ((*imrh)->recHits().size()>1) {
401 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
402 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
403 DetId id1 = (*hit2d)->geographicalId();
411 double rhitDistance = (ir->localPosition()-(**hit2d).localPosition()).
mag();
412 if ( rhitDistance < coneSize ) layerHits++;
414 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
416 if (layerHits>detRecHits) detRecHits=layerHits;
423 double rhitDistance = (ir->localPosition()-(**imrh).localPosition()).
mag();
424 if ( rhitDistance < coneSize ) detRecHits++;
426 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
435 map<DetId,int>::iterator imap=hitMap.find(chamberId);
436 if (imap!=hitMap.end()) {
437 if (detRecHits>imap->second) imap->second=detRecHits;
438 }
else hitMap[chamberId]=detRecHits;
442 for (map<DetId,int>::iterator imap=hitMap.begin(); imap!=hitMap.end(); imap++ )
443 LogTrace(
theCategory) <<
" Station " << imap->first.rawId() <<
": " << imap->second <<endl;
448 if ( (all.size() > 1) &&
449 ( all.front()->globalPosition().mag() >
450 all.back()->globalPosition().mag() ) ) {
464 LogTrace(
theCategory) <<
" GlobalMuonRefitter::getFirstHits\nall rechits length:" << all.size() << endl;
467 int station_to_keep = 999;
469 for (ConstRecHitContainer::const_iterator ihit = all.begin(); ihit != all.end(); ++ihit) {
473 DetId id = (*ihit)->geographicalId();
474 unsigned raw_id =
id.
rawId();
475 if (!(*ihit)->isValid()) station = -1;
478 switch (
id.subdetId()) {
488 if (use_it && station > 0 && station < station_to_keep) station_to_keep =
station;
489 stations.push_back(station);
490 LogTrace(
theCategory) <<
"rawId: " << raw_id <<
" station = " << station <<
" station_to_keep is now " << station_to_keep;
493 if (station_to_keep <= 0 || station_to_keep > 4 || stations.size() != all.size())
494 LogInfo(
theCategory) <<
"failed to getFirstHits (all muon hits are outliers/bad ?)! station_to_keep = "
495 << station_to_keep <<
" stations.size " << stations.size() <<
" all.size " << all.size();
497 for (
unsigned i = 0;
i < stations.size(); ++
i)
498 if (stations[
i] >= 0 && stations[
i] <= station_to_keep) first.push_back(all[
i]);
510 const map<DetId, int> &hitMap)
const {
513 const double globalChi2Cut = 200.0;
515 vector<TrajectoryMeasurement> muonMeasurements = traj.
measurements();
518 for (std::vector<TrajectoryMeasurement>::const_iterator im = muonMeasurements.begin(); im != muonMeasurements.end(); im++ ) {
520 if ( !(*im).recHit()->isValid() )
continue;
521 if ( (*im).recHit()->det()->geographicalId().det() !=
DetId::Muon ) {
523 muonRecHits.push_back((*im).recHit());
531 double chi2Cut = 0.0;
534 if ( (*immrh).isDT() ) {
541 else if ( (*immrh).isCSC() ) {
548 else if ( (*immrh).isGEM() ) {
555 else if ( (*immrh).isRPC() ) {
563 double chi2ndf = (*im).estimate()/(*im).recHit()->dimension();
566 map<DetId,int>::const_iterator imap=hitMap.find(chamberId);
567 if ( imap!=hitMap.end() )
568 if (imap->second>threshold) keep =
false;
570 if ( (keep || (chi2ndf<chi2Cut)) && (chi2ndf<globalChi2Cut) ) {
571 muonRecHits.push_back((*im).recHit());
574 <<
"Skip hit: " <<
id.rawId() <<
" chi2="
575 << chi2ndf <<
" ( threshold: " << chi2Cut <<
") Det: "
576 << imap->second << endl;
581 reverse(muonRecHits.begin(),muonRecHits.end());
592 for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
593 if ( !(*ir)->isValid() ) {
601 <<
"r = " <<
sqrt(pos.
x() * pos.
x() + pos.
y() * pos.
y())
602 <<
" z = " << pos.
z()
603 <<
" dimension = " << (*ir)->dimension()
604 <<
" det = " << (*ir)->det()->geographicalId().det()
605 <<
" subdet = " << (*ir)->det()->subDetector()
606 <<
" raw id = " << (*ir)->det()->geographicalId().rawId();
618 if (!recHits.empty()){
619 ConstRecHitContainer::const_iterator frontHit = recHits.begin();
620 ConstRecHitContainer::const_iterator backHit = recHits.end() - 1;
621 while( !(*frontHit)->isValid() && frontHit != backHit) {frontHit++;}
622 while( !(*backHit)->isValid() && backHit != frontHit) {backHit--;}
624 double rFirst = (*frontHit)->globalPosition().mag();
625 double rLast = (*backHit) ->globalPosition().mag();
628 else if(rFirst > rLast)
return outsideIn;
648 LogTrace(
theCategory) <<
"GlobalMuonRefitter::transform: " << recHitsForReFit.size() <<
" hits:";
651 if(recHitsForReFit.size() < 2)
return vector<Trajectory>();
661 if(
theRefitDirection != recHitsOrder) reverse(recHitsForReFit.begin(),recHitsForReFit.end());
668 unsigned int innerId;
679 inner_is_first =
true;
686 inner_is_first =
false;
690 <<
" globalPosition is " << firstTSOS.globalPosition()
691 <<
" innerId is " << innerId;
693 if(!firstTSOS.isValid()){
695 return vector<Trajectory>();
719 PropagationDirection propDir_last = (lastTSOS .globalPosition().basicVector().dot(lastTSOS .globalMomentum().basicVector()) > 0) ?
alongMomentum : oppositeToMomentum;
720 LogTrace(
theCategory) <<
"propDir_first " << propDir_first <<
", propdir_last " << propDir_last
721 <<
" : they " << (propDir_first == propDir_last ?
"agree" :
"disagree");
724 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = recHitsForReFit.begin(); it != recHitsForReFit.end(); ++it) {
725 if ((*it)->globalPosition().y() > 0) ++y_count;
740 <<
"; based on geometrically-outermost TSOS, propDir is " << propDir <<
": "
741 << (propDir == propDir_ycount ?
"agrees" :
"disagrees")
742 <<
" with ycount determination";
744 if (propDir_first != propDir_last) {
746 propDir = propDir_ycount;
752 if(recHitsForReFit.front()->geographicalId() !=
DetId(innerId)){
755 <<
" to first rechit with surface pos " << recHitsForReFit.front()->det()->surface().toGlobal(
LocalPoint(0,0,0));
757 if(!firstTSOS.isValid()){
759 return vector<Trajectory>();
782 if(trajectories.empty()){
784 return vector<Trajectory>();
797 ConstRecHitContainer::const_iterator it = hits.begin();
798 for (; it!=hits.end(); it++) {
800 DetId id = (*it)->geographicalId();
861 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
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
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.
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
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
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.