CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoHI/HiMuonAlgos/src/HICFTSfromL1orL2.cc

Go to the documentation of this file.
00001 
00002 // HeavyIonAnalysis
00003 
00004 #include "RecoHI/HiMuonAlgos/interface/HICFTSfromL1orL2.h"
00005 #include "DataFormats/Common/interface/RefToBase.h"
00006 using namespace reco;
00007 using namespace std;
00008 //#define OK_DEBUG
00009 //-----------------------------------------------------------------------------
00010 // Vector of Free Trajectory State in Muon stations from L1 Global Muon Trigger
00011 namespace cms {
00012 vector<FreeTrajectoryState> HICFTSfromL1orL2::createFTSfromL1(vector<L1MuGMTExtendedCand>& gmt) 
00013 { 
00014 // ========================================================================================
00015 //
00016 //  Switch on L1 muon trigger.
00017 //
00018   
00019   vector<FreeTrajectoryState> ftsL1;
00020 
00021   int ngmt = gmt.size();
00022 #ifdef DEBUG
00023   cout << "Number of muons found by the L1 Global Muon TRIGGER : "
00024        << ngmt << endl;
00025 #endif
00026   if(ngmt<0) {
00027     return ftsL1;
00028   } 
00029   
00030   for ( vector<L1MuGMTExtendedCand>::const_iterator gmt_it = gmt.begin(); gmt_it != gmt.end(); gmt_it++ )
00031   {
00032    ftsL1.push_back(FTSfromL1((*gmt_it)));
00033   }
00034   return ftsL1;
00035 } // end createFTSfromL1
00036 //-----------------------------------------------------------------------------
00037 // Vector of Free Trajectory State in Muon stations from L2 Muon Trigger
00038 
00039 vector<FreeTrajectoryState> HICFTSfromL1orL2::createFTSfromL2(const RecoChargedCandidateCollection& recmuons) 
00040 { 
00041 // ========================================================================================
00042 //
00043 //  Switch on L2 muon trigger.
00044 //
00045 
00046   vector<FreeTrajectoryState> ftsL2;
00047 //  RecQuery q(localRecAlgo);
00048 
00049   RecoChargedCandidateCollection::const_iterator recmuon = recmuons.begin();
00050 
00051 //  int nrec = recmuons.size();
00052 #ifdef DEBUG
00053   cout << "Number of muons found by the L2 TRIGGER : "
00054        << nrec << endl;
00055 #endif
00056   for(recmuon=recmuons.begin(); recmuon!=recmuons.end(); recmuon++)
00057   {
00058   ftsL2.push_back(FTSfromL2((*recmuon)));
00059   } // endfor
00060   return ftsL2;
00061 } // end createFTSfromL2
00062 
00063 
00064 vector<FreeTrajectoryState> HICFTSfromL1orL2::createFTSfromStandAlone(const TrackCollection& recmuons) 
00065 { 
00066 // ========================================================================================
00067 //
00068 //  Switch on L2 muon trigger.
00069 //
00070 
00071   vector<FreeTrajectoryState> ftsL2;
00072 //  RecQuery q(localRecAlgo);
00073 
00074   TrackCollection::const_iterator recmuon = recmuons.begin();
00075 
00076  // int nrec = recmuons.size();
00077 #ifdef DEBUG
00078   cout << "Number of muons found by the StandAlone : "
00079        << nrec << endl;
00080 #endif
00081   for(recmuon=recmuons.begin(); recmuon!=recmuons.end(); recmuon++)
00082   {
00083   ftsL2.push_back(FTSfromStandAlone((*recmuon)));
00084   } // endfor
00085   return ftsL2;
00086 } // end createFTSfromStandAlone
00087 
00088 vector<FreeTrajectoryState> HICFTSfromL1orL2::createFTSfromL2(const TrackCollection& recmuons)
00089 {
00090 // ========================================================================================
00091 //
00092 //  Switch on L2 muon trigger.
00093 //
00094 
00095   vector<FreeTrajectoryState> ftsL2;
00096 //  RecQuery q(localRecAlgo);
00097 
00098   TrackCollection::const_iterator recmuon = recmuons.begin();
00099 
00100 //  int nrec = recmuons.size();
00101 #ifdef DEBUG
00102   cout << "Number of muons found by the StandAlone : "
00103        << nrec << endl;
00104 #endif
00105   for(recmuon=recmuons.begin(); recmuon!=recmuons.end(); recmuon++)
00106   {
00107   ftsL2.push_back(FTSfromStandAlone((*recmuon)));
00108   } // endfor
00109   return ftsL2;
00110 } // end createFTSfromStandAlone
00111 
00112 
00113 
00114 //-----------------------------------------------------------------------------
00115 // Vector of Free Trajectory State in Muon stations from L1 Global Muon Trigger
00116 
00117 vector<FreeTrajectoryState> HICFTSfromL1orL2::createFTSfromL1orL2(vector<L1MuGMTExtendedCand>& gmt, const RecoChargedCandidateCollection& recmuons) 
00118 {
00119     double pi=4.*atan(1.);
00120     double twopi=8.*atan(1.);
00121 
00122     vector<FreeTrajectoryState> ftsL1orL2;
00123     vector<FreeTrajectoryState> ftsL1 = createFTSfromL1(gmt);
00124     vector<FreeTrajectoryState> ftsL2 = createFTSfromL2(recmuons);
00125 //
00126 // Clean candidates if L1 and L2 pointed to one muon. 
00127 //
00128     vector<FreeTrajectoryState*>::iterator itused;    
00129     vector<FreeTrajectoryState*> used;
00130     
00131     for(vector<FreeTrajectoryState>::iterator tl1 = ftsL1.begin(); tl1 != ftsL1.end(); tl1++)
00132     { 
00133    //      float ptL1    =  (*tl1).parameters().momentum().perp();
00134          float etaL1   =  (*tl1).parameters().momentum().eta();
00135          float phiL1   =  (*tl1).parameters().momentum().phi();
00136          if( phiL1 < 0.) phiL1 = twopi + phiL1;
00137     //     int chargeL1  =  (*tl1).charge();
00138          int L2 = 0;  // there is no L2 muon.
00139                  
00140        for(vector<FreeTrajectoryState>::iterator tl2 = ftsL2.begin(); tl2 != ftsL2.end(); tl2++)
00141        {
00142          itused = find(used.begin(),used.end(),&(*tl2));
00143  //        float ptL2    =  (*tl2).parameters().momentum().perp();
00144          float etaL2   =  (*tl2).parameters().momentum().eta();
00145          float phiL2   =  (*tl2).parameters().momentum().phi();
00146          if( phiL2 < 0.) phiL2 = twopi + phiL2;
00147   //       int chargeL2  =  (*tl2).charge();
00148          float dphi = abs(phiL1-phiL2);
00149          if( dphi > pi ) dphi = twopi - dphi; 
00150          float dr = sqrt((etaL1 - etaL2)*(etaL1 - etaL2)+dphi*dphi);
00151          
00152 #ifdef OK_DEBUG 
00153          cout<<" ===== Trigger Level 1 candidate: ptL1 "<<ptL1<<" EtaL1 "<<etaL1<<" PhiL1 "<<phiL1<<
00154          " chargeL1 "<<chargeL1<<endl;
00155          cout<<" ===== Trigger Level 2 candidate: ptL2 "<<ptL2<<" EtaL2 "<<etaL2<<" PhiL2 "<<phiL2<<
00156          " chargeL2 "<<chargeL2<<endl;
00157          cout<<" abs(EtaL1 - EtaL2) "<<abs(etaL1 - etaL2)<<" dphi "<<dphi<<" dr "<<dr<<
00158          " dQ "<<chargeL1 - chargeL2
00159          <<" the same muon or not L2 "<<L2<<endl;
00160 #endif   
00161          
00162          if ( itused != used.end() ) {
00163 //          cout<<" L2 is already used in primary cycle"<<endl;
00164             continue;
00165          }
00166          
00167          
00168          
00169          float drmax = 0.5;
00170          if( abs(etaL1) > 1.9 ) drmax = 0.6; 
00171          
00172 #ifdef OK_DEBUG
00173          cout<<" Drmax= "<<drmax<<endl;
00174 #endif    
00175          L2 = 0;       
00176          if( dr < drmax )
00177          { // it is the same muon. Take L2 trigger.
00178 //           if ( chargeL1 == chargeL2 ) 
00179 //           { // The same muon. Take L2 candidate.
00180                L2 = 1;
00181                ftsL1orL2.push_back((*tl2));
00182                used.push_back(&(*tl2));
00183 //             cout<<" add L2 for same muon"<<endl;
00184                break;
00185 //           } // endif  
00186 //             else 
00187 //           { // Probably different muons in the same cell. Try to recover on L3.
00188 //             ftsL1orL2.push_back((*tl1));
00189 //             ftsL1orL2.push_back((*tl2));
00190 //             cout<<" add L2 for diff muon"<<endl;
00191 //             used.push_back(&(*tl2));
00192 //           }  // endelse
00193          } // endif
00194       } // end for L2
00195        if( L2 == 0 ) 
00196        {
00197 //        cout<<" add L1 for no L2 muon"<<endl;
00198           ftsL1orL2.push_back((*tl1)); // No L1 candidate. Take L1 candidate.
00199        }          
00200     } // end for L1
00201 
00202   //  cout<<" Add the last L2 candidates that have not corresponding L1 "<<endl;
00203     
00204     if( ftsL2.size() > 0 )
00205     { // just add the ramains L2 candidates
00206     for(vector<FreeTrajectoryState>::iterator tl2 = ftsL2.begin(); tl2 != ftsL2.end(); tl2++)
00207     {
00208       itused = find(used.begin(),used.end(),&(*tl2));
00209       if ( itused != used.end() ) 
00210       {
00211 //       cout<<" L2 is already used in secondary cycle"<<endl;
00212          continue;
00213       }  
00214       ftsL1orL2.push_back((*tl2));
00215     } // end for L2
00216     }
00217   //  cout<<" The number of trajectories in muon stations "<<ftsL1orL2.size()<<endl;
00218     return ftsL1orL2; 
00219 }
00220 //-----------------------------------------------------------------------------
00221 // Vector of Free Trajectory State from L1 trigger candidate
00222 
00223   FreeTrajectoryState HICFTSfromL1orL2::FTSfromL1(const L1MuGMTExtendedCand& gmt){
00224     double pi=4.*atan(1.);
00225     unsigned int det = gmt.isFwd();
00226     double px,py,pz,x,y,z;
00227     float pt    =  gmt.ptValue();
00228     float eta   =  gmt.etaValue();
00229     float theta =  2*atan(exp(-eta));
00230     float phi   =  gmt.phiValue();
00231     int charge  =  gmt.charge();
00232     
00233     bool barrel = true;
00234     if(det) barrel = false;
00235 //
00236 // Take constant radius for barrel = 513 cm and constant z for endcap = 800 cm.
00237 // hardcodded.
00238 //
00239     float radius = 513.;  
00240     if ( !barrel ) {
00241     radius = 800.;
00242     if(eta<0.) radius=-1.*radius;
00243     }
00244     
00245     if (  barrel && pt < 3.5 ) pt = 3.5;
00246     if ( !barrel && pt < 1.0 ) pt = 1.0;
00247     
00248     
00249 // Calculate FTS for barrel and endcap     
00250     
00251     if(barrel){
00252      
00253 // barrel
00254 
00255     if(abs(theta-pi/2.)<0.00001){
00256       pz=0.;
00257       z=0.;
00258     }else{
00259       pz=pt/tan(theta);
00260       z=radius/tan(theta);
00261     }
00262      x=radius*cos(phi);
00263      y=radius*sin(phi);
00264    
00265     } else {
00266     
00267 // endcap
00268 
00269     pz=pt/tan(theta);
00270     z=radius;
00271     x=z*tan(theta)*cos(phi);
00272     y=z*tan(theta)*sin(phi);
00273     } 
00274     
00275     px=pt*cos(phi);
00276     py=pt*sin(phi);
00277   
00278 //    cout<<" CreateFts:x,y,x,px,py,pz "<<x<< " "<<y<<" "<<z<<" "<<px<<" "<<py<<" "<<pz<<endl;
00279     
00280     GlobalPoint aX(x,y,z);
00281     GlobalVector aP(px,py,pz);    
00282     GlobalTrajectoryParameters gtp(aX,aP,charge,field);
00283     
00284     AlgebraicSymMatrix55 m;
00285     m(0,0)=0.6*pt; m(1,1)=1.; m(2,2)=1.;
00286     m(3,3)=1.;m(4,4)=0.; 
00287     CurvilinearTrajectoryError cte(m);
00288 
00289     FreeTrajectoryState fts(gtp,cte);
00290     return fts;
00291   }
00292   
00293 //-----------------------------------------------------------------------------
00294 // Vector of Free Trajectory State from L2 trigger candidate
00295 
00296   FreeTrajectoryState HICFTSfromL1orL2::FTSfromL2(const RecoChargedCandidate& gmt)
00297   {
00298   
00299     TrackRef tk1 = gmt.get<TrackRef>();
00300     
00301     const math::XYZPoint pos0 = tk1->innerPosition();
00302     const math::XYZVector mom0 = tk1->innerMomentum();
00303     
00304     double pp = sqrt(mom0.x()*mom0.x()+mom0.y()*mom0.y()+mom0.z()*mom0.z());
00305     double pt = sqrt(mom0.x()*mom0.x()+mom0.y()*mom0.y());
00306     double theta = mom0.theta();
00307     double pz = mom0.z();
00308     
00309     GlobalVector mom(mom0.x(),mom0.y(),mom0.z());
00310     
00311     if( pt < 4.) 
00312     {
00313       pt = 4.; if (abs(pz) > 0. )  pz = pt/tan(theta);
00314       double corr = sqrt( pt*pt + pz*pz )/pp;
00315       GlobalVector mom1( corr*mom0.x(), corr*mom0.y(), corr*mom0.z() );
00316       mom = mom1;
00317     }
00318 
00319    // cout<<" L2::Innermost state "<<pos0<<" new momentum "<<mom<<" old momentum "<<mom0<<endl;
00320     
00321     AlgebraicSymMatrix55 m;
00322     /*
00323     double error;
00324     if( abs(mom.eta()) < 1. )
00325     {
00326      error = 0.6*mom.perp();
00327     }
00328      else
00329     {
00330      error = 0.6*abs(mom.z());
00331     }
00332     */
00333     m(0,0)=0.6*mom.perp(); m(1,1)=1.; m(2,2)=1.;
00334     m(3,3)=1.;m(4,4)=0.; 
00335     CurvilinearTrajectoryError cte(m);
00336     GlobalPoint pos(pos0.x(),pos0.y(),pos0.z());
00337     
00338     GlobalTrajectoryParameters gtp(pos,mom,tk1->charge(), field);
00339     FreeTrajectoryState fts(gtp,cte);
00340   
00341   return fts;
00342   }
00343 //-----------------------------------------------------------------------------
00344 // Vector of Free Trajectory State from StanAlone candidate
00345 
00346   FreeTrajectoryState HICFTSfromL1orL2::FTSfromStandAlone(const Track& tk1)
00347   {
00348   
00349 //    TrackRef tk1 = gmt.get<TrackRef>();
00350     
00351     const math::XYZPoint pos0 = tk1.innerPosition();
00352     const math::XYZVector mom0 = tk1.innerMomentum();
00353     
00354     double pp = sqrt(mom0.x()*mom0.x()+mom0.y()*mom0.y()+mom0.z()*mom0.z());
00355     double pt = sqrt(mom0.x()*mom0.x()+mom0.y()*mom0.y());
00356     double theta = mom0.theta();
00357     double pz = mom0.z();
00358     
00359     GlobalVector mom(mom0.x(),mom0.y(),mom0.z());
00360     
00361     if( pt < 4.) 
00362     {
00363       pt = 4.; if (abs(pz) > 0. )  pz = pt/tan(theta);
00364       double corr = sqrt( pt*pt + pz*pz )/pp;
00365       GlobalVector mom1( corr*mom0.x(), corr*mom0.y(), corr*mom0.z() );
00366       mom = mom1;
00367     }
00368 
00369     //cout<<" StandAlone::Innermost state "<<pos0<<" new momentum "<<mom<<" old momentum "<<mom0<<endl;
00370     
00371     AlgebraicSymMatrix55 m;
00372     /*
00373     double error;
00374     if( abs(mom.eta()) < 1. )
00375     {
00376      error = 0.6*mom.perp();
00377     }
00378      else
00379     {
00380      error = 0.6*abs(mom.z());
00381     }
00382     */
00383     m(0,0)=0.6*mom.perp(); m(1,1)=1.; m(2,2)=1.;
00384     m(3,3)=1.;m(4,4)=0.; 
00385     CurvilinearTrajectoryError cte(m);
00386     GlobalPoint pos(pos0.x(),pos0.y(),pos0.z());
00387     
00388     GlobalTrajectoryParameters gtp(pos,mom,tk1.charge(), field);
00389     FreeTrajectoryState fts(gtp,cte);
00390   
00391   return fts;
00392   }
00393 
00394 }