Note: The following code was taken directly from
RootTreeAnalysis in the RootAnalysis package stored in Offline's CVS repository.
In this context, the variable, rec, is a ReconEvent object which was filled in
RootTreeAnalysis::Go( ) method. All file handling is done within the
initialization of the RootTreeAnalysis object and is not shown here.
The complete documentation of the reconRootData library which
defines ReconEvent and all reconstruction classes can be found at:
http://confluence.slac.stanford.edu/display/WB/reconRootData
Code Snippet | Description |
void
RootTreeAnalysis::ReconTkr() { // Purpose and Method: Process one TkrRecon event TkrRecon *tkrRecon = rec->getTkrRecon(); // If no TRKRECON data is available then return if (!tkrRecon) return; |
Retrieve the TkrRecon pointer from the ReconEvent object, exit the method if this TkrRecon object is null. |
// Retrieve
collection of clusters TObjArray* clusterCol = tkrRecon->getClusterCol(); // Retreive collection of vertices TObjArray* vertexCol = tkrRecon->getVertexCol(); // Retrieve collection of tracks TObjArray* trackCol = tkrRecon->getTrackCol(); ((TH1F*)GetObjectPtr("TKRNUMFITTRACKS"))->Fill(trackCol->GetEntries()); |
Retrieve the full collection of TkrClusters.
Retrieve the full set of TkrVertices.
Retrieve the full collection of TkrTracks. Fill the TKRNUMFITSTRACKS histogram with the number of tracks in this TkrRecon event.
|
// loop over all
tracks TIter trackIter(trackCol); TkrTrack *track = 0; while (track = (TkrTrack*)trackIter.Next()) { ((TH1F*)GetObjectPtr("TKRNUMHITSPERTRACK"))->Fill(track->Size()); TVector3 initPos = track->getInitialPosition(); TVector3 dir = track->getInitialDirection(); Double_t costh = -dir.Z(); Double_t quality = track->getQuality(); Double_t kalEnergy = track->getKalEnergy(); // loop over hits in this track TIter hitIter(track); TkrTrackHit *hit = 0; while (hit = (TkrTrackHit*)hitIter.Next()) { Double_t planeZ = hit->getZPlane(); const TkrCluster *cluster = ((*hit).getClusterPtr()); if (!cluster) continue; Int_t layer = cluster->getLayer(); commonRootData::TkrId id = cluster->getTkrId(); Int_t plane = cluster->getPlane(); Int_t view = id.getView(); // get the tower from the TkrId Int_t towerX = id.getTowerX(); Int_t towerY = id.getTowerY(); } } |
Create a ROOT TIter to iterate over the TkrTrack objects. The
while loop uses this iterator and fills the, track, variable with the
current TkrTrack pointer. Retrieve the initial position and direction of the TkrTrack. These are stored in ROOT's TVector3 objects. The Z component of the direction corresponds to cosine theta. Retrieve the quality of the TkrTrack and the KalEnergy. Create a ROOT TIter to iterate over the TkrTrackHits for this TkrTrack - the while loop uses this iterator and fills the hit variable with the current TkrTrackHit pointer.
Determine the Z plane for this TkrTrackHit. Retrieve the TkrCluster pointer for this TkrTrackHit. Check that the TkrCluster pointer is non-null, before continuing. Retrieve the layer for this TkrCluster. Get the commonRootData::TkrId for this TkrCluster.Retrieve the plane and view for this TkrCluster, using the commonRootData::TkrId methods. Finally, get the tower (x,y) from this id.
|
Float_t recArr[2] = {trackCol->GetEntries(),
clusterCol->GetEntries()}; ((TNtuple*)GetObjectPtr("tkrReconTup"))->Fill(recArr); } |
Fill the example ntuple. |
If you desire to download this piece of code - here is a full copy:
void
RootTreeAnalysis::ReconTkr() {
// Purpose and Method: Process
one TkrRecon event
TkrRecon *tkrRecon = rec->getTkrRecon();
// If no TRKRECON data is available
then return
if (!tkrRecon)
return;
// Retrieve collection of clusters
TObjArray* clusterCol = tkrRecon->getClusterCol();
// Retreive collection of vertices
TObjArray* vertexCol = tkrRecon->getVertexCol();
// Retrieve collection of tracks
TObjArray* trackCol = tkrRecon->getTrackCol();
((TH1F*)GetObjectPtr("TKRNUMFITTRACKS"))->Fill(trackCol->GetEntries());
// loop over all tracks
TIter trackIter(trackCol);
TkrTrack *track = 0;
while (track = (TkrTrack*)trackIter.Next())
{
((TH1F*)GetObjectPtr("TKRNUMHITSPERTRACK"))->Fill(track->Size());
TVector3 initPos = track->getInitialPosition();
TVector3 dir = track->getInitialDirection();
Double_t costh = -dir.Z();
Double_t quality = track->getQuality();
Double_t kalEnergy = track->getKalEnergy();
// loop over
hits in this track
TIter hitIter(track);
TkrTrackHit *hit = 0;
while
(hit = (TkrTrackHit*)hitIter.Next()) {
Double_t
planeZ = hit->getZPlane();
const TkrCluster *cluster = ((*hit).getClusterPtr());
if (!cluster) continue;
Int_t layer =
cluster->getLayer();
commonRootData::TkrId id = cluster->getTkrId();
Int_t plane
= cluster->getPlane();
Int_t view
= id.getView();
// get the tower from the TkrId
Int_t towerX = id.getTowerX();
Int_t towerY
= id.getTowerY();
}
}
Float_t recArr[2] = {trackCol->GetEntries(), clusterCol->GetEntries()};
((TNtuple*)GetObjectPtr("tkrReconTup"))->Fill(recArr);
}