]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDmcmSim.cxx
Move the diffusion coefficients, the time structure, omegaTau for ExB, and switches...
[u/mrichter/AliRoot.git] / TRD / AliTRDmcmSim.cxx
index 216dad094a11db2e6878d4b742737d56ea768c82..41ed94532dff0ce30574b21955c9d5cd730bc608 100644 (file)
@@ -99,10 +99,11 @@ The default raw version is 2.
 #include "AliTRDmcmSim.h"
 #include "AliTRDfeeParam.h"
 #include "AliTRDSimParam.h"
+#include "AliTRDCommonParam.h"
 #include "AliTRDgeometry.h"
 #include "AliTRDcalibDB.h"
 #include "AliTRDdigitsManager.h"
-
+#include "AliTRDarrayADC.h"
 // additional for new tail filter and/or tracklet
 #include "AliTRDtrapAlu.h"
 #include "AliTRDpadPlane.h"
@@ -609,6 +610,94 @@ Int_t AliTRDmcmSim::ProduceRawStream( UInt_t *buf, Int_t maxSize )
   if( of != 0 ) return -of; else return nw;
 }
 
+//_____________________________________________________________________________
+Int_t AliTRDmcmSim::ProduceRawStreamV2( UInt_t *buf, Int_t maxSize, UInt_t iEv )
+{
+  //
+  // Produce raw data stream from this MCM and put in buf
+  // Returns number of words filled, or negative value 
+  // with -1 * number of overflowed words
+  //
+
+  UInt_t  x;
+  //UInt_t  iEv = 0;
+  Int_t   nw  = 0;  // Number of written words
+  Int_t   of  = 0;  // Number of overflowed words
+  Int_t   rawVer   = fFeeParam->GetRAWversion();
+  Int_t **adc;
+  Int_t   nActiveADC = 0;      // number of activated ADC bits in a word
+
+  if( !CheckInitialized() ) return 0;
+
+  if( fFeeParam->GetRAWstoreRaw() ) {
+    adc = fADCR;
+  } else {
+    adc = fADCF;
+  }
+
+  // Produce MCM header : xrrr mmmm eeee eeee eeee eeee eeee 1100
+  //                      x : 0 before , 1 since 10.2007
+  //                      r : Readout board position (Alice numbering)
+  //                      m : MCM posi
+  //                      e : Event counter from 1
+  //x = (1<<31) | ((fRobPos * fFeeParam->GetNmcmRob() + fMcmPos) << 24) | ((iEv % 0x100000) << 4) | 0xC;
+  x = (1<<31) | (fRobPos << 28) | (fMcmPos << 24) | ((iEv % 0x100000) << 4) | 0xC;
+  if (nw < maxSize) {
+    buf[nw++] = x;
+       //printf("\nMCM header: %X ",x);
+  }
+  else {
+    of++;
+  }
+
+  // Produce ADC mask : nncc cccm mmmm mmmm mmmm mmmm mmmm 1100
+  //                           n : unused , c : ADC count, m : selected ADCs
+  if( rawVer >= 3 ) {
+    x = 0;
+    for( Int_t iAdc = 0 ; iAdc < fNADC ; iAdc++ ) {
+      if( fZSM1Dim[iAdc] == 0 ) { //  0 means not suppressed
+               x = x | (1 << (iAdc+4) );       // last 4 digit reserved for 1100=0xc
+               nActiveADC++;           // number of 1 in mmm....m
+      }
+    }
+       x = x | (1 << 30) | ( ( 0x3FFFFFFC ) & (~(nActiveADC) << 25) ) | 0xC;   // nn = 01, ccccc are inverted, 0xc=1100
+       //printf("nActiveADC=%d=%08X, inverted=%X ",nActiveADC,nActiveADC,x );
+
+    if (nw < maxSize) {
+      buf[nw++] = x;
+         //printf("ADC mask: %X nMask=%d ADC data: ",x,nActiveADC);
+    }
+    else {
+      of++;
+    }
+  }
+
+  // Produce ADC data. 3 timebins are packed into one 32 bits word
+  // In this version, different ADC channel will NOT share the same word
+
+  UInt_t aa=0, a1=0, a2=0, a3=0;
+
+  for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
+    if( rawVer>= 3 && fZSM1Dim[iAdc] != 0 ) continue; // Zero Suppression, 0 means not suppressed
+    aa = !(iAdc & 1) + 2;      // 3 for the even ADC channel , 2 for the odd ADC channel
+    for (Int_t iT = 0; iT < fNTimeBin; iT+=3 ) {
+      a1 = ((iT    ) < fNTimeBin ) ? adc[iAdc][iT  ] : 0;
+      a2 = ((iT + 1) < fNTimeBin ) ? adc[iAdc][iT+1] : 0;
+      a3 = ((iT + 2) < fNTimeBin ) ? adc[iAdc][iT+2] : 0;
+      x = (a3 << 22) | (a2 << 12) | (a1 << 2) | aa;
+      if (nw < maxSize) {
+       buf[nw++] = x;
+       //printf("%08X ",x);
+      }
+      else {
+       of++;
+      }
+    }
+  }
+
+  if( of != 0 ) return -of; else return nw;
+}
+
 //_____________________________________________________________________________
 Int_t AliTRDmcmSim::ProduceTrackletStream( UInt_t *buf, Int_t maxSize )
 {
@@ -754,8 +843,9 @@ void AliTRDmcmSim::FilterTail()
     break;
   }
 
-  delete dtarg;
-  delete itarg;
+  delete [] dtarg;
+  delete [] itarg;
+
 }
 
 //_____________________________________________________________________________
@@ -1526,7 +1616,7 @@ void AliTRDmcmSim::Tracklet(){
     Int_t j = 1; // selection number
     while(i<fNADC-2 && j<=3){
       i = i + 1;
-      if((mark>>(i-1)) & 1 == 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
        
@@ -1562,7 +1652,7 @@ void AliTRDmcmSim::Tracklet(){
     // read three from left side
     Int_t k = fNADC-2;
     while(k>i && j<=6) {
-      if((mark>>(k-1)) & 1 == 1) {
+      if( ((mark>>(k-1)) & 1) == 1) {
        selection[j].iadc  = fNADC-1-k;
        selection[j].value = qsum[fNADC-1-k]>>6;
        
@@ -1769,7 +1859,7 @@ void AliTRDmcmSim::Tracklet(){
   // insert marked channels into list and sort according to hit-sum
   while(adcL < fNADC-3 && selNr < fNADC-3){
      
-    if((mPair>>((fNADC-4)-(adcL))) & 1 == 1) {
+    if( ((mPair>>((fNADC-4)-(adcL))) & 1) == 1) {
       selectPair[selNr].iadc  = adcL;
       selectPair[selNr].value = hitSum[adcL];   
       
@@ -2098,7 +2188,7 @@ void AliTRDmcmSim::Tracklet(){
   Int_t    nrOfAmplTimeBins  = 2;                           // the number of time bins between anode wire and cathode wires in ampl.region (3.5mm)(guess)(suppose v_drift+3.5cm/us there=>all clusters arrive at anode wire within one time bin (100ns))
   Int_t    nrOfOffsetCorrTimeBins = tFS - nrOfAmplTimeBins - 1; // -1 is  to be conservative; offset correction will not remove the shift but is supposed to improve it; if tFS = 5, 2 drift time bins before tFS are assumed
   if(nrOfOffsetCorrTimeBins < 0) nrOfOffsetCorrTimeBins = 0;// don't apply offset correction if no drift time bins before tFS can be assumed 
-  Double_t lorTan     = fCal->GetOmegaTau(vdrift,magField); // tan of the Lorentz-angle for this detector; could be evaluated and set as a parameter for each mcm
+  Double_t lorTan     = AliTRDCommonParam::Instance()->GetOmegaTau(vdrift); // tan of the Lorentz-angle for this detector; could be evaluated and set as a parameter for each mcm
   //Double_t lorAngle   =  7.0;                             // Lorentz-angle in degrees
   Double_t tiltAngle  = padPlane->GetTiltingAngle();        // sign-respecting tilting angle of pads in actual layer
   Double_t tiltTan    = TMath::Tan(TMath::Pi()/180.0 * tiltAngle);
@@ -2356,7 +2446,7 @@ void AliTRDmcmSim::Tracklet(){
        shift2 = 1;
        for(Int_t iBit = 1; iBit < 7; iBit++) {
            shift2  = shift2<<1;
-           shift2 |= (1-((shift)>>(6-iBit))&1);
+           shift2 |= (1- (((shift)>>(6-iBit))&1) );
            //printf("%d",(1-((-mSlope[i])>>(6-iBit))&1));
        }
        shift2 = shift2 + 1;
@@ -2385,7 +2475,7 @@ void AliTRDmcmSim::Tracklet(){
        shift2 = 1;
        for(Int_t iBit = 1; iBit < 13; iBit++) {
            shift2  = shift2<<1;
-           shift2 |= (1-((shift)>>(12-iBit))&1);
+           shift2 |= (1-(((shift)>>(12-iBit))&1));
            //printf("%d",(1-((-mOffset[i])>>(12-iBit))&1));
        }
        shift2 = shift2 + 1;
@@ -2454,7 +2544,7 @@ void AliTRDmcmSim::Tracklet(){
   Int_t u = 0;
 
   AliTRDdigitsManager *digman = new AliTRDdigitsManager();
-  digman->ReadDigits(gAlice->GetRunLoader()->GetLoader("TRDLoader")->TreeD());
+  digman->ReadDigits(AliRunLoader::Instance()->GetLoader("TRDLoader")->TreeD());
   digman->SetUseDictionaries(kTRUE);
   AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance();
 
@@ -2499,7 +2589,7 @@ void AliTRDmcmSim::Tracklet(){
       }
   }
 
AliDataLoader *dl = gAlice->GetRunLoader()->GetLoader("TRDLoader")->GetDataLoader("tracklets");
 AliDataLoader *dl = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets");
   if (!dl) {
     AliError("Could not get the tracklets data loader!");
   }
@@ -2539,4 +2629,137 @@ void AliTRDmcmSim::Tracklet(){
   // cluster quality threshold (not yet set)
   // electron probability
 }
+//_____________________________________________________________________________________
+void AliTRDmcmSim::GeneratefZSM1Dim()
+{
+  //
+  // Generate the array fZSM1Dim necessary
+  // for the method ProduceRawStream
+  //
+
+  // Fill the mapping
+  // Supressed zeros indicated by -1 in digits array
+  for( Int_t iadc = 1 ; iadc < fNADC-1; iadc++ ) 
+    {
+      for( Int_t it = 0 ; it < fNTimeBin ; it++ ) 
+       {
+         
+         if(fADCF[iadc][it]==-1)  // If is a supressed value
+           {
+             fZSM[iadc][it]=1;
+           }
+         else                    // Not suppressed
+           {
+             fZSM[iadc][it]=0;
+           }
+       }
+    }
+
+  // Make the 1 dim projection
+  for( Int_t iadc = 0 ; iadc < fNADC; iadc++ ) 
+    {
+      for( Int_t it = 0 ; it < fNTimeBin ; it++ ) 
+       {
+         fZSM1Dim[iadc] &= fZSM[iadc][it];
+       }
+    }
+}
+//_______________________________________________________________________________________
+void AliTRDmcmSim::CopyArrays()
+{
+  //
+  // Initialize filtered data array with raw data
+  // Method added for internal consistency
+  //
+
+  for( Int_t iadc = 0 ; iadc < fNADC; iadc++ ) 
+    {
+      for( Int_t it = 0 ; it < fNTimeBin ; it++ ) 
+       {
+         fADCF[iadc][it] = fADCR[iadc][it]; 
+       }
+    }
+}
+//_______________________________________________________________________________________
+void AliTRDmcmSim::StartfastZS(Int_t pads, Int_t timebins)
+{
+  //
+  // Initialize just the necessary elements to perform
+  // the zero suppression in the digitizer
+  //
+   
+  fFeeParam  = AliTRDfeeParam::Instance();
+  fSimParam  = AliTRDSimParam::Instance();
+  fNADC      = pads;      
+  fNTimeBin  = timebins; 
+
+  if( fADCR == NULL ) 
+    {
+      fADCR    = new Int_t *[fNADC];
+      fADCF    = new Int_t *[fNADC];
+      fADCT    = new Int_t *[fNADC]; 
+      fZSM     = new Int_t *[fNADC];
+      fZSM1Dim = new Int_t  [fNADC];
+    for( Int_t iadc = 0 ; iadc < fNADC; iadc++ )
+      {
+       fADCR[iadc] = new Int_t[fNTimeBin];
+       fADCF[iadc] = new Int_t[fNTimeBin];
+       fADCT[iadc] = new Int_t[fNTimeBin]; 
+       fZSM [iadc] = new Int_t[fNTimeBin];
+      }
+    }
+
+  for( Int_t iadc = 0 ; iadc < fNADC; iadc++ ) 
+    {
+      for( Int_t it = 0 ; it < fNTimeBin ; it++ ) 
+       {
+         fADCR[iadc][it] =  0;
+         fADCF[iadc][it] =  0;
+         fADCT[iadc][it] = -1;  
+         fZSM [iadc][it] =  1;   
+       }
+      fZSM1Dim[iadc] = 1;      
+    }
+  
+  fInitialized = kTRUE;
+}
+//_______________________________________________________________________________________
+void AliTRDmcmSim::FlagDigitsArray(AliTRDarrayADC *tempdigs, Int_t valrow)
+{
+  //
+  // Modify the digits array to flag suppressed values
+  //
+
+  for( Int_t iadc = 1 ; iadc < fNADC-1; iadc++ ) 
+    {
+      for( Int_t it = 0 ; it < fNTimeBin ; it++ ) 
+       {
+         if(fZSM[iadc][it]==1)
+           {
+             tempdigs->SetData(valrow,iadc,it,-1);
+           }
+       }
+    }
+}
+//_______________________________________________________________________________________
+void AliTRDmcmSim::RestoreZeros()
+{
+  //
+  // Restore the zero-suppressed values (set as -1) to the value 0
+  //
+
+  for( Int_t iadc = 1 ; iadc < fNADC-1; iadc++ ) 
+    {
+      for( Int_t it = 0 ; it < fNTimeBin ; it++ ) 
+       {
+         
+         if(fADCF[iadc][it]==-1)  //if is a supressed zero, reset to zero
+           {
+             fADCF[iadc][it]=0;
+             fADCR[iadc][it]=0;
+           }     
+       }
+    }
+
+}