CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/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.25 2012/09/11 09:37:41 clseitz 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 //Claudia new libraries
00050 #include "DataFormats/VertexReco/interface/Vertex.h"
00051 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00052 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00053 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00054 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00055 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00056 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
00057 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00058 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00059 
00060 using namespace std;
00061 using namespace edm;
00062 
00063 
00064 SiPixelTrackResidualSource::SiPixelTrackResidualSource(const edm::ParameterSet& pSet) :
00065   pSet_(pSet),
00066   modOn( pSet.getUntrackedParameter<bool>("modOn",true) ),
00067   reducedSet( pSet.getUntrackedParameter<bool>("reducedSet",true) ),
00068   ladOn( pSet.getUntrackedParameter<bool>("ladOn",false) ), 
00069   layOn( pSet.getUntrackedParameter<bool>("layOn",false) ), 
00070   phiOn( pSet.getUntrackedParameter<bool>("phiOn",false) ), 
00071   ringOn( pSet.getUntrackedParameter<bool>("ringOn",false) ), 
00072   bladeOn( pSet.getUntrackedParameter<bool>("bladeOn",false) ), 
00073   diskOn( pSet.getUntrackedParameter<bool>("diskOn",false) )
00074    
00075 { 
00076    pSet_ = pSet; 
00077    debug_ = pSet_.getUntrackedParameter<bool>("debug", false); 
00078    src_ = pSet_.getParameter<edm::InputTag>("src"); 
00079    clustersrc_ = pSet_.getParameter<edm::InputTag>("clustersrc");
00080    tracksrc_ = pSet_.getParameter<edm::InputTag>("trajectoryInput");
00081    dbe_ = edm::Service<DQMStore>().operator->();
00082    ttrhbuilder_ = pSet_.getParameter<std::string>("TTRHBuilder");
00083    ptminres_= pSet.getUntrackedParameter<double>("PtMinRes",4.0) ;
00084 
00085   LogInfo("PixelDQM") << "SiPixelTrackResidualSource constructor" << endl;
00086   LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/" 
00087             << layOn << "/" << phiOn << std::endl;
00088   LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/" 
00089             << ringOn << std::endl;
00090 }
00091 
00092 
00093 SiPixelTrackResidualSource::~SiPixelTrackResidualSource() {
00094   LogInfo("PixelDQM") << "SiPixelTrackResidualSource destructor" << endl;
00095 
00096   std::map<uint32_t,SiPixelTrackResidualModule*>::iterator struct_iter;
00097   for (struct_iter = theSiPixelStructure.begin() ; struct_iter != theSiPixelStructure.end() ; struct_iter++){
00098     delete struct_iter->second;
00099     struct_iter->second = 0;
00100   }
00101 }
00102 
00103 void SiPixelTrackResidualSource::beginJob() {
00104   LogInfo("PixelDQM") << "SiPixelTrackResidualSource beginJob()" << endl;
00105   firstRun = true;
00106   NTotal=0;
00107   NLowProb=0;
00108 }
00109 
00110 
00111 void SiPixelTrackResidualSource::beginRun(const edm::Run& r, edm::EventSetup const& iSetup) {
00112   LogInfo("PixelDQM") << "SiPixelTrackResidualSource beginRun()" << endl;
00113 
00114   if(firstRun){
00115   // retrieve TrackerGeometry for pixel dets
00116   edm::ESHandle<TrackerGeometry> TG;
00117   iSetup.get<TrackerDigiGeometryRecord>().get(TG);
00118   if (debug_) LogVerbatim("PixelDQM") << "TrackerGeometry "<< &(*TG) <<" size is "<< TG->dets().size() << endl;
00119  
00120   // build theSiPixelStructure with the pixel barrel and endcap dets from TrackerGeometry
00121   for (TrackerGeometry::DetContainer::const_iterator pxb = TG->detsPXB().begin();  
00122        pxb!=TG->detsPXB().end(); pxb++) {
00123     if (dynamic_cast<PixelGeomDetUnit*>((*pxb))!=0) {
00124       SiPixelTrackResidualModule* module = new SiPixelTrackResidualModule((*pxb)->geographicalId().rawId());
00125       theSiPixelStructure.insert(pair<uint32_t, SiPixelTrackResidualModule*>((*pxb)->geographicalId().rawId(), module));
00126     }
00127   }
00128   for (TrackerGeometry::DetContainer::const_iterator pxf = TG->detsPXF().begin(); 
00129        pxf!=TG->detsPXF().end(); pxf++) {
00130     if (dynamic_cast<PixelGeomDetUnit*>((*pxf))!=0) {
00131       SiPixelTrackResidualModule* module = new SiPixelTrackResidualModule((*pxf)->geographicalId().rawId());
00132       theSiPixelStructure.insert(pair<uint32_t, SiPixelTrackResidualModule*>((*pxf)->geographicalId().rawId(), module));
00133     }
00134   }
00135   LogInfo("PixelDQM") << "SiPixelStructure size is " << theSiPixelStructure.size() << endl;
00136 
00137   // book residual histograms in theSiPixelFolder - one (x,y) pair of histograms per det
00138   SiPixelFolderOrganizer theSiPixelFolder;
00139   for (std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.begin(); 
00140        pxd!=theSiPixelStructure.end(); pxd++) {
00141 
00142     if(modOn){
00143       if (theSiPixelFolder.setModuleFolder((*pxd).first)) (*pxd).second->book(pSet_,reducedSet);
00144       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Folder Creation Failed! "; 
00145     }
00146     if(ladOn){
00147       if (theSiPixelFolder.setModuleFolder((*pxd).first,1)) {
00148         
00149         (*pxd).second->book(pSet_,reducedSet,1);
00150       }
00151       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource ladder Folder Creation Failed! "; 
00152     }
00153     if(layOn){
00154       if (theSiPixelFolder.setModuleFolder((*pxd).first,2)) (*pxd).second->book(pSet_,reducedSet,2);
00155       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource layer Folder Creation Failed! "; 
00156     }
00157     if(phiOn){
00158       if (theSiPixelFolder.setModuleFolder((*pxd).first,3)) (*pxd).second->book(pSet_,reducedSet,3);
00159       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource phi Folder Creation Failed! "; 
00160     }
00161     if(bladeOn){
00162       if (theSiPixelFolder.setModuleFolder((*pxd).first,4)) (*pxd).second->book(pSet_,reducedSet,4);
00163       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Blade Folder Creation Failed! "; 
00164     }
00165     if(diskOn){
00166       if (theSiPixelFolder.setModuleFolder((*pxd).first,5)) (*pxd).second->book(pSet_,reducedSet,5);
00167       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Disk Folder Creation Failed! "; 
00168     }
00169     if(ringOn){
00170       if (theSiPixelFolder.setModuleFolder((*pxd).first,6)) (*pxd).second->book(pSet_,reducedSet,6);
00171       else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Ring Folder Creation Failed! "; 
00172     }
00173   }
00174 
00175 
00176 //   edm::InputTag tracksrc = pSet_.getParameter<edm::InputTag>("trajectoryInput");
00177 //   edm::InputTag clustersrc = pSet_.getParameter<edm::InputTag>("clustersrc");
00178 
00179   //number of tracks
00180   dbe_->setCurrentFolder("Pixel/Tracks");
00181   meNofTracks_ = dbe_->book1D("ntracks_" + tracksrc_.label(),"Number of Tracks",4,0,4);
00182   meNofTracks_->setAxisTitle("Number of Tracks",1);
00183   meNofTracks_->setBinLabel(1,"All");
00184   meNofTracks_->setBinLabel(2,"Pixel");
00185   meNofTracks_->setBinLabel(3,"BPix");
00186   meNofTracks_->setBinLabel(4,"FPix");
00187 
00188   //number of tracks in pixel fiducial volume
00189   dbe_->setCurrentFolder("Pixel/Tracks");
00190   meNofTracksInPixVol_ = dbe_->book1D("ntracksInPixVol_" + tracksrc_.label(),"Number of Tracks crossing Pixel fiducial Volume",2,0,2);
00191   meNofTracksInPixVol_->setAxisTitle("Number of Tracks",1);
00192   meNofTracksInPixVol_->setBinLabel(1,"With Hits");
00193   meNofTracksInPixVol_->setBinLabel(2,"Without Hits");
00194 
00195   //number of clusters (associated to track / not associated)
00196   dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00197   meNofClustersOnTrack_ = dbe_->book1D("nclusters_" + clustersrc_.label() + "_tot","Number of Clusters (on track)",3,0,3);
00198   meNofClustersOnTrack_->setAxisTitle("Number of Clusters on Track",1);
00199   meNofClustersOnTrack_->setBinLabel(1,"All");
00200   meNofClustersOnTrack_->setBinLabel(2,"BPix");
00201   meNofClustersOnTrack_->setBinLabel(3,"FPix");
00202   dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00203   meNofClustersNotOnTrack_ = dbe_->book1D("nclusters_" + clustersrc_.label() + "_tot","Number of Clusters (off track)",3,0,3);
00204   meNofClustersNotOnTrack_->setAxisTitle("Number of Clusters off Track",1);
00205   meNofClustersNotOnTrack_->setBinLabel(1,"All");
00206   meNofClustersNotOnTrack_->setBinLabel(2,"BPix");
00207   meNofClustersNotOnTrack_->setBinLabel(3,"FPix");
00208 
00209   //cluster charge and size
00210   //charge
00211   //on track
00212   dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00213   meClChargeOnTrack_all = dbe_->book1D("charge_" + clustersrc_.label(),"Charge (on track)",500,0.,500.);
00214   meClChargeOnTrack_all->setAxisTitle("Charge size (in ke)",1);
00215   meClChargeOnTrack_bpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Barrel","Charge (on track, barrel)",500,0.,500.);
00216   meClChargeOnTrack_bpix->setAxisTitle("Charge size (in ke)",1);
00217   meClChargeOnTrack_fpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Endcap","Charge (on track, endcap)",500,0.,500.);
00218   meClChargeOnTrack_fpix->setAxisTitle("Charge size (in ke)",1);
00219   meClChargeOnTrack_layer1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_1","Charge (on track, layer1)",500,0.,500.);
00220   meClChargeOnTrack_layer1->setAxisTitle("Charge size (in ke)",1);
00221   meClChargeOnTrack_layer2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_2","Charge (on track, layer2)",500,0.,500.);
00222   meClChargeOnTrack_layer2->setAxisTitle("Charge size (in ke)",1);
00223   meClChargeOnTrack_layer3 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_3","Charge (on track, layer3)",500,0.,500.);
00224   meClChargeOnTrack_layer3->setAxisTitle("Charge size (in ke)",1);
00225   meClChargeOnTrack_diskp1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p1","Charge (on track, diskp1)",500,0.,500.);
00226   meClChargeOnTrack_diskp1->setAxisTitle("Charge size (in ke)",1);
00227   meClChargeOnTrack_diskp2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p2","Charge (on track, diskp2)",500,0.,500.);
00228   meClChargeOnTrack_diskp2->setAxisTitle("Charge size (in ke)",1);
00229   meClChargeOnTrack_diskm1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m1","Charge (on track, diskm1)",500,0.,500.);
00230   meClChargeOnTrack_diskm1->setAxisTitle("Charge size (in ke)",1);
00231   meClChargeOnTrack_diskm2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m2","Charge (on track, diskm2)",500,0.,500.);
00232   meClChargeOnTrack_diskm2->setAxisTitle("Charge size (in ke)",1);
00233   //off track
00234   dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00235   meClChargeNotOnTrack_all = dbe_->book1D("charge_" + clustersrc_.label(),"Charge (off track)",500,0.,500.);
00236   meClChargeNotOnTrack_all->setAxisTitle("Charge size (in ke)",1);
00237   meClChargeNotOnTrack_bpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Barrel","Charge (off track, barrel)",500,0.,500.);
00238   meClChargeNotOnTrack_bpix->setAxisTitle("Charge size (in ke)",1);
00239   meClChargeNotOnTrack_fpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Endcap","Charge (off track, endcap)",500,0.,500.);
00240   meClChargeNotOnTrack_fpix->setAxisTitle("Charge size (in ke)",1);
00241   meClChargeNotOnTrack_layer1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_1","Charge (off track, layer1)",500,0.,500.);
00242   meClChargeNotOnTrack_layer1->setAxisTitle("Charge size (in ke)",1);
00243   meClChargeNotOnTrack_layer2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_2","Charge (off track, layer2)",500,0.,500.);
00244   meClChargeNotOnTrack_layer2->setAxisTitle("Charge size (in ke)",1);
00245   meClChargeNotOnTrack_layer3 = dbe_->book1D("charge_" + clustersrc_.label() + "_Layer_3","Charge (off track, layer3)",500,0.,500.);
00246   meClChargeNotOnTrack_layer3->setAxisTitle("Charge size (in ke)",1);
00247   meClChargeNotOnTrack_diskp1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p1","Charge (off track, diskp1)",500,0.,500.);
00248   meClChargeNotOnTrack_diskp1->setAxisTitle("Charge size (in ke)",1);
00249   meClChargeNotOnTrack_diskp2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_p2","Charge (off track, diskp2)",500,0.,500.);
00250   meClChargeNotOnTrack_diskp2->setAxisTitle("Charge size (in ke)",1);
00251   meClChargeNotOnTrack_diskm1 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m1","Charge (off track, diskm1)",500,0.,500.);
00252   meClChargeNotOnTrack_diskm1->setAxisTitle("Charge size (in ke)",1);
00253   meClChargeNotOnTrack_diskm2 = dbe_->book1D("charge_" + clustersrc_.label() + "_Disk_m2","Charge (off track, diskm2)",500,0.,500.);
00254   meClChargeNotOnTrack_diskm2->setAxisTitle("Charge size (in ke)",1);
00255 
00256   //size
00257   //on track
00258   dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00259   meClSizeOnTrack_all = dbe_->book1D("size_" + clustersrc_.label(),"Size (on track)",100,0.,100.);
00260   meClSizeOnTrack_all->setAxisTitle("Cluster size (in pixels)",1);
00261   meClSizeOnTrack_bpix = dbe_->book1D("size_" + clustersrc_.label() + "_Barrel","Size (on track, barrel)",100,0.,100.);
00262   meClSizeOnTrack_bpix->setAxisTitle("Cluster size (in pixels)",1);
00263   meClSizeOnTrack_fpix = dbe_->book1D("size_" + clustersrc_.label() + "_Endcap","Size (on track, endcap)",100,0.,100.);
00264   meClSizeOnTrack_fpix->setAxisTitle("Cluster size (in pixels)",1);
00265   meClSizeOnTrack_layer1 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_1","Size (on track, layer1)",100,0.,100.);
00266   meClSizeOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00267   meClSizeOnTrack_layer2 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_2","Size (on track, layer2)",100,0.,100.);
00268   meClSizeOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00269   meClSizeOnTrack_layer3 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_3","Size (on track, layer3)",100,0.,100.);
00270   meClSizeOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00271   meClSizeOnTrack_diskp1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p1","Size (on track, diskp1)",100,0.,100.);
00272   meClSizeOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00273   meClSizeOnTrack_diskp2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p2","Size (on track, diskp2)",100,0.,100.);
00274   meClSizeOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00275   meClSizeOnTrack_diskm1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m1","Size (on track, diskm1)",100,0.,100.);
00276   meClSizeOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00277   meClSizeOnTrack_diskm2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m2","Size (on track, diskm2)",100,0.,100.);
00278   meClSizeOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00279   meClSizeXOnTrack_all = dbe_->book1D("sizeX_" + clustersrc_.label(),"SizeX (on track)",100,0.,100.);
00280   meClSizeXOnTrack_all->setAxisTitle("Cluster sizeX (in pixels)",1);
00281   meClSizeXOnTrack_bpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Barrel","SizeX (on track, barrel)",100,0.,100.);
00282   meClSizeXOnTrack_bpix->setAxisTitle("Cluster sizeX (in pixels)",1);
00283   meClSizeXOnTrack_fpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Endcap","SizeX (on track, endcap)",100,0.,100.);
00284   meClSizeXOnTrack_fpix->setAxisTitle("Cluster sizeX (in pixels)",1);
00285   meClSizeXOnTrack_layer1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_1","SizeX (on track, layer1)",100,0.,100.);
00286   meClSizeXOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00287   meClSizeXOnTrack_layer2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_2","SizeX (on track, layer2)",100,0.,100.);
00288   meClSizeXOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00289   meClSizeXOnTrack_layer3 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_3","SizeX (on track, layer3)",100,0.,100.);
00290   meClSizeXOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00291   meClSizeXOnTrack_diskp1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p1","SizeX (on track, diskp1)",100,0.,100.);
00292   meClSizeXOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00293   meClSizeXOnTrack_diskp2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p2","SizeX (on track, diskp2)",100,0.,100.);
00294   meClSizeXOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00295   meClSizeXOnTrack_diskm1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m1","SizeX (on track, diskm1)",100,0.,100.);
00296   meClSizeXOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00297   meClSizeXOnTrack_diskm2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m2","SizeX (on track, diskm2)",100,0.,100.);
00298   meClSizeXOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00299   meClSizeYOnTrack_all = dbe_->book1D("sizeY_" + clustersrc_.label(),"SizeY (on track)",100,0.,100.);
00300   meClSizeYOnTrack_all->setAxisTitle("Cluster sizeY (in pixels)",1);
00301   meClSizeYOnTrack_bpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Barrel","SizeY (on track, barrel)",100,0.,100.);
00302   meClSizeYOnTrack_bpix->setAxisTitle("Cluster sizeY (in pixels)",1);
00303   meClSizeYOnTrack_fpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Endcap","SizeY (on track, endcap)",100,0.,100.);
00304   meClSizeYOnTrack_fpix->setAxisTitle("Cluster sizeY (in pixels)",1);
00305   meClSizeYOnTrack_layer1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_1","SizeY (on track, layer1)",100,0.,100.);
00306   meClSizeYOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00307   meClSizeYOnTrack_layer2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_2","SizeY (on track, layer2)",100,0.,100.);
00308   meClSizeYOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00309   meClSizeYOnTrack_layer3 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_3","SizeY (on track, layer3)",100,0.,100.);
00310   meClSizeYOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00311   meClSizeYOnTrack_diskp1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p1","SizeY (on track, diskp1)",100,0.,100.);
00312   meClSizeYOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00313   meClSizeYOnTrack_diskp2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p2","SizeY (on track, diskp2)",100,0.,100.);
00314   meClSizeYOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00315   meClSizeYOnTrack_diskm1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m1","SizeY (on track, diskm1)",100,0.,100.);
00316   meClSizeYOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00317   meClSizeYOnTrack_diskm2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m2","SizeY (on track, diskm2)",100,0.,100.);
00318   meClSizeYOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00319   //off track
00320   dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00321   meClSizeNotOnTrack_all = dbe_->book1D("size_" + clustersrc_.label(),"Size (off track)",100,0.,100.);
00322   meClSizeNotOnTrack_all->setAxisTitle("Cluster size (in pixels)",1); 
00323   meClSizeNotOnTrack_bpix = dbe_->book1D("size_" + clustersrc_.label() + "_Barrel","Size (off track, barrel)",100,0.,100.);
00324   meClSizeNotOnTrack_bpix->setAxisTitle("Cluster size (in pixels)",1);
00325   meClSizeNotOnTrack_fpix = dbe_->book1D("size_" + clustersrc_.label() + "_Endcap","Size (off track, endcap)",100,0.,100.);
00326   meClSizeNotOnTrack_fpix->setAxisTitle("Cluster size (in pixels)",1);
00327   meClSizeNotOnTrack_layer1 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_1","Size (off track, layer1)",100,0.,100.);
00328   meClSizeNotOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00329   meClSizeNotOnTrack_layer2 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_2","Size (off track, layer2)",100,0.,100.);
00330   meClSizeNotOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00331   meClSizeNotOnTrack_layer3 = dbe_->book1D("size_" + clustersrc_.label() + "_Layer_3","Size (off track, layer3)",100,0.,100.);
00332   meClSizeNotOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00333   meClSizeNotOnTrack_diskp1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p1","Size (off track, diskp1)",100,0.,100.);
00334   meClSizeNotOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00335   meClSizeNotOnTrack_diskp2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_p2","Size (off track, diskp2)",100,0.,100.);
00336   meClSizeNotOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00337   meClSizeNotOnTrack_diskm1 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m1","Size (off track, diskm1)",100,0.,100.);
00338   meClSizeNotOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00339   meClSizeNotOnTrack_diskm2 = dbe_->book1D("size_" + clustersrc_.label() + "_Disk_m2","Size (off track, diskm2)",100,0.,100.);
00340   meClSizeNotOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00341   meClSizeXNotOnTrack_all = dbe_->book1D("sizeX_" + clustersrc_.label(),"SizeX (off track)",100,0.,100.);
00342   meClSizeXNotOnTrack_all->setAxisTitle("Cluster sizeX (in pixels)",1);
00343   meClSizeXNotOnTrack_bpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Barrel","SizeX (off track, barrel)",100,0.,100.);
00344   meClSizeXNotOnTrack_bpix->setAxisTitle("Cluster sizeX (in pixels)",1);
00345   meClSizeXNotOnTrack_fpix = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Endcap","SizeX (off track, endcap)",100,0.,100.);
00346   meClSizeXNotOnTrack_fpix->setAxisTitle("Cluster sizeX (in pixels)",1);
00347   meClSizeXNotOnTrack_layer1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_1","SizeX (off track, layer1)",100,0.,100.);
00348   meClSizeXNotOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00349   meClSizeXNotOnTrack_layer2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_2","SizeX (off track, layer2)",100,0.,100.);
00350   meClSizeXNotOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00351   meClSizeXNotOnTrack_layer3 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Layer_3","SizeX (off track, layer3)",100,0.,100.);
00352   meClSizeXNotOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00353   meClSizeXNotOnTrack_diskp1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p1","SizeX (off track, diskp1)",100,0.,100.);
00354   meClSizeXNotOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00355   meClSizeXNotOnTrack_diskp2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_p2","SizeX (off track, diskp2)",100,0.,100.);
00356   meClSizeXNotOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00357   meClSizeXNotOnTrack_diskm1 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m1","SizeX (off track, diskm1)",100,0.,100.);
00358   meClSizeXNotOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00359   meClSizeXNotOnTrack_diskm2 = dbe_->book1D("sizeX_" + clustersrc_.label() + "_Disk_m2","SizeX (off track, diskm2)",100,0.,100.);
00360   meClSizeXNotOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00361   meClSizeYNotOnTrack_all = dbe_->book1D("sizeY_" + clustersrc_.label(),"SizeY (off track)",100,0.,100.);
00362   meClSizeYNotOnTrack_all->setAxisTitle("Cluster sizeY (in pixels)",1);
00363   meClSizeYNotOnTrack_bpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Barrel","SizeY (off track, barrel)",100,0.,100.);
00364   meClSizeYNotOnTrack_bpix->setAxisTitle("Cluster sizeY (in pixels)",1);
00365   meClSizeYNotOnTrack_fpix = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Endcap","SizeY (off track, endcap)",100,0.,100.);
00366   meClSizeYNotOnTrack_fpix->setAxisTitle("Cluster sizeY (in pixels)",1);
00367   meClSizeYNotOnTrack_layer1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_1","SizeY (off track, layer1)",100,0.,100.);
00368   meClSizeYNotOnTrack_layer1->setAxisTitle("Cluster size (in pixels)",1);
00369   meClSizeYNotOnTrack_layer2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_2","SizeY (off track, layer2)",100,0.,100.);
00370   meClSizeYNotOnTrack_layer2->setAxisTitle("Cluster size (in pixels)",1);
00371   meClSizeYNotOnTrack_layer3 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Layer_3","SizeY (off track, layer3)",100,0.,100.);
00372   meClSizeYNotOnTrack_layer3->setAxisTitle("Cluster size (in pixels)",1);
00373   meClSizeYNotOnTrack_diskp1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p1","SizeY (off track, diskp1)",100,0.,100.);
00374   meClSizeYNotOnTrack_diskp1->setAxisTitle("Cluster size (in pixels)",1);
00375   meClSizeYNotOnTrack_diskp2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_p2","SizeY (off track, diskp2)",100,0.,100.);
00376   meClSizeYNotOnTrack_diskp2->setAxisTitle("Cluster size (in pixels)",1);
00377   meClSizeYNotOnTrack_diskm1 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m1","SizeY (off track, diskm1)",100,0.,100.);
00378   meClSizeYNotOnTrack_diskm1->setAxisTitle("Cluster size (in pixels)",1);
00379   meClSizeYNotOnTrack_diskm2 = dbe_->book1D("sizeY_" + clustersrc_.label() + "_Disk_m2","SizeY (off track, diskm2)",100,0.,100.);
00380   meClSizeYNotOnTrack_diskm2->setAxisTitle("Cluster size (in pixels)",1);
00381   
00382 
00383   //cluster global position
00384   //on track
00385   dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00386   //bpix
00387   meClPosLayer1OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_1","Clusters Layer1 (on track)",200,-30.,30.,128,-3.2,3.2);
00388   meClPosLayer1OnTrack->setAxisTitle("Global Z (cm)",1);
00389   meClPosLayer1OnTrack->setAxisTitle("Global #phi",2);
00390   meClPosLayer2OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_2","Clusters Layer2 (on track)",200,-30.,30.,128,-3.2,3.2);
00391   meClPosLayer2OnTrack->setAxisTitle("Global Z (cm)",1);
00392   meClPosLayer2OnTrack->setAxisTitle("Global #phi",2);
00393   meClPosLayer3OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_3","Clusters Layer3 (on track)",200,-30.,30.,128,-3.2,3.2);
00394   meClPosLayer3OnTrack->setAxisTitle("Global Z (cm)",1);
00395   meClPosLayer3OnTrack->setAxisTitle("Global #phi",2);
00396   //fpix
00397   meClPosDisk1pzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_1","Clusters +Z Disk1 (on track)",80,-20.,20.,80,-20.,20.);
00398   meClPosDisk1pzOnTrack->setAxisTitle("Global X (cm)",1);
00399   meClPosDisk1pzOnTrack->setAxisTitle("Global Y (cm)",2);
00400   meClPosDisk2pzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_2","Clusters +Z Disk2 (on track)",80,-20.,20.,80,-20.,20.);
00401   meClPosDisk2pzOnTrack->setAxisTitle("Global X (cm)",1);
00402   meClPosDisk2pzOnTrack->setAxisTitle("Global Y (cm)",2);
00403   meClPosDisk1mzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_1","Clusters -Z Disk1 (on track)",80,-20.,20.,80,-20.,20.);
00404   meClPosDisk1mzOnTrack->setAxisTitle("Global X (cm)",1);
00405   meClPosDisk1mzOnTrack->setAxisTitle("Global Y (cm)",2);
00406   meClPosDisk2mzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_2","Clusters -Z Disk2 (on track)",80,-20.,20.,80,-20.,20.);
00407   meClPosDisk2mzOnTrack->setAxisTitle("Global X (cm)",1);
00408   meClPosDisk2mzOnTrack->setAxisTitle("Global Y (cm)",2);
00409 
00410   meNClustersOnTrack_all = dbe_->book1D("nclusters_" + clustersrc_.label(),"Number of Clusters (on Track)",50,0.,50.);
00411   meNClustersOnTrack_all->setAxisTitle("Number of Clusters",1);
00412   meNClustersOnTrack_bpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Barrel","Number of Clusters (on track, barrel)",50,0.,50.);
00413   meNClustersOnTrack_bpix->setAxisTitle("Number of Clusters",1);
00414   meNClustersOnTrack_fpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Endcap","Number of Clusters (on track, endcap)",50,0.,50.);
00415   meNClustersOnTrack_fpix->setAxisTitle("Number of Clusters",1);
00416   meNClustersOnTrack_layer1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_1","Number of Clusters (on track, layer1)",50,0.,50.);
00417   meNClustersOnTrack_layer1->setAxisTitle("Number of Clusters",1);
00418   meNClustersOnTrack_layer2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_2","Number of Clusters (on track, layer2)",50,0.,50.);
00419   meNClustersOnTrack_layer2->setAxisTitle("Number of Clusters",1);
00420   meNClustersOnTrack_layer3 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_3","Number of Clusters (on track, layer3)",50,0.,50.);
00421   meNClustersOnTrack_layer3->setAxisTitle("Number of Clusters",1);
00422   meNClustersOnTrack_diskp1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p1","Number of Clusters (on track, diskp1)",50,0.,50.);
00423   meNClustersOnTrack_diskp1->setAxisTitle("Number of Clusters",1);
00424   meNClustersOnTrack_diskp2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p2","Number of Clusters (on track, diskp2)",50,0.,50.);
00425   meNClustersOnTrack_diskp2->setAxisTitle("Number of Clusters",1);
00426   meNClustersOnTrack_diskm1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m1","Number of Clusters (on track, diskm1)",50,0.,50.);
00427   meNClustersOnTrack_diskm1->setAxisTitle("Number of Clusters",1);
00428   meNClustersOnTrack_diskm2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m2","Number of Clusters (on track, diskm2)",50,0.,50.);
00429   meNClustersOnTrack_diskm2->setAxisTitle("Number of Clusters",1);
00430 
00431   //not on track
00432   dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00433   //bpix
00434   meClPosLayer1NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_1","Clusters Layer1 (off track)",200,-30.,30.,128,-3.2,3.2);
00435   meClPosLayer1NotOnTrack->setAxisTitle("Global Z (cm)",1);
00436   meClPosLayer1NotOnTrack->setAxisTitle("Global #phi",2);
00437   meClPosLayer2NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_2","Clusters Layer2 (off track)",200,-30.,30.,128,-3.2,3.2);
00438   meClPosLayer2NotOnTrack->setAxisTitle("Global Z (cm)",1);
00439   meClPosLayer2NotOnTrack->setAxisTitle("Global #phi",2);
00440   meClPosLayer3NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_3","Clusters Layer3 (off track)",200,-30.,30.,128,-3.2,3.2);
00441   meClPosLayer3NotOnTrack->setAxisTitle("Global Z (cm)",1);
00442   meClPosLayer3NotOnTrack->setAxisTitle("Global #phi",2);
00443   //fpix
00444   meClPosDisk1pzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_1","Clusters +Z Disk1 (off track)",80,-20.,20.,80,-20.,20.);
00445   meClPosDisk1pzNotOnTrack->setAxisTitle("Global X (cm)",1);
00446   meClPosDisk1pzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00447   meClPosDisk2pzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_2","Clusters +Z Disk2 (off track)",80,-20.,20.,80,-20.,20.);
00448   meClPosDisk2pzNotOnTrack->setAxisTitle("Global X (cm)",1);
00449   meClPosDisk2pzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00450   meClPosDisk1mzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_1","Clusters -Z Disk1 (off track)",80,-20.,20.,80,-20.,20.);
00451   meClPosDisk1mzNotOnTrack->setAxisTitle("Global X (cm)",1);
00452   meClPosDisk1mzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00453   meClPosDisk2mzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_2","Clusters -Z Disk2 (off track)",80,-20.,20.,80,-20.,20.);
00454   meClPosDisk2mzNotOnTrack->setAxisTitle("Global X (cm)",1);
00455   meClPosDisk2mzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00456 
00457   meNClustersNotOnTrack_all = dbe_->book1D("nclusters_" + clustersrc_.label(),"Number of Clusters (off Track)",50,0.,50.);
00458   meNClustersNotOnTrack_all->setAxisTitle("Number of Clusters",1);
00459   meNClustersNotOnTrack_bpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Barrel","Number of Clusters (off track, barrel)",50,0.,50.);
00460   meNClustersNotOnTrack_bpix->setAxisTitle("Number of Clusters",1);
00461   meNClustersNotOnTrack_fpix = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Endcap","Number of Clusters (off track, endcap)",50,0.,50.);
00462   meNClustersNotOnTrack_fpix->setAxisTitle("Number of Clusters",1);
00463   meNClustersNotOnTrack_layer1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_1","Number of Clusters (off track, layer1)",50,0.,50.);
00464   meNClustersNotOnTrack_layer1->setAxisTitle("Number of Clusters",1);
00465   meNClustersNotOnTrack_layer2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_2","Number of Clusters (off track, layer2)",50,0.,50.);
00466   meNClustersNotOnTrack_layer2->setAxisTitle("Number of Clusters",1);
00467   meNClustersNotOnTrack_layer3 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Layer_3","Number of Clusters (off track, layer3)",50,0.,50.);
00468   meNClustersNotOnTrack_layer3->setAxisTitle("Number of Clusters",1);
00469   meNClustersNotOnTrack_diskp1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p1","Number of Clusters (off track, diskp1)",50,0.,50.);
00470   meNClustersNotOnTrack_diskp1->setAxisTitle("Number of Clusters",1);
00471   meNClustersNotOnTrack_diskp2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_p2","Number of Clusters (off track, diskp2)",50,0.,50.);
00472   meNClustersNotOnTrack_diskp2->setAxisTitle("Number of Clusters",1);
00473   meNClustersNotOnTrack_diskm1 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m1","Number of Clusters (off track, diskm1)",50,0.,50.);
00474   meNClustersNotOnTrack_diskm1->setAxisTitle("Number of Clusters",1);
00475   meNClustersNotOnTrack_diskm2 = dbe_->book1D("nclusters_" + clustersrc_.label() + "_Disk_m2","Number of Clusters (off track, diskm2)",50,0.,50.);
00476   meNClustersNotOnTrack_diskm2->setAxisTitle("Number of Clusters",1);
00477 
00478   //HitProbability
00479   //on track
00480   dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00481   meHitProbability = dbe_->book1D("FractionLowProb","Fraction of hits with low probability;FractionLowProb;#HitsOnTrack",100,0.,1.);
00482 
00483   if (debug_) {
00484     // book summary residual histograms in a debugging folder - one (x,y) pair of histograms per subdetector 
00485     dbe_->setCurrentFolder("debugging"); 
00486     char hisID[80]; 
00487     for (int s=0; s<3; s++) {
00488       sprintf(hisID,"residual_x_subdet_%i",s); 
00489       meSubdetResidualX[s] = dbe_->book1D(hisID,"Pixel Hit-to-Track Residual in X",500,-5.,5.);
00490       
00491       sprintf(hisID,"residual_y_subdet_%i",s);
00492       meSubdetResidualY[s] = dbe_->book1D(hisID,"Pixel Hit-to-Track Residual in Y",500,-5.,5.);  
00493     }
00494   }
00495   
00496   firstRun = false;
00497   }
00498 }
00499 
00500 
00501 void SiPixelTrackResidualSource::endJob(void) {
00502   LogInfo("PixelDQM") << "SiPixelTrackResidualSource endJob()";
00503 
00504   // save the residual histograms to an output root file
00505   bool saveFile = pSet_.getUntrackedParameter<bool>("saveFile", true);
00506   if (saveFile) { 
00507     std::string outputFile = pSet_.getParameter<std::string>("outputFile");
00508     LogInfo("PixelDQM") << " - saving histograms to "<< outputFile.data();
00509     dbe_->save(outputFile);
00510   } 
00511   LogInfo("PixelDQM") << endl; // dbe_->showDirStructure();
00512 }
00513 
00514 
00515 void SiPixelTrackResidualSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00516   
00517   // retrieve TrackerGeometry again and MagneticField for use in transforming 
00518   // a TrackCandidate's P(ersistent)TrajectoryStateoOnDet (PTSoD) to a TrajectoryStateOnSurface (TSoS)
00519   ESHandle<TrackerGeometry> TG;
00520   iSetup.get<TrackerDigiGeometryRecord>().get(TG);
00521   const TrackerGeometry* theTrackerGeometry = TG.product();
00522   
00523   //analytic triplet method to calculate the track residuals in the pixe barrel detector    
00524   
00525   //--------------------------------------------------------------------
00526   // beam spot:
00527   //
00528   edm::Handle<reco::BeamSpot> rbs;
00529   iEvent.getByLabel( "offlineBeamSpot", rbs );
00530   math::XYZPoint bsP = math::XYZPoint(0,0,0);
00531   if( !rbs.failedToGet() && rbs.isValid() )
00532     {
00533       bsP = math::XYZPoint( rbs->x0(), rbs->y0(), rbs->z0() );
00534     }
00535   
00536   //--------------------------------------------------------------------
00537   // primary vertices:
00538   //
00539   edm::Handle<reco::VertexCollection> vertices;
00540   iEvent.getByLabel("offlinePrimaryVertices", vertices );
00541   
00542   if( vertices.failedToGet() ) return;
00543   if( !vertices.isValid() ) return;
00544   
00545   math::XYZPoint vtxN = math::XYZPoint(0,0,0);
00546   math::XYZPoint vtxP = math::XYZPoint(0,0,0);
00547   
00548   double bestNdof = 0;
00549   double maxSumPt = 0;
00550   reco::Vertex bestPvx;
00551   for(reco::VertexCollection::const_iterator iVertex = vertices->begin();
00552       iVertex != vertices->end(); ++iVertex ) {
00553     if( iVertex->ndof() > bestNdof ) {
00554       bestNdof = iVertex->ndof();
00555       vtxN = math::XYZPoint( iVertex->x(), iVertex->y(), iVertex->z() );
00556     }//ndof
00557     if( iVertex->p4().pt() > maxSumPt ) {
00558       maxSumPt = iVertex->p4().pt();
00559       vtxP = math::XYZPoint( iVertex->x(), iVertex->y(), iVertex->z() );
00560       bestPvx = *iVertex;
00561     }//sumpt
00562     
00563   }//vertex
00564   
00565   if( maxSumPt < 1 ) return;
00566   
00567   if( maxSumPt < 1 ) vtxP = vtxN;
00568   
00569   //---------------------------------------------
00570   //get Tracks
00571   //
00572   edm:: Handle<reco::TrackCollection> TracksForRes;
00573   iEvent.getByLabel( "generalTracks", TracksForRes );
00574   //
00575   // transient track builder, needs B-field from data base (global tag in .py)
00576   //
00577   edm::ESHandle<TransientTrackBuilder> theB;
00578   iSetup.get<TransientTrackRecord>().get( "TransientTrackBuilder", theB );
00579 
00580   //get the TransienTrackingRecHitBuilder needed for extracting the global position of the hits in the pixel
00581   edm::ESHandle<TransientTrackingRecHitBuilder> theTrackerRecHitBuilder;
00582   iSetup.get<TransientRecHitRecord>().get(ttrhbuilder_,theTrackerRecHitBuilder);
00583 
00584   //check that tracks are valid
00585   if( TracksForRes.failedToGet() ) return;
00586   if( !TracksForRes.isValid() ) return;
00587 
00588   //get tracker geometry
00589   edm::ESHandle<TrackerGeometry> pDD;
00590   iSetup.get<TrackerDigiGeometryRecord>().get(pDD);
00591   
00592   if( !pDD.isValid() ) {
00593     cout << "Unable to find TrackerDigiGeometry. Return\n";
00594     return;
00595   }
00596  
00597   int kk = -1;
00598   //----------------------------------------------------------------------------
00599   // Residuals:
00600   //
00601   for( reco::TrackCollection::const_iterator iTrack = TracksForRes->begin();
00602        iTrack != TracksForRes->end(); ++iTrack ) {
00603     //count
00604     kk++;
00605     //Calculate minimal track pt before curling
00606     // cpt = cqRB = 0.3*R[m]*B[T] = 1.14*R[m] for B=3.8T
00607     // D = 2R = 2*pt/1.14
00608     // calo: D = 1.3 m => pt = 0.74 GeV/c
00609     double pt = iTrack->pt();
00610     if( pt < 0.75 ) continue;// curls up
00611     if( abs( iTrack->dxy(vtxP) ) > 5*iTrack->dxyError() ) continue; // not prompt
00612     
00613     double charge = iTrack->charge();
00614        
00615     reco::TransientTrack tTrack = theB->build(*iTrack);
00616     //get curvature of the track, needed for the residuals
00617     double kap = tTrack.initialFreeState().transverseCurvature();
00618     //needed for the TransienTrackingRecHitBuilder
00619     TrajectoryStateOnSurface initialTSOS = tTrack.innermostMeasurementState();
00620     if( iTrack->extra().isNonnull() &&iTrack->extra().isAvailable() ){
00621       
00622       double x1 = 0;
00623       double y1 = 0;
00624       double z1 = 0;
00625       double x2 = 0;
00626       double y2 = 0;
00627       double z2 = 0;
00628       double x3 = 0;
00629       double y3 = 0;
00630       double z3 = 0;
00631       int n1 = 0;
00632       int n2 = 0;
00633       int n3 = 0;
00634       
00635       //for saving the pixel barrel hits
00636       vector<TransientTrackingRecHit::RecHitPointer> GoodPixBarrelHits;
00637       //looping through the RecHits of the track
00638       for( trackingRecHit_iterator irecHit = iTrack->recHitsBegin();
00639            irecHit != iTrack->recHitsEnd(); ++irecHit){
00640         
00641         if( (*irecHit)->isValid() ){
00642           DetId detId = (*irecHit)->geographicalId();
00643           // enum Detector { Tracker=1, Muon=2, Ecal=3, Hcal=4, Calo=5 };
00644           if( detId.det() != 1 ){
00645             if(debug_){
00646               cout << "rec hit ID = " << detId.det() << " not in tracker!?!?\n";
00647             }
00648             continue;
00649           }
00650           uint32_t subDet = detId.subdetId();
00651           
00652           // enum SubDetector{ PixelBarrel=1, PixelEndcap=2 };
00653           // enum SubDetector{ TIB=3, TID=4, TOB=5, TEC=6 };
00654           
00655           TransientTrackingRecHit::RecHitPointer trecHit = theTrackerRecHitBuilder->build(  &*(*irecHit), initialTSOS);
00656           
00657           
00658           double gX = trecHit->globalPosition().x();
00659           double gY = trecHit->globalPosition().y();
00660           double gZ = trecHit->globalPosition().z();
00661               
00662               
00663               if( subDet == PixelSubdetector::PixelBarrel ) {
00664 
00665                 int ilay = PXBDetId(detId).layer();
00666                 
00667                 if( ilay == 1 ){
00668                   n1++;
00669                   x1 = gX;
00670                   y1 = gY;
00671                   z1 = gZ;
00672                   
00673                   GoodPixBarrelHits.push_back((trecHit));
00674                 }//PXB1
00675                 if( ilay == 2 ){
00676                   
00677                   n2++;
00678                   x2 = gX;
00679                   y2 = gY;
00680                   z2 = gZ;
00681                   
00682                   GoodPixBarrelHits.push_back((trecHit));
00683                   
00684                 }//PXB2
00685                 if( ilay == 3 ){
00686                   
00687                   n3++;
00688                   x3 = gX;
00689                   y3 = gY;
00690                   z3 = gZ;
00691                   GoodPixBarrelHits.push_back((trecHit));
00692                 }
00693               }//PXB
00694               
00695               
00696             }//valid
00697           }//loop rechits
00698           
00699           //CS extra plots    
00700           
00701                   
00702           if( n1+n2+n3 == 3 && n1*n2*n3 > 0) {      
00703             for( unsigned int i = 0; i < GoodPixBarrelHits.size(); i++){
00704               
00705               if( GoodPixBarrelHits[i]->isValid() ){
00706                 DetId detId = GoodPixBarrelHits[i]->geographicalId().rawId();
00707                 int ilay = PXBDetId(detId).layer();
00708                 if(pt > ptminres_){   
00709                   
00710                   double dca2 = 0.0, dz2=0.0;
00711                   double ptsig = pt;
00712                   if(charge<0.) ptsig = -pt;
00713                   //Filling the histograms in modules
00714                   
00715                   MeasurementPoint Test;
00716                   MeasurementPoint Test2;
00717                   Test=MeasurementPoint(0,0);
00718                   Test2=MeasurementPoint(0,0);
00719                   Measurement2DVector residual;
00720                  
00721                   if( ilay == 1 ){
00722                     
00723                     triplets(x2,y2,z2,x1,y1,z1,x3,y3,z3,ptsig,dca2,dz2, kap);   
00724                                 
00725                     Test=MeasurementPoint(dca2*1E4,dz2*1E4);
00726                     residual=Test-Test2;
00727                   }
00728                   
00729                   if( ilay == 2 ){
00730                     
00731                     triplets(x1,y1,z1,x2,y2,z2,x3,y3,z3,ptsig,dca2,dz2, kap);
00732                     
00733                     Test=MeasurementPoint(dca2*1E4,dz2*1E4);
00734                     residual=Test-Test2;
00735               
00736                   }
00737                   
00738                   if( ilay == 3 ){
00739                     
00740                     triplets(x1,y1,z1,x3,y3,z3,x2,y2,z2,ptsig,dca2,dz2, kap);
00741                     
00742                     Test=MeasurementPoint(dca2*1E4,dz2*1E4);
00743                     residual=Test-Test2;
00744             }
00745                   // fill the residual histograms 
00746 
00747                   std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find(detId);
00748                   if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill(residual, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);           
00749                 }//three hits
00750               }//is valid
00751             }//rechits loop
00752           }//pt 4
00753         }
00754         
00755         
00756  }//-----Tracks
00758   //get trajectories
00759   edm::Handle<std::vector<Trajectory> > trajCollectionHandle;
00760   iEvent.getByLabel(tracksrc_,trajCollectionHandle);
00761   const std::vector<Trajectory> trajColl = *(trajCollectionHandle.product());
00762    
00763   //get tracks
00764   edm::Handle<std::vector<reco::Track> > trackCollectionHandle;
00765   iEvent.getByLabel(tracksrc_,trackCollectionHandle);
00766   const std::vector<reco::Track> trackColl = *(trackCollectionHandle.product());
00767 
00768   //get the map
00769   edm::Handle<TrajTrackAssociationCollection> match;
00770   iEvent.getByLabel(tracksrc_,match);
00771   const TrajTrackAssociationCollection ttac = *(match.product());
00772 
00773   // get clusters
00774   edm::Handle< edmNew::DetSetVector<SiPixelCluster> >  clusterColl;
00775   iEvent.getByLabel( clustersrc_, clusterColl );
00776   const edmNew::DetSetVector<SiPixelCluster> clustColl = *(clusterColl.product());
00777 
00778   if(debug_){
00779     std::cout << "Trajectories\t : " << trajColl.size() << std::endl;
00780     std::cout << "recoTracks  \t : " << trackColl.size() << std::endl;
00781     std::cout << "Map entries \t : " << ttac.size() << std::endl;
00782   }
00783 
00784   std::set<SiPixelCluster> clusterSet;
00785   TrajectoryStateCombiner tsoscomb;
00786   int tracks=0, pixeltracks=0, bpixtracks=0, fpixtracks=0; 
00787   int trackclusters=0, barreltrackclusters=0, endcaptrackclusters=0;
00788   int otherclusters=0, barrelotherclusters=0, endcapotherclusters=0;
00789 
00790   //Loop over map entries
00791   for(TrajTrackAssociationCollection::const_iterator it =  ttac.begin();it !=  ttac.end(); ++it){
00792     const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;  
00793     // Trajectory Map, extract Trajectory for this track
00794     reco::TrackRef trackref = it->val;
00795     tracks++;
00796 
00797     bool isBpixtrack = false, isFpixtrack = false, crossesPixVol=false;
00798     
00799     //find out whether track crosses pixel fiducial volume (for cosmic tracks)
00800     
00801     double d0 = (*trackref).d0(), dz = (*trackref).dz(); 
00802     
00803     if(abs(d0)<15 && abs(dz)<50) crossesPixVol = true;
00804 
00805     std::vector<TrajectoryMeasurement> tmeasColl =traj_iterator->measurements();
00806     std::vector<TrajectoryMeasurement>::const_iterator tmeasIt;
00807     //loop on measurements to find out whether there are bpix and/or fpix hits
00808     for(tmeasIt = tmeasColl.begin();tmeasIt!=tmeasColl.end();tmeasIt++){
00809       if(! tmeasIt->updatedState().isValid()) continue; 
00810       TransientTrackingRecHit::ConstRecHitPointer testhit = tmeasIt->recHit();
00811       if(! testhit->isValid() || testhit->geographicalId().det() != DetId::Tracker) continue; 
00812       uint testSubDetID = (testhit->geographicalId().subdetId()); 
00813       if(testSubDetID==PixelSubdetector::PixelBarrel) isBpixtrack = true;
00814       if(testSubDetID==PixelSubdetector::PixelEndcap) isFpixtrack = true;
00815     }//end loop on measurements
00816     if(isBpixtrack) {
00817       bpixtracks++; 
00818       if(debug_) std::cout << "bpixtrack\n";
00819     }
00820     if(isFpixtrack) {
00821       fpixtracks++; 
00822       if(debug_) std::cout << "fpixtrack\n";
00823     }
00824     if(isBpixtrack || isFpixtrack){
00825       pixeltracks++;
00826       
00827       if(crossesPixVol) meNofTracksInPixVol_->Fill(0,1);
00828 
00829       std::vector<TrajectoryMeasurement> tmeasColl = traj_iterator->measurements();
00830       for(std::vector<TrajectoryMeasurement>::const_iterator tmeasIt = tmeasColl.begin(); tmeasIt!=tmeasColl.end(); tmeasIt++){   
00831         if(! tmeasIt->updatedState().isValid()) continue; 
00832         
00833         TrajectoryStateOnSurface tsos = tsoscomb( tmeasIt->forwardPredictedState(), tmeasIt->backwardPredictedState() );
00834         TransientTrackingRecHit::ConstRecHitPointer hit = tmeasIt->recHit();
00835         if(! hit->isValid() || hit->geographicalId().det() != DetId::Tracker ) {
00836           continue; 
00837         } else {
00838           
00839 //        //residual
00840           const DetId & hit_detId = hit->geographicalId();
00841           //uint IntRawDetID = (hit_detId.rawId());
00842           uint IntSubDetID = (hit_detId.subdetId());
00843           
00844           if(IntSubDetID == 0 ) continue; // don't look at SiStrip hits!            
00845 
00846           // get the enclosed persistent hit
00847           const TrackingRecHit *persistentHit = hit->hit();
00848           // check if it's not null, and if it's a valid pixel hit
00849           if ((persistentHit != 0) && (typeid(*persistentHit) == typeid(SiPixelRecHit))) {
00850             // tell the C++ compiler that the hit is a pixel hit
00851             const SiPixelRecHit* pixhit = static_cast<const SiPixelRecHit*>( hit->hit() );
00852             //Hit probability:
00853             float hit_prob = -1.;
00854             if(pixhit->hasFilledProb()){
00855               hit_prob = pixhit->clusterProbability(0);
00856               //std::cout<<"HITPROB= "<<hit_prob<<std::endl;
00857               if(hit_prob<pow(10.,-15.)) NLowProb++;
00858               NTotal++;
00859               if(NTotal>0) meHitProbability->Fill(float(NLowProb/NTotal));
00860             }
00861             
00862             // get the edm::Ref to the cluster
00863             edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
00864             //  check if the ref is not null
00865             if (clust.isNonnull()) {
00866 
00867               //define tracker and pixel geometry and topology
00868               const TrackerGeometry& theTracker(*theTrackerGeometry);
00869               const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(hit_detId) );
00870               //test if PixelGeomDetUnit exists
00871               if(theGeomDet == 0) {
00872                 if(debug_) std::cout << "NO THEGEOMDET\n";
00873                 continue;
00874               }
00875 
00876               const PixelTopology * topol = &(theGeomDet->specificTopology());
00877               //fill histograms for clusters on tracks
00878               //correct SiPixelTrackResidualModule
00879               std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*hit).geographicalId().rawId());
00880 
00881               //CHARGE CORRECTION (for track impact angle)
00882               // calculate alpha and beta from cluster position
00883               LocalTrajectoryParameters ltp = tsos.localParameters();
00884               LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
00885               
00886               float clust_alpha = atan2(localDir.z(), localDir.x());
00887               float clust_beta = atan2(localDir.z(), localDir.y());
00888               double corrCharge = clust->charge() * sqrt( 1.0 / ( 1.0/pow( tan(clust_alpha), 2 ) + 
00889                                                                   1.0/pow( tan(clust_beta ), 2 ) + 
00890                                                                   1.0 )
00891                                                           )/1000.;
00892 
00893               if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*clust), true, corrCharge, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);     
00894 
00895 
00896               trackclusters++;
00897               //CORR CHARGE
00898               meClChargeOnTrack_all->Fill(corrCharge);
00899               meClSizeOnTrack_all->Fill((*clust).size());
00900               meClSizeXOnTrack_all->Fill((*clust).sizeX());
00901               meClSizeYOnTrack_all->Fill((*clust).sizeY());
00902               clusterSet.insert(*clust);
00903 
00904               //find cluster global position (rphi, z)
00905               // get cluster center of gravity (of charge)
00906               float xcenter = clust->x();
00907               float ycenter = clust->y();
00908               // get the cluster position in local coordinates (cm) 
00909               LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
00910               // get the cluster position in global coordinates (cm)
00911               GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
00912 
00913               //find location of hit (barrel or endcap, same for cluster)
00914               bool barrel = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
00915               bool endcap = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
00916               if(barrel) {
00917                 barreltrackclusters++;
00918                 //CORR CHARGE
00919                 meClChargeOnTrack_bpix->Fill(corrCharge);
00920                 meClSizeOnTrack_bpix->Fill((*clust).size());
00921                 meClSizeXOnTrack_bpix->Fill((*clust).sizeX());
00922                 meClSizeYOnTrack_bpix->Fill((*clust).sizeY());
00923                 uint32_t DBlayer = PixelBarrelName(DetId((*hit).geographicalId())).layerName();
00924                 float phi = clustgp.phi(); 
00925                 float z = clustgp.z();
00926                 switch(DBlayer){
00927                 case 1: {
00928                   meClPosLayer1OnTrack->Fill(z,phi); 
00929                   meClChargeOnTrack_layer1->Fill(corrCharge);
00930                   meClSizeOnTrack_layer1->Fill((*clust).size());
00931                   meClSizeXOnTrack_layer1->Fill((*clust).sizeX());
00932                   meClSizeYOnTrack_layer1->Fill((*clust).sizeY());
00933                   break;
00934                 }
00935                 case 2: {
00936                   meClPosLayer2OnTrack->Fill(z,phi); 
00937                   meClChargeOnTrack_layer2->Fill(corrCharge);
00938                   meClSizeOnTrack_layer2->Fill((*clust).size());
00939                   meClSizeXOnTrack_layer2->Fill((*clust).sizeX());
00940                   meClSizeYOnTrack_layer2->Fill((*clust).sizeY());
00941                   break;
00942                 }
00943                 case 3: {
00944                   meClPosLayer3OnTrack->Fill(z,phi); 
00945                   meClChargeOnTrack_layer3->Fill(corrCharge);
00946                   meClSizeOnTrack_layer3->Fill((*clust).size());
00947                   meClSizeXOnTrack_layer3->Fill((*clust).sizeX());
00948                   meClSizeYOnTrack_layer3->Fill((*clust).sizeY());
00949                   break;
00950                 }
00951                 
00952                 }
00953                 
00954               }
00955               if(endcap) {
00956                 endcaptrackclusters++;
00957                 //CORR CHARGE
00958                 meClChargeOnTrack_fpix->Fill(corrCharge);
00959                 meClSizeOnTrack_fpix->Fill((*clust).size());
00960                 meClSizeXOnTrack_fpix->Fill((*clust).sizeX());
00961                 meClSizeYOnTrack_fpix->Fill((*clust).sizeY());
00962                 uint32_t DBdisk = PixelEndcapName(DetId((*hit).geographicalId())).diskName();
00963                 float x = clustgp.x(); 
00964                 float y = clustgp.y(); 
00965                 float z = clustgp.z();
00966                 if(z>0){
00967                   if(DBdisk==1) {
00968                     meClPosDisk1pzOnTrack->Fill(x,y);
00969                     meClChargeOnTrack_diskp1->Fill(corrCharge);
00970                     meClSizeOnTrack_diskp1->Fill((*clust).size());
00971                     meClSizeXOnTrack_diskp1->Fill((*clust).sizeX());
00972                     meClSizeYOnTrack_diskp1->Fill((*clust).sizeY());
00973                   }
00974                   if(DBdisk==2) {
00975                     meClPosDisk2pzOnTrack->Fill(x,y); 
00976                     meClChargeOnTrack_diskp2->Fill(corrCharge);
00977                     meClSizeOnTrack_diskp2->Fill((*clust).size());
00978                     meClSizeXOnTrack_diskp2->Fill((*clust).sizeX());
00979                     meClSizeYOnTrack_diskp2->Fill((*clust).sizeY());
00980                   }
00981                 }
00982                 else{
00983                   if(DBdisk==1) {
00984                     meClPosDisk1mzOnTrack->Fill(x,y);
00985                     meClChargeOnTrack_diskm1->Fill(corrCharge);
00986                     meClSizeOnTrack_diskm1->Fill((*clust).size());
00987                     meClSizeXOnTrack_diskm1->Fill((*clust).sizeX());
00988                     meClSizeYOnTrack_diskm1->Fill((*clust).sizeY());
00989                   }
00990                   if(DBdisk==2) {
00991                     meClPosDisk2mzOnTrack->Fill(x,y); 
00992                     meClChargeOnTrack_diskm2->Fill(corrCharge);
00993                     meClSizeOnTrack_diskm2->Fill((*clust).size());
00994                     meClSizeXOnTrack_diskm2->Fill((*clust).sizeX());
00995                     meClSizeYOnTrack_diskm2->Fill((*clust).sizeY());
00996                   }
00997                 } 
00998               }
00999               
01000             }//end if (cluster exists)
01001 
01002           }//end if (persistent hit exists and is pixel hit)
01003           
01004         }//end of else 
01005         
01006         
01007       }//end for (all traj measurements of pixeltrack)
01008     }//end if (is pixeltrack)
01009     else {
01010       if(debug_) std::cout << "no pixeltrack:\n";
01011       if(crossesPixVol) meNofTracksInPixVol_->Fill(1,1);
01012     }
01013     
01014   }//end loop on map entries
01015 
01016   //find clusters that are NOT on track
01017   //edmNew::DetSet<SiPixelCluster>::const_iterator  di;
01018   if(debug_) std::cout << "clusters not on track: (size " << clustColl.size() << ") ";
01019 
01020   for(TrackerGeometry::DetContainer::const_iterator it = TG->dets().begin(); it != TG->dets().end(); it++){
01021     //if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
01022     DetId detId = (*it)->geographicalId();
01023     if(detId>=302055684 && detId<=352477708){ // make sure it's a Pixel module WITHOUT using dynamic_cast!  
01024       int nofclOnTrack = 0, nofclOffTrack=0; 
01025       uint32_t DBlayer=10, DBdisk=10; 
01026       float z=0.; 
01027       //set layer/disk
01028       if(DetId(detId).subdetId() == 1) { // Barrel module
01029         DBlayer = PixelBarrelName(DetId(detId)).layerName();
01030       }
01031       if(DetId(detId).subdetId() == 2){ // Endcap module
01032         DBdisk = PixelEndcapName(DetId(detId )).diskName();
01033       }
01034       edmNew::DetSetVector<SiPixelCluster>::const_iterator isearch = clustColl.find(detId);
01035       if( isearch != clustColl.end() ) {  // Not an empty iterator
01036         edmNew::DetSet<SiPixelCluster>::const_iterator  di;
01037         for(di=isearch->begin(); di!=isearch->end(); di++){
01038           unsigned int temp = clusterSet.size();
01039           clusterSet.insert(*di);
01040           //check if cluster is off track
01041           if(clusterSet.size()>temp) {
01042             otherclusters++;
01043             nofclOffTrack++; 
01044             //fill histograms for clusters off tracks
01045             //correct SiPixelTrackResidualModule
01046             std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
01047 
01048             if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*di), false, -1., reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn); 
01049             
01050 
01051 
01052             meClSizeNotOnTrack_all->Fill((*di).size());
01053             meClSizeXNotOnTrack_all->Fill((*di).sizeX());
01054             meClSizeYNotOnTrack_all->Fill((*di).sizeY());
01055             meClChargeNotOnTrack_all->Fill((*di).charge()/1000);
01056 
01058             //find cluster global position (rphi, z) get cluster
01059             //define tracker and pixel geometry and topology
01060             const TrackerGeometry& theTracker(*theTrackerGeometry);
01061             const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
01062             //test if PixelGeomDetUnit exists
01063             if(theGeomDet == 0) {
01064               if(debug_) std::cout << "NO THEGEOMDET\n";
01065               continue;
01066             }
01067             const PixelTopology * topol = &(theGeomDet->specificTopology());
01068            
01069             //center of gravity (of charge)
01070             float xcenter = di->x();
01071             float ycenter = di->y();
01072             // get the cluster position in local coordinates (cm) 
01073             LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
01074             // get the cluster position in global coordinates (cm)
01075             GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
01076 
01078 
01079             //barrel
01080             if(DetId(detId).subdetId() == 1) {
01081               meClSizeNotOnTrack_bpix->Fill((*di).size());
01082               meClSizeXNotOnTrack_bpix->Fill((*di).sizeX());
01083               meClSizeYNotOnTrack_bpix->Fill((*di).sizeY());
01084               meClChargeNotOnTrack_bpix->Fill((*di).charge()/1000);
01085               barrelotherclusters++;
01086               //DBlayer = PixelBarrelName(DetId(detId)).layerName();
01087               float phi = clustgp.phi(); 
01088               //float r = clustgp.perp();
01089               z = clustgp.z();
01090               switch(DBlayer){
01091               case 1: {
01092                 meClPosLayer1NotOnTrack->Fill(z,phi); 
01093                 meClSizeNotOnTrack_layer1->Fill((*di).size());
01094                 meClSizeXNotOnTrack_layer1->Fill((*di).sizeX());
01095                 meClSizeYNotOnTrack_layer1->Fill((*di).sizeY());
01096                 meClChargeNotOnTrack_layer1->Fill((*di).charge()/1000);
01097                 break;
01098               }
01099               case 2: {
01100                 meClPosLayer2NotOnTrack->Fill(z,phi);
01101                 meClSizeNotOnTrack_layer2->Fill((*di).size());
01102                 meClSizeXNotOnTrack_layer2->Fill((*di).sizeX());
01103                 meClSizeYNotOnTrack_layer2->Fill((*di).sizeY());
01104                 meClChargeNotOnTrack_layer2->Fill((*di).charge()/1000);
01105                 break;
01106               }
01107               case 3: {
01108                 meClPosLayer3NotOnTrack->Fill(z,phi); 
01109                 meClSizeNotOnTrack_layer3->Fill((*di).size());
01110                 meClSizeXNotOnTrack_layer3->Fill((*di).sizeX());
01111                 meClSizeYNotOnTrack_layer3->Fill((*di).sizeY());
01112                 meClChargeNotOnTrack_layer3->Fill((*di).charge()/1000);
01113                 break;
01114               }
01115                 
01116               }
01117             }
01118             //endcap
01119             if(DetId(detId).subdetId() == 2) {
01120               meClSizeNotOnTrack_fpix->Fill((*di).size());
01121               meClSizeXNotOnTrack_fpix->Fill((*di).sizeX());
01122               meClSizeYNotOnTrack_fpix->Fill((*di).sizeY());
01123               meClChargeNotOnTrack_fpix->Fill((*di).charge()/1000);
01124               endcapotherclusters++;
01125               //DBdisk = PixelEndcapName(DetId(detId )).diskName();
01126               float x = clustgp.x(); 
01127               float y = clustgp.y(); 
01128               z = clustgp.z();
01129               if(z>0){
01130                 if(DBdisk==1) {
01131                   meClPosDisk1pzNotOnTrack->Fill(x,y);
01132                   meClSizeNotOnTrack_diskp1->Fill((*di).size());
01133                   meClSizeXNotOnTrack_diskp1->Fill((*di).sizeX());
01134                   meClSizeYNotOnTrack_diskp1->Fill((*di).sizeY());
01135                   meClChargeNotOnTrack_diskp1->Fill((*di).charge()/1000);
01136                 }
01137                 if(DBdisk==2) {
01138                   meClPosDisk2pzNotOnTrack->Fill(x,y); 
01139                   meClSizeNotOnTrack_diskp2->Fill((*di).size());
01140                   meClSizeXNotOnTrack_diskp2->Fill((*di).sizeX());
01141                   meClSizeYNotOnTrack_diskp2->Fill((*di).sizeY());
01142                   meClChargeNotOnTrack_diskp2->Fill((*di).charge()/1000);
01143                 }
01144               }
01145               else{
01146                 if(DBdisk==1) {
01147                   meClPosDisk1mzNotOnTrack->Fill(x,y);
01148                   meClSizeNotOnTrack_diskm1->Fill((*di).size());
01149                   meClSizeXNotOnTrack_diskm1->Fill((*di).sizeX());
01150                   meClSizeYNotOnTrack_diskm1->Fill((*di).sizeY());
01151                   meClChargeNotOnTrack_diskm1->Fill((*di).charge()/1000);
01152                 }
01153                 if(DBdisk==2) {
01154                   meClPosDisk2mzNotOnTrack->Fill(x,y); 
01155                   meClSizeNotOnTrack_diskm2->Fill((*di).size());
01156                   meClSizeXNotOnTrack_diskm2->Fill((*di).sizeX());
01157                   meClSizeYNotOnTrack_diskm2->Fill((*di).sizeY());
01158                   meClChargeNotOnTrack_diskm2->Fill((*di).charge()/1000);
01159                 }
01160               } 
01161 
01162             }
01163           }// end "if cluster off track"
01164           else {
01165             nofclOnTrack++; 
01166             if(z == 0 && DBdisk != 10){
01167               //find cluster global position (rphi, z) get cluster
01168               //define tracker and pixel geometry and topology
01169               const TrackerGeometry& theTracker(*theTrackerGeometry);
01170               const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
01171               //test if PixelGeomDetUnit exists
01172               if(theGeomDet == 0) {
01173                 if(debug_) std::cout << "NO THEGEOMDET\n";
01174                 continue;
01175               }
01176               const PixelTopology * topol = &(theGeomDet->specificTopology());
01177               //center of gravity (of charge)
01178               float xcenter = di->x();
01179               float ycenter = di->y();
01180               // get the cluster position in local coordinates (cm) 
01181               LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
01182               // get the cluster position in global coordinates (cm)
01183               GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );  
01184               z = clustgp.z();
01185             }
01186           }
01187         }
01188       }
01189       //++ fill the number of clusters on a module
01190       std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
01191       if (pxd!=theSiPixelStructure.end()) (*pxd).second->nfill(nofclOnTrack, nofclOffTrack, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn); 
01192       if(nofclOnTrack!=0) meNClustersOnTrack_all->Fill(nofclOnTrack); 
01193       if(nofclOffTrack!=0) meNClustersNotOnTrack_all->Fill(nofclOffTrack); 
01194       //barrel
01195       if(DetId(detId).subdetId() == 1){
01196         if(nofclOnTrack!=0) meNClustersOnTrack_bpix->Fill(nofclOnTrack); 
01197         if(nofclOffTrack!=0) meNClustersNotOnTrack_bpix->Fill(nofclOffTrack); 
01198         //DBlayer = PixelBarrelName(DetId(detId)).layerName();
01199         switch(DBlayer){
01200         case 1: { 
01201           if(nofclOnTrack!=0) meNClustersOnTrack_layer1->Fill(nofclOnTrack);
01202           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer1->Fill(nofclOffTrack); break;
01203         }
01204         case 2: {
01205           if(nofclOnTrack!=0) meNClustersOnTrack_layer2->Fill(nofclOnTrack);
01206           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer2->Fill(nofclOffTrack); break; 
01207         }
01208         case 3: {
01209           if(nofclOnTrack!=0) meNClustersOnTrack_layer3->Fill(nofclOnTrack); 
01210           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer3->Fill(nofclOffTrack); break; 
01211         }
01212         }
01213       }//end barrel
01214       //endcap
01215       if(DetId(detId).subdetId() == 2) {
01216         //DBdisk = PixelEndcapName(DetId(detId )).diskName();
01217         //z = clustgp.z();
01218         if(nofclOnTrack!=0) meNClustersOnTrack_fpix->Fill(nofclOnTrack); 
01219         if(nofclOffTrack!=0) meNClustersNotOnTrack_fpix->Fill(nofclOffTrack);
01220         if(z>0){
01221           if(DBdisk==1) {
01222             if(nofclOnTrack!=0) meNClustersOnTrack_diskp1->Fill(nofclOnTrack); 
01223             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp1->Fill(nofclOffTrack);
01224           }
01225           if(DBdisk==2) {
01226             if(nofclOnTrack!=0) meNClustersOnTrack_diskp2->Fill(nofclOnTrack); 
01227             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp2->Fill(nofclOffTrack);
01228           }
01229         }
01230         if(z<0){
01231           if(DBdisk==1) {
01232             if(nofclOnTrack!=0) meNClustersOnTrack_diskm1->Fill(nofclOnTrack); 
01233             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm1->Fill(nofclOffTrack);
01234           }
01235           if(DBdisk==2) {
01236             if(nofclOnTrack!=0) meNClustersOnTrack_diskm2->Fill(nofclOnTrack); 
01237             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm2->Fill(nofclOffTrack);
01238           }
01239         }
01240       }
01241 
01242     }//end if it's a Pixel module
01243   }//end for loop over tracker detector geometry modules
01244 
01245 
01246   if(trackclusters>0) (meNofClustersOnTrack_)->Fill(0,trackclusters);
01247   if(barreltrackclusters>0)(meNofClustersOnTrack_)->Fill(1,barreltrackclusters);
01248   if(endcaptrackclusters>0)(meNofClustersOnTrack_)->Fill(2,endcaptrackclusters);
01249   if(otherclusters>0)(meNofClustersNotOnTrack_)->Fill(0,otherclusters);
01250   if(barrelotherclusters>0)(meNofClustersNotOnTrack_)->Fill(1,barrelotherclusters);
01251   if(endcapotherclusters>0)(meNofClustersNotOnTrack_)->Fill(2,endcapotherclusters);
01252   if(tracks>0)(meNofTracks_)->Fill(0,tracks);
01253   if(pixeltracks>0)(meNofTracks_)->Fill(1,pixeltracks);
01254   if(bpixtracks>0)(meNofTracks_)->Fill(2,bpixtracks);
01255   if(fpixtracks>0)(meNofTracks_)->Fill(3,fpixtracks);
01256 }
01257 void SiPixelTrackResidualSource::triplets(double x1,double y1,double z1,double x2,double y2,double z2,double x3,double y3,double z3,
01258                                           double ptsig, double & dca2,double & dz2, double kap) {
01259   
01260   //Define some constants
01261   using namespace std;
01262 
01263   //Curvature kap from global Track
01264 
01265  //inverse of the curvature is the radius in the transverse plane
01266   double rho = 1/kap;
01267   //Check that the hits are in the correct layers
01268   double r1 = sqrt( x1*x1 + y1*y1 );
01269   double r3 = sqrt( x3*x3 + y3*y3 );
01270 
01271   if( r3-r1 < 2.0 ) cout << "warn r1 = " << r1 << ", r3 = " << r3 << endl;
01272   
01273   // Calculate the centre of the helix in xy-projection with radius rho from the track.
01274   //start with a line (sekante) connecting the two points (x1,y1) and (x3,y3) vec_L = vec_x3-vec_x1
01275   //with L being the length of that vector.
01276   double L=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
01277   //lam is the line from the middel point of vec_q towards the center of the circle X0,Y0
01278   // we already have kap and rho = 1/kap
01279   double lam = sqrt(rho*rho - L*L/4);
01280   
01281   // There are two solutions, the sign of kap gives the information
01282   // which of them is correct.
01283   //
01284   if( kap > 0 ) lam = -lam;
01285 
01286   //
01287   // ( X0, Y0 ) is the centre of the circle that describes the helix in xy-projection.
01288   //
01289   double x0 =  0.5*( x1 + x3 ) + lam/L * ( -y1 + y3 );
01290   double y0 =  0.5*( y1 + y3 ) + lam/L * (  x1 - x3 );
01291 
01292   // Calculate the dipangle in z direction (needed later for z residual) :
01293   //Starting from the heliz equation whihc has to hold for both points z1,z3
01294   double num = ( y3 - y0 ) * ( x1 - x0 ) - ( x3 - x0 ) * ( y1 - y0 );
01295   double den = ( x1 - x0 ) * ( x3 - x0 ) + ( y1 - y0 ) * ( y3 - y0 );
01296   double tandip = kap * ( z3 - z1 ) / atan( num / den );
01297 
01298  
01299   // angle from first hit to dca point:
01300   //
01301   double dphi = atan( ( ( x1 - x0 ) * y0 - ( y1 - y0 ) * x0 )
01302                       / ( ( x1 - x0 ) * x0 + ( y1 - y0 ) * y0 ) );
01303   //z position of the track based on the middle of the circle
01304   //track equation for the z component
01305   double uz0 = z1 + tandip * dphi * rho;
01306 
01308   //RESIDUAL IN R-PHI
01310   //Calculate distance dca2 from point (x2,y2) to the circle which is given by
01311   //the distance of the point to the middlepoint dcM = sqrt((x0-x2)^2+(y0-y2)) and rho
01312   //dca = rho +- dcM
01313   if(kap>0) dca2=rho-sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2));
01314   else dca2=rho+sqrt((-x0+x2)*(-x0+x2)+(-y0+y2)*(-y0+y2));
01315 
01317   //RESIDUAL IN Z
01319   double xx =0 ;
01320   double yy =0 ;
01321   //sign of kappa determines the calculation
01322   //xx and yy are the new coordinates starting from x2, y2 that are on the track itself
01323   //vec_X2+-dca2*vec(X0-X2)/|(X0-X2)|
01324   if(kap<0){
01325     xx =   x2+(dca2*((x0-x2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
01326     yy = y2+(dca2*((y0-y2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
01327   }
01328   else if(kap>=0){
01329     xx =   x2-(dca2*((x0-x2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
01330     yy = y2-(dca2*((y0-y2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
01331   }
01332 
01333   //to get residual in z start with calculating the new uz2 position if one has moved to xx, yy
01334   //on the track. First calculate the change in phi2 with respect to the center X0, Y0
01335   double dphi2 = atan( ( ( xx - x0 ) * y0 - ( yy - y0 ) * x0 )
01336                        / ( ( xx - x0 ) * x0 + ( yy - y0 ) * y0 ) );
01337   //Solve track equation for this new z depending on the dip angle of the track (see above
01338   //calculated based on X1, X3 and X0, use uz0 as reference point again.
01339   double  uz2= uz0 - dphi2*tandip*rho;
01340   
01341   //subtract new z position from the old one
01342   dz2=z2-uz2;
01343   
01344   //if we are interested in the arclength this is unsigned though
01345   //  double cosphi2 = (x2*xx+y2*yy)/(sqrt(x2*x2+y2*y2)*sqrt(xx*xx+yy*yy));
01346   //double arcdca2=sqrt(x2*x2+y2*y2)*acos(cosphi2);
01347   
01348 }
01349 
01350 
01351 DEFINE_FWK_MODULE(SiPixelTrackResidualSource); // define this as a plug-in