1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //-------------------------------------------------------
19 // Implementation of the TPC clusterer
21 // 1. The Input data for reconstruction - Options
22 // 1.a Simulated data - TTree - invoked Digits2Clusters()
23 // 1.b Raw data - Digits2Clusters(AliRawReader* rawReader);
26 // 2.a TTree with clusters - if SetOutput(TTree * tree) invoked
27 // 2.b TObjArray - Faster option for HLT
29 // 3. Reconstruction setup
30 // see AliTPCRecoParam for list of parameters
31 // The reconstruction parameterization taken from the
32 // AliTPCReconstructor::GetRecoParam()
33 // Possible to setup it in reconstruction macro AliTPCReconstructor::SetRecoParam(...)
37 // Origin: Marian Ivanov
38 //-------------------------------------------------------
40 #include "Riostream.h"
45 #include <TObjArray.h>
48 #include <TTreeStream.h>
50 #include "AliDigits.h"
51 #include "AliLoader.h"
53 #include "AliMathBase.h"
54 #include "AliRawEventHeaderBase.h"
55 #include "AliRawReader.h"
56 #include "AliRunLoader.h"
57 #include "AliSimDigits.h"
58 #include "AliTPCCalPad.h"
59 #include "AliTPCCalROC.h"
60 #include "AliTPCClustersArray.h"
61 #include "AliTPCClustersRow.h"
62 #include "AliTPCParam.h"
63 #include "AliTPCRawStream.h"
64 #include "AliTPCRecoParam.h"
65 #include "AliTPCReconstructor.h"
66 #include "AliTPCcalibDB.h"
67 #include "AliTPCclusterInfo.h"
68 #include "AliTPCclusterMI.h"
69 #include "AliTPCTransform.h"
70 #include "AliTPCclustererMI.h"
72 ClassImp(AliTPCclustererMI)
76 AliTPCclustererMI::AliTPCclustererMI(const AliTPCParam* par, const AliTPCRecoParam * recoParam):
91 fPedSubtraction(kFALSE),
92 fIsOldRCUFormat(kFALSE),
109 // param - tpc parameters for given file
110 // recoparam - reconstruction parameters
112 fIsOldRCUFormat = kFALSE;
116 fRecoParam = recoParam;
118 //set default parameters if not specified
119 fRecoParam = AliTPCReconstructor::GetRecoParam();
120 if (!fRecoParam) fRecoParam = AliTPCRecoParam::GetLowFluxParam();
122 fDebugStreamer = new TTreeSRedirector("TPCsignal.root");
123 Int_t nPoints = fRecoParam->GetLastBin()-fRecoParam->GetFirstBin();
125 //______________________________________________________________
126 AliTPCclustererMI::AliTPCclustererMI(const AliTPCclustererMI ¶m)
142 fPedSubtraction(kFALSE),
143 fIsOldRCUFormat(kFALSE),
161 fMaxBin = param.fMaxBin;
163 //______________________________________________________________
164 AliTPCclustererMI & AliTPCclustererMI::operator =(const AliTPCclustererMI & param)
167 // assignment operator - dummy
169 fMaxBin=param.fMaxBin;
172 //______________________________________________________________
173 AliTPCclustererMI::~AliTPCclustererMI(){
177 if (fDebugStreamer) delete fDebugStreamer;
179 fOutputArray->Delete();
184 void AliTPCclustererMI::SetInput(TTree * tree)
187 // set input tree with digits
190 if (!fInput->GetBranch("Segment")){
191 cerr<<"AliTPC::Digits2Clusters(): no porper input tree !\n";
197 void AliTPCclustererMI::SetOutput(TTree * tree)
200 // Set the output tree
201 // If not set the ObjArray used - Option for HLT
205 AliTPCClustersRow clrow;
206 AliTPCClustersRow *pclrow=&clrow;
207 clrow.SetClass("AliTPCclusterMI");
208 clrow.SetArray(1); // to make Clones array
209 fOutput->Branch("Segment","AliTPCClustersRow",&pclrow,32000,200);
213 void AliTPCclustererMI::FillRow(){
215 // fill the output container -
216 // 2 Options possible
220 if (fOutput) fOutput->Fill();
223 if (!fOutputArray) fOutputArray = new TObjArray;
224 if (fRowCl) fOutputArray->AddAt(fRowCl->Clone(), fRowCl->GetID());
228 Float_t AliTPCclustererMI::GetSigmaY2(Int_t iz){
229 // sigma y2 = in digits - we don't know the angle
230 Float_t z = iz*fParam->GetZWidth()+fParam->GetNTBinsL1()*fParam->GetZWidth();
231 Float_t sd2 = (z*fParam->GetDiffL()*fParam->GetDiffL())/
232 (fPadWidth*fPadWidth);
234 Float_t res = sd2+sres;
239 Float_t AliTPCclustererMI::GetSigmaZ2(Int_t iz){
240 //sigma z2 = in digits - angle estimated supposing vertex constraint
241 Float_t z = iz*fZWidth+fParam->GetNTBinsL1()*fParam->GetZWidth();
242 Float_t sd2 = (z*fParam->GetDiffL()*fParam->GetDiffL())/(fZWidth*fZWidth);
243 Float_t angular = fPadLength*(fParam->GetZLength(fSector)-z)/(fRx*fZWidth);
246 Float_t sres = fParam->GetZSigma()/fZWidth;
248 Float_t res = angular +sd2+sres;
252 void AliTPCclustererMI::MakeCluster(Int_t k,Int_t max,Float_t *bins, UInt_t /*m*/,
256 // k - Make cluster at position k
257 // bins - 2 D array of signals mapped to 1 dimensional array -
258 // max - the number of time bins er one dimension
259 // c - refernce to cluster to be filled
261 Int_t i0=k/max; //central pad
262 Int_t j0=k%max; //central time bin
264 // set pointers to data
265 //Int_t dummy[5] ={0,0,0,0,0};
266 Float_t * matrix[5]; //5x5 matrix with digits - indexing i = 0 ..4 j = -2..2
267 for (Int_t di=-2;di<=2;di++){
268 matrix[di+2] = &bins[k+di*max];
270 //build matrix with virtual charge
271 Float_t sigmay2= GetSigmaY2(j0);
272 Float_t sigmaz2= GetSigmaZ2(j0);
274 Float_t vmatrix[5][5];
275 vmatrix[2][2] = matrix[2][0];
277 c.SetMax((UShort_t)(vmatrix[2][2])); // write maximal amplitude
278 for (Int_t di =-1;di <=1;di++)
279 for (Int_t dj =-1;dj <=1;dj++){
280 Float_t amp = matrix[di+2][dj];
281 if ( (amp<2) && (fLoop<2)){
282 // if under threshold - calculate virtual charge
283 Float_t ratio = TMath::Exp(-1.2*TMath::Abs(di)/sigmay2)*TMath::Exp(-1.2*TMath::Abs(dj)/sigmaz2);
284 amp = ((matrix[2][0]-2)*(matrix[2][0]-2)/(matrix[-di+2][-dj]+2))*ratio;
286 vmatrix[2+di][2+dj]=amp;
287 vmatrix[2+2*di][2+2*dj]=0;
290 vmatrix[2+2*di][2+dj] =0;
291 vmatrix[2+di][2+2*dj] =0;
296 //if small amplitude - below 2 x threshold - don't consider other one
297 vmatrix[2+di][2+dj]=amp;
298 vmatrix[2+2*di][2+2*dj]=0; // don't take to the account next bin
301 vmatrix[2+2*di][2+dj] =0;
302 vmatrix[2+di][2+2*dj] =0;
306 //if bigger then take everything
307 vmatrix[2+di][2+dj]=amp;
308 vmatrix[2+2*di][2+2*dj]= matrix[2*di+2][2*dj] ;
311 vmatrix[2+2*di][2+dj] = matrix[2*di+2][dj];
312 vmatrix[2+di][2+2*dj] = matrix[2+di][dj*2];
324 for (Int_t i=-2;i<=2;i++)
325 for (Int_t j=-2;j<=2;j++){
326 Float_t amp = vmatrix[i+2][j+2];
335 Float_t meani = sumiw/sumw;
336 Float_t mi2 = sumi2w/sumw-meani*meani;
337 Float_t meanj = sumjw/sumw;
338 Float_t mj2 = sumj2w/sumw-meanj*meanj;
340 Float_t ry = mi2/sigmay2;
341 Float_t rz = mj2/sigmaz2;
344 if ( ( (ry<0.6) || (rz<0.6) ) && fLoop==2) return;
345 if ( (ry <1.2) && (rz<1.2) || (!fRecoParam->GetDoUnfold())) {
347 //if cluster looks like expected or Unfolding not switched on
348 //standard COG is used
349 //+1.2 deviation from expected sigma accepted
350 // c.fMax = FitMax(vmatrix,meani,meanj,TMath::Sqrt(sigmay2),TMath::Sqrt(sigmaz2));
354 //set cluster parameters
357 c.SetTimeBin(meanj-3);
361 AddCluster(c,(Float_t*)vmatrix,k);
365 //unfolding when neccessary
368 Float_t * matrix2[7]; //7x7 matrix with digits - indexing i = 0 ..6 j = -3..3
369 Float_t dummy[7]={0,0,0,0,0,0};
370 for (Int_t di=-3;di<=3;di++){
371 matrix2[di+3] = &bins[k+di*max];
372 if ((k+di*max)<3) matrix2[di+3] = &dummy[3];
373 if ((k+di*max)>fMaxBin-3) matrix2[di+3] = &dummy[3];
375 Float_t vmatrix2[5][5];
378 UnfoldCluster(matrix2,vmatrix2,meani,meanj,sumu,overlap);
380 // c.fMax = FitMax(vmatrix2,meani,meanj,TMath::Sqrt(sigmay2),TMath::Sqrt(sigmaz2));
383 //set cluster parameters
386 c.SetTimeBin(meanj-3);
389 c.SetType(Char_t(overlap)+1);
390 AddCluster(c,(Float_t*)vmatrix,k);
396 printf("%f\t%f\n", vmatrix2[2][2], vmatrix[2][2]);
401 void AliTPCclustererMI::UnfoldCluster(Float_t * matrix2[7], Float_t recmatrix[5][5], Float_t & meani, Float_t & meanj,
402 Float_t & sumu, Float_t & overlap )
405 //unfold cluster from input matrix
406 //data corresponding to cluster writen in recmatrix
407 //output meani and meanj
409 //take separatelly y and z
411 Float_t sum3i[7] = {0,0,0,0,0,0,0};
412 Float_t sum3j[7] = {0,0,0,0,0,0,0};
414 for (Int_t k =0;k<7;k++)
415 for (Int_t l = -1; l<=1;l++){
416 sum3i[k]+=matrix2[k][l];
417 sum3j[k]+=matrix2[l+3][k-3];
419 Float_t mratio[3][3]={{1,1,1},{1,1,1},{1,1,1}};
422 Float_t sum3wi = 0; //charge minus overlap
423 Float_t sum3wio = 0; //full charge
424 Float_t sum3iw = 0; //sum for mean value
425 for (Int_t dk=-1;dk<=1;dk++){
426 sum3wio+=sum3i[dk+3];
432 if ( ( ((sum3i[dk+3]+3)/(sum3i[3]-3))+1 < (sum3i[2*dk+3]-3)/(sum3i[dk+3]+3))||
433 sum3i[dk+3]<=sum3i[2*dk+3] && sum3i[dk+3]>2 ){
434 Float_t xm2 = sum3i[-dk+3];
435 Float_t xm1 = sum3i[+3];
436 Float_t x1 = sum3i[2*dk+3];
437 Float_t x2 = sum3i[3*dk+3];
438 Float_t w11 = TMath::Max((Float_t)(4.*xm1-xm2),(Float_t)0.000001);
439 Float_t w12 = TMath::Max((Float_t)(4 *x1 -x2),(Float_t)0.);
440 ratio = w11/(w11+w12);
441 for (Int_t dl=-1;dl<=1;dl++)
442 mratio[dk+1][dl+1] *= ratio;
444 Float_t amp = sum3i[dk+3]*ratio;
449 meani = sum3iw/sum3wi;
450 Float_t overlapi = (sum3wio-sum3wi)/sum3wio;
455 Float_t sum3wj = 0; //charge minus overlap
456 Float_t sum3wjo = 0; //full charge
457 Float_t sum3jw = 0; //sum for mean value
458 for (Int_t dk=-1;dk<=1;dk++){
459 sum3wjo+=sum3j[dk+3];
465 if ( ( ((sum3j[dk+3]+3)/(sum3j[3]-3))+1 < (sum3j[2*dk+3]-3)/(sum3j[dk+3]+3)) ||
466 (sum3j[dk+3]<=sum3j[2*dk+3] && sum3j[dk+3]>2)){
467 Float_t xm2 = sum3j[-dk+3];
468 Float_t xm1 = sum3j[+3];
469 Float_t x1 = sum3j[2*dk+3];
470 Float_t x2 = sum3j[3*dk+3];
471 Float_t w11 = TMath::Max((Float_t)(4.*xm1-xm2),(Float_t)0.000001);
472 Float_t w12 = TMath::Max((Float_t)(4 *x1 -x2),(Float_t)0.);
473 ratio = w11/(w11+w12);
474 for (Int_t dl=-1;dl<=1;dl++)
475 mratio[dl+1][dk+1] *= ratio;
477 Float_t amp = sum3j[dk+3]*ratio;
482 meanj = sum3jw/sum3wj;
483 Float_t overlapj = (sum3wjo-sum3wj)/sum3wjo;
484 overlap = Int_t(100*TMath::Max(overlapi,overlapj)+3);
485 sumu = (sum3wj+sum3wi)/2.;
488 //if not overlap detected remove everything
489 for (Int_t di =-2; di<=2;di++)
490 for (Int_t dj =-2; dj<=2;dj++){
491 recmatrix[di+2][dj+2] = matrix2[3+di][dj];
495 for (Int_t di =-1; di<=1;di++)
496 for (Int_t dj =-1; dj<=1;dj++){
498 if (mratio[di+1][dj+1]==1){
499 recmatrix[di+2][dj+2] = matrix2[3+di][dj];
500 if (TMath::Abs(di)+TMath::Abs(dj)>1){
501 recmatrix[2*di+2][dj+2] = matrix2[3+2*di][dj];
502 recmatrix[di+2][2*dj+2] = matrix2[3+di][2*dj];
504 recmatrix[2*di+2][2*dj+2] = matrix2[3+2*di][2*dj];
508 //if we have overlap in direction
509 recmatrix[di+2][dj+2] = mratio[di+1][dj+1]* matrix2[3+di][dj];
510 if (TMath::Abs(di)+TMath::Abs(dj)>1){
511 ratio = TMath::Min((Float_t)(recmatrix[di+2][dj+2]/(matrix2[3+0*di][1*dj]+1)),(Float_t)1.);
512 recmatrix[2*di+2][dj+2] = ratio*recmatrix[di+2][dj+2];
514 ratio = TMath::Min((Float_t)(recmatrix[di+2][dj+2]/(matrix2[3+1*di][0*dj]+1)),(Float_t)1.);
515 recmatrix[di+2][2*dj+2] = ratio*recmatrix[di+2][dj+2];
518 ratio = recmatrix[di+2][dj+2]/matrix2[3][0];
519 recmatrix[2*di+2][2*dj+2] = ratio*recmatrix[di+2][dj+2];
525 printf("%f\n", recmatrix[2][2]);
529 Float_t AliTPCclustererMI::FitMax(Float_t vmatrix[5][5], Float_t y, Float_t z, Float_t sigmay, Float_t sigmaz)
536 for (Int_t di = -1;di<=1;di++)
537 for (Int_t dj = -1;dj<=1;dj++){
538 if (vmatrix[2+di][2+dj]>2){
539 Float_t teor = TMath::Gaus(di,y,sigmay*1.2)*TMath::Gaus(dj,z,sigmaz*1.2);
540 sumteor += teor*vmatrix[2+di][2+dj];
541 sumamp += vmatrix[2+di][2+dj]*vmatrix[2+di][2+dj];
544 Float_t max = sumamp/sumteor;
548 void AliTPCclustererMI::AddCluster(AliTPCclusterMI &c, Float_t * matrix, Int_t pos){
551 // Transform cluster to the rotated global coordinata
552 // Assign labels to the cluster
553 // add the cluster to the array
554 // for more details - See AliTPCTranform::Transform(x,i,0,1)
555 Float_t meani = c.GetPad();
556 Float_t meanj = c.GetTimeBin();
558 Int_t ki = TMath::Nint(meani);
560 if (ki>=fMaxPad) ki = fMaxPad-1;
561 Int_t kj = TMath::Nint(meanj);
563 if (kj>=fMaxTime-3) kj=fMaxTime-4;
564 // ki and kj shifted as integers coordinata
566 c.SetLabel(fRowDig->GetTrackIDFast(kj,ki,0)-2,0);
567 c.SetLabel(fRowDig->GetTrackIDFast(kj,ki,1)-2,1);
568 c.SetLabel(fRowDig->GetTrackIDFast(kj,ki,2)-2,2);
572 c.SetDetector(fSector);
573 Float_t s2 = c.GetSigmaY2();
574 Float_t w=fParam->GetPadPitchWidth(fSector);
575 c.SetSigmaY2(s2*w*w);
577 c.SetSigmaZ2(s2*fZWidth*fZWidth);
581 AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
583 AliFatal("Tranformations not in calibDB");
585 Double_t x[3]={c.GetRow(),c.GetPad(),c.GetTimeBin()};
586 Int_t i[1]={fSector};
587 transform->Transform(x,i,0,1);
593 if (!fRecoParam->GetBYMirror()){
599 if (ki<=1 || ki>=fMaxPad-1 || kj==1 || kj==fMaxTime-2) {
600 c.SetType(-(c.GetType()+3)); //edge clusters
602 if (fLoop==2) c.SetType(100);
604 TClonesArray * arr = fRowCl->GetArray();
605 AliTPCclusterMI * cl = new ((*arr)[fNcluster]) AliTPCclusterMI(c);
606 if (fRecoParam->DumpSignal() &&matrix ) {
609 if (fRecoParam->GetCalcPedestal() && cl->GetMax()>fRecoParam->GetDumpAmplitudeMin() &&fBDumpSignal){
611 graph = &(fBins[fMaxTime*(pos/fMaxTime)]);
613 AliTPCclusterInfo * info = new AliTPCclusterInfo(matrix,nbins,graph);
616 if (!fRecoParam->DumpSignal()) {
624 //_____________________________________________________________________________
625 void AliTPCclustererMI::Digits2Clusters()
627 //-----------------------------------------------------------------
628 // This is a simple cluster finder.
629 //-----------------------------------------------------------------
632 Error("Digits2Clusters", "input tree not initialised");
636 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
637 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
638 AliSimDigits digarr, *dummy=&digarr;
640 fInput->GetBranch("Segment")->SetAddress(&dummy);
641 Stat_t nentries = fInput->GetEntries();
643 fMaxTime=fRecoParam->GetLastBin()+6; // add 3 virtual time bins before and 3 after
647 for (Int_t n=0; n<nentries; n++) {
649 if (!fParam->AdjustSectorRow(digarr.GetID(),fSector,fRow)) {
650 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
654 AliTPCCalROC * gainROC = gainTPC->GetCalROC(fSector); // pad gains per given sector
655 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(fSector); // noise per given sector
657 fRowCl= new AliTPCClustersRow();
658 fRowCl->SetClass("AliTPCclusterMI");
661 fRowCl->SetID(digarr.GetID());
662 if (fOutput) fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
663 fRx=fParam->GetPadRowRadii(fSector,row);
666 const Int_t kNIS=fParam->GetNInnerSector(), kNOS=fParam->GetNOuterSector();
667 fZWidth = fParam->GetZWidth();
668 if (fSector < kNIS) {
669 fMaxPad = fParam->GetNPadsLow(row);
670 fSign = (fSector < kNIS/2) ? 1 : -1;
671 fPadLength = fParam->GetPadPitchLength(fSector,row);
672 fPadWidth = fParam->GetPadPitchWidth();
674 fMaxPad = fParam->GetNPadsUp(row);
675 fSign = ((fSector-kNIS) < kNOS/2) ? 1 : -1;
676 fPadLength = fParam->GetPadPitchLength(fSector,row);
677 fPadWidth = fParam->GetPadPitchWidth();
681 fMaxBin=fMaxTime*(fMaxPad+6); // add 3 virtual pads before and 3 after
682 fBins =new Float_t[fMaxBin];
683 fSigBins =new Int_t[fMaxBin];
685 memset(fBins,0,sizeof(Float_t)*fMaxBin);
687 if (digarr.First()) //MI change
689 Float_t dig=digarr.CurrentDigit();
690 if (dig<=fParam->GetZeroSup()) continue;
691 Int_t j=digarr.CurrentRow()+3, i=digarr.CurrentColumn()+3;
692 Float_t gain = gainROC->GetValue(row,digarr.CurrentColumn());
693 Int_t bin = i*fMaxTime+j;
695 fSigBins[fNSigBins++]=bin;
696 } while (digarr.Next());
697 digarr.ExpandTrackBuffer();
699 FindClusters(noiseROC);
702 nclusters+=fNcluster;
707 Info("Digits2Clusters", "Number of found clusters : %d", nclusters);
710 void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
712 //-----------------------------------------------------------------
713 // This is a cluster finder for the TPC raw data.
714 // The method assumes NO ordering of the altro channels.
715 // The pedestal subtraction can be switched on and off
716 // using an option of the TPC reconstructor
717 //-----------------------------------------------------------------
721 AliTPCROC * roc = AliTPCROC::Instance();
722 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
723 AliTPCCalPad * pedestalTPC = AliTPCcalibDB::Instance()->GetPedestals();
724 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
725 AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
727 AliTPCRawStream input(rawReader,(AliAltroMapping**)mapping);
728 fEventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
730 fTimeStamp = fEventHeader->Get("Timestamp");
731 fEventType = fEventHeader->Get("Type");
737 fMaxTime = fRecoParam->GetLastBin() + 6; // add 3 virtual time bins before and 3 after
738 const Int_t kNIS = fParam->GetNInnerSector();
739 const Int_t kNOS = fParam->GetNOuterSector();
740 const Int_t kNS = kNIS + kNOS;
741 fZWidth = fParam->GetZWidth();
742 Int_t zeroSup = fParam->GetZeroSup();
744 //alocate memory for sector - maximal case
746 Float_t** allBins = NULL;
747 Int_t** allSigBins = NULL;
748 Int_t* allNSigBins = NULL;
749 Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
750 Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
751 allBins = new Float_t*[nRowsMax];
752 allSigBins = new Int_t*[nRowsMax];
753 allNSigBins = new Int_t[nRowsMax];
754 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
756 Int_t maxBin = fMaxTime*(nPadsMax+6); // add 3 virtual pads before and 3 after
757 allBins[iRow] = new Float_t[maxBin];
758 memset(allBins[iRow],0,sizeof(Float_t)*maxBin);
759 allSigBins[iRow] = new Int_t[maxBin];
765 for(fSector = 0; fSector < kNS; fSector++) {
767 AliTPCCalROC * gainROC = gainTPC->GetCalROC(fSector); // pad gains per given sector
768 AliTPCCalROC * pedestalROC = pedestalTPC->GetCalROC(fSector); // pedestal per given sector
769 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(fSector); // noise per given sector
770 //check the presence of the calibration
771 if (!noiseROC ||!pedestalROC ) {
772 AliError(Form("Missing calibration per sector\t%d\n",fSector));
776 Int_t nDDLs = 0, indexDDL = 0;
777 if (fSector < kNIS) {
778 nRows = fParam->GetNRowLow();
779 fSign = (fSector < kNIS/2) ? 1 : -1;
781 indexDDL = fSector * 2;
784 nRows = fParam->GetNRowUp();
785 fSign = ((fSector-kNIS) < kNOS/2) ? 1 : -1;
787 indexDDL = (fSector-kNIS) * 4 + kNIS * 2;
790 for (Int_t iRow = 0; iRow < nRows; iRow++) {
793 maxPad = fParam->GetNPadsLow(iRow);
795 maxPad = fParam->GetNPadsUp(iRow);
797 Int_t maxBin = fMaxTime*(maxPad+6); // add 3 virtual pads before and 3 after
798 memset(allBins[iRow],0,sizeof(Float_t)*maxBin);
799 allNSigBins[iRow] = 0;
802 // Loas the raw data for corresponding DDLs
804 input.SetOldRCUFormat(fIsOldRCUFormat);
805 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
807 // Begin loop over altro data
808 Bool_t calcPedestal = fRecoParam->GetCalcPedestal();
811 while (input.Next()) {
812 if (input.GetSector() != fSector)
813 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",fSector,input.GetSector()));
816 Int_t iRow = input.GetRow();
817 if (iRow < 0 || iRow >= nRows){
818 AliError(Form("Pad-row index (%d) outside the range (%d -> %d) !",
823 Int_t iPad = input.GetPad();
824 if (iPad < 0 || iPad >= nPadsMax) {
825 AliError(Form("Pad index (%d) outside the range (%d -> %d) !",
826 iPad, 0, nPadsMax-1));
830 gain = gainROC->GetValue(iRow,iPad);
835 Int_t iTimeBin = input.GetTime();
836 if ( iTimeBin < fRecoParam->GetFirstBin() || iTimeBin >= fRecoParam->GetLastBin()){
838 AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
839 iTimeBin, 0, iTimeBin -1));
844 Float_t signal = input.GetSignal();
845 if (!calcPedestal && signal <= zeroSup) continue;
847 Int_t bin = iPad*fMaxTime+iTimeBin;
848 allBins[iRow][bin] = signal/gain;
849 allSigBins[iRow][allNSigBins[iRow]++] = bin;
851 allBins[iRow][iPad*fMaxTime+iTimeBin] = signal;
853 allBins[iRow][iPad*fMaxTime+0]+=1.; // pad with signal
857 } // End of the loop over altro data
862 // Now loop over rows and perform pedestal subtraction
863 if (digCounter==0) continue;
864 // if (calcPedestal) {
866 for (Int_t iRow = 0; iRow < nRows; iRow++) {
869 maxPad = fParam->GetNPadsLow(iRow);
871 maxPad = fParam->GetNPadsUp(iRow);
873 for (Int_t iPad = 3; iPad < maxPad + 3; iPad++) {
875 // Temporary fix for data production - !!!! MARIAN
876 // The noise calibration should take mean and RMS - currently the Gaussian fit used
877 // In case of double peak - the pad should be rejected
879 // Line mean - if more than given digits over threshold - make a noise calculation
880 // and pedestal substration
881 if (!calcPedestal && allBins[iRow][iPad*fMaxTime+0]<50) continue;
883 if (allBins[iRow][iPad*fMaxTime+0] <1 ) continue; // no data
884 Float_t *p = &allBins[iRow][iPad*fMaxTime+3];
885 //Float_t pedestal = TMath::Median(fMaxTime, p);
886 Int_t id[3] = {fSector, iRow, iPad-3};
888 Double_t rmsCalib= noiseROC->GetValue(iRow,iPad-3);
889 Double_t pedestalCalib = pedestalROC->GetValue(iRow,iPad-3);
890 Double_t rmsEvent = rmsCalib;
891 Double_t pedestalEvent = pedestalCalib;
892 ProcesSignal(p, fMaxTime, id, rmsEvent, pedestalEvent);
893 if (rmsEvent<rmsCalib) rmsEvent = rmsCalib; // take worst scenario
894 if (TMath::Abs(pedestalEvent-pedestalCalib)<1.0) pedestalEvent = pedestalCalib;
897 for (Int_t iTimeBin = 0; iTimeBin < fMaxTime; iTimeBin++) {
898 Int_t bin = iPad*fMaxTime+iTimeBin;
899 allBins[iRow][bin] -= pedestalEvent;
900 if (iTimeBin < AliTPCReconstructor::GetRecoParam()->GetFirstBin())
901 allBins[iRow][bin] = 0;
902 if (iTimeBin > AliTPCReconstructor::GetRecoParam()->GetLastBin())
903 allBins[iRow][bin] = 0;
904 if (allBins[iRow][iPad*fMaxTime+iTimeBin] < zeroSup)
905 allBins[iRow][bin] = 0;
906 if (allBins[iRow][bin] < 3.0*rmsEvent) // 3 sigma cut on RMS
907 allBins[iRow][bin] = 0;
908 if (allBins[iRow][bin]) allSigBins[iRow][allNSigBins[iRow]++] = bin;
913 // Now loop over rows and find clusters
914 for (fRow = 0; fRow < nRows; fRow++) {
915 fRowCl = new AliTPCClustersRow;
916 fRowCl->SetClass("AliTPCclusterMI");
918 fRowCl->SetID(fParam->GetIndex(fSector, fRow));
919 if (fOutput) fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
921 fRx = fParam->GetPadRowRadii(fSector, fRow);
922 fPadLength = fParam->GetPadPitchLength(fSector, fRow);
923 fPadWidth = fParam->GetPadPitchWidth();
925 fMaxPad = fParam->GetNPadsLow(fRow);
927 fMaxPad = fParam->GetNPadsUp(fRow);
928 fMaxBin = fMaxTime*(fMaxPad+6); // add 3 virtual pads before and 3 after
930 fBins = allBins[fRow];
931 fSigBins = allSigBins[fRow];
932 fNSigBins = allNSigBins[fRow];
934 FindClusters(noiseROC);
937 nclusters += fNcluster;
938 } // End of loop to find clusters
939 } // End of loop over sectors
941 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
942 delete [] allBins[iRow];
943 delete [] allSigBins[iRow];
946 delete [] allSigBins;
947 delete [] allNSigBins;
949 // if (rawReader->GetEventId() && fOutput ){
950 // Info("Digits2Clusters", "File %s Event\t%d\tNumber of found clusters : %d\n", fOutput->GetName(),*(rawReader->GetEventId()), nclusters);
952 // Info("Digits2Clusters", "Event\t%d\tNumber of found clusters : %d\n",*(rawReader->GetEventId()), nclusters);
958 void AliTPCclustererMI::FindClusters(AliTPCCalROC * noiseROC)
962 // add virtual charge at the edge
964 Double_t kMaxDumpSize = 500000;
966 fBDumpSignal =kFALSE;
968 if (fRecoParam->GetCalcPedestal() && fOutput->GetZipBytes()< kMaxDumpSize) fBDumpSignal =kTRUE; //dump signal flag
973 Int_t crtime = Int_t((fParam->GetZLength(fSector)-fRecoParam->GetCtgRange()*fRx)/fZWidth-fParam->GetNTBinsL1()-5);
974 Float_t minMaxCutAbs = fRecoParam->GetMinMaxCutAbs();
975 Float_t minLeftRightCutAbs = fRecoParam->GetMinLeftRightCutAbs();
976 Float_t minUpDownCutAbs = fRecoParam->GetMinUpDownCutAbs();
977 Float_t minMaxCutSigma = fRecoParam->GetMinMaxCutSigma();
978 Float_t minLeftRightCutSigma = fRecoParam->GetMinLeftRightCutSigma();
979 Float_t minUpDownCutSigma = fRecoParam->GetMinUpDownCutSigma();
980 for (Int_t iSig = 0; iSig < fNSigBins; iSig++) {
981 Int_t i = fSigBins[iSig];
982 if (i%fMaxTime<=crtime) continue;
983 Float_t *b = &fBins[i];
985 if (b[0]<minMaxCutAbs) continue; //threshold for maxima
987 if (b[-1]+b[1]+b[-fMaxTime]+b[fMaxTime]<=0) continue; // cut on isolated clusters
988 if (b[-1]+b[1]<=0) continue; // cut on isolated clusters
989 if (b[-fMaxTime]+b[fMaxTime]<=0) continue; // cut on isolated clusters
991 if ((b[0]+b[-1]+b[1])<minUpDownCutAbs) continue; //threshold for up down (TRF)
992 if ((b[0]+b[-fMaxTime]+b[fMaxTime])<minLeftRightCutAbs) continue; //threshold for left right (PRF)
993 if (!IsMaximum(*b,fMaxTime,b)) continue;
995 Float_t noise = noiseROC->GetValue(fRow, i/fMaxTime);
996 if (noise>fRecoParam->GetMaxNoise()) continue;
998 if (b[0]<minMaxCutSigma*noise) continue; //threshold form maxima
999 if ((b[0]+b[-1]+b[1])<minUpDownCutSigma*noise) continue; //threshold for up town TRF
1000 if ((b[0]+b[-fMaxTime]+b[fMaxTime])<minLeftRightCutSigma*noise) continue; //threshold for left right (PRF)
1002 AliTPCclusterMI c(kFALSE); // default cosntruction without info
1004 MakeCluster(i, fMaxTime, fBins, dummy,c);
1011 Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t id[3], Double_t &rmsEvent, Double_t &pedestalEvent){
1013 // process signal on given pad - + streaming of additional information in special mode
1020 // ESTIMATE pedestal and the noise
1022 const Int_t kPedMax = 100;
1023 Double_t kMaxDebugSize = 5000000.;
1029 Float_t rmsCalib = rmsEvent; // backup initial value ( from calib)
1030 Float_t pedestalCalib = pedestalEvent;// backup initial value ( from calib)
1031 Int_t firstBin = AliTPCReconstructor::GetRecoParam()->GetFirstBin();
1033 UShort_t histo[kPedMax];
1034 memset(histo,0,kPedMax*sizeof(UShort_t));
1035 for (Int_t i=0; i<fMaxTime; i++){
1036 if (signal[i]<=0) continue;
1037 if (signal[i]>max && i>firstBin) {
1041 if (signal[i]>kPedMax-1) continue;
1042 histo[int(signal[i]+0.5)]++;
1046 for (Int_t i=1; i<kPedMax; i++){
1047 if (count1<count0*0.5) median=i;
1052 Float_t count10=histo[median] ,mean=histo[median]*median, rms=histo[median]*median*median ;
1053 Float_t count06=histo[median] ,mean06=histo[median]*median, rms06=histo[median]*median*median ;
1054 Float_t count09=histo[median] ,mean09=histo[median]*median, rms09=histo[median]*median*median ;
1056 for (Int_t idelta=1; idelta<10; idelta++){
1057 if (median-idelta<=0) continue;
1058 if (median+idelta>kPedMax) continue;
1059 if (count06<0.6*count1){
1060 count06+=histo[median-idelta];
1061 mean06 +=histo[median-idelta]*(median-idelta);
1062 rms06 +=histo[median-idelta]*(median-idelta)*(median-idelta);
1063 count06+=histo[median+idelta];
1064 mean06 +=histo[median+idelta]*(median+idelta);
1065 rms06 +=histo[median+idelta]*(median+idelta)*(median+idelta);
1067 if (count09<0.9*count1){
1068 count09+=histo[median-idelta];
1069 mean09 +=histo[median-idelta]*(median-idelta);
1070 rms09 +=histo[median-idelta]*(median-idelta)*(median-idelta);
1071 count09+=histo[median+idelta];
1072 mean09 +=histo[median+idelta]*(median+idelta);
1073 rms09 +=histo[median+idelta]*(median+idelta)*(median+idelta);
1075 if (count10<0.95*count1){
1076 count10+=histo[median-idelta];
1077 mean +=histo[median-idelta]*(median-idelta);
1078 rms +=histo[median-idelta]*(median-idelta)*(median-idelta);
1079 count10+=histo[median+idelta];
1080 mean +=histo[median+idelta]*(median+idelta);
1081 rms +=histo[median+idelta]*(median+idelta)*(median+idelta);
1086 rms = TMath::Sqrt(TMath::Abs(rms/count10-mean*mean));
1090 rms06 = TMath::Sqrt(TMath::Abs(rms06/count06-mean06*mean06));
1094 rms09 = TMath::Sqrt(TMath::Abs(rms09/count09-mean09*mean09));
1098 pedestalEvent = median;
1099 if (AliLog::GetDebugLevel("","AliTPCclustererMI")==0) return median;
1101 UInt_t uid[3] = {UInt_t(id[0]),UInt_t(id[1]),UInt_t(id[2])};
1103 // Dump mean signal info
1105 (*fDebugStreamer)<<"Signal"<<
1106 "TimeStamp="<<fTimeStamp<<
1107 "EventType="<<fEventType<<
1121 "RMSCalib="<<rmsCalib<<
1122 "PedCalib="<<pedestalCalib<<
1125 // fill pedestal histogram
1127 AliTPCROC * roc = AliTPCROC::Instance();
1132 Float_t kMin =fRecoParam->GetDumpAmplitudeMin(); // minimal signal to be dumped
1133 Float_t *dsignal = new Float_t[nchannels];
1134 Float_t *dtime = new Float_t[nchannels];
1135 for (Int_t i=0; i<nchannels; i++){
1137 dsignal[i] = signal[i];
1142 // Big signals dumping
1144 if (max-median>kMin &&maxPos>AliTPCReconstructor::GetRecoParam()->GetFirstBin())
1145 (*fDebugStreamer)<<"SignalB"<< // pads with signal
1146 "TimeStamp="<<fTimeStamp<<
1147 "EventType="<<fEventType<<
1167 if (rms06>fRecoParam->GetMaxNoise()) {
1168 pedestalEvent+=1024.;
1169 return 1024+median; // sign noisy channel in debug mode