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),
108 // param - tpc parameters for given file
109 // recoparam - reconstruction parameters
114 fRecoParam = recoParam;
116 //set default parameters if not specified
117 fRecoParam = AliTPCReconstructor::GetRecoParam();
118 if (!fRecoParam) fRecoParam = AliTPCRecoParam::GetLowFluxParam();
120 fDebugStreamer = new TTreeSRedirector("TPCsignal.root");
121 Int_t nPoints = fRecoParam->GetLastBin()-fRecoParam->GetFirstBin();
122 fRowCl= new AliTPCClustersRow();
123 fRowCl->SetClass("AliTPCclusterMI");
127 //______________________________________________________________
128 AliTPCclustererMI::AliTPCclustererMI(const AliTPCclustererMI ¶m)
144 fPedSubtraction(kFALSE),
162 fMaxBin = param.fMaxBin;
164 //______________________________________________________________
165 AliTPCclustererMI & AliTPCclustererMI::operator =(const AliTPCclustererMI & param)
168 // assignment operator - dummy
170 fMaxBin=param.fMaxBin;
173 //______________________________________________________________
174 AliTPCclustererMI::~AliTPCclustererMI(){
178 if (fDebugStreamer) delete fDebugStreamer;
180 //fOutputArray->Delete();
185 void AliTPCclustererMI::SetInput(TTree * tree)
188 // set input tree with digits
191 if (!fInput->GetBranch("Segment")){
192 cerr<<"AliTPC::Digits2Clusters(): no porper input tree !\n";
198 void AliTPCclustererMI::SetOutput(TTree * tree)
201 // Set the output tree
202 // If not set the ObjArray used - Option for HLT
206 AliTPCClustersRow clrow;
207 AliTPCClustersRow *pclrow=&clrow;
208 clrow.SetClass("AliTPCclusterMI");
209 clrow.SetArray(1); // to make Clones array
210 fOutput->Branch("Segment","AliTPCClustersRow",&pclrow,32000,200);
214 void AliTPCclustererMI::FillRow(){
216 // fill the output container -
217 // 2 Options possible
221 if (fOutput) fOutput->Fill();
224 if (!fOutputArray) fOutputArray = new TObjArray(fParam->GetNRowsTotal());
225 if (fRowCl) fOutputArray->AddAt(fRowCl->Clone(), fRowCl->GetID());
229 Float_t AliTPCclustererMI::GetSigmaY2(Int_t iz){
230 // sigma y2 = in digits - we don't know the angle
231 Float_t z = iz*fParam->GetZWidth()+fParam->GetNTBinsL1()*fParam->GetZWidth();
232 Float_t sd2 = (z*fParam->GetDiffL()*fParam->GetDiffL())/
233 (fPadWidth*fPadWidth);
235 Float_t res = sd2+sres;
240 Float_t AliTPCclustererMI::GetSigmaZ2(Int_t iz){
241 //sigma z2 = in digits - angle estimated supposing vertex constraint
242 Float_t z = iz*fZWidth+fParam->GetNTBinsL1()*fParam->GetZWidth();
243 Float_t sd2 = (z*fParam->GetDiffL()*fParam->GetDiffL())/(fZWidth*fZWidth);
244 Float_t angular = fPadLength*(fParam->GetZLength(fSector)-z)/(fRx*fZWidth);
247 Float_t sres = fParam->GetZSigma()/fZWidth;
249 Float_t res = angular +sd2+sres;
253 void AliTPCclustererMI::MakeCluster(Int_t k,Int_t max,Float_t *bins, UInt_t /*m*/,
257 // k - Make cluster at position k
258 // bins - 2 D array of signals mapped to 1 dimensional array -
259 // max - the number of time bins er one dimension
260 // c - refernce to cluster to be filled
262 Int_t i0=k/max; //central pad
263 Int_t j0=k%max; //central time bin
265 // set pointers to data
266 //Int_t dummy[5] ={0,0,0,0,0};
267 Float_t * matrix[5]; //5x5 matrix with digits - indexing i = 0 ..4 j = -2..2
268 for (Int_t di=-2;di<=2;di++){
269 matrix[di+2] = &bins[k+di*max];
271 //build matrix with virtual charge
272 Float_t sigmay2= GetSigmaY2(j0);
273 Float_t sigmaz2= GetSigmaZ2(j0);
275 Float_t vmatrix[5][5];
276 vmatrix[2][2] = matrix[2][0];
278 c.SetMax((UShort_t)(vmatrix[2][2])); // write maximal amplitude
279 for (Int_t di =-1;di <=1;di++)
280 for (Int_t dj =-1;dj <=1;dj++){
281 Float_t amp = matrix[di+2][dj];
282 if ( (amp<2) && (fLoop<2)){
283 // if under threshold - calculate virtual charge
284 Float_t ratio = TMath::Exp(-1.2*TMath::Abs(di)/sigmay2)*TMath::Exp(-1.2*TMath::Abs(dj)/sigmaz2);
285 amp = ((matrix[2][0]-2)*(matrix[2][0]-2)/(matrix[-di+2][-dj]+2))*ratio;
287 vmatrix[2+di][2+dj]=amp;
288 vmatrix[2+2*di][2+2*dj]=0;
291 vmatrix[2+2*di][2+dj] =0;
292 vmatrix[2+di][2+2*dj] =0;
297 //if small amplitude - below 2 x threshold - don't consider other one
298 vmatrix[2+di][2+dj]=amp;
299 vmatrix[2+2*di][2+2*dj]=0; // don't take to the account next bin
302 vmatrix[2+2*di][2+dj] =0;
303 vmatrix[2+di][2+2*dj] =0;
307 //if bigger then take everything
308 vmatrix[2+di][2+dj]=amp;
309 vmatrix[2+2*di][2+2*dj]= matrix[2*di+2][2*dj] ;
312 vmatrix[2+2*di][2+dj] = matrix[2*di+2][dj];
313 vmatrix[2+di][2+2*dj] = matrix[2+di][dj*2];
325 for (Int_t i=-2;i<=2;i++)
326 for (Int_t j=-2;j<=2;j++){
327 Float_t amp = vmatrix[i+2][j+2];
336 Float_t meani = sumiw/sumw;
337 Float_t mi2 = sumi2w/sumw-meani*meani;
338 Float_t meanj = sumjw/sumw;
339 Float_t mj2 = sumj2w/sumw-meanj*meanj;
341 Float_t ry = mi2/sigmay2;
342 Float_t rz = mj2/sigmaz2;
345 if ( ( (ry<0.6) || (rz<0.6) ) && fLoop==2) return;
346 if ( (ry <1.2) && (rz<1.2) || (!fRecoParam->GetDoUnfold())) {
348 //if cluster looks like expected or Unfolding not switched on
349 //standard COG is used
350 //+1.2 deviation from expected sigma accepted
351 // c.fMax = FitMax(vmatrix,meani,meanj,TMath::Sqrt(sigmay2),TMath::Sqrt(sigmaz2));
355 //set cluster parameters
358 c.SetTimeBin(meanj-3);
362 AddCluster(c,(Float_t*)vmatrix,k);
366 //unfolding when neccessary
369 Float_t * matrix2[7]; //7x7 matrix with digits - indexing i = 0 ..6 j = -3..3
370 Float_t dummy[7]={0,0,0,0,0,0};
371 for (Int_t di=-3;di<=3;di++){
372 matrix2[di+3] = &bins[k+di*max];
373 if ((k+di*max)<3) matrix2[di+3] = &dummy[3];
374 if ((k+di*max)>fMaxBin-3) matrix2[di+3] = &dummy[3];
376 Float_t vmatrix2[5][5];
379 UnfoldCluster(matrix2,vmatrix2,meani,meanj,sumu,overlap);
381 // c.fMax = FitMax(vmatrix2,meani,meanj,TMath::Sqrt(sigmay2),TMath::Sqrt(sigmaz2));
384 //set cluster parameters
387 c.SetTimeBin(meanj-3);
390 c.SetType(Char_t(overlap)+1);
391 AddCluster(c,(Float_t*)vmatrix,k);
397 printf("%f\t%f\n", vmatrix2[2][2], vmatrix[2][2]);
402 void AliTPCclustererMI::UnfoldCluster(Float_t * matrix2[7], Float_t recmatrix[5][5], Float_t & meani, Float_t & meanj,
403 Float_t & sumu, Float_t & overlap )
406 //unfold cluster from input matrix
407 //data corresponding to cluster writen in recmatrix
408 //output meani and meanj
410 //take separatelly y and z
412 Float_t sum3i[7] = {0,0,0,0,0,0,0};
413 Float_t sum3j[7] = {0,0,0,0,0,0,0};
415 for (Int_t k =0;k<7;k++)
416 for (Int_t l = -1; l<=1;l++){
417 sum3i[k]+=matrix2[k][l];
418 sum3j[k]+=matrix2[l+3][k-3];
420 Float_t mratio[3][3]={{1,1,1},{1,1,1},{1,1,1}};
423 Float_t sum3wi = 0; //charge minus overlap
424 Float_t sum3wio = 0; //full charge
425 Float_t sum3iw = 0; //sum for mean value
426 for (Int_t dk=-1;dk<=1;dk++){
427 sum3wio+=sum3i[dk+3];
433 if ( ( ((sum3i[dk+3]+3)/(sum3i[3]-3))+1 < (sum3i[2*dk+3]-3)/(sum3i[dk+3]+3))||
434 sum3i[dk+3]<=sum3i[2*dk+3] && sum3i[dk+3]>2 ){
435 Float_t xm2 = sum3i[-dk+3];
436 Float_t xm1 = sum3i[+3];
437 Float_t x1 = sum3i[2*dk+3];
438 Float_t x2 = sum3i[3*dk+3];
439 Float_t w11 = TMath::Max((Float_t)(4.*xm1-xm2),(Float_t)0.000001);
440 Float_t w12 = TMath::Max((Float_t)(4 *x1 -x2),(Float_t)0.);
441 ratio = w11/(w11+w12);
442 for (Int_t dl=-1;dl<=1;dl++)
443 mratio[dk+1][dl+1] *= ratio;
445 Float_t amp = sum3i[dk+3]*ratio;
450 meani = sum3iw/sum3wi;
451 Float_t overlapi = (sum3wio-sum3wi)/sum3wio;
456 Float_t sum3wj = 0; //charge minus overlap
457 Float_t sum3wjo = 0; //full charge
458 Float_t sum3jw = 0; //sum for mean value
459 for (Int_t dk=-1;dk<=1;dk++){
460 sum3wjo+=sum3j[dk+3];
466 if ( ( ((sum3j[dk+3]+3)/(sum3j[3]-3))+1 < (sum3j[2*dk+3]-3)/(sum3j[dk+3]+3)) ||
467 (sum3j[dk+3]<=sum3j[2*dk+3] && sum3j[dk+3]>2)){
468 Float_t xm2 = sum3j[-dk+3];
469 Float_t xm1 = sum3j[+3];
470 Float_t x1 = sum3j[2*dk+3];
471 Float_t x2 = sum3j[3*dk+3];
472 Float_t w11 = TMath::Max((Float_t)(4.*xm1-xm2),(Float_t)0.000001);
473 Float_t w12 = TMath::Max((Float_t)(4 *x1 -x2),(Float_t)0.);
474 ratio = w11/(w11+w12);
475 for (Int_t dl=-1;dl<=1;dl++)
476 mratio[dl+1][dk+1] *= ratio;
478 Float_t amp = sum3j[dk+3]*ratio;
483 meanj = sum3jw/sum3wj;
484 Float_t overlapj = (sum3wjo-sum3wj)/sum3wjo;
485 overlap = Int_t(100*TMath::Max(overlapi,overlapj)+3);
486 sumu = (sum3wj+sum3wi)/2.;
489 //if not overlap detected remove everything
490 for (Int_t di =-2; di<=2;di++)
491 for (Int_t dj =-2; dj<=2;dj++){
492 recmatrix[di+2][dj+2] = matrix2[3+di][dj];
496 for (Int_t di =-1; di<=1;di++)
497 for (Int_t dj =-1; dj<=1;dj++){
499 if (mratio[di+1][dj+1]==1){
500 recmatrix[di+2][dj+2] = matrix2[3+di][dj];
501 if (TMath::Abs(di)+TMath::Abs(dj)>1){
502 recmatrix[2*di+2][dj+2] = matrix2[3+2*di][dj];
503 recmatrix[di+2][2*dj+2] = matrix2[3+di][2*dj];
505 recmatrix[2*di+2][2*dj+2] = matrix2[3+2*di][2*dj];
509 //if we have overlap in direction
510 recmatrix[di+2][dj+2] = mratio[di+1][dj+1]* matrix2[3+di][dj];
511 if (TMath::Abs(di)+TMath::Abs(dj)>1){
512 ratio = TMath::Min((Float_t)(recmatrix[di+2][dj+2]/(matrix2[3+0*di][1*dj]+1)),(Float_t)1.);
513 recmatrix[2*di+2][dj+2] = ratio*recmatrix[di+2][dj+2];
515 ratio = TMath::Min((Float_t)(recmatrix[di+2][dj+2]/(matrix2[3+1*di][0*dj]+1)),(Float_t)1.);
516 recmatrix[di+2][2*dj+2] = ratio*recmatrix[di+2][dj+2];
519 ratio = recmatrix[di+2][dj+2]/matrix2[3][0];
520 recmatrix[2*di+2][2*dj+2] = ratio*recmatrix[di+2][dj+2];
526 printf("%f\n", recmatrix[2][2]);
530 Float_t AliTPCclustererMI::FitMax(Float_t vmatrix[5][5], Float_t y, Float_t z, Float_t sigmay, Float_t sigmaz)
537 for (Int_t di = -1;di<=1;di++)
538 for (Int_t dj = -1;dj<=1;dj++){
539 if (vmatrix[2+di][2+dj]>2){
540 Float_t teor = TMath::Gaus(di,y,sigmay*1.2)*TMath::Gaus(dj,z,sigmaz*1.2);
541 sumteor += teor*vmatrix[2+di][2+dj];
542 sumamp += vmatrix[2+di][2+dj]*vmatrix[2+di][2+dj];
545 Float_t max = sumamp/sumteor;
549 void AliTPCclustererMI::AddCluster(AliTPCclusterMI &c, Float_t * matrix, Int_t pos){
552 // Transform cluster to the rotated global coordinata
553 // Assign labels to the cluster
554 // add the cluster to the array
555 // for more details - See AliTPCTranform::Transform(x,i,0,1)
556 Float_t meani = c.GetPad();
557 Float_t meanj = c.GetTimeBin();
559 Int_t ki = TMath::Nint(meani);
561 if (ki>=fMaxPad) ki = fMaxPad-1;
562 Int_t kj = TMath::Nint(meanj);
564 if (kj>=fMaxTime-3) kj=fMaxTime-4;
565 // ki and kj shifted as integers coordinata
567 c.SetLabel(fRowDig->GetTrackIDFast(kj,ki,0)-2,0);
568 c.SetLabel(fRowDig->GetTrackIDFast(kj,ki,1)-2,1);
569 c.SetLabel(fRowDig->GetTrackIDFast(kj,ki,2)-2,2);
573 c.SetDetector(fSector);
574 Float_t s2 = c.GetSigmaY2();
575 Float_t w=fParam->GetPadPitchWidth(fSector);
576 c.SetSigmaY2(s2*w*w);
578 c.SetSigmaZ2(s2*fZWidth*fZWidth);
582 AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
584 AliFatal("Tranformations not in calibDB");
586 Double_t x[3]={c.GetRow(),c.GetPad(),c.GetTimeBin()};
587 Int_t i[1]={fSector};
588 transform->Transform(x,i,0,1);
594 if (!fRecoParam->GetBYMirror()){
600 if (ki<=1 || ki>=fMaxPad-1 || kj==1 || kj==fMaxTime-2) {
601 c.SetType(-(c.GetType()+3)); //edge clusters
603 if (fLoop==2) c.SetType(100);
605 TClonesArray * arr = fRowCl->GetArray();
606 AliTPCclusterMI * cl = new ((*arr)[fNcluster]) AliTPCclusterMI(c);
607 // if (fRecoParam->DumpSignal() &&matrix ) {
609 // Float_t *graph =0;
610 // if (fRecoParam->GetCalcPedestal() && cl->GetMax()>fRecoParam->GetDumpAmplitudeMin() &&fBDumpSignal){
612 // graph = &(fBins[fMaxTime*(pos/fMaxTime)]);
614 // AliTPCclusterInfo * info = new AliTPCclusterInfo(matrix,nbins,graph);
615 // cl->SetInfo(info);
617 if (!fRecoParam->DumpSignal()) {
625 //_____________________________________________________________________________
626 void AliTPCclustererMI::Digits2Clusters()
628 //-----------------------------------------------------------------
629 // This is a simple cluster finder.
630 //-----------------------------------------------------------------
633 Error("Digits2Clusters", "input tree not initialised");
637 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
638 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
639 AliSimDigits digarr, *dummy=&digarr;
641 fInput->GetBranch("Segment")->SetAddress(&dummy);
642 Stat_t nentries = fInput->GetEntries();
644 fMaxTime=fRecoParam->GetLastBin()+6; // add 3 virtual time bins before and 3 after
648 for (Int_t n=0; n<nentries; n++) {
650 if (!fParam->AdjustSectorRow(digarr.GetID(),fSector,fRow)) {
651 cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
655 AliTPCCalROC * gainROC = gainTPC->GetCalROC(fSector); // pad gains per given sector
656 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(fSector); // noise per given sector
659 fRowCl->SetID(digarr.GetID());
660 if (fOutput) fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
661 fRx=fParam->GetPadRowRadii(fSector,row);
664 const Int_t kNIS=fParam->GetNInnerSector(), kNOS=fParam->GetNOuterSector();
665 fZWidth = fParam->GetZWidth();
666 if (fSector < kNIS) {
667 fMaxPad = fParam->GetNPadsLow(row);
668 fSign = (fSector < kNIS/2) ? 1 : -1;
669 fPadLength = fParam->GetPadPitchLength(fSector,row);
670 fPadWidth = fParam->GetPadPitchWidth();
672 fMaxPad = fParam->GetNPadsUp(row);
673 fSign = ((fSector-kNIS) < kNOS/2) ? 1 : -1;
674 fPadLength = fParam->GetPadPitchLength(fSector,row);
675 fPadWidth = fParam->GetPadPitchWidth();
679 fMaxBin=fMaxTime*(fMaxPad+6); // add 3 virtual pads before and 3 after
680 fBins =new Float_t[fMaxBin];
681 fSigBins =new Int_t[fMaxBin];
683 memset(fBins,0,sizeof(Float_t)*fMaxBin);
685 if (digarr.First()) //MI change
687 Float_t dig=digarr.CurrentDigit();
688 if (dig<=fParam->GetZeroSup()) continue;
689 Int_t j=digarr.CurrentRow()+3, i=digarr.CurrentColumn()+3;
690 Float_t gain = gainROC->GetValue(row,digarr.CurrentColumn());
691 Int_t bin = i*fMaxTime+j;
693 fSigBins[fNSigBins++]=bin;
694 } while (digarr.Next());
695 digarr.ExpandTrackBuffer();
697 FindClusters(noiseROC);
699 fRowCl->GetArray()->Clear();
700 nclusters+=fNcluster;
705 Info("Digits2Clusters", "Number of found clusters : %d", nclusters);
708 void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
710 //-----------------------------------------------------------------
711 // This is a cluster finder for the TPC raw data.
712 // The method assumes NO ordering of the altro channels.
713 // The pedestal subtraction can be switched on and off
714 // using an option of the TPC reconstructor
715 //-----------------------------------------------------------------
719 AliTPCROC * roc = AliTPCROC::Instance();
720 AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
721 AliTPCCalPad * pedestalTPC = AliTPCcalibDB::Instance()->GetPedestals();
722 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
723 AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
725 AliTPCRawStream input(rawReader,(AliAltroMapping**)mapping);
726 fEventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
728 fTimeStamp = fEventHeader->Get("Timestamp");
729 fEventType = fEventHeader->Get("Type");
735 fMaxTime = fRecoParam->GetLastBin() + 6; // add 3 virtual time bins before and 3 after
736 const Int_t kNIS = fParam->GetNInnerSector();
737 const Int_t kNOS = fParam->GetNOuterSector();
738 const Int_t kNS = kNIS + kNOS;
739 fZWidth = fParam->GetZWidth();
740 Int_t zeroSup = fParam->GetZeroSup();
742 //alocate memory for sector - maximal case
744 Float_t** allBins = NULL;
745 Int_t** allSigBins = NULL;
746 Int_t* allNSigBins = NULL;
747 Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
748 Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
749 allBins = new Float_t*[nRowsMax];
750 allSigBins = new Int_t*[nRowsMax];
751 allNSigBins = new Int_t[nRowsMax];
752 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
754 Int_t maxBin = fMaxTime*(nPadsMax+6); // add 3 virtual pads before and 3 after
755 allBins[iRow] = new Float_t[maxBin];
756 memset(allBins[iRow],0,sizeof(Float_t)*maxBin);
757 allSigBins[iRow] = new Int_t[maxBin];
763 for(fSector = 0; fSector < kNS; fSector++) {
765 AliTPCCalROC * gainROC = gainTPC->GetCalROC(fSector); // pad gains per given sector
766 AliTPCCalROC * pedestalROC = pedestalTPC->GetCalROC(fSector); // pedestal per given sector
767 AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(fSector); // noise per given sector
768 //check the presence of the calibration
769 if (!noiseROC ||!pedestalROC ) {
770 AliError(Form("Missing calibration per sector\t%d\n",fSector));
774 Int_t nDDLs = 0, indexDDL = 0;
775 if (fSector < kNIS) {
776 nRows = fParam->GetNRowLow();
777 fSign = (fSector < kNIS/2) ? 1 : -1;
779 indexDDL = fSector * 2;
782 nRows = fParam->GetNRowUp();
783 fSign = ((fSector-kNIS) < kNOS/2) ? 1 : -1;
785 indexDDL = (fSector-kNIS) * 4 + kNIS * 2;
788 for (Int_t iRow = 0; iRow < nRows; iRow++) {
791 maxPad = fParam->GetNPadsLow(iRow);
793 maxPad = fParam->GetNPadsUp(iRow);
795 Int_t maxBin = fMaxTime*(maxPad+6); // add 3 virtual pads before and 3 after
796 memset(allBins[iRow],0,sizeof(Float_t)*maxBin);
797 allNSigBins[iRow] = 0;
800 // Loas the raw data for corresponding DDLs
802 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
804 // Begin loop over altro data
805 Bool_t calcPedestal = fRecoParam->GetCalcPedestal();
808 while (input.Next()) {
809 if (input.GetSector() != fSector)
810 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",fSector,input.GetSector()));
813 Int_t iRow = input.GetRow();
818 if (iRow < 0 || iRow >= nRows){
819 AliError(Form("Pad-row index (%d) outside the range (%d -> %d) !",
824 Int_t iPad = input.GetPad();
825 if (iPad < 0 || iPad >= nPadsMax) {
826 AliError(Form("Pad index (%d) outside the range (%d -> %d) !",
827 iPad, 0, nPadsMax-1));
831 gain = gainROC->GetValue(iRow,iPad);
836 Int_t iTimeBin = input.GetTime();
837 if ( iTimeBin < fRecoParam->GetFirstBin() || iTimeBin >= fRecoParam->GetLastBin()){
839 AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
840 iTimeBin, 0, iTimeBin -1));
845 Float_t signal = input.GetSignal();
846 if (!calcPedestal && signal <= zeroSup) continue;
847 if (AliTPCReconstructor::StreamLevel()>3 && signal>3) {
848 Double_t x[]={iRow,iPad,iTimeBin};
850 AliTPCTransform trafo;
851 trafo.Transform(x,i,0,1);
852 Double_t gx[3]={x[0],x[1],x[2]};
853 trafo.RotatedGlobal2Global(fSector,gx);
855 (*fDebugStreamer)<<"Digits"<<
871 Int_t bin = iPad*fMaxTime+iTimeBin;
872 allBins[iRow][bin] = signal/gain;
873 allSigBins[iRow][allNSigBins[iRow]++] = bin;
875 allBins[iRow][iPad*fMaxTime+iTimeBin] = signal;
877 allBins[iRow][iPad*fMaxTime+0]+=1.; // pad with signal
881 } // End of the loop over altro data
886 // Now loop over rows and perform pedestal subtraction
887 if (digCounter==0) continue;
888 // if (calcPedestal) {
890 for (Int_t iRow = 0; iRow < nRows; iRow++) {
893 maxPad = fParam->GetNPadsLow(iRow);
895 maxPad = fParam->GetNPadsUp(iRow);
897 for (Int_t iPad = 3; iPad < maxPad + 3; iPad++) {
899 // Temporary fix for data production - !!!! MARIAN
900 // The noise calibration should take mean and RMS - currently the Gaussian fit used
901 // In case of double peak - the pad should be rejected
903 // Line mean - if more than given digits over threshold - make a noise calculation
904 // and pedestal substration
905 if (!calcPedestal && allBins[iRow][iPad*fMaxTime+0]<50) continue;
907 if (allBins[iRow][iPad*fMaxTime+0] <1 ) continue; // no data
908 Float_t *p = &allBins[iRow][iPad*fMaxTime+3];
909 //Float_t pedestal = TMath::Median(fMaxTime, p);
910 Int_t id[3] = {fSector, iRow, iPad-3};
912 Double_t rmsCalib= noiseROC->GetValue(iRow,iPad-3);
913 Double_t pedestalCalib = pedestalROC->GetValue(iRow,iPad-3);
914 Double_t rmsEvent = rmsCalib;
915 Double_t pedestalEvent = pedestalCalib;
916 ProcesSignal(p, fMaxTime, id, rmsEvent, pedestalEvent);
917 if (rmsEvent<rmsCalib) rmsEvent = rmsCalib; // take worst scenario
918 if (TMath::Abs(pedestalEvent-pedestalCalib)<1.0) pedestalEvent = pedestalCalib;
921 for (Int_t iTimeBin = 0; iTimeBin < fMaxTime; iTimeBin++) {
922 Int_t bin = iPad*fMaxTime+iTimeBin;
923 allBins[iRow][bin] -= pedestalEvent;
924 if (iTimeBin < AliTPCReconstructor::GetRecoParam()->GetFirstBin())
925 allBins[iRow][bin] = 0;
926 if (iTimeBin > AliTPCReconstructor::GetRecoParam()->GetLastBin())
927 allBins[iRow][bin] = 0;
928 if (allBins[iRow][iPad*fMaxTime+iTimeBin] < zeroSup)
929 allBins[iRow][bin] = 0;
930 if (allBins[iRow][bin] < 3.0*rmsEvent) // 3 sigma cut on RMS
931 allBins[iRow][bin] = 0;
932 if (allBins[iRow][bin]) allSigBins[iRow][allNSigBins[iRow]++] = bin;
937 // Now loop over rows and find clusters
938 for (fRow = 0; fRow < nRows; fRow++) {
939 fRowCl->SetID(fParam->GetIndex(fSector, fRow));
940 if (fOutput) fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
942 fRx = fParam->GetPadRowRadii(fSector, fRow);
943 fPadLength = fParam->GetPadPitchLength(fSector, fRow);
944 fPadWidth = fParam->GetPadPitchWidth();
946 fMaxPad = fParam->GetNPadsLow(fRow);
948 fMaxPad = fParam->GetNPadsUp(fRow);
949 fMaxBin = fMaxTime*(fMaxPad+6); // add 3 virtual pads before and 3 after
951 fBins = allBins[fRow];
952 fSigBins = allSigBins[fRow];
953 fNSigBins = allNSigBins[fRow];
955 FindClusters(noiseROC);
957 fRowCl->GetArray()->Clear();
958 nclusters += fNcluster;
959 } // End of loop to find clusters
960 } // End of loop over sectors
962 for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
963 delete [] allBins[iRow];
964 delete [] allSigBins[iRow];
967 delete [] allSigBins;
968 delete [] allNSigBins;
970 if (rawReader->GetEventId() && fOutput ){
971 Info("Digits2Clusters", "File %s Event\t%d\tNumber of found clusters : %d\n", fOutput->GetName(),*(rawReader->GetEventId()), nclusters);
973 Info("Digits2Clusters", "Event\t%d\tNumber of found clusters : %d\n",*(rawReader->GetEventId()), nclusters);
979 void AliTPCclustererMI::FindClusters(AliTPCCalROC * noiseROC)
983 // add virtual charge at the edge
985 Double_t kMaxDumpSize = 500000;
987 fBDumpSignal =kFALSE;
989 if (fRecoParam->GetCalcPedestal() && fOutput->GetZipBytes()< kMaxDumpSize) fBDumpSignal =kTRUE; //dump signal flag
994 Int_t crtime = Int_t((fParam->GetZLength(fSector)-fRecoParam->GetCtgRange()*fRx)/fZWidth-fParam->GetNTBinsL1()-5);
995 Float_t minMaxCutAbs = fRecoParam->GetMinMaxCutAbs();
996 Float_t minLeftRightCutAbs = fRecoParam->GetMinLeftRightCutAbs();
997 Float_t minUpDownCutAbs = fRecoParam->GetMinUpDownCutAbs();
998 Float_t minMaxCutSigma = fRecoParam->GetMinMaxCutSigma();
999 Float_t minLeftRightCutSigma = fRecoParam->GetMinLeftRightCutSigma();
1000 Float_t minUpDownCutSigma = fRecoParam->GetMinUpDownCutSigma();
1001 for (Int_t iSig = 0; iSig < fNSigBins; iSig++) {
1002 Int_t i = fSigBins[iSig];
1003 if (i%fMaxTime<=crtime) continue;
1004 Float_t *b = &fBins[i];
1006 if (b[0]<minMaxCutAbs) continue; //threshold for maxima
1008 if (b[-1]+b[1]+b[-fMaxTime]+b[fMaxTime]<=0) continue; // cut on isolated clusters
1009 if (b[-1]+b[1]<=0) continue; // cut on isolated clusters
1010 if (b[-fMaxTime]+b[fMaxTime]<=0) continue; // cut on isolated clusters
1012 if ((b[0]+b[-1]+b[1])<minUpDownCutAbs) continue; //threshold for up down (TRF)
1013 if ((b[0]+b[-fMaxTime]+b[fMaxTime])<minLeftRightCutAbs) continue; //threshold for left right (PRF)
1014 if (!IsMaximum(*b,fMaxTime,b)) continue;
1016 Float_t noise = noiseROC->GetValue(fRow, i/fMaxTime);
1017 if (noise>fRecoParam->GetMaxNoise()) continue;
1019 if (b[0]<minMaxCutSigma*noise) continue; //threshold form maxima
1020 if ((b[0]+b[-1]+b[1])<minUpDownCutSigma*noise) continue; //threshold for up town TRF
1021 if ((b[0]+b[-fMaxTime]+b[fMaxTime])<minLeftRightCutSigma*noise) continue; //threshold for left right (PRF)
1023 AliTPCclusterMI c; // default cosntruction without info
1025 MakeCluster(i, fMaxTime, fBins, dummy,c);
1032 Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t id[3], Double_t &rmsEvent, Double_t &pedestalEvent){
1034 // process signal on given pad - + streaming of additional information in special mode
1041 // ESTIMATE pedestal and the noise
1043 const Int_t kPedMax = 100;
1049 Float_t rmsCalib = rmsEvent; // backup initial value ( from calib)
1050 Float_t pedestalCalib = pedestalEvent;// backup initial value ( from calib)
1051 Int_t firstBin = AliTPCReconstructor::GetRecoParam()->GetFirstBin();
1053 UShort_t histo[kPedMax];
1054 memset(histo,0,kPedMax*sizeof(UShort_t));
1055 for (Int_t i=0; i<fMaxTime; i++){
1056 if (signal[i]<=0) continue;
1057 if (signal[i]>max && i>firstBin) {
1061 if (signal[i]>kPedMax-1) continue;
1062 histo[int(signal[i]+0.5)]++;
1066 for (Int_t i=1; i<kPedMax; i++){
1067 if (count1<count0*0.5) median=i;
1072 Float_t count10=histo[median] ,mean=histo[median]*median, rms=histo[median]*median*median ;
1073 Float_t count06=histo[median] ,mean06=histo[median]*median, rms06=histo[median]*median*median ;
1074 Float_t count09=histo[median] ,mean09=histo[median]*median, rms09=histo[median]*median*median ;
1076 for (Int_t idelta=1; idelta<10; idelta++){
1077 if (median-idelta<=0) continue;
1078 if (median+idelta>kPedMax) continue;
1079 if (count06<0.6*count1){
1080 count06+=histo[median-idelta];
1081 mean06 +=histo[median-idelta]*(median-idelta);
1082 rms06 +=histo[median-idelta]*(median-idelta)*(median-idelta);
1083 count06+=histo[median+idelta];
1084 mean06 +=histo[median+idelta]*(median+idelta);
1085 rms06 +=histo[median+idelta]*(median+idelta)*(median+idelta);
1087 if (count09<0.9*count1){
1088 count09+=histo[median-idelta];
1089 mean09 +=histo[median-idelta]*(median-idelta);
1090 rms09 +=histo[median-idelta]*(median-idelta)*(median-idelta);
1091 count09+=histo[median+idelta];
1092 mean09 +=histo[median+idelta]*(median+idelta);
1093 rms09 +=histo[median+idelta]*(median+idelta)*(median+idelta);
1095 if (count10<0.95*count1){
1096 count10+=histo[median-idelta];
1097 mean +=histo[median-idelta]*(median-idelta);
1098 rms +=histo[median-idelta]*(median-idelta)*(median-idelta);
1099 count10+=histo[median+idelta];
1100 mean +=histo[median+idelta]*(median+idelta);
1101 rms +=histo[median+idelta]*(median+idelta)*(median+idelta);
1106 rms = TMath::Sqrt(TMath::Abs(rms/count10-mean*mean));
1110 rms06 = TMath::Sqrt(TMath::Abs(rms06/count06-mean06*mean06));
1114 rms09 = TMath::Sqrt(TMath::Abs(rms09/count09-mean09*mean09));
1118 pedestalEvent = median;
1119 if (AliLog::GetDebugLevel("","AliTPCclustererMI")==0) return median;
1121 UInt_t uid[3] = {UInt_t(id[0]),UInt_t(id[1]),UInt_t(id[2])};
1123 // Dump mean signal info
1125 (*fDebugStreamer)<<"Signal"<<
1126 "TimeStamp="<<fTimeStamp<<
1127 "EventType="<<fEventType<<
1141 "RMSCalib="<<rmsCalib<<
1142 "PedCalib="<<pedestalCalib<<
1145 // fill pedestal histogram
1150 Float_t kMin =fRecoParam->GetDumpAmplitudeMin(); // minimal signal to be dumped
1151 Float_t *dsignal = new Float_t[nchannels];
1152 Float_t *dtime = new Float_t[nchannels];
1153 for (Int_t i=0; i<nchannels; i++){
1155 dsignal[i] = signal[i];
1160 // Big signals dumping
1162 if (max-median>kMin &&maxPos>AliTPCReconstructor::GetRecoParam()->GetFirstBin())
1163 (*fDebugStreamer)<<"SignalB"<< // pads with signal
1164 "TimeStamp="<<fTimeStamp<<
1165 "EventType="<<fEventType<<
1185 if (rms06>fRecoParam->GetMaxNoise()) {
1186 pedestalEvent+=1024.;
1187 return 1024+median; // sign noisy channel in debug mode