3 /**************************************************************************
4 * This file is property of and copyright by the Experimental Nuclear *
5 * Physics Group, Dep. of Physics *
6 * University of Oslo, Norway, 2006 *
8 * Author: Per Thomas Hille perthi@fys.uio.no for the ALICE DCS Project. *
9 * Contributors are mentioned in the code where appropriate. *
10 * Please report bugs to perthi@fys.uio.no *
12 * Permission to use, copy, modify and distribute this software and its *
13 * documentation strictly for non-commercial purposes is hereby granted *
14 * without fee, provided that the above copyright notice appears in all *
15 * copies and that both the copyright notice and this permission notice *
16 * appear in the supporting documentation. The authors make no claims *
17 * about the suitability of this software for any purpose. It is *
18 * provided "as is" without express or implied warranty. *
19 **************************************************************************/
22 // Mapping class fro mapping
23 // from hardware address to geometrical address
24 // Authors: Per Thomas Hille, Oystein Djuvsland
27 #include "AliHLTPHOSMapper.h"
30 #include "AliHLTPHOSCoordinate.h"
31 #include "AliPHOSRecoParam.h"
32 #include "AliAltroMapping.h"
33 #include "AliCaloAltroMapping.h"
34 #include "TObjArray.h"
37 AliHLTPHOSMapper::AliHLTPHOSMapper():
38 AliHLTCaloMapper(0,"PHOS")
39 ,fIsInitializedMapping(false)
40 ,fDDLMapInitialised(false)
44 sprintf(fFilepath, "./");
48 AliHLTPHOSMapper::~AliHLTPHOSMapper()
50 delete [] fHw2geomapPtr;
56 AliHLTPHOSMapper::InitAltroMapping(const unsigned long specification)
58 // Loads mapping between Altro addresses and geometrical addresses from file
60 // HLTError("Initialising ALTRO map");
62 if (!fDDLMapInitialised) InitDDLSpecificationMapping();
64 fDDLId = GetDDLFromSpec(specification);
65 Int_t modId = GetModuleFromSpec(specification);
67 const TObjArray* maps = AliPHOSRecoParam::GetMappings();
70 HLTError("Cannot retrieve ALTRO mappings!!");
71 fIsInitializedMapping = false;
75 AliCaloAltroMapping *map = dynamic_cast<AliCaloAltroMapping*>(maps->At(modId*fCaloConstants->GetNRCUSPERMODULE()));
79 HLTError("Cannot retrieve ALTRO mappings!!");
80 fIsInitializedMapping = false;
84 if ( modId != fModuleId )
89 int maxaddr = fCaloConstants->GetMAXHWADDRESSES();
97 delete [] fHw2geomapPtr;
99 fHw2geomapPtr = new fAltromap[maxaddr];
100 Int_t hwAdds[maxaddr];
102 for (int x = 0; x < fCaloConstants->GetNXCOLUMNSRCU(); x++)
104 for (int z = 0; z < fCaloConstants->GetNZROWSRCU(); z++)
106 for(int g = 0; g < fCaloConstants->GetNGAINS(); g++)
108 hwAdds[nCh] = map->GetHWAddress(x, z, g);
113 for ( int i=0; i < nCh; i ++ )
115 Int_t add = hwAdds[i];
116 if (map->GetSector(add) < 2)
118 fHw2geomapPtr[add].fXCol = map->GetPadRow(add);
119 fHw2geomapPtr[add].fZRow = map->GetPad(add);
120 fHw2geomapPtr[add].fGain = map->GetSector(add);
123 fIsInitializedMapping = true;
127 fIsInitializedMapping = false;
130 return fIsInitializedMapping;
135 AliHLTPHOSMapper::InitDDLSpecificationMapping()
137 fSpecificationMapPtr = new fDDLSpecificationMap[fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE()];
138 // HLTError("NUMBER OF DDLs: %d, map ptr: %d", fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE(), fSpecificationMapPtr);
139 for (Int_t ddl = 0; ddl < fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE(); ddl++)
142 fSpecificationMapPtr[ddl].fModId = ddl/fCaloConstants->GetNRCUSPERMODULE();
146 fSpecificationMapPtr[ddl].fRcuX = 0;
147 fSpecificationMapPtr[ddl].fRcuZ = 0;
152 fSpecificationMapPtr[ddl].fRcuX = 1;
153 fSpecificationMapPtr[ddl].fRcuZ = 0;
156 else if ( ddl%4 == 2)
158 fSpecificationMapPtr[ddl].fRcuX = 2;
159 fSpecificationMapPtr[ddl].fRcuZ = 0;
163 fSpecificationMapPtr[ddl].fRcuX = 3;
164 fSpecificationMapPtr[ddl].fRcuZ = 0;
167 fSpecificationMapPtr[ddl].fRcuZOffset = fCaloConstants->GetNZROWSRCU()*(fSpecificationMapPtr[ddl].fRcuZ);
168 fSpecificationMapPtr[ddl].fRcuXOffset = fCaloConstants->GetNXCOLUMNSRCU()*(fSpecificationMapPtr[ddl].fRcuX);
171 fDDLMapInitialised = true;
176 AliHLTPHOSMapper::GetIsInitializedMapping()
178 return fIsInitializedMapping;
182 AliHLTPHOSMapper::GetChannelID(Int_t hwAddress)
184 if (!fDDLMapInitialised) InitDDLSpecificationMapping();
186 // HLTError("HW add: %d -> x: %d, z: %d, gain: %d", fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset,
187 // fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset,
188 // fHw2geomapPtr[hwAddress].fGain);
189 return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset) |
191 ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset) << 6) |
192 (fHw2geomapPtr[hwAddress].fGain << 12) |
193 fSpecificationMapPtr[fDDLId].fModId << 13);
197 AliHLTPHOSMapper::GetChannelID(AliHLTUInt32_t specification, Int_t hwAddress)
200 if (!fDDLMapInitialised) InitDDLSpecificationMapping();
204 if (specification == 0x00001) index = 0;
205 else if (specification == 0x00002) index = 1;
206 else if (specification == 0x00004) index = 2;
207 else if (specification == 0x00008) index = 3;
209 else if (specification == 0x00010) index = 4;
210 else if (specification == 0x00020) index = 5;
211 else if (specification == 0x00040) index = 6;
212 else if (specification == 0x00080) index = 7;
214 else if (specification == 0x00100) index = 8;
215 else if (specification == 0x00200) index = 9;
216 else if (specification == 0x00400) index = 10;
217 else if (specification == 0x00800) index = 11;
219 else if (specification == 0x01000) index = 12;
220 else if (specification == 0x02000) index = 13;
221 else if (specification == 0x04000) index = 14;
222 else if (specification == 0x08000) index = 15;
224 else if (specification == 0x10000) index = 16;
225 else if (specification == 0x20000) index = 17;
226 else if (specification == 0x40000) index = 18;
227 else if (specification == 0x80000) index = 19;
229 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
231 // HLTError("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d", ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) | (fHw2geomapPtr[hwAddress].fGain << 12) | fSpecificationMapPtr[index].fModId << 13),
232 // fHw2geomapPtr[hwAddress].fXCol,
233 // fHw2geomapPtr[hwAddress].fZRow,
234 // fHw2geomapPtr[hwAddress].fGain);
236 /* HLTError("HW add: %d -> x: %d, z: %d, gain: %d", hwAddress, fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset,
237 fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset,
238 fHw2geomapPtr[hwAddress].fGain);*/
239 // HLTError("RCU X offset: %d", fSpecificationMapPtr[index].fRcuXOffset);
240 // HLTError("RCU Z offset: %d", fSpecificationMapPtr[index].fRcuZOffset);
241 return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |
242 ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) |
243 (fHw2geomapPtr[hwAddress].fGain << 12) |
244 fSpecificationMapPtr[index].fModId << 13);
250 // AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord)
252 // channelCoord[0] = channelId&0x3f;
253 // channelCoord[1] = (channelId >> 6)&0x3f;
254 // channelCoord[2] = (channelId >> 12)&0x1;
255 // channelCoord[3] = (channelId >> 13)&0x1f;
256 // // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
262 // AliHLTPHOSMapper::ChannelId2Coordinate(const UShort_t channelId, AliHLTPHOSCoordinate &channelCoord)
264 // channelCoord.fX = channelId&0x3f;
265 // channelCoord.fZ = (channelId >> 6)&0x3f;
266 // channelCoord.fGain = (channelId >> 12)&0x1;
267 // channelCoord.fModuleId = (channelId >> 13)&0x1f;
268 // // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
274 // AliHLTPHOSMapper::GetLocalCoord(const UShort_t channelId, Float_t* channelCoord)
276 // channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep;
277 // channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep;
278 // // printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]);
282 AliHLTPHOSMapper::GetDDLFromSpec(AliHLTUInt32_t specification)
285 if (specification == 0x00001) index = 0;
286 else if (specification == 0x00002) index = 1;
287 else if (specification == 0x00004) index = 2;
288 else if (specification == 0x00008) index = 3;
290 else if (specification == 0x00010) index = 4;
291 else if (specification == 0x00020) index = 5;
292 else if (specification == 0x00040) index = 6;
293 else if (specification == 0x00080) index = 7;
295 else if (specification == 0x00100) index = 8;
296 else if (specification == 0x00200) index = 9;
297 else if (specification == 0x00400) index = 10;
298 else if (specification == 0x00800) index = 11;
300 else if (specification == 0x01000) index = 12;
301 else if (specification == 0x02000) index = 13;
302 else if (specification == 0x04000) index = 14;
303 else if (specification == 0x08000) index = 15;
305 else if (specification == 0x10000) index = 16;
306 else if (specification == 0x20000) index = 17;
307 else if (specification == 0x40000) index = 18;
308 else if (specification == 0x80000) index = 19;
310 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
316 AliHLTPHOSMapper::GetModuleFromSpec(AliHLTUInt32_t specification)
320 if (specification & 0xf) module = 0;
321 else if ((specification >> 4) & 0xf) module = 1;
322 else if ((specification >> 8) & 0xf) module = 2;
323 else if ((specification >> 12) & 0xf) module = 3;
324 else if ((specification >> 16) & 0xf) module = 4;
326 else HLTError("Specification 0x%X not consistent with single module in PHOS", specification);