73 theCosmicFlag(par.getParameter<bool>(
"PropDirForCosmics")),
74 theDTRecHitLabel(par.getParameter<
InputTag>(
"DTRecSegmentLabel")),
75 theCSCRecHitLabel(par.getParameter<
InputTag>(
"CSCRecSegmentLabel")),
86 string refitDirectionName = par.
getParameter<
string>(
"RefitDirection");
92 <<
"Wrong refit direction chosen in TrackTransformer ParameterSet"
94 <<
"Possible choices are:"
96 <<
"RefitDirection = insideOut or RefitDirection = outsideIn";
112 if (par.
existsAs<
double>(
"RescaleErrorFactor")) {
161 const int theMuonHitsOption,
163 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
170 if ((*hit)->isValid()) {
173 else if ((*hit)->geographicalId().det() ==
DetId::Muon) {
174 if ((*hit)->geographicalId().subdetId() == 3 && !
theRPCInTheFit) {
181 vector<Trajectory> refitted =
refit(globalTrack,track,allRecHitsTemp,theMuonHitsOption, tTopo);
191 const int theMuonHitsOption,
200 vector<int> stationHits(4,0);
201 map<DetId, int> hitMap;
208 LogTrace(
theCategory) <<
" *** GlobalMuonRefitter *** option " << theMuonHitsOption << endl;
216 vector <Trajectory> outputTraj;
218 if ((theMuonHitsOption == 1) || (theMuonHitsOption == 3) || (theMuonHitsOption == 4) ) {
220 vector <Trajectory> globalTraj =
transform(globalTrack, track, allRecHits);
222 if (!globalTraj.size()) {
224 return vector<Trajectory>();
228 << globalTraj.front().lastMeasurement().updatedState().freeState()->parameters() << endl;
230 if (theMuonHitsOption == 1 )
231 outputTraj.push_back(globalTraj.front());
233 if (theMuonHitsOption == 3 ) {
237 outputTraj =
transform(globalTrack, track, selectedRecHits);
240 if (theMuonHitsOption == 4 ) {
245 DYTRecHits = dytRefit.
filter(globalTraj.front());
247 if ((DYTRecHits.size() > 1) && (DYTRecHits.front()->globalPosition().mag() > DYTRecHits.back()->globalPosition().mag()))
249 outputTraj =
transform(globalTrack, track, DYTRecHits);
252 }
else if (theMuonHitsOption == 2 ) {
254 outputTraj =
transform(globalTrack, track, fmsRecHits);
258 if (outputTraj.size()) {
259 LogTrace(
theCategory) <<
"Refitted pt: " << outputTraj.front().firstMeasurement().updatedState().globalParameters().momentum().perp() << endl;
263 return vector<Trajectory>();
274 map<DetId, int> &hitMap)
const {
278 float coneSize = 20.0;
281 for (ConstRecHitContainer::const_iterator imrh = all.begin(); imrh != all.end(); imrh++ ) {
283 if ( (*imrh != 0 ) && !(*imrh)->isValid() )
continue;
288 DetId id = (*imrh)->geographicalId();
298 if ((*imrh)->recHits().size()>1) {
299 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
300 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
301 if ((*imrh)->recHits().size()>1) {
302 std::vector <const TrackingRecHit*> hits1d = (*hit2d)->recHits();
303 for (std::vector <const TrackingRecHit*>::const_iterator hit1d = hits1d.begin(); hit1d!= hits1d.end(); hit1d++) {
304 DetId id1 = (*hit1d)->geographicalId();
310 double rhitDistance = fabs(ir->localPosition().x()-(**hit1d).localPosition().x());
311 if ( rhitDistance < coneSize ) layerHits++;
313 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits <<
" SL: " << lid.superLayer() << endl;
315 if (layerHits>detRecHits) detRecHits=layerHits;
327 double rhitDistance = fabs(ir->localPosition().x()-(**imrh).localPosition().x());
328 if ( rhitDistance < coneSize ) detRecHits++;
330 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
338 if ((*imrh)->recHits().size()>1) {
339 std::vector <const TrackingRecHit*> hits2d = (*imrh)->recHits();
340 for (std::vector <const TrackingRecHit*>::const_iterator hit2d = hits2d.begin(); hit2d!= hits2d.end(); hit2d++) {
341 DetId id1 = (*hit2d)->geographicalId();
349 double rhitDistance = (ir->localPosition()-(**hit2d).localPosition()).
mag();
350 if ( rhitDistance < coneSize ) layerHits++;
352 <<
" Distance: " << rhitDistance <<
" recHits: " << layerHits << endl;
354 if (layerHits>detRecHits) detRecHits=layerHits;
361 double rhitDistance = (ir->localPosition()-(**imrh).localPosition()).
mag();
362 if ( rhitDistance < coneSize ) detRecHits++;
364 <<
" Distance: " << rhitDistance <<
" recHits: " << detRecHits << endl;
373 map<DetId,int>::iterator imap=hitMap.find(chamberId);
374 if (imap!=hitMap.end()) {
375 if (detRecHits>imap->second) imap->second=detRecHits;
376 }
else hitMap[chamberId]=detRecHits;
380 for (map<DetId,int>::iterator imap=hitMap.begin(); imap!=hitMap.end(); imap++ )
381 LogTrace(
theCategory) <<
" Station " << imap->first.rawId() <<
": " << imap->second <<endl;
386 if ( (all.size() > 1) &&
387 ( all.front()->globalPosition().mag() >
388 all.back()->globalPosition().mag() ) ) {
402 LogTrace(
theCategory) <<
" GlobalMuonRefitter::getFirstHits\nall rechits length:" << all.size() << endl;
405 int station_to_keep = 999;
407 for (ConstRecHitContainer::const_iterator ihit = all.begin(); ihit != all.end(); ++ihit) {
411 DetId id = (*ihit)->geographicalId();
412 unsigned raw_id =
id.
rawId();
413 if (!(*ihit)->isValid()) station = -1;
416 switch (
id.subdetId()) {
424 if (use_it && station > 0 && station < station_to_keep) station_to_keep =
station;
425 stations.push_back(station);
427 LogTrace(
theCategory) <<
"rawId: " << raw_id <<
" station = " << station <<
" station_to_keep is now " << station_to_keep;
430 if (station_to_keep <= 0 || station_to_keep > 4 || stations.size() != all.size())
431 LogInfo(
theCategory) <<
"failed to getFirstHits (all muon hits are outliers/bad ?)! station_to_keep = "
432 << station_to_keep <<
" stations.size " << stations.size() <<
" all.size " << all.size();
434 for (
unsigned i = 0;
i < stations.size(); ++
i)
435 if (stations[
i] >= 0 && stations[
i] <= station_to_keep) first.push_back(all[
i]);
447 const map<DetId, int> &hitMap)
const {
450 const double globalChi2Cut = 200.0;
452 vector<TrajectoryMeasurement> muonMeasurements = traj.
measurements();
455 for (std::vector<TrajectoryMeasurement>::const_iterator im = muonMeasurements.begin(); im != muonMeasurements.end(); im++ ) {
457 if ( !(*im).recHit()->isValid() )
continue;
458 if ( (*im).recHit()->det()->geographicalId().det() !=
DetId::Muon ) {
460 muonRecHits.push_back((*im).recHit());
465 DetId id = immrh->geographicalId();
468 double chi2Cut = 0.0;
471 if ( (*immrh).isDT() ) {
478 else if ( (*immrh).isCSC() ) {
485 else if ( (*immrh).isRPC() ) {
493 double chi2ndf = (*im).estimate()/(*im).recHit()->dimension();
496 map<DetId,int>::const_iterator imap=hitMap.find(chamberId);
497 if ( imap!=hitMap.end() )
498 if (imap->second>threshold) keep =
false;
500 if ( (keep || (chi2ndf<chi2Cut)) && (chi2ndf<globalChi2Cut) ) {
501 muonRecHits.push_back((*im).recHit());
504 <<
"Skip hit: " <<
id.rawId() <<
" chi2="
505 << chi2ndf <<
" ( threshold: " << chi2Cut <<
") Det: "
506 << imap->second << endl;
511 reverse(muonRecHits.begin(),muonRecHits.end());
522 for (ConstRecHitContainer::const_iterator ir = hits.begin(); ir != hits.end(); ir++ ) {
523 if ( !(*ir)->isValid() ) {
531 <<
"r = " <<
sqrt(pos.
x() * pos.
x() + pos.
y() * pos.
y())
532 <<
" z = " << pos.
z()
533 <<
" dimension = " << (*ir)->dimension()
534 <<
" det = " << (*ir)->det()->geographicalId().det()
535 <<
" subdet = " << (*ir)->det()->subDetector()
536 <<
" raw id = " << (*ir)->det()->geographicalId().rawId();
548 if (!recHits.empty()){
549 ConstRecHitContainer::const_iterator frontHit = recHits.begin();
550 ConstRecHitContainer::const_iterator backHit = recHits.end() - 1;
551 while( !(*frontHit)->isValid() && frontHit != backHit) {frontHit++;}
552 while( !(*backHit)->isValid() && backHit != frontHit) {backHit--;}
554 double rFirst = (*frontHit)->globalPosition().mag();
555 double rLast = (*backHit) ->globalPosition().mag();
558 else if(rFirst > rLast)
return outsideIn;
578 LogTrace(
theCategory) <<
"GlobalMuonRefitter::transform: " << recHitsForReFit.size() <<
" hits:";
581 if(recHitsForReFit.size() < 2)
return vector<Trajectory>();
591 if(
theRefitDirection != recHitsOrder) reverse(recHitsForReFit.begin(),recHitsForReFit.end());
598 unsigned int innerId;
609 inner_is_first =
true;
616 inner_is_first =
false;
620 <<
" globalPosition is " << firstTSOS.globalPosition()
621 <<
" innerId is " << innerId;
623 if(!firstTSOS.isValid()){
625 return vector<Trajectory>();
649 PropagationDirection propDir_last = (lastTSOS .globalPosition().basicVector().dot(lastTSOS .globalMomentum().basicVector()) > 0) ?
alongMomentum : oppositeToMomentum;
650 LogTrace(
theCategory) <<
"propDir_first " << propDir_first <<
", propdir_last " << propDir_last
651 <<
" : they " << (propDir_first == propDir_last ?
"agree" :
"disagree");
654 for (TransientTrackingRecHit::ConstRecHitContainer::const_iterator it = recHitsForReFit.begin(); it != recHitsForReFit.end(); ++it) {
655 if ((*it)->globalPosition().y() > 0) ++y_count;
670 <<
"; based on geometrically-outermost TSOS, propDir is " << propDir <<
": "
671 << (propDir == propDir_ycount ?
"agrees" :
"disagrees")
672 <<
" with ycount determination";
674 if (propDir_first != propDir_last) {
676 propDir = propDir_ycount;
682 if(recHitsForReFit.front()->geographicalId() !=
DetId(innerId)){
685 <<
" to first rechit with surface pos " << recHitsForReFit.front()->det()->surface().toGlobal(
LocalPoint(0,0,0));
687 if(!firstTSOS.isValid()){
689 return vector<Trajectory>();
710 vector<Trajectory> trajectories =
theFitter->fit(seed,recHitsForReFit,firstTSOS);
712 if(trajectories.empty()){
714 return vector<Trajectory>();
728 ConstRecHitContainer::const_iterator it = hits.begin();
729 for (; it!=hits.end(); it++) {
731 DetId id = (*it)->geographicalId();
789 results.push_back(*it);
std::string theMuonRecHitBuilderName
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
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
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
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
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
C::const_iterator const_iterator
constant access iterator type
DataContainer const & measurements() const
edm::ESHandle< TrajectoryFitter > theFitter
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
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
unsigned int pxbLayer(const DetId &id) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
virtual void setEvent(const edm::Event &)
pass the Event to the algo at each event
GlobalMuonRefitter(const edm::ParameterSet &, const MuonServiceProxy *)
constructor with Parameter Set and MuonServiceProxy
void setThr(int, int, int)
GlobalVector globalMomentum() const
virtual ~GlobalMuonRefitter()
destructor
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 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
unsigned int tobLayer(const DetId &id) const
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.