CMS 3D CMS Logo

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