Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-12 07:47:32

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTTSPhi.cpp
0004 //
0005 //   Description: Implementation of TS Phi trigger algorithm
0006 //
0007 //
0008 //   Author List:
0009 //   C. Grandi
0010 //   Modifications:
0011 //   jan02 - D.Bonacorsi/S.Marcellini
0012 //           improved algorithm for 2nd track handling in case of pile-up in TSM
0013 //           param: tsmgetcarryflag - value: 1 (default)
0014 //   feb04 - Implementation of sector collector related stuff(S. Marcellini)
0015 //   jan07 - C. Battilana local conf update
0016 //   mar07 - S. Vanini : parameters from DTConfigManager
0017 //
0018 //--------------------------------------------------
0019 
0020 #include "L1TriggerConfig/DTTPGConfig/interface/BitArray.h"
0021 
0022 //-----------------------
0023 // This Class's Header --
0024 //-----------------------
0025 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSPhi.h"
0026 
0027 //-------------------------------
0028 // Collaborating Class Headers --
0029 //-------------------------------
0030 #include "L1Trigger/DTTraco/interface/DTTracoCard.h"
0031 #include "L1Trigger/DTTraco/interface/DTTracoTrigData.h"
0032 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSCand.h"
0033 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSM.h"
0034 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSS.h"
0035 
0036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0037 
0038 //---------------
0039 // C++ Headers --
0040 //---------------
0041 #include <iostream>
0042 
0043 //----------------
0044 // Constructors --
0045 //----------------
0046 DTTSPhi::DTTSPhi(DTTrigGeom *geom, DTTracoCard *tracocard) : DTGeomSupplier(geom), _tracocard(tracocard) {
0047   // reserve the appropriate amount of space for vectors
0048   int i = 0;
0049   for (i = 0; i < DTConfigTSPhi::NSTEPL - DTConfigTSPhi::NSTEPF + 1; i++) {  // SM add + 1
0050     _tss[i].reserve(DTConfigTSPhi::NTSSTSM);
0051     // DBSM-doubleTSM
0052     _tsm[i].reserve(DTConfigTSPhi::NTSMD);
0053   }
0054 
0055   for (int is = 0; is < DTConfigTSPhi::NSTEPL - DTConfigTSPhi::NSTEPF + 1; is++) {
0056     // create DTTSSs
0057     for (int itss = 1; itss <= DTConfigTSPhi::NTSSTSM; itss++) {
0058       DTTSS *tss = new DTTSS(itss);
0059       _tss[is].push_back(tss);
0060     }
0061 
0062     // create DTTSMs     SM double TSM
0063     for (int itsmd = 1; itsmd <= DTConfigTSPhi::NTSMD; itsmd++) {
0064       DTTSM *tsm = new DTTSM(itsmd);
0065       _tsm[is].push_back(tsm);
0066     }
0067   }
0068 }
0069 
0070 //--------------
0071 // Destructor --
0072 //--------------
0073 DTTSPhi::~DTTSPhi() {
0074   std::vector<DTTSS *>::iterator ptss;
0075   std::vector<DTTSM *>::iterator ptsm;
0076   for (int is = 0; is < DTConfigTSPhi::NSTEPL - DTConfigTSPhi::NSTEPF + 1; is++) {
0077     // clear TSSs
0078     for (ptss = _tss[is].begin(); ptss != _tss[is].end(); ptss++) {
0079       delete (*ptss);
0080     }
0081     _tss[is].clear();
0082     // clear TSMs
0083     for (ptsm = _tsm[is].begin(); ptsm != _tsm[is].end(); ptsm++) {
0084       delete (*ptsm);
0085     }
0086     _tsm[is].clear();
0087   }
0088 
0089   localClear();
0090 
0091   // delete _config;
0092 }
0093 
0094 //--------------
0095 // Operations --
0096 //--------------
0097 
0098 void DTTSPhi::localClear() {
0099   for (int is = 0; is < DTConfigTSPhi::NSTEPL - DTConfigTSPhi::NSTEPF + 1; is++) {
0100     // clear buffer
0101     std::vector<DTTSCand *>::iterator p1;
0102     for (p1 = _tctrig[is].begin(); p1 != _tctrig[is].end(); p1++) {
0103       delete (*p1);
0104     }
0105     _tctrig[is].clear();
0106 
0107     std::vector<DTTSS *>::iterator ptss;
0108     for (ptss = _tss[is].begin(); ptss != _tss[is].end(); ptss++) {
0109       (*ptss)->clear();
0110     }
0111     // clear all DTTSM
0112     std::vector<DTTSM *>::iterator ptsm;
0113     for (ptsm = _tsm[is].begin(); ptsm != _tsm[is].end(); ptsm++) {
0114       (*ptsm)->clear();
0115     }
0116   }
0117 }
0118 
0119 void DTTSPhi::setConfig(const DTConfigManager *conf) {
0120   DTChamberId sid = ChamberId();
0121   _config = conf->getDTConfigTSPhi(sid);
0122 
0123   for (int is = 0; is < DTConfigTSPhi::NSTEPL - DTConfigTSPhi::NSTEPF + 1; is++) {
0124     // set TSS config
0125     std::vector<DTTSS *>::iterator ptss;
0126     for (ptss = _tss[is].begin(); ptss != _tss[is].end(); ptss++) {
0127       (*ptss)->setConfig(config());
0128     }
0129     // set TSM config
0130     std::vector<DTTSM *>::iterator ptsm;
0131     for (ptsm = _tsm[is].begin(); ptsm != _tsm[is].end(); ptsm++) {
0132       (*ptsm)->setConfig(config());
0133     }
0134   }
0135 }
0136 
0137 void DTTSPhi::loadTSPhi() {
0138   // clear DTTSSs and DTTSM
0139   localClear();
0140 
0141   if (config()->debug()) {
0142     edm::LogInfo("DTTSPhi") << "loadDTTSPhi called for wheel=" << wheel() << ", station=" << station()
0143                             << ", sector=" << sector();
0144   }
0145 
0146   // loop on all TRACO triggers
0147   std::vector<DTTracoTrigData>::const_iterator p;
0148   std::vector<DTTracoTrigData>::const_iterator pend = _tracocard->end();
0149   for (p = _tracocard->begin(); p != pend; p++) {
0150     if (config()->usedTraco(p->tracoNumber()) /*|| config()->usedTraco(p->tracoNumber())==1*/) {
0151       int step = p->step();
0152       int fs = (p->isFirst()) ? 1 : 2;
0153 
0154       // if first track is found inhibit second track processing in previous BX
0155       if (fs == 1 && step > DTConfigTSPhi::NSTEPF)
0156         ignoreSecondTrack(step - 1, p->tracoNumber());
0157 
0158       // load trigger
0159       addTracoT(step, &(*p), fs);
0160     }
0161   }
0162 }
0163 
0164 void DTTSPhi::addTracoT(int step, const DTTracoTrigData *tracotrig, int ifs) {
0165   if (step < DTConfigTSPhi::NSTEPF || step > DTConfigTSPhi::NSTEPL) {
0166     edm::LogWarning("DTTSPhi") << "addTracoT: step out of range: " << step << " trigger not added!";
0167     return;
0168   }
0169   // Check that a preview is present and code is not zero
0170   if (!tracotrig->pvCode() || !tracotrig->code()) {
0171     edm::LogWarning("DTTSPhi") << "addTracoT: preview not present in TRACO trigger or its code=0 "
0172                                << " trigger not added!";
0173     return;
0174   }
0175 
0176   // Get the appropriate TSS
0177   int itss = (tracotrig->tracoNumber() - 1) / DTConfigTSPhi::NTCTSS + 1;
0178   if (itss < 1 || itss > DTConfigTSPhi::NTSSTSM) {
0179     edm::LogWarning("DTTSPhi") << "addTracoT: wrong TRACO number: " << tracotrig->tracoNumber()
0180                                << " trigger not added!";
0181     return;
0182   }
0183 
0184   // TSM status check (if it is the case, reject TRACO triggers related to
0185   // broken TSMData)
0186   if (config()->TsmStatus().element(itss) == 0) {  // TSMD broken
0187     return;
0188   }
0189 
0190   int pos = tracotrig->tracoNumber() - (itss - 1) * DTConfigTSPhi::NTCTSS;
0191   DTTSS *tss = getDTTSS(step, itss);
0192 
0193   // Create a new Trigger Server candidate
0194   DTTSCand *cand = new DTTSCand(tss, tracotrig, ifs, pos);
0195 
0196   // Add it to the buffer and to the TSS
0197   _tctrig[step - DTConfigTSPhi::NSTEPF].push_back(cand);
0198   tss->addDTTSCand(cand);
0199 
0200   // Debugging...
0201   if (config()->debug()) {
0202     edm::LogInfo("DTTSPhi") << "addTracoT at step " << step;
0203     if (ifs == 1) {
0204       edm::LogWarning("DTTSPhi") << " (first track)";
0205     } else {
0206       edm::LogWarning("DTTSPhi") << " (second track)";
0207     }
0208     edm::LogWarning("DTTSPhi") << " from TRACO " << tracotrig->tracoNumber() << " to TSS " << tss->number()
0209                                << ", position=" << pos;
0210     tracotrig->print();
0211   }
0212   // end debugging
0213 }
0214 
0215 void DTTSPhi::runTSPhi() {
0216   DTTSCand *secondPrevBx = nullptr;  // new DTTSCand;
0217 
0218   bool existSecondPrevBx = false;
0219   int itsmd = 1;  // initialize it to 1, default value if not in back up mode
0220   int ntsm[DTConfigTSPhi::NSTEPL + 1 - DTConfigTSPhi::NSTEPF][DTConfigTSPhi::NTSMD];
0221   int i_tsmd;
0222 
0223   for (int is = DTConfigTSPhi::NSTEPF; is < DTConfigTSPhi::NSTEPL + 1; is++) {
0224     // loop on DTTSSs
0225     int ntss = 0;
0226     i_tsmd = 0;
0227     ntsm[is - DTConfigTSPhi::NSTEPF][0] = 0;  // counter to make sector collector run if at least a tsm
0228     ntsm[is - DTConfigTSPhi::NSTEPF][1] = 0;
0229     std::vector<DTTSS *>::iterator p;
0230     for (p = _tss[is - DTConfigTSPhi::NSTEPF].begin(); p < _tss[is - DTConfigTSPhi::NSTEPF].end(); p++) {
0231       if ((*p)->nTracoT(1) > 0) {
0232         // run DTTSS algorithm on non-empty DTTSSs
0233         (*p)->run();
0234         // load DTTSM with output DTTSS tracks
0235         if ((*p)->nTracks() > 0) {
0236           for (int it = 1; it <= (*p)->nTracks(); it++) {
0237             //--- SM double TSM    get the corresponding tsm data
0238             int bkmod = config()->TsmStatus().element(0);
0239             if (bkmod == 0) {                // we are in back-up mode
0240               int my_itss = (*p)->number();  // metodo di DTTSS che ritorna itss
0241               int ntsstsmd = config()->TSSinTSMD(station(), sector());
0242               if (ntsstsmd < 2 || ntsstsmd > DTConfigTSPhi::NTSSTSMD) {
0243                 edm::LogWarning("DTTSPhi") << " addTracoT - wrong TSMD: " << ntsstsmd;
0244               }
0245 
0246               // Get the appropriate TSMD
0247               itsmd = (my_itss - 1) / ntsstsmd + 1;
0248               if (config()->debug()) {
0249                 edm::LogInfo("DTTSPhi") << " addTracoT: itsmd = (my_itss -1 ) / ntsstsmd + 1  ---> my_itss = "
0250                                         << my_itss << "  ntsstsmd = " << ntsstsmd << "  itsmd = " << itsmd;
0251               }
0252             } else if (bkmod == 1) {
0253               itsmd = 1;  // initialize it to 1, default value if not in back up mode
0254             }
0255             if (itsmd > 2)
0256               edm::LogWarning("DTTSPhi") << "****** RunTSPhi wrong  itsmd = " << itsmd;
0257             DTTSM *tsm = getDTTSM(is, itsmd);
0258             tsm->addCand((*p)->getTrack(it));
0259           }
0260           ntss++;
0261         }  // end loop on output DTTSS tracks
0262       }
0263     }  // end loop on DTTSSs
0264 
0265     // at least a DTTSS with signal. Run DTTSM
0266 
0267     std::vector<DTTSM *>::iterator p_tsm;
0268 
0269     for (p_tsm = _tsm[is - DTConfigTSPhi::NSTEPF].begin(); p_tsm < _tsm[is - DTConfigTSPhi::NSTEPF].end(); p_tsm++) {
0270       // Run TSM sorting if at least a first track
0271 
0272       i_tsmd = (*p_tsm)->number() - 1;  // returns itsmd (0 in default, 0 or 1 when bkmode )
0273 
0274       if ((*p_tsm)->nCand(1) > 0) {
0275         int bkmod = config()->TsmStatus().element(0);
0276 
0277         (*p_tsm)->run(bkmod);  // bkmod 1 normal, 0 backup
0278         // Run TSM for current BX in case of 1st Tracks
0279         // Run TSM for previous BX for second tracks, to check whether there is
0280         // a pile up Tells whether a second track at previous BX exists
0281 
0282         if ((*p_tsm)->nTracks() > 0) {
0283           // We have a first track. Store it if code is > 0
0284 
0285           if ((*p_tsm)->getTrack(1)->tracoTr()->code() > 0) {
0286             DTTSCand *first = (*p_tsm)->getTrack(1);
0287             if (config()->TsmGetCarryFlag() == 0) {  //  get 1st tk at current BX and ignore any 2nd tk at
0288                                                      //  previous BX
0289 
0290               _cache.push_back(DTChambPhSegm(ChamberId(), is, (*p_tsm)->getTrack(1)->tracoTr(), 1));
0291               ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;  // SM increment ntsm at current BX
0292               if (config()->debug())
0293                 edm::LogInfo("DTTSPhi") << "ntsm = " << ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd] << " is = " << is
0294                                         << " i_tsmd = " << i_tsmd;
0295               if ((*p_tsm)->nTracks() > 1) {                         // there is a 2nd tk
0296                 if ((*p_tsm)->getTrack(2)->tracoTr()->code() > 0) {  // check if its code > 0
0297                   ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0298                   if (config()->debug())
0299                     edm::LogInfo("DTTSPhi") << "ntsm = " << ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd] << " is = " << is
0300                                             << " i_tsmd = " << i_tsmd;
0301 
0302                   secondPrevBx = (*p_tsm)->getTrack(2);  // assign second tk of previous BX
0303                 }
0304               }
0305             } else if (config()->TsmGetCarryFlag() == 1) {  // compare with 2nd tk in previous BX and get the tk
0306                                                             // with better quality
0307               existSecondPrevBx =
0308                   ((is - 1 - DTConfigTSPhi::NSTEPF >= 0) && (ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd] > 1) &&
0309                    (secondPrevBx->tracoTr()->code() > 0));
0310               if ((!existSecondPrevBx) ||
0311                   !((secondPrevBx->isCorr() && secondPrevBx->isHtrig() && secondPrevBx->isInner()) ||
0312                     (secondPrevBx->isCorr() && secondPrevBx->isHtrig() && !secondPrevBx->isInner()) ||
0313                     (!secondPrevBx->isCorr() && secondPrevBx->isHtrig() && secondPrevBx->isInner())) ||
0314 
0315                   ((secondPrevBx->isCorr() && secondPrevBx->isHtrig() && secondPrevBx->isInner()) &&
0316                    (first->isCorr() && first->isHtrig() && first->isInner())) ||
0317 
0318                   ((secondPrevBx->isCorr() && secondPrevBx->isHtrig() && !secondPrevBx->isInner()) &&
0319                    ((first->isCorr() && first->isHtrig() && first->isInner()) ||
0320                     (first->isCorr() && first->isHtrig() && !first->isInner()))) ||
0321 
0322                   ((!secondPrevBx->isCorr() && secondPrevBx->isHtrig() && secondPrevBx->isInner()) &&
0323                    !((!first->isCorr() && first->isHtrig() && !first->isInner()) ||
0324                      (!first->isCorr() && !first->isHtrig() && first->isInner()) ||
0325                      (!first->isCorr() && !first->isHtrig() && !first->isInner()) ||
0326                      (first->isCorr() && !first->isHtrig() && !first->isInner()) ||
0327                      (first->isCorr() && !first->isHtrig() && first->isInner())))) {
0328                 // SM sector collector
0329                 ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;  // SM increment ntsm at current BX. I need to
0330                                                              // know if there is at least a first track from
0331                                                              // TSM to run Sect Coll
0332 
0333                 _cache.push_back(DTChambPhSegm(ChamberId(), is, (*p_tsm)->getTrack(1)->tracoTr(), 1));
0334                 //      (*p_tsm)->getTrack(1)->print();
0335 
0336                 if ((*p_tsm)->nTracks() > 1) {  // there is a 2nd tk
0337                   ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0338                   if ((*p_tsm)->getTrack(2)->tracoTr()->code() > 0) {  // check if its code > 0
0339                     secondPrevBx = (*p_tsm)->getTrack(2);              // assign second previous BX
0340                   }
0341                 }
0342               } else {  // if 2nd tk prev BX is better than first present BX skip
0343                         // the event and get 2nd prev BX
0344                 ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd]++;  // SM increment ntsm at previous BX.
0345                 _cache.push_back(DTChambPhSegm(ChamberId(), is - 1, secondPrevBx->tracoTr(), 2));
0346                 // secondPrevBx->print();
0347               }
0348             }
0349 
0350             else if (config()->TsmGetCarryFlag() == 2) {  // neglect first tk if it is a low uncorrelated
0351                                                           // trigger
0352               existSecondPrevBx =
0353                   ((is - 1 - DTConfigTSPhi::NSTEPF >= 0) && (ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd] > 1) &&
0354                    (secondPrevBx->tracoTr()->code() > 0));
0355               if ((!existSecondPrevBx) || first->isHtrig() || first->isCorr()) {
0356                 ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;  // SM increment ntsm at current BX.
0357                 // SM sector collector: Load DTSectColl with output of DTTSM
0358                 _cache.push_back(DTChambPhSegm(ChamberId(), is, (*p_tsm)->getTrack(1)->tracoTr(), 1));
0359                 //      (*p_tsm)->getTrack(1)->print();
0360 
0361                 if ((*p_tsm)->nTracks() > 1) {  // there is a 2nd tk
0362                   ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0363                   if ((*p_tsm)->getTrack(2)->tracoTr()->code() > 0) {  // check if its code > 0
0364                     secondPrevBx = (*p_tsm)->getTrack(2);              // assign second tk of previous BX
0365                   }
0366                 }
0367               } else {
0368                 ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd]++;  // SM increment ntsm at previous BX.
0369                 _cache.push_back(DTChambPhSegm(ChamberId(), is - 1, secondPrevBx->tracoTr(), 2));
0370                 //      secondPrevBx->print();
0371               }
0372             }
0373           }
0374         }
0375 
0376       } else if (((*p_tsm)->nCand(1) == 0) && (is - 1 - DTConfigTSPhi::NSTEPF >= 0) &&
0377                  ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd] >
0378                      0) {  // it means that the last BX with sort 2 was not the
0379                            // previous one
0380         existSecondPrevBx =
0381             ((is - 1 - DTConfigTSPhi::NSTEPF >= 0) && (ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd] > 1) &&
0382              (secondPrevBx->tracoTr()->code() > 0));
0383         if (existSecondPrevBx) {
0384           _cache.push_back(DTChambPhSegm(ChamberId(), is - 1, secondPrevBx->tracoTr(), 2));
0385 
0386           //      secondPrevBx->print();
0387         }
0388       }
0389     }
0390     //---
0391 
0392   }  // end loop on step
0393   // debugging...
0394   if (config()->debug()) {
0395     if (!_cache.empty()) {
0396       edm::LogInfo("DTTSPhi") << " Phi segments ";
0397       std::vector<DTChambPhSegm>::const_iterator p;
0398       for (p = _cache.begin(); p < _cache.end(); p++) {
0399         p->print();
0400       }
0401     }
0402   }
0403   //  end debugging
0404 }
0405 
0406 void DTTSPhi::ignoreSecondTrack(int step, int tracon) {
0407   int itsmd = 1;  // initialize it to default
0408 
0409   if (step < DTConfigTSPhi::NSTEPF || step > DTConfigTSPhi::NSTEPL) {
0410     edm::LogWarning("DTTSPhi") << "ignoreSecondTrack: step out of range: " << step << " no flag set!";
0411     return;
0412   }
0413   int itss = (tracon - 1) / DTConfigTSPhi::NTCTSS + 1;
0414   if (itss < 1 || itss > DTConfigTSPhi::NTSSTSM) {
0415     edm::LogWarning("DTTSPhi") << "ignoreSecondTrack: wrong TRACO number: " << tracon << " no flag set!";
0416     return;
0417   }
0418   DTTSS *tss = getDTTSS(step, itss);
0419   tss->ignoreSecondTrack();
0420 
0421   int bkmod = config()->TsmStatus().element(0);
0422   if (bkmod == 0) {  // we are in back-up mode
0423 
0424     int ntsstsmd = config()->TSSinTSMD(station(), sector());
0425     // Get the appropriate TSMD
0426     itsmd = (itss - 1) / ntsstsmd + 1;
0427   }
0428 
0429   DTTSM *tsm = getDTTSM(step, itsmd);
0430   tsm->ignoreSecondTrack();
0431 }
0432 
0433 DTTSS *DTTSPhi::getDTTSS(int step, unsigned n) const {
0434   if (step < DTConfigTSPhi::NSTEPF || step > DTConfigTSPhi::NSTEPL) {
0435     edm::LogWarning("DTTSPhi") << "getDTTSS: step out of range: " << step << " empty pointer returned!";
0436     return nullptr;
0437   }
0438   if (n < 1 || n > _tss[step - DTConfigTSPhi::NSTEPF].size()) {
0439     edm::LogWarning("DTTSPhi") << "getDTTSS: requested DTTSS not present: " << n << " (at step " << step << ")"
0440                                << " empty pointer returned!";
0441     return nullptr;
0442   }
0443 
0444   std::vector<DTTSS *>::const_iterator p = _tss[step - DTConfigTSPhi::NSTEPF].begin() + n - 1;
0445   return *p;
0446 }
0447 
0448 DTTSM *DTTSPhi::getDTTSM(int step, unsigned n) const {
0449   if (step < DTConfigTSPhi::NSTEPF || step > DTConfigTSPhi::NSTEPL) {
0450     edm::LogWarning("DTTSPhi") << "getDTTSM: step out of range: " << step << " empty pointer returned!";
0451     return nullptr;
0452   }
0453   if (n < 1 || n > _tsm[step - DTConfigTSPhi::NSTEPF].size()) {
0454     edm::LogWarning("DTTSPhi") << "getDTTSM: requested DTTSM not present: " << n << " (at step " << step << ")"
0455                                << " empty pointer returned!";
0456     return nullptr;
0457   }
0458   std::vector<DTTSM *>::const_iterator p_tsm = _tsm[step - DTConfigTSPhi::NSTEPF].begin() + n - 1;
0459   return *p_tsm;
0460 }
0461 
0462 int DTTSPhi::nSegm(int step) {
0463   int n = 0;
0464   std::vector<DTChambPhSegm>::const_iterator p;  // p=0;
0465   for (p = begin(); p < end(); p++) {
0466     if (p->step() == step)
0467       n++;
0468   }
0469   return n;
0470 }
0471 
0472 const DTChambPhSegm *DTTSPhi::segment(int step, unsigned n) {
0473   std::vector<DTChambPhSegm>::const_iterator p;  // p=0;
0474   for (p = begin(); p < end(); p++) {
0475     if (p->step() == step && ((n == 1 && p->isFirst()) || (n == 2 && !p->isFirst())))
0476       return &(*p);  // p;
0477   }
0478   return nullptr;
0479 }
0480 
0481 LocalPoint DTTSPhi::localPosition(const DTTrigData *tr) const {
0482   //@@ patch for Sun 4.2 compiler
0483   // sm DTChambPhSegm* trig =
0484   // dynamic_cast<DTChambPhSegm*>(const_cast<DTTrigData*>(tr));
0485   const DTChambPhSegm *trig = dynamic_cast<const DTChambPhSegm *>(tr);
0486   if (!trig) {
0487     edm::LogWarning("DTTSPhi") << "LocalPosition called with wrong argument!";
0488     return LocalPoint(0, 0, 0);
0489   }
0490   return _tracocard->localPosition(trig->tracoTrig());
0491 }
0492 
0493 LocalVector DTTSPhi::localDirection(const DTTrigData *tr) const {
0494   DTChambPhSegm *trig = dynamic_cast<DTChambPhSegm *>(const_cast<DTTrigData *>(tr));
0495   //  const DTChambPhSegm* trig = dynamic_cast<const DTChambPhSegm*>(tr);
0496   if (!trig) {
0497     edm::LogWarning("DTTSPhi") << "LocalDirection called with wrong argument!";
0498     return LocalVector(0, 0, 0);
0499   }
0500   return _tracocard->localDirection(trig->tracoTrig());
0501 }