00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016 #include <map>
00017 #include <string>
00018 #include <vector>
00019 #include <utility>
00020
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 #include "FWCore/Framework/interface/ESHandle.h"
00023
00024 #include "DataFormats/Common/interface/Handle.h"
00025 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00026
00027 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00028 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00029 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00030
00031 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
00032
00033 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00034
00035 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
00036
00037 #include "TrackingTools/PatternTools/interface/TrajectoryFitter.h"
00038 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00039 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00040 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00041 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00042
00043 #include "DQMServices/Core/interface/DQMStore.h"
00044 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
00045 #include "DQM/SiPixelMonitorTrack/interface/SiPixelTrackResidualSource.h"
00046
00047
00048 using namespace std;
00049 using namespace edm;
00050
00051
00052 SiPixelTrackResidualSource::SiPixelTrackResidualSource(const edm::ParameterSet& pSet) :
00053 pSet_(pSet),
00054 modOn( pSet.getUntrackedParameter<bool>("modOn",true) ),
00055 ladOn( pSet.getUntrackedParameter<bool>("ladOn",false) ),
00056 layOn( pSet.getUntrackedParameter<bool>("layOn",false) ),
00057 phiOn( pSet.getUntrackedParameter<bool>("phiOn",false) ),
00058 ringOn( pSet.getUntrackedParameter<bool>("ringOn",false) ),
00059 bladeOn( pSet.getUntrackedParameter<bool>("bladeOn",false) ),
00060 diskOn( pSet.getUntrackedParameter<bool>("diskOn",false) )
00061 {
00062 pSet_ = pSet;
00063 debug_ = pSet_.getUntrackedParameter<bool>("debug", false);
00064 src_ = pSet_.getParameter<edm::InputTag>("src");
00065 clustersrc_ = pSet_.getParameter<edm::InputTag>("clustersrc");
00066 tracksrc_ = pSet_.getParameter<edm::InputTag>("trajectoryInput");
00067 dbe_ = edm::Service<DQMStore>().operator->();
00068
00069 LogInfo("PixelDQM") << "SiPixelTrackResidualSource constructor" << endl;
00070 LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/"
00071 << layOn << "/" << phiOn << std::endl;
00072 LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/"
00073 << ringOn << std::endl;
00074 }
00075
00076
00077 SiPixelTrackResidualSource::~SiPixelTrackResidualSource() {
00078 LogInfo("PixelDQM") << "SiPixelTrackResidualSource destructor" << endl;
00079 }
00080
00081
00082 void SiPixelTrackResidualSource::beginJob(edm::EventSetup const& iSetup) {
00083 LogInfo("PixelDQM") << "SiPixelTrackResidualSource beginJob()" << endl;
00084
00085
00086 edm::ESHandle<TrackerGeometry> TG;
00087 iSetup.get<TrackerDigiGeometryRecord>().get(TG);
00088 if (debug_) LogVerbatim("PixelDQM") << "TrackerGeometry "<< &(*TG) <<" size is "<< TG->dets().size() << endl;
00089
00090
00091 for (TrackerGeometry::DetContainer::const_iterator pxb = TG->detsPXB().begin();
00092 pxb!=TG->detsPXB().end(); pxb++) {
00093 if (dynamic_cast<PixelGeomDetUnit*>((*pxb))!=0) {
00094 SiPixelTrackResidualModule* module = new SiPixelTrackResidualModule((*pxb)->geographicalId().rawId());
00095 theSiPixelStructure.insert(pair<uint32_t, SiPixelTrackResidualModule*>((*pxb)->geographicalId().rawId(), module));
00096 }
00097 }
00098 for (TrackerGeometry::DetContainer::const_iterator pxf = TG->detsPXF().begin();
00099 pxf!=TG->detsPXF().end(); pxf++) {
00100 if (dynamic_cast<PixelGeomDetUnit*>((*pxf))!=0) {
00101 SiPixelTrackResidualModule* module = new SiPixelTrackResidualModule((*pxf)->geographicalId().rawId());
00102 theSiPixelStructure.insert(pair<uint32_t, SiPixelTrackResidualModule*>((*pxf)->geographicalId().rawId(), module));
00103 }
00104 }
00105 LogInfo("PixelDQM") << "SiPixelStructure size is " << theSiPixelStructure.size() << endl;
00106
00107 dbe_->setVerbose(0);
00108
00109
00110 SiPixelFolderOrganizer theSiPixelFolder;
00111 for (std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.begin();
00112 pxd!=theSiPixelStructure.end(); pxd++) {
00113
00114 if(modOn){
00115 if (theSiPixelFolder.setModuleFolder((*pxd).first)) (*pxd).second->book(pSet_);
00116 else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Folder Creation Failed! ";
00117 }
00118 if(ladOn){
00119 if (theSiPixelFolder.setModuleFolder((*pxd).first,1)) {
00120
00121 (*pxd).second->book(pSet_,1);
00122 }
00123 else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource ladder Folder Creation Failed! ";
00124 }
00125 if(layOn){
00126 if (theSiPixelFolder.setModuleFolder((*pxd).first,2)) (*pxd).second->book(pSet_,2);
00127 else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource layer Folder Creation Failed! ";
00128 }
00129 if(phiOn){
00130 if (theSiPixelFolder.setModuleFolder((*pxd).first,3)) (*pxd).second->book(pSet_,3);
00131 else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource phi Folder Creation Failed! ";
00132 }
00133 if(bladeOn){
00134 if (theSiPixelFolder.setModuleFolder((*pxd).first,4)) (*pxd).second->book(pSet_,4);
00135 else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Blade Folder Creation Failed! ";
00136 }
00137 if(diskOn){
00138 if (theSiPixelFolder.setModuleFolder((*pxd).first,5)) (*pxd).second->book(pSet_,5);
00139 else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Disk Folder Creation Failed! ";
00140 }
00141 if(ringOn){
00142 if (theSiPixelFolder.setModuleFolder((*pxd).first,6)) (*pxd).second->book(pSet_,6);
00143 else throw cms::Exception("LogicError") << "SiPixelTrackResidualSource Ring Folder Creation Failed! ";
00144 }
00145 }
00146
00147
00148
00149
00150
00151
00152 dbe_->setCurrentFolder("Pixel/Tracks");
00153 meNofTracks_ = dbe_->book1D("ntracks_" + tracksrc_.label(),"Number of Tracks",4,0,4);
00154 meNofTracks_->setAxisTitle("Number of Tracks",1);
00155 meNofTracks_->setBinLabel(1,"All");
00156 meNofTracks_->setBinLabel(2,"Pixel");
00157 meNofTracks_->setBinLabel(3,"BPix");
00158 meNofTracks_->setBinLabel(4,"FPix");
00159
00160
00161 dbe_->setCurrentFolder("Pixel/Tracks");
00162 meNofTracksInPixVol_ = dbe_->book1D("ntracksInPixVol_" + tracksrc_.label(),"Number of Tracks crossing Pixel fiducial Volume",2,0,2);
00163 meNofTracksInPixVol_->setAxisTitle("Number of Tracks",1);
00164 meNofTracksInPixVol_->setBinLabel(1,"With Hits");
00165 meNofTracksInPixVol_->setBinLabel(2,"Without Hits");
00166
00167
00168 dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00169 meNofClustersOnTrack_ = dbe_->book1D("nclusters_" + clustersrc_.label(),"Number of Clusters (on track)",3,0,3);
00170 meNofClustersOnTrack_->setAxisTitle("Number of Clusters on Track",1);
00171 meNofClustersOnTrack_->setBinLabel(1,"All");
00172 meNofClustersOnTrack_->setBinLabel(2,"BPix");
00173 meNofClustersOnTrack_->setBinLabel(3,"FPix");
00174 dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00175 meNofClustersNotOnTrack_ = dbe_->book1D("nclusters_" + clustersrc_.label(),"Number of Clusters (off track)",3,0,3);
00176 meNofClustersNotOnTrack_->setAxisTitle("Number of Clusters off Track",1);
00177 meNofClustersNotOnTrack_->setBinLabel(1,"All");
00178 meNofClustersNotOnTrack_->setBinLabel(2,"BPix");
00179 meNofClustersNotOnTrack_->setBinLabel(3,"FPix");
00180
00181
00182
00183
00184 dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00185 meClChargeOnTrack_all = dbe_->book1D("charge_" + clustersrc_.label(),"Charge (on track)",500,0.,500.);
00186 meClChargeOnTrack_all->setAxisTitle("Charge size (MeV)",1);
00187 meClChargeOnTrack_bpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Barrel","Charge (on track, barrel)",500,0.,500.);
00188 meClChargeOnTrack_bpix->setAxisTitle("Charge size (MeV)",1);
00189 meClChargeOnTrack_fpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Endcap","Charge (on track, endcap)",500,0.,500.);
00190 meClChargeOnTrack_fpix->setAxisTitle("Charge size (MeV)",1);
00191
00192 dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00193 meClChargeNotOnTrack_all = dbe_->book1D("charge_" + clustersrc_.label(),"Charge (off track)",500,0.,500.);
00194 meClChargeNotOnTrack_all->setAxisTitle("Charge size (MeV)",1);
00195 meClChargeNotOnTrack_bpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Barrel","Charge (off track, barrel)",500,0.,500.);
00196 meClChargeNotOnTrack_bpix->setAxisTitle("Charge size (MeV)",1);
00197 meClChargeNotOnTrack_fpix = dbe_->book1D("charge_" + clustersrc_.label() + "_Endcap","Charge (off track, endcap)",500,0.,500.);
00198 meClChargeNotOnTrack_fpix->setAxisTitle("Charge size (MeV)",1);
00199
00200
00201 dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00202 meClSizeOnTrack_all = dbe_->book1D("size_" + clustersrc_.label(),"Size (on track)",100,0.,100.);
00203 meClSizeOnTrack_all->setAxisTitle("Cluster size (in pixels)",1);
00204 meClSizeOnTrack_bpix = dbe_->book1D("size" + clustersrc_.label() + "_Barrel","Size (on track, barrel)",100,0.,100.);
00205 meClSizeOnTrack_bpix->setAxisTitle("Cluster size (in pixels)",1);
00206 meClSizeOnTrack_fpix = dbe_->book1D("size_" + clustersrc_.label() + "_Endcap","Size (on track, endcap)",100,0.,100.);
00207 meClSizeOnTrack_fpix->setAxisTitle("Cluster size (in pixels)",1);
00208
00209 dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00210 meClSizeNotOnTrack_all = dbe_->book1D("size_" + clustersrc_.label(),"Size (off track)",100,0.,100.);
00211 meClSizeNotOnTrack_all->setAxisTitle("Cluster size (in pixels)",1);
00212
00213 meClSizeNotOnTrack_bpix = dbe_->book1D("size_" + clustersrc_.label() + "_Barrel","Size (off track, barrel)",100,0.,100.);
00214 meClSizeNotOnTrack_bpix->setAxisTitle("Cluster size (in pixels)",1);
00215
00216 meClSizeNotOnTrack_fpix = dbe_->book1D("size_" + clustersrc_.label() + "_Endcap","Size (off track, endcap)",100,0.,100.);
00217 meClSizeNotOnTrack_fpix->setAxisTitle("Cluster size (in pixels)",1);
00218
00219
00220
00221
00222 dbe_->setCurrentFolder("Pixel/Clusters/OnTrack");
00223
00224 meClPosLayer1OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_1","Clusters Layer1 (on track)",200,-30.,30.,128,-3.2,3.2);
00225 meClPosLayer1OnTrack->setAxisTitle("Global Z (cm)",1);
00226 meClPosLayer1OnTrack->setAxisTitle("Global #phi",2);
00227 meClPosLayer2OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_2","Clusters Layer2 (on track)",200,-30.,30.,128,-3.2,3.2);
00228 meClPosLayer2OnTrack->setAxisTitle("Global Z (cm)",1);
00229 meClPosLayer2OnTrack->setAxisTitle("Global #phi",2);
00230 meClPosLayer3OnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_3","Clusters Layer3 (on track)",200,-30.,30.,128,-3.2,3.2);
00231 meClPosLayer3OnTrack->setAxisTitle("Global Z (cm)",1);
00232 meClPosLayer3OnTrack->setAxisTitle("Global #phi",2);
00233
00234 meClPosDisk1pzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_1","Clusters +Z Disk1 (on track)",80,-20.,20.,80,-20.,20.);
00235 meClPosDisk1pzOnTrack->setAxisTitle("Global X (cm)",1);
00236 meClPosDisk1pzOnTrack->setAxisTitle("Global Y (cm)",2);
00237 meClPosDisk2pzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_2","Clusters +Z Disk2 (on track)",80,-20.,20.,80,-20.,20.);
00238 meClPosDisk2pzOnTrack->setAxisTitle("Global X (cm)",1);
00239 meClPosDisk2pzOnTrack->setAxisTitle("Global Y (cm)",2);
00240 meClPosDisk1mzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_1","Clusters -Z Disk1 (on track)",80,-20.,20.,80,-20.,20.);
00241 meClPosDisk1mzOnTrack->setAxisTitle("Global X (cm)",1);
00242 meClPosDisk1mzOnTrack->setAxisTitle("Global Y (cm)",2);
00243 meClPosDisk2mzOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_2","Clusters -Z Disk2 (on track)",80,-20.,20.,80,-20.,20.);
00244 meClPosDisk2mzOnTrack->setAxisTitle("Global X (cm)",1);
00245 meClPosDisk2mzOnTrack->setAxisTitle("Global Y (cm)",2);
00246
00247 dbe_->setCurrentFolder("Pixel/Clusters/OffTrack");
00248
00249 meClPosLayer1NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_1","Clusters Layer1 (off track)",200,-30.,30.,128,-3.2,3.2);
00250 meClPosLayer1NotOnTrack->setAxisTitle("Global Z (cm)",1);
00251 meClPosLayer1NotOnTrack->setAxisTitle("Global #phi",2);
00252 meClPosLayer2NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_2","Clusters Layer2 (off track)",200,-30.,30.,128,-3.2,3.2);
00253 meClPosLayer2NotOnTrack->setAxisTitle("Global Z (cm)",1);
00254 meClPosLayer2NotOnTrack->setAxisTitle("Global #phi",2);
00255 meClPosLayer3NotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_Layer_3","Clusters Layer3 (off track)",200,-30.,30.,128,-3.2,3.2);
00256 meClPosLayer3NotOnTrack->setAxisTitle("Global Z (cm)",1);
00257 meClPosLayer3NotOnTrack->setAxisTitle("Global #phi",2);
00258
00259 meClPosDisk1pzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_1","Clusters +Z Disk1 (off track)",80,-20.,20.,80,-20.,20.);
00260 meClPosDisk1pzNotOnTrack->setAxisTitle("Global X (cm)",1);
00261 meClPosDisk1pzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00262 meClPosDisk2pzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_pz_Disk_2","Clusters +Z Disk2 (off track)",80,-20.,20.,80,-20.,20.);
00263 meClPosDisk2pzNotOnTrack->setAxisTitle("Global X (cm)",1);
00264 meClPosDisk2pzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00265 meClPosDisk1mzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_1","Clusters -Z Disk1 (off track)",80,-20.,20.,80,-20.,20.);
00266 meClPosDisk1mzNotOnTrack->setAxisTitle("Global X (cm)",1);
00267 meClPosDisk1mzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00268 meClPosDisk2mzNotOnTrack = dbe_->book2D("position_" + clustersrc_.label() + "_mz_Disk_2","Clusters -Z Disk2 (off track)",80,-20.,20.,80,-20.,20.);
00269 meClPosDisk2mzNotOnTrack->setAxisTitle("Global X (cm)",1);
00270 meClPosDisk2mzNotOnTrack->setAxisTitle("Global Y (cm)",2);
00271
00272 if (debug_) {
00273
00274 dbe_->setCurrentFolder("debugging");
00275 char hisID[80];
00276 for (int s=0; s<3; s++) {
00277 sprintf(hisID,"residual_x_subdet_%i",s);
00278 meSubdetResidualX[s] = dbe_->book1D(hisID,"Pixel Hit-to-Track Residual in X",500,-5.,5.);
00279
00280 sprintf(hisID,"residual_y_subdet_%i",s);
00281 meSubdetResidualY[s] = dbe_->book1D(hisID,"Pixel Hit-to-Track Residual in Y",500,-5.,5.);
00282 }
00283 }
00284 }
00285
00286
00287 void SiPixelTrackResidualSource::endJob(void) {
00288 LogInfo("PixelDQM") << "SiPixelTrackResidualSource endJob()";
00289
00290
00291 bool saveFile = pSet_.getUntrackedParameter<bool>("saveFile", true);
00292 if (saveFile) {
00293 std::string outputFile = pSet_.getParameter<std::string>("outputFile");
00294 LogInfo("PixelDQM") << " - saving histograms to "<< outputFile.data();
00295 dbe_->save(outputFile);
00296 }
00297 LogInfo("PixelDQM") << endl;
00298 }
00299
00300
00301 void SiPixelTrackResidualSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00302
00303
00304
00305
00306 ESHandle<TrackerGeometry> TG;
00307 iSetup.get<TrackerDigiGeometryRecord>().get(TG);
00308 const TrackerGeometry* theTrackerGeometry = TG.product();
00309
00310 ESHandle<MagneticField> MF;
00311 iSetup.get<IdealMagneticFieldRecord>().get(MF);
00312 const MagneticField* theMagneticField = MF.product();
00313
00314
00315 std::string TTRHBuilder = pSet_.getParameter<std::string>("TTRHBuilder");
00316 ESHandle<TransientTrackingRecHitBuilder> TTRHB;
00317 iSetup.get<TransientRecHitRecord>().get(TTRHBuilder, TTRHB);
00318 const TransientTrackingRecHitBuilder* theTTRHBuilder = TTRHB.product();
00319
00320
00321 std::string Fitter = pSet_.getParameter<std::string>("Fitter");
00322 ESHandle<TrajectoryFitter> TF;
00323 iSetup.get<TrackingComponentsRecord>().get(Fitter, TF);
00324 const TrajectoryFitter* theFitter = TF.product();
00325
00326
00327 std::string TrackCandidateLabel = pSet_.getParameter<std::string>("TrackCandidateLabel");
00328 std::string TrackCandidateProducer = pSet_.getParameter<std::string>("TrackCandidateProducer");
00329 Handle<TrackCandidateCollection> trackCandidateCollection;
00330 iEvent.getByLabel(TrackCandidateProducer, TrackCandidateLabel, trackCandidateCollection);
00331
00332 for (TrackCandidateCollection::const_iterator tc = trackCandidateCollection->begin();
00333 tc!=trackCandidateCollection->end(); ++tc) {
00334 TrajectoryStateTransform transformer;
00335 PTrajectoryStateOnDet tcPTSoD = tc->trajectoryStateOnDet();
00336 TrajectoryStateOnSurface tcTSoS = transformer.transientState(tcPTSoD, &(theTrackerGeometry->idToDet(tcPTSoD.detId())->surface()),
00337 theMagneticField);
00338 const TrajectorySeed& tcSeed = tc->seed();
00339
00340 const TrackCandidate::range& tcRecHits = tc->recHits();
00341 if (debug_) cout << "track candidate has "<< int(tcRecHits.second - tcRecHits.first) <<" hits with ID ";
00342
00343 Trajectory::RecHitContainer tcTTRHs;
00344 for (TrackingRecHitCollection::const_iterator tcRecHit = tcRecHits.first;
00345 tcRecHit!=tcRecHits.second; ++tcRecHit) {
00346 if (debug_) cout << tcRecHit->geographicalId().rawId() <<" ";
00347
00348 tcTTRHs.push_back(theTTRHBuilder->build(&(*tcRecHit)));
00349 }
00350
00351
00352
00353 std::vector<Trajectory> refitTrajectoryCollection = theFitter->fit(tcSeed, tcTTRHs, tcTSoS);
00354 if (debug_) cout << "refitTrajectoryCollection size is "<< refitTrajectoryCollection.size() << endl;
00355
00356 if (refitTrajectoryCollection.size()>0) {
00357 const Trajectory& refitTrajectory = refitTrajectoryCollection.front();
00358
00359
00360 Trajectory::DataContainer refitTMs = refitTrajectory.measurements();
00361 if (debug_) cout << "refitTrajectory has "<< refitTMs.size() <<" hits with ID ";
00362
00363 for (Trajectory::DataContainer::iterator refitTM = refitTMs.begin();
00364 refitTM!=refitTMs.end(); refitTM++) {
00365 TransientTrackingRecHit::ConstRecHitPointer refitTTRH = refitTM->recHit();
00366 if (debug_) cout << refitTTRH->geographicalId().rawId() <<" ";
00367
00368
00369 const GeomDet* ttrhDet = refitTTRH->det();
00370 if (ttrhDet->components().empty() && (ttrhDet->subDetector()==GeomDetEnumerators::PixelBarrel ||
00371 ttrhDet->subDetector()==GeomDetEnumerators::PixelEndcap)) {
00372
00373
00374
00375 TrajectoryStateOnSurface combinedTSoS = TrajectoryStateCombiner().combine(refitTM->forwardPredictedState(),
00376 refitTM->backwardPredictedState());
00377 if (refitTTRH->isValid() && combinedTSoS.isValid()) {
00378
00379 const GeomDetUnit* GDU = dynamic_cast<const GeomDetUnit*>(ttrhDet);
00380 const Topology* theTopology = &(GDU->topology());
00381
00382 MeasurementPoint hitPosition = theTopology->measurementPosition(refitTTRH->localPosition());
00383 MeasurementPoint combinedTSoSPosition = theTopology->measurementPosition(combinedTSoS.localPosition());
00384
00385 Measurement2DVector residual = hitPosition - combinedTSoSPosition;
00386 if(debug_) std::cout << "fill residual " << residual.x() << " " << residual.y() << " \n";
00387
00388
00389 std::map<uint32_t, SiPixelTrackResidualModule*>::iterator pxd = theSiPixelStructure.find(refitTTRH->geographicalId().rawId());
00390 if (pxd!=theSiPixelStructure.end()) (*pxd).second->fill(residual, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
00391
00392 if (debug_) {
00393 if (ttrhDet->subDetector()==GeomDetEnumerators::PixelBarrel) {
00394 meSubdetResidualX[0]->Fill(residual.x());
00395 meSubdetResidualY[0]->Fill(residual.y());
00396 }
00397 else {
00398 meSubdetResidualX[PXFDetId(refitTTRH->geographicalId()).side()]->Fill(residual.x());
00399 meSubdetResidualY[PXFDetId(refitTTRH->geographicalId()).side()]->Fill(residual.y());
00400 }
00401 }
00402 }
00403 }
00404 }
00405 if (debug_) cout << endl;
00406 }
00407 }
00408
00409
00410
00411
00412 edm::Handle<std::vector<Trajectory> > trajCollectionHandle;
00413 iEvent.getByLabel(tracksrc_,trajCollectionHandle);
00414 const std::vector<Trajectory> trajColl = *(trajCollectionHandle.product());
00415
00416
00417 edm::Handle<std::vector<reco::Track> > trackCollectionHandle;
00418 iEvent.getByLabel(tracksrc_,trackCollectionHandle);
00419 const std::vector<reco::Track> trackColl = *(trackCollectionHandle.product());
00420
00421
00422 edm::Handle<TrajTrackAssociationCollection> match;
00423 iEvent.getByLabel(tracksrc_,match);
00424 const TrajTrackAssociationCollection ttac = *(match.product());
00425
00426
00427 edm::Handle< edmNew::DetSetVector<SiPixelCluster> > clusterColl;
00428 iEvent.getByLabel( clustersrc_, clusterColl );
00429 const edmNew::DetSetVector<SiPixelCluster> clustColl = *(clusterColl.product());
00430
00431 if(debug_){
00432 std::cout << "Trajectories\t : " << trajColl.size() << std::endl;
00433 std::cout << "recoTracks \t : " << trackColl.size() << std::endl;
00434 std::cout << "Map entries \t : " << ttac.size() << std::endl;
00435 }
00436
00437 std::set<SiPixelCluster> clusterSet;
00438 TrajectoryStateCombiner tsoscomb;
00439 int tracks=0, pixeltracks=0, bpixtracks=0, fpixtracks=0;
00440 int trackclusters=0, barreltrackclusters=0, endcaptrackclusters=0;
00441 int otherclusters=0, barrelotherclusters=0, endcapotherclusters=0;
00442
00443
00444 for(TrajTrackAssociationCollection::const_iterator it = ttac.begin();it != ttac.end(); ++it){
00445 const edm::Ref<std::vector<Trajectory> > traj_iterator = it->key;
00446
00447 reco::TrackRef trackref = it->val;
00448 tracks++;
00449
00450 bool isBpixtrack = false, isFpixtrack = false, crossesPixVol=false;
00451
00452
00453
00454 double d0 = (*trackref).d0(), dz = (*trackref).dz();
00455
00456 if(abs(d0)<15 && abs(dz)<50) crossesPixVol = true;
00457
00458 std::vector<TrajectoryMeasurement> tmeasColl =traj_iterator->measurements();
00459 std::vector<TrajectoryMeasurement>::const_iterator tmeasIt;
00460
00461 for(tmeasIt = tmeasColl.begin();tmeasIt!=tmeasColl.end();tmeasIt++){
00462 if(! tmeasIt->updatedState().isValid()) continue;
00463 TransientTrackingRecHit::ConstRecHitPointer testhit = tmeasIt->recHit();
00464 if(! testhit->isValid() || testhit->geographicalId().det() != DetId::Tracker) continue;
00465 uint testSubDetID = (testhit->geographicalId().subdetId());
00466 if(testSubDetID==PixelSubdetector::PixelBarrel) isBpixtrack = true;
00467 if(testSubDetID==PixelSubdetector::PixelEndcap) isFpixtrack = true;
00468 }
00469 if(isBpixtrack) {
00470 bpixtracks++;
00471 if(debug_) std::cout << "bpixtrack\n";
00472 }
00473 if(isFpixtrack) {
00474 fpixtracks++;
00475 if(debug_) std::cout << "fpixtrack\n";
00476 }
00477 if(isBpixtrack || isFpixtrack){
00478 pixeltracks++;
00479
00480 if(crossesPixVol) meNofTracksInPixVol_->Fill(0,1);
00481
00482 std::vector<TrajectoryMeasurement> tmeasColl = traj_iterator->measurements();
00483 for(std::vector<TrajectoryMeasurement>::const_iterator tmeasIt = tmeasColl.begin(); tmeasIt!=tmeasColl.end(); tmeasIt++){
00484 if(! tmeasIt->updatedState().isValid()) continue;
00485
00486 TrajectoryStateOnSurface tsos = tsoscomb( tmeasIt->forwardPredictedState(), tmeasIt->backwardPredictedState() );
00487 TransientTrackingRecHit::ConstRecHitPointer hit = tmeasIt->recHit();
00488 if(! hit->isValid() || hit->geographicalId().det() != DetId::Tracker ) {
00489 continue;
00490 } else {
00491
00492
00493 const DetId & hit_detId = hit->geographicalId();
00494
00495 uint IntSubDetID = (hit_detId.subdetId());
00496
00497 if(IntSubDetID == 0 )
00498 continue;
00499
00500
00501 const TrackingRecHit *persistentHit = hit->hit();
00502
00503 if ((persistentHit != 0) && (typeid(*persistentHit) == typeid(SiPixelRecHit))) {
00504
00505 const SiPixelRecHit* pixhit = dynamic_cast<const SiPixelRecHit*>( hit->hit() );
00506
00507 edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& clust = (*pixhit).cluster();
00508
00509 if (clust.isNonnull()) {
00510
00511
00512 const TrackerGeometry& theTracker(*theTrackerGeometry);
00513 const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*> (theTracker.idToDet(hit_detId) );
00514
00515 if(theGeomDet == 0) {
00516 if(debug_) std::cout << "NO THEGEOMDET\n";
00517 continue;
00518 }
00519
00520 const RectangularPixelTopology * topol = dynamic_cast<const RectangularPixelTopology*>(&(theGeomDet->specificTopology()));
00521
00522 trackclusters++;
00523 meClChargeOnTrack_all->Fill((*clust).charge()/1000.);
00524 meClSizeOnTrack_all->Fill((*clust).size());
00525 clusterSet.insert(*clust);
00526
00527
00528
00529 float xcenter = clust->x();
00530 float ycenter = clust->y();
00531
00532 LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
00533
00534 GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
00535
00536
00537 bool barrel = DetId::DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
00538 bool endcap = DetId::DetId((*hit).geographicalId()).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
00539 if(barrel) {
00540 barreltrackclusters++;
00541 meClChargeOnTrack_bpix->Fill((*clust).charge()/1000.);
00542 meClSizeOnTrack_bpix->Fill((*clust).size());
00543 uint32_t DBlayer = PixelBarrelName::PixelBarrelName(DetId::DetId((*hit).geographicalId())).layerName();
00544 float phi = clustgp.phi();
00545 float z = clustgp.z();
00546 switch(DBlayer){
00547 case 1: meClPosLayer1OnTrack->Fill(z,phi); break;
00548 case 2: meClPosLayer2OnTrack->Fill(z,phi); break;
00549 case 3: meClPosLayer3OnTrack->Fill(z,phi); break;
00550
00551 }
00552
00553 }
00554 if(endcap) {
00555 endcaptrackclusters++;
00556 meClChargeOnTrack_fpix->Fill((*clust).charge()/1000.);
00557 meClSizeOnTrack_fpix->Fill((*clust).size());
00558 uint32_t DBdisk = PixelEndcapName::PixelEndcapName(DetId::DetId((*hit).geographicalId())).diskName();
00559 float x = clustgp.x();
00560 float y = clustgp.y();
00561 float z = clustgp.z();
00562 if(z>0){
00563 if(DBdisk==1) meClPosDisk1pzOnTrack->Fill(x,y);
00564 if(DBdisk==2) meClPosDisk2pzOnTrack->Fill(x,y);
00565 }
00566 else{
00567 if(DBdisk==1) meClPosDisk1mzOnTrack->Fill(x,y);
00568 if(DBdisk==2) meClPosDisk2mzOnTrack->Fill(x,y);
00569 }
00570 }
00571
00572 }
00573
00574 }
00575
00576 }
00577
00578
00579 }
00580 }
00581 else {
00582 if(debug_) std::cout << "no pixeltrack:\n";
00583 if(crossesPixVol) meNofTracksInPixVol_->Fill(1,1);
00584 }
00585
00586 }
00587
00588
00589
00590 if(debug_) std::cout << "clusters not on track: (size " << clustColl.size() << ") ";
00591
00592 for(TrackerGeometry::DetContainer::const_iterator it = TG->dets().begin(); it != TG->dets().end(); it++){
00593 if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
00594 DetId detId = (*it)->geographicalId();
00595
00596 edmNew::DetSetVector<SiPixelCluster>::const_iterator isearch = clustColl.find(detId);
00597 if( isearch != clustColl.end() ) {
00598 edmNew::DetSet<SiPixelCluster>::const_iterator di;
00599 for(di=isearch->begin(); di!=isearch->end(); di++){
00600 unsigned int temp = clusterSet.size();
00601 clusterSet.insert(*di);
00602 if(clusterSet.size()>temp) {
00603 otherclusters++;
00604 meClSizeNotOnTrack_all->Fill((*di).size());
00605 meClChargeNotOnTrack_all->Fill((*di).charge()/1000);
00606
00608
00609
00610 const TrackerGeometry& theTracker(*theTrackerGeometry);
00611 const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*> (theTracker.idToDet(detId) );
00612
00613 if(theGeomDet == 0) {
00614 if(debug_) std::cout << "NO THEGEOMDET\n";
00615 continue;
00616 }
00617 const RectangularPixelTopology * topol = dynamic_cast<const RectangularPixelTopology*>(&(theGeomDet->specificTopology()));
00618
00619
00620 float xcenter = di->x();
00621 float ycenter = di->y();
00622
00623 LocalPoint clustlp = topol->localPosition( MeasurementPoint(xcenter, ycenter) );
00624
00625 GlobalPoint clustgp = theGeomDet->surface().toGlobal( clustlp );
00626
00628
00629
00630 if(DetId::DetId(detId).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
00631 meClSizeNotOnTrack_bpix->Fill((*di).size());
00632 meClChargeNotOnTrack_bpix->Fill((*di).charge()/1000);
00633 barrelotherclusters++;
00634 uint32_t DBlayer = PixelBarrelName::PixelBarrelName(DetId::DetId(detId)).layerName();
00635 float phi = clustgp.phi();
00636
00637 float z = clustgp.z();
00638 switch(DBlayer){
00639 case 1: meClPosLayer1NotOnTrack->Fill(z,phi); break;
00640 case 2: meClPosLayer2NotOnTrack->Fill(z,phi); break;
00641 case 3: meClPosLayer3NotOnTrack->Fill(z,phi); break;
00642
00643 }
00644 }
00645
00646 if(DetId::DetId(detId).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
00647 meClSizeNotOnTrack_fpix->Fill((*di).size());
00648 meClChargeNotOnTrack_fpix->Fill((*di).charge()/1000);
00649 endcapotherclusters++;
00650 uint32_t DBdisk = PixelEndcapName::PixelEndcapName(DetId::DetId(detId )).diskName();
00651 float x = clustgp.x();
00652 float y = clustgp.y();
00653 float z = clustgp.z();
00654 if(z>0){
00655 if(DBdisk==1) meClPosDisk1pzNotOnTrack->Fill(x,y);
00656 if(DBdisk==2) meClPosDisk2pzNotOnTrack->Fill(x,y);
00657 }
00658 else{
00659 if(DBdisk==1) meClPosDisk1mzNotOnTrack->Fill(x,y);
00660 if(DBdisk==2) meClPosDisk2mzNotOnTrack->Fill(x,y);
00661 }
00662
00663 }
00664 }
00665 }
00666 }
00667 }
00668 }
00669
00670
00671 if(trackclusters>0) (meNofClustersOnTrack_)->Fill(0,trackclusters);
00672 if(barreltrackclusters>0)(meNofClustersOnTrack_)->Fill(1,barreltrackclusters);
00673 if(endcaptrackclusters>0)(meNofClustersOnTrack_)->Fill(2,endcaptrackclusters);
00674 if(otherclusters>0)(meNofClustersNotOnTrack_)->Fill(0,otherclusters);
00675 if(barrelotherclusters>0)(meNofClustersNotOnTrack_)->Fill(1,barrelotherclusters);
00676 if(endcapotherclusters>0)(meNofClustersNotOnTrack_)->Fill(2,endcapotherclusters);
00677 if(tracks>0)(meNofTracks_)->Fill(0,tracks);
00678 if(pixeltracks>0)(meNofTracks_)->Fill(1,pixeltracks);
00679 if(bpixtracks>0)(meNofTracks_)->Fill(2,bpixtracks);
00680 if(fpixtracks>0)(meNofTracks_)->Fill(3,fpixtracks);
00681 }
00682
00683
00684 DEFINE_FWK_MODULE(SiPixelTrackResidualSource);