CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/RecoMuon/GlobalTrackingTools/src/MuonTrackingRegionBuilder.cc

Go to the documentation of this file.
00001 
00013 #include "RecoMuon/GlobalTrackingTools/interface/MuonTrackingRegionBuilder.h"
00014 
00015 //---------------
00016 // C++ Headers --
00017 //---------------
00018 
00019 
00020 //-------------------------------
00021 // Collaborating Class Headers --
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 #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
00034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00035 
00036 using namespace std;
00037 
00038 //
00039 // constructor
00040 //
00041 
00042 void MuonTrackingRegionBuilder::init(const MuonServiceProxy* service) { theService= service;}
00043 MuonTrackingRegionBuilder::MuonTrackingRegionBuilder(const edm::ParameterSet& par)
00044 {
00045   build(par);
00046 }
00047 void MuonTrackingRegionBuilder::build(const edm::ParameterSet& par){
00048   // vertex Collection and Beam Spot
00049   theBeamSpotTag = par.getParameter<edm::InputTag>("beamSpot");
00050   theVertexCollTag = par.getParameter<edm::InputTag>("vertexCollection");
00051 
00052   // parmeters
00053   theNsigmaEta  = par.getParameter<double>("Rescale_eta");
00054   theNsigmaPhi  = par.getParameter<double>("Rescale_phi");
00055   theNsigmaDz   = par.getParameter<double>("Rescale_Dz");
00056   theTkEscapePt = par.getParameter<double>("EscapePt");
00057 
00058   // upper limits parameters   
00059   theEtaRegionPar1 = par.getParameter<double>("EtaR_UpperLimit_Par1"); 
00060   theEtaRegionPar2 = par.getParameter<double>("EtaR_UpperLimit_Par2");
00061   thePhiRegionPar1 = par.getParameter<double>("PhiR_UpperLimit_Par1");
00062   thePhiRegionPar2 = par.getParameter<double>("PhiR_UpperLimit_Par2");
00063 
00064   useVertex = par.getParameter<bool>("UseVertex");
00065   useFixedRegion = par.getParameter<bool>("UseFixedRegion");
00066 
00067   // fixed limits
00068   thePhiFixed = par.getParameter<double>("Phi_fixed");
00069   theEtaFixed = par.getParameter<double>("Eta_fixed");
00070 
00071   thePhiMin = par.getParameter<double>("Phi_min");
00072   theEtaMin = par.getParameter<double>("Eta_min");
00073   theHalfZ  = par.getParameter<double>("DeltaZ_Region");
00074   theDeltaR = par.getParameter<double>("DeltaR");
00075 
00076   // perigee reference point
00077 
00078   theOnDemand = par.getParameter<double>("OnDemand");
00079   theMeasurementTrackerName = par.getParameter<std::string>("MeasurementTrackerName");
00080 }
00081 
00082 
00083 //
00084 //
00085 //
00086 RectangularEtaPhiTrackingRegion* 
00087 MuonTrackingRegionBuilder::region(const reco::TrackRef& track) const {
00088 
00089   return region(*track);
00090 
00091 }
00092 
00093 
00094 //
00095 //
00096 //
00097 void MuonTrackingRegionBuilder::setEvent(const edm::Event& event) {
00098   
00099   theEvent = &event;
00100 
00101 }
00102 
00103 
00104 //
00105 //
00106 //
00107 RectangularEtaPhiTrackingRegion* 
00108 MuonTrackingRegionBuilder::region(const reco::Track& staTrack) const {
00109 
00110   // get the free trajectory state of the muon updated at vertex
00111   TSCPBuilderNoMaterial tscpBuilder; 
00112   
00113   FreeTrajectoryState muFTS = trajectoryStateTransform::initialFreeState(staTrack,&*theService->magneticField());
00114 
00115   LogDebug("MuonTrackingRegionBuilder")<<"from state: "<<muFTS;
00116 
00117   // get track direction at vertex
00118   GlobalVector dirVector(muFTS.momentum());
00119 
00120   // get track momentum
00121   const math::XYZVector& mo = staTrack.innerMomentum();
00122   GlobalVector mom(mo.x(),mo.y(),mo.z());
00123   if ( staTrack.p() > 1.5 ) {
00124     mom = dirVector; 
00125   }
00126 
00127   // initial vertex position -  in the following it is replaced with beam spot/vertexing
00128   GlobalPoint vertexPos(0.0,0.0,0.0);
00129   double deltaZatVTX = 0.0;
00130 
00131   // retrieve beam spot information
00132   edm::Handle<reco::BeamSpot> bsHandle;
00133   bool bsHandleFlag = theEvent->getByLabel(theBeamSpotTag, bsHandle);
00134   // check the validity, otherwise vertexing
00135   // inizialization of BS
00136 
00137   if ( bsHandleFlag && !useVertex ) {
00138     const reco::BeamSpot& bs =  *bsHandle;
00139     vertexPos = GlobalPoint(bs.x0(), bs.y0(), bs.z0());
00140   } else {
00141     // get originZPos from list of reconstructed vertices (first or all)
00142     edm::Handle<reco::VertexCollection> vertexCollection;
00143     bool vtxHandleFlag = theEvent->getByLabel(theVertexCollTag,vertexCollection);
00144     // check if there exists at least one reconstructed vertex
00145     if ( vtxHandleFlag && !vertexCollection->empty() ) {
00146       // use the first vertex in the collection and assume it is the primary event vertex 
00147       reco::VertexCollection::const_iterator vtx = vertexCollection->begin();
00148       vertexPos = GlobalPoint(vtx->x(),vtx->y(),vtx->z());
00149       // delta Z from vertex error
00150       deltaZatVTX = vtx->zError() * theNsigmaDz;
00151     }
00152   }
00153 
00154 
00155  // inizialize to the maximum possible value to avoit 
00156  // problems with TSCBL
00157 
00158   double deta = 0.4;
00159   double dphi = 0.6;
00160 
00161   // take into account the correct beanspot rotation
00162   if ( bsHandleFlag ) {
00163 
00164   const reco::BeamSpot& bs =  *bsHandle;
00165 
00166   TSCBLBuilderNoMaterial tscblBuilder;
00167   TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(muFTS,bs);
00168 
00169  
00170     // evaluate the dynamical region if possible
00171     if(tscbl.isValid()){
00172 
00173       PerigeeTrajectoryError trackPerigeeErrors = PerigeeConversions::ftsToPerigeeError(tscbl.trackStateAtPCA());
00174       GlobalVector pTrack = tscbl.trackStateAtPCA().momentum();
00175 
00176     // calculate deltaEta from deltaTheta
00177       double deltaTheta = trackPerigeeErrors.thetaError();
00178       double theta      = pTrack.theta();
00179       double sin_theta  = sin(theta);
00180 
00181     // get dEta and dPhi
00182       deta = theNsigmaEta*(1/fabs(sin_theta))*deltaTheta;
00183       dphi = theNsigmaPhi*(trackPerigeeErrors.phiError());
00184 
00185     }
00186  }
00187 
00188   /* Region_Parametrizations to take into account possible 
00189      L2 error matrix inconsistencies. Detailed Explanation in TWIKI
00190      page.
00191   */
00192   double region_dEta = 0;
00193   double region_dPhi = 0;
00194   double eta=0; double phi=0;
00195 
00196   // eta, pt parametrization from MC study
00197   float pt = fabs(mom.perp());
00198 
00199   if ( pt <= 10. ) {
00200      // angular coefficients
00201      float acoeff_Phi = (thePhiRegionPar2 - thePhiRegionPar1)/5;
00202      float acoeff_Eta = (theEtaRegionPar2 - theEtaRegionPar1)/5;
00203 
00204      eta = theEtaRegionPar1 + (acoeff_Eta)*(mom.perp()-5.);
00205      phi = thePhiRegionPar1 + (acoeff_Phi)*(mom.perp()-5.) ;
00206    }
00207    // parametrization 2nd bin in pt from MC study  
00208    if ( pt > 10. && pt < 100. ) {
00209      eta = theEtaRegionPar2;
00210      phi = thePhiRegionPar2;
00211    }
00212    // parametrization 3rd bin in pt from MC study
00213    if ( pt >= 100. ) {
00214      // angular coefficients
00215      float acoeff_Phi = (thePhiRegionPar1 - thePhiRegionPar2)/900;
00216      float acoeff_Eta = (theEtaRegionPar1 - theEtaRegionPar2)/900;
00217 
00218      eta = theEtaRegionPar2 + (acoeff_Eta)*(mom.perp()-100.);
00219      phi = thePhiRegionPar2 + (acoeff_Phi)*(mom.perp()-100.);
00220    }
00221 
00222   // decide to use either a parametrization or a dynamical region
00223   double region_dPhi1 = min(phi,dphi);
00224   double region_dEta1 = min(eta,deta);
00225 
00226   // minimum size
00227   region_dPhi = max(thePhiMin,region_dPhi1);
00228   region_dEta = max(theEtaMin,region_dEta1);
00229 
00230   float deltaZ = 0.0;
00231   // standard 15.9 is useVertex than region from vertexing
00232   if ( useVertex ) {
00233     deltaZ = max(theHalfZ,deltaZatVTX);
00234   } else { 
00235     deltaZ = theHalfZ;
00236   }
00237 
00238   float deltaR = theDeltaR;
00239   double minPt = max(theTkEscapePt,mom.perp()*0.6);
00240 
00241   RectangularEtaPhiTrackingRegion* region = 0;  
00242 
00243   if (useFixedRegion) {
00244      region_dEta = theEtaFixed;
00245      region_dPhi = thePhiFixed;
00246   }
00247 
00248   region = new RectangularEtaPhiTrackingRegion(dirVector, vertexPos,
00249                                                minPt, deltaR,
00250                                                deltaZ, region_dEta, region_dPhi,
00251                                                theOnDemand,
00252                                                true,/*default in the header*/
00253                                                theMeasurementTrackerName);
00254 
00255   LogDebug("MuonTrackingRegionBuilder")<<"the region parameters are:\n"
00256                                        <<"\n dirVector: "<<dirVector
00257                                        <<"\n vertexPos: "<<vertexPos
00258                                        <<"\n minPt: "<<minPt
00259                                        <<"\n deltaR:"<<deltaR
00260                                        <<"\n deltaZ:"<<deltaZ
00261                                        <<"\n region_dEta:"<<region_dEta
00262                                        <<"\n region_dPhi:"<<region_dPhi
00263                                        <<"\n on demand parameter: "<<theOnDemand;
00264 
00265   
00266   return region;
00267   
00268 }