CMS 3D CMS Logo

SiPixelErrorEstimation.cc

Go to the documentation of this file.
00001 
00002 // Package:          SiPixelErrorEstimation
00003 // Class:            SiPixelErrorEstimation
00004 // Original Author:  Gavril Giurgiu (JHU)
00005 // Created:          Fri May  4 17:48:24 CDT 2007
00006 
00007 #include <iostream>
00008 #include "CalibTracker/SiPixelErrorEstimation/interface/SiPixelErrorEstimation.h"
00009 
00010 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00011 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00012 
00013 #include "DataFormats/TrackReco/interface/Track.h"
00014 #include "DataFormats/DetId/interface/DetId.h" 
00015 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00016 
00017 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
00018 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00019 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00020 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00021 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00022 
00023 #include "Geometry/TrackerTopology/interface/RectangularPixelTopology.h"
00024 
00025 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
00026 
00027 
00028 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00029 
00030 
00031 using namespace std;
00032 using namespace edm;
00033 
00034 SiPixelErrorEstimation::SiPixelErrorEstimation(const edm::ParameterSet& ps):tfile_(0), ttree_all_hits_(0), ttree_track_hits_(0) 
00035 {
00036   //Read config file
00037   outputFile_ = ps.getUntrackedParameter<string>( "outputFile", "SiPixelErrorEstimation_Ntuple.root" );
00038   
00039   // Replace  "ctfWithMaterialTracks" with "generalTracks"
00040   //src_ = ps.getUntrackedParameter<std::string>( "src", "ctfWithMaterialTracks" );
00041   src_ = ps.getUntrackedParameter<std::string>( "src", "generalTracks" );
00042 
00043   checkType_ = ps.getParameter<bool>( "checkType" );
00044   genType_ = ps.getParameter<int>( "genType" );
00045   include_trk_hits_ = ps.getParameter<bool>( "include_trk_hits" );
00046 }
00047 
00048 SiPixelErrorEstimation::~SiPixelErrorEstimation()
00049 {}
00050 
00051 void SiPixelErrorEstimation::beginJob(const edm::EventSetup& es)
00052 {
00053   int bufsize = 64000;
00054 
00055   if ( include_trk_hits_ )
00056     {
00057       //tfile_ = new TFile ("SiPixelErrorEstimation_Ntuple.root" , "RECREATE");
00058       //const char* tmp_name = outputFile_.c_str();
00059       tfile_ = new TFile ( outputFile_.c_str() , "RECREATE");
00060       
00061       ttree_track_hits_ = new TTree("TrackHitNtuple", "TrackHitNtuple");
00062       
00063       ttree_track_hits_->Branch("evt", &evt, "evt/I", bufsize);
00064       ttree_track_hits_->Branch("run", &run, "run/I", bufsize);
00065       
00066       ttree_track_hits_->Branch("subdetId", &subdetId, "subdetId/I", bufsize);
00067       
00068       ttree_track_hits_->Branch("layer" , &layer , "layer/I" , bufsize);
00069       ttree_track_hits_->Branch("ladder", &ladder, "ladder/I", bufsize);
00070       ttree_track_hits_->Branch("mod"   , &mod   , "mod/I"   , bufsize);
00071       
00072       ttree_track_hits_->Branch("side"  , &side  , "side/I"  , bufsize);
00073       ttree_track_hits_->Branch("disk"  , &disk  , "disk/I"  , bufsize);
00074       ttree_track_hits_->Branch("blade" , &blade , "blade/I" , bufsize);
00075       ttree_track_hits_->Branch("panel" , &panel , "panel/I" , bufsize);
00076       ttree_track_hits_->Branch("plaq"  , &plaq  , "plaq/I"  , bufsize);
00077       
00078       ttree_track_hits_->Branch("half"   , &half   , "half/I"   , bufsize);
00079       ttree_track_hits_->Branch("flipped", &flipped, "flipped/I", bufsize);
00080       
00081       ttree_track_hits_->Branch("rechitx", &rechitx, "rechitx/F"    , bufsize);
00082       ttree_track_hits_->Branch("rechity", &rechity, "rechity/F"    , bufsize);
00083       ttree_track_hits_->Branch("rechitz", &rechitz, "rechitz/F"    , bufsize);
00084       
00085       ttree_track_hits_->Branch("rechiterrx", &rechiterrx, "rechiterrx/F" , bufsize);
00086       ttree_track_hits_->Branch("rechiterry", &rechiterry, "rechiterry/F" , bufsize);
00087       
00088       ttree_track_hits_->Branch("rechitresx", &rechitresx, "rechitresx/F" , bufsize);
00089       ttree_track_hits_->Branch("rechitresy", &rechitresy, "rechitresy/F" , bufsize);
00090       
00091       ttree_track_hits_->Branch("rechitpullx", &rechitpullx, "rechitpullx/F", bufsize);
00092       ttree_track_hits_->Branch("rechitpully", &rechitpully, "rechitpully/F", bufsize);
00093       
00094       ttree_track_hits_->Branch("npix"  , &npix  , "npix/I"  , bufsize);
00095       ttree_track_hits_->Branch("nxpix" , &nxpix , "nxpix/I" , bufsize);
00096       ttree_track_hits_->Branch("nypix" , &nypix , "nypix/I" , bufsize);
00097       ttree_track_hits_->Branch("charge", &charge, "charge/F", bufsize);
00098       
00099       ttree_track_hits_->Branch("edgex", &edgex, "edgex/I", bufsize);
00100       ttree_track_hits_->Branch("edgey", &edgey, "edgey/I", bufsize);
00101       
00102       ttree_track_hits_->Branch("bigx", &bigx, "bigx/I", bufsize);
00103       ttree_track_hits_->Branch("bigy", &bigy, "bigy/I", bufsize);
00104       
00105       ttree_track_hits_->Branch("alpha", &alpha, "alpha/F", bufsize);
00106       ttree_track_hits_->Branch("beta" , &beta , "beta/F" , bufsize);
00107       
00108       ttree_track_hits_->Branch("trk_alpha", &trk_alpha, "trk_alpha/F", bufsize);
00109       ttree_track_hits_->Branch("trk_beta" , &trk_beta , "trk_beta/F" , bufsize);
00110 
00111       ttree_track_hits_->Branch("phi", &phi, "phi/F", bufsize);
00112       ttree_track_hits_->Branch("eta", &eta, "eta/F", bufsize);
00113       
00114       ttree_track_hits_->Branch("simhitx", &simhitx, "simhitx/F", bufsize);
00115       ttree_track_hits_->Branch("simhity", &simhity, "simhity/F", bufsize);
00116       
00117       ttree_track_hits_->Branch("nsimhit", &nsimhit, "nsimhit/I", bufsize);
00118       ttree_track_hits_->Branch("pidhit" , &pidhit , "pidhit/I" , bufsize);
00119       ttree_track_hits_->Branch("simproc", &simproc, "simproc/I", bufsize);
00120     } // if ( include_trk_hits_ )
00121 
00122   // ----------------------------------------------------------------------
00123   
00124   ttree_all_hits_ = new TTree("AllHitNtuple", "AllHitNtuple");
00125 
00126   ttree_all_hits_->Branch("evt", &evt, "evt/I", bufsize);
00127   ttree_all_hits_->Branch("run", &run, "run/I", bufsize);
00128 
00129   ttree_all_hits_->Branch("subdetid", &all_subdetid, "subdetid/I", bufsize);
00130   
00131   ttree_all_hits_->Branch("layer" , &all_layer , "layer/I" , bufsize);
00132   ttree_all_hits_->Branch("ladder", &all_ladder, "ladder/I", bufsize);
00133   ttree_all_hits_->Branch("mod"   , &all_mod   , "mod/I"   , bufsize);
00134   
00135   ttree_all_hits_->Branch("side"  , &all_side  , "side/I"  , bufsize);
00136   ttree_all_hits_->Branch("disk"  , &all_disk  , "disk/I"  , bufsize);
00137   ttree_all_hits_->Branch("blade" , &all_blade , "blade/I" , bufsize);
00138   ttree_all_hits_->Branch("panel" , &all_panel , "panel/I" , bufsize);
00139   ttree_all_hits_->Branch("plaq"  , &all_plaq  , "plaq/I"  , bufsize);
00140 
00141   ttree_all_hits_->Branch("half"   , &all_half   , "half/I"   , bufsize);
00142   ttree_all_hits_->Branch("flipped", &all_flipped, "flipped/I", bufsize);
00143 
00144   ttree_all_hits_->Branch("cols", &all_cols, "cols/I", bufsize);
00145   ttree_all_hits_->Branch("rows", &all_rows, "rows/I", bufsize);
00146 
00147   ttree_all_hits_->Branch("rechitx"    , &all_rechitx    , "rechitx/F"    , bufsize);
00148   ttree_all_hits_->Branch("rechity"    , &all_rechity    , "rechity/F"    , bufsize);
00149   ttree_all_hits_->Branch("rechitz"    , &all_rechitz    , "rechitz/F"    , bufsize);
00150  
00151   ttree_all_hits_->Branch("rechiterrx" , &all_rechiterrx , "rechiterrx/F" , bufsize);
00152   ttree_all_hits_->Branch("rechiterry" , &all_rechiterry , "rechiterry/F" , bufsize);
00153   
00154   ttree_all_hits_->Branch("rechitresx" , &all_rechitresx , "rechitresx/F" , bufsize);
00155   ttree_all_hits_->Branch("rechitresy" , &all_rechitresy , "rechitresy/F" , bufsize);
00156   
00157   ttree_all_hits_->Branch("rechitpullx", &all_rechitpullx, "rechitpullx/F", bufsize);
00158   ttree_all_hits_->Branch("rechitpully", &all_rechitpully, "rechitpully/F", bufsize);
00159 
00160   ttree_all_hits_->Branch("npix"  , &all_npix  , "npix/I"  , bufsize);
00161   ttree_all_hits_->Branch("nxpix" , &all_nxpix , "nxpix/I" , bufsize);
00162   ttree_all_hits_->Branch("nypix" , &all_nypix , "nypix/I" , bufsize);
00163 
00164   ttree_all_hits_->Branch("edgex", &all_edgex, "edgex/I", bufsize);
00165   ttree_all_hits_->Branch("edgey", &all_edgey, "edgey/I", bufsize);
00166  
00167   ttree_all_hits_->Branch("bigx", &all_bigx, "bigx/I", bufsize);
00168   ttree_all_hits_->Branch("bigy", &all_bigy, "bigy/I", bufsize);
00169   
00170   ttree_all_hits_->Branch("alpha", &all_alpha, "alpha/F", bufsize);
00171   ttree_all_hits_->Branch("beta" , &all_beta , "beta/F" , bufsize);
00172 
00173   ttree_all_hits_->Branch("simhitx", &all_simhitx, "simhitx/F", bufsize);
00174   ttree_all_hits_->Branch("simhity", &all_simhity, "simhity/F", bufsize);
00175 
00176   ttree_all_hits_->Branch("nsimhit", &all_nsimhit, "nsimhit/I", bufsize);
00177   ttree_all_hits_->Branch("pidhit" , &all_pidhit , "pidhit/I" , bufsize);
00178   ttree_all_hits_->Branch("simproc", &all_simproc, "simproc/I", bufsize);
00179 
00180   ttree_all_hits_->Branch("vtxr", &all_vtxr, "vtxr/F", bufsize);
00181   ttree_all_hits_->Branch("vtxz", &all_vtxz, "vtxz/F", bufsize);
00182 
00183   ttree_all_hits_->Branch("simpx", &all_simpx, "simpx/F", bufsize);
00184   ttree_all_hits_->Branch("simpy", &all_simpy, "simpy/F", bufsize);
00185   ttree_all_hits_->Branch("simpz", &all_simpz, "simpz/F", bufsize);
00186 
00187   ttree_all_hits_->Branch("eloss", &all_eloss, "eloss/F", bufsize);
00188   
00189   ttree_all_hits_->Branch("simphi", &all_simphi, "simphi/F", bufsize);
00190   ttree_all_hits_->Branch("simtheta", &all_simtheta, "simtheta/F", bufsize);
00191   
00192   ttree_all_hits_->Branch("trkid", &all_trkid, "trkid/I", bufsize);
00193   
00194   ttree_all_hits_->Branch("x1", &all_x1, "x1/F", bufsize);
00195   ttree_all_hits_->Branch("x2", &all_x2, "x2/F", bufsize);
00196   ttree_all_hits_->Branch("y1", &all_x1, "y1/F", bufsize);
00197   ttree_all_hits_->Branch("y2", &all_x2, "y2/F", bufsize);
00198   ttree_all_hits_->Branch("z1", &all_x1, "z1/F", bufsize);
00199   ttree_all_hits_->Branch("z2", &all_x2, "z2/F", bufsize);
00200 
00201   ttree_all_hits_->Branch("row1", &all_row1, "row1/F", bufsize);
00202   ttree_all_hits_->Branch("row2", &all_row2, "row2/F", bufsize);
00203   ttree_all_hits_->Branch("col1", &all_col1, "col1/F", bufsize);
00204   ttree_all_hits_->Branch("col2", &all_col2, "col2/F", bufsize);
00205 
00206   ttree_all_hits_->Branch("gx1", &all_gx1, "gx1/F", bufsize);
00207   ttree_all_hits_->Branch("gx2", &all_gx2, "gx2/F", bufsize);
00208   ttree_all_hits_->Branch("gy1", &all_gx1, "gy1/F", bufsize);
00209   ttree_all_hits_->Branch("gy2", &all_gx2, "gy2/F", bufsize);
00210   ttree_all_hits_->Branch("gz1", &all_gx1, "gz1/F", bufsize);
00211   ttree_all_hits_->Branch("gz2", &all_gx2, "gz2/F", bufsize);
00212   
00213   ttree_all_hits_->Branch("simtrketa", &all_simtrketa, "simtrketa/F", bufsize);
00214   ttree_all_hits_->Branch("simtrkphi", &all_simtrkphi, "simtrkphi/F", bufsize);
00215 
00216   ttree_all_hits_->Branch("clust_row", &all_clust_row, "clust_row/F", bufsize);
00217   ttree_all_hits_->Branch("clust_col", &all_clust_col, "clust_col/F", bufsize);
00218   
00219   ttree_all_hits_->Branch("clust_x", &all_clust_x, "clust_x/F", bufsize);
00220   ttree_all_hits_->Branch("clust_y", &all_clust_y, "clust_y/F", bufsize);
00221 
00222   ttree_all_hits_->Branch("clust_q", &all_clust_q, "clust_q/F", bufsize);
00223 
00224   ttree_all_hits_->Branch("clust_maxpixcol", &all_clust_maxpixcol, "clust_maxpixcol/I", bufsize);
00225   ttree_all_hits_->Branch("clust_maxpixrow", &all_clust_maxpixrow, "clust_maxpixrow/I", bufsize);
00226   ttree_all_hits_->Branch("clust_minpixcol", &all_clust_minpixcol, "clust_minpixcol/I", bufsize);
00227   ttree_all_hits_->Branch("clust_minpixrow", &all_clust_minpixrow, "clust_minpixrow/I", bufsize);
00228   
00229   ttree_all_hits_->Branch("clust_geoid", &all_clust_geoid, "clust_geoid/I", bufsize);
00230   
00231   ttree_all_hits_->Branch("clust_alpha", &all_clust_alpha, "clust_alpha/F", bufsize);
00232   ttree_all_hits_->Branch("clust_beta" , &all_clust_beta , "clust_beta/F" , bufsize);
00233 
00234   ttree_all_hits_->Branch("rowpix", all_pixrow, "row[npix]/F", bufsize);
00235   ttree_all_hits_->Branch("colpix", all_pixcol, "col[npix]/F", bufsize);
00236   ttree_all_hits_->Branch("adc", all_pixadc, "adc[npix]/F", bufsize);
00237   ttree_all_hits_->Branch("xpix", all_pixx, "x[npix]/F", bufsize);
00238   ttree_all_hits_->Branch("ypix", all_pixy, "y[npix]/F", bufsize);
00239   ttree_all_hits_->Branch("gxpix", all_pixgx, "gx[npix]/F", bufsize);
00240   ttree_all_hits_->Branch("gypix", all_pixgy, "gy[npix]/F", bufsize);
00241   ttree_all_hits_->Branch("gzpix", all_pixgz, "gz[npix]/F", bufsize);
00242   
00243   ttree_all_hits_->Branch("hit_probx", &all_hit_probx, "hit_probx/F" , bufsize);
00244   ttree_all_hits_->Branch("hit_proby", &all_hit_proby, "hit_proby/F" , bufsize);
00245 
00246 }
00247 
00248 void SiPixelErrorEstimation::endJob() 
00249 {
00250   tfile_->Write();
00251   tfile_->Close();
00252 }
00253 
00254 void
00255 SiPixelErrorEstimation::analyze(const edm::Event& e, const edm::EventSetup& es)
00256 {
00257   using namespace edm;
00258   
00259   run = e.id().run();
00260   evt = e.id().event();
00261   
00262   if ( evt%1000 == 0 ) 
00263     cout << "evt = " << evt << endl;
00264 
00265   float math_pi = 3.14159265;
00266   float radtodeg = 180.0 / math_pi;
00267     
00268   DetId detId;
00269 
00270   LocalPoint position;
00271   LocalError error;
00272   float mindist = 999999.9;
00273 
00274   std::vector<PSimHit> matched;
00275   TrackerHitAssociator associate(e);
00276 
00277   edm::ESHandle<TrackerGeometry> pDD;
00278   es.get<TrackerDigiGeometryRecord> ().get (pDD);
00279   const TrackerGeometry* tracker = &(* pDD);
00280         
00281   // --------------------------------------- all hits -----------------------------------------------------------
00282   edm::Handle<SiPixelRecHitCollection> recHitColl;
00283   e.getByLabel( "siPixelRecHits", recHitColl);
00284 
00285   Handle<edm::SimTrackContainer> simtracks;
00286   e.getByLabel("g4SimHits", simtracks);
00287 
00288   //-----Iterate over detunits
00289   for (TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++) 
00290     {
00291       DetId detId = ((*it)->geographicalId());
00292       
00293       SiPixelRecHitCollection::range pixelrechitRange = (recHitColl.product())->get(detId);
00294       SiPixelRecHitCollection::const_iterator pixelrechitRangeIteratorBegin = pixelrechitRange.first;
00295       SiPixelRecHitCollection::const_iterator pixelrechitRangeIteratorEnd = pixelrechitRange.second;
00296       SiPixelRecHitCollection::const_iterator pixeliter = pixelrechitRangeIteratorBegin;
00297       std::vector<PSimHit> matched;
00298       
00299       //----Loop over rechits for this detId
00300       for ( ; pixeliter != pixelrechitRangeIteratorEnd; ++pixeliter) 
00301         {
00302           matched.clear();
00303           matched = associate.associateHit(*pixeliter);
00304           // only consider rechits that have associated simhit
00305           // otherwise cannot determine residiual
00306           if ( matched.empty() )
00307             {
00308               cout << "SiPixelErrorEstimation::analyze: rechits without associated simhit !!!!!!!" 
00309                    << endl;
00310               continue;
00311             }
00312                 
00313           all_subdetid = -9999;
00314           
00315           all_layer = -9999;
00316           all_ladder = -9999;
00317           all_mod = -9999;
00318           
00319           all_side = -9999;
00320           all_disk = -9999;
00321           all_blade = -9999;
00322           all_panel = -9999;
00323           all_plaq = -9999;
00324           
00325           all_half = -9999;
00326           all_flipped = -9999;
00327           
00328           all_cols = -9999;
00329           all_rows = -9999;
00330           
00331           all_rechitx = -9999;
00332           all_rechity = -9999;
00333           all_rechitz = -9999;
00334           
00335           all_simhitx = -9999;
00336           all_simhity = -9999;
00337 
00338           all_rechiterrx = -9999;
00339           all_rechiterry = -9999;
00340           
00341           all_rechitresx = -9999;
00342           all_rechitresy = -9999;
00343           
00344           all_rechitpullx = -9999;
00345           all_rechitpully = -9999;
00346           
00347           all_npix = -9999;
00348           all_nxpix = -9999;
00349           all_nypix = -9999;
00350                   
00351           all_edgex = -9999;
00352           all_edgey = -9999;
00353           
00354           all_bigx = -9999;
00355           all_bigy = -9999;
00356           
00357           all_alpha = -9999;
00358           all_beta = -9999;
00359           
00360           all_simphi = -9999;
00361           all_simtheta = -9999;
00362           
00363           all_simhitx = -9999;
00364           all_simhity = -9999;
00365           
00366           all_nsimhit = -9999;
00367           all_pidhit = -9999;
00368           all_simproc = -9999;
00369           
00370           all_vtxr = -9999;
00371           all_vtxz = -9999;
00372           
00373           all_simpx = -9999;
00374           all_simpy = -9999;
00375           all_simpz = -9999;
00376           
00377           all_eloss = -9999;
00378                   
00379           all_trkid = -9999;
00380           
00381           all_x1 = -9999;
00382           all_x2 = -9999;
00383           all_y1 = -9999;
00384           all_y2 = -9999;
00385           all_z1 = -9999;
00386           all_z2 = -9999;
00387           
00388           all_row1 = -9999;
00389           all_row2 = -9999;
00390           all_col1 = -9999;
00391           all_col2 = -9999;
00392           
00393           all_gx1 = -9999;
00394           all_gx2 = -9999;
00395           all_gy1 = -9999;
00396           all_gy2 = -9999;
00397           all_gz1 = -9999;
00398           all_gz2 = -9999;
00399           
00400           all_simtrketa = -9999;
00401           all_simtrkphi = -9999;
00402           
00403           all_clust_row = -9999;
00404           all_clust_col = -9999;
00405           
00406           all_clust_x = -9999;
00407           all_clust_y = -9999;
00408           
00409           all_clust_q = -9999;
00410           
00411           all_clust_maxpixcol = -9999;
00412           all_clust_maxpixrow = -9999;
00413           all_clust_minpixcol = -9999;
00414           all_clust_minpixrow = -9999;
00415           
00416           all_clust_geoid = -9999;
00417           
00418           all_clust_alpha = -9999;
00419           all_clust_beta = -9999;
00420           
00421           /*
00422             for (int i=0; i<all_npix; ++i)
00423             {
00424             all_pixrow[i] = -9999;
00425             all_pixcol[i] = -9999;
00426             all_pixadc[i] = -9999;
00427             all_pixx[i] = -9999;
00428             all_pixy[i] = -9999;
00429             all_pixgx[i] = -9999;
00430             all_pixgy[i] = -9999;
00431             all_pixgz[i] = -9999;
00432             }
00433           */
00434 
00435           all_hit_probx = -9999;
00436           all_hit_proby = -9999;
00437           
00438           all_nsimhit = (int)matched.size();
00439           
00440           all_subdetid = (int)detId.subdetId();
00441           // only consider rechits in pixel barrel and pixel forward 
00442           if ( !(all_subdetid==1 || all_subdetid==2) ) 
00443             {
00444               cout << "SiPixelErrorEstimation::analyze: Not in a pixel detector !!!!!" << endl; 
00445               continue;
00446             }
00447 
00448           const PixelGeomDetUnit* theGeomDet 
00449             = dynamic_cast<const PixelGeomDetUnit*> ( tracker->idToDet(detId) );
00450           
00451           const RectangularPixelTopology* topol = 
00452             dynamic_cast<const RectangularPixelTopology*>(&(theGeomDet->specificTopology()));
00453 
00454           const int maxPixelCol = pixeliter->cluster()->maxPixelCol();
00455           const int maxPixelRow = pixeliter->cluster()->maxPixelRow();
00456           const int minPixelCol = pixeliter->cluster()->minPixelCol();
00457           const int minPixelRow = pixeliter->cluster()->minPixelRow();
00458           
00459           // check whether the cluster is at the module edge 
00460           if ( topol->isItEdgePixelInX( minPixelRow ) || 
00461                topol->isItEdgePixelInX( maxPixelRow ) )
00462             all_edgex = 1;
00463           else 
00464             all_edgex = 0;
00465           
00466           if ( topol->isItEdgePixelInY( minPixelCol ) || 
00467                topol->isItEdgePixelInY( maxPixelCol ) )
00468             all_edgey = 1;
00469           else 
00470             all_edgey = 0;
00471           
00472           // check whether this rechit contains big pixels
00473           if ( topol->containsBigPixelInX(minPixelRow, maxPixelRow) )
00474             all_bigx = 1;
00475           else 
00476             all_bigx = 0;
00477           
00478           if ( topol->containsBigPixelInY(minPixelCol, maxPixelCol) )
00479             all_bigy = 1;
00480           else 
00481             all_bigy = 0;
00482           
00483           if ( (int)detId.subdetId() == (int)PixelSubdetector::PixelBarrel ) 
00484             {
00485               PXBDetId bdetid(detId);
00486               all_layer = bdetid.layer();
00487               all_ladder = bdetid.ladder();
00488               all_mod = bdetid.module();
00489               
00490               int tmp_nrows = theGeomDet->specificTopology().nrows();
00491               if ( tmp_nrows == 80 ) 
00492                 all_half = 1;
00493               else if ( tmp_nrows == 160 ) 
00494                 all_half = 0;
00495               else 
00496                 cout << "-------------------------------------------------- Wrong module size !!!" << endl;
00497               
00498               float tmp1 = theGeomDet->surface().toGlobal(Local3DPoint(0.,0.,0.)).perp();
00499               float tmp2 = theGeomDet->surface().toGlobal(Local3DPoint(0.,0.,1.)).perp();
00500               
00501               if ( tmp2<tmp1 ) 
00502                 all_flipped = 1;
00503               else 
00504                 all_flipped = 0;
00505             }
00506           else if ( (int)detId.subdetId() == (int)PixelSubdetector::PixelEndcap )
00507             {
00508               PXFDetId fdetid(detId);
00509               all_side  = fdetid.side();
00510               all_disk  = fdetid.disk();
00511               all_blade = fdetid.blade();
00512               all_panel = fdetid.panel();
00513               all_plaq  = fdetid.module(); // also known as plaquette
00514               
00515             } // else if ( detId.subdetId()==PixelSubdetector::PixelEndcap )
00516           else std::cout << "We are not in the pixel detector" << (int)detId.subdetId() << endl;
00517           
00518           all_cols = theGeomDet->specificTopology().ncolumns();
00519           all_rows = theGeomDet->specificTopology().nrows();
00520                   
00521           LocalPoint lp = pixeliter->localPosition();
00522           // gavril: change this name
00523           all_rechitx = lp.x();
00524           all_rechity = lp.y();
00525           all_rechitz = lp.z();
00526           
00527           LocalError le = pixeliter->localPositionError();
00528           all_rechiterrx = sqrt( le.xx() );
00529           all_rechiterry = sqrt( le.yy() );
00530 
00531           bool found_hit_from_generated_particle = false;
00532           
00533           //---Loop over sim hits, fill closest
00534           float closest_dist = 99999.9;
00535           std::vector<PSimHit>::const_iterator closest_simhit = matched.begin();
00536           
00537           for (std::vector<PSimHit>::const_iterator m = matched.begin(); m < matched.end(); m++) 
00538             {
00539               if ( checkType_ )
00540                 {
00541                   int pid = (*m).particleType();
00542                   if ( abs(pid) != genType_ )
00543                     continue;
00544                 } 
00545               
00546               float simhitx = 0.5 * ( (*m).entryPoint().x() + (*m).exitPoint().x() );
00547               float simhity = 0.5 * ( (*m).entryPoint().y() + (*m).exitPoint().y() );
00548               
00549               float x_res = simhitx - rechitx;
00550               float y_res = simhity - rechity;
00551                   
00552               float dist = sqrt( x_res*x_res + y_res*y_res );             
00553               
00554               if ( dist < closest_dist ) 
00555                 {
00556                   closest_dist = dist;
00557                   closest_simhit = m;
00558                   found_hit_from_generated_particle = true;
00559                 } 
00560             } // end sim hit loop
00561           
00562           // If this recHit does not have any simHit with the same particleType as the particles generated
00563           // ignore it as most probably comes from delta rays.
00564           if ( checkType_ && !found_hit_from_generated_particle )
00565             continue; 
00566 
00567           all_x1 = (*closest_simhit).entryPoint().x(); // width (row index, in col direction)
00568           all_y1 = (*closest_simhit).entryPoint().y(); // length (col index, in row direction) 
00569           all_z1 = (*closest_simhit).entryPoint().z(); 
00570           all_x2 = (*closest_simhit).exitPoint().x();
00571           all_y2 = (*closest_simhit).exitPoint().y();
00572           all_z2 = (*closest_simhit).exitPoint().z();
00573           GlobalPoint GP1 = 
00574             theGeomDet->surface().toGlobal( Local3DPoint( (*closest_simhit).entryPoint().x(),
00575                                                           (*closest_simhit).entryPoint().y(),
00576                                                           (*closest_simhit).entryPoint().z() ) );
00577           GlobalPoint GP2 = 
00578             theGeomDet->surface().toGlobal (Local3DPoint( (*closest_simhit).exitPoint().x(),
00579                                                           (*closest_simhit).exitPoint().y(),
00580                                                           (*closest_simhit).exitPoint().z() ) );
00581           all_gx1 = GP1.x();
00582           all_gx2 = GP2.x();
00583           all_gy1 = GP1.y();
00584           all_gy2 = GP2.y();
00585           all_gz1 = GP1.z();
00586           all_gz2 = GP2.z();
00587           
00588           MeasurementPoint mp1 =
00589             topol->measurementPosition( LocalPoint( (*closest_simhit).entryPoint().x(),
00590                                                     (*closest_simhit).entryPoint().y(),
00591                                                     (*closest_simhit).entryPoint().z() ) );
00592           MeasurementPoint mp2 =
00593             topol->measurementPosition( LocalPoint( (*closest_simhit).exitPoint().x(),
00594                                                     (*closest_simhit).exitPoint().y(), 
00595                                                     (*closest_simhit).exitPoint().z() ) );
00596           all_row1 = mp1.x();
00597           all_col1 = mp1.y();
00598           all_row2 = mp2.x();
00599           all_col2 = mp2.y();
00600           
00601           all_simhitx = 0.5*(all_x1+all_x2);  
00602           all_simhity = 0.5*(all_y1+all_y2);  
00603           
00604           all_rechitresx = all_rechitx - all_simhitx;
00605           all_rechitresy = all_rechity - all_simhity;
00606 
00607           all_rechitpullx = all_rechitresx / all_rechiterrx;
00608           all_rechitpully = all_rechitresy / all_rechiterry;
00609           
00610           SiPixelRecHit::ClusterRef const& clust = pixeliter->cluster();
00611           
00612           all_npix = clust->size();
00613           all_nxpix = clust->sizeX();
00614           all_nypix = clust->sizeY();
00615 
00616           all_clust_row = clust->x();
00617           all_clust_col = clust->y();
00618           
00619           LocalPoint lp2 = topol->localPosition( MeasurementPoint( all_clust_row, all_clust_col ) );
00620           all_clust_x = lp2.x();
00621           all_clust_y = lp2.y();
00622 
00623           all_clust_q = clust->charge();
00624 
00625           all_clust_maxpixcol = clust->maxPixelCol();
00626           all_clust_maxpixrow = clust->maxPixelRow();
00627           all_clust_minpixcol = clust->minPixelCol();
00628           all_clust_minpixrow = clust->minPixelRow();
00629           
00630           all_clust_geoid = clust->geographicalId();
00631   
00632           all_simpx  = (*closest_simhit).momentumAtEntry().x();
00633           all_simpy  = (*closest_simhit).momentumAtEntry().y();
00634           all_simpz  = (*closest_simhit).momentumAtEntry().z();
00635           all_eloss = (*closest_simhit).energyLoss();
00636           all_simphi   = (*closest_simhit).phiAtEntry();
00637           all_simtheta = (*closest_simhit).thetaAtEntry();
00638           all_pidhit = (*closest_simhit).particleType();
00639           all_trkid = (*closest_simhit).trackId();
00640           
00641           //--- Fill alpha and beta -- more useful for exploring the residuals...
00642           all_beta  = atan2(all_simpz, all_simpy);
00643           all_alpha = atan2(all_simpz, all_simpx);
00644           
00645           all_simproc = (int)closest_simhit->processType();
00646           
00647           const edm::SimTrackContainer& trks = *(simtracks.product());
00648           SimTrackContainer::const_iterator trksiter;
00649           for (trksiter = trks.begin(); trksiter != trks.end(); trksiter++) 
00650             if ( (int)trksiter->trackId() == all_trkid ) 
00651               {
00652                 all_simtrketa = trksiter->momentum().eta();
00653                 all_simtrkphi = trksiter->momentum().phi();
00654               }
00655           
00656           all_vtxz = theGeomDet->surface().position().z();
00657           all_vtxr = theGeomDet->surface().position().perp();
00658           
00659           //computeAnglesFromDetPosition(clust, 
00660           //                   theGeomDet, 
00661           //                   all_clust_alpha, all_clust_beta )
00662 
00663           const std::vector<SiPixelCluster::Pixel>& pixvector = clust->pixels();
00664           for ( int i=0;  i<(int)pixvector.size(); ++i)
00665             {
00666               SiPixelCluster::Pixel holdpix = pixvector[i];
00667               all_pixrow[i] = holdpix.x;
00668               all_pixcol[i] = holdpix.y;
00669               all_pixadc[i] = holdpix.adc;
00670               LocalPoint lp = topol->localPosition(MeasurementPoint(holdpix.x, holdpix.y));
00671               all_pixx[i] = lp.x();
00672               all_pixy[i]= lp.y();
00673               GlobalPoint GP =  theGeomDet->surface().toGlobal(Local3DPoint(lp.x(),lp.y(),lp.z()));
00674               all_pixgx[i] = GP.x();    
00675               all_pixgy[i]= GP.y();
00676               all_pixgz[i]= GP.z();
00677             }
00678           
00679           ttree_all_hits_->Fill();
00680           
00681         } // for ( ; pixeliter != pixelrechitRangeIteratorEnd; ++pixeliter) 
00682     } // for (TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++) 
00683  
00684   // ------------------------------------------------ all hits ---------------------------------------------------------------
00685   
00686 
00687   // ------------------------------------------------ track hits only -------------------------------------------------------- 
00688   
00689   if ( include_trk_hits_ )
00690     {
00691       // Get tracks
00692       edm::Handle<reco::TrackCollection> trackCollection;
00693       e.getByLabel(src_, trackCollection);
00694       const reco::TrackCollection *tracks = trackCollection.product();
00695       reco::TrackCollection::const_iterator tciter;
00696       
00697       if ( tracks->size() > 0 )
00698         {
00699           // Loop on tracks
00700           for ( tciter=tracks->begin(); tciter!=tracks->end(); ++tciter)
00701             {
00702               // First loop on hits: find matched hits
00703               for ( trackingRecHit_iterator it = tciter->recHitsBegin(); it != tciter->recHitsEnd(); ++it) 
00704                 {
00705                   const TrackingRecHit &thit = **it;
00706                   // Is it a matched hit?
00707                   const SiPixelRecHit* matchedhit = dynamic_cast<const SiPixelRecHit*>(&thit);
00708                   
00709                   if ( matchedhit ) 
00710                     {
00711                       rechitx = -9999.9;
00712                       rechity = -9999.9;
00713                       rechitz = -9999.9;
00714                       rechiterrx = -9999.9;
00715                       rechiterry = -9999.9;                   
00716                       rechitresx = -9999.9;
00717                       rechitresy = -9999.9;
00718                       rechitpullx = -9999.9;
00719                       rechitpully = -9999.9;
00720                       
00721                       npix = -9999;
00722                       nxpix = -9999;
00723                       nypix = -9999;
00724                       charge = -9999.9;
00725                       
00726                       edgex = -9999;
00727                       edgey = -9999;
00728                       
00729                       bigx = -9999;
00730                       bigy = -9999;
00731                       
00732                       alpha = -9999.9;
00733                       beta  = -9999.9;
00734                       
00735                       phi = -9999.9;
00736                       eta = -9999.9;
00737                       
00738                       subdetId = -9999;
00739                       
00740                       layer  = -9999; 
00741                       ladder = -9999; 
00742                       mod    = -9999; 
00743                       side   = -9999;  
00744                       disk   = -9999;  
00745                       blade  = -9999; 
00746                       panel  = -9999; 
00747                       plaq   = -9999; 
00748                       
00749                       half = -9999;
00750                       flipped = -9999;
00751                       
00752                       nsimhit = -9999;
00753                       pidhit  = -9999;
00754                       simproc = -9999;
00755                       
00756                       simhitx = -9999.9;
00757                       simhity = -9999.9;
00758                       
00759                       position = (*it)->localPosition();
00760                       error = (*it)->localPositionError();
00761                       
00762                       rechitx = position.x();
00763                       rechity = position.y();
00764                       rechitz = position.z();
00765                       rechiterrx = sqrt(error.xx());
00766                       rechiterry = sqrt(error.yy());
00767                       
00768                       npix = matchedhit->cluster()->size();
00769                       nxpix = matchedhit->cluster()->sizeX();
00770                       nypix = matchedhit->cluster()->sizeY();
00771                       charge = matchedhit->cluster()->charge();
00772                       
00773                       //Association of the rechit to the simhit
00774                       matched.clear();
00775                       matched = associate.associateHit(*matchedhit);
00776                       
00777                       nsimhit = (int)matched.size();
00778                       
00779                       if ( !matched.empty() ) 
00780                         {
00781                           mindist = 999999.9;
00782                           float distx, disty, dist;
00783                           bool found_hit_from_generated_particle = false;
00784                           
00785                           int n_assoc_muon = 0;
00786                           
00787                           vector<PSimHit>::const_iterator closestit = matched.begin();
00788                           for (vector<PSimHit>::const_iterator m=matched.begin(); m<matched.end(); ++m)
00789                             {
00790                               if ( checkType_ )
00791                                 { // only consider associated simhits with the generated pid (muons)
00792                                   int pid = (*m).particleType();
00793                                   if ( abs(pid) != genType_ )
00794                                     continue;
00795                                 }
00796                               
00797                               float simhitx = 0.5 * ( (*m).entryPoint().x() + (*m).exitPoint().x() );
00798                               float simhity = 0.5 * ( (*m).entryPoint().y() + (*m).exitPoint().y() );
00799                               
00800                               distx = fabs(rechitx - simhitx);
00801                               disty = fabs(rechity - simhity);
00802                               dist = sqrt( distx*distx + disty*disty );
00803                               
00804                               if ( dist < mindist )
00805                                 {
00806                                   n_assoc_muon++;
00807                                   
00808                                   mindist = dist;
00809                                   closestit = m;
00810                                   found_hit_from_generated_particle = true;
00811                                 }
00812                             } // for (vector<PSimHit>::const_iterator m=matched.begin(); m<matched.end(); m++)
00813                           
00814                           // This recHit does not have any simHit with the same particleType as the particles generated
00815                           // Ignore it as most probably come from delta rays.
00816                           if ( checkType_ && !found_hit_from_generated_particle )
00817                             continue; 
00818                           
00819                           //if ( n_assoc_muon > 1 )
00820                           //{
00821                           //  cout << " ----- This is not good: n_assoc_muon = " << n_assoc_muon << endl;
00822                           //  cout << "evt = " << evt << endl;
00823                           //}
00824                           
00825                           detId = (*it)->geographicalId();
00826 
00827                           const PixelGeomDetUnit* theGeomDet =
00828                             dynamic_cast<const PixelGeomDetUnit*> ((*tracker).idToDet(detId) );
00829                           
00830                           const RectangularPixelTopology* theTopol = 
00831                             dynamic_cast<const RectangularPixelTopology*>(&(theGeomDet->specificTopology()));
00832 
00833                           pidhit = (*closestit).particleType();
00834                           simproc = (int)(*closestit).processType();
00835                           
00836                           simhitx = 0.5*( (*closestit).entryPoint().x() + (*closestit).exitPoint().x() );
00837                           simhity = 0.5*( (*closestit).entryPoint().y() + (*closestit).exitPoint().y() );
00838                           
00839                           rechitresx = rechitx - simhitx;
00840                           rechitresy = rechity - simhity;
00841                           rechitpullx = ( rechitx - simhitx ) / sqrt(error.xx());
00842                           rechitpully = ( rechity - simhity ) / sqrt(error.yy());
00843                           
00844                           float simhitpx = (*closestit).momentumAtEntry().x();
00845                           float simhitpy = (*closestit).momentumAtEntry().y();
00846                           float simhitpz = (*closestit).momentumAtEntry().z();
00847                           
00848                           beta = atan2(simhitpz, simhitpy) * radtodeg;
00849                           alpha = atan2(simhitpz, simhitpx) * radtodeg;
00850                           
00851                           //beta  = fabs(atan2(simhitpz, simhitpy)) * radtodeg;
00852                           //alpha = fabs(atan2(simhitpz, simhitpx)) * radtodeg;
00853 
00854                           // calculate alpha and beta exactly as in PixelCPEBase.cc
00855                           float locx = simhitpx;
00856                           float locy = simhitpy;
00857                           float locz = simhitpz;
00858                           
00859                           bool isFlipped = false;
00860                           float tmp1 = theGeomDet->surface().toGlobal(Local3DPoint(0.,0.,0.)).perp();
00861                           float tmp2 = theGeomDet->surface().toGlobal(Local3DPoint(0.,0.,1.)).perp();
00862                           if ( tmp2<tmp1 ) 
00863                             isFlipped = true;
00864                           else 
00865                             isFlipped = false;    
00866 
00867                           trk_alpha = acos(locx/sqrt(locx*locx+locz*locz)) * radtodeg;
00868                           if ( isFlipped )                    // &&& check for FPIX !!!
00869                             trk_alpha = 180.0 - trk_alpha ;
00870                           
00871                           trk_beta = acos(locy/sqrt(locy*locy+locz*locz)) * radtodeg;
00872                           
00873 
00874                           phi = tciter->momentum().phi() / math_pi*180.0;
00875                           eta = tciter->momentum().eta();
00876                           
00877                           const int maxPixelCol = (*matchedhit).cluster()->maxPixelCol();
00878                           const int maxPixelRow = (*matchedhit).cluster()->maxPixelRow();
00879                           const int minPixelCol = (*matchedhit).cluster()->minPixelCol();
00880                           const int minPixelRow = (*matchedhit).cluster()->minPixelRow();
00881                                           
00882                           // check whether the cluster is at the module edge 
00883                           if ( theTopol->isItEdgePixelInX( minPixelRow ) || 
00884                                theTopol->isItEdgePixelInX( maxPixelRow ) )
00885                             edgex = 1;
00886                           else 
00887                             edgex = 0;
00888                           
00889                           if ( theTopol->isItEdgePixelInY( minPixelCol ) || 
00890                                theTopol->isItEdgePixelInY( maxPixelCol ) )
00891                             edgey = 1;
00892                           else 
00893                             edgey = 0;
00894                           
00895                           // check whether this rechit contains big pixels
00896                           if ( theTopol->containsBigPixelInX(minPixelRow, maxPixelRow) )
00897                             bigx = 1;
00898                           else 
00899                             bigx = 0;
00900                           
00901                           if ( theTopol->containsBigPixelInY(minPixelCol, maxPixelCol) )
00902                             bigy = 1;
00903                           else 
00904                             bigy = 0;
00905                           
00906                           subdetId = (int)detId.subdetId();
00907                           
00908                           if ( (int)detId.subdetId() == (int)PixelSubdetector::PixelBarrel ) 
00909                             {
00910                               //const PixelGeomDetUnit* theGeomDet 
00911                               //= dynamic_cast<const PixelGeomDetUnit*> ( tracker->idToDet(detId) );
00912                               //const RectangularPixelTopology * topol 
00913                               //= dynamic_cast<const RectangularPixelTopology*>(&(theGeomDet->specificTopology()));
00914                               
00915                               int tmp_nrows = theGeomDet->specificTopology().nrows();
00916                               if ( tmp_nrows == 80 ) 
00917                                 half = 1;
00918                               else if ( tmp_nrows == 160 ) 
00919                                 half = 0;
00920                               else 
00921                                 cout << "-------------------------------------------------- Wrong module size !!!" << endl;
00922                               
00923                               float tmp1 = theGeomDet->surface().toGlobal(Local3DPoint(0.,0.,0.)).perp();
00924                               float tmp2 = theGeomDet->surface().toGlobal(Local3DPoint(0.,0.,1.)).perp();
00925                               
00926                               if ( tmp2<tmp1 ) 
00927                                 flipped = 1;
00928                               else 
00929                                 flipped = 0;
00930                               
00931                               PXBDetId  bdetid(detId);
00932                               layer  = bdetid.layer();   // Layer: 1,2,3.
00933                               ladder = bdetid.ladder();  // Ladder: 1-20, 32, 44. 
00934                               mod   = bdetid.module();  // Mod: 1-8.
00935                             }                     
00936                           else if ( (int)detId.subdetId() == (int)PixelSubdetector::PixelEndcap )
00937                             {
00938                               PXFDetId fdetid(detId);
00939                               side  = fdetid.side();
00940                               disk  = fdetid.disk();
00941                               blade = fdetid.blade();
00942                               panel = fdetid.panel();
00943                               plaq  = fdetid.module(); // also known as plaquette
00944                               
00945                               float tmp1 = theGeomDet->surface().toGlobal(Local3DPoint(0.,0.,0.)).perp();
00946                               float tmp2 = theGeomDet->surface().toGlobal(Local3DPoint(0.,0.,1.)).perp();
00947                               
00948                               if ( tmp2<tmp1 ) 
00949                                 flipped = 1;
00950                               else 
00951                                 flipped = 0;
00952                               
00953                             } // else if ( detId.subdetId()==PixelSubdetector::PixelEndcap )
00954                           //else std::cout << "We are not in the pixel detector. detId.subdetId() = " << (int)detId.subdetId() << endl;
00955                           
00956                           ttree_track_hits_->Fill();
00957                           
00958                         } // if ( !matched.empty() )
00959                       else
00960                         cout << "---------------- RecHit with no associated SimHit !!! -------------------------- " << endl;
00961                       
00962                     } // if ( matchedhit )
00963                   
00964                 } // end of loop on hits
00965               
00966             } //end of loop on track 
00967       
00968         } // tracks > 0.
00969      
00970     } // if ( include_trk_hits_ )
00971 
00972   // ----------------------------------------------- track hits only -----------------------------------------------------------
00973   
00974 }
00975 
00976 void SiPixelErrorEstimation::
00977 computeAnglesFromDetPosition(const SiPixelCluster & cl, 
00978                              const GeomDetUnit    & det, 
00979                              float& alpha, float& beta )
00980 {
00981   //--- This is a new det unit, so cache it
00982   const PixelGeomDetUnit* theDet = dynamic_cast<const PixelGeomDetUnit*>( &det );
00983   if (! theDet) 
00984     {
00985       cout << "---------------------------------------------- Not a pixel detector !!!!!!!!!!!!!!" << endl;
00986       assert(0);
00987     }
00988 
00989   const RectangularPixelTopology* theTopol = 
00990     dynamic_cast<const RectangularPixelTopology*>(&(theDet->specificTopology()));
00991 
00992   // get cluster center of gravity (of charge)
00993   float xcenter = cl.x();
00994   float ycenter = cl.y();
00995   
00996   // get the cluster position in local coordinates (cm) 
00997   LocalPoint lp = theTopol->localPosition( MeasurementPoint(xcenter, ycenter) );
00998   //float lp_mod = sqrt( lp.x()*lp.x() + lp.y()*lp.y() + lp.z()*lp.z() );
00999 
01000   // get the cluster position in global coordinates (cm)
01001   GlobalPoint gp = theDet->surface().toGlobal( lp );
01002   float gp_mod = sqrt( gp.x()*gp.x() + gp.y()*gp.y() + gp.z()*gp.z() );
01003 
01004   // normalize
01005   float gpx = gp.x()/gp_mod;
01006   float gpy = gp.y()/gp_mod;
01007   float gpz = gp.z()/gp_mod;
01008 
01009   // make a global vector out of the global point; this vector will point from the 
01010   // origin of the detector to the cluster
01011   GlobalVector gv(gpx, gpy, gpz);
01012 
01013   // make local unit vector along local X axis
01014   const Local3DVector lvx(1.0, 0.0, 0.0);
01015 
01016   // get the unit X vector in global coordinates/
01017   GlobalVector gvx = theDet->surface().toGlobal( lvx );
01018 
01019   // make local unit vector along local Y axis
01020   const Local3DVector lvy(0.0, 1.0, 0.0);
01021 
01022   // get the unit Y vector in global coordinates
01023   GlobalVector gvy = theDet->surface().toGlobal( lvy );
01024    
01025   // make local unit vector along local Z axis
01026   const Local3DVector lvz(0.0, 0.0, 1.0);
01027 
01028   // get the unit Z vector in global coordinates
01029   GlobalVector gvz = theDet->surface().toGlobal( lvz );
01030     
01031   // calculate the components of gv (the unit vector pointing to the cluster) 
01032   // in the local coordinate system given by the basis {gvx, gvy, gvz}
01033   // note that both gv and the basis {gvx, gvy, gvz} are given in global coordinates
01034   float gv_dot_gvx = gv.x()*gvx.x() + gv.y()*gvx.y() + gv.z()*gvx.z();
01035   float gv_dot_gvy = gv.x()*gvy.x() + gv.y()*gvy.y() + gv.z()*gvy.z();
01036   float gv_dot_gvz = gv.x()*gvz.x() + gv.y()*gvz.y() + gv.z()*gvz.z();
01037 
01038   // calculate angles
01039   alpha = atan2( gv_dot_gvz, gv_dot_gvx );
01040   beta  = atan2( gv_dot_gvz, gv_dot_gvy );
01041 
01042   // calculate cotalpha and cotbeta
01043   //   cotalpha_ = 1.0/tan(alpha_);
01044   //   cotbeta_  = 1.0/tan(beta_ );
01045   // or like this
01046   //cotalpha_ = gv_dot_gvx / gv_dot_gvz;
01047   //cotbeta_  = gv_dot_gvy / gv_dot_gvz;
01048 }
01049 
01050 //define this as a plug-in
01051 DEFINE_FWK_MODULE(SiPixelErrorEstimation);

Generated on Tue Jun 9 17:25:45 2009 for CMSSW by  doxygen 1.5.4