]>
Commit | Line | Data |
---|---|---|
d8a72780 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-2000, 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$ | |
18 | */ | |
19 | ||
20 | #include <TTree.h> | |
21 | #include <TVector.h> | |
22 | #include <TObjArray.h> | |
23 | #include <TFile.h> | |
24 | #include <TDirectory.h> | |
25 | #include <TParticle.h> | |
26 | ||
27 | ||
28 | // #include "AliMerger.h" | |
29 | // #include "AliMergable.h" | |
30 | #include "AliRICHMerger.h" | |
31 | #include "AliRICHChamber.h" | |
32 | #include "AliHitMap.h" | |
33 | #include "AliRICHHitMapA1.h" | |
34 | #include "AliRICH.h" | |
35 | #include "AliRICHHit.h" | |
36 | #include "AliRICHSDigit.h" | |
37 | #include "AliRICHDigit.h" | |
38 | #include "AliRICHTransientDigit.h" | |
39 | #include "AliRun.h" | |
40 | #include "AliPDG.h" | |
41 | ||
42 | ClassImp(AliRICHMerger) | |
43 | ||
44 | //___________________________________________ | |
45 | AliRICHMerger::AliRICHMerger() | |
46 | { | |
47 | // Default constructor | |
48 | fEvNrSig = 0; | |
49 | fEvNrBgr = 0; | |
50 | fMerge = kDigitize; | |
51 | fFnBgr = 0; | |
52 | fHitMap = 0; | |
53 | fList = 0; | |
54 | fTrH1 = 0; | |
55 | fHitsBgr = 0; | |
56 | fSDigitsBgr = 0; | |
57 | fHitMap = 0; | |
58 | fList = 0; | |
59 | fTrList = 0; | |
60 | fAddress = 0; | |
61 | } | |
62 | ||
63 | //------------------------------------------------------------------------ | |
64 | AliRICHMerger::~AliRICHMerger() | |
65 | { | |
66 | // Destructor | |
67 | if (fTrH1) delete fTrH1; | |
68 | if (fHitsBgr) delete fHitsBgr; | |
69 | if (fSDigitsBgr) delete fSDigitsBgr; | |
70 | if (fHitMap) delete fHitMap; | |
71 | if (fList) delete fList; | |
72 | if (fTrList) delete fTrList; | |
73 | if (fAddress) delete fAddress; | |
74 | } | |
75 | ||
76 | //------------------------------------------------------------------------ | |
77 | Bool_t AliRICHMerger::Exists(const AliRICHSDigit *mergable) | |
78 | { | |
79 | AliRICHSDigit *padhit = (AliRICHSDigit*) mergable; | |
80 | return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY())); | |
81 | } | |
82 | ||
83 | //------------------------------------------------------------------------ | |
84 | void AliRICHMerger::Update(AliRICHSDigit *mergable) | |
85 | { | |
86 | AliRICHSDigit *padhit = (AliRICHSDigit*) mergable; | |
87 | AliRICHTransientDigit* pdigit; | |
88 | Int_t ipx = padhit->PadX(); // pad number on X | |
89 | Int_t ipy = padhit->PadY(); // pad number on Y | |
90 | Int_t iqpad = Int_t(padhit->QPad()); // charge per pad | |
91 | ||
92 | pdigit = (AliRICHTransientDigit*) fHitMap[fNch]->GetHit(ipx, ipy); | |
93 | // update charge | |
94 | // | |
95 | (*pdigit).AddSignal(iqpad); | |
96 | (*pdigit).AddPhysicsSignal(iqpad); | |
97 | // update list of tracks | |
98 | // | |
99 | TObjArray* fTrList = (TObjArray*)pdigit->TrackList(); | |
100 | Int_t lastEntry = fTrList->GetLast(); | |
101 | TVector *pTrack = (TVector*)fTrList->At(lastEntry); | |
102 | TVector &ptrk = *pTrack; | |
103 | TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]); | |
104 | Int_t lastTrack = Int_t(ptrk(0)); | |
105 | ||
106 | if (trinfo(0) != kBgTag) { | |
107 | if (lastTrack == fTrack) { | |
108 | Int_t lastCharge = Int_t(ptrk(1)); | |
109 | lastCharge += iqpad; | |
110 | fTrList->RemoveAt(lastEntry); | |
111 | trinfo(1) = lastCharge; | |
112 | fTrList->AddAt(&trinfo,lastEntry); | |
113 | } else { | |
114 | fTrList->Add(&trinfo); | |
115 | } | |
116 | } else { | |
117 | if (lastTrack != -1) fTrList->Add(&trinfo); | |
118 | } | |
119 | } | |
120 | ||
121 | //------------------------------------------------------------------------ | |
122 | void AliRICHMerger::CreateNew(AliRICHSDigit *mergable) | |
123 | { | |
124 | AliRICHSDigit *padhit = (AliRICHSDigit*) mergable; | |
125 | AliRICHTransientDigit* pdigit; | |
126 | ||
127 | Int_t ipx = padhit->PadX(); // pad number on X | |
128 | Int_t ipy = padhit->PadY(); // pad number on Y | |
129 | fList->AddAtAndExpand( | |
130 | new AliRICHTransientDigit(fNch,fDigits),fCounter); | |
131 | fHitMap[fNch]->SetHit(ipx, ipy, fCounter); | |
132 | fCounter++; | |
133 | pdigit = (AliRICHTransientDigit*)fList->At(fList->GetLast()); | |
134 | // list of tracks | |
135 | TObjArray *fTrList = (TObjArray*)pdigit->TrackList(); | |
136 | TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]); | |
137 | fTrList->Add(&trinfo); | |
138 | } | |
139 | ||
140 | ||
141 | //------------------------------------------------------------------------ | |
142 | void AliRICHMerger::Init() | |
143 | { | |
144 | // Initialisation | |
145 | ||
146 | if (fMerge) fBgrFile = InitBgr(); | |
147 | } | |
148 | ||
149 | ||
150 | ||
151 | //------------------------------------------------------------------------ | |
152 | TFile* AliRICHMerger::InitBgr() | |
153 | { | |
154 | // Initialise background event | |
155 | TFile *file = new TFile(fFnBgr); | |
156 | // add error checking later | |
157 | printf("\n AliRICHMerger has opened %s file with background event \n", fFnBgr); | |
158 | fHitsBgr = new TClonesArray("AliRICHHit",1000); | |
159 | fSDigitsBgr = new TClonesArray("AliRICHSDigit",1000); | |
160 | return file; | |
161 | } | |
162 | ||
163 | //------------------------------------------------------------------------ | |
164 | void AliRICHMerger::Digitise(Int_t nev, Int_t flag) | |
165 | { | |
166 | ||
167 | // keep galice.root for signal and name differently the file for | |
168 | // background when add! otherwise the track info for signal will be lost ! | |
169 | ||
170 | Int_t particle; | |
171 | ||
172 | FILE* points; //these will be the digits... | |
173 | ||
174 | points=fopen("points.dat","w"); | |
175 | ||
176 | AliRICHChamber* iChamber; | |
177 | AliSegmentation* segmentation; | |
178 | ||
179 | Int_t digitise=0; | |
180 | Int_t trk[50]; | |
181 | Int_t chtrk[50]; | |
182 | TObjArray *list=new TObjArray; | |
183 | static TClonesArray *pAddress=0; | |
184 | if(!pAddress) pAddress=new TClonesArray("TVector",1000); | |
185 | Int_t digits[5]; | |
186 | ||
187 | AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH"); | |
188 | AliHitMap* pHitMap[10]; | |
189 | Int_t i; | |
190 | for (i=0; i<10; i++) {pHitMap[i]=0;} | |
191 | ||
192 | if (fMerge ) { | |
193 | fBgrFile->cd(); | |
194 | fBgrFile->ls(); | |
195 | // | |
196 | // Get Hits Tree header from file | |
197 | if(fHitsBgr) fHitsBgr->Clear(); | |
198 | if(fSDigitsBgr) fSDigitsBgr->Clear(); | |
199 | if(fTrH1) delete fTrH1; | |
200 | fTrH1 = 0; | |
201 | ||
202 | char treeName[20]; | |
203 | sprintf(treeName,"TreeH%d",fEvNrBgr); | |
204 | fTrH1 = (TTree*)gDirectory->Get(treeName); | |
205 | if (!fTrH1) { | |
206 | printf("ERROR: cannot find Hits Tree for event:%d\n",fEvNrBgr); | |
207 | } | |
208 | // | |
209 | // Set branch addresses | |
210 | TBranch *branch; | |
211 | char branchname[20]; | |
212 | sprintf(branchname,"%s",pRICH->GetName()); | |
213 | if (fTrH1 && fHitsBgr) { | |
214 | branch = fTrH1->GetBranch(branchname); | |
215 | if (branch) branch->SetAddress(&fHitsBgr); | |
216 | } | |
217 | if (fTrH1 && fSDigitsBgr) { | |
218 | branch = fTrH1->GetBranch("MUONCluster"); | |
219 | if (branch) branch->SetAddress(&fSDigitsBgr); | |
220 | } | |
221 | } | |
222 | ||
223 | AliHitMap* hm; | |
224 | Int_t countadr=0; | |
225 | Int_t counter=0; | |
226 | for (i =0; i<kNCH; i++) { | |
227 | iChamber= &(pRICH->Chamber(i)); | |
228 | segmentation=iChamber->GetSegmentationModel(1); | |
229 | pHitMap[i] = new AliRICHHitMapA1(segmentation, list); | |
230 | } | |
231 | // | |
232 | // Loop over tracks | |
233 | // | |
234 | ||
235 | TTree *treeH = gAlice->TreeH(); | |
236 | Int_t ntracks =(Int_t) treeH->GetEntries(); | |
237 | for (Int_t track=0; track<ntracks; track++) { | |
238 | gAlice->ResetHits(); | |
239 | treeH->GetEvent(track); | |
240 | // | |
241 | // Loop over hits | |
242 | for(AliRICHHit* mHit=(AliRICHHit*)pRICH->FirstHit(-1); | |
243 | mHit; | |
244 | mHit=(AliRICHHit*)pRICH->NextHit()) | |
245 | { | |
246 | ||
247 | Int_t nch = mHit->fChamber-1; // chamber number | |
248 | Int_t index = mHit->Track(); | |
249 | if (nch >kNCH) continue; | |
250 | iChamber = &(pRICH->Chamber(nch)); | |
251 | ||
252 | TParticle *current = (TParticle*)gAlice->Particle(index); | |
253 | ||
254 | if (current->GetPdgCode() >= 50000050) | |
255 | { | |
256 | TParticle *motherofcurrent = (TParticle*)gAlice->Particle(current->GetFirstMother()); | |
257 | particle = motherofcurrent->GetPdgCode(); | |
258 | } | |
259 | else | |
260 | { | |
261 | particle = current->GetPdgCode(); | |
262 | } | |
263 | ||
264 | ||
265 | //printf("Flag:%d\n",flag); | |
266 | //printf("Track:%d\n",track); | |
267 | //printf("Particle:%d\n",particle); | |
268 | ||
269 | digitise=1; | |
270 | ||
271 | if (flag == 1) | |
272 | if(TMath::Abs(particle)==211 || TMath::Abs(particle)==111) | |
273 | digitise=0; | |
274 | ||
275 | if (flag == 2) | |
276 | if(TMath::Abs(particle)==321 || TMath::Abs(particle)==130 || TMath::Abs(particle)==310 | |
277 | || TMath::Abs(particle)==311) | |
278 | digitise=0; | |
279 | ||
280 | if (flag == 3 && TMath::Abs(particle)==2212) | |
281 | digitise=0; | |
282 | ||
283 | if (flag == 4 && TMath::Abs(particle)==13) | |
284 | digitise=0; | |
285 | ||
286 | if (flag == 5 && TMath::Abs(particle)==11) | |
287 | digitise=0; | |
288 | ||
289 | if (flag == 6 && TMath::Abs(particle)==2112) | |
290 | digitise=0; | |
291 | ||
292 | ||
293 | //printf ("Particle: %d, Flag: %d, Digitise: %d\n",particle,flag,digitise); | |
294 | ||
295 | ||
296 | if (digitise) | |
297 | { | |
298 | ||
299 | // | |
300 | // Loop over pad hits | |
301 | for (AliRICHSDigit* mPad= | |
302 | (AliRICHSDigit*)pRICH->FirstPad(mHit,pRICH->SDigits()); | |
303 | mPad; | |
304 | mPad=(AliRICHSDigit*)pRICH->NextPad(pRICH->SDigits())) | |
305 | { | |
306 | Int_t ipx = mPad->fPadX; // pad number on X | |
307 | Int_t ipy = mPad->fPadY; // pad number on Y | |
308 | Int_t iqpad = mPad->fQpad; // charge per pad | |
309 | // | |
310 | // | |
311 | //printf("X:%d, Y:%d, Q:%d\n",ipx,ipy,iqpad); | |
312 | ||
313 | Float_t thex, they, thez; | |
314 | segmentation=iChamber->GetSegmentationModel(0); | |
315 | segmentation->GetPadC(ipx,ipy,thex,they,thez); | |
316 | new((*pAddress)[countadr++]) TVector(2); | |
317 | TVector &trinfo=*((TVector*) (*pAddress)[countadr-1]); | |
318 | trinfo(0)=(Float_t)track; | |
319 | trinfo(1)=(Float_t)iqpad; | |
320 | ||
321 | digits[0]=ipx; | |
322 | digits[1]=ipy; | |
323 | digits[2]=iqpad; | |
324 | ||
325 | AliRICHTransientDigit* pdigit; | |
326 | // build the list of fired pads and update the info | |
327 | if (!pHitMap[nch]->TestHit(ipx, ipy)) { | |
328 | list->AddAtAndExpand(new AliRICHTransientDigit(nch,digits),counter); | |
329 | pHitMap[nch]->SetHit(ipx, ipy, counter); | |
330 | counter++; | |
331 | pdigit=(AliRICHTransientDigit*)list->At(list->GetLast()); | |
332 | // list of tracks | |
333 | TObjArray *trlist=(TObjArray*)pdigit->TrackList(); | |
334 | trlist->Add(&trinfo); | |
335 | } else { | |
336 | pdigit=(AliRICHTransientDigit*) pHitMap[nch]->GetHit(ipx, ipy); | |
337 | // update charge | |
338 | (*pdigit).fSignal+=iqpad; | |
339 | // update list of tracks | |
340 | TObjArray* trlist=(TObjArray*)pdigit->TrackList(); | |
341 | Int_t lastEntry=trlist->GetLast(); | |
342 | TVector *ptrkP=(TVector*)trlist->At(lastEntry); | |
343 | TVector &ptrk=*ptrkP; | |
344 | Int_t lastTrack=Int_t(ptrk(0)); | |
345 | Int_t lastCharge=Int_t(ptrk(1)); | |
346 | if (lastTrack==track) { | |
347 | lastCharge+=iqpad; | |
348 | trlist->RemoveAt(lastEntry); | |
349 | trinfo(0)=lastTrack; | |
350 | trinfo(1)=lastCharge; | |
351 | trlist->AddAt(&trinfo,lastEntry); | |
352 | } else { | |
353 | trlist->Add(&trinfo); | |
354 | } | |
355 | // check the track list | |
356 | Int_t nptracks=trlist->GetEntriesFast(); | |
357 | if (nptracks > 2) { | |
358 | printf("Attention - tracks: %d (>2)\n",nptracks); | |
359 | //printf("cat,nch,ix,iy %d %d %d %d \n",icat+1,nch,ipx,ipy); | |
360 | for (Int_t tr=0;tr<nptracks;tr++) { | |
361 | TVector *pptrkP=(TVector*)trlist->At(tr); | |
362 | TVector &pptrk=*pptrkP; | |
363 | trk[tr]=Int_t(pptrk(0)); | |
364 | chtrk[tr]=Int_t(pptrk(1)); | |
365 | } | |
366 | } // end if nptracks | |
367 | } // end if pdigit | |
368 | } //end loop over clusters | |
369 | }// track type condition | |
370 | } // hit loop | |
371 | } // track loop | |
372 | ||
373 | // open the file with background | |
374 | ||
375 | if (fMerge) { | |
376 | ntracks = (Int_t)fTrH1->GetEntries(); | |
377 | // | |
378 | // Loop over tracks | |
379 | // | |
380 | for (fTrack = 0; fTrack < ntracks; fTrack++) { | |
381 | ||
382 | if (fHitsBgr) fHitsBgr->Clear(); | |
383 | if (fSDigitsBgr) fSDigitsBgr->Clear(); | |
384 | ||
385 | fTrH1->GetEvent(fTrack); | |
386 | // | |
387 | // Loop over hits | |
388 | AliRICHHit* mHit; | |
389 | for(int i = 0; i < fHitsBgr->GetEntriesFast(); ++i) | |
390 | { | |
391 | mHit = (AliRICHHit*) (*fHitsBgr)[i]; | |
392 | fNch = mHit->Chamber()-1; // chamber number | |
393 | iChamber = &(pRICH->Chamber(fNch)); | |
394 | //Float_t xbgr = mHit->X(); | |
395 | //Float_t ybgr = mHit->Y(); | |
396 | Bool_t cond = kFALSE; | |
397 | cond = kTRUE; | |
398 | // | |
399 | // Loop over pad hits | |
400 | for (AliRICHSDigit* mPad = | |
401 | (AliRICHSDigit*)pRICH->FirstPad(mHit,fSDigitsBgr); | |
402 | mPad; | |
403 | mPad = (AliRICHSDigit*)pRICH->NextPad(fSDigitsBgr)) | |
404 | { | |
405 | Int_t ipx = mPad->PadX(); // pad number on X | |
406 | Int_t ipy = mPad->PadY(); // pad number on Y | |
407 | Int_t iqpad = Int_t(mPad->QPad()); // charge per pad | |
408 | ||
409 | new((*fAddress)[fCountadr++]) TVector(2); | |
410 | TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]); | |
411 | trinfo(0) = kBgTag; // tag background | |
412 | trinfo(1) = kBgTag; | |
413 | ||
414 | fDigits[0] = ipx; | |
415 | fDigits[1] = ipy; | |
416 | fDigits[3] = iqpad; | |
417 | ||
418 | // build the list of fired pads and update the info | |
419 | if (!Exists(mPad)) { | |
420 | CreateNew(mPad); | |
421 | } else { | |
422 | Update(mPad); | |
423 | } // end if !Exists | |
424 | } //end loop over clusters | |
425 | } // hit loop | |
426 | } // track loop | |
427 | ||
428 | TTree *fAli = gAlice->TreeK(); | |
429 | TFile *file = NULL; | |
430 | ||
431 | if (fAli) file = fAli->GetCurrentFile(); | |
432 | file->cd(); | |
433 | } // if fMerge | |
434 | ||
435 | Int_t tracks[10]; | |
436 | Int_t charges[10]; | |
437 | //cout<<"Start filling digits \n "<<endl; | |
438 | Int_t nentries=list->GetEntriesFast(); | |
439 | //printf(" \n \n nentries %d \n",nentries); | |
440 | ||
441 | // start filling the digits | |
442 | ||
443 | for (Int_t nent=0;nent<nentries;nent++) { | |
444 | AliRICHTransientDigit *address=(AliRICHTransientDigit*)list->At(nent); | |
445 | if (address==0) continue; | |
446 | ||
447 | Int_t ich=address->fChamber; | |
448 | Int_t q=address->fSignal; | |
449 | iChamber=&(pRICH->Chamber(ich)); | |
450 | AliRICHResponse * response=iChamber->GetResponseModel(); | |
451 | Int_t adcmax= (Int_t) response->MaxAdc(); | |
452 | ||
453 | ||
454 | // add white noise and do zero-suppression and signal truncation (new electronics,old electronics gaus 1.2,0.2) | |
455 | //printf("Treshold: %d\n",iChamber->fTresh->GetHitIndex(address->fPadX,address->fPadY)); | |
456 | Int_t pedestal = iChamber->fTresh->GetHitIndex(address->fPadX,address->fPadY); | |
457 | ||
458 | //printf("Pedestal:%d\n",pedestal); | |
459 | //Int_t pedestal=0; | |
460 | Float_t treshold = (pedestal + 4*2.2); | |
461 | ||
462 | Float_t meanNoise = gRandom->Gaus(2.2, 0.3); | |
463 | Float_t noise = gRandom->Gaus(0, meanNoise); | |
464 | q+=(Int_t)(noise + pedestal); | |
465 | //q+=(Int_t)(noise); | |
466 | // magic number to be parametrised !!! | |
467 | if ( q <= treshold) | |
468 | { | |
469 | q = q - pedestal; | |
470 | continue; | |
471 | } | |
472 | q = q - pedestal; | |
473 | if ( q >= adcmax) q=adcmax; | |
474 | digits[0]=address->fPadX; | |
475 | digits[1]=address->fPadY; | |
476 | digits[2]=q; | |
477 | ||
478 | TObjArray* trlist=(TObjArray*)address->TrackList(); | |
479 | Int_t nptracks=trlist->GetEntriesFast(); | |
480 | ||
481 | // this was changed to accomodate the real number of tracks | |
482 | if (nptracks > 10) { | |
483 | printf("Attention - tracks > 10 %d\n",nptracks); | |
484 | nptracks=10; | |
485 | } | |
486 | if (nptracks > 2) { | |
487 | printf("Attention - tracks > 2 %d \n",nptracks); | |
488 | //printf("cat,ich,ix,iy,q %d %d %d %d %d \n", | |
489 | //icat,ich,digits[0],digits[1],q); | |
490 | } | |
491 | for (Int_t tr=0;tr<nptracks;tr++) { | |
492 | TVector *ppP=(TVector*)trlist->At(tr); | |
493 | TVector &pp =*ppP; | |
494 | tracks[tr]=Int_t(pp(0)); | |
495 | charges[tr]=Int_t(pp(1)); | |
496 | } //end loop over list of tracks for one pad | |
497 | if (nptracks < 10 ) { | |
498 | for (Int_t t=nptracks; t<10; t++) { | |
499 | tracks[t]=0; | |
500 | charges[t]=0; | |
501 | } | |
502 | } | |
503 | //write file | |
504 | if (ich==2) | |
505 | fprintf(points,"%4d, %4d, %4d\n",digits[0],digits[1],digits[2]); | |
506 | ||
507 | // fill digits | |
508 | pRICH->AddDigits(ich,tracks,charges,digits); | |
509 | } | |
510 | gAlice->TreeD()->Fill(); | |
511 | ||
512 | list->Delete(); | |
513 | for(Int_t ii=0;ii<kNCH;++ii) { | |
514 | if (pHitMap[ii]) { | |
515 | hm=pHitMap[ii]; | |
516 | delete hm; | |
517 | pHitMap[ii]=0; | |
518 | } | |
519 | } | |
520 | ||
521 | //TTree *TD=gAlice->TreeD(); | |
522 | //Stat_t ndig=TD->GetEntries(); | |
523 | //cout<<"number of digits "<<ndig<<endl; | |
524 | TClonesArray *fDch; | |
525 | for (int k=0;k<kNCH;k++) { | |
526 | fDch= pRICH->DigitsAddress(k); | |
527 | int ndigit=fDch->GetEntriesFast(); | |
528 | printf ("Chamber %d digits %d \n",k,ndigit); | |
529 | } | |
530 | pRICH->ResetDigits(); | |
531 | char hname[30]; | |
532 | sprintf(hname,"TreeD%d",nev); | |
533 | gAlice->TreeD()->Write(hname); | |
534 | ||
535 | // reset tree | |
536 | // gAlice->TreeD()->Reset(); | |
537 | delete list; | |
538 | pAddress->Clear(); | |
539 | // gObjectTable->Print(); | |
540 | ||
541 | } | |
542 | ||
543 | ||
544 | ||
545 | ||
546 |