00001 #include "RecoHIMuon/HiMuSeed/interface/DiMuonSeedGeneratorHIC.h"
00002 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
00003 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
00004 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00005 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00006 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00007 #include "TrackingTools/MeasurementDet/interface/MeasurementDet.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009
00010
00011 using namespace edm;
00012 using namespace std;
00013
00014
00015 namespace cms {
00016 DiMuonSeedGeneratorHIC::DiMuonSeedGeneratorHIC(edm::InputTag rphirecHitsTag0,
00017 const MagneticField* magfield0,
00018 const GeometricSearchTracker* theTracker0,
00019 const HICConst* hh,
00020 const string bb,
00021 int aMult = 1):
00022 TTRHbuilder(0),
00023 builderName(bb),
00024 rphirecHitsTag(rphirecHitsTag0),
00025 magfield(magfield0),
00026 theTracker(theTracker0),
00027 theHICConst(hh),
00028 theLowMult(aMult)
00029
00030 {
00031
00032
00033
00034 thePropagator=new PropagatorWithMaterial(oppositeToMomentum,0.1057,&(*magfield) );
00035
00036
00037 }
00038
00039 map<DetLayer*,DiMuonSeedGeneratorHIC::SeedContainer> DiMuonSeedGeneratorHIC::produce(const edm::Event& e, const edm::EventSetup& iSetup,
00040 FreeTrajectoryState& theFtsTracker,
00041 TrajectoryStateOnSurface& newtsos,
00042 FreeTrajectoryState& theFtsMuon,
00043 const TransientTrackingRecHitBuilder* RecHitBuilder,
00044 const MeasurementTracker* measurementTracker,
00045 vector<DetLayer*>* theDetLayer ) {
00046
00047
00048 theMeasurementTracker = measurementTracker;
00049 theLayerMeasurements = new LayerMeasurements(theMeasurementTracker);
00050
00051
00052
00053 std::map<DetLayer*,DiMuonSeedGeneratorHIC::SeedContainer> seedMap;
00054 SeedContainer seedContainer;
00055
00056 bl = theTracker->barrelLayers();
00057 fpos = theTracker->posForwardLayers();
00058 fneg = theTracker->negForwardLayers();
00059
00060 if(TTRHbuilder == 0){
00061 edm::ESHandle<TransientTrackingRecHitBuilder> theBuilderHandle;
00062
00063 iSetup.get<TransientRecHitRecord>().get(builderName,theBuilderHandle);
00064 TTRHbuilder = theBuilderHandle.product();
00065 }
00066
00067 int npair=0;
00068
00069
00070
00071 int nSig =3;
00072 bool itrust=true;
00073 HICSeedMeasurementEstimator theEstimator(itrust,nSig);
00074
00075
00076
00077 double phipred, zpred, phiupd, zupd;
00078
00079 for( vector<DetLayer* >::const_iterator ml=theDetLayer->begin(); ml != theDetLayer->end(); ml++)
00080 {
00081
00082 const BarrelDetLayer* bl = dynamic_cast<const BarrelDetLayer*>(*ml);
00083 const ForwardDetLayer* fl = dynamic_cast<const ForwardDetLayer*>(*ml);
00084 if( bl != 0 )
00085 {
00086
00087 phipred = (double)theHICConst->phicut[12];
00088 phiupd = (double)theHICConst->phiro[12];
00089 zpred = (double)theHICConst->zcut[12];
00090 zupd = (double)theHICConst->tetro[12];
00091
00092 }
00093 else
00094 {
00095 if ( fl != 0 )
00096 {
00097
00098
00099 phipred = (double)theHICConst->phicutf[13];
00100 phiupd = (double)theHICConst->phirof[13];
00101 zpred = (double)theHICConst->tetcutf[13];
00102 zupd = (double)theHICConst->tetrof[13];
00103
00104
00105
00106 }
00107 }
00108
00109 theEstimator.set(phipred, zpred);
00110 #ifdef DEBUG
00111 std::cout<<" DiMuonSeedGenerator::estimator::set cuts "<<std::endl;
00112 #endif
00113 std::vector<TrajectoryMeasurement> vTM = theLayerMeasurements->measurements((**ml),newtsos, *thePropagator, theEstimator);
00114 #ifdef DEBUG
00115 std::cout<<" DiMuonSeedGenerator::Size of compatible TM found by measurements "<<vTM.size()<<std::endl;
00116 #endif
00117
00118 int measnum = 0;
00119
00120 for(std::vector<TrajectoryMeasurement>::iterator it=vTM.begin(); it!=vTM.end(); it++)
00121 {
00122 pair<TrajectoryMeasurement,bool> newtmr;
00123
00124 if( bl != 0 )
00125 {
00126 #ifdef DEBUG
00127 cout<<" DiMuonSeedGenerator::Barrel seed "<<endl;
00128 #endif
00129 newtmr = barrelUpdateSeed(theFtsMuon,(*it));
00130
00131 }
00132 else
00133 {
00134 #ifdef DEBUG
00135 cout<<" DiMuonSeedGenerator::Endcap seed "<<endl;
00136 #endif
00137 newtmr = forwardUpdateSeed(theFtsMuon,(*it));
00138 }
00139 #ifdef DEBUG
00140 cout<<" DiMuonSeedGenerator::Estimate seed "<<newtmr.first.estimate()<<" True or false "<<newtmr.second<<endl;
00141 #endif
00142 if(newtmr.second) seedContainer.push_back(DiMuonTrajectorySeed(newtmr.first,theFtsMuon,theLowMult));
00143 }
00144 seedMap[*ml] = seedContainer;
00145 }
00146 delete theLayerMeasurements;
00147 return seedMap;
00148
00149 }
00150
00151 pair<TrajectoryMeasurement,bool> DiMuonSeedGeneratorHIC::barrelUpdateSeed (
00152 const FreeTrajectoryState& FTSOLD,
00153 const TrajectoryMeasurement& tm
00154 ) const
00155 {
00156
00157 bool good=false;
00158 #ifdef DEBUG
00159 std::cout<<" DiMuonSeedGeneratorHIC::barrelUpdateSeed::BarrelSeed "<<std::endl;
00160 #endif
00161 const DetLayer* dl = tm.layer();
00162
00163 const TransientTrackingRecHit::ConstRecHitPointer rh = tm.recHit();
00164
00165 if(!(rh->isValid()))
00166 {
00167 #ifdef DEBUG
00168 std::cout<<" DiMuonSeedGeneratorHIC::barrelUpdateSeed::hit is not valid "<<std::endl;
00169 #endif
00170 return pair<TrajectoryMeasurement,bool>(tm,good);
00171 }
00172 #ifdef DEBUG
00173 std::cout<<" DiMuonSeedGeneratorHIC::barrelUpdateSeed::hit is valid "<<std::endl;
00174 #endif
00175
00176 FreeTrajectoryState FTS = *(tm.forwardPredictedState().freeTrajectoryState());
00177
00178
00179
00180
00181 int imin = 0;
00182 int imax = 0;
00183 int imin1 = 0;
00184 int imax1 = 0;
00185 double phi = FTSOLD.parameters().position().phi();
00186 double pt = FTS.parameters().momentum().perp();
00187 double aCharge = FTS.parameters().charge();
00188 AlgebraicSymMatrix55 e = FTS.curvilinearError().matrix();
00189
00190 double dpt = 0.35*pt;
00191
00192
00193
00194
00195
00196 int imax0 = (int)((pt+dpt-theHICConst->ptboun)/theHICConst->step) + 1;
00197 int imin0 = (int)((pt-dpt-theHICConst->ptboun)/theHICConst->step) + 1;
00198 if( imin0 < 1 ) imin0 = 1;
00199 #ifdef DEBUG
00200 std::cout<<" DiMuonSeedGeneratorHIC::barrelUpdateSeed::imin0,imax0 "<<imin0<<" "<<imax0<<" pt,dpt "<<pt<<" "<<dpt<<std::endl;
00201 #endif
00202
00203 double dens,df,ptmax,ptmin;
00204
00205 GlobalPoint realhit = (*rh).globalPosition();
00206 df = fabs(realhit.phi() - phi);
00207
00208 if(df > pi) df = twopi-df;
00209 if(df > 1.e-5)
00210 {
00211 dens = 1./df;
00212 }
00213 else
00214 {
00215 dens = 100000.;
00216 }
00217
00218
00219
00220
00221
00222
00223 ptmax = (dens-(double)(theHICConst->phias[26]))/(double)(theHICConst->phibs[26]) + theHICConst->ptbmax;
00224 ptmin = (dens-(double)(theHICConst->phiai[26]))/(double)(theHICConst->phibi[26]) + theHICConst->ptbmax;
00225 #ifdef DEBUG
00226 std::cout<<" Phias,phibs,phiai,phibi "<<theHICConst->phias[26]<<" "<<theHICConst->phibs[26]<<" "<<
00227 theHICConst->phiai[26]<<" "<<theHICConst->phibi[26]<<" "<<theHICConst->ptbmax<<std::endl;
00228 std::cout<<" ptmin= "<<ptmin<<" ptmax "<<ptmax<<std::endl;
00229 std::cout<<" ptboun "<<theHICConst->ptboun<<" "<<theHICConst->step<<std::endl;
00230 #endif
00231 imax = (int)((ptmax-theHICConst->ptboun)/theHICConst->step)+1;
00232 imin = (int)((ptmin-theHICConst->ptboun)/theHICConst->step)+1;
00233 if(imin > imax) {
00234 #ifdef DEBUG
00235 std::cout<<" imin>imax "<<imin<<" "<<imax<<std::endl;
00236 #endif
00237 return pair<TrajectoryMeasurement,bool>(tm,good);}
00238 if(imax < 1) {
00239 #ifdef DEBUG
00240 std::cout<<"imax < 1 "<<imax<<std::endl;
00241 #endif
00242 return pair<TrajectoryMeasurement,bool>(tm,good);}
00243
00244 imin1 = max(imin,imin0);
00245 imax1 = min(imax,imax0);
00246 if(imin1 > imax1) {
00247 #ifdef DEBUG
00248 std::cout<<" imin,imax "<<imin<<" "<<imax<<std::endl;
00249 std::cout<<" imin,imax "<<imin0<<" "<<imax0<<std::endl;
00250 std::cout<<" imin1>imax1 "<<imin1<<" "<<imax1<<std::endl;
00251 #endif
00252 return pair<TrajectoryMeasurement,bool>(tm,good);
00253 }
00254
00255
00256
00257
00258 double ptnew = theHICConst->ptboun + theHICConst->step * (imax1 + imin1)/2. - theHICConst->step/2.;
00259
00260
00261
00262
00263
00264 double dfmax = 1./((double)(theHICConst->phias[26])+(double)(theHICConst->phibs[26])*(ptnew-theHICConst->ptbmax));
00265 double dfmin = 1./((double)(theHICConst->phiai[26])+(double)(theHICConst->phibi[26])*(ptnew-theHICConst->ptbmax));
00266 double dfcalc = fabs(dfmax+dfmin)/2.;
00267 double phinew = phi+aCharge*dfcalc;
00268
00269
00270
00271
00272
00273 double rad = 100.*ptnew/(0.3*4.);
00274 double alf = 2.*asin(realhit.perp()/rad);
00275 double alfnew = phinew - aCharge*alf;
00276
00277
00278
00279
00280
00281 double delx = realhit.z()-theHICConst->zvert;
00282 double delr = sqrt( realhit.y()*realhit.y()+realhit.x()*realhit.x() );
00283 double theta = atan2(delr,delx);
00284
00285
00286
00287
00288
00289
00290 GlobalPoint xnew0( realhit.x(), realhit.y(), realhit.z() );
00291
00292 GlobalVector pnew0(ptnew*cos(alfnew),ptnew*sin(alfnew),ptnew/tan(theta));
00293
00294 AlgebraicSymMatrix m(5,0);
00295 m(1,1) = 0.5*ptnew; m(2,2) = theHICConst->phiro[12];
00296 m(3,3) = theHICConst->tetro[12];
00297 m(4,4) = theHICConst->phiro[12];
00298 m(5,5) = theHICConst->tetro[12];
00299
00300 TrajectoryStateOnSurface updatedTsosOnDet=TrajectoryStateOnSurface
00301 ( GlobalTrajectoryParameters( xnew0, pnew0, (int)aCharge, &(*magfield) ),
00302 CurvilinearTrajectoryError(m), dl->surface() );
00303
00304 float estimate = 1.;
00305 TrajectoryMeasurement newtm(tm.forwardPredictedState(), updatedTsosOnDet, rh, estimate, dl );
00306 good=true;
00307 pair<TrajectoryMeasurement,bool> newtmr(newtm,good);
00308
00309 return newtmr;
00310 }
00311
00312 pair<TrajectoryMeasurement,bool> DiMuonSeedGeneratorHIC::forwardUpdateSeed (
00313 const FreeTrajectoryState& FTSOLD,
00314 const TrajectoryMeasurement& tm
00315 ) const
00316 {
00317 bool good=false;
00318 #ifdef DEBUG
00319 std::cout<<" DiMuonSeedGeneratorHIC::forwardUpdateSeed::EndcapSeed::start "<<std::endl;
00320 #endif
00321 const DetLayer* dl = tm.layer();
00322
00323 const TransientTrackingRecHit::ConstRecHitPointer rh = tm.recHit();
00324
00325 if(!(rh->isValid()))
00326 {
00327 #ifdef DEBUG
00328 std::cout<<" DiMuonSeedGeneratorHIC::forwardUpdateSeed::EndcapSeed::EndcapSeed::hit is not valid "<<std::endl;
00329 #endif
00330
00331 return pair<TrajectoryMeasurement,bool>(tm,good);
00332 }
00333
00334 #ifdef DEBUG
00335 std::cout<<" DiMuonSeedGeneratorHIC::forwardUpdateSeed::EndcapSeed::EndcapSeed::valid "<<std::endl;
00336 #endif
00337
00338 FreeTrajectoryState FTS = *(tm.forwardPredictedState().freeTrajectoryState());
00339
00340
00341
00342
00343
00344 double phi = FTSOLD.parameters().position().phi();
00345 double aCharge = FTS.parameters().charge();
00346 AlgebraicSymMatrix55 e = FTS.curvilinearError().matrix();
00347 double pt = FTS.parameters().momentum().perp();
00348 double pz = FTS.parameters().momentum().z();
00349 double dpt = 0.6*pt;
00350
00351
00352
00353 GlobalPoint realhit = rh->globalPosition();
00354
00355
00356
00357 double df = fabs(realhit.phi() - phi);
00358
00359 if(df > pi) df = twopi-df;
00360
00361 #ifdef DEBUG
00362 cout<<" DiMuonSeedGeneratorHIC::forwardUpdateSeed::phipred::phihit::df "<<phi<<" "<<realhit.phi()<<" "<<df<<endl;
00363 #endif
00364
00365
00366
00367
00368
00369 double delx = realhit.z() - theHICConst->zvert;
00370 double delr = sqrt(realhit.y()*realhit.y()+realhit.x()*realhit.x());
00371 double theta = atan2( delr, delx );
00372 double ptmin = 0.;
00373 double ptmax = 0.;
00374 double ptnew = 0.;
00375 double pznew = 0.;
00376
00377
00378
00379 if( fabs(FTSOLD.parameters().momentum().eta()) > 1.9 )
00380 {
00381 #ifdef DEBUG
00382 cout<<" First parametrization "<<df<<endl;
00383 #endif
00384 pznew = fabs(( df - 0.0191878 )/(-0.0015952))/3.;
00385
00386 if( df > 0.1 ) pznew = 5.;
00387 if( fabs(pznew)<3.) pznew = 3.;
00388
00389 if( FTSOLD.parameters().position().z() < 0. ) pznew = (-1)*pznew;
00390 ptnew = pznew * tan( theta );
00391 }
00392 if( fabs(FTSOLD.parameters().momentum().eta()) > 1.7 && fabs(FTSOLD.parameters().momentum().eta()) < 1.9 )
00393 {
00394 #ifdef DEBUG
00395 cout<<" Second parametrization "<<df<<endl;
00396 #endif
00397 pznew = fabs(( df - 0.38 )/(-0.009))/3.;
00398 if( fabs(pznew)<2.) pznew = 2.;
00399
00400 if( FTSOLD.parameters().position().z() < 0. ) pznew = (-1)*pznew;
00401 ptnew = pznew * tan( theta );
00402 }
00403 if( fabs(FTSOLD.parameters().momentum().eta()) > 1.6 && fabs(FTSOLD.parameters().momentum().eta()) < 1.7 )
00404 {
00405 #ifdef DEBUG
00406 cout<<" Third parametrization "<<df<<endl;
00407 #endif
00408 pznew = fabs(( df - 0.9 )/(-0.02))/3.;
00409 if( fabs(pznew)<1.) pznew = 1.;
00410 if( FTSOLD.parameters().position().z() < 0. ) pznew = (-1)*pznew;
00411 ptnew = pznew * tan( theta );
00412 }
00413 if( fabs(FTSOLD.parameters().momentum().eta()) > 0.7 && fabs(FTSOLD.parameters().momentum().eta()) < 1.6 )
00414 {
00415 #ifdef DEBUG
00416 cout<<" Forth parametrization "<<df<<endl;
00417 #endif
00418 double dfinv = 0.;
00419 if( df < 0.0000001 ) {
00420 dfinv = 1000000.;
00421 }
00422 else
00423 {
00424 dfinv = 1/df;
00425 }
00426 ptmin = (dfinv - 4.)/0.7 + 3.;
00427 if( ptmin < 2. ) ptmin = 2.;
00428 ptmax = (dfinv - 0.5)/0.3 + 3.;
00429 ptnew = ( ptmin + ptmax )/2.;
00430 pznew = ptnew/tan( theta );
00431
00432
00433 #ifdef DEBUG
00434 std::cout<<" Paramters of algorithm "<<df<<" "<<theHICConst->forwparam[1]<<" "<<theHICConst->forwparam[0]<<std::endl;
00435 std::cout<<" dfinv "<<dfinv<<" ptmax "<<ptmax<<" ptmin "<<ptmin<<std::endl;
00436 std::cout<<" check "<<pt<<" "<<ptnew<<" "<<dpt<<" pz "<<pznew<<" "<<pz<<std::endl;
00437 #endif
00438 }
00439
00440
00441
00442 if( (pt - ptnew)/pt < -2 || (pt - ptnew)/pt > 1 )
00443 {
00444 #ifdef DEBUG
00445 cout<<" Return fake 0 pt::ptnew "<<pt<<" "<<ptnew<<endl;
00446 #endif
00447 return pair<TrajectoryMeasurement,bool>(tm,good);
00448 }
00449
00450
00451
00452
00453 double alf = theHICConst->atra * ( realhit.z() - theHICConst->zvert )/fabs(pznew);
00454 double alfnew = realhit.phi() + aCharge*alf;
00455 GlobalPoint xnew0(realhit.x(), realhit.y(), realhit.z());
00456 GlobalVector pnew0( ptnew*cos(alfnew), ptnew*sin(alfnew), pznew );
00457 #ifdef DEBUG
00458 cout<<" Start recalculation 1 FTSOLD eta, r hit, pt "<<FTSOLD.parameters().momentum().eta()<<" "<<realhit.perp()<<
00459 " "<<FTSOLD.parameters().momentum().perp()<<endl;
00460 #endif
00461 if( fabs(FTSOLD.parameters().momentum().eta()) < 1.7 && fabs(FTSOLD.parameters().momentum().eta()) > 0.8 )
00462 {
00463 if( realhit.perp() < 80. ) {
00464
00465 #ifdef DEBUG
00466 cout<<" Return fake 1 "<<realhit.perp()<<endl;
00467 #endif
00468 return pair<TrajectoryMeasurement,bool>(tm,good);
00469 }
00470 }
00471
00472
00473 if( FTSOLD.parameters().momentum().perp() > 2.0){
00474 if( fabs(FTSOLD.parameters().momentum().eta()) < 2.0 && fabs(FTSOLD.parameters().momentum().eta()) >= 1.7 )
00475 {
00476 if( realhit.perp() > 100. || realhit.perp() < 60. ) {
00477 #ifdef DEBUG
00478 cout<<" Return fake 2 "<<endl;
00479 #endif
00480 return pair<TrajectoryMeasurement,bool>(tm,good);
00481 }
00482 }
00483 if( fabs(FTSOLD.parameters().momentum().eta()) < 2.4 && fabs(FTSOLD.parameters().momentum().eta()) >= 2.0 )
00484 {
00485 if( realhit.perp() > 75. || realhit.perp() < 40. ) {
00486
00487 #ifdef DEBUG
00488 cout<<" Return fake 3 "<<endl;
00489 #endif
00490 return pair<TrajectoryMeasurement,bool>(tm,good);
00491 }
00492 }
00493
00494 }
00495 else
00496 {
00497 if( fabs(FTSOLD.parameters().momentum().eta()) < 2.0 && fabs(FTSOLD.parameters().momentum().eta()) >= 1.7 )
00498 {
00499 if( realhit.perp() > 84. || realhit.perp() < 40. ) {
00500 #ifdef DEBUG
00501 cout<<" Return fake 4 "<<endl;
00502 #endif
00503 return pair<TrajectoryMeasurement,bool>(tm,good);
00504 }
00505 }
00506 if( fabs(FTSOLD.parameters().momentum().eta()) < 2.4 && fabs(FTSOLD.parameters().momentum().eta()) >= 2.0 )
00507 {
00508 if( realhit.perp() > 84. || realhit.perp() < 40. ) {
00509 #ifdef DEBUG
00510 cout<<" Return fake 5 "<<endl;
00511 #endif
00512 return pair<TrajectoryMeasurement,bool>(tm,good);
00513 }
00514 }
00515 }
00516 #ifdef DEBUG
00517 cout<<" Create new TM "<<endl;
00518 #endif
00519 AlgebraicSymMatrix m(5,0);
00520 m(1,1) = fabs(0.5*pznew); m(2,2) = theHICConst->phiro[13];
00521 m(3,3) = theHICConst->tetro[13];
00522 m(4,4) = theHICConst->phiro[13];
00523 m(5,5) = theHICConst->tetro[13];
00524
00525 TrajectoryStateOnSurface updatedTsosOnDet=TrajectoryStateOnSurface
00526 (GlobalTrajectoryParameters( xnew0, pnew0, (int)aCharge, &(*magfield) ),
00527 CurvilinearTrajectoryError(m), dl->surface() );
00528
00529 float estimate=1.;
00530 TrajectoryMeasurement newtm(tm.forwardPredictedState(), updatedTsosOnDet, rh,estimate, dl);
00531 good=true;
00532 pair<TrajectoryMeasurement,bool> newtmr(newtm,good);
00533 #ifdef DEBUG
00534 std::cout<<" Endcap newtm estimate= "<<newtmr.first.estimate()<<" "<<newtmr.second<<" pt "<<pnew0.perp()<<" pz "<<pnew0.z()<<std::endl;
00535 #endif
00536 return newtmr;
00537 }
00538 }