Project

General

Profile

Example Analysis Code » root_analysis_example.C

Example ROOT analysis - Dobbs, Adam, 08 May 2015 17:32

 
1
{
2
  // Load the MAUS data structure
3
  maus_root_dir = TString(gSystem->Getenv("MAUS_ROOT_DIR"));
4
  gSystem->Load(maus_root_dir + "/build/libMausCpp.so"); // Load the MAUS datastructure
5

    
6
  // Set up the ROOT file and data pointer
7
  TFile f1("maus_output.root"); // Load the MAUS output file
8
  TTree *T = f1.Get("Spill");   // Pull out the TTree
9
  MAUS::Data *data_ptr; // A variable to store the Data from each spill
10
  T->SetBranchAddress("data", &data_ptr);  // Set the address of data_ptr
11

    
12
  // Create the histogram
13
  TH1D* h1 = new TH1D("npe", "SciFi Spacepoint NPE", 100, 0, 150);
14
  h1->GetXaxis()->SetTitle("Number of photoelectrons");
15
  h1->SetLineColor(kBlue);
16

    
17
  // Loop over all spills
18
  for (size_t i = 0; i < T->GetEntries(); ++i) {
19
    T->GetEntry(i);  // Update the spill pointed to by data_ptr
20
    MAUS::Spill* spill = data_ptr->GetSpill();  
21
    if (spill == NULL || !(spill->GetDaqEventType() == "physics_event")) continue;
22
    std::cout << "Spill: " << spill->GetSpillNumber() << "\n";
23
    std::vector<MAUS::ReconEvent*>* revts = spill->GetReconEvents();
24

    
25
    // Loop over recon events in spill
26
    for ( size_t j = 0; j < revts->size(); ++j ) {
27
      if ( !revts->at(j) ) continue;
28
      MAUS::SciFiEvent* sfevt = revts->at(j)->GetSciFiEvent(); // Pull out scifi event
29
      std::vector<SciFiSpacePoint*> spnts = sfevt->spacepoints(); // Pull out spoints
30
      for ( size_t k = 0; k < spnts.size(); ++k ) {  // Loop over spacepoints
31
        h1->Fill(spnts[k]->get_npe()); // Fill histo with npe
32
      }
33
    }
34
  }
35
  // Draw the histogram
36
  TCanvas * c1 = new TCanvas("c1", "SciFi Spacepoint NPE", 900, 600);
37
  h1->Draw();
38
}
(1-1/5)