CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/RecoTracker/TkMSParametrization/src/MSLayersKeeperX0AtEta.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkMSParametrization/interface/MSLayersKeeperX0AtEta.h"
00002 #include "RecoTracker/TkMSParametrization/interface/MultipleScatteringX0Data.h"
00003 #include "RecoTracker/TkMSParametrization/interface/MultipleScatteringGeometry.h"
00004 #include <algorithm>
00005 using namespace std;
00006 template <class T> T sqr( T t) {return t*t;}
00007 
00008 //------------------------------------------------------------------------------
00009 const MSLayersAtAngle & MSLayersKeeperX0AtEta::layers(float cotTheta) const
00010 {
00011   float eta = asinh(cotTheta);
00012   return theLayersData[idxBin(eta)];
00013 }
00014 
00015 //------------------------------------------------------------------------------
00016 float MSLayersKeeperX0AtEta::eta(int idxBin) const
00017 { return (idxBin+0.5-theHalfNBins)*theDeltaEta; }
00018 
00019 //------------------------------------------------------------------------------
00020 int MSLayersKeeperX0AtEta::idxBin(float eta) const
00021 {
00022   float ieta = eta/theDeltaEta;
00023   if ( fabs(ieta) >= theHalfNBins - 1.e-3)
00024     return (eta>0) ? max(2*theHalfNBins-1,0) : 0;
00025   else
00026     return int(ieta+theHalfNBins);
00027 }
00028 
00029 //------------------------------------------------------------------------------
00030 void MSLayersKeeperX0AtEta::init(const edm::EventSetup &iSetup)
00031 {
00032   if (isInitialised) return;
00033   isInitialised = true;
00034   const float BIG = 99999.;
00035 
00036   // set size from data file
00037   MultipleScatteringX0Data msX0data;
00038   theHalfNBins = msX0data.nBinsEta();
00039   float etaMax = msX0data.maxEta();
00040   theDeltaEta = (theHalfNBins!=0) ? etaMax/theHalfNBins : BIG;
00041 
00042   theLayersData = vector<MSLayersAtAngle>(max(2*theHalfNBins, 1));
00043   MultipleScatteringGeometry layout(iSetup);
00044   for (int idxbin = 0; idxbin < 2*theHalfNBins; idxbin++) {
00045     float etaValue = eta(idxbin);
00046     float cotTheta = sinh(etaValue);
00047 
00048     vector<MSLayer> layers = layout.detLayers(etaValue,0,iSetup);
00049     vector<MSLayer> tmplay = layout.otherLayers(etaValue,iSetup);
00050     layers.insert(layers.end(),tmplay.begin(),tmplay.end()); 
00051     sort(layers.begin(), layers.end()); 
00052     setX0(layers, etaValue, msX0data);
00053     theLayersData[idxbin] = MSLayersAtAngle(layers);
00054     PixelRecoPointRZ zero(0.,0.);
00055     PixelRecoLineRZ line( zero, cotTheta);
00056     vector<MSLayer>::iterator it;
00057     for (it = layers.begin(); it != layers.end(); it++) {
00058       float x0 = getDataX0(*it).x0;
00059       float sumX0D = theLayersData[idxbin].sumX0D(zero, 
00060           it->crossing(line).first); 
00061       setDataX0(*it, DataX0(x0, sumX0D, cotTheta));
00062       theLayersData[idxbin].update(*it);
00063     } 
00064   }
00065 
00066   // add layers not seen from nominal vertex but crossed if
00067   // vertex seperated from nominal by less than 3 sigma
00068   for (int idxbin = 0; idxbin < 2*theHalfNBins; idxbin++) {
00069     float etaValue = eta(idxbin);
00070     for (int isign=-1; isign <=1; isign+=2) {
00071       float z = isign*15.9;   //3 sigma from zero
00072       const MSLayersAtAngle & layersAtAngle = theLayersData[idxbin];
00073       vector<MSLayer> candidates = layout.detLayers( etaValue, z,iSetup);
00074       vector<MSLayer>::iterator it;
00075       for (it = candidates.begin(); it != candidates.end(); it++) {
00076         if (layersAtAngle.findLayer(*it)) continue;
00077         const MSLayer * found = 0;
00078         int bin = idxbin;
00079         while(!found) {
00080           bin--; if (bin < 0) break; 
00081           found = theLayersData[bin].findLayer(*it);
00082         }
00083         bin = idxbin;
00084         while(!found) {
00085           bin++; if (bin > 2*theHalfNBins-1) break;
00086           found = theLayersData[bin].findLayer(*it);
00087         }
00088         if (found) theLayersData[idxbin].update(*found);
00089       }
00090     }
00091   }
00092 
00093 // cout << "LAYERS, size=: "<<theLayersData.size()<< endl;
00094 /*
00095   for (int idxbin = 0; idxbin <= theHalfNBins; idxbin+=25) {
00096     float etaValue = eta(idxbin);
00097     const MSLayersAtAngle & layers= theLayersData[idxbin];
00098     cout << "ETA: "<< etaValue <<" (bin:"<<idxbin<<") #layers:"
00099          <<layers.size()<<endl;
00100     layers.print();
00101   }
00102   for (int idxbin = 2*theHalfNBins-1; idxbin > theHalfNBins; idxbin-=25) {
00103     float etaValue = eta(idxbin);
00104     const MSLayersAtAngle & layers= theLayersData[idxbin];
00105     cout << "ETA: "<< etaValue <<" (bin:"<<idxbin<<") #layers:"
00106          <<layers.size()<<endl;
00107     layers.print();
00108   }
00109 */
00110 }
00111 
00112 //------------------------------------------------------------------------------
00113 void MSLayersKeeperX0AtEta::setX0(
00114     vector<MSLayer>& layers, 
00115     float eta, 
00116     const SumX0AtEtaDataProvider & sumX0) const
00117 {
00118   const float BIG = 99999.;
00119   float cotTheta = sinh(eta);
00120   float sinTheta = 1/sqrt(1+sqr(cotTheta));
00121   float cosTheta = cotTheta*sinTheta;
00122 
00123   float sumX0atAngleLast = 0.;
00124   vector<MSLayer>::iterator il;
00125   for (il = layers.begin(); il != layers.end(); il++) {
00126     PixelRecoLineRZ line(PixelRecoPointRZ(0.,0.), cotTheta);
00127     float rL= (*il).crossing(line).first.r();
00128     float rN = (il+1 != layers.end()) ? (il+1)->crossing(line).first.r() : BIG;
00129     float rBound = (rL+rN)/2.;
00130     float sumX0atAngle = sumX0.sumX0atEta(eta,rBound);
00131    
00132     float dX0 = (il->face() == GeomDetEnumerators::barrel) ?
00133       (sumX0atAngle - sumX0atAngleLast)*sinTheta
00134       : (sumX0atAngle - sumX0atAngleLast)* fabs(cosTheta);
00135    
00136   setDataX0(*il,DataX0(dX0,0,cotTheta) );
00137     sumX0atAngleLast = sumX0atAngle;
00138   }
00139 }