]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCCalibTCF.cxx
Corrected UInt_t <-> Int_t conversion
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibTCF.cxx
index 5511e7ef98659f8efc78ec78877c65630b11e6b0..ba909d532324fd7b3597f8ff15e93836c56f3071 100644 (file)
@@ -41,6 +41,7 @@
 #include "AliRawReaderRoot.h"
 #include "AliRawHLTManager.h"
 #include "AliTPCRawStream.h"
+#include "AliTPCRawStreamV3.h"
 #include "AliTPCROC.h"
 
 #include "AliTPCAltroEmulator.h"
@@ -52,13 +53,13 @@ ClassImp(AliTPCCalibTCF)
   
 AliTPCCalibTCF::AliTPCCalibTCF() :
   TNamed(),
-  fGateWidth(80),
+  fGateWidth(50),
   fSample(900),
-  fPulseLength(500),
+  fPulseLength(400),
   fLowPulseLim(30),
-  fUpPulseLim(1000),
-  fRMSLim(2.5),
-  fRatioIntLim(2.5)
+  fUpPulseLim(900),
+  fRMSLim(1.0),
+  fRatioIntLim(2)
 
 {
   //
@@ -121,6 +122,51 @@ AliTPCCalibTCF::~AliTPCCalibTCF()
   //
 }
 
+
+//_____________________________________________________________________________
+void AliTPCCalibTCF::ProcessRawFileV3(const char *nameRawFile, const char *nameFileOut) {
+  //
+  // New RCU data format!: Standard middle of 2009 
+  //
+  // Loops over all events within one RawData file and collects proper pulses 
+  // (according to given tresholds) per pad
+  // Histograms per pad are stored in 'nameFileOut'
+  //
+  
+  AliRawReader *rawReader = AliRawReader::Create(nameRawFile);
+  if (!rawReader) {
+    printf("Could not create a raw reader for %s\n",nameRawFile);
+    return;
+  } 
+
+  rawReader->RewindEvents(); // just to make sure
+  
+  rawReader->Select("TPC");
+
+  if (!rawReader->NextEvent()) {
+    printf("no events found in %s\n",nameRawFile);
+    return;
+  }
+
+  // TPC stream reader 
+  AliTPCRawStreamV3 rawStream(rawReader);
+  
+  Int_t ievent=0;
+  do {  
+    AliSysInfo::AddStamp(Form("start_event_%d",ievent), ievent,-1,-1);
+    printf("Reading next event ... Nr: %d\n",ievent);
+    // Start the basic data extraction
+    ProcessRawEventV3(rawReader, &rawStream, nameFileOut);
+    AliSysInfo::AddStamp(Form("end_event_%d",ievent), ievent,-1,-1);
+    ievent++;
+
+  } while (rawReader->NextEvent());
+
+  rawReader->~AliRawReader();
+  
+}
+
+
 //_____________________________________________________________________________
 void AliTPCCalibTCF::ProcessRawFile(const char *nameRawFile, const char *nameFileOut, bool bUseHLTOUT) {
   //
@@ -166,6 +212,179 @@ void AliTPCCalibTCF::ProcessRawFile(const char *nameRawFile, const char *nameFil
 }
 
 
+//_____________________________________________________________________________
+void AliTPCCalibTCF::ProcessRawEventV3( AliRawReader *rawReader, AliTPCRawStreamV3 *rawStream, const char *nameFileOut) {
+  //
+  // New RCU data format!: Standard middle of 2009 
+  //
+  // Extracts proper pulses (according the given tresholds) within one event
+  // and accumulates them into one histogram per pad. All histograms are
+  // saved in the file 'nameFileOut'. 
+  // The first bins of the histograms contain the following information:
+  //   bin 1: Number of accumulated pulses
+  //   bin 2;3;4: Sector; Row; Pad; 
+  // 
+  
+  TFile fileOut(nameFileOut,"UPDATE");
+  fileOut.cd();  
+  
+  TH1I *tempHis = new TH1I("tempHis","tempHis",fSample,fGateWidth,fSample+fGateWidth);
+  TH1I *tempRMSHis = new TH1I("tempRMSHis","tempRMSHis",2000,0,2000);
+  
+  // loop over the data in this event
+
+  while (rawStream->NextDDL() ) { 
+
+    Int_t ddl = rawReader->GetDDLID();
+    
+    while (rawStream->NextChannel() ) {
+      
+      while (rawStream->NextBunch() ) {
+
+       Int_t t0 = rawStream->GetStartTimeBin();
+       Int_t bl = rawStream->GetBunchLength();
+
+       if (bl<fSample+fGateWidth) continue;
+
+       Int_t sector = rawStream->GetSector();
+       Int_t row =    rawStream->GetRow();
+       Int_t pad =    rawStream->GetPad();
+
+       UShort_t *signals=(UShort_t*)rawStream->GetSignals();
+       if (!signals) continue;
+       
+       // Write to temporary histogramm
+       for (Int_t i=0;i<bl;++i) {
+         UShort_t time=t0-i;
+         UShort_t signal=signals[i];
+         if ( (fGateWidth<time) && (time<=fSample+fGateWidth) ) {
+           tempHis->SetBinContent(time-fGateWidth,signal);
+         }
+       }
+         
+       // calculation of the pulse properties and comparison to thresholds settings
+       
+       Int_t max = (Int_t)tempHis->GetMaximum(FLT_MAX);
+       Int_t maxpos =  tempHis->GetMaximumBin();
+       
+       Int_t first = (Int_t)TMath::Max(maxpos-10, 0);
+       Int_t last  = TMath::Min((Int_t)maxpos+fPulseLength-10, fSample+fGateWidth);
+       
+       // simple baseline substraction ? better one needed ? (pedestalsubstr.?)
+       // and RMS calculation with timebins before the pulse and at the end of
+       // the signal 
+       for (Int_t ipos = 0; ipos<6; ipos++) {
+         // before the pulse
+         tempRMSHis->Fill(tempHis->GetBinContent(first+ipos));
+       }
+       for (Int_t ipos = 0; ipos<20; ipos++) {
+         // at the end to get rid of pulses with serious baseline fluctuations
+         tempRMSHis->Fill(tempHis->GetBinContent(last-ipos)); 
+       }
+       
+       Double_t baseline = tempRMSHis->GetMean();
+       Double_t rms = tempRMSHis->GetRMS();
+       tempRMSHis->Reset();
+       
+       Double_t lowLim = fLowPulseLim+baseline;
+       Double_t upLim = fUpPulseLim+baseline;
+
+       // get rid of pulses which contain gate signal and/or too much noise
+       // with the help of ratio of integrals
+       Double_t intHist = 0;
+       Double_t intPulse = 0;
+       Double_t binValue;
+       for(Int_t ipos=first; ipos<=last; ipos++) {
+         binValue = TMath::Abs(tempHis->GetBinContent(ipos) - baseline);
+         intHist += binValue;
+         if(ipos>=first+5 && ipos<=first+15) {intPulse += binValue;}
+       }
+        
+       // gets rid of high frequency noise:
+       // calculating ratio (value one to the right of maximum)/(maximum)
+       // has to be >= 0.1; if maximum==0 set ratio to 0.1
+       Double_t maxCorr = max - baseline;
+       Double_t binRatio = 0.1;
+       if(TMath::Abs(maxCorr)>1e-5) {
+         binRatio = (tempHis->GetBinContent(maxpos+1) - baseline) / maxCorr;
+       }
+       
+       // Decision if found pulse is a proper one according to given tresholds
+        if (max>lowLim && max<upLim && !((last-first)<fPulseLength) && rms<fRMSLim && (intHist/intPulse)<fRatioIntLim &&intPulse>10&& (binRatio >= 0.1) ) {
+
+         // 1D histogramm for mean pulse per pad
+         char hname[100];
+         snprintf(hname,100,"sec%drow%dpad%d",sector,row,pad);
+         
+         TH1F *his = (TH1F*)fileOut.Get(hname);
+         
+         if (!his ) { // new entry (pulse in new pad found)
+           
+           his = new TH1F(hname,hname, fPulseLength+5, 0, fPulseLength+5);
+           his->SetBinContent(1,1);        //  pulse counter (1st pulse)
+           his->SetBinContent(2,sector);   //  sector
+           his->SetBinContent(3,row);      //  row
+           his->SetBinContent(4,pad);      //  pad       
+           
+           for (Int_t ipos=0; ipos<last-first; ipos++){
+             Int_t signal = (Int_t)(tempHis->GetBinContent(ipos+first)-baseline);
+             his->SetBinContent(ipos+5,signal);
+           }
+           his->Write(hname);
+           printf("new  %s: Signal %d at bin %d \n", hname, max-(Int_t)baseline, maxpos+fGateWidth);
+           
+         } else {  // adding pulse to existing histogram (pad already found)
+           
+           his->AddBinContent(1,1); //  pulse counter for each pad
+           for (Int_t ipos=0; ipos<last-first; ipos++){
+             Int_t signal= (Int_t)(tempHis->GetBinContent(ipos+first)-baseline);
+             his->AddBinContent(ipos+5,signal);
+           }
+           printf("adding ...  %s: Signal %d at bin %d \n", hname, max-(Int_t)baseline, maxpos+fGateWidth);
+           his->Write(hname,kOverwrite);
+         }     
+
+
+         // 2D histogramm for pulse spread within a DDL (normalized to one)
+         char hname2d[100];
+         snprintf(hname2d,100,"2Dhisto_ddl%d",ddl);
+         TH2F *his2d = (TH2F*)fileOut.Get(hname2d);
+         if (!his2d ) { // new entry (ddl was not seen before)
+
+           his2d = new TH2F(hname2d,hname2d, fPulseLength, 0., (Double_t)fPulseLength, 50,-0.02,0.02);
+           for (Int_t ipos=0; ipos<last-first; ipos++){
+             Double_t signal = tempHis->GetBinContent(ipos+first)-baseline;
+             if (TMath::Abs(signal/maxCorr)>1e-10)  // zero bins are biased
+               his2d->Fill(ipos,signal/maxCorr);
+           }
+           his2d->Write(hname2d);
+           printf("new  %s: \n", hname2d);
+         } else {  // adding pulse to existing histogram 
+
+           for (Int_t ipos=0; ipos<last-first; ipos++){
+             Double_t signal= tempHis->GetBinContent(ipos+first)-baseline;
+             if (TMath::Abs(signal/maxCorr)>1e-10) // zero bins are biased
+               his2d->Fill(ipos,signal/maxCorr);
+           }
+           his2d->Write(hname2d,kOverwrite);
+         }
+         
+         tempHis->Reset();
+
+        } // pulse stored
+
+      } // bunch loop
+    }// channel loop
+  } // ddl loop
+  
+  tempHis->~TH1I();
+  tempRMSHis->~TH1I();
+  printf("Finished to read event ... \n");
+  fileOut.Close();
+
+}
+
+
 //_____________________________________________________________________________
 void AliTPCCalibTCF::ProcessRawEvent(AliTPCRawStream *rawStream, const char *nameFileOut) {
   //
@@ -286,14 +505,14 @@ void AliTPCCalibTCF::ProcessRawEvent(AliTPCRawStream *rawStream, const char *nam
       // has to be >= 0.1; if maximum==0 set ratio to 0.1
       Double_t maxCorr = max - baseline;
       Double_t binRatio = 0.1;
-      if(maxCorr != 0) {
+      if(TMath::Abs(maxCorr)>1e-5) {
        binRatio = (tempHis->GetBinContent(maxpos+1) - baseline) / maxCorr;
       }
       
       // Decision if found pulse is a proper one according to given tresholds
       if (max>lowLim && max<upLim && !((last-first)<fPulseLength) && rms<fRMSLim && (intHist/intPulse)<fRatioIntLim && (binRatio >= 0.1) ) {
        char hname[100];
-       sprintf(hname,"sec%drow%dpad%d",prevSec,prevRow,prevPad);
+       snprintf(hname,100,"sec%drow%dpad%d",prevSec,prevRow,prevPad);
        
        TH1F *his = (TH1F*)fileOut.Get(hname);
        
@@ -359,7 +578,7 @@ void AliTPCCalibTCF::MergeHistoPerSector(const char *nameFileIn) {
   TIter next( fileIn.GetListOfKeys() );
 
   char nameFileOut[100];
-  sprintf(nameFileOut,"Sec-%s",nameFileIn);
+  snprintf(nameFileOut,100,"Sec-%s",nameFileIn);
 
   TFile fileOut(nameFileOut,"RECREATE");
   fileOut.cd();
@@ -370,15 +589,18 @@ void AliTPCCalibTCF::MergeHistoPerSector(const char *nameFileIn) {
   while ( (key=(TKey*)next()) ) {
 
     iHist++;
+    TString name(key->GetName());
+    if (name.Contains("ddl") ) continue;  // ignore the 2d histogramms per ddl
+
+    hisPad = (TH1F*)fileIn.Get(name.Data()); // copy object to memory
 
-    hisPad = (TH1F*)fileIn.Get(key->GetName()); // copy object to memory
     Int_t pulseLength = hisPad->GetNbinsX() -4; 
     // -4 because first four timebins contain pad specific informations
     Int_t npulse = (Int_t)hisPad->GetBinContent(1);
     Int_t sector = (Int_t)hisPad->GetBinContent(2);
   
     char hname[100];
-    sprintf(hname,"sector%d",sector);
+    snprintf(hname,100,"sector%d",sector);
     TH1F *his = (TH1F*)fileOut.Get(hname);
     
     if (!his ) { // new histogram (new sector)
@@ -397,7 +619,7 @@ void AliTPCCalibTCF::MergeHistoPerSector(const char *nameFileIn) {
       for (Int_t ipos=0; ipos<pulseLength; ipos++){
        his->AddBinContent(ipos+5,hisPad->GetBinContent(ipos+5));
       }
-      his->Write(hname,kOverwrite);
+      his->Write(hname,kOverwrite); 
     }
 
     if (iHist%500==0) {
@@ -431,7 +653,7 @@ void AliTPCCalibTCF::AnalyzeRootFile(const char *nameFileIn, Int_t minNumPulse,
   TIter next( fileIn.GetListOfKeys() );
 
   char nameFileOut[100];
-  sprintf(nameFileOut,"TCF-%s",nameFileIn);
+  snprintf(nameFileOut,100,"TCF-%s",nameFileIn);
   
   TFile fileOut(nameFileOut,"RECREATE");
   fileOut.cd();
@@ -444,9 +666,12 @@ void AliTPCCalibTCF::AnalyzeRootFile(const char *nameFileIn, Int_t minNumPulse,
   while ((key = (TKey *) next())) { // loop over histograms
     ++iHist;
     if(iHist < histStart || iHist  > histEnd) {continue;}
-   
-    hisIn = (TH1F*)fileIn.Get(key->GetName()); // copy object to memory
 
+    TString name(key->GetName());
+    if (name.Contains("ddl") ) continue;  // ignore the 2d histogramms per ddl
+
+    hisIn = (TH1F*)fileIn.Get(key->GetName()); // copy object to memory
+  
     Int_t numPulse = (Int_t)hisIn->GetBinContent(1); 
     if ( numPulse >= minNumPulse ) {
       printf("Analyze histogram %d out of %d\n",iHist,nHist);
@@ -480,7 +705,7 @@ void AliTPCCalibTCF::AnalyzeRootFile(const char *nameFileIn, Int_t minNumPulse,
 
 
 //____________________________________________________________________________
-Int_t AliTPCCalibTCF::AnalyzePulse(TH1F *hisIn, Double_t *coefZ, Double_t *coefP) {
+Int_t AliTPCCalibTCF::AnalyzePulse(TH1F * const hisIn, Double_t *coefZ, Double_t *coefP) {
   //
   // Performs the analysis on one specific pulse (histogram) by means of fitting
   // the pulse and equalization of the pulseheight. The found TCF parameters 
@@ -570,7 +795,7 @@ void AliTPCCalibTCF::TestTCFonRootFile(const char *nameFileIn, const char *nameF
   }
 
   char nameFileOut[100];
-  sprintf(nameFileOut,"Quality_%s_AT_%s",nameFileTCF, nameFileIn);
+  snprintf(nameFileOut,100,"Quality_%s_AT_%s",nameFileTCF, nameFileIn);
   TFile fileOut(nameFileOut,"RECREATE");
 
   TNtuple *qualityTuple = new TNtuple("TCFquality","TCF quality Values","sec:row:pad:npulse:heightDev:areaRed:widthRed:undershot:maxUndershot");
@@ -586,8 +811,12 @@ void AliTPCCalibTCF::TestTCFonRootFile(const char *nameFileIn, const char *nameF
   while ((key = (TKey *) next())) { // loop over saved histograms
     
     //  loading pulse to memory;
+    TString name(key->GetName());
+    if (name.Contains("ddl") ) continue;  // ignore the 2d histogramms per ddl
+
     printf("validating pulse %d out of %d\n",++iHist,nHist);
     hisIn = (TH1F*)fileIn.Get(key->GetName()); 
 
     // find the correct TCF parameter according to the his infos (first 4 bins)
     Int_t nPulse = FindCorTCFparam(hisIn, nameFileTCF, coefZ, coefP); 
@@ -761,7 +990,7 @@ void AliTPCCalibTCF::TestTCFonRawFile(const char *nameRawFile, const char *nameF
        for(Int_t ipos=first; ipos<=last; ipos++) {
          binValue = TMath::Abs(tempHis->GetBinContent(ipos) - baseline);
          intHist += binValue;
-         if(ipos>=first+5 && ipos<=first+25) {intPulse += binValue;}
+         if(ipos>=first+5 && ipos<=first+15) {intPulse += binValue;}
        }
        
        // gets rid of high frequency noise:
@@ -769,7 +998,7 @@ void AliTPCCalibTCF::TestTCFonRawFile(const char *nameRawFile, const char *nameF
        // has to be >= 0.1; if maximum==0 set ratio to 0.1
        Double_t maxCorr = max - baseline;
        Double_t binRatio = 0.1;
-       if(maxCorr != 0) {
+       if(TMath::Abs(maxCorr) > 1e-5 ) {
          binRatio = (tempHis->GetBinContent(maxpos+1) - baseline) / maxCorr;
        }
 
@@ -779,7 +1008,7 @@ void AliTPCCalibTCF::TestTCFonRawFile(const char *nameRawFile, const char *nameF
          // note:
          // assuming that lowLim is higher than the pedestal value!
          char hname[100];
-         sprintf(hname,"sec%drow%dpad%d",prevSec,prevRow,prevPad);
+         snprintf(hname,100,"sec%drow%dpad%d",prevSec,prevRow,prevPad);
          TH1F *his = new TH1F(hname,hname, fPulseLength+4, 0, fPulseLength+4);
          his->SetBinContent(1,1); //  pulse counter (1st pulse)
          his->SetBinContent(2,prevSec);  //  sector
@@ -868,6 +1097,10 @@ TH2F *AliTPCCalibTCF::PlotOccupSummary2Dhist(const char *nameFileIn, Int_t side)
 
   while ((key = (TKey *) next())) { // loop over histograms within the file
     iHist++;
+    
+    TString name(key->GetName());
+    if (name.Contains("ddl") ) continue;  // ignore the 2d histogramms per ddl
+
     his = (TH1F*)fileIn.Get(key->GetName()); // copy object to memory
 
     npulse = (Int_t)his->GetBinContent(1);
@@ -878,7 +1111,7 @@ TH2F *AliTPCCalibTCF::PlotOccupSummary2Dhist(const char *nameFileIn, Int_t side)
     if ( (side==0) && (sec%36>=18) ) continue;
     if ( (side>0) && (sec%36<18) ) continue;
 
-    if ( (row==-1) && (pad==-1) ) { // summed pulses per sector
+    if ( (row<0) && (pad<0) ) { // row and pad are equal to -1, then -> summed pulses per sector
       // fill all pad with this values
       for (UInt_t rowi=0; rowi<roc->GetNRows(sec); rowi++) {
         for (UInt_t padi=0; padi<roc->GetNPads(sec,rowi); padi++) {
@@ -928,7 +1161,7 @@ void AliTPCCalibTCF::PlotOccupSummary(const char *nameFile, Int_t side, Int_t nP
 
 
   char nameFileOut[100];
-  sprintf(nameFileOut,"Occup-%s",nameFile);
+  snprintf(nameFileOut,100,"Occup-%s",nameFile);
   TFile fileOut(nameFileOut,"RECREATE");
   // fileOut.cd();
 
@@ -942,6 +1175,10 @@ void AliTPCCalibTCF::PlotOccupSummary(const char *nameFile, Int_t side, Int_t nP
   Int_t secWise = 0;
 
   while ((key = (TKey *) next())) { // loop over histograms within the file
+    
+    TString name(key->GetName());
+    if (name.Contains("ddl") ) continue;  // ignore the 2d histogramms per ddl
+
     his = (TH1F*)file->Get(key->GetName()); // copy object to memory
     iHist++;
     Int_t npulse = (Int_t)his->GetBinContent(1);
@@ -949,7 +1186,7 @@ void AliTPCCalibTCF::PlotOccupSummary(const char *nameFile, Int_t side, Int_t nP
     Int_t row = (Int_t)his->GetBinContent(3);
     Int_t pad = (Int_t)his->GetBinContent(4);
 
-    if ( (row==-1) && (pad==-1) ) { // summed pulses per sector
+    if ( (row<0) && (pad<0) ) { // row and pad are equal to -1, then -> summed pulses per sector
       row = 40; pad = 40;    // set to approx middle row for better plot
       secWise=1;
     }
@@ -973,10 +1210,10 @@ void AliTPCCalibTCF::PlotOccupSummary(const char *nameFile, Int_t side, Int_t nP
 
   char cSel[100];
   if (!side) {
-    sprintf(cSel,"z>0&&npulse>=%d",nPulseMin);
+    snprintf(cSel,100,"z>0&&npulse>=%d",nPulseMin);
     ntuple->Draw("y:x:npulse",cSel,"colz");
   } else {
-    sprintf(cSel,"z<0&&npulse>=%d",nPulseMin);
+    snprintf(cSel,100,"z<0&&npulse>=%d",nPulseMin);
     ntuple->Draw("y:x:npulse",cSel,"colz");
   }
 
@@ -1017,7 +1254,7 @@ void AliTPCCalibTCF::PlotQualitySummary(const char *nameFileQuality, const char
   
   TH2F *his2D = new TH2F(plotSpec,nameFileQuality,11,-10,1,25,1,100);
   char plSpec[100];
-  sprintf(plSpec,"%s>>%s",plotSpec,plotSpec);
+  snprintf(plSpec,100,"%s>>%s",plotSpec,plotSpec);
   qualityTuple->Draw(plSpec,cut,pOpt);
 
   gStyle->SetLabelSize(0.03,"X");
@@ -1125,7 +1362,7 @@ Int_t AliTPCCalibTCF::FitPulse(TNtuple *dataTuple, Double_t *coefZ, Double_t *co
 
 
 //____________________________________________________________________________
-void AliTPCCalibTCF::FitFcn(Int_t &/*nPar*/, Double_t */*grad*/, Double_t &f, Double_t *par, Int_t /*iflag*/)
+void AliTPCCalibTCF::FitFcn(Int_t &/*nPar*/, Double_t */*grad*/, Double_t &f, Double_t * const par, Int_t /*iflag*/)
 {
   //
   // Minimization function needed for TMinuit with FitFunction included 
@@ -1189,8 +1426,8 @@ Double_t* AliTPCCalibTCF::ExtractPZValues(Double_t *param) {
   // to the different stages of the TCF filter
   // (e.g. first 2 fit parameters represent the electron signal itself!)
 
-  if (param[3]==param[4]) {param[3]=param[3]+0.0001;}
-  if (param[5]==param[4]) {param[5]=param[5]+0.0001;}
+  if ((param[3]-param[4]) <1e-5 ) {param[3]=param[3]+0.0001;} // if equal
+  if ((param[5]-param[4]) <1e-5 ) {param[5]=param[5]+0.0001;} // if equal
   
   if ((param[5]>param[4])&&(param[5]>param[3])) {
     if (param[4]>=param[3]) {
@@ -1252,12 +1489,17 @@ Int_t AliTPCCalibTCF::Equalization(TNtuple *dataTuple, Double_t *coefZ, Double_t
   // order to restore the original pulse height and adds them to the passed arrays
   //
 
-  Double_t *s0 = new Double_t[1000]; // original pulse
-  Double_t *s1 = new Double_t[1000]; // pulse after 1st PZ filter
-  Double_t *s2 = new Double_t[1000]; // pulse after 2nd PZ filter
-
   const Int_t kPulseLength = dataTuple->GetEntries();
-  
+
+  if (kPulseLength<2) {
+    //    prinft("PulseLength does not make sense\n");
+    return 0;
+  }
+
+  Double_t *s0 = new Double_t[kPulseLength]; // original pulse
+  Double_t *s1 = new Double_t[kPulseLength]; // pulse after 1st PZ filter
+  Double_t *s2 = new Double_t[kPulseLength]; // pulse after 2nd PZ filter
+
   for (Int_t ipos=0; ipos<kPulseLength; ipos++) {
     dataTuple->GetEntry(ipos);
     Float_t *p = dataTuple->GetArgs();
@@ -1302,9 +1544,9 @@ Int_t AliTPCCalibTCF::Equalization(TNtuple *dataTuple, Double_t *coefZ, Double_t
     coefZ[2] = 0;
   }
 
-  s0->~Double_t();
-  s1->~Double_t();
-  s2->~Double_t();
+  delete [] s0;
+  delete [] s1;
+  delete [] s2;
   
   // if equalization out of range (<0 or >=1) it failed!
   // if ratio of amplitudes of fittet to original pulse < 0.9 it failed!
@@ -1319,7 +1561,7 @@ Int_t AliTPCCalibTCF::Equalization(TNtuple *dataTuple, Double_t *coefZ, Double_t
 
 
 //____________________________________________________________________________
-Int_t AliTPCCalibTCF::FindCorTCFparam(TH1F *hisIn, const char *nameFileTCF, Double_t *coefZ, Double_t *coefP) {
+Int_t AliTPCCalibTCF::FindCorTCFparam(TH1F * const hisIn, const char *nameFileTCF, Double_t *coefZ, Double_t *coefP) {
   //
   // This function searches for the correct TCF parameters to the given
   // histogram 'hisIn' within the file 'nameFileTCF' 
@@ -1340,10 +1582,10 @@ Int_t AliTPCCalibTCF::FindCorTCFparam(TH1F *hisIn, const char *nameFileTCF, Doub
   char sel[100];   
   if ( paramTuple->GetEntries("row==-1&&pad==-1") ) { 
     // parameters per SECTOR
-    sprintf(sel,"sec==%d&&row==-1&&pad==-1",sector);
+    snprintf(sel,100,"sec==%d&&row==-1&&pad==-1",sector);
   } else {            
     // parameters per PAD
-    sprintf(sel,"sec==%d&&row==%d&&pad==%d",sector,row,pad);
+    snprintf(sel,100,"sec==%d&&row==%d&&pad==%d",sector,row,pad);
   }
 
   // list should contain just ONE entry! ... otherwise there is a mistake!
@@ -1355,9 +1597,9 @@ Int_t AliTPCCalibTCF::FindCorTCFparam(TH1F *hisIn, const char *nameFileTCF, Doub
     paramTuple->GetEntry(pos);   // get specific TCF parameters       
     Float_t *p = paramTuple->GetArgs();
     // check ...
-    if(sector==p[0]) {printf("sector ok ... "); }          
-    if(row==p[1]) {printf("row ok ... "); }          
-    if(pad==p[2]) {printf("pad ok ... \n"); }          
+    if((sector-p[0])<1e-5) {printf("sector ok ... "); }          
+    if((row-p[1])<1e-5) {printf("row ok ... "); }          
+    if((pad-p[2])<1e-5) {printf("pad ok ... \n"); }          
     
     // number of averaged pulses used to produce TCF params
     nPulse = (Int_t)p[3]; 
@@ -1480,7 +1722,7 @@ Double_t *AliTPCCalibTCF::GetQualityOfTCF(TH1F *hisIn, Double_t *coefZ, Double_t
     }
 
     // Search for maximal undershot (is equal to minimum after the pulse)
-    if ( (undershotStart==1)&&(i<(posOfStartTCF+widthTCF+20)) ) {
+    if ( ((undershotStart-1)<1e-7)&&(i<(posOfStartTCF+widthTCF+20)) ) {
       if (maxUndershot>sigTCF) { maxUndershot = sigTCF; }
     }
 
@@ -1544,7 +1786,7 @@ Double_t *AliTPCCalibTCF::GetQualityOfTCF(TH1F *hisIn, Double_t *coefZ, Double_t
 
 
 //____________________________________________________________________________
-TNtuple *AliTPCCalibTCF::ApplyTCFilter(TH1F *hisIn, Double_t *coefZ, Double_t *coefP, Int_t plotFlag) {
+TNtuple *AliTPCCalibTCF::ApplyTCFilter(TH1F * const hisIn, Double_t * const coefZ, Double_t * const coefP, Int_t plotFlag) {
   //
   // Applies the given TCF parameters on the given pulse via the ALTRO emulator 
   // class (discret values) and stores both pulses into a returned TNtuple
@@ -1570,8 +1812,8 @@ TNtuple *AliTPCCalibTCF::ApplyTCFilter(TH1F *hisIn, Double_t *coefZ, Double_t *c
   }
 
   // transform TCF parameters into ALTRO readable format (Integer)
-  Int_t* valK = new Int_t[3];
-  Int_t* valL = new Int_t[3];
+  Int_t valK[3];
+  Int_t valL[3];
   for (Int_t i=0; i<3; i++) {
     valK[i] = (Int_t)(coefP[i]*(TMath::Power(2,16)-1));
     valL[i] = (Int_t)(coefZ[i]*(TMath::Power(2,16)-1));
@@ -1611,7 +1853,7 @@ TNtuple *AliTPCCalibTCF::ApplyTCFilter(TH1F *hisIn, Double_t *coefZ, Double_t *c
 
   if (plotFlag) {
     char hname[100];
-    sprintf(hname,"sec%drow%dpad%d",sector,row,pad);
+    snprintf(hname,100,"sec%drow%dpad%d",sector,row,pad);
     new TCanvas(hname,hname,600,400);
     //just plotting non-discret pulses | they look pretties in case of mean sig ;-)
     pulseTuple->Draw("sigND:timebin","","L");
@@ -1621,14 +1863,11 @@ TNtuple *AliTPCCalibTCF::ApplyTCFilter(TH1F *hisIn, Double_t *coefZ, Double_t *c
     // pulseTuple->Draw("sigAfterTCF:timebin","","Lsame");
   }
   
-  valK->~Int_t();
-  valL->~Int_t();
-
-  signalIn->~Double_t();
-  signalOut->~Double_t();
-  delete signalIn;
-  delete signalOut;
-
+  delete [] signalIn;
+  delete [] signalOut;
+  delete [] signalInD;
+  delete [] signalOutD;
   return pulseTuple;
 
 }
@@ -1668,7 +1907,8 @@ void AliTPCCalibTCF::MergeHistoPerFile(const char *fileNameIn, const char *fileN
   TH1F *hisIn;                             
   TKey *key;                                          
   TIter next(fileIn.GetListOfKeys());  
-  TFile *fileOut = 0;
+  // opens a file, although, it might not be uses (see "mode")
+  TFile *fileOut = new TFile(fileNameSum,"UPDATE"); 
   //fileOut.cd();
   
   Int_t nHist=fileIn.GetNkeys();
@@ -1677,13 +1917,15 @@ void AliTPCCalibTCF::MergeHistoPerFile(const char *fileNameIn, const char *fileN
   Int_t secPrev = -1;
   char fileNameSumSec[100];
 
-  if (mode==0) {
-    fileOut = new TFile(fileNameSum,"UPDATE");
-  }
+
   while((key=(TKey*)next())) {
     const char *hisName = key->GetName();
 
+    TString name(key->GetName());
+    if (name.Contains("ddl") ) continue;  // ignore the 2d histogramms per ddl
+
     hisIn=(TH1F*)fileIn.Get(hisName);          
+    
     Int_t numPulse=(Int_t)hisIn->GetBinContent(1);
     Int_t sec=(Int_t)hisIn->GetBinContent(2);
     Int_t pulseLength= hisIn->GetNbinsX()-4;    
@@ -1694,7 +1936,7 @@ void AliTPCCalibTCF::MergeHistoPerFile(const char *fileNameIn, const char *fileN
         fileOut->Close();
       }
       // opening new file 
-      sprintf(fileNameSumSec,"%s-Sec%d.root",fileNameSum,sec);
+      snprintf(fileNameSumSec,100,"%s-Sec%d.root",fileNameSum,sec);
       fileOut = new TFile(fileNameSumSec,"UPDATE");
       secPrev = sec;
     }
@@ -1750,7 +1992,7 @@ void AliTPCCalibTCF::MergeToOneFile(const char *nameFileSum) {
 
   for (Int_t sec=0; sec<72; sec++) { // loop over all possible filenames
 
-    sprintf(nameFileSumSec,"%s-Sec%d.root",nameFileSum,sec);
+    snprintf(nameFileSumSec,100,"%s-Sec%d.root",nameFileSum,sec);
     TFile *fileSumSec = new TFile(nameFileSumSec,"READ");
 
     Int_t nHist=fileSumSec->GetNkeys();
@@ -1765,9 +2007,11 @@ void AliTPCCalibTCF::MergeToOneFile(const char *nameFileSum) {
       TIter next(fileSumSec->GetListOfKeys());
       while( (key=(TKey*)next()) ) {
         const char *hisName = key->GetName();
-
+       TString name(hisName);
+       if (name.Contains("ddl") ) continue;  // ignore the 2d histogramms per ddl
         hisIn=(TH1F*)fileSumSec->Get(hisName);
 
+
         if (iHist%100==0) {
           printf("found histogram %d / %d, %s\n",iHist,nHist,hisName);
         }
@@ -1803,18 +2047,13 @@ Int_t AliTPCCalibTCF::DumpTCFparamToFilePerPad(const char *nameFileTCFPerPad,con
   // the roc are retreived from nameFileTCFPerSec. If there are parameters for
   // a roc missing, then the parameters are set to -1.  
 
-  Float_t K0 = -1, K1 = -1, K2 = -1, L0 = -1, L1 = -1, L2 = -1;
+  Float_t k0 = -1, k1 = -1, k2 = -1, l0 = -1, l1 = -1, l2 = -1;
   Int_t roc, row, pad, side, sector, rcu, hwAddr; 
   Int_t entryNum = 0;
   Int_t checksum = 0;
   Int_t tpcPadNum = 557568;
   Int_t validFlag = 1; // 1 if parameters for pad exist, 0 if they are only inherited from the roc
 
-  Bool_t *entryID = new Bool_t[7200000]; // helping vector
-  for (Int_t ii = 0; ii<7200000; ii++) {
-    entryID[ii]=0;
-  }
-    
   // get file/tuple with parameters per pad
   TFile fileTCFparam(nameFileTCFPerPad);
   TNtuple *paramTuple = (TNtuple*)fileTCFparam.Get("TCFparam");
@@ -1832,14 +2071,19 @@ Int_t AliTPCCalibTCF::DumpTCFparamToFilePerPad(const char *nameFileTCFPerPad,con
     printf("Got mapping object from %s\n", nameMappingFile);
   }
 
+  Bool_t *entryID = new Bool_t[7200000]; // helping vector
+  for (Int_t ii = 0; ii<7200000; ii++) {
+    entryID[ii]=0;
+  }
+
   // creating outputfile
   ofstream fileOut;
   char nameFileOut[255];
-  sprintf(nameFileOut,"tpcTCFparamPAD.data");
+  snprintf(nameFileOut,255,"tpcTCFparamPAD.data");
   fileOut.open(nameFileOut);
   // following not used:
   // char headerLine[255];
-  // sprintf(headerLine,"15\tside\tsector\tRCU\tHWadr\tK0\tK1\tK2\tL0\tL1\tL2\tValidFlag");
+  // snprintf(headerLine,255,"15\tside\tsector\tRCU\tHWadr\tk0\tk1\tk2\tl0\tl1\tl2\tValidFlag");
   // fileOut << headerLine << std::endl;
   fileOut << "15" << std::endl;
  
@@ -1856,18 +2100,18 @@ Int_t AliTPCCalibTCF::DumpTCFparamToFilePerPad(const char *nameFileTCFPerPad,con
     sector = Int_t(mapping->GetSectorFromRoc(roc));
     rcu = Int_t(mapping->GetRcu(roc,row,pad));
     hwAddr = Int_t(mapping->GetHWAddress(roc,row,pad));
-    K0 = TMath::Nint(paramArgs[7] * (TMath::Power(2,16) - 1));
-    K1 = TMath::Nint(paramArgs[8] * (TMath::Power(2,16) - 1));
-    K2 = TMath::Nint(paramArgs[9] * (TMath::Power(2,16) - 1));
-    L0 = TMath::Nint(paramArgs[4] * (TMath::Power(2,16) - 1));
-    L1 = TMath::Nint(paramArgs[5] * (TMath::Power(2,16) - 1));
-    L2 = TMath::Nint(paramArgs[6] * (TMath::Power(2,16) - 1));
+    k0 = TMath::Nint(paramArgs[7] * (TMath::Power(2,16) - 1));
+    k1 = TMath::Nint(paramArgs[8] * (TMath::Power(2,16) - 1));
+    k2 = TMath::Nint(paramArgs[9] * (TMath::Power(2,16) - 1));
+    l0 = TMath::Nint(paramArgs[4] * (TMath::Power(2,16) - 1));
+    l1 = TMath::Nint(paramArgs[5] * (TMath::Power(2,16) - 1));
+    l2 = TMath::Nint(paramArgs[6] * (TMath::Power(2,16) - 1));
     if (entryNum%10000==0) {
       printf("assigned pad %i / %i\n",entryNum,tpcPadNum);
     }
     
     fileOut << entryNum++ << "\t" << side << "\t" << sector << "\t" << rcu << "\t" << hwAddr << "\t";
-    fileOut << K0 << "\t" << K1 << "\t" << K2 << "\t" << L0 << "\t" << L1 << "\t" << L2 << "\t" << validFlag << std::endl;
+    fileOut << k0 << "\t" << k1 << "\t" << k2 << "\t" << l0 << "\t" << l1 << "\t" << l2 << "\t" << validFlag << std::endl;
     entryID[roc*100000 + row*1000 + pad] = 1;
   }
 
@@ -1887,16 +2131,16 @@ Int_t AliTPCCalibTCF::DumpTCFparamToFilePerPad(const char *nameFileTCFPerPad,con
     for (Int_t iParamSec = 0; iParamSec < paramTupleSec->GetEntries(); iParamSec++) {
       paramTupleSec->GetEntry(iParamSec);
       Float_t *paramArgsSec = paramTupleSec->GetArgs();
-      if (paramArgsSec[0] == roc) {
-       K0 = TMath::Nint(paramArgsSec[7] * (TMath::Power(2,16) - 1));
-       K1 = TMath::Nint(paramArgsSec[8] * (TMath::Power(2,16) - 1));
-       K2 = TMath::Nint(paramArgsSec[9] * (TMath::Power(2,16) - 1));
-       L0 = TMath::Nint(paramArgsSec[4] * (TMath::Power(2,16) - 1));
-       L1 = TMath::Nint(paramArgsSec[5] * (TMath::Power(2,16) - 1));
-       L2 = TMath::Nint(paramArgsSec[6] * (TMath::Power(2,16) - 1));
+      if ((paramArgsSec[0]-roc)<1e-7) { // if roc is found
+       k0 = TMath::Nint(paramArgsSec[7] * (TMath::Power(2,16) - 1));
+       k1 = TMath::Nint(paramArgsSec[8] * (TMath::Power(2,16) - 1));
+       k2 = TMath::Nint(paramArgsSec[9] * (TMath::Power(2,16) - 1));
+       l0 = TMath::Nint(paramArgsSec[4] * (TMath::Power(2,16) - 1));
+       l1 = TMath::Nint(paramArgsSec[5] * (TMath::Power(2,16) - 1));
+       l2 = TMath::Nint(paramArgsSec[6] * (TMath::Power(2,16) - 1));
        break;
       } else {
-       K0 = K1 = K2 = L0 = L1 = L2 = -1;
+       k0 = k1 = k2 = l0 = l1 = l2 = -1;
       }
     }
     for (row = 0; row<mapping->GetNpadrows(roc); row++) {
@@ -1913,7 +2157,7 @@ Int_t AliTPCCalibTCF::DumpTCFparamToFilePerPad(const char *nameFileTCFPerPad,con
        }
 
        fileOut << entryNum++ << "\t" << side << "\t" << sector << "\t" << rcu << "\t" << hwAddr << "\t";
-       fileOut << K0 << "\t" << K1 << "\t" << K2 << "\t" << L0 << "\t" << L1 << "\t" << L2 << "\t" << validFlag << std::endl;
+       fileOut << k0 << "\t" << k1 << "\t" << k2 << "\t" << l0 << "\t" << l1 << "\t" << l2 << "\t" << validFlag << std::endl;
       }
     }
   }
@@ -1934,7 +2178,7 @@ Int_t AliTPCCalibTCF::DumpTCFparamToFilePerPad(const char *nameFileTCFPerPad,con
   fileOut.close();
   fileTCFparam.Close();
   fileSecTCFparam.Close();
-  entryID->~Bool_t();
+  delete [] entryID;
   printf("output written to file: %s\n",nameFileOut);
   return 0;
 }
@@ -1954,7 +2198,7 @@ Int_t AliTPCCalibTCF::DumpTCFparamToFilePerSector(const char *nameFileTCFPerSec,
   //
   // If there are parameters for a roc missing, then the parameters are set to -1
   
-  Float_t K0 = -1, K1 = -1, K2 = -1, L0 = -1, L1 = -1, L2 = -1;
+  Float_t k0 = -1, k1 = -1, k2 = -1, l0 = -1, l1 = -1, l2 = -1;
   Int_t entryNum = 0;
   Int_t validFlag = 0; // 1 if parameters for roc exist
   
@@ -1981,11 +2225,11 @@ Int_t AliTPCCalibTCF::DumpTCFparamToFilePerSector(const char *nameFileTCFPerSec,
   
   ofstream fileOut;
   char nameFileOut[255];
-  sprintf(nameFileOut,"tpcTCFparamSector.data");
+  snprintf(nameFileOut,255,"tpcTCFparamSector.data");
   fileOut.open(nameFileOut);
   // following not used:   
   // char headerLine[255];
-  // sprintf(headerLine,"16\tside\tsector\tRCU\tHWadr\tK0\tK1\tK2\tL0\tL1\tL2\tValidFlag");
+  // snprintf(headerLine,255,"16\tside\tsector\tRCU\tHWadr\tk0\tk1\tk2\tl0\tl1\tl2\tValidFlag");
   // fileOut << headerLine << std::endl;
   fileOut << "16" << std::endl;
   
@@ -2002,23 +2246,23 @@ Int_t AliTPCCalibTCF::DumpTCFparamToFilePerSector(const char *nameFileTCFPerSec,
        for (Int_t iParam = 0; iParam < paramTupleSec->GetEntries(); iParam++) {
          paramTupleSec->GetEntry(iParam);
          Float_t *paramArgs = paramTupleSec->GetArgs();
-         if (paramArgs[0] == roc) {
+         if ((paramArgs[0]-roc)<1e-7) { // if roc is found
            validFlag = 1; 
-           K0 = TMath::Nint(paramArgs[7] * (TMath::Power(2,16) - 1));
-           K1 = TMath::Nint(paramArgs[8] * (TMath::Power(2,16) - 1));
-           K2 = TMath::Nint(paramArgs[9] * (TMath::Power(2,16) - 1));
-           L0 = TMath::Nint(paramArgs[4] * (TMath::Power(2,16) - 1));
-           L1 = TMath::Nint(paramArgs[5] * (TMath::Power(2,16) - 1));
-           L2 = TMath::Nint(paramArgs[6] * (TMath::Power(2,16) - 1));
+           k0 = TMath::Nint(paramArgs[7] * (TMath::Power(2,16) - 1));
+           k1 = TMath::Nint(paramArgs[8] * (TMath::Power(2,16) - 1));
+           k2 = TMath::Nint(paramArgs[9] * (TMath::Power(2,16) - 1));
+           l0 = TMath::Nint(paramArgs[4] * (TMath::Power(2,16) - 1));
+           l1 = TMath::Nint(paramArgs[5] * (TMath::Power(2,16) - 1));
+           l2 = TMath::Nint(paramArgs[6] * (TMath::Power(2,16) - 1));
            break;
          }
        }
        if (!validFlag) { // No TCF parameters found for this roc 
-         K0 = K1 = K2 = L0 = L1 = L2 = -1;
+         k0 = k1 = k2 = l0 = l1 = l2 = -1;
        }
        
        fileOut << entryNum++ << "\t" << side << "\t" << sector << "\t" << rcu << "\t" << -1 << "\t";
-       fileOut << K0 << "\t" << K1 << "\t" << K2 << "\t" << L0 << "\t" << L1 << "\t" << L2 << "\t" << validFlag << std::endl;
+       fileOut << k0 << "\t" << k1 << "\t" << k2 << "\t" << l0 << "\t" << l1 << "\t" << l2 << "\t" << validFlag << std::endl;
       }
     }
   }