]>
Commit | Line | Data |
---|---|---|
b762c2f6 | 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 | ||
88cb7938 | 16 | /* $Id$ */ |
b9d0a01d | 17 | |
88cb7938 | 18 | //Piotr.Skowronski@cern.ch : |
19 | //Corrections applied in order to compile (only) with new I/O and folder structure | |
20 | //To be implemented correctly by responsible | |
30f2451c | 21 | |
7118aef0 | 22 | #include <Riostream.h> |
b762c2f6 | 23 | |
24 | #include <TTree.h> | |
25 | #include <TObjArray.h> | |
26 | #include <TFile.h> | |
27 | #include <TDirectory.h> | |
28 | #include <TParticle.h> | |
29 | ||
88cb7938 | 30 | #include "AliRunLoader.h" |
31 | #include "AliLoader.h" | |
32 | ||
b762c2f6 | 33 | #include "AliRICHDigitizer.h" |
34 | #include "AliRICHChamber.h" | |
35 | #include "AliHitMap.h" | |
36 | #include "AliRICHHitMapA1.h" | |
37 | #include "AliRICH.h" | |
b762c2f6 | 38 | #include "AliRICHSDigit.h" |
39 | #include "AliRICHDigit.h" | |
40 | #include "AliRICHTransientDigit.h" | |
41 | #include "AliRun.h" | |
42 | #include "AliPDG.h" | |
43 | #include "AliRunDigitizer.h" | |
44 | ||
45 | ClassImp(AliRICHDigitizer) | |
46 | ||
47 | //___________________________________________ | |
48 | AliRICHDigitizer::AliRICHDigitizer() | |
49 | { | |
50 | // Default constructor - don't use it | |
51 | fHits = 0; | |
52 | fSDigits = 0; | |
53 | fHitMap = 0; | |
54 | fTDList = 0; | |
55 | } | |
56 | ||
57 | //////////////////////////////////////////////////////////////////////// | |
58 | AliRICHDigitizer::AliRICHDigitizer(AliRunDigitizer* manager) | |
59 | :AliDigitizer(manager) | |
60 | { | |
61 | // ctor which should be used | |
62 | fHits = 0; | |
63 | fSDigits = 0; | |
64 | fHitMap = 0; | |
65 | fTDList = 0; | |
66 | fDebug = 0; | |
67 | if (GetDebug()>2) | |
68 | cerr<<"AliRICHDigitizer::AliRICHDigitizer" | |
88cb7938 | 69 | <<"(AliRunDigitizer* manager) was processed"<<endl; |
b762c2f6 | 70 | } |
71 | ||
72 | //////////////////////////////////////////////////////////////////////// | |
73 | AliRICHDigitizer::~AliRICHDigitizer() | |
74 | { | |
75 | // Destructor | |
b5d9757b | 76 | if (fHits) { |
77 | fHits->Delete(); | |
78 | delete fHits; | |
79 | } | |
80 | if (fSDigits) { | |
81 | fSDigits->Delete(); | |
82 | delete fSDigits; | |
83 | } | |
84 | for (Int_t i=0; i<kNCH; i++ ) | |
85 | delete fHitMap[i]; | |
86 | delete [] fHitMap; | |
87 | if (fTDList) { | |
88 | fTDList->Delete(); | |
89 | delete fTDList; | |
00827f3e | 90 | } |
b762c2f6 | 91 | } |
92 | ||
93 | //------------------------------------------------------------------------ | |
94 | Bool_t AliRICHDigitizer::Exists(const AliRICHSDigit *padhit) | |
95 | { | |
96 | return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY())); | |
97 | } | |
98 | ||
99 | //------------------------------------------------------------------------ | |
100 | void AliRICHDigitizer::Update(AliRICHSDigit *padhit) | |
101 | { | |
102 | AliRICHTransientDigit *pdigit = | |
103 | static_cast<AliRICHTransientDigit*>( | |
104 | fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY())); | |
105 | ||
106 | // update charge | |
107 | // | |
108 | Int_t iqpad = Int_t(padhit->QPad()); // charge per pad | |
109 | pdigit->AddSignal(iqpad); | |
88cb7938 | 110 | pdigit->AddPhysicsSignal(iqpad); |
b762c2f6 | 111 | |
112 | // update list of tracks | |
113 | // | |
114 | Int_t track, charge; | |
115 | track = fTrack+fMask; | |
116 | if (fSignal) { | |
117 | charge = iqpad; | |
118 | } else { | |
119 | charge = kBgTag; | |
120 | } | |
121 | pdigit->UpdateTrackList(track,charge); | |
122 | } | |
123 | ||
124 | //------------------------------------------------------------------------ | |
125 | void AliRICHDigitizer::CreateNew(AliRICHSDigit *padhit) | |
126 | { | |
127 | fTDList->AddAtAndExpand( | |
128 | new AliRICHTransientDigit(fNch,fDigits),fCounter); | |
129 | fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter); | |
130 | ||
131 | AliRICHTransientDigit* pdigit = | |
132 | static_cast<AliRICHTransientDigit*>(fTDList->Last()); | |
133 | // list of tracks | |
134 | Int_t track, charge; | |
135 | if (fSignal) { | |
136 | track = fTrack; | |
137 | charge = padhit->QPad(); | |
138 | } else { | |
139 | track = kBgTag; | |
140 | charge = kBgTag; | |
141 | } | |
142 | pdigit->AddToTrackList(track,charge); | |
143 | fCounter++; | |
144 | } | |
145 | ||
146 | ||
147 | //////////////////////////////////////////////////////////////////////// | |
148 | Bool_t AliRICHDigitizer::Init() | |
149 | { | |
150 | // Initialisation | |
853634d3 | 151 | fHits = new TClonesArray("AliRICHhit",1000); |
b762c2f6 | 152 | fSDigits = new TClonesArray("AliRICHSDigit",1000); |
153 | return kTRUE; | |
154 | } | |
155 | ||
156 | //////////////////////////////////////////////////////////////////////// | |
157 | //void AliRICHDigitizer::Digitise(Int_t nev, Int_t flag) | |
158 | void AliRICHDigitizer::Exec(Option_t* option) | |
159 | { | |
160 | TString optionString = option; | |
161 | if (optionString.Data() == "deb") { | |
162 | cout<<"AliMUONDigitizer::Exec: called with option deb "<<endl; | |
163 | fDebug = 3; | |
164 | } | |
165 | ||
166 | AliRICHChamber* iChamber; | |
167 | AliSegmentation* segmentation; | |
88cb7938 | 168 | |
169 | AliRunLoader *inRL, *outRL;//in and out Run Loaders | |
170 | AliLoader *ingime, *outgime;// in and out ITSLoaders | |
171 | ||
172 | outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); | |
173 | outgime = outRL->GetLoader("RICHLoader"); | |
174 | ||
b762c2f6 | 175 | fTDList = new TObjArray; |
88cb7938 | 176 | |
177 | ||
b762c2f6 | 178 | AliRICH *pRICH = (AliRICH *) gAlice->GetDetector("RICH"); |
88cb7938 | 179 | |
180 | if (outgime->TreeD() == 0x0) outgime->MakeTree("D"); | |
181 | ||
182 | pRICH->MakeBranchInTreeD(outgime->TreeD()); | |
b762c2f6 | 183 | fHitMap= new AliHitMap* [kNCH]; |
184 | ||
185 | for (Int_t i =0; i<kNCH; i++) { | |
186 | iChamber= &(pRICH->Chamber(i)); | |
cc23c5c6 | 187 | segmentation=iChamber->GetSegmentationModel(); |
b762c2f6 | 188 | fHitMap[i] = new AliRICHHitMapA1(segmentation, fTDList); |
189 | } | |
190 | ||
191 | // Loop over files to digitize | |
192 | fSignal = kTRUE; | |
193 | fCounter = 0; | |
88cb7938 | 194 | for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); inputFile++) |
195 | { | |
196 | inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile)); | |
197 | ingime = inRL->GetLoader("RICHLoader"); | |
198 | ||
b762c2f6 | 199 | // Connect RICH branches |
200 | ||
201 | if (inputFile > 0 ) fSignal = kFALSE; | |
202 | TBranch *branchHits = 0; | |
203 | TBranch *branchSDigits = 0; | |
88cb7938 | 204 | |
205 | ingime->LoadHits("READ"); | |
206 | TTree *treeH = ingime->TreeH(); | |
b762c2f6 | 207 | if (GetDebug()>2) { |
208 | cerr<<" inputFile "<<inputFile<<endl; | |
209 | cerr<<" treeH, fHits "<<treeH<<" "<<fHits<<endl; | |
210 | } | |
211 | if (treeH && fHits) { | |
212 | branchHits = treeH->GetBranch("RICH"); | |
88cb7938 | 213 | if (branchHits) |
214 | { | |
215 | fHits->Clear(); | |
216 | branchHits->SetAddress(&fHits); | |
b762c2f6 | 217 | } |
218 | else | |
88cb7938 | 219 | Error("Exec","branch RICH was not found"); |
b762c2f6 | 220 | } |
221 | if (GetDebug()>2) cerr<<" branchHits = "<<branchHits<<endl; | |
222 | ||
223 | if (treeH && fSDigits) { | |
224 | branchSDigits = treeH->GetBranch("RICHSDigits"); | |
225 | if (branchSDigits) | |
88cb7938 | 226 | branchSDigits->SetAddress(&fSDigits); |
b762c2f6 | 227 | else |
88cb7938 | 228 | Error("exec","branch RICHSDigits was not found"); |
b762c2f6 | 229 | } |
230 | if (GetDebug()>2) cerr<<" branchSDigits = "<<branchSDigits<<endl; | |
231 | ||
232 | ||
233 | // | |
234 | // Loop over tracks | |
235 | // | |
236 | ||
237 | Int_t ntracks =(Int_t) treeH->GetEntries(); | |
238 | for (fTrack=0; fTrack<ntracks; fTrack++) { | |
239 | fHits->Clear(); | |
240 | fSDigits->Clear(); | |
241 | branchHits->GetEntry(fTrack); | |
242 | branchSDigits->GetEntry(fTrack); | |
243 | ||
244 | ||
245 | // | |
246 | // Loop over hits | |
247 | for(Int_t i = 0; i < fHits->GetEntriesFast(); ++i) { | |
853634d3 | 248 | AliRICHhit* mHit = static_cast<AliRICHhit*>(fHits->At(i)); |
b762c2f6 | 249 | fNch = mHit->Chamber()-1; // chamber number |
250 | if (fNch >= kNCH) { | |
251 | cerr<<"AliRICHDigitizer: chamber nr. fNch out of range: "<<fNch<<endl; | |
252 | cerr<<" track: "<<fTrack<<endl; | |
253 | continue; | |
254 | } | |
255 | iChamber = &(pRICH->Chamber(fNch)); | |
256 | ||
257 | // | |
258 | // Loop over pad hits | |
259 | for (AliRICHSDigit* mPad= | |
260 | (AliRICHSDigit*)pRICH->FirstPad(mHit,fSDigits); | |
261 | mPad; | |
262 | mPad=(AliRICHSDigit*)pRICH->NextPad(fSDigits)) | |
263 | { | |
264 | Int_t iqpad = mPad->QPad(); // charge per pad | |
265 | fDigits[0]=mPad->PadX(); | |
266 | fDigits[1]=mPad->PadY(); | |
267 | fDigits[2]=iqpad; | |
268 | fDigits[3]=iqpad; | |
269 | fDigits[4]=mPad->HitNumber(); | |
270 | ||
5546f238 | 271 | |
272 | ||
b762c2f6 | 273 | // build the list of fired pads and update the info |
274 | if (Exists(mPad)) { | |
275 | Update(mPad); | |
276 | } else { | |
277 | CreateNew(mPad); | |
278 | } | |
279 | } //end loop over clusters | |
280 | } // hit loop | |
281 | } // track loop | |
282 | } // end file loop | |
283 | if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl; | |
284 | ||
285 | Int_t tracks[kMAXTRACKSPERRICHDIGIT]; | |
286 | Int_t charges[kMAXTRACKSPERRICHDIGIT]; | |
287 | Int_t nentries=fTDList->GetEntriesFast(); | |
288 | ||
289 | for (Int_t nent=0;nent<nentries;nent++) { | |
290 | AliRICHTransientDigit *transDigit=(AliRICHTransientDigit*)fTDList->At(nent); | |
291 | if (transDigit==0) continue; | |
292 | Int_t ich=transDigit->GetChamber(); | |
293 | Int_t q=transDigit->Signal(); | |
294 | iChamber=&(pRICH->Chamber(ich)); | |
295 | AliRICHResponse * response=iChamber->GetResponseModel(); | |
296 | Int_t adcmax= (Int_t) response->MaxAdc(); | |
297 | ||
298 | ||
299 | // add white noise and do zero-suppression and signal truncation (new electronics,old electronics gaus 1.2,0.2) | |
300 | //printf("Treshold: %d\n",iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY())); | |
301 | ||
302 | // tmp change | |
303 | // Int_t pedestal = iChamber->fTresh->GetHitIndex(transDigit->PadX(),transDigit->PadY()); | |
304 | Int_t pedestal = 0; | |
305 | ||
306 | ||
307 | //printf("Pedestal:%d\n",pedestal); | |
308 | //Int_t pedestal=0; | |
309 | Float_t treshold = (pedestal + 4*2.2); | |
310 | ||
311 | Float_t meanNoise = gRandom->Gaus(2.2, 0.3); | |
312 | Float_t noise = gRandom->Gaus(0, meanNoise); | |
313 | q+=(Int_t)(noise + pedestal); | |
314 | //q+=(Int_t)(noise); | |
315 | // magic number to be parametrised !!! | |
316 | if ( q <= treshold) | |
317 | { | |
318 | q = q - pedestal; | |
319 | continue; | |
320 | } | |
321 | q = q - pedestal; | |
322 | if ( q >= adcmax) q=adcmax; | |
323 | fDigits[0]=transDigit->PadX(); | |
324 | fDigits[1]=transDigit->PadY(); | |
325 | fDigits[2]=q; | |
326 | fDigits[3]=transDigit->Physics(); | |
327 | fDigits[4]=transDigit->Hit(); | |
328 | ||
329 | Int_t nptracks = transDigit->GetNTracks(); | |
330 | ||
331 | // this was changed to accomodate the real number of tracks | |
332 | if (nptracks > kMAXTRACKSPERRICHDIGIT) { | |
333 | printf("Attention - tracks > 10 %d\n",nptracks); | |
334 | nptracks=kMAXTRACKSPERRICHDIGIT; | |
335 | } | |
336 | if (nptracks > 2) { | |
337 | printf("Attention - tracks > 2 %d \n",nptracks); | |
338 | } | |
339 | for (Int_t tr=0;tr<nptracks;tr++) { | |
340 | tracks[tr]=transDigit->GetTrack(tr); | |
341 | charges[tr]=transDigit->GetCharge(tr); | |
5546f238 | 342 | //printf("%f \n",charges[tr]); |
b762c2f6 | 343 | } //end loop over list of tracks for one pad |
344 | if (nptracks < kMAXTRACKSPERRICHDIGIT ) { | |
345 | for (Int_t t=nptracks; t<kMAXTRACKSPERRICHDIGIT; t++) { | |
88cb7938 | 346 | tracks[t]=0; |
347 | charges[t]=0; | |
b762c2f6 | 348 | } |
349 | } | |
350 | //write file | |
351 | //if (ich==2) | |
352 | //fprintf(points,"%4d, %4d, %4d\n",digits[0],digits[1],digits[2]); | |
353 | ||
354 | // fill digits | |
355 | pRICH->AddDigits(ich,tracks,charges,fDigits); | |
88cb7938 | 356 | } |
357 | outgime->TreeD()->Fill(); | |
b762c2f6 | 358 | |
5546f238 | 359 | //pRICH->ResetDigits(); |
b762c2f6 | 360 | fTDList->Delete(); // or fTDList->Clear(); ??? |
361 | for(Int_t ii=0;ii<kNCH;++ii) { | |
362 | if (fHitMap[ii]) { | |
363 | delete fHitMap[ii]; | |
364 | fHitMap[ii]=0; | |
365 | } | |
366 | } | |
367 | ||
368 | TClonesArray *richDigits; | |
369 | for (Int_t k=0;k<kNCH;k++) { | |
370 | richDigits = pRICH->DigitsAddress(k); | |
371 | Int_t ndigit=richDigits->GetEntriesFast(); | |
372 | printf ("Chamber %d digits %d \n",k,ndigit); | |
373 | } | |
88cb7938 | 374 | pRICH->ResetDigits(); /// ??? should it be here??? |
375 | ||
376 | outgime->WriteDigits("OVERWRITE"); | |
377 | ||
b762c2f6 | 378 | delete [] fHitMap; |
379 | delete fTDList; | |
380 | ||
381 | if (fHits) fHits->Delete(); | |
382 | if (fSDigits) fSDigits->Delete(); | |
383 | ||
384 | } |