With Boris and Antonin:
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONHitReconstructorComponent.cxx
CommitLineData
b0201cbe 1/**************************************************************************
960d54ad 2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
b0201cbe 4 * *
960d54ad 5 * Primary Authors: *
6 * Indranil Das <indra.das@saha.ac.in> *
b0201cbe 7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
960d54ad 13 * about the suitability of this software for any purpose. It is *
b0201cbe 14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/* $Id$ */
18
6253e09b 19///
20///
21/// The HitRec Component is designed to deal the rawdata inputfiles to findout the
22/// the reconstructed hits. The output is send to the output block for further
23/// processing.
24///
25/// Author : Indranil Das ( indra.das@saha.ac.in || indra.ehep@gmail.com )
26///
b0201cbe 27
960d54ad 28#include "AliHLTMUONRecHitsBlockStruct.h"
b0201cbe 29#include "AliHLTMUONHitReconstructorComponent.h"
b12fe461 30#include "AliHLTMUONHitReconstructor.h"
960d54ad 31#include "AliHLTMUONConstants.h"
668eee9f 32#include "AliHLTMUONUtils.h"
5ff5f960 33#include "AliHLTMUONDataBlockWriter.h"
b0201cbe 34#include "AliHLTLogging.h"
35#include "AliHLTSystem.h"
36#include "AliHLTDefinitions.h"
29486e5a 37#include <cstdlib>
38#include <cerrno>
39#include <cassert>
b0201cbe 40
ee3678d3 41//STEER
42#include "AliCDBManager.h"
43#include "AliGeomManager.h"
44
45//MUON
46#include "AliMUONGeometryTransformer.h"
47#include "AliMUONCalibrationData.h"
48#include "AliMUONVCalibParam.h"
49
50//MUON/mapping
51#include "AliMpCDB.h"
52#include "AliMpPad.h"
53#include "AliMpSegmentation.h"
54#include "AliMpDDLStore.h"
55#include "AliMpDEIterator.h"
56#include "AliMpVSegmentation.h"
57#include "AliMpDEManager.h"
58#include "AliMpDetElement.h"
59
b0201cbe 60ClassImp(AliHLTMUONHitReconstructorComponent)
61
62
29486e5a 63AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() :
6253e09b 64 AliHLTProcessor(),
29486e5a 65 fHitRec(NULL),
29486e5a 66 fDDL(0),
ee3678d3 67 fIdToEntry(),
29486e5a 68 fWarnForUnexpecedBlock(false)
b0201cbe 69{
6253e09b 70 ///
71 /// Default constructor.
72 ///
b0201cbe 73}
74
960d54ad 75
b0201cbe 76AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent()
77{
6253e09b 78 ///
79 /// Default destructor.
80 ///
ee3678d3 81
82 if (fHitRec != NULL)
83 {
84 delete fHitRec;
85 }
960d54ad 86}
b0201cbe 87
960d54ad 88const char* AliHLTMUONHitReconstructorComponent::GetComponentID()
89{
6253e09b 90 ///
91 /// Inherited from AliHLTComponent. Returns the component ID.
92 ///
93
29486e5a 94 return AliHLTMUONConstants::HitReconstructorId();
b0201cbe 95}
96
b0201cbe 97
960d54ad 98void AliHLTMUONHitReconstructorComponent::GetInputDataTypes( std::vector<AliHLTComponentDataType>& list)
99{
6253e09b 100 ///
101 /// Inherited from AliHLTProcessor. Returns the list of expected input data types.
102 ///
103
29486e5a 104 list.clear();
668eee9f 105 list.push_back( AliHLTMUONConstants::DDLRawDataType() );
960d54ad 106}
b0201cbe 107
b0201cbe 108
960d54ad 109AliHLTComponentDataType AliHLTMUONHitReconstructorComponent::GetOutputDataType()
110{
6253e09b 111 ///
112 /// Inherited from AliHLTComponent. Returns the output data type.
113 ///
114
29486e5a 115 return AliHLTMUONConstants::RecHitsBlockDataType();
960d54ad 116}
b0201cbe 117
b0201cbe 118
960d54ad 119void AliHLTMUONHitReconstructorComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
120{
6253e09b 121 ///
122 /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
123 ///
124
13f09bc1 125 constBase = sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType);
29486e5a 126 inputMultiplier = 1;
960d54ad 127}
b0201cbe 128
b0201cbe 129
960d54ad 130AliHLTComponent* AliHLTMUONHitReconstructorComponent::Spawn()
131{
6253e09b 132 ///
133 /// Inherited from AliHLTComponent. Creates a new object instance.
134 ///
135
29486e5a 136 return new AliHLTMUONHitReconstructorComponent;
960d54ad 137}
b0201cbe 138
b0201cbe 139
29486e5a 140int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
960d54ad 141{
6253e09b 142 ///
143 /// Inherited from AliHLTComponent.
144 /// Parses the command line parameters and initialises the component.
145 ///
b0201cbe 146
ee3678d3 147 HLTInfo("Initialising dHLT hit reconstruction component.");
960d54ad 148
ee3678d3 149 try
150 {
151 fHitRec = new AliHLTMUONHitReconstructor();
960d54ad 152 }
ee3678d3 153 catch (const std::bad_alloc&)
b8d467da 154 {
ee3678d3 155 HLTError("Could not allocate more memory for the hit reconstructor component.");
156 return -ENOMEM;
b8d467da 157 }
960d54ad 158
ee3678d3 159 fWarnForUnexpecedBlock = false;
960d54ad 160
ee3678d3 161 const char* lutFileName = NULL;
162 const char* cdbPath = NULL;
163 Int_t run = -1;
164 bool useCDB = false;
165
166 for (int i = 0; i < argc; i++)
167 {
168 HLTDebug("argv[%d] == %s", i, argv[i]);
169
170 if (strcmp( argv[i], "-ddl" ) == 0)
171 {
172 if (argc <= i+1)
173 {
174 HLTError("The DDL number was not specified. Must be in the range [13..20].");
175 return EINVAL;
176 }
177
178 char* cpErr = NULL;
179 unsigned long num = strtoul( argv[i+1], &cpErr, 0 );
180 if (cpErr == NULL or *cpErr != '\0')
181 {
182 HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
183 return EINVAL;
184 }
185 if (num < 13 or 20 < num)
186 {
187 HLTError("The DDL number must be in the range [13..20].");
188 return EINVAL;
189 }
190 fDDL = num - 1;
191
192 i++;
193 continue;
194 } // -ddl argument
195
196 if (strcmp( argv[i], "-lut" ) == 0)
197 {
198 if (argc <= i+1)
199 {
200 HLTError("The lookup table filename was not specified.");
201 return EINVAL;
202 }
203 lutFileName = argv[i+1];
204 i++;
205 continue;
206 } // -lut argument
207
208 if (strcmp( argv[i], "-cdb" ) == 0)
209 {
210 useCDB = true;
211 continue;
212 } // -cdb argument
213
214 if (strcmp( argv[i], "-cdbpath" ) == 0)
215 {
216 if ( argc <= i+1 )
217 {
218 HLTError("The CDB path was not specified." );
219 return EINVAL;
220 }
221 cdbPath = argv[i+1];
222 useCDB = true;
223 i++;
224 continue;
225 } // -cdb argument
226
227 if (strcmp( argv[i], "-run" ) == 0)
228 {
229 if ( argc <= i+1 )
230 {
231 HLTError("The RUN number was not specified." );
232 return EINVAL;
233 }
234
235 char* cpErr = NULL;
236 run = Int_t( strtoul(argv[i+1], &cpErr, 0) );
237 if (cpErr == NULL or *cpErr != '\0')
238 {
239 HLTError("Cannot convert '%s' to a valid run number."
240 " Expected an integer value.", argv[i+1]
241 );
242 return EINVAL;
243 }
244
245 i++;
246 continue;
247 } // -run argument
248
249 if (strcmp( argv[i], "-warn_on_unexpected_block" ) == 0)
250 {
251 fWarnForUnexpecedBlock = true;
252 continue;
253 }
254
255 HLTError("Unknown option '%s'", argv[i]);
256 return EINVAL;
257
258 } // for loop
259
260 if (lutFileName == NULL) useCDB = true;
261
262 AliHLTMUONHitRecoLutRow* lookupTable;
263
264 if (useCDB)
265 {
266 if(!ReadCDB(lookupTable,cdbPath,run))
267 {
268 HLTError("Failed to read cdb, cdb cannot be read, DoInit");
269
270 if (fHitRec)
271 {
272 delete fHitRec;
273 fHitRec = NULL;
274 }
275 if(lookupTable)
276 delete []lookupTable;
277
278 return ENOENT ; /* No such file or directory */
279 }
960d54ad 280 }
ee3678d3 281 else
282 {
283 AliHLTUInt32_t lutLine;
284 if(!GetLutLine(lutFileName,fDDL,lutLine))
285 {
286 HLTError("Failed for lookuptable count the number of lines in lookuptable, DoInit");
287
288 if(fHitRec)
289 delete fHitRec;
290 return EIO;
291 }
292
293 try
294 {
295 lookupTable = new AliHLTMUONHitRecoLutRow[lutLine];
296 }
297 catch(const std::bad_alloc&)
298 {
299 HLTError("Dynamic memory allocation failed for lookuptable, DoInit");
300
301 if(fHitRec)
302 delete fHitRec;
303
304 return ENOMEM;
305 }
306
307
308 if(!ReadLookUpTable(lookupTable,lutFileName))
309 {
310 HLTError("Failed to read lut, lut cannot be read, DoInit");
311
312 if(fHitRec)
313 delete fHitRec;
314 if(lookupTable)
315 delete []lookupTable;
316
317 return ENOENT ; /* No such file or directory */
318 }
960d54ad 319 }
960d54ad 320
ee3678d3 321 if(!fHitRec->SetIdManuChannelToEntry(fIdToEntry))
322 {
323 HLTError("Failed to set fIdToEntry mapping, DoInit");
324
325 if(fHitRec)
326 delete fHitRec;
327 if(lookupTable)
328 delete []lookupTable;
329
330 fIdToEntry.clear();
331
332 return ENOENT ; /* No such file or directory */
333 }
334
335 if(!fHitRec->LoadLookUpTable(lookupTable,fDDL))
336 {
337 HLTError("Cannot Laod hitrec lookuptable , DoInit");
338
339 if(fHitRec)
340 delete fHitRec;
341 if(lookupTable)
342 delete []lookupTable;
343
344 fIdToEntry.clear();
345
346 return ENOENT;
347 }
348
349 delete [] lookupTable;
350
351 return 0;
b0201cbe 352}
353
960d54ad 354
355int AliHLTMUONHitReconstructorComponent::DoDeinit()
356{
6253e09b 357 ///
358 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
359 ///
360
ee3678d3 361 HLTInfo("Deinitialising dHLT hit reconstruction component.");
362
363 if (fHitRec != NULL)
364 {
365 delete fHitRec;
366 fHitRec = NULL;
367 }
368
369 fIdToEntry.clear();
370
371 return 0;
b0201cbe 372}
373
b0201cbe 374
960d54ad 375int AliHLTMUONHitReconstructorComponent::DoEvent(
376 const AliHLTComponentEventData& evtData,
b8d467da 377 const AliHLTComponentBlockData* blocks,
378 AliHLTComponentTriggerData& /*trigData*/,
379 AliHLTUInt8_t* outputPtr,
960d54ad 380 AliHLTUInt32_t& size,
381 std::vector<AliHLTComponentBlockData>& outputBlocks
382 )
383{
6253e09b 384 ///
385 /// Inherited from AliHLTProcessor. Processes the new event data.
386 ///
387
29486e5a 388 // Process an event
389 unsigned long totalSize = 0; // Amount of memory currently consumed in bytes.
b0201cbe 390
29486e5a 391 HLTDebug("Processing event %llu with %u input data blocks.",
392 evtData.fEventID, evtData.fBlockCnt
393 );
394
395 // Loop over all input blocks in the event
396 for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
5ff5f960 397 {
29486e5a 398#ifdef __DEBUG
399 char id[kAliHLTComponentDataTypefIDsize+1];
400 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
401 id[i] = blocks[n].fDataType.fID[i];
402 id[kAliHLTComponentDataTypefIDsize] = '\0';
403 char origin[kAliHLTComponentDataTypefOriginSize+1];
404 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
405 origin[i] = blocks[n].fDataType.fOrigin[i];
406 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
407#endif // __DEBUG
408 HLTDebug("Handling block: %u, with fDataType.fID = '%s',"
409 " fDataType.fID = '%s', fPtr = %p and fSize = %u bytes.",
410 n, static_cast<char*>(id), static_cast<char*>(origin),
411 blocks[n].fPtr, blocks[n].fSize
5ff5f960 412 );
29486e5a 413
668eee9f 414 if (blocks[n].fDataType != AliHLTMUONConstants::DDLRawDataType()
415 or not AliHLTMUONUtils::IsTrackerDDL(blocks[n].fSpecification)
416 )
29486e5a 417 {
418 // Log a message indicating that we got a data block that we
419 // do not know how to handle.
420 char id[kAliHLTComponentDataTypefIDsize+1];
421 for (int i = 0; i < kAliHLTComponentDataTypefIDsize; i++)
422 id[i] = blocks[n].fDataType.fID[i];
423 id[kAliHLTComponentDataTypefIDsize] = '\0';
424 char origin[kAliHLTComponentDataTypefOriginSize+1];
425 for (int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++)
426 origin[i] = blocks[n].fDataType.fOrigin[i];
427 origin[kAliHLTComponentDataTypefOriginSize] = '\0';
428
429 if (fWarnForUnexpecedBlock)
668eee9f 430 HLTWarning("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X",
431 static_cast<char*>(id), static_cast<char*>(origin), blocks[n].fSpecification
29486e5a 432 );
433 else
668eee9f 434 HLTDebug("Received a data block of a type we cannot handle: '%s' origin: '%s' spec: 0x%X",
435 static_cast<char*>(id), static_cast<char*>(origin), blocks[n].fSpecification
29486e5a 436 );
437
438 continue;
439 }
440
ee3678d3 441 bool ddl[22];
442 AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
443 if (not ddl[fDDL])
444 {
445 HLTWarning("Received raw data from an unexpected DDL.");
446 }
447
29486e5a 448 // Create a new output data block and initialise the header.
449 AliHLTMUONRecHitsBlockWriter block(outputPtr+totalSize, size-totalSize);
450 if (not block.InitCommonHeader())
451 {
452 HLTError("There is not enough space in the output buffer for the new data block.",
453 " We require at least %u bytes, but have %u bytes left.",
454 sizeof(AliHLTMUONRecHitsBlockWriter::HeaderType),
455 block.BufferSize()
456 );
457 break;
458 }
459
460 AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
461 AliHLTUInt32_t ddlRawDataSize = totalDDLSize - fHitRec->GetkDDLHeaderSize();
462 AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr)
463 + fHitRec->GetkDDLHeaderSize();
464 AliHLTUInt32_t nofHit = block.MaxNumberOfEntries();
465
ee3678d3 466#ifdef DEBUG
29486e5a 467 HLTDebug("=========== Dumping DDL payload buffer ==========");
468 for (AliHLTUInt32_t j = 0; j < totalDDLSize; j++)
469 HLTDebug("buffer[%d] : %x",j,buffer[j]);
470 HLTDebug("================== End of dump =================");
ee3678d3 471#endif // DEBUG
29486e5a 472
473 if (not fHitRec->Run(buffer, ddlRawDataSize, block.GetArray(), nofHit))
474 {
475 HLTError("Error while processing of hit reconstruction algorithm.");
476 size = totalSize; // Must tell the framework how much buffer space was used.
477 return EIO;
478 }
479
480 // nofHit should now contain the number of reconstructed hits actually found
481 // and filled into the output data block, so we can set this number.
482 assert( nofHit <= block.MaxNumberOfEntries() );
483 block.SetNumberOfEntries(nofHit);
484
485 HLTDebug("Number of reconstructed hits found is %d", nofHit);
486
487 // Fill a block data structure for our output block.
488 AliHLTComponentBlockData bd;
489 FillBlockData(bd);
490 bd.fPtr = outputPtr;
491 // This block's start (offset) is after all other blocks written so far.
492 bd.fOffset = totalSize;
493 bd.fSize = block.BytesUsed();
494 bd.fDataType = AliHLTMUONConstants::RecHitsBlockDataType();
495 bd.fSpecification = blocks[n].fSpecification;
496 outputBlocks.push_back(bd);
497
498 // Increase the total amount of data written so far to our output memory
499 totalSize += block.BytesUsed();
5ff5f960 500 }
29486e5a 501 // Finally we set the total size of output memory we consumed.
502 size = totalSize;
503
504 return 0;
b0201cbe 505}
506
507
ee3678d3 508bool AliHLTMUONHitReconstructorComponent::GetLutLine(
509 const char* lutFileName, AliHLTInt32_t /*iDDL*/, AliHLTUInt32_t& iLine
510 )
511{
512 // Reads LUT from CDB.
513 // TODO: combine this with ReadLookUpTable().
514
515 ifstream fin(lutFileName);
516
517 if(!fin){
518 HLTError("Failed to open file '%s' ",lutFileName);
519 return false;
520 }
521
522 string s;
523 iLine = 0;
524 while(getline(fin,s)){
525 iLine++;
526 }
527
528 fin.close();
529
530 return true;
531}
532
533
534bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable(
535 AliHLTMUONHitRecoLutRow* lookupTable, const char* lutFileName
536 )
b0201cbe 537{
6253e09b 538 ///
539 /// Read in the lookup table from a text file.
540 ///
ee3678d3 541
960d54ad 542 if (fDDL < AliHLTMUONHitReconstructor::GetkDDLOffSet() ||
ee3678d3 543 fDDL >= AliHLTMUONHitReconstructor::GetkDDLOffSet() + AliHLTMUONHitReconstructor::GetkNofDDL())
544 {
960d54ad 545 HLTError("DDL number is out of range");
546 return false;
547 }
548
ee3678d3 549 AliHLTUInt32_t lutLine;
550 if(!GetLutLine(lutFileName,fDDL,lutLine)){
551 HLTError("Failed for lookuptable count the number of lines in lookuptable, DoInit");
552
960d54ad 553 return false;
554 }
555
ee3678d3 556 int idManuChannel;
557 fIdToEntry.clear();
960d54ad 558
ee3678d3 559 FILE *fin = fopen(lutFileName,"r");
560 if(fin == NULL){
561 printf("Failed to open file %s\n",lutFileName);
562 return false;
563 }else{
564 for(AliHLTUInt32_t i=0;i<lutLine;i++){
565 fscanf(fin,"%d\t%d\t%d\t%d\t%f\t%f\t%f\t%f\t%d\t%f\t%f\t%f\t%f\t%d\t%d\n",
566 &idManuChannel,&lookupTable[i].fDetElemId,&lookupTable[i].fIX,
567 &lookupTable[i].fIY,&lookupTable[i].fRealX,
568 &lookupTable[i].fRealY,&lookupTable[i].fRealZ,
569 &lookupTable[i].fHalfPadSize,&lookupTable[i].fPlane,
570 &lookupTable[i].fPed,&lookupTable[i].fSigma,&lookupTable[i].fA0,
571 &lookupTable[i].fA1,&lookupTable[i].fThres,&lookupTable[i].fSat);
572
573 fIdToEntry[idManuChannel] = i+1;
574
575
576 }
577 }
578
960d54ad 579 fclose(fin);
ee3678d3 580
960d54ad 581 return true;
b0201cbe 582}
583
b0201cbe 584
ee3678d3 585bool AliHLTMUONHitReconstructorComponent::ReadCDB(
586 AliHLTMUONHitRecoLutRow*& lookupTable,
587 const char* cdbPath, Int_t run
588 )
b0201cbe 589{
ee3678d3 590 // Reads LUT from CDB.
591 // TODO: merge this with CreateHitRecoLookupTables.C, make this static and use in the macro for example.
592
593 vector<AliHLTMUONHitRecoLutRow> lutList;
594 lutList.clear();
595 AliHLTMUONHitRecoLutRow lut;
596 int iEntry = 0;
597
598 Bool_t warn = kTRUE;
599
600 AliCDBManager* cdbManager = AliCDBManager::Instance();
601 if (cdbPath != NULL) cdbManager->SetDefaultStorage(cdbPath);
602 if (run != -1) cdbManager->SetRun(run);
603
604 if (! AliMpCDB::LoadDDLStore(warn)){
605 HLTError("Failed to Load DDLStore specified for CDBPath '%s', and Run : '%d'",cdbPath,run);
606 return false;
607 }
608
609 AliMpSegmentation *mpSegFactory = AliMpSegmentation::Instance();
610 AliGeomManager::LoadGeometry();
611 AliMUONGeometryTransformer* chamberGeometryTransformer = new AliMUONGeometryTransformer();
612 if(! chamberGeometryTransformer->LoadGeometryData()){
613 HLTError("Failed to Load Geomerty Data ");
614 return false;
615 }
960d54ad 616
ee3678d3 617 AliMUONCalibrationData calibData(run);
618
619 int totMaxIX = -1;
620 int totMaxIY = -1;
621 Int_t chamberId;
622
623 for(Int_t iCh = 6; iCh < 10; iCh++){ // max 4
624
625 chamberId = iCh ;
626
627 AliMpDEIterator it;
628 for ( it.First(chamberId); ! it.IsDone(); it.Next() ) {
629
630 Int_t detElemId = it.CurrentDEId();
631 int iDDL = AliMpDDLStore::Instance()->GetDetElement(detElemId)->GetDdlId() + 1;
632 if(iDDL == fDDL){
633
634 for(Int_t iCath = 0 ; iCath <= 1 ; iCath++){
635
636 AliMp::CathodType cath;
637
638 if(iCath == 0)
639 cath = AliMp::kCath0 ;
640 else
641 cath = AliMp::kCath1 ;
642
643 const AliMpVSegmentation* seg = mpSegFactory->GetMpSegmentation(detElemId, cath);
644 AliMp::PlaneType plane = seg->PlaneType();
645 Int_t maxIX = seg->MaxPadIndexX();
646 Int_t maxIY = seg->MaxPadIndexY();
647 if(maxIX > totMaxIX)
648 totMaxIX = maxIX;
649 if(maxIY > totMaxIY)
650 totMaxIY = maxIY;
651
652 Int_t idManuChannel, manuId, channelId, buspatchId;
653 float padSizeX, padSizeY;
654 float halfPadSize ;
655 Double_t realX, realY, realZ;
656 Double_t localX, localY, localZ;
657 Float_t calibA0Coeff,calibA1Coeff,pedestal,sigma;
658 Int_t thresold,saturation;
659
660 // cout<<"Running for detElemId :"<<detElemId<<", and plane : "<<plane<<endl;
661 //Pad Info of a segment to print in lookuptable
662 for(Int_t iX = 0; iX<= maxIX ; iX++){
663 for(Int_t iY = 0; iY<= maxIY ; iY++){
664 if(seg->HasPad(AliMpIntPair(iX,iY))){
665 AliMpPad pad = seg->PadByIndices(AliMpIntPair(iX,iY),kFALSE);
666
667 // Getting Manu id
668 manuId = pad.GetLocation().GetFirst();
669 manuId &= 0x7FF; // 11 bits
670
671 buspatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
672
673 // Getting channel id
674 channelId = pad.GetLocation().GetSecond();
675 channelId &= 0x3F; // 6 bits
676
677 idManuChannel &= 0x0;
678 idManuChannel = (idManuChannel|buspatchId)<<11;
679 idManuChannel = (idManuChannel|manuId)<<6 ;
680 idManuChannel |= channelId ;
681
682 localX = pad.Position().X();
683 localY = pad.Position().Y();
684 localZ = 0.0;
685
686 chamberGeometryTransformer->Local2Global(detElemId,localX,localY,localZ,
687 realX,realY,realZ);
688
689 padSizeX = pad.Dimensions().X();
690 padSizeY = pad.Dimensions().Y();
691
692 calibA0Coeff = (calibData.Gains(detElemId,manuId))->ValueAsFloat(channelId,0) ;
693 calibA1Coeff = (calibData.Gains(detElemId,manuId))->ValueAsFloat(channelId,1) ;
694 thresold = (calibData.Gains(detElemId,manuId))->ValueAsInt(channelId,2) ;
695 saturation = (calibData.Gains(detElemId,manuId))->ValueAsInt(channelId,4) ;
696
697 pedestal = (calibData.Pedestals(detElemId,manuId))->ValueAsFloat(channelId,0);
698 sigma = (calibData.Pedestals(detElemId,manuId))->ValueAsFloat(channelId,1);
699
700 if(plane==0)
701 halfPadSize = padSizeX;
702 else
703 halfPadSize = padSizeY;
704
705 fIdToEntry[idManuChannel] = iEntry+1;
706
707 lut.fDetElemId = detElemId;
708 lut.fIX = iX;
709 lut.fIY = iY;
710 lut.fRealX = realX;
711 lut.fRealY = realY;
712 lut.fRealZ = realZ;
713 lut.fHalfPadSize = halfPadSize;
714 lut.fPlane = plane;
715 lut.fPed = pedestal;
716 lut.fSigma = sigma;
717 lut.fA0 = calibA0Coeff;
718 lut.fA1 = calibA1Coeff;
719 lut.fThres = thresold;
720 lut.fSat = saturation;
721
722 lutList.push_back(lut);
723 iEntry++;
724 }// HasPad Condn
725 }// iY loop
726 }// iX loop
727
728 }// iPlane
729 }// iDDL
730 } // detElemId loop
731
732 }// ichamber loop
733
734 AliHLTMUONHitRecoLutRow *temp;
735
736 try{
737 temp = new AliHLTMUONHitRecoLutRow[iEntry];
738 }
739 catch(const std::bad_alloc&){
740 HLTError("Dynamic memory allocation failed for temp");
741
960d54ad 742 return false;
743 }
744
ee3678d3 745 for(int iterm = 0; iterm < iEntry ;iterm++)
746 temp[iterm] = lutList.at(iterm);
960d54ad 747
ee3678d3 748 lookupTable = temp;
749
960d54ad 750 return true;
b0201cbe 751}