CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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.27 2013/01/03 23:50:05 wmtan 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/TrackerCommon/interface/TrackerTopology.h"
00029 #include "Geometry/Records/interface/IdealGeometryRecord.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   //Retrieve tracker topology from geometry
00517   edm::ESHandle<TrackerTopology> tTopoHandle;
00518   iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
00519   const TrackerTopology* const tTopo = tTopoHandle.product();
00520 
00521 
00522   
00523   // retrieve TrackerGeometry again and MagneticField for use in transforming 
00524   // a TrackCandidate's P(ersistent)TrajectoryStateoOnDet (PTSoD) to a TrajectoryStateOnSurface (TSoS)
00525   ESHandle<TrackerGeometry> TG;
00526   iSetup.get<TrackerDigiGeometryRecord>().get(TG);
00527   const TrackerGeometry* theTrackerGeometry = TG.product();
00528   
00529   //analytic triplet method to calculate the track residuals in the pixe barrel detector    
00530   
00531   //--------------------------------------------------------------------
00532   // beam spot:
00533   //
00534   edm::Handle<reco::BeamSpot> rbs;
00535   iEvent.getByLabel( "offlineBeamSpot", rbs );
00536   math::XYZPoint bsP = math::XYZPoint(0,0,0);
00537   if( !rbs.failedToGet() && rbs.isValid() )
00538     {
00539       bsP = math::XYZPoint( rbs->x0(), rbs->y0(), rbs->z0() );
00540     }
00541   
00542   //--------------------------------------------------------------------
00543   // primary vertices:
00544   //
00545   edm::Handle<reco::VertexCollection> vertices;
00546   iEvent.getByLabel("offlinePrimaryVertices", vertices );
00547   
00548   if( vertices.failedToGet() ) return;
00549   if( !vertices.isValid() ) return;
00550   
00551   math::XYZPoint vtxN = math::XYZPoint(0,0,0);
00552   math::XYZPoint vtxP = math::XYZPoint(0,0,0);
00553   
00554   double bestNdof = 0;
00555   double maxSumPt = 0;
00556   reco::Vertex bestPvx;
00557   for(reco::VertexCollection::const_iterator iVertex = vertices->begin();
00558       iVertex != vertices->end(); ++iVertex ) {
00559     if( iVertex->ndof() > bestNdof ) {
00560       bestNdof = iVertex->ndof();
00561       vtxN = math::XYZPoint( iVertex->x(), iVertex->y(), iVertex->z() );
00562     }//ndof
00563     if( iVertex->p4().pt() > maxSumPt ) {
00564       maxSumPt = iVertex->p4().pt();
00565       vtxP = math::XYZPoint( iVertex->x(), iVertex->y(), iVertex->z() );
00566       bestPvx = *iVertex;
00567     }//sumpt
00568     
00569   }//vertex
00570   
00571   if( maxSumPt < 1 ) return;
00572   
00573   if( maxSumPt < 1 ) vtxP = vtxN;
00574   
00575   //---------------------------------------------
00576   //get Tracks
00577   //
00578   edm:: Handle<reco::TrackCollection> TracksForRes;
00579   iEvent.getByLabel( "generalTracks", TracksForRes );
00580   //
00581   // transient track builder, needs B-field from data base (global tag in .py)
00582   //
00583   edm::ESHandle<TransientTrackBuilder> theB;
00584   iSetup.get<TransientTrackRecord>().get( "TransientTrackBuilder", theB );
00585 
00586   //get the TransienTrackingRecHitBuilder needed for extracting the global position of the hits in the pixel
00587   edm::ESHandle<TransientTrackingRecHitBuilder> theTrackerRecHitBuilder;
00588   iSetup.get<TransientRecHitRecord>().get(ttrhbuilder_,theTrackerRecHitBuilder);
00589 
00590   //check that tracks are valid
00591   if( TracksForRes.failedToGet() ) return;
00592   if( !TracksForRes.isValid() ) return;
00593 
00594   //get tracker geometry
00595   edm::ESHandle<TrackerGeometry> pDD;
00596   iSetup.get<TrackerDigiGeometryRecord>().get(pDD);
00597   
00598   if( !pDD.isValid() ) {
00599     cout << "Unable to find TrackerDigiGeometry. Return\n";
00600     return;
00601   }
00602  
00603   int kk = -1;
00604   //----------------------------------------------------------------------------
00605   // Residuals:
00606   //
00607   for( reco::TrackCollection::const_iterator iTrack = TracksForRes->begin();
00608        iTrack != TracksForRes->end(); ++iTrack ) {
00609     //count
00610     kk++;
00611     //Calculate minimal track pt before curling
00612     // cpt = cqRB = 0.3*R[m]*B[T] = 1.14*R[m] for B=3.8T
00613     // D = 2R = 2*pt/1.14
00614     // calo: D = 1.3 m => pt = 0.74 GeV/c
00615     double pt = iTrack->pt();
00616     if( pt < 0.75 ) continue;// curls up
00617     if( abs( iTrack->dxy(vtxP) ) > 5*iTrack->dxyError() ) continue; // not prompt
00618     
00619     double charge = iTrack->charge();
00620        
00621     reco::TransientTrack tTrack = theB->build(*iTrack);
00622     //get curvature of the track, needed for the residuals
00623     double kap = tTrack.initialFreeState().transverseCurvature();
00624     //needed for the TransienTrackingRecHitBuilder
00625     TrajectoryStateOnSurface initialTSOS = tTrack.innermostMeasurementState();
00626     if( iTrack->extra().isNonnull() &&iTrack->extra().isAvailable() ){
00627       
00628       double x1 = 0;
00629       double y1 = 0;
00630       double z1 = 0;
00631       double x2 = 0;
00632       double y2 = 0;
00633       double z2 = 0;
00634       double x3 = 0;
00635       double y3 = 0;
00636       double z3 = 0;
00637       int n1 = 0;
00638       int n2 = 0;
00639       int n3 = 0;
00640       
00641       //for saving the pixel barrel hits
00642       vector<TransientTrackingRecHit::RecHitPointer> GoodPixBarrelHits;
00643       //looping through the RecHits of the track
00644       for( trackingRecHit_iterator irecHit = iTrack->recHitsBegin();
00645            irecHit != iTrack->recHitsEnd(); ++irecHit){
00646         
00647         if( (*irecHit)->isValid() ){
00648           DetId detId = (*irecHit)->geographicalId();
00649           // enum Detector { Tracker=1, Muon=2, Ecal=3, Hcal=4, Calo=5 };
00650           if( detId.det() != 1 ){
00651             if(debug_){
00652               cout << "rec hit ID = " << detId.det() << " not in tracker!?!?\n";
00653             }
00654             continue;
00655           }
00656           uint32_t subDet = detId.subdetId();
00657           
00658           // enum SubDetector{ PixelBarrel=1, PixelEndcap=2 };
00659           // enum SubDetector{ TIB=3, TID=4, TOB=5, TEC=6 };
00660           
00661           TransientTrackingRecHit::RecHitPointer trecHit = theTrackerRecHitBuilder->build(  &*(*irecHit), initialTSOS);
00662           
00663           
00664           double gX = trecHit->globalPosition().x();
00665           double gY = trecHit->globalPosition().y();
00666           double gZ = trecHit->globalPosition().z();
00667               
00668               
00669               if( subDet == PixelSubdetector::PixelBarrel ) {
00670 
00671                 int ilay = tTopo->pxbLayer(detId);
00672                 
00673                 if( ilay == 1 ){
00674                   n1++;
00675                   x1 = gX;
00676                   y1 = gY;
00677                   z1 = gZ;
00678                   
00679                   GoodPixBarrelHits.push_back((trecHit));
00680                 }//PXB1
00681                 if( ilay == 2 ){
00682                   
00683                   n2++;
00684                   x2 = gX;
00685                   y2 = gY;
00686                   z2 = gZ;
00687                   
00688                   GoodPixBarrelHits.push_back((trecHit));
00689                   
00690                 }//PXB2
00691                 if( ilay == 3 ){
00692                   
00693                   n3++;
00694                   x3 = gX;
00695                   y3 = gY;
00696                   z3 = gZ;
00697                   GoodPixBarrelHits.push_back((trecHit));
00698                 }
00699               }//PXB
00700               
00701               
00702             }//valid
00703           }//loop rechits
00704           
00705           //CS extra plots    
00706           
00707                   
00708           if( n1+n2+n3 == 3 && n1*n2*n3 > 0) {      
00709             for( unsigned int i = 0; i < GoodPixBarrelHits.size(); i++){
00710               
00711               if( GoodPixBarrelHits[i]->isValid() ){
00712                 DetId detId = GoodPixBarrelHits[i]->geographicalId().rawId();
00713                 int ilay = tTopo->pxbLayer(detId);
00714                 if(pt > ptminres_){   
00715                   
00716                   double dca2 = 0.0, dz2=0.0;
00717                   double ptsig = pt;
00718                   if(charge<0.) ptsig = -pt;
00719                   //Filling the histograms in modules
00720                   
00721                   MeasurementPoint Test;
00722                   MeasurementPoint Test2;
00723                   Test=MeasurementPoint(0,0);
00724                   Test2=MeasurementPoint(0,0);
00725                   Measurement2DVector residual;
00726                  
00727                   if( ilay == 1 ){
00728                     
00729                     triplets(x2,y2,z2,x1,y1,z1,x3,y3,z3,ptsig,dca2,dz2, kap);   
00730                                 
00731                     Test=MeasurementPoint(dca2*1E4,dz2*1E4);
00732                     residual=Test-Test2;
00733                   }
00734                   
00735                   if( ilay == 2 ){
00736                     
00737                     triplets(x1,y1,z1,x2,y2,z2,x3,y3,z3,ptsig,dca2,dz2, kap);
00738                     
00739                     Test=MeasurementPoint(dca2*1E4,dz2*1E4);
00740                     residual=Test-Test2;
00741               
00742                   }
00743                   
00744                   if( ilay == 3 ){
00745                     
00746                     triplets(x1,y1,z1,x3,y3,z3,x2,y2,z2,ptsig,dca2,dz2, kap);
00747                     
00748                     Test=MeasurementPoint(dca2*1E4,dz2*1E4);
00749                     residual=Test-Test2;
00750             }
00751                   // fill the residual histograms 
00752 
00753                   std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find(detId);
00754                   if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill(residual, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);           
00755                 }//three hits
00756               }//is valid
00757             }//rechits loop
00758           }//pt 4
00759         }
00760         
00761         
00762  }//-----Tracks
00764   //get trajectories
00765   edm::Handle<std::vector<Trajectory> > trajCollectionHandle;
00766   iEvent.getByLabel(tracksrc_,trajCollectionHandle);
00767   const std::vector<Trajectory> trajColl = *(trajCollectionHandle.product());
00768    
00769   //get tracks
00770   edm::Handle<std::vector<reco::Track> > trackCollectionHandle;
00771   iEvent.getByLabel(tracksrc_,trackCollectionHandle);
00772   const std::vector<reco::Track> trackColl = *(trackCollectionHandle.product());
00773 
00774   //get the map
00775   edm::Handle<TrajTrackAssociationCollection> match;
00776   iEvent.getByLabel(tracksrc_,match);
00777   const TrajTrackAssociationCollection ttac = *(match.product());
00778 
00779   // get clusters
00780   edm::Handle< edmNew::DetSetVector<SiPixelCluster> >  clusterColl;
00781   iEvent.getByLabel( clustersrc_, clusterColl );
00782   const edmNew::DetSetVector<SiPixelCluster> clustColl = *(clusterColl.product());
00783 
00784   if(debug_){
00785     std::cout << "Trajectories\t : " << trajColl.size() << std::endl;
00786     std::cout << "recoTracks  \t : " << trackColl.size() << std::endl;
00787     std::cout << "Map entries \t : " << ttac.size() << std::endl;
00788   }
00789 
00790   std::set<SiPixelCluster> clusterSet;
00791   TrajectoryStateCombiner tsoscomb;
00792   int tracks=0, pixeltracks=0, bpixtracks=0, fpixtracks=0; 
00793   int trackclusters=0, barreltrackclusters=0, endcaptrackclusters=0;
00794   int otherclusters=0, barrelotherclusters=0, endcapotherclusters=0;
00795 
00796   //Loop over map entries
00797   for(TrajTrackAssociationCollection::const_iterator it =  ttac.begin();it !=  ttac.end(); ++it){
00798     const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;  
00799     // Trajectory Map, extract Trajectory for this track
00800     reco::TrackRef trackref = it->val;
00801     tracks++;
00802 
00803     bool isBpixtrack = false, isFpixtrack = false, crossesPixVol=false;
00804     
00805     //find out whether track crosses pixel fiducial volume (for cosmic tracks)
00806     
00807     double d0 = (*trackref).d0(), dz = (*trackref).dz(); 
00808     
00809     if(abs(d0)<15 && abs(dz)<50) crossesPixVol = true;
00810 
00811     std::vector<TrajectoryMeasurement> tmeasColl =traj_iterator->measurements();
00812     std::vector<TrajectoryMeasurement>::const_iterator tmeasIt;
00813     //loop on measurements to find out whether there are bpix and/or fpix hits
00814     for(tmeasIt = tmeasColl.begin();tmeasIt!=tmeasColl.end();tmeasIt++){
00815       if(! tmeasIt->updatedState().isValid()) continue; 
00816       TransientTrackingRecHit::ConstRecHitPointer testhit = tmeasIt->recHit();
00817       if(! testhit->isValid() || testhit->geographicalId().det() != DetId::Tracker) continue; 
00818       uint testSubDetID = (testhit->geographicalId().subdetId()); 
00819       if(testSubDetID==PixelSubdetector::PixelBarrel) isBpixtrack = true;
00820       if(testSubDetID==PixelSubdetector::PixelEndcap) isFpixtrack = true;
00821     }//end loop on measurements
00822     if(isBpixtrack) {
00823       bpixtracks++; 
00824       if(debug_) std::cout << "bpixtrack\n";
00825     }
00826     if(isFpixtrack) {
00827       fpixtracks++; 
00828       if(debug_) std::cout << "fpixtrack\n";
00829     }
00830     if(isBpixtrack || isFpixtrack){
00831       pixeltracks++;
00832       
00833       if(crossesPixVol) meNofTracksInPixVol_->Fill(0,1);
00834 
00835       std::vector<TrajectoryMeasurement> tmeasColl = traj_iterator->measurements();
00836       for(std::vector<TrajectoryMeasurement>::const_iterator tmeasIt = tmeasColl.begin(); tmeasIt!=tmeasColl.end(); tmeasIt++){   
00837         if(! tmeasIt->updatedState().isValid()) continue; 
00838         
00839         TrajectoryStateOnSurface tsos = tsoscomb( tmeasIt->forwardPredictedState(), tmeasIt->backwardPredictedState() );
00840         TransientTrackingRecHit::ConstRecHitPointer hit = tmeasIt->recHit();
00841         if(! hit->isValid() || hit->geographicalId().det() != DetId::Tracker ) {
00842           continue; 
00843         } else {
00844           
00845 //        //residual
00846           const DetId & hit_detId = hit->geographicalId();
00847           //uint IntRawDetID = (hit_detId.rawId());
00848           uint IntSubDetID = (hit_detId.subdetId());
00849           
00850           if(IntSubDetID == 0 ) continue; // don't look at SiStrip hits!            
00851 
00852           // get the enclosed persistent hit
00853           const TrackingRecHit *persistentHit = hit->hit();
00854           // check if it's not null, and if it's a valid pixel hit
00855           if ((persistentHit != 0) && (typeid(*persistentHit) == typeid(SiPixelRecHit))) {
00856             // tell the C++ compiler that the hit is a pixel hit
00857             const SiPixelRecHit* pixhit = static_cast<const SiPixelRecHit*>( hit->hit() );
00858             //Hit probability:
00859             float hit_prob = -1.;
00860             if(pixhit->hasFilledProb()){
00861               hit_prob = pixhit->clusterProbability(0);
00862               //std::cout<<"HITPROB= "<<hit_prob<<std::endl;
00863               if(hit_prob<pow(10.,-15.)) NLowProb++;
00864               NTotal++;
00865               if(NTotal>0) meHitProbability->Fill(float(NLowProb/NTotal));
00866             }
00867             
00868             // get the edm::Ref to the cluster
00869             edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
00870             //  check if the ref is not null
00871             if (clust.isNonnull()) {
00872 
00873               //define tracker and pixel geometry and topology
00874               const TrackerGeometry& theTracker(*theTrackerGeometry);
00875               const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(hit_detId) );
00876               //test if PixelGeomDetUnit exists
00877               if(theGeomDet == 0) {
00878                 if(debug_) std::cout << "NO THEGEOMDET\n";
00879                 continue;
00880               }
00881 
00882               const PixelTopology * topol = &(theGeomDet->specificTopology());
00883               //fill histograms for clusters on tracks
00884               //correct SiPixelTrackResidualModule
00885               std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*hit).geographicalId().rawId());
00886 
00887               //CHARGE CORRECTION (for track impact angle)
00888               // calculate alpha and beta from cluster position
00889               LocalTrajectoryParameters ltp = tsos.localParameters();
00890               LocalVector localDir = ltp.momentum()/ltp.momentum().mag();
00891               
00892               float clust_alpha = atan2(localDir.z(), localDir.x());
00893               float clust_beta = atan2(localDir.z(), localDir.y());
00894               double corrCharge = clust->charge() * sqrt( 1.0 / ( 1.0/pow( tan(clust_alpha), 2 ) + 
00895                                                                   1.0/pow( tan(clust_beta ), 2 ) + 
00896                                                                   1.0 )
00897                                                           )/1000.;
00898 
00899               if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*clust), true, corrCharge, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);     
00900 
00901 
00902               trackclusters++;
00903               //CORR CHARGE
00904               meClChargeOnTrack_all->Fill(corrCharge);
00905               meClSizeOnTrack_all->Fill((*clust).size());
00906               meClSizeXOnTrack_all->Fill((*clust).sizeX());
00907               meClSizeYOnTrack_all->Fill((*clust).sizeY());
00908               clusterSet.insert(*clust);
00909 
00910               //find cluster global position (rphi, z)
00911               // get cluster center of gravity (of charge)
00912               float xcenter = clust->x();
00913               float ycenter = clust->y();
00914               // get the cluster position in local coordinates (cm) 
00915               LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
00916               // get the cluster position in global coordinates (cm)
00917               GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
00918 
00919               //find location of hit (barrel or endcap, same for cluster)
00920               bool barrel = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
00921               bool endcap = DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
00922               if(barrel) {
00923                 barreltrackclusters++;
00924                 //CORR CHARGE
00925                 meClChargeOnTrack_bpix->Fill(corrCharge);
00926                 meClSizeOnTrack_bpix->Fill((*clust).size());
00927                 meClSizeXOnTrack_bpix->Fill((*clust).sizeX());
00928                 meClSizeYOnTrack_bpix->Fill((*clust).sizeY());
00929                 uint32_t DBlayer = PixelBarrelName(DetId((*hit).geographicalId())).layerName();
00930                 float phi = clustgp.phi(); 
00931                 float z = clustgp.z();
00932                 switch(DBlayer){
00933                 case 1: {
00934                   meClPosLayer1OnTrack->Fill(z,phi); 
00935                   meClChargeOnTrack_layer1->Fill(corrCharge);
00936                   meClSizeOnTrack_layer1->Fill((*clust).size());
00937                   meClSizeXOnTrack_layer1->Fill((*clust).sizeX());
00938                   meClSizeYOnTrack_layer1->Fill((*clust).sizeY());
00939                   break;
00940                 }
00941                 case 2: {
00942                   meClPosLayer2OnTrack->Fill(z,phi); 
00943                   meClChargeOnTrack_layer2->Fill(corrCharge);
00944                   meClSizeOnTrack_layer2->Fill((*clust).size());
00945                   meClSizeXOnTrack_layer2->Fill((*clust).sizeX());
00946                   meClSizeYOnTrack_layer2->Fill((*clust).sizeY());
00947                   break;
00948                 }
00949                 case 3: {
00950                   meClPosLayer3OnTrack->Fill(z,phi); 
00951                   meClChargeOnTrack_layer3->Fill(corrCharge);
00952                   meClSizeOnTrack_layer3->Fill((*clust).size());
00953                   meClSizeXOnTrack_layer3->Fill((*clust).sizeX());
00954                   meClSizeYOnTrack_layer3->Fill((*clust).sizeY());
00955                   break;
00956                 }
00957                 
00958                 }
00959                 
00960               }
00961               if(endcap) {
00962                 endcaptrackclusters++;
00963                 //CORR CHARGE
00964                 meClChargeOnTrack_fpix->Fill(corrCharge);
00965                 meClSizeOnTrack_fpix->Fill((*clust).size());
00966                 meClSizeXOnTrack_fpix->Fill((*clust).sizeX());
00967                 meClSizeYOnTrack_fpix->Fill((*clust).sizeY());
00968                 uint32_t DBdisk = PixelEndcapName(DetId((*hit).geographicalId())).diskName();
00969                 float x = clustgp.x(); 
00970                 float y = clustgp.y(); 
00971                 float z = clustgp.z();
00972                 if(z>0){
00973                   if(DBdisk==1) {
00974                     meClPosDisk1pzOnTrack->Fill(x,y);
00975                     meClChargeOnTrack_diskp1->Fill(corrCharge);
00976                     meClSizeOnTrack_diskp1->Fill((*clust).size());
00977                     meClSizeXOnTrack_diskp1->Fill((*clust).sizeX());
00978                     meClSizeYOnTrack_diskp1->Fill((*clust).sizeY());
00979                   }
00980                   if(DBdisk==2) {
00981                     meClPosDisk2pzOnTrack->Fill(x,y); 
00982                     meClChargeOnTrack_diskp2->Fill(corrCharge);
00983                     meClSizeOnTrack_diskp2->Fill((*clust).size());
00984                     meClSizeXOnTrack_diskp2->Fill((*clust).sizeX());
00985                     meClSizeYOnTrack_diskp2->Fill((*clust).sizeY());
00986                   }
00987                 }
00988                 else{
00989                   if(DBdisk==1) {
00990                     meClPosDisk1mzOnTrack->Fill(x,y);
00991                     meClChargeOnTrack_diskm1->Fill(corrCharge);
00992                     meClSizeOnTrack_diskm1->Fill((*clust).size());
00993                     meClSizeXOnTrack_diskm1->Fill((*clust).sizeX());
00994                     meClSizeYOnTrack_diskm1->Fill((*clust).sizeY());
00995                   }
00996                   if(DBdisk==2) {
00997                     meClPosDisk2mzOnTrack->Fill(x,y); 
00998                     meClChargeOnTrack_diskm2->Fill(corrCharge);
00999                     meClSizeOnTrack_diskm2->Fill((*clust).size());
01000                     meClSizeXOnTrack_diskm2->Fill((*clust).sizeX());
01001                     meClSizeYOnTrack_diskm2->Fill((*clust).sizeY());
01002                   }
01003                 } 
01004               }
01005               
01006             }//end if (cluster exists)
01007 
01008           }//end if (persistent hit exists and is pixel hit)
01009           
01010         }//end of else 
01011         
01012         
01013       }//end for (all traj measurements of pixeltrack)
01014     }//end if (is pixeltrack)
01015     else {
01016       if(debug_) std::cout << "no pixeltrack:\n";
01017       if(crossesPixVol) meNofTracksInPixVol_->Fill(1,1);
01018     }
01019     
01020   }//end loop on map entries
01021 
01022   //find clusters that are NOT on track
01023   //edmNew::DetSet<SiPixelCluster>::const_iterator  di;
01024   if(debug_) std::cout << "clusters not on track: (size " << clustColl.size() << ") ";
01025 
01026   for(TrackerGeometry::DetContainer::const_iterator it = TG->dets().begin(); it != TG->dets().end(); it++){
01027     //if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
01028     DetId detId = (*it)->geographicalId();
01029     if(detId>=302055684 && detId<=352477708){ // make sure it's a Pixel module WITHOUT using dynamic_cast!  
01030       int nofclOnTrack = 0, nofclOffTrack=0; 
01031       uint32_t DBlayer=10, DBdisk=10; 
01032       float z=0.; 
01033       //set layer/disk
01034       if(DetId(detId).subdetId() == 1) { // Barrel module
01035         DBlayer = PixelBarrelName(DetId(detId)).layerName();
01036       }
01037       if(DetId(detId).subdetId() == 2){ // Endcap module
01038         DBdisk = PixelEndcapName(DetId(detId )).diskName();
01039       }
01040       edmNew::DetSetVector<SiPixelCluster>::const_iterator isearch = clustColl.find(detId);
01041       if( isearch != clustColl.end() ) {  // Not an empty iterator
01042         edmNew::DetSet<SiPixelCluster>::const_iterator  di;
01043         for(di=isearch->begin(); di!=isearch->end(); di++){
01044           unsigned int temp = clusterSet.size();
01045           clusterSet.insert(*di);
01046           //check if cluster is off track
01047           if(clusterSet.size()>temp) {
01048             otherclusters++;
01049             nofclOffTrack++; 
01050             //fill histograms for clusters off tracks
01051             //correct SiPixelTrackResidualModule
01052             std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
01053 
01054             if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill((*di), false, -1., reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn); 
01055             
01056 
01057 
01058             meClSizeNotOnTrack_all->Fill((*di).size());
01059             meClSizeXNotOnTrack_all->Fill((*di).sizeX());
01060             meClSizeYNotOnTrack_all->Fill((*di).sizeY());
01061             meClChargeNotOnTrack_all->Fill((*di).charge()/1000);
01062 
01064             //find cluster global position (rphi, z) get cluster
01065             //define tracker and pixel geometry and topology
01066             const TrackerGeometry& theTracker(*theTrackerGeometry);
01067             const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
01068             //test if PixelGeomDetUnit exists
01069             if(theGeomDet == 0) {
01070               if(debug_) std::cout << "NO THEGEOMDET\n";
01071               continue;
01072             }
01073             const PixelTopology * topol = &(theGeomDet->specificTopology());
01074            
01075             //center of gravity (of charge)
01076             float xcenter = di->x();
01077             float ycenter = di->y();
01078             // get the cluster position in local coordinates (cm) 
01079             LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
01080             // get the cluster position in global coordinates (cm)
01081             GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
01082 
01084 
01085             //barrel
01086             if(DetId(detId).subdetId() == 1) {
01087               meClSizeNotOnTrack_bpix->Fill((*di).size());
01088               meClSizeXNotOnTrack_bpix->Fill((*di).sizeX());
01089               meClSizeYNotOnTrack_bpix->Fill((*di).sizeY());
01090               meClChargeNotOnTrack_bpix->Fill((*di).charge()/1000);
01091               barrelotherclusters++;
01092               //DBlayer = PixelBarrelName(DetId(detId)).layerName();
01093               float phi = clustgp.phi(); 
01094               //float r = clustgp.perp();
01095               z = clustgp.z();
01096               switch(DBlayer){
01097               case 1: {
01098                 meClPosLayer1NotOnTrack->Fill(z,phi); 
01099                 meClSizeNotOnTrack_layer1->Fill((*di).size());
01100                 meClSizeXNotOnTrack_layer1->Fill((*di).sizeX());
01101                 meClSizeYNotOnTrack_layer1->Fill((*di).sizeY());
01102                 meClChargeNotOnTrack_layer1->Fill((*di).charge()/1000);
01103                 break;
01104               }
01105               case 2: {
01106                 meClPosLayer2NotOnTrack->Fill(z,phi);
01107                 meClSizeNotOnTrack_layer2->Fill((*di).size());
01108                 meClSizeXNotOnTrack_layer2->Fill((*di).sizeX());
01109                 meClSizeYNotOnTrack_layer2->Fill((*di).sizeY());
01110                 meClChargeNotOnTrack_layer2->Fill((*di).charge()/1000);
01111                 break;
01112               }
01113               case 3: {
01114                 meClPosLayer3NotOnTrack->Fill(z,phi); 
01115                 meClSizeNotOnTrack_layer3->Fill((*di).size());
01116                 meClSizeXNotOnTrack_layer3->Fill((*di).sizeX());
01117                 meClSizeYNotOnTrack_layer3->Fill((*di).sizeY());
01118                 meClChargeNotOnTrack_layer3->Fill((*di).charge()/1000);
01119                 break;
01120               }
01121                 
01122               }
01123             }
01124             //endcap
01125             if(DetId(detId).subdetId() == 2) {
01126               meClSizeNotOnTrack_fpix->Fill((*di).size());
01127               meClSizeXNotOnTrack_fpix->Fill((*di).sizeX());
01128               meClSizeYNotOnTrack_fpix->Fill((*di).sizeY());
01129               meClChargeNotOnTrack_fpix->Fill((*di).charge()/1000);
01130               endcapotherclusters++;
01131               //DBdisk = PixelEndcapName(DetId(detId )).diskName();
01132               float x = clustgp.x(); 
01133               float y = clustgp.y(); 
01134               z = clustgp.z();
01135               if(z>0){
01136                 if(DBdisk==1) {
01137                   meClPosDisk1pzNotOnTrack->Fill(x,y);
01138                   meClSizeNotOnTrack_diskp1->Fill((*di).size());
01139                   meClSizeXNotOnTrack_diskp1->Fill((*di).sizeX());
01140                   meClSizeYNotOnTrack_diskp1->Fill((*di).sizeY());
01141                   meClChargeNotOnTrack_diskp1->Fill((*di).charge()/1000);
01142                 }
01143                 if(DBdisk==2) {
01144                   meClPosDisk2pzNotOnTrack->Fill(x,y); 
01145                   meClSizeNotOnTrack_diskp2->Fill((*di).size());
01146                   meClSizeXNotOnTrack_diskp2->Fill((*di).sizeX());
01147                   meClSizeYNotOnTrack_diskp2->Fill((*di).sizeY());
01148                   meClChargeNotOnTrack_diskp2->Fill((*di).charge()/1000);
01149                 }
01150               }
01151               else{
01152                 if(DBdisk==1) {
01153                   meClPosDisk1mzNotOnTrack->Fill(x,y);
01154                   meClSizeNotOnTrack_diskm1->Fill((*di).size());
01155                   meClSizeXNotOnTrack_diskm1->Fill((*di).sizeX());
01156                   meClSizeYNotOnTrack_diskm1->Fill((*di).sizeY());
01157                   meClChargeNotOnTrack_diskm1->Fill((*di).charge()/1000);
01158                 }
01159                 if(DBdisk==2) {
01160                   meClPosDisk2mzNotOnTrack->Fill(x,y); 
01161                   meClSizeNotOnTrack_diskm2->Fill((*di).size());
01162                   meClSizeXNotOnTrack_diskm2->Fill((*di).sizeX());
01163                   meClSizeYNotOnTrack_diskm2->Fill((*di).sizeY());
01164                   meClChargeNotOnTrack_diskm2->Fill((*di).charge()/1000);
01165                 }
01166               } 
01167 
01168             }
01169           }// end "if cluster off track"
01170           else {
01171             nofclOnTrack++; 
01172             if(z == 0 && DBdisk != 10){
01173               //find cluster global position (rphi, z) get cluster
01174               //define tracker and pixel geometry and topology
01175               const TrackerGeometry& theTracker(*theTrackerGeometry);
01176               const PixelGeomDetUnit* theGeomDet = static_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
01177               //test if PixelGeomDetUnit exists
01178               if(theGeomDet == 0) {
01179                 if(debug_) std::cout << "NO THEGEOMDET\n";
01180                 continue;
01181               }
01182               const PixelTopology * topol = &(theGeomDet->specificTopology());
01183               //center of gravity (of charge)
01184               float xcenter = di->x();
01185               float ycenter = di->y();
01186               // get the cluster position in local coordinates (cm) 
01187               LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
01188               // get the cluster position in global coordinates (cm)
01189               GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );  
01190               z = clustgp.z();
01191             }
01192           }
01193         }
01194       }
01195       //++ fill the number of clusters on a module
01196       std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find((*it)->geographicalId().rawId());
01197       if (pxd!=theSiPixelStructure.end()) (*pxd).second->nfill(nofclOnTrack, nofclOffTrack, reducedSet, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn); 
01198       if(nofclOnTrack!=0) meNClustersOnTrack_all->Fill(nofclOnTrack); 
01199       if(nofclOffTrack!=0) meNClustersNotOnTrack_all->Fill(nofclOffTrack); 
01200       //barrel
01201       if(DetId(detId).subdetId() == 1){
01202         if(nofclOnTrack!=0) meNClustersOnTrack_bpix->Fill(nofclOnTrack); 
01203         if(nofclOffTrack!=0) meNClustersNotOnTrack_bpix->Fill(nofclOffTrack); 
01204         //DBlayer = PixelBarrelName(DetId(detId)).layerName();
01205         switch(DBlayer){
01206         case 1: { 
01207           if(nofclOnTrack!=0) meNClustersOnTrack_layer1->Fill(nofclOnTrack);
01208           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer1->Fill(nofclOffTrack); break;
01209         }
01210         case 2: {
01211           if(nofclOnTrack!=0) meNClustersOnTrack_layer2->Fill(nofclOnTrack);
01212           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer2->Fill(nofclOffTrack); break; 
01213         }
01214         case 3: {
01215           if(nofclOnTrack!=0) meNClustersOnTrack_layer3->Fill(nofclOnTrack); 
01216           if(nofclOffTrack!=0) meNClustersNotOnTrack_layer3->Fill(nofclOffTrack); break; 
01217         }
01218         }
01219       }//end barrel
01220       //endcap
01221       if(DetId(detId).subdetId() == 2) {
01222         //DBdisk = PixelEndcapName(DetId(detId )).diskName();
01223         //z = clustgp.z();
01224         if(nofclOnTrack!=0) meNClustersOnTrack_fpix->Fill(nofclOnTrack); 
01225         if(nofclOffTrack!=0) meNClustersNotOnTrack_fpix->Fill(nofclOffTrack);
01226         if(z>0){
01227           if(DBdisk==1) {
01228             if(nofclOnTrack!=0) meNClustersOnTrack_diskp1->Fill(nofclOnTrack); 
01229             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp1->Fill(nofclOffTrack);
01230           }
01231           if(DBdisk==2) {
01232             if(nofclOnTrack!=0) meNClustersOnTrack_diskp2->Fill(nofclOnTrack); 
01233             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskp2->Fill(nofclOffTrack);
01234           }
01235         }
01236         if(z<0){
01237           if(DBdisk==1) {
01238             if(nofclOnTrack!=0) meNClustersOnTrack_diskm1->Fill(nofclOnTrack); 
01239             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm1->Fill(nofclOffTrack);
01240           }
01241           if(DBdisk==2) {
01242             if(nofclOnTrack!=0) meNClustersOnTrack_diskm2->Fill(nofclOnTrack); 
01243             if(nofclOffTrack!=0) meNClustersNotOnTrack_diskm2->Fill(nofclOffTrack);
01244           }
01245         }
01246       }
01247 
01248     }//end if it's a Pixel module
01249   }//end for loop over tracker detector geometry modules
01250 
01251 
01252   if(trackclusters>0) (meNofClustersOnTrack_)->Fill(0,trackclusters);
01253   if(barreltrackclusters>0)(meNofClustersOnTrack_)->Fill(1,barreltrackclusters);
01254   if(endcaptrackclusters>0)(meNofClustersOnTrack_)->Fill(2,endcaptrackclusters);
01255   if(otherclusters>0)(meNofClustersNotOnTrack_)->Fill(0,otherclusters);
01256   if(barrelotherclusters>0)(meNofClustersNotOnTrack_)->Fill(1,barrelotherclusters);
01257   if(endcapotherclusters>0)(meNofClustersNotOnTrack_)->Fill(2,endcapotherclusters);
01258   if(tracks>0)(meNofTracks_)->Fill(0,tracks);
01259   if(pixeltracks>0)(meNofTracks_)->Fill(1,pixeltracks);
01260   if(bpixtracks>0)(meNofTracks_)->Fill(2,bpixtracks);
01261   if(fpixtracks>0)(meNofTracks_)->Fill(3,fpixtracks);
01262 }
01263 void SiPixelTrackResidualSource::triplets(double x1,double y1,double z1,double x2,double y2,double z2,double x3,double y3,double z3,
01264                                           double ptsig, double & dca2,double & dz2, double kap) {
01265   
01266   //Define some constants
01267   using namespace std;
01268 
01269   //Curvature kap from global Track
01270 
01271  //inverse of the curvature is the radius in the transverse plane
01272   double rho = 1/kap;
01273   //Check that the hits are in the correct layers
01274   double r1 = sqrt( x1*x1 + y1*y1 );
01275   double r3 = sqrt( x3*x3 + y3*y3 );
01276 
01277   if( r3-r1 < 2.0 ) cout << "warn r1 = " << r1 << ", r3 = " << r3 << endl;
01278   
01279   // Calculate the centre of the helix in xy-projection with radius rho from the track.
01280   //start with a line (sekante) connecting the two points (x1,y1) and (x3,y3) vec_L = vec_x3-vec_x1
01281   //with L being the length of that vector.
01282   double L=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
01283   //lam is the line from the middel point of vec_q towards the center of the circle X0,Y0
01284   // we already have kap and rho = 1/kap
01285   double lam = sqrt(rho*rho - L*L/4);
01286   
01287   // There are two solutions, the sign of kap gives the information
01288   // which of them is correct.
01289   //
01290   if( kap > 0 ) lam = -lam;
01291 
01292   //
01293   // ( X0, Y0 ) is the centre of the circle that describes the helix in xy-projection.
01294   //
01295   double x0 =  0.5*( x1 + x3 ) + lam/L * ( -y1 + y3 );
01296   double y0 =  0.5*( y1 + y3 ) + lam/L * (  x1 - x3 );
01297 
01298   // Calculate the dipangle in z direction (needed later for z residual) :
01299   //Starting from the heliz equation whihc has to hold for both points z1,z3
01300   double num = ( y3 - y0 ) * ( x1 - x0 ) - ( x3 - x0 ) * ( y1 - y0 );
01301   double den = ( x1 - x0 ) * ( x3 - x0 ) + ( y1 - y0 ) * ( y3 - y0 );
01302   double tandip = kap * ( z3 - z1 ) / atan( num / den );
01303 
01304  
01305   // angle from first hit to dca point:
01306   //
01307   double dphi = atan( ( ( x1 - x0 ) * y0 - ( y1 - y0 ) * x0 )
01308                       / ( ( x1 - x0 ) * x0 + ( y1 - y0 ) * y0 ) );
01309   //z position of the track based on the middle of the circle
01310   //track equation for the z component
01311   double uz0 = z1 + tandip * dphi * rho;
01312 
01314   //RESIDUAL IN R-PHI
01316   //Calculate distance dca2 from point (x2,y2) to the circle which is given by
01317   //the distance of the point to the middlepoint dcM = sqrt((x0-x2)^2+(y0-y2)) and rho
01318   //dca = rho +- dcM
01319   if(kap>0) dca2=rho-sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2));
01320   else dca2=rho+sqrt((-x0+x2)*(-x0+x2)+(-y0+y2)*(-y0+y2));
01321 
01323   //RESIDUAL IN Z
01325   double xx =0 ;
01326   double yy =0 ;
01327   //sign of kappa determines the calculation
01328   //xx and yy are the new coordinates starting from x2, y2 that are on the track itself
01329   //vec_X2+-dca2*vec(X0-X2)/|(X0-X2)|
01330   if(kap<0){
01331     xx =   x2+(dca2*((x0-x2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
01332     yy = y2+(dca2*((y0-y2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
01333   }
01334   else if(kap>=0){
01335     xx =   x2-(dca2*((x0-x2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
01336     yy = y2-(dca2*((y0-y2))/sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)));
01337   }
01338 
01339   //to get residual in z start with calculating the new uz2 position if one has moved to xx, yy
01340   //on the track. First calculate the change in phi2 with respect to the center X0, Y0
01341   double dphi2 = atan( ( ( xx - x0 ) * y0 - ( yy - y0 ) * x0 )
01342                        / ( ( xx - x0 ) * x0 + ( yy - y0 ) * y0 ) );
01343   //Solve track equation for this new z depending on the dip angle of the track (see above
01344   //calculated based on X1, X3 and X0, use uz0 as reference point again.
01345   double  uz2= uz0 - dphi2*tandip*rho;
01346   
01347   //subtract new z position from the old one
01348   dz2=z2-uz2;
01349   
01350   //if we are interested in the arclength this is unsigned though
01351   //  double cosphi2 = (x2*xx+y2*yy)/(sqrt(x2*x2+y2*y2)*sqrt(xx*xx+yy*yy));
01352   //double arcdca2=sqrt(x2*x2+y2*y2)*acos(cosphi2);
01353   
01354 }
01355 
01356 
01357 DEFINE_FWK_MODULE(SiPixelTrackResidualSource); // define this as a plug-in