CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/SUSYBSMAnalysis/HSCP/src/HSCPValidator.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HSCP
00004 // Class:      HSCPValidator
00005 // 
00013 //
00014 // Original Author:  Seth Cooper,27 1-024,+41227672342,
00015 //         Created:  Wed Apr 14 14:27:52 CEST 2010
00016 // $Id: HSCPValidator.cc,v 1.7 2011/04/08 23:20:41 gowdy Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <vector>
00024 #include <string>
00025 #include <map>
00026 
00027 // user include files
00028 #include "FWCore/ServiceRegistry/interface/Service.h"
00029 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00030 #include "DataFormats/Common/interface/Handle.h"
00031 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00032 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00033 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00034 #include "DataFormats/RPCDigi/interface/RPCDigi.h"
00035 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00036 #include "DataFormats/RPCRecHit/interface/RPCRecHit.h"
00037 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00038 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00039 #include <DataFormats/GeometrySurface/interface/LocalError.h>
00040 #include <DataFormats/GeometryVector/interface/LocalPoint.h>
00041 #include "DataFormats/GeometrySurface/interface/Surface.h"
00042 #include "DataFormats/DetId/interface/DetId.h"
00043 #include "DataFormats/Candidate/interface/Candidate.h"
00044 #include "DataFormats/Candidate/interface/CandMatchMap.h"
00045 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00046 #include <DataFormats/GeometrySurface/interface/LocalError.h>
00047 #include <DataFormats/GeometryVector/interface/LocalPoint.h>
00048 #include "DataFormats/GeometrySurface/interface/Surface.h"
00049 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00050 #include "FastSimulation/Tracking/test/FastTrackAnalyzer.h"
00051 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00052 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00053 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00054 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00055 #include <Geometry/RPCGeometry/interface/RPCGeometry.h>
00056 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00057 #include <Geometry/Records/interface/MuonGeometryRecord.h>
00058 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00059 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00060 #include "MagneticField/Engine/interface/MagneticField.h"
00061 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00062 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00063 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00064 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00065 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
00066 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00067 #include "SimDataFormats/Track/interface/SimTrack.h"
00068 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00069 #include "SimDataFormats/Vertex/interface/SimVertex.h"
00070 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00071 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00072 #include "SUSYBSMAnalysis/HSCP/interface/HSCPValidator.h"
00073 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00074 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00075 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00076 #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
00077 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00078 
00079 
00080 
00081 #include "TH1.h"
00082 #include "TGraph.h"
00083 #include "TCanvas.h"
00084 
00085 //
00086 // constants, enums and typedefs
00087 //
00088 
00089 //
00090 // static data member definitions
00091 //
00092 edm::Service<TFileService> fileService;
00093 
00094 //
00095 // constructors and destructor
00096 //
00097 HSCPValidator::HSCPValidator(const edm::ParameterSet& iConfig) :
00098   doGenPlots_ (iConfig.getParameter<bool>("MakeGenPlots")),
00099   doHLTPlots_ (iConfig.getParameter<bool>("MakeHLTPlots")),
00100   doSimTrackPlots_ (iConfig.getParameter<bool>("MakeSimTrackPlots")),
00101   doSimDigiPlots_ (iConfig.getParameter<bool>("MakeSimDigiPlots")),
00102   doRecoPlots_ (iConfig.getParameter<bool>("MakeRecoPlots")),
00103   label_ (iConfig.getParameter<edm::InputTag>("generatorLabel")),
00104   particleIds_ (iConfig.getParameter< std::vector<int> >("particleIds")),
00105   particleStatus_ (iConfig.getUntrackedParameter<int>("particleStatus",1)),
00106   ebSimHitTag_ (iConfig.getParameter<edm::InputTag>("EBSimHitCollection")),
00107   eeSimHitTag_ (iConfig.getParameter<edm::InputTag>("EESimHitCollection")),
00108   simTrackTag_ (iConfig.getParameter<edm::InputTag>("SimTrackCollection")),
00109   EBDigiCollection_ (iConfig.getParameter<edm::InputTag>("EBDigiCollection")),
00110   EEDigiCollection_ (iConfig.getParameter<edm::InputTag>("EEDigiCollection")),
00111   RPCRecHitTag_ (iConfig.getParameter<edm::InputTag>("RPCRecHitTag"))
00112 {
00113   //now do what ever initialization is needed
00114   // GEN
00115   particleEtaHist_ = fileService->make<TH1F>("particleEta","Eta of gen particle",100,-5,5);
00116   particlePhiHist_ = fileService->make<TH1F>("particlePhi","Phi of gen particle",180,-3.15,3.15);
00117   particlePHist_ = fileService->make<TH1F>("particleP","Momentum of gen particle",500,0,2000);
00118   particlePtHist_ = fileService->make<TH1F>("particlePt","P_{T} of gen particle",500,0,2000);
00119   particleMassHist_ = fileService->make<TH1F>("particleMass","Mass of gen particle",1000,0,2000);
00120   particleStatusHist_ = fileService->make<TH1F>("particleStatus","Status of gen particle",10,0,10);
00121   particleBetaHist_ = fileService->make<TH1F>("particleBeta","Beta of gen particle",100,0,1);
00122   particleBetaInverseHist_ = fileService->make<TH1F>("particleBetaInverse","1/#beta of gen particle",100,0,5);
00123   
00124   h_genhscp_met = fileService->make<TH1F>( "hscp_met"  , "missing E_{T} hscp" , 100, 0., 1500. );
00125   h_genhscp_met_nohscp = fileService->make<TH1F>( "hscp_met_nohscp"  , "missing E_{T} w/o hscp" , 100, 0., 1500. );
00126   h_genhscp_scaloret =  fileService->make<TH1F>( "hscp_scaloret"  , "scalor E_{T} sum" , 100, 0., 1500. );
00127   h_genhscp_scaloret_nohscp =  fileService->make<TH1F>( "hscp_scaloret_nohscp"  , "scalor E_{T} sum w/o hscp" , 100, 0., 1500. );
00128 
00129 
00130 
00131 
00132   //SIM track Info
00133   simTrackParticleEtaHist_ = fileService->make<TH1F>("simTrackParticleEta","Eta of simTrackParticle",100,-5,5);
00134   simTrackParticlePhiHist_ = fileService->make<TH1F>("simTrackParticlePhi","Phi of simTrackParticle",180,-3.15,3.15);
00135   simTrackParticlePHist_ = fileService->make<TH1F>("simTrackParticleP","Momentum of simTrackParticle",500,0,2000);
00136   simTrackParticlePtHist_ = fileService->make<TH1F>("simTrackParticlePt","P_{T} of simTrackParticle",500,0,2000);
00137   simTrackParticleBetaHist_ = fileService->make<TH1F>("simTrackParticleBeta","Beta of simTrackParticle",100,0,1);
00138 
00139 //HLT Info
00140   hltmet100_ = fileService->make<TH1F>("HLT_MET100","MET100",3,-1,2);
00141   hltjet140_ = fileService->make<TH1F>("HLT_JET140","JET140",3,-1,2);
00142   hltmu15_ = fileService->make<TH1F>("HLT_Mu15","Mu15",3,-1,2);
00143 
00144 
00145   // SIM-DIGI: ECAL
00146   simHitsEcalEnergyHistEB_ = fileService->make<TH1F>("ecalEnergyOfSimHitsEB","HSCP SimTrack-matching SimHit energy EB [GeV]",125,-1,4);
00147   simHitsEcalEnergyHistEE_ = fileService->make<TH1F>("ecalEnergyOfSimHitsEE","HSCP SimTrack-matching SimHit energy EE [GeV]",125,-1,4);
00148   simHitsEcalTimeHistEB_ = fileService->make<TH1F>("ecalTimingOfSimHitsEB","HSCP SimTrack-matching SimHit time EB [ns]",115,-15,100);
00149   simHitsEcalTimeHistEE_ = fileService->make<TH1F>("ecalTimingOfSimHitsEE","HSCP SimTrack-matching SimHit time EE [ns]",115,-15,100);
00150   simHitsEcalNumHistEB_ = fileService->make<TH1F>("ecalNumberOfSimHitsEB","Number of HSCP SimTrack-matching EB sim hits in event",100,0,200);
00151   simHitsEcalNumHistEE_ = fileService->make<TH1F>("ecalNumberOfSimHitsEE","Number of HSCP SimTrack-matching EE sim hits in event",100,0,200);
00152   simHitsEcalEnergyVsTimeHistEB_ = fileService->make<TH2F>("ecalEnergyVsTimeOfSimHitsEB","Energy vs. time of HSCP SimTrack-matching EB sim hits in event",115,-15,100,125,-1,4);
00153   simHitsEcalEnergyVsTimeHistEE_ = fileService->make<TH2F>("ecalEnergyVsTimeOfSimHitsEE","Energy vs. time of HSCP SimTrack-matching EE sim hits in event",115,-15,100,125,-1,4);
00154   simHitsEcalDigiMatchEnergyHistEB_ = fileService->make<TH1F>("ecalEnergyOfDigiMatSimHitsEB","HSCP digi-matching SimHit energy EB [GeV]",125,-1,4);
00155   simHitsEcalDigiMatchEnergyHistEE_ = fileService->make<TH1F>("ecalEnergyOfDigiMatSimHitsEE","HSCP digi-matching SimHit energy EE [GeV]",125,-1,4);
00156   simHitsEcalDigiMatchTimeHistEB_ = fileService->make<TH1F>("ecalTimingOfDigiMatSimHitsEB","HSCP digi-matching SimHit time EB [ns]",115,-15,100);
00157   simHitsEcalDigiMatchTimeHistEE_ = fileService->make<TH1F>("ecalTimingOfDigiMatSimHitsEE","HSCP digi-matching SimHit time EE [ns]",115,-15,100);
00158   simHitsEcalDigiMatchEnergyVsTimeHistEB_ = fileService->make<TH2F>("ecalEnergyVsTimeOfDigiMatSimHitsEB","HSCP digi-matching EB SimHit energy vs. time",115,-15,100,125,-1,4);
00159   simHitsEcalDigiMatchEnergyVsTimeHistEE_ = fileService->make<TH2F>("ecalEnergyVsTimeOfDigiMatSimHitsEE","HSCP digi-matching EE SimHit energy vs. time",115,-15,100,125,-1,4);
00160   simHitsEcalDigiMatchIEtaHist_ = fileService->make<TH1F>("ecalIEtaOfDigiMatchSimHits","iEta of digi-matching Ecal simHits (EB)",171,-85,86);
00161   simHitsEcalDigiMatchIPhiHist_ = fileService->make<TH1F>("ecalIPhiOfDigiMatchSimHits","iPhi of digi-matching Ecal simHits (EB)",360,1,361);
00162   digisEcalNumHistEB_ = fileService->make<TH1F>("ecalDigisNumberEB","Number of EB digis matching simhits in event",200,0,1000);
00163   digisEcalNumHistEE_ = fileService->make<TH1F>("ecalDigisNumberEE","Number of EE digis matching simhits in event",200,0,1000);
00164   digiOccupancyMapEB_ = fileService->make<TH2F>("ecalDigiOccupancyMapEB","Occupancy of simhit-matching digis EB;i#phi;i#eta",360,1,361,171,-85,86);
00165   digiOccupancyMapEEP_ = fileService->make<TH2F>("ecalDigiOccupancyMapEEM","Occupancy of simhit-matching digis EEM;ix;iy",100,1,100,100,1,100);
00166   digiOccupancyMapEEM_ = fileService->make<TH2F>("ecalDigiOccupancyMapEEP","Occupancy of simhit-matching digis EEP;ix;iy",100,1,100,100,1,100);
00167 
00168   // SIM-DIGI: RPC
00169   residualsRPCRecHitSimDigis_ = fileService->make<TH1F>("residualsRPCRecHitSimDigis","HSCP SimHit - Clossest RPC RecHit",100,-5,5);
00170   efficiencyRPCRecHitSimDigis_ = fileService->make<TH1F>("efficiencyRPCRecHitSimDigis","HSCP SimHits RecHits Efficiency",2,-0.5,1.5);
00171   cluSizeDistribution_ = fileService->make<TH1F>("RPCCluSizeDistro","RPC HSCP CluSize Distribution",11,-0.5,10.5);
00172   rpcTimeOfFlightBarrel_[0] = fileService->make<TH1F>("RPCToFLayer1","RPC HSCP Time Of Flight Layer 1",50,5,100);
00173   rpcTimeOfFlightBarrel_[1] = fileService->make<TH1F>("RPCToFLayer2","RPC HSCP Time Of Flight Layer 2",50,5,100);
00174   rpcTimeOfFlightBarrel_[2] = fileService->make<TH1F>("RPCToFLayer3","RPC HSCP Time Of Flight Layer 3",50,5,100);
00175   rpcTimeOfFlightBarrel_[3] = fileService->make<TH1F>("RPCToFLayer4","RPC HSCP Time Of Flight Layer 4",50,5,100);
00176   rpcTimeOfFlightBarrel_[4] = fileService->make<TH1F>("RPCToFLayer5","RPC HSCP Time Of Flight Layer 5",50,5,100);
00177   rpcTimeOfFlightBarrel_[5] = fileService->make<TH1F>("RPCToFLayer6","RPC HSCP Time Of Flight Layer 6",50,5,100);
00178   rpcBXBarrel_[0] = fileService->make<TH1F>("RPCBXLayer1","RPC HSCP BX Layer 1",5,-0.5,4.5);
00179   rpcBXBarrel_[1] = fileService->make<TH1F>("RPCBXLayer2","RPC HSCP BX Layer 2",5,-0.5,4.5);
00180   rpcBXBarrel_[2] = fileService->make<TH1F>("RPCBXLayer3","RPC HSCP BX Layer 3",5,-0.5,4.5);
00181   rpcBXBarrel_[3] = fileService->make<TH1F>("RPCBXLayer4","RPC HSCP BX Layer 4",5,-0.5,4.5);
00182   rpcBXBarrel_[4] = fileService->make<TH1F>("RPCBXLayer5","RPC HSCP BX Layer 5",5,-0.5,4.5);
00183   rpcBXBarrel_[5] = fileService->make<TH1F>("RPCBXLayer6","RPC HSCP BX Layer 6",5,-0.5,4.5);
00184   rpcTimeOfFlightEndCap_[0]= fileService->make<TH1F>("RPCToFDisk1","RPC HSCP Time Of Flight Disk 1",50,5,100);
00185   rpcTimeOfFlightEndCap_[1]= fileService->make<TH1F>("RPCToFDisk2","RPC HSCP Time Of Flight Disk 2",50,5,100);
00186   rpcTimeOfFlightEndCap_[2]= fileService->make<TH1F>("RPCToFDisk3","RPC HSCP Time Of Flight Disk 3",50,5,100);
00187   rpcBXEndCap_[0] = fileService->make<TH1F>("RPCBXDisk1","RPC HSCP BX Disk 1",5,-0.5,4.5);
00188   rpcBXEndCap_[1] = fileService->make<TH1F>("RPCBXDisk2","RPC HSCP BX Disk 2",5,-0.5,4.5);
00189   rpcBXEndCap_[2] = fileService->make<TH1F>("RPCBXDisk3","RPC HSCP BX Disk 3",5,-0.5,4.5);
00190 }
00191 
00192 
00193 HSCPValidator::~HSCPValidator()
00194 {
00195  
00196    // do anything here that needs to be done at desctruction time
00197    // (e.g. close files, deallocate resources etc.)
00198 //   particleEtaHist_ = fileService->make<TH1F>("particleEta","Eta of gen particle",100,-5,5);
00199 //   particlePhiHist_ = fileService->make<TH1F>("particlePhi","Phi of gen particle",180,-3.15,3.15);
00200 //   particlePHist_ = fileService->make<TH1F>("particleP","Momentum of gen particle",500,0,2000);
00201 //   particlePtHist_ = fileService->make<TH1F>("particlePt","P_{T} of gen particle",500,0,2000);
00202 //   particleMassHist_ = fileService->make<TH1F>("particleMass","Mass of gen particle",1000,0,2000);
00203 //   particleStatusHist_ = fileService->make<TH1F>("particleStatus","Status of gen particle",10,0,10);
00204 //   particleBetaHist_ = fileService->make<TH1F>("particleBeta","Beta of gen particle",100,0,1);
00205 //   particleBetaInverseHist_ = fileService->make<TH1F>("particleBetaInverse","1/#beta of gen particle",100,0,5);
00206 
00207 }
00208 
00209 
00210 //
00211 // member functions
00212 //
00213 
00214 // ------------ method called to for each event  ------------
00215 void
00216 HSCPValidator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00217 {
00218   using namespace edm;
00219   iSetup.get<MuonGeometryRecord>().get(rpcGeo);
00220 
00221 
00222   if(doGenPlots_)
00223     makeGenPlots(iEvent);
00224   if(doSimTrackPlots_)
00225     makeSimTrackPlots(iEvent);
00226   if(doSimDigiPlots_){
00227     makeSimDigiPlotsECAL(iEvent);
00228     makeSimDigiPlotsRPC(iEvent);
00229   }
00230   if(doHLTPlots_){
00231     makeHLTPlots(iEvent);
00232   }
00233 }
00234 
00235 
00236 // ------------ method called once each job just before starting event loop  ------------
00237 void 
00238 HSCPValidator::beginJob()
00239 {
00240 }
00241 
00242 // ------------ method called once each job just after ending the event loop  ------------
00243 void 
00244 HSCPValidator::endJob()
00245 {
00246   std::string frequencies = "";
00247   for(std::map<int,int>::const_iterator itr = particleIdsFoundMap_.begin();
00248       itr != particleIdsFoundMap_.end(); ++itr)
00249   {
00250       frequencies+="PDG ID: ";
00251       frequencies+=intToString(itr->first);
00252       frequencies+=" Frequency: ";
00253       frequencies+=intToString(itr->second);
00254       frequencies+="\n";
00255   }
00256   std::cout << "Found PDGIds: " << "\n\n" << frequencies << std::endl;
00257 
00258 }
00259 
00260 // ------------- Make gen plots ---------------------------------------------------------
00261 void HSCPValidator::makeGenPlots(const edm::Event& iEvent)
00262 {
00263   using namespace edm;
00264 
00265   double missingpx=0;
00266   double missingpy=0;
00267   double missingpx_nohscp=0;
00268   double missingpy_nohscp=0;
00269   double scalorEt=0;
00270   double scalorEt_nohscp=0;
00271 
00272 
00273   Handle<HepMCProduct> evt;
00274   iEvent.getByLabel(label_, evt);
00275 
00276   HepMC::GenEvent * myGenEvent = new  HepMC::GenEvent(*(evt->GetEvent()));
00277   for(HepMC::GenEvent::particle_iterator p = myGenEvent->particles_begin();
00278       p != myGenEvent->particles_end(); ++p )
00279   {
00280 
00281     if((*p)->status() != particleStatus_)
00282       continue;
00283     //calculate MET(neutrino as MET)
00284     if(abs((*p)->pdg_id())!=12 && abs((*p)->pdg_id())!=14 && abs((*p)->pdg_id())!=16){ //for non-neutrino particles. 
00285        missingpx-=(*p)->momentum().px();
00286        missingpy-=(*p)->momentum().py();
00287        scalorEt+=(*p)->momentum().perp();
00288     }
00289 
00290     // Check if the particleId is in our R-hadron list
00291     std::vector<int>::const_iterator partIdItr = find(particleIds_.begin(),particleIds_.end(),(*p)->pdg_id());
00292     if(partIdItr==particleIds_.end()){
00293        //calculate MET(neutrino+ HSCP as MET)
00294        if(abs((*p)->pdg_id())!=12 && abs((*p)->pdg_id())!=14 && abs((*p)->pdg_id())!=16){ //for non-neutrino particles. 
00295           missingpx_nohscp-=(*p)->momentum().px();
00296           missingpy_nohscp-=(*p)->momentum().py();
00297           scalorEt_nohscp+=(*p)->momentum().perp();
00298         }
00299     }
00300     else{
00301 
00302        particleStatusHist_->Fill((*p)->status());
00303     
00304        std::pair<std::map<int,int>::iterator,bool> pair = particleIdsFoundMap_.insert(std::make_pair<int,int>((*p)->pdg_id(),1));
00305        if(!pair.second)
00306        {
00307           ++(pair.first->second);
00308        }
00309        
00310        double mag = sqrt(pow((*p)->momentum().px(),2) + pow((*p)->momentum().py(),2) + pow((*p)->momentum().pz(),2) );
00311        particleEtaHist_->Fill((*p)->momentum().eta());
00312        particlePhiHist_->Fill((*p)->momentum().phi());
00313        particlePHist_->Fill(mag);
00314        particlePtHist_->Fill((*p)->momentum().perp());
00315        particleMassHist_->Fill((*p)->generated_mass());
00316        float particleP = mag;
00317        float particleM = (*p)->generated_mass();
00318        particleBetaHist_->Fill(particleP/sqrt(particleP*particleP+particleM*particleM));
00319        particleBetaInverseHist_->Fill(sqrt(particleP*particleP+particleM*particleM)/particleP);
00320     }
00321        
00322   }
00323 
00324   h_genhscp_met->Fill(sqrt(missingpx*missingpx+missingpy*missingpy));
00325   h_genhscp_met_nohscp->Fill(sqrt(missingpx_nohscp*missingpx_nohscp+missingpy_nohscp*missingpy_nohscp));
00326   h_genhscp_scaloret->Fill(scalorEt);
00327   h_genhscp_scaloret_nohscp->Fill(scalorEt_nohscp);
00328 
00329 
00330   delete myGenEvent; 
00331 
00332 
00333 
00334 }
00335 
00336 // ------------- Make SimTrack plots ---------------------------------------------------------
00337 void HSCPValidator::makeSimTrackPlots(const edm::Event& iEvent)
00338 {  using namespace edm;
00339   //get sim track infos
00340   Handle<edm::SimTrackContainer> simTracksHandle;
00341   iEvent.getByLabel("g4SimHits",simTracksHandle);
00342   const SimTrackContainer simTracks = *(simTracksHandle.product());
00343 
00344   SimTrackContainer::const_iterator simTrack;
00345 
00346   for (simTrack = simTracks.begin(); simTrack != simTracks.end(); ++simTrack){
00347      // Check if the particleId is in our list
00348      std::vector<int>::const_iterator partIdItr = find(particleIds_.begin(),particleIds_.end(),simTrack->type());
00349      if(partIdItr==particleIds_.end()) continue;
00350 
00351      simTrackParticleEtaHist_->Fill((*simTrack).momentum().eta());
00352      simTrackParticlePhiHist_->Fill((*simTrack).momentum().phi());
00353      simTrackParticlePHist_->Fill((*simTrack).momentum().P());
00354      
00355      simTrackParticlePtHist_->Fill((*simTrack).momentum().pt());
00356      
00357      simTrackParticleBetaHist_->Fill((*simTrack).momentum().P()/(*simTrack).momentum().e());  
00358      
00359 
00360 
00361   }
00362 }
00363 // ------------- Make HLT plots ---------------------------------------------------------
00364 void HSCPValidator::makeHLTPlots(const edm::Event& iEvent)
00365 {
00366   using namespace edm;
00367   //get HLT infos
00368      
00369 
00370       edm::TriggerResultsByName tr = iEvent.triggerResultsByName("HLT");
00371 
00372       if(!tr.isValid()){
00373          std::cout<<"Tirgger Results not available"<<std::endl;
00374        }
00375  
00376 //     std::cout<<"trigger names are : ";
00377 //      for(unsigned int i=0;i<tr.size();i++){
00378 //         std::cout<<" "<<tr.triggerName(i);
00379 //      }
00380 //      std::cout<<std::endl;
00381 
00382    edm::Handle< trigger::TriggerEvent > trEvHandle;
00383    iEvent.getByLabel("hltTriggerSummaryAOD", trEvHandle);
00384    trigger::TriggerEvent trEv = *trEvHandle;
00385 
00386 
00387    unsigned int TrIndex_Unknown     = tr.size();
00388 
00389 
00390    // HLT TRIGGER BASED ON 1 MUON!
00391    if(TrIndex_Unknown != tr.triggerIndex("HLT_Mu15_v1")){
00392       if(tr.accept(tr.triggerIndex("HLT_Mu15_v1"))) hltmu15_->Fill(1);
00393       else hltmu15_->Fill(0);
00394    }else{
00395       if(TrIndex_Unknown != tr.triggerIndex("HLT_Mu11")){
00396          if(IncreasedTreshold(trEv, InputTag("hltSingleMu11L3Filtered11","","HLT"), 15, 1, false))  hltmu15_->Fill(1);
00397          else hltmu15_->Fill(0);
00398       }else{
00399          if(TrIndex_Unknown != tr.triggerIndex("HLT_Mu9")){
00400             if(IncreasedTreshold(trEv, InputTag("hltSingleMu9L3Filtered9","","HLT"), 15, 1, false)) hltmu15_->Fill(1);
00401             else hltmu15_->Fill(0);
00402          }else{           printf("BUG with HLT_Mu15\n");
00403 
00404          }
00405       }
00406    }
00407 
00408  // HLT TRIGGER BASED ON MET!
00409    if(TrIndex_Unknown != tr.triggerIndex("HLT_MET100_v3")){
00410       if(tr.accept(tr.triggerIndex("HLT_MET100_v3")))hltmet100_->Fill(1);
00411       else hltmet100_->Fill(0);
00412    }else{
00413       if(TrIndex_Unknown != tr.triggerIndex("HLT_MET100_v2")){
00414           if(tr.accept(tr.triggerIndex("HLT_MET100_v2"))) hltmet100_->Fill(1);
00415           else hltmet100_->Fill(0);
00416       }else{
00417          if(TrIndex_Unknown != tr.triggerIndex("HLT_MET100")){
00418              if(tr.accept(tr.triggerIndex("HLT_MET100"))) hltmet100_->Fill(1);
00419              else hltmet100_->Fill(0);
00420          }else{
00421            printf("BUG with HLT_MET100\n");
00422 
00423          }
00424       }
00425    }
00426 
00427   // HLT TRIGGER BASED ON 1 JET!
00428    if(TrIndex_Unknown != tr.triggerIndex("HLT_Jet140U_v3")){
00429        if(tr.accept(tr.triggerIndex("HLT_Jet140U_v3")))hltjet140_->Fill(1);
00430        else   hltjet140_->Fill(0);
00431    }else{ 
00432       if(TrIndex_Unknown != tr.triggerIndex("HLT_Jet140U_v1")){
00433           if(tr.accept(tr.triggerIndex("HLT_Jet140U_v1")))hltjet140_->Fill(1);
00434           else   hltjet140_->Fill(0);
00435       }else{
00436          if(TrIndex_Unknown != tr.triggerIndex("HLT_Jet100U")){
00437              if(IncreasedTreshold(trEv, InputTag("hlt1jet100U","","HLT"), 140, 1, false))hltjet140_->Fill(1);
00438              else   hltjet140_->Fill(0);
00439          }else{
00440             if(TrIndex_Unknown != tr.triggerIndex("HLT_Jet70U")){   
00441                if(IncreasedTreshold(trEv, InputTag("hlt1jet70U","","HLT"), 140, 1, false))hltjet140_->Fill(1);
00442                else   hltjet140_->Fill(0);
00443             }else{
00444                if(TrIndex_Unknown != tr.triggerIndex("HLT_Jet50U")){
00445                   if(IncreasedTreshold(trEv, InputTag("hlt1jet50U","","HLT"), 140, 1, false))hltjet140_->Fill(1);
00446                   else   hltjet140_->Fill(0); 
00447                }else{
00448                   printf("BUG with HLT_Jet140\n");
00449 
00450                }
00451             }
00452          }
00453       }
00454    }
00455 
00456 
00457 
00458   
00459 }
00460 
00461 // ------------- Make simDigi plots ECAL ------------------------------------------------
00462 void HSCPValidator::makeSimDigiPlotsECAL(const edm::Event& iEvent)
00463 {
00464   using namespace edm;
00465   // EB SimHits
00466   Handle<PCaloHitContainer> ebSimHits;
00467   iEvent.getByLabel(ebSimHitTag_, ebSimHits);
00468   if(!ebSimHits.isValid())
00469   {
00470     std::cout << "Cannot get EBSimHits from event!" << std::endl;
00471     return;
00472   }
00473   // EE SimHits
00474   Handle<PCaloHitContainer> eeSimHits;
00475   iEvent.getByLabel(eeSimHitTag_, eeSimHits);
00476   if(!eeSimHits.isValid())
00477   {
00478     std::cout << "Cannot get EESimHits from event!" << std::endl;
00479     return;
00480   }
00481   // SimTracks
00482   Handle<SimTrackContainer> simTracks;
00483   iEvent.getByLabel(simTrackTag_,simTracks);
00484   if(!simTracks.isValid())
00485   {
00486     std::cout << "Cannot get SimTracks from event!" << std::endl;
00487     return;
00488   }
00489   // EB Digis
00490   Handle<EBDigiCollection> ebDigis;
00491   iEvent.getByLabel(EBDigiCollection_,ebDigis);
00492   if(!ebDigis.isValid())
00493   {
00494     std::cout << "Cannot get EBDigis from event!" << std::endl;
00495     return;
00496   }
00497   // EE Digis
00498   Handle<EEDigiCollection> eeDigis;
00499   iEvent.getByLabel(EEDigiCollection_,eeDigis);
00500   if(!eeDigis.isValid())
00501   {
00502     std::cout << "Cannot get EEDigis from event!" << std::endl;
00503     return;
00504   }
00505 
00506   // EB first
00507   // 1) Look at SimTracks, getting only the HSCP tracks
00508   // 2) Match to PCaloHits
00509   // 3) Match to digis
00510   int numMatchedSimHitsEventEB = 0;
00511   int numMatchedDigisEventEB = 0;
00512   const PCaloHitContainer* phitsEB=0;
00513   phitsEB = ebSimHits.product();
00514   for(SimTrackContainer::const_iterator simTrack = simTracks->begin(); simTrack != simTracks->end(); ++simTrack)
00515   {
00516     // Check if the particleId is in our list
00517     std::vector<int>::const_iterator partIdItr = find(particleIds_.begin(),particleIds_.end(),simTrack->type());
00518     if(partIdItr==particleIds_.end())
00519       continue;
00520 
00521     PCaloHitContainer mySimHitsEB;
00522     std::vector<EBDataFrame> myDigisEB;
00523 
00524     //int particleId = simTrack->type();
00525     int trackId = simTrack->trackId();
00526     PCaloHitContainer::const_iterator simHitItr = phitsEB->begin();
00527     while(simHitItr != phitsEB->end())
00528     {
00529       if(simHitItr->geantTrackId()==trackId)
00530         mySimHitsEB.push_back(*simHitItr);
00531       ++simHitItr;
00532     }
00533     if(mySimHitsEB.size()==0)
00534     {
00535       std::cout << "Could not find matching EB PCaloHits for SimTrack id: " << trackId << ".  Skipping this SimTrack" << std::endl;
00536       continue;
00537     }
00538 
00539     // Loop over matching PCaloHits
00540     for(simHitItr = mySimHitsEB.begin(); simHitItr != mySimHitsEB.end(); ++simHitItr)
00541     {
00542       simHitsEcalEnergyHistEB_->Fill(simHitItr->energy());
00543       simHitsEcalTimeHistEB_->Fill(simHitItr->time());
00544       simHitsEcalEnergyVsTimeHistEB_->Fill(simHitItr->time(),simHitItr->energy());
00545       EBDetId simHitId = EBDetId(simHitItr->id());
00546       std::cout << "SimHit DetId found: " << simHitId << " for PDGid: " << simTrack->type() << std::endl;
00547       //std::cout << "SimHit hashedIndex: " << simHitId.hashedIndex() << std::endl;
00548       std::cout << "SimHit energy: " << simHitItr->energy() << " time: " << simHitItr->time() << std::endl;
00549       ++numMatchedSimHitsEventEB;
00550 
00551       EBDigiCollection::const_iterator digiItr = ebDigis->begin();
00552       while(digiItr != ebDigis->end() && (digiItr->id() != simHitId))
00553         ++digiItr;
00554       if(digiItr==ebDigis->end())
00555       {
00556         // Commented out for debugging ease, Aug 3 2009
00557         std::cout << "Could not find simHit detId: " << simHitId << "in EBDigiCollection!" << std::endl;
00558         continue;
00559       }
00560       std::vector<EBDataFrame>::const_iterator myDigiItr = myDigisEB.begin();
00561       while(myDigiItr != myDigisEB.end() && (digiItr->id() != myDigiItr->id()))
00562         ++myDigiItr;
00563       if(myDigiItr!=myDigisEB.end())
00564         continue; // if this digi is already in the list, skip it
00565 
00566       ++numMatchedDigisEventEB;
00567       EBDataFrame df = *digiItr;
00568       myDigisEB.push_back(df);
00569       std::cout << "SAMPLE ADCs: " << "\t";
00570       for(int i=0; i<10;++i)
00571         std::cout << i << "\t";
00572       std::cout << std::endl << "\t\t";
00573       for(int i=0; i < df.size(); ++i)
00574       {
00575         std::cout << df.sample(i).adc() << "\t";
00576       }
00577       std::cout << std::endl << std::endl;
00578 
00579       simHitsEcalDigiMatchEnergyHistEB_->Fill(simHitItr->energy());
00580       simHitsEcalDigiMatchTimeHistEB_->Fill(simHitItr->time());
00581       simHitsEcalDigiMatchEnergyVsTimeHistEB_->Fill(simHitItr->time(),simHitItr->energy());
00582       simHitsEcalDigiMatchIEtaHist_->Fill(((EBDetId)digiItr->id()).ieta());
00583       simHitsEcalDigiMatchIPhiHist_->Fill(((EBDetId)digiItr->id()).iphi());
00584       digiOccupancyMapEB_->Fill(((EBDetId)digiItr->id()).iphi(),((EBDetId)digiItr->id()).ieta());
00585     }
00586   }
00587   simHitsEcalNumHistEB_->Fill(numMatchedSimHitsEventEB);
00588   digisEcalNumHistEB_->Fill(numMatchedDigisEventEB);
00589 
00590   // EE next
00591   int numMatchedSimHitsEventEE = 0;
00592   int numMatchedDigisEventEE = 0;
00593   const PCaloHitContainer* phitsEE=0;
00594   phitsEE = eeSimHits.product();
00595   for(SimTrackContainer::const_iterator simTrack = simTracks->begin(); simTrack != simTracks->end(); ++simTrack)
00596   {
00597     // Check if the particleId is in our list
00598     std::vector<int>::const_iterator partIdItr = find(particleIds_.begin(),particleIds_.end(),simTrack->type());
00599     if(partIdItr==particleIds_.end())
00600       continue;
00601 
00602     PCaloHitContainer mySimHitsEE;
00603     std::vector<EEDataFrame> myDigisEE;
00604 
00605     //int particleId = simTrack->type();
00606     int trackId = simTrack->trackId();
00607     PCaloHitContainer::const_iterator simHitItr = phitsEE->begin();
00608     while(simHitItr != phitsEE->end())
00609     {
00610       if(simHitItr->geantTrackId()==trackId)
00611         mySimHitsEE.push_back(*simHitItr);
00612       ++simHitItr;
00613     }
00614     if(mySimHitsEE.size()==0)
00615     {
00616       std::cout << "Could not find matching EE PCaloHits for SimTrack id: " << trackId << ".  Skipping this SimTrack" << std::endl;
00617       continue;
00618     }
00619 
00620     // Loop over matching PCaloHits
00621     for(simHitItr = mySimHitsEE.begin(); simHitItr != mySimHitsEE.end(); ++simHitItr)
00622     {
00623       simHitsEcalEnergyHistEE_->Fill(simHitItr->energy());
00624       simHitsEcalTimeHistEE_->Fill(simHitItr->time());
00625       simHitsEcalEnergyVsTimeHistEE_->Fill(simHitItr->time(),simHitItr->energy());
00626       EEDetId simHitId = EEDetId(simHitItr->id());
00627       std::cout << "SimHit DetId found: " << simHitId << " for PDGid: " << simTrack->type() << std::endl;
00628       //std::cout << "SimHit hashedIndex: " << simHitId.hashedIndex() << std::endl;
00629       std::cout << "SimHit energy: " << simHitItr->energy() << " time: " << simHitItr->time() << std::endl;
00630       ++numMatchedSimHitsEventEE;
00631 
00632       EEDigiCollection::const_iterator digiItr = eeDigis->begin();
00633       while(digiItr != eeDigis->end() && (digiItr->id() != simHitId))
00634         ++digiItr;
00635       if(digiItr==eeDigis->end())
00636       {
00637         // Commented out for debugging ease, Aug 3 2009
00638         std::cout << "Could not find simHit detId: " << simHitId << "in EEDigiCollection!" << std::endl;
00639         continue;
00640       }
00641       std::vector<EEDataFrame>::const_iterator myDigiItr = myDigisEE.begin();
00642       while(myDigiItr != myDigisEE.end() && (digiItr->id() != myDigiItr->id()))
00643         ++myDigiItr;
00644       if(myDigiItr!=myDigisEE.end())
00645         continue; // if this digi is already in the list, skip it
00646 
00647       ++numMatchedDigisEventEE;
00648       EEDataFrame df = *digiItr;
00649       myDigisEE.push_back(df);
00650       std::cout << "SAMPLE ADCs: " << "\t";
00651       for(int i=0; i<10;++i)
00652         std::cout << i << "\t";
00653       std::cout << std::endl << "\t\t";
00654       for(int i=0; i < df.size(); ++i)
00655       {
00656         std::cout << df.sample(i).adc() << "\t";
00657       }
00658       std::cout << std::endl << std::endl;
00659 
00660       simHitsEcalDigiMatchEnergyHistEE_->Fill(simHitItr->energy());
00661       simHitsEcalDigiMatchTimeHistEE_->Fill(simHitItr->time());
00662       simHitsEcalDigiMatchEnergyVsTimeHistEE_->Fill(simHitItr->time(),simHitItr->energy());
00663       if(((EEDetId)digiItr->id()).zside() > 0)
00664         digiOccupancyMapEEP_->Fill(((EEDetId)digiItr->id()).ix(),((EEDetId)digiItr->id()).iy());
00665       else if(((EEDetId)digiItr->id()).zside() < 0)
00666         digiOccupancyMapEEM_->Fill(((EEDetId)digiItr->id()).ix(),((EEDetId)digiItr->id()).iy());
00667     }
00668   }
00669   simHitsEcalNumHistEE_->Fill(numMatchedSimHitsEventEE);
00670   digisEcalNumHistEE_->Fill(numMatchedDigisEventEE);
00671 
00672 }
00673 
00674 // ------------- Make simDigi plots RPC -------------------------------------------------
00675 void HSCPValidator::makeSimDigiPlotsRPC(const edm::Event& iEvent)
00676 {
00677   using namespace edm;
00678 
00679   //std::cout << " Getting the SimHits " <<std::endl;
00680   std::vector<Handle<edm::PSimHitContainer> > theSimHitContainers;
00681   iEvent.getManyByType(theSimHitContainers);
00682   //std::cout << " The Number of sim Hits is  " << theSimHitContainers.size() <<std::endl;
00683 
00684   Handle<RPCRecHitCollection> rpcRecHits;
00685   iEvent.getByLabel("rpcRecHits","",rpcRecHits);
00686 
00687   //SimTrack Stuff
00688   std::vector<PSimHit> theSimHits;
00689 
00690   for (int i = 0; i < int(theSimHitContainers.size()); i++){
00691     theSimHits.insert(theSimHits.end(),theSimHitContainers.at(i)->begin(),theSimHitContainers.at(i)->end());
00692   } 
00693 
00694 
00695   for (std::vector<PSimHit>::const_iterator iHit = theSimHits.begin(); iHit != theSimHits.end(); iHit++){
00696 
00697     std::vector<int>::const_iterator partIdItr = find(particleIds_.begin(),particleIds_.end(),(*iHit).particleType());
00698     if(partIdItr==particleIds_.end())
00699       continue;
00700 
00701     DetId theDetUnitId((*iHit).detUnitId());
00702 
00703     DetId simdetid= DetId((*iHit).detUnitId());
00704 
00705     if(simdetid.det()==DetId::Muon &&  simdetid.subdetId()== MuonSubdetId::RPC){//Only RPCs
00706 
00707       RPCDetId rollId(theDetUnitId);
00708       RPCGeomServ rpcsrv(rollId);
00709 
00710       //std::cout << " Reading the Roll"<<std::endl;
00711       const RPCRoll* rollasociated = rpcGeo->roll(rollId);
00712 
00713       //std::cout << " Getting the Surface"<<std::endl;
00714       const BoundPlane & RPCSurface = rollasociated->surface(); 
00715 
00716       GlobalPoint SimHitInGlobal = RPCSurface.toGlobal((*iHit).localPosition());
00717 
00718       std::cout<<"\t\t We have an RPC Sim Hit! in t="<<(*iHit).timeOfFlight()<<"ns "<<rpcsrv.name()<<" Global postition="<<SimHitInGlobal<<std::endl;
00719 
00720       int layer = 0;
00721 
00722       if(rollId.station()==1&&rollId.layer()==1) layer = 1;
00723       else if(rollId.station()==1&&rollId.layer()==2) layer = 2;
00724       else if(rollId.station()==2&&rollId.layer()==1) layer = 3;
00725       else if(rollId.station()==2&&rollId.layer()==2)  layer = 4;
00726       else if(rollId.station()==3) layer = 5;
00727       else if(rollId.station()==4) layer = 6;
00728 
00729       if(rollId.region()==0){
00730         rpcTimeOfFlightBarrel_[layer-1]->Fill((*iHit).timeOfFlight());
00731       }else{
00732         rpcTimeOfFlightEndCap_[rollId.station()-1]->Fill((*iHit).timeOfFlight());
00733       }
00734 
00735       std::cout<<"\t\t r="<<SimHitInGlobal.mag()<<" phi="<<SimHitInGlobal.phi()<<" eta="<<SimHitInGlobal.eta()<<std::endl;
00736 
00737       int cluSize = 0;
00738       int bx = 100;
00739       float minres = 3000.;
00740 
00741       std::cout<<"\t \t \t \t Getting RecHits in Roll Asociated"<<std::endl;
00742 
00743       typedef std::pair<RPCRecHitCollection::const_iterator, RPCRecHitCollection::const_iterator> rangeRecHits;
00744       rangeRecHits recHitCollection =  rpcRecHits->get(rollId);
00745       RPCRecHitCollection::const_iterator recHit;
00746 
00747       efficiencyRPCRecHitSimDigis_->Fill(0);
00748 
00749       for(recHit = recHitCollection.first; recHit != recHitCollection.second ; recHit++){
00750         LocalPoint recHitPos=recHit->localPosition();
00751         float res=(*iHit).localPosition().x()- recHitPos.x();
00752         if(fabs(res)<fabs(minres)){
00753           minres=res;
00754           cluSize = recHit->clusterSize();
00755           bx=recHit->BunchX();
00756           std::cout<<"\t New Min Res "<<res<<"cm."<<std::endl;
00757         }
00758       }
00759 
00760       if(minres<3000.){
00761         residualsRPCRecHitSimDigis_->Fill(minres);
00762         efficiencyRPCRecHitSimDigis_->Fill(1);
00763         cluSizeDistribution_->Fill(cluSize);
00764         if(rollId.region()==0) rpcBXBarrel_[layer-1]->Fill(bx);
00765         else rpcBXEndCap_[rollId.station()-1]->Fill(bx);
00766       }
00767     }
00768   }
00769 }
00770 
00771 // ------------- Convert int to string for printing -------------------------------------
00772 std::string HSCPValidator::intToString(int num)
00773 {
00774   using namespace std;
00775   ostringstream myStream;
00776   myStream << num << flush;
00777   return(myStream.str()); //returns the string form of the stringstream object
00778 }
00779 
00780 
00781 
00782 //------Increase trigger thresold----
00783 bool HSCPValidator::IncreasedTreshold(const trigger::TriggerEvent& trEv, const edm::InputTag& InputPath, double NewThreshold, int NObjectAboveThreshold, bool averageThreshold)
00784 {
00785    unsigned int filterIndex = trEv.filterIndex(InputPath);
00786    //if(filterIndex<trEv.sizeFilters())printf("SELECTED INDEX =%i --> %s    XXX   %s\n",filterIndex,trEv.filterTag(filterIndex).label().c_str(), trEv.filterTag(filterIndex).process().c_str());
00787 
00788    if (filterIndex<trEv.sizeFilters()){
00789       const trigger::Vids& VIDS(trEv.filterIds(filterIndex));
00790       const trigger::Keys& KEYS(trEv.filterKeys(filterIndex));
00791       const int nI(VIDS.size());
00792       const int nK(KEYS.size());
00793       assert(nI==nK);
00794       const int n(std::max(nI,nK));
00795       const trigger::TriggerObjectCollection& TOC(trEv.getObjects());
00796 
00797 
00798       if(!averageThreshold){
00799          int NObjectAboveThresholdObserved = 0;
00800          for (int i=0; i!=n; ++i) {
00801             if(TOC[KEYS[i]].pt()> NewThreshold) NObjectAboveThresholdObserved++;
00802             //cout << "   " << i << " " << VIDS[i] << "/" << KEYS[i] << ": "<< TOC[KEYS[i]].id() << " " << TOC[KEYS[i]].pt() << " " << TOC[KEYS[i]].eta() << " " << TOC[KEYS[i]].phi() << " " << TOC[KEYS[i]].mass()<< endl;
00803          }
00804          if(NObjectAboveThresholdObserved>=NObjectAboveThreshold)return true;
00805 
00806       }else{
00807          std::vector<double> ObjPt;
00808 
00809          for (int i=0; i!=n; ++i) {
00810             ObjPt.push_back(TOC[KEYS[i]].pt());
00811             //cout << "   " << i << " " << VIDS[i] << "/" << KEYS[i] << ": "<< TOC[KEYS[i]].id() << " " << TOC[KEYS[i]].pt() << " " << TOC[KEYS[i]].eta() << " " << TOC[KEYS[i]].phi() << " " << TOC[KEYS[i]].mass()<< endl;
00812          }
00813          if((int)(ObjPt.size())<NObjectAboveThreshold)return false;
00814          std::sort(ObjPt.begin(), ObjPt.end());
00815 
00816          double Average = 0;
00817          for(int i=0; i<NObjectAboveThreshold;i++){
00818             Average+= ObjPt[ObjPt.size()-1-i];
00819          }Average/=NObjectAboveThreshold;
00820          //cout << "AVERAGE = " << Average << endl;
00821 
00822          if(Average>NewThreshold)return true;
00823       }
00824    }
00825    return false;
00826 }
00827 
00828 
00829 
00830 //define this as a plug-in
00831 DEFINE_FWK_MODULE(HSCPValidator);