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(mat);
00300
00301
00302 TrajectoryStateOnSurface tsos(param, error, seg[last]->det()->surface(),&*BField);
00303
00304
00305 DetId id = seg[last]->geographicalId();
00306
00307
00308 TrajectoryStateTransform tsTransform;
00309
00310
00311 std::auto_ptr<PTrajectoryStateOnDet> seedTSOS(tsTransform.persistentState( tsos, id.rawId()));
00312
00313 edm::OwnVector<TrackingRecHit> container;
00314 for (unsigned l=0; l<seg.size(); l++) {
00315 container.push_back( seg[l]->hit()->clone() );
00316
00317 }
00318
00319 TrajectorySeed theSeed(*seedTSOS,container,alongMomentum);
00320 return theSeed;
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 void MuonSeedCreator::estimatePtCSC(SegmentContainer seg, std::vector<int> layers, double& thePt, double& theSpt ) {
00334
00335 unsigned size = seg.size();
00336 if (size < 2) return;
00337
00338
00339
00340
00341
00342
00343
00344 std::vector<double> ptEstimate;
00345 std::vector<double> sptEstimate;
00346
00347 thePt = defaultMomentum;
00348 theSpt = defaultMomentum;
00349
00350 double pt = 0.;
00351 double spt = 0.;
00352 GlobalPoint segPos[2];
00353
00354 int layer0 = layers[0];
00355 segPos[0] = seg[0]->globalPosition();
00356 float eta = fabs( segPos[0].eta() );
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 unsigned idx1 = size;
00373 if (size > 1) {
00374 while ( idx1 > 1 ) {
00375 idx1--;
00376 int layer1 = layers[idx1];
00377 if (layer0 == layer1) continue;
00378 segPos[1] = seg[idx1]->globalPosition();
00379
00380 double dphi = segPos[0].phi() - segPos[1].phi();
00381
00382 double temp_dphi = dphi;
00383
00384 double sign = 1.0;
00385 if (temp_dphi < 0.) {
00386 temp_dphi = -1.0*temp_dphi;
00387 sign = -1.0;
00388 }
00389
00390
00391 if (temp_dphi < 0.0001 ) {
00392 temp_dphi = 0.0001 ;
00393 pt = theMaxMomentum ;
00394 spt = theMaxMomentum*0.25 ;
00395 ptEstimate.push_back( pt*sign );
00396 sptEstimate.push_back( spt );
00397 }
00398
00399 if ( layer0 == 0 && temp_dphi >= 0.0001 ) {
00400
00401
00402 if ( layer1 == 1 ) {
00403
00404 pt = getPt( CSC01, eta , temp_dphi )[0];
00405 spt = getPt( CSC01, eta , temp_dphi )[1];
00406 }
00407
00408 else if ( layer1 == 2 ) {
00409
00410 pt = getPt( CSC02, eta , temp_dphi )[0];
00411 spt = getPt( CSC02, eta , temp_dphi )[1];
00412 }
00413
00414 else if ( layer1 == 3 ) {
00415
00416 pt = getPt( CSC03, eta , temp_dphi )[0];
00417 spt = getPt( CSC03, eta , temp_dphi )[1];
00418 }
00419
00420 else {
00421
00422 pt = getPt( CSC14, eta , temp_dphi )[0];
00423 spt = getPt( CSC14, eta , temp_dphi )[1];
00424 }
00425 ptEstimate.push_back( pt*sign );
00426 sptEstimate.push_back( spt );
00427 }
00428
00429
00430 if ( layer0 == 1 ) {
00431
00432 if ( layer1 == 2 ) {
00433
00434
00435
00436 pt = getPt( CSC12, eta , temp_dphi )[0];
00437 spt = getPt( CSC12, eta , temp_dphi )[1];
00438 }
00439
00440 else if ( layer1 == 3 ) {
00441 temp_dphi = scaledPhi(temp_dphi, CSC13_2[3]);
00442 pt = getPt( CSC13, eta , temp_dphi )[0];
00443 spt = getPt( CSC13, eta , temp_dphi )[1];
00444 }
00445
00446 else {
00447 temp_dphi = scaledPhi(temp_dphi, CSC14_3[3]);
00448 pt = getPt( CSC14, eta , temp_dphi )[0];
00449 spt = getPt( CSC14, eta , temp_dphi )[1];
00450 }
00451 ptEstimate.push_back( pt*sign );
00452 sptEstimate.push_back( spt );
00453 }
00454
00455
00456 if ( layer0 == 2 && temp_dphi > 0.0001 ) {
00457
00458
00459 bool ME4av =false;
00460 if ( layer1 == 4 ) {
00461 temp_dphi = scaledPhi(temp_dphi, CSC24_1[3]);
00462 pt = getPt( CSC24, eta , temp_dphi )[0];
00463 spt = getPt( CSC24, eta , temp_dphi )[1];
00464 ME4av = true;
00465 }
00466
00467 else {
00468
00469 if ( !ME4av ) {
00470 if ( eta <= 1.7 ) { temp_dphi = scaledPhi(temp_dphi, CSC23_1[3]); }
00471 if ( eta > 1.7 ) { temp_dphi = scaledPhi(temp_dphi, CSC23_2[3]); }
00472 pt = getPt( CSC23, eta , temp_dphi )[0];
00473 spt = getPt( CSC23, eta , temp_dphi )[1];
00474 }
00475 }
00476 ptEstimate.push_back( pt*sign );
00477 sptEstimate.push_back( spt );
00478 }
00479
00480
00481 if ( layer0 == 3 && temp_dphi > 0.0001 ) {
00482
00483 temp_dphi = scaledPhi(temp_dphi, CSC34_1[3]);
00484 pt = getPt( CSC34, eta , temp_dphi )[0];
00485 spt = getPt( CSC34, eta , temp_dphi )[1];
00486 ptEstimate.push_back( pt*sign );
00487 sptEstimate.push_back( spt );
00488 }
00489
00490 }
00491 }
00492
00493
00494 if ( ptEstimate.size() > 0 ) weightedPt( ptEstimate, sptEstimate, thePt, theSpt);
00495
00496 }
00497
00498
00499
00500
00501
00502
00503
00504
00505 void MuonSeedCreator::estimatePtDT(SegmentContainer seg, std::vector<int> layers, double& thePt, double& theSpt) {
00506
00507 unsigned size = seg.size();
00508 if (size < 2) return;
00509
00510 std::vector<double> ptEstimate;
00511 std::vector<double> sptEstimate;
00512
00513 thePt = defaultMomentum;
00514 theSpt = defaultMomentum;
00515
00516 double pt = 0.;
00517 double spt = 0.;
00518 GlobalPoint segPos[2];
00519
00520 int layer0 = layers[0];
00521 segPos[0] = seg[0]->globalPosition();
00522 float eta = fabs(segPos[0].eta());
00523
00524
00525
00526
00527
00528
00529
00530
00531 for ( unsigned idx1 = 1; idx1 <size ; ++idx1 ) {
00532
00533 int layer1 = layers[idx1];
00534 segPos[1] = seg[idx1]->globalPosition();
00535
00536
00537
00538
00539 double dphi = segPos[0].phi() - segPos[1].phi();
00540 double temp_dphi = dphi;
00541
00542
00543
00544 double sign = 1.0;
00545 if (temp_dphi < 0.) {
00546 temp_dphi = -temp_dphi;
00547 sign = -1.0;
00548 }
00549
00550 if (temp_dphi < 0.0001 ) {
00551 temp_dphi = 0.0001 ;
00552 pt = theMaxMomentum ;
00553 spt = theMaxMomentum*0.25 ;
00554 ptEstimate.push_back( pt*sign );
00555 sptEstimate.push_back( spt );
00556 }
00557
00558
00559 bool MB23av = false;
00560 if (layer0 == -1 && temp_dphi > 0.0001 ) {
00561
00562 if (layer1 == -2) {
00563
00564 if ( eta <= 0.7 ) { temp_dphi = scaledPhi(temp_dphi, DT12_1[3]); }
00565 if ( eta > 0.7 ) { temp_dphi = scaledPhi(temp_dphi, DT12_2[3]); }
00566 pt = getPt( DT12, eta , temp_dphi )[0];
00567 spt = getPt( DT12, eta , temp_dphi )[1];
00568 MB23av = true;
00569 }
00570
00571 else if (layer1 == -3) {
00572
00573 if ( eta <= 0.6 ) { temp_dphi = scaledPhi(temp_dphi, DT13_1[3]); }
00574 if ( eta > 0.6 ) { temp_dphi = scaledPhi(temp_dphi, DT13_2[3]); }
00575 pt = getPt( DT13, eta , temp_dphi )[0];
00576 spt = getPt( DT13, eta , temp_dphi )[1];
00577 MB23av = true;
00578 }
00579
00580 else {
00581 if ( !MB23av ) {
00582 if ( eta <= 0.52 ) { temp_dphi = scaledPhi(temp_dphi, DT14_1[3]); }
00583 if ( eta > 0.52 ) { temp_dphi = scaledPhi(temp_dphi, DT14_2[3]); }
00584 pt = getPt( DT14, eta , temp_dphi )[0];
00585 spt = getPt( DT14, eta , temp_dphi )[1];
00586 }
00587 }
00588 ptEstimate.push_back( pt*sign );
00589 sptEstimate.push_back( spt );
00590 }
00591
00592
00593 if (layer0 == -2 && temp_dphi > 0.0001 ) {
00594
00595 if ( layer1 == -3) {
00596
00597 if ( eta <= 0.6 ) { temp_dphi = scaledPhi(temp_dphi, DT23_1[3]); }
00598 if ( eta > 0.6 ) { temp_dphi = scaledPhi(temp_dphi, DT23_2[3]); }
00599 pt = getPt( DT23, eta , temp_dphi )[0];
00600 spt = getPt( DT23, eta , temp_dphi )[1];
00601 }
00602
00603 else {
00604
00605 if ( eta <= 0.52 ) { temp_dphi = scaledPhi(temp_dphi, DT24_1[3]); }
00606 if ( eta > 0.52 ) { temp_dphi = scaledPhi(temp_dphi, DT24_2[3]); }
00607 pt = getPt( DT24, eta , temp_dphi )[0];
00608 spt = getPt( DT24, eta , temp_dphi )[1];
00609 }
00610 ptEstimate.push_back( pt*sign );
00611 sptEstimate.push_back( spt );
00612 }
00613
00614
00615 if (layer0 == -3 && temp_dphi > 0.0001 ) {
00616
00617
00618 if ( eta <= 0.51 ) { temp_dphi = scaledPhi(temp_dphi, DT34_1[3]); }
00619 if ( eta > 0.51 ) { temp_dphi = scaledPhi(temp_dphi, DT34_2[3]); }
00620 pt = getPt( DT34, eta , temp_dphi )[0];
00621 spt = getPt( DT34, eta , temp_dphi )[1];
00622 ptEstimate.push_back( pt*sign );
00623 sptEstimate.push_back( spt );
00624 }
00625 }
00626
00627
00628
00629
00630 if (ptEstimate.size() > 0 ) weightedPt( ptEstimate, sptEstimate, thePt, theSpt);
00631
00632 }
00633
00634
00635
00636
00637
00638
00639 void MuonSeedCreator::estimatePtOverlap(SegmentContainer seg, std::vector<int> layers, double& thePt, double& theSpt) {
00640
00641 int size = layers.size();
00642
00643 thePt = defaultMomentum;
00644 theSpt = defaultMomentum;
00645
00646 SegmentContainer segCSC;
00647 std::vector<int> layersCSC;
00648 SegmentContainer segDT;
00649 std::vector<int> layersDT;
00650
00651
00652 for ( unsigned j = 0; j < layers.size(); ++j ) {
00653 if ( layers[j] > -1 ) {
00654 segCSC.push_back(seg[j]);
00655 layersCSC.push_back(layers[j]);
00656 }
00657 else {
00658 segDT.push_back(seg[j]);
00659 layersDT.push_back(layers[j]);
00660 }
00661 }
00662
00663 std::vector<double> ptEstimate;
00664 std::vector<double> sptEstimate;
00665
00666 GlobalPoint segPos[2];
00667 int layer0 = layers[0];
00668 segPos[0] = seg[0]->globalPosition();
00669 float eta = fabs(segPos[0].eta());
00670
00671
00672 if ( segDT.size() > 0 && segCSC.size() > 0 ) {
00673 int layer1 = layers[size-1];
00674 segPos[1] = seg[size-1]->globalPosition();
00675
00676 double dphi = segPos[0].phi() - segPos[1].phi();
00677 double temp_dphi = dphi;
00678
00679
00680
00681 double sign = 1.0;
00682 if (temp_dphi < 0.) {
00683 temp_dphi = -temp_dphi;
00684 sign = -1.0;
00685 }
00686
00687 if (temp_dphi < 0.0001 ) {
00688 temp_dphi = 0.0001 ;
00689 thePt = theMaxMomentum ;
00690 theSpt = theMaxMomentum*0.25 ;
00691 ptEstimate.push_back( thePt*sign );
00692 sptEstimate.push_back( theSpt );
00693 }
00694
00695
00696 if ( layer0 == -1 && temp_dphi > 0.0001 ) {
00697
00698 if ( layer1 == 1 ) {
00699 temp_dphi = scaledPhi(temp_dphi, OL_1213[3]);
00700 thePt = getPt( OL1213, eta , temp_dphi )[0];
00701 theSpt = getPt( OL1213, eta , temp_dphi )[1];
00702 }
00703
00704 else if ( layer1 == 2) {
00705 temp_dphi = scaledPhi(temp_dphi, OL_1222[3]);
00706 thePt = getPt( OL1222, eta , temp_dphi )[0];
00707 theSpt = getPt( OL1222, eta , temp_dphi )[1];
00708 }
00709
00710 else {
00711 temp_dphi = scaledPhi(temp_dphi, OL_1232[3]);
00712 thePt = getPt( OL1232, eta , temp_dphi )[0];
00713 theSpt = getPt( OL1232, eta , temp_dphi )[1];
00714 }
00715 ptEstimate.push_back(thePt*sign);
00716 sptEstimate.push_back(theSpt);
00717 }
00718
00719 if ( layer0 == -2 && temp_dphi > 0.0001 ) {
00720
00721 if ( layer1 == 1 ) {
00722 temp_dphi = scaledPhi(temp_dphi, OL_2213[3]);
00723 thePt = getPt( OL2213, eta , temp_dphi )[0];
00724 theSpt = getPt( OL2213, eta , temp_dphi )[1];
00725 ptEstimate.push_back(thePt*sign);
00726 sptEstimate.push_back(theSpt);
00727 }
00728
00729 if ( layer1 == 2) {
00730 temp_dphi = scaledPhi(temp_dphi, OL_2222[3]);
00731 thePt = getPt( OL2222, eta , temp_dphi )[0];
00732 theSpt = getPt( OL2222, eta , temp_dphi )[1];
00733 }
00734 }
00735 }
00736
00737 if ( segDT.size() > 1 ) {
00738 estimatePtDT(segDT, layersDT, thePt, theSpt);
00739 ptEstimate.push_back(thePt);
00740 sptEstimate.push_back(theSpt);
00741 }
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760 if (ptEstimate.size() > 0 ) weightedPt( ptEstimate, sptEstimate, thePt, theSpt);
00761
00762 }
00763
00764
00765
00766
00767
00768 void MuonSeedCreator::estimatePtSingle(SegmentContainer seg, std::vector<int> layers, double& thePt, double& theSpt) {
00769
00770 thePt = defaultMomentum;
00771 theSpt = defaultMomentum;
00772
00773 GlobalPoint segPos = seg[0]->globalPosition();
00774 double eta = segPos.eta();
00775 GlobalVector gv = seg[0]->globalDirection();
00776
00777
00778
00779 double cosDpsi = (gv.x()*segPos.x() + gv.y()*segPos.y());
00780 cosDpsi /= sqrt(segPos.x()*segPos.x() + segPos.y()*segPos.y());
00781 cosDpsi /= sqrt(gv.x()*gv.x() + gv.y()*gv.y());
00782
00783 double axb = ( segPos.x()*gv.y() ) - ( segPos.y()*gv.x() ) ;
00784 double sign = (axb < 0.) ? 1.0 : -1.0;
00785
00786 double dpsi = fabs(acos(cosDpsi)) ;
00787 if ( dpsi > 1.570796 ) {
00788 dpsi = 3.141592 - dpsi;
00789 sign = -1.*sign ;
00790 }
00791 if (fabs(dpsi) < 0.00005) {
00792 dpsi = 0.00005;
00793 }
00794
00795
00796 if ( layers[0] == -1 ) {
00797
00798 if ( fabs(eta) < 0.3 ) {
00799 dpsi = scaledPhi(dpsi, SMB_10S[3] );
00800 thePt = getPt( SMB10, eta , dpsi )[0];
00801 theSpt = getPt( SMB10, eta , dpsi )[1];
00802 }
00803
00804 if ( fabs(eta) >= 0.3 && fabs(eta) < 0.82 ) {
00805 dpsi = scaledPhi(dpsi, SMB_11S[3] );
00806 thePt = getPt( SMB11, eta , dpsi )[0];
00807 theSpt = getPt( SMB11, eta , dpsi )[1];
00808 }
00809
00810 if ( fabs(eta) >= 0.82 && fabs(eta) < 1.2 ) {
00811 dpsi = scaledPhi(dpsi, SMB_12S[3] );
00812 thePt = getPt( SMB12, eta , dpsi )[0];
00813 theSpt = getPt( SMB12, eta , dpsi )[1];
00814 }
00815 }
00816 if ( layers[0] == 1 ) {
00817
00818 if ( fabs(eta) > 0.92 && fabs(eta) < 1.16 ) {
00819 dpsi = scaledPhi(dpsi, SME_13S[3] );
00820 thePt = getPt( SME13, eta , dpsi )[0];
00821 theSpt = getPt( SME13, eta , dpsi )[1];
00822 }
00823
00824 if ( fabs(eta) >= 1.16 && fabs(eta) <= 1.6 ) {
00825 dpsi = scaledPhi(dpsi, SME_12S[3] );
00826 thePt = getPt( SME12, eta , dpsi )[0];
00827 theSpt = getPt( SME12, eta , dpsi )[1];
00828 }
00829 }
00830 if ( layers[0] == 0 ) {
00831
00832 if ( fabs(eta) > 1.6 ) {
00833 dpsi = scaledPhi(dpsi, SMB_11S[3] );
00834 thePt = getPt( SME11, eta , dpsi )[0];
00835 theSpt = getPt( SME11, eta , dpsi )[1];
00836 }
00837 }
00838
00839 if ( layers[0] == -2 ) {
00840
00841 if ( fabs(eta) < 0.25 ) {
00842 dpsi = scaledPhi(dpsi, SMB_20S[3] );
00843 thePt = getPt( SMB20, eta , dpsi )[0];
00844 theSpt = getPt( SMB20, eta , dpsi )[1];
00845 }
00846
00847 if ( fabs(eta) >= 0.25 && fabs(eta) < 0.72 ) {
00848 dpsi = scaledPhi(dpsi, SMB_21S[3] );
00849 thePt = getPt( SMB21, eta , dpsi )[0];
00850 theSpt = getPt( SMB21, eta , dpsi )[1];
00851 }
00852
00853 if ( fabs(eta) >= 0.72 && fabs(eta) < 1.04 ) {
00854 dpsi = scaledPhi(dpsi, SMB_22S[3] );
00855 thePt = getPt( SMB22, eta , dpsi )[0];
00856 theSpt = getPt( SMB22, eta , dpsi )[1];
00857 }
00858 }
00859 if ( layers[0] == 2 ) {
00860
00861 if ( fabs(eta) > 0.95 && fabs(eta) <= 1.6 ) {
00862 dpsi = scaledPhi(dpsi, SME_22S[3] );
00863 thePt = getPt( SME22, eta , dpsi )[0];
00864 theSpt = getPt( SME22, eta , dpsi )[1];
00865 }
00866
00867 if ( fabs(eta) > 1.6 && fabs(eta) < 2.45 ) {
00868 dpsi = scaledPhi(dpsi, SME_21S[3] );
00869 thePt = getPt( SME21, eta , dpsi )[0];
00870 theSpt = getPt( SME21, eta , dpsi )[1];
00871 }
00872 }
00873
00874
00875 if ( layers[0] == -3 ) {
00876
00877 if ( fabs(eta) <= 0.22 ) {
00878 dpsi = scaledPhi(dpsi, SMB_30S[3] );
00879 thePt = getPt( SMB30, eta , dpsi )[0];
00880 theSpt = getPt( SMB30, eta , dpsi )[1];
00881 }
00882
00883 if ( fabs(eta) > 0.22 && fabs(eta) <= 0.6 ) {
00884 dpsi = scaledPhi(dpsi, SMB_31S[3] );
00885 thePt = getPt( SMB31, eta , dpsi )[0];
00886 theSpt = getPt( SMB31, eta , dpsi )[1];
00887 }
00888
00889 if ( fabs(eta) > 0.6 && fabs(eta) < 0.95 ) {
00890 dpsi = scaledPhi(dpsi, SMB_32S[3] );
00891 thePt = getPt( SMB32, eta , dpsi )[0];
00892 theSpt = getPt( SMB32, eta , dpsi )[1];
00893 }
00894 }
00895 thePt = fabs(thePt)*sign;
00896 theSpt = fabs(theSpt);
00897
00898 return;
00899 }
00900
00901
00902 void MuonSeedCreator::estimatePtShowering(int& NShowers, int& NShowerSegments, double& thePt, double& theSpt) {
00903
00904 if ( NShowers > 2 && thePt < 300. ) {
00905 thePt = 800. ;
00906 theSpt = 200. ;
00907 }
00908 if ( NShowers == 2 && NShowerSegments > 11 && thePt < 150. ) {
00909 thePt = 280. ;
00910 theSpt = 70. ;
00911 }
00912 if ( NShowers == 2 && NShowerSegments <= 11 && thePt < 50. ) {
00913 thePt = 80.;
00914 theSpt = 40. ;
00915 }
00916 if ( NShowers == 1 && NShowerSegments <= 5 && thePt < 10. ) {
00917 thePt = 16. ;
00918 theSpt = 8. ;
00919 }
00920
00921 }
00922
00923
00924
00925
00926
00927
00928
00929 void MuonSeedCreator::weightedPt(std::vector<double> ptEstimate, std::vector<double> sptEstimate, double& thePt, double& theSpt) {
00930
00931
00932 int size = ptEstimate.size();
00933
00934
00935 if (size < 2) {
00936 thePt = ptEstimate[0];
00937 theSpt = sptEstimate[0];
00938 return;
00939 }
00940
00941 double charge = 0.;
00942
00943
00944
00945 for ( unsigned j = 0; j < ptEstimate.size(); j++ ) {
00946
00947 if ( ptEstimate[j] < 0. ) {
00948
00949 charge -= 1. * (ptEstimate[j]*ptEstimate[j]) / (sptEstimate[j]*sptEstimate[j] );
00950 } else {
00951 charge += 1. * (ptEstimate[j]*ptEstimate[j]) / (sptEstimate[j]*sptEstimate[j] );
00952 }
00953 }
00954
00955
00956 if (charge < 0.) {
00957 charge = -1.;
00958 } else {
00959 charge = 1.;
00960 }
00961
00962
00963 double weightPtSum = 0.;
00964 double sigmaSqr_sum = 0.;
00965
00966
00967
00968 for ( unsigned j = 0; j < ptEstimate.size(); ++j ) {
00969
00970
00971
00972 sigmaSqr_sum += 1.0 / (sptEstimate[j]*sptEstimate[j]);
00973 weightPtSum += fabs(ptEstimate[j])/(sptEstimate[j]*sptEstimate[j]);
00974
00975 }
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985 thePt = (charge*weightPtSum) / sigmaSqr_sum;
00986 theSpt = sqrt( 1.0 / sigmaSqr_sum ) ;
00987
00988
00989
00990 return;
00991 }
00992
00993 std::vector<double> MuonSeedCreator::getPt(std::vector<double> vPara, double eta, double dPhi ) {
00994
00995 double h = fabs(eta);
00996 double estPt = ( vPara[0] + vPara[1]*h + vPara[2]*h*h ) / dPhi;
00997 double estSPt = ( vPara[3] + vPara[4]*h + vPara[5]*h*h ) * estPt;
00998 std::vector<double> paraPt ;
00999 paraPt.push_back( estPt );
01000 paraPt.push_back( estSPt ) ;
01001
01002
01003 return paraPt ;
01004 }
01005
01006 double MuonSeedCreator::scaledPhi( double dphi, double t1) {
01007
01008 if (dphi != 0. ) {
01009
01010 double oPhi = 1./dphi ;
01011 dphi = dphi /( 1. + t1/( oPhi + 10. ) ) ;
01012 return dphi ;
01013
01014 } else {
01015 return dphi ;
01016 }
01017
01018 }
01019