00001
00009 #include "RecoMuon/MuonSeedGenerator/src/MuonSeedCreator.h"
00010
00011 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00012
00013 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00014
00015 #include "MagneticField/Engine/interface/MagneticField.h"
00016 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00017
00018 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00019 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00020
00021 #include "DataFormats/TrajectoryState/interface/PTrajectoryStateOnDet.h"
00022 #include "DataFormats/Common/interface/OwnVector.h"
00023 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00024 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00025 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00026
00027 #include "FWCore/Framework/interface/EventSetup.h"
00028 #include "FWCore/Framework/interface/ESHandle.h"
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030
00031 #include "gsl/gsl_statistics.h"
00032
00033
00034
00035
00036
00037 MuonSeedCreator::MuonSeedCreator(const edm::ParameterSet& pset){
00038
00039 theMinMomentum = pset.getParameter<double>("minimumSeedPt");
00040 theMaxMomentum = pset.getParameter<double>("maximumSeedPt");
00041 defaultMomentum = pset.getParameter<double>("defaultSeedPt");
00042 debug = pset.getParameter<bool>("DebugMuonSeed");
00043 sysError = pset.getParameter<double>("SeedPtSystematics");
00044
00045 DT12 = pset.getParameter<std::vector<double> >("DT_12");
00046 DT13 = pset.getParameter<std::vector<double> >("DT_13");
00047 DT14 = pset.getParameter<std::vector<double> >("DT_14");
00048 DT23 = pset.getParameter<std::vector<double> >("DT_23");
00049 DT24 = pset.getParameter<std::vector<double> >("DT_24");
00050 DT34 = pset.getParameter<std::vector<double> >("DT_34");
00051
00052 CSC01 = pset.getParameter<std::vector<double> >("CSC_01");
00053 CSC12 = pset.getParameter<std::vector<double> >("CSC_12");
00054 CSC02 = pset.getParameter<std::vector<double> >("CSC_02");
00055 CSC13 = pset.getParameter<std::vector<double> >("CSC_13");
00056 CSC03 = pset.getParameter<std::vector<double> >("CSC_03");
00057 CSC14 = pset.getParameter<std::vector<double> >("CSC_14");
00058 CSC23 = pset.getParameter<std::vector<double> >("CSC_23");
00059 CSC24 = pset.getParameter<std::vector<double> >("CSC_24");
00060 CSC34 = pset.getParameter<std::vector<double> >("CSC_34");
00061
00062 OL1213 = pset.getParameter<std::vector<double> >("OL_1213");
00063 OL1222 = pset.getParameter<std::vector<double> >("OL_1222");
00064 OL1232 = pset.getParameter<std::vector<double> >("OL_1232");
00065 OL1213 = pset.getParameter<std::vector<double> >("OL_1213");
00066 OL2222 = pset.getParameter<std::vector<double> >("OL_1222");
00067
00068 SME11 = pset.getParameter<std::vector<double> >("SME_11");
00069 SME12 = pset.getParameter<std::vector<double> >("SME_12");
00070 SME13 = pset.getParameter<std::vector<double> >("SME_13");
00071 SME21 = pset.getParameter<std::vector<double> >("SME_21");
00072 SME22 = pset.getParameter<std::vector<double> >("SME_22");
00073 SME31 = pset.getParameter<std::vector<double> >("SME_31");
00074 SME32 = pset.getParameter<std::vector<double> >("SME_32");
00075 SME41 = pset.getParameter<std::vector<double> >("SME_41");
00076
00077 SMB10 = pset.getParameter<std::vector<double> >("SMB_10");
00078 SMB11 = pset.getParameter<std::vector<double> >("SMB_11");
00079 SMB12 = pset.getParameter<std::vector<double> >("SMB_12");
00080 SMB20 = pset.getParameter<std::vector<double> >("SMB_20");
00081 SMB21 = pset.getParameter<std::vector<double> >("SMB_21");
00082 SMB22 = pset.getParameter<std::vector<double> >("SMB_22");
00083 SMB30 = pset.getParameter<std::vector<double> >("SMB_30");
00084 SMB31 = pset.getParameter<std::vector<double> >("SMB_31");
00085 SMB32 = pset.getParameter<std::vector<double> >("SMB_32");
00086
00087
00088 CSC01_1 = pset.getParameter<std::vector<double> >("CSC_01_1_scale");
00089 CSC12_1 = pset.getParameter<std::vector<double> >("CSC_12_1_scale");
00090 CSC12_2 = pset.getParameter<std::vector<double> >("CSC_12_2_scale");
00091 CSC12_3 = pset.getParameter<std::vector<double> >("CSC_12_3_scale");
00092 CSC13_2 = pset.getParameter<std::vector<double> >("CSC_13_2_scale");
00093 CSC13_3 = pset.getParameter<std::vector<double> >("CSC_13_3_scale");
00094 CSC14_3 = pset.getParameter<std::vector<double> >("CSC_14_3_scale");
00095 CSC23_1 = pset.getParameter<std::vector<double> >("CSC_23_1_scale");
00096 CSC23_2 = pset.getParameter<std::vector<double> >("CSC_23_2_scale");
00097 CSC24_1 = pset.getParameter<std::vector<double> >("CSC_24_1_scale");
00098 CSC34_1 = pset.getParameter<std::vector<double> >("CSC_34_1_scale");
00099
00100 DT12_1 = pset.getParameter<std::vector<double> >("DT_12_1_scale");
00101 DT12_2 = pset.getParameter<std::vector<double> >("DT_12_2_scale");
00102 DT13_1 = pset.getParameter<std::vector<double> >("DT_13_1_scale");
00103 DT13_2 = pset.getParameter<std::vector<double> >("DT_13_2_scale");
00104 DT14_1 = pset.getParameter<std::vector<double> >("DT_14_1_scale");
00105 DT14_2 = pset.getParameter<std::vector<double> >("DT_14_2_scale");
00106 DT23_1 = pset.getParameter<std::vector<double> >("DT_23_1_scale");
00107 DT23_2 = pset.getParameter<std::vector<double> >("DT_23_2_scale");
00108 DT24_1 = pset.getParameter<std::vector<double> >("DT_24_1_scale");
00109 DT24_2 = pset.getParameter<std::vector<double> >("DT_24_2_scale");
00110 DT34_1 = pset.getParameter<std::vector<double> >("DT_34_1_scale");
00111 DT34_2 = pset.getParameter<std::vector<double> >("DT_34_2_scale");
00112
00113 OL_1213 = pset.getParameter<std::vector<double> >("OL_1213_0_scale");
00114 OL_1222 = pset.getParameter<std::vector<double> >("OL_1222_0_scale");
00115 OL_1232 = pset.getParameter<std::vector<double> >("OL_1232_0_scale");
00116 OL_2213 = pset.getParameter<std::vector<double> >("OL_2213_0_scale");
00117 OL_2222 = pset.getParameter<std::vector<double> >("OL_2222_0_scale");
00118
00119 SMB_10S = pset.getParameter<std::vector<double> >("SMB_10_0_scale");
00120 SMB_11S = pset.getParameter<std::vector<double> >("SMB_11_0_scale");
00121 SMB_12S = pset.getParameter<std::vector<double> >("SMB_12_0_scale");
00122 SMB_20S = pset.getParameter<std::vector<double> >("SMB_20_0_scale");
00123 SMB_21S = pset.getParameter<std::vector<double> >("SMB_21_0_scale");
00124 SMB_22S = pset.getParameter<std::vector<double> >("SMB_22_0_scale");
00125 SMB_30S = pset.getParameter<std::vector<double> >("SMB_30_0_scale");
00126 SMB_31S = pset.getParameter<std::vector<double> >("SMB_31_0_scale");
00127 SMB_32S = pset.getParameter<std::vector<double> >("SMB_32_0_scale");
00128
00129 SME_11S = pset.getParameter<std::vector<double> >("SME_11_0_scale");
00130 SME_12S = pset.getParameter<std::vector<double> >("SME_12_0_scale");
00131 SME_13S = pset.getParameter<std::vector<double> >("SME_13_0_scale");
00132 SME_21S = pset.getParameter<std::vector<double> >("SME_21_0_scale");
00133 SME_22S = pset.getParameter<std::vector<double> >("SME_22_0_scale");
00134
00135 }
00136
00137
00138
00139
00140
00141 MuonSeedCreator::~MuonSeedCreator(){
00142
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 TrajectorySeed MuonSeedCreator::createSeed(int type, SegmentContainer seg, std::vector<int> layers, int NShowers, int NShowerSegments ) {
00154
00155
00156 int last = 0;
00157
00158 double ptmean = theMinMomentum;
00159 double sptmean = theMinMomentum;
00160
00161 AlgebraicVector t(4);
00162 AlgebraicSymMatrix mat(5,0) ;
00163 LocalPoint segPos;
00164
00165
00166 if (type == 1 ) estimatePtCSC(seg, layers, ptmean, sptmean);
00167 if (type == 2 ) estimatePtOverlap(seg, layers, ptmean, sptmean);
00168 if (type == 3 ) estimatePtDT(seg, layers, ptmean, sptmean);
00169 if (type == 4 ) estimatePtSingle(seg, layers, ptmean, sptmean);
00170
00171 if (type == 5 ) estimatePtCSC(seg, layers, ptmean, sptmean);
00172
00173
00174 if ( NShowers > 0 ) estimatePtShowering( NShowers, NShowerSegments, ptmean, sptmean );
00175
00176
00177
00178
00179 double charge = 1.0;
00180 if (ptmean < 0.) charge = -1.0;
00181 if ( (charge * ptmean) < theMinMomentum ) {
00182 ptmean = theMinMomentum * charge;
00183 sptmean = theMinMomentum ;
00184 }
00185 else if ( (charge * ptmean) > theMaxMomentum ) {
00186 ptmean = theMaxMomentum * charge;
00187 sptmean = theMaxMomentum * 0.25 ;
00188 }
00189
00190 LocalTrajectoryParameters param;
00191
00192 double p_err =0.0;
00193
00194 int best_seg= 0;
00195 double chi2_dof = 9999.0;
00196 unsigned int ini_seg = 0;
00197
00198 if ( type == 5 ) ini_seg = 1;
00199 for (size_t i = ini_seg ; i < seg.size(); i++) {
00200 double dof = static_cast<double>(seg[i]->degreesOfFreedom());
00201 if ( chi2_dof < ( seg[i]->chi2()/dof ) ) continue;
00202 chi2_dof = seg[i]->chi2() / dof ;
00203 best_seg = static_cast<int>(i);
00204 }
00205
00206
00207 if ( type==1 || type==5 || type== 4) {
00208
00210 last = best_seg;
00211
00212 GlobalVector mom = seg[last]->globalPosition()-GlobalPoint();
00213 segPos = seg[last]->localPosition();
00215
00216 GlobalVector polar(GlobalVector::Spherical(mom.theta(),seg[last]->globalDirection().phi(),1.));
00217
00219 polar *= fabs(ptmean)/polar.perp();
00221 LocalVector segDirFromPos = seg[last]->det()->toLocal(polar);
00222 int chargeI = static_cast<int>(charge);
00223 LocalTrajectoryParameters param1(segPos, segDirFromPos, chargeI);
00224 param = param1;
00225 p_err = (sptmean*sptmean)/(polar.mag()*polar.mag()*ptmean*ptmean) ;
00226 mat = seg[last]->parametersError().similarityT( seg[last]->projectionMatrix() );
00227 mat[0][0]= p_err;
00228 if ( type == 5 ) {
00229 mat[0][0] = mat[0][0]/fabs( tan(mom.theta()) );
00230 mat[1][1] = mat[1][1]/fabs( tan(mom.theta()) );
00231 mat[3][3] = 2.25*mat[3][3];
00232 mat[4][4] = 2.25*mat[4][4];
00233 }
00234 if ( type == 4 ) {
00235 mat[0][0] = mat[0][0]/fabs( tan(mom.theta()) );
00236 mat[1][1] = mat[1][1]/fabs( tan(mom.theta()) );
00237 mat[2][2] = 2.25*mat[2][2];
00238 mat[3][3] = 2.25*mat[3][3];
00239 mat[4][4] = 2.25*mat[4][4];
00240 }
00241 double dh = fabs( seg[last]->globalPosition().eta() ) - 1.6 ;
00242 if ( fabs(dh) < 0.1 && type == 1 ) {
00243 mat[1][1] = 4.*mat[1][1];
00244 mat[2][2] = 4.*mat[2][2];
00245 mat[3][3] = 9.*mat[3][3];
00246 mat[4][4] = 9.*mat[4][4];
00247 }
00248
00249
00250
00251
00252
00253
00254 }
00255 else {
00256
00258 last = 0;
00259 segPos = seg[last]->localPosition();
00260 GlobalVector mom = seg[last]->globalPosition()-GlobalPoint();
00262 GlobalVector polar(GlobalVector::Spherical(mom.theta(),seg[last]->globalDirection().phi(),1.));
00263
00264
00266
00267
00268
00270 polar *= fabs(ptmean)/polar.perp();
00272 LocalVector segDirFromPos = seg[last]->det()->toLocal(polar);
00273 int chargeI = static_cast<int>(charge);
00274 LocalTrajectoryParameters param1(segPos, segDirFromPos, chargeI);
00275 param = param1;
00276 p_err = (sptmean*sptmean)/(polar.mag()*polar.mag()*ptmean*ptmean) ;
00277 mat = seg[last]->parametersError().similarityT( seg[last]->projectionMatrix() );
00278
00279 mat[0][0]= p_err;
00280 }
00281
00282 if ( debug ) {
00283 GlobalPoint gp = seg[last]->globalPosition();
00284 float Geta = gp.eta();
00285
00286 std::cout << "Type " << type << " Nsegments " << layers.size() << " ";
00287 std::cout << "pt " << ptmean << " errpt " << sptmean
00288 << " eta " << Geta << " charge " << charge
00289 << std::endl;
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299 LocalTrajectoryError error(asSMatrix<5>(mat));
00300
00301
00302 TrajectoryStateOnSurface tsos(param, error, seg[last]->det()->surface(),&*BField);
00303
00304
00305 DetId id = seg[last]->geographicalId();
00306
00307
00308
00309
00310 PTrajectoryStateOnDet seedTSOS = trajectoryStateTransform::persistentState( tsos, id.rawId());
00311
00312 edm::OwnVector<TrackingRecHit> container;
00313 for (unsigned l=0; l<seg.size(); l++) {
00314 container.push_back( seg[l]->hit()->clone() );
00315
00316 }
00317
00318 TrajectorySeed theSeed(seedTSOS,container,alongMomentum);
00319 return theSeed;
00320 }
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 void MuonSeedCreator::estimatePtCSC(SegmentContainer seg, std::vector<int> layers, double& thePt, double& theSpt ) {
00333
00334 unsigned size = seg.size();
00335 if (size < 2) return;
00336
00337
00338
00339
00340
00341
00342
00343 std::vector<double> ptEstimate;
00344 std::vector<double> sptEstimate;
00345
00346 thePt = defaultMomentum;
00347 theSpt = defaultMomentum;
00348
00349 double pt = 0.;
00350 double spt = 0.;
00351 GlobalPoint segPos[2];
00352
00353 int layer0 = layers[0];
00354 segPos[0] = seg[0]->globalPosition();
00355 float eta = fabs( segPos[0].eta() );
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 unsigned idx1 = size;
00372 if (size > 1) {
00373 while ( idx1 > 1 ) {
00374 idx1--;
00375 int layer1 = layers[idx1];
00376 if (layer0 == layer1) continue;
00377 segPos[1] = seg[idx1]->globalPosition();
00378
00379 double dphi = segPos[0].phi() - segPos[1].phi();
00380
00381 double temp_dphi = dphi;
00382
00383 double sign = 1.0;
00384 if (temp_dphi < 0.) {
00385 temp_dphi = -1.0*temp_dphi;
00386 sign = -1.0;
00387 }
00388
00389
00390 if (temp_dphi < 0.0001 ) {
00391 temp_dphi = 0.0001 ;
00392 pt = theMaxMomentum ;
00393 spt = theMaxMomentum*0.25 ;
00394 ptEstimate.push_back( pt*sign );
00395 sptEstimate.push_back( spt );
00396 }
00397
00398 if ( layer0 == 0 && temp_dphi >= 0.0001 ) {
00399
00400
00401 if ( layer1 == 1 ) {
00402
00403 pt = getPt( CSC01, eta , temp_dphi )[0];
00404 spt = getPt( CSC01, eta , temp_dphi )[1];
00405 }
00406
00407 else if ( layer1 == 2 ) {
00408
00409 pt = getPt( CSC02, eta , temp_dphi )[0];
00410 spt = getPt( CSC02, eta , temp_dphi )[1];
00411 }
00412
00413 else if ( layer1 == 3 ) {
00414
00415 pt = getPt( CSC03, eta , temp_dphi )[0];
00416 spt = getPt( CSC03, eta , temp_dphi )[1];
00417 }
00418
00419 else {
00420
00421 pt = getPt( CSC14, eta , temp_dphi )[0];
00422 spt = getPt( CSC14, eta , temp_dphi )[1];
00423 }
00424 ptEstimate.push_back( pt*sign );
00425 sptEstimate.push_back( spt );
00426 }
00427
00428
00429 if ( layer0 == 1 ) {
00430
00431 if ( layer1 == 2 ) {
00432
00433
00434
00435 pt = getPt( CSC12, eta , temp_dphi )[0];
00436 spt = getPt( CSC12, eta , temp_dphi )[1];
00437 }
00438
00439 else if ( layer1 == 3 ) {
00440 temp_dphi = scaledPhi(temp_dphi, CSC13_2[3]);
00441 pt = getPt( CSC13, eta , temp_dphi )[0];
00442 spt = getPt( CSC13, eta , temp_dphi )[1];
00443 }
00444
00445 else {
00446 temp_dphi = scaledPhi(temp_dphi, CSC14_3[3]);
00447 pt = getPt( CSC14, eta , temp_dphi )[0];
00448 spt = getPt( CSC14, eta , temp_dphi )[1];
00449 }
00450 ptEstimate.push_back( pt*sign );
00451 sptEstimate.push_back( spt );
00452 }
00453
00454
00455 if ( layer0 == 2 && temp_dphi > 0.0001 ) {
00456
00457
00458 bool ME4av =false;
00459 if ( layer1 == 4 ) {
00460 temp_dphi = scaledPhi(temp_dphi, CSC24_1[3]);
00461 pt = getPt( CSC24, eta , temp_dphi )[0];
00462 spt = getPt( CSC24, eta , temp_dphi )[1];
00463 ME4av = true;
00464 }
00465
00466 else {
00467
00468 if ( !ME4av ) {
00469 if ( eta <= 1.7 ) { temp_dphi = scaledPhi(temp_dphi, CSC23_1[3]); }
00470 if ( eta > 1.7 ) { temp_dphi = scaledPhi(temp_dphi, CSC23_2[3]); }
00471 pt = getPt( CSC23, eta , temp_dphi )[0];
00472 spt = getPt( CSC23, eta , temp_dphi )[1];
00473 }
00474 }
00475 ptEstimate.push_back( pt*sign );
00476 sptEstimate.push_back( spt );
00477 }
00478
00479
00480 if ( layer0 == 3 && temp_dphi > 0.0001 ) {
00481
00482 temp_dphi = scaledPhi(temp_dphi, CSC34_1[3]);
00483 pt = getPt( CSC34, eta , temp_dphi )[0];
00484 spt = getPt( CSC34, eta , temp_dphi )[1];
00485 ptEstimate.push_back( pt*sign );
00486 sptEstimate.push_back( spt );
00487 }
00488
00489 }
00490 }
00491
00492
00493 if ( ptEstimate.size() > 0 ) weightedPt( ptEstimate, sptEstimate, thePt, theSpt);
00494
00495 }
00496
00497
00498
00499
00500
00501
00502
00503
00504 void MuonSeedCreator::estimatePtDT(SegmentContainer seg, std::vector<int> layers, double& thePt, double& theSpt) {
00505
00506 unsigned size = seg.size();
00507 if (size < 2) return;
00508
00509 std::vector<double> ptEstimate;
00510 std::vector<double> sptEstimate;
00511
00512 thePt = defaultMomentum;
00513 theSpt = defaultMomentum;
00514
00515 double pt = 0.;
00516 double spt = 0.;
00517 GlobalPoint segPos[2];
00518
00519 int layer0 = layers[0];
00520 segPos[0] = seg[0]->globalPosition();
00521 float eta = fabs(segPos[0].eta());
00522
00523
00524
00525
00526
00527
00528
00529
00530 for ( unsigned idx1 = 1; idx1 <size ; ++idx1 ) {
00531
00532 int layer1 = layers[idx1];
00533 segPos[1] = seg[idx1]->globalPosition();
00534
00535
00536
00537
00538 double dphi = segPos[0].phi() - segPos[1].phi();
00539 double temp_dphi = dphi;
00540
00541
00542
00543 double sign = 1.0;
00544 if (temp_dphi < 0.) {
00545 temp_dphi = -temp_dphi;
00546 sign = -1.0;
00547 }
00548
00549 if (temp_dphi < 0.0001 ) {
00550 temp_dphi = 0.0001 ;
00551 pt = theMaxMomentum ;
00552 spt = theMaxMomentum*0.25 ;
00553 ptEstimate.push_back( pt*sign );
00554 sptEstimate.push_back( spt );
00555 }
00556
00557
00558 bool MB23av = false;
00559 if (layer0 == -1 && temp_dphi > 0.0001 ) {
00560
00561 if (layer1 == -2) {
00562
00563 if ( eta <= 0.7 ) { temp_dphi = scaledPhi(temp_dphi, DT12_1[3]); }
00564 if ( eta > 0.7 ) { temp_dphi = scaledPhi(temp_dphi, DT12_2[3]); }
00565 pt = getPt( DT12, eta , temp_dphi )[0];
00566 spt = getPt( DT12, eta , temp_dphi )[1];
00567 MB23av = true;
00568 }
00569
00570 else if (layer1 == -3) {
00571
00572 if ( eta <= 0.6 ) { temp_dphi = scaledPhi(temp_dphi, DT13_1[3]); }
00573 if ( eta > 0.6 ) { temp_dphi = scaledPhi(temp_dphi, DT13_2[3]); }
00574 pt = getPt( DT13, eta , temp_dphi )[0];
00575 spt = getPt( DT13, eta , temp_dphi )[1];
00576 MB23av = true;
00577 }
00578
00579 else {
00580 if ( !MB23av ) {
00581 if ( eta <= 0.52 ) { temp_dphi = scaledPhi(temp_dphi, DT14_1[3]); }
00582 if ( eta > 0.52 ) { temp_dphi = scaledPhi(temp_dphi, DT14_2[3]); }
00583 pt = getPt( DT14, eta , temp_dphi )[0];
00584 spt = getPt( DT14, eta , temp_dphi )[1];
00585 }
00586 }
00587 ptEstimate.push_back( pt*sign );
00588 sptEstimate.push_back( spt );
00589 }
00590
00591
00592 if (layer0 == -2 && temp_dphi > 0.0001 ) {
00593
00594 if ( layer1 == -3) {
00595
00596 if ( eta <= 0.6 ) { temp_dphi = scaledPhi(temp_dphi, DT23_1[3]); }
00597 if ( eta > 0.6 ) { temp_dphi = scaledPhi(temp_dphi, DT23_2[3]); }
00598 pt = getPt( DT23, eta , temp_dphi )[0];
00599 spt = getPt( DT23, eta , temp_dphi )[1];
00600 }
00601
00602 else {
00603
00604 if ( eta <= 0.52 ) { temp_dphi = scaledPhi(temp_dphi, DT24_1[3]); }
00605 if ( eta > 0.52 ) { temp_dphi = scaledPhi(temp_dphi, DT24_2[3]); }
00606 pt = getPt( DT24, eta , temp_dphi )[0];
00607 spt = getPt( DT24, eta , temp_dphi )[1];
00608 }
00609 ptEstimate.push_back( pt*sign );
00610 sptEstimate.push_back( spt );
00611 }
00612
00613
00614 if (layer0 == -3 && temp_dphi > 0.0001 ) {
00615
00616
00617 if ( eta <= 0.51 ) { temp_dphi = scaledPhi(temp_dphi, DT34_1[3]); }
00618 if ( eta > 0.51 ) { temp_dphi = scaledPhi(temp_dphi, DT34_2[3]); }
00619 pt = getPt( DT34, eta , temp_dphi )[0];
00620 spt = getPt( DT34, eta , temp_dphi )[1];
00621 ptEstimate.push_back( pt*sign );
00622 sptEstimate.push_back( spt );
00623 }
00624 }
00625
00626
00627
00628
00629 if (ptEstimate.size() > 0 ) weightedPt( ptEstimate, sptEstimate, thePt, theSpt);
00630
00631 }
00632
00633
00634
00635
00636
00637
00638 void MuonSeedCreator::estimatePtOverlap(SegmentContainer seg, std::vector<int> layers, double& thePt, double& theSpt) {
00639
00640 int size = layers.size();
00641
00642 thePt = defaultMomentum;
00643 theSpt = defaultMomentum;
00644
00645 SegmentContainer segCSC;
00646 std::vector<int> layersCSC;
00647 SegmentContainer segDT;
00648 std::vector<int> layersDT;
00649
00650
00651 for ( unsigned j = 0; j < layers.size(); ++j ) {
00652 if ( layers[j] > -1 ) {
00653 segCSC.push_back(seg[j]);
00654 layersCSC.push_back(layers[j]);
00655 }
00656 else {
00657 segDT.push_back(seg[j]);
00658 layersDT.push_back(layers[j]);
00659 }
00660 }
00661
00662 std::vector<double> ptEstimate;
00663 std::vector<double> sptEstimate;
00664
00665 GlobalPoint segPos[2];
00666 int layer0 = layers[0];
00667 segPos[0] = seg[0]->globalPosition();
00668 float eta = fabs(segPos[0].eta());
00669
00670
00671 if ( segDT.size() > 0 && segCSC.size() > 0 ) {
00672 int layer1 = layers[size-1];
00673 segPos[1] = seg[size-1]->globalPosition();
00674
00675 double dphi = segPos[0].phi() - segPos[1].phi();
00676 double temp_dphi = dphi;
00677
00678
00679
00680 double sign = 1.0;
00681 if (temp_dphi < 0.) {
00682 temp_dphi = -temp_dphi;
00683 sign = -1.0;
00684 }
00685
00686 if (temp_dphi < 0.0001 ) {
00687 temp_dphi = 0.0001 ;
00688 thePt = theMaxMomentum ;
00689 theSpt = theMaxMomentum*0.25 ;
00690 ptEstimate.push_back( thePt*sign );
00691 sptEstimate.push_back( theSpt );
00692 }
00693
00694
00695 if ( layer0 == -1 && temp_dphi > 0.0001 ) {
00696
00697 if ( layer1 == 1 ) {
00698 temp_dphi = scaledPhi(temp_dphi, OL_1213[3]);
00699 thePt = getPt( OL1213, eta , temp_dphi )[0];
00700 theSpt = getPt( OL1213, eta , temp_dphi )[1];
00701 }
00702
00703 else if ( layer1 == 2) {
00704 temp_dphi = scaledPhi(temp_dphi, OL_1222[3]);
00705 thePt = getPt( OL1222, eta , temp_dphi )[0];
00706 theSpt = getPt( OL1222, eta , temp_dphi )[1];
00707 }
00708
00709 else {
00710 temp_dphi = scaledPhi(temp_dphi, OL_1232[3]);
00711 thePt = getPt( OL1232, eta , temp_dphi )[0];
00712 theSpt = getPt( OL1232, eta , temp_dphi )[1];
00713 }
00714 ptEstimate.push_back(thePt*sign);
00715 sptEstimate.push_back(theSpt);
00716 }
00717
00718 if ( layer0 == -2 && temp_dphi > 0.0001 ) {
00719
00720 if ( layer1 == 1 ) {
00721 temp_dphi = scaledPhi(temp_dphi, OL_2213[3]);
00722 thePt = getPt( OL2213, eta , temp_dphi )[0];
00723 theSpt = getPt( OL2213, eta , temp_dphi )[1];
00724 ptEstimate.push_back(thePt*sign);
00725 sptEstimate.push_back(theSpt);
00726 }
00727
00728 if ( layer1 == 2) {
00729 temp_dphi = scaledPhi(temp_dphi, OL_2222[3]);
00730 thePt = getPt( OL2222, eta , temp_dphi )[0];
00731 theSpt = getPt( OL2222, eta , temp_dphi )[1];
00732 }
00733 }
00734 }
00735
00736 if ( segDT.size() > 1 ) {
00737 estimatePtDT(segDT, layersDT, thePt, theSpt);
00738 ptEstimate.push_back(thePt);
00739 sptEstimate.push_back(theSpt);
00740 }
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759 if (ptEstimate.size() > 0 ) weightedPt( ptEstimate, sptEstimate, thePt, theSpt);
00760
00761 }
00762
00763
00764
00765
00766
00767 void MuonSeedCreator::estimatePtSingle(SegmentContainer seg, std::vector<int> layers, double& thePt, double& theSpt) {
00768
00769 thePt = defaultMomentum;
00770 theSpt = defaultMomentum;
00771
00772 GlobalPoint segPos = seg[0]->globalPosition();
00773 double eta = segPos.eta();
00774 GlobalVector gv = seg[0]->globalDirection();
00775
00776
00777
00778 double cosDpsi = (gv.x()*segPos.x() + gv.y()*segPos.y());
00779 cosDpsi /= sqrt(segPos.x()*segPos.x() + segPos.y()*segPos.y());
00780 cosDpsi /= sqrt(gv.x()*gv.x() + gv.y()*gv.y());
00781
00782 double axb = ( segPos.x()*gv.y() ) - ( segPos.y()*gv.x() ) ;
00783 double sign = (axb < 0.) ? 1.0 : -1.0;
00784
00785 double dpsi = fabs(acos(cosDpsi)) ;
00786 if ( dpsi > 1.570796 ) {
00787 dpsi = 3.141592 - dpsi;
00788 sign = -1.*sign ;
00789 }
00790 if (fabs(dpsi) < 0.00005) {
00791 dpsi = 0.00005;
00792 }
00793
00794
00795 if ( layers[0] == -1 ) {
00796
00797 if ( fabs(eta) < 0.3 ) {
00798 dpsi = scaledPhi(dpsi, SMB_10S[3] );
00799 thePt = getPt( SMB10, eta , dpsi )[0];
00800 theSpt = getPt( SMB10, eta , dpsi )[1];
00801 }
00802
00803 if ( fabs(eta) >= 0.3 && fabs(eta) < 0.82 ) {
00804 dpsi = scaledPhi(dpsi, SMB_11S[3] );
00805 thePt = getPt( SMB11, eta , dpsi )[0];
00806 theSpt = getPt( SMB11, eta , dpsi )[1];
00807 }
00808
00809 if ( fabs(eta) >= 0.82 && fabs(eta) < 1.2 ) {
00810 dpsi = scaledPhi(dpsi, SMB_12S[3] );
00811 thePt = getPt( SMB12, eta , dpsi )[0];
00812 theSpt = getPt( SMB12, eta , dpsi )[1];
00813 }
00814 }
00815 if ( layers[0] == 1 ) {
00816
00817 if ( fabs(eta) > 0.92 && fabs(eta) < 1.16 ) {
00818 dpsi = scaledPhi(dpsi, SME_13S[3] );
00819 thePt = getPt( SME13, eta , dpsi )[0];
00820 theSpt = getPt( SME13, eta , dpsi )[1];
00821 }
00822
00823 if ( fabs(eta) >= 1.16 && fabs(eta) <= 1.6 ) {
00824 dpsi = scaledPhi(dpsi, SME_12S[3] );
00825 thePt = getPt( SME12, eta , dpsi )[0];
00826 theSpt = getPt( SME12, eta , dpsi )[1];
00827 }
00828 }
00829 if ( layers[0] == 0 ) {
00830
00831 if ( fabs(eta) > 1.6 ) {
00832 dpsi = scaledPhi(dpsi, SMB_11S[3] );
00833 thePt = getPt( SME11, eta , dpsi )[0];
00834 theSpt = getPt( SME11, eta , dpsi )[1];
00835 }
00836 }
00837
00838 if ( layers[0] == -2 ) {
00839
00840 if ( fabs(eta) < 0.25 ) {
00841 dpsi = scaledPhi(dpsi, SMB_20S[3] );
00842 thePt = getPt( SMB20, eta , dpsi )[0];
00843 theSpt = getPt( SMB20, eta , dpsi )[1];
00844 }
00845
00846 if ( fabs(eta) >= 0.25 && fabs(eta) < 0.72 ) {
00847 dpsi = scaledPhi(dpsi, SMB_21S[3] );
00848 thePt = getPt( SMB21, eta , dpsi )[0];
00849 theSpt = getPt( SMB21, eta , dpsi )[1];
00850 }
00851
00852 if ( fabs(eta) >= 0.72 && fabs(eta) < 1.04 ) {
00853 dpsi = scaledPhi(dpsi, SMB_22S[3] );
00854 thePt = getPt( SMB22, eta , dpsi )[0];
00855 theSpt = getPt( SMB22, eta , dpsi )[1];
00856 }
00857 }
00858 if ( layers[0] == 2 ) {
00859
00860 if ( fabs(eta) > 0.95 && fabs(eta) <= 1.6 ) {
00861 dpsi = scaledPhi(dpsi, SME_22S[3] );
00862 thePt = getPt( SME22, eta , dpsi )[0];
00863 theSpt = getPt( SME22, eta , dpsi )[1];
00864 }
00865
00866 if ( fabs(eta) > 1.6 && fabs(eta) < 2.45 ) {
00867 dpsi = scaledPhi(dpsi, SME_21S[3] );
00868 thePt = getPt( SME21, eta , dpsi )[0];
00869 theSpt = getPt( SME21, eta , dpsi )[1];
00870 }
00871 }
00872
00873
00874 if ( layers[0] == -3 ) {
00875
00876 if ( fabs(eta) <= 0.22 ) {
00877 dpsi = scaledPhi(dpsi, SMB_30S[3] );
00878 thePt = getPt( SMB30, eta , dpsi )[0];
00879 theSpt = getPt( SMB30, eta , dpsi )[1];
00880 }
00881
00882 if ( fabs(eta) > 0.22 && fabs(eta) <= 0.6 ) {
00883 dpsi = scaledPhi(dpsi, SMB_31S[3] );
00884 thePt = getPt( SMB31, eta , dpsi )[0];
00885 theSpt = getPt( SMB31, eta , dpsi )[1];
00886 }
00887
00888 if ( fabs(eta) > 0.6 && fabs(eta) < 0.95 ) {
00889 dpsi = scaledPhi(dpsi, SMB_32S[3] );
00890 thePt = getPt( SMB32, eta , dpsi )[0];
00891 theSpt = getPt( SMB32, eta , dpsi )[1];
00892 }
00893 }
00894 thePt = fabs(thePt)*sign;
00895 theSpt = fabs(theSpt);
00896
00897 return;
00898 }
00899
00900
00901 void MuonSeedCreator::estimatePtShowering(int& NShowers, int& NShowerSegments, double& thePt, double& theSpt) {
00902
00903 if ( NShowers > 2 && thePt < 300. ) {
00904 thePt = 800. ;
00905 theSpt = 200. ;
00906 }
00907 if ( NShowers == 2 && NShowerSegments > 11 && thePt < 150. ) {
00908 thePt = 280. ;
00909 theSpt = 70. ;
00910 }
00911 if ( NShowers == 2 && NShowerSegments <= 11 && thePt < 50. ) {
00912 thePt = 80.;
00913 theSpt = 40. ;
00914 }
00915 if ( NShowers == 1 && NShowerSegments <= 5 && thePt < 10. ) {
00916 thePt = 16. ;
00917 theSpt = 8. ;
00918 }
00919
00920 }
00921
00922
00923
00924
00925
00926
00927
00928 void MuonSeedCreator::weightedPt(std::vector<double> ptEstimate, std::vector<double> sptEstimate, double& thePt, double& theSpt) {
00929
00930
00931 int size = ptEstimate.size();
00932
00933
00934 if (size < 2) {
00935 thePt = ptEstimate[0];
00936 theSpt = sptEstimate[0];
00937 return;
00938 }
00939
00940 double charge = 0.;
00941
00942
00943
00944 for ( unsigned j = 0; j < ptEstimate.size(); j++ ) {
00945
00946 if ( ptEstimate[j] < 0. ) {
00947
00948 charge -= 1. * (ptEstimate[j]*ptEstimate[j]) / (sptEstimate[j]*sptEstimate[j] );
00949 } else {
00950 charge += 1. * (ptEstimate[j]*ptEstimate[j]) / (sptEstimate[j]*sptEstimate[j] );
00951 }
00952 }
00953
00954
00955 if (charge < 0.) {
00956 charge = -1.;
00957 } else {
00958 charge = 1.;
00959 }
00960
00961
00962 double weightPtSum = 0.;
00963 double sigmaSqr_sum = 0.;
00964
00965
00966
00967 for ( unsigned j = 0; j < ptEstimate.size(); ++j ) {
00968
00969
00970
00971 sigmaSqr_sum += 1.0 / (sptEstimate[j]*sptEstimate[j]);
00972 weightPtSum += fabs(ptEstimate[j])/(sptEstimate[j]*sptEstimate[j]);
00973
00974 }
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984 thePt = (charge*weightPtSum) / sigmaSqr_sum;
00985 theSpt = sqrt( 1.0 / sigmaSqr_sum ) ;
00986
00987
00988
00989 return;
00990 }
00991
00992 std::vector<double> MuonSeedCreator::getPt(std::vector<double> vPara, double eta, double dPhi ) {
00993
00994 double h = fabs(eta);
00995 double estPt = ( vPara[0] + vPara[1]*h + vPara[2]*h*h ) / dPhi;
00996 double estSPt = ( vPara[3] + vPara[4]*h + vPara[5]*h*h ) * estPt;
00997 std::vector<double> paraPt ;
00998 paraPt.push_back( estPt );
00999 paraPt.push_back( estSPt ) ;
01000
01001
01002 return paraPt ;
01003 }
01004
01005 double MuonSeedCreator::scaledPhi( double dphi, double t1) {
01006
01007 if (dphi != 0. ) {
01008
01009 double oPhi = 1./dphi ;
01010 dphi = dphi /( 1. + t1/( oPhi + 10. ) ) ;
01011 return dphi ;
01012
01013 } else {
01014 return dphi ;
01015 }
01016
01017 }
01018