CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Validation/TrackerRecHits/plugins/SiStripRecHitsValid.cc

Go to the documentation of this file.
00001 // File: SiStripRecHitsValid.cc
00002 // Description:  see SiStripRecHitsValid.h
00003 // Author:  P. Azzi
00004 // Creation Date:  PA May 2006 Initial version.
00005 //
00006 //--------------------------------------------
00007 #include "Validation/TrackerRecHits/interface/SiStripRecHitsValid.h"
00008 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h" 
00009 
00010 //needed for the geometry: 
00011 #include "DataFormats/DetId/interface/DetId.h" 
00012 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h" 
00013 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00014 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00015 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00016 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00017 
00018 
00019 //--- for RecHit
00020 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h" 
00021 #include "DataFormats/SiStripCluster/interface/SiStripClusterCollection.h" 
00022 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h" 
00023 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h" 
00024 #include "DataFormats/Common/interface/OwnVector.h" 
00025 #include "DQMServices/Core/interface/DQMStore.h"
00026 
00027 using namespace std;
00028 using namespace edm;
00029 
00030 namespace helper { 
00031     struct GetDetId { 
00032         template<typename X> 
00033         DetId operator()(const X &x) { return DetId(x.detId()); }
00034     };
00035 
00036     template<typename T>
00037     std::pair<typename T::DetSet::const_iterator, typename T::DetSet::const_iterator> 
00038     getRange(const T &detset, const DetId &id) {
00039         typedef std::pair<typename T::DetSet::const_iterator, typename T::DetSet::const_iterator> return_type;
00040         typename T::const_iterator match = detset.find(id);
00041         if (match == detset.end()) return return_type();
00042         typename T::DetSet hits = *match;
00043         return return_type(hits.begin(), hits.end());
00044     } 
00045 }
00046 
00047 
00048 
00049 //Constructor
00050 SiStripRecHitsValid::SiStripRecHitsValid(const ParameterSet& ps) :
00051   dbe_(0),      
00052   conf_(ps),
00053   matchedRecHits_( ps.getParameter<edm::InputTag>("matchedRecHits") ),
00054   rphiRecHits_( ps.getParameter<edm::InputTag>("rphiRecHits") ),
00055   stereoRecHits_( ps.getParameter<edm::InputTag>("stereoRecHits") ) {
00056 
00057   outputFile_ = ps.getUntrackedParameter<string>("outputFile", "sistriprechitshisto.root");
00058   dbe_ = Service<DQMStore>().operator->();
00059   //dbe_->showDirStructure();
00060   dbe_->setCurrentFolder("TrackerRecHitsV/TrackerRecHits/Strip/SISTRIP");
00061 
00062   meNumTotRphi = dbe_->book1D("NumTotRphi","Num of RecHits rphi",100, 0, 10000);
00063   meNumTotSas = dbe_->book1D("NumTotSas","Num of RecHits sas",100, 0, 10000);
00064   meNumTotMatched = dbe_->book1D("NumTotMatched","Num of RecHits rmatched",100, 0, 10000);
00065 
00066   dbe_->setCurrentFolder("TrackerRecHitsV/TrackerRecHits/Strip/TIB");
00067   meNumRphiTIB = dbe_->book1D("NumRphiTIB","Num of RecHits rphi", 100, 0, 1000.);
00068   meNumSasTIB = dbe_->book1D("NumSasTIB","Num of RecHits sas", 100, 0, 1000.);
00069   meNumMatchedTIB = dbe_->book1D("NumMatchedTIB","Num of RecHits matched", 100, 0, 1000.);
00070 
00071   //one histo per Layer rphi hits
00072   for(int i = 0 ;i<4 ; i++) {
00073     Char_t histo[200];
00074     sprintf(histo,"Nstp_rphi_layer%dtib",i+1);
00075     meNstpRphiTIB[i] = dbe_->book1D(histo,"RecHit Cluster Size",10,0.5,10.5);  
00076     sprintf(histo,"Adc_rphi_layer%dtib",i+1);
00077     meAdcRphiTIB[i] = dbe_->book1D(histo,"RecHit Cluster Charge",100,0.,300.);  
00078     sprintf(histo,"Posx_rphi_layer%dtib",i+1);
00079     mePosxRphiTIB[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0,+6.0);  
00080     sprintf(histo,"Errx_rphi_layer%dtib",i+1);
00081     meErrxRphiTIB[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0,0.01); //<error>~20micron  
00082     sprintf(histo,"Res_rphi_layer%dtib",i+1);
00083     meResRphiTIB[i] = dbe_->book1D(histo,"RecHit Residual",100,-0.02,+0.02);  
00084     sprintf(histo,"Pull_LF_rphi_layer%dtib",i+1);
00085     mePullLFRphiTIB[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00086     sprintf(histo,"Pull_MF_rphi_layer%dtib",i+1);
00087     mePullMFRphiTIB[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00088     sprintf(histo,"Chi2_rphi_layer%dtib",i+1);
00089     meChi2RphiTIB[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00090   }
00091 
00092   //one histo per Layer stereo and matched hits
00093   for(int i = 0 ;i<2 ; i++) {
00094     Char_t histo[200];
00095     sprintf(histo,"Nstp_sas_layer%dtib",i+1);
00096     meNstpSasTIB[i] = dbe_->book1D(histo,"RecHit Cluster Size",10,0.5,10.5);  
00097     sprintf(histo,"Adc_sas_layer%dtib",i+1);
00098     meAdcSasTIB[i] = dbe_->book1D(histo,"RecHit Cluster Charge",100,0.,300.);  
00099     sprintf(histo,"Posx_sas_layer%dtib",i+1);
00100     mePosxSasTIB[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0,+6.0);  
00101     sprintf(histo,"Errx_sas_layer%dtib",i+1);
00102     meErrxSasTIB[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0.,0.01);  
00103     sprintf(histo,"Res_sas_layer%dtib",i+1);
00104     meResSasTIB[i] = dbe_->book1D(histo,"RecHit Residual",100,-0.02,+0.02);  
00105     sprintf(histo,"Pull_LF_sas_layer%dtib",i+1);
00106     mePullLFSasTIB[i] = dbe_->book1D(histo,"Pull",100,-4.,4.);  
00107     sprintf(histo,"Pull_MF_sas_layer%dtib",i+1);
00108     mePullMFSasTIB[i] = dbe_->book1D(histo,"Pull",100,-4.,4.);  
00109     sprintf(histo,"Chi2_sas_layer%dtib",i+1);
00110     meChi2SasTIB[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00111 
00112     sprintf(histo,"Posx_matched_layer%dtib",i+1);
00113     mePosxMatchedTIB[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0, +6.0);  
00114     sprintf(histo,"Posy_matched_layer%dtib",i+1);
00115     mePosyMatchedTIB[i] = dbe_->book1D(histo,"RecHit y coord.",100,-6.0, +6.0);  
00116     sprintf(histo,"Errx_matched_layer%dtib",i+1);
00117     meErrxMatchedTIB[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0., 0.01);  
00118     sprintf(histo,"Erry_matched_layer%dtib",i+1);
00119     meErryMatchedTIB[i] = dbe_->book1D(histo,"RecHit err(y) coord.",100,0., 0.05);  
00120     sprintf(histo,"Resx_matched_layer%dtib",i+1);
00121     meResxMatchedTIB[i] = dbe_->book1D(histo,"RecHit Res(x) coord.",100,-0.02, +0.02);  
00122     sprintf(histo,"Resy_matched_layer%dtib",i+1);
00123     meResyMatchedTIB[i] = dbe_->book1D(histo,"RecHit Res(y) coord.",100,-1., +1.);  
00124     sprintf(histo,"Chi2_matched_layer%dtib",i+1);
00125     meChi2MatchedTIB[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00126   }
00127 
00128   dbe_->setCurrentFolder("TrackerRecHitsV/TrackerRecHits/Strip/TOB");
00129   meNumRphiTOB = dbe_->book1D("NumRphiTOB","Num of RecHits rphi", 100, 0, 1000.);
00130   meNumSasTOB = dbe_->book1D("NumSasTOB","Num of RecHits sas", 100, 0, 1000.);
00131   meNumMatchedTOB = dbe_->book1D("NumMatchedTOB","Num of RecHits matched", 100, 0, 1000.);
00132   //one histo per Layer rphi hits
00133   for(int i = 0 ;i<6 ; i++) {
00134     Char_t histo[200];
00135     sprintf(histo,"Nstp_rphi_layer%dtob",i+1);
00136     meNstpRphiTOB[i] = dbe_->book1D(histo,"RecHit Cluster Size",10,0.5,10.5);  
00137     sprintf(histo,"Adc_rphi_layer%dtob",i+1);
00138     meAdcRphiTOB[i] = dbe_->book1D(histo,"RecHit Cluster Charge",100,0.,300.);  
00139     sprintf(histo,"Posx_rphi_layer%dtob",i+1);
00140     mePosxRphiTOB[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0,+6.0);  
00141     sprintf(histo,"Errx_rphi_layer%dtob",i+1);
00142     meErrxRphiTOB[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0,0.01);  
00143     sprintf(histo,"Res_rphi_layer%dtob",i+1);
00144     meResRphiTOB[i] = dbe_->book1D(histo,"RecHit Residual",100,-0.02,+0.02);  
00145     sprintf(histo,"Pull_LF_rphi_layer%dtob",i+1);
00146     mePullLFRphiTOB[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00147     sprintf(histo,"Pull_MF_rphi_layer%dtob",i+1);
00148     mePullMFRphiTOB[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00149     sprintf(histo,"Chi2_rphi_layer%dtob",i+1);
00150     meChi2RphiTOB[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00151   }
00152 
00153   //one histo per Layer stereo and matched hits
00154   for(int i = 0 ;i<2 ; i++) {
00155     Char_t histo[200];
00156     sprintf(histo,"Nstp_sas_layer%dtob",i+1);
00157     meNstpSasTOB[i] = dbe_->book1D(histo,"RecHit Cluster Size",10,0.5,10.5);  
00158     sprintf(histo,"Adc_sas_layer%dtob",i+1);
00159     meAdcSasTOB[i] = dbe_->book1D(histo,"RecHit Cluster Charge",100,0.,300.);  
00160     sprintf(histo,"Posx_sas_layer%dtob",i+1);
00161     mePosxSasTOB[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0,+6.0);  
00162     sprintf(histo,"Errx_sas_layer%dtob",i+1);
00163     meErrxSasTOB[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0.,0.01);  
00164     sprintf(histo,"Res_sas_layer%dtob",i+1);
00165     meResSasTOB[i] = dbe_->book1D(histo,"RecHit Residual",100,-0.02,+0.02);  
00166     sprintf(histo,"Pull_LF_sas_layer%dtob",i+1);
00167     mePullLFSasTOB[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00168     sprintf(histo,"Pull_MF_sas_layer%dtob",i+1);
00169     mePullMFSasTOB[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00170     sprintf(histo,"Chi2_sas_layer%dtob",i+1);
00171     meChi2SasTOB[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00172 
00173     sprintf(histo,"Posx_matched_layer%dtob",i+1);
00174     mePosxMatchedTOB[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0, +6.0);  
00175     sprintf(histo,"Posy_matched_layer%dtob",i+1);
00176     mePosyMatchedTOB[i] = dbe_->book1D(histo,"RecHit y coord.",100,-10.0, +10.0);  
00177     sprintf(histo,"Errx_matched_layer%dtob",i+1);
00178     meErrxMatchedTOB[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0., 0.01);  
00179     sprintf(histo,"Erry_matched_layer%dtob",i+1);
00180     meErryMatchedTOB[i] = dbe_->book1D(histo,"RecHit err(y) coord.",100,0., 0.1);  
00181     sprintf(histo,"Resx_matched_layer%dtob",i+1);
00182     meResxMatchedTOB[i] = dbe_->book1D(histo,"RecHit Res(x) coord.",100,-0.02, +0.02);  
00183     sprintf(histo,"Resy_matched_layer%dtob",i+1);
00184     meResyMatchedTOB[i] = dbe_->book1D(histo,"RecHit Res(y) coord.",100,-1., +1.);  
00185     sprintf(histo,"Chi2_matched_layer%dtob",i+1);
00186     meChi2MatchedTOB[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00187   }
00188 
00189   dbe_->setCurrentFolder("TrackerRecHitsV/TrackerRecHits/Strip/TID");
00190   meNumRphiTID = dbe_->book1D("NumRphiTID","Num of RecHits rphi", 100, 0, 1000.);
00191   meNumSasTID = dbe_->book1D("NumSasTID","Num of RecHits sas", 100, 0, 1000.);
00192   meNumMatchedTID = dbe_->book1D("NumMatchedTID","Num of RecHits matched", 100, 0, 1000.);
00193 
00194   //one histo per Ring rphi hits: 3 rings, 6 disks, 2 inner rings are glued 
00195   for(int i = 0 ;i<3 ; i++) {
00196     Char_t histo[200];
00197     sprintf(histo,"Nstp_rphi_layer%dtid",i+1);
00198     meNstpRphiTID[i] = dbe_->book1D(histo,"RecHit Cluster Size",10,0.5,10.5);  
00199     sprintf(histo,"Adc_rphi_layer%dtid",i+1);
00200     meAdcRphiTID[i] = dbe_->book1D(histo,"RecHit Cluster Charge",100,0.,300.);  
00201     sprintf(histo,"Posx_rphi_layer%dtid",i+1);
00202     mePosxRphiTID[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0,+6.0);  
00203     sprintf(histo,"Errx_rphi_layer%dtid",i+1);
00204     meErrxRphiTID[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0,0.5);  
00205     sprintf(histo,"Res_rphi_layer%dtid",i+1);
00206     meResRphiTID[i] = dbe_->book1D(histo,"RecHit Residual",100,-0.5,+0.5);  
00207     sprintf(histo,"Pull_LF_rphi_layer%dtid",i+1);
00208     mePullLFRphiTID[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00209     sprintf(histo,"Pull_MF_rphi_layer%dtid",i+1);
00210     mePullMFRphiTID[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00211     sprintf(histo,"Chi2_rphi_layer%dtid",i+1);
00212     meChi2RphiTID[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00213   }
00214 
00215   //one histo per Ring stereo and matched hits
00216   for(int i = 0 ;i<2 ; i++) {
00217     Char_t histo[200];
00218     sprintf(histo,"Nstp_sas_layer%dtid",i+1);
00219     meNstpSasTID[i] = dbe_->book1D(histo,"RecHit Cluster Size",10,0.5,10.5);  
00220     sprintf(histo,"Adc_sas_layer%dtid",i+1);
00221     meAdcSasTID[i] = dbe_->book1D(histo,"RecHit Cluster Charge",100,0.,300.);  
00222     sprintf(histo,"Posx_sas_layer%dtid",i+1);
00223     mePosxSasTID[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0,+6.0);  
00224     sprintf(histo,"Errx_sas_layer%dtid",i+1);
00225     meErrxSasTID[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0.,0.5);  
00226     sprintf(histo,"Res_sas_layer%dtid",i+1);
00227     meResSasTID[i] = dbe_->book1D(histo,"RecHit Residual",100,-0.5,+0.5);  
00228     sprintf(histo,"Pull_LF_sas_layer%dtid",i+1);
00229     mePullLFSasTID[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00230     sprintf(histo,"Pull_MF_sas_layer%dtid",i+1);
00231     mePullMFSasTID[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00232     sprintf(histo,"Chi2_sas_layer%dtid",i+1);
00233     meChi2SasTID[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00234 
00235     sprintf(histo,"Posx_matched_layer%dtid",i+1);
00236     mePosxMatchedTID[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0, +6.0);  
00237     sprintf(histo,"Posy_matched_layer%dtid",i+1);
00238     mePosyMatchedTID[i] = dbe_->book1D(histo,"RecHit y coord.",100,-6.0, +6.0);  
00239     sprintf(histo,"Errx_matched_layer%dtid",i+1);
00240     meErrxMatchedTID[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0., 0.05);  
00241     sprintf(histo,"Erry_matched_layer%dtid",i+1);
00242     meErryMatchedTID[i] = dbe_->book1D(histo,"RecHit err(y) coord.",100,0., 0.1);  
00243     sprintf(histo,"Resx_matched_layer%dtid",i+1);
00244     meResxMatchedTID[i] = dbe_->book1D(histo,"RecHit Res(x) coord.",100,-0.2, +0.2);  
00245     sprintf(histo,"Resy_matched_layer%dtid",i+1);
00246     meResyMatchedTID[i] = dbe_->book1D(histo,"RecHit Res(y) coord.",100,-1., +1.);  
00247     sprintf(histo,"Chi2_matched_layer%dtid",i+1);
00248     meChi2MatchedTID[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00249   }
00250 
00251   dbe_->setCurrentFolder("TrackerRecHitsV/TrackerRecHits/Strip/TEC");
00252   meNumRphiTEC = dbe_->book1D("NumRphiTEC","Num of RecHits rphi", 100, 0, 1000.);
00253   meNumSasTEC = dbe_->book1D("NumSasTEC","Num of RecHits sas", 100, 0, 1000.);
00254   meNumMatchedTEC = dbe_->book1D("NumMatchedTEC","Num of RecHits matched", 100, 0, 1000.);
00255 
00256   //one histo per Ring rphi hits: 7 rings, 18 disks. Innermost 3 rings are same as TID above.  
00257   for(int i = 0 ;i<7 ; i++) {
00258     Char_t histo[200];
00259     sprintf(histo,"Nstp_rphi_layer%dtec",i+1);
00260     meNstpRphiTEC[i] = dbe_->book1D(histo,"RecHit Cluster Size",10,0.5,10.5);  
00261     sprintf(histo,"Adc_rphi_layer%dtec",i+1);
00262     meAdcRphiTEC[i] = dbe_->book1D(histo,"RecHit Cluster Charge",100,0.,300.);  
00263     sprintf(histo,"Posx_rphi_layer%dtec",i+1);
00264     mePosxRphiTEC[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0,+6.0);  
00265     sprintf(histo,"Errx_rphi_layer%dtec",i+1);
00266     meErrxRphiTEC[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0,0.5);  
00267     sprintf(histo,"Res_rphi_layer%dtec",i+1);
00268     meResRphiTEC[i] = dbe_->book1D(histo,"RecHit Residual",100,-0.5,+0.5);  
00269     sprintf(histo,"Pull_LF_rphi_layer%dtec",i+1);
00270     mePullLFRphiTEC[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00271     sprintf(histo,"Pull_MF_rphi_layer%dtec",i+1);
00272     mePullMFRphiTEC[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);  
00273     sprintf(histo,"Chi2_rphi_layer%dtec",i+1);
00274     meChi2RphiTEC[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00275   }
00276 
00277   //one histo per Layer stereo and matched hits: rings 1,2,5 are double sided
00278   for(int i = 0 ;i<5 ; i++) {
00279     if(i == 0 || i == 1 || i == 4) {
00280       Char_t histo[200];
00281       sprintf(histo,"Nstp_sas_layer%dtec",i+1);
00282       meNstpSasTEC[i] = dbe_->book1D(histo,"RecHit Cluster Size",10,0.5,10.5);  
00283       sprintf(histo,"Adc_sas_layer%dtec",i+1);
00284       meAdcSasTEC[i] = dbe_->book1D(histo,"RecHit Cluster Charge",100,0.,300.);  
00285       sprintf(histo,"Posx_sas_layer%dtec",i+1);
00286       mePosxSasTEC[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0,+6.0);  
00287       sprintf(histo,"Errx_sas_layer%dtec",i+1);
00288       meErrxSasTEC[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0.,0.5);  
00289       sprintf(histo,"Res_sas_layer%dtec",i+1);
00290       meResSasTEC[i] = dbe_->book1D(histo,"RecHit Residual",100,-0.5,+0.5);  
00291       sprintf(histo,"Pull_LF_sas_layer%dtec",i+1);
00292       mePullLFSasTEC[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);
00293       sprintf(histo,"Pull_MF_sas_layer%dtec",i+1);
00294       mePullMFSasTEC[i] = dbe_->book1D(histo,"Pull",100,-5.,5.);
00295       sprintf(histo,"Chi2_sas_layer%dtec",i+1);
00296       meChi2SasTEC[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00297       
00298       sprintf(histo,"Posx_matched_layer%dtec",i+1);
00299       mePosxMatchedTEC[i] = dbe_->book1D(histo,"RecHit x coord.",100,-6.0, +6.0);  
00300       sprintf(histo,"Posy_matched_layer%dtec",i+1);
00301       mePosyMatchedTEC[i] = dbe_->book1D(histo,"RecHit y coord.",100,-8.0, +8.0);  
00302       sprintf(histo,"Errx_matched_layer%dtec",i+1);
00303       meErrxMatchedTEC[i] = dbe_->book1D(histo,"RecHit err(x) coord.",100,0., 0.05);  
00304       sprintf(histo,"Erry_matched_layer%dtec",i+1);
00305       meErryMatchedTEC[i] = dbe_->book1D(histo,"RecHit err(y) coord.",100,0., 0.1);  
00306       sprintf(histo,"Resx_matched_layer%dtec",i+1);
00307       meResxMatchedTEC[i] = dbe_->book1D(histo,"RecHit Res(x) coord.",100,-0.2, +0.2);  
00308       sprintf(histo,"Resy_matched_layer%dtec",i+1);
00309       meResyMatchedTEC[i] = dbe_->book1D(histo,"RecHit Res(y) coord.",100,-1., +1.);  
00310       sprintf(histo,"Chi2_matched_layer%dtec",i+1);
00311       meChi2MatchedTEC[i] = dbe_->book1D(histo,"RecHit Chi2 test",100,0., 50);  
00312     }
00313   }
00314 }
00315 
00316 
00317 SiStripRecHitsValid::~SiStripRecHitsValid(){
00318  //if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
00319 }
00320 
00321 void SiStripRecHitsValid::beginJob(){
00322 
00323 }
00324 
00325 void SiStripRecHitsValid::endJob() {
00326  if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
00327 }
00328 
00329 
00330 void SiStripRecHitsValid::analyze(const edm::Event& e, const edm::EventSetup& es) {
00331   //Retrieve tracker topology from geometry
00332   edm::ESHandle<TrackerTopology> tTopo;
00333   es.get<IdealGeometryRecord>().get(tTopo);
00334 
00335 
00336 
00337   LogInfo("EventInfo") << " Run = " << e.id().run() << " Event = " << e.id().event();  
00338   //cout  << " Run = " << e.id().run() << " Event = " << e.id().event() << endl;  
00339   
00340   //--- get RecHits
00341   
00342   std::string rechitProducer = "SiStripRecHits2D";
00343   
00344   // Step A: Get Inputs 
00345   edm::Handle<SiStripMatchedRecHit2DCollection> rechitsmatched;
00346   edm::Handle<SiStripRecHit2DCollection> rechitsrphi;
00347   edm::Handle<SiStripRecHit2DCollection> rechitsstereo;
00348   e.getByLabel(matchedRecHits_, rechitsmatched);
00349   e.getByLabel(rphiRecHits_, rechitsrphi);
00350   e.getByLabel(stereoRecHits_, rechitsstereo);
00351 
00352   int numrechitrphi   =0;
00353   int numrechitsas    =0;
00354   int numrechitmatched=0;
00355 
00356   int totTibnumrechitrphi=0;
00357   int totTibnumrechitsas=0;
00358   int totTibnumrechitmatched=0;
00359   int totTobnumrechitrphi=0;
00360   int totTobnumrechitsas=0;
00361   int totTobnumrechitmatched=0;
00362   int totTidnumrechitrphi=0;
00363   int totTidnumrechitsas=0;
00364   int totTidnumrechitmatched=0;
00365   int totTecnumrechitrphi=0;
00366   int totTecnumrechitsas=0;
00367   int totTecnumrechitmatched=0;
00368   int totrechitrphi =0;
00369   int totrechitsas =0;
00370   int totrechitmatched =0;
00371   
00372   TrackerHitAssociator associate(e, conf_);
00373   
00374   edm::ESHandle<TrackerGeometry> pDD;
00375   es.get<TrackerDigiGeometryRecord> ().get (pDD);
00376   const TrackerGeometry &tracker(*pDD);
00377   // FIXME: this using of vector<DetId> is suboptimal, but I don't want to re-write the full class now
00378   std::vector<DetId> IDs; 
00379   IDs.reserve(rechitsrphi->size() + rechitsmatched->size() + rechitsstereo->size());
00380   std::transform(rechitsrphi->begin(), rechitsrphi->end(), std::back_inserter(IDs), helper::GetDetId() );
00381   std::transform(rechitsstereo->begin(), rechitsstereo->end(), std::back_inserter(IDs), helper::GetDetId() );
00382   std::transform(rechitsmatched->begin(), rechitsmatched->end(), std::back_inserter(IDs), helper::GetDetId() );
00383   // loop over detunits
00384   //  for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00385   for(std::vector<DetId>::const_iterator it = IDs.begin(); it != IDs.end(); ++it ){//loop on rphi detector with hits
00386     uint32_t myid=((*it).rawId());       
00387     DetId detid = ((*it));
00388     
00389     // initialize here
00390     for(int i=0; i<MAXHIT; i++){
00391       rechitrphix[i] =0;
00392       rechitrphierrx[i] =0;
00393       rechitrphiy[i] =0;
00394       rechitrphiz[i] =0;
00395       rechitsasx[i] =0;
00396       rechitsaserrx[i] =0;
00397       rechitsasy[i] =0;
00398       rechitsasz[i] =0;
00399       clusizrphi[i] =0;
00400       clusizsas[i] =0;
00401       cluchgrphi[i] =0;
00402       cluchgsas[i] =0;
00403       rechitrphires[i]=-999.;
00404       rechitsasres[i]=-999.;
00405       rechitrphipullMF[i]=-999.;
00406       rechitsaspullMF[i]=-999.;
00407       chi2rphi[i] =0;
00408       chi2sas[i]=0;
00409       rechitmatchedx[i] =0;
00410       rechitmatchedy[i] =0;
00411       rechitmatchedz[i] =0;
00412       rechitmatchederrxx[i] =0;
00413       rechitmatchederrxy[i] =0;
00414       rechitmatchederryy[i] =0;
00415       rechitmatchedresx[i]=-999;
00416       rechitmatchedresy[i]=-999;
00417       chi2matched[i]=0;
00418     }
00419     
00420     numrechitrphi =0;
00421     //loop over rechits-rphi in the same subdetector
00422     std::pair<SiStripRecHit2DCollection::DetSet::const_iterator,SiStripRecHit2DCollection::DetSet::const_iterator> rechitrphiRange = helper::getRange(*rechitsrphi, detid);
00423     SiStripRecHit2DCollection::DetSet::const_iterator rechitrphiRangeIteratorBegin = rechitrphiRange.first;
00424     SiStripRecHit2DCollection::DetSet::const_iterator rechitrphiRangeIteratorEnd   = rechitrphiRange.second;
00425     SiStripRecHit2DCollection::DetSet::const_iterator iterrphi=rechitrphiRangeIteratorBegin;
00426     
00427     numrechitrphi = rechitrphiRangeIteratorEnd - rechitrphiRangeIteratorBegin;   
00428          
00429 
00430     int i=0;
00431     int i2=0;
00432 
00433     if(numrechitrphi > 0 ){
00434       totrechitrphi+=numrechitrphi;
00435       for(iterrphi=rechitrphiRangeIteratorBegin; iterrphi!=rechitrphiRangeIteratorEnd;++iterrphi){
00436         const GeomDetUnit *  det = tracker.idToDetUnit(detid);
00437         const StripGeomDetUnit * stripdet=(const StripGeomDetUnit*)(det);
00438         const StripTopology &topol=(StripTopology&)stripdet->topology();
00439         SiStripRecHit2D const rechit=*iterrphi;
00440         LocalPoint position=rechit.localPosition();
00441         LocalError error=rechit.localPositionError();
00442         MeasurementPoint Mposition;
00443         MeasurementError Merror;
00444         Mposition = topol.measurementPosition(position);
00445         Merror = topol.measurementError(position,error);
00446         SiStripRecHit2D::ClusterRef clust=rechit.cluster();
00447         int clusiz=0;
00448         int totcharge=0;
00449         clusiz = clust->amplitudes().size();
00450         const std::vector<uint8_t> amplitudes=clust->amplitudes();
00451           for(size_t ia=0; ia<amplitudes.size();ia++){
00452             totcharge+=amplitudes[ia];
00453           }
00454         rechitrphix[i] = position.x();
00455         rechitrphiy[i] = position.y();
00456         rechitrphiz[i] = position.z();
00457         rechitrphierrx[i] = error.xx();
00458         clusizrphi[i] = clusiz;
00459         cluchgrphi[i] = totcharge;
00460 
00461         matched.clear();
00462         matched = associate.associateHit(rechit);
00463         float mindist = 999999;
00464         float dist = 999999;
00465         PSimHit closest;
00466         if(!matched.empty()){
00467           for(vector<PSimHit>::const_iterator m=matched.begin(); m<matched.end(); m++){
00468             dist = fabs(rechitrphix[i] - (*m).localPosition().x());
00469             if(dist<mindist){
00470               mindist = dist;
00471               closest = (*m);
00472             }
00473             rechitrphires[i] = rechitrphix[i] - closest.localPosition().x();
00474           }  
00475           rechitrphipullMF[i] = (Mposition.x() - (topol.measurementPosition(closest.localPosition())).x())/sqrt(Merror.uu());
00476 
00477           //chi2test compare rechit errors with the simhit position ( using null matrix for the simhit). 
00478           //Can spot problems in the geometry better than a simple residual. (thanks to BorisM)
00479           AlgebraicVector  rhparameters(2);//= rechit.parameters();
00480           rhparameters[0] = position.x(); 
00481           rhparameters[1] = position.y();
00482           AlgebraicVector shparameters(2);
00483           shparameters[0] = closest.localPosition().x();
00484           shparameters[1] = closest.localPosition().y();
00485           AlgebraicVector r(rhparameters - shparameters);
00486           AlgebraicSymMatrix R(2);//  = rechit.parametersError();
00487           R[0][0] = error.xx();
00488           R[0][1] = error.xy();
00489           R[1][1] = error.yy();
00490           int ierr; 
00491           R.invert(ierr); // if (ierr != 0) throw exception;
00492           double est = R.similarity(r);
00493           //      std::cout << " ====== Chi2 test rphi hits ====== " << std::endl;
00494           //      std::cout << "RecHit param. = " << rhparameters << std::endl;
00495           //      std::cout << "RecHit errors = " << R << std::endl;
00496           //      std::cout << "SimHit param. = " << shparameters << std::endl;
00497           //      std::cout << " chi2  = " << est << std::endl;
00498           //      std::cout << "DEBUG BORIS,filling chi2rphi[i],i: " << i << std::endl;
00499           chi2rphi[i2] = est;
00500           i2++;
00501         }
00502         i++;
00503       }
00504     }
00505     
00506     //loop over rechits-sas in the same subdetector
00507     int j=0;
00508     int j2=0;
00509     numrechitsas=0;
00510     std::pair<SiStripRecHit2DCollection::DetSet::const_iterator,SiStripRecHit2DCollection::DetSet::const_iterator> rechitsasRange = helper::getRange(*rechitsstereo, detid);
00511     SiStripRecHit2DCollection::DetSet::const_iterator rechitsasRangeIteratorBegin = rechitsasRange.first;
00512     SiStripRecHit2DCollection::DetSet::const_iterator rechitsasRangeIteratorEnd   = rechitsasRange.second;
00513     SiStripRecHit2DCollection::DetSet::const_iterator itersas=rechitsasRangeIteratorBegin;
00514     numrechitsas = rechitsasRangeIteratorEnd - rechitsasRangeIteratorBegin;   
00515     if(numrechitsas > 0){
00516       totrechitsas+=numrechitsas;
00517       for(itersas=rechitsasRangeIteratorBegin; itersas!=rechitsasRangeIteratorEnd;++itersas){
00518         const GeomDetUnit *  det = tracker.idToDetUnit(detid);
00519         const StripGeomDetUnit * stripdet=(const StripGeomDetUnit*)(det);
00520         const StripTopology &topol=(StripTopology&)stripdet->topology();
00521         SiStripRecHit2D const rechit=*itersas;
00522         LocalPoint position=rechit.localPosition();
00523         LocalError error=rechit.localPositionError();
00524         MeasurementPoint Mposition;
00525         MeasurementError Merror;
00526         Mposition = topol.measurementPosition(position);
00527         Merror = topol.measurementError(position,error);
00528         SiStripRecHit2D::ClusterRef clust=rechit.cluster();     int clusiz=0;
00529         int totcharge=0;
00530         clusiz = clust->amplitudes().size();
00531         const std::vector<uint8_t> amplitudes=clust->amplitudes();
00532         for(size_t ia=0; ia<amplitudes.size();ia++){
00533           totcharge+=amplitudes[ia];
00534         }
00535         
00536         rechitsasx[j] = position.x();
00537         rechitsasy[j] = position.y();
00538         rechitsasz[j] = position.z();
00539         rechitsaserrx[j] = error.xx();
00540         clusizsas[j] = clusiz;
00541         cluchgsas[j] = totcharge;
00542         
00543         float mindist = 999999;
00544         float dist = 999999;
00545         PSimHit closest;
00546         matched.clear();
00547         matched = associate.associateHit(rechit);
00548         if(!matched.empty()){
00549           for(vector<PSimHit>::const_iterator m=matched.begin(); m<matched.end(); m++){
00550             dist = fabs(rechitsasx[j] - (*m).localPosition().x());
00551             if(dist<mindist){
00552               mindist = dist;
00553               closest = (*m);
00554             }
00555             rechitsasres[j] = rechitsasx[j] - closest.localPosition().x();
00556           }  
00557           rechitsaspullMF[j] = (Mposition.x() - (topol.measurementPosition(closest.localPosition())).x())/sqrt(Merror.uu());
00558           //chi2test compare rechit errors with the simhit position ( using null matrix for the simhit). 
00559           //Can spot problems in the geometry better than a simple residual. (thanks to BorisM)
00560 //        AlgebraicVector rhparameters = rechit.parameters();
00561           AlgebraicVector  rhparameters(2);//= rechit.parameters();
00562           rhparameters[0] = position.x(); 
00563           rhparameters[1] = position.y();
00564           AlgebraicVector shparameters(2);
00565           shparameters[0] = closest.localPosition().x();
00566           shparameters[1] = closest.localPosition().y();
00567           AlgebraicVector r(rhparameters - shparameters);
00568 //        AlgebraicSymMatrix R  = rechit.parametersError();
00569           AlgebraicSymMatrix R(2);//  = rechit.parametersError();
00570           R[0][0] = error.xx();
00571           R[0][1] = error.xy();
00572           R[1][1] = error.yy();
00573           int ierr; 
00574           R.invert(ierr); // if (ierr != 0) throw exception;
00575           double est = R.similarity(r);
00576           //      std::cout << " ====== Chi2 test sas hits ====== " << std::endl;
00577           //      std::cout << "RecHit param. = " << rhparameters << std::endl;
00578           //      std::cout << "RecHit errors = " << R << std::endl;
00579           //      std::cout << "SimHit param. = " << shparameters << std::endl;
00580           //      std::cout << " chi2  = " << est << std::endl;
00581           //      std::cout << "DEBUG BORIS,filling chi2sas[j],j: " << i << std::endl;
00582           chi2sas[j2] = est;
00583           j2++;
00584         }
00585         j++;
00586       }
00587     }
00588     
00589     //now matched hits
00590 
00591     int k=0;
00592     int k2=0;
00593     
00594     //loop over rechits-matched in the same subdetector
00595     numrechitmatched=0;
00596     std::pair<SiStripMatchedRecHit2DCollection::DetSet::const_iterator,SiStripMatchedRecHit2DCollection::DetSet::const_iterator> rechitmatchedRange = helper::getRange(*rechitsmatched, detid);
00597     SiStripMatchedRecHit2DCollection::DetSet::const_iterator rechitmatchedRangeIteratorBegin = rechitmatchedRange.first;
00598     SiStripMatchedRecHit2DCollection::DetSet::const_iterator rechitmatchedRangeIteratorEnd   = rechitmatchedRange.second;
00599     SiStripMatchedRecHit2DCollection::DetSet::const_iterator itermatched=rechitmatchedRangeIteratorBegin;
00600     numrechitmatched = rechitmatchedRangeIteratorEnd - rechitmatchedRangeIteratorBegin;   
00601     if(numrechitmatched > 0){
00602       totrechitmatched +=numrechitmatched;
00603 
00604       for(itermatched=rechitmatchedRangeIteratorBegin; itermatched!=rechitmatchedRangeIteratorEnd;++itermatched){
00605         SiStripMatchedRecHit2D const rechit=*itermatched;
00606         LocalPoint position=rechit.localPosition();
00607         LocalError error=rechit.localPositionError();
00608         
00609         float mindist = 999999;
00610         float distx = 999999;
00611         float disty = 999999;
00612         float dist = 999999;
00613         std::pair<LocalPoint,LocalVector> closestPair;
00614         matched.clear();
00615         //      const SiStripRecHit2D *mono = rechit.monoHit();
00616         //      const SiStripRecHit2D *st = rechit.stereoHit();
00617         //      LocalPoint monopos = mono->localPosition();
00618         //      LocalPoint stpos   = st->localPosition();
00619         
00620         rechitmatchedx[k] = position.x();
00621         rechitmatchedy[k] = position.y();
00622         rechitmatchedz[k] = position.z();
00623         rechitmatchederrxx[k] = error.xx();
00624         rechitmatchederrxy[k] = error.xy();
00625         rechitmatchederryy[k] = error.yy();
00626 
00627         //      std::cout << " before association " << std::endl;
00628         matched = associate.associateHit(rechit);
00629         //std::cout << " after association size = " << matched.size() << std::endl;
00630 
00631         if(!matched.empty()){
00632           //project simhit;
00633           const GluedGeomDet* gluedDet = (const GluedGeomDet*)tracker.idToDet(rechit.geographicalId());
00634           const StripGeomDetUnit* partnerstripdet =(StripGeomDetUnit*) gluedDet->stereoDet();
00635           std::pair<LocalPoint,LocalVector> hitPair;
00636 
00637           //std::cout << " RECHIT position = " << position << std::endl;          
00638           
00639           for(vector<PSimHit>::const_iterator m=matched.begin(); m<matched.end(); m++){
00640             //project simhit;
00641             hitPair= projectHit((*m),partnerstripdet,gluedDet->surface());
00642             distx = fabs(rechitmatchedx[k] - hitPair.first.x());
00643             disty = fabs(rechitmatchedy[k] - hitPair.first.y());
00644             dist = sqrt(distx*distx+disty*disty);
00645             // std::cout << " Simhit position x = " << hitPair.first.x() 
00646             //      << " y = " << hitPair.first.y() << " dist = " << dist << std::endl;   
00647             if(dist<mindist){
00648               mindist = dist;
00649               closestPair = hitPair;
00650             }
00651           }
00652           //std::cout << " Closest position x = " << closestPair.first.x() 
00653           //      << " y = " << closestPair.first.y() << " dist = " << dist << std::endl;         
00654           rechitmatchedresx[k] = rechitmatchedx[k] - closestPair.first.x();
00655           rechitmatchedresy[k] = rechitmatchedy[k] - closestPair.first.y();
00656 
00657           //chi2test compare rechit errors with the simhit position ( using null matrix for the simhit). 
00658           //Can spot problems in the geometry better than a simple residual. (thanks to BorisM)
00659 
00660           AlgebraicVector  rhparameters(2);//= rechit.parameters();
00661           rhparameters[0] = position.x(); 
00662           rhparameters[1] = position.y();
00663           LocalPoint sh = closestPair.first;
00664           AlgebraicVector shparameters(2);
00665           shparameters[0] = sh.x();
00666           shparameters[1] = sh.y();
00667           AlgebraicVector r(rhparameters - shparameters);
00668           AlgebraicSymMatrix R(2);//  = rechit.parametersError();
00669           R[0][0] = error.xx();
00670           R[0][1] = error.xy();
00671           R[1][1] = error.yy();
00672           int ierr; 
00673           R.invert(ierr); // if (ierr != 0) throw exception;
00674           double est = R.similarity(r);
00675           //      std::cout << " ====== Chi2 test matched ====== " << std::endl;
00676           //      std::cout << "RecHit param. = " << rhparameters << std::endl;
00677           //      std::cout << "RecHit errors = " << R << std::endl;
00678           //      std::cout << "SimHit param. = " << shparameters << std::endl;
00679           //      std::cout << " chi2  = " << est << std::endl;
00680           chi2matched[k2] = est;
00681           k2++;
00682         }
00683         
00684         k++;
00685       }
00686     }
00687     
00688     //for each detid
00689     if(numrechitrphi>0 || numrechitsas>0 || numrechitmatched){
00690       if (detid.subdetId() == int(StripSubdetector::TIB)){
00691         
00692         int Tibnumrechitrphi    = numrechitrphi;
00693         int Tibnumrechitsas     = numrechitsas;
00694         int Tibnumrechitmatched = numrechitmatched;
00695 
00696         int Tibnumrechitrphi2    = i2;
00697         int Tibnumrechitsas2     = j2;
00698         int Tibnumrechitmatched2 = k2;
00699 
00700         totTibnumrechitrphi +=numrechitrphi;
00701         totTibnumrechitsas +=numrechitsas;
00702         totTibnumrechitmatched +=numrechitmatched;
00703 
00704         int ilay = tTopo->tibLayer(myid) - 1; //for histogram filling
00705         
00706         if(tTopo->tibStereo(myid)==0){
00707           for(int k = 0; k<Tibnumrechitrphi; k++){
00708             meNstpRphiTIB[ilay]->Fill(clusizrphi[k]);
00709             meAdcRphiTIB[ilay]->Fill(cluchgrphi[k]);
00710             mePosxRphiTIB[ilay]->Fill(rechitrphix[k]);
00711             meErrxRphiTIB[ilay]->Fill(sqrt(rechitrphierrx[k]));
00712             meResRphiTIB[ilay]->Fill(rechitrphires[k]);
00713             mePullLFRphiTIB[ilay]->Fill(rechitrphires[k]/sqrt(rechitrphierrx[k]));
00714             mePullMFRphiTIB[ilay]->Fill(rechitrphipullMF[k]);
00715 
00716           }
00717 
00718           for(int k = 0; k<Tibnumrechitrphi2; k++){
00719             meChi2RphiTIB[ilay]->Fill(chi2rphi[k]);
00720           }
00721 
00722         } else  if(tTopo->tibStereo(myid)==1){
00723           for(int kk = 0; kk < Tibnumrechitsas; kk++)       
00724             {
00725               meNstpSasTIB[ilay]->Fill(clusizsas[kk]);
00726               meAdcSasTIB[ilay]->Fill(cluchgsas[kk]);
00727               mePosxSasTIB[ilay]->Fill(rechitsasx[kk]);
00728               meErrxSasTIB[ilay]->Fill(sqrt(rechitsaserrx[kk]));
00729               meResSasTIB[ilay]->Fill(rechitsasres[kk]);
00730               mePullLFSasTIB[ilay]->Fill(rechitsasres[kk]/sqrt(rechitsaserrx[kk]));
00731               mePullMFSasTIB[ilay]->Fill(rechitsaspullMF[kk]);
00732             }     
00733           for(int l = 0; l<Tibnumrechitsas2; l++){
00734             meChi2SasTIB[ilay]->Fill(chi2sas[l]);
00735           }
00736 
00737         }
00738         if(Tibnumrechitmatched>0){
00739           for(int kkk = 0; kkk<Tibnumrechitmatched; kkk++)
00740             {
00741               mePosxMatchedTIB[ilay]->Fill(rechitmatchedx[kkk]);
00742               mePosyMatchedTIB[ilay]->Fill(rechitmatchedy[kkk]);
00743               meErrxMatchedTIB[ilay]->Fill(sqrt(rechitmatchederrxx[kkk]));
00744               meErryMatchedTIB[ilay]->Fill(sqrt(rechitmatchederryy[kkk]));
00745               meResxMatchedTIB[ilay]->Fill(rechitmatchedresx[kkk]);
00746               meResyMatchedTIB[ilay]->Fill(rechitmatchedresy[kkk]);
00747             }     
00748           for(int l = 0; l<Tibnumrechitmatched2; l++){
00749             meChi2MatchedTIB[ilay]->Fill(chi2matched[l]);
00750           }
00751 
00752         }
00753       }
00754 
00755 
00756       if (detid.subdetId() == int(StripSubdetector::TOB)){
00757         
00758         int Tobnumrechitrphi    = numrechitrphi;
00759         int Tobnumrechitsas     = numrechitsas;
00760         int Tobnumrechitmatched = numrechitmatched;
00761         totTobnumrechitrphi +=numrechitrphi;
00762         totTobnumrechitsas +=numrechitsas;
00763         totTobnumrechitmatched +=numrechitmatched;
00764 
00765         int Tobnumrechitrphi2    = i2;
00766         int Tobnumrechitsas2     = j2;
00767         int Tobnumrechitmatched2 = k2;
00768 
00769         int ilay = tTopo->tobLayer(myid) - 1; //for histogram filling
00770         
00771         if(tTopo->tobStereo(myid)==0){
00772           for(int k = 0; k<Tobnumrechitrphi; k++){
00773             meNstpRphiTOB[ilay]->Fill(clusizrphi[k]);
00774             meAdcRphiTOB[ilay]->Fill(cluchgrphi[k]);
00775             mePosxRphiTOB[ilay]->Fill(rechitrphix[k]);
00776             meErrxRphiTOB[ilay]->Fill(sqrt(rechitrphierrx[k]));
00777             meResRphiTOB[ilay]->Fill(rechitrphires[k]);
00778             mePullLFRphiTOB[ilay]->Fill(rechitrphires[k]/sqrt(rechitrphierrx[k]));
00779             mePullMFRphiTOB[ilay]->Fill(rechitrphipullMF[k]);
00780           }
00781           for(int l = 0; l<Tobnumrechitrphi2; l++){
00782             meChi2RphiTOB[ilay]->Fill(chi2rphi[l]);
00783           }
00784         } else  if(tTopo->tobStereo(myid)==1){
00785           for(int kk = 0; kk < Tobnumrechitsas; kk++)       
00786             {
00787               meNstpSasTOB[ilay]->Fill(clusizsas[kk]);
00788               meAdcSasTOB[ilay]->Fill(cluchgsas[kk]);
00789               mePosxSasTOB[ilay]->Fill(rechitsasx[kk]);
00790               meErrxSasTOB[ilay]->Fill(sqrt(rechitsaserrx[kk]));
00791               meResSasTOB[ilay]->Fill(rechitsasres[kk]);
00792               mePullLFSasTOB[ilay]->Fill(rechitsasres[kk]/sqrt(rechitsaserrx[kk]));
00793               mePullMFSasTOB[ilay]->Fill(rechitsaspullMF[kk]);
00794             }
00795           for(int l = 0; l<Tobnumrechitsas2; l++){
00796             meChi2SasTOB[ilay]->Fill(chi2sas[l]);
00797           }
00798           
00799         }
00800         if(Tobnumrechitmatched>0){
00801           for(int kkk = 0; kkk<Tobnumrechitmatched; kkk++)
00802             {
00803               mePosxMatchedTOB[ilay]->Fill(rechitmatchedx[kkk]);
00804               mePosyMatchedTOB[ilay]->Fill(rechitmatchedy[kkk]);
00805               meErrxMatchedTOB[ilay]->Fill(sqrt(rechitmatchederrxx[kkk]));
00806               meErryMatchedTOB[ilay]->Fill(sqrt(rechitmatchederryy[kkk]));
00807               meResxMatchedTOB[ilay]->Fill(rechitmatchedresx[kkk]);
00808               meResyMatchedTOB[ilay]->Fill(rechitmatchedresy[kkk]);
00809             }     
00810           for(int l = 0; l<Tobnumrechitmatched2; l++){
00811             meChi2MatchedTOB[ilay]->Fill(chi2matched[l]);
00812           }
00813 
00814         }
00815       }
00816       if (detid.subdetId() == int(StripSubdetector::TID)){
00817         
00818         int Tidnumrechitrphi    = numrechitrphi;
00819         int Tidnumrechitsas     = numrechitsas;
00820         int Tidnumrechitmatched = numrechitmatched;
00821         totTidnumrechitrphi +=numrechitrphi;
00822         totTidnumrechitsas +=numrechitsas;
00823         totTidnumrechitmatched +=numrechitmatched;
00824 
00825         int Tidnumrechitrphi2    = i2;
00826         int Tidnumrechitsas2     = j2;
00827         int Tidnumrechitmatched2 = k2;
00828 
00829         int ilay = tTopo->tidRing(myid) - 1; //for histogram filling
00830         
00831         if(tTopo->tidStereo(myid)==0){
00832           for(int k = 0; k<Tidnumrechitrphi; k++){
00833             meNstpRphiTID[ilay]->Fill(clusizrphi[k]);
00834             meAdcRphiTID[ilay]->Fill(cluchgrphi[k]);
00835             mePosxRphiTID[ilay]->Fill(rechitrphix[k]);
00836             meErrxRphiTID[ilay]->Fill(sqrt(rechitrphierrx[k]));
00837             meResRphiTID[ilay]->Fill(rechitrphires[k]);
00838             mePullLFRphiTID[ilay]->Fill(rechitrphires[k]/sqrt(rechitrphierrx[k]));
00839             mePullMFRphiTID[ilay]->Fill(rechitrphipullMF[k]);
00840           }
00841           for(int l = 0; l<Tidnumrechitrphi2; l++){
00842             meChi2RphiTID[ilay]->Fill(chi2rphi[l]);
00843           }
00844 
00845         } else  if(tTopo->tidStereo(myid)==1){
00846           for(int kk = 0; kk < Tidnumrechitsas; kk++)       
00847             {
00848               meNstpSasTID[ilay]->Fill(clusizsas[kk]);
00849               meAdcSasTID[ilay]->Fill(cluchgsas[kk]);
00850               mePosxSasTID[ilay]->Fill(rechitsasx[kk]);
00851               meErrxSasTID[ilay]->Fill(sqrt(rechitsaserrx[kk]));
00852               meResSasTID[ilay]->Fill(rechitsasres[kk]);
00853               mePullLFSasTID[ilay]->Fill(rechitsasres[kk]/sqrt(rechitsaserrx[kk]));
00854               mePullMFSasTID[ilay]->Fill(rechitsaspullMF[kk]);
00855             }     
00856           for(int l = 0; l<Tidnumrechitsas2; l++){
00857             meChi2SasTID[ilay]->Fill(chi2sas[l]);
00858           }
00859 
00860         }
00861         if(Tidnumrechitmatched>0){
00862           for(int kkk = 0; kkk<Tidnumrechitmatched; kkk++)
00863             {
00864               mePosxMatchedTID[ilay]->Fill(rechitmatchedx[kkk]);
00865               mePosyMatchedTID[ilay]->Fill(rechitmatchedy[kkk]);
00866               meErrxMatchedTID[ilay]->Fill(sqrt(rechitmatchederrxx[kkk]));
00867               meErryMatchedTID[ilay]->Fill(sqrt(rechitmatchederryy[kkk]));
00868               meResxMatchedTID[ilay]->Fill(rechitmatchedresx[kkk]);
00869               meResyMatchedTID[ilay]->Fill(rechitmatchedresy[kkk]);
00870             }
00871           for(int l = 0; l<Tidnumrechitmatched2; l++){
00872             meChi2MatchedTID[ilay]->Fill(chi2matched[l]);
00873           }
00874           
00875         }
00876       }
00877       if (detid.subdetId() == int(StripSubdetector::TEC)){
00878         
00879         int Tecnumrechitrphi    = numrechitrphi;
00880         int Tecnumrechitsas     = numrechitsas;
00881         int Tecnumrechitmatched = numrechitmatched;
00882         totTecnumrechitrphi +=numrechitrphi;
00883         totTecnumrechitsas +=numrechitsas;
00884         totTecnumrechitmatched +=numrechitmatched;
00885 
00886         int Tecnumrechitrphi2    = i2;
00887         int Tecnumrechitsas2     = j2;
00888         int Tecnumrechitmatched2 = k2;
00889 
00890         int ilay = tTopo->tecRing(myid) - 1; //for histogram filling
00891         
00892         if(tTopo->tecStereo(myid)==0){
00893           for(int k = 0; k<Tecnumrechitrphi; k++){
00894             meNstpRphiTEC[ilay]->Fill(clusizrphi[k]);
00895             meAdcRphiTEC[ilay]->Fill(cluchgrphi[k]);
00896             mePosxRphiTEC[ilay]->Fill(rechitrphix[k]);
00897             meErrxRphiTEC[ilay]->Fill(sqrt(rechitrphierrx[k]));
00898             meResRphiTEC[ilay]->Fill(rechitrphires[k]);
00899             mePullLFRphiTEC[ilay]->Fill(rechitrphires[k]/sqrt(rechitrphierrx[k]));
00900             mePullMFRphiTEC[ilay]->Fill(rechitrphipullMF[k]);
00901           }
00902           for(int l = 0; l<Tecnumrechitrphi2; l++){
00903             meChi2RphiTEC[ilay]->Fill(chi2rphi[l]);
00904           }
00905 
00906         } else  if(tTopo->tecStereo(myid)==1){
00907           for(int kk = 0; kk < Tecnumrechitsas; kk++)       
00908             {
00909               meNstpSasTEC[ilay]->Fill(clusizsas[kk]);
00910               meAdcSasTEC[ilay]->Fill(cluchgsas[kk]);
00911               mePosxSasTEC[ilay]->Fill(rechitsasx[kk]);
00912               meErrxSasTEC[ilay]->Fill(sqrt(rechitsaserrx[kk]));
00913               meResSasTEC[ilay]->Fill(rechitsasres[kk]);
00914               mePullLFSasTEC[ilay]->Fill(rechitsasres[kk]/sqrt(rechitsaserrx[kk]));
00915               mePullMFSasTEC[ilay]->Fill(rechitsaspullMF[kk]);
00916             }     
00917           for(int l = 0; l<Tecnumrechitsas2; l++){
00918             meChi2SasTEC[ilay]->Fill(chi2sas[l]);
00919           }
00920 
00921         }
00922         if(Tecnumrechitmatched>0){
00923           for(int kkk = 0; kkk<Tecnumrechitmatched; kkk++)
00924             {
00925               mePosxMatchedTEC[ilay]->Fill(rechitmatchedx[kkk]);
00926               mePosyMatchedTEC[ilay]->Fill(rechitmatchedy[kkk]);
00927               meErrxMatchedTEC[ilay]->Fill(sqrt(rechitmatchederrxx[kkk]));
00928               meErryMatchedTEC[ilay]->Fill(sqrt(rechitmatchederryy[kkk]));
00929               meResxMatchedTEC[ilay]->Fill(rechitmatchedresx[kkk]);
00930               meResyMatchedTEC[ilay]->Fill(rechitmatchedresy[kkk]);
00931             }     
00932           for(int l = 0; l<Tecnumrechitmatched2; l++){
00933             meChi2MatchedTEC[ilay]->Fill(chi2matched[l]);
00934           }
00935 
00936         }
00937       }
00938 
00939     }
00940   }
00941 
00942   //now fill the cumulative histograms of the hits
00943 
00944   meNumRphiTIB->Fill(totTibnumrechitrphi);
00945   meNumSasTIB->Fill(totTibnumrechitsas);
00946   meNumMatchedTIB->Fill(totTibnumrechitmatched);
00947   meNumRphiTOB->Fill(totTobnumrechitrphi);
00948   meNumSasTOB->Fill(totTobnumrechitsas);
00949   meNumMatchedTOB->Fill(totTobnumrechitmatched);
00950   meNumRphiTID->Fill(totTidnumrechitrphi);
00951   meNumSasTID->Fill(totTidnumrechitsas);
00952   meNumMatchedTID->Fill(totTidnumrechitmatched);
00953   meNumRphiTEC->Fill(totTecnumrechitrphi);
00954   meNumSasTEC->Fill(totTecnumrechitsas);
00955   meNumMatchedTEC->Fill(totTecnumrechitmatched);
00956 
00957   meNumTotRphi->Fill(totrechitrphi);
00958   meNumTotSas->Fill(totrechitsas);
00959   meNumTotMatched->Fill(totrechitmatched);
00960 
00961  
00962 }
00963 
00964   
00965 //needed by to do the residual for matched hits
00966 std::pair<LocalPoint,LocalVector> SiStripRecHitsValid::projectHit( const PSimHit& hit, const StripGeomDetUnit* stripDet,
00967                                                                    const BoundPlane& plane) 
00968 {
00969   //  const StripGeomDetUnit* stripDet = dynamic_cast<const StripGeomDetUnit*>(hit.det());
00970   //if (stripDet == 0) throw MeasurementDetException("HitMatcher hit is not on StripGeomDetUnit");
00971   
00972   const StripTopology& topol = stripDet->specificTopology();
00973   GlobalPoint globalpos= stripDet->surface().toGlobal(hit.localPosition());
00974   LocalPoint localHit = plane.toLocal(globalpos);
00975   //track direction
00976   LocalVector locdir=hit.localDirection();
00977   //rotate track in new frame
00978   
00979   GlobalVector globaldir= stripDet->surface().toGlobal(locdir);
00980   LocalVector dir=plane.toLocal(globaldir);
00981   float scale = -localHit.z() / dir.z();
00982   
00983   LocalPoint projectedPos = localHit + scale*dir;
00984   
00985   //  std::cout << "projectedPos " << projectedPos << std::endl;
00986   
00987   float selfAngle = topol.stripAngle( topol.strip( hit.localPosition()));
00988   
00989   LocalVector stripDir( sin(selfAngle), cos(selfAngle), 0); // vector along strip in hit frame
00990   
00991   LocalVector localStripDir( plane.toLocal(stripDet->surface().toGlobal( stripDir)));
00992   
00993   return std::pair<LocalPoint,LocalVector>( projectedPos, localStripDir);
00994 }
00995 
00996