3 /** \class AliHLTTPCDisplayMain
5 //_____________________________________________________________
6 // AliHLTTPCDisplayMain
8 // Display class for the HLT events.
11 // Author: Jochen Thaeder <mailto:thaeder@kip.uni-heidelberg.de>
12 //*-- Copyright © ALICE HLT Group
17 #if defined(HAVE_HOMERREADER)
18 #include "HOMERReader.h"
19 #endif // defined(HAVE_HOMERREADER)
21 #include "AliHLTTPCDisplayMain.h"
22 #include "AliHLTTPCDisplayCharge.h"
23 #include "AliHLTTPCDisplayPadRow.h"
24 #include "AliHLTTPCDisplayPad.h"
25 #include "AliHLTTPCDisplay3D.h"
26 #include "AliHLTTPCDisplayResiduals.h"
27 #include "AliHLTTPCDisplayFront.h"
29 #include "AliHLTStdIncludes.h"
30 #include "AliHLTTPCDefinitions.h"
31 #include "AliHLTDataTypes.h"
32 #include "AliHLTTPCSpacePointData.h"
33 #include "AliHLTTPCClusterDataFormat.h"
34 #include "AliHLTTPCTrackletDataFormat.h"
35 #include "AliHLTTPCDigitReader.h"
36 #include "AliHLT_C_Component_WrapperInterface.h"
37 #include "AliHLTTPCLogging.h"
39 #include "AliHLTTPCTransform.h"
40 #include "AliHLTTPCTrack.h"
41 #include "AliHLTTPCTrackArray.h"
42 #include "AliHLTTPCMemHandler.h"
43 #include "AliHLTTPCDigitReaderPacked.h"
46 #include <TClonesArray.h>
48 #include <AliSimDigits.h>
49 #include <AliTPCParam.h>
56 ClassImp(AliHLTTPCDisplayMain)
58 //____________________________________________________________________________________________________
59 AliHLTTPCDisplayMain::AliHLTTPCDisplayMain(void* pt2GUI, void (*pt2Function)(void*, Int_t)) {
63 AliHLTTPCTransform::SetBField( 0.8 );
67 fPadCallback = pt2Function;
71 fDisplayCharge = NULL;
72 fDisplayPadRow = NULL;
75 fDisplayResiduals = NULL;
82 fCanvasResiduals = NULL;
85 fCanvasQ_Track = NULL;
90 fExistsRawData = kFALSE;
91 fExistsClusterData = kFALSE;
92 fExistsTrackData = kFALSE;
94 AliHLTTPCTransform::SetBField(0.4);
96 memset(fClusters,0,36*6*sizeof(AliHLTTPCSpacePointData*));
97 memset(fNcl, 0, 36*6*sizeof(UInt_t));
104 fSwitch3DCluster = kFALSE;
105 fSwitch3DTracks = kFALSE;
106 fSwitch3DPadRow = kFALSE;
107 fSwitch3DGeometry = kTRUE;
111 // fPtThreshold = 0.;
120 fNPads = AliHLTTPCTransform::GetNPads(0);
125 fAllTimebins = kTRUE;
126 fSplitPadRow = kFALSE;
130 fSelectTrackSlice = 0;
131 fSelectTrackSwitch = kFALSE;
144 fTrackParam.kappa = 0.;
145 fTrackParam.nHits = 0;
146 fTrackParam.charge = 0;
147 fTrackParam.radius = 0.;
148 fTrackParam.slice = 0;
149 fTrackParam.phi0 = 0.;
150 fTrackParam.psi = 0.;
151 fTrackParam.lambda = 0.;
154 fTrackParam.bfield = 0.;
158 //____________________________________________________________________________________________________
159 AliHLTTPCDisplayMain::~AliHLTTPCDisplayMain() {
161 if ( fTracks ) delete fTracks;
164 #if defined(HAVE_HOMERREADER)
165 HOMERReader* reader= (HOMERReader*) fReader;
170 #endif // defined(HAVE_HOMERREADER)
172 if (fDisplayResiduals)
173 delete fDisplayResiduals;
174 fDisplayResiduals = NULL;
185 delete fDisplayPadRow;
186 fDisplayPadRow = NULL;
189 delete fDisplayFront;
190 fDisplayFront = NULL;
193 delete fDisplayCharge;
194 fDisplayCharge = NULL;
197 //____________________________________________________________________________________________________
198 Int_t AliHLTTPCDisplayMain::Connect( unsigned int cnt, const char** hostnames, unsigned short* ports, Char_t *gfile){
200 #if defined(HAVE_HOMERREADER)
201 // -- input datatypes , reverse
202 Char_t* spptID="SRETSULC";
203 Char_t* trkID = "SGESKART";
204 Char_t* padrowID = "KPWR_LDD";
210 HOMERReader* reader = new HOMERReader( cnt, (const char**) hostnames, ports );
212 ret=reader->GetConnectionStatus();
215 Int_t ndx = reader->GetErrorConnectionNdx();
216 if ( ndx < (Int_t) cnt) printf( "Error establishing connection to TCP source %s:%hu: %s (%d)\n", hostnames[ndx], ports[ndx], strerror(ret), ret );
217 else printf( "Error establishing connection to unknown source with index %d: %s (%d)\n",ndx, strerror(ret), ret );
224 //cout << "TRY = " << tries << " || " ;
227 Int_t ret1 = reader->ReadNextEvent();
229 Int_t ndx = reader->GetErrorConnectionNdx();
230 printf( "Error reading event from source %d: %s (%d)\n", ndx, strerror(ret1), ret1 );
236 unsigned long blockCnt = reader->GetBlockCnt(); // ####
238 printf( "Event 0x%016LX (%Lu) with %lu blocks\n", (ULong64_t)reader->GetEventID(), (ULong64_t)reader->GetEventID(), blockCnt );
246 fReader = (void*) reader;
248 // Switch on the Display parts according what data types are present
249 for ( unsigned long i = 0; i < blockCnt; i++ ) {
251 memset( tmp1, 0, 9 );
253 ULong64_t* tmp12 = (ULong64_t*)tmp11;
254 *tmp12 = reader->GetBlockDataType( i );
255 if (!strcmp(tmp1,padrowID)) fExistsRawData = kTRUE;
256 if (!strcmp(tmp1,spptID)) fExistsClusterData = kTRUE;
257 if (!strcmp(tmp1,trkID)) fExistsTrackData = kTRUE;
264 // Initialize TPC Display Classes -- IMPORTANT... don't change the order of them
265 fDisplay3D = new AliHLTTPCDisplay3D(this, gfile);
267 if (ExistsRawData()){
268 fDisplayPadRow = new AliHLTTPCDisplayPadRow(this);
269 fDisplayPad = new AliHLTTPCDisplayPad(this);
270 fDisplayFront = new AliHLTTPCDisplayFront(this);
273 if (ExistsClusterData()){
274 fDisplayCharge = new AliHLTTPCDisplayCharge(this);
277 if (ExistsTrackData() && ExistsClusterData() ){
278 fDisplayResiduals = new AliHLTTPCDisplayResiduals(this);
283 HLTFatal("HOMER raeder not available");
284 #endif // defined(HAVE_HOMERREADER)
287 //____________________________________________________________________________________________________
288 void AliHLTTPCDisplayMain::ReadData(Bool_t nextSwitch){
289 #if defined(HAVE_HOMERREADER)
290 // READ CLUSTER and TRACK data
291 HOMERReader* reader = (HOMERReader*)fReader;
293 for(Int_t ii=0;ii<36;ii++) fTracksPerSlice[ii] = 0;
295 // -- input datatypes , reverse
296 Char_t* spptID="SRETSULC";
297 Char_t* trkID = "SGESKART";
303 ret = reader->ReadNextEvent();
306 Int_t ndx = reader->GetErrorConnectionNdx();
307 printf( "------------ TRY AGAIN --------------->Error reading event from source %d: %s (%d)\n", ndx, strerror(ret), ret );
314 ULong_t blockCnt = reader->GetBlockCnt();
316 printf( "Event 0x%016LX (%Lu) with %lu blocks\n", (ULong64_t)reader->GetEventID(), (ULong64_t)reader->GetEventID(), blockCnt );
318 for ( ULong_t i = 0; i < blockCnt; i++ ) {
319 Char_t tmp1[9], tmp2[5];
320 memset( tmp1, 0, 9 );
321 memset( tmp2, 0, 5 );
323 ULong64_t* tmp12 = (ULong64_t*)tmp11;
324 *tmp12 = reader->GetBlockDataType( i );
326 ULong_t* tmp22 = (ULong_t*)tmp21;
327 *tmp22 = reader->GetBlockDataOrigin( i );
329 printf( "Block %lu length: %lu - type: %s - origin: %s\n",i, reader->GetBlockDataLength( i ), tmp1, tmp2 );
333 //--------------------------------------------------------------------------------------------
335 //--------------------------------------------------------------------------------------------
336 blk = reader->FindBlockNdx( spptID, " CPT",0xFFFFFFFF );
338 while ( blk != ~(ULong_t)0 ) {
340 printf( "Found clusters block %lu\n", blk );
342 const AliHLTTPCClusterData* clusterData = (const AliHLTTPCClusterData*)reader->GetBlockData( blk );
343 if ( !clusterData ) {
345 printf( "No track data for block %lu\n", blk );
350 ULong_t spec = reader->GetBlockDataSpec( blk );
351 Int_t patch = AliHLTTPCDefinitions::GetMinPatchNr( spec );
352 Int_t slice = AliHLTTPCDefinitions::GetMinSliceNr( spec );
354 printf( "%lu Clusters found for slice %u - patch %u\n", clusterData->fSpacePointCnt, slice, patch );
356 void* tmp30 = (void*)clusterData;
357 Byte_t* tmp31 = (Byte_t*)tmp30;
359 offset = sizeof(clusterData->fSpacePointCnt);
360 if ( offset <= reader->GetBlockTypeAlignment( blk, 1 ) ) offset = reader->GetBlockTypeAlignment( blk, 1 );
363 AliHLTTPCSpacePointData* tmp32 = (AliHLTTPCSpacePointData*)tmp30;
365 SetupCluster( slice, patch, clusterData->fSpacePointCnt, tmp32 );
367 blk = reader->FindBlockNdx( spptID, " CPT", 0xFFFFFFFF, blk+1 );
370 //--------------------------------------------------------------------------------------------
372 //--------------------------------------------------------------------------------------------
373 if ( fTracks ) delete fTracks;
374 fTracks = new AliHLTTPCTrackArray;
376 blk = reader->FindBlockNdx( trkID, " CPT", 0xFFFFFFFF );
378 while ( blk != ~(ULong_t)0 ) {
380 printf( "Found tracks in block %lu\n", blk );
382 const AliHLTTPCTrackletData* trackData = (const AliHLTTPCTrackletData*)reader->GetBlockData( blk );
385 printf( "No track data for block %lu\n", blk );
390 ULong_t spec = reader->GetBlockDataSpec( blk );
391 Int_t slice = AliHLTTPCDefinitions::GetMinSliceNr( spec );
393 Int_t patchmin = AliHLTTPCDefinitions::GetMinPatchNr( spec );
394 Int_t patchmax = AliHLTTPCDefinitions::GetMaxPatchNr( spec );
396 printf( "%lu tracks found for slice %u - patch %u-%u\n", trackData->fTrackletCnt, slice, patchmin, patchmax );
398 fTracksPerSlice[slice] = trackData->fTrackletCnt; // Fill number if tracks per slice
400 AliHLTTPCTrackSegmentData* tmp42 = (AliHLTTPCTrackSegmentData*) &(trackData->fTracklets[0]);
401 fTracks->FillTracks( trackData->fTrackletCnt, tmp42, slice );
403 blk = reader->FindBlockNdx( trkID, " CPT", 0xFFFFFFFF, blk+1 );
408 HLTFatal("HOMER raeder not available");
409 #endif // defined(HAVE_HOMERREADER)
412 //____________________________________________________________________________________________________
413 void AliHLTTPCDisplayMain::DisplayEvent(){
414 #if defined(HAVE_HOMERREADER)
415 HOMERReader* reader = (HOMERReader*)fReader;
417 //--------------------------------------------------------------------------------------------
418 // READ RAW DATA for PADROW/PAD HISTOGRAM
419 //--------------------------------------------------------------------------------------------
420 if ( ExistsRawData() ){
421 fDisplayPadRow->Reset();
422 fDisplayPad->Reset();
423 fDisplayFront->Reset();
425 char* rawID = "KPWR_LDD";
426 Int_t padrowpatch = AliHLTTPCTransform::GetPatch(fPadRow);
427 Int_t maxpadrowpatch = padrowpatch;
429 if (fPadRow == 30 || fPadRow == 90 || fPadRow == 139) maxpadrowpatch++;
431 for (Int_t patch=0; patch < 6; patch++){
433 AliHLTUInt32_t rawSpec = AliHLTTPCDefinitions::EncodeDataSpecification( (AliHLTUInt8_t) fSlicePadRow, (AliHLTUInt8_t) fSlicePadRow,
434 (AliHLTUInt8_t) patch,(AliHLTUInt8_t) patch );
435 // READ RAW DATA BLOCK
436 blk = reader->FindBlockNdx( rawID, " CPT", rawSpec );
438 if ( ~(unsigned long)0 != blk ){
440 printf( "Raw Data found for slice %u/patch %u\n", fSlicePadRow, patch );
442 unsigned long rawDataBlock = (unsigned long) reader->GetBlockData( blk );
443 unsigned long rawDataLen = reader->GetBlockDataLength( blk );
445 fDisplayFront->Fill(patch, rawDataBlock, rawDataLen);
447 if (patch == padrowpatch || patch == maxpadrowpatch ) {
448 fDisplayPadRow->Fill(patch, rawDataBlock, rawDataLen);
449 fDisplayPad->Fill(patch, rawDataBlock, rawDataLen);
455 fDisplayPadRow->Draw();
456 fDisplayFront->Draw();
459 //--------------------------------------------------------------------------------------------
461 //--------------------------------------------------------------------------------------------
462 if ( ExistsClusterData() && ExistsTrackData() ){
463 fDisplayResiduals->Reset();
464 fDisplayResiduals->Fill();
465 fDisplayResiduals->Draw();
468 //--------------------------------------------------------------------------------------------
470 //--------------------------------------------------------------------------------------------
471 if ( ExistsClusterData() ){
472 fDisplayCharge->Reset();
473 fDisplayCharge->Fill();
474 fDisplayCharge->Draw();
477 //--------------------------------------------------------------------------------------------
479 //--------------------------------------------------------------------------------------------
481 // TAKE CARE !!! EXISTSxxxData() HANDLING of 3D will be done IN this class !!!
484 HLTFatal("HOMER raeder not available");
485 #endif // defined(HAVE_HOMERREADER)
489 //____________________________________________________________________________________________________
490 void AliHLTTPCDisplayMain::SaveHistograms(){
491 // Save histograms as eps
492 fDisplayCharge->Save();
493 fDisplayPadRow->Save();
496 fDisplayResiduals->Save();
497 fDisplayFront->Save();
498 fDisplayCharge->Save();
501 //----------------------------------------------------------------------------------------------------
503 //____________________________________________________________________________________________________
504 void AliHLTTPCDisplayMain::SetupCluster(Int_t slice, Int_t patch, UInt_t nofClusters, AliHLTTPCSpacePointData* data) {
506 if (data && slice>=0 && slice<36 && patch>=0 && patch<AliHLTTPCTransform::GetNPatches()) {
507 if (fClusters[slice][patch]!=NULL) {
508 delete(fClusters[slice][patch]);
509 fClusters[slice][patch]=NULL;
511 Int_t arraysize=nofClusters*sizeof(AliHLTTPCSpacePointData);
512 fClusters[slice][patch] = (AliHLTTPCSpacePointData*)new Byte_t[arraysize];
513 if (fClusters[slice][patch]) {
514 memcpy(fClusters[slice][patch], data, arraysize);
515 fNcl[slice][patch]=nofClusters;
517 fNcl[slice][patch]=nofClusters;
518 LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::SetupCluster","memory allocation") << "memory allocation failed "<<ENDLOG;
520 } else LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::SetupCluster","argument check") << "invalid argument "<<ENDLOG;
523 //____________________________________________________________________________________________________
524 void AliHLTTPCDisplayMain::SetupTracks() {
527 Int_t ntracks = fTracks->GetNTracks();
529 for(Int_t j=0; j<ntracks; j++) {
530 AliHLTTPCTrack *gtrack = fTracks->GetCheckedTrack(j);
531 if(!gtrack) continue;
533 Int_t nHits = gtrack->GetNHits();
534 UInt_t *hitnum = gtrack->GetHitNumbers();
536 for(Int_t h=0; h<nHits; h++){
539 Int_t slice = (id>>25) & 0x7f;
540 Int_t patch = (id>>22) & 0x7;
541 UInt_t pos = id&0x3fffff;
543 AliHLTTPCSpacePointData *points = fClusters[slice][patch];
546 LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplayMain::SetupTracks","Clusterarray")
547 <<"No points at slice "<<slice<<" patch "<<patch<<" pos "<<pos<<ENDLOG;
551 if(pos>=fNcl[slice][patch]) {
552 LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplayMain::SetupTracks","Clusterarray")
553 <<"Pos is too large: pos "<<pos <<" ncl "<<fNcl[slice][patch]<<ENDLOG;
556 points[pos].fUsed = kTRUE;
557 points[pos].fTrackN = j;
562 //____________________________________________________________________________________________________
563 void AliHLTTPCDisplayMain::SetSliceArray() {
565 Int_t minSlice = fMinSlice;
566 Int_t maxSlice = fMaxSlice;
569 for (slice=0;slice< 36;slice++){
570 fSliceArray[slice] = kFALSE;
573 // Single Slice, or Range
574 if (minSlice > maxSlice) maxSlice += 17;
576 for (slice=minSlice;slice<=maxSlice;slice++){
577 realslice = slice % 18;
578 fSliceArray[realslice] = kTRUE;
579 fSliceArray[realslice+18] = kTRUE;
584 minSlice = fMinSlice + 9;
585 maxSlice = fMaxSlice + 9;
587 if (minSlice > maxSlice) maxSlice += 17;
589 for (slice=minSlice;slice<=maxSlice;slice++){
590 realslice = slice % 18;
591 fSliceArray[realslice] = kTRUE;
592 fSliceArray[realslice+18] = kTRUE;
597 //----------------------------------------------------------------------------------------------------
599 //____________________________________________________________________________________________________
600 Int_t AliHLTTPCDisplayMain::GetGlobalTrack(Int_t slice){
601 // get global track out of the "selectTrack" parameters
602 Int_t currenttrack= -1;
603 Int_t trackcounter = 0;
604 Int_t ntracks = fTracks->GetNTracks();
606 if ( slice == fSelectTrackSlice) {
607 for(Int_t j=0; j<ntracks; j++) {
609 AliHLTTPCTrack *gtrack = fTracks->GetCheckedTrack(j);
610 if(!gtrack) continue;
612 // --- CHECK if track is should be drawn
613 // select Single Track
614 if(gtrack->GetSector() != fSelectTrackSlice) continue;
616 if (trackcounter != fSelectTrack){
622 //if((fPtThreshold > 0) && (gtrack->GetPt()< fPtThreshold)) continue;
623 //if(gtrack->GetNHits() < fMinHits) continue;
633 //----------------------------------------------------------------------------------------------------
635 //____________________________________________________________________________________________________
636 void AliHLTTPCDisplayMain::ExecPadEvent(Int_t event, Int_t px, Int_t py, TObject *selected){
637 TCanvas *c = (TCanvas *) gTQSender;
639 if (event == 11 &&selected->InheritsFrom("TH2F")) {
640 TH2F *hist = (TH2F*) selected;
642 Int_t binx = hist->GetXaxis()->FindBin(c->AbsPixeltoX(px)) -1 ;
643 // Int_t biny = hist->GetYaxis()->FindBin(c->AbsPixeltoY(py)) -1;
645 fPadCallback(fPt2Gui, binx);