{ // Simple display of events from exampleR05 // 03-Oct-2000 Bill Seligman gROOT->Reset(); // Load the libStar ROOT extension gSystem.Load("$ROOTSYS/lib/libStar.so"); // Load the definitions of our custom classes. gSystem.Load("ExR05.so"); // Display them (a clumsy way to imbed a ROOT command in a CINT file) // TExec("ex1",".class ExR05RootEvent")->Exec(); // TExec("ex2",".class ExR05RootHit")->Exec(); TFile* f = new TFile("~/public/exampleR08.root"); f->ls(); TString eventName = "LarEvent;"; TString eventNumber = "2"; // You can change this to "0", "1", "2", or "3". TDataSet* myEvent = (TDataSet*)f->Get(eventName + eventNumber); myEvent->ls(4); // Note how the number of hits changes (for Tree #2 or #3), though the // event ID does not; "hitBranch->GetEvent" only reads the m_hits, but // nothing else. eventNumber = "45"; delete myEvent; myEvent = (TDataSet*)f->Get(eventName + eventNumber); myEvent->ls(4); ExR05StarHit* aHit = (ExR05StarHit*)myEvent->FindByName("hits"); ExR05StarEvent* aEvent = (ExR05StarEvent*)myEvent->FindByName("event"); aEvent->Print(0,1); // Let's make a histogram (compare with example R04). TH1F* hitHist = new TH1F("Hist" + eventName, "z-distribution of energy deposited by hits",240,0.,600.); hitHist->SetDirectory(gROOT); // otherwise ROOT wants to write this histogran to ROOT file hitHist->Draw(); hitHist->SetXTitle("z-position [cm]"); hitHist->SetYTitle("Energy [GeV]"); // Work variables for filling the histogram. TList *events = f->GetListOfKeys(); TIter nextEvent(events); TKey *nextRecord = 0; Int_t i = 0; // refresh counter // For each event in the tree... while (nextRecord = (TKey *)nextEvent()) { delete myEvent; myEvent = (TDataSet *)nextRecord->ReadObj(); // For each hit in the event... aHit = (ExR05StarHit*)myEvent->FindByName("hits"); if (!aHit) continue; // new ExR05StarHit::iterator hit = aHit->begin(); // new ExR05StarHit::iterator lastHit = aHit->end(); // new for (; hit != lastHit; hit++) // This is the obsolete version since Lar keeps the obsolete "libStar" Int_t nHits = aHit->GetNRows(); hit_t *hit = aHit->GetTable(); Int_t j; for (j=0; j < nHits; j++,hit++) { hitHist->Fill(hit->xyz[2],hit->energy); } } // Another demonstration: Let ROOT write the dataset in form if directory tree // using MakeClass. The following will create a ".h" and ".C" file, // which can then be edited manually to suit a particular analysis // task. eventNumber = "45"; delete myEvent; myEvent = (TDataSet*)f->Get(eventName + eventNumber); aHit = (ExR05StarHit*)myEvent->FindByName("hits"); TString outName = aHit->GetName(); outName += ".C"; ofstream *out = new ofstream(outName.Data()); aHit->SavePrimitive(*out,""); printf(" The hits from the event #%s have been converted to ACSII ROOT macro %s\n", eventNumber.Data() , outName.Data()); delete out; TString lsCmd = "ls -l "; lsCmd += outName; gSystem->Exec(lsCmd); // Call ROOT browser new TBrowser("ATLAS events",f); // Create the HTML documentation for our ROOT classes. ROOT provides // a facility for creating the documentation for an entire directory // of code at once, but we don't use that here since only a couple of // exampleR05's classes are ROOT-based. THtml* html = new THtml(); html->SetSourceDir( "./include:./src:./" ); html->SetOutputDir( "./htmldoc" ); html->MakeClass("ExR05StarEvent",kTRUE); html->MakeClass("ExR05StarHit",kTRUE); TClass ee("event_t",1, ExR05StarEvent::DeclFileName(), ExR05StarEvent::DeclFileName()); TClass hh("hit_t", 1, ExR05StarHit::DeclFileName(), ExR05StarHit::DeclFileName()); html->MakeClass("event_t",kTRUE); html->MakeClass("hit_t",kTRUE); // MakeAll is interesting, but it generates output for all the classes // loaded in memory. //html->MakeAll(); }