//////////////////////////////////////////////////////////////////// // // File: TrackingVariables2.cc // Authors: Heather Gerberich // Description: High level analysis tracking variables defined as functions // Created: 10/30/2000 // //////////////////////////////////////////////////////////////////// #include //#include #include "BaBar/Cdf.hh" #include "AbsEnv/AbsEnv.hh" #include "Edm/StorableObject.hh" #include "HighLevelObjects/TrackingVariables.hh" #include "VertexObjects/ZVertexColl.hh" #include "VertexObjects/VertexColl.hh" #include "VertexObjects/Vertex.hh" #include "TrackingObjects/Tracks/track_cut.hh" #include "TrackingObjects/Storable/CdfTrackView.hh" #include "TofObjects/Event/TofTrackView.hh" #include "OldTofObjects/TofMatchColl.hh" #include namespace TrackingVariables { // The following are overloaded ways to call the tracking isolation // Tracking isolation, geometry-based arguments double trkTrackIsolation(double phi, double eta, double z, double cone, double dzMaxCut, double ptMinCut, int flags) { CdfTrackView_h trview; if(CdfTrackView::defTracks(trview,"PROD") != CdfTrackView::OK) { if(CdfTrackView::defTracks(trview,"USRP") != CdfTrackView::OK) { if(CdfTrackView::defTracks(trview,"UNKN") != CdfTrackView::OK) { if(CdfTrackView::defTracks(trview,"L3") != CdfTrackView::OK) return -99.0; } } } return trkTrackIsolationCore(phi, eta, z, *trview, NULL, cone, dzMaxCut, ptMinCut, flags); } // Tracking isolation, track-based arguments double trkTrackIsolation(const CdfTrack& seedTrack, double cone, double dzMaxCut, double ptMinCut, int flags) { CdfTrackView_h trview; if(CdfTrackView::defTracks(trview,"PROD") != CdfTrackView::OK) { if(CdfTrackView::defTracks(trview,"USRP") != CdfTrackView::OK) { if(CdfTrackView::defTracks(trview,"UNKN") != CdfTrackView::OK) { if(CdfTrackView::defTracks(trview,"L3") != CdfTrackView::OK) return -99.0; } } } return trkTrackIsolationCore(seedTrack.phi0(), seedTrack.pseudoRapidity(), seedTrack.z0(), *trview, &seedTrack, cone, dzMaxCut, ptMinCut, flags); } double trkTrackIsolation(double phi, double eta, double z, const CdfTrackView& trview, double cone, double dzMaxCut, double ptMinCut, int flags) { return trkTrackIsolationCore(phi, eta, z, trview, NULL, cone, dzMaxCut, ptMinCut, flags); } double trkTrackIsolation(const CdfTrack& seedTrack, const CdfTrackView& trview, double cone, double dzMaxCut, double ptMinCut, int flags) { return trkTrackIsolationCore(seedTrack.phi0(), seedTrack.pseudoRapidity(), seedTrack.z0(), trview, &seedTrack, cone, dzMaxCut, ptMinCut, flags); } //Old utility routine with almost all the arguments double trkTrackIsolationCore(double phi, double eta, double z, const CdfTrackView& trackList, const CdfTrack* seedTrack, double cone, double dzMaxCut, double ptMinCut, int flags) { int nTrkInCone; double ptMax; return trkTrackIsolationInnerCore(phi, eta, z, trackList, seedTrack, cone, dzMaxCut, ptMinCut, flags, nTrkInCone, ptMax); } //Utility routine with all the arguments double trkTrackIsolationInnerCore(double phi, double eta, double z, const CdfTrackView& trackList, const CdfTrack* seedTrack, double cone, double dzMaxCut, double ptMinCut, int flags, int& nTrkInCone, double& ptMax) { double sumPt = 0.0; nTrkInCone = 0; ptMax = 0.0; Hep3Vector p; p.setREtaPhi(1.0,eta,phi); CdfTrackView* pTrkInCone = new CdfTrackView( trackList.contents().begin(), trackList.contents().end(), track_cut::InConeAround(p,cone)&& track_cut::Z0WrtZInRange(z,dzMaxCut) ); for(CdfTrackView::const_iterator itrack=pTrkInCone->contents().begin(); itrack!=pTrkInCone->contents().end(); ++itrack) { // check the track and parents (COT track for SVX track) // against the seedTrack bool ok = true; if(seedTrack!=NULL) { const CdfTrack* testTrack = (*itrack).operator->(); do { if( testTrack->id() == seedTrack->id() ) ok = false; testTrack = testTrack->parent().operator->(); } while ( testTrack!=NULL ); } if(ok) { double aPt = (*itrack)->pt(); sumPt += aPt; if(aPt>ptMax) ptMax = aPt; nTrkInCone++; } } pTrkInCone->destroy(); return sumPt; } // **************** Primary Vertex from vxprim -> VertexColl const Vertex* trkPrimaryVertex() { EventRecord* event = AbsEnv::instance()->theEvent(); const Vertex* prim = NULL; double htMax = -1.0; EventRecord::ConstIterator it(event,"VertexColl","DEFAULT_VXPRIM_VERTICES"); if(it.is_valid()) { ConstHandle vs(it); // Coll is a vector of Link, Link dereferences to Vertex& for(VertexColl::const_iterator iv = vs->contents().begin(); iv != vs->contents().end(); ++iv) { if(*iv) { // if Link is valid const Vertex& vrt = *(*iv); if(vrt.ht() > htMax) { htMax = vrt.ht(); prim = &vrt; } } } // end loop over vertices } // end valid iterator return prim; } //Number of Vertices int trkNPrimaryVertex() { EventRecord* event = AbsEnv::instance()->theEvent(); EventRecord::ConstIterator it(event,"VertexColl","DEFAULT_VXPRIM_VERTICES"); if(it.is_valid()) { ConstHandle vs(it); return vs->contents().size(); } return 0; } //Z of Primary Vertex double trkPrimaryVertexZ(){ const Vertex* v = trkPrimaryVertex(); if(v==NULL) return -999.0; return v->z(); } //Ht of Primary Vertex double trkPrimaryVertexHt(){ const Vertex* v = trkPrimaryVertex(); if(v==NULL) return -99.0; return v->ht(); } //Number of tracks associated with the primary Vertex int trkPrimaryVertexNTracks(){ const Vertex* v = trkPrimaryVertex(); if(v==NULL) return -99; return v->nTracks(); } // **************** Primary Vertex from ZVertexModule -> ZVertexColl const ZVertex* trkZVertex() { EventRecord* event = AbsEnv::instance()->theEvent(); const ZVertex* prim = NULL; double htMax = -1.0; EventRecord::ConstIterator it(event,"ZVertexColl","ZVertexColl"); if (it.is_valid()) { ConstHandle vertexSet(it); ZVertexColl::const_iterator iZVertex; for(iZVertex=vertexSet->contents().begin(); iZVertex!=vertexSet->contents().end(); iZVertex++) { if(iZVertex->getSumPt()>htMax) { prim = &(*iZVertex); htMax = iZVertex->getSumPt(); } } } return prim; } //Number of Vertices int trkNZVertex() { EventRecord* event = AbsEnv::instance()->theEvent(); EventRecord::ConstIterator it(event,"ZVertexColl","ZVertexColl"); if (it.is_valid()) { ConstHandle vertexSet(it); return vertexSet->contents().size(); } return 0; } //Number of good (cal>=12) vertices int trkNGoodZVertex() { EventRecord* event = AbsEnv::instance()->theEvent(); int n = 0; EventRecord::ConstIterator it(event,"ZVertexColl","ZVertexColl"); if (it.is_valid()) { ConstHandle vertexSet(it); ZVertexColl::const_iterator iZVertex; for(iZVertex=vertexSet->contents().begin(); iZVertex!=vertexSet->contents().end(); iZVertex++) { if(iZVertex->getQuality()>=12) n++; } } return n; } //Z of Primary Vertex double trkZVertexZ(){ const ZVertex* v = trkZVertex(); if(v==NULL) return -999.0; return v->zPosition(); } //Ht of Primary Vertex double trkZVertexHt(){ const ZVertex* v = trkZVertex(); if(v==NULL) return -99.0; return v->getSumPt(); } //Number of tracks associated with the primary Vertex int trkZVertexNTracks(){ const ZVertex* v = trkZVertex(); if(v==NULL) return -99; return v->getNTracks(); } //******************* TOF information //Return associated TofMatches TofMatches* trkTofMatches(const CdfTrack* track) { TofTrackView_ch tofview; TofTrackView::Error tofStatus = TofTrackView::find(tofview); if (tofStatus == TofTrackView::OK) { for (TofTrackView::const_iterator it = tofview->contents().begin(); it != tofview->contents().end(); it++) { if (((CdfTrack*) &**it) == track) return (TofMatches*) it->assoc(); } } return NULL; } //Return associated TofMatch. This is the old tof object but is still //present in old production const TofMatch* trkOldTofMatch(const CdfTrack* track) { CdfTrack::Id trackid; if (!track) { return NULL; } else { trackid = track->id(); } TofMatchColl_ch tofcol; TofMatchColl::Error status = TofMatchColl::find(tofcol); if (status == TofMatchColl::OK) { for (TofMatchColl::const_iterator it = tofcol->contents().begin(); it != tofcol->contents().end(); ++it) { const TofMatch* tof = &**it; if (tof && (CdfTrack::Id) tof->getTrackId() == trackid) { return tof; } } } return NULL; } }