]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - T0/AliT0Reconstructor.cxx
with TOF satisfied request about writng in ESD T0 spread
[u/mrichter/AliRoot.git] / T0 / AliT0Reconstructor.cxx
index 5b61a32a3b84861d63fe7449bff4216d60709f73..5bc175fffdb8161e56f4c2d3ae9e078a9d51d62a 100644 (file)
@@ -1,4 +1,5 @@
 
+
 /**************************************************************************
  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  *                                                                        *
@@ -38,6 +39,8 @@
 #include "AliCDBManager.h"
 #include "AliCTPTimeParams.h"
 #include "AliLHCClockPhase.h"
+#include "AliT0CalibSeasonTimeShift.h"
+#include "AliESDRun.h"
 
 #include <TArrayI.h>
 #include <TGraph.h>
@@ -60,9 +63,13 @@ ClassImp(AliT0Reconstructor)
                                              fLatencyL1A(0),
                                              fLatencyL1C(0),
                                             fGRPdelays(0),
+                                            fTimeMeanShift(0x0),
+                                            fTimeSigmaShift(0x0),
                                              fESDTZEROfriend(NULL)
 
 {
+
+
   //constructor
   AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
   if (!entry) AliFatal("CTP timing parameters are not found in OCDB !");
@@ -80,6 +87,16 @@ ClassImp(AliT0Reconstructor)
 
   fGRPdelays = l1Delay - phase->GetMeanPhase();
 
+  AliCDBEntry *entry5 = AliCDBManager::Instance()->Get("T0/Calib/TimeAdjust");
+  if (entry5) {
+    AliT0CalibSeasonTimeShift *timeshift = (AliT0CalibSeasonTimeShift*)entry5->GetObject();
+    fTimeMeanShift = timeshift->GetT0Means();
+    fTimeSigmaShift  = timeshift->GetT0Sigmas();
+    //   timeshift->Print();
+   }
+  else
+    AliWarning("Time Adjust is not found in OCDB !");
+
   fParam = AliT0Parameters::Instance();
   fParam->Init();
  
@@ -159,7 +176,7 @@ void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
   Int_t pmtBestC=99999;
   
   AliT0RecPoint* frecpoints= new AliT0RecPoint ();
-  clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
+  clustersTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints);
   
   Float_t time[24], adc[24];
   for (Int_t ipmt=0; ipmt<24; ipmt++) {
@@ -173,12 +190,12 @@ void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
             
       Double_t sl = Double_t(timeLED->At(ipmt) - timeCFD->At(ipmt));
       //    time[ipmt] = fCalib-> WalkCorrection( refAmp,ipmt, Int_t(sl),  timeCFD->At(ipmt) ) ;
-      AliDebug(10,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
+      AliDebug(5,Form(" ipmt %i QTC %i , time in chann %i (led-cfd) %i ",
                       ipmt, Int_t(adc[ipmt]) ,Int_t(time[ipmt]),Int_t( sl)));
 
       Double_t ampMip =((TGraph*)fAmpLED.At(ipmt))->Eval(sl);
       Double_t qtMip = ((TGraph*)fQTC.At(ipmt))->Eval(adc[ipmt]);
-      AliDebug(10,Form("  Amlitude in MIPS LED %f ,  QTC %f in channels %f\n ",ampMip,qtMip, adc[ipmt]));
+      AliDebug(5,Form("  Amlitude in MIPS LED %f ,  QTC %f in channels %f\n ",ampMip,qtMip, adc[ipmt]));
       
       frecpoints->SetTime(ipmt, Float_t(time[ipmt]) );
       frecpoints->SetAmpLED(ipmt, Float_t( ampMip)); //for cosmic &pp beam 
@@ -214,7 +231,7 @@ void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
     frecpoints->SetTimeBestC(Int_t(besttimeC *channelWidth - fdZonA/c));
     tr[2]=true;
   }
-  AliDebug(10,Form(" besttimeA %f ch,  besttimeC %f ch",besttimeA, besttimeC));
+  AliDebug(5,Form(" besttimeA %f ch,  besttimeC %f ch",besttimeA, besttimeC));
   if(besttimeA <999999 && besttimeC < 999999 ){
     //    timeDiff = (besttimeC - besttimeA)*channelWidth;
     timeDiff = (besttimeA - besttimeC)*channelWidth;
@@ -228,7 +245,7 @@ void AliT0Reconstructor::Reconstruct(TTree*digitsTree, TTree*clustersTree) const
   frecpoints->SetT0clock(timeclock);
   frecpoints->SetT0Trig(tr);
 
-  AliDebug(10,Form("T0 triggers %d %d %d %d %d",tr[0],tr[1],tr[2],tr[3],tr[4]));
+  AliDebug(5,Form("T0 triggers %d %d %d %d %d",tr[0],tr[1],tr[2],tr[3],tr[4]));
 
   //online mean
   frecpoints->SetOnlineMean(Int_t(onlineMean));
@@ -259,24 +276,23 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
   Int_t refPoint = 0;
   //Bad channel
   Int_t badpmt = GetRecoParam()->GetRefPoint();
-  
   Int_t low[110], high[110];
 
   Int_t allData[110][5];
   
   Int_t timeCFD[24], timeLED[24], chargeQT0[24], chargeQT1[24];
-  Double32_t timeDiff=999999, meanTime=999999, timeclock=999999;
+  Double32_t timeDiff=999999, meanTime=999999, timeclock=9999999;
   Float_t c = 29.9792458; // cm/ns
   Double32_t vertex = 9999999;
   Int_t onlineMean=0;
   // Float_t meanVertex = fParam->GetMeanVertex();
   Float_t meanVertex = 0;
-  for (Int_t i0=0; i0<105; i0++)
+  for (Int_t i0=0; i0<110; i0++)
     {
       for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0; 
       low[i0] = Int_t (GetRecoParam()->GetLow(i0));    
       high[i0] = Int_t (GetRecoParam()->GetHigh(i0));
-    }
+      }
    
   Double32_t besttimeA=9999999;
   Double32_t besttimeC=9999999;
@@ -285,7 +301,7 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
    
   AliT0RecPoint* frecpoints= new AliT0RecPoint ();
   
-  recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints, 405,1);
+  recTree->Branch( "T0", "AliT0RecPoint" ,&frecpoints);
    
   AliDebug(10," before read data ");
   AliT0RawReader myrawreader(rawReader);
@@ -305,7 +321,7 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
       AliDebug(10,Form(" CDH BC ID %i, TRM BC ID %i \n", fBCID, trmbunch ));
  
       if(type == 7  ) {  //only physics 
-       for (Int_t i=0; i<105; i++) {
+       for (Int_t i=0; i<107; i++) {
        for (Int_t iHit=0; iHit<5; iHit++) 
          {
            allData[i][iHit] = myrawreader.GetData(i,iHit);
@@ -354,11 +370,12 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
                if(allData[in+1+68][iHit] > low[in+1+68] && 
                   allData[in+1+68][iHit] < high[in+1+68])
                  {
+
                    timeLED[in+12] = allData[in+68+1][iHit] ;
                    break;
                  }
              }
-           AliDebug(10, Form(" readed i %i cfdC %i cfdA %i ledC %i ledA%i ",
+           AliDebug(5, Form(" readed i %i cfdC %i cfdA %i ledC %i ledA%i ",
                              in, timeCFD[in],timeCFD[in+12],timeLED[in], 
                              timeLED[in+12]));   
            
@@ -391,7 +408,7 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
          }
        Double32_t time[24], adc[24],  noncalibtime[24];
        for (Int_t ipmt=0; ipmt<24; ipmt++) {
-         if(timeCFD[ipmt]>0 ){
+         if(timeCFD[ipmt]>0 && ipmt != badpmt ){
           //for simulated data
             //for physics  data
           if(( chargeQT0[ipmt] - chargeQT1[ipmt])>0)  {
@@ -423,17 +440,17 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
        }
        fESDTZEROfriend->SetT0timeCorr(noncalibtime) ;     
        for (Int_t ipmt=0; ipmt<12; ipmt++){
-        if(time[ipmt] > 1 && ipmt != badpmt )
+        if(time[ipmt] > 1 && ipmt != badpmt && adc[ipmt]>0.1 )
           {
             if(time[ipmt]<besttimeC){
-              besttimeC=time[ipmt]; //timeC
-              pmtBestC=ipmt;
+                 besttimeC=time[ipmt]; //timeC
+                 pmtBestC=ipmt;
             }
           }
        }
        for ( Int_t ipmt=12; ipmt<24; ipmt++)
         {
-          if(time[ipmt] > 1 && ipmt != badpmt)
+          if(time[ipmt] > 1 && ipmt != badpmt && adc[ipmt]>0.1)
             {
               if(time[ipmt]<besttimeA) {
                 besttimeA=time[ipmt]; //timeA
@@ -442,19 +459,22 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
             }
         }
        if(besttimeA < 999999) 
-        frecpoints->SetTimeBestA(besttimeA * channelWidth - 1000.*fLatencyHPTDC + 1000.*fLatencyL1A - 1000.*fGRPdelays);
+        frecpoints->SetTimeBestA(besttimeA * channelWidth - 1000.*fLatencyHPTDC + 1000.*fLatencyL1A - 1000.*fGRPdelays - fTimeMeanShift[1]);
+
        if( besttimeC < 999999 ) 
-        frecpoints->SetTimeBestC(besttimeC * channelWidth - 1000.*fLatencyHPTDC +1000.*fLatencyL1C - 1000.*fGRPdelays);
-       AliDebug(10,Form(" pmtA %i besttimeA %f ps, pmtC %i besttimeC %f ps",
-                      pmtBestA,besttimeA, pmtBestC,  besttimeC));
+        frecpoints->SetTimeBestC(besttimeC * channelWidth - 1000.*fLatencyHPTDC +1000.*fLatencyL1C - 1000.*fGRPdelays - fTimeMeanShift[2]);
+       AliDebug(5,Form(" pmtA %i besttimeA %f shift A %f ps, pmtC %i besttimeC %f shiftC %f ps",
+                      pmtBestA,besttimeA, fTimeMeanShift[1],
+
+                      pmtBestC,  besttimeC,fTimeMeanShift[2]));
         if(besttimeA <999999 && besttimeC < 999999 ){
         timeDiff = ( besttimeA - besttimeC)* 0.001* channelWidth + fLatencyL1A - fLatencyL1C;
-        timeclock = channelWidth * Float_t( besttimeA+besttimeC)/2. - 1000.*fLatencyHPTDC + 1000.*fLatencyL1 - 1000.*fGRPdelays;  
+        timeclock = channelWidth * Float_t( besttimeA+besttimeC)/2. - 1000.*fLatencyHPTDC + 1000.*fLatencyL1 - 1000.*fGRPdelays - fTimeMeanShift[0];  
         meanTime = (besttimeA+besttimeC-2.*Float_t(ref))/2.;
         vertex =  meanVertex - c*(timeDiff)/2. ; //+ (fdZonA - fdZonC)/2; 
        }
       }  //if phys event       
-      AliDebug(5,Form("  timeDiff %f #channel,  meanTime %f #channel, TOFmean%f  vertex %f cm meanVertex %f online mean %i \n",timeDiff, meanTime,timeclock, vertex,meanVertex, onlineMean));
+      AliDebug(10,Form("  timeDiff %f #channel,  meanTime %f #channel, TOFmean%f  vertex %f cm meanVertex %f online mean %i \n",timeDiff, meanTime,timeclock, vertex,meanVertex, onlineMean));
       frecpoints->SetT0clock(timeclock);
       frecpoints->SetVertex(vertex);
       frecpoints->SetMeanTime(meanTime);
@@ -468,13 +488,19 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
        for (Int_t iHit=0; iHit<5; iHit++) 
          {
            Int_t trr=trchan[itr];
-           if(allData[trr][iHit] > low[trr] &&
-              allData[trr][iHit] < high[trr]&&
-              allData[trr][iHit] > 0) tr[itr]=true;
+           if( allData[trr][iHit] > 0) tr[itr]=true;
          }
       }
       frecpoints->SetT0Trig(tr);
-     } // if (else )raw data
+
+      //Set MPD
+      if(allData[53][0]>0 && allData[54][0]) 
+       frecpoints->SetMultA(allData[53][0]-allData[54][0]);
+       if(allData[105][0]>0 && allData[106][0]) 
+         frecpoints->SetMultC(allData[105][0]-allData[106][0]);
+       
+       
+    } // if (else )raw data
   recTree->Fill();
   if(frecpoints) delete frecpoints;
 }
@@ -490,10 +516,13 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
   ****************************************************/
   
   AliDebug(1,Form("Start FillESD T0"));
+  pESD ->SetT0spread(fTimeSigmaShift);
+
   Float_t channelWidth = fParam->GetChannelWidth() ;  
   Float_t c = 0.0299792458; // cm/ps
   Float_t currentVertex=0, shift=0;
-  Int_t ncont=0;
+  Int_t ncont=-1;
   const AliESDVertex* vertex = pESD->GetPrimaryVertex();
   if (!vertex)        vertex = pESD->GetPrimaryVertexSPD();
   if (!vertex)        vertex = pESD->GetPrimaryVertexTPC();
@@ -506,7 +535,7 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
     
     ncont = vertex->GetNContributors();
     //  cout<<"@@ spdver "<<spdver<<" ncont "<<ncont<<endl;
-    if(ncont>2 ) {
+    if(ncont>0 ) {
       shift = currentVertex/c;
     }
   }
@@ -533,6 +562,7 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
   for(Int_t i=0; i<24; i++) 
     amp[i]=time[i]=ampQTC[i]=timecorr[i]=0;
 
+
   Double32_t timeClock[3];
   Double32_t zPosition = frecpoints -> GetVertex();
   Double32_t timeStart = frecpoints -> GetMeanTime();
@@ -551,7 +581,14 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
   pESD->SetT0Trig(trig);
   
   pESD->SetT0zVertex(zPosition); //vertex Z position 
-  pESD->SetT0(timeStart);        // interaction time 
+
+  Double32_t multA=frecpoints ->GetMultA();
+  Double32_t multC=frecpoints ->GetMultC();
+  //  pESD->SetT0MultC(multC);        // multiplicity Cside 
+  //  pESD->SetT0MultA(multA);        // multiplicity Aside 
+  pESD->SetT0(multA); // for backward compatubility
+  pESD->SetT0clock(multC); // for backward compatubility
+
   for(Int_t i=0; i<3; i++) 
     pESD->SetT0TOF(i,timeClock[i]);   // interaction time (ns) 
   pESD->SetT0time(time);         // best TOF on each PMT 
@@ -570,7 +607,7 @@ void AliT0Reconstructor::Reconstruct(AliRawReader* rawReader, TTree*recTree) con
        for ( Int_t i=0; i<24; i++) {
          if(i<12 && time[i]>1) timecorr[i] = tcorr[i] -  shift/channelWidth;
          if(i>11 && time[i]>1) timecorr[i] = tcorr[i] +  shift/channelWidth;
-         if(time[i]>1)   AliDebug(1,Form("T0 friend : time %f  ampQTC %f ampLED %f \n", timecorr[i], ampQTC[i], amp[i]));
+         if(time[i]>1)   AliDebug(10,Form("T0 friend : time %f  ampQTC %f ampLED %f \n", timecorr[i], ampQTC[i], amp[i]));
        }
        fESDTZEROfriend->SetT0timeCorr( timecorr) ;
        fESDTZEROfriend->SetT0ampLEDminCFD(amp);