CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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.20 2011/01/10 00:26:34 dlange 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     TrajectoryStateTransform transformer; 
00534     PTrajectoryStateOnDet tcPTSoD = tc->trajectoryStateOnDet();
00535     TrajectoryStateOnSurface tcTSoS = transformer.transientState(tcPTSoD, &(theTrackerGeometry->idToDet(tcPTSoD.detId())->surface()), 
00536                                                                  theMagneticField);
00537     const TrajectorySeed& tcSeed = tc->seed();
00538 
00539     const TrackCandidate::range& tcRecHits = tc->recHits();    
00540     if (debug_) cout << "track candidate has "<< int(tcRecHits.second - tcRecHits.first) <<" hits with ID "; 
00541     
00542     Trajectory::RecHitContainer tcTTRHs;
00543     for (TrackingRecHitCollection::const_iterator tcRecHit = tcRecHits.first; 
00544          tcRecHit!=tcRecHits.second; ++tcRecHit) { 
00545       if (debug_) cout << tcRecHit->geographicalId().rawId() <<" "; 
00546       
00547       tcTTRHs.push_back(theTTRHBuilder->build(&(*tcRecHit)));
00548     } 
00549     // note a TrackCandidate keeps only the PTSoD of the first hit as well as the seed and all the hits; 
00550     // to 99.9%-recover all the hit's TSoS's, refit with the seed, the hits and an initial TSoS from the PTSoD 
00551     // to get a Trajectory of all the hit's TrajectoryMeasurements (TMs) 
00552     std::vector<Trajectory> refitTrajectoryCollection = theFitter->fit(tcSeed, tcTTRHs, tcTSoS);            
00553     if (debug_) cout << "refitTrajectoryCollection size is "<< refitTrajectoryCollection.size() << endl;
00554 
00555     if (refitTrajectoryCollection.size()>0) { // should be either 0 or 1 
00556       const Trajectory& refitTrajectory = refitTrajectoryCollection.front();
00557 
00558       // retrieve and loop over all the TMs 
00559       Trajectory::DataContainer refitTMs = refitTrajectory.measurements();                                                              
00560       if (debug_) cout << "refitTrajectory has "<< refitTMs.size() <<" hits with ID "; 
00561 
00562       for (Trajectory::DataContainer::iterator refitTM = refitTMs.begin(); 
00563            refitTM!=refitTMs.end(); refitTM++) {                                        
00564         TransientTrackingRecHit::ConstRecHitPointer refitTTRH = refitTM->recHit();
00565         if (debug_) cout << refitTTRH->geographicalId().rawId() <<" "; 
00566         
00567         // only analyze the most elemental pixel hit's TMs to calculate residuals 
00568         const GeomDet* ttrhDet = refitTTRH->det(); 
00569         if (ttrhDet->components().empty() && (ttrhDet->subDetector()==GeomDetEnumerators::PixelBarrel ||                                
00570                                               ttrhDet->subDetector()==GeomDetEnumerators::PixelEndcap)) {                               
00571 
00572           // combine the forward and backward states without using the hit's information (hence unbiased by the hit); 
00573           // 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 
00574           TrajectoryStateOnSurface combinedTSoS = TrajectoryStateCombiner().combine(refitTM->forwardPredictedState(),        
00575                                                                                     refitTM->backwardPredictedState());      
00576           if (refitTTRH->isValid() && combinedTSoS.isValid()) { 
00577             // calculate the distance between the hit location and the track-crossing point predicted by the combined state 
00578             const GeomDetUnit* GDU = static_cast<const GeomDetUnit*>(ttrhDet);
00579             const Topology* theTopology = &(GDU->topology());                                                                   
00580             
00581             MeasurementPoint hitPosition = theTopology->measurementPosition(refitTTRH->localPosition());                                
00582             MeasurementPoint combinedTSoSPosition = theTopology->measurementPosition(combinedTSoS.localPosition());     
00583             
00584             Measurement2DVector residual = hitPosition - combinedTSoSPosition;                          
00585             if(debug_) std::cout << "fill residual " << residual.x() << " " << residual.y() << " \n";
00586                                                                                                                                 
00587             // fill the residual histograms 
00588             std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find(refitTTRH->geographicalId().rawId());      
00589             if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill(residual, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);                 
00590                                                                                                                                 
00591             if (debug_) {
00592               if (ttrhDet->subDetector()==GeomDetEnumerators::PixelBarrel) {                                                   
00593                 meSubdetResidualX[0]->Fill(residual.x());                                                                  
00594                 meSubdetResidualY[0]->Fill(residual.y());                                                                  
00595               }                                                                                                                
00596               else {                                                                              
00597                 meSubdetResidualX[PXFDetId(refitTTRH->geographicalId()).side()]->Fill(residual.x());                                                
00598                 meSubdetResidualY[PXFDetId(refitTTRH->geographicalId()).side()]->Fill(residual.y());                                                
00599               } 
00600             }                                                                                                                   
00601           }
00602         }                                                                                       
00603       } 
00604       if (debug_) cout << endl;                                                                                                                         
00605     }                                                                                                                           
00606   } 
00607 
00608 
00609   //get trajectories
00610   edm::Handle<std::vector<Trajectory> > trajCollectionHandle;
00611   iEvent.getByLabel(tracksrc_,trajCollectionHandle);
00612   const std::vector<Trajectory> trajColl = *(trajCollectionHandle.product());
00613    
00614   //get tracks
00615   edm::Handle<std::vector<reco::Track> > trackCollectionHandle;
00616   iEvent.getByLabel(tracksrc_,trackCollectionHandle);
00617   const std::vector<reco::Track> trackColl = *(trackCollectionHandle.product());
00618 
00619   //get the map
00620   edm::Handle<TrajTrackAssociationCollection> match;
00621   iEvent.getByLabel(tracksrc_,match);
00622   const TrajTrackAssociationCollection ttac = *(match.product());
00623 
00624   // get clusters
00625   edm::Handle< edmNew::DetSetVector<SiPixelCluster> >  clusterColl;
00626   iEvent.getByLabel( clustersrc_, clusterColl );
00627   const edmNew::DetSetVector<SiPixelCluster> clustColl = *(clusterColl.product());
00628 
00629   if(debug_){
00630     std::cout << "Trajectories\t : " << trajColl.size() << std::endl;
00631     std::cout << "recoTracks  \t : " << trackColl.size() << std::endl;
00632     std::cout << "Map entries \t : " << ttac.size() << std::endl;
00633   }
00634 
00635   std::set<SiPixelCluster> clusterSet;
00636   TrajectoryStateCombiner tsoscomb;
00637   int tracks=0, pixeltracks=0, bpixtracks=0, fpixtracks=0; 
00638   int trackclusters=0, barreltrackclusters=0, endcaptrackclusters=0;
00639   int otherclusters=0, barrelotherclusters=0, endcapotherclusters=0;
00640 
00641   //Loop over map entries
00642   for(TrajTrackAssociationCollection::const_iterator it =  ttac.begin();it !=  ttac.end(); ++it){
00643     const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;  
00644     // Trajectory Map, extract Trajectory for this track
00645     reco::TrackRef trackref = it->val;
00646     tracks++;
00647 
00648     bool isBpixtrack = false, isFpixtrack = false, crossesPixVol=false;
00649     
00650     //find out whether track crosses pixel fiducial volume (for cosmic tracks)
00651     
00652     double d0 = (*trackref).d0(), dz = (*trackref).dz(); 
00653     
00654     if(abs(d0)<15 && abs(dz)<50) crossesPixVol = true;
00655 
00656     std::vector<TrajectoryMeasurement> tmeasColl =traj_iterator->measurements();
00657     std::vector<TrajectoryMeasurement>::const_iterator tmeasIt;
00658     //loop on measurements to find out whether there are bpix and/or fpix hits
00659     for(tmeasIt = tmeasColl.begin();tmeasIt!=tmeasColl.end();tmeasIt++){
00660       if(! tmeasIt->updatedState().isValid()) continue; 
00661       TransientTrackingRecHit::ConstRecHitPointer testhit = tmeasIt->recHit();
00662       if(! testhit->isValid() || testhit->geographicalId().det() != DetId::Tracker) continue; 
00663       uint testSubDetID = (testhit->geographicalId().subdetId()); 
00664       if(testSubDetID==PixelSubdetector::PixelBarrel) isBpixtrack = true;
00665       if(testSubDetID==PixelSubdetector::PixelEndcap) isFpixtrack = true;
00666     }//end loop on measurements
00667     if(isBpixtrack) {
00668       bpixtracks++; 
00669       if(debug_) std::cout << "bpixtrack\n";
00670     }
00671     if(isFpixtrack) {
00672       fpixtracks++; 
00673       if(debug_) std::cout << "fpixtrack\n";
00674     }
00675     if(isBpixtrack || isFpixtrack){
00676       pixeltracks++;
00677       
00678       if(crossesPixVol) meNofTracksInPixVol_->Fill(0,1);
00679 
00680       std::vector<TrajectoryMeasurement> tmeasColl = traj_iterator->measurements();
00681       for(std::vector<TrajectoryMeasurement>::const_iterator tmeasIt = tmeasColl.begin(); tmeasIt!=tmeasColl.end(); tmeasIt++){   
00682         if(! tmeasIt->updatedState().isValid()) continue; 
00683         
00684         TrajectoryStateOnSurface tsos = tsoscomb( tmeasIt->forwardPredictedState(), tmeasIt->backwardPredictedState() );
00685         TransientTrackingRecHit::ConstRecHitPointer hit = tmeasIt->recHit();
00686         if(! hit->isValid() || hit->geographicalId().det() != DetId::Tracker ) {
00687           continue; 
00688         } else {
00689           
00690 //        //residual
00691           const DetId & hit_detId = hit->geographicalId();
00692           //uint IntRawDetID = (hit_detId.rawId());
00693           uint IntSubDetID = (hit_detId.subdetId());
00694           
00695           if(IntSubDetID == 0 ) continue; // don't look at SiStrip hits!            
00696 
00697           // get the enclosed persistent hit
00698           const TrackingRecHit *persistentHit = hit->hit();
00699           // check if it's not null, and if it's a valid pixel hit
00700           if ((persistentHit != 0) && (typeid(*persistentHit) == typeid(SiPixelRecHit))) {
00701             // tell the C++ compiler that the hit is a pixel hit
00702             const SiPixelRecHit* pixhit = static_cast<const SiPixelRecHit*>( hit->hit() );
00703             //Hit probability:
00704             float hit_prob = -1.;
00705             if(pixhit->hasFilledProb()){
00706               hit_prob = pixhit->clusterProbability(0);
00707               //std::cout<<"HITPROB= "<<hit_prob<<std::endl;
00708               if(hit_prob<pow(10.,-15.)) NLowProb++;
00709               NTotal++;
00710               if(NTotal>0) meHitProbability->Fill(float(NLowProb/NTotal));
00711             }
00712             
00713             // get the edm::Ref to the cluster
00714             edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
00715             //  check if the ref is not null
00716             if (clust.isNonnull()) {
00717 
00718               //define tracker and pixel geometry and topology
00719               const TrackerGeometry& theTracker(*theTrackerGeometry);
00720               const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(hit_detId) );
00721               //test if PixelGeomDetUnit exists
00722               if(theGeomDet == 0) {
00723                 if(debug_) std::cout << "NO THEGEOMDET\n";
00724                 continue;
00725               }
00726 
00727               const PixelTopology * topol = &(theGeomDet->specificTopology());
00728               //fill histograms for clusters on tracks
00729               //correct SiPixelTrackResidualModule
00730               std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*hit).geographicalId().rawId());
00731 
00732               //CHARGE CORRECTION (for track impact angle)
00733               // calculate alpha and beta from cluster position
00734               LocalTrajectoryParameters ltp = tsos.localParameters();
00735               LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
00736               
00737               float clust_alpha = atan2(localDir.z(), localDir.x());
00738               float clust_beta = atan2(localDir.z(), localDir.y());
00739               double corrCharge = clust->charge() * sqrt( 1.0 / ( 1.0/pow( tan(clust_alpha), 2 ) + 
00740                                                                   1.0/pow( tan(clust_beta ), 2 ) + 
00741                                                                   1.0 )
00742                                                           )/1000.;
00743 
00744               if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*clust), true, corrCharge, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);     
00745 
00746 
00747               trackclusters++;
00748               //CORR CHARGE
00749               meClChargeOnTrack_all->Fill(corrCharge);
00750               meClSizeOnTrack_all->Fill((*clust).size());
00751               meClSizeXOnTrack_all->Fill((*clust).sizeX());
00752               meClSizeYOnTrack_all->Fill((*clust).sizeY());
00753               clusterSet.insert(*clust);
00754 
00755               //find cluster global position (rphi, z)
00756               // get cluster center of gravity (of charge)
00757               float xcenter = clust->x();
00758               float ycenter = clust->y();
00759               // get the cluster position in local coordinates (cm) 
00760               LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
00761               // get the cluster position in global coordinates (cm)
00762               GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
00763 
00764               //find location of hit (barrel or endcap, same for cluster)
00765               bool barrel = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
00766               bool endcap = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
00767               if(barrel) {
00768                 barreltrackclusters++;
00769                 //CORR CHARGE
00770                 meClChargeOnTrack_bpix->Fill(corrCharge);
00771                 meClSizeOnTrack_bpix->Fill((*clust).size());
00772                 meClSizeXOnTrack_bpix->Fill((*clust).sizeX());
00773                 meClSizeYOnTrack_bpix->Fill((*clust).sizeY());
00774                 uint32_t DBlayer = PixelBarrelName(DetId((*hit).geographicalId())).layerName();
00775                 float phi = clustgp.phi(); 
00776                 float z = clustgp.z();
00777                 switch(DBlayer){
00778                 case 1: {
00779                   meClPosLayer1OnTrack->Fill(z,phi); 
00780                   meClChargeOnTrack_layer1->Fill(corrCharge);
00781                   meClSizeOnTrack_layer1->Fill((*clust).size());
00782                   meClSizeXOnTrack_layer1->Fill((*clust).sizeX());
00783                   meClSizeYOnTrack_layer1->Fill((*clust).sizeY());
00784                   break;
00785                 }
00786                 case 2: {
00787                   meClPosLayer2OnTrack->Fill(z,phi); 
00788                   meClChargeOnTrack_layer2->Fill(corrCharge);
00789                   meClSizeOnTrack_layer2->Fill((*clust).size());
00790                   meClSizeXOnTrack_layer2->Fill((*clust).sizeX());
00791                   meClSizeYOnTrack_layer2->Fill((*clust).sizeY());
00792                   break;
00793                 }
00794                 case 3: {
00795                   meClPosLayer3OnTrack->Fill(z,phi); 
00796                   meClChargeOnTrack_layer3->Fill(corrCharge);
00797                   meClSizeOnTrack_layer3->Fill((*clust).size());
00798                   meClSizeXOnTrack_layer3->Fill((*clust).sizeX());
00799                   meClSizeYOnTrack_layer3->Fill((*clust).sizeY());
00800                   break;
00801                 }
00802                 
00803                 }
00804                 
00805               }
00806               if(endcap) {
00807                 endcaptrackclusters++;
00808                 //CORR CHARGE
00809                 meClChargeOnTrack_fpix->Fill(corrCharge);
00810                 meClSizeOnTrack_fpix->Fill((*clust).size());
00811                 meClSizeXOnTrack_fpix->Fill((*clust).sizeX());
00812                 meClSizeYOnTrack_fpix->Fill((*clust).sizeY());
00813                 uint32_t DBdisk = PixelEndcapName(DetId((*hit).geographicalId())).diskName();
00814                 float x = clustgp.x(); 
00815                 float y = clustgp.y(); 
00816                 float z = clustgp.z();
00817                 if(z>0){
00818                   if(DBdisk==1) {
00819                     meClPosDisk1pzOnTrack->Fill(x,y);
00820                     meClChargeOnTrack_diskp1->Fill(corrCharge);
00821                     meClSizeOnTrack_diskp1->Fill((*clust).size());
00822                     meClSizeXOnTrack_diskp1->Fill((*clust).sizeX());
00823                     meClSizeYOnTrack_diskp1->Fill((*clust).sizeY());
00824                   }
00825                   if(DBdisk==2) {
00826                     meClPosDisk2pzOnTrack->Fill(x,y); 
00827                     meClChargeOnTrack_diskp2->Fill(corrCharge);
00828                     meClSizeOnTrack_diskp2->Fill((*clust).size());
00829                     meClSizeXOnTrack_diskp2->Fill((*clust).sizeX());
00830                     meClSizeYOnTrack_diskp2->Fill((*clust).sizeY());
00831                   }
00832                 }
00833                 else{
00834                   if(DBdisk==1) {
00835                     meClPosDisk1mzOnTrack->Fill(x,y);
00836                     meClChargeOnTrack_diskm1->Fill(corrCharge);
00837                     meClSizeOnTrack_diskm1->Fill((*clust).size());
00838                     meClSizeXOnTrack_diskm1->Fill((*clust).sizeX());
00839                     meClSizeYOnTrack_diskm1->Fill((*clust).sizeY());
00840                   }
00841                   if(DBdisk==2) {
00842                     meClPosDisk2mzOnTrack->Fill(x,y); 
00843                     meClChargeOnTrack_diskm2->Fill(corrCharge);
00844                     meClSizeOnTrack_diskm2->Fill((*clust).size());
00845                     meClSizeXOnTrack_diskm2->Fill((*clust).sizeX());
00846                     meClSizeYOnTrack_diskm2->Fill((*clust).sizeY());
00847                   }
00848                 } 
00849               }
00850               
00851             }//end if (cluster exists)
00852 
00853           }//end if (persistent hit exists and is pixel hit)
00854           
00855         }//end of else 
00856         
00857         
00858       }//end for (all traj measurements of pixeltrack)
00859     }//end if (is pixeltrack)
00860     else {
00861       if(debug_) std::cout << "no pixeltrack:\n";
00862       if(crossesPixVol) meNofTracksInPixVol_->Fill(1,1);
00863     }
00864     
00865   }//end loop on map entries
00866 
00867   //find clusters that are NOT on track
00868   //edmNew::DetSet<SiPixelCluster>::const_iterator  di;
00869   if(debug_) std::cout << "clusters not on track: (size " << clustColl.size() << ") ";
00870 
00871   for(TrackerGeometry::DetContainer::const_iterator it = TG->dets().begin(); it != TG->dets().end(); it++){
00872     //if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
00873     DetId detId = (*it)->geographicalId();
00874     if(detId>=302055684 && detId<=352477708){ // make sure it's a Pixel module WITHOUT using dynamic_cast!  
00875       int nofclOnTrack = 0, nofclOffTrack=0; 
00876       uint32_t DBlayer=10, DBdisk=10; 
00877       float z=0.; 
00878       //set layer/disk
00879       if(DetId(detId).subdetId() == 1) { // Barrel module
00880         DBlayer = PixelBarrelName(DetId(detId)).layerName();
00881       }
00882       if(DetId(detId).subdetId() == 2){ // Endcap module
00883         DBdisk = PixelEndcapName(DetId(detId )).diskName();
00884       }
00885       edmNew::DetSetVector<SiPixelCluster>::const_iterator isearch = clustColl.find(detId);
00886       if( isearch != clustColl.end() ) {  // Not an empty iterator
00887         edmNew::DetSet<SiPixelCluster>::const_iterator  di;
00888         for(di=isearch->begin(); di!=isearch->end(); di++){
00889           unsigned int temp = clusterSet.size();
00890           clusterSet.insert(*di);
00891           //check if cluster is off track
00892           if(clusterSet.size()>temp) {
00893             otherclusters++;
00894             nofclOffTrack++; 
00895             //fill histograms for clusters off tracks
00896             //correct SiPixelTrackResidualModule
00897             std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
00898 
00899             if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*di), false, -1., reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn); 
00900             
00901 
00902 
00903             meClSizeNotOnTrack_all->Fill((*di).size());
00904             meClSizeXNotOnTrack_all->Fill((*di).sizeX());
00905             meClSizeYNotOnTrack_all->Fill((*di).sizeY());
00906             meClChargeNotOnTrack_all->Fill((*di).charge()/1000);
00907 
00909             //find cluster global position (rphi, z) get cluster
00910             //define tracker and pixel geometry and topology
00911             const TrackerGeometry& theTracker(*theTrackerGeometry);
00912             const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
00913             //test if PixelGeomDetUnit exists
00914             if(theGeomDet == 0) {
00915               if(debug_) std::cout << "NO THEGEOMDET\n";
00916               continue;
00917             }
00918             const PixelTopology * topol = &(theGeomDet->specificTopology());
00919            
00920             //center of gravity (of charge)
00921             float xcenter = di->x();
00922             float ycenter = di->y();
00923             // get the cluster position in local coordinates (cm) 
00924             LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
00925             // get the cluster position in global coordinates (cm)
00926             GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
00927 
00929 
00930             //barrel
00931             if(DetId(detId).subdetId() == 1) {
00932               meClSizeNotOnTrack_bpix->Fill((*di).size());
00933               meClSizeXNotOnTrack_bpix->Fill((*di).sizeX());
00934               meClSizeYNotOnTrack_bpix->Fill((*di).sizeY());
00935               meClChargeNotOnTrack_bpix->Fill((*di).charge()/1000);
00936               barrelotherclusters++;
00937               //DBlayer = PixelBarrelName(DetId(detId)).layerName();
00938               float phi = clustgp.phi(); 
00939               //float r = clustgp.perp();
00940               z = clustgp.z();
00941               switch(DBlayer){
00942               case 1: {
00943                 meClPosLayer1NotOnTrack->Fill(z,phi); 
00944                 meClSizeNotOnTrack_layer1->Fill((*di).size());
00945                 meClSizeXNotOnTrack_layer1->Fill((*di).sizeX());
00946                 meClSizeYNotOnTrack_layer1->Fill((*di).sizeY());
00947                 meClChargeNotOnTrack_layer1->Fill((*di).charge()/1000);
00948                 break;
00949               }
00950               case 2: {
00951                 meClPosLayer2NotOnTrack->Fill(z,phi);
00952                 meClSizeNotOnTrack_layer2->Fill((*di).size());
00953                 meClSizeXNotOnTrack_layer2->Fill((*di).sizeX());
00954                 meClSizeYNotOnTrack_layer2->Fill((*di).sizeY());
00955                 meClChargeNotOnTrack_layer2->Fill((*di).charge()/1000);
00956                 break;
00957               }
00958               case 3: {
00959                 meClPosLayer3NotOnTrack->Fill(z,phi); 
00960                 meClSizeNotOnTrack_layer3->Fill((*di).size());
00961                 meClSizeXNotOnTrack_layer3->Fill((*di).sizeX());
00962                 meClSizeYNotOnTrack_layer3->Fill((*di).sizeY());
00963                 meClChargeNotOnTrack_layer3->Fill((*di).charge()/1000);
00964                 break;
00965               }
00966                 
00967               }
00968             }
00969             //endcap
00970             if(DetId(detId).subdetId() == 2) {
00971               meClSizeNotOnTrack_fpix->Fill((*di).size());
00972               meClSizeXNotOnTrack_fpix->Fill((*di).sizeX());
00973               meClSizeYNotOnTrack_fpix->Fill((*di).sizeY());
00974               meClChargeNotOnTrack_fpix->Fill((*di).charge()/1000);
00975               endcapotherclusters++;
00976               //DBdisk = PixelEndcapName(DetId(detId )).diskName();
00977               float x = clustgp.x(); 
00978               float y = clustgp.y(); 
00979               z = clustgp.z();
00980               if(z>0){
00981                 if(DBdisk==1) {
00982                   meClPosDisk1pzNotOnTrack->Fill(x,y);
00983                   meClSizeNotOnTrack_diskp1->Fill((*di).size());
00984                   meClSizeXNotOnTrack_diskp1->Fill((*di).sizeX());
00985                   meClSizeYNotOnTrack_diskp1->Fill((*di).sizeY());
00986                   meClChargeNotOnTrack_diskp1->Fill((*di).charge()/1000);
00987                 }
00988                 if(DBdisk==2) {
00989                   meClPosDisk2pzNotOnTrack->Fill(x,y); 
00990                   meClSizeNotOnTrack_diskp2->Fill((*di).size());
00991                   meClSizeXNotOnTrack_diskp2->Fill((*di).sizeX());
00992                   meClSizeYNotOnTrack_diskp2->Fill((*di).sizeY());
00993                   meClChargeNotOnTrack_diskp2->Fill((*di).charge()/1000);
00994                 }
00995               }
00996               else{
00997                 if(DBdisk==1) {
00998                   meClPosDisk1mzNotOnTrack->Fill(x,y);
00999                   meClSizeNotOnTrack_diskm1->Fill((*di).size());
01000                   meClSizeXNotOnTrack_diskm1->Fill((*di).sizeX());
01001                   meClSizeYNotOnTrack_diskm1->Fill((*di).sizeY());
01002                   meClChargeNotOnTrack_diskm1->Fill((*di).charge()/1000);
01003                 }
01004                 if(DBdisk==2) {
01005                   meClPosDisk2mzNotOnTrack->Fill(x,y); 
01006                   meClSizeNotOnTrack_diskm2->Fill((*di).size());
01007                   meClSizeXNotOnTrack_diskm2->Fill((*di).sizeX());
01008                   meClSizeYNotOnTrack_diskm2->Fill((*di).sizeY());
01009                   meClChargeNotOnTrack_diskm2->Fill((*di).charge()/1000);
01010                 }
01011               } 
01012 
01013             }
01014           }// end "if cluster off track"
01015           else {
01016             nofclOnTrack++; 
01017             if(z == 0 && DBdisk != 10){
01018               //find cluster global position (rphi, z) get cluster
01019               //define tracker and pixel geometry and topology
01020               const TrackerGeometry& theTracker(*theTrackerGeometry);
01021               const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
01022               //test if PixelGeomDetUnit exists
01023               if(theGeomDet == 0) {
01024                 if(debug_) std::cout << "NO THEGEOMDET\n";
01025                 continue;
01026               }
01027               const PixelTopology * topol = &(theGeomDet->specificTopology());
01028               //center of gravity (of charge)
01029               float xcenter = di->x();
01030               float ycenter = di->y();
01031               // get the cluster position in local coordinates (cm) 
01032               LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
01033               // get the cluster position in global coordinates (cm)
01034               GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );  
01035               z = clustgp.z();
01036             }
01037           }
01038         }
01039       }
01040       //++ fill the number of clusters on a module
01041       std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
01042       if (pxd!=theSiPixelStructure.end()) (*pxd).second->nfill(nofclOnTrack, nofclOffTrack, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn); 
01043       if(nofclOnTrack!=0) meNClustersOnTrack_all->Fill(nofclOnTrack); 
01044       if(nofclOffTrack!=0) meNClustersNotOnTrack_all->Fill(nofclOffTrack); 
01045       //barrel
01046       if(DetId(detId).subdetId() == 1){
01047         if(nofclOnTrack!=0) meNClustersOnTrack_bpix->Fill(nofclOnTrack); 
01048         if(nofclOffTrack!=0) meNClustersNotOnTrack_bpix->Fill(nofclOffTrack); 
01049         //DBlayer = PixelBarrelName(DetId(detId)).layerName();
01050         switch(DBlayer){
01051         case 1: { 
01052           if(nofclOnTrack!=0) meNClustersOnTrack_layer1->Fill(nofclOnTrack);
01053           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer1->Fill(nofclOffTrack); break;
01054         }
01055         case 2: {
01056           if(nofclOnTrack!=0) meNClustersOnTrack_layer2->Fill(nofclOnTrack);
01057           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer2->Fill(nofclOffTrack); break; 
01058         }
01059         case 3: {
01060           if(nofclOnTrack!=0) meNClustersOnTrack_layer3->Fill(nofclOnTrack); 
01061           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer3->Fill(nofclOffTrack); break; 
01062         }
01063         }
01064       }//end barrel
01065       //endcap
01066       if(DetId(detId).subdetId() == 2) {
01067         //DBdisk = PixelEndcapName(DetId(detId )).diskName();
01068         //z = clustgp.z();
01069         if(nofclOnTrack!=0) meNClustersOnTrack_fpix->Fill(nofclOnTrack); 
01070         if(nofclOffTrack!=0) meNClustersNotOnTrack_fpix->Fill(nofclOffTrack);
01071         if(z>0){
01072           if(DBdisk==1) {
01073             if(nofclOnTrack!=0) meNClustersOnTrack_diskp1->Fill(nofclOnTrack); 
01074             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp1->Fill(nofclOffTrack);
01075           }
01076           if(DBdisk==2) {
01077             if(nofclOnTrack!=0) meNClustersOnTrack_diskp2->Fill(nofclOnTrack); 
01078             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp2->Fill(nofclOffTrack);
01079           }
01080         }
01081         if(z<0){
01082           if(DBdisk==1) {
01083             if(nofclOnTrack!=0) meNClustersOnTrack_diskm1->Fill(nofclOnTrack); 
01084             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm1->Fill(nofclOffTrack);
01085           }
01086           if(DBdisk==2) {
01087             if(nofclOnTrack!=0) meNClustersOnTrack_diskm2->Fill(nofclOnTrack); 
01088             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm2->Fill(nofclOffTrack);
01089           }
01090         }
01091       }
01092 
01093     }//end if it's a Pixel module
01094   }//end for loop over tracker detector geometry modules
01095 
01096 
01097   if(trackclusters>0) (meNofClustersOnTrack_)->Fill(0,trackclusters);
01098   if(barreltrackclusters>0)(meNofClustersOnTrack_)->Fill(1,barreltrackclusters);
01099   if(endcaptrackclusters>0)(meNofClustersOnTrack_)->Fill(2,endcaptrackclusters);
01100   if(otherclusters>0)(meNofClustersNotOnTrack_)->Fill(0,otherclusters);
01101   if(barrelotherclusters>0)(meNofClustersNotOnTrack_)->Fill(1,barrelotherclusters);
01102   if(endcapotherclusters>0)(meNofClustersNotOnTrack_)->Fill(2,endcapotherclusters);
01103   if(tracks>0)(meNofTracks_)->Fill(0,tracks);
01104   if(pixeltracks>0)(meNofTracks_)->Fill(1,pixeltracks);
01105   if(bpixtracks>0)(meNofTracks_)->Fill(2,bpixtracks);
01106   if(fpixtracks>0)(meNofTracks_)->Fill(3,fpixtracks);
01107 }
01108 
01109 
01110 DEFINE_FWK_MODULE(SiPixelTrackResidualSource); // define this as a plug-in