-void AliTRDmcmSim::Tracklet(){
- // tracklet calculation
- // if you use this code after a simulation, please make sure the same filter-settings as in the simulation are set in AliTRDfeeParam
-
- if(!CheckInitialized()){ return; }
-
- Bool_t filtered = kTRUE;
-
-
-
- AliTRDtrapAlu data;
- data.Init(10,2);
- if(fADCT[0][0]==-1){ // check if filter was applied
- filtered = kFALSE;
- for( Int_t iadc = 0 ; iadc < fNADC; iadc++ ) {
- for( Int_t iT = 0 ; iT < fNTimeBin ; iT++ ) {
- data.AssignInt(fADCR[iadc][iT]);
- fADCT[iadc][iT] = data.GetValue(); // all incoming values are positive 10+2 bit values; if el.filter was called, this is done correctly
- }
- }
-
- }
-
- // the online ordering of mcm's is reverse to the TRAP-manual-ordering! reverse fADCT (to be consistent to TRAP), then do all calculations
- // reverse fADCT:
- Int_t** rev0 = new Int_t *[fNADC];
- Int_t** rev1 = new Int_t *[fNADC];
-
- for( Int_t iadc = 0 ; iadc < fNADC; iadc++ ) {
- rev0[iadc] = new Int_t[fNTimeBin];
- rev1[iadc] = new Int_t[fNTimeBin];
- for( Int_t iT = 0; iT < fNTimeBin; iT++) {
- if( iadc <= fNADC-iadc-1 ) {
- rev0[iadc][iT] = fADCT[fNADC-iadc-1][iT];
- rev1[iadc][iT] = fADCT[iadc][iT];
- fADCT[iadc][iT] = rev0[iadc][iT];
- }
- else {
- rev0[iadc][iT] = rev1[fNADC-iadc-1][iT];
- fADCT[iadc][iT] = rev0[iadc][iT];
- }
- }
- }
- for( Int_t iadc = 0 ; iadc < fNADC; iadc++ ) {
- delete[] rev0[iadc];
- delete[] rev1[iadc];
- }
-
- delete[] rev0;
- delete[] rev1;
-
- rev0 = NULL;
- rev1 = NULL;
-
- // get the filtered pedestal; supports only electronic tail-cancellation filter
- AliTRDtrapAlu filPed;
- Int_t ep = 0;
- Int_t *ieffped = new Int_t[fNTimeBin];
- for(Int_t iT = 0; iT < fNTimeBin; iT++){
- ieffped[iT] = ep;
- }
-
- if( filtered == kTRUE ) {
- if( fFeeParam->IsPFon() ){
- ep = fFeeParam->GetPFeffectPedestal();
- }
- Int_t nexp = fFeeParam->GetTFnExp();
- Int_t *isource = new Int_t[fNTimeBin];
- filPed.Init(10,2);
- filPed.AssignInt(ep);
- Int_t epf = filPed.GetValue();
- for(Int_t iT = 0; iT < fNTimeBin; iT++){
- isource[iT] = ep;
- ieffped[iT] = epf;
- }
-
- if( fFeeParam->IsTFon() ) {
- FilterSimDeConvExpEl( isource, ieffped, fNTimeBin, nexp);
- }
-
- delete[] isource;
- }
-
- //the following values should go to AliTRDfeeParam once they are defined; then they have to be read in properly
- //naming follows conventions in TRAP-manual
-
-
- Bool_t bVBY = kTRUE; // cluster-verification bypass
-
- Double_t cQTParam = 0; // cluster quality threshold; granularity 2^-10; range: 0<=cQT/2^-10<=2^-4 - 2^-10
- AliTRDtrapAlu cQTAlu;
- cQTAlu.Init(1,10,0,63);
- cQTAlu.AssignDouble(cQTParam);
- Int_t cQT = cQTAlu.GetValue();
-
- // linear fit
- Int_t tFS = fFeeParam->GetLinearFitStart(); // linear fit start
- Int_t tFE = fFeeParam->GetLinearFitEnd(); // linear fit stop
-
- // charge accumulators
- Int_t tQS0 = fFeeParam->GetQacc0Start(); // start-time for charge-accumulator 0
- Int_t tQE0 = fFeeParam->GetQacc0End(); // stop-time for charge-accumulator 0
- Int_t tQS1 = fFeeParam->GetQacc1Start(); // start-time for charge-accumulator 1
- Int_t tQE1 = fFeeParam->GetQacc1End(); // stop-time for charge-accumulator 1
- // values set such that tQS0=tFS; tQE0=tQS1-1; tFE=tQE1; want to do (QS0+QS1)/N
-
- Double_t cTHParam = (Double_t)fFeeParam->GetMinClusterCharge(); // cluster charge threshold
- AliTRDtrapAlu cTHAlu;
- cTHAlu.Init(12,2);
- cTHAlu.AssignDouble(cTHParam);
- Int_t cTH = cTHAlu.GetValue(); // cTH used for comparison
-
- struct List_t {
- List_t *next;
- Int_t iadc;
- Int_t value;
- };
-
- List_t selection[7]; // list with 7 elements
- List_t *list = NULL;
- List_t *listLeft = NULL;
-
- Int_t* qsum = new Int_t[fNADC];
-
- // fit sums
- AliTRDtrapAlu qsumAlu;
- qsumAlu.Init(12,2); // charge sum will be 12+2 bits
- AliTRDtrapAlu dCOGAlu;
- dCOGAlu.Init(1,7,0,127); // COG will be 1+7 Bits; maximum 1 - 2^-7 for LUT
- AliTRDtrapAlu yrawAlu;
- yrawAlu.Init(1,8,-1,255);
- AliTRDtrapAlu yAlu;
- yAlu.Init(1,16,-1,0xFF00); // only first 8 past-comma bits filled;additional 8 bits for accuracy;maximum 1 - 2^-8; sign is given by + or -
- AliTRDtrapAlu xAlu;
- xAlu.Init(5,8); // 8 past-comma bits because value will be added/multiplied to another value with this accuracy
- AliTRDtrapAlu xxAlu;
- xxAlu.Init(10,0);
- AliTRDtrapAlu yyAlu;
- yyAlu.Init(1,16,0,0xFFFF); // maximum is 2^16-1; 16Bit for past-commas
- AliTRDtrapAlu xyAlu;
- xyAlu.Init(6,8);
- AliTRDtrapAlu XAlu;
- XAlu.Init(9,0);
- AliTRDtrapAlu XXAlu;
- XXAlu.Init(14,0);
- AliTRDtrapAlu YAlu;
- YAlu.Init(5,8); // 14 bit, 1 is sign-bit; therefore only 13 bit
- AliTRDtrapAlu YYAlu;
- YYAlu.Init(5,16);
- AliTRDtrapAlu XYAlu;
- XYAlu.Init(8,8); // 17 bit, 1 is sign-bit; therefore only 16 bit
- AliTRDtrapAlu qtruncAlu;
- qtruncAlu.Init(12,0);
- AliTRDtrapAlu QT0Alu;
- QT0Alu.Init(15,0);
- AliTRDtrapAlu QT1Alu;
- QT1Alu.Init(16,0);
-
- AliTRDtrapAlu oneAlu;
- oneAlu.Init(1,8);
-
-
- AliTRDtrapAlu inverseNAlu;
- inverseNAlu.Init(1,8); // simulates the LUT for 1/N
- AliTRDtrapAlu MeanChargeAlu; // mean charge in ADC counts
- MeanChargeAlu.Init(8,0);
- AliTRDtrapAlu TotalChargeAlu;
- TotalChargeAlu.Init(17,8);
- //nr of post comma bits should be the same for inverseN and TotalCharge
-
-
- SetPosLUT(); // initialize the position correction LUT for this MCM;
-
-
- // fit-sums; remapping!; 0,1,2->0; 1,2,3->1; ... 18,19,20->18
- Int_t *X = new Int_t[fNADC-2];
- Int_t *XX = new Int_t[fNADC-2];
- Int_t *Y = new Int_t[fNADC-2];
- Int_t *YY = new Int_t[fNADC-2];
- Int_t *XY = new Int_t[fNADC-2];
- Int_t *N = new Int_t[fNADC-2];
- Int_t *QT0 = new Int_t[fNADC-2]; // accumulated charge
- Int_t *QT1 = new Int_t[fNADC-2]; // accumulated charge
-
- for (Int_t iCol = 0; iCol < fNADC-2; iCol++) {
-
- // initialize fit-sums
- X[iCol] = 0;
- XX[iCol] = 0;
- Y[iCol] = 0;
- YY[iCol] = 0;
- XY[iCol] = 0;
- N[iCol] = 0;
- QT0[iCol] = 0;
- QT1[iCol] = 0;
- }
-
-
- filPed.Init(7,2); // convert filtered pedestal into 7+2Bits
-
- for(Int_t iT = 0; iT < fNTimeBin; iT++){
-
- if(iT<tFS || iT>=tFE) continue; // linear fit yes/no?
-
- // reset
- Int_t portChannel[4] = {-1,-1,-1,-1};
- Int_t clusterCharge[4] = {0,0,0,0};
- Int_t leftCharge[4] = {0,0,0,0};
- Int_t centerCharge[4] = {0,0,0,0};
- Int_t rightCharge[4] = {0,0,0,0};
-
- Int_t mark = 0;
-
- filPed.AssignFormatted(ieffped[iT]); // no size-checking when using AssignFormatted; ieffped>=0
- filPed = filPed; // this checks the size
-
- ieffped[iT] = filPed.GetValue();
-
- for(Int_t i = 0; i<7; i++){
- selection[i].next = NULL;
- selection[i].iadc = -1; // value of -1: invalid adc
- selection[i].value = 0;
-
- }
- // selection[0] is starting list-element; just for pointing
-
- // loop over inner adc's
- for (Int_t iCol = 1; iCol < fNADC-1; iCol++) {
-
- Int_t left = fADCT[iCol-1][iT];
- Int_t center = fADCT[iCol][iT];
- Int_t right = fADCT[iCol+1][iT];
-
- Int_t sum = left + center + right; // cluster charge sum
- qsumAlu.AssignFormatted(sum);
- qsumAlu = qsumAlu; // size-checking; redundant
-
- qsum[iCol] = qsumAlu.GetValue();
-
- //hit detection and masking
- if(center>=left){
- if(center>right){
- if(qsum[iCol]>=(cTH + 3*ieffped[iT])){ // effective pedestal of all three channels must be added to cTH(+20); this is not parallel to TRAP manual; maybe cTH has to be adjusted in fFeeParam; therefore channels are not yet reduced by their pedestal
- mark |= 1; // marker
- }
- }
- }
- mark = mark<<1;
- }
- mark = mark>>1;
-
-
- // get selection of 6 adc's and sort,starting with greatest values
-
- //read three from right side and sort (primitive sorting algorithm)
- Int_t i = 0; // adc number
- Int_t j = 1; // selection number
- while(i<fNADC-2 && j<=3){
- i = i + 1;
- if( ((mark>>(i-1)) & 1) == 1) {
- selection[j].iadc = fNADC-1-i;
- selection[j].value = qsum[fNADC-1-i]>>6; // for hit-selection only the first 8 out of the 14 Bits are used for comparison
-
- // insert into sorted list
- listLeft = &selection[0];
- list = listLeft->next;
-
- if(list!=NULL) {
- while((list->next != NULL) && (selection[j].value <= list->value)){
- listLeft = list;
- list = list->next;
- }
-
- if(selection[j].value<=list->value){
- selection[j].next = list->next;
- list->next = &selection[j];
- }
- else {
- listLeft->next = &selection[j];
- selection[j].next = list;
- }
- }
- else{
- listLeft->next = &selection[j];
- selection[j].next = list;
- }
-
- j = j + 1;
- }
- }