]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSL2GConvertPointsV2.C
28-mar-2007 NvE Explicitly included TMath.h in IceChi2.h and IcePandel.h due to a
[u/mrichter/AliRoot.git] / ITS / AliITSL2GConvertPointsV2.C
1 // 
2 // Macro to convert ITS local-coordinate points
3 // into globa lones
4 // 
5
6 Int_t AliITSL2GConvertPointsV2 
7 (const char* in_name = "ITS.RecPoints.root", 
8  const char* out_name = "ITS.Neural.PointsV2.root", Int_t nev = 0)
9 {
10         TStopwatch timer;
11
12         // Open output file
13         TFile *in = new TFile(in_name);
14         TFile *out = new TFile(out_name, "recreate");
15         
16         // Load event files
17         if (gAlice) {
18                 delete gAlice->GetRunLoader();
19                 delete gAlice;
20                 gAlice=0;
21         } 
22         AliRunLoader* rl = AliRunLoader::Open("galice.root");
23     if (rl == 0x0) {
24                 cerr << "AliITSL2GConvertPoints.C : Can not open session." << endl;
25                 return 3;
26         }
27     Int_t retval = rl->LoadgAlice();
28         if (retval) {
29                 cerr << "AliITSL2GConvertPoints.C : LoadgAlice returned error" << endl;
30                 return 3;
31         }
32         gAlice=rl->GetAliRun();
33         AliITSLoader* gime = (AliITSLoader*)rl->GetLoader("ITSLoader");
34         if (gime == 0x0) {
35                 cerr << "AliITSL2GConvertPoints.C : can not get ITS loader" << endl;
36                 return 3;
37         }
38         AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");
39         if (!ITS) {
40                 cerr << "AliITSL2GConvertPoints.C : AliITS object not found on file" << endl;
41                 return 3;
42         }  // end if !ITS
43         AliITSgeom *geom = (AliITSgeom*)ITS->GetITSgeom();
44         if(!geom) {
45                 cerr << "AliITSL2GConvertPoints.C : AliITSgeom not found." << endl;
46                 return 4;
47         } // end if
48         gime->LoadRecPoints("read");
49         rl->GetEvent(nev);
50         TTree *TR = gime->TreeR();
51         if (!TR) {
52                 cerr << "AliITSL2GConvertPoints.C : Can't get the clusters tree." << endl;
53                 return 4;
54         }
55                 
56         // Tree of recpoints
57         Int_t nModules = 0;
58         TTree *TR = (TTree*)in->Get(Form("Event%d/TreeR", nev));
59         nModules = (Int_t)TR->GetEntries();
60         if (!nModules) {
61                 cout << "Empty TreeR!!!" << endl;
62                 return;
63         }
64
65         timer.Start();
66         
67         // Converts and stores the ITS points into global coordinate format
68         Int_t pos = 0;
69         AliITSRecPoint *local = 0;
70         AliITSNeuralPoint *global = 0;
71         TTree *TP = new TTree("TreeP", "Event points in global coords");
72         TP->Branch("pos", &pos, "pos/I");
73         TP->Branch("Points", "AliITSNeuralPoint", &global);
74         
75         TObjArray *localArray = 0;
76         TR->SetBranchAddress("Clusters", &localArray);
77         Int_t module, layer, i, j, count, index;
78         Double_t locPos[3], globPos[3], locErr[3][3], globErr[3][3];
79         
80         cout << geom->GetModuleIndex(1,1,1) << endl;
81         cout << geom->GetModuleIndex(2,1,1) << endl;
82         cout << geom->GetModuleIndex(3,1,1) << endl;
83         cout << geom->GetModuleIndex(4,1,1) << endl;
84         cout << geom->GetModuleIndex(5,1,1) << endl;
85         cout << geom->GetModuleIndex(6,1,1) << endl;
86         
87         for(module = 0; module < nModules; module++) {
88                 TR->GetEvent(module);
89                 count = (Int_t)localArray->GetEntriesFast();
90                 for (index = 0; index < count; index++) {
91                         local = (AliITSRecPoint*)localArray->At(index);
92                         cout << module << " - " << local->GetDetectorIndex() << endl;
93                         global = new AliITSNeuralPoint(local, geom, module, index);
94                         global->SetUser(-1);
95                         global->ConfMap(0.0, 0.0);
96                         TP->Fill();
97                         pos++;
98                 }
99         }
100
101         timer.Stop();
102         timer.Print();
103         cout << TP->GetEntries() << " points collected" << endl;
104         
105         out->cd();
106         out->mkdir(Form("Event%d", nev));
107         out->cd(Form("Event%d", nev));
108         TP->Write(Form("TreeP", nev));
109         out->Close();
110 }
111