track number corrected
[u/mrichter/AliRoot.git] / PMD / AliPMDesdmake.C
CommitLineData
c3a5643d 1// ----------------------------------------------------//
2// //
3// This macro reads the PMD clusters, //
4// does photon/hadron discrimination //
5// and stores in the ESD //
6// //
7// ----------------------------------------------------//
8
9extern AliRun *gAlice;
10
11Int_t AliPMDesdmake(Int_t nevt = 1)
12{
13 if (gAlice)
14 {
880d6abe 15 delete AliRunLoader::GetRunLoader();
c3a5643d 16 delete gAlice;//if everything was OK here it is already NULL
17 gAlice = 0x0;
18 }
19
20 AliRunLoader *fRunLoader = AliRunLoader::Open("galice.root");
21 if (!fRunLoader)
22 {
23 cerr<<"Can't load RunLoader"<<endl;
24 return 1;
25 }
26 fRunLoader->LoadgAlice();
27 gAlice = fRunLoader->GetAliRun();
28
29 AliLoader *pmdloader = fRunLoader->GetLoader("PMDLoader");
30 Int_t nEvent = 0;
31 if (nevt <= 0)
32 {
33 nEvent = fRunLoader->GetNumberOfEvents();
34 }
35 else if (nevt > 0)
36 {
37 nEvent = nevt;
38 }
39 cout << " ************ nevent = " << nEvent << endl;
40
41 if (pmdloader == 0x0)
42 {
43 cerr<<" ===> Can not find PMD or PMDLoader <===\n";
44 delete fRunLoader;
45 return 2;
46 }
47 pmdloader->LoadRecPoints("READ");
48
49 TFile *bf=TFile::Open("AliESDcheck.root","RECREATE");
50 if (!bf || !bf->IsOpen()) {
51 cerr<<"Can't open AliESDcheck.root !\n"; return 1;
52 }
53
54 Char_t ename[100];
55
56 for (Int_t ievt = 0; ievt < nEvent; ievt++)
57 {
58
59 AliESD *event=new AliESD();
60 Int_t run = 0;
61 event->SetRunNumber(run);
62 event->SetEventNumber(ievt);
63
64 fRunLoader->GetEvent(ievt);
65 TTree *treeR = pmdloader->TreeR();
66 if (treeR == 0x0)
67 {
68 cout << " Can not get TreeR" << endl;
69 return 3;
70 }
71 AliPMDtracker *pmdtracker = new AliPMDtracker();
72 pmdtracker->LoadClusters(treeR);
73 pmdtracker->Clusters2Tracks(event);
74
75 bf->cd();
76 sprintf(ename,"in%d",ievt);
77 event->Write(ename); bf->Flush();
78
79 delete pmdtracker;
80 delete event;
81 }
82 bf->Close();
83 return 0;
84}
85