Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-04 04:34:44

0001 /*! \class   TTTrack
0002  *  \brief   Class to store the L1 Track Trigger tracks
0003  *  \details After moving from SimDataFormats to DataFormats,
0004  *           the template structure of the class was maintained
0005  *           in order to accomodate any types other than PixelDigis
0006  *           in case there is such a need in the future.
0007  *
0008  *  \author Nicola Pozzobon
0009  *  \date   2013, Jul 12
0010  *
0011  */
0012 
0013 #ifndef L1_TRACK_TRIGGER_TRACK_FORMAT_H
0014 #define L1_TRACK_TRIGGER_TRACK_FORMAT_H
0015 
0016 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0017 #include "DataFormats/L1TrackTrigger/interface/TTStub.h"
0018 #include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h"
0019 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0020 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0021 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0022 #include "DataFormats/Phase2TrackerDigi/interface/Phase2TrackerDigi.h"
0023 
0024 namespace tttrack {
0025   void errorSetTrackWordBits(unsigned int);
0026 }
0027 
0028 template <typename T>
0029 class TTTrack : public TTTrack_TrackWord {
0030 private:
0031   /// Data members
0032   std::vector<edm::Ref<edmNew::DetSetVector<TTStub<T> >, TTStub<T> > > theStubRefs;
0033   GlobalVector theMomentum_;
0034   GlobalPoint thePOCA_;
0035   double theRInv_;
0036   double thePhi_;
0037   double theTanL_;
0038   double theD0_;
0039   double theZ0_;
0040   unsigned int thePhiSector_;
0041   unsigned int theEtaSector_;
0042   double theStubPtConsistency_;
0043   double theChi2_;
0044   double theChi2_XY_;
0045   double theChi2_Z_;
0046   unsigned int theNumFitPars_;
0047   unsigned int theHitPattern_;
0048   double theTrkMVA1_;
0049   double theTrkMVA2_;
0050   double theTrkMVA3_;
0051   int theTrackSeedType_;
0052   double theBField_;  // needed for unpacking
0053   static constexpr unsigned int Npars4 = 4;
0054   static constexpr unsigned int Npars5 = 5;
0055   static constexpr float MagConstant =
0056       CLHEP::c_light / 1.0E3;  //constant is 0.299792458; who knew c_light was in mm/ns?
0057 
0058 public:
0059   /// Constructors
0060   TTTrack();
0061 
0062   TTTrack(double aRinv,
0063           double aphi,
0064           double aTanLambda,
0065           double az0,
0066           double ad0,
0067           double aChi2,
0068           double trkMVA1,
0069           double trkMVA2,
0070           double trkMVA3,
0071           unsigned int aHitpattern,
0072           unsigned int nPar,
0073           double Bfield);
0074 
0075   TTTrack(double aRinv,
0076           double aphi,
0077           double aTanLambda,
0078           double az0,
0079           double ad0,
0080           double aChi2xyfit,
0081           double aChi2zfit,
0082           double trkMVA1,
0083           double trkMVA2,
0084           double trkMVA3,
0085           unsigned int aHitpattern,
0086           unsigned int nPar,
0087           double Bfield);
0088 
0089   /// Destructor
0090   ~TTTrack();
0091 
0092   /// Track components
0093   std::vector<edm::Ref<edmNew::DetSetVector<TTStub<T> >, TTStub<T> > > getStubRefs() const { return theStubRefs; }
0094   void addStubRef(edm::Ref<edmNew::DetSetVector<TTStub<T> >, TTStub<T> > aStub) { theStubRefs.push_back(aStub); }
0095   void setStubRefs(std::vector<edm::Ref<edmNew::DetSetVector<TTStub<T> >, TTStub<T> > > aStubs) {
0096     theStubRefs = aStubs;
0097   }
0098 
0099   /// Track momentum
0100   GlobalVector momentum() const;
0101 
0102   /// Track curvature
0103   double rInv() const;
0104 
0105   /// Track phi
0106   double phi() const;
0107 
0108   /// Local track phi (within the sector)
0109   double localPhi() const;
0110 
0111   /// Track tanL
0112   double tanL() const;
0113 
0114   /// Track d0
0115   double d0() const;
0116 
0117   /// Track z0
0118   double z0() const;
0119 
0120   /// Track eta
0121   double eta() const;
0122 
0123   /// POCA
0124   GlobalPoint POCA() const;
0125 
0126   /// MVA Track quality variables
0127   double trkMVA1() const;
0128   void settrkMVA1(double atrkMVA1);
0129   double trkMVA2() const;
0130   void settrkMVA2(double atrkMVA2);
0131   double trkMVA3() const;
0132   void settrkMVA3(double atrkMVA3);
0133 
0134   /// Phi Sector
0135   unsigned int phiSector() const { return thePhiSector_; }
0136   void setPhiSector(unsigned int aSector) { thePhiSector_ = aSector; }
0137 
0138   /// Eta Sector
0139   unsigned int etaSector() const { return theEtaSector_; }
0140   void setEtaSector(unsigned int aSector) { theEtaSector_ = aSector; }
0141 
0142   /// Track seeding (for debugging)
0143   unsigned int trackSeedType() const { return theTrackSeedType_; }
0144   void setTrackSeedType(int aSeed) { theTrackSeedType_ = aSeed; }
0145 
0146   /// Chi2
0147   double chi2() const;
0148   double chi2Red() const;
0149   double chi2Z() const;
0150   double chi2ZRed() const;
0151   double chi2XY() const;
0152   double chi2XYRed() const;
0153 
0154   /// Stub Pt consistency (i.e. stub bend chi2/dof)
0155   /// Note: The "stubPtConsistency" names are historic and people are encouraged
0156   ///       to adopt the "chi2Bend" names.
0157   double stubPtConsistency() const;
0158   void setStubPtConsistency(double aPtConsistency);
0159   double chi2BendRed() { return stubPtConsistency(); }
0160   void setChi2BendRed(double aChi2BendRed) { setStubPtConsistency(aChi2BendRed); }
0161   double chi2Bend() { return chi2BendRed() * theStubRefs.size(); }
0162 
0163   void setFitParNo(unsigned int aFitParNo);
0164   int nFitPars() const { return theNumFitPars_; }
0165 
0166   /// Hit Pattern
0167   unsigned int hitPattern() const;
0168 
0169   /// set new Bfield
0170   void setBField(double aBField);
0171 
0172   void setTrackWordBits();
0173   void testTrackWordBits();
0174 
0175   /// Information
0176   std::string print(unsigned int i = 0) const;
0177 
0178 };  /// Close class
0179 
0180 /*! \brief   Implementation of methods
0181  *  \details Here, in the header file, the methods which do not depend
0182  *           on the specific type <T> that can fit the template.
0183  *           Other methods, with type-specific features, are implemented
0184  *           in the source file.
0185  */
0186 
0187 /// Default Constructor
0188 template <typename T>
0189 TTTrack<T>::TTTrack() {
0190   theStubRefs.clear();
0191   theMomentum_ = GlobalVector(0.0, 0.0, 0.0);
0192   theRInv_ = 0.0;
0193   thePOCA_ = GlobalPoint(0.0, 0.0, 0.0);
0194   theD0_ = 0.;
0195   theZ0_ = 0.;
0196   theTanL_ = 0;
0197   thePhi_ = 0;
0198   theTrkMVA1_ = 0;
0199   theTrkMVA2_ = 0;
0200   theTrkMVA3_ = 0;
0201   thePhiSector_ = 0;
0202   theEtaSector_ = 0;
0203   theTrackSeedType_ = 0;
0204   theChi2_ = 0.0;
0205   theChi2_XY_ = 0.0;
0206   theChi2_Z_ = 0.0;
0207   theStubPtConsistency_ = 0.0;
0208   theNumFitPars_ = 0;
0209 }
0210 
0211 /// Meant to be default constructor
0212 template <typename T>
0213 TTTrack<T>::TTTrack(double aRinv,
0214                     double aphi0,
0215                     double aTanlambda,
0216                     double az0,
0217                     double ad0,
0218                     double aChi2,
0219                     double trkMVA1,
0220                     double trkMVA2,
0221                     double trkMVA3,
0222                     unsigned int aHitPattern,
0223                     unsigned int nPar,
0224                     double aBfield) {
0225   theStubRefs.clear();
0226   double thePT = std::abs(MagConstant / aRinv * aBfield / 100.0);  // Rinv is in cm-1
0227   theMomentum_ = GlobalVector(GlobalVector::Cylindrical(thePT, aphi0, thePT * aTanlambda));
0228   theRInv_ = aRinv;
0229   thePOCA_ = GlobalPoint(ad0 * sin(aphi0), -ad0 * cos(aphi0), az0);
0230   theD0_ = ad0;
0231   theZ0_ = az0;
0232   thePhi_ = aphi0;
0233   theTanL_ = aTanlambda;
0234   thePhiSector_ = 0;      // must be set externally
0235   theEtaSector_ = 0;      // must be set externally
0236   theTrackSeedType_ = 0;  // must be set externally
0237   theChi2_ = aChi2;
0238   theTrkMVA1_ = trkMVA1;
0239   theTrkMVA2_ = trkMVA2;
0240   theTrkMVA3_ = trkMVA3;
0241   theStubPtConsistency_ = 0.0;  // must be set externally
0242   theNumFitPars_ = nPar;
0243   theHitPattern_ = aHitPattern;
0244   theBField_ = aBfield;
0245   theChi2_XY_ = -999.;
0246   theChi2_Z_ = -999.;
0247 }
0248 
0249 /// Second default constructor with split chi2
0250 template <typename T>
0251 TTTrack<T>::TTTrack(double aRinv,
0252                     double aphi0,
0253                     double aTanlambda,
0254                     double az0,
0255                     double ad0,
0256                     double aChi2XY,
0257                     double aChi2Z,
0258                     double trkMVA1,
0259                     double trkMVA2,
0260                     double trkMVA3,
0261                     unsigned int aHitPattern,
0262                     unsigned int nPar,
0263                     double aBfield)
0264     : TTTrack(aRinv,
0265               aphi0,
0266               aTanlambda,
0267               az0,
0268               ad0,
0269               aChi2XY + aChi2Z,  // add chi2 values
0270               trkMVA1,
0271               trkMVA2,
0272               trkMVA3,
0273               aHitPattern,
0274               nPar,
0275               aBfield) {
0276   this->theChi2_XY_ = aChi2XY;
0277   this->theChi2_Z_ = aChi2Z;
0278 }
0279 
0280 /// Destructor
0281 template <typename T>
0282 TTTrack<T>::~TTTrack() {}
0283 
0284 template <typename T>
0285 void TTTrack<T>::setFitParNo(unsigned int nPar) {
0286   theNumFitPars_ = nPar;
0287 
0288   return;
0289 }
0290 
0291 // Note that these calls return the floating point values.  If a TTTrack is made with only ditized values,
0292 // the unpacked values must come from the TTTrack_Trackword member functions.
0293 
0294 template <typename T>
0295 GlobalVector TTTrack<T>::momentum() const {
0296   return theMomentum_;
0297 }
0298 
0299 template <typename T>
0300 double TTTrack<T>::rInv() const {
0301   return theRInv_;
0302 }
0303 
0304 template <typename T>
0305 double TTTrack<T>::tanL() const {
0306   return theTanL_;
0307 }
0308 
0309 template <typename T>
0310 double TTTrack<T>::eta() const {
0311   return theMomentum_.eta();
0312 }
0313 
0314 template <typename T>
0315 double TTTrack<T>::phi() const {
0316   return thePhi_;
0317 }
0318 
0319 template <typename T>
0320 double TTTrack<T>::localPhi() const {
0321   return TTTrack_TrackWord::localPhi(thePhi_, thePhiSector_);
0322 }
0323 
0324 template <typename T>
0325 double TTTrack<T>::d0() const {
0326   return theD0_;
0327 }
0328 
0329 template <typename T>
0330 double TTTrack<T>::z0() const {
0331   return theZ0_;
0332 }
0333 
0334 template <typename T>
0335 GlobalPoint TTTrack<T>::POCA() const {
0336   return thePOCA_;
0337 }
0338 
0339 /// Chi2
0340 template <typename T>
0341 double TTTrack<T>::chi2() const {
0342   return theChi2_;
0343 }
0344 
0345 /// Chi2Z
0346 template <typename T>
0347 double TTTrack<T>::chi2Z() const {
0348   return theChi2_Z_;
0349 }
0350 
0351 /// Chi2XY
0352 template <typename T>
0353 double TTTrack<T>::chi2XY() const {
0354   return theChi2_XY_;
0355 }
0356 
0357 /// Chi2 reduced
0358 template <typename T>
0359 double TTTrack<T>::chi2Red() const {
0360   return theChi2_ / (2 * theStubRefs.size() - theNumFitPars_);
0361 }
0362 
0363 /// Chi2XY reduced
0364 template <typename T>
0365 double TTTrack<T>::chi2XYRed() const {
0366   return theChi2_XY_ / (theStubRefs.size() - (theNumFitPars_ - 2));
0367 }
0368 
0369 /// Chi2Z reduced
0370 template <typename T>
0371 double TTTrack<T>::chi2ZRed() const {
0372   return theChi2_Z_ / (theStubRefs.size() - 2.);
0373 }
0374 
0375 /// prompt track quality MVA
0376 template <typename T>
0377 double TTTrack<T>::trkMVA1() const {
0378   return theTrkMVA1_;
0379 }
0380 
0381 template <typename T>
0382 void TTTrack<T>::settrkMVA1(double atrkMVA1) {
0383   theTrkMVA1_ = atrkMVA1;
0384   return;
0385 }
0386 
0387 template <typename T>
0388 double TTTrack<T>::trkMVA2() const {
0389   return theTrkMVA2_;
0390 }
0391 
0392 template <typename T>
0393 void TTTrack<T>::settrkMVA2(double atrkMVA2) {
0394   theTrkMVA2_ = atrkMVA2;
0395   return;
0396 }
0397 
0398 template <typename T>
0399 double TTTrack<T>::trkMVA3() const {
0400   return theTrkMVA3_;
0401 }
0402 
0403 template <typename T>
0404 void TTTrack<T>::settrkMVA3(double atrkMVA3) {
0405   theTrkMVA3_ = atrkMVA3;
0406   return;
0407 }
0408 
0409 /// StubPtConsistency
0410 template <typename T>
0411 void TTTrack<T>::setStubPtConsistency(double aStubPtConsistency) {
0412   theStubPtConsistency_ = aStubPtConsistency;
0413   return;
0414 }
0415 
0416 /// StubPtConsistency
0417 template <typename T>
0418 double TTTrack<T>::stubPtConsistency() const {
0419   return theStubPtConsistency_;
0420 }
0421 
0422 /// Hit Pattern
0423 template <typename T>
0424 unsigned int TTTrack<T>::hitPattern() const {
0425   return theHitPattern_;
0426 }
0427 
0428 /// set B field if need be
0429 template <typename T>
0430 void TTTrack<T>::setBField(double aBField) {
0431   // if, for some reason, we want to change the value of the B-Field, recompute pT and momentum:
0432   double thePT = std::abs(MagConstant / theRInv_ * aBField / 100.0);  // Rinv is in cm-1
0433   theMomentum_ = GlobalVector(GlobalVector::Cylindrical(thePT, thePhi_, thePT * theTanL_));
0434 
0435   return;
0436 }
0437 
0438 /// Set bits in 96-bit Track word
0439 template <typename T>
0440 void TTTrack<T>::setTrackWordBits() {
0441   if (!(theNumFitPars_ == Npars4 || theNumFitPars_ == Npars5)) {
0442     tttrack::errorSetTrackWordBits(theNumFitPars_);
0443     return;
0444   }
0445 
0446   unsigned int valid = true;
0447   unsigned int mvaOther = 0;
0448 
0449   // missing conversion of global phi to difference from sector center phi
0450 
0451   if (theChi2_Z_ < 0) {
0452     setTrackWord(valid,
0453                  theMomentum_,
0454                  thePOCA_,
0455                  theRInv_,
0456                  theChi2_,
0457                  0,
0458                  theStubPtConsistency_,
0459                  theHitPattern_,
0460                  theTrkMVA1_,
0461                  mvaOther,
0462                  thePhiSector_);
0463   } else {
0464     setTrackWord(valid,
0465                  theMomentum_,
0466                  thePOCA_,
0467                  theRInv_,
0468                  chi2XYRed(),
0469                  chi2ZRed(),
0470                  chi2BendRed(),
0471                  theHitPattern_,
0472                  theTrkMVA1_,
0473                  mvaOther,
0474                  thePhiSector_);
0475   }
0476   return;
0477 }
0478 
0479 /// Test bits in 96-bit Track word
0480 template <typename T>
0481 void TTTrack<T>::testTrackWordBits() {
0482   //  float rPhi = theMomentum_.phi();  // this needs to be phi relative to center of sector ****
0483   //float rEta = theMomentum_.eta();
0484   //float rZ0 = thePOCA_.z();
0485   //float rD0 = thePOCA_.perp();
0486 
0487   //this is meant for debugging only.
0488 
0489   //std::cout << " phi " << rPhi << " " << get_iphi() << std::endl;
0490   //std::cout << " eta " << rEta << " " << get_ieta() << std::endl;
0491   //std::cout << " Z0 " << rZ0 << " " << get_iz0() << std::endl;
0492   //std::cout << " D0 " << rD0 << " " << get_id0() << std::endl;
0493   //std::cout << " Rinv " << theRInv_ << " " << get_iRinv() << std::endl;
0494   //std::cout << " chi2 " << theChi2_ << " " << get_ichi2() << std::endl;
0495 
0496   return;
0497 }
0498 
0499 /// Information
0500 template <typename T>
0501 std::string TTTrack<T>::print(unsigned int i) const {
0502   std::string padding("");
0503   for (unsigned int j = 0; j != i; ++j) {
0504     padding += "\t";
0505   }
0506 
0507   std::stringstream output;
0508   output << padding << "TTTrack:\n";
0509   padding += '\t';
0510   output << '\n';
0511   unsigned int iStub = 0;
0512 
0513   typename std::vector<edm::Ref<edmNew::DetSetVector<TTStub<T> >, TTStub<T> > >::const_iterator stubIter;
0514   for (stubIter = theStubRefs.begin(); stubIter != theStubRefs.end(); ++stubIter) {
0515     output << padding << "stub: " << iStub++ << ", DetId: " << ((*stubIter)->getDetId()).rawId() << '\n';
0516   }
0517 
0518   return output.str();
0519 }
0520 
0521 template <typename T>
0522 std::ostream& operator<<(std::ostream& os, const TTTrack<T>& aTTTrack) {
0523   return (os << aTTTrack.print());
0524 }
0525 
0526 #endif