1 /****************************************************************************
2 * This macro calculates the efficiency of pileup reconstruction. *
3 * Works only for events generated with the AliGenPileup generator. *
5 * Before running, load the ITSU libraries: *
6 * gSystem->Load("libITSUpgradeBase");gSystem->Load("libITSUpgradeRec"); *
8 * Origin: I.Belikov, IPHC, Iouri.Belikov@iphc.cnrs.fr *
9 ****************************************************************************/
11 #if !defined(__CINT__) || defined(__MAKECINT__)
12 #include <Riostream.h>
15 #include <TParticle.h>
21 #include "AliHeader.h"
22 #include "AliGenCocktailEventHeader.h"
23 #include "AliRunLoader.h"
25 #include "AliESDEvent.h"
26 #include "AliESDtrack.h"
29 Int_t GoodPileupVertices(const Char_t *dir=".");
31 extern AliRun *gAlice;
34 Int_t AliITSUComparisonPileup(const Char_t *dir=".") {
35 ::Info("AliITSUComparisonPileup.C","Doing comparison...");
37 // **** Book histogramms
38 TH2F *h2=(TH2F*)gROOT->FindObject("h2");
39 if (!h2) h2=new TH2F("h2",";Number of good vertices;Number of reconstructed vertices",100,0.,100.,10,0.,10.);
42 // **** Generate a rerefence file with reconstructable vertices
44 sprintf(fname,"%s/GoodPileupVertices.root",dir);
45 TFile *refFile=TFile::Open(fname,"old");
46 if (!refFile || !refFile->IsOpen()) {
47 ::Info("AliITSUComparisonPileup.C",
48 "Marking good pileup vertices (will take a while)...");
49 if (GoodPileupVertices(dir)) {
50 ::Error("AliITSUComparisonPileup.C","Can't generate the reference file !");
54 refFile=TFile::Open(fname,"old");
55 if (!refFile || !refFile->IsOpen()) {
56 ::Error("AliITSUComparisonPileup.C","Can't open the reference file !");
59 TTree *refTree=(TTree*)refFile->Get("refTree");
61 ::Error("AliITSUComparisonPileup.C","Can't get the reference tree !");
64 TBranch *branch=refTree->GetBranch("Vertices");
66 ::Error("AliITSUComparisonPileup.C","Can't get the vertex branch !");
69 TClonesArray dummy("AliESDVertex",100), *refs=&dummy;
70 branch->SetAddress(&refs);
74 sprintf(fname,"%s/AliESDs.root",dir);
75 TFile *ef=TFile::Open(fname);
76 if ((!ef)||(!ef->IsOpen())) {
77 ::Error("AliITSUComparisonPileup.C","Can't open AliESDs.root !");
80 AliESDEvent* event = new AliESDEvent();
81 TTree* esdTree = (TTree*) ef->Get("esdTree");
83 ::Error("AliITSUComparisonPileup.C", "no ESD tree found");
86 event->ReadFromTree(esdTree);
89 //******* Loop over events *********
91 while (esdTree->GetEvent(e)) {
92 cout<<endl<<endl<<"********* Processing event number: "<<e<<"*******\n";
93 TClonesArray *vertices=event->GetPileupVerticesTracks();
94 Int_t nrec=vertices->GetEntriesFast();
96 if (refTree->GetEvent(e++)==0) {
97 cerr<<"No reconstructable vertices for this event !\n";
100 Int_t ngood=refs->GetEntriesFast();
101 cout<<"reconstructed: "<<nrec<<" good: "<<ngood<<endl;
103 h2->Fill(ngood,nrec);
105 } //***** End of the loop over events
113 TCanvas *c1=new TCanvas("c1","",0,0,750,500);
116 TFile fc("AliITSUComparisonCooked.root","RECREATE");
125 Int_t GoodPileupVertices(const Char_t *dir) {
127 delete AliRunLoader::Instance();
128 delete gAlice;//if everything was OK here it is already NULL
133 sprintf(fname,"%s/galice.root",dir);
135 AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON");
137 ::Error("GoodPileupVertices","Can't start session !");
143 rl->LoadKinematics();
146 Int_t nev=rl->GetNumberOfEvents();
147 ::Info("GoodPileupVertices","Number of events : %d\n",nev);
149 sprintf(fname,"%s/GoodPileupVertices.root",dir);
150 TFile *refFile=TFile::Open(fname,"recreate");
151 TClonesArray dummy("AliESDVertex",100), *refs=&dummy;
152 TTree refTree("refTree","Tree with the reconstructable vertices");
153 refTree.Branch("Vertices",&refs);
155 //******** Loop over generated events
156 for (Int_t e=0; e<nev; e++) {
157 rl->GetEvent(e); refFile->cd();
159 AliHeader *ah=rl->GetHeader();
160 AliGenCocktailEventHeader *cock=
161 (AliGenCocktailEventHeader*)ah->GenEventHeader();
162 TList *headers=cock->GetHeaders();
163 const Int_t nvtx=headers->GetEntries();
164 cout<<"Event "<<e<<" Number of vertices: "<<nvtx<<endl;
167 for (Int_t v=0; v<nvtx; v++) {
168 AliGenEventHeader *h=(AliGenEventHeader *)headers->At(v);
169 TArrayF vtx(3); h->PrimaryVertex(vtx);
170 //if (...) continue; // Check if this vertex is reconstructable
171 AliESDVertex *vertex=new ((*refs)[nv]) AliESDVertex();
172 vertex->SetXv(vtx[0]);
173 vertex->SetYv(vtx[1]);
174 vertex->SetZv(vtx[2]);
179 } //*** end of the loop over generated events