]>
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$ | |
31eeed4f | 18 | Revision 1.5 2001/10/23 13:03:35 hristov |
19 | The access to several data members was changed from public to protected. The digitisation was adapted to the multi-event case (J.Chudoba) | |
20 | ||
6e585aa2 | 21 | Revision 1.4 2001/10/21 18:31:24 hristov |
22 | Several pointers were set to zero in the default constructors to avoid memory management problems | |
23 | ||
2685bf00 | 24 | Revision 1.3 2001/05/16 14:57:20 alibrary |
25 | New files for folders and Stack | |
26 | ||
9e1a0ddb | 27 | Revision 1.2 2001/03/14 18:16:08 jbarbosa |
28 | Corrected bug (more to correct). | |
29 | File "points.dat" is no longer created. | |
30 | ||
14886cb7 | 31 | Revision 1.1 2001/02/27 22:13:34 jbarbosa |
32 | Implementing merger class. | |
33 | ||
d8a72780 | 34 | */ |
b762c2f6 | 35 | #include <iostream> |
d8a72780 | 36 | |
37 | #include <TTree.h> | |
d8a72780 | 38 | #include <TObjArray.h> |
39 | #include <TFile.h> | |
40 | #include <TDirectory.h> | |
41 | #include <TParticle.h> | |
42 | ||
d8a72780 | 43 | #include "AliRICHMerger.h" |
44 | #include "AliRICHChamber.h" | |
45 | #include "AliHitMap.h" | |
46 | #include "AliRICHHitMapA1.h" | |
47 | #include "AliRICH.h" | |
48 | #include "AliRICHHit.h" | |
49 | #include "AliRICHSDigit.h" | |
50 | #include "AliRICHDigit.h" | |
51 | #include "AliRICHTransientDigit.h" | |
52 | #include "AliRun.h" | |
53 | #include "AliPDG.h" | |
54 | ||
55 | ClassImp(AliRICHMerger) | |
56 | ||
57 | //___________________________________________ | |
b762c2f6 | 58 | AliRICHMerger::AliRICHMerger() |
d8a72780 | 59 | { |
60 | // Default constructor | |
b762c2f6 | 61 | fEvNrSig = 0; |
62 | fEvNrBgr = 0; | |
63 | fMerge = kDigitize; | |
64 | fFnBgr = 0; | |
65 | fHitMap = 0; | |
66 | fList = 0; | |
67 | fTrH1 = 0; | |
68 | fHitsBgr = 0; | |
69 | fSDigitsBgr = 0; | |
70 | fHitMap = 0; | |
71 | fList = 0; | |
72 | fBgrFile = 0; | |
d8a72780 | 73 | } |
74 | ||
75 | //------------------------------------------------------------------------ | |
76 | AliRICHMerger::~AliRICHMerger() | |
77 | { | |
78 | // Destructor | |
b762c2f6 | 79 | if (fTrH1) delete fTrH1; |
80 | if (fHitsBgr) delete fHitsBgr; | |
81 | if (fSDigitsBgr) delete fSDigitsBgr; | |
82 | if (fHitMap) delete fHitMap; | |
83 | if (fList) delete fList; | |
84 | if (fBgrFile) delete fBgrFile; | |
d8a72780 | 85 | } |
86 | ||
87 | //------------------------------------------------------------------------ | |
b762c2f6 | 88 | Bool_t AliRICHMerger::Exists(const AliRICHSDigit *padhit) |
d8a72780 | 89 | { |
b762c2f6 | 90 | return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY())); |
d8a72780 | 91 | } |
92 | ||
93 | //------------------------------------------------------------------------ | |
b762c2f6 | 94 | void AliRICHMerger::Update(AliRICHSDigit *padhit) |
d8a72780 | 95 | { |
b762c2f6 | 96 | AliRICHTransientDigit *pdigit = |
97 | static_cast<AliRICHTransientDigit*>( | |
98 | fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY())); | |
99 | ||
100 | // update charge | |
101 | // | |
102 | Int_t iqpad = Int_t(padhit->QPad()); // charge per pad | |
103 | pdigit->AddSignal(iqpad); | |
104 | pdigit->AddPhysicsSignal(iqpad); | |
105 | ||
106 | // update list of tracks | |
107 | // | |
108 | Int_t track, charge; | |
109 | if (fSignal) { | |
110 | track = fTrack; | |
111 | charge = iqpad; | |
112 | } else { | |
113 | track = kBgTag; | |
114 | charge = kBgTag; | |
115 | } | |
116 | pdigit->UpdateTrackList(track,charge); | |
d8a72780 | 117 | } |
118 | ||
119 | //------------------------------------------------------------------------ | |
b762c2f6 | 120 | void AliRICHMerger::CreateNew(AliRICHSDigit *padhit) |
d8a72780 | 121 | { |
b762c2f6 | 122 | fList->AddAtAndExpand( |
123 | new AliRICHTransientDigit(fNch,fDigits),fCounter); | |
124 | fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter); | |
125 | ||
126 | AliRICHTransientDigit* pdigit = | |
127 | static_cast<AliRICHTransientDigit*>(fList->Last()); | |
128 | // list of tracks | |
129 | Int_t track, charge; | |
130 | if (fSignal) { | |
131 | track = fTrack; | |
132 | charge = padhit->QPad(); | |
133 | } else { | |
134 | track = kBgTag; | |
135 | charge = kBgTag; | |
136 | } | |
137 | pdigit->AddToTrackList(track,charge); | |
138 | fCounter++; | |
d8a72780 | 139 | } |
140 | ||
141 | ||
142 | //------------------------------------------------------------------------ | |
143 | void AliRICHMerger::Init() | |
144 | { | |
145 | // Initialisation | |
146 | ||
b762c2f6 | 147 | if (fMerge && !fBgrFile) fBgrFile = InitBgr(); |
d8a72780 | 148 | } |
149 | ||
150 | ||
151 | ||
152 | //------------------------------------------------------------------------ | |
153 | TFile* AliRICHMerger::InitBgr() | |
154 | { | |
155 | // Initialise background event | |
b762c2f6 | 156 | TFile *file = new TFile(fFnBgr); |
d8a72780 | 157 | // add error checking later |
b762c2f6 | 158 | printf("\n AliRICHMerger has opened %s file with background event \n", fFnBgr); |
159 | fHitsBgr = new TClonesArray("AliRICHHit",1000); | |
160 | fSDigitsBgr = new TClonesArray("AliRICHSDigit",1000); | |
161 | return file; | |
d8a72780 | 162 | } |
163 | ||
164 | //------------------------------------------------------------------------ | |
165 | void AliRICHMerger::Digitise(Int_t nev, Int_t flag) | |
166 | { | |
167 | ||
b762c2f6 | 168 | // keep galice.root for signal and name differently the file for |
169 | // background when add! otherwise the track info for signal will be lost ! | |
d8a72780 | 170 | |
171 | Int_t particle; | |
172 | ||
d8a72780 | 173 | AliRICHChamber* iChamber; |
174 | AliSegmentation* segmentation; | |
175 | ||
b762c2f6 | 176 | fList = new TObjArray; |
d8a72780 | 177 | |
b762c2f6 | 178 | AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH"); |
179 | fHitMap= new AliHitMap* [kNCH]; | |
d8a72780 | 180 | |
b762c2f6 | 181 | if (fMerge ) { |
182 | fBgrFile->cd(); | |
183 | // | |
184 | // Get Hits Tree header from file | |
185 | if(fHitsBgr) fHitsBgr->Clear(); | |
186 | if(fSDigitsBgr) fSDigitsBgr->Clear(); | |
187 | if(fTrH1) delete fTrH1; | |
188 | fTrH1 = 0; | |
d8a72780 | 189 | |
b762c2f6 | 190 | char treeName[20]; |
191 | sprintf(treeName,"TreeH%d",fEvNrBgr); | |
192 | fTrH1 = (TTree*)gDirectory->Get(treeName); | |
193 | if (!fTrH1) { | |
194 | printf("ERROR: cannot find Hits Tree for event:%d\n",fEvNrBgr); | |
d8a72780 | 195 | } |
d8a72780 | 196 | // |
b762c2f6 | 197 | // Set branch addresses |
198 | TBranch *branch; | |
199 | char branchname[20]; | |
200 | sprintf(branchname,"%s",pRICH->GetName()); | |
201 | if (fTrH1 && fHitsBgr) { | |
202 | branch = fTrH1->GetBranch(branchname); | |
203 | if (branch) branch->SetAddress(&fHitsBgr); | |
204 | } | |
205 | if (fTrH1 && fSDigitsBgr) { | |
206 | branch = fTrH1->GetBranch("RICHSDigits"); | |
207 | if (branch) branch->SetAddress(&fSDigitsBgr); | |
208 | } | |
209 | } | |
d8a72780 | 210 | |
b762c2f6 | 211 | for (Int_t i =0; i<kNCH; i++) { |
212 | iChamber= &(pRICH->Chamber(i)); | |
213 | segmentation=iChamber->GetSegmentationModel(1); | |
214 | fHitMap[i] = new AliRICHHitMapA1(segmentation, fList); | |
215 | } | |
216 | // | |
217 | // Loop over tracks | |
218 | // | |
219 | ||
220 | fSignal = kTRUE; | |
221 | fCounter = 0; | |
222 | TTree *treeH = gAlice->TreeH(); | |
223 | Int_t ntracks =(Int_t) treeH->GetEntries(); | |
224 | for (fTrack=0; fTrack<ntracks; fTrack++) { | |
225 | gAlice->ResetHits(); | |
226 | treeH->GetEvent(fTrack); | |
227 | // | |
228 | // Loop over hits | |
229 | for(AliRICHHit* mHit=(AliRICHHit*)pRICH->FirstHit(-1); | |
230 | mHit; | |
231 | mHit=(AliRICHHit*)pRICH->NextHit()) | |
232 | { | |
d8a72780 | 233 | |
b762c2f6 | 234 | fNch = mHit->Chamber()-1; // chamber number |
235 | Int_t trackIndex = mHit->Track(); | |
236 | if (fNch >= kNCH) { | |
237 | cerr<<"AliRICHMerger: chamber nr. fNch out of range: "<<fNch<<endl; | |
238 | cerr<<" track: "<<fTrack<<endl; | |
239 | continue; | |
240 | } | |
241 | iChamber = &(pRICH->Chamber(fNch)); | |
d8a72780 | 242 | |
b762c2f6 | 243 | |
244 | // | |
245 | // If flag is set, create digits only for some particles | |
246 | // | |
247 | TParticle *current = (TParticle*)gAlice->Particle(trackIndex); | |
248 | if (current->GetPdgCode() >= 50000050) | |
249 | { | |
250 | TParticle *motherofcurrent = (TParticle*)gAlice->Particle(current->GetFirstMother()); | |
251 | particle = motherofcurrent->GetPdgCode(); | |
252 | } | |
253 | else | |
254 | { | |
255 | particle = current->GetPdgCode(); | |
256 | } | |
d8a72780 | 257 | |
258 | ||
b762c2f6 | 259 | //printf("Flag:%d\n",flag); |
260 | //printf("Track:%d\n",track); | |
261 | //printf("Particle:%d\n",particle); | |
d8a72780 | 262 | |
b762c2f6 | 263 | Int_t digitise=1; |
d8a72780 | 264 | |
b762c2f6 | 265 | if (flag == 1) |
266 | if(TMath::Abs(particle)==211 || TMath::Abs(particle)==111) | |
267 | digitise=0; | |
d8a72780 | 268 | |
b762c2f6 | 269 | if (flag == 2) |
270 | if(TMath::Abs(particle)==321 || TMath::Abs(particle)==130 || TMath::Abs(particle)==310 | |
271 | || TMath::Abs(particle)==311) | |
272 | digitise=0; | |
d8a72780 | 273 | |
b762c2f6 | 274 | if (flag == 3 && TMath::Abs(particle)==2212) |
275 | digitise=0; | |
d8a72780 | 276 | |
b762c2f6 | 277 | if (flag == 4 && TMath::Abs(particle)==13) |
278 | digitise=0; | |
d8a72780 | 279 | |
b762c2f6 | 280 | if (flag == 5 && TMath::Abs(particle)==11) |
281 | digitise=0; | |
d8a72780 | 282 | |
b762c2f6 | 283 | if (flag == 6 && TMath::Abs(particle)==2112) |
284 | digitise=0; | |
d8a72780 | 285 | |
286 | ||
b762c2f6 | 287 | //printf ("Particle: %d, Flag: %d, Digitise: %d\n",particle,flag,digitise); |
d8a72780 | 288 | |
289 | ||
b762c2f6 | 290 | if (digitise) |
291 | { | |
d8a72780 | 292 | |
b762c2f6 | 293 | // |
294 | // Loop over pad hits | |
295 | for (AliRICHSDigit* mPad= | |
296 | (AliRICHSDigit*)pRICH->FirstPad(mHit,pRICH->SDigits()); | |
297 | mPad; | |
298 | mPad=(AliRICHSDigit*)pRICH->NextPad(pRICH->SDigits())) | |
299 | { | |
300 | Int_t iqpad = mPad->QPad(); // charge per pad | |
301 | fDigits[0]=mPad->PadX(); | |
302 | fDigits[1]=mPad->PadY(); | |
303 | fDigits[2]=iqpad; | |
304 | fDigits[3]=iqpad; | |
305 | fDigits[4]=mPad->HitNumber(); | |
d8a72780 | 306 | |
b762c2f6 | 307 | // build the list of fired pads and update the info |
308 | if (Exists(mPad)) { | |
309 | Update(mPad); | |
310 | } else { | |
311 | CreateNew(mPad); | |
312 | } | |
313 | } //end loop over clusters | |
314 | }// track type condition | |
315 | } // hit loop | |
316 | } // track loop | |
d8a72780 | 317 | |
b762c2f6 | 318 | // open the file with background |
d8a72780 | 319 | |
b762c2f6 | 320 | if (fMerge) { |
321 | fSignal = kFALSE; | |
322 | ntracks = (Int_t)fTrH1->GetEntries(); | |
323 | // | |
324 | // Loop over tracks | |
325 | // | |
326 | for (fTrack = 0; fTrack < ntracks; fTrack++) { | |
d8a72780 | 327 | |
b762c2f6 | 328 | if (fHitsBgr) fHitsBgr->Clear(); |
329 | if (fSDigitsBgr) fSDigitsBgr->Clear(); | |
d8a72780 | 330 | |
b762c2f6 | 331 | fTrH1->GetEvent(fTrack); |
332 | // | |
333 | // Loop over hits | |
334 | AliRICHHit* mHit; | |
335 | for(Int_t i = 0; i < fHitsBgr->GetEntriesFast(); ++i) | |
336 | { | |
337 | mHit = (AliRICHHit*) (*fHitsBgr)[i]; | |
338 | fNch = mHit->Chamber()-1; // chamber number | |
339 | iChamber = &(pRICH->Chamber(fNch)); | |
340 | ||
d8a72780 | 341 | // |
b762c2f6 | 342 | // Loop over pad hits |
343 | for (AliRICHSDigit* mPad = | |
344 | (AliRICHSDigit*)pRICH->FirstPad(mHit,fSDigitsBgr); | |
345 | mPad; | |
346 | mPad = (AliRICHSDigit*)pRICH->NextPad(fSDigitsBgr)) | |
347 | { | |
348 | fDigits[0] = mPad->PadX(); | |
349 | fDigits[1] = mPad->PadY(); | |
350 | fDigits[2] = mPad->QPad(); | |
351 | fDigits[3] = 0; | |
352 | fDigits[4] = -1; // set hit number to -1 for bgr | |
d8a72780 | 353 | |
b762c2f6 | 354 | // build the list of fired pads and update the info |
355 | if (!Exists(mPad)) { | |
356 | CreateNew(mPad); | |
357 | } else { | |
358 | Update(mPad); | |
359 | } // end if !Exists | |
360 | } //end loop over clusters | |
361 | } // hit loop | |
362 | } // track loop | |
d8a72780 | 363 | |
b762c2f6 | 364 | TTree *treeK = gAlice->TreeK(); |
365 | TFile *file = NULL; | |
d8a72780 | 366 | |
b762c2f6 | 367 | if (treeK) file = treeK->GetCurrentFile(); |
368 | file->cd(); | |
369 | } // if fMerge | |
d8a72780 | 370 | |
b762c2f6 | 371 | Int_t tracks[kMAXTRACKSPERRICHDIGIT]; |
372 | Int_t charges[kMAXTRACKSPERRICHDIGIT]; | |
373 | Int_t nentries=fList->GetEntriesFast(); | |
d8a72780 | 374 | |
b762c2f6 | 375 | for (Int_t nent=0;nent<nentries;nent++) { |
376 | AliRICHTransientDigit *transDigit=(AliRICHTransientDigit*)fList->At(nent); | |
377 | if (transDigit==0) continue; | |
378 | Int_t ich=transDigit->GetChamber(); | |
379 | Int_t q=transDigit->Signal(); | |
380 | iChamber=&(pRICH->Chamber(ich)); | |
381 | AliRICHResponse * response=iChamber->GetResponseModel(); | |
382 | Int_t adcmax= (Int_t) response->MaxAdc(); | |
d8a72780 | 383 | |
d8a72780 | 384 | |
b762c2f6 | 385 | // add white noise and do zero-suppression and signal truncation (new electronics,old electronics gaus 1.2,0.2) |
386 | //printf("Treshold: %d\n",iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY())); | |
387 | Int_t pedestal = iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY()); | |
d8a72780 | 388 | |
b762c2f6 | 389 | //printf("Pedestal:%d\n",pedestal); |
390 | //Int_t pedestal=0; | |
391 | Float_t treshold = (pedestal + 4*2.2); | |
d8a72780 | 392 | |
b762c2f6 | 393 | Float_t meanNoise = gRandom->Gaus(2.2, 0.3); |
394 | Float_t noise = gRandom->Gaus(0, meanNoise); | |
395 | q+=(Int_t)(noise + pedestal); | |
396 | //q+=(Int_t)(noise); | |
397 | // magic number to be parametrised !!! | |
398 | if ( q <= treshold) | |
399 | { | |
d8a72780 | 400 | q = q - pedestal; |
b762c2f6 | 401 | continue; |
402 | } | |
403 | q = q - pedestal; | |
404 | if ( q >= adcmax) q=adcmax; | |
405 | fDigits[0]=transDigit->PadX(); | |
406 | fDigits[1]=transDigit->PadY(); | |
407 | fDigits[2]=q; | |
408 | fDigits[3]=transDigit->Physics(); | |
409 | fDigits[4]=transDigit->Hit(); | |
410 | ||
411 | Int_t nptracks = transDigit->GetNTracks(); | |
412 | ||
413 | // this was changed to accomodate the real number of tracks | |
414 | if (nptracks > kMAXTRACKSPERRICHDIGIT) { | |
415 | printf("Attention - tracks > 10 %d\n",nptracks); | |
416 | nptracks=kMAXTRACKSPERRICHDIGIT; | |
417 | } | |
418 | if (nptracks > 2) { | |
419 | printf("Attention - tracks > 2 %d \n",nptracks); | |
420 | //printf("cat,ich,ix,iy,q %d %d %d %d %d \n", | |
421 | //icat,ich,digits[0],digits[1],q); | |
422 | } | |
423 | for (Int_t tr=0;tr<nptracks;tr++) { | |
424 | tracks[tr]=transDigit->GetTrack(tr); | |
425 | charges[tr]=transDigit->GetCharge(tr); | |
426 | } //end loop over list of tracks for one pad | |
427 | if (nptracks < kMAXTRACKSPERRICHDIGIT ) { | |
428 | for (Int_t t=nptracks; t<kMAXTRACKSPERRICHDIGIT; t++) { | |
429 | tracks[t]=0; | |
430 | charges[t]=0; | |
d8a72780 | 431 | } |
b762c2f6 | 432 | } |
433 | //write file | |
434 | //if (ich==2) | |
435 | //fprintf(points,"%4d, %4d, %4d\n",digits[0],digits[1],digits[2]); | |
d8a72780 | 436 | |
b762c2f6 | 437 | // fill digits |
438 | pRICH->AddDigits(ich,tracks,charges,fDigits); | |
439 | } | |
440 | gAlice->TreeD()->Fill(); | |
441 | ||
442 | fList->Delete(); | |
443 | for(Int_t ii=0;ii<kNCH;++ii) { | |
444 | if (fHitMap[ii]) { | |
445 | delete fHitMap[ii]; | |
446 | fHitMap[ii]=0; | |
d8a72780 | 447 | } |
b762c2f6 | 448 | } |
d8a72780 | 449 | |
b762c2f6 | 450 | TClonesArray *richDigits; |
451 | for (Int_t k=0;k<kNCH;k++) { | |
452 | richDigits = pRICH->DigitsAddress(k); | |
453 | Int_t ndigit=richDigits->GetEntriesFast(); | |
454 | printf ("Chamber %d digits %d \n",k,ndigit); | |
455 | } | |
456 | pRICH->ResetDigits(); /// ??? should it be here??? | |
457 | gAlice->TreeD()->Write(0,TObject::kOverwrite); | |
458 | // reset tree | |
459 | // gAlice->TreeD()->Reset(); | |
460 | // delete fList; // deleted in dtor | |
461 | // gObjectTable->Print(); | |
d8a72780 | 462 | |
463 | } |