- fTDList = new TObjArray;
-
- AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH");
- pRICH->MakeBranchInTreeD(fManager->GetTreeD());
- fHitMap= new AliHitMap* [kNCH];
-
- for (Int_t i =0; i<kNCH; i++) {
- iChamber= &(pRICH->Chamber(i));
- segmentation=iChamber->GetSegmentationModel(1);
- fHitMap[i] = new AliRICHHitMapA1(segmentation, fTDList);
- }
-
-// Loop over files to digitize
- fSignal = kTRUE;
- fCounter = 0;
- for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
- inputFile++) {
-
-// Connect RICH branches
-
- if (inputFile > 0 ) fSignal = kFALSE;
- TBranch *branchHits = 0;
- TBranch *branchSDigits = 0;
- TTree *treeH = fManager->GetInputTreeH(inputFile);
- if (GetDebug()>2) {
- cerr<<" inputFile "<<inputFile<<endl;
- cerr<<" treeH, fHits "<<treeH<<" "<<fHits<<endl;
- }
- if (treeH && fHits) {
- branchHits = treeH->GetBranch("RICH");
- if (branchHits) {
- fHits->Clear();
- branchHits->SetAddress(&fHits);
- }
- else
- Error("Exec","branch RICH was not found");
- }
- if (GetDebug()>2) cerr<<" branchHits = "<<branchHits<<endl;
-
- if (treeH && fSDigits) {
- branchSDigits = treeH->GetBranch("RICHSDigits");
- if (branchSDigits)
- branchSDigits->SetAddress(&fSDigits);
- else
- Error("exec","branch RICHSDigits was not found");
- }
- if (GetDebug()>2) cerr<<" branchSDigits = "<<branchSDigits<<endl;
-
-
- //
- // Loop over tracks
- //
-
- Int_t ntracks =(Int_t) treeH->GetEntries();
- for (fTrack=0; fTrack<ntracks; fTrack++) {
- fHits->Clear();
- fSDigits->Clear();
- branchHits->GetEntry(fTrack);
- branchSDigits->GetEntry(fTrack);
-
-
- //
- // Loop over hits
- for(Int_t i = 0; i < fHits->GetEntriesFast(); ++i) {
- AliRICHHit* mHit = static_cast<AliRICHHit*>(fHits->At(i));
- fNch = mHit->Chamber()-1; // chamber number
- if (fNch >= kNCH) {
- cerr<<"AliRICHDigitizer: chamber nr. fNch out of range: "<<fNch<<endl;
- cerr<<" track: "<<fTrack<<endl;
- continue;
- }
- iChamber = &(pRICH->Chamber(fNch));
-
- //
- // Loop over pad hits
- for (AliRICHSDigit* mPad=
- (AliRICHSDigit*)pRICH->FirstPad(mHit,fSDigits);
- mPad;
- mPad=(AliRICHSDigit*)pRICH->NextPad(fSDigits))
- {
- Int_t iqpad = mPad->QPad(); // charge per pad
- fDigits[0]=mPad->PadX();
- fDigits[1]=mPad->PadY();
- fDigits[2]=iqpad;
- fDigits[3]=iqpad;
- fDigits[4]=mPad->HitNumber();
-
- // build the list of fired pads and update the info
- if (Exists(mPad)) {
- Update(mPad);
- } else {
- CreateNew(mPad);
- }
- } //end loop over clusters
- } // hit loop
- } // track loop
- } // end file loop
- if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl;
-
- Int_t tracks[kMAXTRACKSPERRICHDIGIT];
- Int_t charges[kMAXTRACKSPERRICHDIGIT];
- Int_t nentries=fTDList->GetEntriesFast();
-
- for (Int_t nent=0;nent<nentries;nent++) {
- AliRICHTransientDigit *transDigit=(AliRICHTransientDigit*)fTDList->At(nent);
- if (transDigit==0) continue;
- Int_t ich=transDigit->GetChamber();
- Int_t q=transDigit->Signal();
- iChamber=&(pRICH->Chamber(ich));
- AliRICHResponse * response=iChamber->GetResponseModel();
- Int_t adcmax= (Int_t) response->MaxAdc();
-
-
- // add white noise and do zero-suppression and signal truncation (new electronics,old electronics gaus 1.2,0.2)
- //printf("Treshold: %d\n",iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY()));
-
-// tmp change
-// Int_t pedestal = iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY());
- Int_t pedestal = 0;
-
-
- //printf("Pedestal:%d\n",pedestal);
- //Int_t pedestal=0;
- Float_t treshold = (pedestal + 4*2.2);
-
- Float_t meanNoise = gRandom->Gaus(2.2, 0.3);
- Float_t noise = gRandom->Gaus(0, meanNoise);
- q+=(Int_t)(noise + pedestal);
- //q+=(Int_t)(noise);
- // magic number to be parametrised !!!
- if ( q <= treshold)
- {
- q = q - pedestal;
- continue;
- }
- q = q - pedestal;
- if ( q >= adcmax) q=adcmax;
- fDigits[0]=transDigit->PadX();
- fDigits[1]=transDigit->PadY();
- fDigits[2]=q;
- fDigits[3]=transDigit->Physics();
- fDigits[4]=transDigit->Hit();
-
- Int_t nptracks = transDigit->GetNTracks();
-
- // this was changed to accomodate the real number of tracks
- if (nptracks > kMAXTRACKSPERRICHDIGIT) {
- printf("Attention - tracks > 10 %d\n",nptracks);
- nptracks=kMAXTRACKSPERRICHDIGIT;
- }
- if (nptracks > 2) {
- printf("Attention - tracks > 2 %d \n",nptracks);
- }
- for (Int_t tr=0;tr<nptracks;tr++) {
- tracks[tr]=transDigit->GetTrack(tr);
- charges[tr]=transDigit->GetCharge(tr);
- } //end loop over list of tracks for one pad
- if (nptracks < kMAXTRACKSPERRICHDIGIT ) {
- for (Int_t t=nptracks; t<kMAXTRACKSPERRICHDIGIT; t++) {
- tracks[t]=0;
- charges[t]=0;
+ tmpCA.Sort(); //at this point we have a list of all sdigits from all inputs, now sort them according to fPad field
+
+ AliRunLoader *pOutRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); //open output stream (only 1 possible)
+ AliLoader *pOutRichLoader = pOutRunLoader->GetLoader("RICHLoader"); //take output RICH loader
+ AliRICH *pOutRich = (AliRICH*)pOutRunLoader->GetAliRun()->GetDetector("RICH"); //take output RICH
+ pOutRichLoader->MakeTree("D"); pOutRich->MakeBranch("D"); //create TreeD in output stream
+
+ TVector pad(2); pad[0]=0; pad[1]=0; Int_t iChamber=0,iCfm=0,aTids[3]={0,0,0},iId=-1; Double_t dQdc=0;//current pad info
+ Int_t iNdigsPerPad=0; //how many sdigits for a given pad
+ for(Int_t i=0;i<tmpCA.GetEntries();i++){//sdigits loop (sorted)
+ AliRICHDigit *pSdig=(AliRICHDigit*)tmpCA.At(i);//get new sdigit
+ if(pSdig->PadAbs()==iId){//still the same pad
+ iNdigsPerPad++; dQdc+=pSdig->Qdc(); iCfm+=pSdig->Cfm();//sum up charge and cfm
+ if(pSdig->Cfm()==1) aTids[0] = pSdig->GetTrack(0); // force the first tid to be mip's tid if it exists in the current pad
+ if(iNdigsPerPad<=3) aTids[iNdigsPerPad-1]=pSdig->GetTrack(0);
+ else AliDebug(1,Form("More then 3 sdigits in (%d,%d,%f,%f) with Q= %f",pSdig->Chamber(),-1,pSdig->Pad()(0),pSdig->Pad()(1),pSdig->Qdc()));
+ }else{//new pad, add the pevious one
+ if(iId!=-1 && AliRICHParam::IsOverTh(iChamber,pad,dQdc)) pOutRich->DigAdd(iChamber,pad,(Int_t)dQdc,iCfm,aTids); //add newly created dig
+ iChamber=pSdig->Chamber(); pad=pSdig->Pad(); iCfm=pSdig->Cfm(); dQdc=pSdig->Qdc(); iId=pSdig->PadAbs(); //init all values by current sdig
+ iNdigsPerPad=1; aTids[0]=pSdig->GetTrack(0); aTids[1]=aTids[2]=-1;