CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DQM/SiPixelMonitorTrack/src/SiPixelTrackResidualSource.cc

Go to the documentation of this file.
00001 // Package:    SiPixelMonitorTrack
00002 // Class:      SiPixelTrackResidualSource
00003 // 
00004 // class SiPixelTrackResidualSource SiPixelTrackResidualSource.cc 
00005 //       DQM/SiPixelMonitorTrack/src/SiPixelTrackResidualSource.cc
00006 //
00007 // Description: SiPixel hit-to-track residual data quality monitoring modules
00008 // Implementation: prototype -> improved -> never final - end of the 1st step 
00009 //
00010 // Original Author: Shan-Huei Chuang
00011 //         Created: Fri Mar 23 18:41:42 CET 2007
00012 //         Updated by Lukas Wehrli (plots for clusters on/off track added)
00013 // $Id: SiPixelTrackResidualSource.cc,v 1.23 2012/01/28 08:10:14 slava77 Exp $
00014 
00015 
00016 #include <iostream>
00017 #include <map>
00018 #include <string>
00019 #include <vector>
00020 #include <utility>
00021 
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 #include "FWCore/Framework/interface/ESHandle.h"
00024 
00025 #include "DataFormats/Common/interface/Handle.h"
00026 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00027 
00028 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00029 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00030 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00031 
00032 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
00033 
00034 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00035 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00036 
00037 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
00038 
00039 #include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h"
00040 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00041 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00042 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00043 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00044 
00045 #include "DQMServices/Core/interface/DQMStore.h"
00046 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
00047 #include "DQM/SiPixelMonitorTrack/interface/SiPixelTrackResidualSource.h"
00048 
00049 
00050 using namespace std;
00051 using namespace edm;
00052 
00053 
00054 SiPixelTrackResidualSource::SiPixelTrackResidualSource(const edm::ParameterSet& pSet) :
00055   pSet_(pSet),
00056   modOn( pSet.getUntrackedParameter<bool>("modOn",true) ),
00057   reducedSet( pSet.getUntrackedParameter<bool>("reducedSet",true) ),
00058   ladOn( pSet.getUntrackedParameter<bool>("ladOn",false) ), 
00059   layOn( pSet.getUntrackedParameter<bool>("layOn",false) ), 
00060   phiOn( pSet.getUntrackedParameter<bool>("phiOn",false) ), 
00061   ringOn( pSet.getUntrackedParameter<bool>("ringOn",false) ), 
00062   bladeOn( pSet.getUntrackedParameter<bool>("bladeOn",false) ), 
00063   diskOn( pSet.getUntrackedParameter<bool>("diskOn",false) )
00064  { 
00065    pSet_ = pSet; 
00066   debug_ = pSet_.getUntrackedParameter<bool>("debug", false); 
00067     src_ = pSet_.getParameter<edm::InputTag>("src"); 
00068     clustersrc_ = pSet_.getParameter<edm::InputTag>("clustersrc");
00069     tracksrc_ = pSet_.getParameter<edm::InputTag>("trajectoryInput");
00070     dbe_ = edm::Service<DQMStore>().operator->();
00071 
00072   LogInfo("PixelDQM") << "SiPixelTrackResidualSource constructor" << endl;
00073   LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/" 
00074             << layOn << "/" << phiOn << std::endl;
00075   LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/" 
00076             << ringOn << std::endl;
00077 }
00078 
00079 
00080 SiPixelTrackResidualSource::~SiPixelTrackResidualSource() {
00081   LogInfo("PixelDQM") << "SiPixelTrackResidualSource destructor" << endl;
00082 
00083   std::map<uint32_t,SiPixelTrackResidualModule*>::iterator struct_iter;
00084   for (struct_iter = theSiPixelStructure.begin() ; struct_iter != theSiPixelStructure.end() ; struct_iter++){
00085     delete struct_iter->second;
00086     struct_iter->second = 0;
00087   }
00088 }
00089 
00090 void SiPixelTrackResidualSource::beginJob() {
00091   LogInfo("PixelDQM") << "SiPixelTrackResidualSource beginJob()" << endl;
00092   firstRun = true;
00093   NTotal=0;
00094   NLowProb=0;
00095 }
00096 
00097 
00098 void SiPixelTrackResidualSource::beginRun(const edm::Run& r, edm::EventSetup const& iSetup) {
00099   LogInfo("PixelDQM") << "SiPixelTrackResidualSource beginRun()" << endl;
00100 
00101   if(firstRun){
00102   // retrieve TrackerGeometry for pixel dets
00103   edm::ESHandle<TrackerGeometry> TG;
00104   iSetup.get<TrackerDigiGeometryRecord>().get(TG);
00105   if (debug_) LogVerbatim("PixelDQM") << "TrackerGeometry "<< &(*TG) <<" size is "<< TG->dets().size() << endl;
00106  
00107   // build theSiPixelStructure with the pixel barrel and endcap dets from TrackerGeometry
00108   for (TrackerGeometry::DetContainer::const_iterator pxb = TG->detsPXB().begin();  
00109        pxb!=TG->detsPXB().end(); pxb++) {
00110     if (dynamic_cast<PixelGeomDetUnit*>((*pxb))!=0) {
00111       SiPixelTrackResidualModule* module = new SiPixelTrackResidualModule((*pxb)->geographicalId().rawId());
00112       theSiPixelStructure.insert(pair<uint32_t, SiPixelTrackResidualModule*>((*pxb)->geographicalId().rawId(), module));
00113     }
00114   }
00115   for (TrackerGeometry::DetContainer::const_iterator pxf = TG->detsPXF().begin(); 
00116        pxf!=TG->detsPXF().end(); pxf++) {
00117     if (dynamic_cast<PixelGeomDetUnit*>((*pxf))!=0) {
00118       SiPixelTrackResidualModule* module = new SiPixelTrackResidualModule((*pxf)->geographicalId().rawId());
00119       theSiPixelStructure.insert(pair<uint32_t, SiPixelTrackResidualModule*>((*pxf)->geographicalId().rawId(), module));
00120     }
00121   }
00122   LogInfo("PixelDQM") << "SiPixelStructure size is " << theSiPixelStructure.size() << endl;
00123 
00124   // book residual histograms in theSiPixelFolder - one (x,y) pair of histograms per det
00125   SiPixelFolderOrganizer theSiPixelFolder;
00126   for (std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.begin(); 
00127        pxd!=theSiPixelStructure.end(); pxd++) {
00128 
00129     if(modOn){
00130       if (theSiPixelFolder.setModuleFolder((*pxd).first)) (*pxd).second->book(pSet_,reducedSet);
00131       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Folder Creation Failed! "; 
00132     }
00133     if(ladOn){
00134       if (theSiPixelFolder.setModuleFolder((*pxd).first,1)) {
00135         
00136         (*pxd).second->book(pSet_,reducedSet,1);
00137       }
00138       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource ladder Folder Creation Failed! "; 
00139     }
00140     if(layOn){
00141       if (theSiPixelFolder.setModuleFolder((*pxd).first,2)) (*pxd).second->book(pSet_,reducedSet,2);
00142       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource layer Folder Creation Failed! "; 
00143     }
00144     if(phiOn){
00145       if (theSiPixelFolder.setModuleFolder((*pxd).first,3)) (*pxd).second->book(pSet_,reducedSet,3);
00146       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource phi Folder Creation Failed! "; 
00147     }
00148     if(bladeOn){
00149       if (theSiPixelFolder.setModuleFolder((*pxd).first,4)) (*pxd).second->book(pSet_,reducedSet,4);
00150       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Blade Folder Creation Failed! "; 
00151     }
00152     if(diskOn){
00153       if (theSiPixelFolder.setModuleFolder((*pxd).first,5)) (*pxd).second->book(pSet_,reducedSet,5);
00154       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Disk Folder Creation Failed! "; 
00155     }
00156     if(ringOn){
00157       if (theSiPixelFolder.setModuleFolder((*pxd).first,6)) (*pxd).second->book(pSet_,reducedSet,6);
00158       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Ring Folder Creation Failed! "; 
00159     }
00160   }
00161 
00162 
00163 //   edm::InputTag tracksrc = pSet_.getParameter<edm::InputTag>("trajectoryInput");
00164 //   edm::InputTag clustersrc = pSet_.getParameter<edm::InputTag>("clustersrc");
00165 
00166   //number of tracks
00167   dbe_->setCurrentFolder("Pixel/Tracks");
00168   meNofTracks_ = dbe_->book1D("ntracks_" + tracksrc_.label(),"Number of Tracks",4,0,4);
00169   meNofTracks_->setAxisTitle("Number of Tracks",1);
00170   meNofTracks_->setBinLabel(1,"All");
00171   meNofTracks_->setBinLabel(2,"Pixel");
00172   meNofTracks_->setBinLabel(3,"BPix");
00173   meNofTracks_->setBinLabel(4,"FPix");
00174 
00175   //number of tracks in pixel fiducial volume
00176   dbe_->setCurrentFolder("Pixel/Tracks");
00177   meNofTracksInPixVol_ = dbe_->book1D("ntracksInPixVol_" + tracksrc_.label(),"Number of Tracks crossing Pixel fiducial Volume",2,0,2);
00178   meNofTracksInPixVol_->setAxisTitle("Number of Tracks",1);
00179   meNofTracksInPixVol_->setBinLabel(1,"With Hits");
00180   meNofTracksInPixVol_->setBinLabel(2,"Without Hits");
00181 
00182   //number of clusters (associated to track / not associated)
00183   dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00184   meNofClustersOnTrack_ = dbe_->book1D("nclusters_" + clustersrc_.label() + "_tot","Number of Clusters (on track)",3,0,3);
00185   meNofClustersOnTrack_->setAxisTitle("Number of Clusters on Track",1);
00186   meNofClustersOnTrack_->setBinLabel(1,"All");
00187   meNofClustersOnTrack_->setBinLabel(2,"BPix");
00188   meNofClustersOnTrack_->setBinLabel(3,"FPix");
00189   dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00190   meNofClustersNotOnTrack_ = dbe_->book1D("nclusters_" + clustersrc_.label() + "_tot","Number of Clusters (off track)",3,0,3);
00191   meNofClustersNotOnTrack_->setAxisTitle("Number of Clusters off Track",1);
00192   meNofClustersNotOnTrack_->setBinLabel(1,"All");
00193   meNofClustersNotOnTrack_->setBinLabel(2,"BPix");
00194   meNofClustersNotOnTrack_->setBinLabel(3,"FPix");
00195 
00196   //cluster charge and size
00197   //charge
00198   //on track
00199   dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00200   meClChargeOnTrack_all = dbe_->book1D("charge_" + clustersrc_.label(),"Charge (on track)",500,0.,500.);
00201   meClChargeOnTrack_all->setAxisTitle("Charge size (in ke)",1);
00202   meClChargeOnTrack_bpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Barrel","Charge (on track, barrel)",500,0.,500.);
00203   meClChargeOnTrack_bpix->setAxisTitle("Charge size (in ke)",1);
00204   meClChargeOnTrack_fpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Endcap","Charge (on track, endcap)",500,0.,500.);
00205   meClChargeOnTrack_fpix->setAxisTitle("Charge size (in ke)",1);
00206   meClChargeOnTrack_layer1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_1","Charge (on track, layer1)",500,0.,500.);
00207   meClChargeOnTrack_layer1->setAxisTitle("Charge size (in ke)",1);
00208   meClChargeOnTrack_layer2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_2","Charge (on track, layer2)",500,0.,500.);
00209   meClChargeOnTrack_layer2->setAxisTitle("Charge size (in ke)",1);
00210   meClChargeOnTrack_layer3 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_3","Charge (on track, layer3)",500,0.,500.);
00211   meClChargeOnTrack_layer3->setAxisTitle("Charge size (in ke)",1);
00212   meClChargeOnTrack_diskp1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p1","Charge (on track, diskp1)",500,0.,500.);
00213   meClChargeOnTrack_diskp1->setAxisTitle("Charge size (in ke)",1);
00214   meClChargeOnTrack_diskp2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p2","Charge (on track, diskp2)",500,0.,500.);
00215   meClChargeOnTrack_diskp2->setAxisTitle("Charge size (in ke)",1);
00216   meClChargeOnTrack_diskm1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m1","Charge (on track, diskm1)",500,0.,500.);
00217   meClChargeOnTrack_diskm1->setAxisTitle("Charge size (in ke)",1);
00218   meClChargeOnTrack_diskm2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m2","Charge (on track, diskm2)",500,0.,500.);
00219   meClChargeOnTrack_diskm2->setAxisTitle("Charge size (in ke)",1);
00220   //off track
00221   dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00222   meClChargeNotOnTrack_all = dbe_->book1D("charge_" + clustersrc_.label(),"Charge (off track)",500,0.,500.);
00223   meClChargeNotOnTrack_all->setAxisTitle("Charge size (in ke)",1);
00224   meClChargeNotOnTrack_bpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Barrel","Charge (off track, barrel)",500,0.,500.);
00225   meClChargeNotOnTrack_bpix->setAxisTitle("Charge size (in ke)",1);
00226   meClChargeNotOnTrack_fpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Endcap","Charge (off track, endcap)",500,0.,500.);
00227   meClChargeNotOnTrack_fpix->setAxisTitle("Charge size (in ke)",1);
00228   meClChargeNotOnTrack_layer1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_1","Charge (off track, layer1)",500,0.,500.);
00229   meClChargeNotOnTrack_layer1->setAxisTitle("Charge size (in ke)",1);
00230   meClChargeNotOnTrack_layer2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_2","Charge (off track, layer2)",500,0.,500.);
00231   meClChargeNotOnTrack_layer2->setAxisTitle("Charge size (in ke)",1);
00232   meClChargeNotOnTrack_layer3 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_3","Charge (off track, layer3)",500,0.,500.);
00233   meClChargeNotOnTrack_layer3->setAxisTitle("Charge size (in ke)",1);
00234   meClChargeNotOnTrack_diskp1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p1","Charge (off track, diskp1)",500,0.,500.);
00235   meClChargeNotOnTrack_diskp1->setAxisTitle("Charge size (in ke)",1);
00236   meClChargeNotOnTrack_diskp2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p2","Charge (off track, diskp2)",500,0.,500.);
00237   meClChargeNotOnTrack_diskp2->setAxisTitle("Charge size (in ke)",1);
00238   meClChargeNotOnTrack_diskm1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m1","Charge (off track, diskm1)",500,0.,500.);
00239   meClChargeNotOnTrack_diskm1->setAxisTitle("Charge size (in ke)",1);
00240   meClChargeNotOnTrack_diskm2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m2","Charge (off track, diskm2)",500,0.,500.);
00241   meClChargeNotOnTrack_diskm2->setAxisTitle("Charge size (in ke)",1);
00242 
00243   //size
00244   //on track
00245   dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00246   meClSizeOnTrack_all = dbe_->book1D("size_" + clustersrc_.label(),"Size (on track)",100,0.,100.);
00247   meClSizeOnTrack_all->setAxisTitle("Cluster size (in pixels)",1);
00248   meClSizeOnTrack_bpix = dbe_->book1D("size_" + clustersrc_.label() + "_Barrel","Size (on track, barrel)",100,0.,100.);
00249   meClSizeOnTrack_bpix->setAxisTitle("Cluster size (in pixels)",1);
00250   meClSizeOnTrack_fpix = dbe_->book1D("size_" + clustersrc_.label() + "_Endcap","Size (on track, endcap)",100,0.,100.);
00251   meClSizeOnTrack_fpix->setAxisTitle("Cluster size (in pixels)",1);
00252   meClSizeOnTrack_layer1 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_1","Size (on track, layer1)",100,0.,100.);
00253   meClSizeOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00254   meClSizeOnTrack_layer2 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_2","Size (on track, layer2)",100,0.,100.);
00255   meClSizeOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00256   meClSizeOnTrack_layer3 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_3","Size (on track, layer3)",100,0.,100.);
00257   meClSizeOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00258   meClSizeOnTrack_diskp1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p1","Size (on track, diskp1)",100,0.,100.);
00259   meClSizeOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00260   meClSizeOnTrack_diskp2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p2","Size (on track, diskp2)",100,0.,100.);
00261   meClSizeOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00262   meClSizeOnTrack_diskm1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m1","Size (on track, diskm1)",100,0.,100.);
00263   meClSizeOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00264   meClSizeOnTrack_diskm2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m2","Size (on track, diskm2)",100,0.,100.);
00265   meClSizeOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00266   meClSizeXOnTrack_all = dbe_->book1D("sizeX_" + clustersrc_.label(),"SizeX (on track)",100,0.,100.);
00267   meClSizeXOnTrack_all->setAxisTitle("Cluster sizeX (in pixels)",1);
00268   meClSizeXOnTrack_bpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Barrel","SizeX (on track, barrel)",100,0.,100.);
00269   meClSizeXOnTrack_bpix->setAxisTitle("Cluster sizeX (in pixels)",1);
00270   meClSizeXOnTrack_fpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Endcap","SizeX (on track, endcap)",100,0.,100.);
00271   meClSizeXOnTrack_fpix->setAxisTitle("Cluster sizeX (in pixels)",1);
00272   meClSizeXOnTrack_layer1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_1","SizeX (on track, layer1)",100,0.,100.);
00273   meClSizeXOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00274   meClSizeXOnTrack_layer2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_2","SizeX (on track, layer2)",100,0.,100.);
00275   meClSizeXOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00276   meClSizeXOnTrack_layer3 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_3","SizeX (on track, layer3)",100,0.,100.);
00277   meClSizeXOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00278   meClSizeXOnTrack_diskp1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p1","SizeX (on track, diskp1)",100,0.,100.);
00279   meClSizeXOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00280   meClSizeXOnTrack_diskp2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p2","SizeX (on track, diskp2)",100,0.,100.);
00281   meClSizeXOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00282   meClSizeXOnTrack_diskm1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m1","SizeX (on track, diskm1)",100,0.,100.);
00283   meClSizeXOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00284   meClSizeXOnTrack_diskm2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m2","SizeX (on track, diskm2)",100,0.,100.);
00285   meClSizeXOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00286   meClSizeYOnTrack_all = dbe_->book1D("sizeY_" + clustersrc_.label(),"SizeY (on track)",100,0.,100.);
00287   meClSizeYOnTrack_all->setAxisTitle("Cluster sizeY (in pixels)",1);
00288   meClSizeYOnTrack_bpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Barrel","SizeY (on track, barrel)",100,0.,100.);
00289   meClSizeYOnTrack_bpix->setAxisTitle("Cluster sizeY (in pixels)",1);
00290   meClSizeYOnTrack_fpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Endcap","SizeY (on track, endcap)",100,0.,100.);
00291   meClSizeYOnTrack_fpix->setAxisTitle("Cluster sizeY (in pixels)",1);
00292   meClSizeYOnTrack_layer1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_1","SizeY (on track, layer1)",100,0.,100.);
00293   meClSizeYOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00294   meClSizeYOnTrack_layer2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_2","SizeY (on track, layer2)",100,0.,100.);
00295   meClSizeYOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00296   meClSizeYOnTrack_layer3 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_3","SizeY (on track, layer3)",100,0.,100.);
00297   meClSizeYOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00298   meClSizeYOnTrack_diskp1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p1","SizeY (on track, diskp1)",100,0.,100.);
00299   meClSizeYOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00300   meClSizeYOnTrack_diskp2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p2","SizeY (on track, diskp2)",100,0.,100.);
00301   meClSizeYOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00302   meClSizeYOnTrack_diskm1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m1","SizeY (on track, diskm1)",100,0.,100.);
00303   meClSizeYOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00304   meClSizeYOnTrack_diskm2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m2","SizeY (on track, diskm2)",100,0.,100.);
00305   meClSizeYOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00306   //off track
00307   dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00308   meClSizeNotOnTrack_all = dbe_->book1D("size_" + clustersrc_.label(),"Size (off track)",100,0.,100.);
00309   meClSizeNotOnTrack_all->setAxisTitle("Cluster size (in pixels)",1); 
00310   meClSizeNotOnTrack_bpix = dbe_->book1D("size_" + clustersrc_.label() + "_Barrel","Size (off track, barrel)",100,0.,100.);
00311   meClSizeNotOnTrack_bpix->setAxisTitle("Cluster size (in pixels)",1);
00312   meClSizeNotOnTrack_fpix = dbe_->book1D("size_" + clustersrc_.label() + "_Endcap","Size (off track, endcap)",100,0.,100.);
00313   meClSizeNotOnTrack_fpix->setAxisTitle("Cluster size (in pixels)",1);
00314   meClSizeNotOnTrack_layer1 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_1","Size (off track, layer1)",100,0.,100.);
00315   meClSizeNotOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00316   meClSizeNotOnTrack_layer2 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_2","Size (off track, layer2)",100,0.,100.);
00317   meClSizeNotOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00318   meClSizeNotOnTrack_layer3 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_3","Size (off track, layer3)",100,0.,100.);
00319   meClSizeNotOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00320   meClSizeNotOnTrack_diskp1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p1","Size (off track, diskp1)",100,0.,100.);
00321   meClSizeNotOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00322   meClSizeNotOnTrack_diskp2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p2","Size (off track, diskp2)",100,0.,100.);
00323   meClSizeNotOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00324   meClSizeNotOnTrack_diskm1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m1","Size (off track, diskm1)",100,0.,100.);
00325   meClSizeNotOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00326   meClSizeNotOnTrack_diskm2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m2","Size (off track, diskm2)",100,0.,100.);
00327   meClSizeNotOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00328   meClSizeXNotOnTrack_all = dbe_->book1D("sizeX_" + clustersrc_.label(),"SizeX (off track)",100,0.,100.);
00329   meClSizeXNotOnTrack_all->setAxisTitle("Cluster sizeX (in pixels)",1);
00330   meClSizeXNotOnTrack_bpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Barrel","SizeX (off track, barrel)",100,0.,100.);
00331   meClSizeXNotOnTrack_bpix->setAxisTitle("Cluster sizeX (in pixels)",1);
00332   meClSizeXNotOnTrack_fpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Endcap","SizeX (off track, endcap)",100,0.,100.);
00333   meClSizeXNotOnTrack_fpix->setAxisTitle("Cluster sizeX (in pixels)",1);
00334   meClSizeXNotOnTrack_layer1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_1","SizeX (off track, layer1)",100,0.,100.);
00335   meClSizeXNotOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00336   meClSizeXNotOnTrack_layer2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_2","SizeX (off track, layer2)",100,0.,100.);
00337   meClSizeXNotOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00338   meClSizeXNotOnTrack_layer3 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_3","SizeX (off track, layer3)",100,0.,100.);
00339   meClSizeXNotOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00340   meClSizeXNotOnTrack_diskp1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p1","SizeX (off track, diskp1)",100,0.,100.);
00341   meClSizeXNotOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00342   meClSizeXNotOnTrack_diskp2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p2","SizeX (off track, diskp2)",100,0.,100.);
00343   meClSizeXNotOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00344   meClSizeXNotOnTrack_diskm1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m1","SizeX (off track, diskm1)",100,0.,100.);
00345   meClSizeXNotOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00346   meClSizeXNotOnTrack_diskm2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m2","SizeX (off track, diskm2)",100,0.,100.);
00347   meClSizeXNotOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00348   meClSizeYNotOnTrack_all = dbe_->book1D("sizeY_" + clustersrc_.label(),"SizeY (off track)",100,0.,100.);
00349   meClSizeYNotOnTrack_all->setAxisTitle("Cluster sizeY (in pixels)",1);
00350   meClSizeYNotOnTrack_bpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Barrel","SizeY (off track, barrel)",100,0.,100.);
00351   meClSizeYNotOnTrack_bpix->setAxisTitle("Cluster sizeY (in pixels)",1);
00352   meClSizeYNotOnTrack_fpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Endcap","SizeY (off track, endcap)",100,0.,100.);
00353   meClSizeYNotOnTrack_fpix->setAxisTitle("Cluster sizeY (in pixels)",1);
00354   meClSizeYNotOnTrack_layer1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_1","SizeY (off track, layer1)",100,0.,100.);
00355   meClSizeYNotOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00356   meClSizeYNotOnTrack_layer2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_2","SizeY (off track, layer2)",100,0.,100.);
00357   meClSizeYNotOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00358   meClSizeYNotOnTrack_layer3 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_3","SizeY (off track, layer3)",100,0.,100.);
00359   meClSizeYNotOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00360   meClSizeYNotOnTrack_diskp1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p1","SizeY (off track, diskp1)",100,0.,100.);
00361   meClSizeYNotOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00362   meClSizeYNotOnTrack_diskp2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p2","SizeY (off track, diskp2)",100,0.,100.);
00363   meClSizeYNotOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00364   meClSizeYNotOnTrack_diskm1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m1","SizeY (off track, diskm1)",100,0.,100.);
00365   meClSizeYNotOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00366   meClSizeYNotOnTrack_diskm2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m2","SizeY (off track, diskm2)",100,0.,100.);
00367   meClSizeYNotOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00368   
00369 
00370   //cluster global position
00371   //on track
00372   dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00373   //bpix
00374   meClPosLayer1OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_1","Clusters Layer1 (on track)",200,-30.,30.,128,-3.2,3.2);
00375   meClPosLayer1OnTrack->setAxisTitle("Global Z (cm)",1);
00376   meClPosLayer1OnTrack->setAxisTitle("Global #phi",2);
00377   meClPosLayer2OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_2","Clusters Layer2 (on track)",200,-30.,30.,128,-3.2,3.2);
00378   meClPosLayer2OnTrack->setAxisTitle("Global Z (cm)",1);
00379   meClPosLayer2OnTrack->setAxisTitle("Global #phi",2);
00380   meClPosLayer3OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_3","Clusters Layer3 (on track)",200,-30.,30.,128,-3.2,3.2);
00381   meClPosLayer3OnTrack->setAxisTitle("Global Z (cm)",1);
00382   meClPosLayer3OnTrack->setAxisTitle("Global #phi",2);
00383   //fpix
00384   meClPosDisk1pzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_1","Clusters +Z Disk1 (on track)",80,-20.,20.,80,-20.,20.);
00385   meClPosDisk1pzOnTrack->setAxisTitle("Global X (cm)",1);
00386   meClPosDisk1pzOnTrack->setAxisTitle("Global Y (cm)",2);
00387   meClPosDisk2pzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_2","Clusters +Z Disk2 (on track)",80,-20.,20.,80,-20.,20.);
00388   meClPosDisk2pzOnTrack->setAxisTitle("Global X (cm)",1);
00389   meClPosDisk2pzOnTrack->setAxisTitle("Global Y (cm)",2);
00390   meClPosDisk1mzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_1","Clusters -Z Disk1 (on track)",80,-20.,20.,80,-20.,20.);
00391   meClPosDisk1mzOnTrack->setAxisTitle("Global X (cm)",1);
00392   meClPosDisk1mzOnTrack->setAxisTitle("Global Y (cm)",2);
00393   meClPosDisk2mzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_2","Clusters -Z Disk2 (on track)",80,-20.,20.,80,-20.,20.);
00394   meClPosDisk2mzOnTrack->setAxisTitle("Global X (cm)",1);
00395   meClPosDisk2mzOnTrack->setAxisTitle("Global Y (cm)",2);
00396 
00397   meNClustersOnTrack_all = dbe_->book1D("nclusters_" + clustersrc_.label(),"Number of Clusters (on Track)",50,0.,50.);
00398   meNClustersOnTrack_all->setAxisTitle("Number of Clusters",1);
00399   meNClustersOnTrack_bpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Barrel","Number of Clusters (on track, barrel)",50,0.,50.);
00400   meNClustersOnTrack_bpix->setAxisTitle("Number of Clusters",1);
00401   meNClustersOnTrack_fpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Endcap","Number of Clusters (on track, endcap)",50,0.,50.);
00402   meNClustersOnTrack_fpix->setAxisTitle("Number of Clusters",1);
00403   meNClustersOnTrack_layer1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_1","Number of Clusters (on track, layer1)",50,0.,50.);
00404   meNClustersOnTrack_layer1->setAxisTitle("Number of Clusters",1);
00405   meNClustersOnTrack_layer2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_2","Number of Clusters (on track, layer2)",50,0.,50.);
00406   meNClustersOnTrack_layer2->setAxisTitle("Number of Clusters",1);
00407   meNClustersOnTrack_layer3 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_3","Number of Clusters (on track, layer3)",50,0.,50.);
00408   meNClustersOnTrack_layer3->setAxisTitle("Number of Clusters",1);
00409   meNClustersOnTrack_diskp1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p1","Number of Clusters (on track, diskp1)",50,0.,50.);
00410   meNClustersOnTrack_diskp1->setAxisTitle("Number of Clusters",1);
00411   meNClustersOnTrack_diskp2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p2","Number of Clusters (on track, diskp2)",50,0.,50.);
00412   meNClustersOnTrack_diskp2->setAxisTitle("Number of Clusters",1);
00413   meNClustersOnTrack_diskm1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m1","Number of Clusters (on track, diskm1)",50,0.,50.);
00414   meNClustersOnTrack_diskm1->setAxisTitle("Number of Clusters",1);
00415   meNClustersOnTrack_diskm2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m2","Number of Clusters (on track, diskm2)",50,0.,50.);
00416   meNClustersOnTrack_diskm2->setAxisTitle("Number of Clusters",1);
00417 
00418   //not on track
00419   dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00420   //bpix
00421   meClPosLayer1NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_1","Clusters Layer1 (off track)",200,-30.,30.,128,-3.2,3.2);
00422   meClPosLayer1NotOnTrack->setAxisTitle("Global Z (cm)",1);
00423   meClPosLayer1NotOnTrack->setAxisTitle("Global #phi",2);
00424   meClPosLayer2NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_2","Clusters Layer2 (off track)",200,-30.,30.,128,-3.2,3.2);
00425   meClPosLayer2NotOnTrack->setAxisTitle("Global Z (cm)",1);
00426   meClPosLayer2NotOnTrack->setAxisTitle("Global #phi",2);
00427   meClPosLayer3NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_3","Clusters Layer3 (off track)",200,-30.,30.,128,-3.2,3.2);
00428   meClPosLayer3NotOnTrack->setAxisTitle("Global Z (cm)",1);
00429   meClPosLayer3NotOnTrack->setAxisTitle("Global #phi",2);
00430   //fpix
00431   meClPosDisk1pzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_1","Clusters +Z Disk1 (off track)",80,-20.,20.,80,-20.,20.);
00432   meClPosDisk1pzNotOnTrack->setAxisTitle("Global X (cm)",1);
00433   meClPosDisk1pzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00434   meClPosDisk2pzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_2","Clusters +Z Disk2 (off track)",80,-20.,20.,80,-20.,20.);
00435   meClPosDisk2pzNotOnTrack->setAxisTitle("Global X (cm)",1);
00436   meClPosDisk2pzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00437   meClPosDisk1mzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_1","Clusters -Z Disk1 (off track)",80,-20.,20.,80,-20.,20.);
00438   meClPosDisk1mzNotOnTrack->setAxisTitle("Global X (cm)",1);
00439   meClPosDisk1mzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00440   meClPosDisk2mzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_2","Clusters -Z Disk2 (off track)",80,-20.,20.,80,-20.,20.);
00441   meClPosDisk2mzNotOnTrack->setAxisTitle("Global X (cm)",1);
00442   meClPosDisk2mzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00443 
00444   meNClustersNotOnTrack_all = dbe_->book1D("nclusters_" + clustersrc_.label(),"Number of Clusters (off Track)",50,0.,50.);
00445   meNClustersNotOnTrack_all->setAxisTitle("Number of Clusters",1);
00446   meNClustersNotOnTrack_bpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Barrel","Number of Clusters (off track, barrel)",50,0.,50.);
00447   meNClustersNotOnTrack_bpix->setAxisTitle("Number of Clusters",1);
00448   meNClustersNotOnTrack_fpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Endcap","Number of Clusters (off track, endcap)",50,0.,50.);
00449   meNClustersNotOnTrack_fpix->setAxisTitle("Number of Clusters",1);
00450   meNClustersNotOnTrack_layer1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_1","Number of Clusters (off track, layer1)",50,0.,50.);
00451   meNClustersNotOnTrack_layer1->setAxisTitle("Number of Clusters",1);
00452   meNClustersNotOnTrack_layer2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_2","Number of Clusters (off track, layer2)",50,0.,50.);
00453   meNClustersNotOnTrack_layer2->setAxisTitle("Number of Clusters",1);
00454   meNClustersNotOnTrack_layer3 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_3","Number of Clusters (off track, layer3)",50,0.,50.);
00455   meNClustersNotOnTrack_layer3->setAxisTitle("Number of Clusters",1);
00456   meNClustersNotOnTrack_diskp1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p1","Number of Clusters (off track, diskp1)",50,0.,50.);
00457   meNClustersNotOnTrack_diskp1->setAxisTitle("Number of Clusters",1);
00458   meNClustersNotOnTrack_diskp2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p2","Number of Clusters (off track, diskp2)",50,0.,50.);
00459   meNClustersNotOnTrack_diskp2->setAxisTitle("Number of Clusters",1);
00460   meNClustersNotOnTrack_diskm1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m1","Number of Clusters (off track, diskm1)",50,0.,50.);
00461   meNClustersNotOnTrack_diskm1->setAxisTitle("Number of Clusters",1);
00462   meNClustersNotOnTrack_diskm2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m2","Number of Clusters (off track, diskm2)",50,0.,50.);
00463   meNClustersNotOnTrack_diskm2->setAxisTitle("Number of Clusters",1);
00464 
00465   //HitProbability
00466   //on track
00467   dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00468   meHitProbability = dbe_->book1D("FractionLowProb","Fraction of hits with low probability;FractionLowProb;#HitsOnTrack",100,0.,1.);
00469 
00470   if (debug_) {
00471     // book summary residual histograms in a debugging folder - one (x,y) pair of histograms per subdetector 
00472     dbe_->setCurrentFolder("debugging"); 
00473     char hisID[80]; 
00474     for (int s=0; s<3; s++) {
00475       sprintf(hisID,"residual_x_subdet_%i",s); 
00476       meSubdetResidualX[s] = dbe_->book1D(hisID,"Pixel Hit-to-Track Residual in X",500,-5.,5.);
00477       
00478       sprintf(hisID,"residual_y_subdet_%i",s);
00479       meSubdetResidualY[s] = dbe_->book1D(hisID,"Pixel Hit-to-Track Residual in Y",500,-5.,5.);  
00480     }
00481   }
00482   
00483   firstRun = false;
00484   }
00485 }
00486 
00487 
00488 void SiPixelTrackResidualSource::endJob(void) {
00489   LogInfo("PixelDQM") << "SiPixelTrackResidualSource endJob()";
00490 
00491   // save the residual histograms to an output root file
00492   bool saveFile = pSet_.getUntrackedParameter<bool>("saveFile", true);
00493   if (saveFile) { 
00494     std::string outputFile = pSet_.getParameter<std::string>("outputFile");
00495     LogInfo("PixelDQM") << " - saving histograms to "<< outputFile.data();
00496     dbe_->save(outputFile);
00497   } 
00498   LogInfo("PixelDQM") << endl; // dbe_->showDirStructure();
00499 }
00500 
00501 
00502 void SiPixelTrackResidualSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00503 
00504   // retrieve TrackerGeometry again and MagneticField for use in transforming 
00505   // a TrackCandidate's P(ersistent)TrajectoryStateoOnDet (PTSoD) to a TrajectoryStateOnSurface (TSoS)
00506   ESHandle<TrackerGeometry> TG;
00507   iSetup.get<TrackerDigiGeometryRecord>().get(TG);
00508   const TrackerGeometry* theTrackerGeometry = TG.product();
00509   ESHandle<MagneticField> MF;
00510   iSetup.get<IdealMagneticFieldRecord>().get(MF);
00511   const MagneticField* theMagneticField = MF.product();
00512   
00513   // retrieve TransientTrackingRecHitBuilder to build TTRHs with TrackCandidate's TrackingRecHits for refitting 
00514   std::string TTRHBuilder = pSet_.getParameter<std::string>("TTRHBuilder"); 
00515   ESHandle<TransientTrackingRecHitBuilder> TTRHB; 
00516   iSetup.get<TransientRecHitRecord>().get(TTRHBuilder, TTRHB);
00517   const TransientTrackingRecHitBuilder* theTTRHBuilder = TTRHB.product();
00518    
00519   // get a fitter to refit TrackCandidates, the same fitter as used in standard reconstruction 
00520   std::string Fitter = pSet_.getParameter<std::string>("Fitter");
00521   ESHandle<TrajectoryFitter> TF;
00522   iSetup.get<TrajectoryFitter::Record>().get(Fitter, TF);
00523   const TrajectoryFitter* theFitter = TF.product();
00524 
00525   // get TrackCandidateCollection in accordance with the fitter, i.e. rs-RS, ckf-KF... 
00526   std::string TrackCandidateLabel = pSet_.getParameter<std::string>("TrackCandidateLabel");
00527   std::string TrackCandidateProducer = pSet_.getParameter<std::string>("TrackCandidateProducer");  
00528   Handle<TrackCandidateCollection> trackCandidateCollection;
00529   iEvent.getByLabel(TrackCandidateProducer, TrackCandidateLabel, trackCandidateCollection);
00530 
00531   for (TrackCandidateCollection::const_iterator tc = trackCandidateCollection->begin(); 
00532        tc!=trackCandidateCollection->end(); ++tc) {
00533     PTrajectoryStateOnDet tcPTSoD = tc->trajectoryStateOnDet();
00534     TrajectoryStateOnSurface tcTSoS = trajectoryStateTransform::transientState(tcPTSoD, &(theTrackerGeometry->idToDet(tcPTSoD.detId())->surface()), 
00535                                                                  theMagneticField);
00536     const TrajectorySeed& tcSeed = tc->seed();
00537 
00538     const TrackCandidate::range& tcRecHits = tc->recHits();    
00539     if (debug_) cout << "track candidate has "<< int(tcRecHits.second - tcRecHits.first) <<" hits with ID "; 
00540     
00541     Trajectory::RecHitContainer tcTTRHs;
00542     for (TrackingRecHitCollection::const_iterator tcRecHit = tcRecHits.first; 
00543          tcRecHit!=tcRecHits.second; ++tcRecHit) { 
00544       if (debug_) cout << tcRecHit->geographicalId().rawId() <<" "; 
00545       
00546       tcTTRHs.push_back(theTTRHBuilder->build(&(*tcRecHit)));
00547     } 
00548     // note a TrackCandidate keeps only the PTSoD of the first hit as well as the seed and all the hits; 
00549     // to 99.9%-recover all the hit's TSoS's, refit with the seed, the hits and an initial TSoS from the PTSoD 
00550     // to get a Trajectory of all the hit's TrajectoryMeasurements (TMs) 
00551     std::vector<Trajectory> refitTrajectoryCollection = theFitter->fit(tcSeed, tcTTRHs, tcTSoS);            
00552     if (debug_) cout << "refitTrajectoryCollection size is "<< refitTrajectoryCollection.size() << endl;
00553 
00554     if (refitTrajectoryCollection.size()>0) { // should be either 0 or 1 
00555       const Trajectory& refitTrajectory = refitTrajectoryCollection.front();
00556 
00557       // retrieve and loop over all the TMs 
00558       Trajectory::DataContainer refitTMs = refitTrajectory.measurements();                                                              
00559       if (debug_) cout << "refitTrajectory has "<< refitTMs.size() <<" hits with ID "; 
00560 
00561       for (Trajectory::DataContainer::iterator refitTM = refitTMs.begin(); 
00562            refitTM!=refitTMs.end(); refitTM++) {                                        
00563         TransientTrackingRecHit::ConstRecHitPointer refitTTRH = refitTM->recHit();
00564         if (debug_) cout << refitTTRH->geographicalId().rawId() <<" "; 
00565         
00566         // only analyze the most elemental pixel hit's TMs to calculate residuals 
00567         const GeomDet* ttrhDet = refitTTRH->det(); 
00568         if (ttrhDet->components().empty() && (ttrhDet->subDetector()==GeomDetEnumerators::PixelBarrel ||                                
00569                                               ttrhDet->subDetector()==GeomDetEnumerators::PixelEndcap)) {                               
00570 
00571           // combine the forward and backward states without using the hit's information (hence unbiased by the hit); 
00572           // the TM's updated state keeps the state combined and updated with the hit's info but we don't use the updated state at all 
00573           TrajectoryStateOnSurface combinedTSoS = TrajectoryStateCombiner().combine(refitTM->forwardPredictedState(),        
00574                                                                                     refitTM->backwardPredictedState());      
00575           if (refitTTRH->isValid() && combinedTSoS.isValid()) { 
00576             // calculate the distance between the hit location and the track-crossing point predicted by the combined state 
00577             const GeomDetUnit* GDU = static_cast<const GeomDetUnit*>(ttrhDet);
00578             const Topology* theTopology = &(GDU->topology());                                                                   
00579             
00580             MeasurementPoint hitPosition = theTopology->measurementPosition(refitTTRH->localPosition());                                
00581             MeasurementPoint combinedTSoSPosition = theTopology->measurementPosition(combinedTSoS.localPosition());     
00582             
00583             Measurement2DVector residual = hitPosition - combinedTSoSPosition;                          
00584             if(debug_) std::cout << "fill residual " << residual.x() << " " << residual.y() << " \n";
00585                                                                                                                                 
00586             // fill the residual histograms 
00587             std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find(refitTTRH->geographicalId().rawId());      
00588             if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill(residual, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);                 
00589                                                                                                                                 
00590             if (debug_) {
00591               if (ttrhDet->subDetector()==GeomDetEnumerators::PixelBarrel) {                                                   
00592                 meSubdetResidualX[0]->Fill(residual.x());                                                                  
00593                 meSubdetResidualY[0]->Fill(residual.y());                                                                  
00594               }                                                                                                                
00595               else {                                                                              
00596                 meSubdetResidualX[PXFDetId(refitTTRH->geographicalId()).side()]->Fill(residual.x());                                                
00597                 meSubdetResidualY[PXFDetId(refitTTRH->geographicalId()).side()]->Fill(residual.y());                                                
00598               } 
00599             }                                                                                                                   
00600           }
00601         }                                                                                       
00602       } 
00603       if (debug_) cout << endl;                                                                                                                         
00604     }                                                                                                                           
00605   } 
00606 
00607 
00608   //get trajectories
00609   edm::Handle<std::vector<Trajectory> > trajCollectionHandle;
00610   iEvent.getByLabel(tracksrc_,trajCollectionHandle);
00611   const std::vector<Trajectory> trajColl = *(trajCollectionHandle.product());
00612    
00613   //get tracks
00614   edm::Handle<std::vector<reco::Track> > trackCollectionHandle;
00615   iEvent.getByLabel(tracksrc_,trackCollectionHandle);
00616   const std::vector<reco::Track> trackColl = *(trackCollectionHandle.product());
00617 
00618   //get the map
00619   edm::Handle<TrajTrackAssociationCollection> match;
00620   iEvent.getByLabel(tracksrc_,match);
00621   const TrajTrackAssociationCollection ttac = *(match.product());
00622 
00623   // get clusters
00624   edm::Handle< edmNew::DetSetVector<SiPixelCluster> >  clusterColl;
00625   iEvent.getByLabel( clustersrc_, clusterColl );
00626   const edmNew::DetSetVector<SiPixelCluster> clustColl = *(clusterColl.product());
00627 
00628   if(debug_){
00629     std::cout << "Trajectories\t : " << trajColl.size() << std::endl;
00630     std::cout << "recoTracks  \t : " << trackColl.size() << std::endl;
00631     std::cout << "Map entries \t : " << ttac.size() << std::endl;
00632   }
00633 
00634   std::set<SiPixelCluster> clusterSet;
00635   TrajectoryStateCombiner tsoscomb;
00636   int tracks=0, pixeltracks=0, bpixtracks=0, fpixtracks=0; 
00637   int trackclusters=0, barreltrackclusters=0, endcaptrackclusters=0;
00638   int otherclusters=0, barrelotherclusters=0, endcapotherclusters=0;
00639 
00640   //Loop over map entries
00641   for(TrajTrackAssociationCollection::const_iterator it =  ttac.begin();it !=  ttac.end(); ++it){
00642     const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;  
00643     // Trajectory Map, extract Trajectory for this track
00644     reco::TrackRef trackref = it->val;
00645     tracks++;
00646 
00647     bool isBpixtrack = false, isFpixtrack = false, crossesPixVol=false;
00648     
00649     //find out whether track crosses pixel fiducial volume (for cosmic tracks)
00650     
00651     double d0 = (*trackref).d0(), dz = (*trackref).dz(); 
00652     
00653     if(abs(d0)<15 && abs(dz)<50) crossesPixVol = true;
00654 
00655     std::vector<TrajectoryMeasurement> tmeasColl =traj_iterator->measurements();
00656     std::vector<TrajectoryMeasurement>::const_iterator tmeasIt;
00657     //loop on measurements to find out whether there are bpix and/or fpix hits
00658     for(tmeasIt = tmeasColl.begin();tmeasIt!=tmeasColl.end();tmeasIt++){
00659       if(! tmeasIt->updatedState().isValid()) continue; 
00660       TransientTrackingRecHit::ConstRecHitPointer testhit = tmeasIt->recHit();
00661       if(! testhit->isValid() || testhit->geographicalId().det() != DetId::Tracker) continue; 
00662       uint testSubDetID = (testhit->geographicalId().subdetId()); 
00663       if(testSubDetID==PixelSubdetector::PixelBarrel) isBpixtrack = true;
00664       if(testSubDetID==PixelSubdetector::PixelEndcap) isFpixtrack = true;
00665     }//end loop on measurements
00666     if(isBpixtrack) {
00667       bpixtracks++; 
00668       if(debug_) std::cout << "bpixtrack\n";
00669     }
00670     if(isFpixtrack) {
00671       fpixtracks++; 
00672       if(debug_) std::cout << "fpixtrack\n";
00673     }
00674     if(isBpixtrack || isFpixtrack){
00675       pixeltracks++;
00676       
00677       if(crossesPixVol) meNofTracksInPixVol_->Fill(0,1);
00678 
00679       std::vector<TrajectoryMeasurement> tmeasColl = traj_iterator->measurements();
00680       for(std::vector<TrajectoryMeasurement>::const_iterator tmeasIt = tmeasColl.begin(); tmeasIt!=tmeasColl.end(); tmeasIt++){   
00681         if(! tmeasIt->updatedState().isValid()) continue; 
00682         
00683         TrajectoryStateOnSurface tsos = tsoscomb( tmeasIt->forwardPredictedState(), tmeasIt->backwardPredictedState() );
00684         TransientTrackingRecHit::ConstRecHitPointer hit = tmeasIt->recHit();
00685         if(! hit->isValid() || hit->geographicalId().det() != DetId::Tracker ) {
00686           continue; 
00687         } else {
00688           
00689 //        //residual
00690           const DetId & hit_detId = hit->geographicalId();
00691           //uint IntRawDetID = (hit_detId.rawId());
00692           uint IntSubDetID = (hit_detId.subdetId());
00693           
00694           if(IntSubDetID == 0 ) continue; // don't look at SiStrip hits!            
00695 
00696           // get the enclosed persistent hit
00697           const TrackingRecHit *persistentHit = hit->hit();
00698           // check if it's not null, and if it's a valid pixel hit
00699           if ((persistentHit != 0) && (typeid(*persistentHit) == typeid(SiPixelRecHit))) {
00700             // tell the C++ compiler that the hit is a pixel hit
00701             const SiPixelRecHit* pixhit = static_cast<const SiPixelRecHit*>( hit->hit() );
00702             //Hit probability:
00703             float hit_prob = -1.;
00704             if(pixhit->hasFilledProb()){
00705               hit_prob = pixhit->clusterProbability(0);
00706               //std::cout<<"HITPROB= "<<hit_prob<<std::endl;
00707               if(hit_prob<pow(10.,-15.)) NLowProb++;
00708               NTotal++;
00709               if(NTotal>0) meHitProbability->Fill(float(NLowProb/NTotal));
00710             }
00711             
00712             // get the edm::Ref to the cluster
00713             edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
00714             //  check if the ref is not null
00715             if (clust.isNonnull()) {
00716 
00717               //define tracker and pixel geometry and topology
00718               const TrackerGeometry& theTracker(*theTrackerGeometry);
00719               const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(hit_detId) );
00720               //test if PixelGeomDetUnit exists
00721               if(theGeomDet == 0) {
00722                 if(debug_) std::cout << "NO THEGEOMDET\n";
00723                 continue;
00724               }
00725 
00726               const PixelTopology * topol = &(theGeomDet->specificTopology());
00727               //fill histograms for clusters on tracks
00728               //correct SiPixelTrackResidualModule
00729               std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*hit).geographicalId().rawId());
00730 
00731               //CHARGE CORRECTION (for track impact angle)
00732               // calculate alpha and beta from cluster position
00733               LocalTrajectoryParameters ltp = tsos.localParameters();
00734               LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
00735               
00736               float clust_alpha = atan2(localDir.z(), localDir.x());
00737               float clust_beta = atan2(localDir.z(), localDir.y());
00738               double corrCharge = clust->charge() * sqrt( 1.0 / ( 1.0/pow( tan(clust_alpha), 2 ) + 
00739                                                                   1.0/pow( tan(clust_beta ), 2 ) + 
00740                                                                   1.0 )
00741                                                           )/1000.;
00742 
00743               if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*clust), true, corrCharge, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);     
00744 
00745 
00746               trackclusters++;
00747               //CORR CHARGE
00748               meClChargeOnTrack_all->Fill(corrCharge);
00749               meClSizeOnTrack_all->Fill((*clust).size());
00750               meClSizeXOnTrack_all->Fill((*clust).sizeX());
00751               meClSizeYOnTrack_all->Fill((*clust).sizeY());
00752               clusterSet.insert(*clust);
00753 
00754               //find cluster global position (rphi, z)
00755               // get cluster center of gravity (of charge)
00756               float xcenter = clust->x();
00757               float ycenter = clust->y();
00758               // get the cluster position in local coordinates (cm) 
00759               LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
00760               // get the cluster position in global coordinates (cm)
00761               GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
00762 
00763               //find location of hit (barrel or endcap, same for cluster)
00764               bool barrel = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
00765               bool endcap = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
00766               if(barrel) {
00767                 barreltrackclusters++;
00768                 //CORR CHARGE
00769                 meClChargeOnTrack_bpix->Fill(corrCharge);
00770                 meClSizeOnTrack_bpix->Fill((*clust).size());
00771                 meClSizeXOnTrack_bpix->Fill((*clust).sizeX());
00772                 meClSizeYOnTrack_bpix->Fill((*clust).sizeY());
00773                 uint32_t DBlayer = PixelBarrelName(DetId((*hit).geographicalId())).layerName();
00774                 float phi = clustgp.phi(); 
00775                 float z = clustgp.z();
00776                 switch(DBlayer){
00777                 case 1: {
00778                   meClPosLayer1OnTrack->Fill(z,phi); 
00779                   meClChargeOnTrack_layer1->Fill(corrCharge);
00780                   meClSizeOnTrack_layer1->Fill((*clust).size());
00781                   meClSizeXOnTrack_layer1->Fill((*clust).sizeX());
00782                   meClSizeYOnTrack_layer1->Fill((*clust).sizeY());
00783                   break;
00784                 }
00785                 case 2: {
00786                   meClPosLayer2OnTrack->Fill(z,phi); 
00787                   meClChargeOnTrack_layer2->Fill(corrCharge);
00788                   meClSizeOnTrack_layer2->Fill((*clust).size());
00789                   meClSizeXOnTrack_layer2->Fill((*clust).sizeX());
00790                   meClSizeYOnTrack_layer2->Fill((*clust).sizeY());
00791                   break;
00792                 }
00793                 case 3: {
00794                   meClPosLayer3OnTrack->Fill(z,phi); 
00795                   meClChargeOnTrack_layer3->Fill(corrCharge);
00796                   meClSizeOnTrack_layer3->Fill((*clust).size());
00797                   meClSizeXOnTrack_layer3->Fill((*clust).sizeX());
00798                   meClSizeYOnTrack_layer3->Fill((*clust).sizeY());
00799                   break;
00800                 }
00801                 
00802                 }
00803                 
00804               }
00805               if(endcap) {
00806                 endcaptrackclusters++;
00807                 //CORR CHARGE
00808                 meClChargeOnTrack_fpix->Fill(corrCharge);
00809                 meClSizeOnTrack_fpix->Fill((*clust).size());
00810                 meClSizeXOnTrack_fpix->Fill((*clust).sizeX());
00811                 meClSizeYOnTrack_fpix->Fill((*clust).sizeY());
00812                 uint32_t DBdisk = PixelEndcapName(DetId((*hit).geographicalId())).diskName();
00813                 float x = clustgp.x(); 
00814                 float y = clustgp.y(); 
00815                 float z = clustgp.z();
00816                 if(z>0){
00817                   if(DBdisk==1) {
00818                     meClPosDisk1pzOnTrack->Fill(x,y);
00819                     meClChargeOnTrack_diskp1->Fill(corrCharge);
00820                     meClSizeOnTrack_diskp1->Fill((*clust).size());
00821                     meClSizeXOnTrack_diskp1->Fill((*clust).sizeX());
00822                     meClSizeYOnTrack_diskp1->Fill((*clust).sizeY());
00823                   }
00824                   if(DBdisk==2) {
00825                     meClPosDisk2pzOnTrack->Fill(x,y); 
00826                     meClChargeOnTrack_diskp2->Fill(corrCharge);
00827                     meClSizeOnTrack_diskp2->Fill((*clust).size());
00828                     meClSizeXOnTrack_diskp2->Fill((*clust).sizeX());
00829                     meClSizeYOnTrack_diskp2->Fill((*clust).sizeY());
00830                   }
00831                 }
00832                 else{
00833                   if(DBdisk==1) {
00834                     meClPosDisk1mzOnTrack->Fill(x,y);
00835                     meClChargeOnTrack_diskm1->Fill(corrCharge);
00836                     meClSizeOnTrack_diskm1->Fill((*clust).size());
00837                     meClSizeXOnTrack_diskm1->Fill((*clust).sizeX());
00838                     meClSizeYOnTrack_diskm1->Fill((*clust).sizeY());
00839                   }
00840                   if(DBdisk==2) {
00841                     meClPosDisk2mzOnTrack->Fill(x,y); 
00842                     meClChargeOnTrack_diskm2->Fill(corrCharge);
00843                     meClSizeOnTrack_diskm2->Fill((*clust).size());
00844                     meClSizeXOnTrack_diskm2->Fill((*clust).sizeX());
00845                     meClSizeYOnTrack_diskm2->Fill((*clust).sizeY());
00846                   }
00847                 } 
00848               }
00849               
00850             }//end if (cluster exists)
00851 
00852           }//end if (persistent hit exists and is pixel hit)
00853           
00854         }//end of else 
00855         
00856         
00857       }//end for (all traj measurements of pixeltrack)
00858     }//end if (is pixeltrack)
00859     else {
00860       if(debug_) std::cout << "no pixeltrack:\n";
00861       if(crossesPixVol) meNofTracksInPixVol_->Fill(1,1);
00862     }
00863     
00864   }//end loop on map entries
00865 
00866   //find clusters that are NOT on track
00867   //edmNew::DetSet<SiPixelCluster>::const_iterator  di;
00868   if(debug_) std::cout << "clusters not on track: (size " << clustColl.size() << ") ";
00869 
00870   for(TrackerGeometry::DetContainer::const_iterator it = TG->dets().begin(); it != TG->dets().end(); it++){
00871     //if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
00872     DetId detId = (*it)->geographicalId();
00873     if(detId>=302055684 && detId<=352477708){ // make sure it's a Pixel module WITHOUT using dynamic_cast!  
00874       int nofclOnTrack = 0, nofclOffTrack=0; 
00875       uint32_t DBlayer=10, DBdisk=10; 
00876       float z=0.; 
00877       //set layer/disk
00878       if(DetId(detId).subdetId() == 1) { // Barrel module
00879         DBlayer = PixelBarrelName(DetId(detId)).layerName();
00880       }
00881       if(DetId(detId).subdetId() == 2){ // Endcap module
00882         DBdisk = PixelEndcapName(DetId(detId )).diskName();
00883       }
00884       edmNew::DetSetVector<SiPixelCluster>::const_iterator isearch = clustColl.find(detId);
00885       if( isearch != clustColl.end() ) {  // Not an empty iterator
00886         edmNew::DetSet<SiPixelCluster>::const_iterator  di;
00887         for(di=isearch->begin(); di!=isearch->end(); di++){
00888           unsigned int temp = clusterSet.size();
00889           clusterSet.insert(*di);
00890           //check if cluster is off track
00891           if(clusterSet.size()>temp) {
00892             otherclusters++;
00893             nofclOffTrack++; 
00894             //fill histograms for clusters off tracks
00895             //correct SiPixelTrackResidualModule
00896             std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
00897 
00898             if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*di), false, -1., reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn); 
00899             
00900 
00901 
00902             meClSizeNotOnTrack_all->Fill((*di).size());
00903             meClSizeXNotOnTrack_all->Fill((*di).sizeX());
00904             meClSizeYNotOnTrack_all->Fill((*di).sizeY());
00905             meClChargeNotOnTrack_all->Fill((*di).charge()/1000);
00906 
00908             //find cluster global position (rphi, z) get cluster
00909             //define tracker and pixel geometry and topology
00910             const TrackerGeometry& theTracker(*theTrackerGeometry);
00911             const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
00912             //test if PixelGeomDetUnit exists
00913             if(theGeomDet == 0) {
00914               if(debug_) std::cout << "NO THEGEOMDET\n";
00915               continue;
00916             }
00917             const PixelTopology * topol = &(theGeomDet->specificTopology());
00918            
00919             //center of gravity (of charge)
00920             float xcenter = di->x();
00921             float ycenter = di->y();
00922             // get the cluster position in local coordinates (cm) 
00923             LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
00924             // get the cluster position in global coordinates (cm)
00925             GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
00926 
00928 
00929             //barrel
00930             if(DetId(detId).subdetId() == 1) {
00931               meClSizeNotOnTrack_bpix->Fill((*di).size());
00932               meClSizeXNotOnTrack_bpix->Fill((*di).sizeX());
00933               meClSizeYNotOnTrack_bpix->Fill((*di).sizeY());
00934               meClChargeNotOnTrack_bpix->Fill((*di).charge()/1000);
00935               barrelotherclusters++;
00936               //DBlayer = PixelBarrelName(DetId(detId)).layerName();
00937               float phi = clustgp.phi(); 
00938               //float r = clustgp.perp();
00939               z = clustgp.z();
00940               switch(DBlayer){
00941               case 1: {
00942                 meClPosLayer1NotOnTrack->Fill(z,phi); 
00943                 meClSizeNotOnTrack_layer1->Fill((*di).size());
00944                 meClSizeXNotOnTrack_layer1->Fill((*di).sizeX());
00945                 meClSizeYNotOnTrack_layer1->Fill((*di).sizeY());
00946                 meClChargeNotOnTrack_layer1->Fill((*di).charge()/1000);
00947                 break;
00948               }
00949               case 2: {
00950                 meClPosLayer2NotOnTrack->Fill(z,phi);
00951                 meClSizeNotOnTrack_layer2->Fill((*di).size());
00952                 meClSizeXNotOnTrack_layer2->Fill((*di).sizeX());
00953                 meClSizeYNotOnTrack_layer2->Fill((*di).sizeY());
00954                 meClChargeNotOnTrack_layer2->Fill((*di).charge()/1000);
00955                 break;
00956               }
00957               case 3: {
00958                 meClPosLayer3NotOnTrack->Fill(z,phi); 
00959                 meClSizeNotOnTrack_layer3->Fill((*di).size());
00960                 meClSizeXNotOnTrack_layer3->Fill((*di).sizeX());
00961                 meClSizeYNotOnTrack_layer3->Fill((*di).sizeY());
00962                 meClChargeNotOnTrack_layer3->Fill((*di).charge()/1000);
00963                 break;
00964               }
00965                 
00966               }
00967             }
00968             //endcap
00969             if(DetId(detId).subdetId() == 2) {
00970               meClSizeNotOnTrack_fpix->Fill((*di).size());
00971               meClSizeXNotOnTrack_fpix->Fill((*di).sizeX());
00972               meClSizeYNotOnTrack_fpix->Fill((*di).sizeY());
00973               meClChargeNotOnTrack_fpix->Fill((*di).charge()/1000);
00974               endcapotherclusters++;
00975               //DBdisk = PixelEndcapName(DetId(detId )).diskName();
00976               float x = clustgp.x(); 
00977               float y = clustgp.y(); 
00978               z = clustgp.z();
00979               if(z>0){
00980                 if(DBdisk==1) {
00981                   meClPosDisk1pzNotOnTrack->Fill(x,y);
00982                   meClSizeNotOnTrack_diskp1->Fill((*di).size());
00983                   meClSizeXNotOnTrack_diskp1->Fill((*di).sizeX());
00984                   meClSizeYNotOnTrack_diskp1->Fill((*di).sizeY());
00985                   meClChargeNotOnTrack_diskp1->Fill((*di).charge()/1000);
00986                 }
00987                 if(DBdisk==2) {
00988                   meClPosDisk2pzNotOnTrack->Fill(x,y); 
00989                   meClSizeNotOnTrack_diskp2->Fill((*di).size());
00990                   meClSizeXNotOnTrack_diskp2->Fill((*di).sizeX());
00991                   meClSizeYNotOnTrack_diskp2->Fill((*di).sizeY());
00992                   meClChargeNotOnTrack_diskp2->Fill((*di).charge()/1000);
00993                 }
00994               }
00995               else{
00996                 if(DBdisk==1) {
00997                   meClPosDisk1mzNotOnTrack->Fill(x,y);
00998                   meClSizeNotOnTrack_diskm1->Fill((*di).size());
00999                   meClSizeXNotOnTrack_diskm1->Fill((*di).sizeX());
01000                   meClSizeYNotOnTrack_diskm1->Fill((*di).sizeY());
01001                   meClChargeNotOnTrack_diskm1->Fill((*di).charge()/1000);
01002                 }
01003                 if(DBdisk==2) {
01004                   meClPosDisk2mzNotOnTrack->Fill(x,y); 
01005                   meClSizeNotOnTrack_diskm2->Fill((*di).size());
01006                   meClSizeXNotOnTrack_diskm2->Fill((*di).sizeX());
01007                   meClSizeYNotOnTrack_diskm2->Fill((*di).sizeY());
01008                   meClChargeNotOnTrack_diskm2->Fill((*di).charge()/1000);
01009                 }
01010               } 
01011 
01012             }
01013           }// end "if cluster off track"
01014           else {
01015             nofclOnTrack++; 
01016             if(z == 0 && DBdisk != 10){
01017               //find cluster global position (rphi, z) get cluster
01018               //define tracker and pixel geometry and topology
01019               const TrackerGeometry& theTracker(*theTrackerGeometry);
01020               const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
01021               //test if PixelGeomDetUnit exists
01022               if(theGeomDet == 0) {
01023                 if(debug_) std::cout << "NO THEGEOMDET\n";
01024                 continue;
01025               }
01026               const PixelTopology * topol = &(theGeomDet->specificTopology());
01027               //center of gravity (of charge)
01028               float xcenter = di->x();
01029               float ycenter = di->y();
01030               // get the cluster position in local coordinates (cm) 
01031               LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
01032               // get the cluster position in global coordinates (cm)
01033               GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );  
01034               z = clustgp.z();
01035             }
01036           }
01037         }
01038       }
01039       //++ fill the number of clusters on a module
01040       std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
01041       if (pxd!=theSiPixelStructure.end()) (*pxd).second->nfill(nofclOnTrack, nofclOffTrack, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn); 
01042       if(nofclOnTrack!=0) meNClustersOnTrack_all->Fill(nofclOnTrack); 
01043       if(nofclOffTrack!=0) meNClustersNotOnTrack_all->Fill(nofclOffTrack); 
01044       //barrel
01045       if(DetId(detId).subdetId() == 1){
01046         if(nofclOnTrack!=0) meNClustersOnTrack_bpix->Fill(nofclOnTrack); 
01047         if(nofclOffTrack!=0) meNClustersNotOnTrack_bpix->Fill(nofclOffTrack); 
01048         //DBlayer = PixelBarrelName(DetId(detId)).layerName();
01049         switch(DBlayer){
01050         case 1: { 
01051           if(nofclOnTrack!=0) meNClustersOnTrack_layer1->Fill(nofclOnTrack);
01052           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer1->Fill(nofclOffTrack); break;
01053         }
01054         case 2: {
01055           if(nofclOnTrack!=0) meNClustersOnTrack_layer2->Fill(nofclOnTrack);
01056           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer2->Fill(nofclOffTrack); break; 
01057         }
01058         case 3: {
01059           if(nofclOnTrack!=0) meNClustersOnTrack_layer3->Fill(nofclOnTrack); 
01060           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer3->Fill(nofclOffTrack); break; 
01061         }
01062         }
01063       }//end barrel
01064       //endcap
01065       if(DetId(detId).subdetId() == 2) {
01066         //DBdisk = PixelEndcapName(DetId(detId )).diskName();
01067         //z = clustgp.z();
01068         if(nofclOnTrack!=0) meNClustersOnTrack_fpix->Fill(nofclOnTrack); 
01069         if(nofclOffTrack!=0) meNClustersNotOnTrack_fpix->Fill(nofclOffTrack);
01070         if(z>0){
01071           if(DBdisk==1) {
01072             if(nofclOnTrack!=0) meNClustersOnTrack_diskp1->Fill(nofclOnTrack); 
01073             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp1->Fill(nofclOffTrack);
01074           }
01075           if(DBdisk==2) {
01076             if(nofclOnTrack!=0) meNClustersOnTrack_diskp2->Fill(nofclOnTrack); 
01077             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp2->Fill(nofclOffTrack);
01078           }
01079         }
01080         if(z<0){
01081           if(DBdisk==1) {
01082             if(nofclOnTrack!=0) meNClustersOnTrack_diskm1->Fill(nofclOnTrack); 
01083             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm1->Fill(nofclOffTrack);
01084           }
01085           if(DBdisk==2) {
01086             if(nofclOnTrack!=0) meNClustersOnTrack_diskm2->Fill(nofclOnTrack); 
01087             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm2->Fill(nofclOffTrack);
01088           }
01089         }
01090       }
01091 
01092     }//end if it's a Pixel module
01093   }//end for loop over tracker detector geometry modules
01094 
01095 
01096   if(trackclusters>0) (meNofClustersOnTrack_)->Fill(0,trackclusters);
01097   if(barreltrackclusters>0)(meNofClustersOnTrack_)->Fill(1,barreltrackclusters);
01098   if(endcaptrackclusters>0)(meNofClustersOnTrack_)->Fill(2,endcaptrackclusters);
01099   if(otherclusters>0)(meNofClustersNotOnTrack_)->Fill(0,otherclusters);
01100   if(barrelotherclusters>0)(meNofClustersNotOnTrack_)->Fill(1,barrelotherclusters);
01101   if(endcapotherclusters>0)(meNofClustersNotOnTrack_)->Fill(2,endcapotherclusters);
01102   if(tracks>0)(meNofTracks_)->Fill(0,tracks);
01103   if(pixeltracks>0)(meNofTracks_)->Fill(1,pixeltracks);
01104   if(bpixtracks>0)(meNofTracks_)->Fill(2,bpixtracks);
01105   if(fpixtracks>0)(meNofTracks_)->Fill(3,fpixtracks);
01106 }
01107 
01108 
01109 DEFINE_FWK_MODULE(SiPixelTrackResidualSource); // define this as a plug-in