Introduce variable Config.C function signature
[u/mrichter/AliRoot.git] / RICH / AliRICH.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17$Log$
1cedd08a 18Revision 1.14 1999/11/03 13:17:07 fca
19Have ProdProcess return const char*
20
6a935c13 21Revision 1.13 1999/10/26 06:04:49 fca
22Introduce TLorentzVector in AliMC::GetSecondary. Thanks to I.Hrivnacova
23
5d84196c 24Revision 1.12 1999/09/29 09:24:29 fca
25Introduction of the Copyright and cvs Log
26
4c039060 27*/
28
ddae0931 29////////////////////////////////////////////////
30// Manager and hits classes for set:RICH //
31////////////////////////////////////////////////
fe4da5cc 32
ddae0931 33#include <TBRIK.h>
34#include <TTUBE.h>
fe4da5cc 35#include <TNode.h>
36#include <TRandom.h>
ddae0931 37#include <TObject.h>
38#include <TVector.h>
39#include <TObjArray.h>
fe4da5cc 40
fe4da5cc 41#include "AliRICH.h"
ddae0931 42#include "AliRICHHitMap.h"
fe4da5cc 43#include "AliRun.h"
ddae0931 44#include "AliMC.h"
45#include "iostream.h"
46#include "AliCallf77.h"
47
48// Static variables for the pad-hit iterator routines
49static Int_t sMaxIterPad=0;
50static Int_t sCurIterPad=0;
51static TClonesArray *fClusters2;
52static TClonesArray *fHits2;
53
fe4da5cc 54ClassImp(AliRICH)
ddae0931 55
56//___________________________________________
fe4da5cc 57AliRICH::AliRICH()
58{
ddae0931 59 fIshunt = 0;
60 fHits = 0;
61 fClusters = 0;
62 fNclusters = 0;
63 fDchambers = 0;
64 fRecClusters= 0;
65 fCerenkovs = 0;
66 fNdch = 0;
fe4da5cc 67}
ddae0931 68
69//___________________________________________
fe4da5cc 70AliRICH::AliRICH(const char *name, const char *title)
ddae0931 71 : AliDetector(name,title)
fe4da5cc 72{
ddae0931 73//Begin_Html
74/*
75 <img src="gif/alirich.gif">
76*/
77//End_Html
78
79 fHits = new TClonesArray("AliRICHhit",1000 );
1cedd08a 80 gAlice->AddHitList(fHits);
ddae0931 81 fClusters = new TClonesArray("AliRICHcluster",10000);
82 fCerenkovs = new TClonesArray("AliRICHCerenkov",20000);
83 fNclusters = 0;
84 fIshunt = 0;
85
86 fNdch = new Int_t[7];
87
88 fDchambers = new TObjArray(7);
89
90 Int_t i;
91
92 for (i=0; i<7 ;i++) {
93 (*fDchambers)[i] = new TClonesArray("AliRICHdigit",10000);
94 fNdch[i]=0;
95 }
96
97 fRecClusters=new TObjArray(7);
98 for (i=0; i<7;i++)
99 (*fRecClusters)[i] = new TObjArray(1000);
100
101//
102// Transport angular cut
103 fAccCut=0;
104 fAccMin=2;
105 fAccMax=9;
106
107 SetMarkerColor(kRed);
fe4da5cc 108}
109
ddae0931 110//___________________________________________
fe4da5cc 111AliRICH::~AliRICH()
112{
ddae0931 113 fIshunt = 0;
114 delete fHits;
115 delete fClusters;
116 delete fCerenkovs;
117 for (Int_t i=0;i<7;i++)
118 delete (*fRecClusters)[i];
119 delete fRecClusters;
120
fe4da5cc 121}
122
ddae0931 123//___________________________________________
fe4da5cc 124void AliRICH::AddHit(Int_t track, Int_t *vol, Float_t *hits)
125{
ddae0931 126 TClonesArray &lhits = *fHits;
127 new(lhits[fNhits++]) AliRICHhit(fIshunt,track,vol,hits);
fe4da5cc 128}
fe4da5cc 129//_____________________________________________________________________________
ddae0931 130void AliRICH::AddCerenkov(Int_t track, Int_t *vol, Float_t *cerenkovs)
131{
132 TClonesArray &lcerenkovs = *fCerenkovs;
133 new(lcerenkovs[fNcerenkovs++]) AliRICHCerenkov(fIshunt,track,vol,cerenkovs);
fe4da5cc 134}
ddae0931 135//___________________________________________
136void AliRICH::AddCluster(Int_t *clhits)
137{
138 TClonesArray &lclusters = *fClusters;
139 new(lclusters[fNclusters++]) AliRICHcluster(clhits);
fe4da5cc 140}
fe4da5cc 141//_____________________________________________________________________________
ddae0931 142void AliRICH::AddDigits(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
143{
144 //
145 // Add a RICH digit to the list
146 //
147
148 TClonesArray &ldigits = *((TClonesArray*)(*fDchambers)[id]);
149 new(ldigits[fNdch[id]++]) AliRICHdigit(tracks,charges,digits);
fe4da5cc 150}
151
ddae0931 152
fe4da5cc 153//_____________________________________________________________________________
ddae0931 154void AliRICH::AddRecCluster(Int_t iCh, Int_t iCat, AliRICHRecCluster* Cluster)
fe4da5cc 155{
ddae0931 156 //
157 // Add a RICH reconstructed cluster to the list
158 //
159 TObjArray* ClusterList = RecClusters(iCh,iCat);
160 ClusterList->Add(Cluster);
fe4da5cc 161}
162
fe4da5cc 163
164
ddae0931 165//___________________________________________
166void AliRICH::BuildGeometry()
167
fe4da5cc 168{
ddae0931 169 //
170 // Builds a TNode geometry for event display
171 //
172 TNode *Node, *Top;
173
174 const int kColorRICH = kGreen;
175 //
176 Top=gAlice->GetGeometry()->GetNode("alice");
177
178
179 new TBRIK("S_RICH","S_RICH","void",71.09999,11.5,73.15);
180
181 Top->cd();
182 Float_t pos1[3]={0,471.8999,165.2599};
183 Chamber(0).SetChamberTransform(pos1[0],pos1[1],pos1[2],new TRotMatrix("rot993","rot993",90,0,70.69,90,19.30999,-90));
184 Node = new TNode("RICH1","RICH1","S_RICH",pos1[0],pos1[1],pos1[2],"rot993");
185
186
187 Node->SetLineColor(kColorRICH);
188 fNodes->Add(Node);
189 Top->cd();
190
191 Float_t pos2[3]={171,470,0};
192 Chamber(1).SetChamberTransform(pos2[0],pos2[1],pos2[2],new TRotMatrix("rot994","rot994",90,-20,90,70,0,0));
193 Node = new TNode("RICH2","RICH2","S_RICH",pos2[0],pos2[1],pos2[2],"rot994");
194
195
196 Node->SetLineColor(kColorRICH);
197 fNodes->Add(Node);
198 Top->cd();
199 Float_t pos3[3]={0,500,0};
200 Chamber(2).SetChamberTransform(pos3[0],pos3[1],pos3[2],new TRotMatrix("rot995","rot995",90,0,90,90,0,0));
201 Node = new TNode("RICH3","RICH3","S_RICH",pos3[0],pos3[1],pos3[2],"rot995");
202
203
204 Node->SetLineColor(kColorRICH);
205 fNodes->Add(Node);
206 Top->cd();
207 Float_t pos4[3]={-171,470,0};
208 Chamber(3).SetChamberTransform(pos4[0],pos4[1],pos4[2], new TRotMatrix("rot996","rot996",90,20,90,110,0,0));
209 Node = new TNode("RICH4","RICH4","S_RICH",pos4[0],pos4[1],pos4[2],"rot996");
210
211
212 Node->SetLineColor(kColorRICH);
213 fNodes->Add(Node);
214 Top->cd();
215 Float_t pos5[3]={161.3999,443.3999,-165.3};
216 Chamber(4).SetChamberTransform(pos5[0],pos5[1],pos5[2],new TRotMatrix("rot997","rot997",90,340,108.1999,70,18.2,70));
217 Node = new TNode("RICH5","RICH5","S_RICH",pos5[0],pos5[1],pos5[2],"rot997");
218
219 Node->SetLineColor(kColorRICH);
220 fNodes->Add(Node);
221 Top->cd();
222 Float_t pos6[3]={0., 471.9, -165.3,};
223 Chamber(5).SetChamberTransform(pos6[0],pos6[1],pos6[2],new TRotMatrix("rot998","rot998",90,0,109.3099,90,19.30999,90));
224 Node = new TNode("RICH6","RICH6","S_RICH",pos6[0],pos6[1],pos6[2],"rot998");
225
226
227 Node->SetLineColor(kColorRICH);
228 fNodes->Add(Node);
229 Top->cd();
230 Float_t pos7[3]={-161.399,443.3999,-165.3};
231 Chamber(6).SetChamberTransform(pos7[0],pos7[1],pos7[2],new TRotMatrix("rot999","rot999",90,20,108.1999,110,18.2,110));
232 Node = new TNode("RICH7","RICH7","S_RICH",pos7[0],pos7[1],pos7[2],"rot999");
233 Node->SetLineColor(kColorRICH);
234 fNodes->Add(Node);
235
fe4da5cc 236}
237
ddae0931 238//___________________________________________
239Int_t AliRICH::DistancetoPrimitive(Int_t , Int_t )
240{
241 return 9999;
242}
fe4da5cc 243
ddae0931 244//___________________________________________
245void AliRICH::MakeBranch(Option_t* option)
fe4da5cc 246{
ddae0931 247 // Create Tree branches for the RICH.
fe4da5cc 248
ddae0931 249 const Int_t buffersize = 4000;
250 char branchname[20];
fe4da5cc 251
ddae0931 252
253 AliDetector::MakeBranch(option);
254 sprintf(branchname,"%sCerenkov",GetName());
255 if (fCerenkovs && gAlice->TreeH()) {
256 gAlice->TreeH()->Branch(branchname,&fCerenkovs, buffersize);
257 printf("Making Branch %s for Cerenkov Hits\n",branchname);
fe4da5cc 258 }
ddae0931 259
260 sprintf(branchname,"%sCluster",GetName());
261 if (fClusters && gAlice->TreeH()) {
262 gAlice->TreeH()->Branch(branchname,&fClusters, buffersize);
263 printf("Making Branch %s for clusters\n",branchname);
fe4da5cc 264 }
265
ddae0931 266// one branch for digits per chamber
267 Int_t i;
268
269 for (i=0; i<7 ;i++) {
270 sprintf(branchname,"%sDigits%d",GetName(),i+1);
271
272 if (fDchambers && gAlice->TreeD()) {
273 gAlice->TreeD()->Branch(branchname,&((*fDchambers)[i]), buffersize);
274 printf("Making Branch %s for digits in chamber %d\n",branchname,i+1);
275 }
fe4da5cc 276 }
ddae0931 277// one branch for rec clusters
278 for (i=0; i<7; i++) {
279 sprintf(branchname,"%sRecClus%d",GetName(),i+1);
280 if (fRecClusters && gAlice->TreeD()) {
281 gAlice->TreeR()
282 ->Branch(branchname,"TObjArray",
283 &((*fRecClusters)[i]), buffersize,0);
284 printf("Making Branch %s for clusters in chamber %d\n",
285 branchname,i+1);
fe4da5cc 286 }
ddae0931 287 }
fe4da5cc 288}
289
ddae0931 290//___________________________________________
291void AliRICH::SetTreeAddress()
fe4da5cc 292{
ddae0931 293 // Set branch address for the Hits and Digits Tree.
294 char branchname[20];
295 AliDetector::SetTreeAddress();
296
297 TBranch *branch;
298 TTree *treeH = gAlice->TreeH();
299 TTree *treeD = gAlice->TreeD();
300
301 if (treeH) {
302 if (fClusters) {
303 branch = treeH->GetBranch("RICHCluster");
304 if (branch) branch->SetAddress(&fClusters);
fe4da5cc 305 }
ddae0931 306 if (fCerenkovs) {
307 branch = treeH->GetBranch("RICHCerenkov");
308 if (branch) branch->SetAddress(&fCerenkovs);
fe4da5cc 309 }
ddae0931 310
311 }
312
313 if (treeD) {
314 for (int i=0; i<7; i++) {
315 sprintf(branchname,"%sDigits%d",GetName(),i+1);
316 if (fDchambers) {
317 branch = treeD->GetBranch(branchname);
318 if (branch) branch->SetAddress(&((*fDchambers)[i]));
319 }
fe4da5cc 320 }
fe4da5cc 321 }
ddae0931 322}
323//___________________________________________
324void AliRICH::ResetHits()
325{
326 // Reset number of clusters and the cluster array for this detector
327 AliDetector::ResetHits();
328 fNclusters = 0;
329 if (fClusters) fClusters->Clear();
330 if (fCerenkovs) fCerenkovs->Clear();
fe4da5cc 331}
332
ddae0931 333//____________________________________________
334void AliRICH::ResetDigits()
335{
336 //
337 // Reset number of digits and the digits array for this detector
338 //
339 for ( int i=0;i<7;i++ ) {
340 if ((*fDchambers)[i]) (*fDchambers)[i]->Clear();
341 if (fNdch) fNdch[i]=0;
342 }
343}
344//____________________________________________
345void AliRICH::ResetRecClusters()
fe4da5cc 346{
ddae0931 347 //
348 // Reset the rec clusters
349 //
350 for ( int i=0;i<7;i++ ) {
351 if ((*fRecClusters)[i]) (*fRecClusters)[i]->Clear();
fe4da5cc 352 }
ddae0931 353}
354//___________________________________________
fe4da5cc 355
ddae0931 356void AliRICH::SetPADSIZ(Int_t id, Int_t isec, Float_t p1, Float_t p2)
fe4da5cc 357{
ddae0931 358 Int_t i=2*(id-1);
359 ((AliRICHchamber*) (*fChambers)[i]) ->SetPADSIZ(isec,p1,p2);
360 ((AliRICHchamber*) (*fChambers)[i+1])->SetPADSIZ(isec,p1,p2);
361}
fe4da5cc 362
ddae0931 363//___________________________________________
364void AliRICH::SetMUCHSP(Int_t id, Float_t p1)
fe4da5cc 365{
ddae0931 366 Int_t i=2*(id-1);
367 ((AliRICHchamber*) (*fChambers)[i])->SetMUCHSP(p1);
368 ((AliRICHchamber*) (*fChambers)[i+1])->SetMUCHSP(p1);
369}
fe4da5cc 370
ddae0931 371//___________________________________________
372void AliRICH::SetMUSIGM(Int_t id, Float_t p1, Float_t p2)
373{
374 Int_t i=2*(id-1);
375 ((AliRICHchamber*) (*fChambers)[i])->SetMUSIGM(p1,p2);
376 ((AliRICHchamber*) (*fChambers)[i+1])->SetMUSIGM(p1,p2);
377}
fe4da5cc 378
ddae0931 379//___________________________________________
380void AliRICH::SetRSIGM(Int_t id, Float_t p1)
381{
382 Int_t i=2*(id-1);
383 ((AliRICHchamber*) (*fChambers)[i])->SetRSIGM(p1);
384 ((AliRICHchamber*) (*fChambers)[i+1])->SetRSIGM(p1);
385}
fe4da5cc 386
ddae0931 387//___________________________________________
388void AliRICH::SetMAXADC(Int_t id, Float_t p1)
fe4da5cc 389{
ddae0931 390 Int_t i=2*(id-1);
391 ((AliRICHchamber*) (*fChambers)[i])->SetMAXADC(p1);
392 ((AliRICHchamber*) (*fChambers)[i+1])->SetMAXADC(p1);
fe4da5cc 393}
394
ddae0931 395//___________________________________________
396void AliRICH::SetSMAXAR(Float_t p1)
fe4da5cc 397{
ddae0931 398 fMaxStepGas=p1;
fe4da5cc 399}
400
ddae0931 401//___________________________________________
402void AliRICH::SetSMAXAL(Float_t p1)
403{
404 fMaxStepAlu=p1;
405}
fe4da5cc 406
ddae0931 407//___________________________________________
408void AliRICH::SetDMAXAR(Float_t p1)
fe4da5cc 409{
ddae0931 410 fMaxDestepGas=p1;
fe4da5cc 411}
412
ddae0931 413//___________________________________________
414void AliRICH::SetDMAXAL(Float_t p1)
415{
416 fMaxDestepAlu=p1;
417}
418//___________________________________________
419void AliRICH::SetRICHACC(Bool_t acc, Float_t angmin, Float_t angmax)
420{
421 fAccCut=acc;
422 fAccMin=angmin;
423 fAccMax=angmax;
424}
425//___________________________________________
426void AliRICH::SetSegmentationModel(Int_t id, Int_t isec, AliRICHsegmentation *segmentation)
427{
428 ((AliRICHchamber*) (*fChambers)[id])->SegmentationModel(isec, segmentation);
fe4da5cc 429
ddae0931 430}
431//___________________________________________
432void AliRICH::SetResponseModel(Int_t id, Response_t res, AliRICHresponse *response)
fe4da5cc 433{
ddae0931 434 ((AliRICHchamber*) (*fChambers)[id])->ResponseModel(res, response);
fe4da5cc 435}
436
ddae0931 437void AliRICH::SetNsec(Int_t id, Int_t nsec)
438{
439 ((AliRICHchamber*) (*fChambers)[id])->SetNsec(nsec);
440}
441
442
443//___________________________________________
444
445void AliRICH::StepManager()
fe4da5cc 446{
ddae0931 447 printf("Dummy version of RICH step -- it should never happen!!\n");
448 const Float_t kRaddeg = 180/TMath::Pi();
ddae0931 449 Int_t nsec, ipart;
5d84196c 450 TLorentzVector x, p;
ddae0931 451 Float_t pt, th0, th1;
6a935c13 452 const char *proc;
ddae0931 453 if(fAccCut) {
5d84196c 454 if((nsec=gMC->NSecondaries())>0) {
6a935c13 455 proc=gMC->ProdProcess();
5d84196c 456 if((gMC->TrackPid()==113 || gMC->TrackPid()==114) && !strcmp(proc,"DCAY")) {
ddae0931 457
458 // Check angular acceptance
459 //* --- and have muons from resonance decays in the wanted window ---
460 if(nsec != 2) {
461 printf(" AliRICH::StepManager: Strange resonance Decay into %d particles\n",nsec);
5d84196c 462 gMC->StopEvent();
ddae0931 463 } else {
5d84196c 464 gMC->GetSecondary(0,ipart,x,p);
ddae0931 465 pt = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
466 th0 = TMath::ATan2(pt,p[2])*kRaddeg;
5d84196c 467 gMC->GetSecondary(1,ipart,x,p);
ddae0931 468 pt = TMath::Sqrt(p[0]*p[0]+p[1]*p[1]);
469 th1 = TMath::ATan2(pt,p[2])*kRaddeg;
470 if(!(fAccMin < th0 && th0 < fAccMax) ||
471 !(fAccMin < th1 && th1 < fAccMax))
5d84196c 472 gMC->StopEvent();
ddae0931 473 }
474 }
475 }
fe4da5cc 476 }
ddae0931 477}
478void AliRICH::ReconstructClusters()
479{
480//
481// Initialize the necessary correspondance table
482//
f91473f6 483 static const Int_t kMaxNPadx = 600;
484 static const Int_t kMaxNPady = 600;
485 Int_t elem[kMaxNPadx*2][kMaxNPady*2];
ddae0931 486//
487// Loop on chambers and on cathode planes
488//
489 for (Int_t ich=0;ich<7;ich++)
490 for (Int_t icat=0;icat<1;icat++) {
491 //
492 // Get ready the current chamber stuff
493 //
494
495 printf ("Olarilole");
496 AliRICHchamber* iChamber= &(this->Chamber(ich));
497 AliRICHsegmentation* segmentation =
498 iChamber->GetSegmentationModel(icat+1);
499 if (!segmentation)
500 continue;
501 TClonesArray *RICHdigits = this->DigitsAddress(ich);
502 if (RICHdigits == 0)
503 continue;
504 cout << "Npx " << segmentation->Npx()
505 << " Npy " << segmentation->Npy() << endl;
506 //
507 // Ready the digits
508 //
509 gAlice->ResetDigits();
510 gAlice->TreeD()->GetEvent(icat+1); // spurious +1 ...
511 Int_t ndigits = RICHdigits->GetEntriesFast();
512 if (ndigits == 0)
513 continue;
514 printf("Found %d digits for cathode %d in chamber %d \n",
515 ndigits,icat,ich+1);
516 AliRICHdigit *mdig;
517 AliRICHRecCluster *Cluster;
518 //
519 // Build the correspondance table
520 //
f91473f6 521 memset(elem,0,sizeof(Int_t)*kMaxNPadx*kMaxNPady*4);
ddae0931 522 Int_t digit;
523 for (digit=0; digit<ndigits; digit++)
524 {
525 mdig = (AliRICHdigit*)RICHdigits->UncheckedAt(digit);
f91473f6 526 elem[kMaxNPadx+mdig->fPadX][kMaxNPady+mdig->fPadY] = digit+1;
ddae0931 527 // because default is 0
528 }
529 //
530 // Declare some useful variables
531 //
532 Int_t Xlist[10];
533 Int_t Ylist[10];
534 Int_t Nlist;
535 Int_t nclust=0;
536 //
537 // loop over digits
538 //
539 for (digit=0;digit<ndigits;digit++) {
540 mdig = (AliRICHdigit*)RICHdigits->UncheckedAt(digit);
541 //
542 // if digit still available, start clustering
543 //
f91473f6 544 if (elem[kMaxNPadx+mdig->fPadX][kMaxNPady+mdig->fPadY]) {
ddae0931 545 Cluster = new AliRICHRecCluster(digit, ich, icat);
f91473f6 546 elem[kMaxNPadx+mdig->fPadX][kMaxNPady+mdig->fPadY]=0;
ddae0931 547 //
548 // loop over the current list of digits
549 // and look for neighbours
550 //
551 for(Int_t clusDigit=Cluster->FirstDigitIndex();
552 clusDigit!=Cluster->InvalidDigitIndex();
553 clusDigit=Cluster->NextDigitIndex()) {
554 AliRICHdigit* pDigit=(AliRICHdigit*)RICHdigits
555 ->UncheckedAt(clusDigit);
556 segmentation->Neighbours(pDigit->fPadX,pDigit->fPadY,
557 &Nlist, Xlist, Ylist);
558 for (Int_t Ilist=0;Ilist<Nlist;Ilist++) {
f91473f6 559 if (elem[kMaxNPadx+Xlist[Ilist]][kMaxNPady
ddae0931 560 +Ylist[Ilist]]) {
561 //
562 // Add the digit at the end and reset the table
563 //
f91473f6 564 Cluster->AddDigit(elem[kMaxNPadx+Xlist[Ilist]][kMaxNPady+Ylist[Ilist]]-1);
565 elem[kMaxNPadx+Xlist[Ilist]][kMaxNPady
ddae0931 566 +Ylist[Ilist]] =0;
567 } // if elem
568 } // for Ilist
569 } // for pDigit
570 //
571 // Store the cluster (good time to do Cluster polishing)
572 //
573 segmentation->FitXY(Cluster,RICHdigits);
574 nclust ++;
575 AddRecCluster(ich,icat,Cluster);
576 }
577 }
578 printf("===> %d Clusters\n",nclust);
579 } // for icat
580}
581
582
583//______________________________________________________________________________
584void AliRICH::Streamer(TBuffer &R__b)
585{
586 // Stream an object of class AliRICH.
587 AliRICHchamber *iChamber;
588 AliRICHsegmentation *segmentation;
589 AliRICHresponse *response;
590 TClonesArray *digitsaddress;
591
592 if (R__b.IsReading()) {
593 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
594 AliDetector::Streamer(R__b);
595 R__b >> fNclusters;
596 R__b >> fClusters; // diff
597 R__b >> fDchambers;
598 R__b.ReadArray(fNdch);
599 //
600 R__b >> fAccCut;
601 R__b >> fAccMin;
602 R__b >> fAccMax;
603 //
604 R__b >> fChambers;
605// Stream chamber related information
606 for (Int_t i =0; i<7; i++) {
607 iChamber=(AliRICHchamber*) (*fChambers)[i];
608 iChamber->Streamer(R__b);
609 if (iChamber->Nsec()==1) {
610 segmentation=iChamber->GetSegmentationModel(1);
611 segmentation->Streamer(R__b);
612 } else {
613 segmentation=iChamber->GetSegmentationModel(1);
614 segmentation->Streamer(R__b);
615 segmentation=iChamber->GetSegmentationModel(2);
616 segmentation->Streamer(R__b);
617 }
618 response=iChamber->GetResponseModel(mip);
619 response->Streamer(R__b);
620 response=iChamber->GetResponseModel(cerenkov);
621 response->Streamer(R__b);
622
623 digitsaddress=(TClonesArray*) (*fDchambers)[i];
624 digitsaddress->Streamer(R__b);
625 }
626
627 } else {
628 R__b.WriteVersion(AliRICH::IsA());
629 AliDetector::Streamer(R__b);
630 R__b << fNclusters;
631 R__b << fClusters; // diff
632 R__b << fDchambers;
633 R__b.WriteArray(fNdch, 7);
634 //
635 R__b << fAccCut;
636 R__b << fAccMin;
637 R__b << fAccMax;
638 //
639 R__b << fChambers;
640// Stream chamber related information
641 for (Int_t i =0; i<7; i++) {
642 iChamber=(AliRICHchamber*) (*fChambers)[i];
643 iChamber->Streamer(R__b);
644 if (iChamber->Nsec()==1) {
645 segmentation=iChamber->GetSegmentationModel(1);
646 segmentation->Streamer(R__b);
647 } else {
648 segmentation=iChamber->GetSegmentationModel(1);
649 segmentation->Streamer(R__b);
650 segmentation=iChamber->GetSegmentationModel(2);
651 segmentation->Streamer(R__b);
652 }
653 response=iChamber->GetResponseModel(mip);
654 response->Streamer(R__b);
655 response=iChamber->GetResponseModel(cerenkov);
656 response->Streamer(R__b);
657
658 digitsaddress=(TClonesArray*) (*fDchambers)[i];
659 digitsaddress->Streamer(R__b);
660 }
fe4da5cc 661 }
ddae0931 662}
663AliRICHcluster* AliRICH::FirstPad(AliRICHhit* hit,TClonesArray *clusters )
664{
665//
666 // Initialise the pad iterator
667 // Return the address of the first padhit for hit
668 TClonesArray *theClusters = clusters;
669 Int_t nclust = theClusters->GetEntriesFast();
670 if (nclust && hit->fPHlast > 0) {
671 sMaxIterPad=hit->fPHlast;
672 sCurIterPad=hit->fPHfirst;
673 return (AliRICHcluster*) clusters->UncheckedAt(sCurIterPad-1);
674 } else {
675 return 0;
fe4da5cc 676 }
ddae0931 677
fe4da5cc 678}
679
ddae0931 680AliRICHcluster* AliRICH::NextPad(TClonesArray *clusters)
fe4da5cc 681{
ddae0931 682 sCurIterPad++;
683 if (sCurIterPad <= sMaxIterPad) {
684 return (AliRICHcluster*) clusters->UncheckedAt(sCurIterPad-1);
685 } else {
686 return 0;
687 }
fe4da5cc 688}
689
ddae0931 690ClassImp(AliRICHcluster)
691
692//___________________________________________
693AliRICHcluster::AliRICHcluster(Int_t *clhits)
694{
695 fHitNumber=clhits[0];
696 fCathode=clhits[1];
697 fQ=clhits[2];
698 fPadX=clhits[3];
699 fPadY=clhits[4];
700 fQpad=clhits[5];
701 fRSec=clhits[6];
702}
703ClassImp(AliRICHdigit)
fe4da5cc 704//_____________________________________________________________________________
ddae0931 705AliRICHdigit::AliRICHdigit(Int_t *digits)
fe4da5cc 706{
ddae0931 707 //
708 // Creates a RICH digit object to be updated
709 //
710 fPadX = digits[0];
711 fPadY = digits[1];
712 fSignal = digits[2];
713
fe4da5cc 714}
fe4da5cc 715//_____________________________________________________________________________
ddae0931 716AliRICHdigit::AliRICHdigit(Int_t *tracks, Int_t *charges, Int_t *digits)
fe4da5cc 717{
ddae0931 718 //
719 // Creates a RICH digit object
720 //
721 fPadX = digits[0];
722 fPadY = digits[1];
723 fSignal = digits[2];
724 for(Int_t i=0; i<10; i++) {
725 fTcharges[i] = charges[i];
726 fTracks[i] = tracks[i];
727 }
fe4da5cc 728}
729
ddae0931 730ClassImp(AliRICHlist)
731
732//____________________________________________________________________________
733AliRICHlist::AliRICHlist(Int_t ich, Int_t *digits):
734 AliRICHdigit(digits)
fe4da5cc 735{
ddae0931 736 //
737 // Creates a RICH digit list object
738 //
739
740 fChamber = ich;
741 fTrackList = new TObjArray;
742
fe4da5cc 743}
ddae0931 744//_____________________________________________________________________________
fe4da5cc 745
fe4da5cc 746
ddae0931 747ClassImp(AliRICHhit)
748
749//___________________________________________
750AliRICHhit::AliRICHhit(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
751 AliHit(shunt, track)
fe4da5cc 752{
ddae0931 753 fChamber=vol[0];
754 fParticle=hits[0];
755 fX=hits[1];
756 fY=hits[2];
757 fZ=hits[3];
758 fTheta=hits[4];
759 fPhi=hits[5];
760 fTlength=hits[6];
761 fEloss=hits[7];
762 fPHfirst=(Int_t) hits[8];
763 fPHlast=(Int_t) hits[9];
fe4da5cc 764}
ddae0931 765ClassImp(AliRICHreccluster)
766
767ClassImp(AliRICHCerenkov)
768//___________________________________________
769AliRICHCerenkov::AliRICHCerenkov(Int_t shunt, Int_t track, Int_t *vol, Float_t *hits):
770 AliHit(shunt, track)
fe4da5cc 771{
ddae0931 772 fChamber=vol[0];
773 fX=hits[1];
774 fY=hits[2];
775 fZ=hits[3];
776 fTheta=hits[4];
777 fPhi=hits[5];
778 fTlength=hits[6];
779 fPHfirst=(Int_t) hits[8];
780 fPHlast=(Int_t) hits[9];
fe4da5cc 781}
782
ddae0931 783ClassImp(AliRICHRecCluster)
784
785//_____________________________________________________________________
786AliRICHRecCluster::AliRICHRecCluster()
fe4da5cc 787{
ddae0931 788 fDigits=0;
789 fNdigit=-1;
fe4da5cc 790}
ddae0931 791
792AliRICHRecCluster::AliRICHRecCluster(Int_t FirstDigit,Int_t Ichamber, Int_t Icathod)
fe4da5cc 793{
ddae0931 794 fX = 0.;
795 fY = 0.;
796 fDigits = new TArrayI(10);
797 fNdigit=0;
798 AddDigit(FirstDigit);
799 fChamber=Ichamber;
800 fCathod=Icathod;
fe4da5cc 801}
802
ddae0931 803void AliRICHRecCluster::AddDigit(Int_t Digit)
fe4da5cc 804{
ddae0931 805 if (fNdigit==fDigits->GetSize()) {
806 //enlarge the list by hand!
807 Int_t *array= new Int_t[fNdigit*2];
808 for(Int_t i=0;i<fNdigit;i++)
809 array[i] = fDigits->At(i);
810 fDigits->Adopt(fNdigit*2,array);
811 }
812 fDigits->AddAt(Digit,fNdigit);
813 fNdigit++;
fe4da5cc 814}
815
ddae0931 816
817AliRICHRecCluster::~AliRICHRecCluster()
fe4da5cc 818{
ddae0931 819 if (fDigits)
820 delete fDigits;
fe4da5cc 821}
822
ddae0931 823Int_t AliRICHRecCluster::FirstDigitIndex()
fe4da5cc 824{
ddae0931 825 fCurrentDigit=0;
826 return fDigits->At(fCurrentDigit);
fe4da5cc 827}
828
ddae0931 829Int_t AliRICHRecCluster::NextDigitIndex()
830{
831 fCurrentDigit++;
832 if (fCurrentDigit<fNdigit)
833 return fDigits->At(fCurrentDigit);
834 else
835 return InvalidDigitIndex();
836}
fe4da5cc 837
ddae0931 838Int_t AliRICHRecCluster::NDigits()
fe4da5cc 839{
ddae0931 840 return fNdigit;
fe4da5cc 841}
842
ddae0931 843void AliRICHRecCluster::Finish()
fe4da5cc 844{
ddae0931 845 // In order to reconstruct coordinates, one has to
846 // get back to the digits which is not trivial here,
847 // because we don't know where digits are stored!
848 // Center Of Gravity, or other method should be
849 // a property of AliRICH class!
fe4da5cc 850}
851
fe4da5cc 852
853
ddae0931 854void AliRICH::Digitise(Int_t nev,Option_t *option,Text_t *filename)
fe4da5cc 855{
ddae0931 856 // keep galice.root for signal and name differently the file for
857 // background when add! otherwise the track info for signal will be lost !
858
c90dd3e2 859 static Bool_t first=kTRUE;
ddae0931 860 static TTree *TH1;
861 static TFile *File;
c90dd3e2 862 Int_t i;
ddae0931 863 char *Add = strstr(option,"Add");
864
865 AliRICHchamber* iChamber;
866 AliRICHsegmentation* segmentation;
867
868
869 Int_t trk[50];
870 Int_t chtrk[50];
871 TObjArray *list=new TObjArray;
872 Int_t digits[3];
873
874 AliRICH *RICH = (AliRICH *) gAlice->GetDetector("RICH");
875 AliRICHHitMap* HitMap[10];
c90dd3e2 876 for (i=0; i<10; i++) {HitMap[i]=0;}
ddae0931 877 if (Add ) {
878 if(first) {
879 fFileName=filename;
880 cout<<"filename"<<fFileName<<endl;
881 File=new TFile(fFileName);
882 cout<<"I have opened "<<fFileName<<" file "<<endl;
883 fHits2 = new TClonesArray("AliRICHhit",1000 );
884 fClusters2 = new TClonesArray("AliRICHcluster",10000);
c90dd3e2 885 first=kFALSE;
ddae0931 886 }
887 File->cd();
888 File->ls();
889 // Get Hits Tree header from file
890 if(fHits2) fHits2->Clear();
891 if(fClusters2) fClusters2->Clear();
892 if(TH1) delete TH1;
893 TH1=0;
894 //
895 char treeName[20];
896 sprintf(treeName,"TreeH%d",nev);
897 TH1 = (TTree*)gDirectory->Get(treeName);
898 if (!TH1) {
899 printf("ERROR: cannot find Hits Tree for event:%d\n",nev);
900 }
901 // Set branch addresses
902 TBranch *branch;
903 char branchname[20];
904 sprintf(branchname,"%s",GetName());
905 if (TH1 && fHits2) {
906 branch = TH1->GetBranch(branchname);
907 if (branch) branch->SetAddress(&fHits2);
908 }
909 if (TH1 && fClusters2) {
910 branch = TH1->GetBranch("RICHCluster");
911 if (branch) branch->SetAddress(&fClusters2);
912 }
913 }
914 //
915 // loop over cathodes
916 //
917 AliRICHHitMap* hm;
918
f91473f6 919 for (int icat=0; icat<1; icat++) {
c90dd3e2 920 for (i=0; i<7; i++) {
ddae0931 921 if (HitMap[i]) {
922 hm=HitMap[i];
923 delete hm;
924 HitMap[i]=0;
925 }
926 }
927 Int_t counter=0;
c90dd3e2 928 for (i =0; i<7; i++) {
ddae0931 929 iChamber=(AliRICHchamber*) (*fChambers)[i];
930 if (iChamber->Nsec()==1 && icat==1) {
931 continue;
932 } else {
933 segmentation=iChamber->GetSegmentationModel(icat+1);
934 }
935 HitMap[i] = new AliRICHHitMapA1(segmentation, list);
936 }
937 printf("Start loop over tracks \n");
938//
939// Loop over tracks
940//
941
942 TTree *TH = gAlice->TreeH();
943 Int_t ntracks =(Int_t) TH->GetEntries();
944 for (Int_t track=0; track<ntracks; track++) {
945 gAlice->ResetHits();
946 TH->GetEvent(track);
947//
948// Loop over hits
949 for(AliRICHhit* mHit=(AliRICHhit*)RICH->FirstHit(-1);
950 mHit;
951 mHit=(AliRICHhit*)RICH->NextHit())
952 {
953 Int_t nch = mHit->fChamber-1; // chamber number
954 if (nch >7) continue;
955 iChamber = &(RICH->Chamber(nch));
956
957//
958// Loop over pad hits
959 for (AliRICHcluster* mPad=
960 (AliRICHcluster*)RICH->FirstPad(mHit,fClusters);
961 mPad;
962 mPad=(AliRICHcluster*)RICH->NextPad(fClusters))
963 {
964 Int_t cathode = mPad->fCathode; // cathode number
965 Int_t ipx = mPad->fPadX; // pad number on X
966 Int_t ipy = mPad->fPadY; // pad number on Y
967 Int_t iqpad = mPad->fQpad; // charge per pad
968//
969//
970
971 if (cathode != (icat+1)) continue;
972 // fill the info array
973 Float_t thex, they;
974 segmentation=iChamber->GetSegmentationModel(cathode);
975 segmentation->GetPadCxy(ipx,ipy,thex,they);
976 TVector *trinfo_p= new TVector(2);
977 TVector &trinfo = *trinfo_p;
978 trinfo(0)=(Float_t)track;
979 trinfo(1)=(Float_t)iqpad;
980
981 digits[0]=ipx;
982 digits[1]=ipy;
983 digits[2]=iqpad;
984
985 AliRICHlist* pdigit;
986 // build the list of fired pads and update the info
987 if (!HitMap[nch]->TestHit(ipx, ipy)) {
988 list->AddAtAndExpand(
989 new AliRICHlist(nch,digits),counter);
990 HitMap[nch]->SetHit(ipx, ipy, counter);
991 counter++;
992 pdigit=(AliRICHlist*)list->At(list->GetLast());
993 // list of tracks
994 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
995 trlist->Add(&trinfo);
996 } else {
997 pdigit=(AliRICHlist*) HitMap[nch]->GetHit(ipx, ipy);
998 // update charge
999 (*pdigit).fSignal+=iqpad;
1000 // update list of tracks
1001 TObjArray* trlist=(TObjArray*)pdigit->TrackList();
1002 Int_t last_entry=trlist->GetLast();
1003 TVector *ptrk_p=(TVector*)trlist->At(last_entry);
1004 TVector &ptrk=*ptrk_p;
1005 Int_t last_track=Int_t(ptrk(0));
1006 Int_t last_charge=Int_t(ptrk(1));
1007 if (last_track==track) {
1008 last_charge+=iqpad;
1009 trlist->RemoveAt(last_entry);
1010 trinfo(0)=last_track;
1011 trinfo(1)=last_charge;
1012 trlist->AddAt(&trinfo,last_entry);
1013 } else {
1014 trlist->Add(&trinfo);
1015 }
1016 // check the track list
1017 Int_t nptracks=trlist->GetEntriesFast();
1018 if (nptracks > 2) {
1019 printf("Attention - nptracks > 2 %d \n",nptracks);
1020 printf("cat,nch,ix,iy %d %d %d %d \n",icat+1,nch,ipx,ipy);
1021 for (Int_t tr=0;tr<nptracks;tr++) {
1022 TVector *pptrk_p=(TVector*)trlist->At(tr);
1023 TVector &pptrk=*pptrk_p;
1024 trk[tr]=Int_t(pptrk(0));
1025 chtrk[tr]=Int_t(pptrk(1));
1026 }
1027 } // end if nptracks
1028 } // end if pdigit
1029 } //end loop over clusters
1030 } // hit loop
1031 } // track loop
1032
1033 Int_t nentr1=list->GetEntriesFast();
1034 printf(" \n counter, nentr1 %d %d\n",counter,nentr1);
1035
1036 // open the file with background
1037
1038 if (Add ) {
1039 ntracks =(Int_t)TH1->GetEntries();
1040 printf("background - icat,ntracks1 %d %d\n",icat,ntracks);
1041 printf("background - Start loop over tracks \n");
1042//
1043// Loop over tracks
1044//
f91473f6 1045 for (Int_t trak=0; trak<ntracks; trak++) {
ddae0931 1046
1047 if (fHits2) fHits2->Clear();
1048 if (fClusters2) fClusters2->Clear();
1049
f91473f6 1050 TH1->GetEvent(trak);
ddae0931 1051//
1052// Loop over hits
1053 AliRICHhit* mHit;
f91473f6 1054 for(int j=0;j<fHits2->GetEntriesFast();++j)
ddae0931 1055 {
f91473f6 1056 mHit=(AliRICHhit*) (*fHits2)[j];
ddae0931 1057 Int_t nch = mHit->fChamber-1; // chamber number
1058 if (nch >9) continue;
1059 iChamber = &(RICH->Chamber(nch));
1060 Int_t rmin = (Int_t)iChamber->RInner();
1061 Int_t rmax = (Int_t)iChamber->ROuter();
1062//
1063// Loop over pad hits
1064 for (AliRICHcluster* mPad=
1065 (AliRICHcluster*)RICH->FirstPad(mHit,fClusters2);
1066 mPad;
1067 mPad=(AliRICHcluster*)RICH->NextPad(fClusters2))
1068 {
1069 Int_t cathode = mPad->fCathode; // cathode number
1070 Int_t ipx = mPad->fPadX; // pad number on X
1071 Int_t ipy = mPad->fPadY; // pad number on Y
1072 Int_t iqpad = mPad->fQpad; // charge per pad
f91473f6 1073 if (trak==3 && nch==0 && icat==0) printf("bgr - trak,iqpad,ipx,ipy %d %d %d %d\n",trak,iqpad,ipx,ipy);
ddae0931 1074//
1075//
1076 if (cathode != (icat+1)) continue;
1077 // fill the info array
1078 Float_t thex, they;
1079 segmentation=iChamber->GetSegmentationModel(cathode);
1080 segmentation->GetPadCxy(ipx,ipy,thex,they);
1081 Float_t rpad=TMath::Sqrt(thex*thex+they*they);
1082 if (rpad < rmin || iqpad ==0 || rpad > rmax) continue;
1083
1084 TVector *trinfo_p;
1085 trinfo_p = new TVector(2);
1086 TVector &trinfo = *trinfo_p;
1087 trinfo(0)=-1; // tag background
1088 trinfo(1)=-1;
1089
1090 digits[0]=ipx;
1091 digits[1]=ipy;
1092 digits[2]=iqpad;
1093
1094
f91473f6 1095 if (trak <4 && icat==0 && nch==0)
1096 printf("bgr - HitMap[nch]->TestHit(ipx, ipy),trak %d %d\n",
1097 HitMap[nch]->TestHit(ipx, ipy),trak);
ddae0931 1098 AliRICHlist* pdigit;
1099 // build the list of fired pads and update the info
1100 if (!HitMap[nch]->TestHit(ipx, ipy)) {
1101 list->AddAtAndExpand(new AliRICHlist(nch,digits),counter);
1102
1103 HitMap[nch]->SetHit(ipx, ipy, counter);
1104 counter++;
1105 printf("bgr new elem in list - counter %d\n",counter);
1106
1107 pdigit=(AliRICHlist*)list->At(list->GetLast());
1108 // list of tracks
1109 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
1110 trlist->Add(&trinfo);
1111 } else {
1112 pdigit=(AliRICHlist*) HitMap[nch]->GetHit(ipx, ipy);
1113 // update charge
1114 (*pdigit).fSignal+=iqpad;
1115 // update list of tracks
1116 TObjArray* trlist=(TObjArray*)pdigit->TrackList();
1117 Int_t last_entry=trlist->GetLast();
1118 TVector *ptrk_p=(TVector*)trlist->At(last_entry);
1119 TVector &ptrk=*ptrk_p;
1120 Int_t last_track=Int_t(ptrk(0));
1121 if (last_track==-1) {
1122 continue;
1123 } else {
1124 trlist->Add(&trinfo);
1125 }
1126 // check the track list
1127 Int_t nptracks=trlist->GetEntriesFast();
1128 if (nptracks > 0) {
1129 for (Int_t tr=0;tr<nptracks;tr++) {
1130 TVector *pptrk_p=(TVector*)trlist->At(tr);
1131 TVector &pptrk=*pptrk_p;
1132 trk[tr]=Int_t(pptrk(0));
1133 chtrk[tr]=Int_t(pptrk(1));
1134 }
1135 } // end if nptracks
1136 } // end if pdigit
1137 } //end loop over clusters
1138 } // hit loop
1139 } // track loop
1140 Int_t nentr2=list->GetEntriesFast();
1141 printf(" \n counter2, nentr2 %d %d \n",counter,nentr2);
1142 TTree *fAli=gAlice->TreeK();
1143 if (fAli) File =fAli->GetCurrentFile();
1144 File->cd();
1145 } // if Add
1146
1147 Int_t tracks[10];
1148 Int_t charges[10];
1149 cout<<"start filling digits \n "<<endl;
1150 Int_t nentries=list->GetEntriesFast();
1151 printf(" \n \n nentries %d \n",nentries);
1152
1153 // start filling the digits
1154
1155 for (Int_t nent=0;nent<nentries;nent++) {
1156 AliRICHlist *address=(AliRICHlist*)list->At(nent);
1157 if (address==0) continue;
1158 Int_t ich=address->fChamber;
1159 Int_t q=address->fSignal;
1160 iChamber=(AliRICHchamber*) (*fChambers)[ich];
1161 // add white noise and do zero-suppression and signal truncation
1162 Float_t MeanNoise = gRandom->Gaus(1, 0.2);
1163 Float_t ZeroSupp=5*MeanNoise;
1164 Float_t Noise = gRandom->Gaus(0, MeanNoise);
1165 q+=(Int_t)Noise;
1166 if ( q <= ZeroSupp) continue;
1167 digits[0]=address->fPadX;
1168 digits[1]=address->fPadY;
1169 digits[2]=q;
1170
1171 TObjArray* trlist=(TObjArray*)address->TrackList();
1172 Int_t nptracks=trlist->GetEntriesFast();
1173
1174 // this was changed to accomodate the real number of tracks
1175 if (nptracks > 10) {
1176 cout<<"Attention - nptracks > 10 "<<nptracks<<endl;
1177 nptracks=10;
1178 }
1179 if (nptracks > 2) {
1180 printf("Attention - nptracks > 2 %d \n",nptracks);
1181 printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,digits[0],digits[1],q);
1182 }
1183 for (Int_t tr=0;tr<nptracks;tr++) {
1184 TVector *pp_p=(TVector*)trlist->At(tr);
1185 TVector &pp =*pp_p;
1186 tracks[tr]=Int_t(pp(0));
1187 charges[tr]=Int_t(pp(1));
1188 } //end loop over list of tracks for one pad
1189 if (nptracks < 10 ) {
f91473f6 1190 for (Int_t t=nptracks; t<10; t++) {
1191 tracks[t]=0;
1192 charges[t]=0;
ddae0931 1193 }
1194 }
1195 // fill digits
1196 RICH->AddDigits(ich,tracks,charges,digits);
1197
1198 delete address;
1199 }
1200 cout<<"I'm out of the loops for digitisation"<<endl;
1201 gAlice->TreeD()->Fill();
1202 TTree *TD=gAlice->TreeD();
1203 Stat_t ndig=TD->GetEntries();
1204 cout<<"number of digits "<<ndig<<endl;
1205 TClonesArray *fDch;
f91473f6 1206 for (int k=0;k<7;k++) {
1207 fDch= RICH->DigitsAddress(k);
c90dd3e2 1208 int ndigit=fDch->GetEntriesFast();
1209 printf (" k, ndigits %d %d \n",k,ndigit);
ddae0931 1210 }
1211 RICH->ResetDigits();
1212
1213 list->Clear();
1214
1215 } //end loop over cathodes
1216 char hname[30];
1217 sprintf(hname,"TreeD%d",nev);
1218 gAlice->TreeD()->Write(hname);
fe4da5cc 1219}
1220
1221
ddae0931 1222
1223
1224
1225
1226
1227
1228