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 Revision 1.13 1999/10/26 06:04:49 fca
19 Introduce TLorentzVector in AliMC::GetSecondary. Thanks to I.Hrivnacova
21 Revision 1.12 1999/09/29 09:24:29 fca
22 Introduction of the Copyright and cvs Log
26 ////////////////////////////////////////////////
27 // Manager and hits classes for set:RICH //
28 ////////////////////////////////////////////////
36 #include <TObjArray.h>
39 #include "AliRICHHitMap.h"
43 #include "AliCallf77.h"
45 // Static variables for the pad-hit iterator routines
46 static Int_t sMaxIterPad=0;
47 static Int_t sCurIterPad=0;
48 static TClonesArray *fClusters2;
49 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 fClusters = new TClonesArray("AliRICHcluster",10000);
78 fCerenkovs = new TClonesArray("AliRICHCerenkov",20000);
84 fDchambers = new TObjArray(7);
89 (*fDchambers)[i] = new TClonesArray("AliRICHdigit",10000);
93 fRecClusters=new TObjArray(7);
95 (*fRecClusters)[i] = new TObjArray(1000);
98 // Transport angular cut
103 SetMarkerColor(kRed);
106 //___________________________________________
113 for (Int_t i=0;i<7;i++)
114 delete (*fRecClusters)[i];
119 //___________________________________________
120 void AliRICH::AddHit(Int_t track, Int_t *vol, Float_t *hits)
122 TClonesArray &lhits = *fHits;
123 new(lhits[fNhits++]) AliRICHhit(fIshunt,track,vol,hits);
125 //_____________________________________________________________________________
126 void AliRICH::AddCerenkov(Int_t track, Int_t *vol, Float_t *cerenkovs)
128 TClonesArray &lcerenkovs = *fCerenkovs;
129 new(lcerenkovs[fNcerenkovs++]) AliRICHCerenkov(fIshunt,track,vol,cerenkovs);
131 //___________________________________________
132 void AliRICH::AddCluster(Int_t *clhits)
134 TClonesArray &lclusters = *fClusters;
135 new(lclusters[fNclusters++]) AliRICHcluster(clhits);
137 //_____________________________________________________________________________
138 void AliRICH::AddDigits(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
141 // Add a RICH digit to the list
144 TClonesArray &ldigits = *((TClonesArray*)(*fDchambers)[id]);
145 new(ldigits[fNdch[id]++]) AliRICHdigit(tracks,charges,digits);
149 //_____________________________________________________________________________
150 void AliRICH::AddRecCluster(Int_t iCh, Int_t iCat, AliRICHRecCluster* Cluster)
153 // Add a RICH reconstructed cluster to the list
155 TObjArray* ClusterList = RecClusters(iCh,iCat);
156 ClusterList->Add(Cluster);
161 //___________________________________________
162 void AliRICH::BuildGeometry()
166 // Builds a TNode geometry for event display
170 const int kColorRICH = kGreen;
172 Top=gAlice->GetGeometry()->GetNode("alice");
175 new TBRIK("S_RICH","S_RICH","void",71.09999,11.5,73.15);
178 Float_t pos1[3]={0,471.8999,165.2599};
179 Chamber(0).SetChamberTransform(pos1[0],pos1[1],pos1[2],new TRotMatrix("rot993","rot993",90,0,70.69,90,19.30999,-90));
180 Node = new TNode("RICH1","RICH1","S_RICH",pos1[0],pos1[1],pos1[2],"rot993");
183 Node->SetLineColor(kColorRICH);
187 Float_t pos2[3]={171,470,0};
188 Chamber(1).SetChamberTransform(pos2[0],pos2[1],pos2[2],new TRotMatrix("rot994","rot994",90,-20,90,70,0,0));
189 Node = new TNode("RICH2","RICH2","S_RICH",pos2[0],pos2[1],pos2[2],"rot994");
192 Node->SetLineColor(kColorRICH);
195 Float_t pos3[3]={0,500,0};
196 Chamber(2).SetChamberTransform(pos3[0],pos3[1],pos3[2],new TRotMatrix("rot995","rot995",90,0,90,90,0,0));
197 Node = new TNode("RICH3","RICH3","S_RICH",pos3[0],pos3[1],pos3[2],"rot995");
200 Node->SetLineColor(kColorRICH);
203 Float_t pos4[3]={-171,470,0};
204 Chamber(3).SetChamberTransform(pos4[0],pos4[1],pos4[2], new TRotMatrix("rot996","rot996",90,20,90,110,0,0));
205 Node = new TNode("RICH4","RICH4","S_RICH",pos4[0],pos4[1],pos4[2],"rot996");
208 Node->SetLineColor(kColorRICH);
211 Float_t pos5[3]={161.3999,443.3999,-165.3};
212 Chamber(4).SetChamberTransform(pos5[0],pos5[1],pos5[2],new TRotMatrix("rot997","rot997",90,340,108.1999,70,18.2,70));
213 Node = new TNode("RICH5","RICH5","S_RICH",pos5[0],pos5[1],pos5[2],"rot997");
215 Node->SetLineColor(kColorRICH);
218 Float_t pos6[3]={0., 471.9, -165.3,};
219 Chamber(5).SetChamberTransform(pos6[0],pos6[1],pos6[2],new TRotMatrix("rot998","rot998",90,0,109.3099,90,19.30999,90));
220 Node = new TNode("RICH6","RICH6","S_RICH",pos6[0],pos6[1],pos6[2],"rot998");
223 Node->SetLineColor(kColorRICH);
226 Float_t pos7[3]={-161.399,443.3999,-165.3};
227 Chamber(6).SetChamberTransform(pos7[0],pos7[1],pos7[2],new TRotMatrix("rot999","rot999",90,20,108.1999,110,18.2,110));
228 Node = new TNode("RICH7","RICH7","S_RICH",pos7[0],pos7[1],pos7[2],"rot999");
229 Node->SetLineColor(kColorRICH);
234 //___________________________________________
235 Int_t AliRICH::DistancetoPrimitive(Int_t , Int_t )
240 //___________________________________________
241 void AliRICH::MakeBranch(Option_t* option)
243 // Create Tree branches for the RICH.
245 const Int_t buffersize = 4000;
249 AliDetector::MakeBranch(option);
250 sprintf(branchname,"%sCerenkov",GetName());
251 if (fCerenkovs && gAlice->TreeH()) {
252 gAlice->TreeH()->Branch(branchname,&fCerenkovs, buffersize);
253 printf("Making Branch %s for Cerenkov Hits\n",branchname);
256 sprintf(branchname,"%sCluster",GetName());
257 if (fClusters && gAlice->TreeH()) {
258 gAlice->TreeH()->Branch(branchname,&fClusters, buffersize);
259 printf("Making Branch %s for clusters\n",branchname);
262 // one branch for digits per chamber
265 for (i=0; i<7 ;i++) {
266 sprintf(branchname,"%sDigits%d",GetName(),i+1);
268 if (fDchambers && gAlice->TreeD()) {
269 gAlice->TreeD()->Branch(branchname,&((*fDchambers)[i]), buffersize);
270 printf("Making Branch %s for digits in chamber %d\n",branchname,i+1);
273 // one branch for rec clusters
274 for (i=0; i<7; i++) {
275 sprintf(branchname,"%sRecClus%d",GetName(),i+1);
276 if (fRecClusters && gAlice->TreeD()) {
278 ->Branch(branchname,"TObjArray",
279 &((*fRecClusters)[i]), buffersize,0);
280 printf("Making Branch %s for clusters in chamber %d\n",
286 //___________________________________________
287 void AliRICH::SetTreeAddress()
289 // Set branch address for the Hits and Digits Tree.
291 AliDetector::SetTreeAddress();
294 TTree *treeH = gAlice->TreeH();
295 TTree *treeD = gAlice->TreeD();
299 branch = treeH->GetBranch("RICHCluster");
300 if (branch) branch->SetAddress(&fClusters);
303 branch = treeH->GetBranch("RICHCerenkov");
304 if (branch) branch->SetAddress(&fCerenkovs);
310 for (int i=0; i<7; i++) {
311 sprintf(branchname,"%sDigits%d",GetName(),i+1);
313 branch = treeD->GetBranch(branchname);
314 if (branch) branch->SetAddress(&((*fDchambers)[i]));
319 //___________________________________________
320 void AliRICH::ResetHits()
322 // Reset number of clusters and the cluster array for this detector
323 AliDetector::ResetHits();
325 if (fClusters) fClusters->Clear();
326 if (fCerenkovs) fCerenkovs->Clear();
329 //____________________________________________
330 void AliRICH::ResetDigits()
333 // Reset number of digits and the digits array for this detector
335 for ( int i=0;i<7;i++ ) {
336 if ((*fDchambers)[i]) (*fDchambers)[i]->Clear();
337 if (fNdch) fNdch[i]=0;
340 //____________________________________________
341 void AliRICH::ResetRecClusters()
344 // Reset the rec clusters
346 for ( int i=0;i<7;i++ ) {
347 if ((*fRecClusters)[i]) (*fRecClusters)[i]->Clear();
350 //___________________________________________
352 void AliRICH::SetPADSIZ(Int_t id, Int_t isec, Float_t p1, Float_t p2)
355 ((AliRICHchamber*) (*fChambers)[i]) ->SetPADSIZ(isec,p1,p2);
356 ((AliRICHchamber*) (*fChambers)[i+1])->SetPADSIZ(isec,p1,p2);
359 //___________________________________________
360 void AliRICH::SetMUCHSP(Int_t id, Float_t p1)
363 ((AliRICHchamber*) (*fChambers)[i])->SetMUCHSP(p1);
364 ((AliRICHchamber*) (*fChambers)[i+1])->SetMUCHSP(p1);
367 //___________________________________________
368 void AliRICH::SetMUSIGM(Int_t id, Float_t p1, Float_t p2)
371 ((AliRICHchamber*) (*fChambers)[i])->SetMUSIGM(p1,p2);
372 ((AliRICHchamber*) (*fChambers)[i+1])->SetMUSIGM(p1,p2);
375 //___________________________________________
376 void AliRICH::SetRSIGM(Int_t id, Float_t p1)
379 ((AliRICHchamber*) (*fChambers)[i])->SetRSIGM(p1);
380 ((AliRICHchamber*) (*fChambers)[i+1])->SetRSIGM(p1);
383 //___________________________________________
384 void AliRICH::SetMAXADC(Int_t id, Float_t p1)
387 ((AliRICHchamber*) (*fChambers)[i])->SetMAXADC(p1);
388 ((AliRICHchamber*) (*fChambers)[i+1])->SetMAXADC(p1);
391 //___________________________________________
392 void AliRICH::SetSMAXAR(Float_t p1)
397 //___________________________________________
398 void AliRICH::SetSMAXAL(Float_t p1)
403 //___________________________________________
404 void AliRICH::SetDMAXAR(Float_t p1)
409 //___________________________________________
410 void AliRICH::SetDMAXAL(Float_t p1)
414 //___________________________________________
415 void AliRICH::SetRICHACC(Bool_t acc, Float_t angmin, Float_t angmax)
421 //___________________________________________
422 void AliRICH::SetSegmentationModel(Int_t id, Int_t isec, AliRICHsegmentation *segmentation)
424 ((AliRICHchamber*) (*fChambers)[id])->SegmentationModel(isec, segmentation);
427 //___________________________________________
428 void AliRICH::SetResponseModel(Int_t id, Response_t res, AliRICHresponse *response)
430 ((AliRICHchamber*) (*fChambers)[id])->ResponseModel(res, response);
433 void AliRICH::SetNsec(Int_t id, Int_t nsec)
435 ((AliRICHchamber*) (*fChambers)[id])->SetNsec(nsec);
439 //___________________________________________
441 void AliRICH::StepManager()
443 printf("Dummy version of RICH step -- it should never happen!!\n");
444 const Float_t kRaddeg = 180/TMath::Pi();
447 Float_t pt, th0, th1;
450 if((nsec=gMC->NSecondaries())>0) {
451 proc=gMC->ProdProcess();
452 if((gMC->TrackPid()==113 || gMC->TrackPid()==114) && !strcmp(proc,"DCAY")) {
454 // Check angular acceptance
455 //* --- and have muons from resonance decays in the wanted window ---
457 printf(" AliRICH::StepManager: Strange resonance Decay into %d particles\n",nsec);
460 gMC->GetSecondary(0,ipart,x,p);
461 pt = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
462 th0 = TMath::ATan2(pt,p[2])*kRaddeg;
463 gMC->GetSecondary(1,ipart,x,p);
464 pt = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
465 th1 = TMath::ATan2(pt,p[2])*kRaddeg;
466 if(!(fAccMin < th0 && th0 < fAccMax) ||
467 !(fAccMin < th1 && th1 < fAccMax))
474 void AliRICH::ReconstructClusters()
477 // Initialize the necessary correspondance table
479 static const Int_t kMaxNPadx = 600;
480 static const Int_t kMaxNPady = 600;
481 Int_t elem[kMaxNPadx*2][kMaxNPady*2];
483 // Loop on chambers and on cathode planes
485 for (Int_t ich=0;ich<7;ich++)
486 for (Int_t icat=0;icat<1;icat++) {
488 // Get ready the current chamber stuff
491 printf ("Olarilole");
492 AliRICHchamber* iChamber= &(this->Chamber(ich));
493 AliRICHsegmentation* segmentation =
494 iChamber->GetSegmentationModel(icat+1);
497 TClonesArray *RICHdigits = this->DigitsAddress(ich);
500 cout << "Npx " << segmentation->Npx()
501 << " Npy " << segmentation->Npy() << endl;
505 gAlice->ResetDigits();
506 gAlice->TreeD()->GetEvent(icat+1); // spurious +1 ...
507 Int_t ndigits = RICHdigits->GetEntriesFast();
510 printf("Found %d digits for cathode %d in chamber %d \n",
513 AliRICHRecCluster *Cluster;
515 // Build the correspondance table
517 memset(elem,0,sizeof(Int_t)*kMaxNPadx*kMaxNPady*4);
519 for (digit=0; digit<ndigits; digit++)
521 mdig = (AliRICHdigit*)RICHdigits->UncheckedAt(digit);
522 elem[kMaxNPadx+mdig->fPadX][kMaxNPady+mdig->fPadY] = digit+1;
523 // because default is 0
526 // Declare some useful variables
535 for (digit=0;digit<ndigits;digit++) {
536 mdig = (AliRICHdigit*)RICHdigits->UncheckedAt(digit);
538 // if digit still available, start clustering
540 if (elem[kMaxNPadx+mdig->fPadX][kMaxNPady+mdig->fPadY]) {
541 Cluster = new AliRICHRecCluster(digit, ich, icat);
542 elem[kMaxNPadx+mdig->fPadX][kMaxNPady+mdig->fPadY]=0;
544 // loop over the current list of digits
545 // and look for neighbours
547 for(Int_t clusDigit=Cluster->FirstDigitIndex();
548 clusDigit!=Cluster->InvalidDigitIndex();
549 clusDigit=Cluster->NextDigitIndex()) {
550 AliRICHdigit* pDigit=(AliRICHdigit*)RICHdigits
551 ->UncheckedAt(clusDigit);
552 segmentation->Neighbours(pDigit->fPadX,pDigit->fPadY,
553 &Nlist, Xlist, Ylist);
554 for (Int_t Ilist=0;Ilist<Nlist;Ilist++) {
555 if (elem[kMaxNPadx+Xlist[Ilist]][kMaxNPady
558 // Add the digit at the end and reset the table
560 Cluster->AddDigit(elem[kMaxNPadx+Xlist[Ilist]][kMaxNPady+Ylist[Ilist]]-1);
561 elem[kMaxNPadx+Xlist[Ilist]][kMaxNPady
567 // Store the cluster (good time to do Cluster polishing)
569 segmentation->FitXY(Cluster,RICHdigits);
571 AddRecCluster(ich,icat,Cluster);
574 printf("===> %d Clusters\n",nclust);
579 //______________________________________________________________________________
580 void AliRICH::Streamer(TBuffer &R__b)
582 // Stream an object of class AliRICH.
583 AliRICHchamber *iChamber;
584 AliRICHsegmentation *segmentation;
585 AliRICHresponse *response;
586 TClonesArray *digitsaddress;
588 if (R__b.IsReading()) {
589 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
590 AliDetector::Streamer(R__b);
592 R__b >> fClusters; // diff
594 R__b.ReadArray(fNdch);
601 // Stream chamber related information
602 for (Int_t i =0; i<7; i++) {
603 iChamber=(AliRICHchamber*) (*fChambers)[i];
604 iChamber->Streamer(R__b);
605 if (iChamber->Nsec()==1) {
606 segmentation=iChamber->GetSegmentationModel(1);
607 segmentation->Streamer(R__b);
609 segmentation=iChamber->GetSegmentationModel(1);
610 segmentation->Streamer(R__b);
611 segmentation=iChamber->GetSegmentationModel(2);
612 segmentation->Streamer(R__b);
614 response=iChamber->GetResponseModel(mip);
615 response->Streamer(R__b);
616 response=iChamber->GetResponseModel(cerenkov);
617 response->Streamer(R__b);
619 digitsaddress=(TClonesArray*) (*fDchambers)[i];
620 digitsaddress->Streamer(R__b);
624 R__b.WriteVersion(AliRICH::IsA());
625 AliDetector::Streamer(R__b);
627 R__b << fClusters; // diff
629 R__b.WriteArray(fNdch, 7);
636 // Stream chamber related information
637 for (Int_t i =0; i<7; i++) {
638 iChamber=(AliRICHchamber*) (*fChambers)[i];
639 iChamber->Streamer(R__b);
640 if (iChamber->Nsec()==1) {
641 segmentation=iChamber->GetSegmentationModel(1);
642 segmentation->Streamer(R__b);
644 segmentation=iChamber->GetSegmentationModel(1);
645 segmentation->Streamer(R__b);
646 segmentation=iChamber->GetSegmentationModel(2);
647 segmentation->Streamer(R__b);
649 response=iChamber->GetResponseModel(mip);
650 response->Streamer(R__b);
651 response=iChamber->GetResponseModel(cerenkov);
652 response->Streamer(R__b);
654 digitsaddress=(TClonesArray*) (*fDchambers)[i];
655 digitsaddress->Streamer(R__b);
659 AliRICHcluster* AliRICH::FirstPad(AliRICHhit* hit,TClonesArray *clusters )
662 // Initialise the pad iterator
663 // Return the address of the first padhit for hit
664 TClonesArray *theClusters = clusters;
665 Int_t nclust = theClusters->GetEntriesFast();
666 if (nclust && hit->fPHlast > 0) {
667 sMaxIterPad=hit->fPHlast;
668 sCurIterPad=hit->fPHfirst;
669 return (AliRICHcluster*) clusters->UncheckedAt(sCurIterPad-1);
676 AliRICHcluster* AliRICH::NextPad(TClonesArray *clusters)
679 if (sCurIterPad <= sMaxIterPad) {
680 return (AliRICHcluster*) clusters->UncheckedAt(sCurIterPad-1);
686 ClassImp(AliRICHcluster)
688 //___________________________________________
689 AliRICHcluster::AliRICHcluster(Int_t *clhits)
691 fHitNumber=clhits[0];
699 ClassImp(AliRICHdigit)
700 //_____________________________________________________________________________
701 AliRICHdigit::AliRICHdigit(Int_t *digits)
704 // Creates a RICH digit object to be updated
711 //_____________________________________________________________________________
712 AliRICHdigit::AliRICHdigit(Int_t *tracks, Int_t *charges, Int_t *digits)
715 // Creates a RICH digit object
720 for(Int_t i=0; i<10; i++) {
721 fTcharges[i] = charges[i];
722 fTracks[i] = tracks[i];
726 ClassImp(AliRICHlist)
728 //____________________________________________________________________________
729 AliRICHlist::AliRICHlist(Int_t ich, Int_t *digits):
733 // Creates a RICH digit list object
737 fTrackList = new TObjArray;
740 //_____________________________________________________________________________
745 //___________________________________________
746 AliRICHhit::AliRICHhit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
758 fPHfirst=(Int_t) hits[8];
759 fPHlast=(Int_t) hits[9];
761 ClassImp(AliRICHreccluster)
763 ClassImp(AliRICHCerenkov)
764 //___________________________________________
765 AliRICHCerenkov::AliRICHCerenkov(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
775 fPHfirst=(Int_t) hits[8];
776 fPHlast=(Int_t) hits[9];
779 ClassImp(AliRICHRecCluster)
781 //_____________________________________________________________________
782 AliRICHRecCluster::AliRICHRecCluster()
788 AliRICHRecCluster::AliRICHRecCluster(Int_t FirstDigit,Int_t Ichamber, Int_t Icathod)
792 fDigits = new TArrayI(10);
794 AddDigit(FirstDigit);
799 void AliRICHRecCluster::AddDigit(Int_t Digit)
801 if (fNdigit==fDigits->GetSize()) {
802 //enlarge the list by hand!
803 Int_t *array= new Int_t[fNdigit*2];
804 for(Int_t i=0;i<fNdigit;i++)
805 array[i] = fDigits->At(i);
806 fDigits->Adopt(fNdigit*2,array);
808 fDigits->AddAt(Digit,fNdigit);
813 AliRICHRecCluster::~AliRICHRecCluster()
819 Int_t AliRICHRecCluster::FirstDigitIndex()
822 return fDigits->At(fCurrentDigit);
825 Int_t AliRICHRecCluster::NextDigitIndex()
828 if (fCurrentDigit<fNdigit)
829 return fDigits->At(fCurrentDigit);
831 return InvalidDigitIndex();
834 Int_t AliRICHRecCluster::NDigits()
839 void AliRICHRecCluster::Finish()
841 // In order to reconstruct coordinates, one has to
842 // get back to the digits which is not trivial here,
843 // because we don't know where digits are stored!
844 // Center Of Gravity, or other method should be
845 // a property of AliRICH class!
850 void AliRICH::Digitise(Int_t nev,Option_t *option,Text_t *filename)
852 // keep galice.root for signal and name differently the file for
853 // background when add! otherwise the track info for signal will be lost !
855 static Bool_t first=kTRUE;
859 char *Add = strstr(option,"Add");
861 AliRICHchamber* iChamber;
862 AliRICHsegmentation* segmentation;
867 TObjArray *list=new TObjArray;
870 AliRICH *RICH = (AliRICH *) gAlice->GetDetector("RICH");
871 AliRICHHitMap* HitMap[10];
872 for (i=0; i<10; i++) {HitMap[i]=0;}
876 cout<<"filename"<<fFileName<<endl;
877 File=new TFile(fFileName);
878 cout<<"I have opened "<<fFileName<<" file "<<endl;
879 fHits2 = new TClonesArray("AliRICHhit",1000 );
880 fClusters2 = new TClonesArray("AliRICHcluster",10000);
885 // Get Hits Tree header from file
886 if(fHits2) fHits2->Clear();
887 if(fClusters2) fClusters2->Clear();
892 sprintf(treeName,"TreeH%d",nev);
893 TH1 = (TTree*)gDirectory->Get(treeName);
895 printf("ERROR: cannot find Hits Tree for event:%d\n",nev);
897 // Set branch addresses
900 sprintf(branchname,"%s",GetName());
902 branch = TH1->GetBranch(branchname);
903 if (branch) branch->SetAddress(&fHits2);
905 if (TH1 && fClusters2) {
906 branch = TH1->GetBranch("RICHCluster");
907 if (branch) branch->SetAddress(&fClusters2);
911 // loop over cathodes
915 for (int icat=0; icat<1; icat++) {
916 for (i=0; i<7; i++) {
924 for (i =0; i<7; i++) {
925 iChamber=(AliRICHchamber*) (*fChambers)[i];
926 if (iChamber->Nsec()==1 && icat==1) {
929 segmentation=iChamber->GetSegmentationModel(icat+1);
931 HitMap[i] = new AliRICHHitMapA1(segmentation, list);
933 printf("Start loop over tracks \n");
938 TTree *TH = gAlice->TreeH();
939 Int_t ntracks =(Int_t) TH->GetEntries();
940 for (Int_t track=0; track<ntracks; track++) {
945 for(AliRICHhit* mHit=(AliRICHhit*)RICH->FirstHit(-1);
947 mHit=(AliRICHhit*)RICH->NextHit())
949 Int_t nch = mHit->fChamber-1; // chamber number
950 if (nch >7) continue;
951 iChamber = &(RICH->Chamber(nch));
954 // Loop over pad hits
955 for (AliRICHcluster* mPad=
956 (AliRICHcluster*)RICH->FirstPad(mHit,fClusters);
958 mPad=(AliRICHcluster*)RICH->NextPad(fClusters))
960 Int_t cathode = mPad->fCathode; // cathode number
961 Int_t ipx = mPad->fPadX; // pad number on X
962 Int_t ipy = mPad->fPadY; // pad number on Y
963 Int_t iqpad = mPad->fQpad; // charge per pad
967 if (cathode != (icat+1)) continue;
968 // fill the info array
970 segmentation=iChamber->GetSegmentationModel(cathode);
971 segmentation->GetPadCxy(ipx,ipy,thex,they);
972 TVector *trinfo_p= new TVector(2);
973 TVector &trinfo = *trinfo_p;
974 trinfo(0)=(Float_t)track;
975 trinfo(1)=(Float_t)iqpad;
982 // build the list of fired pads and update the info
983 if (!HitMap[nch]->TestHit(ipx, ipy)) {
984 list->AddAtAndExpand(
985 new AliRICHlist(nch,digits),counter);
986 HitMap[nch]->SetHit(ipx, ipy, counter);
988 pdigit=(AliRICHlist*)list->At(list->GetLast());
990 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
991 trlist->Add(&trinfo);
993 pdigit=(AliRICHlist*) HitMap[nch]->GetHit(ipx, ipy);
995 (*pdigit).fSignal+=iqpad;
996 // update list of tracks
997 TObjArray* trlist=(TObjArray*)pdigit->TrackList();
998 Int_t last_entry=trlist->GetLast();
999 TVector *ptrk_p=(TVector*)trlist->At(last_entry);
1000 TVector &ptrk=*ptrk_p;
1001 Int_t last_track=Int_t(ptrk(0));
1002 Int_t last_charge=Int_t(ptrk(1));
1003 if (last_track==track) {
1005 trlist->RemoveAt(last_entry);
1006 trinfo(0)=last_track;
1007 trinfo(1)=last_charge;
1008 trlist->AddAt(&trinfo,last_entry);
1010 trlist->Add(&trinfo);
1012 // check the track list
1013 Int_t nptracks=trlist->GetEntriesFast();
1015 printf("Attention - nptracks > 2 %d \n",nptracks);
1016 printf("cat,nch,ix,iy %d %d %d %d \n",icat+1,nch,ipx,ipy);
1017 for (Int_t tr=0;tr<nptracks;tr++) {
1018 TVector *pptrk_p=(TVector*)trlist->At(tr);
1019 TVector &pptrk=*pptrk_p;
1020 trk[tr]=Int_t(pptrk(0));
1021 chtrk[tr]=Int_t(pptrk(1));
1023 } // end if nptracks
1025 } //end loop over clusters
1029 Int_t nentr1=list->GetEntriesFast();
1030 printf(" \n counter, nentr1 %d %d\n",counter,nentr1);
1032 // open the file with background
1035 ntracks =(Int_t)TH1->GetEntries();
1036 printf("background - icat,ntracks1 %d %d\n",icat,ntracks);
1037 printf("background - Start loop over tracks \n");
1041 for (Int_t trak=0; trak<ntracks; trak++) {
1043 if (fHits2) fHits2->Clear();
1044 if (fClusters2) fClusters2->Clear();
1046 TH1->GetEvent(trak);
1050 for(int j=0;j<fHits2->GetEntriesFast();++j)
1052 mHit=(AliRICHhit*) (*fHits2)[j];
1053 Int_t nch = mHit->fChamber-1; // chamber number
1054 if (nch >9) continue;
1055 iChamber = &(RICH->Chamber(nch));
1056 Int_t rmin = (Int_t)iChamber->RInner();
1057 Int_t rmax = (Int_t)iChamber->ROuter();
1059 // Loop over pad hits
1060 for (AliRICHcluster* mPad=
1061 (AliRICHcluster*)RICH->FirstPad(mHit,fClusters2);
1063 mPad=(AliRICHcluster*)RICH->NextPad(fClusters2))
1065 Int_t cathode = mPad->fCathode; // cathode number
1066 Int_t ipx = mPad->fPadX; // pad number on X
1067 Int_t ipy = mPad->fPadY; // pad number on Y
1068 Int_t iqpad = mPad->fQpad; // charge per pad
1069 if (trak==3 && nch==0 && icat==0) printf("bgr - trak,iqpad,ipx,ipy %d %d %d %d\n",trak,iqpad,ipx,ipy);
1072 if (cathode != (icat+1)) continue;
1073 // fill the info array
1075 segmentation=iChamber->GetSegmentationModel(cathode);
1076 segmentation->GetPadCxy(ipx,ipy,thex,they);
1077 Float_t rpad=TMath::Sqrt(thex*thex+they*they);
1078 if (rpad < rmin || iqpad ==0 || rpad > rmax) continue;
1081 trinfo_p = new TVector(2);
1082 TVector &trinfo = *trinfo_p;
1083 trinfo(0)=-1; // tag background
1091 if (trak <4 && icat==0 && nch==0)
1092 printf("bgr - HitMap[nch]->TestHit(ipx, ipy),trak %d %d\n",
1093 HitMap[nch]->TestHit(ipx, ipy),trak);
1094 AliRICHlist* pdigit;
1095 // build the list of fired pads and update the info
1096 if (!HitMap[nch]->TestHit(ipx, ipy)) {
1097 list->AddAtAndExpand(new AliRICHlist(nch,digits),counter);
1099 HitMap[nch]->SetHit(ipx, ipy, counter);
1101 printf("bgr new elem in list - counter %d\n",counter);
1103 pdigit=(AliRICHlist*)list->At(list->GetLast());
1105 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
1106 trlist->Add(&trinfo);
1108 pdigit=(AliRICHlist*) HitMap[nch]->GetHit(ipx, ipy);
1110 (*pdigit).fSignal+=iqpad;
1111 // update list of tracks
1112 TObjArray* trlist=(TObjArray*)pdigit->TrackList();
1113 Int_t last_entry=trlist->GetLast();
1114 TVector *ptrk_p=(TVector*)trlist->At(last_entry);
1115 TVector &ptrk=*ptrk_p;
1116 Int_t last_track=Int_t(ptrk(0));
1117 if (last_track==-1) {
1120 trlist->Add(&trinfo);
1122 // check the track list
1123 Int_t nptracks=trlist->GetEntriesFast();
1125 for (Int_t tr=0;tr<nptracks;tr++) {
1126 TVector *pptrk_p=(TVector*)trlist->At(tr);
1127 TVector &pptrk=*pptrk_p;
1128 trk[tr]=Int_t(pptrk(0));
1129 chtrk[tr]=Int_t(pptrk(1));
1131 } // end if nptracks
1133 } //end loop over clusters
1136 Int_t nentr2=list->GetEntriesFast();
1137 printf(" \n counter2, nentr2 %d %d \n",counter,nentr2);
1138 TTree *fAli=gAlice->TreeK();
1139 if (fAli) File =fAli->GetCurrentFile();
1145 cout<<"start filling digits \n "<<endl;
1146 Int_t nentries=list->GetEntriesFast();
1147 printf(" \n \n nentries %d \n",nentries);
1149 // start filling the digits
1151 for (Int_t nent=0;nent<nentries;nent++) {
1152 AliRICHlist *address=(AliRICHlist*)list->At(nent);
1153 if (address==0) continue;
1154 Int_t ich=address->fChamber;
1155 Int_t q=address->fSignal;
1156 iChamber=(AliRICHchamber*) (*fChambers)[ich];
1157 // add white noise and do zero-suppression and signal truncation
1158 Float_t MeanNoise = gRandom->Gaus(1, 0.2);
1159 Float_t ZeroSupp=5*MeanNoise;
1160 Float_t Noise = gRandom->Gaus(0, MeanNoise);
1162 if ( q <= ZeroSupp) continue;
1163 digits[0]=address->fPadX;
1164 digits[1]=address->fPadY;
1167 TObjArray* trlist=(TObjArray*)address->TrackList();
1168 Int_t nptracks=trlist->GetEntriesFast();
1170 // this was changed to accomodate the real number of tracks
1171 if (nptracks > 10) {
1172 cout<<"Attention - nptracks > 10 "<<nptracks<<endl;
1176 printf("Attention - nptracks > 2 %d \n",nptracks);
1177 printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,digits[0],digits[1],q);
1179 for (Int_t tr=0;tr<nptracks;tr++) {
1180 TVector *pp_p=(TVector*)trlist->At(tr);
1182 tracks[tr]=Int_t(pp(0));
1183 charges[tr]=Int_t(pp(1));
1184 } //end loop over list of tracks for one pad
1185 if (nptracks < 10 ) {
1186 for (Int_t t=nptracks; t<10; t++) {
1192 RICH->AddDigits(ich,tracks,charges,digits);
1196 cout<<"I'm out of the loops for digitisation"<<endl;
1197 gAlice->TreeD()->Fill();
1198 TTree *TD=gAlice->TreeD();
1199 Stat_t ndig=TD->GetEntries();
1200 cout<<"number of digits "<<ndig<<endl;
1202 for (int k=0;k<7;k++) {
1203 fDch= RICH->DigitsAddress(k);
1204 int ndigit=fDch->GetEntriesFast();
1205 printf (" k, ndigits %d %d \n",k,ndigit);
1207 RICH->ResetDigits();
1211 } //end loop over cathodes
1213 sprintf(hname,"TreeD%d",nev);
1214 gAlice->TreeD()->Write(hname);