1 /**************************************************************************
2 * Copyright(c) 1998-2000, 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.3 2001/05/16 14:57:20 alibrary
19 New files for folders and Stack
21 Revision 1.2 2001/03/14 18:16:08 jbarbosa
22 Corrected bug (more to correct).
23 File "points.dat" is no longer created.
25 Revision 1.1 2001/02/27 22:13:34 jbarbosa
26 Implementing merger class.
32 #include <TObjArray.h>
34 #include <TDirectory.h>
35 #include <TParticle.h>
38 // #include "AliMerger.h"
39 // #include "AliMergable.h"
40 #include "AliRICHMerger.h"
41 #include "AliRICHChamber.h"
42 #include "AliHitMap.h"
43 #include "AliRICHHitMapA1.h"
45 #include "AliRICHHit.h"
46 #include "AliRICHSDigit.h"
47 #include "AliRICHDigit.h"
48 #include "AliRICHTransientDigit.h"
52 ClassImp(AliRICHMerger)
54 //___________________________________________
55 AliRICHMerger::AliRICHMerger()
57 // Default constructor
74 //------------------------------------------------------------------------
75 AliRICHMerger::~AliRICHMerger()
78 if (fTrH1) delete fTrH1;
79 if (fHitsBgr) delete fHitsBgr;
80 if (fSDigitsBgr) delete fSDigitsBgr;
81 if (fHitMap) delete fHitMap;
82 if (fList) delete fList;
83 if (fTrList) delete fTrList;
84 if (fAddress) delete fAddress;
87 //------------------------------------------------------------------------
88 Bool_t AliRICHMerger::Exists(const AliRICHSDigit *mergable)
90 AliRICHSDigit *padhit = (AliRICHSDigit*) mergable;
91 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
94 //------------------------------------------------------------------------
95 void AliRICHMerger::Update(AliRICHSDigit *mergable)
97 AliRICHSDigit *padhit = (AliRICHSDigit*) mergable;
98 AliRICHTransientDigit* pdigit;
99 Int_t ipx = padhit->PadX(); // pad number on X
100 Int_t ipy = padhit->PadY(); // pad number on Y
101 Int_t iqpad = Int_t(padhit->QPad()); // charge per pad
103 pdigit = (AliRICHTransientDigit*) fHitMap[fNch]->GetHit(ipx, ipy);
106 (*pdigit).AddSignal(iqpad);
107 (*pdigit).AddPhysicsSignal(iqpad);
108 // update list of tracks
110 TObjArray* fTrList = (TObjArray*)pdigit->TrackList();
111 Int_t lastEntry = fTrList->GetLast();
112 TVector *pTrack = (TVector*)fTrList->At(lastEntry);
113 TVector &ptrk = *pTrack;
114 TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]);
115 Int_t lastTrack = Int_t(ptrk(0));
117 if (trinfo(0) != kBgTag) {
118 if (lastTrack == fTrack) {
119 Int_t lastCharge = Int_t(ptrk(1));
121 fTrList->RemoveAt(lastEntry);
122 trinfo(1) = lastCharge;
123 fTrList->AddAt(&trinfo,lastEntry);
125 fTrList->Add(&trinfo);
128 if (lastTrack != -1) fTrList->Add(&trinfo);
132 //------------------------------------------------------------------------
133 void AliRICHMerger::CreateNew(AliRICHSDigit *mergable)
135 AliRICHSDigit *padhit = (AliRICHSDigit*) mergable;
136 AliRICHTransientDigit* pdigit;
138 Int_t ipx = padhit->PadX(); // pad number on X
139 Int_t ipy = padhit->PadY(); // pad number on Y
140 fList->AddAtAndExpand(
141 new AliRICHTransientDigit(fNch,fDigits),fCounter);
142 fHitMap[fNch]->SetHit(ipx, ipy, fCounter);
144 pdigit = (AliRICHTransientDigit*)fList->At(fList->GetLast());
146 TObjArray *fTrList = (TObjArray*)pdigit->TrackList();
147 TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]);
148 fTrList->Add(&trinfo);
152 //------------------------------------------------------------------------
153 void AliRICHMerger::Init()
157 if (fMerge) fBgrFile = InitBgr();
162 //------------------------------------------------------------------------
163 TFile* AliRICHMerger::InitBgr()
165 // Initialise background event
166 TFile *file = new TFile(fFnBgr);
167 // add error checking later
168 printf("\n AliRICHMerger has opened %s file with background event \n", fFnBgr);
169 fHitsBgr = new TClonesArray("AliRICHHit",1000);
170 fSDigitsBgr = new TClonesArray("AliRICHSDigit",1000);
174 //------------------------------------------------------------------------
175 void AliRICHMerger::Digitise(Int_t nev, Int_t flag)
178 // keep galice.root for signal and name differently the file for
179 // background when add! otherwise the track info for signal will be lost !
183 //FILE* points; //these will be the digits...
185 //points=fopen("points.dat","w");
187 AliRICHChamber* iChamber;
188 AliSegmentation* segmentation;
193 TObjArray *list=new TObjArray;
194 static TClonesArray *pAddress=0;
195 if(!pAddress) pAddress=new TClonesArray("TVector",1000);
198 AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH");
199 AliHitMap* pHitMap[10];
201 for (i=0; i<10; i++) {pHitMap[i]=0;}
207 // Get Hits Tree header from file
208 if(fHitsBgr) fHitsBgr->Clear();
209 if(fSDigitsBgr) fSDigitsBgr->Clear();
210 if(fTrH1) delete fTrH1;
214 sprintf(treeName,"TreeH%d",fEvNrBgr);
215 fTrH1 = (TTree*)gDirectory->Get(treeName);
217 printf("ERROR: cannot find Hits Tree for event:%d\n",fEvNrBgr);
220 // Set branch addresses
223 sprintf(branchname,"%s",pRICH->GetName());
224 if (fTrH1 && fHitsBgr) {
225 branch = fTrH1->GetBranch(branchname);
226 if (branch) branch->SetAddress(&fHitsBgr);
228 if (fTrH1 && fSDigitsBgr) {
229 branch = fTrH1->GetBranch("RICHSDigits");
230 if (branch) branch->SetAddress(&fSDigitsBgr);
237 for (i =0; i<kNCH; i++) {
238 iChamber= &(pRICH->Chamber(i));
239 segmentation=iChamber->GetSegmentationModel(1);
240 pHitMap[i] = new AliRICHHitMapA1(segmentation, list);
246 TTree *treeH = gAlice->TreeH();
247 Int_t ntracks =(Int_t) treeH->GetEntries();
248 for (Int_t track=0; track<ntracks; track++) {
250 treeH->GetEvent(track);
253 for(AliRICHHit* mHit=(AliRICHHit*)pRICH->FirstHit(-1);
255 mHit=(AliRICHHit*)pRICH->NextHit())
258 Int_t nch = mHit->fChamber-1; // chamber number
259 Int_t index = mHit->Track();
260 if (nch >kNCH) continue;
261 iChamber = &(pRICH->Chamber(nch));
263 TParticle *current = (TParticle*)gAlice->Particle(index);
265 if (current->GetPdgCode() >= 50000050)
267 TParticle *motherofcurrent = (TParticle*)gAlice->Particle(current->GetFirstMother());
268 particle = motherofcurrent->GetPdgCode();
272 particle = current->GetPdgCode();
276 //printf("Flag:%d\n",flag);
277 //printf("Track:%d\n",track);
278 //printf("Particle:%d\n",particle);
283 if(TMath::Abs(particle)==211 || TMath::Abs(particle)==111)
287 if(TMath::Abs(particle)==321 || TMath::Abs(particle)==130 || TMath::Abs(particle)==310
288 || TMath::Abs(particle)==311)
291 if (flag == 3 && TMath::Abs(particle)==2212)
294 if (flag == 4 && TMath::Abs(particle)==13)
297 if (flag == 5 && TMath::Abs(particle)==11)
300 if (flag == 6 && TMath::Abs(particle)==2112)
304 //printf ("Particle: %d, Flag: %d, Digitise: %d\n",particle,flag,digitise);
311 // Loop over pad hits
312 for (AliRICHSDigit* mPad=
313 (AliRICHSDigit*)pRICH->FirstPad(mHit,pRICH->SDigits());
315 mPad=(AliRICHSDigit*)pRICH->NextPad(pRICH->SDigits()))
317 Int_t ipx = mPad->fPadX; // pad number on X
318 Int_t ipy = mPad->fPadY; // pad number on Y
319 Int_t iqpad = mPad->fQpad; // charge per pad
322 //printf("X:%d, Y:%d, Q:%d\n",ipx,ipy,iqpad);
324 Float_t thex, they, thez;
325 segmentation=iChamber->GetSegmentationModel(0);
326 segmentation->GetPadC(ipx,ipy,thex,they,thez);
327 new((*pAddress)[countadr++]) TVector(2);
328 TVector &trinfo=*((TVector*) (*pAddress)[countadr-1]);
329 trinfo(0)=(Float_t)track;
330 trinfo(1)=(Float_t)iqpad;
336 AliRICHTransientDigit* pdigit;
337 // build the list of fired pads and update the info
338 if (!pHitMap[nch]->TestHit(ipx, ipy)) {
339 list->AddAtAndExpand(new AliRICHTransientDigit(nch,digits),counter);
340 pHitMap[nch]->SetHit(ipx, ipy, counter);
342 pdigit=(AliRICHTransientDigit*)list->At(list->GetLast());
344 TObjArray *trlist=(TObjArray*)pdigit->TrackList();
345 trlist->Add(&trinfo);
347 pdigit=(AliRICHTransientDigit*) pHitMap[nch]->GetHit(ipx, ipy);
349 (*pdigit).fSignal+=iqpad;
350 // update list of tracks
351 TObjArray* trlist=(TObjArray*)pdigit->TrackList();
352 Int_t lastEntry=trlist->GetLast();
353 TVector *ptrkP=(TVector*)trlist->At(lastEntry);
354 TVector &ptrk=*ptrkP;
355 Int_t lastTrack=Int_t(ptrk(0));
356 Int_t lastCharge=Int_t(ptrk(1));
357 if (lastTrack==track) {
359 trlist->RemoveAt(lastEntry);
361 trinfo(1)=lastCharge;
362 trlist->AddAt(&trinfo,lastEntry);
364 trlist->Add(&trinfo);
366 // check the track list
367 Int_t nptracks=trlist->GetEntriesFast();
369 printf("Attention - tracks: %d (>2)\n",nptracks);
370 //printf("cat,nch,ix,iy %d %d %d %d \n",icat+1,nch,ipx,ipy);
371 for (Int_t tr=0;tr<nptracks;tr++) {
372 TVector *pptrkP=(TVector*)trlist->At(tr);
373 TVector &pptrk=*pptrkP;
374 trk[tr]=Int_t(pptrk(0));
375 chtrk[tr]=Int_t(pptrk(1));
379 } //end loop over clusters
380 }// track type condition
384 // open the file with background
387 ntracks = (Int_t)fTrH1->GetEntries();
391 for (fTrack = 0; fTrack < ntracks; fTrack++) {
393 if (fHitsBgr) fHitsBgr->Clear();
394 if (fSDigitsBgr) fSDigitsBgr->Clear();
396 fTrH1->GetEvent(fTrack);
400 for(int i = 0; i < fHitsBgr->GetEntriesFast(); ++i)
402 mHit = (AliRICHHit*) (*fHitsBgr)[i];
403 fNch = mHit->Chamber()-1; // chamber number
404 iChamber = &(pRICH->Chamber(fNch));
405 //Float_t xbgr = mHit->X();
406 //Float_t ybgr = mHit->Y();
407 Bool_t cond = kFALSE;
410 // Loop over pad hits
411 for (AliRICHSDigit* mPad =
412 (AliRICHSDigit*)pRICH->FirstPad(mHit,fSDigitsBgr);
414 mPad = (AliRICHSDigit*)pRICH->NextPad(fSDigitsBgr))
416 Int_t ipx = mPad->PadX(); // pad number on X
417 Int_t ipy = mPad->PadY(); // pad number on Y
418 Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
420 new((*fAddress)[fCountadr++]) TVector(2);
421 TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]);
422 trinfo(0) = kBgTag; // tag background
429 // build the list of fired pads and update the info
435 } //end loop over clusters
439 TTree *fAli = gAlice->TreeK();
442 if (fAli) file = fAli->GetCurrentFile();
448 //cout<<"Start filling digits \n "<<endl;
449 Int_t nentries=list->GetEntriesFast();
450 //printf(" \n \n nentries %d \n",nentries);
452 // start filling the digits
454 for (Int_t nent=0;nent<nentries;nent++) {
455 AliRICHTransientDigit *address=(AliRICHTransientDigit*)list->At(nent);
456 if (address==0) continue;
458 Int_t ich=address->fChamber;
459 Int_t q=address->fSignal;
460 iChamber=&(pRICH->Chamber(ich));
461 AliRICHResponse * response=iChamber->GetResponseModel();
462 Int_t adcmax= (Int_t) response->MaxAdc();
465 // add white noise and do zero-suppression and signal truncation (new electronics,old electronics gaus 1.2,0.2)
466 //printf("Treshold: %d\n",iChamber->fTresh->GetHitIndex(address->fPadX,address->fPadY));
467 Int_t pedestal = iChamber->fTresh->GetHitIndex(address->fPadX,address->fPadY);
469 //printf("Pedestal:%d\n",pedestal);
471 Float_t treshold = (pedestal + 4*2.2);
473 Float_t meanNoise = gRandom->Gaus(2.2, 0.3);
474 Float_t noise = gRandom->Gaus(0, meanNoise);
475 q+=(Int_t)(noise + pedestal);
477 // magic number to be parametrised !!!
484 if ( q >= adcmax) q=adcmax;
485 digits[0]=address->fPadX;
486 digits[1]=address->fPadY;
489 TObjArray* trlist=(TObjArray*)address->TrackList();
490 Int_t nptracks=trlist->GetEntriesFast();
492 // this was changed to accomodate the real number of tracks
494 printf("Attention - tracks > 10 %d\n",nptracks);
498 printf("Attention - tracks > 2 %d \n",nptracks);
499 //printf("cat,ich,ix,iy,q %d %d %d %d %d \n",
500 //icat,ich,digits[0],digits[1],q);
502 for (Int_t tr=0;tr<nptracks;tr++) {
503 TVector *ppP=(TVector*)trlist->At(tr);
505 tracks[tr]=Int_t(pp(0));
506 charges[tr]=Int_t(pp(1));
507 } //end loop over list of tracks for one pad
508 if (nptracks < 10 ) {
509 for (Int_t t=nptracks; t<10; t++) {
516 //fprintf(points,"%4d, %4d, %4d\n",digits[0],digits[1],digits[2]);
519 pRICH->AddDigits(ich,tracks,charges,digits);
521 gAlice->TreeD()->Fill();
524 for(Int_t ii=0;ii<kNCH;++ii) {
532 //TTree *TD=gAlice->TreeD();
533 //Stat_t ndig=TD->GetEntries();
534 //cout<<"number of digits "<<ndig<<endl;
536 for (int k=0;k<kNCH;k++) {
537 fDch= pRICH->DigitsAddress(k);
538 int ndigit=fDch->GetEntriesFast();
539 printf ("Chamber %d digits %d \n",k,ndigit);
541 pRICH->ResetDigits();
543 // sprintf(hname,"TreeD%d",nev);
544 // gAlice->TreeD()->Write(hname);
545 gAlice->TreeD()->Write(0,TObject::kOverwrite);
547 // gAlice->TreeD()->Reset();
550 // gObjectTable->Print();