+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * *
+ * Author: The ALICE Off-line Project. *
+ * Contributors are mentioned in the code where appropriate. *
+ * *
+ * Permission to use, copy, modify and distribute this software and its *
+ * documentation strictly for non-commercial purposes is hereby granted *
+ * without fee, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission notice *
+ * appear in the supporting documentation. The authors make no claims *
+ * about the suitability of this software for any purpose. It is *
+ * provided "as is" without express or implied warranty. *
+ **************************************************************************/
-#include "AliTRDtestBeam.h"
-
-#include "AliTRDRawStreamTB.h"
-#include "AliRawReaderMemory.h"
+/* $Id$ */
-#include <iostream>
-#include <fstream>
+////////////////////////////////////////////////////////////////////////////
+// //
+// Class to handle the test beam data of 2007 //
+// //
+// Authors: //
+// Sylwester Radomski (radomski@physi.uni-heidelberg.de) //
+// Anton Andronic (A.Andronic@gsi.de) //
+// //
+////////////////////////////////////////////////////////////////////////////
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
+//#include <iostream>
+//#include <fstream>
+//#include <sys/types.h>
+//#include <sys/stat.h>
+//#include <fcntl.h>
+//include <unistd.h>
-//#include <>
+#include "AliTRDrawStream.h"
+#include "AliRawReaderMemory.h"
+#include "AliTRDtestBeam.h"
ClassImp(AliTRDtestBeam)
-const Long_t AliTRDtestBeam::file_head_size = 544; // ?
-const Long_t AliTRDtestBeam::event_head_size = 68; //?
-const Long_t AliTRDtestBeam::ldc_head_size = 68; //?
-const Long_t AliTRDtestBeam::equip_head_size = 28; //
-const Int_t AliTRDtestBeam::vme_in =1; //VME event in
-const Int_t AliTRDtestBeam::sim_in =1; //Si-strips in
+const Long_t AliTRDtestBeam::fgkFileHeadSize = 544; // ?
+const Long_t AliTRDtestBeam::fgkEventHeadSize = 68; //?
+const Long_t AliTRDtestBeam::fgkLdcHeadSize = 68; //?
+const Long_t AliTRDtestBeam::fgkEquipHeadSize = 28; //
+const Int_t AliTRDtestBeam::fgkVmeIn =1; //VME event in
+const Int_t AliTRDtestBeam::fgkSimIn =1; //Si-strips in
//typedef char byte;
//offsets in bytes
-const Int_t AliTRDtestBeam::pos_run = 20; //run nr. (in file and event header)
-const Int_t AliTRDtestBeam::pos_length = 0; //event/equip. length
-const Int_t AliTRDtestBeam::pos_eqid = 8; //equipment id.
-const Int_t AliTRDtestBeam::pos_sioff = 12; //Si data size offset (3 extra words!!!)
+const Int_t AliTRDtestBeam::fgkPosRun = 20; //run nr. (in file and event header)
+const Int_t AliTRDtestBeam::fgkPosLength = 0; //event/equip. length
+const Int_t AliTRDtestBeam::fgkEqId = 8; //equipment id.
+const Int_t AliTRDtestBeam::fgkPosSiOff = 12; //Si data size offset (3 extra words!!!)
using namespace std;
fCher(0),
fPb(0)
{
+ //
+ // Standard construction
+ //
}
//____________________________________________________________________________
fCher(0),
fPb(0)
{
+ //
+ // AliTRDtestBeam constructor
+ //
fDataStream = new ifstream(filename, ifstream::in | ifstream::binary );
cout << fDataStream->is_open() << endl;
//fHeaderIsRead = kTRUE;
fHeaderIsRead = kTRUE;
- fFileHeader = new Char_t[file_head_size];
- fEventHeader = new Char_t[event_head_size];
+ fFileHeader = new Char_t[fgkFileHeadSize];
+ fEventHeader = new Char_t[fgkEventHeadSize];
fEventData = new Char_t[fLimit];
+
}
-
+
+//____________________________________________________________________________
+AliTRDtestBeam::AliTRDtestBeam(const AliTRDtestBeam &tb)
+ :TObject(tb),
+ fDataStream(0),
+ fHeaderIsRead(0),
+ fEventCount(0),
+ fLimit(4),
+ fCurrent(0),
+ fDdlOff(0),
+ fSiOff(0),
+ fQdcOff(0),
+ fDdlSize(0),
+ fFileHeader(0),
+ fEventHeader(0),
+ fEventData(0),
+ fNSi1(0),
+ fNSi2(0),
+ fCher(0),
+ fPb(0)
+{
+ //
+ // Copy constructor
+ //
+
+}
+
//____________________________________________________________________________
+AliTRDtestBeam::~AliTRDtestBeam()
+{
+ //
+ // Destructor
+ //
+
+ if (fDataStream) delete fDataStream;
+ if (fEventHeader) delete fEventHeader;
+ if (fFileHeader) delete fFileHeader;
+ if (fEventData) delete fEventData;
+
+}
-Int_t AliTRDtestBeam::NextEvent() {
+//____________________________________________________________________________
+Int_t AliTRDtestBeam::NextEvent()
+{
+ //
+ // Read the next event
+ //
- Long_t data_size=0,ldc_off; //,ldc_id,ldc2_id;
- Long_t ldc_size,eq_id; //,ev_l2;
- Long_t event_nr,ev_l1;
+ Long_t dataSize=0,ldcOff; //,ldc_id,ldc2_id;
+ Long_t ldcSize,eqId; //,ev_l2;
+ Long_t eventNr,evL1;
Long_t word;
if ( !fHeaderIsRead ) {
- fDataStream->read(fFileHeader, file_head_size);
+ fDataStream->read(fFileHeader, fgkFileHeadSize);
if(fDataStream->fail()) {
cerr << "Error reading file header! " << endl;
return false;
}
- cout << " Run nr. " << Int(pos_run, fFileHeader) << endl;
+ cout << " Run nr. " << Int(fgkPosRun, fFileHeader) << endl;
fHeaderIsRead=kTRUE;
}
- fDataStream->read(fEventHeader, event_head_size);
+ fDataStream->read(fEventHeader, fgkEventHeadSize);
if(fDataStream->fail()) {
cerr << "End of file, Event " << fEventCount << endl;
return false;
}
- data_size = Int(pos_length, fEventHeader)-event_head_size; //?
- event_nr = Int((4+pos_run), fEventHeader); //ev.nr.
- //cout << " Event " << event_nr <<" size "<< data_size <<endl;
+ dataSize = Int(fgkPosLength, fEventHeader)-fgkEventHeadSize; //?
+ eventNr = Int((4+fgkPosRun), fEventHeader); //ev.nr.
+ //cout << " Event " << eventNr <<" size "<< dataSize <<endl;
- if (event_nr <= fEventCount-1) { //watch-out ...event counter starts at 1?
+ if (eventNr <= fEventCount-1) { //watch-out ...event counter starts at 1?
cout << fEventCount << " End of file?, Event " << fEventCount << endl;
return false;
}
- //cout << "Run " << Int(pos_run, header)<< " , Event " <<event_nr <<endl;
+ //cout << "Run " << Int(fgkPosRun, header)<< " , Event " <<eventNr <<endl;
// enough space for data?
- if (fLimit < data_size) {
+ if (fLimit < dataSize) {
delete[] fEventData;
- fEventData = new Char_t[data_size];
- fLimit = data_size;
+ fEventData = new Char_t[dataSize];
+ fLimit = dataSize;
}
- fDataStream->read(fEventData, data_size);
+ fDataStream->read(fEventData, dataSize);
if(fDataStream->fail()) {
cerr << "End of file, Event " << fEventCount; // << endl;
//cout << " ...IDs (size) : ";
- ldc_off=0; // size of data from one DDL link
+ ldcOff=0; // size of data from one DDL link
for ( size_t k = 0; k < 2; k++ ) { // 2 LDCs (DDL & VME)
- ldc_size = Int(ldc_off+pos_length, fEventData); //
- //ldc_size1=(ldc_size-ldc_head_size);
- eq_id = Int(ldc_off+ldc_head_size+pos_eqid, fEventData);
- //cout << eq_id <<" ("<<ldc_size<<") ";
+ ldcSize = Int(ldcOff+fgkPosLength, fEventData); //
+ //ldcSize1=(ldcSize-fgkLdcHeadSize);
+ eqId = Int(ldcOff+fgkLdcHeadSize+fgkEqId, fEventData);
+ //cout << eqId <<" ("<<ldcSize<<") ";
- ev_l1 = Int((4+ldc_off+pos_run), fEventData); //ev.nr.
- if ( ev_l1 != event_nr ){
- //cerr << "Eq_id " <<eq_id<<" event nr. mismatch? " << event_nr <<" / "<< ev_l1 <<" ...LDC data size (header:68) " <<ldc_size<<endl;
+ evL1 = Int((4+ldcOff+fgkPosRun), fEventData); //ev.nr.
+ if ( evL1 != eventNr ){
+ //cerr << "eqId " <<eqId<<" event nr. mismatch? " << eventNr <<" / "<< evL1 <<" ...LDC data size (header:68) " <<ldcSize<<endl;
}
- if (eq_id == 1024) { //DDL data
- fDdlOff = ldc_off; //+ldc_head_size+equip_head_size + 32;
- fDdlSize = ldc_size;
+ if (eqId == 1024) { //DDL data
+ fDdlOff = ldcOff; //+fgkLdcHeadSize+fgkEquipHeadSize + 32;
+ fDdlSize = ldcSize;
}
- if (eq_id == 550) { //Si-strip data (+QDC)
+ if (eqId == 550) { //Si-strip data (+QDC)
//cout << "550" << endl;
- fSiOff=ldc_off+ldc_head_size+equip_head_size+pos_sioff;
+ fSiOff=ldcOff+fgkLdcHeadSize+fgkEquipHeadSize+fgkPosSiOff;
word = Int(fSiOff, fEventData);
- Short_t LenSi1 = (word >> 16) & 0xffff;
- Short_t LenSi2 = word & 0xffff;
- fQdcOff=fSiOff+4*(LenSi1+LenSi2+1)+equip_head_size+4;
+ Short_t lenSi1 = (word >> 16) & 0xffff;
+ Short_t lenSi2 = word & 0xffff;
+ fQdcOff=fSiOff+4*(lenSi1+lenSi2+1)+fgkEquipHeadSize+4;
}
- else if (eq_id == 1182) { //QDC first...
+ else if (eqId == 1182) { //QDC first...
//cout << "1182" << endl;
- fQdcOff=ldc_off+ldc_head_size+equip_head_size+pos_sioff;
- fSiOff=fQdcOff+equip_head_size+4;
+ fQdcOff=ldcOff+fgkLdcHeadSize+fgkEquipHeadSize+fgkPosSiOff;
+ fSiOff=fQdcOff+fgkEquipHeadSize+4;
}
- ldc_off=ldc_size;
+ ldcOff=ldcSize;
}
//cout << endl;
fEventCount++; //event counter
return true;
}
+
//____________________________________________________________________________
-Int_t AliTRDtestBeam::DecodeSi() {
+Int_t AliTRDtestBeam::DecodeSi()
+{
+ //
+ // Decode the silicon detector
+ //
if (fSiOff < 0) return 0;
// reconstruction
- int LenSiX = 640;
+ int aLenSiX = 640;
- int qmaxX; int amaxX;
- int qmaxY; int amaxY;
+ int amaxX=0;
+ int amaxY=0;
+
+ Int_t q, a;
+ Int_t nst1=0,nst2=0;
+ Int_t qclX=0,qclY=0, nclX=0,nclY=0, nstX=0,nstY=0;
+ const Int_t kThr = 20;
+
+ nst1=0;
+ nstX=0;
+ nstY=0;
+ nclX=0;
+ nclY=0;
+ qclX=0;
+ qclY=0;
- qmaxX = 5;
- qmaxY = 5;
- amaxX = -1;
- amaxY = -1+LenSiX;
-
for( int i = 0; i < GetNSi1(); i++ ) {
if (fSi1Address[i] == 0) continue; // noise
-
- if (fSi1Address[i] < LenSiX ) {
- if( fSi1Charge[i] > qmaxX ) {
- qmaxX = fSi1Charge[i];
- amaxX = fSi1Address[i];
- }
- } else {
- if( fSi1Charge[i] > qmaxY ) {
- qmaxY = fSi1Charge[i];
- amaxY = fSi1Address[i];
- }
+
+ q = fSi1Charge[i];
+ a = fSi1Address[i];
+
+ if ( q > kThr )
+ {
+ if ( i > 0 && i < (GetNSi1()-1) ) {
+
+ if ( (a-fSi1Address[i+1]) == -1 &&
+ (a-fSi1Address[i-1]) == 1)
+ {
+ nst1++;
+ if (a < aLenSiX) {
+ qclX = q+fSi1Charge[i+1]+fSi1Charge[i-1];
+ nclX++;
+ nstX+=3;
+ amaxX = a;
+ }
+ else {
+ qclY = q+fSi1Charge[i+1]+fSi1Charge[i-1];
+ nclY++;
+ nstY+=3;
+ amaxY = a;
+ }
+ i+=1;
+ }
+ else if ( (a-fSi1Address[i-1]) == 1)
+ {
+ nst1++;
+ if (a < aLenSiX) {
+ qclX = q+fSi1Charge[i-1];
+ nclX++;
+ nstX+=2;
+ amaxX = a;
+ }
+ else {
+ qclY = q+fSi1Charge[i-1];
+ nclY++;
+ nstY+=2;
+ amaxY = a;
+ }
+ }
+ else if ( (a-fSi1Address[i+1]) == -1)
+ {
+ nst1++;
+ if (a < aLenSiX) {
+ qclX = q+fSi1Charge[i+1];
+ nclX++;
+ nstX+=2;
+ amaxX = a;
+ }
+ else {
+ qclY = q+fSi1Charge[i+1];
+ nclY++;
+ nstY+=2;
+ amaxY = a;
+ }
+ i+=1;
+ }
+ }
}
}
+ if (nst1==2 && nstX<4 && nstY<4 ) {
+ fX[0] = (float)(amaxX*0.05); // [mm]
+ fY[0] = (float)((amaxY-aLenSiX)*0.05);
+ fQx[0] = (float)qclX;
+ fQy[0] = (float)qclY;
+ }
+ else {
+ fX[0] = -1.;
+ fY[0] = -1.;
+ fQx[0] = 0.;
+ fQy[0] = 0.;
+ }
- fX[0] = (float)(amaxX*0.05); // [mm]
- fY[0] = (float)((amaxY-LenSiX)*0.05);
- fQx[0] = (float)qmaxX;
- fQy[0] = (float)qmaxY;
-
- //
- qmaxX = 5;
- qmaxY = 5;
- amaxX = -1;
- amaxY = -1+LenSiX;
+ // ...and Si2
+
+ nst2=0;
+ nstX=0;
+ nstY=0;
+ nclX=0;
+ nclY=0;
+ qclX=0;
+ qclY=0;
for( int i = 0; i < GetNSi2(); i++ ) {
if (fSi2Address[i] == 1279) continue; // noise
if (fSi2Address[i] == 0) continue; // noise
- if(fSi2Address[i] < LenSiX) {
- if( fSi2Charge[i] > qmaxX ) {
- qmaxX = fSi2Charge[i];
- amaxX = fSi2Address[i];
- }
- } else {
- if( fSi2Charge[i] > qmaxY ) {
- //if (fSi2Charge[i] > 50) cout << fSi2Charge[i] << " " << i << " " << fSi2Address[i] << endl;
- qmaxY = fSi2Charge[i];
- amaxY = fSi2Address[i];
- }
+ q = fSi2Charge[i];
+ a = fSi2Address[i];
+
+ if ( q > kThr/2 ) //...as Si2 has 1/2 gain!
+ {
+ if ( i > 0 && i < (GetNSi2()-1) ) {
+
+ if ( (a-fSi2Address[i+1]) == -1 &&
+ (a-fSi2Address[i-1]) == 1)
+ {
+ nst2++;
+ if (a < aLenSiX) {
+ qclX = q+fSi2Charge[i+1]+fSi2Charge[i-1];
+ nclX++;
+ nstX+=3;
+ amaxX = a;
+ }
+ else {
+ qclY = q+fSi2Charge[i+1]+fSi2Charge[i-1];
+ nclY++;
+ nstY+=3;
+ amaxY = a;
+ }
+ i+=1;
+ }
+ else if ( (a-fSi2Address[i-1]) == 1)
+ {
+ nst2++;
+ if (a < aLenSiX) {
+ qclX = q+fSi2Charge[i-1];
+ nclX++;
+ nstX+=2;
+ amaxX = a;
+ }
+ else {
+ qclY = q+fSi2Charge[i-1];
+ nclY++;
+ nstY+=2;
+ amaxY = a;
+ }
+ }
+ else if ( (a-fSi2Address[i+1]) == -1)
+ {
+ nst2++;
+ if (a < aLenSiX) {
+ qclX = q+fSi2Charge[i+1];
+ nclX++;
+ nstX+=2;
+ amaxX = a;
+ }
+ else {
+ qclY = q+fSi2Charge[i+1];
+ nclY++;
+ nstY+=2;
+ amaxY = a;
+ }
+ i+=1;
+ }
+ }
}
}
- fX[1] = (float)(amaxX*0.05); // [mm]
- fY[1] = (float)((amaxY-LenSiX)*0.05);
- fQx[1] = (float)qmaxX;
- fQy[1] = (float)qmaxY;
+ if (nst2==2 && nstX<4 && nstY<4 ) {
+ fX[1] = (float)(amaxX*0.05); // [mm]
+ fY[1] = (float)((amaxY-aLenSiX)*0.05);
+ fQx[1] = (float)qclX;
+ fQy[1] = (float)qclY;
+ }
+ else {
+ fX[1] = -1.;
+ fY[1] = -1.;
+ fQx[1] = 0.;
+ fQy[1] = 0.;
+ }
if (fQdcOff < 0) return 0;
//cout << fCher << " " << fPb << endl;
return 1;
+
}
//____________________________________________________________________________
-/**/
-AliTRDRawStreamTB *AliTRDtestBeam::GetTRDrawStream() {
+AliTRDrawStream *AliTRDtestBeam::GetTRDrawStream()
+{
+ //
+ // Get the TRD raw stream
+ //
- // needs AliTRDRawStreamTB
+ // needs AliTRDrawStream
//cout << "Chamber reader:" << (Int_t)(fEventData+fDdlOff) << " " << fDdlSize << endl;
//int ifout = open("dump.dat", O_WRONLY | O_TRUNC | O_CREAT);
//write(ifout, (void*)(fEventData+fDdlOff+16), fDdlSize);
AliRawReaderMemory *reader = new AliRawReaderMemory((UChar_t*)(fEventData+fDdlOff), (UInt_t)fDdlSize);
reader->SetEquipmentID(1024);
reader->ReadHeader();
- AliTRDRawStreamTB::RawBufferMissAligned(kTRUE);
- AliTRDRawStreamTB::SupressWarnings(kTRUE);
-
- AliTRDRawStreamTB *tb = new AliTRDRawStreamTB(reader);
- tb->Init();
+ //AliTRDrawStream::RawBufferMissAligned(kTRUE);
+
+ AliTRDrawStream::SetNoErrorWarning();
+ AliTRDrawStream::SetExtraWordsFix();
+ AliTRDrawStream::AllowCorruptedData();
+
+ AliTRDrawStream *tb = new AliTRDrawStream(reader);
+ //tb->Init();
return tb;
/*
return
- AliRawReaderMemory *rmem = data->GetRawReader();
+ AliEawReaderMemory *rmem = data->GetRawReader();
rmem->ReadHeader();
- AliTRDRawStreamTB tb(rmem);
+ AliTRDrawStream tb(rmem);
tb.Init();
- AliTRDRawStreamTB::SupressWarnings(kTRUE);
+ AliTRDrawStream::SupressWarnings(kTRUE);
*/
}
-/**/
-//____________________________________________________________________________
-Int_t AliTRDtestBeam::Int(Int_t i, Char_t *start) {
+//____________________________________________________________________________
+Int_t AliTRDtestBeam::Int(Int_t i, const Char_t * const start) const
+{
+ //
+ // ?????
+ //
bool swap = kFALSE;
char p[] = {q[3], q[2], q[1], q[0]};
return *((int*) p);
} else return *((int*)(start+i));
+
}
//____________________________________________________________________________