00001 #include <iostream>
00002 #include <vector>
00003 #include <memory>
00004
00005
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/Utilities/interface/Exception.h"
00012
00013 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00014 #include "DataFormats/EgammaTrackReco/interface/TrackCandidateSuperClusterAssociation.h"
00015 #include "DataFormats/EgammaTrackReco/interface/TrackCandidateCaloClusterAssociation.h"
00016
00017 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00018
00019 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00020
00021 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionSeedFinder.h"
00022 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionTrackFinder.h"
00023
00024 #include "RecoEgamma/EgammaPhotonProducers/interface/ConversionTrackCandidateProducer.h"
00025
00026 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
00027 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00028 #include "RecoTracker/Record/interface/NavigationSchoolRecord.h"
00029 #include "RecoEgamma/EgammaPhotonAlgos/interface/OutInConversionSeedFinder.h"
00030 #include "RecoEgamma/EgammaPhotonAlgos/interface/InOutConversionSeedFinder.h"
00031 #include "RecoEgamma/EgammaPhotonAlgos/interface/OutInConversionTrackFinder.h"
00032 #include "RecoEgamma/EgammaPhotonAlgos/interface/InOutConversionTrackFinder.h"
00033 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
00034 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaRecHitIsolation.h"
00035
00036 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00037 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00038 #include "CommonTools/Utils/interface/StringToEnumValue.h"
00039 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00040 #include "DataFormats/DetId/interface/DetId.h"
00041 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00042 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00043
00044
00045 ConversionTrackCandidateProducer::ConversionTrackCandidateProducer(const edm::ParameterSet& config) :
00046 conf_(config),
00047 theNavigationSchool_(0),
00048 theOutInSeedFinder_(0),
00049 theOutInTrackFinder_(0),
00050 theInOutSeedFinder_(0),
00051 theInOutTrackFinder_(0)
00052 {
00053
00054
00055
00056
00057 nEvt_=0;
00058
00059
00060
00061
00062 bcBarrelCollection_ = conf_.getParameter<edm::InputTag>("bcBarrelCollection");
00063 bcEndcapCollection_ = conf_.getParameter<edm::InputTag>("bcEndcapCollection");
00064
00065 scHybridBarrelProducer_ = conf_.getParameter<edm::InputTag>("scHybridBarrelProducer");
00066 scIslandEndcapProducer_ = conf_.getParameter<edm::InputTag>("scIslandEndcapProducer");
00067
00068 OutInTrackCandidateCollection_ = conf_.getParameter<std::string>("outInTrackCandidateCollection");
00069 InOutTrackCandidateCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateCollection");
00070
00071
00072 OutInTrackSuperClusterAssociationCollection_ = conf_.getParameter<std::string>("outInTrackCandidateSCAssociationCollection");
00073 InOutTrackSuperClusterAssociationCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateSCAssociationCollection");
00074
00075 barrelecalCollection_ = conf_.getParameter<edm::InputTag>("barrelEcalRecHitCollection");
00076 endcapecalCollection_ = conf_.getParameter<edm::InputTag>("endcapEcalRecHitCollection");
00077
00078 hcalTowers_ = conf_.getParameter<edm::InputTag>("hcalTowers");
00079 hOverEConeSize_ = conf_.getParameter<double>("hOverEConeSize");
00080 maxHOverE_ = conf_.getParameter<double>("maxHOverE");
00081 minSCEt_ = conf_.getParameter<double>("minSCEt");
00082 isoConeR_ = conf_.getParameter<double>("isoConeR");
00083 isoInnerConeR_ = conf_.getParameter<double>("isoInnerConeR");
00084 isoEtaSlice_ = conf_.getParameter<double>("isoEtaSlice");
00085 isoEtMin_ = conf_.getParameter<double>("isoEtMin");
00086 isoEMin_ = conf_.getParameter<double>("isoEMin");
00087 vetoClusteredHits_ = conf_.getParameter<bool>("vetoClusteredHits");
00088 useNumXtals_ = conf_.getParameter<bool>("useNumXstals");
00089 severityLevelCut_ = conf_.getParameter<int>("severityLevelCut");
00090 ecalIsoCut_offset_ = conf_.getParameter<double>("ecalIsoCut_offset");
00091 ecalIsoCut_slope_ = conf_.getParameter<double>("ecalIsoCut_slope");
00092
00093 const std::vector<std::string> flagnames =
00094 conf_.getParameter<std::vector<std::string> >("recHitFlagsToBeExcluded");
00095
00096 v_chstatus_= StringToEnumValue<EcalRecHit::Flags>(flagnames);
00097
00098
00099
00100 produces< TrackCandidateCollection > (OutInTrackCandidateCollection_);
00101 produces< TrackCandidateCollection > (InOutTrackCandidateCollection_);
00102
00103 produces< reco::TrackCandidateCaloClusterPtrAssociation > ( OutInTrackSuperClusterAssociationCollection_);
00104 produces< reco::TrackCandidateCaloClusterPtrAssociation > ( InOutTrackSuperClusterAssociationCollection_);
00105
00106
00107 }
00108
00109 ConversionTrackCandidateProducer::~ConversionTrackCandidateProducer() {}
00110
00111 void ConversionTrackCandidateProducer::setEventSetup (const edm::EventSetup & theEventSetup) {
00112
00113
00114 theOutInSeedFinder_->setEventSetup(theEventSetup);
00115 theInOutSeedFinder_->setEventSetup(theEventSetup);
00116 theOutInTrackFinder_->setEventSetup(theEventSetup);
00117 theInOutTrackFinder_->setEventSetup(theEventSetup);
00118
00119
00120 }
00121
00122
00123 void ConversionTrackCandidateProducer::beginRun (edm::Run& r , edm::EventSetup const & theEventSetup) {
00124
00125 edm::ESHandle<NavigationSchool> nav;
00126 theEventSetup.get<NavigationSchoolRecord>().get("SimpleNavigationSchool", nav);
00127 theNavigationSchool_ = nav.product();
00128
00129
00130 theOutInSeedFinder_ = new OutInConversionSeedFinder ( conf_ );
00131
00132
00133 theOutInTrackFinder_ = new OutInConversionTrackFinder ( theEventSetup, conf_ );
00134
00135
00136
00137 theInOutSeedFinder_ = new InOutConversionSeedFinder ( conf_ );
00138
00139
00140
00141 theInOutTrackFinder_ = new InOutConversionTrackFinder ( theEventSetup, conf_ );
00142
00143
00144
00145 }
00146
00147
00148 void ConversionTrackCandidateProducer::endRun (edm::Run& r , edm::EventSetup const & theEventSetup) {
00149 delete theOutInSeedFinder_;
00150 delete theOutInTrackFinder_;
00151 delete theInOutSeedFinder_;
00152 delete theInOutTrackFinder_;
00153 }
00154
00155
00156
00157
00158 void ConversionTrackCandidateProducer::produce(edm::Event& theEvent, const edm::EventSetup& theEventSetup) {
00159
00160 using namespace edm;
00161 nEvt_++;
00162
00163
00164
00165
00166 setEventSetup( theEventSetup );
00167 theOutInSeedFinder_->setEvent(theEvent);
00168 theInOutSeedFinder_->setEvent(theEvent);
00169 theOutInTrackFinder_->setEvent(theEvent);
00170 theInOutTrackFinder_->setEvent(theEvent);
00171
00172
00173 NavigationSetter setter(*theNavigationSchool_);
00174
00175
00176
00177
00178
00179 std::auto_ptr<TrackCandidateCollection> outInTrackCandidate_p(new TrackCandidateCollection);
00180
00181 std::auto_ptr<TrackCandidateCollection> inOutTrackCandidate_p(new TrackCandidateCollection);
00182
00183 std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> outInAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
00184 std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> inOutAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
00185
00186
00187 bool validBarrelBCHandle=true;
00188 edm::Handle<edm::View<reco::CaloCluster> > bcBarrelHandle;
00189 theEvent.getByLabel(bcBarrelCollection_, bcBarrelHandle);
00190 if (!bcBarrelHandle.isValid()) {
00191 edm::LogError("ConversionTrackCandidateProducer") << "Error! Can't get the product "<<bcBarrelCollection_.label();
00192 validBarrelBCHandle=false;
00193 }
00194
00195
00196
00197 bool validEndcapBCHandle=true;
00198 edm::Handle<edm::View<reco::CaloCluster> > bcEndcapHandle;
00199 theEvent.getByLabel(bcEndcapCollection_, bcEndcapHandle);
00200 if (!bcEndcapHandle.isValid()) {
00201 edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<bcEndcapCollection_.label();
00202 validEndcapBCHandle=false;
00203 }
00204
00205
00206
00207
00208 bool validBarrelSCHandle=true;
00209 edm::Handle<edm::View<reco::CaloCluster> > scBarrelHandle;
00210 theEvent.getByLabel(scHybridBarrelProducer_,scBarrelHandle);
00211 if (!scBarrelHandle.isValid()) {
00212 edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<scHybridBarrelProducer_.label();
00213 validBarrelSCHandle=false;
00214 }
00215
00216
00217
00218 bool validEndcapSCHandle=true;
00219 edm::Handle<edm::View<reco::CaloCluster> > scEndcapHandle;
00220 theEvent.getByLabel(scIslandEndcapProducer_,scEndcapHandle);
00221 if (!scEndcapHandle.isValid()) {
00222 edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<scIslandEndcapProducer_.label();
00223 validEndcapSCHandle=false;
00224 }
00225
00226
00227
00228 theEventSetup.get<CaloGeometryRecord>().get(theCaloGeom_);
00229
00230
00231 Handle<CaloTowerCollection> hcalTowersHandle;
00232 theEvent.getByLabel(hcalTowers_, hcalTowersHandle);
00233
00234 edm::Handle<EcalRecHitCollection> ecalhitsCollEB;
00235 edm::Handle<EcalRecHitCollection> ecalhitsCollEE;
00236
00237 theEvent.getByLabel(endcapecalCollection_, ecalhitsCollEE);
00238 theEvent.getByLabel(barrelecalCollection_, ecalhitsCollEB);
00239
00240
00241
00242 edm::ESHandle<EcalChannelStatus> chStatus;
00243 theEventSetup.get<EcalChannelStatusRcd>().get(chStatus);
00244
00245 edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
00246 theEventSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);
00247 const EcalSeverityLevelAlgo* sevLevel = sevlv.product();
00248
00249 std::auto_ptr<CaloRecHitMetaCollectionV> RecHitsEE(0);
00250 RecHitsEE = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(ecalhitsCollEE.product()));
00251
00252 std::auto_ptr<CaloRecHitMetaCollectionV> RecHitsEB(0);
00253 RecHitsEB = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(ecalhitsCollEB.product()));
00254
00255
00256 caloPtrVecOutIn_.clear();
00257 caloPtrVecInOut_.clear();
00258
00259 bool isBarrel=true;
00260 if ( validBarrelBCHandle && validBarrelSCHandle )
00261 buildCollections(isBarrel, scBarrelHandle, bcBarrelHandle, ecalhitsCollEB, &(*RecHitsEB), sevLevel, &(*chStatus), hcalTowersHandle, *outInTrackCandidate_p,*inOutTrackCandidate_p,caloPtrVecOutIn_,caloPtrVecInOut_ );
00262
00263 if ( validEndcapBCHandle && validEndcapSCHandle ) {
00264 isBarrel=false;
00265 buildCollections(isBarrel,scEndcapHandle, bcEndcapHandle, ecalhitsCollEE, &(*RecHitsEE), sevLevel, &(*chStatus), hcalTowersHandle, *outInTrackCandidate_p,*inOutTrackCandidate_p,caloPtrVecOutIn_,caloPtrVecInOut_ );
00266 }
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 const edm::OrphanHandle<TrackCandidateCollection> refprodOutInTrackC = theEvent.put( outInTrackCandidate_p, OutInTrackCandidateCollection_ );
00278
00279
00280
00281 const edm::OrphanHandle<TrackCandidateCollection> refprodInOutTrackC = theEvent.put( inOutTrackCandidate_p, InOutTrackCandidateCollection_ );
00282
00283
00284
00285 edm::ValueMap<reco::CaloClusterPtr>::Filler fillerOI(*outInAssoc_p);
00286 fillerOI.insert(refprodOutInTrackC, caloPtrVecOutIn_.begin(), caloPtrVecOutIn_.end());
00287 fillerOI.fill();
00288 edm::ValueMap<reco::CaloClusterPtr>::Filler fillerIO(*inOutAssoc_p);
00289 fillerIO.insert(refprodInOutTrackC, caloPtrVecInOut_.begin(), caloPtrVecInOut_.end());
00290 fillerIO.fill();
00291
00292
00293
00294
00295 theEvent.put( outInAssoc_p, OutInTrackSuperClusterAssociationCollection_);
00296
00297
00298 theEvent.put( inOutAssoc_p, InOutTrackSuperClusterAssociationCollection_);
00299
00300 theOutInSeedFinder_->clear();
00301 theInOutSeedFinder_->clear();
00302
00303
00304
00305 }
00306
00307
00308 void ConversionTrackCandidateProducer::buildCollections(bool isBarrel,
00309 const edm::Handle<edm::View<reco::CaloCluster> > & scHandle,
00310 const edm::Handle<edm::View<reco::CaloCluster> > & bcHandle,
00311 edm::Handle<EcalRecHitCollection> ecalRecHitHandle,
00312 CaloRecHitMetaCollectionV* ecalRecHits,
00313 const EcalSeverityLevelAlgo* sevLevel,
00314 edm::ESHandle<EcalChannelStatus> chStatus,
00315
00316 const edm::Handle<CaloTowerCollection> & hcalTowersHandle,
00317 TrackCandidateCollection& outInTrackCandidates,
00318 TrackCandidateCollection& inOutTrackCandidates,
00319 std::vector<edm::Ptr<reco::CaloCluster> >& vecRecOI,
00320 std::vector<edm::Ptr<reco::CaloCluster> >& vecRecIO )
00321
00322 {
00323
00324
00325
00326
00327
00328 for (unsigned i = 0; i < scHandle->size(); ++i ) {
00329
00330 reco::CaloClusterPtr aClus= scHandle->ptrAt(i);
00331
00332
00333 if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
00334 const reco::CaloCluster* pClus=&(*aClus);
00335 const reco::SuperCluster* sc=dynamic_cast<const reco::SuperCluster*>(pClus);
00336 double scEt = sc->energy()/cosh(sc->eta());
00337 const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
00338 EgammaTowerIsolation towerIso(hOverEConeSize_,0.,0.,-1,hcalTowersColl) ;
00339 double HoE=towerIso.getTowerESum(sc)/sc->energy();
00340 if (HoE>=maxHOverE_) continue;
00341
00343 EgammaRecHitIsolation ecalIso(isoConeR_,
00344 isoInnerConeR_,
00345 isoEtaSlice_,
00346 isoEtMin_,
00347 isoEMin_,
00348 theCaloGeom_,
00349 &(*ecalRecHits),
00350 sevLevel,
00351 DetId::Ecal);
00352
00353 ecalIso.setVetoClustered(vetoClusteredHits_);
00354 ecalIso.setUseNumCrystals(useNumXtals_);
00355 if ( isBarrel ) ecalIso.doSpikeRemoval(ecalRecHitHandle.product(),chStatus.product(),severityLevelCut_);
00356 ecalIso.doFlagChecks(v_chstatus_);
00357 double ecalIsolation = ecalIso.getEtSum(sc);
00358 if ( ecalIsolation > ecalIsoCut_offset_ + ecalIsoCut_slope_*scEt ) continue;
00359
00360
00361
00362 theOutInSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
00363 theOutInSeedFinder_->makeSeeds( bcHandle );
00364
00365 std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(theOutInSeedFinder_->seeds(), outInTrackCandidates);
00366
00367
00368 theInOutSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
00369 theInOutSeedFinder_->setTracks( theOutInTracks );
00370 theInOutSeedFinder_->makeSeeds( bcHandle);
00371
00372 std::vector<Trajectory> theInOutTracks= theInOutTrackFinder_->tracks(theInOutSeedFinder_->seeds(), inOutTrackCandidates);
00373
00374
00375
00376
00377
00378
00380 for (std::vector<Trajectory>::const_iterator it = theOutInTracks.begin(); it != theOutInTracks.end(); ++it) {
00381 caloPtrVecOutIn_.push_back(aClus);
00382
00383 }
00384
00385 for (std::vector<Trajectory>::const_iterator it = theInOutTracks.begin(); it != theInOutTracks.end(); ++it) {
00386 caloPtrVecInOut_.push_back(aClus);
00387
00388 }
00389
00390
00391
00392
00393
00394
00395 }
00396
00397
00398
00399 }
00400