]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ACORDE/macros/ReadACORDEHits.C
Adding ANALYSIS
[u/mrichter/AliRoot.git] / ACORDE / macros / ReadACORDEHits.C
1 void ReadACORDEHits (Int_t numberOfEvents=-1,
2                      const char *filename="galice.root")
3
4   //  produces some plots from acorde hits
5
6 {
7   // Dynamically link some shared libs
8   if (gClassTable->GetID("AliRun") < 0) 
9     {
10       gROOT->LoadMacro("loadlibs.C");
11       loadlibs();
12     }
13   if (gAlice)
14     {
15       delete gAlice->GetRunLoader();
16       delete gAlice;
17       gAlice = 0x0;
18     }
19
20   // get loaders
21   AliRunLoader *rl =
22     AliRunLoader::Open("galice.root",
23                        AliConfig::GetDefaultEventFolderName(),"read");
24   if (!rl)
25     {
26       cerr<<"Can't load RunLoader from file! \n";      return 0x0;
27     }
28   
29   rl->LoadgAlice();
30   gAlice = rl->GetAliRun();
31   if (!gAlice)
32     {
33       cerr << " AliRun object not found on file \n";     return 0x0; 
34     }
35   rl->LoadHeader();
36   
37
38   // Get the pointer to the ACORDE detector
39   AliLoader *acordel = rl->GetLoader("ACORDELoader");
40   AliACORDE *ACORDE = (AliACORDE *) gAlice->GetDetector("ACORDE");
41   if (ACORDE == 0x0 || acordel == 0x0) {
42     cerr << " Can not find ACORDE or ACORDELoader \n";    return 0x0;  
43   }
44
45   // get number of events 
46   if (numberOfEvents<0) numberOfEvents=(Int_t)(rl->GetNumberOfEvents());
47   
48   //create histograms
49   TH1F *elossH = new TH1F("eloss" ,"Energy Loss ",1000,0.,10);
50   TH2F *geoH = new TH2F("geo"," ACORDE geometry seen by hits",
51                         250, -750,750, 250, -500,500);
52
53   for (Int_t ievent=0; ievent<numberOfEvents; ievent++) {
54     if ((ievent%10) == 0)  printf ("Processing event %d \n", ievent);
55     rl->GetEvent(ievent);
56     
57     // Get the pointer Hit tree
58     acordel->LoadHits();
59     TTree *hitTree = acordel->TreeH();
60     ACORDE->SetTreeAddress();
61     if (!hitTree) {
62       cout << " No TreeH found" << endl;      return 0x0; //rc;
63     }
64     
65     rl->LoadKinematics();
66     Int_t nTrack = (Int_t) hitTree->GetEntries();
67     
68     // Start loop on tracks in the hits containers
69     for(Int_t iTrack=0; iTrack<nTrack;iTrack++){
70       ACORDE->ResetHits();
71       hitTree->GetEvent(iTrack);          
72       if(ACORDE) {       
73         for(acordeHit=(AliACORDEhit*)ACORDE->FirstHit(-1);acordeHit;
74             acordeHit=(AliACORDEhit*)ACORDE->NextHit()) {
75           elossH->Fill( (Float_t)(acordeHit->Eloss()*1000.0));
76           geoH->Fill(acordeHit->X(),acordeHit->Z());
77         } // end for acordeHits
78       } // end if ACORDE
79     } // end for iTrack  
80   }
81  // save histos in a root file
82   TFile *fout = new TFile("ACORDE_hits.root","RECREATE");
83   elossH->Write();
84   geoH->Write();
85   fout->Close();
86 }