CMS 3D CMS Logo

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