]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDCalibraFillHisto.cxx
Added to AliITSMultReconstructor flagging of tracks
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraFillHisto.cxx
index 4e0b3c68468ded28a3a6883c463c1cf7894b8b56..be1b40249c72530ab810d1271859d3329051b5ae 100644 (file)
@@ -28,8 +28,9 @@
 // in the function "FollowBackProlongation" (AliTRDtracker)
 // Per default the functions to fill are off.                                   
 //                        
-// Author:
-//   R. Bailhache (R.Bailhache@gsi.de)
+// Authors:
+//   R. Bailhache (R.Bailhache@gsi.de, rbailhache@ikf.uni-frankfurt.de)
+//   J. Book (jbook@ikf.uni-frankfurt.de)
 //                            
 //////////////////////////////////////////////////////////////////////////////////////
 
 #include "./Cal/AliTRDCalROC.h"
 #include "./Cal/AliTRDCalDet.h"
 
+#include "AliTRDrawFastStream.h"
+#include "AliTRDdigitsManager.h"
+#include "AliTRDdigitsParam.h"
+#include "AliTRDSignalIndex.h"
+#include "AliTRDarrayADC.h"
+
 #ifdef ALI_DATE
 #include "event.h"
 #endif
@@ -119,6 +126,7 @@ void AliTRDCalibraFillHisto::Terminate()
 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
   :TObject()
   ,fGeo(0)
+  ,fCalibDB(0)
   ,fIsHLT(kFALSE)
   ,fCH2dOn(kFALSE)
   ,fPH2dOn(kFALSE)
@@ -134,6 +142,10 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
   ,fNormalizeNbOfCluster(kFALSE)
   ,fMaxCluster(0)
   ,fNbMaxCluster(0)
+  ,fVersionGainUsed(0)
+  ,fSubVersionGainUsed(0)
+  ,fVersionVdriftUsed(0) 
+  ,fSubVersionVdriftUsed(0)
   ,fCalibraMode(new AliTRDCalibraMode())
   ,fDebugStreamer(0)
   ,fDebugLevel(0)
@@ -142,6 +154,10 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
   ,fROBPrevious(-1)
   ,fNumberClusters(1)
   ,fNumberClustersf(30)
+  ,fNumberClustersProcent(0.5)
+  ,fThresholdClustersDAQ(120.0)
+  ,fNumberRowDAQ(2)
+  ,fNumberColDAQ(4)
   ,fProcent(6.0)
   ,fDifference(17)
   ,fNumberTrack(0)
@@ -180,13 +196,14 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
   fNumberUsedPh[1]       = 0;
   
   fGeo = new AliTRDgeometry();
-
+  fCalibDB = AliTRDcalibDB::Instance();
 }
 
 //______________________________________________________________________________________
 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
   :TObject(c)
   ,fGeo(0)
+  ,fCalibDB(0)
   ,fIsHLT(c.fIsHLT)
   ,fCH2dOn(c.fCH2dOn)
   ,fPH2dOn(c.fPH2dOn)
@@ -202,6 +219,10 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
   ,fNormalizeNbOfCluster(c.fNormalizeNbOfCluster)
   ,fMaxCluster(c.fMaxCluster)
   ,fNbMaxCluster(c.fNbMaxCluster)
+  ,fVersionGainUsed(c.fVersionGainUsed)
+  ,fSubVersionGainUsed(c.fSubVersionGainUsed)
+  ,fVersionVdriftUsed(c.fVersionVdriftUsed) 
+  ,fSubVersionVdriftUsed(c.fSubVersionVdriftUsed)
   ,fCalibraMode(0x0)
   ,fDebugStreamer(0)
   ,fDebugLevel(c.fDebugLevel)
@@ -210,6 +231,10 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
   ,fROBPrevious(c.fROBPrevious)
   ,fNumberClusters(c.fNumberClusters)
   ,fNumberClustersf(c.fNumberClustersf)
+  ,fNumberClustersProcent(c.fNumberClustersProcent)
+  ,fThresholdClustersDAQ(c.fThresholdClustersDAQ)
+  ,fNumberRowDAQ(c.fNumberRowDAQ)
+  ,fNumberColDAQ(c.fNumberColDAQ)
   ,fProcent(c.fProcent)
   ,fDifference(c.fDifference)
   ,fNumberTrack(c.fNumberTrack)
@@ -262,6 +287,7 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
     delete fGeo;
   }
   fGeo = new AliTRDgeometry();
+  fCalibDB = AliTRDcalibDB::Instance();
 }
 
 //____________________________________________________________________________________
@@ -289,6 +315,7 @@ AliTRDCalibraFillHisto::~AliTRDCalibraFillHisto()
     TLinearFitter *f = (TLinearFitter*)fLinearFitterArray.At(idet);
     if(f) { delete f;}
   }
+  if(fLinearVdriftFit) delete fLinearVdriftFit;
   if (fGeo) {
     delete fGeo;
   }
@@ -342,7 +369,7 @@ void AliTRDCalibraFillHisto::ClearHistos()
 // calibration with AliTRDtrackV1: Init, Update 
 //////////////////////////////////////////////////////////////////////////////////
 //____________Functions for initialising the AliTRDCalibraFillHisto in the code_________
-Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
+Bool_t AliTRDCalibraFillHisto::Init2Dhistos(Int_t nboftimebin)
 {
   //
   // Init the histograms and stuff to be filled 
@@ -362,12 +389,17 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
   }
 
   // Some parameters
-  fTimeMax            = cal->GetNumberOfTimeBins();
+  if(nboftimebin > 0) fTimeMax = nboftimebin;
+  else fTimeMax = cal->GetNumberOfTimeBinsDCS();
+  if(fTimeMax <= 0) fTimeMax = 30;
+  printf("////////////////////////////////////////////\n");
+  printf("Number of time bins in calibration component %d\n",fTimeMax);
+  printf("////////////////////////////////////////////\n");
   fSf                 = parCom->GetSamplingFrequency();
   if(!fNormalizeNbOfCluster) fRelativeScale = 20.0;
   else fRelativeScale = 1.18;
   fNumberClustersf    = fTimeMax;
-  fNumberClusters     = (Int_t)(0.5*fTimeMax);
+  fNumberClusters     = (Int_t)(fNumberClustersProcent*fTimeMax);
  
   // Init linear fitter
   if(!fLinearFitterTracklet) {
@@ -453,11 +485,12 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
     }
   }
   if (fLinearFitterOn) {
-    //fLinearFitterArray.Expand(540);
-    fLinearFitterArray.SetName("ArrayLinearFitters");
-    fEntriesLinearFitter = new Int_t[540];
-    for(Int_t k = 0; k < 540; k++){
-      fEntriesLinearFitter[k] = 0;
+    if(fLinearFitterDebugOn) {
+      fLinearFitterArray.SetName("ArrayLinearFitters");
+      fEntriesLinearFitter = new Int_t[540];
+      for(Int_t k = 0; k < 540; k++){
+       fEntriesLinearFitter[k] = 0;
+      }
     }
     fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit();
   }
@@ -623,14 +656,22 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t)
   
   const AliTRDseedV1 *tracklet = 0x0;          // tracklet per plane
   AliTRDcluster *cl      = 0x0;                // cluster attached now to the tracklet
+  AliTRDcluster *cls     = 0x0;                // shared cluster attached now to the tracklet
   Bool_t         newtr   = kTRUE;              // new track
   
   // Get cal
-  AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
+  //  AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
+  /*
   if (!cal) {
     AliInfo("Could not get calibDB");
     return kFALSE;
   }
+*/
+  if (!fCalibDB) {
+    AliInfo("Could not get calibDB");
+    return kFALSE;
+  }
+
   
   ///////////////////////////
   // loop over the tracklet
@@ -664,9 +705,9 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t)
       if( fCalROCGain ){ 
        if(!fIsHLT){    
          fCalROCGain->~AliTRDCalROC();
-         new(fCalROCGain) AliTRDCalROC(*(cal->GetGainFactorROC(detector)));
+         new(fCalROCGain) AliTRDCalROC(*(fCalibDB->GetGainFactorROC(detector)));
        }
-      }else fCalROCGain = new AliTRDCalROC(*(cal->GetGainFactorROC(detector)));
+      }else fCalROCGain = new AliTRDCalROC(*(fCalibDB->GetGainFactorROC(detector)));
       
       // reset
       fDetectorPreviousTrack = detector;
@@ -688,7 +729,10 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t)
       Int_t     group[2] = {0,0};
       if(fCH2dOn)  group[0]  = CalculateCalibrationGroup(0,row,col);
       if(fPH2dOn)  group[1]  = CalculateCalibrationGroup(1,row,col);
-      StoreInfoCHPHtrack(cl, tracklet->GetdQdl(jc),group,row,col);
+      // Add the charge if shared cluster
+      cls = tracklet->GetClusters(jc+AliTRDseedV1::kNtb);
+      //
+      StoreInfoCHPHtrack(cl, tracklet->GetdQdl(jc),group,row,col,cls);
     }
     
     ////////////////////////////////////////
@@ -852,11 +896,11 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtracklet(const AliTRDtrack *t, Int_t
     //Add to the linear fitter of the detector
     if( TMath::Abs(snp) <  1.){
       Double_t x = tnp-dzdx*tnt; 
-      (GetLinearFitter(detector,kTRUE))->AddPoint(&x,dydt);
       if(fLinearFitterDebugOn) {
-       fLinearVdriftFit->Update(detector,x,pars[1]);
+       (GetLinearFitter(detector,kTRUE))->AddPoint(&x,dydt);
+       fEntriesLinearFitter[detector]++;
       }
-      fEntriesLinearFitter[detector]++;
+      fLinearVdriftFit->Update(detector,x,pars[1]);
     }
   }
   
@@ -915,6 +959,15 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *track
   ////////////////////////////
   Int_t  nbli = 0;
   AliTRDcluster *cl                   = 0x0;
+  //////////////////////////////
+  // Check no shared clusters
+  //////////////////////////////
+  for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
+    if((cl = tracklet->GetClusters(icc)))  crossrow = 1;
+  }
+  //////////////////////////////////
+  // Loop clusters
+  //////////////////////////////////
   for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
     if(!(cl = tracklet->GetClusters(ic))) continue;
     if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
@@ -930,12 +983,7 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *track
     fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
     nbli++;  
 
-    //////////////////////////////
-    // Check no shared clusters
-    //////////////////////////////
-    for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
-      if((cl = tracklet->GetClusters(icc)))  crossrow = 1;
-    }
+    
   }
   
   ////////////////////////////////////
@@ -1006,11 +1054,11 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *track
     //Add to the linear fitter of the detector
     if( TMath::Abs(snp) <  1.){
       Double_t x = tnp-dzdx*tnt; 
-      (GetLinearFitter(fDetectorPreviousTrack,kTRUE))->AddPoint(&x,dydt);
       if(fLinearFitterDebugOn) {
-       fLinearVdriftFit->Update(fDetectorPreviousTrack,x,pars[1]);
+       (GetLinearFitter(fDetectorPreviousTrack,kTRUE))->AddPoint(&x,dydt);
+       fEntriesLinearFitter[fDetectorPreviousTrack]++;
       }
-      fEntriesLinearFitter[fDetectorPreviousTrack]++;
+      fLinearVdriftFit->Update(fDetectorPreviousTrack,x,pars[1]);
     }
   }
   
@@ -1898,16 +1946,23 @@ void AliTRDCalibraFillHisto::SetNumberGroupsPRF(Short_t numberGroupsPRF)
 // Per tracklet: store or reset the info, fill the histos with the info
 //////////////////////////////////////////////////////////////////////////////////////////
 //_____________________________________________________________________________
-void AliTRDCalibraFillHisto::StoreInfoCHPHtrack(const AliTRDcluster *cl,const Double_t dqdl,const Int_t *group,const Int_t row,const Int_t col)
+void AliTRDCalibraFillHisto::StoreInfoCHPHtrack(const AliTRDcluster *cl,const Double_t dqdl,const Int_t *group,const Int_t row,const Int_t col,const AliTRDcluster *cls)
 {
   //
   // Store the infos in fAmpTotal, fPHPlace and fPHValue
   // Correct from the gain correction before
+  // cls is shared cluster if any
   //
   
+  //printf("StoreInfoCHPHtrack\n");
+
   // time bin of the cluster not corrected
   Int_t    time     = cl->GetPadTime();
   Float_t  charge   = TMath::Abs(cl->GetQ());  
+  if(cls) {
+    charge += TMath::Abs(cls->GetQ());
+    //printf("AliTRDCalibraFillHisto::Add the cluster charge");
+  }
 
   //printf("Store::time %d, amplitude %f\n",time,dqdl);
   
@@ -2301,6 +2356,8 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bo
   // 2 input
   // Same algorithm as TestBeam but different reader
   //
+
+  rawStream->SetSharedPadReadout(kFALSE);
   
   Int_t withInput = 1;
   
@@ -2318,8 +2375,8 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bo
   fROBPrevious           = -1;
   Int_t nbtimebin = 0;                                        
   Int_t baseline  = 10;  
-
-
+  //printf("------------Detector\n");
+  
   if(!nocheck){
   
     fTimeMax = 0;
@@ -2337,7 +2394,7 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bo
        // Fill
        withInput = TMath::Max(FillDAQ(phvalue),withInput);
 
-
+       
        // reset
        for(Int_t k = 0; k < 36; k++){
          for(Int_t j = 0; j < 16; j++){
@@ -2359,7 +2416,7 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bo
 
       //baseline          = rawStream->GetCommonAdditive();                // common additive baseline
       fNumberClustersf    = fTimeMax;
-      fNumberClusters     = (Int_t)(0.6*fTimeMax);
+      fNumberClusters     = (Int_t)(fNumberClustersProcent*fTimeMax);
 
 
       Int_t *signal     = rawStream->GetSignals();                       //  current ADC signal
@@ -2367,7 +2424,7 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bo
       Int_t row         = rawStream->GetRow();    
 
       
-      //printf("detector %d, signal[0] %d, signal[1] %d, signal[2] %d, baseline %d\n",idetector,signal[0],signal[1],signal[2], baseline);
+      // printf("detector %d, signal[0] %d, signal[1] %d, signal[2] %d, baseline %d\n",idetector,signal[0],signal[1],signal[2], baseline);
      
                 
       for(Int_t itime = 0; itime < nbtimebin; itime++){
@@ -2394,7 +2451,7 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bo
   }
   else{
 
-    while (rawStream->Next()) {
+    while (rawStream->Next()) { //iddetecte
 
       Int_t idetector = rawStream->GetDet();                            //  current detector
       Int_t imcm      = rawStream->GetMCM();                            //  current MCM
@@ -2425,7 +2482,7 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bo
       
       fTimeMax          = rawStream->GetNumberOfTimeBins();              //  number of time bins read from data
       fNumberClustersf    = fTimeMax;
-      fNumberClusters     = (Int_t)(0.6*fTimeMax);
+      fNumberClusters     = (Int_t)(fNumberClustersProcent*fTimeMax);
       Int_t *signal     = rawStream->GetSignals();                       //  current ADC signal
       Int_t col         = rawStream->GetCol();
       Int_t row         = rawStream->GetRow();   
@@ -2435,6 +2492,14 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bo
       
       for(Int_t itime = 0; itime < fTimeMax; itime++){
        phvalue[row][col][itime] = signal[itime]-baseline;
+       /*if(phvalue[row][col][itime] >= 20) {
+               printf("----------> phvalue[%d][%d][%d] %d  baseline %d \n",
+                      row,
+                      col,
+                      itime,
+                      signal[itime],
+                      baseline);
+                      }*/
       }
     }
     
@@ -2500,6 +2565,146 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(
 #endif
 
 }
+//_____________________________________________________________________
+Int_t AliTRDCalibraFillHisto::ProcessEventDAQ2(AliRawReader *rawReader)
+ { //main
+  //
+  // Event Processing loop - AliTRDrawFastStream
+  // 
+  // 0 timebin problem
+  // 1 no input
+  // 2 input
+  // Same algorithm as TestBeam but different reader
+  //
+
+   //  AliTRDrawFastStream *rawStream = AliTRDrawFastStream::GetRawStream(rawReader);
+  AliTRDrawFastStream *rawStream = new AliTRDrawFastStream(rawReader);
+  rawStream->SetNoErrorWarning();
+  rawStream->SetSharedPadReadout(kFALSE);
+
+  AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
+  digitsManager->CreateArrays();
+    
+  Int_t withInput = 1;
+  
+  Double_t phvalue[16][144][36];
+  for(Int_t k = 0; k < 36; k++){
+    for(Int_t j = 0; j < 16; j++){
+      for(Int_t c = 0; c < 144; c++){
+       phvalue[j][c][k] = 0.0;
+      }
+    }
+  }
+  
+  fDetectorPreviousTrack = -1;
+  fMCMPrevious           = -1;
+  fROBPrevious           = -1;
+  
+  Int_t nbtimebin = 0;                                        
+  Int_t baseline  = 10;  
+
+  
+    fTimeMax = 0;
+       
+    Int_t det    = 0;
+    while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
+
+      if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
+       //      printf("there is ADC data on this chamber!\n");
+
+       AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
+       if (digits->HasData()) { //array
+         
+         AliTRDSignalIndex   *indexes = digitsManager->GetIndexes(det);
+         if (indexes->IsAllocated() == kFALSE) {
+           AliError("Indexes do not exist!");
+           break;
+         }
+         Int_t iRow  = 0;
+         Int_t iCol  = 0;
+         indexes->ResetCounters();
+         
+         while (indexes->NextRCIndex(iRow, iCol)) { //column,row
+           //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
+           //while (rawStream->Next()) {
+           
+           Int_t idetector = det;                                             //  current detector
+           //Int_t imcm      = rawStream->GetMCM();                            //  current MCM
+           //Int_t irob      = rawStream->GetROB();                            //  current ROB
+           
+         
+           if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
+             // Fill
+             withInput = TMath::Max(FillDAQ(phvalue),withInput);
+             
+             // reset
+             for(Int_t k = 0; k < 36; k++){
+               for(Int_t j = 0; j < 16; j++){
+                 for(Int_t c = 0; c < 144; c++){
+                   phvalue[j][c][k] = 0.0;
+                 }
+               }
+             }
+           }
+           
+           fDetectorPreviousTrack = idetector;
+           //fMCMPrevious           = imcm;
+           //fROBPrevious           = irob;
+           
+           //    nbtimebin              = rawStream->GetNumberOfTimeBins();              //  number of time bins read from data
+           AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
+           nbtimebin              = digitParam->GetNTimeBins(det);              //  number of time bins read from data
+           baseline               = digitParam->GetADCbaseline(det);            //  baseline
+           
+           if(nbtimebin == 0) return 0;
+           if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
+           fTimeMax          = nbtimebin;
+           
+           fNumberClustersf    = fTimeMax;
+           fNumberClusters     = (Int_t)(fNumberClustersProcent*fTimeMax);
+                 
+           
+           for(Int_t itime = 0; itime < nbtimebin; itime++) {
+             //            phvalue[row][col][itime] = signal[itime]-baseline;
+             phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
+             /*if(phvalue[iRow][iCol][itime] >= 20) {
+                printf("----------> phvalue[%d][%d][%d] %d  baseline %d \n",
+                      iRow,
+                      iCol,
+                      itime,
+                      (Short_t)(digits->GetData(iRow,iCol,itime)),
+                      baseline);
+                      }*/
+           }
+           
+         }//column,row
+         
+         // fill the last one
+         if(fDetectorPreviousTrack != -1){
+           
+           // Fill
+           withInput = TMath::Max(FillDAQ(phvalue),withInput);
+           //      printf("\n ---> withinput %d\n\n",withInput);
+           // reset
+           for(Int_t k = 0; k < 36; k++){
+             for(Int_t j = 0; j < 16; j++){
+               for(Int_t c = 0; c < 144; c++){
+                 phvalue[j][c][k] = 0.0;
+               }
+             }
+           }
+         }
+         
+       }//array
+      }//QA
+      digitsManager->ClearArrays(det);
+    }//idetector
+    delete digitsManager;
+
+    delete rawStream;
+    return withInput;
+ }//main
+//_____________________________________________________________________
 //////////////////////////////////////////////////////////////////////////////
 // Routine inside the DAQ process
 /////////////////////////////////////////////////////////////////////////////
@@ -2538,9 +2743,9 @@ Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
       for (Int_t ic = 2; ic <= 142; ic++)
        {
          Double_t integral = 0;                  
-         for (Int_t ishiftR = 0; ishiftR < 2; ishiftR++)
+         for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
            {
-             for (Int_t ishiftC = -2; ishiftC < 2; ishiftC++)
+             for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
                {
                  if (ir + ishiftR >= 1 && ir + ishiftR <= 16 &&
                      ic + ishiftC >= 1 && ic + ishiftC <= 144)
@@ -2552,19 +2757,23 @@ Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
                    } //addsignal
                } //shiftC
            } // shiftR
-         
          if (integralMax < integral)
            {
              imaxRow = ir;
              imaxCol = ic;
              integralMax = integral;
+             
            } // check max integral
        } //ic
     } // ir
 
-  //printf("imaxRow %d, imaxCol %d, fTimeMax %d, integralMax %f\n",imaxRow,imaxCol,fTimeMax, integralMax);
+  //  printf("imaxRow %d, imaxCol %d, fTimeMax %d, integralMax %f\n",imaxRow,imaxCol,fTimeMax, integralMax);
+  //if((imaxRow == 0) || (imaxRow >= 15) || (imaxCol <= 3) || (imaxCol >= 140)) {
+  //  used=1;
+  //  return used;
+  // }
 
-  if((imaxRow == 0) || (imaxCol == 0)) {
+  if(((imaxRow + fNumberRowDAQ) > 16) || (imaxRow == 0) || ((imaxCol - fNumberColDAQ) <= 1) || ((imaxCol + fNumberColDAQ) >= 144)) {
     used=1;
     return used;
   }
@@ -2576,21 +2785,26 @@ Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
   //  ////////////////////////////////////////////////////       
   
   
-  for (Int_t ir = imaxRow - 1; ir < imaxRow + 1; ir++)
+  
+  for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
     {
-      for (Int_t ic = imaxCol - 2; ic < imaxCol + 2; ic++)
+      for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
        {
-         for(Int_t it = 0; it < fTimeMax; it++){
-           sum[it] += phvalue[ir][ic][it];
-         }
-       }//ic
-    }//ir  
+         if (imaxRow + ishiftR >= 1 && imaxRow + ishiftR <= 16 &&
+             imaxCol + ishiftC >= 1 && imaxCol + ishiftC <= 144)
+           { 
+             for(Int_t it = 0; it < fTimeMax; it++){
+               sum[it] += phvalue[imaxRow + ishiftR-1][imaxCol + ishiftC-1][it];
+             } 
+           }
+       } // col shift
+    }// row shift
 
   Int_t nbcl = 0;
   Double_t sumcharge = 0.0;
   for(Int_t it = 0; it < fTimeMax; it++){
     sumcharge += sum[it];
-    if(sum[it] > 20.0) nbcl++;
+    if(sum[it] > fThresholdClustersDAQ)  nbcl++;
   }
 
 
@@ -2623,6 +2837,7 @@ Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
       "clustera="<<clustera<<
       "it="<<it<<
       "rms="<<rms<<
+      "nbcl="<<nbcl<<
       "\n"; 
     }
   }
@@ -2630,6 +2845,7 @@ Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
   ////////////////////////////////////////////////////////
   // fill
   ///////////////////////////////////////////////////////
+  //printf("fNumberClusters %d, fNumberClustersf %d\n",fNumberClusters,fNumberClustersf);
   if(sum[0] > 100.0) used = 1; 
   if(nbcl < fNumberClusters) used = 1;
   if(nbcl > fNumberClustersf) used = 1;
@@ -2644,6 +2860,10 @@ Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
       else{
        if(sum[it] > 0.0) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax); 
       } 
+      //if(fFillWithZero) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
+      //else{
+      // if(sum[it] > 0.0) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
+      //}
     }
     
    
@@ -2724,7 +2944,7 @@ void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
     }
   }
   if(fLinearFitterOn){
-    AnalyseLinearFitter();
+    if(fLinearFitterDebugOn) AnalyseLinearFitter();
     f.WriteTObject(fLinearVdriftFit);
   }
    
@@ -2989,7 +3209,11 @@ void AliTRDCalibraFillHisto::CreatePH2d(Int_t nn)
   // Create the 2D histos
   //
 
-  TString name("Nz");
+  TString name("Ver");
+  name += fVersionVdriftUsed;
+  name += "Subver";
+  name += fSubVersionVdriftUsed;
+  name += "Nz";
   name += fCalibraMode->GetNz(1);
   name += "Nrphi";
   name += fCalibraMode->GetNrphi(1);
@@ -3010,11 +3234,15 @@ void AliTRDCalibraFillHisto::CreateCH2d(Int_t nn)
   // Create the 2D histos
   //
 
-  TString name("Nz");
+  TString name("Ver");
+  name += fVersionGainUsed;
+  name += "Subver";
+  name += fSubVersionGainUsed;
+  name += "Nz";
   name += fCalibraMode->GetNz(0);
   name += "Nrphi";
   name += fCalibraMode->GetNrphi(0);
-
+  
   fCH2d = new TH2I("CH2d",(const Char_t *) name
                   ,fNumberBinCharge,0,300,nn,0,nn);
   fCH2d->SetYTitle("Det/pad groups");
@@ -3186,3 +3414,5 @@ void AliTRDCalibraFillHisto::AnalyseLinearFitter()
     }
   }
 }
+
+