CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFBlockAlgo.h
Go to the documentation of this file.
1 #ifndef RecoParticleFlow_PFProducer_PFBlockAlgo_h
2 #define RecoParticleFlow_PFProducer_PFBlockAlgo_h
3 
4 #include <set>
5 #include <vector>
6 #include <iostream>
7 
8 // #include "FWCore/Framework/interface/Handle.h"
10 // #include "FWCore/Framework/interface/OrphanHandle.h"
12 
13 
27 
31 
32 // Glowinski & Gouzevitch
37 // !Glowinski & Gouzevitch
38 
39 // #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
40 
45 
57 
59 
61 
62 #include <map>
63 
64 
66 
71 class PFBlockAlgo {
72 
73  public:
74 
75  PFBlockAlgo();
76 
77  ~PFBlockAlgo();
78 
79 
80  void setParameters( std::vector<double>& DPtovPtCut,
81  std::vector<unsigned>& NHitCut,
82  bool useConvBremPFRecTracks,
83  bool useIterTracking,
84  int nuclearInteractionsPurity,
85  bool useEGPhotons,
86  std::vector<double> & photonSelectionCuts
87  );
88 
89  // Glowinski & Gouzevitch
90  void setUseOptimization(bool useKDTreeTrackEcalLinker);
91  // ! Glowinski & Gouzevitch
92 
93  typedef std::vector<bool> Mask;
94 
96  template< template<typename> class T>
97  void setInput(const T<reco::PFRecTrackCollection>& trackh,
98  const T<reco::GsfPFRecTrackCollection>& gsftrackh,
99  const T<reco::GsfPFRecTrackCollection>& convbremgsftrackh,
100  const T<reco::MuonCollection>& muonh,
102  const T<reco::PFRecTrackCollection>& nucleartrackh,
104  const T<reco::PFV0Collection>& v0,
105  const T<reco::PFClusterCollection>& ecalh,
106  const T<reco::PFClusterCollection>& hcalh,
107  const T<reco::PFClusterCollection>& hoh,
108  const T<reco::PFClusterCollection>& hfemh,
109  const T<reco::PFClusterCollection>& hfhadh,
110  const T<reco::PFClusterCollection>& psh,
111  const T<reco::PhotonCollection>& egphh,
112  const Mask& trackMask = dummyMask_,
113  const Mask& gsftrackMask = dummyMask_,
114  const Mask& ecalMask = dummyMask_,
115  const Mask& hcalMask = dummyMask_,
116  const Mask& hoMask = dummyMask_,
117  const Mask& hfemMask = dummyMask_,
118  const Mask& hfhadMask = dummyMask_,
119  const Mask& psMask = dummyMask_,
120  const Mask& phMask = dummyMask_);
121 
123  template< template<typename> class T >
125  const T<reco::MuonCollection>& muonh,
126  const T<reco::PFClusterCollection>& ecalh,
127  const T<reco::PFClusterCollection>& hcalh,
128  const T<reco::PFClusterCollection>& hoh,
129  const T<reco::PFClusterCollection>& hfemh,
130  const T<reco::PFClusterCollection>& hfhadh,
131  const T<reco::PFClusterCollection>& psh,
132  const Mask& trackMask = dummyMask_,
133  const Mask& ecalMask = dummyMask_,
134  const Mask& hcalMask = dummyMask_,
135  const Mask& hoMask = dummyMask_,
136  const Mask& psMask = dummyMask_) {
138  T<reco::GsfPFRecTrackCollection> convbremgsftrackh;
139  //T<reco::MuonCollection> muonh;
141  T<reco::PFRecTrackCollection> nucleartrackh;
145  setInput<T>( trackh, gsftrackh, convbremgsftrackh, muonh, nuclearh, nucleartrackh, convh, v0,
146  ecalh, hcalh, hoh, hfemh, hfhadh, psh, phh,
147  trackMask, ecalMask, hcalMask, hoMask, psMask);
148  }
149 
151  template< template<typename> class T >
153  const T<reco::GsfPFRecTrackCollection>& gsftrackh,
154  const T<reco::PFClusterCollection>& ecalh,
155  const T<reco::PFClusterCollection>& hcalh,
156  const T<reco::PFClusterCollection>& hoh,
157  const T<reco::PFClusterCollection>& psh,
158  const Mask& trackMask = dummyMask_,
159  const Mask& gsftrackMask = dummyMask_,
160  const Mask& ecalMask = dummyMask_,
161  const Mask& hcalMask = dummyMask_,
162  const Mask& hoMask = dummyMask_,
163  const Mask& psMask = dummyMask_) {
164  T<reco::GsfPFRecTrackCollection> convbremgsftrackh;
167  T<reco::PFRecTrackCollection> nucleartrackh;
171  setInput<T>( trackh, gsftrackh, convbremgsftrackh, muonh, nuclearh, nucleartrackh, convh, v0, ecalh, hcalh, hoh, psh, egphh,
172  trackMask, gsftrackMask,ecalMask, hcalMask, hoMask, psMask);
173  }
174 
175 
177  void setDebug( bool debug ) {debug_ = debug;}
178 
180  void findBlocks();
181 
182 
184  /* const reco::PFBlockCollection& blocks() const {return *blocks_;} */
185  const std::auto_ptr< reco::PFBlockCollection >& blocks() const
186  {return blocks_;}
187 
189  std::auto_ptr< reco::PFBlockCollection > transferBlocks() {return blocks_;}
190 
192  typedef std::list< reco::PFBlockElement* >::iterator IE;
193  typedef std::list< reco::PFBlockElement* >::const_iterator IEC;
194  typedef reco::PFBlockCollection::const_iterator IBC;
195 
196  void setHOTag(bool ho) { useHO_ = ho;}
197 
198  private:
199 
206  IE associate(IE next, IE last, std::vector<PFBlockLink>& links);
207 
211  const std::vector<PFBlockLink>& links) const;
212 
215 
219  void buildGraph();
220 
222  inline bool linkPrefilter(const reco::PFBlockElement* last, const reco::PFBlockElement* next) const;
223 
225  void link( const reco::PFBlockElement* el1,
226  const reco::PFBlockElement* el2,
227  PFBlockLink::Type& linktype,
228  reco::PFBlock::LinkTest& linktest,
229  double& dist) const;
230 
233  double testTrackAndPS(const reco::PFRecTrack& track,
234  const reco::PFCluster& ps) const;
235 
238  double testECALAndHCAL(const reco::PFCluster& ecal,
239  const reco::PFCluster& hcal) const;
240 
243  double testHCALAndHO(const reco::PFCluster& hcal,
244  const reco::PFCluster& ho) const;
245 
246 
249  double testPS1AndPS2(const reco::PFCluster& ps1,
250  const reco::PFCluster& ps2) const;
251 
253  double testLinkBySuperCluster(const reco::PFClusterRef & elt1,
254  const reco::PFClusterRef & elt2) const;
255 
258  const reco::PFClusterRef & elt2) const;
259 
264  const reco::GsfPFRecTrackCollection& gsftracks,
265  const reco::PFClusterCollection& ecals,
266  const reco::PFClusterCollection& hcals,
267  const reco::PFClusterCollection& hos,
268  const reco::PFClusterCollection& hfems,
269  const reco::PFClusterCollection& hfhads,
271  const reco::PhotonCollection& egphh,
272  const Mask& trackMask,
273  const Mask& gsftrackMask,
274  const Mask& ecalMask,
275  const Mask& hcalMask,
276  const Mask& hoMask,
277  const Mask& hfemMask,
278  const Mask& hfhadMask,
279  const Mask& psMask,
280  const Mask& phMask) const;
281 
283  // PFResolutionMap* openResolutionMap(const char* resMapName);
284 
286  bool goodPtResolution( const reco::TrackRef& trackref);
287 
288  double testLinkByVertex(const reco::PFBlockElement* elt1,
289  const reco::PFBlockElement* elt2) const;
290 
291  int muAssocToTrack( const reco::TrackRef& trackref,
292  const edm::Handle<reco::MuonCollection>& muonh) const;
293  int muAssocToTrack( const reco::TrackRef& trackref,
294  const edm::OrphanHandle<reco::MuonCollection>& muonh) const;
295 
296  template< template<typename> class T>
298 
299  std::auto_ptr< reco::PFBlockCollection > blocks_;
300 
302  // std::vector< reco::PFCandidate > particles_;
303 
304  // the test elements will be transferred to the blocks
305  std::list< reco::PFBlockElement* > elements_;
306 
307  // Glowinski & Gouzevitch
312  // !Glowinski & Gouzevitch
313 
314  static const Mask dummyMask_;
315 
317  std::vector<double> DPtovPtCut_;
318 
320  std::vector<unsigned> NHitCut_;
321 
324 
327 
328  // This parameters defines the level of purity of
329  // nuclear interactions choosen.
330  // Level 1 is only high Purity sample labeled as isNucl.
331  // Level 2 isNucl + isNucl_Loose (2 secondary tracks vertices)
332  // Level 3 isNucl + isNucl_Loose + isNucl_Kink
333  // (low purity sample made of 1 primary and 1 secondary track)
334  // By default the level 1 is teh safest one.
336 
339 
343  std::vector<reco::SuperClusterRef > superClusters_;
344 
346  // std::map<reco::PFClusterRef,int> pfcRefSCMap_;
347  std::vector<int> pfcSCVec_;
348 
349  // A boolean to avoid to compare ECAL and ECAl if there i no superclusters in the event
351 
353  std::vector<std::vector<reco::PFClusterRef> > scpfcRefs_;
355  bool debug_;
356 
357  friend std::ostream& operator<<(std::ostream&, const PFBlockAlgo&);
358 
359  // Create links between tracks or HCAL clusters, and HO clusters
360  bool useHO_;
361 
362 };
363 
369 
370 template< template<typename> class T >
371 void
373  const T<reco::GsfPFRecTrackCollection>& gsftrackh,
374  const T<reco::GsfPFRecTrackCollection>& convbremgsftrackh,
375  const T<reco::MuonCollection>& muonh,
377  const T<reco::PFRecTrackCollection>& nucleartrackh,
378  const T<reco::PFConversionCollection>& convh,
379  const T<reco::PFV0Collection>& v0,
380  const T<reco::PFClusterCollection>& ecalh,
381  const T<reco::PFClusterCollection>& hcalh,
382  const T<reco::PFClusterCollection>& hoh,
383  const T<reco::PFClusterCollection>& hfemh,
384  const T<reco::PFClusterCollection>& hfhadh,
385  const T<reco::PFClusterCollection>& psh,
386  const T<reco::PhotonCollection>& egphh,
387  const Mask& trackMask,
388  const Mask& gsftrackMask,
389  const Mask& ecalMask,
390  const Mask& hcalMask,
391  const Mask& hoMask,
392  const Mask& hfemMask,
393  const Mask& hfhadMask,
394  const Mask& psMask,
395  const Mask& phMask) {
396 
397 
398  checkMaskSize( *trackh,
399  *gsftrackh,
400  *ecalh,
401  *hcalh,
402  *hoh,
403  *hfemh,
404  *hfhadh,
405  *psh,
406  *egphh,
407  trackMask,
408  gsftrackMask,
409  ecalMask,
410  hcalMask,
411  hoMask,
412  hfemMask,
413  hfhadMask,
414  psMask,
415  phMask);
416 
417  /*
418  if (nucleartrackh.isValid()){
419  for(unsigned i=0;i<nucleartrackh->size(); i++) {
420  reco::PFRecTrackRef trackRef(nucleartrackh,i);
421  std::cout << *trackRef << std::endl;
422  }
423  }
424  */
425 
427  std::vector<reco::PFRecTrackRef> convBremPFRecTracks;
428  convBremPFRecTracks.clear();
429  // Super cluster mapping
430  superClusters_.clear();
431  scpfcRefs_.clear();
432  pfcSCVec_.clear();
433 
434  if(gsftrackh.isValid() ) {
435  const reco::GsfPFRecTrackCollection PFGsfProd = *(gsftrackh.product());
436  for(unsigned i=0;i<gsftrackh->size(); ++i) {
437  if( !gsftrackMask.empty() &&
438  !gsftrackMask[i] ) continue;
439  reco::GsfPFRecTrackRef refgsf(gsftrackh,i );
440 
441  if((refgsf).isNull()) continue;
442  reco::GsfTrackRef gsf=refgsf->gsfTrackRef();
443 
444  // retrieve and save the SC if ECAL-driven - Florian
445  if(gsf->extra().isAvailable() && gsf->extra()->seedRef().isAvailable()) {
446  reco::ElectronSeedRef seedRef= gsf->extra()->seedRef().castTo<reco::ElectronSeedRef>();
447  // check that the seed is valid
448  if(seedRef.isAvailable() && seedRef->isEcalDriven()) {
449  reco::SuperClusterRef scRef = seedRef->caloCluster().castTo<reco::SuperClusterRef>();
450  if(scRef.isNonnull()) {
451  std::vector<reco::SuperClusterRef>::iterator itcheck=find(superClusters_.begin(),superClusters_.end(),scRef);
452  // not present, add it
453  if(itcheck==superClusters_.end())
454  {
455  superClusters_.push_back(scRef);
458  sce->setFromGsfElectron(true);
459  elements_.push_back(sce);
460  }
461  else // it is already present, update the PFBE
462  {
463  PFBlockElementSCEqual myEqual(scRef);
464  std::list<reco::PFBlockElement*>::iterator itcheck=find_if(elements_.begin(),elements_.end(),myEqual);
465  if(itcheck!=elements_.end())
466  {
467  reco::PFBlockElementSuperCluster* thePFBE=dynamic_cast<reco::PFBlockElementSuperCluster*>(*itcheck);
468  thePFBE->setFromGsfElectron(true);
469  // std::cout << " Updating element to add electron information" << std::endl;
470  }
471 // else
472 // {
473 // std::cout << " Missing element " << std::endl;
474 // }
475  }
476  }
477  }
478  }
479 
480  reco::PFBlockElement* gsfEl;
481 
482  const std::vector<reco::PFTrajectoryPoint>
483  PfGsfPoint = PFGsfProd[i].trajectoryPoints();
484 
485  unsigned int c_gsf=0;
486  bool PassTracker = false;
487  bool GetPout = false;
488  unsigned int IndexPout = 0;
489 
490  typedef std::vector<reco::PFTrajectoryPoint>::const_iterator IP;
491  for(IP itPfGsfPoint = PfGsfPoint.begin();
492  itPfGsfPoint!= PfGsfPoint.end();++itPfGsfPoint) {
493 
494  if (itPfGsfPoint->isValid()){
495  int layGsfP = itPfGsfPoint->layer();
496  if (layGsfP == -1) PassTracker = true;
497  if (PassTracker && layGsfP > 0 && GetPout == false) {
498  IndexPout = c_gsf-1;
499  GetPout = true;
500  }
501  //const math::XYZTLorentzVector GsfMoment = itPfGsfPoint->momentum();
502  ++c_gsf;
503  }
504  }
505  math::XYZTLorentzVector pin = PfGsfPoint[0].momentum();
506  math::XYZTLorentzVector pout = PfGsfPoint[IndexPout].momentum();
507 
510  const std::vector<reco::PFRecTrackRef>& temp_convBremPFRecTracks(refgsf->convBremPFRecTrackRef());
511  if(temp_convBremPFRecTracks.size() > 0) {
512  for(unsigned int iconv = 0; iconv <temp_convBremPFRecTracks.size(); ++iconv) {
513  convBremPFRecTracks.push_back(temp_convBremPFRecTracks[iconv]);
514  }
515  }
516  }
517 
518  gsfEl = new reco::PFBlockElementGsfTrack(refgsf, pin, pout);
519 
520  elements_.push_back( gsfEl);
521 
522  std::vector<reco::PFBrem> pfbrem = refgsf->PFRecBrem();
523 
524  for (unsigned i2=0;i2<pfbrem.size(); ++i2) {
525  const double DP = pfbrem[i2].DeltaP();
526  const double SigmaDP = pfbrem[i2].SigmaDeltaP();
527  const unsigned int TrajP = pfbrem[i2].indTrajPoint();
528  if(TrajP == 99) continue;
529 
530  reco::PFBlockElement* bremEl;
531  bremEl = new reco::PFBlockElementBrem(refgsf,DP,SigmaDP,TrajP);
532  elements_.push_back(bremEl);
533 
534  }
535  }
536 
537  }
538 
540  if(useEGPhotons_ && egphh.isValid()) {
541  unsigned size=egphh->size();
542  for(unsigned isc=0; isc<size; ++isc) {
543  if(!phMask.empty() && !(phMask)[isc] ) continue;
544  if(!photonSelector_->passPhotonSelection((*egphh)[isc])) continue;
545  // std::cout << " Selected a supercluster" << std::endl;
546  // Add only the super clusters not already included
547  reco::SuperClusterRef scRef((*egphh)[isc].superCluster());
548  std::vector<reco::SuperClusterRef>::iterator itcheck=find(superClusters_.begin(),superClusters_.end(),(*egphh)[isc].superCluster());
549  if(itcheck==superClusters_.end())
550  {
551  superClusters_.push_back(scRef);
553  new reco::PFBlockElementSuperCluster((*egphh)[isc].superCluster());
554  fillFromPhoton(egphh,isc,sce);
555  elements_.push_back(sce);
556  }
557  else
558  {
559  PFBlockElementSCEqual myEqual(scRef);
560  std::list<reco::PFBlockElement*>::iterator itcheck=find_if(elements_.begin(),elements_.end(),myEqual);
561  if(itcheck!=elements_.end())
562  {
563  reco::PFBlockElementSuperCluster* thePFBE=dynamic_cast<reco::PFBlockElementSuperCluster*>(*itcheck);
564  fillFromPhoton(egphh,isc,thePFBE);
565  thePFBE->setFromPhoton(true);
566  // std::cout << " Updating element to add Photon information " << photonSelector_->passPhotonSelection((*egphh)[isc]) << std::endl;
567 
568  }
569 // else
570 // {
571 // std::cout << " Missing element " << std::endl;
572 // }
573  }
574  }
575  }
576 
577  // set the vector to the right size so to allow random access
578  scpfcRefs_.resize(superClusters_.size());
579 
581 
583 
584  if(convh.isValid() ) {
585  reco::PFBlockElement* trkFromConversionElement;
586  for(unsigned i=0;i<convh->size(); ++i) {
587  reco::PFConversionRef convRef(convh,i);
588 
589  unsigned int trackSize=(convRef->pfTracks()).size();
590  if ( convRef->pfTracks().size() < 2) continue;
591  for(unsigned iTk=0;iTk<trackSize; ++iTk) {
592 
593  reco::PFRecTrackRef compPFTkRef = convRef->pfTracks()[iTk];
594  trkFromConversionElement = new reco::PFBlockElementTrack(convRef->pfTracks()[iTk]);
595  trkFromConversionElement->setConversionRef( convRef->originalConversion(), reco::PFBlockElement::T_FROM_GAMMACONV);
596 
597  elements_.push_back( trkFromConversionElement );
598 
599 
600  if (debug_){
601  std::cout << "PF Block Element from Conversion electron " <<
602  (*trkFromConversionElement).trackRef().key() << std::endl;
603  std::cout << *trkFromConversionElement << std::endl;
604  }
605 
606  }
607  }
608  }
609 
610 
612 
614 
615  if(v0.isValid() ) {
616  reco::PFBlockElement* trkFromV0Element = 0;
617  for(unsigned i=0;i<v0->size(); ++i) {
618  reco::PFV0Ref v0Ref( v0, i );
619  unsigned int trackSize=(v0Ref->pfTracks()).size();
620  for(unsigned iTk=0;iTk<trackSize; ++iTk) {
621 
622  reco::PFRecTrackRef newPFRecTrackRef = (v0Ref->pfTracks())[iTk];
623  reco::TrackBaseRef newTrackBaseRef(newPFRecTrackRef->trackRef());
624  bool bNew = true;
625 
628  for(IE iel = elements_.begin(); iel != elements_.end(); ++iel){
629  reco::TrackBaseRef elemTrackBaseRef((*iel)->trackRef());
630  if (newTrackBaseRef == elemTrackBaseRef){
631  trkFromV0Element = *iel;
632  bNew = false;
633  continue;
634  }
635  }
636 
638  if (bNew) {
639  trkFromV0Element = new reco::PFBlockElementTrack(v0Ref->pfTracks()[iTk]);
640  elements_.push_back( trkFromV0Element );
641  }
642 
643  trkFromV0Element->setV0Ref( v0Ref->originalV0(),
645 
646  if (debug_){
647  std::cout << "PF Block Element from V0 track New = " << bNew
648  << (*trkFromV0Element).trackRef().key() << std::endl;
649  std::cout << *trkFromV0Element << std::endl;
650  }
651 
652 
653  }
654  }
655  }
656 
658 
660 
661  if(nuclearh.isValid()) {
662  reco::PFBlockElement* trkFromDisplacedVertexElement = 0;
663  for(unsigned i=0;i<nuclearh->size(); ++i) {
664 
665  const reco::PFDisplacedTrackerVertexRef dispacedVertexRef( nuclearh, i );
666 
667  // std::cout << "Nuclear Interactions Purity " << nuclearInteractionsPurity_ << std::endl;
668  // dispacedVertexRef->displacedVertexRef()->Dump();
669  //bool bIncludeVertices = true;
670  // We add a cut at rho > 2.7 since this corresponds to the lower edge of the beam pipe
671  // This cut have to be changer when a new beam pipe would be installed
672 
673  bool bIncludeVertices = false;
674  bool bNucl = dispacedVertexRef->displacedVertexRef()->isNucl()
675  && dispacedVertexRef->displacedVertexRef()->position().rho()> 2.7;
676  bool bNucl_Loose = dispacedVertexRef->displacedVertexRef()->isNucl_Loose();
677  bool bNucl_Kink = dispacedVertexRef->displacedVertexRef()->isNucl_Kink();
678 
679  if (nuclearInteractionsPurity_ >= 1) bIncludeVertices = bNucl;
680  if (nuclearInteractionsPurity_ >= 2) bIncludeVertices = bIncludeVertices || bNucl_Loose;
681  if (nuclearInteractionsPurity_ >= 3) bIncludeVertices = bIncludeVertices || bNucl_Kink;
682 
683  if (bIncludeVertices){
684 
685  unsigned int trackSize= dispacedVertexRef->pfRecTracks().size();
686  if (debug_){
687  std::cout << "" << std::endl;
688  std::cout << "Displaced Vertex " << i << std::endl;
689  dispacedVertexRef->displacedVertexRef()->Dump();
690  }
691  for(unsigned iTk=0;iTk < trackSize; ++iTk) {
692 
693 
694  // This peace of code looks weired at first but it seems to be necessary to let
695  // PFRooTEvent work properly. Since the track position called REPPoint is transient
696  // it has to be calculated and the PFRecTrack collection associted to Displaced Vertex is not
697  // anymore the original collection. So here we match both collections if possible
698  reco::PFRecTrackRef newPFRecTrackRef = dispacedVertexRef->pfRecTracks()[iTk];
699  reco::TrackBaseRef constTrackBaseRef(newPFRecTrackRef->trackRef());
700 
701 
702  if (nucleartrackh.isValid()){
703  for(unsigned i=0;i<nucleartrackh->size(); ++i) {
704  reco::PFRecTrackRef transientPFRecTrackRef(nucleartrackh,i);
705  reco::TrackBaseRef transientTrackBaseRef(transientPFRecTrackRef->trackRef());
706  if (constTrackBaseRef==transientTrackBaseRef){
707  newPFRecTrackRef = transientPFRecTrackRef;
708  break;
709  }
710  }
711  }
712  reco::TrackBaseRef newTrackBaseRef(newPFRecTrackRef->trackRef());
713 
714 
715 
716  bool bNew = true;
718 
721  for(IE iel = elements_.begin(); iel != elements_.end(); ++iel){
722  reco::TrackBaseRef elemTrackBaseRef((*iel)->trackRef());
723  if (newTrackBaseRef == elemTrackBaseRef){
724  trkFromDisplacedVertexElement = *iel;
725  bNew = false;
726  continue;
727  }
728  }
729 
730 
732  if (bNew) {
733 
734 
735 
736  trkFromDisplacedVertexElement = new reco::PFBlockElementTrack(newPFRecTrackRef);
737  elements_.push_back( trkFromDisplacedVertexElement );
738  }
739 
740  if (dispacedVertexRef->isIncomingTrack(newPFRecTrackRef))
742  else if (dispacedVertexRef->isOutgoingTrack(newPFRecTrackRef))
744  else
745  blockType = reco::PFBlockElement::DEFAULT;
746 
748  trkFromDisplacedVertexElement->setDisplacedVertexRef( dispacedVertexRef, blockType );
749 
750 
751  if (debug_){
752  std::cout << "PF Block Element from DisplacedTrackingVertex track New = " << bNew
753  << (*trkFromDisplacedVertexElement).trackRef().key() << std::endl;
754  std::cout << *trkFromDisplacedVertexElement << std::endl;
755  }
756 
757 
758  }
759  }
760  }
761 
762  if (debug_) std::cout << "" << std::endl;
763 
764  }
765 
767 
771 
772  if(trackh.isValid() ) {
773 
774  if (debug_) std::cout << "Tracks already in from Displaced Vertices " << std::endl;
775 
776  Mask trackMaskVertex;
777 
778  for(unsigned i=0;i<trackh->size(); ++i) {
779  reco::PFRecTrackRef pfRefTrack( trackh,i );
780  reco::TrackRef trackRef = pfRefTrack->trackRef();
781 
782  bool bMask = true;
783  for(IE iel = elements_.begin(); iel != elements_.end(); ++iel){
784  reco::TrackRef elemTrackRef = (*iel)->trackRef();
785  if( trackRef == elemTrackRef ) {
786  if (debug_) std::cout << " " << trackRef.key();
787  bMask = false; continue;
788  }
789  }
790 
791  trackMaskVertex.push_back(bMask);
792  }
793 
794  if (debug_) std::cout << "" << std::endl;
795 
796  if (debug_) std::cout << "Additionnal tracks from main collection " << std::endl;
797 
798  for(unsigned i=0;i<trackh->size(); ++i) {
799 
800 
801  // this track has been disabled
802  if( !trackMask.empty() && !trackMask[i] ) continue;
803 
804  reco::PFRecTrackRef ref( trackh,i );
805 
806  if (debug_) std::cout << " " << ref->trackRef().key();
807 
808  // Get the eventual muon associated to this track
809  int muId_ = muAssocToTrack( ref->trackRef(), muonh );
810  bool thisIsAPotentialMuon = false;
811  if( muId_ != -1 ) {
812  reco::MuonRef muonref( muonh, muId_ );
813  thisIsAPotentialMuon =
814  PFMuonAlgo::isLooseMuon(muonref) ||
815  PFMuonAlgo::isMuon(muonref);
816  }
817  // Reject bad tracks (except if identified as muon
818  if( !thisIsAPotentialMuon && !goodPtResolution( ref->trackRef() ) ) continue;
819 
820  if (thisIsAPotentialMuon && debug_) std::cout << "Potential Muon P " << ref->trackRef()->p()
821  << " pt " << ref->trackRef()->p() << std::endl;
822 
823 
824 
825  reco::PFBlockElement* primaryElement = new reco::PFBlockElementTrack( ref );
826 
827  if( muId_ != -1 ) {
828  // if a muon has been found
829  reco::MuonRef muonref( muonh, muId_ );
830 
831  // If this track was already added to the collection, we just need to find the associated element and
832  // attach to it the reference
833  if (!trackMaskVertex.empty() && !trackMaskVertex[i]){
834  reco::TrackRef primaryTrackRef = ref->trackRef();
835  for(IE iel = elements_.begin(); iel != elements_.end(); ++iel){
836  reco::TrackRef elemTrackRef = (*iel)->trackRef();
837  if( primaryTrackRef == elemTrackRef ) {
838  (*iel)->setMuonRef( muonref );
839  if (debug_) std::cout << "One of the tracks identified in displaced vertices collections was spotted as muon" <<std:: endl;
840  }
841  }
842  } else primaryElement->setMuonRef( muonref );
843 
844  }
845 
846  if (!trackMaskVertex.empty() && !trackMaskVertex[i]) continue;
847 
848 
849  // set track type T_FROM_GAMMA for pfrectracks associated to conv brems
851  if(convBremPFRecTracks.size() > 0.) {
852  for(unsigned int iconv = 0; iconv < convBremPFRecTracks.size(); ++iconv) {
853  if((*ref).trackRef() == (*convBremPFRecTracks[iconv]).trackRef()) {
854  bool value = true;
856  }
857  }
858  }
859  }
860  elements_.push_back( primaryElement );
861  }
862 
863  if (debug_) std::cout << " " << std::endl;
864 
865  }
866 
867 
868  // -------------- GSF tracks and brems for Conversion Recovery ----------
869 
870  if(convbremgsftrackh.isValid() ) {
871 
872 
873  const reco::GsfPFRecTrackCollection ConvPFGsfProd = *(convbremgsftrackh.product());
874  for(unsigned i=0;i<convbremgsftrackh->size(); ++i) {
875 
876  reco::GsfPFRecTrackRef refgsf(convbremgsftrackh,i );
877 
878  if((refgsf).isNull()) continue;
879 
880  reco::PFBlockElement* gsfEl;
881 
882  const std::vector<reco::PFTrajectoryPoint>
883  PfGsfPoint = ConvPFGsfProd[i].trajectoryPoints();
884 
885  unsigned int c_gsf=0;
886  bool PassTracker = false;
887  bool GetPout = false;
888  unsigned int IndexPout = -1;
889 
890  typedef std::vector<reco::PFTrajectoryPoint>::const_iterator IP;
891  for(IP itPfGsfPoint = PfGsfPoint.begin();
892  itPfGsfPoint!= PfGsfPoint.end();++itPfGsfPoint) {
893 
894  if (itPfGsfPoint->isValid()){
895  int layGsfP = itPfGsfPoint->layer();
896  if (layGsfP == -1) PassTracker = true;
897  if (PassTracker && layGsfP > 0 && GetPout == false) {
898  IndexPout = c_gsf-1;
899  GetPout = true;
900  }
901  //const math::XYZTLorentzVector GsfMoment = itPfGsfPoint->momentum();
902  ++c_gsf;
903  }
904  }
905  math::XYZTLorentzVector pin = PfGsfPoint[0].momentum();
906  math::XYZTLorentzVector pout = PfGsfPoint[IndexPout].momentum();
907 
908 
909 
910  gsfEl = new reco::PFBlockElementGsfTrack(refgsf, pin, pout);
911 
912  bool valuegsf = true;
913  // IMPORTANT SET T_FROM_GAMMACONV trackType() FOR CONVERSIONS
915 
916 
917 
918  elements_.push_back( gsfEl);
919  std::vector<reco::PFBrem> pfbrem = refgsf->PFRecBrem();
920 
921  for (unsigned i2=0;i2<pfbrem.size(); ++i2) {
922  const double DP = pfbrem[i2].DeltaP();
923  const double SigmaDP = pfbrem[i2].SigmaDeltaP();
924  const unsigned int TrajP = pfbrem[i2].indTrajPoint();
925  if(TrajP == 99) continue;
926 
927  reco::PFBlockElement* bremEl;
928  bremEl = new reco::PFBlockElementBrem(refgsf,DP,SigmaDP,TrajP);
929  elements_.push_back(bremEl);
930 
931  }
932  }
933  }
934 
935 
936  // -------------- ECAL clusters ---------------------
937 
938 
939  if(ecalh.isValid() ) {
940  // pfcSCVec_.resize(ecalh->size(),-1);
941 
942  bNoSuperclus_ = (superClusters_.size() == 0);
943  if (!bNoSuperclus_) pfcSCVec_.resize(ecalh->size(),-1);
944 
945 
946  for(unsigned i=0;i<ecalh->size(); ++i) {
947 
948  // this ecal cluster has been disabled
949  if( !ecalMask.empty() &&
950  !ecalMask[i] ) continue;
951 
952  reco::PFClusterRef ref( ecalh,i );
954  = new reco::PFBlockElementCluster( ref,
956  elements_.push_back( te );
957 
958  if (!bNoSuperclus_) {
959 
960  // Now mapping with Superclusters
962 
963  if(scindex>=0) {
964  pfcSCVec_[ref.key()]=scindex;
965  scpfcRefs_[scindex].push_back(ref);
966  }
967  }
968 
969  }
970 
971  bNoSuperclus_ = (scpfcRefs_.size() == 0);
972 
973  }
974 
975  // -------------- HCAL clusters ---------------------
976 
977  if(hcalh.isValid() ) {
978 
979  for(unsigned i=0;i<hcalh->size(); ++i) {
980 
981  // this hcal cluster has been disabled
982  if( !hcalMask.empty() &&
983  !hcalMask[i] ) continue;
984 
985  reco::PFClusterRef ref( hcalh,i );
987  = new reco::PFBlockElementCluster( ref,
989  elements_.push_back( th );
990  }
991  }
992 
993  // -------------- HO clusters ---------------------
994 
995  if(useHO_ && hoh.isValid() ) {
996 
997  for(unsigned i=0;i<hoh->size(); ++i) {
998 
999  // this hcal cluster has been disabled
1000  if( !hoMask.empty() &&
1001  !hoMask[i] ) continue;
1002 
1003  reco::PFClusterRef ref( hoh,i );
1005  = new reco::PFBlockElementCluster( ref,
1007  elements_.push_back( th );
1008  }
1009  }
1010 
1011  // -------------- HFEM clusters ---------------------
1012 
1013  if(hfemh.isValid() ) {
1014 
1015  for(unsigned i=0;i<hfemh->size(); ++i) {
1016 
1017  // this hfem cluster has been disabled
1018  if( !hfemMask.empty() &&
1019  !hfemMask[i] ) continue;
1020 
1021  reco::PFClusterRef ref( hfemh,i );
1023  = new reco::PFBlockElementCluster( ref,
1025  elements_.push_back( th );
1026  }
1027  }
1028 
1029 
1030  // -------------- HFHAD clusters ---------------------
1031 
1032  if(hfhadh.isValid() ) {
1033 
1034  for(unsigned i=0;i<hfhadh->size(); ++i) {
1035 
1036  // this hfhad cluster has been disabled
1037  if( !hfhadMask.empty() &&
1038  !hfhadMask[i] ) continue;
1039 
1040  reco::PFClusterRef ref( hfhadh,i );
1042  = new reco::PFBlockElementCluster( ref,
1044  elements_.push_back( th );
1045  }
1046  }
1047 
1048 
1049 
1050 
1051  // -------------- PS clusters ---------------------
1052 
1053  if(psh.isValid() ) {
1054  for(unsigned i=0;i<psh->size(); ++i) {
1055 
1056  // this ps cluster has been disabled
1057  if( !psMask.empty() &&
1058  !psMask[i] ) continue;
1060  reco::PFClusterRef ref( psh,i );
1061  // two types of elements: PS1 (V) and PS2 (H)
1062  // depending on layer: PS1 or PS2
1063  switch(ref->layer()){
1064  case PFLayer::PS1:
1066  break;
1067  case PFLayer::PS2:
1069  break;
1070  default:
1071  break;
1072  }
1074  = new reco::PFBlockElementCluster( ref,
1075  type );
1076  elements_.push_back( tp );
1077  }
1078  }
1079 
1080 
1081  // -------------- Loop over block elements ---------------------
1082 
1083  // Here we provide to all KDTree linkers the collections to link.
1084  // Glowinski & Gouzevitch
1085 
1086  for (std::list< reco::PFBlockElement* >::iterator it = elements_.begin();
1087  it != elements_.end(); ++it) {
1088  switch ((*it)->type()){
1089 
1092  if ( (*it)->trackRefPF()->extrapolatedPoint( reco::PFTrajectoryPoint::ECALShowerMax ).isValid() )
1094  if ( (*it)->trackRefPF()->extrapolatedPoint( reco::PFTrajectoryPoint::HCALEntrance ).isValid() )
1096  }
1097 
1098  break;
1099 
1104  break;
1105 
1109  break;
1110 
1113  // THLinker_.insertFieldClusterElt(*it);
1114  }
1115  break;
1116 
1117 
1122  }
1123  break;
1124 
1125  default:
1126  break;
1127  }
1128  }
1129 }
1130 
1131 
1132 template< template<typename> class T>
1134  reco::PhotonRef photonRef(egh,isc);
1135  pfbe->setTrackIso(photonRef->trkSumPtHollowConeDR04());
1136  pfbe->setEcalIso(photonRef->ecalRecHitSumEtConeDR04());
1137  pfbe->setHcalIso(photonRef->hcalTowerSumEtConeDR04());
1138  pfbe->setHoE(photonRef->hadronicOverEm());
1139  pfbe->setPhotonRef(photonRef);
1140  pfbe->setFromPhoton(true);
1141  }
1142 
1143 #endif
1144 
1145 
const std::auto_ptr< reco::PFBlockCollection > & blocks() const
Definition: PFBlockAlgo.h:185
void insertFieldClusterElt(reco::PFBlockElement *hcalCluster)
type
Definition: HCALResponse.h:22
Abstract base class for a PFBlock element (track, cluster...)
reconstructed track used as an input to particle flow
Definition: PFRecTrack.h:22
int i
Definition: DBlmapReader.cc:9
std::vector< reco::SuperClusterRef > superClusters_
list of superclusters
Definition: PFBlockAlgo.h:343
bool passPhotonSelection(const reco::Photon &) const
std::pair< ALIstring, ALIstring > pss
Definition: Fit.h:27
double testECALAndHCAL(const reco::PFCluster &ecal, const reco::PFCluster &hcal) const
Definition: PFBlockAlgo.cc:933
bool useIterTracking_
Flag to turn off quality cuts which require iterative tracking (for heavy-ions)
Definition: PFBlockAlgo.h:323
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
static bool isMuon(const reco::PFBlockElement &elt)
Check if a block element is a muon.
Definition: PFMuonAlgo.cc:11
static HepMC::IO_HEPEVT conv
void setHOTag(bool ho)
Definition: PFBlockAlgo.h:196
double testSuperClusterPFCluster(const reco::SuperClusterRef &sct1, const reco::PFClusterRef &elt2) const
test association between SuperClusters and ECAL
KDTreeLinkerTrackEcal TELinker_
Definition: PFBlockAlgo.h:309
double testHCALAndHO(const reco::PFCluster &hcal, const reco::PFCluster &ho) const
Definition: PFBlockAlgo.cc:963
KDTreeLinkerPSEcal PSELinker_
Definition: PFBlockAlgo.h:311
friend std::ostream & operator<<(std::ostream &, const PFBlockAlgo &)
int nuclearInteractionsPurity_
Definition: PFBlockAlgo.h:335
void checkMaskSize(const reco::PFRecTrackCollection &tracks, const reco::GsfPFRecTrackCollection &gsftracks, const reco::PFClusterCollection &ecals, const reco::PFClusterCollection &hcals, const reco::PFClusterCollection &hos, const reco::PFClusterCollection &hfems, const reco::PFClusterCollection &hfhads, const reco::PFClusterCollection &pss, const reco::PhotonCollection &egphh, const Mask &trackMask, const Mask &gsftrackMask, const Mask &ecalMask, const Mask &hcalMask, const Mask &hoMask, const Mask &hfemMask, const Mask &hfhadMask, const Mask &psMask, const Mask &phMask) const
void checkDisplacedVertexLinks(reco::PFBlock &block) const
remove extra links between primary track and clusters
void setInput(const T< reco::PFRecTrackCollection > &trackh, const T< reco::GsfPFRecTrackCollection > &gsftrackh, const T< reco::PFClusterCollection > &ecalh, const T< reco::PFClusterCollection > &hcalh, const T< reco::PFClusterCollection > &hoh, const T< reco::PFClusterCollection > &psh, const Mask &trackMask=dummyMask_, const Mask &gsftrackMask=dummyMask_, const Mask &ecalMask=dummyMask_, const Mask &hcalMask=dummyMask_, const Mask &hoMask=dummyMask_, const Mask &psMask=dummyMask_)
COLIN: what is this setinput function for? can it be removed?
Definition: PFBlockAlgo.h:152
void setFromGsfElectron(bool val)
set provenance
std::auto_ptr< reco::PFBlockCollection > blocks_
Definition: PFBlockAlgo.h:299
std::vector< double > DPtovPtCut_
DPt/Pt cut for creating atrack element.
Definition: PFBlockAlgo.h:317
bool isAvailable() const
Definition: Ref.h:276
void insertFieldClusterElt(reco::PFBlockElement *ecalCluster)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
double testTrackAndPS(const reco::PFRecTrack &track, const reco::PFCluster &ps) const
Definition: PFBlockAlgo.cc:869
std::list< reco::PFBlockElement * >::const_iterator IEC
Definition: PFBlockAlgo.h:193
static int checkOverlap(const reco::PFCluster &pfc, std::vector< const reco::SuperCluster * > sc, float minfrac=0.01, bool debug=false)
virtual void setTrackType(TrackType trType, bool value)
the trackType
Particle Flow Algorithm.
Definition: PFBlockAlgo.h:71
void fillFromPhoton(const T< reco::PhotonCollection > &, unsigned isc, reco::PFBlockElementSuperCluster *pfbe)
Definition: PFBlockAlgo.h:1133
void setFromPhoton(bool val)
set provenance
void setHcalIso(float val)
set the had Iso
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
double testLinkBySuperCluster(const reco::PFClusterRef &elt1, const reco::PFClusterRef &elt2) const
test association by Supercluster between two ECAL
Definition: PFBlockAlgo.cc:994
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
KDTreeLinkerTrackHcal THLinker_
Definition: PFBlockAlgo.h:310
double testPS1AndPS2(const reco::PFCluster &ps1, const reco::PFCluster &ps2) const
void setInput(const T< reco::PFRecTrackCollection > &trackh, const T< reco::MuonCollection > &muonh, const T< reco::PFClusterCollection > &ecalh, const T< reco::PFClusterCollection > &hcalh, const T< reco::PFClusterCollection > &hoh, const T< reco::PFClusterCollection > &hfemh, const T< reco::PFClusterCollection > &hfhadh, const T< reco::PFClusterCollection > &psh, const Mask &trackMask=dummyMask_, const Mask &ecalMask=dummyMask_, const Mask &hcalMask=dummyMask_, const Mask &hoMask=dummyMask_, const Mask &psMask=dummyMask_)
COLIN: I think this is for particle flow at HLT...
Definition: PFBlockAlgo.h:124
std::vector< GsfPFRecTrack > GsfPFRecTrackCollection
collection of GsfPFRecTrack objects
void setTrackIso(float val)
set the track Iso
bool useConvBremPFRecTracks_
switch on/off Conversions Brem Recovery with KF Tracks
Definition: PFBlockAlgo.h:338
void setPhotonRef(const PhotonRef &ref)
set photonRef
int muAssocToTrack(const reco::TrackRef &trackref, const edm::Handle< reco::MuonCollection > &muonh) const
void setDebug(bool debug)
sets debug printout flag
Definition: PFBlockAlgo.h:177
virtual void setDisplacedVertexRef(const PFDisplacedTrackerVertexRef &niref, TrackType trType)
void link(const reco::PFBlockElement *el1, const reco::PFBlockElement *el2, PFBlockLink::Type &linktype, reco::PFBlock::LinkTest &linktest, double &dist) const
check whether 2 elements are linked. Returns distance and linktype
Definition: PFBlockAlgo.cc:320
void setInput(const T< reco::PFRecTrackCollection > &trackh, const T< reco::GsfPFRecTrackCollection > &gsftrackh, const T< reco::GsfPFRecTrackCollection > &convbremgsftrackh, const T< reco::MuonCollection > &muonh, const T< reco::PFDisplacedTrackerVertexCollection > &nuclearh, const T< reco::PFRecTrackCollection > &nucleartrackh, const T< reco::PFConversionCollection > &conv, const T< reco::PFV0Collection > &v0, const T< reco::PFClusterCollection > &ecalh, const T< reco::PFClusterCollection > &hcalh, const T< reco::PFClusterCollection > &hoh, const T< reco::PFClusterCollection > &hfemh, const T< reco::PFClusterCollection > &hfhadh, const T< reco::PFClusterCollection > &psh, const T< reco::PhotonCollection > &egphh, const Mask &trackMask=dummyMask_, const Mask &gsftrackMask=dummyMask_, const Mask &ecalMask=dummyMask_, const Mask &hcalMask=dummyMask_, const Mask &hoMask=dummyMask_, const Mask &hfemMask=dummyMask_, const Mask &hfhadMask=dummyMask_, const Mask &psMask=dummyMask_, const Mask &phMask=dummyMask_)
set input collections of tracks and clusters
Definition: PFBlockAlgo.h:372
virtual void setV0Ref(const VertexCompositeCandidateRef &v0ref, TrackType trType)
void insertFieldClusterElt(reco::PFBlockElement *ecalCluster)
std::list< reco::PFBlockElement * >::iterator IE
define these in *Fwd files in DataFormats/ParticleFlowReco?
Definition: PFBlockAlgo.h:192
void buildGraph()
Definition: PFBlockAlgo.cc:313
std::list< reco::PFBlockElement * > elements_
actually, particles will be created by a separate producer
Definition: PFBlockAlgo.h:305
void insertTargetElt(reco::PFBlockElement *track)
std::vector< std::vector< reco::PFClusterRef > > scpfcRefs_
PF clusters corresponding to a given SC.
Definition: PFBlockAlgo.h:353
bool goodPtResolution(const reco::TrackRef &trackref)
open a resolution map
void packLinks(reco::PFBlock &block, const std::vector< PFBlockLink > &links) const
Definition: PFBlockAlgo.cc:237
static const Mask dummyMask_
Definition: PFBlockAlgo.h:314
reco::PFBlockCollection::const_iterator IBC
Definition: PFBlockAlgo.h:194
IE associate(IE next, IE last, std::vector< PFBlockLink > &links)
Definition: PFBlockAlgo.cc:123
const PhotonSelectorAlgo * photonSelector_
PhotonSelector.
Definition: PFBlockAlgo.h:341
virtual void setConversionRef(const ConversionRef &convRef, TrackType trType)
double testLinkByVertex(const reco::PFBlockElement *elt1, const reco::PFBlockElement *elt2) const
tuple tracks
Definition: testEve_cfg.py:39
static bool isLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:24
std::auto_ptr< reco::PFBlockCollection > transferBlocks()
Definition: PFBlockAlgo.h:189
void insertTargetElt(reco::PFBlockElement *track)
key_type key() const
Accessor for product key.
Definition: Ref.h:266
bool linkPrefilter(const reco::PFBlockElement *last, const reco::PFBlockElement *next) const
Avoid to check links when not useful.
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
void findBlocks()
build blocks
Definition: PFBlockAlgo.cc:81
std::vector< int > pfcSCVec_
SC corresponding to the PF cluster.
Definition: PFBlockAlgo.h:347
void setParameters(std::vector< double > &DPtovPtCut, std::vector< unsigned > &NHitCut, bool useConvBremPFRecTracks, bool useIterTracking, int nuclearInteractionsPurity, bool useEGPhotons, std::vector< double > &photonSelectionCuts)
Definition: PFBlockAlgo.cc:31
void insertTargetElt(reco::PFBlockElement *psCluster)
virtual void setMuonRef(const MuonRef &muref)
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
tuple cout
Definition: gather_cfg.py:121
std::vector< bool > Mask
Definition: PFBlockAlgo.h:93
void setUseOptimization(bool useKDTreeTrackEcalLinker)
Definition: PFBlockAlgo.cc:61
bool bNoSuperclus_
Definition: PFBlockAlgo.h:350
bool debug_
if true, debug printouts activated
Definition: PFBlockAlgo.h:355
#define debug
Definition: MEtoEDMFormat.h:34
long double T
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9
tuple size
Write out results.
bool useEGPhotons_
Flag to turn off the import of EG Photons.
Definition: PFBlockAlgo.h:326
bool useKDTreeTrackEcalLinker_
Definition: PFBlockAlgo.h:308
void setEcalIso(float val)
set the ecal Iso
std::vector< unsigned > NHitCut_
Number of layers crossed cut for creating atrack element.
Definition: PFBlockAlgo.h:320
Block of elements.
Definition: PFBlock.h:30