CMS 3D CMS Logo

MuonCSCSeedFromRecHits.cc

Go to the documentation of this file.
00001 #include "RecoMuon/MuonSeedGenerator/src/MuonCSCSeedFromRecHits.h"
00002 #include "RecoMuon/MuonSeedGenerator/src/MuonSeedPtExtractor.h"
00003 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00004 #include "Geometry/CSCGeometry/interface/CSCChamberSpecs.h"
00005 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00006 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00007 #include "DataFormats/TrajectoryState/interface/PTrajectoryStateOnDet.h"
00008 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "Geometry/CSCGeometry/interface/CSCChamberSpecs.h"
00011 #include <iomanip>
00012 
00013 
00014 MuonCSCSeedFromRecHits::MuonCSCSeedFromRecHits()
00015 : MuonSeedFromRecHits()
00016 {
00017   //FIXME make configurable
00018   // parameters for the fit of dphi between chambers vs. eta
00019   // pt = (c1 + c2 abs(eta))/ dphi
00020   fillConstants(1,5, 0.6640, -0.2253);
00021   fillConstants(1,7, 0.6255, -0.1955);
00022   fillConstants(2,5, 0.6876, -0.2379);
00023   fillConstants(2,7, 0.6404, -0.2009);
00024   //fillConstants(2,8, 0.7972, -0.3032);
00025   fillConstants(3,5, 0.2773, -0.1017);
00026   fillConstants(3,6, -0.05597, 0.11840);
00027   fillConstants(3,8, -0.09705, 0.15916);
00028   // numbers from Shih-Chuam's May 2007 talk
00029   fillConstants(4,6, -0.123,   0.167);
00030   fillConstants(5,7, 0.035, 0.);
00031   fillConstants(6,8, 0.025, 0.);
00032 
00033 
00034 
00035 }
00036 
00037 
00038 void MuonCSCSeedFromRecHits::fillConstants(int chamberType1, int chamberType2, double c1, double c2)
00039 {
00040   theConstantsMap[std::make_pair(chamberType1,chamberType2)] = std::make_pair(c1, c2);
00041 }
00042 
00043 
00044 TrajectorySeed MuonCSCSeedFromRecHits::seed() const
00045 {
00046   if(theRhits.size() == 1) 
00047   {
00048      return createSeed(100., 100., theRhits[0]);
00049   }
00050   //analyze();
00051   TrajectorySeed result;
00052   //@@ doesn't handle overlap between ME11 and ME12 correctly
00053   // sort by station
00054   MuonRecHitContainer station1Hits, station2Hits, station3Hits, station4Hits;
00055   for ( MuonRecHitContainer::const_iterator iter = theRhits.begin(), end = theRhits.end();
00056         iter != end; ++iter)
00057   {
00058     int station = CSCDetId((*iter)->geographicalId().rawId()).station();
00059     if(station == 1)
00060     {
00061       station1Hits.push_back(*iter);
00062     }
00063     else if(station == 2) 
00064     {
00065       station2Hits.push_back(*iter);
00066     }
00067     else if(station == 3)
00068     {
00069       station3Hits.push_back(*iter);
00070     }
00071     else if(station == 4)
00072     {
00073       station4Hits.push_back(*iter);
00074     }
00075   }
00076 
00077   //std::cout << "Station hits " << station1Hits.size() << " " 
00078   //                            << station2Hits.size() << " "
00079   //                             << station3Hits.size() << std::endl;
00080 
00081   // see whether station 2 or station 3 is better
00082   MuonRecHitContainer * betterSecondHits = &station2Hits; 
00083   MuonRecHitContainer * notAsGoodSecondHits = &station3Hits;
00084   if(!station2Hits.empty() && !station3Hits.empty())
00085   { 
00086     // swap if station 3 has better quailty
00087     if(segmentQuality(station3Hits[0]) < segmentQuality(station2Hits[0]))
00088     {
00089       betterSecondHits = &station3Hits;
00090       notAsGoodSecondHits = &station2Hits; 
00091     }
00092   }
00093 
00094   // now try to make pairs
00095   if(makeSeed(station1Hits, *betterSecondHits, result))
00096   {
00097     return result;
00098   }
00099   if(makeSeed(station1Hits, *notAsGoodSecondHits, result))
00100   {
00101     return result;
00102   }
00103   if(makeSeed(station2Hits, station3Hits, result))
00104   {
00105     return result;
00106   }
00107   if(makeSeed(station1Hits, station4Hits, result))
00108   {
00109     return result;
00110   }
00111 
00112 
00113 
00114   // no luck
00115   makeDefaultSeed(result);
00116   return result;
00117 }
00118 
00119 
00120 bool MuonCSCSeedFromRecHits::makeSeed(const MuonRecHitContainer & hits1, const MuonRecHitContainer & hits2,
00121                                       TrajectorySeed & seed) const
00122 {
00123   for ( MuonRecHitContainer::const_iterator itr1 = hits1.begin(), end1 = hits1.end();
00124         itr1 != end1; ++itr1)
00125   {
00126     CSCDetId cscId1((*itr1)->geographicalId().rawId());
00127     //int type1 = CSCChamberSpecs::whatChamberType(cscId1.station(), cscId1.ring());
00128 
00129     for ( MuonRecHitContainer::const_iterator itr2 = hits2.begin(), end2 = hits2.end();
00130           itr2 != end2; ++itr2)
00131     {
00132 
00133       CSCDetId cscId2((*itr2)->geographicalId().rawId());
00134       //int type2 = CSCChamberSpecs::whatChamberType(cscId2.station(), cscId2.ring());
00135 
00136         // take the first pair that comes along.  Probably want to rank them later
00137       std::vector<double> pts = thePtExtractor->pT_extract(*itr1, *itr2);
00138         
00139         double pt = pts[0];
00140         double sigmapt = pts[1];
00141         double minpt = 3.;
00142 
00143         // if too small, probably an error.  Keep trying.
00144         if(fabs(pt) > minpt)
00145         {
00146           double maxpt = 2000.;
00147           if(pt > maxpt) {
00148             pt = maxpt;
00149             sigmapt = maxpt;
00150           }
00151           if(pt < -maxpt) {
00152             pt = -maxpt;
00153             sigmapt = maxpt;
00154           }
00155 
00156           // get the position and direction from the higher-quality segment
00157           ConstMuonRecHitPointer bestSeg = bestSegment();
00158           seed = createSeed(pt, sigmapt, bestSeg);
00159 
00160           //std::cout << "FITTED TIMESPT " << pt << " dphi " << dphi << " eta " << eta << std::endl;
00161           return true;
00162         }
00163 
00164     }
00165   }
00166 
00167   // guess it didn't find one
00168 //std::cout << "NOTHING FOUND ! " << std::endl;
00169   return false;
00170 }
00171 
00172 
00173 //typedef MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer;
00174 int MuonCSCSeedFromRecHits::segmentQuality(ConstMuonRecHitPointer  segment) const
00175 {
00176   int Nchi2 = 0;
00177   int quality = 0;
00178   int nhits = segment->recHits().size();
00179   if ( segment->chi2()/(nhits*2.-4.) > 3. ) Nchi2 = 1;
00180   if ( segment->chi2()/(nhits*2.-4.) > 9. ) Nchi2 = 2;
00181 
00182   if ( nhits >  4 ) quality = 1 + Nchi2;
00183   if ( nhits == 4 ) quality = 3 + Nchi2;
00184   if ( nhits == 3 ) quality = 5 + Nchi2;
00185 
00186   float dPhiGloDir = fabs ( segment->globalPosition().phi() - segment->globalDirection().phi() );
00187   if ( dPhiGloDir > M_PI   )  dPhiGloDir = 2.*M_PI - dPhiGloDir;
00188 
00189   if ( dPhiGloDir > .2 ) ++quality;
00190   return quality;
00191 }
00192 
00193 
00194 
00195 MuonCSCSeedFromRecHits::ConstMuonRecHitPointer
00196 MuonCSCSeedFromRecHits::bestSegment() const
00197 {
00198   MuonRecHitPointer me1=0, meit=0;
00199   float dPhiGloDir = .0;                            //  +v
00200   float bestdPhiGloDir = M_PI;                      //  +v
00201   int quality1 = 0, quality = 0;        //  +v  I= 5,6-p. / II= 4p.  / III= 3p.
00202 
00203   for ( MuonRecHitContainer::const_iterator iter = theRhits.begin(); iter!= theRhits.end(); iter++ ){
00204     if ( !(*iter)->isCSC() ) continue;
00205 
00206     // tmp compar. Glob-Dir for the same tr-segm:
00207 
00208     meit = *iter;
00209 
00210     quality = segmentQuality(meit);
00211 
00212     dPhiGloDir = fabs ( meit->globalPosition().phi() - meit->globalDirection().phi() );
00213     if ( dPhiGloDir > M_PI   )  dPhiGloDir = 2.*M_PI - dPhiGloDir;
00214 
00215 
00216     if(!me1){
00217       me1 = meit;
00218       quality1 = quality;
00219       bestdPhiGloDir = dPhiGloDir;
00220     }
00221 
00222     if(me1) {
00223 
00224       if ( !me1->isValid() ) {
00225         me1 = meit;
00226         quality1 = quality;
00227         bestdPhiGloDir = dPhiGloDir;
00228       }
00229 
00230       if ( me1->isValid() && quality < quality1 ) {
00231         me1 = meit;
00232         quality1 = quality;
00233         bestdPhiGloDir = dPhiGloDir;
00234       }
00235 
00236       if ( me1->isValid() && bestdPhiGloDir > .03 ) {
00237         if ( dPhiGloDir < bestdPhiGloDir - .01 && quality == quality1 ) {
00238           me1 = meit;
00239           quality1 = quality;
00240           bestdPhiGloDir = dPhiGloDir;
00241         }
00242       }
00243     }
00244 
00245   }   //  iter
00246 
00247   return me1;
00248 }
00249 
00250 
00251 void MuonCSCSeedFromRecHits::makeDefaultSeed(TrajectorySeed & seed) const
00252 {
00253   //Search ME1  ...
00254   ConstMuonRecHitPointer me1= bestSegment();
00255   bool good=false;
00256 
00257   if(me1 && me1->isValid() )
00258   {
00259     good = createDefaultEndcapSeed(me1, seed); 
00260   }
00261 }
00262 
00263 
00264 
00265 
00266 
00267 bool 
00268 MuonCSCSeedFromRecHits::createDefaultEndcapSeed(ConstMuonRecHitPointer last, 
00269                                  TrajectorySeed & seed) const {
00270   const std::string metname = "Muon|RecoMuon|MuonSeedFinder";
00271   
00272   AlgebraicSymMatrix mat(5,0) ;
00273 
00274   // this perform H.T() * parErr * H, which is the projection of the 
00275   // the measurement error (rechit rf) to the state error (TSOS rf)
00276   // Legenda:
00277   // H => is the 4x5 projection matrix
00278   // parError the 4x4 parameter error matrix of the RecHit
00279   
00280   mat = last->parametersError().similarityT( last->projectionMatrix() );
00281   
00282   // We want pT but it's not in RecHit interface, so we've put it within this class
00283   //float momentum = computeDefaultPt(last);
00284   std::vector<double> momentum = thePtExtractor->pT_extract(last, last);
00285   // FIXME
00286   //  float smomentum = 0.25*momentum; // FIXME!!!!
00287   float smomentum = 25; 
00288 
00289   seed = createSeed(momentum[0],momentum[1],last);
00290   return true;
00291 }
00292 
00293 
00294 
00295 void MuonCSCSeedFromRecHits::analyze() const 
00296 {
00297   for ( MuonRecHitContainer::const_iterator iter = theRhits.begin(); iter!= theRhits.end(); iter++ ){
00298     if ( !(*iter)->isCSC() ) continue;
00299     for ( MuonRecHitContainer::const_iterator iter2 = iter + 1; iter2 != theRhits.end(); ++iter2)
00300     {
00301       if( !(*iter2)->isCSC() ) continue;
00302 
00303       CSCDetId cscId1((*iter)->geographicalId().rawId());
00304       CSCDetId cscId2((*iter2)->geographicalId().rawId());
00305       double dphi = (**iter).globalPosition().phi() - (**iter2).globalPosition().phi();
00306       if(dphi > M_PI) dphi -= 2*M_PI;
00307       if(dphi < -M_PI) dphi += 2*M_PI;
00308 
00309       int type1 = CSCChamberSpecs::whatChamberType(cscId1.station(), cscId1.ring());
00310       int type2 = CSCChamberSpecs::whatChamberType(cscId2.station(), cscId2.ring());
00311 
00312       // say the lower station first
00313       if(type1 < type2)
00314       {
00315         std::cout << "HITPAIRA," << type1 << type2 << "," <<
00316             dphi << "," << (**iter).globalPosition().eta() << std::endl;
00317       }
00318       if(type2 < type1)
00319       {
00320         std::cout << "HITPAIRB," << type2 << type1 << "," <<
00321             -dphi << "," << (**iter2).globalPosition().eta() << std::endl;
00322       }
00323       if(type1 == type2)
00324       {
00325         std::cout << "HITPAIRSAMESTATION," << type1 << cscId1.ring() << cscId2.ring()
00326            << "," << dphi << "," << (**iter).globalPosition().eta() << std::endl;
00327       }
00328 
00329     }
00330   }
00331 }

Generated on Tue Jun 9 17:44:25 2009 for CMSSW by  doxygen 1.5.4