00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <memory>
00024 #include <string>
00025 #include <iostream>
00026 #include <fstream>
00027 #include <vector>
00028
00029
00030 #include "FWCore/Framework/interface/Frameworkfwd.h"
00031 #include "FWCore/Framework/interface/EDAnalyzer.h"
00032
00033 #include "FWCore/Framework/interface/Event.h"
00034 #include "DataFormats/Common/interface/Handle.h"
00035 #include "FWCore/Framework/interface/MakerMacros.h"
00036 #include "FWCore/Framework/interface/EventSetup.h"
00037 #include "FWCore/Framework/interface/ESHandle.h"
00038 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00039
00040
00041 #include "CLHEP/Vector/LorentzVector.h"
00042 #include "CLHEP/Units/PhysicalConstants.h"
00043 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00044 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00045
00046
00047 #include "DataFormats/Math/interface/LorentzVector.h"
00048 #include "DataFormats/Math/interface/Vector3D.h"
00049 #include "Math/GenVector/VectorUtil.h"
00050 #include "Math/GenVector/PxPyPzE4D.h"
00051 #include "DataFormats/Math/interface/deltaR.h"
00052
00053
00054
00055 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00056 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00057 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00058
00059 #include "DataFormats/JetReco/interface/CaloJet.h"
00060 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00061
00062 #include "DataFormats/JetReco/interface/GenJet.h"
00063 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00064
00065 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00066
00067
00068 #include "DataFormats/TrackReco/interface/Track.h"
00069 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00070 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
00071 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00072 #include "DataFormats/TrackReco/interface/HitPattern.h"
00073
00074 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00075 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
00076 #include "SimTracker/Records/interface/TrackAssociatorRecord.h"
00077 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00078 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00079 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00080 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00081 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00082 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00083
00084
00085 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
00086 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00087 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00088 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00089 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00090 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00091 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00092 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h"
00093 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00094 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00095 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00096
00097 #include "RecoLocalTracker/SiPixelRecHits/test/ReadPixelRecHit.h"
00098 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
00099
00100 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00101 #include "DataFormats/VertexReco/interface/Vertex.h"
00102
00103
00104 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00105 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00106
00107 #include "SimDataFormats/Track/interface/SimTrack.h"
00108 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00109 #include "SimDataFormats/Vertex/interface/SimVertex.h"
00110 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00111
00112
00113 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00114 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00115 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00116
00117 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00118 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00119 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00120 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00121 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
00122 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00123 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00124 #include "DataFormats/DetId/interface/DetId.h"
00125 #include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
00126 #include "Geometry/CaloTopology/interface/CaloTowerTopology.h"
00127 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
00128 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00129 #include "Geometry/CaloTopology/interface/CaloTopology.h"
00130 #include "RecoCaloTools/Navigation/interface/EcalBarrelNavigator.h"
00131 #include "RecoCaloTools/Navigation/interface/EcalEndcapNavigator.h"
00132 #include "RecoCaloTools/Navigation/interface/EcalPreshowerNavigator.h"
00133 #include "RecoCaloTools/Navigation/interface/CaloTowerNavigator.h"
00134 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
00135
00136
00137
00138
00139
00140
00141
00142
00143 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00144 #include "DataFormats/Candidate/interface/Candidate.h"
00145 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00146
00147 #include "TFile.h"
00148 #include "TTree.h"
00149 #include "TH1.h"
00150 #include "TH2.h"
00151
00152
00153 #include "DataFormats/Math/interface/LorentzVector.h"
00154 #include "DataFormats/Math/interface/Vector3D.h"
00155 #include "Math/GenVector/VectorUtil.h"
00156 #include "Math/GenVector/PxPyPzE4D.h"
00157
00158 using namespace std;
00159 using namespace reco;
00160
00161
00162
00163
00164 class SinglePionEfficiencyNew : public edm::EDAnalyzer {
00165 public:
00166 explicit SinglePionEfficiencyNew(const edm::ParameterSet&);
00167 ~SinglePionEfficiencyNew();
00168
00169
00170 double eECALmatrix(CaloNavigator<DetId>& navigator,edm::Handle<EcalRecHitCollection>& hits, int ieta, int iphi);
00171
00172 double eHCALmatrix(const HcalTopology* topology, const DetId& det,const HBHERecHitCollection& hits, int ieta, int iphi);
00173
00174 double eHCALneighbours(std::vector<DetId>& vNeighboursDetId, std::vector<DetId>& dets, const HcalTopology* topology, const HBHERecHitCollection& hits);
00175
00176 private:
00177 virtual void beginJob(const edm::EventSetup&) ;
00178 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00179 virtual void endJob() ;
00180
00181
00182
00183 string fOutputFileName ;
00184 TFile* hOutputFile ;
00185 TTree* t1;
00186
00187 string tracksSrc;
00188 string pxltracksSrc;
00189 string pxlhitsSrc;
00190 string calotowersSrc;
00191
00192 string ecalHitsProducerSrc;
00193 string ECALbarrelHitCollectionSrc;
00194 string ECALendcapHitCollectionSrc;
00195
00196 string hbheInputSrc;
00197 string hoInputSrc;
00198 string hfInputSrc;
00199 string towermakerSrc;
00200
00201
00202
00203 double ptSim1, etaSim1, phiSim1;
00204 double ptSim2, etaSim2, phiSim2;
00205
00206 double ptTrk1, etaTrk1, phiTrk1, drTrk1, purityTrk1;
00207 double ptTrk2, etaTrk2, phiTrk2, drTrk2, purityTrk2;
00208
00209 int trkQuality1, trkQuality2, trkNVhits1, trkNVhits2;
00210 int idmax1, idmax2;
00211
00212 double ptPxl1, etaPxl1, phiPxl1, drPxl1, purityPxl1;
00213 double ptPxl2, etaPxl2, phiPxl2, drPxl2, purityPxl2;
00214
00215 double etCalo1, etCalo2;
00216 double eCalo1, eCalo2;
00217
00218 double e1ECAL7x7, e2ECAL7x7, e1ECAL11x11, e2ECAL11x11;
00219 double e1HCAL3x3, e2HCAL3x3, e1HCAL5x5, e2HCAL5x5;
00220
00221
00222
00223 TrackerHitAssociator* hitAssociator;
00224
00225 TrackAssociatorParameters parameters_;
00226 mutable TrackDetectorAssociator* trackAssociator_;
00227
00228 const edm::ParameterSet conf_;
00229 };
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 SinglePionEfficiencyNew::SinglePionEfficiencyNew(const edm::ParameterSet& iConfig) : conf_(iConfig)
00242 {
00243
00244 using namespace edm;
00245
00246
00247 fOutputFileName = iConfig.getUntrackedParameter<string>("HistOutFile");
00248 tracksSrc = iConfig.getParameter<string>("tracks");
00249 pxltracksSrc = iConfig.getParameter<string>("pxltracks");
00250 pxlhitsSrc = iConfig.getParameter<string>("pxlhits");
00251 calotowersSrc = iConfig.getParameter<std::string>("calotowers");
00252 towermakerSrc = iConfig.getParameter<std::string>("towermaker");
00253
00254 ecalHitsProducerSrc = iConfig.getParameter< std::string >("ecalRecHitsProducer");
00255 ECALbarrelHitCollectionSrc = iConfig.getParameter<string>("ECALbarrelHitCollection");
00256 ECALendcapHitCollectionSrc = iConfig.getParameter<string>("ECALendcapHitCollection");
00257
00258 hbheInputSrc = iConfig.getParameter<string>("hbheInput");
00259 hoInputSrc = iConfig.getParameter<string>("hoInput");
00260 hfInputSrc = iConfig.getParameter<string>("hfInput");
00261
00262 edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
00263 parameters_.loadParameters( parameters );
00264 trackAssociator_ = new TrackDetectorAssociator();
00265 trackAssociator_->useDefaultPropagator();
00266 }
00267
00268
00269 SinglePionEfficiencyNew::~SinglePionEfficiencyNew()
00270 {
00271
00272
00273
00274
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 void
00305 SinglePionEfficiencyNew::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00306 {
00307 using namespace edm;
00308
00309 hitAssociator = new TrackerHitAssociator::TrackerHitAssociator(iEvent);
00310
00311
00312
00313 ptSim1 = 0.; etaSim1 = 0.; phiSim1 = 0.; ptSim2 = 0.; etaSim2 = 0.; phiSim2 = 0.;
00314
00315 ptTrk1 = 0.; etaTrk1 = 0.; phiTrk1 = 0.; drTrk1 = 1000.; purityTrk1 = 0.;
00316 ptTrk2 = 0.; etaTrk2 = 0.; phiTrk2 = 0.; drTrk2 = 1000.; purityTrk2 = 0.;
00317
00318 ptPxl1 = 0.; etaPxl1 = 0.; phiPxl1 = 0.; drPxl1 = 1000.; purityPxl1 = 0.;
00319 ptPxl2 = 0.; etaPxl2 = 0.; phiPxl2 = 0.; drPxl2 = 1000.; purityPxl2 = 0.;
00320
00321 etCalo1 = 0.; etCalo2 = 0.;
00322 eCalo1 = 0.; eCalo2 = 0.;
00323
00324 e1ECAL7x7 = 0.; e2ECAL7x7 = 0.; e1ECAL11x11 = 0.; e2ECAL11x11 = 0.;
00325 e1HCAL3x3 = 0.; e2HCAL3x3 = 0.; e1HCAL5x5 = 0.; e2HCAL5x5 = 0.;
00326
00327 trkQuality1 = -1; trkQuality2 = -1; trkNVhits1 = -1; trkNVhits2 = -1;
00328 idmax1 = -1; idmax2 = -1;
00329
00330
00331
00332
00333 edm::ESHandle<TrackerGeometry> theG;
00334 iSetup.get<TrackerDigiGeometryRecord>().get(theG);
00335
00336
00337 edm::ESHandle<CaloGeometry> pG;
00338
00339 iSetup.get<CaloGeometryRecord>().get(pG);
00340 const CaloGeometry* geo = pG.product();
00341 const CaloSubdetectorGeometry* gEB = geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
00342 const CaloSubdetectorGeometry* gEE = geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
00343 const CaloSubdetectorGeometry* gHBHE = geo->getSubdetectorGeometry(DetId::Hcal,HcalBarrel);
00344
00345
00346 edm::ESHandle<CaloTopology> theCaloTopology;
00347 iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
00348 const CaloSubdetectorTopology* theEBTopology = theCaloTopology->getSubdetectorTopology(DetId::Ecal,EcalBarrel);
00349 const CaloSubdetectorTopology* theEETopology = theCaloTopology->getSubdetectorTopology(DetId::Ecal,EcalEndcap);
00350
00351
00352 edm::ESHandle<HcalTopology> htopo;
00353 iSetup.get<IdealGeometryRecord>().get(htopo);
00354 const HcalTopology* theHBHETopology = htopo.product();
00355
00356
00357
00358
00359 edm::Handle<HepMCProduct> EvtHandle ;
00360 iEvent.getByLabel( "source", EvtHandle ) ;
00361
00362
00363 const HepMC::GenEvent* evt = EvtHandle->GetEvent() ;
00364 ESHandle<ParticleDataTable> pdt;
00365 iSetup.getData( pdt );
00366
00367 vector<HepLorentzVector> genpions;
00368 genpions.clear();
00369
00370 for ( HepMC::GenEvent::particle_const_iterator p = evt->particles_begin();
00371 p != evt->particles_end(); ++p ) {
00372
00373 HepLorentzVector pion((*p)->momentum().px(),(*p)->momentum().py(),(*p)->momentum().pz(),(*p)->momentum().e());
00374 genpions.push_back(pion);
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 }
00386
00387
00388 edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
00389 edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
00390
00391 iEvent.getByLabel(ecalHitsProducerSrc,ECALbarrelHitCollectionSrc,barrelRecHitsHandle);
00392 iEvent.getByLabel(ecalHitsProducerSrc,ECALendcapHitCollectionSrc,endcapRecHitsHandle);
00393
00394
00395 EBRecHitCollection::const_iterator itb;
00396 for (itb=barrelRecHitsHandle->begin(); itb!=barrelRecHitsHandle->end(); itb++) {
00397 GlobalPoint pos = geo->getPosition(itb->detid());
00398 double eta = pos.eta();
00399
00400 double phi = pos.phi();
00401
00402 double DR1 = deltaR(genpions[0].eta(),genpions[0].phi(),eta,phi);
00403 double DR2 = deltaR(genpions[1].eta(),genpions[1].phi(),eta,phi);
00404
00405
00406
00407
00408
00409
00410
00411 if(DR1 < 0.5) {
00412 eCalo1 = eCalo1 + itb->energy();
00413 }
00414 if(DR2 < 0.5) {
00415 eCalo2 = eCalo2 + itb->energy();
00416 }
00417 }
00418
00419 for (itb=endcapRecHitsHandle->begin(); itb!=endcapRecHitsHandle->end(); itb++) {
00420 GlobalPoint pos = geo->getPosition(itb->detid());
00421 double eta = pos.eta();
00422 double phi = pos.phi();
00423
00424
00425 double DR1 = deltaR(genpions[0].eta(),genpions[0].phi(),eta,phi);
00426 double DR2 = deltaR(genpions[1].eta(),genpions[1].phi(),eta,phi);
00427 if(DR1 < 0.5) {
00428 eCalo1 = eCalo1 + itb->energy();
00429 }
00430 if(DR2 < 0.5) {
00431 eCalo2 = eCalo2 + itb->energy();
00432 }
00433
00434
00435
00436
00437
00438
00439
00440 }
00441
00442 edm::Handle<HBHERecHitCollection> hbhe;
00443 iEvent.getByLabel(hbheInputSrc,hbhe);
00444 const HBHERecHitCollection Hithbhe = *(hbhe.product());
00445
00446
00447
00448
00449 for(HBHERecHitCollection::const_iterator hbheItr=Hithbhe.begin(); hbheItr!=Hithbhe.end(); hbheItr++) {
00450 GlobalPoint pos = geo->getPosition( hbheItr->detid());
00451 double eta = pos.eta();
00452 double phi = pos.phi();
00453
00454
00455 double DR1 = deltaR(genpions[0].eta(),genpions[0].phi(),eta,phi);
00456 double DR2 = deltaR(genpions[1].eta(),genpions[1].phi(),eta,phi);
00457 if(DR1 < 0.5) {
00458 eCalo1 = eCalo1 + hbheItr->energy();
00459 }
00460 if(DR2 < 0.5) {
00461 eCalo2 = eCalo2 + hbheItr->energy();
00462 }
00463
00464
00465
00466
00467
00468
00469
00470 }
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 etCalo1 = eCalo1 * sin(genpions[0].theta());
00524 etCalo2 = eCalo2 * sin(genpions[1].theta());
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573 std::vector<SimTrack> theSimTracks;
00574 edm::Handle<SimTrackContainer> SimTk;
00575 iEvent.getByLabel("g4SimHits",SimTk);
00576 theSimTracks.insert(theSimTracks.end(),SimTk->begin(),SimTk->end());
00577
00578
00579 edm::Handle<SiPixelRecHitCollection> pxlrecHitColl;
00580 iEvent.getByLabel(pxlhitsSrc, pxlrecHitColl);
00581
00582
00583
00584 std::vector<PSimHit> matched;
00585 std::vector<unsigned int> SimTrackIds;
00586
00587
00588
00589
00590
00591 Handle<TrackCollection> tracks;
00592 iEvent.getByLabel(tracksSrc, tracks);
00593
00594
00595
00596 Handle<TrackCollection> pxltracks;
00597 iEvent.getByLabel(pxltracksSrc, pxltracks);
00598
00599
00600
00601
00602 for(size_t j = 0; j < theSimTracks.size(); j++){
00603
00604
00605
00606
00607
00608
00609
00610
00611 }
00612
00613 int t = 0;
00614
00615 std::string theTrackQuality = "highPurity";
00616 reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
00617
00618 ptSim1 = genpions[0].perp();
00619 etaSim1 = genpions[0].eta();
00620 phiSim1 = genpions[0].phi();
00621
00622 ptSim2 = genpions[1].perp();
00623 etaSim2 = genpions[1].eta();
00624 phiSim2 = genpions[1].phi();
00625
00626
00627
00628 for(TrackCollection::const_iterator track = tracks->begin();
00629 track != tracks->end(); track++) {
00630
00631
00632 int trkQuality = track->quality(trackQuality_);
00633 int trkNVhits = track->numberOfValidHits();
00634
00635
00636
00637 double eECAL7x7i = -1000.;
00638 double eECAL11x11i = -1000.;
00639 double eHCAL3x3i = -1000.;
00640 double eHCAL5x5i = -1000.;
00641
00642 const FreeTrajectoryState fts = trackAssociator_->getFreeTrajectoryState(iSetup, *track);
00643 TrackDetMatchInfo info = trackAssociator_->associate(iEvent, iSetup, fts, parameters_);
00644 if( info.isGoodEcal != 0 ) {
00645 const GlobalPoint point(info.trkGlobPosAtEcal.x(),info.trkGlobPosAtEcal.y(),info.trkGlobPosAtEcal.z());
00646 double etaimp = fabs(point.eta());
00647
00648
00649
00650
00651
00652
00653
00654
00655 if(etaimp < 1.479) {
00656 const DetId ClosestCell = gEB->getClosestCell(point);
00657
00658
00659
00660 CaloNavigator<DetId> theNavigator(ClosestCell,theEBTopology);
00661
00662 eECAL7x7i = eECALmatrix(theNavigator,barrelRecHitsHandle,3,3);
00663 eECAL11x11i = eECALmatrix(theNavigator,barrelRecHitsHandle,5,5);
00664
00665
00666 } else {
00667 const DetId ClosestCell = gEE->getClosestCell(point);
00668
00669
00670 CaloNavigator<DetId> theNavigator(ClosestCell,theEETopology);
00671
00672 eECAL7x7i = eECALmatrix(theNavigator,endcapRecHitsHandle,3,3);
00673 eECAL11x11i = eECALmatrix(theNavigator,endcapRecHitsHandle,5,5);
00674
00675
00676 }
00677
00678
00679 const DetId ClosestCell = gHBHE->getClosestCell(point);
00680 HcalDetId hcd = ClosestCell;
00681 if(abs(hcd.ieta()) <= 25) {
00682
00683
00684
00685
00686
00687
00688
00689 eHCAL3x3i = eHCALmatrix(theHBHETopology, ClosestCell, Hithbhe,1,1);
00690 eHCAL5x5i = eHCALmatrix(theHBHETopology, ClosestCell, Hithbhe,2,2);
00691 }
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713 }
00714
00715
00716
00717 SimTrackIds.clear();
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732 size_t ih = 0;
00733 for(trackingRecHit_iterator rhit = track->recHitsBegin();
00734 rhit != track->recHitsEnd(); ++rhit) {
00735
00736 if((*rhit)->isValid()) {
00737
00738 float mindist = 999999;
00739 float dist;
00740 PSimHit closest;
00741 matched.clear();
00742 matched = hitAssociator->associateHit((**rhit));
00743
00744
00745
00746
00747
00748
00749
00750 if(!matched.empty()){
00751
00752 int ish = 0;
00753 for(vector<PSimHit>::const_iterator m = matched.begin(); m < matched.end(); m++) {
00754 if((*m).localPosition().y() < 0.0001) {
00755 dist = fabs((*rhit)->localPosition().x() - (*m).localPosition().x());
00756 } else {
00757 float distx = (*rhit)->localPosition().x() - (*m).localPosition().x();
00758 float disty = (*rhit)->localPosition().y() - (*m).localPosition().y();
00759 dist = sqrt(distx*distx + disty*disty);
00760 }
00761
00762
00763
00764
00765
00766
00767
00768 ish++;
00769 if(dist < mindist) {
00770 mindist = dist;
00771 closest = (*m);
00772 }
00773 }
00774 int trkid = closest.trackId();
00775
00776
00777 SimTrackIds.push_back(trkid);
00778
00779
00780
00781
00782
00783
00784 }
00785 }
00786 ih++;
00787 }
00788
00789 int nmax = 0;
00790 int idmax = -1;
00791 for(size_t j=0; j<SimTrackIds.size(); j++){
00792 int n =0;
00793 n = std::count(SimTrackIds.begin(), SimTrackIds.end(), SimTrackIds[j]);
00794 if(n>nmax){
00795 nmax = n;
00796 idmax = SimTrackIds[j];
00797 }
00798 }
00799
00800 float purity = 0;
00801 if(SimTrackIds.size() != 0) {
00802 float totsim = nmax;
00803 float tothits = track->recHitsSize();
00804 purity = totsim/tothits ;
00805
00806
00807
00808
00809
00810
00811
00812 } else {
00813
00814 }
00815
00816 HepLorentzVector tracki(track->px(), track->py(), track->pz(), track->p());
00817 double DR1 = genpions[0].deltaR(tracki);
00818 if(DR1 < drTrk1) {
00819 ptTrk1 = tracki.perp();
00820 etaTrk1 = tracki.eta();
00821 phiTrk1 = tracki.phi();
00822 purityTrk1 = purity;
00823 drTrk1 = DR1;
00824 e1ECAL7x7 = eECAL7x7i;
00825 e1ECAL11x11= eECAL11x11i;
00826 e1HCAL3x3 = eHCAL3x3i;
00827 e1HCAL5x5 = eHCAL5x5i;
00828 trkQuality1 = trkQuality;
00829 trkNVhits1 = trkNVhits;
00830 idmax1 = idmax;
00831 }
00832 double DR2 = genpions[1].deltaR(tracki);
00833 if(DR2 < drTrk2) {
00834 ptTrk2 = tracki.perp();
00835 etaTrk2 = tracki.eta();
00836 phiTrk2 = tracki.phi();
00837 purityTrk2 = purity;
00838 drTrk2 = DR2;
00839 e2ECAL7x7 = eECAL7x7i;
00840 e2ECAL11x11= eECAL11x11i;
00841 e2HCAL3x3 = eHCAL3x3i;
00842 e2HCAL5x5 = eHCAL5x5i;
00843 trkQuality2 = trkQuality;
00844 trkNVhits2 = trkNVhits;
00845 idmax2 = idmax;
00846 }
00847 t++;
00848 }
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869 t = 0;
00870 for(TrackCollection::const_iterator pxltrack = pxltracks->begin();
00871 pxltrack != pxltracks->end(); ++pxltrack) {
00872 SimTrackIds.clear();
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889 size_t ih = 0;
00890 for(trackingRecHit_iterator rhit = pxltrack->recHitsBegin();
00891 rhit != pxltrack->recHitsEnd(); ++rhit) {
00892 if((*rhit)->isValid()) {
00893
00894 float mindist = 999999;
00895 float dist;
00896 PSimHit closest;
00897 matched.clear();
00898 matched = hitAssociator->associateHit((**rhit));
00899
00900
00901
00902
00903
00904
00905 if(!matched.empty()){
00906 int ish = 0;
00907 for(vector<PSimHit>::const_iterator m = matched.begin(); m < matched.end(); m++) {
00908 float distx = (*rhit)->localPosition().x() - (*m).localPosition().x();
00909 float disty = (*rhit)->localPosition().y() - (*m).localPosition().y();
00910 dist = sqrt(distx*distx + disty*disty);
00911
00912
00913
00914
00915
00916
00917 ish++;
00918 if(dist < mindist) {
00919 mindist = dist;
00920 closest = (*m);
00921 }
00922 }
00923 int trkid = closest.trackId();
00924 if(trkid <= (int) theSimTracks.size()) {
00925 if(theSimTracks[trkid-1].noGenpart() == 0) {
00926 SimTrackIds.push_back(trkid);
00927
00928
00929 cout <<" " << endl;
00930 }
00931 } else {
00932
00933 }
00934 }
00935 }
00936 ih++;
00937 }
00938
00939 int nmax = 0;
00940 int idmax = -1;
00941 for(size_t j=0; j<SimTrackIds.size(); j++){
00942 int n =0;
00943 n = std::count(SimTrackIds.begin(), SimTrackIds.end(), SimTrackIds[j]);
00944 if(n>nmax){
00945 nmax = n;
00946 idmax = SimTrackIds[j];
00947 }
00948 }
00949 float purity = 0;
00950 if(SimTrackIds.size() != 0) {
00951 float totsim = nmax;
00952 float tothits = pxltrack->recHitsSize();
00953 purity = totsim/tothits ;
00954
00955
00956
00957
00958
00959
00960
00961 } else {
00962
00963 }
00964
00965 HepLorentzVector pxltracki(pxltrack->px(), pxltrack->py(), pxltrack->pz(), pxltrack->p());
00966 double DR1 = genpions[0].deltaR(pxltracki);
00967 if(DR1 < drPxl1) {
00968 ptPxl1 = pxltracki.perp();
00969 etaPxl1 = pxltracki.eta();
00970 phiPxl1 = pxltracki.phi();
00971 purityPxl1 = purity;
00972 drPxl1 = DR1;
00973 }
00974 double DR2 = genpions[1].deltaR(pxltracki);
00975 if(DR2 < drPxl2) {
00976 ptPxl2 = pxltracki.perp();
00977 etaPxl2 = pxltracki.eta();
00978 phiPxl2 = pxltracki.phi();
00979 purityPxl2 = purity;
00980 drPxl2 = DR2;
00981 }
00982 t++;
00983 }
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002 t1->Fill();
01003
01004
01005 delete hitAssociator;
01006 }
01007
01008
01009
01010 void
01011 SinglePionEfficiencyNew::beginJob(const edm::EventSetup& iSetup)
01012 {
01013
01014 using namespace edm;
01015
01016
01017
01018
01019
01020 hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
01021 t1 = new TTree("t1","analysis tree");
01022
01023 t1->Branch("ptSim1",&ptSim1,"ptSim1/D");
01024 t1->Branch("etaSim1",&etaSim1,"etaSim1/D");
01025 t1->Branch("phiSim1",&phiSim1,"phiSim1/D");
01026 t1->Branch("ptSim2",&ptSim2,"ptSim2/D");
01027 t1->Branch("etaSim2",&etaSim2,"etaSim2/D");
01028 t1->Branch("phiSim2",&phiSim2,"phiSim2/D");
01029
01030 t1->Branch("ptTrk1",&ptTrk1,"ptTrk1/D");
01031 t1->Branch("etaTrk1",&etaTrk1,"etaTrk1/D");
01032 t1->Branch("phiTrk1",&phiTrk1,"phiTrk1/D");
01033 t1->Branch("drTrk1",&drTrk1,"drTrk1/D");
01034 t1->Branch("purityTrk1",&purityTrk1,"purityTrk1/D");
01035 t1->Branch("ptTrk2",&ptTrk2,"ptTrk2/D");
01036 t1->Branch("etaTrk2",&etaTrk2,"etaTrk2/D");
01037 t1->Branch("phiTrk2",&phiTrk2,"phiTrk2/D");
01038 t1->Branch("drTrk2",&drTrk2,"drTrk2/D");
01039 t1->Branch("purityTrk2",&purityTrk2,"purityTrk2/D");
01040
01041 t1->Branch("ptPxl1",&ptPxl1,"ptPxl1/D");
01042 t1->Branch("etaPxl1",&etaPxl1,"etaPxl1/D");
01043 t1->Branch("phiPxl1",&phiPxl1,"phiPxl1/D");
01044 t1->Branch("drPxl1",&drPxl1,"drPxl1/D");
01045 t1->Branch("purityPxl1",&purityPxl1,"purityPxl1/D");
01046 t1->Branch("ptPxl2",&ptPxl2,"ptPxl2/D");
01047 t1->Branch("etaPxl2",&etaPxl2,"etaPxl2/D");
01048 t1->Branch("phiPxl2",&phiPxl2,"phiPxl2/D");
01049 t1->Branch("drPxl2",&drPxl2,"drPxl2/D");
01050 t1->Branch("purityPxl2",&purityPxl2,"purityPxl2/D");
01051
01052 t1->Branch("etCalo1",&etCalo1,"etCalo1/D");
01053 t1->Branch("etCalo2",&etCalo2,"etCalo2/D");
01054 t1->Branch("eCalo1",&eCalo1,"eCalo1/D");
01055 t1->Branch("eCalo2",&eCalo2,"eCalo2/D");
01056
01057 t1->Branch("e1ECAL7x7",&e1ECAL7x7,"e1ECAL7x7/D");
01058 t1->Branch("e1ECAL11x11",&e1ECAL11x11,"e1ECAL11x11/D");
01059 t1->Branch("e2ECAL7x7",&e2ECAL7x7,"e2ECAL7x7/D");
01060 t1->Branch("e2ECAL11x11",&e2ECAL11x11,"e2ECAL11x11/D");
01061 t1->Branch("e1HCAL3x3",&e1HCAL3x3,"e1HCAL3x3/D");
01062 t1->Branch("e1HCAL5x5",&e1HCAL5x5,"e1HCAL5x5/D");
01063 t1->Branch("e2HCAL3x3",&e2HCAL3x3,"e2HCAL3x3/D");
01064 t1->Branch("e2HCAL5x5",&e2HCAL5x5,"e2HCAL5x5/D");
01065
01066 t1->Branch("trkQuality1",&trkQuality1,"trkQuality1/I");
01067 t1->Branch("trkQuality2",&trkQuality2,"trkQuality2/I");
01068 t1->Branch("trkNVhits1",&trkNVhits1,"trkNVhits1/I");
01069 t1->Branch("trkNVhits2",&trkNVhits2,"trkNVhits2/I");
01070 t1->Branch("idmax1",&idmax1,"idmax1/I");
01071 t1->Branch("idmax2",&idmax2,"idmax2/I");
01072
01073 return ;
01074 }
01075
01076
01077 void
01078 SinglePionEfficiencyNew::endJob() {
01079
01080
01081 hOutputFile->Write() ;
01082 hOutputFile->Close() ;
01083 return ;
01084
01085 }
01086
01087 double SinglePionEfficiencyNew::eECALmatrix(CaloNavigator<DetId>& navigator,edm::Handle<EcalRecHitCollection>& hits, int ieta, int iphi)
01088 {
01089 DetId thisDet;
01090 std::vector<DetId> dets;
01091 dets.clear();
01092 EcalRecHitCollection::const_iterator hit;
01093 double energySum = 0.0;
01094
01095 for (int dx = -ieta; dx < ieta+1; ++dx)
01096 {
01097 for (int dy = -iphi; dy < iphi+1; ++dy)
01098 {
01099
01100 thisDet = navigator.offsetBy(dx, dy);
01101 navigator.home();
01102
01103 if (thisDet != DetId(0))
01104 {
01105 hit = hits->find(thisDet);
01106 if (hit != hits->end())
01107 {
01108 dets.push_back(thisDet);
01109 energySum += hit->energy();
01110 }
01111 }
01112 }
01113 }
01114 return energySum;
01115 }
01116
01117 double SinglePionEfficiencyNew::eHCALmatrix(const HcalTopology* topology, const DetId& det, const HBHERecHitCollection& hits, int ieta, int iphi)
01118 {
01119 double energy = 0;
01120
01121 if(ieta > 2) {
01122 cout <<" no matrix > 5x5 is coded ! " << endl;
01123 return energy;
01124 }
01125
01126 std::vector<DetId> dets;
01127 dets.clear();
01128
01129
01130 HBHERecHitCollection::const_iterator hbheItr = hits.find(det);
01131 if(hbheItr != hits.end()) {
01132 energy = hbheItr->energy();
01133 dets.push_back(det);
01134 }
01135 HcalDetId depth = det;
01136
01137 for(int idepth = 0; idepth < 2; idepth++) {
01138 std::vector<DetId> vUpDetId = topology->up(depth);
01139 if(vUpDetId.size() != 0) {
01140 int n = std::count(dets.begin(),dets.end(),vUpDetId[0]);
01141 if(n == 0) {
01142 dets.push_back(vUpDetId[0]);
01143 HBHERecHitCollection::const_iterator hbheItrUp = hits.find(vUpDetId[0]);
01144 if(hbheItrUp != hits.end()) {
01145 energy = energy + hbheItrUp->energy();
01146 }
01147 }
01148 depth = vUpDetId[0];
01149 }
01150 }
01151
01152
01153 std::vector<DetId> vNeighboursDetId = topology->east(det);
01154 energy = energy + eHCALneighbours(vNeighboursDetId, dets, topology, hits);
01155 if(ieta == 2) {
01156 for (int ii = 0; ii < (int) vNeighboursDetId.size(); ii++) {
01157 std::vector<DetId> vNeighboursDetIdc = topology->east(vNeighboursDetId[ii]);
01158 energy = energy + eHCALneighbours(vNeighboursDetIdc, dets, topology, hits);
01159 }
01160 }
01161 vNeighboursDetId.clear();
01162
01163 vNeighboursDetId = topology->west(det);
01164 energy = energy + eHCALneighbours(vNeighboursDetId, dets, topology, hits);
01165 if(ieta == 2) {
01166 for (int ii = 0; ii < (int) vNeighboursDetId.size(); ii++) {
01167 std::vector<DetId> vNeighboursDetIdc = topology->west(vNeighboursDetId[ii]);
01168 energy = energy + eHCALneighbours(vNeighboursDetIdc, dets, topology, hits);
01169 }
01170 }
01171 vNeighboursDetId.clear();
01172
01173
01174
01175 DetId detnorth = det;
01176 for (int inorth = 0; inorth < iphi; inorth++) {
01177 std::vector<DetId> NorthDetId = topology->north(detnorth);
01178 energy = energy + eHCALneighbours(NorthDetId, dets, topology, hits);
01179
01180
01181 vNeighboursDetId = topology->east(NorthDetId[0]);
01182 energy = energy + eHCALneighbours(vNeighboursDetId, dets, topology, hits);
01183 if(ieta == 2) {
01184 for (int ii = 0; ii < (int) vNeighboursDetId.size(); ii++) {
01185 std::vector<DetId> vNeighboursDetIdc = topology->east(vNeighboursDetId[ii]);
01186 energy = energy + eHCALneighbours(vNeighboursDetIdc, dets, topology, hits);
01187 }
01188 }
01189 vNeighboursDetId.clear();
01190
01191 vNeighboursDetId = topology->west(NorthDetId[0]);
01192 energy = energy + eHCALneighbours(vNeighboursDetId, dets, topology, hits);
01193 if(ieta == 2) {
01194 for (int ii = 0; ii < (int) vNeighboursDetId.size(); ii++) {
01195 std::vector<DetId> vNeighboursDetIdc = topology->west(vNeighboursDetId[ii]);
01196 energy = energy + eHCALneighbours(vNeighboursDetIdc, dets, topology, hits);
01197 }
01198 }
01199 detnorth = NorthDetId[0];
01200 vNeighboursDetId.clear();
01201 }
01202
01203
01204 DetId detsouth = det;
01205 for (int isouth = 0; isouth < iphi; isouth++) {
01206 std::vector<DetId> SouthDetId = topology->south(detsouth);
01207 energy = energy + eHCALneighbours(SouthDetId, dets, topology, hits);
01208
01209
01210 vNeighboursDetId = topology->east(SouthDetId[0]);
01211 energy = energy + eHCALneighbours(vNeighboursDetId, dets, topology, hits);
01212 if(ieta == 2) {
01213 for (int ii = 0; ii < (int) vNeighboursDetId.size(); ii++) {
01214 std::vector<DetId> vNeighboursDetIdc = topology->east(vNeighboursDetId[ii]);
01215 energy = energy + eHCALneighbours(vNeighboursDetIdc, dets, topology, hits);
01216 }
01217 }
01218 vNeighboursDetId.clear();
01219
01220 vNeighboursDetId = topology->west(SouthDetId[0]);
01221 energy = energy + eHCALneighbours(vNeighboursDetId, dets, topology, hits);
01222 if(ieta == 2) {
01223 for (int ii = 0; ii < (int) vNeighboursDetId.size(); ii++) {
01224 std::vector<DetId> vNeighboursDetIdc = topology->west(vNeighboursDetId[ii]);
01225 energy = energy + eHCALneighbours(vNeighboursDetIdc, dets, topology, hits);
01226 }
01227 }
01228 detsouth = SouthDetId[0];
01229 vNeighboursDetId.clear();
01230 }
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255 return energy;
01256 }
01257
01258 double SinglePionEfficiencyNew::eHCALneighbours(std::vector<DetId>& vNeighboursDetId, std::vector<DetId>& dets,
01259 const HcalTopology* topology, const HBHERecHitCollection& hits)
01260 {
01261 double eHCALneighbour = 0.;
01262 for(int i = 0; i < (int) vNeighboursDetId.size(); i++) {
01263 int n = std::count(dets.begin(),dets.end(),vNeighboursDetId[i]);
01264 if(n != 0) continue;
01265 dets.push_back(vNeighboursDetId[i]);
01266 HBHERecHitCollection::const_iterator hbheItr = hits.find(vNeighboursDetId[i]);
01267 if(hbheItr != hits.end()) {
01268 eHCALneighbour = eHCALneighbour + hbheItr->energy();
01269 }
01270
01271
01272 HcalDetId depth = vNeighboursDetId[i];
01273
01274 for(int idepth = 0; idepth < 2; idepth++) {
01275
01276
01277
01278
01279
01280
01281 std::vector<DetId> vUpDetId = topology->up(depth);
01282 if(vUpDetId.size() != 0) {
01283 int n = std::count(dets.begin(),dets.end(),vUpDetId[0]);
01284 if(n == 0) {
01285 dets.push_back(vUpDetId[0]);
01286 HBHERecHitCollection::const_iterator hbheItrUp = hits.find(vUpDetId[0]);
01287 if(hbheItrUp != hits.end()) {
01288 eHCALneighbour = eHCALneighbour + hbheItrUp->energy();
01289 }
01290 }
01291 depth = vUpDetId[0];
01292 }
01293 }
01294
01295 }
01296 return eHCALneighbour;
01297 }
01298
01299
01300 DEFINE_FWK_MODULE(SinglePionEfficiencyNew);