CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoTracker/DebugTools/plugins/TestOutliers.cc

Go to the documentation of this file.
00001  // -*- C++ -*-
00002 //
00003 // Package:    TestOutliers
00004 // Class:      TestOutliers
00005 // 
00013 //
00014 // Original Author:  Giuseppe Cerati
00015 //         Created:  Mon Sep 17 10:31:30 CEST 2007
00016 // $Id: TestOutliers.cc,v 1.11 2010/10/15 12:22:09 elmer Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <vector>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDAnalyzer.h"
00028 
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033 #include "FWCore/Utilities/interface/InputTag.h"
00034 #include "DataFormats/TrackReco/interface/Track.h"
00035 #include "SimTracker/TrackAssociation/interface/TrackAssociatorByHits.h"
00036 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
00037 #include "SimTracker/Records/interface/TrackAssociatorRecord.h"
00038 #include <TH1.h>
00039 #include <TH2.h>
00040 #include <TFile.h>
00041 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00042 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
00043 #include "MagneticField/Engine/interface/MagneticField.h" 
00044 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" 
00045 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00046 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00047 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00048 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00049 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00050 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00051 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00052 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00053 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00054 #include "DataFormats/GeometryCommonDetAlgo/interface/ErrorFrameTransformer.h"
00055 #include "CommonTools/RecoAlgos/interface/RecoTrackSelector.h"
00056 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00057 
00058 //
00059 // class decleration
00060 //
00061 
00062 class TestOutliers : public edm::EDAnalyzer {
00063 public:
00064   explicit TestOutliers(const edm::ParameterSet&);
00065   ~TestOutliers();
00066 
00067 
00068 private:
00069   virtual void beginRun(edm::Run & run, const edm::EventSetup&) ;
00070   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00071   virtual void endJob() ;
00072 
00073   // ----------member data ---------------------------
00074   edm::InputTag trackTagsOut_; //used to select what tracks to read from configuration file
00075   edm::InputTag trackTagsOld_; //used to select what tracks to read from configuration file
00076   edm::InputTag tpTags_; //used to select what tracks to read from configuration file
00077   TrackAssociatorBase * theAssociatorOld;
00078   TrackAssociatorBase * theAssociatorOut;
00079   //RecoTrackSelector selectRecoTracks;
00080   TrackerHitAssociator* hitAssociator;
00081   edm::ESHandle<TrackerGeometry> theG;
00082   std::string out;
00083   TFile * file;
00084   TH1F *histoPtOut, *histoPtOld ;
00085   TH1F *histoQoverpOut,*histoQoverpOld;
00086   TH1F *histoPhiOut,*histoPhiOld;
00087   TH1F *histoD0Out,*histoD0Old;
00088   TH1F *histoDzOut,*histoDzOld;
00089   TH1F *histoLambdaOut,*histoLambdaOld;
00090   TH1F *deltahits,*deltahitsAssocGained,*deltahitsAssocLost,*hitsPerTrackLost,*hitsPerTrackAssocLost,*hitsPerTrackGained,*hitsPerTrackAssocGained,*deltahitsOK,*deltahitsNO;
00091   TH1F *okcutsOut,*okcutsOld;
00092   TH1F *tracks, *goodbadhits, *process, *goodcluster, *goodprocess, *badcluster, *badprocess;
00093   TH1F *goodhittype, *goodlayer, *goodhittype_clgteq4, *goodlayer_clgteq4, *goodhittype_cllt4, *goodlayer_cllt4, *badhittype, *badlayer;
00094   TH2F *posxy, *poszr;
00095   TH1F *goodpixgteq4_simvecsize, *goodpixlt4_simvecsize;
00096   TH1F *goodst1gteq4_simvecsize, *goodst1lt4_simvecsize;
00097   TH1F *goodst2gteq4_simvecsize, *goodst2lt4_simvecsize;
00098   TH1F *goodprjgteq4_simvecsize, *goodprjlt4_simvecsize;
00099   TH1F *goodpix_clustersize;
00100   TH1F *goodst1_clustersize;
00101   TH1F *goodst2_clustersize;
00102   TH1F *goodprj_clustersize;
00103   TH1F *goodpix_simvecsize;
00104   TH1F *goodst1_simvecsize;
00105   TH1F *goodst2_simvecsize;
00106   TH1F *goodprj_simvecsize;
00107   TH1F *goodhittype_simvecsmall, *goodlayer_simvecsmall, *goodhittype_simvecbig, *goodlayer_simvecbig, *goodbadmerged, *goodbadmergedLost, *goodbadmergedGained;
00108   TH1F *energyLoss,*energyLossMax,*energyLossRatio, *nOfTrackIds, *mergedPull, *mergedlayer, *mergedcluster, *mergedhittype;
00109   TH1F *sizeOut, *sizeOld, *sizeOutT, *sizeOldT;
00110   TH1F *countOutA, *countOutT, *countOldT;
00111   TH1F *gainedhits,*gainedhits2;
00112   TH1F *probXgood,*probXbad,*probXdelta,*probXshared,*probXnoshare;
00113   TH1F *probYgood,*probYbad,*probYdelta,*probYshared,*probYnoshare;
00114   edm::ParameterSet psetold,psetout;
00115 };
00116 //
00117 // constants, enums and typedefs
00118 //
00119 
00120 //
00121 // static data member definitions
00122 //
00123 
00124 using namespace edm;
00125 
00126 //
00127 // constructors and destructor
00128 //
00129 TestOutliers::TestOutliers(const edm::ParameterSet& iConfig)
00130   :
00131   trackTagsOut_(iConfig.getUntrackedParameter<edm::InputTag>("tracksOut")),
00132   trackTagsOld_(iConfig.getUntrackedParameter<edm::InputTag>("tracksOld")),
00133   tpTags_(iConfig.getUntrackedParameter<edm::InputTag>("tp")),
00134   out(iConfig.getParameter<std::string>("out"))
00135 {
00136   LogTrace("TestOutliers") <<"constructor";
00137 //   ParameterSet cuts = iConfig.getParameter<ParameterSet>("RecoTracksCuts");
00138 //   selectRecoTracks = RecoTrackSelector(cuts.getParameter<double>("ptMin"),
00139 //                                     cuts.getParameter<double>("minRapidity"),
00140 //                                     cuts.getParameter<double>("maxRapidity"),
00141 //                                     cuts.getParameter<double>("tip"),
00142 //                                     cuts.getParameter<double>("lip"),
00143 //                                     cuts.getParameter<int>("minHit"),
00144 //                                     cuts.getParameter<double>("maxChi2"));
00145   
00146   psetold = iConfig.getParameter<ParameterSet>("TrackAssociatorByHitsPSetOld");
00147   psetout = iConfig.getParameter<ParameterSet>("TrackAssociatorByHitsPSetOut");
00148   LogTrace("TestOutliers") <<"end constructor";
00149 }
00150 
00151 
00152 TestOutliers::~TestOutliers()
00153 {
00154  
00155   // do anything here that needs to be done at desctruction time
00156   // (e.g. close files, deallocate resources etc.)
00157 
00158 }
00159 
00160 
00161 //
00162 // member functions
00163 //
00164 
00165 // ------------ method called to for each event  ------------
00166 void
00167 TestOutliers::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00168 
00169   using namespace edm;
00170   using namespace std;
00171   using reco::TrackCollection;
00172 
00173   LogTrace("TestOutliers") <<"analyze event #" << iEvent.id();
00174   
00175   edm::Handle<edm::View<reco::Track> > tracksOut;
00176   iEvent.getByLabel(trackTagsOut_,tracksOut);
00177   edm::Handle<edm::View<reco::Track> > tracksOld;
00178   iEvent.getByLabel(trackTagsOld_,tracksOld);
00179   Handle<TrackingParticleCollection> tps;
00180   iEvent.getByLabel(tpTags_,tps);
00181   edm::Handle<reco::BeamSpot> beamSpot;
00182   iEvent.getByLabel("offlineBeamSpot",beamSpot); 
00183 
00184   hitAssociator = new TrackerHitAssociator(iEvent);
00185 
00186   theAssociatorOld = new TrackAssociatorByHits(psetold);
00187   theAssociatorOut = new TrackAssociatorByHits(psetout);
00188   reco::RecoToSimCollection recSimCollOut=theAssociatorOut->associateRecoToSim(tracksOut, tps, &iEvent);
00189   reco::RecoToSimCollection recSimCollOld=theAssociatorOld->associateRecoToSim(tracksOld, tps, &iEvent);
00190   sizeOut->Fill(recSimCollOut.size());
00191   sizeOld->Fill(recSimCollOld.size());
00192   sizeOutT->Fill(tracksOut->size());
00193   sizeOldT->Fill(tracksOld->size());
00194 
00195   LogTrace("TestOutliers") << "tOld size=" << tracksOld->size() << " tOut size=" << tracksOut->size() 
00196                            << " aOld size=" << recSimCollOld.size() << " aOut size=" << recSimCollOut.size();
00197 
00198 #if 0
00199   LogTrace("TestOutliers") << "recSimCollOld.size()=" << recSimCollOld.size() ;
00200   for(reco::TrackCollection::size_type j=0; j<tracksOld->size(); ++j){
00201     reco::TrackRef trackOld(tracksOld, j);
00202     //if ( !selectRecoTracks( *trackOld,beamSpot.product() ) ) continue;
00203     LogTrace("TestOutliers") << "trackOld->pt()=" << trackOld->pt() << " trackOld->numberOfValidHits()=" << trackOld->numberOfValidHits();
00204     std::vector<pair<TrackingParticleRef, double> > tpOld;
00205     if(recSimCollOld.find(trackOld) != recSimCollOld.end()){
00206       tpOld = recSimCollOld[trackOld];
00207       if (tpOld.size()!=0) LogTrace("TestOutliers") << " associated" ;
00208       else LogTrace("TestOutliers") << " NOT associated" ;
00209     } else LogTrace("TestOutliers") << " NOT associated" ;
00210   }
00211   LogTrace("TestOutliers") << "recSimCollOut.size()=" << recSimCollOut.size() ;
00212   for(reco::TrackCollection::size_type j=0; j<tracksOut->size(); ++j){
00213     reco::TrackRef trackOut(tracksOut, j);
00214     //if ( !selectRecoTracks( *trackOut,beamSpot.product() ) ) continue;
00215     LogTrace("TestOutliers") << "trackOut->pt()=" << trackOut->pt() << " trackOut->numberOfValidHits()=" << trackOut->numberOfValidHits();
00216     std::vector<pair<TrackingParticleRef, double> > tpOut;
00217     if(recSimCollOut.find(trackOut) != recSimCollOut.end()){
00218       tpOut = recSimCollOut[trackOut];
00219       if (tpOut.size()!=0) LogTrace("TestOutliers") << " associated" ;
00220       else LogTrace("TestOutliers") << " NOT associated" ;
00221     } else LogTrace("TestOutliers") << " NOT associated" ;
00222   }
00223 #endif
00224 
00225   LogTrace("TestOutliers") <<"tracksOut->size()="<<tracksOut->size();
00226   LogTrace("TestOutliers") <<"tracksOld->size()="<<tracksOld->size();
00227 
00228   std::vector<unsigned int> outused;
00229   for(unsigned int j=0; j<tracksOld->size(); ++j) {
00230     countOldT->Fill(1);
00231     edm::RefToBase<reco::Track> trackOld(tracksOld, j);
00232     LogTrace("TestOutliers") << "now track old with id=" << j << " seed ref=" << trackOld->seedRef().get() << " pt=" << trackOld->pt()
00233                               << " eta=" <<  trackOld->eta() << " chi2=" <<  trackOld->normalizedChi2()
00234                               << " tip= " << fabs(trackOld->dxy(beamSpot->position()))
00235                               << " lip= " << fabs(trackOld->dsz(beamSpot->position()));
00236 
00237     //     if (i==tracksOut->size()) {
00238     //       if(recSimCollOld.find(trackOld) != recSimCollOld.end()){      
00239     //  vector<pair<TrackingParticleRef, double> > tpOld;
00240     //  tpOld = recSimCollOld[trackOld];
00241     //  if (tpOld.size()!=0) { 
00242     //    LogTrace("TestOutliers") <<"no match: old associated and out lost! old has #hits=" << trackOld->numberOfValidHits() 
00243     //                             << " and fraction=" << tpOld.begin()->second;
00244     //    if (tpOld.begin()->second>0.5) hitsPerTrackLost->Fill(trackOld->numberOfValidHits());
00245     //  }
00246     //       }
00247     //       continue;
00248     //     }
00249 
00250     std::vector<unsigned int> outtest;//all the out tracks with the same seed ref
00251     for(unsigned int k=0; k<tracksOut->size(); ++k) {
00252       edm::RefToBase<reco::Track> tmpOut = edm::RefToBase<reco::Track>(tracksOut, k);
00253       if ( tmpOut->seedRef() == trackOld->seedRef() ) {
00254         outtest.push_back(k);
00255       }      
00256     }
00257 
00258     edm::RefToBase<reco::Track> trackOut;
00259     if (outtest.size()==1) {// if only one that's it
00260       trackOut = edm::RefToBase<reco::Track>(tracksOut, outtest[0]);
00261       LogTrace("TestOutliers") << "now track out with id=" << outtest[0] << " seed ref=" << trackOut->seedRef().get() << " pt=" << trackOut->pt();      
00262       outused.push_back(outtest[0]);
00263     } else if (outtest.size()>1) {//if > 1 take the one that shares all the hits with the old track
00264       for(unsigned int p=0; p<outtest.size(); ++p) {
00265         edm::RefToBase<reco::Track> tmpOut = edm::RefToBase<reco::Track>(tracksOut, outtest[p]);        
00266         bool allhits = true;
00267         for (trackingRecHit_iterator itOut = tmpOut->recHitsBegin(); itOut!=tmpOut->recHitsEnd(); itOut++) {
00268           if ((*itOut)->isValid()) { 
00269             bool thishit = false;
00270             for (trackingRecHit_iterator itOld = trackOld->recHitsBegin();  itOld!=trackOld->recHitsEnd(); itOld++) {
00271               if ((*itOld)->isValid()) {
00272                 const TrackingRecHit* kt = &(**itOld);
00273                 if ( (*itOut)->sharesInput(kt,TrackingRecHit::some) ) { 
00274                   thishit = true;
00275                   break;
00276                 }
00277               }
00278             }
00279             if (!thishit) allhits = false;
00280           }
00281         }
00282         if (allhits) {
00283           trackOut = edm::RefToBase<reco::Track>(tracksOut, outtest[p]);
00284           LogTrace("TestOutliers") << "now track out with id=" << outtest[p] << " seed ref=" << trackOut->seedRef().get() << " pt=" << trackOut->pt();  
00285           outused.push_back(outtest[p]);          
00286         }
00287       }
00288     } 
00289 
00290     if (outtest.size()==0 || trackOut.get()==0 ) {//no out track found for the old track
00291       if(recSimCollOld.find(trackOld) != recSimCollOld.end()){      
00292         vector<pair<TrackingParticleRef, double> > tpOld;
00293         tpOld = recSimCollOld[trackOld];
00294         if (tpOld.size()!=0) { 
00295           LogTrace("TestOutliers") <<"no match: old associated and out lost! old has #hits=" << trackOld->numberOfValidHits() 
00296                                    << " and fraction=" << tpOld.begin()->second;
00297           if (tpOld.begin()->second>0.5) hitsPerTrackLost->Fill(trackOld->numberOfValidHits());
00298         }
00299       }      
00300       LogTrace("TestOutliers") <<"...skip to next old track";
00301       continue;
00302     }
00303 
00304     //look if old and out are associated    
00305     LogTrace("TestOutliers") <<"trackOut->seedRef()=" << trackOut->seedRef().get() << " trackOld->seedRef()=" << trackOld->seedRef().get();
00306     bool oldAssoc = recSimCollOld.find(trackOld) != recSimCollOld.end();
00307     bool outAssoc = recSimCollOut.find(trackOut) != recSimCollOut.end();
00308     LogTrace("TestOutliers") <<"outAssoc=" << outAssoc <<" oldAssoc=" << oldAssoc;
00309 
00310     //     if ( trackOut->seedRef()!= trackOld->seedRef() ||  
00311     //   (trackOut->seedRef() == trackOld->seedRef() && trackOut->numberOfValidHits()>trackOld->numberOfValidHits()) ) {
00312     //       LogTrace("TestOutliers") <<"out and old tracks does not match...";
00313     //       LogTrace("TestOutliers") <<"old has #hits=" << trackOld->numberOfValidHits();
00314     //       std::vector<pair<TrackingParticleRef, double> > tpOld;
00315     //       if(recSimCollOld.find(trackOld) != recSimCollOld.end()) {
00316     //  tpOld = recSimCollOld[trackOld];
00317     //  if (tpOld.size()!=0) { 
00318     //    LogTrace("TestOutliers") <<"old was associated with fraction=" << tpOld.begin()->second;
00319     //    if (tpOld.begin()->second>0.5) hitsPerTrackLost->Fill(trackOld->numberOfValidHits());
00320     //  }
00321     //       }
00322     //       LogTrace("TestOutliers") <<"...skip to next old track";
00323     //       continue;
00324     //     }
00325     //     //++i;
00326     countOutT->Fill(1);
00327 
00328     //if ( !selectRecoTracks( *trackOld,beamSpot.product() ) ) continue;//no more cuts
00329 
00330     tracks->Fill(0);//FIXME
00331 
00332     bool hasOut = false;
00333 
00334     TrackingParticleRef tpr;
00335     TrackingParticleRef tprOut;
00336     TrackingParticleRef tprOld;
00337     double fracOut;
00338     std::vector<unsigned int> tpids;
00339     std::vector<std::pair<TrackingParticleRef, double> > tpOut;
00340     std::vector<pair<TrackingParticleRef, double> > tpOld;
00341     //contare outliers delle tracce che erano associate e non lo sono piu!!!!
00342 
00343     if(outAssoc) {//save the ids od the tp associate to the out track
00344       tpOut = recSimCollOut[trackOut];
00345       if (tpOut.size()!=0) {
00346         countOutA->Fill(1);
00347         tprOut = tpOut.begin()->first;
00348         fracOut = tpOut.begin()->second;
00349         for (TrackingParticle::g4t_iterator g4T=tprOut->g4Track_begin(); g4T!=tprOut->g4Track_end(); ++g4T) {
00350           tpids.push_back(g4T->trackId());
00351         }
00352       }
00353     }
00354 
00355     if(oldAssoc){//save the ids od the tp associate to the old track
00356       tpOld = recSimCollOld[trackOld];
00357       if (tpOld.size()!=0) { 
00358         tprOld = tpOld.begin()->first;
00359         //      LogTrace("TestOutliers") <<"old associated and out not! old has #hits=" << trackOld->numberOfValidHits() 
00360         //                               << " and fraction=" << tpOld.begin()->second;
00361         //      if (tpOld.begin()->second>0.5) hitsPerTrackLost->Fill(trackOld->numberOfValidHits());//deve essere un plot diverso tipo LostAssoc
00362         if (tpOut.size()==0) {
00363           for (TrackingParticle::g4t_iterator g4T=tprOld->g4Track_begin(); g4T!=tprOld->g4Track_end(); ++g4T) {
00364             tpids.push_back(g4T->trackId());
00365           }
00366         }
00367       }
00368     }
00369 
00370     if (tprOut.get()!=0 || tprOld.get()!=0) { //at least one of the tracks has to be associated
00371 
00372       tpr = tprOut.get()!=0 ? tprOut : tprOld;
00373 
00374       const SimTrack * assocTrack = &(*tpr->g4Track_begin());
00375       
00376       //if ( trackOut->numberOfValidHits() < trackOld->numberOfValidHits() ) {
00377       if ( trackOut->numberOfValidHits() != trackOld->numberOfValidHits() || 
00378            !trackOut->recHitsBegin()->get()->sharesInput(trackOld->recHitsBegin()->get(),TrackingRecHit::some) ||
00379            !(trackOut->recHitsEnd()-1)->get()->sharesInput((trackOld->recHitsEnd()-1)->get(),TrackingRecHit::some)  ) 
00380         { //there are outliers if the number of valid hits is != or if the first and last hit does not match
00381         hasOut=true;
00382         LogTrace("TestOutliers") << "outliers for track with #hits=" << trackOut->numberOfValidHits();
00383         tracks->Fill(1);
00384         LogTrace("TestOutliers") << "Out->pt=" << trackOut->pt() << " Old->pt=" << trackOld->pt() 
00385                                  << " tp->pt=" << sqrt(tpr->momentum().perp2()) 
00386           //<< " trackOut->ptError()=" << trackOut->ptError() << " trackOld->ptError()=" << trackOld->ptError() 
00387                                  << " Old->validHits=" << trackOld->numberOfValidHits() << " Out->validHits=" << trackOut->numberOfValidHits()
00388           /*<< " fracOld=" << fracOld*/ << " fracOut=" << fracOut
00389                                  << " deltaHits=" << trackOld->numberOfValidHits()-trackOut->numberOfValidHits();
00390 
00391         //compute all the track parameters        
00392         double PtPullOut = (trackOut->pt()-sqrt(tpr->momentum().perp2()))/trackOut->ptError(); 
00393         double PtPullOld = (trackOld->pt()-sqrt(tpr->momentum().perp2()))/trackOld->ptError();
00394         histoPtOut->Fill( PtPullOut );
00395         histoPtOld->Fill( PtPullOld );
00396 
00397         //LogTrace("TestOutliers") << "MagneticField";            
00398         edm::ESHandle<MagneticField> theMF;
00399         iSetup.get<IdealMagneticFieldRecord>().get(theMF);
00400         FreeTrajectoryState 
00401           ftsAtProduction(GlobalPoint(tpr->vertex().x(),tpr->vertex().y(),tpr->vertex().z()),
00402                           GlobalVector(assocTrack->momentum().x(),assocTrack->momentum().y(),assocTrack->momentum().z()),
00403                           TrackCharge(trackOld->charge()),
00404                           theMF.product());
00405         TSCPBuilderNoMaterial tscpBuilder;
00406         TrajectoryStateClosestToPoint tsAtClosestApproach 
00407           = tscpBuilder(ftsAtProduction,GlobalPoint(0,0,0));//as in TrackProducerAlgorithm
00408         GlobalPoint v = tsAtClosestApproach.theState().position();
00409         GlobalVector p = tsAtClosestApproach.theState().momentum();
00410                   
00411         //LogTrace("TestOutliers") << "qoverpSim";                
00412         double qoverpSim = tsAtClosestApproach.charge()/p.mag();
00413         double lambdaSim = M_PI/2-p.theta();
00414         double phiSim    = p.phi();
00415         double dxySim    = (-v.x()*sin(p.phi())+v.y()*cos(p.phi()));
00416         double dszSim    = v.z()*p.perp()/p.mag() - (v.x()*p.x()+v.y()*p.y())/p.perp() * p.z()/p.mag();
00417         double d0Sim     = -dxySim;
00418         double dzSim     = dszSim*p.mag()/p.perp();
00419                   
00420         //LogTrace("TestOutliers") << "qoverpPullOut";            
00421         double qoverpPullOut=(trackOut->qoverp()-qoverpSim)/trackOut->qoverpError();
00422         double qoverpPullOld=(trackOld->qoverp()-qoverpSim)/trackOld->qoverpError();
00423         double lambdaPullOut=(trackOut->lambda()-lambdaSim)/trackOut->thetaError();
00424         double lambdaPullOld=(trackOld->lambda()-lambdaSim)/trackOld->thetaError();
00425         double phi0PullOut=(trackOut->phi()-phiSim)/trackOut->phiError();
00426         double phi0PullOld=(trackOld->phi()-phiSim)/trackOld->phiError();
00427         double d0PullOut=(trackOut->d0()-d0Sim)/trackOut->d0Error();
00428         double d0PullOld=(trackOld->d0()-d0Sim)/trackOld->d0Error();
00429         double dzPullOut=(trackOut->dz()-dzSim)/trackOut->dzError();
00430         double dzPullOld=(trackOld->dz()-dzSim)/trackOld->dzError();
00431                   
00432         //LogTrace("TestOutliers") << "histoQoverpOut";           
00433         histoQoverpOut->Fill(qoverpPullOut);
00434         histoQoverpOld->Fill(qoverpPullOld);
00435         histoPhiOut->Fill(phi0PullOut);  
00436         histoPhiOld->Fill(phi0PullOld);  
00437         histoD0Out->Fill(d0PullOut);  
00438         histoD0Old->Fill(d0PullOld);  
00439         histoDzOut->Fill(dzPullOut);  
00440         histoDzOld->Fill(dzPullOld);  
00441         histoLambdaOut->Fill(lambdaPullOut);
00442         histoLambdaOld->Fill(lambdaPullOld);
00443 
00444         //delta number of valid hits
00445         LogTrace("TestOutliers") << "deltahits=" << trackOld->numberOfValidHits()-trackOut->numberOfValidHits();                  
00446         deltahits->Fill(trackOld->numberOfValidHits()-trackOut->numberOfValidHits());
00447 
00448         if(tprOut.get()!=0 && tprOld.get()==0) { //out associated and old not: gained track
00449           if (tpOld.size()!=0 && tpOld.begin()->second<=0.5) {
00450             deltahitsAssocGained->Fill(trackOld->numberOfValidHits()-trackOut->numberOfValidHits());
00451             hitsPerTrackAssocGained->Fill(trackOut->numberOfValidHits());
00452             LogTrace("TestOutliers") << "a) gained (assoc) track out #hits==" << trackOut->numberOfValidHits() << " old #hits=" << trackOld->numberOfValidHits();    
00453           } else {
00454             deltahitsAssocGained->Fill(trackOld->numberOfValidHits()-trackOut->numberOfValidHits());
00455             hitsPerTrackAssocGained->Fill(trackOut->numberOfValidHits());
00456             LogTrace("TestOutliers") << "b) gained (assoc) track out #hits==" << trackOut->numberOfValidHits() << " old #hits=" << trackOld->numberOfValidHits();    
00457           }
00458         } else if(tprOut.get()==0 && tprOld.get()!=0) { //old associated and out not: lost track
00459           LogTrace("TestOutliers") <<"old associated and out not! old has #hits=" << trackOld->numberOfValidHits() 
00460                                    << " and fraction=" << tpOld.begin()->second;
00461           if (tpOld.begin()->second>0.5) {      
00462             hitsPerTrackAssocLost->Fill(trackOld->numberOfValidHits());
00463             deltahitsAssocLost->Fill(trackOld->numberOfValidHits()-trackOut->numberOfValidHits());
00464           }
00465         }
00466         
00467         if ( fabs(PtPullOut) < fabs(PtPullOld) ) 
00468           deltahitsOK->Fill(trackOld->numberOfValidHits()-trackOut->numberOfValidHits());
00469         else 
00470           deltahitsNO->Fill(trackOld->numberOfValidHits()-trackOut->numberOfValidHits());
00471         
00472         //LogTrace("TestOutliers") << "RecoTrackSelector";                
00473         //if (selectRecoTracks(*trackOut,beamSpot.product())) okcutsOut->Fill(1); else okcutsOut->Fill(0);
00474         //if (selectRecoTracks(*trackOld,beamSpot.product())) okcutsOld->Fill(1); else okcutsOld->Fill(0);
00475 
00476         LogTrace("TestOutliers") << "track old";
00477         for (trackingRecHit_iterator itOld = trackOld->recHitsBegin(); itOld!=trackOld->recHitsEnd() ; itOld++){
00478           LogTrace("TestOutliers") << (*itOld)->isValid() << " " << (*itOld)->geographicalId().rawId();
00479         }
00480         LogTrace("TestOutliers") << "track out";
00481         for (trackingRecHit_iterator itOut = trackOut->recHitsBegin(); itOut!=trackOut->recHitsEnd() ; itOut++){
00482           LogTrace("TestOutliers") << (*itOut)->isValid() << " " << (*itOut)->geographicalId().rawId();
00483         }
00484         //LogTrace("TestOutliers") << "itOut";            
00485 
00486 
00487         vector<pair<int, trackingRecHit_iterator> > gainedlostoutliers;
00488         //look for gained hits
00489         for (trackingRecHit_iterator itOut = trackOut->recHitsBegin(); itOut!=trackOut->recHitsEnd(); itOut++){
00490           bool gained = true;
00491           if ((*itOut)->isValid()) {
00492             for (trackingRecHit_iterator itOld = trackOld->recHitsBegin(); itOld!=trackOld->recHitsEnd() ; itOld++){
00493               if ( (*itOld)->geographicalId().rawId()==(*itOut)->geographicalId().rawId() ) gained = false;
00494             }
00495             if (gained) {
00496               gainedlostoutliers.push_back(pair<int, trackingRecHit_iterator>(1,itOut));
00497               LogTrace("TestOutliers") << "broken trajectory during old fit... gained hit " << (*itOut)->geographicalId().rawId();
00498               gainedhits->Fill(1);
00499             }
00500           }
00501         }
00502 
00503         //look for outliers and lost hits
00504         for (trackingRecHit_iterator itOld = trackOld->recHitsBegin(); itOld!=trackOld->recHitsEnd() ; itOld++){
00505 
00506           bool outlier = false;
00507           bool lost = true;
00508 
00509           for (trackingRecHit_iterator itOut = trackOut->recHitsBegin(); itOut!=trackOut->recHitsEnd(); itOut++){
00510             if ( (*itOld)->geographicalId().rawId()==(*itOut)->geographicalId().rawId() ) {
00511               lost=false;
00512               if ( (*itOld)->isValid() && !(*itOut)->isValid() && (*itOld)->geographicalId().rawId()==(*itOut)->geographicalId().rawId() ) {
00513                 LogTrace("TestOutliers") << (*itOld)->isValid() << " " << (*itOut)->isValid() << " " 
00514                                          << (*itOld)->geographicalId().rawId() << " " << (*itOut)->geographicalId().rawId();
00515                 outlier=true;
00516               }
00517             }
00518           }
00519           if (lost) gainedlostoutliers.push_back(pair<int, trackingRecHit_iterator>(2,itOld));
00520           if (lost) LogTrace("TestOutliers") << "lost";
00521           else if (outlier) gainedlostoutliers.push_back(pair<int, trackingRecHit_iterator>(3,itOld));
00522         }
00523 
00524         for (std::vector<pair<int, trackingRecHit_iterator> >::iterator it = gainedlostoutliers.begin(); it!=gainedlostoutliers.end();++it) {
00525           LogTrace("TestOutliers") << "type of processed hit:" <<it->first;
00526           trackingRecHit_iterator itHit = it->second;
00527           bool gained = false;
00528           bool lost = false;
00529           bool outlier = false;
00530           if (it->first==1) gained = true;
00531           else if (it->first==2) lost = true;
00532           else if (it->first==3) outlier = true;
00533 
00534           if (outlier||lost||gained) {
00535           //if (1) {
00536 
00537             if (lost && (*itHit)->isValid()==false) {
00538               goodbadmergedLost->Fill(0);
00539               LogTrace("TestOutliers") << "lost invalid";                 
00540               continue;
00541             }
00542             else if (gained && (*itHit)->isValid()==false) {
00543               goodbadmergedGained->Fill(0);
00544               LogTrace("TestOutliers") << "gained invalid";
00545               continue;
00546             }
00547               
00548             //LogTrace("TestOutliers") << "vector<SimHitIdpr>";           
00549             //look if the hit comes from a correct sim track
00550             std::vector<SimHitIdpr> simTrackIds = hitAssociator->associateHitId(**itHit);
00551             bool goodhit = false;
00552             for(size_t j=0; j<simTrackIds.size(); j++){
00553               for (size_t jj=0; jj<tpids.size(); jj++){
00554                 if (simTrackIds[j].first == tpids[jj]) goodhit = true;
00555                 break;
00556               }
00557             }
00558 
00559             //find what kind of hit is it
00560             int clustersize = 0;
00561             int hittypeval = 0;
00562             int layerval = 0 ;
00563             if (dynamic_cast<const SiPixelRecHit*>(&**itHit)){  
00564               LogTrace("TestOutliers") << "SiPixelRecHit";                
00565               clustersize =  ((const SiPixelRecHit*)(&**itHit))->cluster()->size() ;
00566               hittypeval  = 1;
00567             }
00568             else if (dynamic_cast<const SiStripRecHit2D*>(&**itHit)){
00569               LogTrace("TestOutliers") << "SiStripRecHit2D";              
00570               clustersize =  ((const SiStripRecHit2D*)(&**itHit))->cluster()->amplitudes().size() ;
00571               hittypeval  = 2;
00572             }
00573             else if (dynamic_cast<const SiStripMatchedRecHit2D*>(&**itHit)){
00574               LogTrace("TestOutliers") << "SiStripMatchedRecHit2D";               
00575               int clsize1 = ((const SiStripMatchedRecHit2D*)(&**itHit))->monoHit()->cluster()->amplitudes().size();
00576               int clsize2 =  ((const SiStripMatchedRecHit2D*)(&**itHit))->stereoHit()->cluster()->amplitudes().size();
00577               if (clsize1>clsize2) clustersize = clsize1;
00578               else clustersize = clsize2;
00579               hittypeval  = 3;
00580             }
00581             else if (dynamic_cast<const ProjectedSiStripRecHit2D*>(&**itHit)){
00582               LogTrace("TestOutliers") << "ProjectedSiStripRecHit2D";             
00583               clustersize =  ((const ProjectedSiStripRecHit2D*)(&**itHit))->originalHit().cluster()->amplitudes().size();
00584               hittypeval  = 4;
00585             }
00586               
00587             //find the layer of the hit
00588             int subdetId = (*itHit)->geographicalId().subdetId();
00589             int layerId  = 0;
00590             DetId id = (*itHit)->geographicalId();
00591             if (id.subdetId()==3) layerId = ((TIBDetId)(id)).layer();
00592             if (id.subdetId()==5) layerId = ((TOBDetId)(id)).layer();
00593             if (id.subdetId()==1) layerId = ((PXBDetId)(id)).layer();
00594             if (id.subdetId()==4) layerId = ((TIDDetId)(id)).wheel();
00595             if (id.subdetId()==6) layerId = ((TECDetId)(id)).wheel();
00596             if (id.subdetId()==2) layerId = ((PXFDetId)(id)).disk();
00597             layerval = subdetId*10+layerId;
00598       
00599             //LogTrace("TestOutliers") << "gpos";                 
00600             GlobalPoint gpos = theG->idToDet((*itHit)->geographicalId())->surface().toGlobal((*itHit)->localPosition());
00601 
00602 
00603             //get the vector of sim hit associated and choose the one with the largest energy loss
00604             //double delta = 99999;
00605             //LocalPoint rhitLPv = (*itHit)->localPosition();
00606             //vector<PSimHit> assSimHits = hitAssociator->associateHit(**itHit);
00607             //if (assSimHits.size()==0) continue;
00608             //PSimHit shit;
00609             //for(std::vector<PSimHit>::const_iterator m=assSimHits.begin(); m<assSimHits.end(); m++){
00610             //if ((m->localPosition()-rhitLPv).mag()<delta) {
00611             //  shit=*m;
00612             //  delta = (m->localPosition()-rhitLPv).mag();
00613             // }
00614             //}
00615             //LogTrace("TestOutliers") << "energyLoss_";           
00616             double energyLoss_ = 0.;
00617             unsigned int monoId = 0;
00618             std::vector<double> energyLossM;
00619             std::vector<double> energyLossS;
00620             std::vector<PSimHit> assSimHits = hitAssociator->associateHit(**itHit);
00621             if (assSimHits.size()==0) continue;
00622             PSimHit shit;
00623             std::vector<unsigned int> trackIds;
00624             energyLossS.clear();
00625             energyLossM.clear();
00626             //LogTrace("TestOutliers") << "energyLossM";                  
00627             for(std::vector<PSimHit>::const_iterator m=assSimHits.begin(); m<assSimHits.end(); m++){
00628               if (outlier) energyLoss->Fill(m->energyLoss());
00629               unsigned int tId = m->trackId();
00630               if (find(trackIds.begin(),trackIds.end(),tId)==trackIds.end()) trackIds.push_back(tId);
00631               LogTrace("TestOutliers") << "id=" << tId;
00632               if (m->energyLoss()>energyLoss_) {
00633                 shit=*m;
00634                 energyLoss_ = m->energyLoss();
00635               }
00636               if (hittypeval==3) {
00637                 if (monoId==0) monoId = m->detUnitId();
00638                 if (monoId == m->detUnitId()){
00639                   energyLossM.push_back(m->energyLoss());
00640                 }
00641                 else {
00642                   energyLossS.push_back(m->energyLoss());
00643                 }
00644                 //std::cout << "detUnitId="  << m->detUnitId() << " trackId=" << m->trackId() << " energyLoss=" << m->energyLoss() << std::endl;
00645               } else {
00646                 energyLossM.push_back(m->energyLoss());
00647               }
00648             }
00649             unsigned int nIds = trackIds.size();
00650 
00651             if (outlier) {
00652               goodbadhits->Fill(goodhit);
00653               posxy->Fill(fabs(gpos.x()),fabs(gpos.y()));
00654               poszr->Fill(fabs(gpos.z()),sqrt(gpos.x()*gpos.x()+gpos.y()*gpos.y()));
00655               process->Fill(shit.processType());                      
00656               energyLossMax->Fill(energyLoss_);
00657             }
00658               
00659             //look if the hit is shared and if is produced only by ionization processes
00660             bool shared = true;
00661             bool ioniOnly = true;
00662             unsigned int idc = 0;
00663             for (size_t jj=0; jj<tpids.size(); jj++){
00664               idc += std::count(trackIds.begin(),trackIds.end(),tpids[jj]);
00665             }
00666             if (idc==trackIds.size()) {
00667               shared = false;
00668             }
00669             for(std::vector<PSimHit>::const_iterator m=assSimHits.begin()+1; m<assSimHits.end(); m++){
00670               if ((m->processType()!=7&&m->processType()!=8&&m->processType()!=9)&&abs(m->particleType())!=11){
00671                 ioniOnly = false;
00672                 break;
00673               }
00674             }
00675             if (ioniOnly&&!shared){
00676               LogTrace("TestOutliers") << "delta";
00677             }
00678             
00679             if (goodhit) { 
00680               if (outlier) {
00681                 goodprocess->Fill(shit.processType());
00682                 if (clustersize>=4) {
00683                   goodhittype_clgteq4->Fill(hittypeval);
00684                   goodlayer_clgteq4->Fill(layerval);
00685                 } else {
00686                   goodhittype_cllt4->Fill(hittypeval);
00687                   goodlayer_cllt4->Fill(layerval);
00688                 }
00689                 //LogTrace("TestOutliers") << "hittypeval && clustersize";                
00690                 if (hittypeval==1 && clustersize>=4) goodpixgteq4_simvecsize->Fill(assSimHits.size());
00691                 if (hittypeval==1 && clustersize<4 ) goodpixlt4_simvecsize->Fill(assSimHits.size());
00692                 if (hittypeval==2 && clustersize>=4) goodst1gteq4_simvecsize->Fill(assSimHits.size());
00693                 if (hittypeval==2 && clustersize<4 ) goodst1lt4_simvecsize->Fill(assSimHits.size());
00694                 if (hittypeval==3 && clustersize>=4) goodst2gteq4_simvecsize->Fill(assSimHits.size());
00695                 if (hittypeval==3 && clustersize<4 ) goodst2lt4_simvecsize->Fill(assSimHits.size());
00696                 if (hittypeval==4 && clustersize>=4) goodprjgteq4_simvecsize->Fill(assSimHits.size());
00697                 if (hittypeval==4 && clustersize<4 ) goodprjlt4_simvecsize->Fill(assSimHits.size());
00698                   
00699                 //LogTrace("TestOutliers") << "hittypeval";               
00700                 if (hittypeval==1) goodpix_clustersize->Fill(clustersize);
00701                 if (hittypeval==2) goodst1_clustersize->Fill(clustersize);
00702                 if (hittypeval==3) goodst2_clustersize->Fill(clustersize);
00703                 if (hittypeval==4) goodprj_clustersize->Fill(clustersize);
00704                 if (hittypeval==1) goodpix_simvecsize->Fill(assSimHits.size());
00705                 if (hittypeval==2) goodst1_simvecsize->Fill(assSimHits.size());
00706                 if (hittypeval==3) goodst2_simvecsize->Fill(assSimHits.size());
00707                 if (hittypeval==4) goodprj_simvecsize->Fill(assSimHits.size());
00708                                   
00709                 //LogTrace("TestOutliers") << "nOfTrackIds";              
00710                 nOfTrackIds->Fill(nIds);
00711                 if (hittypeval!=3) { 
00712                   if (energyLossM.size()>1) {
00713                     sort(energyLossM.begin(),energyLossM.end(),greater<double>());
00714                     energyLossRatio->Fill(energyLossM[1]/energyLossM[0]);
00715                   }
00716                 } else {
00717                   //LogTrace("TestOutliers") << "hittypeval==3";                  
00718                   if (energyLossM.size()>1&&energyLossS.size()<=1) {
00719                     sort(energyLossM.begin(),energyLossM.end(),greater<double>());
00720                     energyLossRatio->Fill(energyLossM[1]/energyLossM[0]);
00721                   }
00722                   else if (energyLossS.size()>1&&energyLossM.size()<=1) {
00723                     sort(energyLossS.begin(),energyLossS.end(),greater<double>());
00724                     energyLossRatio->Fill(energyLossS[1]/energyLossS[0]);
00725                   }
00726                   else if (energyLossS.size()>1&&energyLossM.size()>1) {
00727                     sort(energyLossM.begin(),energyLossM.end(),greater<double>());
00728                     sort(energyLossS.begin(),energyLossS.end(),greater<double>());
00729                     energyLossM[1]/energyLossM[0] > energyLossS[1]/energyLossS[0] 
00730                       ? energyLossRatio->Fill(energyLossM[1]/energyLossM[0]) 
00731                       : energyLossRatio->Fill(energyLossS[1]/energyLossS[0]);
00732                   }
00733                 }
00734                   
00735                 LogTrace("TestOutliers") << "before merged";              
00736                 const SiStripMatchedRecHit2D* tmp = dynamic_cast<const SiStripMatchedRecHit2D*>(&**itHit);
00737                 LogTrace("TestOutliers") << "tmp=" << tmp; 
00738                 LogTrace("TestOutliers") << "assSimHits.size()=" << assSimHits.size(); 
00739                 if ( (assSimHits.size()>1 && tmp==0) || 
00740                      (assSimHits.size()>2 && tmp!=0) ) {
00741                   //std::cout << "MERGED HIT" << std::endl;
00742                   //LogTrace("TestOutliers") << "merged";                 
00743                   mergedlayer->Fill(layerval);
00744                   mergedcluster->Fill(clustersize);
00745                   mergedhittype->Fill(hittypeval);
00746 
00747                   for(std::vector<PSimHit>::const_iterator m=assSimHits.begin(); m<assSimHits.end(); m++){
00748                     unsigned int tId = m->trackId();
00749                     LogTrace("TestOutliers") << "component with id=" << tId <<  " eLoss=" << m->energyLoss() 
00750                                              << " proc=" <<  m->processType() << " part=" <<  m->particleType();
00751                     if (find(tpids.begin(),tpids.end(),tId)==tpids.end()) continue;
00752                     if (m->processType()==2) {
00753                       //GlobalPoint gpos = theG->idToDet((*itHit)->geographicalId())->surface().toGlobal((*itHit)->localPosition());
00754                       //GlobalPoint gpr = rhit->globalPosition();
00755                       AlgebraicSymMatrix ger = 
00756                         ErrorFrameTransformer().transform((*itHit)->localPositionError(),theG->idToDet((*itHit)->geographicalId())->surface() ).matrix();
00757                       //AlgebraicSymMatrix ger = rhit->globalPositionError().matrix();
00758                       GlobalPoint gps = theG->idToDet((*itHit)->geographicalId())->surface().toGlobal(m->localPosition());
00759                       //LogTrace("TestOutliers") << gpr << " " << gps << " " << ger;
00760                       CLHEP::HepVector delta(3);
00761                       delta[0]=gpos.x()-gps.x();
00762                       delta[1]=gpos.y()-gps.y();
00763                       delta[2]=gpos.z()-gps.z();
00764                       LogTrace("TestOutliers") << delta << " " << ger ;
00765                       double mpull = sqrt(delta[0]*delta[0]/ger[0][0]+delta[1]*delta[1]/ger[1][1]+delta[2]*delta[2]/ger[2][2]);
00766                       LogTrace("TestOutliers") << "hit pull=" << mpull;//ger.similarity(delta);
00767                       mergedPull->Fill(mpull);
00768                     }
00769                   }
00770                   LogTrace("TestOutliers") << "end merged";
00771                 } else {//not merged=>good
00772                   //LogTrace("TestOutliers") << "goodlayer";              
00773                   goodlayer->Fill(layerval);              
00774                   goodcluster->Fill(clustersize);
00775                   goodhittype->Fill(hittypeval);
00776                 }       
00777               }//if (outlier)
00778 
00779               const SiPixelRecHit* pix = dynamic_cast<const SiPixelRecHit*>(&**itHit);
00780               if ((hittypeval!=3 && assSimHits.size()<2)||(hittypeval==3 && assSimHits.size()<3)){
00781                 if (outlier) {
00782                   goodhittype_simvecsmall->Fill(hittypeval);
00783                   goodlayer_simvecsmall->Fill(layerval);
00784                   goodbadmerged->Fill(1);
00785                   if (pix) {
00786                     probXgood->Fill(pix->probabilityX());
00787                     probYgood->Fill(pix->probabilityY());
00788                   }
00789                   LogTrace("TestOutliers") << "out good";                 
00790                 }
00791                 else if (lost){
00792                   goodbadmergedLost->Fill(1);
00793                   LogTrace("TestOutliers") << "lost good";                
00794                 }
00795                 else if (gained){
00796                   goodbadmergedGained->Fill(1);
00797                   LogTrace("TestOutliers") << "gained good";              
00798                 }
00799                 LogTrace("TestOutliers") << "good"; 
00800               } else {
00801                 if (outlier) {
00802                   goodhittype_simvecbig->Fill(hittypeval);
00803                   goodlayer_simvecbig->Fill(layerval);
00804                   if (ioniOnly&&!shared) { 
00805                     goodbadmerged->Fill(3);
00806                     if (pix) {
00807                       probXdelta->Fill(pix->probabilityX());
00808                       probYdelta->Fill(pix->probabilityY());
00809                     }
00810                   } else if(!ioniOnly&&!shared) {
00811                     goodbadmerged->Fill(4);
00812                     if (pix) {
00813                       probXnoshare->Fill(pix->probabilityX());
00814                       probYnoshare->Fill(pix->probabilityY());
00815                     }
00816                   } else {
00817                     goodbadmerged->Fill(5);
00818                     if (pix) {
00819                       probXshared->Fill(pix->probabilityX());
00820                       probYshared->Fill(pix->probabilityY());
00821                     }
00822                   }
00823                   LogTrace("TestOutliers") << "out merged, ioniOnly=" << ioniOnly << " shared=" << shared;
00824                 }
00825                 else if (lost) {
00826                   if (ioniOnly&&!shared) goodbadmergedLost->Fill(3);
00827                   else if(!ioniOnly&&!shared) goodbadmergedLost->Fill(4);
00828                   else goodbadmergedLost->Fill(5);
00829                   LogTrace("TestOutliers") << "lost merged, ioniOnly=" << ioniOnly << " shared=" << shared;
00830                 }
00831                 else if (gained) {
00832                   if (ioniOnly&&!shared) goodbadmergedGained->Fill(3);
00833                   else if(!ioniOnly&&!shared) goodbadmergedGained->Fill(4);
00834                   else goodbadmergedGained->Fill(5);
00835                   LogTrace("TestOutliers") << "gained merged, ioniOnly=" << ioniOnly << " shared=" << shared;
00836                 }
00837                 LogTrace("TestOutliers") << "merged, ioniOnly=" << ioniOnly << " shared=" << shared;
00838               }
00839             } //if (goodhit)
00840             else {//badhit
00841               //LogTrace("TestOutliers") << "badhit";   
00842               if (outlier) {
00843                 badcluster->Fill(clustersize);
00844                 badhittype->Fill(hittypeval);
00845                 badlayer->Fill(layerval);
00846                 badprocess->Fill(shit.processType());
00847                 goodbadmerged->Fill(2);
00848                 const SiPixelRecHit* pix = dynamic_cast<const SiPixelRecHit*>(&**itHit);
00849                 if (pix) {
00850                   probXbad->Fill(pix->probabilityX());
00851                   probYbad->Fill(pix->probabilityY());
00852                 }
00853                 LogTrace("TestOutliers") << "out bad";            
00854               }
00855               else if (lost) {
00856                 goodbadmergedLost->Fill(2);
00857                 LogTrace("TestOutliers") << "lost bad";           
00858               }
00859               else if (gained) {
00860                 goodbadmergedGained->Fill(2);
00861                 LogTrace("TestOutliers") << "gained bad";                 
00862               }
00863               LogTrace("TestOutliers") << "bad"; 
00864             }
00865           }
00866         }
00867       } 
00868       //else if ( trackOut->numberOfValidHits() > trackOld->numberOfValidHits() ) {
00869       else if ( 0 ) {
00870         LogTrace("TestOutliers") << "outliers for track with #hits=" << trackOut->numberOfValidHits();
00871         tracks->Fill(1);
00872         LogTrace("TestOutliers") << "Out->pt=" << trackOut->pt() << " Old->pt=" << trackOld->pt() 
00873                                  << " tp->pt=" << sqrt(tpr->momentum().perp2()) 
00874           //<< " trackOut->ptError()=" << trackOut->ptError() << " trackOld->ptError()=" << trackOld->ptError() 
00875                                  << " Old->validHits=" << trackOld->numberOfValidHits() << " Out->validHits=" << trackOut->numberOfValidHits()
00876           /*<< " fracOld=" << fracOld*/ << " fracOut=" << fracOut
00877                                  << " deltaHits=" << trackOld->numberOfValidHits()-trackOut->numberOfValidHits();
00878         LogTrace("TestOutliers") << "track with gained hits";
00879         gainedhits2->Fill(trackOut->numberOfValidHits()-trackOld->numberOfValidHits()); 
00880       } else {
00881         LogTrace("TestOutliers") << "no outliers for track with #hits=" << trackOut->numberOfValidHits();
00882       }
00883     }
00884     LogTrace("TestOutliers") << "end track old #" << j;
00885   }  
00886 
00887   for (unsigned int k=0;k<tracksOut->size();++k) {
00888     if ( find(outused.begin(),outused.end(),k)==outused.end() ) {
00889       edm::RefToBase<reco::Track> trackOut(tracksOut, k);      
00890       bool outAssoc = recSimCollOut.find(trackOut) != recSimCollOut.end();
00891       if (outAssoc) {
00892         hitsPerTrackGained->Fill(trackOut->numberOfValidHits());
00893         LogTrace("TestOutliers") << "gained track out id=" << k << " #hits==" << trackOut->numberOfValidHits();    
00894 
00895       }
00896     }    
00897   }
00898   delete hitAssociator;
00899   delete theAssociatorOld;
00900   delete theAssociatorOut;
00901 }
00902 
00903 
00904 // ------------ method called once each job just before starting event loop  ------------
00905 void 
00906 TestOutliers::beginRun(edm::Run & run, const edm::EventSetup& es)
00907 {
00908   es.get<TrackerDigiGeometryRecord>().get(theG);
00909   const bool oldAddDir = TH1::AddDirectoryStatus();
00910   TH1::AddDirectory(true);
00911   file = new TFile(out.c_str(),"recreate");
00912   histoPtOut = new TH1F("histoPtOut","histoPtOut",100,-10,10);
00913   histoPtOld = new TH1F("histoPtOld","histoPtOld",100,-10,10);
00914   histoQoverpOut = new TH1F("histoQoverpOut","histoQoverpOut",250,-25,25);
00915   histoQoverpOld = new TH1F("histoQoverpOld","histoQoverpOld",250,-25,25);
00916   histoPhiOut = new TH1F("histoPhiOut","histoPhiOut",250,-25,25);
00917   histoPhiOld = new TH1F("histoPhiOld","histoPhiOld",250,-25,25);
00918   histoD0Out = new TH1F("histoD0Out","histoD0Out",250,-25,25);
00919   histoD0Old = new TH1F("histoD0Old","histoD0Old",250,-25,25);
00920   histoDzOut = new TH1F("histoDzOut","histoDzOut",250,-25,25);
00921   histoDzOld = new TH1F("histoDzOld","histoDzOld",250,-25,25);
00922   histoLambdaOut = new TH1F("histoLambdaOut","histoLambdaOut",250,-25,25);
00923   histoLambdaOld = new TH1F("histoLambdaOld","histoLambdaOld",250,-25,25);
00924   deltahits = new TH1F("deltahits","deltahits",80,-40,40);
00925   deltahitsOK = new TH1F("deltahitsOK","deltahitsOK",20,0,20);
00926   deltahitsNO = new TH1F("deltahitsNO","deltahitsNO",20,0,20);
00927   okcutsOut = new TH1F("okcutsOut","okcutsOut",2,-0.5,1.5);
00928   okcutsOld = new TH1F("okcutsOld","okcutsOld",2,-0.5,1.5);
00929   tracks = new TH1F("tracks_","tracks_",2,-0.5,1.5);
00930   goodbadhits = new TH1F("goodbadhits","goodbadhits",2,-0.5,1.5);
00931   process = new TH1F("process","process",20,-0.5,19.5);
00932   goodcluster = new TH1F("goodcluster","goodcluster",40,-0.5,39.5);
00933   goodprocess = new TH1F("goodprocess","goodprocess",20,-0.5,19.5);
00934   badcluster = new TH1F("badcluster","badcluster",40,-0.5,39.5);
00935   badprocess = new TH1F("badprocess","badprocess",20,-0.5,19.5);
00936   goodhittype = new TH1F("goodhittype","goodhittype",5,-0.5,4.5);
00937   goodlayer = new TH1F("goodlayer","goodlayer",70,-0.5,69.5);
00938   goodhittype_clgteq4 = new TH1F("goodhittype_clgteq4","goodhittype_clgteq4",5,-0.5,4.5);
00939   goodlayer_clgteq4 = new TH1F("goodlayer_clgteq4","goodlayer_clgteq4",70,-0.5,69.5);
00940   goodhittype_cllt4 = new TH1F("goodhittype_cllt4","goodhittype_cllt4",5,-0.5,4.5);
00941   goodlayer_cllt4 = new TH1F("goodlayer_cllt4","goodlayer_cllt4",70,-0.5,69.5);
00942   badhittype = new TH1F("badhittype","badhittype",5,-0.5,4.5);
00943   badlayer = new TH1F("badlayer","badlayer",70,-0.5,69.5);
00944   posxy = new TH2F("posxy","posxy",1200,0,120,1200,0,120);
00945   poszr = new TH2F("poszr","poszr",3000,0,300,1200,0,120);
00946   goodpixgteq4_simvecsize = new TH1F("goodpixgteq4_simvecsize","goodpixgteq4_simvecsize",40,-0.5,39.5);
00947   goodpixlt4_simvecsize  = new TH1F("goodpixlt4_simvecsize","goodpixlt4_simvecsize",40,-0.5,39.5);
00948   goodst1gteq4_simvecsize = new TH1F("goodst1gteq4_simvecsize","goodst1gteq4_simvecsize",40,-0.5,39.5);
00949   goodst1lt4_simvecsize  = new TH1F("goodst1lt4_simvecsize","goodst1lt4_simvecsize",40,-0.5,39.5);
00950   goodst2gteq4_simvecsize = new TH1F("goodst2gteq4_simvecsize","goodst2gteq4_simvecsize",40,-0.5,39.5);
00951   goodst2lt4_simvecsize  = new TH1F("goodst2lt4_simvecsize","goodst2lt4_simvecsize",40,-0.5,39.5);
00952   goodprjgteq4_simvecsize = new TH1F("goodprjgteq4_simvecsize","goodprjgteq4_simvecsize",40,-0.5,39.5);
00953   goodprjlt4_simvecsize  = new TH1F("goodprjlt4_simvecsize","goodprjlt4_simvecsize",40,-0.5,39.5);
00954   goodpix_clustersize = new TH1F("goodpix_clustersize","goodpix_clustersize",40,-0.5,39.5);
00955   goodst1_clustersize = new TH1F("goodst1_clustersize","goodst1_clustersize",40,-0.5,39.5);
00956   goodst2_clustersize = new TH1F("goodst2_clustersize","goodst2_clustersize",40,-0.5,39.5);
00957   goodprj_clustersize = new TH1F("goodprj_clustersize","goodprj_clustersize",40,-0.5,39.5);
00958   goodpix_simvecsize = new TH1F("goodpix_simvecsize","goodpix_simvecsize",40,-0.5,39.5);
00959   goodst1_simvecsize = new TH1F("goodst1_simvecsize","goodst1_simvecsize",40,-0.5,39.5);
00960   goodst2_simvecsize = new TH1F("goodst2_simvecsize","goodst2_simvecsize",40,-0.5,39.5);
00961   goodprj_simvecsize = new TH1F("goodprj_simvecsize","goodprj_simvecsize",40,-0.5,39.5);
00962   goodhittype_simvecsmall = new TH1F("goodhittype_simvecsmall","goodhittype_simvecsmall",5,-0.5,4.5);
00963   goodlayer_simvecsmall = new TH1F("goodlayer_simvecsmall","goodlayer_simvecsmall",70,-0.5,69.5);
00964   goodhittype_simvecbig = new TH1F("goodhittype_simvecbig","goodhittype_simvecbig",5,-0.5,4.5);
00965   goodlayer_simvecbig = new TH1F("goodlayer_simvecbig","goodlayer_simvecbig",70,-0.5,69.5);
00966   goodbadmerged = new TH1F("goodbadmerged","goodbadmerged",5,0.5,5.5);
00967   goodbadmergedLost = new TH1F("goodbadmergedLost","goodbadmergedLost",5,0.5,5.5);
00968   goodbadmergedGained = new TH1F("goodbadmergedGained","goodbadmergedGained",5,0.5,5.5);
00969   energyLoss = new TH1F("energyLoss","energyLoss",1000,0,0.1);
00970   energyLossMax = new TH1F("energyLossMax","energyLossMax",1000,0,0.1);
00971   energyLossRatio = new TH1F("energyLossRatio","energyLossRatio",100,0,1);
00972   nOfTrackIds = new TH1F("nOfTrackIds","nOfTrackIds",10,0,10);
00973   mergedPull = new TH1F("mergedPull","mergedPull",100,0,10);
00974   mergedlayer = new TH1F("mergedlayer","mergedlayer",70,-0.5,69.5);
00975   mergedhittype = new TH1F("mergedhittype","mergedhittype",5,-0.5,4.5);
00976   mergedcluster = new TH1F("mergedcluster","mergedcluster",40,-0.5,39.5);
00977   deltahitsAssocGained = new TH1F("deltahitsAssocGained","deltahitsAssocGained",80, -40, 40);
00978   deltahitsAssocLost = new TH1F("deltahitsAssocLost","deltahitsAssocLost",80, -40, 40);
00979   hitsPerTrackLost = new TH1F("hitsPerTrackLost","hitsPerTrackLost",40, -0.5, 39.5);
00980   hitsPerTrackAssocLost = new TH1F("hitsPerTrackAssocLost","hitsPerTrackAssocLost",40, -0.5, 39.5);
00981   hitsPerTrackGained = new TH1F("hitsPerTrackGained","hitsPerTrackGained",40, -0.5, 39.5);
00982   hitsPerTrackAssocGained = new TH1F("hitsPerTrackAssocGained","hitsPerTrackAssocGained",40, -0.5, 39.5);
00983   sizeOut = new TH1F("sizeOut","sizeOut",900,-0.5,899.5);
00984   sizeOld = new TH1F("sizeOld","sizeOld",900,-0.5,899.5);
00985   sizeOutT = new TH1F("sizeOutT","sizeOutT",900,-0.5,899.5);
00986   sizeOldT = new TH1F("sizeOldT","sizeOldT",900,-0.5,899.5);
00987   countOutA = new TH1F("countOutA","countOutA",2,0,2);
00988   countOutT = new TH1F("countOutT","countOutT",2,0,2);
00989   countOldT = new TH1F("countOldT","countOldT",2,0,2);
00990   gainedhits = new TH1F("gainedhits","gainedhits",2,0,2);
00991   gainedhits2 = new TH1F("gainedhits2","gainedhits2",30,-0.5,29.5);
00992   probXgood = new TH1F("probXgood","probXgood",110,0,1.1);
00993   probXbad = new TH1F("probXbad","probXbad",110,0,1.1);
00994   probXdelta = new TH1F("probXdelta","probXdelta",110,0,1.1);
00995   probXshared = new TH1F("probXshared","probXshared",110,0,1.1);
00996   probXnoshare = new TH1F("probXnoshare","probXnoshare",110,0,1.1);
00997   probYgood = new TH1F("probYgood","probYgood",110,0,1.1);
00998   probYbad = new TH1F("probYbad","probYbad",110,0,1.1);
00999   probYdelta = new TH1F("probYdelta","probYdelta",110,0,1.1);
01000   probYshared = new TH1F("probYshared","probYshared",110,0,1.1);
01001   probYnoshare = new TH1F("probYnoshare","probYnoshare",110,0,1.1);
01002   TH1::AddDirectory(oldAddDir);
01003 }
01004 // ------------ method called once each job just after ending the event loop  ------------
01005 void 
01006 TestOutliers::endJob() {
01007   LogTrace("TestOutliers") << "TestOutliers::endJob";
01008   file->Write();
01009   LogTrace("TestOutliers") << "outfile written";
01010   file->Close();
01011   LogTrace("TestOutliers") << "oufile closed";
01012   LogTrace("TestOutliers") << "exiting TestOutliers::endJob";
01013 }
01014 
01015 //define this as a plug-in
01016 DEFINE_FWK_MODULE(TestOutliers);