71 theCosmicFlag(par.getParameter<bool>(
"PropDirForCosmics")),
72 theDTRecHitLabel(par.getParameter<
InputTag>(
"DTRecSegmentLabel")),
73 theCSCRecHitLabel(par.getParameter<
InputTag>(
"CSCRecSegmentLabel")),
84 string refitDirectionName = par.
getParameter<
string>(
"RefitDirection");
90 <<
"Wrong refit direction chosen in TrackTransformer ParameterSet"
92 <<
"Possible choices are:"
94 <<
"RefitDirection = insideOut or RefitDirection = outsideIn";
114 if (par.
existsAs<
double>(
"RescaleErrorFactor")) {
174 const int theMuonHitsOption,
176 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
185 if ((*hit)->isValid()) {
187 allRecHitsTemp.push_back((**hit).cloneForFit(*tkbuilder->geometry()->idToDet( (**hit).geographicalId() ) ) );
188 else if ((*hit)->geographicalId().det() ==
DetId::Muon) {
189 if ((*hit)->geographicalId().subdetId() == 3 && !
theRPCInTheFit) {
196 vector<Trajectory> refitted =
refit(globalTrack,track,allRecHitsTemp,theMuonHitsOption, tTopo);
206 const int theMuonHitsOption,
215 vector<int> stationHits(4,0);
216 map<DetId, int> hitMap;
223 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
231 vector <Trajectory> outputTraj;
233 if ((theMuonHitsOption == 1) || (theMuonHitsOption == 3) || (theMuonHitsOption == 4) ) {
235 vector <Trajectory> globalTraj =
transform(globalTrack, track, allRecHits);
237 if (!globalTraj.size()) {
239 return vector<Trajectory>();
243 << globalTraj.front().lastMeasurement().updatedState().freeState()->parameters() << endl;
245 if (theMuonHitsOption == 1 )
246 outputTraj.push_back(globalTraj.front());
248 if (theMuonHitsOption == 3 ) {
252 outputTraj =
transform(globalTrack, track, selectedRecHits);
255 if (theMuonHitsOption == 4 ) {
265 DYTRecHits = dytRefit.
filter(globalTraj.front());
267 if ((DYTRecHits.size() > 1) && (DYTRecHits.front()->globalPosition().mag() > DYTRecHits.back()->globalPosition().mag()))
269 outputTraj =
transform(globalTrack, track, DYTRecHits);
272 }
else if (theMuonHitsOption == 2 ) {
274 outputTraj =
transform(globalTrack, track, fmsRecHits);
278 if (outputTraj.size()) {
279 LogTrace(
theCategory) <<
"Refitted pt: " << outputTraj.front().firstMeasurement().updatedState().globalParameters().momentum().perp() << endl;
283 return vector<Trajectory>();
294 map<DetId, int> &hitMap)
const {
298 float coneSize = 20.0;
301 for (ConstRecHitContainer::const_iterator imrh = all.begin(); imrh != all.end(); imrh++ ) {
303 if ( (*imrh != 0 ) && !(*imrh)->isValid() )
continue;
308 DetId id = (*imrh)->geographicalId();
318 if ((*imrh)->recHits().size()>1) {
319 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
320 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
321 if ((*imrh)->recHits().size()>1) {
322 std::vector <const TrackingRecHit*> hits1d = (*hit2d)->recHits();
323 for (std::vector <const TrackingRecHit*>::const_iterator hit1d = hits1d.begin(); hit1d!= hits1d.end(); hit1d++) {
324 DetId id1 = (*hit1d)->geographicalId();
330 double rhitDistance = fabs(ir->localPosition().x()-(**hit1d).localPosition().x());
331 if ( rhitDistance < coneSize ) layerHits++;
333 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits <<
" SL: " << lid.superLayer() << endl;
335 if (layerHits>detRecHits) detRecHits=layerHits;
347 double rhitDistance = fabs(ir->localPosition().x()-(**imrh).localPosition().x());
348 if ( rhitDistance < coneSize ) detRecHits++;
350 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
358 if ((*imrh)->recHits().size()>1) {
359 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
360 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
361 DetId id1 = (*hit2d)->geographicalId();
369 double rhitDistance = (ir->localPosition()-(**hit2d).localPosition()).
mag();
370 if ( rhitDistance < coneSize ) layerHits++;
372 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
374 if (layerHits>detRecHits) detRecHits=layerHits;
381 double rhitDistance = (ir->localPosition()-(**imrh).localPosition()).
mag();
382 if ( rhitDistance < coneSize ) detRecHits++;
384 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
393 map<DetId,int>::iterator imap=hitMap.find(chamberId);
394 if (imap!=hitMap.end()) {
395 if (detRecHits>imap->second) imap->second=detRecHits;
396 }
else hitMap[chamberId]=detRecHits;
400 for (map<DetId,int>::iterator imap=hitMap.begin(); imap!=hitMap.end(); imap++ )
401 LogTrace(
theCategory) <<
" Station " << imap->first.rawId() <<
": " << imap->second <<endl;
406 if ( (all.size() > 1) &&
407 ( all.front()->globalPosition().mag() >
408 all.back()->globalPosition().mag() ) ) {
422 LogTrace(
theCategory) <<
" GlobalMuonRefitter::getFirstHits\nall rechits length:" << all.size() << endl;
425 int station_to_keep = 999;
427 for (ConstRecHitContainer::const_iterator ihit = all.begin(); ihit != all.end(); ++ihit) {
431 DetId id = (*ihit)->geographicalId();
432 unsigned raw_id =
id.
rawId();
433 if (!(*ihit)->isValid()) station = -1;
436 switch (
id.subdetId()) {
444 if (use_it && station > 0 && station < station_to_keep) station_to_keep =
station;
445 stations.push_back(station);
447 LogTrace(
theCategory) <<
"rawId: " << raw_id <<
" station = " << station <<
" station_to_keep is now " << station_to_keep;
450 if (station_to_keep <= 0 || station_to_keep > 4 || stations.size() != all.size())
451 LogInfo(
theCategory) <<
"failed to getFirstHits (all muon hits are outliers/bad ?)! station_to_keep = "
452 << station_to_keep <<
" stations.size " << stations.size() <<
" all.size " << all.size();
454 for (
unsigned i = 0;
i < stations.size(); ++
i)
455 if (stations[
i] >= 0 && stations[
i] <= station_to_keep) first.push_back(all[
i]);
467 const map<DetId, int> &hitMap)
const {
470 const double globalChi2Cut = 200.0;
472 vector<TrajectoryMeasurement> muonMeasurements = traj.
measurements();
475 for (std::vector<TrajectoryMeasurement>::const_iterator im = muonMeasurements.begin(); im != muonMeasurements.end(); im++ ) {
477 if ( !(*im).recHit()->isValid() )
continue;
478 if ( (*im).recHit()->det()->geographicalId().det() !=
DetId::Muon ) {
480 muonRecHits.push_back((*im).recHit());
488 double chi2Cut = 0.0;
491 if ( (*immrh).isDT() ) {
498 else if ( (*immrh).isCSC() ) {
505 else if ( (*immrh).isRPC() ) {
513 double chi2ndf = (*im).estimate()/(*im).recHit()->dimension();
516 map<DetId,int>::const_iterator imap=hitMap.find(chamberId);
517 if ( imap!=hitMap.end() )
518 if (imap->second>threshold) keep =
false;
520 if ( (keep || (chi2ndf<chi2Cut)) && (chi2ndf<globalChi2Cut) ) {
521 muonRecHits.push_back((*im).recHit());
524 <<
"Skip hit: " <<
id.rawId() <<
" chi2="
525 << chi2ndf <<
" ( threshold: " << chi2Cut <<
") Det: "
526 << imap->second << endl;
531 reverse(muonRecHits.begin(),muonRecHits.end());
542 for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
543 if ( !(*ir)->isValid() ) {
551 <<
"r = " <<
sqrt(pos.
x() * pos.
x() + pos.
y() * pos.
y())
552 <<
" z = " << pos.
z()
553 <<
" dimension = " << (*ir)->dimension()
554 <<
" det = " << (*ir)->det()->geographicalId().det()
555 <<
" subdet = " << (*ir)->det()->subDetector()
556 <<
" raw id = " << (*ir)->det()->geographicalId().rawId();
568 if (!recHits.empty()){
569 ConstRecHitContainer::const_iterator frontHit = recHits.begin();
570 ConstRecHitContainer::const_iterator backHit = recHits.end() - 1;
571 while( !(*frontHit)->isValid() && frontHit != backHit) {frontHit++;}
572 while( !(*backHit)->isValid() && backHit != frontHit) {backHit--;}
574 double rFirst = (*frontHit)->globalPosition().mag();
575 double rLast = (*backHit) ->globalPosition().mag();
578 else if(rFirst > rLast)
return outsideIn;
598 LogTrace(
theCategory) <<
"GlobalMuonRefitter::transform: " << recHitsForReFit.size() <<
" hits:";
601 if(recHitsForReFit.size() < 2)
return vector<Trajectory>();
611 if(
theRefitDirection != recHitsOrder) reverse(recHitsForReFit.begin(),recHitsForReFit.end());
618 unsigned int innerId;
629 inner_is_first =
true;
636 inner_is_first =
false;
640 <<
" globalPosition is " << firstTSOS.globalPosition()
641 <<
" innerId is " << innerId;
643 if(!firstTSOS.isValid()){
645 return vector<Trajectory>();
669 PropagationDirection propDir_last = (lastTSOS .globalPosition().basicVector().dot(lastTSOS .globalMomentum().basicVector()) > 0) ?
alongMomentum : oppositeToMomentum;
670 LogTrace(
theCategory) <<
"propDir_first " << propDir_first <<
", propdir_last " << propDir_last
671 <<
" : they " << (propDir_first == propDir_last ?
"agree" :
"disagree");
674 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = recHitsForReFit.begin(); it != recHitsForReFit.end(); ++it) {
675 if ((*it)->globalPosition().y() > 0) ++y_count;
690 <<
"; based on geometrically-outermost TSOS, propDir is " << propDir <<
": "
691 << (propDir == propDir_ycount ?
"agrees" :
"disagrees")
692 <<
" with ycount determination";
694 if (propDir_first != propDir_last) {
696 propDir = propDir_ycount;
702 if(recHitsForReFit.front()->geographicalId() !=
DetId(innerId)){
705 <<
" to first rechit with surface pos " << recHitsForReFit.front()->det()->surface().toGlobal(
LocalPoint(0,0,0));
707 if(!firstTSOS.isValid()){
709 return vector<Trajectory>();
730 vector<Trajectory> trajectories =
theFitter->fit(seed,recHitsForReFit,firstTSOS);
732 if(trajectories.empty()){
734 return vector<Trajectory>();
748 ConstRecHitContainer::const_iterator it = hits.begin();
749 for (; it!=hits.end(); it++) {
751 DetId id = (*it)->geographicalId();
809 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.