]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCclustererKr.cxx
Update (Chiara)
[u/mrichter/AliRoot.git] / TPC / AliTPCclustererKr.cxx
index 567c8d753335805d94a9eaa1514efbd451037c30..03c16a048e685c89cfa3e126765811f2f60787f7 100644 (file)
-/**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- *                                                                        *
- * Author: The ALICE Off-line Project.                                    *
- * Contributors are mentioned in the code where appropriate.              *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
-
-/* $Id: AliTPCclustererKr.cxx,v 1.7 2008/02/06 17:24:53 matyja Exp $ */
-
-//-----------------------------------------------------------------
-//           Implementation of the TPC cluster class
-//
-// Origin: Adam Matyja, INP PAN, adam.matyja@ifj.edu.pl
-//-----------------------------------------------------------------
-
-#include "AliTPCclustererKr.h"
-#include "AliTPCclusterKr.h"
-#include <vector>
-#include "TObject.h"
-#include "AliPadMax.h"
-#include "AliSimDigits.h"
-#include "AliTPCv4.h"
-#include "AliTPCParam.h"
-#include "AliTPCDigitsArray.h"
-#include "AliTPCvtpr.h"
-#include "AliTPCClustersRow.h"
-#include "TTree.h"
-
-//used in raw data finder
-#include "AliTPCROC.h"
-#include "AliTPCCalPad.h"
-#include "AliTPCAltroMapping.h"
-#include "AliTPCcalibDB.h"
-#include "AliTPCRawStream.h"
-#include "AliTPCRecoParam.h"
-#include "AliTPCReconstructor.h"
-#include "AliRawReader.h"
-#include "AliTPCCalROC.h"
-
-ClassImp(AliTPCclustererKr)
-
-
-AliTPCclustererKr::AliTPCclustererKr()
-  :TObject(),
-  fRawData(kFALSE),
-  fRowCl(0),
-  fInput(0),
-  fOutput(0),
-  fParam(0),
-  fDigarr(0),
-  fRecoParam(0),
-  fIsOldRCUFormat(kFALSE)
-{
-//
-// default constructor
-//
-}
-
-AliTPCclustererKr::AliTPCclustererKr(const AliTPCclustererKr &param)
-  :TObject(),
-  fRawData(kFALSE),
-  fRowCl(0),
-  fInput(0),
-  fOutput(0),
-  fParam(0),
-  fDigarr(0),
-  fRecoParam(0),
-  fIsOldRCUFormat(kFALSE)
-{
-//
-// copy constructor
-//
-  fParam = param.fParam;
-  fRecoParam=param.fRecoParam;
-  fIsOldRCUFormat=param.fIsOldRCUFormat;
-  fRawData=param.fRawData;
-  fRowCl =param.fRowCl ;
-  fInput =param.fInput ;
-  fOutput=param.fOutput;
-  fDigarr=param.fDigarr;
-} 
-
-AliTPCclustererKr & AliTPCclustererKr::operator = (const AliTPCclustererKr & param)
-{
-  fParam = param.fParam;
-  fRecoParam=param.fRecoParam;
-  fIsOldRCUFormat=param.fIsOldRCUFormat;
-  fRawData=param.fRawData;
-  fRowCl =param.fRowCl ;
-  fInput =param.fInput ;
-  fOutput=param.fOutput;
-  fDigarr=param.fDigarr;
-  return (*this);
-}
-
-AliTPCclustererKr::~AliTPCclustererKr()
-{
-  //
-  // destructor
-  //
-}
-
-void AliTPCclustererKr::SetRecoParam(AliTPCRecoParam *recoParam)
-{
-  if (recoParam) {
-    fRecoParam = recoParam;
-  }else{
-    //set default parameters if not specified
-    fRecoParam = AliTPCReconstructor::GetRecoParam();
-    if (!fRecoParam)  fRecoParam = AliTPCRecoParam::GetLowFluxParam();
-  }
-  return;
-}
-
-
-////____________________________________________________________________________
-////       I/O
-void AliTPCclustererKr::SetInput(TTree * tree)
-{
-  //
-  // set input tree with digits
-  //
-  fInput = tree;  
-  if  (!fInput->GetBranch("Segment")){
-    cerr<<"AliTPCclusterKr::findClusterKr(): no proper input tree !\n";
-    fInput=0;
-    return;
-  }
-}
-
-void AliTPCclustererKr::SetOutput(TTree * tree) 
-{
-  //
-  // set output
-  //
-  fOutput= tree;  
-  AliTPCClustersRow clrow;
-  AliTPCClustersRow *pclrow=&clrow;  
-  clrow.SetClass("AliTPCclusterKr");
-  clrow.SetArray(1); // to make Clones array
-  fOutput->Branch("Segment","AliTPCClustersRow",&pclrow,32000,200);    
-}
-
-////____________________________________________________________________________
-//// with new I/O
-Int_t AliTPCclustererKr::finderIO()
-{
-  // Krypton cluster finder for simulated events from MC
-
-  if (!fInput) { 
-    Error("Digits2Clusters", "input tree not initialised");
-    return 10;
-  }
-  
-  if (!fOutput) {
-    Error("Digits2Clusters", "output tree not initialised");
-    return 11;
-  }
-
-  findClusterKrIO();
-  return 0;
-}
-
-Int_t AliTPCclustererKr::finderIO(AliRawReader* rawReader)
-{
-  // Krypton cluster finder for the TPC raw data
-  //
-  // fParam must be defined before
-
-  // consider noiceROC or not
-
-  if(rawReader)fRawData=kTRUE; //set flag to data
-
-  if (!fOutput) {
-    Error("Digits2Clusters", "output tree not initialised");
-    return 11;
-  }
-
-  fParam->SetMaxTBin(fRecoParam->GetLastBin());//set number of timebins from reco -> param
-  //   used later for memory allocation
-
-  Bool_t isAltro=kFALSE;
-
-  AliTPCROC * roc = AliTPCROC::Instance();
-  //AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
-  AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
-  //
-  AliTPCRawStream input(rawReader,(AliAltroMapping**)mapping);
-
-  const Int_t kNIS = fParam->GetNInnerSector();//number of inner sectors
-  const Int_t kNOS = fParam->GetNOuterSector();//number of outer sectors
-  const Int_t kNS = kNIS + kNOS;//all sectors
-  Int_t zeroSup = fParam->GetZeroSup();//zero suppression parameter
-
-  //crate TPC view
-  AliTPCDigitsArray *digarr=new AliTPCDigitsArray(kFALSE);//data not sim
-  digarr->Setup(fParam);//as usually parameters
-
-  //
-  // Loop over sectors
-  //
-  for(Int_t sec = 0; sec < kNS; sec++) {
-    //AliTPCCalROC * noiseROC   = noiseTPC->GetCalROC(sec);  // noise per given sector
-    Int_t nRows = 0; //number of rows in sector
-    Int_t nDDLs = 0; //number of DDLs
-    Int_t indexDDL = 0; //DDL index
-    if (sec < kNIS) {
-      nRows = fParam->GetNRowLow();
-      nDDLs = 2;
-      indexDDL = sec * 2;
-    }else {
-      nRows = fParam->GetNRowUp();
-      nDDLs = 4;
-      indexDDL = (sec-kNIS) * 4 + kNIS * 2;
-    }
-
-    //
-    // Load the raw data for corresponding DDLs
-    //
-    rawReader->Reset();
-    input.SetOldRCUFormat(fIsOldRCUFormat);
-    rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
-
-    if(input.Next()) {
-      isAltro=kTRUE;
-      // Allocate memory for rows in sector (pads(depends on row) x timebins)
-      for(Int_t row = 0; row < nRows; row++) {
-       digarr->CreateRow(sec,row);
-      }//end loop over rows
-    }
-    rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
-
-    //
-    // Begin loop over altro data
-    //
-    while (input.Next()) {
-
-      //check sector consistency
-      if (input.GetSector() != sec)
-       AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",sec,input.GetSector()));
-      
-      //check row consistency
-      Short_t iRow = input.GetRow();
-      if (iRow < 0 || iRow >= nRows){
-       AliError(Form("Pad-row index (%d) outside the range (%d -> %d) !",
-                     iRow, 0, nRows -1));
-       continue;
-      }
-
-      //check pad consistency
-      Short_t iPad = input.GetPad();
-      if (iPad < 0 || iPad >= (Short_t)(roc->GetNPads(sec,iRow))) {
-       AliError(Form("Pad index (%d) outside the range (%d -> %d) !",
-                     iPad, 0, roc->GetNPads(sec,iRow) ));
-       continue;
-      }
-
-      //check time consistency
-      Short_t iTimeBin = input.GetTime();
-      if ( iTimeBin < fRecoParam->GetFirstBin() || iTimeBin >= fRecoParam->GetLastBin()){
-       //cout<<iTimeBin<<endl;
-       continue;
-       AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
-                     iTimeBin, 0, fRecoParam->GetLastBin() -1));
-      }
-
-      //signal
-      Int_t signal = input.GetSignal();
-      if (signal <= zeroSup) {
-       //continue;
-       digarr->GetRow(sec,iRow)->SetDigitFast(0,iTimeBin,iPad);
-      }
-      (//(AliSimDigits*)
-       digarr->GetRow(sec,iRow))->SetDigitFast(signal,iTimeBin,iPad);
-    }//end of loop over altro data
-  }//end of loop over sectors
-  
-  SetDigArr(digarr);
-  if(isAltro) findClusterKrIO();
-  delete digarr;
-
-  return 0;
-}
-
-////____________________________________________________________________________
-Int_t AliTPCclustererKr::findClusterKrIO()
-{
-  //fParam and  fDigarr must be set to run this method
-
-  Int_t cluster_counter=0;
-  const Short_t NTotalSector=fParam->GetNSector();//number of sectors
-  for(Short_t sec=0; sec<NTotalSector; sec++){
-    
-    //vector of maxima for each sector
-    std::vector<AliPadMax*> maxima_in_sector;
-    
-    const Short_t Nrows=fParam->GetNRow(sec);//number of rows in sector
-    for(Short_t row=0; row<Nrows; row++){
-      AliSimDigits *digrow;
-      if(fRawData){
-       digrow = (AliSimDigits*)fDigarr->GetRow(sec,row);//real data
-      }else{
-       digrow = (AliSimDigits*)fDigarr->LoadRow(sec,row);//MC
-      }
-      if(digrow){//if pointer exist
-       digrow->ExpandBuffer(); //decrunch
-       const Short_t npads = digrow->GetNCols();  // number of pads
-       const Short_t ntime = digrow->GetNRows(); // number of timebins
-       for(Short_t np=0;np<npads;np++){
-         
-         Short_t tb_max=-1;//timebin of maximum 
-         Short_t value_maximum=-1;//value of maximum in adc
-         Short_t increase_begin=-1;//timebin when increase starts
-         Short_t sum_adc=0;//sum of adc on the pad in maximum surrounding
-         bool if_increase_begin=true;//flag - check if increasing start
-         bool if_maximum=false;//flag - check if it could be maximum
-
-         for(Short_t nt=0;nt<ntime;nt++){
-           Short_t adc = digrow->GetDigitFast(nt,np);
-           if(adc<3){
-             if(if_maximum){
-               if(nt-1-increase_begin<1){//at least 2 time bins
-                 tb_max=-1;
-                 value_maximum=-1;
-                 increase_begin=-1;
-                 sum_adc=0;
-                 if_increase_begin=true;
-                 if_maximum=false;
-                 continue;
-               }
-               //insert maximum, default values and set flags
-               AliPadMax *one_maximum = new AliPadMax(AliTPCvtpr(value_maximum,
-                                                                 tb_max,
-                                                                 np,
-                                                                 row),
-                                                      increase_begin,
-                                                      nt-1,
-                                                      sum_adc);
-               maxima_in_sector.push_back(one_maximum);
-               
-               tb_max=-1;
-               value_maximum=-1;
-               increase_begin=-1;
-               sum_adc=0;
-               if_increase_begin=true;
-               if_maximum=false;
-             }
-             continue;
-           }
-           
-           if(if_increase_begin){
-             if_increase_begin=false;
-             increase_begin=nt;
-           }
-           
-           if(adc>value_maximum){
-             tb_max=nt;
-             value_maximum=adc;
-             if_maximum=true;
-           }
-           sum_adc+=adc;
-           if(nt==ntime-1 && if_maximum && ntime-1-increase_begin>2){//on the edge
-             //insert maximum, default values and set flags
-             AliPadMax *one_maximum = new AliPadMax(AliTPCvtpr(value_maximum,
-                                                               tb_max,
-                                                               np,
-                                                               row),
-                                                    increase_begin,
-                                                    nt-1,
-                                                    sum_adc);
-             maxima_in_sector.push_back(one_maximum);
-             
-             tb_max=-1;
-             value_maximum=-1;
-             increase_begin=-1;
-             sum_adc=0;
-             if_increase_begin=true;
-             if_maximum=false;
-             continue;
-           }
-           
-         }//end loop over timebins
-       }//end loop over pads
-//      }else{
-//     cout<<"Pointer does not exist!!"<<endl;
-      }//end if poiner exists
-    }//end loop over rows
-    
-
-    Short_t max_dig=0;
-    Short_t max_sum_adc=0;
-    Short_t max_nt=0;
-    Short_t max_np=0;
-    Short_t max_row=0;
-    
-    for( std::vector<AliPadMax*>::iterator mp1  = maxima_in_sector.begin();
-        mp1 != maxima_in_sector.end(); ++mp1 ) {
-      
-      AliTPCclusterKr *tmp=new AliTPCclusterKr();
-      
-      Short_t n_used_pads=1;
-      Short_t cluster_value=0;
-      cluster_value+=(*mp1)->GetSum();
-      
-      max_dig      =(*mp1)->GetAdc() ;
-      max_sum_adc  =(*mp1)->GetSum() ;
-      max_nt       =(*mp1)->GetTime();
-      max_np       =(*mp1)->GetPad() ;
-      max_row      =(*mp1)->GetRow() ;
-      
-      AliSimDigits *digrow_tmp;
-      if(fRawData){
-       digrow_tmp = (AliSimDigits*)fDigarr->GetRow(sec,(*mp1)->GetRow());
-      }else{
-       digrow_tmp = (AliSimDigits*)fDigarr->LoadRow(sec,(*mp1)->GetRow());
-      }
-
-      digrow_tmp->ExpandBuffer(); //decrunch
-      for(Short_t tb=(*mp1)->GetBegin(); tb<((*mp1)->GetEnd())+1; tb++){
-       Short_t adc_tmp = digrow_tmp->GetDigitFast(tb,(*mp1)->GetPad());
-       AliTPCvtpr *vtpr=new AliTPCvtpr(adc_tmp,tb,(*mp1)->GetPad(),(*mp1)->GetRow());
-       tmp->fCluster.push_back(vtpr);
-      }
-      
-      maxima_in_sector.erase(mp1);
-      mp1--;
-      
-      for( std::vector<AliPadMax*>::iterator mp2  = maxima_in_sector.begin();
-          mp2 != maxima_in_sector.end(); ++mp2 ) {
-       
-       Short_t two_pad_max=4;
-       Short_t two_row_max=3;
-       
-       if(abs(max_row - (*mp2)->GetRow())<two_row_max && 
-          abs(max_np - (*mp2)->GetPad())<two_pad_max  &&
-          abs(max_nt - (*mp2)->GetTime())<7){
-         
-         cluster_value+=(*mp2)->GetSum();
-         n_used_pads++;
-         
-         AliSimDigits *digrow_tmp1;
-         if(fRawData){
-           digrow_tmp1 = (AliSimDigits*)fDigarr->GetRow(sec,(*mp2)->GetRow());
-         }else{
-           digrow_tmp1 = (AliSimDigits*)fDigarr->LoadRow(sec,(*mp2)->GetRow());
-         }
-         digrow_tmp1->ExpandBuffer(); //decrunch
-         
-         for(Short_t tb=(*mp2)->GetBegin(); tb<(*mp2)->GetEnd()+1; tb++){
-           Short_t adc_tmp = digrow_tmp1->GetDigitFast(tb,(*mp2)->GetPad());
-           AliTPCvtpr *vtpr=new AliTPCvtpr(adc_tmp,tb,(*mp2)->GetPad(),(*mp2)->GetRow());
-             tmp->fCluster.push_back(vtpr);
-         }
-         
-         //which one is bigger
-         if( (*mp2)->GetAdc() > max_dig ){
-           max_dig      =(*mp2)->GetAdc() ;
-           max_sum_adc  =(*mp2)->GetSum() ;
-           max_nt       =(*mp2)->GetTime();
-           max_np       =(*mp2)->GetPad() ;
-           max_row      =(*mp2)->GetRow() ;
-         } else if ( (*mp2)->GetAdc() == max_dig ){
-           if( (*mp2)->GetSum() > max_sum_adc){
-             max_dig      =(*mp2)->GetAdc() ;
-             max_sum_adc  =(*mp2)->GetSum() ;
-             max_nt       =(*mp2)->GetTime();
-             max_np       =(*mp2)->GetPad() ;
-             max_row      =(*mp2)->GetRow() ;
-           }
-         }
-         maxima_in_sector.erase(mp2);
-         mp2--;
-       }
-      }//inside loop
-      
-      //through out ADC=6,7 on 1 pad, 2 tb and ADC=12 on 2 pads,2 tb
-      if(n_used_pads==1 && cluster_value/tmp->fCluster.size()<3.6)continue;
-      if(n_used_pads==2 && cluster_value/tmp->fCluster.size()<3.1)continue;
-      
-      tmp->SetADCcluster(cluster_value);
-      tmp->SetNpads(n_used_pads);
-      tmp->SetMax(AliTPCvtpr(max_dig,max_nt,max_np,max_row));
-      tmp->SetSec(sec);
-      tmp->SetSize();
-      
-      cluster_counter++;
-      
-      //save each cluster into file
-
-      AliTPCClustersRow *clrow= new AliTPCClustersRow();
-      fRowCl=clrow;
-      clrow->SetClass("AliTPCclusterKr");
-      clrow->SetArray(1);
-      fOutput->GetBranch("Segment")->SetAddress(&clrow);
-
-      Int_t tmp_cluster=0;
-      TClonesArray * arr = fRowCl->GetArray();
-      AliTPCclusterKr * cl = new ((*arr)[tmp_cluster]) AliTPCclusterKr(*tmp);
-      
-      fOutput->Fill(); 
-      delete clrow;
-
-      //end of save each cluster into file adc.root
-    }//outer loop
-
-  }//end sector for
-  cout<<"Number of clusters in event: "<<cluster_counter<<endl;
-
-  return 0;
-}
-
-////____________________________________________________________________________
+/**************************************************************************\r
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
+ *                                                                        *\r
+ * Author: The ALICE Off-line Project.                                    *\r
+ * Contributors are mentioned in the code where appropriate.              *\r
+ *                                                                        *\r
+ * Permission to use, copy, modify and distribute this software and its   *\r
+ * documentation strictly for non-commercial purposes is hereby granted   *\r
+ * without fee, provided that the above copyright notice appears in all   *\r
+ * copies and that both the copyright notice and this permission notice   *\r
+ * appear in the supporting documentation. The authors make no claims     *\r
+ * about the suitability of this software for any purpose. It is          *\r
+ * provided "as is" without express or implied warranty.                  *\r
+ **************************************************************************/\r
+\r
+/* $Id: AliTPCclustererKr.cxx,v 1.7 2008/02/06 17:24:53 matyja Exp $ */\r
+\r
+//-----------------------------------------------------------------\r
+//           Implementation of the TPC Kr cluster class\r
+//\r
+// Origin: Adam Matyja, INP PAN, adam.matyja@ifj.edu.pl\r
+//-----------------------------------------------------------------\r
+\r
+/*\r
+Instruction - how to use that:\r
+There are two macros prepared. One is for preparing clusters from MC \r
+samples:  FindKrClusters.C. The output is kept in TPC.RecPoints.root.\r
+The other macro is prepared for data analysis: FindKrClustersRaw.C. \r
+The output is created for each processed file in root file named adc.root. \r
+For each data subsample the same named file is created. So be careful \r
+do not overwrite them. \r
+\r
+Additional selection criteria to select the GOLD cluster\r
+Example:\r
+// open  file with clusters\r
+TFile f("Krypton.root");\r
+TTree * tree = (TTree*)f.Get("Kr")\r
+TCut cutR0("cutR0","fADCcluster/fSize<100");        // adjust it according v seetings - \r
+TCut cutR1("cutR1","fADCcluster/fSize>7");          // cosmic tracks and noise removal\r
+TCut cutR2("cutR2","fMax.fAdc/fADCcluster<0.2");    // digital noise removal\r
+TCut cutR3("cutR3","fMax.fAdc/fADCcluster>0.01");   // noise removal\r
+TCut cutS1("cutS1","fSize<200");    // adjust it according v seetings - cosmic tracks\r
+TCut cutAll = cutR0+cutR1+cutR2+cutR3+cutS1;\r
+This values are typical values to be applied in selectors\r
+\r
+\r
+*\r
+**** MC ****\r
+*\r
+\r
+To run clusterizaton for MC type:\r
+.x FindKrClusters.C\r
+\r
+If you don't want to use the standard selection criteria then you \r
+have to do following:\r
+\r
+// load the standard setup\r
+AliRunLoader* rl = AliRunLoader::Open("galice.root");\r
+AliTPCLoader *tpcl = (AliTPCLoader*)rl->GetLoader("TPCLoader");\r
+tpcl->LoadDigits();\r
+rl->LoadgAlice();\r
+gAlice=rl->GetAliRun();\r
+TDirectory *cwd = gDirectory;\r
+AliTPCv4 *tpc = (AliTPCv4*)gAlice->GetDetector("TPC");\r
+Int_t ver = tpc->IsVersion();\r
+rl->CdGAFile();\r
+AliTPCParam *param=(AliTPCParamSR *)gDirectory->Get("75x40_100x60_150x60");\r
+AliTPCDigitsArray *digarr=new AliTPCDigitsArray;\r
+digarr->Setup(param);\r
+cwd->cd();\r
+\r
+//loop over events\r
+Int_t nevmax=rl->GetNumberOfEvents();\r
+for(Int_t nev=0;nev<nevmax ;nev++){\r
+  rl->GetEvent(nev);\r
+  TTree* input_tree= tpcl->TreeD();//load tree with digits\r
+  digarr->ConnectTree(input_tree);\r
+  TTree *output_tree =tpcl->TreeR();//load output tree\r
+\r
+  AliTPCclustererKr *clusters = new AliTPCclustererKr();\r
+  clusters->SetParam(param);\r
+  clusters->SetInput(input_tree);\r
+  clusters->SetOutput(output_tree);\r
+  clusters->SetDigArr(digarr);\r
+  \r
+//If you want to change the cluster finder parameters for MC there are \r
+//several of them:\r
+\r
+//1. signal threshold (everything below the given number is treated as 0)\r
+  clusters->SetMinAdc(3);\r
+\r
+//2. number of neighbouring timebins to be considered\r
+  clusters->SetMinTimeBins(2);\r
+\r
+//3. distance of the cluster center to the center of a pad in pad-padrow plane \r
+//(in cm). Remenber that this is still quantified by pad size.\r
+  clusters->SetMaxPadRangeCm(2.5);\r
+\r
+//4. distance of the cluster center to the center of a padrow in pad-padrow \r
+//plane (in cm). Remenber that this is still quantified by pad size.\r
+  clusters->SetMaxRowRangeCm(3.5);\r
+\r
+//5. distance of the cluster center to the max time bin on a pad (in tackts)\r
+//ie. fabs(centerT - time)<7\r
+  clusters->SetMaxTimeRange(7);\r
+\r
+//6. cut reduce peak at 0. There are noises which appear mostly as two \r
+//timebins on one pad.\r
+  clusters->SetValueToSize(3.5);\r
+\r
+\r
+  clusters->finderIO();\r
+  tpcl->WriteRecPoints("OVERWRITE");\r
+}\r
+delete rl;//cleans everything\r
+\r
+*\r
+********* DATA *********\r
+*\r
+\r
+To run clusterizaton for DATA for file named raw_data.root type:\r
+.x FindKrClustersRaw.C("raw_data.root")\r
+\r
+If you want to change some criteria do the following:\r
+\r
+//\r
+// remove Altro warnings\r
+//\r
+AliLog::SetClassDebugLevel("AliTPCRawStream",-5);\r
+AliLog::SetClassDebugLevel("AliRawReaderDate",-5);\r
+AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);\r
+AliLog::SetModuleDebugLevel("RAW",-5);\r
+\r
+//\r
+// Get database with noises\r
+//\r
+//  char *ocdbpath = gSystem->Getenv("OCDB_PATH");\r
+char *ocdbpath ="local:///afs/cern.ch/alice/tpctest/OCDB";\r
+if (ocdbpath==0){\r
+ocdbpath="alien://folder=/alice/data/2007/LHC07w/OCDB/";\r
+}\r
+AliCDBManager * man = AliCDBManager::Instance();\r
+man->SetDefaultStorage(ocdbpath);\r
+man->SetRun(0);\r
+AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();\r
+AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();\r
+\r
+//define tree\r
+TFile *hfile=new TFile("adc.root","RECREATE","ADC file");\r
+// Create a ROOT Tree\r
+TTree *mytree = new TTree("Kr","Krypton cluster tree");\r
+\r
+//define infput file\r
+const char *fileName="data.root";\r
+AliRawReader *reader = new AliRawReaderRoot(fileName);\r
+//AliRawReader *reader = new AliRawReaderDate(fileName);\r
+reader->Reset();\r
+AliAltroRawStreamFast* stream = new AliAltroRawStreamFast(reader);\r
+stream->SelectRawData("TPC");\r
+\r
+//one general output\r
+AliTPCclustererKr *clusters = new AliTPCclustererKr();\r
+clusters->SetOutput(mytree);\r
+clusters->SetRecoParam(0);//standard reco parameters\r
+AliTPCParamSR *param=new AliTPCParamSR();\r
+clusters->SetParam(param);//TPC parameters(sectors, timebins, etc.)\r
+\r
+//set cluster finder parameters (from data):\r
+//1. zero suppression parameter\r
+  clusters->SetZeroSup(param->GetZeroSup());\r
+\r
+//2. first bin\r
+  clusters->SetFirstBin(60);\r
+\r
+//3. last bin\r
+  clusters->SetLastBin(950);\r
+\r
+//4. maximal noise\r
+  clusters->SetMaxNoiseAbs(2);\r
+\r
+//5. maximal amount of sigma of noise\r
+  clusters->SetMaxNoiseSigma(3);\r
+\r
+//The remaining parameters are the same paramters as for MC (see MC section \r
+//points 1-6)\r
+  clusters->SetMinAdc(3);\r
+  clusters->SetMinTimeBins(2);\r
+  clusters->SetMaxPadRangeCm(2.5);\r
+  clusters->SetMaxRowRangeCm(3.5);\r
+  clusters->SetMaxTimeRange(7);\r
+  clusters->SetValueToSize(3.5);\r
+\r
+while (reader->NextEvent()) {\r
+  clusters->FinderIO(reader);\r
+}\r
+\r
+hfile->Write();\r
+hfile->Close();\r
+delete stream;\r
+\r
+\r
+*/\r
+\r
+#include "AliTPCclustererKr.h"\r
+#include "AliTPCclusterKr.h"\r
+//#include <vector>\r
+#include <list>\r
+#include "TObject.h"\r
+#include "AliPadMax.h"\r
+#include "AliSimDigits.h"\r
+#include "AliTPCv4.h"\r
+#include "AliTPCParam.h"\r
+#include "AliTPCDigitsArray.h"\r
+#include "AliTPCvtpr.h"\r
+#include "AliTPCClustersRow.h"\r
+#include "TTree.h"\r
+#include "TH1F.h"\r
+#include "TH2F.h"\r
+#include "TTreeStream.h"\r
+\r
+#include "AliTPCTransform.h"\r
+\r
+//used in raw data finder\r
+#include "AliTPCROC.h"\r
+#include "AliTPCCalPad.h"\r
+#include "AliTPCAltroMapping.h"\r
+#include "AliTPCcalibDB.h"\r
+#include "AliTPCRawStream.h"\r
+#include "AliTPCRawStreamV3.h"\r
+#include "AliTPCRecoParam.h"\r
+#include "AliTPCReconstructor.h"\r
+#include "AliRawReader.h"\r
+#include "AliTPCCalROC.h"\r
+#include "AliRawEventHeaderBase.h"\r
+\r
+ClassImp(AliTPCclustererKr)\r
+\r
+\r
+AliTPCclustererKr::AliTPCclustererKr()\r
+  :TObject(),\r
+  fRawData(kFALSE),\r
+  fInput(0),\r
+  fOutput(0),\r
+  fParam(0),\r
+  fDigarr(0),\r
+  fRecoParam(0),\r
+  fZeroSup(2),\r
+  fFirstBin(60),\r
+  fLastBin(950),\r
+  fMaxNoiseAbs(2),\r
+  fMaxNoiseSigma(3),\r
+  fMinAdc(3),\r
+  fMinTimeBins(2),\r
+//  fMaxPadRange(4),\r
+//  fMaxRowRange(3),\r
+  fMaxTimeRange(7),\r
+  fValueToSize(3.5),\r
+  fMaxPadRangeCm(2.5),\r
+  fMaxRowRangeCm(3.5),\r
+  fIsolCut(3),\r
+  fDebugLevel(-1),\r
+  fHistoRow(0),\r
+  fHistoPad(0),\r
+  fHistoTime(0),\r
+   fHistoRowPad(0),\r
+   fTimeStamp(0),\r
+  fRun(0)\r
+{\r
+//\r
+// default constructor\r
+//\r
+}\r
+\r
+AliTPCclustererKr::AliTPCclustererKr(const AliTPCclustererKr &param)\r
+  :TObject(),\r
+  fRawData(kFALSE),\r
+  fInput(0),\r
+  fOutput(0),\r
+  fParam(0),\r
+  fDigarr(0),\r
+  fRecoParam(0),\r
+  fZeroSup(2),\r
+  fFirstBin(60),\r
+  fLastBin(950),\r
+  fMaxNoiseAbs(2),\r
+  fMaxNoiseSigma(3),\r
+  fMinAdc(3),\r
+  fMinTimeBins(2),\r
+//  fMaxPadRange(4),\r
+//  fMaxRowRange(3),\r
+  fMaxTimeRange(7),\r
+  fValueToSize(3.5),\r
+  fMaxPadRangeCm(2.5),\r
+  fMaxRowRangeCm(3.5),\r
+  fIsolCut(3),\r
+  fDebugLevel(-1),\r
+  fHistoRow(0),\r
+  fHistoPad(0),\r
+  fHistoTime(0),\r
+  fHistoRowPad(0),\r
+   fTimeStamp(0),\r
+   fRun(0)\r
+{\r
+//\r
+// copy constructor\r
+//\r
+  fParam = param.fParam;\r
+  fRecoParam = param.fRecoParam;\r
+  fRawData = param.fRawData;\r
+  fInput  = param.fInput ;\r
+  fOutput = param.fOutput;\r
+  fDigarr = param.fDigarr;\r
+  fZeroSup       = param.fZeroSup       ;\r
+  fFirstBin     = param.fFirstBin      ;\r
+  fLastBin      = param.fLastBin       ;\r
+  fMaxNoiseAbs  = param.fMaxNoiseAbs   ;\r
+  fMaxNoiseSigma = param.fMaxNoiseSigma ;\r
+  fMinAdc = param.fMinAdc;\r
+  fMinTimeBins = param.fMinTimeBins;\r
+//  fMaxPadRange  = param.fMaxPadRange ;\r
+//  fMaxRowRange  = param.fMaxRowRange ;\r
+  fMaxTimeRange = param.fMaxTimeRange;\r
+  fValueToSize  = param.fValueToSize;\r
+  fMaxPadRangeCm = param.fMaxPadRangeCm;\r
+  fMaxRowRangeCm = param.fMaxRowRangeCm;\r
+  fIsolCut = param.fIsolCut;\r
+  fDebugLevel = param.fDebugLevel;\r
+  fHistoRow    = param.fHistoRow   ;\r
+  fHistoPad    = param.fHistoPad  ;\r
+  fHistoTime   = param.fHistoTime;\r
+  fHistoRowPad = param.fHistoRowPad;\r
+  fTimeStamp = param.fTimeStamp;\r
+  fRun = param.fRun;\r
+\r
+} \r
+\r
+AliTPCclustererKr & AliTPCclustererKr::operator = (const AliTPCclustererKr & param)\r
+{\r
+  //\r
+  // assignment operator\r
+  //\r
+  fParam = param.fParam;\r
+  fRecoParam = param.fRecoParam;\r
+  fRawData = param.fRawData;\r
+  fInput  = param.fInput ;\r
+  fOutput = param.fOutput;\r
+  fDigarr = param.fDigarr;\r
+  fZeroSup       = param.fZeroSup       ;\r
+  fFirstBin     = param.fFirstBin      ;\r
+  fLastBin      = param.fLastBin       ;\r
+  fMaxNoiseAbs  = param.fMaxNoiseAbs   ;\r
+  fMaxNoiseSigma = param.fMaxNoiseSigma ;\r
+  fMinAdc = param.fMinAdc;\r
+  fMinTimeBins = param.fMinTimeBins;\r
+//  fMaxPadRange  = param.fMaxPadRange ;\r
+//  fMaxRowRange  = param.fMaxRowRange ;\r
+  fMaxTimeRange = param.fMaxTimeRange;\r
+  fValueToSize  = param.fValueToSize;\r
+  fMaxPadRangeCm = param.fMaxPadRangeCm;\r
+  fMaxRowRangeCm = param.fMaxRowRangeCm;\r
+  fIsolCut = param.fIsolCut;\r
+  fDebugLevel = param.fDebugLevel;\r
+  fHistoRow    = param.fHistoRow   ;\r
+  fHistoPad    = param.fHistoPad  ;\r
+  fHistoTime   = param.fHistoTime;\r
+  fHistoRowPad = param.fHistoRowPad;\r
+  fTimeStamp = param.fTimeStamp;\r
+  fRun = param.fRun;\r
+  return (*this);\r
+}\r
+\r
+AliTPCclustererKr::~AliTPCclustererKr()\r
+{\r
+  //\r
+  // destructor\r
+  //\r
+  delete fOutput;\r
+}\r
+\r
+void AliTPCclustererKr::SetRecoParam(AliTPCRecoParam *recoParam)\r
+{\r
+  //\r
+  // set reconstruction parameters\r
+  //\r
+  if (recoParam) {\r
+    fRecoParam = recoParam;\r
+  }else{\r
+    //set default parameters if not specified\r
+    fRecoParam = AliTPCReconstructor::GetRecoParam();\r
+    if (!fRecoParam)  fRecoParam = AliTPCRecoParam::GetLowFluxParam();\r
+  }\r
+  return;\r
+}\r
+\r
+\r
+////____________________________________________________________________________\r
+////       I/O\r
+void AliTPCclustererKr::SetInput(TTree * tree)\r
+{\r
+  //\r
+  // set input tree with digits\r
+  //\r
+  fInput = tree;  \r
+  if  (!fInput->GetBranch("Segment")){\r
+    cerr<<"AliTPCclusterKr::FindClusterKr(): no proper input tree !\n";\r
+    fInput=0;\r
+    return;\r
+  }\r
+}\r
+\r
+void AliTPCclustererKr::SetOutput(TTree * /*tree*/) \r
+{\r
+  //\r
+  //dummy\r
+  //\r
+  fOutput = new TTreeSRedirector("Krypton.root");\r
+}\r
+\r
+////____________________________________________________________________________\r
+//// with new I/O\r
+Int_t AliTPCclustererKr::FinderIO()\r
+{\r
+  // Krypton cluster finder for simulated events from MC\r
+\r
+  if (!fInput) { \r
+    Error("Digits2Clusters", "input tree not initialised");\r
+    return 10;\r
+  }\r
+  \r
+  if (!fOutput) {\r
+    Error("Digits2Clusters", "output tree not initialised");\r
+    return 11;\r
+  }\r
+\r
+  FindClusterKrIO();\r
+  return 0;\r
+}\r
+\r
+\r
+\r
+Int_t AliTPCclustererKr::FinderIO(AliRawReader* rawReader)\r
+{\r
+  // Krypton cluster finder for the TPC raw data\r
+  // this method is unsing AliAltroRawStreamV3\r
+  // fParam must be defined before\r
+  if (!rawReader) return 1;\r
+  //\r
+  fRawData=kTRUE; //set flag to data\r
+  \r
+  if (!fOutput) {\r
+    Error("Digits2Clusters", "output tree not initialised");\r
+    return 11;\r
+  }\r
+  \r
+  fParam->SetMaxTBin(fRecoParam->GetLastBin());//set number of timebins from reco -> param\r
+  //   used later for memory allocation\r
+\r
+  AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();\r
+  if (eventHeader){\r
+    fTimeStamp = eventHeader->Get("Timestamp");\r
+    fRun = rawReader->GetRunNumber();\r
+  }\r
+\r
+\r
+  Bool_t isAltro=kFALSE;\r
+  \r
+  AliTPCROC * roc = AliTPCROC::Instance();\r
+  AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();\r
+  AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();\r
+  //\r
+  AliTPCRawStreamV3 input(rawReader,(AliAltroMapping**)mapping);\r
+  \r
+  const Int_t kNIS = fParam->GetNInnerSector();//number of inner sectors\r
+  const Int_t kNOS = fParam->GetNOuterSector();//number of outer sectors\r
+  const Int_t kNS = kNIS + kNOS;//all sectors\r
+  \r
+  \r
+  //crate TPC view\r
+  AliTPCDigitsArray *digarr=new AliTPCDigitsArray(kFALSE);//data not sim\r
+  digarr->Setup(fParam);//as usually parameters\r
+  \r
+  for(Int_t iSec = 0; iSec < kNS; iSec++) {\r
+    AliTPCCalROC * noiseROC;\r
+    AliTPCCalROC noiseDummy(iSec);\r
+    if(noiseTPC==0x0){\r
+      noiseROC = &noiseDummy;//noise=0\r
+    }else{\r
+      noiseROC = noiseTPC->GetCalROC(iSec);  // noise per given sector\r
+    }\r
+    Int_t nRows = 0; //number of rows in sector\r
+    Int_t nDDLs = 0; //number of DDLs\r
+    Int_t indexDDL = 0; //DDL index\r
+    if (iSec < kNIS) {\r
+      nRows = fParam->GetNRowLow();\r
+      nDDLs = 2;\r
+      indexDDL = iSec * 2;\r
+    }else {\r
+      nRows = fParam->GetNRowUp();\r
+      nDDLs = 4;\r
+      indexDDL = (iSec-kNIS) * 4 + kNIS * 2;\r
+    }\r
+    \r
+    //\r
+    // Load the raw data for corresponding DDLs\r
+    //\r
+    rawReader->Reset();\r
+    rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);\r
+      \r
+    \r
+    while (input.NextDDL()){\r
+      // Allocate memory for rows in sector (pads(depends on row) x timebins)\r
+      if (!digarr->GetRow(iSec,0)){\r
+        for(Int_t iRow = 0; iRow < nRows; iRow++) {\r
+          digarr->CreateRow(iSec,iRow);\r
+        }//end loop over rows\r
+      }\r
+      //loop over pads\r
+      while ( input.NextChannel() ) {\r
+        Int_t iRow = input.GetRow();\r
+        Int_t iPad = input.GetPad();\r
+        //check row consistency\r
+        if (iRow < 0 ) continue;\r
+        if (iRow < 0 || iRow >= nRows){\r
+          AliError(Form("Pad-row index (%d) outside the range (%d -> %d) !",\r
+                        iRow, 0, nRows -1));\r
+          continue;\r
+        }\r
+        \r
+      //check pad consistency\r
+        if (iPad < 0 || iPad >= (Int_t)(roc->GetNPads(iSec,iRow))) {\r
+          AliError(Form("Pad index (%d) outside the range (%d -> %d) !",\r
+                        iPad, 0, roc->GetNPads(iSec,iRow) ));\r
+          continue;\r
+        }\r
+        \r
+      //loop over bunches\r
+        while ( input.NextBunch() ){\r
+          Int_t  startTbin    = (Int_t)input.GetStartTimeBin();\r
+          Int_t  bunchlength  = (Int_t)input.GetBunchLength();\r
+          const UShort_t *sig = input.GetSignals();\r
+          isAltro=kTRUE;\r
+          for (Int_t iTime = 0; iTime<bunchlength; iTime++){\r
+            Int_t iTimeBin=startTbin-iTime;\r
+            //\r
+            if(fDebugLevel==72){\r
+              fHistoRow->Fill(iRow);\r
+              fHistoPad->Fill(iPad);\r
+              fHistoTime->Fill(iTimeBin);\r
+              fHistoRowPad->Fill(iPad,iRow);\r
+            }else if(fDebugLevel>=0&&fDebugLevel<72){\r
+              if(iSec==fDebugLevel){\r
+                fHistoRow->Fill(iRow);\r
+                fHistoPad->Fill(iPad);\r
+                fHistoTime->Fill(iTimeBin);\r
+                fHistoRowPad->Fill(iPad,iRow);\r
+              }\r
+            }else if(fDebugLevel==73){\r
+              if(iSec<36){\r
+                fHistoRow->Fill(iRow);\r
+                fHistoPad->Fill(iPad);\r
+                fHistoTime->Fill(iTimeBin);\r
+                fHistoRowPad->Fill(iPad,iRow);\r
+              }\r
+            }else if(fDebugLevel==74){\r
+              if(iSec>=36){\r
+                fHistoRow->Fill(iRow);\r
+                fHistoPad->Fill(iPad);\r
+                fHistoTime->Fill(iTimeBin);\r
+                fHistoRowPad->Fill(iPad,iRow);\r
+              }\r
+            }\r
+            \r
+            //check time consistency\r
+            if ( iTimeBin < fRecoParam->GetFirstBin() || iTimeBin >= fRecoParam->GetLastBin()){\r
+              //cout<<iTimeBin<<endl;\r
+              continue;\r
+              AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",\r
+                            iTimeBin, 0, fRecoParam->GetLastBin() -1));\r
+            }\r
+            //signal\r
+            Float_t signal=(Float_t)sig[iTime];\r
+            if (signal <= fZeroSup ||\r
+                iTimeBin < fFirstBin ||\r
+                iTimeBin > fLastBin\r
+               ) {\r
+                 digarr->GetRow(iSec,iRow)->SetDigitFast(0,iTimeBin,iPad);\r
+                 continue;\r
+               }\r
+            if (!noiseROC) continue;\r
+            Double_t noiseOnPad = noiseROC->GetValue(iRow,iPad);//noise on given pad and row in sector\r
+            if (noiseOnPad > fMaxNoiseAbs){\r
+              digarr->GetRow(iSec,iRow)->SetDigitFast(0,iTimeBin,iPad);\r
+              continue; // consider noisy pad as dead\r
+            }\r
+            if(signal <= fMaxNoiseSigma * noiseOnPad){\r
+              digarr->GetRow(iSec,iRow)->SetDigitFast(0,iTimeBin,iPad);\r
+              continue;\r
+            }\r
+            digarr->GetRow(iSec,iRow)->SetDigitFast(TMath::Nint(signal),iTimeBin,iPad);\r
+          }// end loop signals in bunch\r
+        }// end loop bunches\r
+      } // end loop pads\r
+    }// end ddl loop\r
+  }// end sector loop\r
+  SetDigArr(digarr);\r
+  if(isAltro) FindClusterKrIO();\r
+  delete digarr;\r
+  \r
+  return 0;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+Int_t AliTPCclustererKr::FinderIOold(AliRawReader* rawReader)\r
+{\r
+  // Krypton cluster finder for the TPC raw data\r
+  //\r
+  // fParam must be defined before\r
+  if (!rawReader) return 1;\r
+\r
+  if(rawReader)fRawData=kTRUE; //set flag to data\r
+  \r
+  if (!fOutput) {\r
+    Error("Digits2Clusters", "output tree not initialised");\r
+    return 11;\r
+  }\r
+  \r
+  fParam->SetMaxTBin(fRecoParam->GetLastBin());//set number of timebins from reco -> param\r
+  //   used later for memory allocation\r
+\r
+  AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();\r
+  if (eventHeader){\r
+    fTimeStamp = eventHeader->Get("Timestamp");\r
+    fRun = rawReader->GetRunNumber();\r
+  }\r
+  \r
+  Bool_t isAltro=kFALSE;\r
+  \r
+  AliTPCROC * roc = AliTPCROC::Instance();\r
+  AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();\r
+  AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();\r
+  //\r
+  AliTPCRawStream input(rawReader,(AliAltroMapping**)mapping);\r
+  \r
+  const Int_t kNIS = fParam->GetNInnerSector();//number of inner sectors\r
+  const Int_t kNOS = fParam->GetNOuterSector();//number of outer sectors\r
+  const Int_t kNS = kNIS + kNOS;//all sectors\r
+  \r
+  \r
+  //crate TPC view\r
+  AliTPCDigitsArray *digarr=new AliTPCDigitsArray(kFALSE);//data not sim\r
+  digarr->Setup(fParam);//as usually parameters\r
+  \r
+  //\r
+  // Loop over sectors\r
+  //\r
+  for(Int_t iSec = 0; iSec < kNS; iSec++) {\r
+    AliTPCCalROC * noiseROC;\r
+    if(noiseTPC==0x0){\r
+      noiseROC =new AliTPCCalROC(iSec);//noise=0\r
+    }\r
+    else{\r
+      noiseROC = noiseTPC->GetCalROC(iSec);  // noise per given sector\r
+    }\r
+    Int_t nRows = 0; //number of rows in sector\r
+    Int_t nDDLs = 0; //number of DDLs\r
+    Int_t indexDDL = 0; //DDL index\r
+    if (iSec < kNIS) {\r
+      nRows = fParam->GetNRowLow();\r
+      nDDLs = 2;\r
+      indexDDL = iSec * 2;\r
+    }else {\r
+      nRows = fParam->GetNRowUp();\r
+      nDDLs = 4;\r
+      indexDDL = (iSec-kNIS) * 4 + kNIS * 2;\r
+    }\r
+    \r
+    //\r
+    // Load the raw data for corresponding DDLs\r
+    //\r
+    rawReader->Reset();\r
+    rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);\r
+    \r
+    if(input.Next()) {\r
+      isAltro=kTRUE;\r
+      // Allocate memory for rows in sector (pads(depends on row) x timebins)\r
+      for(Int_t iRow = 0; iRow < nRows; iRow++) {\r
+        digarr->CreateRow(iSec,iRow);\r
+      }//end loop over rows\r
+    }\r
+    rawReader->Reset();\r
+    rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);\r
+    \r
+    //\r
+    // Begin loop over altro data\r
+    //\r
+    while (input.Next()) {\r
+      \r
+      //check sector consistency\r
+      if (input.GetSector() != iSec)\r
+        AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",iSec,input.GetSector()));\r
+      \r
+      Int_t iRow = input.GetRow();\r
+      Int_t iPad = input.GetPad();\r
+      Int_t iTimeBin = input.GetTime();\r
+      \r
+      //\r
+      if(fDebugLevel==72){\r
+        fHistoRow->Fill(iRow);\r
+        fHistoPad->Fill(iPad);\r
+        fHistoTime->Fill(iTimeBin);\r
+        fHistoRowPad->Fill(iPad,iRow);\r
+      }else if(fDebugLevel>=0&&fDebugLevel<72){\r
+        if(iSec==fDebugLevel){\r
+          fHistoRow->Fill(iRow);\r
+          fHistoPad->Fill(iPad);\r
+          fHistoTime->Fill(iTimeBin);\r
+          fHistoRowPad->Fill(iPad,iRow);\r
+        }\r
+      }else if(fDebugLevel==73){\r
+        if(iSec<36){\r
+          fHistoRow->Fill(iRow);\r
+          fHistoPad->Fill(iPad);\r
+          fHistoTime->Fill(iTimeBin);\r
+          fHistoRowPad->Fill(iPad,iRow);\r
+        }\r
+      }else if(fDebugLevel==74){\r
+        if(iSec>=36){\r
+          fHistoRow->Fill(iRow);\r
+          fHistoPad->Fill(iPad);\r
+          fHistoTime->Fill(iTimeBin);\r
+          fHistoRowPad->Fill(iPad,iRow);\r
+        }\r
+      }\r
+      \r
+      //check row consistency\r
+      if (iRow < 0 ) continue;\r
+      if (iRow < 0 || iRow >= nRows){\r
+        AliError(Form("Pad-row index (%d) outside the range (%d -> %d) !",\r
+                      iRow, 0, nRows -1));\r
+        continue;\r
+      }\r
+      \r
+      //check pad consistency\r
+      if (iPad < 0 || iPad >= (Int_t)(roc->GetNPads(iSec,iRow))) {\r
+        AliError(Form("Pad index (%d) outside the range (%d -> %d) !",\r
+                      iPad, 0, roc->GetNPads(iSec,iRow) ));\r
+        continue;\r
+      }\r
+      \r
+      //check time consistency\r
+      if ( iTimeBin < fRecoParam->GetFirstBin() || iTimeBin >= fRecoParam->GetLastBin()){\r
+  //cout<<iTimeBin<<endl;\r
+        continue;\r
+        AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",\r
+                      iTimeBin, 0, fRecoParam->GetLastBin() -1));\r
+      }\r
+      \r
+      //signal\r
+      Int_t signal = input.GetSignal();\r
+      if (signal <= fZeroSup ||\r
+          iTimeBin < fFirstBin ||\r
+          iTimeBin > fLastBin\r
+         ) {\r
+           digarr->GetRow(iSec,iRow)->SetDigitFast(0,iTimeBin,iPad);\r
+           continue;\r
+         }\r
+      if (!noiseROC) continue;\r
+      Double_t noiseOnPad = noiseROC->GetValue(iRow,iPad);//noise on given pad and row in sector\r
+      if (noiseOnPad > fMaxNoiseAbs){\r
+        digarr->GetRow(iSec,iRow)->SetDigitFast(0,iTimeBin,iPad);\r
+        continue; // consider noisy pad as dead\r
+      }\r
+      if(signal <= fMaxNoiseSigma * noiseOnPad){\r
+        digarr->GetRow(iSec,iRow)->SetDigitFast(0,iTimeBin,iPad);\r
+        continue;\r
+      }\r
+      digarr->GetRow(iSec,iRow)->SetDigitFast(signal,iTimeBin,iPad);\r
+    }//end of loop over altro data\r
+  }//end of loop over sectors\r
+  \r
+  SetDigArr(digarr);\r
+  if(isAltro) FindClusterKrIO();\r
+  delete digarr;\r
+  \r
+  return 0;\r
+}\r
+\r
+void AliTPCclustererKr::CleanSector(Int_t sector){\r
+  //\r
+  // clean isolated digits\r
+  //  \r
+  const Int_t kNRows=fParam->GetNRow(sector);//number of rows in sector\r
+  for(Int_t iRow=0; iRow<kNRows; ++iRow){\r
+    AliSimDigits *digrow;\r
+    if(fRawData){\r
+      digrow = (AliSimDigits*)fDigarr->GetRow(sector,iRow);//real data\r
+    }else{\r
+      digrow = (AliSimDigits*)fDigarr->LoadRow(sector,iRow);//MC\r
+    }\r
+    if(!digrow) continue;\r
+    digrow->ExpandBuffer(); //decrunch\r
+    const Int_t kNPads = digrow->GetNCols();  // number of pads\r
+    const Int_t kNTime = digrow->GetNRows(); // number of timebins\r
+    for(Int_t iPad=1;iPad<kNPads-1;iPad++){\r
+      Short_t*  val = digrow->GetDigitsColumn(iPad);\r
+\r
+      for(Int_t iTimeBin=1;iTimeBin<kNTime-1;iTimeBin++){\r
+       if (val[iTimeBin]<=0) continue;\r
+       if (val[iTimeBin-1]+val[iTimeBin+1]<fIsolCut) {val[iTimeBin]=0; continue;}\r
+       if (val[iTimeBin-kNTime]+val[iTimeBin+kNTime]<fIsolCut) {val[iTimeBin]=0; continue;}\r
+       //\r
+       if (val[iTimeBin-1-kNTime]+val[iTimeBin+1+kNTime]<fIsolCut) {val[iTimeBin]=0; continue;}\r
+       if (val[iTimeBin+1-kNTime]+val[iTimeBin-1+kNTime]<fIsolCut) {val[iTimeBin]=0; continue;}\r
+\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+\r
+////____________________________________________________________________________\r
+Int_t AliTPCclustererKr::FindClusterKrIO()\r
+{\r
+\r
+  //\r
+  //fParam and  fDigarr must be set to run this method\r
+  //\r
+\r
+  Int_t clusterCounter=0;\r
+  const Int_t nTotalSector=fParam->GetNSector();//number of sectors\r
+  for(Int_t iSec=0; iSec<nTotalSector; ++iSec){\r
+    CleanSector(iSec);\r
+\r
+    //vector of maxima for each sector\r
+    //std::vector<AliPadMax*> maximaInSector;\r
+    TObjArray *maximaInSector=new TObjArray();//to store AliPadMax*\r
+\r
+    //\r
+    //  looking for the maxima on the pad\r
+    //\r
+\r
+    const Int_t kNRows=fParam->GetNRow(iSec);//number of rows in sector\r
+    for(Int_t iRow=0; iRow<kNRows; ++iRow){\r
+      AliSimDigits *digrow;\r
+      if(fRawData){\r
+       digrow = (AliSimDigits*)fDigarr->GetRow(iSec,iRow);//real data\r
+      }else{\r
+       digrow = (AliSimDigits*)fDigarr->LoadRow(iSec,iRow);//MC\r
+      }\r
+      if(digrow){//if pointer exist\r
+       digrow->ExpandBuffer(); //decrunch\r
+       const Int_t kNPads = digrow->GetNCols();  // number of pads\r
+       const Int_t kNTime = digrow->GetNRows(); // number of timebins\r
+       for(Int_t iPad=0;iPad<kNPads;iPad++){\r
+         \r
+         Int_t timeBinMax=-1;//timebin of maximum \r
+         Int_t valueMaximum=-1;//value of maximum in adc\r
+         Int_t increaseBegin=-1;//timebin when increase starts\r
+         Int_t sumAdc=0;//sum of adc on the pad in maximum surrounding\r
+         bool ifIncreaseBegin=true;//flag - check if increasing started\r
+         bool ifMaximum=false;//flag - check if it could be maximum\r
+         Short_t* val = digrow->GetDigitsColumn(iPad);\r
+         for(Int_t iTimeBin=1;iTimeBin<kNTime-1;iTimeBin++){\r
+           if (!ifMaximum)  {\r
+             if (val[iTimeBin]==-1) break;   // 0 until the end\r
+             for( ; iTimeBin<kNTime-2&&val[iTimeBin]<fMinAdc ;iTimeBin++) {}\r
+           }\r
+           //\r
+           Short_t adc = val[iTimeBin];\r
+\r
+           if(adc<fMinAdc){//standard was 3 for fMinAdc\r
+             if(ifMaximum){\r
+               if(iTimeBin-increaseBegin<fMinTimeBins){//at least 2 time bins\r
+                 timeBinMax=-1;\r
+                 valueMaximum=-1;\r
+                 increaseBegin=-1;\r
+                 sumAdc=0;\r
+                 ifIncreaseBegin=true;\r
+                 ifMaximum=false;\r
+                 continue;\r
+               }\r
+               //insert maximum, default values and set flags\r
+               //Double_t xCord,yCord;\r
+               //GetXY(iSec,iRow,iPad,xCord,yCord);\r
+               Double_t x[]={iRow,iPad,iTimeBin};\r
+               Int_t i[]={iSec};\r
+               AliTPCTransform *transform     = AliTPCcalibDB::Instance()->GetTransform() ;\r
+\r
+               transform->Transform(x,i,0,1);\r
+               \r
+               AliPadMax *oneMaximum = new AliPadMax(AliTPCvtpr(valueMaximum,\r
+                                                                timeBinMax,\r
+                                                                iPad,\r
+                                                                iRow,\r
+                                                                x[0],//xCord,\r
+                                                                x[1],//yCord,\r
+                                                                x[2]/*timeBinMax*/),\r
+                                                     increaseBegin,\r
+                                                     iTimeBin-1,\r
+                                                     sumAdc);\r
+               maximaInSector->AddLast(oneMaximum);\r
+               \r
+               timeBinMax=-1;\r
+               valueMaximum=-1;\r
+               increaseBegin=-1;\r
+               sumAdc=0;\r
+               ifIncreaseBegin=true;\r
+               ifMaximum=false;\r
+             }\r
+             continue;\r
+           }\r
+\r
+\r
+\r
+\r
+\r
+\r
+           if(ifIncreaseBegin){\r
+             ifIncreaseBegin=false;\r
+             increaseBegin=iTimeBin;\r
+           }\r
+           \r
+           if(adc>valueMaximum){\r
+             timeBinMax=iTimeBin;\r
+             valueMaximum=adc;\r
+             ifMaximum=true;\r
+           }\r
+           sumAdc+=adc;\r
+           if(iTimeBin==kNTime-1 && ifMaximum && kNTime-increaseBegin>fMinTimeBins){//on the edge\r
+             //at least 3 timebins\r
+             //insert maximum, default values and set flags\r
+             //Double_t xCord,yCord;\r
+             //GetXY(iSec,iRow,iPad,xCord,yCord);\r
+             Double_t x[]={iRow,iPad,iTimeBin};\r
+             Int_t i[]={iSec};\r
+             //AliTPCTransform trafo;\r
+             //trafo.Transform(x,i,0,1);\r
+\r
+               AliTPCTransform *transform     = AliTPCcalibDB::Instance()->GetTransform() ;\r
+\r
+               transform->Transform(x,i,0,1);\r
+\r
+             AliPadMax *oneMaximum = new AliPadMax(AliTPCvtpr(valueMaximum,\r
+                                                              timeBinMax,\r
+                                                              iPad,\r
+                                                              iRow,\r
+                                                              x[0],//xCord,\r
+                                                              x[1],//yCord,\r
+                                                              x[2]/*timeBinMax*/),\r
+                                                   increaseBegin,\r
+                                                   iTimeBin-1,\r
+                                                   sumAdc);\r
+             maximaInSector->AddLast(oneMaximum);\r
+               \r
+             timeBinMax=-1;\r
+             valueMaximum=-1;\r
+             increaseBegin=-1;\r
+             sumAdc=0;\r
+             ifIncreaseBegin=true;\r
+             ifMaximum=false;\r
+             continue;\r
+           }\r
+           \r
+         }//end loop over timebins\r
+       }//end loop over pads\r
+//      }else{\r
+//     cout<<"Pointer does not exist!!"<<endl;\r
+      }//end if poiner exists\r
+    }//end loop over rows\r
+\r
+    MakeClusters(maximaInSector,iSec,clusterCounter);\r
+    //\r
+    maximaInSector->SetOwner(kTRUE);\r
+    maximaInSector->Delete();\r
+    delete maximaInSector;\r
+  }//end sector for\r
+  cout<<"Number of clusters in event: "<<clusterCounter<<endl;\r
+  return 0;\r
+}\r
+\r
+void AliTPCclustererKr::MakeClusters(TObjArray * maximaInSector, Int_t iSec, Int_t &clusterCounter){\r
+  //\r
+  // Make clusters\r
+  //\r
+\r
+  Int_t maxDig=0;\r
+  Int_t maxSumAdc=0;\r
+  Int_t maxTimeBin=0;\r
+  Int_t maxPad=0;\r
+  Int_t maxRow=0;\r
+  Double_t maxX=0;\r
+  Double_t maxY=0;\r
+  Double_t maxT=0;\r
+  Int_t entriesArr = maximaInSector->GetEntriesFast();\r
+  for(Int_t it1 = 0; it1 < entriesArr; ++it1 ) {\r
+    \r
+    AliPadMax *mp1=(AliPadMax *)maximaInSector->UncheckedAt(it1);\r
+    if (!mp1) continue;\r
+    AliTPCclusterKr clusterKr;\r
+    \r
+    Int_t nUsedPads=1;\r
+    Int_t clusterValue=0;\r
+    clusterValue+=(mp1)->GetSum();\r
+    list<Int_t> nUsedRows;\r
+    nUsedRows.push_back((mp1)->GetRow());\r
+    \r
+    maxDig      =(mp1)->GetAdc() ;\r
+    maxSumAdc   =(mp1)->GetSum() ;\r
+    maxTimeBin  =(mp1)->GetTime();\r
+    maxPad      =(mp1)->GetPad() ;\r
+    maxRow      =(mp1)->GetRow() ;\r
+    maxX        =(mp1)->GetX();\r
+    maxY        =(mp1)->GetY();\r
+    maxT        =(mp1)->GetT();\r
+    \r
+    AliSimDigits *digrowTmp;\r
+    if(fRawData){\r
+      digrowTmp = (AliSimDigits*)fDigarr->GetRow(iSec,(mp1)->GetRow());\r
+    }else{\r
+      digrowTmp = (AliSimDigits*)fDigarr->LoadRow(iSec,(mp1)->GetRow());\r
+    }\r
+    \r
+    digrowTmp->ExpandBuffer(); //decrunch\r
+    \r
+    for(Int_t itb=(mp1)->GetBegin(); itb<((mp1)->GetEnd())+1; itb++){\r
+      Int_t adcTmp = digrowTmp->GetDigitUnchecked(itb,(mp1)->GetPad());\r
+      AliTPCvtpr *vtpr=new AliTPCvtpr(adcTmp,itb,(mp1)->GetPad(),(mp1)->GetRow(),(mp1)->GetX(),(mp1)->GetY(),(mp1)->GetT());\r
+      clusterKr.AddDigitToCluster(vtpr);\r
+    }\r
+    clusterKr.SetCenter();//set centr of the cluster\r
+    \r
+    for(Int_t it2 = it1+1; it2 < entriesArr; ++it2 ) {\r
+      AliPadMax *mp2=(AliPadMax *)maximaInSector->UncheckedAt(it2);\r
+      if (!mp2) continue;\r
+      if (TMath::Abs(clusterKr.GetCenterX() - (mp2)->GetX()) > fMaxPadRangeCm) continue;\r
+      if (TMath::Abs(clusterKr.GetCenterY() - (mp2)->GetY()) > fMaxRowRangeCm) continue;      \r
+      if (TMath::Abs(clusterKr.GetCenterT() - (mp2)->GetT()) > fMaxTimeRange) continue;\r
+\r
+      {\r
+       clusterValue+=(mp2)->GetSum();\r
+       \r
+       nUsedPads++;\r
+       nUsedRows.push_back((mp2)->GetRow());\r
+       \r
+       AliSimDigits *digrowTmp1;\r
+       if(fRawData){\r
+         digrowTmp1 = (AliSimDigits*)fDigarr->GetRow(iSec,(mp2)->GetRow());\r
+       }else{\r
+         digrowTmp1 = (AliSimDigits*)fDigarr->LoadRow(iSec,(mp2)->GetRow());\r
+       }\r
+       digrowTmp1->ExpandBuffer(); //decrunch\r
+       \r
+       for(Int_t itb=(mp2)->GetBegin(); itb<(mp2)->GetEnd()+1; itb++){\r
+         Int_t adcTmp = digrowTmp1->GetDigitUnchecked(itb,(mp2)->GetPad());\r
+         AliTPCvtpr *vtpr=new AliTPCvtpr(adcTmp,itb,(mp2)->GetPad(),(mp2)->GetRow(),(mp2)->GetX(),(mp2)->GetY(),(mp2)->GetT());\r
+         clusterKr.AddDigitToCluster(vtpr);\r
+       }\r
+       \r
+       clusterKr.SetCenter();//set center of the cluster\r
+       \r
+       //which one is bigger\r
+       if( (mp2)->GetAdc() > maxDig ){\r
+         maxDig      =(mp2)->GetAdc() ;\r
+         maxSumAdc   =(mp2)->GetSum() ;\r
+         maxTimeBin  =(mp2)->GetTime();\r
+         maxPad      =(mp2)->GetPad() ;\r
+         maxRow      =(mp2)->GetRow() ;\r
+         maxX        =(mp2)->GetX() ;\r
+         maxY        =(mp2)->GetY() ;\r
+         maxT        =(mp2)->GetT() ;\r
+       } else if ( (mp2)->GetAdc() == maxDig ){\r
+         if( (mp2)->GetSum() > maxSumAdc){\r
+           maxDig      =(mp2)->GetAdc() ;\r
+           maxSumAdc   =(mp2)->GetSum() ;\r
+           maxTimeBin  =(mp2)->GetTime();\r
+           maxPad      =(mp2)->GetPad() ;\r
+           maxRow      =(mp2)->GetRow() ;\r
+           maxX        =(mp2)->GetX() ;\r
+           maxY        =(mp2)->GetY() ;\r
+           maxT        =(mp2)->GetT() ;\r
+         }\r
+       }\r
+       delete maximaInSector->RemoveAt(it2);\r
+      }\r
+    }//inside loop\r
+    delete maximaInSector->RemoveAt(it1);          \r
+    clusterKr.SetSize();\r
+    //through out clusters on the edge and noise\r
+    //if(clusterValue/clusterKr.fCluster.size()<fValueToSize)continue;\r
+    if(clusterValue/(clusterKr.GetSize())<fValueToSize)continue;\r
+    \r
+    clusterKr.SetADCcluster(clusterValue);\r
+    clusterKr.SetNPads(nUsedPads);\r
+    clusterKr.SetMax(AliTPCvtpr(maxDig,maxTimeBin,maxPad,maxRow,maxX,maxY,maxT));\r
+    clusterKr.SetSec(iSec);\r
+    clusterKr.SetSize();\r
+    \r
+    nUsedRows.sort();\r
+    nUsedRows.unique();\r
+    clusterKr.SetNRows(nUsedRows.size());\r
+    clusterKr.SetCenter();\r
+    \r
+    clusterKr.SetRMS();//Set pad,row,timebin RMS\r
+    clusterKr.Set1D();//Set size in pads and timebins\r
+\r
+    clusterKr.SetTimeStamp(fTimeStamp);\r
+    clusterKr.SetRun(fRun);\r
+\r
+    clusterCounter++;\r
+    \r
+    \r
+    //save each cluster into file\r
+    if (fOutput){\r
+      (*fOutput)<<"Kr"<<\r
+       "Cl.="<<&clusterKr<<\r
+       "\n";\r
+    }\r
+    //end of save each cluster into file adc.root\r
+  }//outer loop\r
+}\r
+\r
+\r
+\r
+////____________________________________________________________________________\r
+\r
+\r
+void AliTPCclustererKr::GetXY(Int_t sec,Int_t row,Int_t pad,Double_t& xGlob,Double_t& yGlob){\r
+  //\r
+  //gives global XY coordinate of the pad\r
+  //\r
+\r
+  Double_t yLocal = fParam->GetPadRowRadii(sec,row);//radius of row in sector in cm\r
+\r
+  Int_t padmax = fParam->GetNPads(sec,row);//number of pads in a given row\r
+  Float_t padXSize;\r
+  if(sec<fParam->GetNInnerSector())padXSize=0.4;\r
+  else padXSize=0.6;\r
+  Double_t xLocal=(pad+0.5-padmax/2.)*padXSize;//x-value of the center of pad\r
+\r
+  Float_t sin,cos;\r
+  fParam->AdjustCosSin((Int_t)sec,cos,sin);//return sinus and cosinus of the sector\r
+\r
+  Double_t xGlob1 =  xLocal * cos + yLocal * sin;\r
+  Double_t yGlob1 = -xLocal * sin + yLocal * cos;\r
+\r
+\r
+  Double_t rot=0;\r
+  rot=TMath::Pi()/2.;\r
+\r
+  xGlob =  xGlob1 * TMath::Cos(rot) + yGlob1 * TMath::Sin(rot);\r
+  yGlob = -xGlob1 * TMath::Sin(rot) + yGlob1 * TMath::Cos(rot);\r
+\r
+   yGlob=-1*yGlob;\r
+   if(sec<18||(sec>=36&&sec<54)) xGlob =-1*xGlob;\r
+\r
+\r
+  return;\r
+}\r