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 **************************************************************************/
16 /* $Id: AliTPCclustererKr.cxx,v 1.7 2008/02/06 17:24:53 matyja Exp $ */
18 //-----------------------------------------------------------------
19 // Implementation of the TPC cluster class
21 // Origin: Adam Matyja, INP PAN, adam.matyja@ifj.edu.pl
22 //-----------------------------------------------------------------
24 #include "AliTPCclustererKr.h"
25 #include "AliTPCclusterKr.h"
28 #include "AliPadMax.h"
29 #include "AliSimDigits.h"
31 #include "AliTPCParam.h"
32 #include "AliTPCDigitsArray.h"
33 #include "AliTPCvtpr.h"
34 #include "AliTPCClustersRow.h"
37 //used in raw data finder
38 #include "AliTPCROC.h"
39 #include "AliTPCCalPad.h"
40 #include "AliTPCAltroMapping.h"
41 #include "AliTPCcalibDB.h"
42 #include "AliTPCRawStream.h"
43 #include "AliTPCRecoParam.h"
44 #include "AliTPCReconstructor.h"
45 #include "AliRawReader.h"
46 #include "AliTPCCalROC.h"
48 ClassImp(AliTPCclustererKr)
51 AliTPCclustererKr::AliTPCclustererKr()
60 fIsOldRCUFormat(kFALSE)
63 // default constructor
67 AliTPCclustererKr::AliTPCclustererKr(const AliTPCclustererKr ¶m)
76 fIsOldRCUFormat(kFALSE)
81 fParam = param.fParam;
82 fRecoParam=param.fRecoParam;
83 fIsOldRCUFormat=param.fIsOldRCUFormat;
84 fRawData=param.fRawData;
85 fRowCl =param.fRowCl ;
86 fInput =param.fInput ;
87 fOutput=param.fOutput;
88 fDigarr=param.fDigarr;
91 AliTPCclustererKr & AliTPCclustererKr::operator = (const AliTPCclustererKr & param)
93 fParam = param.fParam;
94 fRecoParam=param.fRecoParam;
95 fIsOldRCUFormat=param.fIsOldRCUFormat;
96 fRawData=param.fRawData;
97 fRowCl =param.fRowCl ;
98 fInput =param.fInput ;
99 fOutput=param.fOutput;
100 fDigarr=param.fDigarr;
104 AliTPCclustererKr::~AliTPCclustererKr()
111 void AliTPCclustererKr::SetRecoParam(AliTPCRecoParam *recoParam)
114 fRecoParam = recoParam;
116 //set default parameters if not specified
117 fRecoParam = AliTPCReconstructor::GetRecoParam();
118 if (!fRecoParam) fRecoParam = AliTPCRecoParam::GetLowFluxParam();
124 ////____________________________________________________________________________
126 void AliTPCclustererKr::SetInput(TTree * tree)
129 // set input tree with digits
132 if (!fInput->GetBranch("Segment")){
133 cerr<<"AliTPCclusterKr::findClusterKr(): no proper input tree !\n";
139 void AliTPCclustererKr::SetOutput(TTree * tree)
145 AliTPCClustersRow clrow;
146 AliTPCClustersRow *pclrow=&clrow;
147 clrow.SetClass("AliTPCclusterKr");
148 clrow.SetArray(1); // to make Clones array
149 fOutput->Branch("Segment","AliTPCClustersRow",&pclrow,32000,200);
152 ////____________________________________________________________________________
154 Int_t AliTPCclustererKr::finderIO()
156 // Krypton cluster finder for simulated events from MC
159 Error("Digits2Clusters", "input tree not initialised");
164 Error("Digits2Clusters", "output tree not initialised");
172 Int_t AliTPCclustererKr::finderIO(AliRawReader* rawReader)
174 // Krypton cluster finder for the TPC raw data
176 // fParam must be defined before
178 // consider noiceROC or not
180 if(rawReader)fRawData=kTRUE; //set flag to data
183 Error("Digits2Clusters", "output tree not initialised");
187 fParam->SetMaxTBin(fRecoParam->GetLastBin());//set number of timebins from reco -> param
188 // used later for memory allocation
190 Bool_t isAltro=kFALSE;
192 AliTPCROC * roc = AliTPCROC::Instance();
193 AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
194 AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
196 AliTPCRawStream input(rawReader,(AliAltroMapping**)mapping);
198 const Int_t kNIS = fParam->GetNInnerSector();//number of inner sectors
199 const Int_t kNOS = fParam->GetNOuterSector();//number of outer sectors
200 const Int_t kNS = kNIS + kNOS;//all sectors
201 Int_t zeroSup = fParam->GetZeroSup();//zero suppression parameter
204 AliTPCDigitsArray *digarr=new AliTPCDigitsArray(kFALSE);//data not sim
205 digarr->Setup(fParam);//as usually parameters
210 for(Int_t sec = 0; sec < kNS; sec++) {
211 AliTPCCalROC * noiseROC;
213 noiseROC =new AliTPCCalROC(sec);//noise=0
216 noiseROC = noiseTPC->GetCalROC(sec); // noise per given sector
218 Int_t nRows = 0; //number of rows in sector
219 Int_t nDDLs = 0; //number of DDLs
220 Int_t indexDDL = 0; //DDL index
222 nRows = fParam->GetNRowLow();
226 nRows = fParam->GetNRowUp();
228 indexDDL = (sec-kNIS) * 4 + kNIS * 2;
232 // Load the raw data for corresponding DDLs
235 input.SetOldRCUFormat(fIsOldRCUFormat);
236 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
240 // Allocate memory for rows in sector (pads(depends on row) x timebins)
241 for(Int_t row = 0; row < nRows; row++) {
242 digarr->CreateRow(sec,row);
243 }//end loop over rows
246 input.SetOldRCUFormat(fIsOldRCUFormat);
247 rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
250 // Begin loop over altro data
252 while (input.Next()) {
254 //check sector consistency
255 if (input.GetSector() != sec)
256 AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",sec,input.GetSector()));
258 //check row consistency
259 Short_t iRow = input.GetRow();
260 if (iRow < 0 || iRow >= nRows){
261 AliError(Form("Pad-row index (%d) outside the range (%d -> %d) !",
266 //check pad consistency
267 Short_t iPad = input.GetPad();
268 if (iPad < 0 || iPad >= (Short_t)(roc->GetNPads(sec,iRow))) {
269 AliError(Form("Pad index (%d) outside the range (%d -> %d) !",
270 iPad, 0, roc->GetNPads(sec,iRow) ));
274 //check time consistency
275 Short_t iTimeBin = input.GetTime();
276 if ( iTimeBin < fRecoParam->GetFirstBin() || iTimeBin >= fRecoParam->GetLastBin()){
277 //cout<<iTimeBin<<endl;
279 AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
280 iTimeBin, 0, fRecoParam->GetLastBin() -1));
284 Int_t signal = input.GetSignal();
285 Short_t timeWindowLow=60, timeWindowHigh=950;
286 if (signal <= zeroSup ||
287 iTimeBin < timeWindowLow ||
288 iTimeBin > timeWindowHigh
290 digarr->GetRow(sec,iRow)->SetDigitFast(0,iTimeBin,iPad);
293 if (!noiseROC) continue;
294 Double_t noiseOnPad = noiseROC->GetValue(iRow,iPad);//noise on given pad and row in sector
295 if (noiseOnPad>2) continue; // consider noisy pad as dead
297 if(signal<4*noiseOnPad){
298 digarr->GetRow(sec,iRow)->SetDigitFast(0,iTimeBin,iPad);
303 // cout<<" s "<<sec<<" r "<<iRow<<" p "<<iPad<<" t "<<iTimeBin<<" dig "<<signal<<endl;
304 digarr->GetRow(sec,iRow)->SetDigitFast(signal,iTimeBin,iPad);
305 // }else digarr->GetRow(sec,iRow)->SetDigitFast(0,iTimeBin,iPad);
308 }//end of loop over altro data
309 }//end of loop over sectors
312 if(isAltro) findClusterKrIO();
318 ////____________________________________________________________________________
319 Int_t AliTPCclustererKr::findClusterKrIO()
321 //fParam and fDigarr must be set to run this method
323 Int_t cluster_counter=0;
324 const Short_t NTotalSector=fParam->GetNSector();//number of sectors
325 for(Short_t sec=0; sec<NTotalSector; sec++){
327 //vector of maxima for each sector
328 std::vector<AliPadMax*> maxima_in_sector;
330 const Short_t Nrows=fParam->GetNRow(sec);//number of rows in sector
331 for(Short_t row=0; row<Nrows; row++){
332 AliSimDigits *digrow;
334 digrow = (AliSimDigits*)fDigarr->GetRow(sec,row);//real data
336 digrow = (AliSimDigits*)fDigarr->LoadRow(sec,row);//MC
338 if(digrow){//if pointer exist
339 digrow->ExpandBuffer(); //decrunch
340 const Short_t npads = digrow->GetNCols(); // number of pads
341 const Short_t ntime = digrow->GetNRows(); // number of timebins
342 for(Short_t np=0;np<npads;np++){
344 Short_t tb_max=-1;//timebin of maximum
345 Short_t value_maximum=-1;//value of maximum in adc
346 Short_t increase_begin=-1;//timebin when increase starts
347 Short_t sum_adc=0;//sum of adc on the pad in maximum surrounding
348 bool if_increase_begin=true;//flag - check if increasing started
349 bool if_maximum=false;//flag - check if it could be maximum
351 for(Short_t nt=0;nt<ntime;nt++){
352 Short_t adc = digrow->GetDigitFast(nt,np);
353 if(adc<6){//standard was 3
355 if(nt-1-increase_begin<1){//at least 2 time bins, was = 1
360 if_increase_begin=true;
364 //insert maximum, default values and set flags
365 AliPadMax *one_maximum = new AliPadMax(AliTPCvtpr(value_maximum,
372 maxima_in_sector.push_back(one_maximum);
378 if_increase_begin=true;
384 if(if_increase_begin){
385 if_increase_begin=false;
389 if(adc>value_maximum){
395 if(nt==ntime-1 && if_maximum && ntime-1-increase_begin>2){//on the edge
396 //insert maximum, default values and set flags
397 AliPadMax *one_maximum = new AliPadMax(AliTPCvtpr(value_maximum,
404 maxima_in_sector.push_back(one_maximum);
410 if_increase_begin=true;
415 }//end loop over timebins
416 }//end loop over pads
418 // cout<<"Pointer does not exist!!"<<endl;
419 }//end if poiner exists
420 }//end loop over rows
424 Short_t max_sum_adc=0;
429 for( std::vector<AliPadMax*>::iterator mp1 = maxima_in_sector.begin();
430 mp1 != maxima_in_sector.end(); ++mp1 ) {
432 AliTPCclusterKr *tmp=new AliTPCclusterKr();
434 Short_t n_used_pads=1;
435 Int_t cluster_value=0;
436 cluster_value+=(*mp1)->GetSum();
438 max_dig =(*mp1)->GetAdc() ;
439 max_sum_adc =(*mp1)->GetSum() ;
440 max_nt =(*mp1)->GetTime();
441 max_np =(*mp1)->GetPad() ;
442 max_row =(*mp1)->GetRow() ;
444 AliSimDigits *digrow_tmp;
446 digrow_tmp = (AliSimDigits*)fDigarr->GetRow(sec,(*mp1)->GetRow());
448 digrow_tmp = (AliSimDigits*)fDigarr->LoadRow(sec,(*mp1)->GetRow());
451 digrow_tmp->ExpandBuffer(); //decrunch
452 for(Short_t tb=(*mp1)->GetBegin(); tb<((*mp1)->GetEnd())+1; tb++){
453 Short_t adc_tmp = digrow_tmp->GetDigitFast(tb,(*mp1)->GetPad());
454 AliTPCvtpr *vtpr=new AliTPCvtpr(adc_tmp,tb,(*mp1)->GetPad(),(*mp1)->GetRow());
455 tmp->fCluster.push_back(vtpr);
458 maxima_in_sector.erase(mp1);
461 for( std::vector<AliPadMax*>::iterator mp2 = maxima_in_sector.begin();
462 mp2 != maxima_in_sector.end(); ++mp2 ) {
464 Short_t two_pad_max=4;
465 Short_t two_row_max=3;
467 if(abs(max_row - (*mp2)->GetRow())<two_row_max &&
468 abs(max_np - (*mp2)->GetPad())<two_pad_max &&
469 abs(max_nt - (*mp2)->GetTime())<7){//was 7
471 cluster_value+=(*mp2)->GetSum();
475 AliSimDigits *digrow_tmp1;
477 digrow_tmp1 = (AliSimDigits*)fDigarr->GetRow(sec,(*mp2)->GetRow());
479 digrow_tmp1 = (AliSimDigits*)fDigarr->LoadRow(sec,(*mp2)->GetRow());
481 digrow_tmp1->ExpandBuffer(); //decrunch
483 for(Short_t tb=(*mp2)->GetBegin(); tb<(*mp2)->GetEnd()+1; tb++){
484 Short_t adc_tmp = digrow_tmp1->GetDigitFast(tb,(*mp2)->GetPad());
485 AliTPCvtpr *vtpr=new AliTPCvtpr(adc_tmp,tb,(*mp2)->GetPad(),(*mp2)->GetRow());
486 tmp->fCluster.push_back(vtpr);
489 //which one is bigger
490 if( (*mp2)->GetAdc() > max_dig ){
491 max_dig =(*mp2)->GetAdc() ;
492 max_sum_adc =(*mp2)->GetSum() ;
493 max_nt =(*mp2)->GetTime();
494 max_np =(*mp2)->GetPad() ;
495 max_row =(*mp2)->GetRow() ;
496 } else if ( (*mp2)->GetAdc() == max_dig ){
497 if( (*mp2)->GetSum() > max_sum_adc){
498 max_dig =(*mp2)->GetAdc() ;
499 max_sum_adc =(*mp2)->GetSum() ;
500 max_nt =(*mp2)->GetTime();
501 max_np =(*mp2)->GetPad() ;
502 max_row =(*mp2)->GetRow() ;
505 maxima_in_sector.erase(mp2);
510 //through out ADC=6,7 on 1 pad, 2 tb and ADC=12 on 2 pads,2 tb
511 if(n_used_pads==1 && cluster_value/tmp->fCluster.size()<3.6)continue;
512 if(n_used_pads==2 && cluster_value/tmp->fCluster.size()<3.1)continue;
514 tmp->SetADCcluster(cluster_value);
515 tmp->SetNpads(n_used_pads);
516 tmp->SetMax(AliTPCvtpr(max_dig,max_nt,max_np,max_row));
522 //save each cluster into file
524 AliTPCClustersRow *clrow= new AliTPCClustersRow();
526 clrow->SetClass("AliTPCclusterKr");
528 fOutput->GetBranch("Segment")->SetAddress(&clrow);
531 TClonesArray * arr = fRowCl->GetArray();
532 AliTPCclusterKr * cl = new ((*arr)[tmp_cluster]) AliTPCclusterKr(*tmp);
537 //end of save each cluster into file adc.root
541 cout<<"Number of clusters in event: "<<cluster_counter<<endl;
546 ////____________________________________________________________________________