1 |
lethuill |
1.5 |
#include "../interface/PhotonAnalyzer.h"
|
2 |
mlethuil |
1.1 |
|
3 |
|
|
using namespace std;
|
4 |
|
|
using namespace reco;
|
5 |
|
|
using namespace edm;
|
6 |
|
|
|
7 |
lethuill |
1.6 |
PhotonAnalyzer::PhotonAnalyzer(const edm::ParameterSet& producersNames):verbosity_(0), iconvtrack_(0), doPhotonConversion_(true), doVertexCorrection_(true),useMC_(false)
|
8 |
mlethuil |
1.1 |
{
|
9 |
lethuill |
1.2 |
photonIDProducer_ = producersNames.getParameter<edm::InputTag>("photonIDProducer");
|
10 |
mlethuil |
1.1 |
}
|
11 |
lethuill |
1.2 |
|
12 |
lethuill |
1.6 |
PhotonAnalyzer::PhotonAnalyzer(const edm::ParameterSet& producersNames, const edm::ParameterSet& myConfig, int verbosity, bool doPhotonConversion, bool doVertexCorrection):verbosity_(verbosity), iconvtrack_(0), doPhotonConversion_(doPhotonConversion), doVertexCorrection_(doVertexCorrection)
|
13 |
lethuill |
1.2 |
{
|
14 |
lethuill |
1.6 |
dataType_ = producersNames.getUntrackedParameter<string>("dataType","unknown");
|
15 |
lethuill |
1.2 |
photonIDProducer_ = producersNames.getParameter<edm::InputTag>("photonIDProducer");
|
16 |
|
|
}
|
17 |
|
|
|
18 |
mlethuil |
1.1 |
PhotonAnalyzer::~PhotonAnalyzer()
|
19 |
|
|
{
|
20 |
|
|
}
|
21 |
|
|
|
22 |
lethuill |
1.2 |
void PhotonAnalyzer::Process(const edm::Event& iEvent, const edm::EventSetup& iSetup, TRootEvent* rootEvent, TClonesArray* rootPhotons, string collectionName, TClonesArray* conversionTracks, ConversionLikelihoodCalculator* convLikelihoodCalculator, EcalClusterLazyTools& lazyTools)
|
23 |
mlethuil |
1.1 |
{
|
24 |
|
|
|
25 |
|
|
edm::Handle< reco::PhotonCollection > recoPhotons;
|
26 |
|
|
iEvent.getByLabel(collectionName, recoPhotons);
|
27 |
lethuill |
1.4 |
if(verbosity_>1) std::cout << " Producer: " << collectionName << " PhotonID Producer: " << photonIDProducer_.label() << " - Number of photons = " << recoPhotons->size() << std::endl;
|
28 |
lethuill |
1.2 |
|
29 |
|
|
edm::Handle<reco::PhotonIDAssociationCollection> photonIDMapColl;
|
30 |
|
|
iEvent.getByLabel(photonIDProducer_, photonIDMapColl);
|
31 |
|
|
const reco::PhotonIDAssociationCollection *photonIDMap = photonIDMapColl.product();
|
32 |
|
|
|
33 |
|
|
/*
|
34 |
|
|
// Cluster Shapes with EcalTools
|
35 |
mlethuil |
1.1 |
|
36 |
lethuill |
1.2 |
cout << "ecalBarrelRecHitHandle..."<<endl;
|
37 |
|
|
// Get handle to rec hits ecal barrel
|
38 |
|
|
edm::Handle<EcalRecHitCollection> ecalBarrelRecHitHandle;
|
39 |
|
|
iEvent.getByLabel(reducedBarrelEcalRecHitCollection_, ecalBarrelRecHitHandle);
|
40 |
|
|
if (!ecalBarrelRecHitHandle.isValid())
|
41 |
|
|
{
|
42 |
|
|
edm::LogError("PhotonAnalyzer.cc") << "Error! Can't get the product " << reducedBarrelEcalRecHitCollection_;
|
43 |
|
|
return;
|
44 |
|
|
}
|
45 |
mlethuil |
1.1 |
|
46 |
lethuill |
1.2 |
cout << "ecalEndcapRecHitHandle..."<<endl;
|
47 |
|
|
// Get handle to rec hits ecal endcap
|
48 |
|
|
edm::Handle<EcalRecHitCollection> ecalEndcapRecHitHandle;
|
49 |
|
|
iEvent.getByLabel(reducedEndcapEcalRecHitCollection_, ecalEndcapRecHitHandle);
|
50 |
|
|
if (!ecalEndcapRecHitHandle.isValid())
|
51 |
|
|
{
|
52 |
|
|
edm::LogError("PhotonAnalyzer.cc") << "Error! Can't get the product " << reducedEndcapEcalRecHitCollection_;
|
53 |
|
|
return;
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
cout << "CaloTopology..."<<endl;
|
57 |
|
|
// Get calorimeter topology
|
58 |
|
|
edm::ESHandle<CaloTopology> caloTopo;
|
59 |
|
|
iSetup.get<CaloTopologyRecord>().get(caloTopo);
|
60 |
|
|
const CaloTopology *topology = caloTopo.product();
|
61 |
|
|
*/
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
// TODO - add Pi0Disc... not yet implemented in 2.1.X
|
65 |
|
|
//cout << "Pi0Disc..."<<endl;
|
66 |
|
|
//edm::Handle<reco::PhotonPi0DiscriminatorAssociationMap> pi0map;
|
67 |
|
|
//iEvent.getByLabel("piZeroDiscriminators","PhotonPi0DiscriminatorAssociationMap", pi0map);
|
68 |
|
|
//reco::PhotonPi0DiscriminatorAssociationMap::const_iterator pi0mapIter;
|
69 |
|
|
//Double_t pi0nn;
|
70 |
|
|
|
71 |
|
|
// Index in TRootPhoton TCloneArray
|
72 |
|
|
unsigned int iPhoton = 0;
|
73 |
|
|
|
74 |
|
|
for (unsigned int iphot=0; iphot<recoPhotons->size(); iphot++)
|
75 |
mlethuil |
1.1 |
{
|
76 |
|
|
|
77 |
lethuill |
1.2 |
// TODO - add Pi0Disc... not yet implemented in 2.1.X
|
78 |
|
|
//pi0mapIter = pi0map->find(edm::Ref<reco::PhotonCollection>(recoPhotons,iPhoton));
|
79 |
|
|
//pi0nn = ( pi0mapIter == pi0map->end() ? -1 : pi0mapIter->val );
|
80 |
|
|
|
81 |
|
|
edm::Ref<reco::PhotonCollection> photonRef(recoPhotons, iphot);
|
82 |
|
|
reco::PhotonIDAssociationCollection::const_iterator photonIter = photonIDMap->find(photonRef);
|
83 |
|
|
const reco::PhotonIDRef &photonID = photonIter->val;
|
84 |
|
|
const reco::PhotonRef &photon = photonIter->key;
|
85 |
|
|
|
86 |
|
|
TRootPhoton localPhoton( photon->px(), photon->py(), photon->pz(), photon->energy(), photon->vx(), photon->vy(), photon->vz(), 22, photon->charge() );
|
87 |
|
|
localPhoton.setHasPixelSeed( photon->hasPixelSeed() );
|
88 |
|
|
localPhoton.setHoE(photon->hadronicOverEm());
|
89 |
|
|
// TODO - add Pi0Disc... not yet implemented in 2.1.X
|
90 |
|
|
//localPhoton.setPi0nn( pi0nn );
|
91 |
|
|
|
92 |
|
|
localPhoton.setSCRawEnergy( photon->superCluster()->rawEnergy() );
|
93 |
|
|
localPhoton.setCaloPosition( photon->caloPosition().X(), photon->caloPosition().Y(), photon->caloPosition().Z() );
|
94 |
|
|
|
95 |
|
|
reco::BasicClusterRef localSeed = photon->superCluster()->seed();
|
96 |
|
|
localPhoton.setEmax( lazyTools.eMax(*localSeed) );
|
97 |
|
|
localPhoton.setE3x3( lazyTools.e3x3(*localSeed) );
|
98 |
|
|
localPhoton.setE5x5( lazyTools.e5x5(*localSeed) );
|
99 |
|
|
localPhoton.setBitsID( photonID->isLooseEM(), photonID->isLoosePhoton(), photonID->isTightPhoton(), photonID->isEBPho(), photonID->isEEPho(), photonID->isEBGap(), photonID->isEEGap(), photonID->isEBEEGap(), photonID->isAlsoElectron() );
|
100 |
|
|
|
101 |
|
|
if(verbosity_>4) std::cout << "seed E5x5=" << lazyTools.e5x5( *localSeed )
|
102 |
|
|
//<< " pi0NN=" << pi0nn
|
103 |
|
|
<< " photonID->isolationEcalRecHit()=" << photonID->isolationEcalRecHit()
|
104 |
|
|
<< " photonID->r9()=" << photonID->r9()
|
105 |
|
|
<< " e3x3 / SC->energy()=" << ( lazyTools.e3x3( *localSeed ) / photon->superCluster()->energy() )
|
106 |
|
|
<< " e3x3 / SC->rawEnergy()=" << ( lazyTools.e3x3( *localSeed ) / photon->superCluster()->rawEnergy() )
|
107 |
|
|
<< " sc->pos=" << photon->superCluster()->position().X() << " , " << photon->superCluster()->position().Y() << " , " << photon->superCluster()->position().Z()
|
108 |
|
|
<< " photon->caloPos=" << photon->caloPosition().X() << " , " << photon->caloPosition().Y() << " , " << photon->caloPosition().Z()
|
109 |
|
|
<< std::endl;
|
110 |
mlethuil |
1.1 |
|
111 |
lethuill |
1.2 |
if( doPhotonConversion_ )
|
112 |
mlethuil |
1.1 |
{
|
113 |
lethuill |
1.2 |
// If more than one associated convertedPhotons is found, then
|
114 |
|
|
// if nTracks=2, select the convertedPhoton with greatest Likelihood value using Ted's weights file
|
115 |
|
|
// if nTracks=1, select the convertedPhoton with E/p closest to 1
|
116 |
|
|
double eoverp;
|
117 |
|
|
double best_eoverp = 999999.;
|
118 |
|
|
double likely;
|
119 |
|
|
double best_likely = -1.;
|
120 |
|
|
int best_iconv = -1;
|
121 |
|
|
int best_iconv_likely = -1;
|
122 |
|
|
int best_iconv_eoverp = -1;
|
123 |
|
|
|
124 |
|
|
std::vector<reco::ConversionRef> conversions = photon->conversions();
|
125 |
|
|
for (unsigned int iconv=0; iconv<conversions.size(); iconv++)
|
126 |
|
|
{
|
127 |
|
|
if(verbosity_>4) cout << " ["<< setw(3) << iconv << "] Conversion - "
|
128 |
|
|
<< " conv_vertex (x,y,z)=(" << conversions[iconv]->conversionVertex().x()
|
129 |
|
|
<< "," << conversions[iconv]->conversionVertex().y()
|
130 |
|
|
<< "," << conversions[iconv]->conversionVertex().z()
|
131 |
|
|
<< ") isConverted=" << conversions[iconv]->isConverted()
|
132 |
|
|
<< " nTracks=" << conversions[iconv]->nTracks()
|
133 |
|
|
<< " primary_vtx_z=" << conversions[iconv]->zOfPrimaryVertexFromTracks()
|
134 |
|
|
<< " inv_mass=" << conversions[iconv]->pairInvariantMass()
|
135 |
|
|
<< " E/p=" << conversions[iconv]->EoverP()
|
136 |
|
|
<< " cotanTheta=" << conversions[iconv]->pairCotThetaSeparation()
|
137 |
|
|
<< " likely=" << convLikelihoodCalculator->calculateLikelihood(conversions[iconv])
|
138 |
|
|
<< endl;
|
139 |
|
|
|
140 |
|
|
likely = convLikelihoodCalculator->calculateLikelihood(conversions[iconv]);
|
141 |
|
|
if ( likely>best_likely )
|
142 |
|
|
{
|
143 |
|
|
best_iconv_likely = iconv;
|
144 |
|
|
best_likely = likely;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
eoverp = conversions[iconv]->EoverP();
|
148 |
|
|
if ( abs(eoverp-1)<abs(best_eoverp-1) )
|
149 |
|
|
{
|
150 |
|
|
best_iconv_eoverp = iconv;
|
151 |
|
|
best_eoverp = eoverp;
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
best_iconv = (best_iconv_likely==-1 ? best_iconv_eoverp : best_iconv_likely);
|
156 |
|
|
|
157 |
|
|
// Update Photon object with conversion infos
|
158 |
|
|
if ( best_iconv != -1 )
|
159 |
|
|
{
|
160 |
|
|
if(verbosity_>4) cout
|
161 |
|
|
<< "Photon[" << iphot << "] associated to Conversion[" << best_iconv
|
162 |
|
|
<< "] with E/p=" << conversions[best_iconv]->EoverP()
|
163 |
|
|
<< " likely=" << convLikelihoodCalculator->calculateLikelihood(conversions[best_iconv])
|
164 |
|
|
<< endl;
|
165 |
|
|
|
166 |
|
|
localPhoton.setConvNTracks( conversions[best_iconv]->nTracks() );
|
167 |
|
|
localPhoton.setConvEoverP( conversions[best_iconv]->EoverP() );
|
168 |
|
|
localPhoton.setConvMass( conversions[best_iconv]->pairInvariantMass() );
|
169 |
|
|
localPhoton.setConvCotanTheta( conversions[best_iconv]->pairCotThetaSeparation() );
|
170 |
|
|
localPhoton.setConvLikely( convLikelihoodCalculator->calculateLikelihood(conversions[best_iconv]) );
|
171 |
|
|
localPhoton.setConvVertex( conversions[best_iconv]->conversionVertex().x(), conversions[best_iconv]->conversionVertex().y(), conversions[best_iconv]->conversionVertex().z() );
|
172 |
|
|
std::vector<math::XYZPoint> impactVector = conversions[best_iconv]->ecalImpactPosition();
|
173 |
|
|
if ( impactVector.size()>0 ) localPhoton.setConvEcalImpactPosition1( impactVector.at(0).x(), impactVector.at(0).y(), impactVector.at(0).z() );
|
174 |
|
|
if ( impactVector.size()>1 ) localPhoton.setConvEcalImpactPosition2( impactVector.at(1).x(), impactVector.at(1).y(), impactVector.at(1).z() );
|
175 |
|
|
|
176 |
|
|
if ( conversions[best_iconv]->nTracks()>0 )
|
177 |
|
|
{
|
178 |
|
|
std::vector<reco::TrackRef> tracks = conversions[best_iconv]->tracks();
|
179 |
|
|
reco::TrackRef tk1 = tracks.at(0);
|
180 |
|
|
const reco::HitPattern& hit1 = tk1->hitPattern();
|
181 |
|
|
new( (*conversionTracks)[iconvtrack_] ) TRootTrack( tk1->px(), tk1->py(), tk1->pz(), tk1->p(), tk1->vx(), tk1->vy(), tk1->vz(), 0, tk1->charge()
|
182 |
|
|
,hit1.numberOfValidPixelHits(), hit1.numberOfValidTrackerHits(), tk1->chi2(), tk1->d0(), tk1->d0Error(), tk1->dz(), tk1->dzError() );
|
183 |
|
|
localPhoton.setConvIndexTrack1(iconvtrack_);
|
184 |
lethuill |
1.3 |
localPhoton.setConvTrack1((*conversionTracks)[iconvtrack_]);
|
185 |
lethuill |
1.2 |
iconvtrack_++;
|
186 |
|
|
|
187 |
|
|
if ( conversions[best_iconv]->nTracks()>1 )
|
188 |
|
|
{
|
189 |
|
|
reco::TrackRef tk2 = tracks.at(1);
|
190 |
|
|
const reco::HitPattern& hit2 = tk2->hitPattern();
|
191 |
|
|
new( (*conversionTracks)[iconvtrack_] ) TRootTrack( tk2->px(), tk2->py(), tk2->pz(), tk2->p(), tk2->vx(), tk2->vy(), tk2->vz(), 0, tk2->charge()
|
192 |
|
|
,hit2.numberOfValidPixelHits(), hit2.numberOfValidTrackerHits(), tk2->chi2(), tk2->d0(), tk2->d0Error(), tk2->dz(), tk2->dzError() );
|
193 |
|
|
localPhoton.setConvIndexTrack2(iconvtrack_);
|
194 |
lethuill |
1.3 |
localPhoton.setConvTrack2((*conversionTracks)[iconvtrack_]);
|
195 |
lethuill |
1.2 |
iconvtrack_++;
|
196 |
|
|
}
|
197 |
|
|
}
|
198 |
|
|
}
|
199 |
mlethuil |
1.1 |
}
|
200 |
lethuill |
1.2 |
|
201 |
|
|
if(verbosity_>3) cout << " ["<< setw(3) << iPhoton << "] " << localPhoton << endl;
|
202 |
|
|
|
203 |
|
|
// Vertex correction to photon - Assume photon is coming from primary vertex
|
204 |
|
|
if( doVertexCorrection_)
|
205 |
mlethuil |
1.1 |
{
|
206 |
lethuill |
1.2 |
if( rootEvent->nPrimaryVertices()>0 )
|
207 |
|
|
{
|
208 |
|
|
TVector3 vertex( rootEvent->primaryVertex_x(), rootEvent->primaryVertex_y(), rootEvent->primaryVertex_z() );
|
209 |
|
|
localPhoton.setVertex(vertex);
|
210 |
|
|
if(verbosity_>3) cout << " after vtx correction - ["<< setw(3) << iPhoton << "] " << localPhoton << endl;
|
211 |
|
|
}
|
212 |
|
|
else
|
213 |
|
|
{
|
214 |
|
|
cout << " PhotonAnalyzer - NO PRIMARY VERTEX FOUND !!!" << endl;
|
215 |
|
|
}
|
216 |
mlethuil |
1.1 |
}
|
217 |
lethuill |
1.6 |
|
218 |
|
|
/*if(useMC_)
|
219 |
|
|
{
|
220 |
|
|
if( dataType_=="PAT" || dataType_=="PATAOD" )
|
221 |
|
|
// MC truth associator index
|
222 |
|
|
if ((photon.genParticleRef()).isNonnull()) {
|
223 |
lethuill |
1.7 |
localPhoton.setGenParticleIndex((photon.genParticleRef()).index());
|
224 |
lethuill |
1.6 |
} else {
|
225 |
lethuill |
1.7 |
localPhoton.setGenParticleIndex(-1);
|
226 |
lethuill |
1.6 |
}
|
227 |
|
|
if ( photon->genParticle() != NULL ) {
|
228 |
|
|
localPhoton.setMomentumMCPhoton(photon->genParticle()->px(),photon->genParticle()->py(),photon->genParticle()->pz(),photon->genParticle()->energy());
|
229 |
|
|
localPhoton.setVertexMCPhoton(TVector3(photon->genParticle()->vx(),photon->genParticle()->vy(),photon->genParticle()->vz()));
|
230 |
|
|
localPhoton.setPdgIdMCPhoton(photon->genParticle()->pdgId());
|
231 |
|
|
}
|
232 |
|
|
}
|
233 |
|
|
}*/
|
234 |
mlethuil |
1.1 |
|
235 |
lethuill |
1.2 |
// Stock new TRootPhoton in TCloneArray
|
236 |
|
|
new( (*rootPhotons)[iPhoton] ) TRootPhoton(localPhoton);
|
237 |
|
|
iPhoton++;
|
238 |
mlethuil |
1.1 |
}
|
239 |
|
|
}
|