00001
00002
00003
00004 #include "RecoHI/HiMuonAlgos/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
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
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
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 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
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
00134 float etaL1 = (*tl1).parameters().momentum().eta();
00135 float phiL1 = (*tl1).parameters().momentum().phi();
00136 if( phiL1 < 0.) phiL1 = twopi + phiL1;
00137
00138 int L2 = 0;
00139
00140 for(vector<FreeTrajectoryState>::iterator tl2 = ftsL2.begin(); tl2 != ftsL2.end(); tl2++)
00141 {
00142 itused = find(used.begin(),used.end(),&(*tl2));
00143
00144 float etaL2 = (*tl2).parameters().momentum().eta();
00145 float phiL2 = (*tl2).parameters().momentum().phi();
00146 if( phiL2 < 0.) phiL2 = twopi + phiL2;
00147
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
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 {
00178
00179
00180 L2 = 1;
00181 ftsL1orL2.push_back((*tl2));
00182 used.push_back(&(*tl2));
00183
00184 break;
00185
00186
00187
00188
00189
00190
00191
00192
00193 }
00194 }
00195 if( L2 == 0 )
00196 {
00197
00198 ftsL1orL2.push_back((*tl1));
00199 }
00200 }
00201
00202
00203
00204 if( ftsL2.size() > 0 )
00205 {
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
00212 continue;
00213 }
00214 ftsL1orL2.push_back((*tl2));
00215 }
00216 }
00217
00218 return ftsL1orL2;
00219 }
00220
00221
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
00237
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
00250
00251 if(barrel){
00252
00253
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
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
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
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
00320
00321 AlgebraicSymMatrix55 m;
00322
00323
00324
00325
00326
00327
00328
00329
00330
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
00345
00346 FreeTrajectoryState HICFTSfromL1orL2::FTSfromStandAlone(const Track& tk1)
00347 {
00348
00349
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
00370
00371 AlgebraicSymMatrix55 m;
00372
00373
00374
00375
00376
00377
00378
00379
00380
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 }