New macro, import ITS hits by layer.
[u/mrichter/AliRoot.git] / MUON / MUONGenerateBusPatch.C
CommitLineData
36903978 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16
17void MUONGenerateBusPatch()
18{
19 // Generates buspatch id and DDL id for given detection element id
0a69c1eb 20 // station 1 & 2 assuming 24 buspatches per quadrant
36903978 21 // station345, reading from DetElemIdToSlatType.dat file and calculates
22 // the number of bus patches per slat (and also number of Translator and Bridge Boards).
23 // Generates an output file DetElemIdToBusPatch.dat.out, preserve from overwriting
24 // (Ch. Finck, July 05)
f2bc136f 25 // (Nov. 05, added DDL)
42c7b335 26 // (June 06, correction for St123)
f2bc136f 27 // (Feb. 07, add 1st manu list for St12 (starting on NB !) and new ddl sharing for station 3)
36903978 28
6e96542a 29
36903978 30 TString dirPath2 = gSystem->Getenv("ALICE_ROOT");
31 dirPath2 += "/MUON/mapping/data/";
32
33 TString dirPath1 = dirPath2 + "station345/";
34
35 TString infile = dirPath1 + "DetElemIdToSlatType.dat";
36 TString outfile = dirPath2 + "DetElemIdToBusPatch.dat.out";
37
38 ifstream in(infile, ios::in);
39 ofstream out(outfile, ios::out);
40 char line[80];
41 char nameSlat[82];
42 Int_t idDE;
43 Int_t i;
44 Int_t cursor = 0;
45 Int_t begin[800];
46 Int_t end[800];
47 Int_t nbBusPatch;
48 Int_t listDE[800];
49 Int_t nbTB = 0;
50 Int_t nbBB = 0;
51 Int_t idSt12[] = {100, 101, 102, 103,
52 200, 201, 202, 203,
53 300, 301, 302, 303,
54 400, 401, 402, 403};
55
f2bc136f 56 Char_t manuListSt1[]
57 = " 1,27,53,79,105,131,157,183,201,214,224,232,1025,1051,1077,1103,1129,1155,1181,1207,1225,1238,1249,1257";
58
59 Char_t manuListSt2[]
60 = " 1,27,53,79,105,131,157,183,201,214,226,246,1025,1051,1077,1103,1129,1155,1181,1207,1225,1238,1251,1269";
61
62 Int_t idCh5swp1 = 5; // 1/4 chamber for DDL on horizontal
63 Int_t idCh5swp2 = 10; // 1/4 chamber for DDL on horizontal
64 Int_t idCh5swp3 = 14; // 1/4 chamber for DDL on horizontal
65
66 Int_t idCh6swp1 = 5; // 1/4 chamber for DDL on horizontal
67 Int_t idCh6swp2 = 9; // 1/4 chamber for DDL on horizontal
68 Int_t idCh6swp3 = 14; // 1/4 chamber for DDL on horizontal
42c7b335 69
36903978 70 Int_t idSt45swp1 = 7; // half chamber for DDL in vertical cutting twice the official numbering
71 Int_t idSt45swp2 = 20;
72
73 Int_t iDDL = 0;
74 // station 1 & 2
0a69c1eb 75 nbBusPatch = 24;
f2bc136f 76 Int_t nbHalfBusPatch = nbBusPatch/2;
36903978 77 cout << "#DE BusPatch DDL SlatName" << endl;
f2bc136f 78 out << "#DE BusPatch DDL 1st manu in buspatch" << endl;
36903978 79
80 for (Int_t j = 0; j < 16; j++) {
81
82 idDE = idSt12[j];
83 if (idDE % 100 == 0) {
42c7b335 84 iDDL++;
6e96542a 85 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
36903978 86 cout << "# Chamber " << idDE/100 << endl;
87 out << "# Chamber " << idDE/100 << endl;
88 }
42c7b335 89 if (idDE % 100 == 1) {
90 iDDL++;
6e96542a 91 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 92 }
f2bc136f 93
42c7b335 94 if (idDE % 100 == 3) {
95 iDDL--;
6e96542a 96 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1) + nbBusPatch;
42c7b335 97 }
f2bc136f 98
36903978 99 end[cursor] = begin[cursor] + nbBusPatch - 1;
100 begin[++cursor] = end[cursor] + 1;
101
f2bc136f 102 cout << idDE << " " << begin[cursor-1] + nbHalfBusPatch << "-" <<end[cursor-1] << ";" <<
103 begin[cursor-1] << "-" << end[cursor-1] - nbHalfBusPatch << " " << iDDL-1 << endl;
104
105 if (idDE < 300 )
106 out << idDE << " " << begin[cursor-1] + nbHalfBusPatch << "-" <<end[cursor-1] << ";" <<
107 begin[cursor-1] << "-" << end[cursor-1] - nbHalfBusPatch << " " << iDDL-1 <<
108 manuListSt1 << endl;
109 else
110 out << idDE << " " << begin[cursor-1] + nbHalfBusPatch << "-" <<end[cursor-1] << ";" <<
111 begin[cursor-1] << "-" << end[cursor-1] - nbHalfBusPatch << " " << iDDL-1 <<
112 manuListSt2 << endl;
42c7b335 113 if (idDE % 100 == 3) iDDL++;
114
36903978 115 }
116
117 // station 345
118 nbBusPatch = 0;
42c7b335 119 Int_t nbBusSt3Tot1 = 0;
120 Int_t nbBusSt3Tot2 = 0;
121 Int_t nbBusSt3Tot3 = 0;
122 Int_t nbBusSt3Tot4 = 0;
123
124 Int_t nbBusSt3Swap1 = 0;
125 Int_t nbBusSt3Swap2 = 0;
126 Int_t nbBusSt3Swap3 = 0;
127 Int_t nbBusSt3Swap4 = 0;
128
129 Int_t iDDLSt3Swap1 = 0;
130 Int_t iDDLSt3Swap2 = 0;
131 Int_t iDDLSt3Swap3 = 0;
132 Int_t iDDLSt3Swap4 = 0;
133
134 Int_t nbBusSt45Tot = 0;
135 Int_t nbBusSt45Swap = 0;
136
f2bc136f 137 Int_t nbBus500 = 4; // number of buspatch in DE 500
138 Int_t nbDDL500 = 11; // DDL number for DE 500
139 Int_t offsetBus500 = 13; // number of buspatches in DDL 11 before DE 500
140
42c7b335 141 // reads from file
36903978 142 while ( in.getline(line,80) ) {
143
144 if ( line[0] == '#' || line[0] == '\0' ) continue;
145 i = 0;
146 sscanf(line, "%d %s", &idDE, nameSlat);
147
148 // number of PCB's
149 while(nameSlat[i] < '4' && nameSlat[i] !='0') i++;
150 Int_t len = strlen(nameSlat);
151
152 // number of buspatch
153 if (i == 2 || i == 3)
154 nbBusPatch = 2;
155 else
156 nbBusPatch = 4;
157
158 // calculate the number of TB & BB
159 // R1: 2 bridges more per PCB
160 // R2 & R3: 1 translator more per PCB
161 if (i == 2) nbBB += 2;
162 if (i == 3) nbBB += 4;
163 if (i == 4) nbBB += 4;
164 if (i == 5) nbBB += 6;
165 if (i == 6) nbBB += 8;
166
167 nbTB += nbBusPatch;
08ce37ff 168 if (nameSlat[len-1] == '1') {
42c7b335 169 nbTB += 2;
170 nbBusPatch+=2;
08ce37ff 171 }
0a69c1eb 172 if (nameSlat[len-1] == '2' || nameSlat[len-1] == '3') {
36903978 173 nbTB += 1;
0a69c1eb 174 nbBusPatch++;
175 }
42c7b335 176
177 // station 3
178 // for buspatch length reasons, one ddl connects one 1/4 of two chambers
179 // really messy isn't it ?
f2bc136f 180 // much more with the new DDL sharing for station 3
42c7b335 181
182 if (idDE < 700 ) {
183
f2bc136f 184 if (idDE == 501) {
42c7b335 185 iDDL++;
6e96542a 186 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 187 nbBusSt3Tot1 = 0;
188
189 }
190 if (idDE % 100 == 0) {
191 cout << "# Chamber " << idDE/100 << endl;
192 out << "# Chamber " << idDE/100 << endl;
193 }
194
f2bc136f 195 // taking into account that idDE = 500 is connected to ddl = 11;
196 if (idDE == 500) {
197 cout << idDE << " " << AliMpBusPatch::GetGlobalBusID(offsetBus500, nbDDL500)<<"-"
198 << AliMpBusPatch::GetGlobalBusID(offsetBus500, nbDDL500) + nbBus500 -1
199 << " " << nbDDL500 << " " <<nameSlat <<endl;
200
201 out << idDE << " " << AliMpBusPatch::GetGlobalBusID(offsetBus500, nbDDL500)<<"-"
202 << AliMpBusPatch::GetGlobalBusID(offsetBus500, nbDDL500) + nbBus500 -1
203 << " " << nbDDL500 <<endl;
204 continue;
205 }
42c7b335 206 nbBusSt3Tot1 += nbBusPatch;
207
208 // second 1/4 for chamber 5
f2bc136f 209 if (idDE == 500+idCh5swp1) {
42c7b335 210 iDDLSt3Swap1 = iDDL++;
6e96542a 211 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 212 nbBusSt3Swap1 = nbBusSt3Tot1 - nbBusPatch;
213 nbBusSt3Tot1 = 0;
214 nbBusSt3Tot2 = 0;
215 }
216
217 // first 1/4 chamber 6
218 if (idDE == 600) {
219 iDDL = iDDLSt3Swap1;
6e96542a 220 begin[cursor] = AliMpBusPatch::GetGlobalBusID(nbBusSt3Swap1, iDDL-1);
42c7b335 221 }
222 // third 1/4 for chamber 5
f2bc136f 223 if (idDE == 500+idCh5swp2) {
42c7b335 224 iDDL = iDDLSt3Swap1+1;
225 iDDLSt3Swap2 = iDDL++;
6e96542a 226 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 227 nbBusSt3Swap2 = nbBusSt3Tot2;
228 nbBusSt3Tot2 = 0;
229 nbBusSt3Tot3 = 0;
230 }
231 nbBusSt3Tot2 += nbBusPatch;
232
233 // second 1/4 chamber 6
f2bc136f 234 if (idDE == 600 +idCh6swp1) {
42c7b335 235 iDDL = iDDLSt3Swap2;
6e96542a 236 begin[cursor] = AliMpBusPatch::GetGlobalBusID(nbBusSt3Swap2, iDDL-1);
42c7b335 237 }
238
239 // fourth 1/4 chamber 5
f2bc136f 240 if (idDE == 500+idCh5swp3) {
42c7b335 241 iDDL = iDDLSt3Swap2+1;
242 iDDLSt3Swap3 = iDDL++;
6e96542a 243 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 244 nbBusSt3Swap3 = nbBusSt3Tot3;
245 nbBusSt3Tot2 = 0;
246 nbBusSt3Tot3 = 0;
247 nbBusSt3Tot4 = 0;
248 }
249 nbBusSt3Tot3 += nbBusPatch;
250
251 //third 1/4 chamber 6
252 if (idDE == 600)
253 nbBusSt3Swap4 = nbBusSt3Tot4;
254
f2bc136f 255 if (idDE == 600 +idCh6swp2) {
42c7b335 256 iDDL = iDDLSt3Swap3;
6e96542a 257 begin[cursor] = AliMpBusPatch::GetGlobalBusID(nbBusSt3Swap3, iDDL-1);
42c7b335 258 nbBusSt3Tot4 += nbBusPatch;
259 }
260 nbBusSt3Tot4 += nbBusPatch;
261
262 // fourth 1/4 chamber 6
f2bc136f 263 if (idDE == 600 +idCh6swp3) {
42c7b335 264 iDDL = iDDLSt3Swap3+1;
f2bc136f 265 begin[cursor] = AliMpBusPatch::GetGlobalBusID(nbBusSt3Swap4 + nbBus500, iDDL-1);
42c7b335 266 }
267
268 end[cursor] = begin[cursor] + nbBusPatch - 1;
269 begin[++cursor] = end[cursor] + 1;
270
271 cout << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
272 out << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] <<" " << iDDL-1 <<endl;
273 }
274
275 // station 4 & 5
276 // back to normal one ddl connects one 1/2 chamber
277 // finally !
278 if (idDE == 700) {
279 iDDL = ((idDE-1)/100)*2;
280 }
281 if (idDE >= 700) {
282
36903978 283 if (idDE % 100 == 0) {
42c7b335 284 nbBusSt45Tot = 0;
36903978 285 iDDL++;
286 if (idDE >=800)
287 iDDL++;
6e96542a 288 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
36903978 289 cout << "# Chamber " << idDE/100 << endl;
290 out << "# Chamber " << idDE/100 << endl;
291 }
36903978 292
42c7b335 293 nbBusSt45Tot += nbBusPatch;
36903978 294
42c7b335 295 if (idDE == 700+idSt45swp1 || idDE == 800+idSt45swp1 || idDE == 900+idSt45swp1 || idDE == 1000+idSt45swp1 ) {
296 iDDL++;
6e96542a 297 begin[cursor] = AliMpBusPatch::GetGlobalBusID(0, iDDL-1);
42c7b335 298 nbBusSt45Swap = nbBusSt45Tot - nbBusPatch;
299 nbBusSt45Tot = 0;
300 }
301 if (idDE == 700+idSt45swp2 || idDE == 800+idSt45swp2 || idDE == 900+idSt45swp2 || idDE == 1000+idSt45swp2 ) {
36903978 302 iDDL--;
6e96542a 303 begin[cursor] = AliMpBusPatch::GetGlobalBusID(nbBusSt45Swap, iDDL-1);
42c7b335 304 }
305 end[cursor] = begin[cursor] + nbBusPatch - 1;
306 begin[++cursor] = end[cursor] + 1;
36903978 307
42c7b335 308 cout << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] << " " << iDDL-1 << " " <<nameSlat <<endl;
309 out << idDE << " " << begin[cursor-1]<<"-"<<end[cursor-1] <<" " << iDDL-1 <<endl;
310 }
36903978 311
36903978 312 }
313 printf(" Slat: number of TB %d and BB %d\n", nbTB, nbBB);
314 in.close();
315 out.close();
316}