CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
PFConversionAlgo Class Reference

#include <PFConversionAlgo.h>

Public Member Functions

std::vector< reco::PFCandidateconversionCandidates ()
 
bool isConversionValidCandidate (const reco::PFBlockRef &blockRef, std::vector< bool > &active)
 
 PFConversionAlgo ()
 
 ~PFConversionAlgo ()
 

Private Types

typedef std::multimap
< unsigned, std::vector
< unsigned > > 
AssMap
 

Private Member Functions

void runPFConversion (const reco::PFBlockRef &blockRef, std::vector< bool > &active)
 
void setActive (const reco::PFBlockRef &blockRef, AssMap &assToConv, std::vector< bool > &active)
 
void setCandidates (const reco::PFBlockRef &blockref, AssMap &assToConv)
 
bool setLinks (const reco::PFBlockRef &blockRef, AssMap &assToConv, std::vector< bool > &active)
 

Private Attributes

std::vector< reco::PFCandidateconversionCandidate_
 
bool isvalid_
 

Detailed Description

Definition at line 14 of file PFConversionAlgo.h.

Member Typedef Documentation

typedef std::multimap<unsigned, std::vector<unsigned> > PFConversionAlgo::AssMap
private

Definition at line 35 of file PFConversionAlgo.h.

Constructor & Destructor Documentation

PFConversionAlgo::PFConversionAlgo ( )

Definition at line 20 of file PFConversionAlgo.cc.

20  {
21 
22 }
PFConversionAlgo::~PFConversionAlgo ( )
inline

Definition at line 23 of file PFConversionAlgo.h.

23 {;};

Member Function Documentation

std::vector<reco::PFCandidate> PFConversionAlgo::conversionCandidates ( )
inline

Definition at line 35 of file PFConversionAlgo.h.

References conversionCandidate_.

Referenced by PFAlgo::processBlock().

35 {return conversionCandidate_;};
std::vector< reco::PFCandidate > conversionCandidate_
bool PFConversionAlgo::isConversionValidCandidate ( const reco::PFBlockRef blockRef,
std::vector< bool > &  active 
)
inline

Definition at line 26 of file PFConversionAlgo.h.

References isvalid_, and runPFConversion().

Referenced by PFAlgo::processBlock().

28  {
29  isvalid_=false;
30  runPFConversion(blockRef,active);
31  return isvalid_;
32  };
void runPFConversion(const reco::PFBlockRef &blockRef, std::vector< bool > &active)
void PFConversionAlgo::runPFConversion ( const reco::PFBlockRef blockRef,
std::vector< bool > &  active 
)
private

Definition at line 24 of file PFConversionAlgo.cc.

References reco::PFCandidate::gamma, and reco::PFCandidate::GAMMA_TO_GAMMACONV.

Referenced by isConversionValidCandidate().

25  {
26 
27  // std::cout << " PFConversionAlgo::RunPFConversion " << std::endl;
28 
29  AssMap elemAssociatedToConv;
30 
31  bool blockHasConversion = setLinks(blockRef,elemAssociatedToConv, active );
32 
33  if ( blockHasConversion ) {
34  conversionCandidate_.clear();
35  setCandidates(blockRef,elemAssociatedToConv);
36  if (conversionCandidate_.size() > 0 ){
37  isvalid_ = true;
38  //cout << " There is a candidate " << endl;
39  // if there is at least a candidate the active vector is modified
40  // setting = false all the elements used to build the candidate
41  setActive(blockRef,elemAssociatedToConv, active);
42  // this is just debug to check that all is going fine. Will take it out later
43  std::vector<reco::PFCandidate>::iterator it;
44  for ( it = conversionCandidate_.begin(); it != conversionCandidate_.end(); ++it ) {
45  reco::PFCandidate::ParticleType type = (*it).particleId();
46  bool isConverted = (*it).flag( reco::PFCandidate::GAMMA_TO_GAMMACONV );
47  if ( type == reco::PFCandidate::gamma && isConverted ) {
48  // cout<<"Conversion PFCandidate!"<< *it << endl;
49  }
50  }
51  }
52 
53  } // conversion was found in the block
54 
55 }
type
Definition: HCALResponse.h:22
ParticleType
particle types
Definition: PFCandidate.h:38
std::vector< reco::PFCandidate > conversionCandidate_
std::multimap< unsigned, std::vector< unsigned > > AssMap
void setActive(const reco::PFBlockRef &blockRef, AssMap &assToConv, std::vector< bool > &active)
void setCandidates(const reco::PFBlockRef &blockref, AssMap &assToConv)
bool setLinks(const reco::PFBlockRef &blockRef, AssMap &assToConv, std::vector< bool > &active)
void PFConversionAlgo::setActive ( const reco::PFBlockRef blockRef,
AssMap assToConv,
std::vector< bool > &  active 
)
private

Definition at line 352 of file PFConversionAlgo.cc.

References i, j, and findQualityFiles::size.

353  {
354 
355  // Lock tracks and clusters belonging to the conversion
356  for ( std::multimap<unsigned, std::vector<unsigned> >::iterator i=elemAssociatedToConv.begin();
357  i!= elemAssociatedToConv.end(); ++i) {
358  unsigned int iConvTrk = i->first;
359  active[iConvTrk]=false;
360  //std::cout << " PFConversionAlgo::setActive locking all elements linked to a conversion " << std::endl;
361  for (unsigned int j=0; j< (i->second).size(); ++j ) {
362  active[(i->second)[j]]=false;
363  //std::cout << " Locking element " << (i->second)[j] << std::endl;
364  }
365  }
366 
367 
368  return;
369 }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
tuple size
Write out results.
void PFConversionAlgo::setCandidates ( const reco::PFBlockRef blockref,
AssMap assToConv 
)
private

Get the momentum of the parent track pair

for a first try just simple cuts

Build candidate

Definition at line 243 of file PFConversionAlgo.cc.

References abs, reco::PFCandidate::addElementInBlock(), createPayload::block, reco::PFBlockElementCluster::clusterRef(), Geom::deltaPhi(), reco::PFBlockElement::ECAL, reco::PFBlock::elements(), asciidump::elements, reco::PFCluster::energy(), reco::PFCandidate::gamma, reco::PFCandidate::GAMMA_TO_GAMMACONV, i, j, reco::PFBlock::linkData(), pi, reco::PFCandidate::setConversionRef(), reco::PFCandidate::setEcalEnergy(), reco::PFCandidate::setFlag(), reco::PFCandidate::setHcalEnergy(), reco::PFCandidate::setPs1Energy(), reco::PFCandidate::setPs2Energy(), findQualityFiles::size, reco::PFBlockElement::TRACK, and reco::PFBlockElementTrack::trackRef().

244  {
245 
246 
247  vector<unsigned int> elementsToAdd(0);
248  const reco::PFBlock& block = *blockRef;
249  PFBlock::LinkData linkData = block.linkData();
251 
254  float EcalEne=0;
255  float pairPx=0;
256  float pairPy=0;
257  float pairPz=0;
258  const reco::PFBlockElementTrack* elTrack=0;
259  reco::TrackRef convTrackRef;
260  for ( std::multimap<unsigned, std::vector<unsigned> >::iterator i=elemAssociatedToConv.begin();
261  i!= elemAssociatedToConv.end(); ++i) {
262 
263  unsigned int iTrack = i->first;
264  elementsToAdd.push_back(iTrack);
265  // std::cout << " setCandidates adding track " << iTrack << " to block in PFCandiate " << std::endl;
266  elTrack = dynamic_cast<const reco::PFBlockElementTrack*>((&elements[iTrack]));
267  convTrackRef= elTrack->trackRef();
268  pairPx+=convTrackRef->innerMomentum().x();
269  pairPy+=convTrackRef->innerMomentum().y();
270  pairPz+=convTrackRef->innerMomentum().z();
271 
272  ConversionRef origConv = elements[iTrack].convRef();
273  // std::cout << " Ref to original conversions: track size " << origConv->tracks().size() << " SC energy " << origConv->caloCluster()[0]->energy() << std::endl;
274  // std::cout << " SC Et " << origConv->caloCluster()[0]->energy()/cosh(origConv->caloCluster()[0]->eta()) <<" eta " << origConv->caloCluster()[0]->eta() << " phi " << origConv->caloCluster()[0]->phi() << std::endl;
275 
276  unsigned int nEl= (i->second).size();
277  // std::cout << " Number of elements connected " << nEl << std::endl;
278  for (unsigned int j=0; j< nEl; ++j ) {
279  unsigned int iEl = (i->second)[j];
280  //std::cout << " Adding element " << iEl << std::endl;
281  PFBlockElement::Type typeassCalo = elements[iEl].type();
282 
284  if ( typeassCalo == reco::PFBlockElement::TRACK) {
285  const reco::PFBlockElementTrack * elTrack = dynamic_cast<const reco::PFBlockElementTrack*>((&elements[iEl]));
286  elTrack = dynamic_cast<const reco::PFBlockElementTrack*>((&elements[iEl]));
287  convTrackRef= elTrack->trackRef();
288  pairPx+=convTrackRef->innerMomentum().x();
289  pairPy+=convTrackRef->innerMomentum().y();
290  pairPz+=convTrackRef->innerMomentum().z();
291  }
292 
293  if ( typeassCalo == reco::PFBlockElement::ECAL) {
294  const reco::PFBlockElementCluster * clu = dynamic_cast<const reco::PFBlockElementCluster*>((&elements[iEl]));
295  reco::PFCluster cl=*clu->clusterRef();
296  EcalEne+= cl.energy();
297  }
298 
299  elementsToAdd.push_back(iEl);
300  }
301 
302  // std::cout << " setCandidates EcalEne " << EcalEne << std::endl;
304 
305  // define energy and momentum of the conversion. Momentum from the track pairs and Energy from
306  // the sum of the ecal cluster(s)
307  math::XYZTLorentzVector momentum;
308  momentum.SetPxPyPzE(pairPx , pairPy, pairPz, EcalEne);
309 
311 
312  float deltaCotTheta=origConv->pairCotThetaSeparation();
313  float phiTk1= origConv->tracks()[0]->innerMomentum().phi();
314  float phiTk2= origConv->tracks()[1]->innerMomentum().phi();
315  float deltaPhi = phiTk1-phiTk2;
316  if(deltaPhi > pi) {deltaPhi = deltaPhi - twopi;}
317  if(deltaPhi < -pi) {deltaPhi = deltaPhi + twopi;}
318 
320  if ( fabs(deltaCotTheta) < 0.05 && abs(deltaPhi<0.1) ) {
321 
322 
324  reco::PFCandidate aCandidate = PFCandidate(0, momentum,particleType);
325  for (unsigned int elad=0; elad<elementsToAdd.size();elad++){
326  aCandidate.addElementInBlock(blockRef,elementsToAdd[elad]);
327  }
328 
329 
331  aCandidate.setConversionRef(origConv);
332  aCandidate.setEcalEnergy(EcalEne,EcalEne);
333  aCandidate.setHcalEnergy(0.,0.);
334  aCandidate.setPs1Energy(0.);
335  aCandidate.setPs2Energy(0.);
336 
337 
338  conversionCandidate_.push_back( aCandidate);
339  }
340 
341 
342  }
343 
344 
345 
346  return;
347 }
void setPs2Energy(float e2)
set corrected PS2 energy
Definition: PFCandidate.h:232
int i
Definition: DBlmapReader.cc:9
void setPs1Energy(float e1)
set corrected PS1 energy
Definition: PFCandidate.h:226
ParticleType
particle types
Definition: PFCandidate.h:38
void setFlag(Flags theFlag, bool value)
set a given flag
Definition: PFCandidate.cc:191
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
std::vector< reco::PFCandidate > conversionCandidate_
double deltaPhi(float phi1, float phi2)
Definition: VectorUtil.h:30
PFClusterRef clusterRef() const
std::map< unsigned int, Link > LinkData
Definition: PFBlock.h:46
#define abs(x)
Definition: mlp_lapack.h:159
list elements
Definition: asciidump.py:414
const edm::OwnVector< reco::PFBlockElement > & elements() const
Definition: PFBlock.h:107
const LinkData & linkData() const
Definition: PFBlock.h:112
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
void addElementInBlock(const reco::PFBlockRef &blockref, unsigned elementIndex)
add an element to the current PFCandidate
Definition: PFCandidate.cc:119
int j
Definition: DBlmapReader.cc:9
double energy() const
cluster energy
Definition: PFCluster.h:73
void setEcalEnergy(float eeRaw, float eeCorr)
set corrected Ecal energy
Definition: PFCandidate.h:185
void setConversionRef(const reco::ConversionRef &ref)
set ref to original reco conversion
Definition: PFCandidate.cc:427
reco::TrackRef trackRef() const
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:33
double pi
tuple size
Write out results.
void setHcalEnergy(float ehRaw, float ehCorr)
set corrected Hcal energy
Definition: PFCandidate.h:195
Block of elements.
Definition: PFBlock.h:30
bool PFConversionAlgo::setLinks ( const reco::PFBlockRef blockRef,
AssMap assToConv,
std::vector< bool > &  active 
)
private

Definition at line 58 of file PFConversionAlgo.cc.

References reco::PFBlock::associatedElements(), createPayload::block, gather_cfg::cout, reco::PFBlockElement::ECAL, reco::PFBlock::elements(), asciidump::elements, spr::find(), newFWLiteAna::found, reco::PFBlockElement::HCAL, i, getHLTprescales::index, j, reco::PFBlock::linkData(), reco::PFBlock::LINKTEST_ALL, reco::PFBlock::LINKTEST_RECHIT, edm::OwnVector< T, P >::size(), findQualityFiles::size, and reco::PFBlockElement::TRACK.

60  {
61 
62  bool conversionFound = false;
63  typedef std::multimap<double, unsigned>::iterator IE;
64  const reco::PFBlock& block = *blockRef;
65  // std::cout << " PFConversionAlgo::setLinks block " << block << std::endl;
67  PFBlock::LinkData linkData = block.linkData();
68 
69  // this method looks in all elements in a block, idenitifies those
70  // blonging to a conversions and stores them in a local map
71  // so that in the further code the search needs not be done again
72 
73  unsigned convTrack1Ind=100;
74  unsigned convTrack2Ind=100;
75  unsigned convEcal1Ind=200;
76  unsigned convEcal2Ind=200;
77  unsigned convHcal1Ind=200;
78  unsigned convHcal2Ind=200;
79 
80  for(unsigned iElem=0; iElem<elements.size(); iElem++) {
81  bool trackFromConv = elements[iElem].trackType( PFBlockElement::T_FROM_GAMMACONV);
82 
83  if (!active[iElem]) continue;
84  if ( !trackFromConv ) continue;
85  conversionFound = true;
86 
87  // std::cout << " Track " << iElem << " is from conversion" << std::endl;
88  convTrack1Ind= iElem;
89 
90  std::multimap<unsigned, std::vector<unsigned> >::iterator found = elemAssociatedToConv.find(iElem);
91  if ( found!= elemAssociatedToConv.end()) {
92  // std::cout << " Track " << iElem << " has already been included " << std::endl;
93  continue;
94  }
95 
96 
97  bool alreadyTaken=false;
98  for ( std::multimap<unsigned, std::vector<unsigned> >::iterator i=elemAssociatedToConv.begin();
99  i!= elemAssociatedToConv.end(); ++i) {
100  for (unsigned int j=0; j< (i->second).size(); ++j ) {
101  if ( iElem == (i->second)[j] ) alreadyTaken=true;
102  }
103  }
104  if ( alreadyTaken ) {
105  // std::cout << " iElem " << iElem << " already taken" << std::endl;
106  continue;
107  }
108 
109 
110  vector<unsigned> assElements(0);
111  vector<unsigned>::iterator iVec;
112 
113  std::multimap<double, unsigned> ecalElems;
114  block.associatedElements(iElem , linkData,
115  ecalElems ,
117 
118  std::multimap<double, unsigned> hcalElems;
119  block.associatedElements( iElem , linkData,
120  hcalElems,
123 
124  std::multimap<double, unsigned> trackElems;
125  block.associatedElements( iElem, linkData,
126  trackElems ,
129 
130 
131  if(trackElems.empty() ) {
132  // std::cout<<"PFConversionAlgo::setLinks no track element connected to track "<<iElem<<std::endl;
133  }
134 
135  if(ecalElems.empty() ) {
136  // std::cout<<"PFConversionAlgo::setLinks no ecal element connected to track "<<iElem<<std::endl;
137  }
138 
139  if(hcalElems.empty() ) {
140  // std::cout<<"PFConversionAlgo::setLinks no hcal element connected to track "<<iElem<<std::endl;
141  }
142 
143  //std::cout<<"PFConversionAlgo::setLinks now looping on elements associated to the track"<<std::endl;
144 
145 
146 
147  // std::cout<<" look at linked hcal clusters"<<std::endl;
148  for(IE iTk = hcalElems.begin(); iTk != hcalElems.end(); ++iTk ) {
149  unsigned index = iTk->second;
150  PFBlockElement::Type type = elements[index].type();
151  if ( type == reco::PFBlockElement::HCAL) {
152  // link track-ecal is found
153  convHcal1Ind=index;
154  // std::cout << " Hcal-Track link found with " << convHcal1Ind << std::endl;
155  // if ( index< 100) assElements.push_back(index);
156  }
157  }
158 
159 
160 
161  // std::cout<<" look at linked ecal clusters"<<std::endl;
162  for(IE iTk = ecalElems.begin(); iTk != ecalElems.end(); ++iTk ) {
163  unsigned index = iTk->second;
164  PFBlockElement::Type type = elements[index].type();
165  if ( type == reco::PFBlockElement::ECAL) {
166  // link track-ecal is found
167  convEcal1Ind=index;
168  //std::cout << " Ecal-Track link found with " << convEcal1Ind << std::endl;
169  iVec = find ( assElements.begin(), assElements.end(), index) ;
170  if ( index< 100 && iVec == assElements.end() ) assElements.push_back(index);
171  }
172  }
173 
174 
175  // std::cout<<"PFConversionAlgo::setLinks look at linked tracks"<<std::endl;
176  for(IE iTk = trackElems.begin(); iTk != trackElems.end(); ++iTk ) {
177  unsigned index = iTk->second;
178  //PFBlockElement::Type type = elements[index].type();
179  // link track-track is found
180  convTrack2Ind=index;
181  if ( index< 100) assElements.push_back(index);
182  //std::cout << " Track-Track link found with " << convTrack2Ind << std::endl;
183  std::multimap<double, unsigned> ecalElems2;
184  block.associatedElements(convTrack2Ind , linkData,
185  ecalElems2 ,
187 
188 
189  for(IE iTk = ecalElems2.begin(); iTk != ecalElems2.end(); ++iTk ) {
190  unsigned index = iTk->second;
191  PFBlockElement::Type type = elements[index].type();
192  if ( type == reco::PFBlockElement::ECAL) {
193  convEcal2Ind=index;
194  // std::cout << " 2nd ecal track link found betwtenn track " << convTrack2Ind << " and Ecal " << convEcal2Ind << std::endl;
195  iVec = find ( assElements.begin(), assElements.end(), index) ;
196  if ( index< 100 && iVec== assElements.end() ) assElements.push_back(index);
197 
198  }
199  }
200 
201  std::multimap<double, unsigned> hcalElems2;
202  block.associatedElements(convTrack2Ind , linkData,
203  hcalElems2 ,
205  for(IE iTk = hcalElems.begin(); iTk != hcalElems.end(); ++iTk ) {
206  unsigned index = iTk->second;
207  PFBlockElement::Type type = elements[index].type();
208  if ( type == reco::PFBlockElement::HCAL) {
209  // link track-ecal is found
210  convHcal2Ind=index;
211  std::cout << " Hcal-Track link found with " << convHcal2Ind << std::endl;
212  // if ( index< 100) assElements.push_back(index);
213  }
214  }
215 
216  }
217 
218 
219  elemAssociatedToConv.insert(make_pair(convTrack1Ind, assElements));
220 
221  // This is just for debug
222  //std::cout << " PFConversionAlgo::setLink map size " << elemAssociatedToConv.size() << std::endl;
223  // for ( std::multimap<unsigned, std::vector<unsigned> >::iterator i=elemAssociatedToConv.begin();
224  // i!= elemAssociatedToConv.end(); ++i) {
225  //std::cout << " links found for " << i->first << std::endl;
226  //std::cout << " elements " << (i->second).size() << std::endl;
227  // for (unsigned int j=0; j< (i->second).size(); ++j ) {
228  // unsigned int iEl = (i->second)[j];
229  //std::cout << " ass element " << iEl << std::endl;
230  // }
231  // }
232 
233 
234 
235  } // end loop over elements of the block looking for conversion track
236 
237 
238  return conversionFound;
239 
240 }
type
Definition: HCALResponse.h:22
int i
Definition: DBlmapReader.cc:9
std::map< unsigned int, Link > LinkData
Definition: PFBlock.h:46
size_type size() const
Definition: OwnVector.h:262
list elements
Definition: asciidump.py:414
const edm::OwnVector< reco::PFBlockElement > & elements() const
Definition: PFBlock.h:107
const LinkData & linkData() const
Definition: PFBlock.h:112
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int j
Definition: DBlmapReader.cc:9
void associatedElements(unsigned i, const LinkData &linkData, std::multimap< double, unsigned > &sortedAssociates, reco::PFBlockElement::Type type=PFBlockElement::NONE, LinkTest test=LINKTEST_RECHIT) const
Definition: PFBlock.cc:75
tuple cout
Definition: gather_cfg.py:41
tuple size
Write out results.
Block of elements.
Definition: PFBlock.h:30

Member Data Documentation

std::vector<reco::PFCandidate> PFConversionAlgo::conversionCandidate_
private

Definition at line 52 of file PFConversionAlgo.h.

Referenced by conversionCandidates().

bool PFConversionAlgo::isvalid_
private

Definition at line 53 of file PFConversionAlgo.h.

Referenced by isConversionValidCandidate().