00001
00002
00003
00004 #include "RecoHIMuon/HiMuSeed/interface/HICFTSfromL1orL2.h"
00005 #include "DataFormats/Common/interface/RefToBase.h"
00006 using namespace reco;
00007 using namespace std;
00008
00009
00010
00011 namespace cms {
00012 vector<FreeTrajectoryState> HICFTSfromL1orL2::createFTSfromL1(vector<L1MuGMTExtendedCand>& gmt)
00013 {
00014
00015
00016
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 }
00036
00037
00038
00039 vector<FreeTrajectoryState> HICFTSfromL1orL2::createFTSfromL2(const RecoChargedCandidateCollection& recmuons)
00040 {
00041
00042
00043
00044
00045
00046 vector<FreeTrajectoryState> ftsL2;
00047
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 }
00060 return ftsL2;
00061 }
00062
00063
00064 vector<FreeTrajectoryState> HICFTSfromL1orL2::createFTSfromStandAlone(const TrackCollection& recmuons)
00065 {
00066
00067
00068
00069
00070
00071 vector<FreeTrajectoryState> ftsL2;
00072
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 }
00085 return ftsL2;
00086 }
00087
00088 vector<FreeTrajectoryState> HICFTSfromL1orL2::createFTSfromL2(const TrackCollection& recmuons)
00089 {
00090
00091
00092
00093
00094
00095 vector<FreeTrajectoryState> ftsL2;
00096
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 }
00109 return ftsL2;
00110 }
00111
00112
00113
00114
00115
00116
00117 vector<FreeTrajectoryState> HICFTSfromL1orL2::createFTSfromL1orL2(vector<L1MuGMTExtendedCand>& gmt, const RecoChargedCandidateCollection& recmuons)
00118 {
00119 vector<FreeTrajectoryState> ftsL1orL2;
00120 vector<FreeTrajectoryState> ftsL1 = createFTSfromL1(gmt);
00121 vector<FreeTrajectoryState> ftsL2 = createFTSfromL2(recmuons);
00122
00123
00124
00125 vector<FreeTrajectoryState*>::iterator itused;
00126 vector<FreeTrajectoryState*> used;
00127
00128 for(vector<FreeTrajectoryState>::iterator tl1 = ftsL1.begin(); tl1 != ftsL1.end(); tl1++)
00129 {
00130 float ptL1 = (*tl1).parameters().momentum().perp();
00131 float etaL1 = (*tl1).parameters().momentum().eta();
00132 float phiL1 = (*tl1).parameters().momentum().phi();
00133 if( phiL1 < 0.) phiL1 = twopi + phiL1;
00134 int chargeL1 = (*tl1).charge();
00135 int L2 = 0;
00136
00137 for(vector<FreeTrajectoryState>::iterator tl2 = ftsL2.begin(); tl2 != ftsL2.end(); tl2++)
00138 {
00139 itused = find(used.begin(),used.end(),&(*tl2));
00140 float ptL2 = (*tl2).parameters().momentum().perp();
00141 float etaL2 = (*tl2).parameters().momentum().eta();
00142 float phiL2 = (*tl2).parameters().momentum().phi();
00143 if( phiL2 < 0.) phiL2 = twopi + phiL2;
00144 int chargeL2 = (*tl2).charge();
00145 float dphi = abs(phiL1-phiL2);
00146 if( dphi > pi ) dphi = twopi - dphi;
00147 float dr = sqrt((etaL1 - etaL2)*(etaL1 - etaL2)+dphi*dphi);
00148
00149 #ifdef OK_DEBUG
00150 cout<<" ===== Trigger Level 1 candidate: ptL1 "<<ptL1<<" EtaL1 "<<etaL1<<" PhiL1 "<<phiL1<<
00151 " chargeL1 "<<chargeL1<<endl;
00152 cout<<" ===== Trigger Level 2 candidate: ptL2 "<<ptL2<<" EtaL2 "<<etaL2<<" PhiL2 "<<phiL2<<
00153 " chargeL2 "<<chargeL2<<endl;
00154 cout<<" abs(EtaL1 - EtaL2) "<<abs(etaL1 - etaL2)<<" dphi "<<dphi<<" dr "<<dr<<
00155 " dQ "<<chargeL1 - chargeL2
00156 <<" the same muon or not L2 "<<L2<<endl;
00157 #endif
00158
00159 if ( itused != used.end() ) {
00160
00161 continue;
00162 }
00163
00164
00165
00166 float drmax = 0.5;
00167 if( abs(etaL1) > 1.9 ) drmax = 0.6;
00168
00169 #ifdef OK_DEBUG
00170 cout<<" Drmax= "<<drmax<<endl;
00171 #endif
00172 L2 = 0;
00173 if( dr < drmax )
00174 {
00175
00176
00177 L2 = 1;
00178 ftsL1orL2.push_back((*tl2));
00179 used.push_back(&(*tl2));
00180
00181 break;
00182
00183
00184
00185
00186
00187
00188
00189
00190 }
00191 }
00192 if( L2 == 0 )
00193 {
00194
00195 ftsL1orL2.push_back((*tl1));
00196 }
00197 }
00198
00199
00200
00201 if( ftsL2.size() > 0 )
00202 {
00203 for(vector<FreeTrajectoryState>::iterator tl2 = ftsL2.begin(); tl2 != ftsL2.end(); tl2++)
00204 {
00205 itused = find(used.begin(),used.end(),&(*tl2));
00206 if ( itused != used.end() )
00207 {
00208
00209 continue;
00210 }
00211 ftsL1orL2.push_back((*tl2));
00212 }
00213 }
00214
00215 return ftsL1orL2;
00216 }
00217
00218
00219
00220 FreeTrajectoryState HICFTSfromL1orL2::FTSfromL1(const L1MuGMTExtendedCand& gmt){
00221 unsigned int det = gmt.isFwd();
00222 double px,py,pz,x,y,z;
00223 float pt = gmt.ptValue();
00224 float eta = gmt.etaValue();
00225 float theta = 2*atan(exp(-eta));
00226 float phi = gmt.phiValue();
00227 int charge = gmt.charge();
00228
00229 bool barrel = true;
00230 if(det) barrel = false;
00231
00232
00233
00234
00235 float radius = 513.;
00236 if ( !barrel ) {
00237 radius = 800.;
00238 if(eta<0.) radius=-1.*radius;
00239 }
00240
00241 if ( barrel && pt < 3.5 ) pt = 3.5;
00242 if ( !barrel && pt < 1.0 ) pt = 1.0;
00243
00244
00245
00246
00247 if(barrel){
00248
00249
00250
00251 if(abs(theta-pi/2.)<0.00001){
00252 pz=0.;
00253 z=0.;
00254 }else{
00255 pz=pt/tan(theta);
00256 z=radius/tan(theta);
00257 }
00258 x=radius*cos(phi);
00259 y=radius*sin(phi);
00260
00261 } else {
00262
00263
00264
00265 pz=pt/tan(theta);
00266 z=radius;
00267 x=z*tan(theta)*cos(phi);
00268 y=z*tan(theta)*sin(phi);
00269 }
00270
00271 px=pt*cos(phi);
00272 py=pt*sin(phi);
00273
00274
00275
00276 GlobalPoint aX(x,y,z);
00277 GlobalVector aP(px,py,pz);
00278 GlobalTrajectoryParameters gtp(aX,aP,charge,field);
00279
00280 AlgebraicSymMatrix m(5,0);
00281 m(1,1)=0.6*pt; m(2,2)=1.; m(3,3)=1.;
00282 m(4,4)=1.;m(5,5)=0.;
00283 CurvilinearTrajectoryError cte(m);
00284
00285 FreeTrajectoryState fts(gtp,cte);
00286 return fts;
00287 }
00288
00289
00290
00291
00292 FreeTrajectoryState HICFTSfromL1orL2::FTSfromL2(const RecoChargedCandidate& gmt)
00293 {
00294
00295 TrackRef tk1 = gmt.get<TrackRef>();
00296
00297 const math::XYZPoint pos0 = tk1->innerPosition();
00298 const math::XYZVector mom0 = tk1->innerMomentum();
00299
00300 double pp = sqrt(mom0.x()*mom0.x()+mom0.y()*mom0.y()+mom0.z()*mom0.z());
00301 double pt = sqrt(mom0.x()*mom0.x()+mom0.y()*mom0.y());
00302 double theta = mom0.theta();
00303 double pz = mom0.z();
00304
00305 GlobalVector mom(mom0.x(),mom0.y(),mom0.z());
00306
00307 if( pt < 4.)
00308 {
00309 pt = 4.; if (abs(pz) > 0. ) pz = pt/tan(theta);
00310 double corr = sqrt( pt*pt + pz*pz )/pp;
00311 GlobalVector mom1( corr*mom0.x(), corr*mom0.y(), corr*mom0.z() );
00312 mom = mom1;
00313 }
00314
00315
00316
00317 AlgebraicSymMatrix m(5,0);
00318 double error;
00319 if( abs(mom.eta()) < 1. )
00320 {
00321 error = 0.6*mom.perp();
00322 }
00323 else
00324 {
00325 error = 0.6*abs(mom.z());
00326 }
00327 m(1,1)=0.6*mom.perp(); m(2,2)=1.; m(3,3)=1.;
00328 m(4,4)=1.;m(5,5)=0.;
00329 CurvilinearTrajectoryError cte(m);
00330 GlobalPoint pos(pos0.x(),pos0.y(),pos0.z());
00331
00332 GlobalTrajectoryParameters gtp(pos,mom,tk1->charge(), field);
00333 FreeTrajectoryState fts(gtp,cte);
00334
00335 return fts;
00336 }
00337
00338
00339
00340 FreeTrajectoryState HICFTSfromL1orL2::FTSfromStandAlone(const Track& tk1)
00341 {
00342
00343
00344
00345 const math::XYZPoint pos0 = tk1.innerPosition();
00346 const math::XYZVector mom0 = tk1.innerMomentum();
00347
00348 double pp = sqrt(mom0.x()*mom0.x()+mom0.y()*mom0.y()+mom0.z()*mom0.z());
00349 double pt = sqrt(mom0.x()*mom0.x()+mom0.y()*mom0.y());
00350 double theta = mom0.theta();
00351 double pz = mom0.z();
00352
00353 GlobalVector mom(mom0.x(),mom0.y(),mom0.z());
00354
00355 if( pt < 4.)
00356 {
00357 pt = 4.; if (abs(pz) > 0. ) pz = pt/tan(theta);
00358 double corr = sqrt( pt*pt + pz*pz )/pp;
00359 GlobalVector mom1( corr*mom0.x(), corr*mom0.y(), corr*mom0.z() );
00360 mom = mom1;
00361 }
00362
00363
00364
00365 AlgebraicSymMatrix m(5,0);
00366 double error;
00367 if( abs(mom.eta()) < 1. )
00368 {
00369 error = 0.6*mom.perp();
00370 }
00371 else
00372 {
00373 error = 0.6*abs(mom.z());
00374 }
00375 m(1,1)=0.6*mom.perp(); m(2,2)=1.; m(3,3)=1.;
00376 m(4,4)=1.;m(5,5)=0.;
00377 CurvilinearTrajectoryError cte(m);
00378 GlobalPoint pos(pos0.x(),pos0.y(),pos0.z());
00379
00380 GlobalTrajectoryParameters gtp(pos,mom,tk1.charge(), field);
00381 FreeTrajectoryState fts(gtp,cte);
00382
00383 return fts;
00384 }
00385
00386 }