bug fixed
[u/mrichter/AliRoot.git] / T0 / AliT0Digitizer.cxx
index 921982d..1a27aec 100644 (file)
@@ -57,8 +57,8 @@ ClassImp(AliT0Digitizer)
                                     fADC(new TArrayI(24)), 
                                     fADC0 (new TArrayI(24)),
                                     fSumMult(0),
-                                    fEffPMT(0)
-
+                                    fAmpLED(0),
+                                    fParam(0)
 
 
 {
@@ -77,15 +77,33 @@ AliT0Digitizer::AliT0Digitizer(AliRunDigitizer* manager)
    fADC(new TArrayI(24)), 
    fADC0 (new TArrayI(24)),
    fSumMult(0),
-   fEffPMT(0)
+   fAmpLED(0),
+   fParam(0)
 {
 // ctor which should be used
 
   AliDebug(1,"processed");
+  fParam = AliT0Parameters::Instance();
+  fParam->Init();
 
+  for (Int_t i=0; i<24; i++){
+    TGraph* gr = fParam ->GetAmpLEDRec(i);
+    Int_t np = gr->GetN();
+    Double_t *x = gr->GetX();
+    Double_t *y = gr->GetY();
 
+    Double_t *x1 = new Double_t[np];
+    Double_t *y1 = new Double_t[np];
+    for (Int_t ii=0; ii<np; ii++) {
+      y1[ii]=y[np-ii-1]; x1[ii]=x[np-ii-1];
+    }
+    
+    TGraph *grInverse = new TGraph(np,y1,x1);
+    delete [] x1;
+    delete [] y1;
+    fAmpLED.AddAtAndExpand(grInverse,i);
+  }
 }
-
 //------------------------------------------------------------------------
 AliT0Digitizer::~AliT0Digitizer()
 {
@@ -97,9 +115,10 @@ AliT0Digitizer::~AliT0Digitizer()
   delete fADC;
   delete ftimeLED;
   delete  fADC0;
+  //  delete fAmpLED;
 }
 
- //------------------------------------------------------------------------
+//------------------------------------------------------------------------
 Bool_t AliT0Digitizer::Init()
 {
 // Initialization
@@ -107,9 +126,7 @@ Bool_t AliT0Digitizer::Init()
  return kTRUE;
 }
  
-
 //---------------------------------------------------------------------
-
 void AliT0Digitizer::Exec(Option_t* /*option*/)
 {
 
@@ -143,18 +160,17 @@ void AliT0Digitizer::Exec(Option_t* /*option*/)
   Int_t threshold =50; //photoelectrons
   Float_t zdetA, zdetC;
   Int_t sumMultCoeff = 100;
+  Int_t refpoint=0;
   TH1F *hr;
 
-  AliT0Parameters* param = AliT0Parameters::Instance();
-  param->Init();
 
   
-  Int_t ph2Mip = param->GetPh2Mip();     
-  Int_t channelWidth = param->GetChannelWidth() ;  
-  Float_t delayVertex = param->GetTimeDelayTVD();
+  Int_t ph2Mip = fParam->GetPh2Mip();     
+  Float_t channelWidth = fParam->GetChannelWidth() ;  
+  Float_t delayVertex = fParam->GetTimeDelayTVD();
    
-  zdetC = TMath::Abs(param->GetZPosition("T0/C/PMT1"));
-  zdetA  = TMath::Abs(param->GetZPosition("T0/A/PMT15"));
+  zdetC = TMath::Abs(fParam->GetZPosition("T0/C/PMT1"));
+  zdetA  = TMath::Abs(fParam->GetZPosition("T0/A/PMT15"));
   
   AliT0hit  *startHit;
   TBranch *brHits=0;
@@ -241,9 +257,9 @@ void AliT0Digitizer::Exec(Option_t* /*option*/)
        if(timeGaus[ipmt]<besttimeC){
          besttimeC=timeGaus[ipmt]; //timeC
          pmtBestC=ipmt;}
-     }
+      }
     }
-     for ( Int_t ipmt=12; ipmt<24; ipmt++){
+    for ( Int_t ipmt=12; ipmt<24; ipmt++){
       if(countE[ipmt] > threshold) {
        timeGaus[ipmt]=gRandom->Gaus(time[ipmt],25); 
        if(timeGaus[ipmt]<besttimeA) {
@@ -251,25 +267,10 @@ void AliT0Digitizer::Exec(Option_t* /*option*/)
          pmtBestA=ipmt;}
       }        
     }
-   //folding with alignmentz position distribution  
-    if( besttimeC > 10000. && besttimeC <15000)
-      bestCTDC=Int_t ((besttimeC+timeDelayCFD[pmtBestC])
-                        /channelWidth);
-    if( besttimeA > 10000. && besttimeA <15000)
-      bestATDC=Int_t ((besttimeA+timeDelayCFD[pmtBestA])
-                       /channelWidth);
 
-    if (bestATDC < 99999 && bestCTDC < 99999)
-      {
-       timeDiff=Int_t (((besttimeC-besttimeA)+1000*delayVertex)
-                       /channelWidth);
-       meanTime=Int_t (((besttimeC+timeDelayCFD[pmtBestC]+
-                         besttimeA+timeDelayCFD[pmtBestA])/2.)
-                       /channelWidth);
-      }
-       AliDebug(10,Form(" time A& C %i %i  time diff && mean time in channels %i %i",bestATDC,bestCTDC, timeDiff, meanTime));
-         timeDelayCFD[0] = param->GetTimeDelayCFD(0);
+    timeDelayCFD[0] = fParam->GetTimeDelayCFD(0);
+    Int_t meanTimeDelay=200;
+
     for (Int_t i=0; i<24; i++)
       {
                Float_t  al = countE[i]; 
@@ -281,13 +282,13 @@ void AliT0Digitizer::Exec(Option_t* /*option*/)
          // channel 25ps
          qt= 50.*al/ph2Mip;  // 50mv/Mip amp in mV 
          //  fill TDC
-         timeDelayCFD[i] = param->GetTimeDelayCFD(i);
+         timeDelayCFD[i] = fParam->GetTimeDelayCFD(i);
          trCFD = Int_t (timeGaus[i]/channelWidth + (timeDelayCFD[i]-timeDelayCFD[0])); 
-         //      trLED= Int_t (timeGaus[i] + timeDelayLED[i]); 
-         TGraph* gr = param ->GetAmpLED(i);
+         TGraph* gr = ((TGraph*)fAmpLED.At(i));
          sl = gr->Eval(qt);
+
          trLED = Int_t(( timeGaus[i] + 1000*sl )/channelWidth);
-         qtCh=Int_t (1000.*TMath::Log(qt)) / channelWidth;
+         qtCh=Int_t (1000.*TMath::Log(qt) / channelWidth);
          fADC0->AddAt(0,i);
          fADC->AddAt(qtCh,i);
          ftimeLED->AddAt(trLED,i); 
@@ -295,7 +296,7 @@ void AliT0Digitizer::Exec(Option_t* /*option*/)
          sumMult += Int_t (qt/sumMultCoeff)  ;
         
          // put slewing 
-         TGraph* fu = param ->GetWalk(i);
+         TGraph *fu=(TGraph*) fParam ->GetWalk(i) ;
          Float_t slew=fu->Eval(Float_t(qtCh));
          hr=fu->GetHistogram();
          Float_t maxValue=hr->GetMaximum(50);
@@ -309,6 +310,23 @@ void AliT0Digitizer::Exec(Option_t* /*option*/)
        }
       } //pmt loop
 
+    //folding with alignmentz position distribution  
+    if( besttimeC > 10000. && besttimeC <15000)
+      bestCTDC=Int_t ((besttimeC+timeDelayCFD[pmtBestC])
+                        /channelWidth);
+    if( besttimeA > 10000. && besttimeA <15000)
+      bestATDC=Int_t ((besttimeA+timeDelayCFD[pmtBestA])
+                       /channelWidth);
+
+    if (bestATDC < 99999 && bestCTDC < 99999)
+      {
+       timeDiff=Int_t (((besttimeC-besttimeA)+1000*delayVertex)
+                       /channelWidth);
+       meanTime=Int_t (((besttimeC+besttimeA)/2. + meanTimeDelay)/channelWidth);
+      }
+       AliDebug(10,Form(" time A& C %i %i  time diff && mean time in channels %i %i",bestATDC,bestCTDC, timeDiff, meanTime));
+
     if (sumMult > threshold){
       fSumMult =  Int_t (1000.* TMath::Log(Double_t(sumMult) / Double_t(sumMultCoeff))
                         /channelWidth);
@@ -316,10 +334,11 @@ void AliT0Digitizer::Exec(Option_t* /*option*/)
                      sumMult, fSumMult, fSumMult*channelWidth));
     }
 
-      fT0->AddDigit(bestATDC,bestCTDC,meanTime,timeDiff,fSumMult,
+    fT0->AddDigit(bestATDC,bestCTDC,meanTime,timeDiff,fSumMult, refpoint,
                       ftimeCFD,fADC0,ftimeLED,fADC);
      
-      AliDebug(10,Form(" Digits wrote bestATDC %i bestCTDC %i  meanTime %i  timeDiff %i fSumMult %i ", bestATDC,bestCTDC,meanTime,timeDiff,fSumMult ));
+    
+      AliDebug(10,Form(" Digits wrote refpoint %i bestATDC %i bestCTDC %i  meanTime %i  timeDiff %i fSumMult %i ",refpoint ,bestATDC,bestCTDC,meanTime,timeDiff,fSumMult ));
     pOutStartLoader->UnloadHits();
   } //input streams loop