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 **************************************************************************/
21 ////////////////////////////////////////////////
22 // Manager and hits classes for set:RICH //
23 ////////////////////////////////////////////////
31 #include <TObjArray.h>
35 #include "AliRICHHitMap.h"
36 #include "AliRICHClusterFinder.h"
39 #include "AliPoints.h"
41 #include "AliCallf77.h"
42 #include "TParticle.h"
44 // Static variables for the pad-hit iterator routines
45 static Int_t sMaxIterPad=0;
46 static Int_t sCurIterPad=0;
47 static TClonesArray *fClusters2;
48 static TClonesArray *fHits2;
53 //___________________________________________
66 //___________________________________________
67 AliRICH::AliRICH(const char *name, const char *title)
68 : AliDetector(name,title)
72 <img src="gif/alirich.gif">
76 fHits = new TClonesArray("AliRICHHit",1000 );
77 gAlice->AddHitList(fHits);
78 fPadHits = new TClonesArray("AliRICHPadHit",100000);
79 fCerenkovs = new TClonesArray("AliRICHCerenkov",1000);
80 gAlice->AddHitList(fCerenkovs);
81 //gAlice->AddHitList(fHits);
88 fDchambers = new TObjArray(7);
90 fRecHits = new TObjArray(7);
95 (*fDchambers)[i] = new TClonesArray("AliRICHDigit",10000);
99 fNrawch = new Int_t[7];
101 fRawClusters = new TObjArray(7);
102 printf("Created fRwClusters with adress:%p",fRawClusters);
104 for (i=0; i<7 ;i++) {
105 (*fRawClusters)[i] = new TClonesArray("AliRICHRawCluster",10000);
109 fNrechits = new Int_t[7];
111 for (i=0; i<7 ;i++) {
112 (*fRecHits)[i] = new TClonesArray("AliRICHRecHit",1000);
114 printf("Created fRecHits with adress:%p",fRecHits);
117 SetMarkerColor(kRed);
120 //___________________________________________
129 //___________________________________________
130 void AliRICH::AddHit(Int_t track, Int_t *vol, Float_t *hits)
132 TClonesArray &lhits = *fHits;
133 new(lhits[fNhits++]) AliRICHHit(fIshunt,track,vol,hits);
135 //_____________________________________________________________________________
136 void AliRICH::AddCerenkov(Int_t track, Int_t *vol, Float_t *cerenkovs)
138 TClonesArray &lcerenkovs = *fCerenkovs;
139 new(lcerenkovs[fNcerenkovs++]) AliRICHCerenkov(fIshunt,track,vol,cerenkovs);
140 //printf ("Done for Cerenkov %d\n\n\n\n",fNcerenkovs);
142 //___________________________________________
143 void AliRICH::AddPadHit(Int_t *clhits)
145 TClonesArray &lPadHits = *fPadHits;
146 new(lPadHits[fNPadHits++]) AliRICHPadHit(clhits);
148 //_____________________________________________________________________________
149 void AliRICH::AddDigits(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
152 // Add a RICH digit to the list
155 TClonesArray &ldigits = *((TClonesArray*)(*fDchambers)[id]);
156 new(ldigits[fNdch[id]++]) AliRICHDigit(tracks,charges,digits);
159 //_____________________________________________________________________________
160 void AliRICH::AddRawCluster(Int_t id, const AliRICHRawCluster& c)
163 // Add a RICH digit to the list
166 TClonesArray &lrawcl = *((TClonesArray*)(*fRawClusters)[id]);
167 new(lrawcl[fNrawch[id]++]) AliRICHRawCluster(c);
170 //_____________________________________________________________________________
171 void AliRICH::AddRecHit(Int_t id, Float_t *rechit)
174 // Add a RICH reconstructed hit to the list
177 TClonesArray &lrec = *((TClonesArray*)(*fRecHits)[id]);
178 new(lrec[fNrechits[id]++]) AliRICHRecHit(id,rechit);
181 //___________________________________________
182 void AliRICH::BuildGeometry()
186 // Builds a TNode geometry for event display
190 const int kColorRICH = kGreen;
192 Top=gAlice->GetGeometry()->GetNode("alice");
195 new TBRIK("S_RICH","S_RICH","void",71.09999,11.5,73.15);
198 Float_t pos1[3]={0,471.8999,165.2599};
199 //Chamber(0).SetChamberTransform(pos1[0],pos1[1],pos1[2],
200 new TRotMatrix("rot993","rot993",90,0,70.69,90,19.30999,-90);
201 Node = new TNode("RICH1","RICH1","S_RICH",pos1[0],pos1[1],pos1[2],"rot993");
204 Node->SetLineColor(kColorRICH);
208 Float_t pos2[3]={171,470,0};
209 //Chamber(1).SetChamberTransform(pos2[0],pos2[1],pos2[2],
210 new TRotMatrix("rot994","rot994",90,-20,90,70,0,0);
211 Node = new TNode("RICH2","RICH2","S_RICH",pos2[0],pos2[1],pos2[2],"rot994");
214 Node->SetLineColor(kColorRICH);
217 Float_t pos3[3]={0,500,0};
218 //Chamber(2).SetChamberTransform(pos3[0],pos3[1],pos3[2],
219 new TRotMatrix("rot995","rot995",90,0,90,90,0,0);
220 Node = new TNode("RICH3","RICH3","S_RICH",pos3[0],pos3[1],pos3[2],"rot995");
223 Node->SetLineColor(kColorRICH);
226 Float_t pos4[3]={-171,470,0};
227 //Chamber(3).SetChamberTransform(pos4[0],pos4[1],pos4[2],
228 new TRotMatrix("rot996","rot996",90,20,90,110,0,0);
229 Node = new TNode("RICH4","RICH4","S_RICH",pos4[0],pos4[1],pos4[2],"rot996");
232 Node->SetLineColor(kColorRICH);
235 Float_t pos5[3]={161.3999,443.3999,-165.3};
236 //Chamber(4).SetChamberTransform(pos5[0],pos5[1],pos5[2],
237 new TRotMatrix("rot997","rot997",90,340,108.1999,70,18.2,70);
238 Node = new TNode("RICH5","RICH5","S_RICH",pos5[0],pos5[1],pos5[2],"rot997");
240 Node->SetLineColor(kColorRICH);
243 Float_t pos6[3]={0., 471.9, -165.3,};
244 //Chamber(5).SetChamberTransform(pos6[0],pos6[1],pos6[2],
245 new TRotMatrix("rot998","rot998",90,0,109.3099,90,19.30999,90);
246 Node = new TNode("RICH6","RICH6","S_RICH",pos6[0],pos6[1],pos6[2],"rot998");
249 Node->SetLineColor(kColorRICH);
252 Float_t pos7[3]={-161.399,443.3999,-165.3};
253 //Chamber(6).SetChamberTransform(pos7[0],pos7[1],pos7[2],
254 new TRotMatrix("rot999","rot999",90,20,108.1999,110,18.2,110);
255 Node = new TNode("RICH7","RICH7","S_RICH",pos7[0],pos7[1],pos7[2],"rot999");
256 Node->SetLineColor(kColorRICH);
261 //___________________________________________
262 Int_t AliRICH::DistancetoPrimitive(Int_t , Int_t )
267 //___________________________________________
268 void AliRICH::MakeBranch(Option_t* option)
270 // Create Tree branches for the RICH.
272 const Int_t buffersize = 4000;
276 AliDetector::MakeBranch(option);
277 sprintf(branchname,"%sCerenkov",GetName());
278 if (fCerenkovs && gAlice->TreeH()) {
279 gAlice->TreeH()->Branch(branchname,&fCerenkovs, buffersize);
280 printf("Making Branch %s for Cerenkov Hits\n",branchname);
283 sprintf(branchname,"%sPadHits",GetName());
284 if (fPadHits && gAlice->TreeH()) {
285 gAlice->TreeH()->Branch(branchname,&fPadHits, buffersize);
286 printf("Making Branch %s for PadHits\n",branchname);
289 // one branch for digits per chamber
292 for (i=0; i<7 ;i++) {
293 sprintf(branchname,"%sDigits%d",GetName(),i+1);
295 if (fDchambers && gAlice->TreeD()) {
296 gAlice->TreeD()->Branch(branchname,&((*fDchambers)[i]), buffersize);
297 printf("Making Branch %s for digits in chamber %d\n",branchname,i+1);
301 // one branch for raw clusters per chamber
302 for (i=0; i<7 ;i++) {
303 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
305 if (fRawClusters && gAlice->TreeR()) {
306 gAlice->TreeR()->Branch(branchname,&((*fRawClusters)[i]), buffersize);
307 printf("Making Branch %s for raw clusters in chamber %d\n",branchname,i+1);
311 // one branch for rec hits per chamber
312 for (i=0; i<7 ;i++) {
313 sprintf(branchname,"%sRecHits%d",GetName(),i+1);
315 if (fRecHits && gAlice->TreeR()) {
316 gAlice->TreeR()->Branch(branchname,&((*fRecHits)[i]), buffersize);
317 printf("Making Branch %s for rec. hits in chamber %d\n",branchname,i+1);
322 //___________________________________________
323 void AliRICH::SetTreeAddress()
325 // Set branch address for the Hits and Digits Tree.
329 AliDetector::SetTreeAddress();
332 TTree *treeH = gAlice->TreeH();
333 TTree *treeD = gAlice->TreeD();
334 TTree *treeR = gAlice->TreeR();
338 branch = treeH->GetBranch("RICHPadHits");
339 if (branch) branch->SetAddress(&fPadHits);
342 branch = treeH->GetBranch("RICHCerenkov");
343 if (branch) branch->SetAddress(&fCerenkovs);
348 for (int i=0; i<7; i++) {
349 sprintf(branchname,"%sDigits%d",GetName(),i+1);
351 branch = treeD->GetBranch(branchname);
352 if (branch) branch->SetAddress(&((*fDchambers)[i]));
357 for (i=0; i<7; i++) {
358 sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
360 branch = treeR->GetBranch(branchname);
361 if (branch) branch->SetAddress(&((*fRawClusters)[i]));
365 for (i=0; i<7; i++) {
366 sprintf(branchname,"%sRecHits%d",GetName(),i+1);
368 branch = treeR->GetBranch(branchname);
369 if (branch) branch->SetAddress(&((*fRecHits)[i]));
375 //___________________________________________
376 void AliRICH::ResetHits()
378 // Reset number of clusters and the cluster array for this detector
379 AliDetector::ResetHits();
382 if (fPadHits) fPadHits->Clear();
383 if (fCerenkovs) fCerenkovs->Clear();
387 //____________________________________________
388 void AliRICH::ResetDigits()
391 // Reset number of digits and the digits array for this detector
393 for ( int i=0;i<7;i++ ) {
394 if ((*fDchambers)[i]) (*fDchambers)[i]->Clear();
395 if (fNdch) fNdch[i]=0;
399 //____________________________________________
400 void AliRICH::ResetRawClusters()
403 // Reset number of raw clusters and the raw clust array for this detector
405 for ( int i=0;i<7;i++ ) {
406 if ((*fRawClusters)[i]) ((TClonesArray*)(*fRawClusters)[i])->Clear();
407 if (fNrawch) fNrawch[i]=0;
411 //____________________________________________
412 void AliRICH::ResetRecHits()
415 // Reset number of raw clusters and the raw clust array for this detector
418 for ( int i=0;i<7;i++ ) {
419 if ((*fRecHits)[i]) ((TClonesArray*)(*fRecHits)[i])->Clear();
420 if (fNrechits) fNrechits[i]=0;
424 //___________________________________________
425 void AliRICH::SetGeometryModel(Int_t id, AliRICHGeometry *geometry)
427 ((AliRICHChamber*) (*fChambers)[id])->GeometryModel(geometry);
430 //___________________________________________
431 void AliRICH::SetSegmentationModel(Int_t id, AliRICHSegmentation *segmentation)
433 ((AliRICHChamber*) (*fChambers)[id])->SegmentationModel(segmentation);
436 //___________________________________________
437 void AliRICH::SetResponseModel(Int_t id, AliRICHResponse *response)
439 ((AliRICHChamber*) (*fChambers)[id])->ResponseModel(response);
442 void AliRICH::SetReconstructionModel(Int_t id, AliRICHClusterFinder *reconst)
444 ((AliRICHChamber*) (*fChambers)[id])->ReconstructionModel(reconst);
447 void AliRICH::SetNsec(Int_t id, Int_t nsec)
449 ((AliRICHChamber*) (*fChambers)[id])->SetNsec(nsec);
453 //___________________________________________
455 void AliRICH::StepManager()
459 void AliRICH::FindClusters(Int_t nev,Int_t last_entry)
463 // Loop on chambers and on cathode planes
465 for (Int_t icat=1;icat<2;icat++) {
466 gAlice->ResetDigits();
467 gAlice->TreeD()->GetEvent(1); // spurious +1 ...
468 for (Int_t ich=0;ich<7;ich++) {
469 AliRICHChamber* iChamber=(AliRICHChamber*) (*fChambers)[ich];
470 TClonesArray *RICHdigits = this->DigitsAddress(ich);
474 // Get ready the current chamber stuff
476 AliRICHResponse* response = iChamber->GetResponseModel();
477 AliRICHSegmentation* seg = iChamber->GetSegmentationModel();
478 AliRICHClusterFinder* rec = iChamber->GetReconstructionModel();
480 rec->SetSegmentation(seg);
481 rec->SetResponse(response);
482 rec->SetDigits(RICHdigits);
483 rec->SetChamber(ich);
484 if (nev==0) rec->CalibrateCOG();
485 rec->FindRawClusters();
488 fRch=RawClustAddress(ich);
492 gAlice->TreeR()->Fill();
494 for (int i=0;i<7;i++) {
495 fRch=RawClustAddress(i);
496 int nraw=fRch->GetEntriesFast();
497 printf ("Chamber %d, raw clusters %d\n",i,nraw);
505 sprintf(hname,"TreeR%d",nev);
506 gAlice->TreeR()->Write(hname);
507 gAlice->TreeR()->Reset();
509 //gObjectTable->Print();
513 //______________________________________________________________________________
514 void AliRICH::Streamer(TBuffer &R__b)
516 // Stream an object of class AliRICH.
517 AliRICHChamber *iChamber;
518 AliRICHSegmentation *segmentation;
519 AliRICHResponse *response;
520 TClonesArray *digitsaddress;
521 TClonesArray *rawcladdress;
522 TClonesArray *rechitaddress;
524 if (R__b.IsReading()) {
525 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
526 AliDetector::Streamer(R__b);
528 R__b >> fPadHits; // diff
530 R__b >> fCerenkovs; // diff
532 R__b >> fRawClusters;
533 R__b >> fRecHits; //diff
534 R__b.ReadArray(fNdch);
535 R__b.ReadArray(fNrawch);
536 R__b.ReadArray(fNrechits);
539 // Stream chamber related information
540 for (Int_t i =0; i<7; i++) {
541 iChamber=(AliRICHChamber*) (*fChambers)[i];
542 iChamber->Streamer(R__b);
543 segmentation=iChamber->GetSegmentationModel();
544 segmentation->Streamer(R__b);
545 response=iChamber->GetResponseModel();
546 response->Streamer(R__b);
547 rawcladdress=(TClonesArray*) (*fRawClusters)[i];
548 rawcladdress->Streamer(R__b);
549 rechitaddress=(TClonesArray*) (*fRecHits)[i];
550 rechitaddress->Streamer(R__b);
551 digitsaddress=(TClonesArray*) (*fDchambers)[i];
552 digitsaddress->Streamer(R__b);
556 R__b.WriteVersion(AliRICH::IsA());
557 AliDetector::Streamer(R__b);
559 R__b << fPadHits; // diff
561 R__b << fCerenkovs; // diff
563 R__b << fRawClusters;
564 R__b << fRecHits; //diff
565 R__b.WriteArray(fNdch, 7);
566 R__b.WriteArray(fNrawch, 7);
567 R__b.WriteArray(fNrechits, 7);
570 // Stream chamber related information
571 for (Int_t i =0; i<7; i++) {
572 iChamber=(AliRICHChamber*) (*fChambers)[i];
573 iChamber->Streamer(R__b);
574 segmentation=iChamber->GetSegmentationModel();
575 segmentation->Streamer(R__b);
576 response=iChamber->GetResponseModel();
577 response->Streamer(R__b);
578 rawcladdress=(TClonesArray*) (*fRawClusters)[i];
579 rawcladdress->Streamer(R__b);
580 rechitaddress=(TClonesArray*) (*fRecHits)[i];
581 rechitaddress->Streamer(R__b);
582 digitsaddress=(TClonesArray*) (*fDchambers)[i];
583 digitsaddress->Streamer(R__b);
587 AliRICHPadHit* AliRICH::FirstPad(AliRICHHit* hit,TClonesArray *clusters )
590 // Initialise the pad iterator
591 // Return the address of the first padhit for hit
592 TClonesArray *theClusters = clusters;
593 Int_t nclust = theClusters->GetEntriesFast();
594 if (nclust && hit->fPHlast > 0) {
595 sMaxIterPad=Int_t(hit->fPHlast);
596 sCurIterPad=Int_t(hit->fPHfirst);
597 return (AliRICHPadHit*) clusters->UncheckedAt(sCurIterPad-1);
604 AliRICHPadHit* AliRICH::NextPad(TClonesArray *clusters)
607 if (sCurIterPad <= sMaxIterPad) {
608 return (AliRICHPadHit*) clusters->UncheckedAt(sCurIterPad-1);
615 void AliRICH::Digitise(Int_t nev,Option_t *option,Text_t *filename)
617 // keep galice.root for signal and name differently the file for
618 // background when add! otherwise the track info for signal will be lost !
620 static Bool_t first=kTRUE;
622 char *Add = strstr(option,"Add");
624 FILE* points; //these will be the digits...
626 points=fopen("points.dat","w");
628 AliRICHChamber* iChamber;
629 AliRICHSegmentation* segmentation;
634 TObjArray *list=new TObjArray;
635 static TClonesArray *p_adr=0;
636 if(!p_adr) p_adr=new TClonesArray("TVector",1000);
639 AliRICH *RICH = (AliRICH *) gAlice->GetDetector("RICH");
640 AliRICHHitMap* HitMap[10];
642 for (i=0; i<10; i++) {HitMap[i]=0;}
646 cout<<"filename"<<fFileName<<endl;
647 File=new TFile(fFileName);
648 cout<<"I have opened "<<fFileName<<" file "<<endl;
649 fHits2 = new TClonesArray("AliRICHHit",1000 );
650 fClusters2 = new TClonesArray("AliRICHPadHit",10000);
654 // Get Hits Tree header from file
655 if(fHits2) fHits2->Clear();
656 if(fClusters2) fClusters2->Clear();
657 if(TrH1) delete TrH1;
661 sprintf(treeName,"TreeH%d",nev);
662 TrH1 = (TTree*)gDirectory->Get(treeName);
664 printf("ERROR: cannot find Hits Tree for event:%d\n",nev);
666 // Set branch addresses
669 sprintf(branchname,"%s",GetName());
670 if (TrH1 && fHits2) {
671 branch = TrH1->GetBranch(branchname);
672 if (branch) branch->SetAddress(&fHits2);
674 if (TrH1 && fClusters2) {
675 branch = TrH1->GetBranch("RICHCluster");
676 if (branch) branch->SetAddress(&fClusters2);
680 // loop over cathodes
684 for (int icat=0; icat<1; icat++) {
686 for (i =0; i<7; i++) {
687 iChamber=(AliRICHChamber*) (*fChambers)[i];
688 if (iChamber->Nsec()==1 && icat==1) {
691 segmentation=iChamber->GetSegmentationModel(icat+1);
693 HitMap[i] = new AliRICHHitMapA1(segmentation, list);
699 TTree *TH = gAlice->TreeH();
700 Int_t ntracks =(Int_t) TH->GetEntries();
701 for (Int_t track=0; track<ntracks; track++) {
706 for(AliRICHHit* mHit=(AliRICHHit*)RICH->FirstHit(-1);
708 mHit=(AliRICHHit*)RICH->NextHit())
710 Int_t nch = mHit->fChamber-1; // chamber number
711 if (nch >7) continue;
712 iChamber = &(RICH->Chamber(nch));
716 // Loop over pad hits
717 for (AliRICHPadHit* mPad=
718 (AliRICHPadHit*)RICH->FirstPad(mHit,fPadHits);
720 mPad=(AliRICHPadHit*)RICH->NextPad(fPadHits))
722 Int_t cathode = mPad->fCathode; // cathode number
723 Int_t ipx = mPad->fPadX; // pad number on X
724 Int_t ipy = mPad->fPadY; // pad number on Y
725 Int_t iqpad = mPad->fQpad; // charge per pad
728 //printf("X:%d, Y:%d, Q:%d\n",ipx,ipy,iqpad);
731 segmentation=iChamber->GetSegmentationModel(cathode);
732 segmentation->GetPadCxy(ipx,ipy,thex,they);
733 new((*p_adr)[countadr++]) TVector(2);
734 TVector &trinfo=*((TVector*) (*p_adr)[countadr-1]);
735 trinfo(0)=(Float_t)track;
736 trinfo(1)=(Float_t)iqpad;
742 AliRICHTransientDigit* pdigit;
743 // build the list of fired pads and update the info
744 if (!HitMap[nch]->TestHit(ipx, ipy)) {
745 list->AddAtAndExpand(
746 new AliRICHTransientDigit(nch,digits),counter);
747 HitMap[nch]->SetHit(ipx, ipy, counter);
749 pdigit=(AliRICHTransientDigit*)list->At(list->GetLast());
751 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
752 trlist->Add(&trinfo);
754 pdigit=(AliRICHTransientDigit*) HitMap[nch]->GetHit(ipx, ipy);
756 (*pdigit).fSignal+=iqpad;
757 // update list of tracks
758 TObjArray* trlist=(TObjArray*)pdigit->TrackList();
759 Int_t last_entry=trlist->GetLast();
760 TVector *ptrk_p=(TVector*)trlist->At(last_entry);
761 TVector &ptrk=*ptrk_p;
762 Int_t last_track=Int_t(ptrk(0));
763 Int_t last_charge=Int_t(ptrk(1));
764 if (last_track==track) {
766 trlist->RemoveAt(last_entry);
767 trinfo(0)=last_track;
768 trinfo(1)=last_charge;
769 trlist->AddAt(&trinfo,last_entry);
771 trlist->Add(&trinfo);
773 // check the track list
774 Int_t nptracks=trlist->GetEntriesFast();
776 printf("Attention - tracks: %d (>2)\n",nptracks);
777 //printf("cat,nch,ix,iy %d %d %d %d \n",icat+1,nch,ipx,ipy);
778 for (Int_t tr=0;tr<nptracks;tr++) {
779 TVector *pptrk_p=(TVector*)trlist->At(tr);
780 TVector &pptrk=*pptrk_p;
781 trk[tr]=Int_t(pptrk(0));
782 chtrk[tr]=Int_t(pptrk(1));
786 } //end loop over clusters
790 // open the file with background
793 ntracks =(Int_t)TrH1->GetEntries();
794 //printf("background - icat,ntracks1 %d %d\n",icat,ntracks);
795 //printf("background - Start loop over tracks \n");
799 for (Int_t trak=0; trak<ntracks; trak++) {
800 if (fHits2) fHits2->Clear();
801 if (fClusters2) fClusters2->Clear();
802 TrH1->GetEvent(trak);
806 for(int j=0;j<fHits2->GetEntriesFast();++j)
808 mHit=(AliRICHHit*) (*fHits2)[j];
809 Int_t nch = mHit->fChamber-1; // chamber number
810 if (nch >6) continue;
811 iChamber = &(RICH->Chamber(nch));
812 Int_t rmin = (Int_t)iChamber->RInner();
813 Int_t rmax = (Int_t)iChamber->ROuter();
815 // Loop over pad hits
816 for (AliRICHPadHit* mPad=
817 (AliRICHPadHit*)RICH->FirstPad(mHit,fClusters2);
819 mPad=(AliRICHPadHit*)RICH->NextPad(fClusters2))
821 Int_t cathode = mPad->fCathode; // cathode number
822 Int_t ipx = mPad->fPadX; // pad number on X
823 Int_t ipy = mPad->fPadY; // pad number on Y
824 Int_t iqpad = mPad->fQpad; // charge per pad
825 if (trak==3 && nch==0 && icat==0) printf("bgr - trak,iqpad,ipx,ipy %d %d %d %d\n",trak,iqpad,ipx,ipy);
829 segmentation=iChamber->GetSegmentationModel(cathode);
830 segmentation->GetPadCxy(ipx,ipy,thex,they);
831 Float_t rpad=TMath::Sqrt(thex*thex+they*they);
832 if (rpad < rmin || iqpad ==0 || rpad > rmax) continue;
833 new((*p_adr)[countadr++]) TVector(2);
834 TVector &trinfo=*((TVector*) (*p_adr)[countadr-1]);
835 trinfo(0)=-1; // tag background
840 if (trak <4 && icat==0 && nch==0)
841 printf("bgr - HitMap[nch]->TestHit(ipx, ipy),trak %d %d\n",
842 HitMap[nch]->TestHit(ipx, ipy),trak);
843 AliRICHTransientDigit* pdigit;
844 // build the list of fired pads and update the info
845 if (!HitMap[nch]->TestHit(ipx, ipy)) {
846 list->AddAtAndExpand(new AliRICHTransientDigit(nch,digits),counter);
848 HitMap[nch]->SetHit(ipx, ipy, counter);
850 printf("bgr new elem in list - counter %d\n",counter);
852 pdigit=(AliRICHTransientDigit*)list->At(list->GetLast());
854 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
855 trlist->Add(&trinfo);
857 pdigit=(AliRICHTransientDigit*) HitMap[nch]->GetHit(ipx, ipy);
859 (*pdigit).fSignal+=iqpad;
860 // update list of tracks
861 TObjArray* trlist=(TObjArray*)pdigit->TrackList();
862 Int_t last_entry=trlist->GetLast();
863 TVector *ptrk_p=(TVector*)trlist->At(last_entry);
864 TVector &ptrk=*ptrk_p;
865 Int_t last_track=Int_t(ptrk(0));
866 if (last_track==-1) {
869 trlist->Add(&trinfo);
871 // check the track list
872 Int_t nptracks=trlist->GetEntriesFast();
874 for (Int_t tr=0;tr<nptracks;tr++) {
875 TVector *pptrk_p=(TVector*)trlist->At(tr);
876 TVector &pptrk=*pptrk_p;
877 trk[tr]=Int_t(pptrk(0));
878 chtrk[tr]=Int_t(pptrk(1));
882 } //end loop over clusters
885 TTree *fAli=gAlice->TreeK();
886 if (fAli) File =fAli->GetCurrentFile();
892 //cout<<"Start filling digits \n "<<endl;
893 Int_t nentries=list->GetEntriesFast();
894 //printf(" \n \n nentries %d \n",nentries);
896 // start filling the digits
898 for (Int_t nent=0;nent<nentries;nent++) {
899 AliRICHTransientDigit *address=(AliRICHTransientDigit*)list->At(nent);
900 if (address==0) continue;
901 Int_t ich=address->fChamber;
902 Int_t q=address->fSignal;
903 iChamber=(AliRICHChamber*) (*fChambers)[ich];
904 AliRICHResponse * response=iChamber->GetResponseModel();
905 Int_t adcmax= (Int_t) response->MaxAdc();
906 // add white noise and do zero-suppression and signal truncation (new electronics,old electronics gaus 1.2,0.2)
907 Float_t MeanNoise = gRandom->Gaus(1.7, 0.25);
908 Float_t Noise = gRandom->Gaus(0, MeanNoise);
910 // magic number to be parametrised !!!
911 if ( q <= 6.8) continue;
912 if ( q >= adcmax) q=adcmax;
913 digits[0]=address->fPadX;
914 digits[1]=address->fPadY;
917 TObjArray* trlist=(TObjArray*)address->TrackList();
918 Int_t nptracks=trlist->GetEntriesFast();
920 // this was changed to accomodate the real number of tracks
922 cout<<"Attention - tracks > 10 "<<nptracks<<endl;
926 printf("Attention - tracks > 2 %d \n",nptracks);
927 //printf("cat,ich,ix,iy,q %d %d %d %d %d \n",
928 //icat,ich,digits[0],digits[1],q);
930 for (Int_t tr=0;tr<nptracks;tr++) {
931 TVector *pp_p=(TVector*)trlist->At(tr);
933 tracks[tr]=Int_t(pp(0));
934 charges[tr]=Int_t(pp(1));
935 } //end loop over list of tracks for one pad
936 if (nptracks < 10 ) {
937 for (Int_t t=nptracks; t<10; t++) {
944 fprintf(points,"%4d, %4d, %4d\n",digits[0],digits[1],digits[2]);
947 RICH->AddDigits(ich,tracks,charges,digits);
949 gAlice->TreeD()->Fill();
952 for(Int_t ii=0;ii<7;++ii) {
960 //TTree *TD=gAlice->TreeD();
961 //Stat_t ndig=TD->GetEntries();
962 //cout<<"number of digits "<<ndig<<endl;
964 for (int k=0;k<7;k++) {
965 fDch= RICH->DigitsAddress(k);
966 int ndigit=fDch->GetEntriesFast();
967 printf ("Chamber %d digits %d \n",k,ndigit);
970 } //end loop over cathodes
972 sprintf(hname,"TreeD%d",nev);
973 gAlice->TreeD()->Write(hname);
976 // gAlice->TreeD()->Reset();
979 // gObjectTable->Print();