]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDCalibraFillHisto.cxx
Update of calibration task and file for test shuttle
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraFillHisto.cxx
index 140c65277b2329fbda56f1f92165bd0e3896a082..82e0f721cb1e95045affc25e1ca336d689854803 100644 (file)
@@ -48,6 +48,7 @@
 #include <TDirectory.h>
 #include <TTreeStream.h>
 #include <TVectorD.h>
+#include <TLinearFitter.h>
 
 #include "AliLog.h"
 
@@ -119,7 +120,6 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
   :TObject()
   ,fGeo(0)
   ,fIsHLT(kFALSE)
-  ,fMcmCorrectAngle(kFALSE)
   ,fCH2dOn(kFALSE)
   ,fPH2dOn(kFALSE)
   ,fPRF2dOn(kFALSE)
@@ -142,14 +142,18 @@ 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)
   ,fTimeMax(0)
   ,fSf(10.0)
-  ,fNumberBinCharge(100)
-  ,fNumberBinPRF(40)
-  ,fNgroupprf(0)
+  ,fNumberBinCharge(50)
+  ,fNumberBinPRF(10)
+  ,fNgroupprf(3)
   ,fAmpTotal(0x0)
   ,fPHPlace(0x0)
   ,fPHValue(0x0)
@@ -188,7 +192,6 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
   :TObject(c)
   ,fGeo(0)
   ,fIsHLT(c.fIsHLT)
-  ,fMcmCorrectAngle(c.fMcmCorrectAngle)
   ,fCH2dOn(c.fCH2dOn)
   ,fPH2dOn(c.fPH2dOn)
   ,fPRF2dOn(c.fPRF2dOn)
@@ -211,6 +214,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)
@@ -290,6 +297,7 @@ AliTRDCalibraFillHisto::~AliTRDCalibraFillHisto()
     TLinearFitter *f = (TLinearFitter*)fLinearFitterArray.At(idet);
     if(f) { delete f;}
   }
+  if(fLinearVdriftFit) delete fLinearVdriftFit;
   if (fGeo) {
     delete fGeo;
   }
@@ -343,7 +351,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 
@@ -363,12 +371,14 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
   }
 
   // Some parameters
-  fTimeMax            = cal->GetNumberOfTimeBins();
+  if(nboftimebin > 0) fTimeMax = nboftimebin;
+  else fTimeMax = cal->GetNumberOfTimeBinsDCS();
+  if(fTimeMax <= 0) fTimeMax = 30;
   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) {
@@ -404,23 +414,10 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
       fCalibraVector->SetDetCha0(k,fCalibraMode->GetDetChamb0(k));
       fCalibraVector->SetDetCha2(k,fCalibraMode->GetDetChamb2(k));
     }
-    TString namech("Nz");
-    namech += fCalibraMode->GetNz(0);
-    namech += "Nrphi";
-    namech += fCalibraMode->GetNrphi(0);
-    fCalibraVector->SetNameCH((const char* ) namech);
-    TString nameph("Nz");
-    nameph += fCalibraMode->GetNz(1);
-    nameph += "Nrphi";
-    nameph += fCalibraMode->GetNrphi(1);
-    fCalibraVector->SetNamePH((const char* ) nameph);
-    TString nameprf("Nz");
-    nameprf += fCalibraMode->GetNz(2);
-    nameprf += "Nrphi";
-    nameprf += fCalibraMode->GetNrphi(2);
-    nameprf += "Ngp";
-    nameprf += fNgroupprf;
-    fCalibraVector->SetNamePRF((const char* ) nameprf);
+    fCalibraVector->SetNzNrphi(0,fCalibraMode->GetNz(0),fCalibraMode->GetNrphi(0));
+    fCalibraVector->SetNzNrphi(1,fCalibraMode->GetNz(1),fCalibraMode->GetNrphi(1));
+    fCalibraVector->SetNzNrphi(2,fCalibraMode->GetNz(2),fCalibraMode->GetNrphi(2));
+    fCalibraVector->SetNbGroupPRF(fNgroupprf);
   }
  
   // Create the 2D histos corresponding to the pad groupCalibration mode
@@ -467,11 +464,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();
   }
@@ -491,7 +489,7 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
 
 }
 //____________Offline tracking in the AliTRDtracker____________________________
-Bool_t AliTRDCalibraFillHisto::UpdateHistograms(AliTRDtrack *t)
+Bool_t AliTRDCalibraFillHisto::UpdateHistograms(const AliTRDtrack *t)
 {
   //
   // Use AliTRDtrack for the calibration
@@ -628,7 +626,7 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistograms(AliTRDtrack *t)
   
 }
 //____________Offline tracking in the AliTRDtracker____________________________
-Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(AliTRDtrackV1 *t)
+Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t)
 {
   //
   // Use AliTRDtrackV1 for the calibration
@@ -709,10 +707,12 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(AliTRDtrackV1 *t)
     // Fill the stuffs if a good tracklet
     ////////////////////////////////////////
     if (fGoodTracklet) {
-      
+
       // drift velocity unables to cut bad tracklets 
       Bool_t  pass = FindP1TrackPHtrackletV1(tracklet, nbclusters);
        
+      //printf("pass %d and nbclusters %d\n",pass,nbclusters);
+
       // Gain calibration
       if (fCH2dOn) {
        FillTheInfoOfTheTrackCH(nbclusters);
@@ -735,7 +735,7 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(AliTRDtrackV1 *t)
 // Routine inside the update with AliTRDtrack
 ///////////////////////////////////////////////////////////////////////////////////
 //____________Offine tracking in the AliTRDtracker_____________________________
-Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtracklet(AliTRDtrack *t, Int_t index0, Int_t index1)
+Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtracklet(const AliTRDtrack *t, Int_t index0, Int_t index1)
 {
   //
   // Drift velocity calibration:
@@ -864,11 +864,11 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtracklet(AliTRDtrack *t, Int_t index
     //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]);
     }
   }
   
@@ -927,6 +927,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;
@@ -942,12 +951,7 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *track
     fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
     nbli++;  
 
-    //////////////////////////////
-    // Check no shared clusters
-    //////////////////////////////
-    for(int ic=AliTRDseedV1::kNtb; ic<AliTRDseedV1::kNTimeBins; ic++){
-      if((cl = tracklet->GetClusters(ic)))  crossrow = 1;
-    }
+   
   }
   
   ////////////////////////////////////
@@ -1018,18 +1022,18 @@ 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]);
     }
   }
   
   return kTRUE;
 }
 //____________Offine tracking in the AliTRDtracker_____________________________
-Bool_t AliTRDCalibraFillHisto::HandlePRFtracklet(AliTRDtrack *t, Int_t index0, Int_t index1)
+Bool_t AliTRDCalibraFillHisto::HandlePRFtracklet(const AliTRDtrack *t, Int_t index0, Int_t index1)
 {
   //
   // PRF width calibration
@@ -1093,8 +1097,9 @@ Bool_t AliTRDCalibraFillHisto::HandlePRFtracklet(AliTRDtrack *t, Int_t index0, I
   for(Int_t k = 0;  k < npoints; k++){
     //Take the cluster
     AliTRDcluster *cl  = (AliTRDcluster *) t->GetCluster(k+index0);
+    if(!cl) continue;
     Short_t  *signals  = cl->GetSignals();
-    Double_t     time  = cl->GetLocalTimeBin();
+    Double_t     time  = cl->GetPadTime();
     //Calculate x if possible 
     Float_t xcenter    = 0.0;    
     Bool_t  echec1      = kTRUE;   
@@ -1149,8 +1154,8 @@ Bool_t AliTRDCalibraFillHisto::HandlePRFtracklet(AliTRDtrack *t, Int_t index0, I
   for(Int_t k = 0;  k < npoints; k++){
     //Take the cluster
     AliTRDcluster *cl      = (AliTRDcluster *) t->GetCluster(k+index0);
-    Short_t  *signals      = cl->GetSignals();              // signal
-    Double_t     time      = cl->GetLocalTimeBin();              // time bin
+    Short_t *signals       = cl->GetSignals();              // signal
+    Double_t time          = cl->GetPadTime();              // time bin
     Float_t padPosTracklet = line[0]+line[1]*time;          // reconstruct position from fit
     Float_t padPos         = cl->GetPadCol();               // middle pad
     Double_t dpad          = padPosTracklet - padPos;       // reconstruct position relative to middle pad from fit 
@@ -1406,9 +1411,11 @@ Bool_t AliTRDCalibraFillHisto::HandlePRFtrackletV1(const AliTRDseedV1 *tracklet,
   AliTRDcluster *cl                   = 0x0;
   for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
     // reject shared clusters on pad row
-    if(((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNTimeBins) && (cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb))) continue;
-   
-    Double_t     time  = cl->GetLocalTimeBin();
+    if((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) {
+      if((cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb))) continue;
+    }
+    if(!(cl = tracklet->GetClusters(ic))) continue;
+    Double_t     time  = cl->GetPadTime();
     if((time<=7) || (time>=21)) continue;
     Short_t  *signals  = cl->GetSignals(); 
     Float_t xcenter    = 0.0;    
@@ -1471,12 +1478,12 @@ Bool_t AliTRDCalibraFillHisto::HandlePRFtrackletV1(const AliTRDseedV1 *tracklet,
   //////////////////////////////////////////////
   for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
     // reject shared clusters on pad row
-    if(((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNTimeBins) && (cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb))) continue;
+    if(((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) && (cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb))) continue;
     //
     if(!(cl = tracklet->GetClusters(ic))) continue;
 
     Short_t  *signals      = cl->GetSignals();              // signal
-    Double_t     time      = cl->GetLocalTimeBin();         // time bin
+    Double_t     time      = cl->GetPadTime();         // time bin
     Float_t padPosTracklet = line[0]+line[1]*time;          // reconstruct position from fit
     Float_t padPos         = cl->GetPadCol();               // middle pad
     Double_t dpad          = padPosTracklet - padPos;       // reconstruct position relative to middle pad from fit 
@@ -1675,7 +1682,7 @@ Bool_t AliTRDCalibraFillHisto::HandlePRFtrackletV1(const AliTRDseedV1 *tracklet,
 // Pad row col stuff: see if masked or not
 ///////////////////////////////////////////////////////////////////////////////////////
 //_____________________________________________________________________________
-void AliTRDCalibraFillHisto::CheckGoodTrackletV1(AliTRDcluster *cl)
+void AliTRDCalibraFillHisto::CheckGoodTrackletV1(const AliTRDcluster *cl)
 {
   //
   // See if we are not near a masked pad
@@ -1686,7 +1693,7 @@ void AliTRDCalibraFillHisto::CheckGoodTrackletV1(AliTRDcluster *cl)
   
 }
 //_____________________________________________________________________________
-void AliTRDCalibraFillHisto::CheckGoodTrackletV0(Int_t detector, Int_t row, Int_t col)
+void AliTRDCalibraFillHisto::CheckGoodTrackletV0(const Int_t detector,const Int_t row,const Int_t col)
 {
   //
   // See if we are not near a masked pad
@@ -1907,7 +1914,7 @@ void AliTRDCalibraFillHisto::SetNumberGroupsPRF(Short_t numberGroupsPRF)
 // Per tracklet: store or reset the info, fill the histos with the info
 //////////////////////////////////////////////////////////////////////////////////////////
 //_____________________________________________________________________________
-void AliTRDCalibraFillHisto::StoreInfoCHPHtrack(AliTRDcluster *cl, Double_t dqdl, Int_t *group, Int_t row, 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)
 {
   //
   // Store the infos in fAmpTotal, fPHPlace and fPHValue
@@ -1916,7 +1923,10 @@ void AliTRDCalibraFillHisto::StoreInfoCHPHtrack(AliTRDcluster *cl, Double_t dqdl
   
   // time bin of the cluster not corrected
   Int_t    time     = cl->GetPadTime();
-   
+  Float_t  charge   = TMath::Abs(cl->GetQ());  
+
+  //printf("Store::time %d, amplitude %f\n",time,dqdl);
+  
   //Correct for the gain coefficient used in the database for reconstruction
   Float_t correctthegain = 1.0;
   if(fIsHLT) correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack);
@@ -1933,13 +1943,16 @@ void AliTRDCalibraFillHisto::StoreInfoCHPHtrack(AliTRDcluster *cl, Double_t dqdl
 
   // Fill the fAmpTotal with the charge
   if (fCH2dOn) {
-    if((!fLimitChargeIntegration) || (cl->IsInChamber())) fAmpTotal[(Int_t) group[0]] += correction;
+    if((!fLimitChargeIntegration) || (cl->IsInChamber())) {
+      //printf("Store::group %d, amplitude %f\n",group[0],correction);
+      fAmpTotal[(Int_t) group[0]] += correction;
+    }
   }
 
   // Fill the fPHPlace and value
   if (fPH2dOn) {
     fPHPlace[time] = group[1];
-    fPHValue[time] = correction;
+    fPHValue[time] = charge;
   }
   
 }
@@ -1982,6 +1995,8 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH(Int_t nbclusters)
   Int_t fd            = -1;   // Premiere zone non nulle
   Float_t totalcharge = 0.0;  // Total charge for the supermodule histo
 
+  //printf("CH2d nbclusters %d, fNumberClusters %d, fNumberClustersf %d\n",nbclusters,fNumberClusters,fNumberClustersf);
+
   if(nbclusters < fNumberClusters) return;
   if(nbclusters > fNumberClustersf) return;
 
@@ -1989,9 +2004,12 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH(Int_t nbclusters)
   // Normalize with the number of clusters
   Double_t normalizeCst = fRelativeScale;
   if(fNormalizeNbOfCluster) normalizeCst = normalizeCst*nbclusters;
+
+  //printf("Number of groups in one detector %d\n",fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0));
   
   // See if the track goes through different zones
   for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
+    //printf("fAmpTotal %f for %d\n",fAmpTotal[k],k);
     if (fAmpTotal[k] > 0.0) {
       totalcharge += fAmpTotal[k];
       nb++;
@@ -2001,6 +2019,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH(Int_t nbclusters)
     }
   }
 
+  //printf("CH2d: nb %d, fd %d, calibration group %d, amplitude %f, detector %d\n",nb,fd,fCalibraMode->GetXbins(0),fAmpTotal[fd]/normalizeCst,fDetectorPreviousTrack);
     
   switch (nb)
     { 
@@ -2296,9 +2315,10 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bo
   // 0 timebin problem
   // 1 no input
   // 2 input
-  //
   // Same algorithm as TestBeam but different reader
   //
+
+  rawStream->SetSharedPadReadout(kFALSE);
   
   Int_t withInput = 1;
   
@@ -2357,7 +2377,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
@@ -2423,7 +2443,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();   
@@ -2474,10 +2494,10 @@ Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliRawReader *rawReader, Bool_t no
 //_________________________________________________________________________
 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(
 #ifdef ALI_DATE
-                                              eventHeaderStruct *event,
+                                              const eventHeaderStruct *event,
                                               Bool_t nocheck
 #else
-                                              eventHeaderStruct* /*event*/,
+                                              const eventHeaderStruct* /*event*/,
                                               Bool_t /*nocheck*/
            
 #endif 
@@ -2536,9 +2556,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)
@@ -2562,7 +2582,12 @@ Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
 
   //printf("imaxRow %d, imaxCol %d, fTimeMax %d, integralMax %f\n",imaxRow,imaxCol,fTimeMax, integralMax);
 
-  if((imaxRow == 0) || (imaxCol == 0)) {
+  //if((imaxRow == 0) || (imaxRow >= 15) || (imaxCol <= 3) || (imaxCol >= 140)) {
+  //  used=1;
+  //  return used;
+  // }
+  
+  if(((imaxRow + fNumberRowDAQ) > 16) || (imaxRow == 0) || ((imaxCol - fNumberColDAQ) <= 1) || ((imaxCol + fNumberColDAQ) >= 144)) {
     used=1;
     return used;
   }
@@ -2574,21 +2599,25 @@ 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++;
   }
 
 
@@ -2621,6 +2650,7 @@ Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
       "clustera="<<clustera<<
       "it="<<it<<
       "rms="<<rms<<
+      "nbcl="<<nbcl<<
       "\n"; 
     }
   }
@@ -2628,6 +2658,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;
@@ -2640,8 +2671,12 @@ Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
     for(Int_t it = 0; it < fTimeMax; it++){
       if(fFillWithZero) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax); 
       else{
-       if(sum[it] > 0.0) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax); 
+       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); 
+      //} 
     }
     
    
@@ -2722,7 +2757,7 @@ void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
     }
   }
   if(fLinearFitterOn){
-    AnalyseLinearFitter();
+    if(fLinearFitterDebugOn) AnalyseLinearFitter();
     f.WriteTObject(fLinearVdriftFit);
   }
    
@@ -3184,4 +3219,3 @@ void AliTRDCalibraFillHisto::AnalyseLinearFitter()
     }
   }
 }
-