ROOT logo
#if !defined(__CINT__)
#include <TFile.h>
#include <TTree.h>
#include "AliTPCParamSR.h"
#include "AliTPCDigitsArray.h"
#include "AliSimDigits.h"
#include "AliTPCBuffer.h"
#endif


void AliTPCDDL(Int_t eventNumber=0, Int_t eth=0){
  //eth is a threshold.
  //Digits stored into a file have an amplitude value greater than "eth"

  const char * inFile_new = "galice.root";
  AliRunLoader *rl = AliRunLoader::Open(inFile_new,"Event","read");

  Int_t nevents=rl->GetNumberOfEvents();
  cout<<"Number of Events:"<<nevents<<endl;
  while (eventNumber<=0 || eventNumber>nevents){
    cout<<"Insert the event number:";
    cin>>eventNumber;
    cout<<endl;
  }
  rl->GetEvent(eventNumber-1);
  AliLoader *tpcloader=rl->GetLoader("TPCLoader");
  tpcloader->LoadDigits();
  TTree *digitsTree=tpcloader->TreeD();

  AliSimDigits digrows, *dummy=&digrows;
  digitsTree->GetBranch("Segment")->SetAddress(&dummy);
  Stat_t nrows = digitsTree->GetEntries();
  cout<<"Number of entries (rows):"<<nrows<<endl;
  // get the TPC parameters
  rl->CdGAFile();
  AliTPCParamSR* param = AliTPC::LoadTPCParam(gFile);
  if (!param)
    cout<<"No TPC parameter"<<endl;
  AliTPCDigitsArray *digarr=new AliTPCDigitsArray;
  digarr->Setup(param);
  digarr->ConnectTree(digitsTree);

  AliTPCBuffer *b=new AliTPCBuffer("AliTPCDDL.dat");

  //Verbose level
  // 0: Silent
  // 1: cout messages
  // 2: txt files with digits 
  //BE CAREFUL, verbose level 2 MUST be used only for debugging and
  //it is highly suggested to use this mode only for debugging digits files
  //reasonably small, because otherwise the size of the txt files can reach
  //quickly several MB wasting time and disk space.
  b->SetVerbose(0);


  nrows=Int_t(digarr->GetTree()->GetEntries());
  cout<<"Number of entries "<<nrows<<endl;
  Int_t PSector=-1;
  Int_t SubSec=0;
  for (Int_t n=0; n<nrows; n++) {
    AliSimDigits *digrow=(AliSimDigits*)digarr->LoadEntry(n);

    Int_t sec,row; // sector and row number (in the TPC)
    param->AdjustSectorRow(digrow->GetID(),sec,row);   
    // cout<<sec<<" row "<<row<<endl;
    if(PSector!=sec){
      SubSec=0;
      PSector=sec;
    }//end if

    if(sec<36){
      //inner sector [0;35]
      if(row!=30)
	//the whole row is written into the output file
	b->WriteRowBinary(eth,digrow,0,0,0,sec,SubSec,row);
      else{
	//only the pads in the range [37;48] are written into the output file
	b->WriteRowBinary(eth,digrow,37,48,1,sec,SubSec,row);
	SubSec=1;
	//only the pads outside the range [37;48] are written into the output file
	b->WriteRowBinary(eth,digrow,37,48,2,sec,SubSec,row);
      }//end else
    }//end if
    else{
      //outer sector [36;71]
      if(row==54)SubSec=2;
      if((row!=27)&&(row!=76))
	b->WriteRowBinary(eth,digrow,0,0,0,sec,SubSec,row);
      else{
	if(row==27){
	  //only the pads outside the range [43;46] are written into the output file
	  b->WriteRowBinary(eth,digrow,43,46,2,sec,SubSec,row);
	  SubSec=1;
	  //only the pads in the range [43;46] are written into the output file
	  b->WriteRowBinary(eth,digrow,43,46,1,sec,SubSec,row);
	}
	if(row==76){
	  //only the pads outside the range [33;88] are written into the output file
	  b->WriteRowBinary(eth,digrow,33,88,2,sec,SubSec,row);
	  SubSec=3;
	  //only the pads in the range [33;88] are written into the output file
	  b->WriteRowBinary(eth,digrow,33,88,1,sec,SubSec,row);
	}
      }
    }//end else
  }//end for
  cout<<"File created !"<<endl;
  cout<<"Total number of digits: "<<b->GetDigNumber()<<endl;
  delete b;
  return;
}//end AliTPCDataChallenge
 AliTPCDDL.C:1
 AliTPCDDL.C:2
 AliTPCDDL.C:3
 AliTPCDDL.C:4
 AliTPCDDL.C:5
 AliTPCDDL.C:6
 AliTPCDDL.C:7
 AliTPCDDL.C:8
 AliTPCDDL.C:9
 AliTPCDDL.C:10
 AliTPCDDL.C:11
 AliTPCDDL.C:12
 AliTPCDDL.C:13
 AliTPCDDL.C:14
 AliTPCDDL.C:15
 AliTPCDDL.C:16
 AliTPCDDL.C:17
 AliTPCDDL.C:18
 AliTPCDDL.C:19
 AliTPCDDL.C:20
 AliTPCDDL.C:21
 AliTPCDDL.C:22
 AliTPCDDL.C:23
 AliTPCDDL.C:24
 AliTPCDDL.C:25
 AliTPCDDL.C:26
 AliTPCDDL.C:27
 AliTPCDDL.C:28
 AliTPCDDL.C:29
 AliTPCDDL.C:30
 AliTPCDDL.C:31
 AliTPCDDL.C:32
 AliTPCDDL.C:33
 AliTPCDDL.C:34
 AliTPCDDL.C:35
 AliTPCDDL.C:36
 AliTPCDDL.C:37
 AliTPCDDL.C:38
 AliTPCDDL.C:39
 AliTPCDDL.C:40
 AliTPCDDL.C:41
 AliTPCDDL.C:42
 AliTPCDDL.C:43
 AliTPCDDL.C:44
 AliTPCDDL.C:45
 AliTPCDDL.C:46
 AliTPCDDL.C:47
 AliTPCDDL.C:48
 AliTPCDDL.C:49
 AliTPCDDL.C:50
 AliTPCDDL.C:51
 AliTPCDDL.C:52
 AliTPCDDL.C:53
 AliTPCDDL.C:54
 AliTPCDDL.C:55
 AliTPCDDL.C:56
 AliTPCDDL.C:57
 AliTPCDDL.C:58
 AliTPCDDL.C:59
 AliTPCDDL.C:60
 AliTPCDDL.C:61
 AliTPCDDL.C:62
 AliTPCDDL.C:63
 AliTPCDDL.C:64
 AliTPCDDL.C:65
 AliTPCDDL.C:66
 AliTPCDDL.C:67
 AliTPCDDL.C:68
 AliTPCDDL.C:69
 AliTPCDDL.C:70
 AliTPCDDL.C:71
 AliTPCDDL.C:72
 AliTPCDDL.C:73
 AliTPCDDL.C:74
 AliTPCDDL.C:75
 AliTPCDDL.C:76
 AliTPCDDL.C:77
 AliTPCDDL.C:78
 AliTPCDDL.C:79
 AliTPCDDL.C:80
 AliTPCDDL.C:81
 AliTPCDDL.C:82
 AliTPCDDL.C:83
 AliTPCDDL.C:84
 AliTPCDDL.C:85
 AliTPCDDL.C:86
 AliTPCDDL.C:87
 AliTPCDDL.C:88
 AliTPCDDL.C:89
 AliTPCDDL.C:90
 AliTPCDDL.C:91
 AliTPCDDL.C:92
 AliTPCDDL.C:93
 AliTPCDDL.C:94
 AliTPCDDL.C:95
 AliTPCDDL.C:96
 AliTPCDDL.C:97
 AliTPCDDL.C:98
 AliTPCDDL.C:99
 AliTPCDDL.C:100
 AliTPCDDL.C:101
 AliTPCDDL.C:102
 AliTPCDDL.C:103
 AliTPCDDL.C:104
 AliTPCDDL.C:105
 AliTPCDDL.C:106
 AliTPCDDL.C:107
 AliTPCDDL.C:108
 AliTPCDDL.C:109
 AliTPCDDL.C:110
 AliTPCDDL.C:111
 AliTPCDDL.C:112