00001
00013 #include "RecoMuon/GlobalTrackingTools/interface/MuonTrackingRegionBuilder.h"
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "FWCore/Framework/interface/Event.h"
00025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00026 #include "DataFormats/Common/interface/Handle.h"
00027 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00028 #include "RecoTracker/TkTrackingRegions/interface/RectangularEtaPhiTrackingRegion.h"
00029 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00030 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
00031 #include "DataFormats/VertexReco/interface/Vertex.h"
00032 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00033
00034 using namespace std;
00035
00036
00037
00038
00039 MuonTrackingRegionBuilder::MuonTrackingRegionBuilder(const edm::ParameterSet& par,
00040 const MuonServiceProxy* service) :
00041 theService(service) {
00042
00043
00044 theBeamSpotTag = par.getParameter<edm::InputTag>("beamSpot");
00045 theVertexCollTag = par.getParameter<edm::InputTag>("vertexCollection");
00046
00047
00048 theNsigmaEta = par.getParameter<double>("Rescale_eta");
00049 theNsigmaPhi = par.getParameter<double>("Rescale_phi");
00050 theNsigmaDz = par.getParameter<double>("Rescale_Dz");
00051 theTkEscapePt = par.getParameter<double>("EscapePt");
00052
00053
00054 theEtaRegionPar1 = par.getParameter<double>("EtaR_UpperLimit_Par1");
00055 theEtaRegionPar2 = par.getParameter<double>("EtaR_UpperLimit_Par2");
00056 thePhiRegionPar1 = par.getParameter<double>("PhiR_UpperLimit_Par1");
00057 thePhiRegionPar2 = par.getParameter<double>("PhiR_UpperLimit_Par2");
00058
00059 useVertex = par.getParameter<bool>("UseVertex");
00060 useFixedRegion = par.getParameter<bool>("UseFixedRegion");
00061
00062
00063 thePhiFixed = par.getParameter<double>("Phi_fixed");
00064 theEtaFixed = par.getParameter<double>("Eta_fixed");
00065
00066 thePhiMin = par.getParameter<double>("Phi_min");
00067 theEtaMin = par.getParameter<double>("Eta_min");
00068 theHalfZ = par.getParameter<double>("DeltaZ_Region");
00069 theDeltaR = par.getParameter<double>("DeltaR");
00070
00071
00072 theVertexPos = GlobalPoint(0.0,0.0,0.0);
00073
00074 theOnDemand = par.getParameter<double>("OnDemand");
00075 }
00076
00077
00078
00079
00080
00081 RectangularEtaPhiTrackingRegion*
00082 MuonTrackingRegionBuilder::region(const reco::TrackRef& track) const {
00083
00084 return region(*track);
00085
00086 }
00087
00088
00089
00090
00091
00092 void MuonTrackingRegionBuilder::setEvent(const edm::Event& event) {
00093
00094 theEvent = &event;
00095
00096 }
00097
00098
00099
00100
00101
00102 RectangularEtaPhiTrackingRegion*
00103 MuonTrackingRegionBuilder::region(const reco::Track& staTrack) const {
00104
00105
00106 TSCPBuilderNoMaterial tscpBuilder;
00107 TrajectoryStateTransform tsTransform;
00108 FreeTrajectoryState muFTS = tsTransform.initialFreeState(staTrack,&*theService->magneticField());
00109
00110
00111 GlobalVector dirVector(muFTS.momentum());
00112
00113
00114 const math::XYZVector& mo = staTrack.innerMomentum();
00115 GlobalVector mom(mo.x(),mo.y(),mo.z());
00116 if ( staTrack.p() > 1.5 ) {
00117 mom = dirVector;
00118 }
00119
00120
00121 GlobalPoint vertexPos(0.0,0.0,0.0);
00122 double deltaZatVTX = 0.0;
00123
00124
00125 edm::Handle<reco::BeamSpot> bsHandle;
00126 bool bsHandleFlag = theEvent->getByLabel(theBeamSpotTag, bsHandle);
00127
00128 if ( bsHandleFlag && !useVertex ) {
00129 const reco::BeamSpot& bs = *bsHandle;
00130 vertexPos = GlobalPoint(bs.x0(), bs.y0(), bs.z0());
00131 } else {
00132
00133 edm::Handle<reco::VertexCollection> vertexCollection;
00134 bool vtxHandleFlag = theEvent->getByLabel(theVertexCollTag,vertexCollection);
00135
00136 if ( vtxHandleFlag && !vertexCollection->empty() ) {
00137
00138 reco::VertexCollection::const_iterator vtx = vertexCollection->begin();
00139 vertexPos = GlobalPoint(0.0,0.0,vtx->z());
00140
00141 deltaZatVTX = vtx->zError() * theNsigmaDz;
00142 }
00143 }
00144
00145 TrajectoryStateClosestToPoint tscp = tscpBuilder(muFTS,theVertexPos);
00146 const PerigeeTrajectoryError& covar = tscp.perigeeError();
00147 const PerigeeTrajectoryParameters& param = tscp.perigeeParameters();
00148
00149
00150 double deltaTheta = covar.thetaError();
00151 double theta = param.theta();
00152 double sin_theta = sin(theta);
00153
00154
00155 double deta = theNsigmaEta*(1/fabs(sin_theta))*deltaTheta;
00156 double dphi = theNsigmaPhi*(covar.phiError());
00157
00158
00159
00160
00161
00162 double region_dEta = 0;
00163 double region_dPhi = 0;
00164 double eta,phi;
00165
00166
00167 float pt = abs(mom.perp());
00168 if ( pt <= 10. ) {
00169
00170 float acoeff_Phi = (thePhiRegionPar2 - thePhiRegionPar1)/5;
00171 float acoeff_Eta = (theEtaRegionPar2 - theEtaRegionPar1)/5;
00172
00173 eta = theEtaRegionPar1 + (acoeff_Eta)*(mom.perp()-5.);
00174 phi = thePhiRegionPar1 + (acoeff_Phi)*(mom.perp()-5.) ;
00175 }
00176
00177 if ( pt > 10. && pt < 100. ) {
00178 eta = theEtaRegionPar2;
00179 phi = thePhiRegionPar2;
00180 }
00181
00182 if ( pt >= 100. ) {
00183
00184 float acoeff_Phi = (thePhiRegionPar1 - thePhiRegionPar2)/900;
00185 float acoeff_Eta = (theEtaRegionPar1 - theEtaRegionPar2)/900;
00186
00187 eta = theEtaRegionPar2 + (acoeff_Eta)*(mom.perp()-100.);
00188 phi = thePhiRegionPar2 + (acoeff_Phi)*(mom.perp()-100.);
00189 }
00190
00191
00192 double region_dPhi1 = min(phi,dphi);
00193 double region_dEta1 = min(eta,deta);
00194
00195
00196 region_dPhi = max(thePhiMin,region_dPhi1);
00197 region_dEta = max(theEtaMin,region_dEta1);
00198
00199 float deltaZ = 0.0;
00200
00201 if ( useVertex ) {
00202 deltaZ = deltaZatVTX;
00203 } else {
00204 deltaZ = theHalfZ;
00205 }
00206
00207 float deltaR = theDeltaR;
00208 double minPt = max(theTkEscapePt,mom.perp()*0.6);
00209
00210 RectangularEtaPhiTrackingRegion* region = 0;
00211
00212 if (useFixedRegion) {
00213 region_dEta = theEtaFixed;
00214 region_dPhi = thePhiFixed;
00215 }
00216
00217 region = new RectangularEtaPhiTrackingRegion(dirVector, vertexPos,
00218 minPt, deltaR,
00219 deltaZ, region_dEta, region_dPhi,
00220 theOnDemand);
00221
00222 return region;
00223
00224 }