48 propagator = theService.propagator(
"SmartPropagatorAny");
49 propagatorPF = theService.propagator(
"SmartPropagatorAny");
50 propagatorCompatibleDet = theService.propagator(
"SmartPropagatorAny");
51 theG = theService.trackingGeometry();
61 if (useDBforThr) dytThresholds = thrManager->getInitialThresholds();
63 doUpdateOfKFStates =
true;
64 useParametrizedThr =
false;
75 if (temp.
isValid()) tsos = updatorHandle->
update(tsos, *rechit);
80 vector<const TrackingRecHit*> DTrh = bestDTSeg.
recHits();
81 for (vector<const TrackingRecHit*>::iterator it = DTrh.begin(); it != DTrh.end(); it++) {
82 tmprecHits.push_back(theMuonRecHitBuilder->build(*it));
85 for (ConstRecHitContainer::const_iterator it = tmprecHits.begin(); it != tmprecHits.end(); ++it) {
86 DTLayerId layid((*it)->det()->geographicalId());
90 if (tempTsos.
isValid() ) tsos = tempTsos;
98 for (vector<CSCRecHit2D>::iterator it = CSCrh.begin(); it != CSCrh.end(); ++it) {
99 tmprecHits.push_back(theMuonRecHitBuilder->build(&*it));
102 for (ConstRecHitContainer::const_iterator it = tmprecHits.begin(); it != tmprecHits.end(); ++it) {
103 const CSCLayer* cscLayer = cscGeom->layer((*it)->det()->geographicalId());
107 if (tempTsos.
isValid() ) tsos = tempTsos;
117 if (selector < 0 || selector > 2)
throw cms::Exception(
"NotAvailable") <<
"DYT selector: wrong option!" << endl;
130 doUpdateOfKFStates = upState;
134 if (thr.size() == 2) {
135 for (
unsigned int i = 0;
i < thr.size();
i++)
136 if (thr[
i] >= 0) Thrs.push_back(thr[
i]);
140 throw cms::Exception(
"NotAvailable") <<
"WARNING: wrong size for the threshold vector!\nExpected size: 2\n Found size: " << thr.size();
160 dtApeMap = thrManager->GetDTApeMap();
161 cscApeMap = thrManager->GetCSCApeMap();
164 vector<TrajectoryMeasurement> muonMeasurements = traj.
measurements();
166 for (vector<TrajectoryMeasurement>::const_iterator imT = muonMeasurements.begin(); imT != muonMeasurements.end(); imT++ ) {
167 if ( !(*imT).recHit()->isValid() )
continue;
170 result.push_back((*imT).recHit());
171 if (!(*imT).forwardPredictedState().isValid())
continue;
172 if ((*imT).forwardPredictedState().globalPosition().mag() >
192 map<int, vector<DetId> > compatibleIds;
193 map<int, vector<DTRecSegment4D> > dtSegMap;
194 map<int, vector<CSCSegment> > cscSegMap;
195 int incompConLay = 0;
199 compatibleDets(currentState, compatibleIds);
202 fillSegmentMaps(compatibleIds, dtSegMap, cscSegMap);
205 if (useDBforThr) preliminaryFit(compatibleIds, dtSegMap, cscSegMap);
208 for (
map<
int, vector<DetId> >::iterator it=compatibleIds.begin(); it!=compatibleIds.end(); ++it) {
209 int stLayer = stationfromDet(it->second.front());
212 double bestDTEstimator =
MAX_THR;
213 double bestCSCEstimator =
MAX_THR;
214 vector<DTRecSegment4D> dtSegs = dtSegMap[it->first];
215 vector<CSCSegment> cscSegs = cscSegMap[it->first];
219 testDTstation(currentState, dtSegs, bestDTEstimator, bestDTSeg, tsosDTlayer);
223 testCSCstation(currentState, cscSegs, bestCSCEstimator, bestCSCSeg, tsosCSClayer);
226 bool chosenLayer = chooseLayers(incompConLay, bestDTEstimator, bestDTSeg, tsosDTlayer, bestCSCEstimator, bestCSCSeg, tsosCSClayer);
227 fillDYTInfos(stLayer, chosenLayer, incompConLay, bestDTEstimator, bestCSCEstimator, bestDTSeg, bestCSCSeg);
249 double const &bestDTEstimator,
double const &bestCSCEstimator,
254 if (bestDTEstimator <= bestCSCEstimator) {
255 estimatorMap[st] = bestDTEstimator;
257 idChamberMap[st] =
id;
260 idChamberMap[st] =
id;
261 estimatorMap[st] = bestCSCEstimator;
263 usedStationMap[st] =
true;
266 estimatorMap[st] = -1;
267 usedStationMap[st] =
false;
276 vector<const DetLayer *> navLayers;
277 navLayers = navigation->compatibleLayers(*(currentState.freeState()),
alongMomentum);
278 unsigned int ilayerCorrected = 0;
279 for (
unsigned int ilayer=0; ilayer<navLayers.size(); ilayer++ ) {
284 vector<DetLayer::DetWithState> comps = navLayers[ilayer]->compatibleDets(currentState, *propagatorCompatibleDet, *theEstimator);
287 if (!comps.empty()) {
288 for (
unsigned int icomp=0; icomp<comps.size(); icomp++ ) {
290 detMap[ilayerCorrected].push_back(
id);
294 if (theEstimator)
delete theEstimator;
300 map<
int, vector<DTRecSegment4D> > &dtSegMap,
301 map<
int, vector<CSCSegment> > &cscSegMap) {
302 for (
map<
int, vector<DetId> >::iterator it=compatibleIds.begin(); it!=compatibleIds.end(); ++it) {
303 vector<DetId>
ids = compatibleIds[it->first];
304 for (
unsigned j = 0; j < ids.size(); j++) {
307 vector<CSCSegment>
tmp = getSegs->getCSCSegmentsInChamber(ch);
308 for (
unsigned int k = 0;
k < tmp.size();
k++) cscSegMap[it->first].push_back(tmp[
k]);
312 vector<DTRecSegment4D>
tmp = getSegs->getDTSegmentsInChamber(ch);
313 for (
unsigned int k = 0;
k < tmp.size();
k++) dtSegMap[it->first].push_back(tmp[
k]);
323 if (segments.empty())
return;
324 for (
unsigned int iSeg = 0; iSeg < segments.size(); iSeg++) {
326 if (!
propagator->propagate(startingState, theG->idToDet(chamber)->
surface()).isValid())
continue;
327 tsosdt =
propagator->propagate(startingState, theG->idToDet(chamber)->
surface());
334 if (estimator >= bestEstimator)
continue;
336 bestSeg = segments[iSeg];
344 if (segments.empty())
return;
345 for (
unsigned int iSeg = 0; iSeg < segments.size(); iSeg++) {
347 if (!
propagator->propagate(startingState, theG->idToDet(chamber)->
surface()).isValid())
continue;
348 tsoscsc =
propagator->propagate(startingState, theG->idToDet(chamber)->
surface());
355 if (estimator >= bestEstimator)
continue;
357 bestSeg = segments[iSeg];
364 result.push_back(theMuonRecHitBuilder->build(&bestDTSeg));
365 if (doUpdateOfKFStates) updateWithDThits(currentState, bestDTSeg);
366 else currentState = tsosDT;
372 result.push_back(theMuonRecHitBuilder->build(&bestCSCSeg));
373 if (doUpdateOfKFStates) updateWithCSChits(currentState, bestCSCSeg);
374 else currentState = tsosCSC;
380 map<
int, vector<CSCSegment> > cscSegMap) {
381 for (
map<
int, vector<DetId> >::iterator it=compatibleIds.begin(); it!=compatibleIds.end(); ++it) {
384 double bestDTEstimator =
MAX_THR;
385 double bestCSCEstimator =
MAX_THR;
387 vector<DTRecSegment4D> dtSegs = dtSegMap[it->first];
388 vector<CSCSegment> cscSegs = cscSegMap[it->first];
392 testDTstation(prelFitState, dtSegs, bestDTEstimator, bestDTSeg, tsosDTlayer);
396 testCSCstation(prelFitState, cscSegs, bestCSCEstimator, bestCSCSeg, tsosCSClayer);
399 if (bestDTEstimator ==
MAX_THR && bestCSCEstimator ==
MAX_THR)
continue;
400 if (bestDTEstimator <= bestCSCEstimator) {
402 if (bestDTEstimator >= initThr)
continue;
403 prelFitMeas.push_back(theMuonRecHitBuilder->build(&bestDTSeg));
404 auto aSegRH = prelFitMeas.back();
405 auto uRes = updatorHandle->update(tsosDTlayer, *aSegRH);
409 prelFitMeas.pop_back();
413 if (bestCSCEstimator >= initThr)
continue;
414 prelFitMeas.push_back(theMuonRecHitBuilder->build(&bestCSCSeg));
415 auto aSegRH = prelFitMeas.back();
416 auto uRes = updatorHandle->update(tsosCSClayer, *aSegRH);
420 prelFitMeas.pop_back();
424 if (!prelFitMeas.empty()) prelFitMeas.pop_back();
425 for (
auto imrh = prelFitMeas.rbegin(); imrh != prelFitMeas.rend(); ++imrh) {
426 DetId id = (*imrh)->geographicalId();
428 if (tmp.
isValid()) prelFitState = tmp;
431 muonETAest = prelFitState.globalMomentum().eta();
439 if (bestDTEstimator ==
MAX_THR && bestCSCEstimator ==
MAX_THR)
return false;
440 if (bestDTEstimator <= bestCSCEstimator) {
442 if (useDBforThr) getThresholdFromDB(initThr,
DetId(bestDTSeg.
chamberId()));
445 (
DYTselector == 2 && incompLayers < 2 && bestDTEstimator < initThr)) {
446 useSegment(bestDTSeg, tsosDT);
451 if (useDBforThr) getThresholdFromDB(initThr,
DetId(bestCSCSeg.
cscDetId()));
452 else getThresholdFromCFG(initThr,
DetId(bestCSCSeg.
cscDetId()));
454 (
DYTselector == 2 && incompLayers < 2 && bestCSCEstimator < initThr)) {
455 useSegment(bestCSCSeg, tsosCSC);
465 vector<DYTThrObject::DytThrStruct> thrvector = dytThresholds->thrsVec;
466 for (vector<DYTThrObject::DytThrStruct>::const_iterator it = thrvector.begin(); it != thrvector.end(); it++) {
473 if (useParametrizedThr) correctThrByPAndEta(thr);
480 auto parametricThreshold = [
this]{
481 double thr50 = this->
parameters[this->region].at(0);
482 double p0 = this->
parameters[this->region].at(1);
484 return thr50 * ( 1 + p0*p_reco +
std::pow( this->p_reco, p1));
489 if ( ! regionsToExclude.count(this->region) ) thr = parametricThreshold();
516 if (useParametrizedThr) correctThrByPAndEta(thr);
527 for(j=n-1; j>=
i; --j)
528 if(recHits[j-1]->globalPosition().
mag() > recHits[j]->globalPosition().
mag())
swap (recHits[j-1],recHits[j]);
T getParameter(std::string const &) const
void compatibleDets(TrajectoryStateOnSurface &, std::map< int, std::vector< DetId > > &)
CSCDetId cscDetId() const
ConstRecHitPointer const & recHit() const
void sort(ConstRecHitContainer &)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
void fillSegmentMaps(std::map< int, std::vector< DetId > > &, std::map< int, std::vector< DTRecSegment4D > > &, std::map< int, std::vector< CSCSegment > > &)
void useSegment(DTRecSegment4D const &, TrajectoryStateOnSurface const &)
GlobalPoint globalPosition() const
void getThresholdFromDB(double &, DetId const &)
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
void updateWithCSChits(TrajectoryStateOnSurface &, CSCSegment const &)
void testDTstation(TrajectoryStateOnSurface &, std::vector< DTRecSegment4D > const &, double &, DTRecSegment4D &, TrajectoryStateOnSurface &)
const Plane & surface() const
The nominal surface of the GeomDet.
void swap(Association< C > &lhs, Association< C > &rhs)
DataContainer const & measurements() const
const SurfaceType & surface() const
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
Abs< T >::type abs(const T &t)
void correctThrByPAndEta(double &)
void testCSCstation(TrajectoryStateOnSurface &, std::vector< CSCSegment > const &, double &, CSCSegment &, TrajectoryStateOnSurface &)
const bool isValidThdDB()
TransientTrackingRecHit::ConstRecHitContainer filter(const Trajectory &)
const std::vector< CSCRecHit2D > & specificRecHits() const
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
std::vector< ConstRecHitPointer > ConstRecHitContainer
void preliminaryFit(std::map< int, std::vector< DetId > >, std::map< int, std::vector< DTRecSegment4D > >, std::map< int, std::vector< CSCSegment > >)
void setThrsMap(const edm::ParameterSet &)
DynamicTruncation(const edm::Event &, const MuonServiceProxy &)
void update(TrajectoryStateOnSurface &, ConstRecHitPointer)
void fillDYTInfos(int const &, bool const &, int &, double const &, double const &, DTRecSegment4D const &, CSCSegment const &)
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
std::vector< std::vector< double > > tmp
GlobalVector globalMomentum() const
bool chooseLayers(int &, double const &, DTRecSegment4D const &, TrajectoryStateOnSurface const &, double const &, CSCSegment const &, TrajectoryStateOnSurface const &)
int stationfromDet(DetId const &)
DetId geographicalId() const
static const std::map< etaRegion, std::string > etaRegionStr
int station() const
Return the station number.
T first(std::pair< T, U > const &p)
void updateWithDThits(TrajectoryStateOnSurface &, DTRecSegment4D const &)
void setThr(const std::vector< int > &)
Power< A, B >::type pow(const A &a, const B &b)
void setUpdateState(bool)
void getThresholdFromCFG(double &, DetId const &)
constexpr Detector det() const
get the detector field from this detid