00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedHits.h"
00012
00013 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00014
00015 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00016
00017 #include "MagneticField/Engine/interface/MagneticField.h"
00018 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00019
00020 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00021 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00022
00023 #include "DataFormats/TrajectoryState/interface/PTrajectoryStateOnDet.h"
00024 #include "DataFormats/Common/interface/OwnVector.h"
00025 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00026 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00027 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00028
00029 #include "FWCore/Framework/interface/EventSetup.h"
00030 #include "FWCore/Framework/interface/ESHandle.h"
00031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00032
00033 #include "gsl/gsl_statistics.h"
00034 #include "TH1F.h"
00035 #include "math.h"
00036
00037 using namespace std;
00038
00039 typedef MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer;
00040 typedef MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer;
00041 typedef MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer;
00042
00043 template <class T> T sqr(const T& t) {return t*t;}
00044
00045 TrajectorySeed RPCSeedHits::seed(const edm::EventSetup& eSetup) const {
00046
00047 double pt[4] = {0,0,0,0};
00048 double spt[4] = {0,0,0,0};
00049
00050 computePtWithoutVtx(pt, spt);
00051
00052 float ptmean=0.;
00053 float sptmean=0.;
00054
00055 computeBestPt(pt, spt, ptmean, sptmean);
00056
00057 cout << "III--> Seed Pt : " << ptmean << endl;
00058 ConstMuonRecHitPointer last = best_cand();
00059 return createSeed(ptmean, sptmean,last,eSetup);
00060 }
00061
00062
00063 ConstMuonRecHitPointer RPCSeedHits::best_cand() const {
00064
00065 MuonRecHitPointer best = 0;
00066
00067 for (MuonRecHitContainer::const_iterator iter=theRhits.begin();
00068 iter!=theRhits.end(); iter++) {
00069 best = (*iter);
00070 }
00071
00072 return best;
00073 }
00074
00075
00076 void RPCSeedHits::computePtWithoutVtx(double* pt, double* spt) const {
00077
00078 int i = 0;
00079 float y1,y2,y3,y4,ys,yt,yq,yd;
00080 float x1,x2,x3,x4,xs,xt,xq,xd;
00081 x1=x2=x3=x4=xs=xt=xq=xd=y1=y2=y3=y4=ys=yd=yt=yq=0;
00082 for (MuonRecHitContainer::const_iterator iter=theRhits.begin();
00083 iter!=theRhits.end(); iter++ ) {
00084 i++;
00085
00086 cout << "X= " << (*iter)->globalPosition().x() << " Y= " << (*iter)->globalPosition().y() << endl;
00087
00088 if (i == 1) {y1= (*iter)->globalPosition().y(); x1= (*iter)->globalPosition().x();}
00089 if (i == 2) {y2= (*iter)->globalPosition().y(); x2= (*iter)->globalPosition().x();}
00090 if (i == 3) {y3= (*iter)->globalPosition().y(); x3= (*iter)->globalPosition().x();}
00091 if (i == 4) {y4= (*iter)->globalPosition().y(); x4= (*iter)->globalPosition().x();}
00092 }
00093
00094 string ord = "1-2-3";
00095 for (int comb = 1; comb < 5; comb++) {
00096
00097 if (comb == 2) {
00098 ord = "1-2-4";
00099 yt=y3; y3=y4; y4=yq; xt=x3; x3=x4; x4=xq;
00100 }
00101
00102 if (comb == 3) {
00103 ord = "1-3-4";
00104 yd=y2; y2=yt; xd=x2; x2=xt;
00105 }
00106
00107 if (comb == 4) {
00108 ord = "2-3-4";
00109 ys=y1; y1=yd; xs=x1; x1=xd;
00110 }
00111
00112 float A = (y3-y2)/(x3-x2) - (y2-y1)/(x2-x1);
00113 float TYO = (x3-x1)/A + (y3*y3-y2*y2)/((x3-x2)*A) - (y2*y2-y1*y1)/((x2-x1)*A);
00114 float TXO = (x3+x2) + (y3*y3-y2*y2)/(x3-x2) - TYO*(y3-y2)/(x3-x2);
00115 float XO = 0.5 * TXO;
00116 float YO = 0.5 * TYO;
00117 float R2 = (x1-XO)*(x1-XO) + (y1-YO)*(y1-YO);
00118 pt[comb-1] = 0.01 * sqrt(R2) * 2 * 0.3;
00119 }
00120
00121 }
00122
00123
00124 void RPCSeedHits::computeBestPt(double* pt,
00125 double* spt,
00126 float& ptmean,
00127 float& sptmean) const {
00128
00129 cout << "[RPCSeedHits] --> computeBestPt class called." << endl;
00130
00131 cout << "---< best pt computing >---" << endl;
00132 cout << "1-2-3 pt = " << pt[0] << endl;
00133 cout << "1-2-4 pt = " << pt[1] << endl;
00134 cout << "1-3-4 pt = " << pt[2] << endl;
00135 cout << "2-3-4 pt = " << pt[3] << endl;
00136 cout << "---------------------------" << endl;
00137
00138 ptmean = (pt[0]+pt[1]+pt[2]+pt[3])/4;
00139
00140 sptmean = spt[0];
00141
00142 }
00143
00144
00145 TrajectorySeed RPCSeedHits::createSeed(float ptmean,
00146 float sptmean,
00147 ConstMuonRecHitPointer last,
00148 const edm::EventSetup& eSetup) const{
00149
00150 MuonPatternRecoDumper debug;
00151
00152 edm::ESHandle<MagneticField> field;
00153 eSetup.get<IdealMagneticFieldRecord>().get(field);
00154
00155 double theMinMomentum = 3.0;
00156
00157 if ( fabs(ptmean) < theMinMomentum ) ptmean = theMinMomentum * ptmean/fabs(ptmean) ;
00158
00159 AlgebraicVector t(4);
00160 AlgebraicSymMatrix mat(5,0) ;
00161
00162 LocalPoint segPos=last->localPosition();
00163 GlobalVector mom=last->globalPosition()-GlobalPoint();
00164 GlobalVector polar(GlobalVector::Spherical(mom.theta(), last->globalDirection().phi(), 1.));
00165 polar *= fabs(ptmean)/polar.perp();
00166 LocalVector segDirFromPos=last->det()->toLocal(polar);
00167 int charge=(int)(ptmean/fabs(ptmean));
00168
00169 LocalTrajectoryParameters param(segPos,segDirFromPos, charge);
00170
00171 mat = last->parametersError().similarityT( last->projectionMatrix() );
00172
00173 float p_err = sqr(sptmean/(ptmean*ptmean));
00174 mat[0][0]= p_err;
00175
00176 LocalTrajectoryError error(mat);
00177
00178 TrajectoryStateOnSurface tsos(param, error, last->det()->surface(),&*field);
00179
00180 cout << "Trajectory State on Surface before the extrapolation"<<endl;
00181 cout << debug.dumpTSOS(tsos);
00182
00183 DetId id = last->geographicalId();
00184
00185 cout << "The RecSegment relies on: "<<endl;
00186 cout << debug.dumpMuonId(id);
00187 cout << debug.dumpTSOS(tsos);
00188
00189 TrajectoryStateTransform tsTransform;
00190
00191 PTrajectoryStateOnDet *seedTSOS = tsTransform.persistentState( tsos ,id.rawId());
00192
00193 edm::OwnVector<TrackingRecHit> container;
00194 TrajectorySeed theSeed(*seedTSOS,container,oppositeToMomentum);
00195
00196 return theSeed;
00197 }