forked from alisw/AliRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAliTOFSDigits2Digits.C
220 lines (180 loc) · 5.84 KB
/
AliTOFSDigits2Digits.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
Int_t AliTOFSDigits2Digits(Int_t numberOfEvents = 0) {
/////////////////////////////////////////////////////////////////////////
//
// Creates TOF digits from the summable digits for all event in the header file
//
// Use case:
// start root
// // load the macro
// root[0] .L AliTOFSDigits2Digits.C
// root[1] AliTOFSDigits2Digits()
//
// By default, it creates digits for all the events in the header file.
//
// If you want create digits only the firts event
// you can use the following lines:
//
// root[0] .L AliTOFSDigits2Digits.C
// root[1] AliTOFSDigits2Digits(1)
//
// Created by: F. Pierella
// Updated to the new I/O: I.Belikov (Jouri.Belikov@cern.ch)
//
// Report problems to decaro@sa.infn.it
//
/////////////////////////////////////////////////////////////////////////
Int_t rc = 0;
if (gAlice)
{
delete AliRunLoader::Instance();
delete gAlice;
gAlice = 0x0;
}
AliRunLoader* rl = AliRunLoader::Open("galice.root");
if (rl == 0x0)
{
cerr<<"Can not open session"<<endl;
rc = 1;
return rc;
}
if (rl->LoadgAlice())
{
cerr<<"Error occured while loading gAlice \n";
rc = 2;
return rc;
}
AliLoader *tofl = rl->GetLoader("TOFLoader");
if (tofl == 0x0)
{
cerr<<"Can not get the TOF Loader \n";
rc = 3;
return rc;
}
gAlice=rl->GetAliRun();
if (!gAlice)
{
cerr<<"Can't get gAlice !\n";
rc = 4;
return rc;
}
tofl->LoadSDigits("read");
tofl->LoadDigits("recreate");
Int_t totndig=0; // total number of digits
Int_t tottracks=0; // total number of tracks contributing to totndig
if (numberOfEvents==0) numberOfEvents=rl->GetNumberOfEvents();
TClonesArray *fSDigits=new TClonesArray("AliTOFSDigit", 1000);
TClonesArray *fDigits =new TClonesArray("AliTOFdigit", 1000);
TClonesArray &da=*fDigits;
for (Int_t ievent = 0; ievent < numberOfEvents; ievent++) {
rl->GetEvent(ievent);
TTree *sTree=tofl->TreeS();
if (sTree == 0)
{
cerr<<"Can't get the sdigit tree !\n";
rc = 5;
return rc;
}
TBranch *branch=sTree->GetBranch("TOF");
if (!branch)
{
cerr<<"Cant' get the branch !\n";
rc = 6;
return rc;
}
branch->SetAddress(&fSDigits);
TTree *dTree=tofl->TreeD();
if (dTree == 0) {
tofl->MakeTree("D");
dTree=tofl->TreeD();
}
branch=dTree->GetBranch("TOF");
if (!branch) dTree->Branch("TOF",&fDigits);
else branch->SetAddress(&fDigits);
Int_t nEntries = sTree->GetEntries();
for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
sTree->GetEvent(iEntry);
Int_t ndig = fSDigits->GetEntriesFast();
cout << "----------------<AliTOFSDigits2Digits>---------------- \n";
cout << "Found " << ndig << " TOF SDigits for event " << ievent << endl;
cout << "------------------------------------------------------ \n";
for (Int_t k = 0; k < ndig; k++) {
Int_t vol[5]; // location for a digit
// Get the information for this digit
AliTOFSDigit *tofsdigit = (AliTOFSDigit *)fSDigits->UncheckedAt(k);
Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots
// for current sdigit
// TOF sdigit volumes (always the same for all slots)
Int_t sector = tofsdigit->GetSector(); // range [0-17]
Int_t plate = tofsdigit->GetPlate(); // range [0- 4]
Int_t strip = tofsdigit->GetStrip(); // range [0-19]
Int_t padz = tofsdigit->GetPadz(); // range [0- 1]
Int_t padx = tofsdigit->GetPadx(); // range [0-47]
vol[0] = sector;
vol[1] = plate;
vol[2] = strip;
vol[3] = padx;
vol[4] = padz;
//--------------------- QA section ----------------------
// in the while, I perform QA
Bool_t isSDigitBad = (sector<0 || sector>17 ||
plate<0 || plate >4 ||
padz<0 || padz>1 ||
padx<0 || padx>47);
if (isSDigitBad)
{
cout << "<AliTOFSDigits2Digits> strange sdigit found \n";
rc = 7;
return rc;
}
//-------------------------------------------------------
// start loop on number of slots for current sdigit
for (Int_t islot = 0; islot < nslot; islot++) {
Float_t digit[2]; // TOF digit variables
const Int_t kMAXDIGITS = 3; // number 3 is a legacy from AliDigit object
Int_t tracknum[kMAXDIGITS]; //contributing tracks for the current slot
Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
tracknum[0]=tofsdigit->GetTrack(islot,0);
tracknum[1]=tofsdigit->GetTrack(islot,1);
tracknum[2]=tofsdigit->GetTrack(islot,2);
for (Int_t i = 0; i < kMAXDIGITS; i++) {
tottracks++;
// search for the first empty location
if(tracknum[i]==-1){
tottracks--;
break;
}
}
// adding a TOF digit for each slot
{
Int_t ndigits=da.GetEntriesFast();
new (da[ndigits]) AliTOFdigit(tracknum, vol, digit);
}
totndig++;
}
} // end loop on sdigits
fSDigits->Clear();
} // end loop on entries
dTree->Fill();
tofl->WriteDigits("OVERWRITE");
// free used memory
fDigits->Clear();
} // end loop on events
delete fSDigits;
delete fDigits;
tofl->UnloadDigits();
tofl->UnloadSDigits();
rl->UnloadHeader();
rl->UnloadgAlice();
cout << "---------------------------------------------------------- \n";
cout << "<AliTOFSDigits2Digits> Summary \n";
cout << "contributing tracks to " << totndig << " digits: " << tottracks << endl;
cout << "---------------------------------------------------------- \n";
if (gAlice)
{
delete AliRunLoader::Instance();
delete gAlice;
gAlice = 0x0;
}
return rc;
}