Note: The following code was taken directly from
RootTreeAnalysis in the RootAnalysis package stored in Offline's CVS repository.
In this context, the variable, evt, is a DigiEvent 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 digiRootData library which
defines DigiEvent and all digitization (detector) classes can be found at:
http://confluence.slac.stanford.edu/display/WB/digiRootData
Code snippet | Description |
void
RootTreeAnalysis::DigiTkr() { // Purpose and Method: Process on TKR digi event // The full collection of TkrDigis for this event const TObjArray* tkrDigiCol = evt->getTkrDigiCol(); if (!tkrDigiCol) return; // Total number of TkrDigis for this event Int_t numTkrDigi = tkrDigiCol->GetEntries(); Int_t totalHits = 0; |
Retrieve the full collection of TkrDigis from the DigiEvent object. Then determine how many TkrDigis exist in this event. |
// Loop over all
TkrDigis TIter tkrIter(tkrDigiCol); TkrDigi *tkr = 0; while (tkr = (TkrDigi*)tkrIter.Next()) { // Identify the tower and layer Int_t tower = tkr->getTower().id(); Int_t layer = tkr->getBilayer(); // get to ToT Int_t tot0 = tkr->getToT(0); Int_t tot1 = tkr->getToT(1); Int_t lastController0 = tkr->getLastController0Strip(); // Returns the orientation of the strips GlastAxis::axis view = tkr->getView(); UInt_t numHits = tkr->getNumHits(); totalHits += numHits; // Loop through collection of hit strips for this TkrDigi UInt_t ihit; for (ihit = 0; ihit < numHits; ihit++) { // Retrieve the strip number Int_t stripNum = tkr->getStrip(ihit); if (layer == 5) ((TH1F*)GetObjectPtr("TKRSTRIPSLYR5"))->Fill(stripNum); } } |
Create a ROOT iterator (TIter) for looping over the full collection
of TkrDigis, the while loop uses this iterator to control the looping,
where tkr then contains the current TkrDigi* object. Next determine the tower and layer number of the TkrDigi. Retrieve the ToT from both ends. Find which strip is the last one associated with controller zero. Determine the orientation (view: X or Y) of the TkrDigi. Find the number of hits associated with this TkrDigi. Then loop over all the strips and find their strip numbers, if we are on bilayer 5, update the TKRSTRIPSLYR5 histogram with the current strip number. |
((TH1F*)GetObjectPtr("NUMTKRDIGI"))->Fill((Float_t)numTkrDigi); // example of filling a simple tree Float_t digiArr[2] = { (Float_t)numTkrDigi, (Float_t)totalHits }; ((TNtuple*)GetObjectPtr("tkrDigiTup"))->Fill(digiArr); return; } |
Fill the histograms and ntuples. |
If you desire to download this piece of code - here is a full copy:
void
RootTreeAnalysis::DigiTkr() {
// Purpose and Method: Process on
TKR digi event
// The full collection of TkrDigis
for this event
const
TObjArray* tkrDigiCol = evt->getTkrDigiCol();
if (!tkrDigiCol)
return;
// Total number of TkrDigis for this
event
Int_t numTkrDigi = tkrDigiCol->GetEntries();
Int_t totalHits = 0;
// Loop over all TkrDigis
TIter tkrIter(tkrDigiCol);
TkrDigi *tkr = 0;
while (tkr = (TkrDigi*)tkrIter.Next())
{
// Identify the tower
and layer
Int_t tower = tkr->getTower().id();
Int_t layer = tkr->getBilayer();
// get to ToT
Int_t tot0 = tkr->getToT(0);
Int_t tot1 = tkr->getToT(1);
Int_t lastController0 = tkr->getLastController0Strip();
// Returns the
orientation of the strips
GlastAxis::axis view = tkr->getView();
UInt_t numHits = tkr->getNumHits();
totalHits += numHits;
// Loop through
collection of hit strips for this TkrDigi
UInt_t ihit;
for (ihit =
0; ihit < numHits; ihit++) {
// Retrieve
the strip number
Int_t stripNum = tkr->getStrip(ihit);
if
(layer == 5) ((TH1F*)GetObjectPtr("TKRSTRIPSLYR5"))->Fill(stripNum);
}
}
((TH1F*)GetObjectPtr("NUMTKRDIGI"))->Fill((Float_t)numTkrDigi);
// example of filling a simple tree
Float_t digiArr[2] = { (Float_t)numTkrDigi, (Float_t)totalHits
};
((TNtuple*)GetObjectPtr("tkrDigiTup"))->Fill(digiArr);
return;
}