]>
Commit | Line | Data |
---|---|---|
28752ff4 | 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$ | |
116cbefd | 18 | Revision 1.11 2002/10/23 07:24:56 alibrary |
19 | Introducing Riostream.h | |
20 | ||
70479d0e | 21 | Revision 1.10 2002/03/13 07:55:04 jchudoba |
22 | Correction of the errourness last commit. | |
23 | ||
4b1670dc | 24 | Revision 1.8 2002/02/13 09:03:24 jchudoba |
25 | Remove some deletes from dtor, those objects are deleted earlier in Exec() method (where they are created) | |
26 | ||
111ce036 | 27 | Revision 1.7 2001/11/22 11:15:41 jchudoba |
28 | Proper deletion of arrays (thanks to Rene Brun) | |
29 | ||
3ec837bb | 30 | Revision 1.6 2001/11/02 12:55:45 jchudoba |
31 | cleanup of the code, add const to Get methods | |
32 | ||
8f36c696 | 33 | Revision 1.4 2001/10/18 14:44:09 jchudoba |
34 | Define constant MAXTRACKS for maximum number of tracks associated with 1 digit | |
35 | ||
0e88acc2 | 36 | Revision 1.3 2001/10/04 20:01:54 jchudoba |
37 | changes for TTask implementation, some other small editing | |
38 | ||
b8278504 | 39 | Revision 1.2 2001/07/28 10:46:04 hristov |
40 | AliRunDigitizer.h included; typos corrected | |
41 | ||
53828ce0 | 42 | Revision 1.1 2001/07/27 15:41:01 jchudoba |
43 | merging/digitization classes | |
44 | ||
28752ff4 | 45 | */ |
70479d0e | 46 | #include <Riostream.h> |
116cbefd | 47 | #include <TDirectory.h> |
48 | #include <TFile.h> | |
49 | #include <TObjArray.h> | |
50 | #include <TPDGCode.h> | |
51 | #include <TTree.h> | |
28752ff4 | 52 | |
28752ff4 | 53 | #include "AliMUON.h" |
116cbefd | 54 | #include "AliMUONChamber.h" |
55 | #include "AliMUONConstants.h" | |
56 | #include "AliMUONDigit.h" | |
57 | #include "AliMUONDigitizer.h" | |
28752ff4 | 58 | #include "AliMUONHit.h" |
116cbefd | 59 | #include "AliMUONHitMapA1.h" |
28752ff4 | 60 | #include "AliMUONPadHit.h" |
28752ff4 | 61 | #include "AliMUONTransientDigit.h" |
62 | #include "AliRun.h" | |
53828ce0 | 63 | #include "AliRunDigitizer.h" |
28752ff4 | 64 | |
65 | ClassImp(AliMUONDigitizer) | |
66 | ||
67 | //___________________________________________ | |
68 | AliMUONDigitizer::AliMUONDigitizer() :AliDigitizer() | |
69 | { | |
70 | // Default ctor - don't use it | |
c7955c78 | 71 | fHits = 0; |
72 | fPadHits = 0; | |
73 | fHitMap = 0; | |
74 | fTDList = 0; | |
28752ff4 | 75 | } |
76 | ||
77 | //___________________________________________ | |
78 | AliMUONDigitizer::AliMUONDigitizer(AliRunDigitizer* manager) | |
79 | :AliDigitizer(manager) | |
80 | { | |
81 | // ctor which should be used | |
28752ff4 | 82 | fHitMap = 0; |
83 | fTDList = 0; | |
28752ff4 | 84 | fHits = 0; |
b8278504 | 85 | fPadHits = 0; |
b8278504 | 86 | fDebug = 0; |
28752ff4 | 87 | if (GetDebug()>2) |
88 | cerr<<"AliMUONDigitizer::AliMUONDigitizer" | |
89 | <<"(AliRunDigitizer* manager) was processed"<<endl; | |
90 | } | |
91 | ||
92 | //------------------------------------------------------------------------ | |
93 | AliMUONDigitizer::~AliMUONDigitizer() | |
94 | { | |
95 | // Destructor | |
28752ff4 | 96 | if (fHits) delete fHits; |
97 | if (fPadHits) delete fPadHits; | |
28752ff4 | 98 | } |
99 | ||
100 | //------------------------------------------------------------------------ | |
c7955c78 | 101 | Bool_t AliMUONDigitizer::Exists(const AliMUONPadHit *padhit) const |
28752ff4 | 102 | { |
28752ff4 | 103 | return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY())); |
104 | } | |
105 | ||
106 | //------------------------------------------------------------------------ | |
8f36c696 | 107 | void AliMUONDigitizer::Update(AliMUONPadHit *padhit) |
28752ff4 | 108 | { |
8f36c696 | 109 | AliMUONTransientDigit *pdigit = |
110 | static_cast<AliMUONTransientDigit*>( | |
111 | fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY())); | |
112 | ||
113 | // update charge | |
114 | // | |
115 | Int_t iqpad = padhit->QPad(); // charge per pad | |
116 | pdigit->AddSignal(iqpad); | |
117 | pdigit->AddPhysicsSignal(iqpad); | |
118 | ||
119 | // update list of tracks | |
120 | // | |
121 | Int_t track, charge; | |
122 | track = fTrack+fMask; | |
123 | if (fSignal) { | |
124 | charge = iqpad; | |
28752ff4 | 125 | } else { |
8f36c696 | 126 | charge = kBgTag; |
28752ff4 | 127 | } |
8f36c696 | 128 | pdigit->UpdateTrackList(track,charge); |
28752ff4 | 129 | } |
130 | ||
131 | //------------------------------------------------------------------------ | |
8f36c696 | 132 | void AliMUONDigitizer::CreateNew(AliMUONPadHit *padhit) |
28752ff4 | 133 | { |
134 | // Create new AliMUONTransientDigit and add it to the fTDList | |
135 | ||
28752ff4 | 136 | fTDList->AddAtAndExpand( |
137 | new AliMUONTransientDigit(fNch,fDigits),fCounter); | |
8f36c696 | 138 | fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter); |
139 | AliMUONTransientDigit* pdigit = | |
c7955c78 | 140 | (AliMUONTransientDigit*)fTDList->Last(); |
28752ff4 | 141 | // list of tracks |
8f36c696 | 142 | Int_t track, charge; |
143 | track = fTrack+fMask; | |
144 | if (fSignal) { | |
145 | charge = padhit->QPad(); | |
146 | } else { | |
147 | charge = kBgTag; | |
148 | } | |
149 | pdigit->AddToTrackList(track,charge); | |
150 | fCounter++; | |
28752ff4 | 151 | } |
152 | ||
153 | ||
154 | //------------------------------------------------------------------------ | |
155 | Bool_t AliMUONDigitizer::Init() | |
156 | { | |
157 | // Initialization | |
158 | ||
159 | fHits = new TClonesArray("AliMUONHit",1000); | |
160 | fPadHits = new TClonesArray("AliMUONPadHit",1000); | |
161 | return kTRUE; | |
162 | } | |
163 | ||
164 | ||
165 | //------------------------------------------------------------------------ | |
b8278504 | 166 | //void AliMUONDigitizer::Digitize() |
167 | void AliMUONDigitizer::Exec(Option_t* option) | |
28752ff4 | 168 | { |
169 | ||
b8278504 | 170 | TString optionString = option; |
171 | if (optionString.Data() == "deb") { | |
172 | cout<<"AliMUONDigitizer::Exec: called with option deb "<<endl; | |
173 | fDebug = 3; | |
174 | } | |
28752ff4 | 175 | AliMUONChamber* iChamber; |
176 | AliSegmentation* segmentation; | |
177 | ||
178 | if (GetDebug()>2) cerr<<" AliMUONDigitizer::Digitize() starts"<<endl; | |
179 | fTDList = new TObjArray; | |
28752ff4 | 180 | |
181 | AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON"); | |
182 | if (!pMUON) { | |
183 | cerr<<"AliMUONDigitizer::Digitize Error:" | |
184 | <<" module MUON not found in the input file"<<endl; | |
185 | return; | |
186 | } | |
187 | pMUON->MakeBranchInTreeD(fManager->GetTreeD()); | |
8f36c696 | 188 | fHitMap= new AliMUONHitMapA1* [AliMUONConstants::NCh()]; |
28752ff4 | 189 | |
190 | // | |
191 | // loop over cathodes | |
192 | // | |
193 | ||
28752ff4 | 194 | for (int icat = 0; icat < 2; icat++) { |
195 | fCounter = 0; | |
28752ff4 | 196 | for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) { |
197 | iChamber = &(pMUON->Chamber(i)); | |
198 | // if (!(iChamber->Nsec() == 1 && icat == 1)) { | |
199 | segmentation = iChamber->SegmentationModel(icat+1); | |
200 | fHitMap[i] = new AliMUONHitMapA1(segmentation, fTDList); | |
28752ff4 | 201 | // } |
202 | } | |
203 | ||
204 | ||
205 | // Loop over files to digitize | |
8f36c696 | 206 | fSignal = kTRUE; |
28752ff4 | 207 | for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); |
208 | inputFile++) { | |
209 | // Connect MUON branches | |
210 | ||
8f36c696 | 211 | if (inputFile > 0 ) fSignal = kFALSE; |
b8278504 | 212 | TBranch *branchHits = 0; |
213 | TBranch *branchPadHits = 0; | |
28752ff4 | 214 | TTree *treeH = fManager->GetInputTreeH(inputFile); |
215 | if (GetDebug()>2) { | |
216 | cerr<<" inputFile , cathode = "<<inputFile<<" " | |
217 | <<icat<<endl; | |
218 | cerr<<" treeH, fHits "<<treeH<<" "<<fHits<<endl; | |
219 | } | |
220 | if (treeH && fHits) { | |
b8278504 | 221 | branchHits = treeH->GetBranch("MUON"); |
222 | if (branchHits) { | |
28752ff4 | 223 | fHits->Clear(); |
b8278504 | 224 | branchHits->SetAddress(&fHits); |
28752ff4 | 225 | } |
226 | else | |
c7955c78 | 227 | Error("Exec","branch MUON was not found"); |
28752ff4 | 228 | } |
b8278504 | 229 | if (GetDebug()>2) cerr<<" branchHits = "<<branchHits<<endl; |
28752ff4 | 230 | |
231 | if (treeH && fPadHits) { | |
b8278504 | 232 | branchPadHits = treeH->GetBranch("MUONCluster"); |
233 | if (branchPadHits) | |
234 | branchPadHits->SetAddress(&fPadHits); | |
28752ff4 | 235 | else |
c7955c78 | 236 | Error("Exec","branch MUONCluster was not found"); |
28752ff4 | 237 | } |
b8278504 | 238 | if (GetDebug()>2) cerr<<" branchPadHits = "<<branchPadHits<<endl; |
28752ff4 | 239 | |
240 | // | |
241 | // Loop over tracks | |
242 | // | |
243 | ||
244 | Int_t ntracks = (Int_t) treeH->GetEntries(); | |
245 | ||
246 | for (fTrack = 0; fTrack < ntracks; fTrack++) { | |
247 | if (GetDebug()>2) cerr<<" fTrack = "<<fTrack<<endl; | |
248 | fHits->Clear(); | |
b8278504 | 249 | fPadHits->Clear(); |
250 | branchHits->GetEntry(fTrack); | |
251 | branchPadHits->GetEntry(fTrack); | |
28752ff4 | 252 | |
253 | // | |
254 | // Loop over hits | |
255 | ||
256 | AliMUONHit* mHit; | |
c7955c78 | 257 | for(Int_t i = 0; i < fHits->GetEntriesFast(); ++i) { |
258 | mHit = static_cast<AliMUONHit*>(fHits->At(i)); | |
28752ff4 | 259 | fNch = mHit->Chamber()-1; // chamber number |
28752ff4 | 260 | if (fNch > AliMUONConstants::NCh()-1) { |
261 | cerr<<"AliMUONDigitizer: ERROR: " | |
262 | <<"fNch > AliMUONConstants::NCh()-1, fNch, NCh(): " | |
263 | <<fNch<<", "<< AliMUONConstants::NCh()<<endl; | |
264 | return; | |
265 | } | |
c7955c78 | 266 | iChamber = &(pMUON->Chamber(fNch)); |
28752ff4 | 267 | // |
268 | // Loop over pad hits | |
269 | for (AliMUONPadHit* mPad = | |
270 | (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHits); | |
271 | mPad; | |
272 | mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHits)) | |
273 | { | |
274 | Int_t cathode = mPad->Cathode(); // cathode number | |
275 | Int_t ipx = mPad->PadX(); // pad number on X | |
276 | Int_t ipy = mPad->PadY(); // pad number on Y | |
277 | Int_t iqpad = Int_t(mPad->QPad()); // charge per pad | |
278 | if (cathode != (icat+1)) continue; | |
279 | ||
8f36c696 | 280 | fMask = fManager->GetMask(inputFile); |
28752ff4 | 281 | fDigits[0] = ipx; |
282 | fDigits[1] = ipy; | |
283 | fDigits[2] = icat; | |
284 | fDigits[3] = iqpad; | |
285 | if (inputFile == 0) { | |
286 | fDigits[4] = iqpad; | |
287 | } else { | |
288 | fDigits[4] = 0; | |
289 | } | |
290 | if (mHit->Particle() == kMuonPlus || | |
291 | mHit->Particle() == kMuonMinus) { | |
8f36c696 | 292 | fDigits[5] = (mPad->HitNumber()) + fMask; |
28752ff4 | 293 | } else fDigits[5] = -1; |
294 | ||
295 | // build the list of fired pads and update the info, | |
296 | // fDigits is input for Update(mPad) | |
297 | ||
298 | if (!Exists(mPad)) { | |
299 | CreateNew(mPad); | |
300 | } else { | |
301 | Update(mPad); | |
302 | } // end if Exists(mPad) | |
303 | } //end loop over clusters | |
304 | } // hit loop | |
305 | } // track loop | |
306 | } // end file loop | |
307 | if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl; | |
308 | ||
8f36c696 | 309 | Int_t tracks[kMAXTRACKS]; |
310 | Int_t charges[kMAXTRACKS]; | |
28752ff4 | 311 | Int_t nentries = fTDList->GetEntriesFast(); |
312 | ||
313 | for (Int_t nent = 0; nent < nentries; nent++) { | |
314 | AliMUONTransientDigit *address = (AliMUONTransientDigit*)fTDList->At(nent); | |
315 | if (address == 0) continue; | |
316 | Int_t ich = address->Chamber(); | |
317 | Int_t q = address->Signal(); | |
318 | iChamber = &(pMUON->Chamber(ich)); | |
319 | // | |
320 | // Digit Response (noise, threshold, saturation, ...) | |
321 | AliMUONResponse * response = iChamber->ResponseModel(); | |
322 | q = response->DigitResponse(q); | |
323 | ||
324 | if (!q) continue; | |
325 | ||
326 | fDigits[0] = address->PadX(); | |
327 | fDigits[1] = address->PadY(); | |
328 | fDigits[2] = address->Cathode(); | |
329 | fDigits[3] = q; | |
330 | fDigits[4] = address->Physics(); | |
331 | fDigits[5] = address->Hit(); | |
332 | ||
8f36c696 | 333 | Int_t nptracks = address->GetNTracks(); |
28752ff4 | 334 | |
8f36c696 | 335 | if (nptracks > kMAXTRACKS) { |
0e88acc2 | 336 | if (GetDebug() >0) { |
337 | cerr<<"AliMUONDigitizer: nptracks > 10 "<<nptracks; | |
8f36c696 | 338 | cerr<<"reset to max value "<<kMAXTRACKS<<endl; |
0e88acc2 | 339 | } |
8f36c696 | 340 | nptracks = kMAXTRACKS; |
28752ff4 | 341 | } |
342 | if (nptracks > 2 && GetDebug() >2) { | |
0e88acc2 | 343 | cerr<<"AliMUONDigitizer: nptracks > 2 "<<nptracks<<endl; |
28752ff4 | 344 | printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q); |
345 | } | |
346 | for (Int_t tr = 0; tr < nptracks; tr++) { | |
8f36c696 | 347 | tracks[tr] = address->GetTrack(tr); |
348 | charges[tr] = address->GetCharge(tr); | |
28752ff4 | 349 | } //end loop over list of tracks for one pad |
350 | // Sort list of tracks according to charge | |
351 | if (nptracks > 1) { | |
352 | SortTracks(tracks,charges,nptracks); | |
353 | } | |
8f36c696 | 354 | if (nptracks < kMAXTRACKS ) { |
355 | for (Int_t i = nptracks; i < kMAXTRACKS; i++) { | |
28752ff4 | 356 | tracks[i] = 0; |
357 | charges[i] = 0; | |
358 | } | |
359 | } | |
360 | ||
361 | // fill digits | |
362 | pMUON->AddDigits(ich,tracks,charges,fDigits); | |
28752ff4 | 363 | } |
364 | ||
365 | fManager->GetTreeD()->Fill(); | |
366 | ||
367 | pMUON->ResetDigits(); // | |
368 | fTDList->Clear(); | |
369 | ||
370 | ||
371 | for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) { | |
372 | if (fHitMap[ii]) { | |
373 | delete fHitMap[ii]; | |
374 | fHitMap[ii] = 0; | |
375 | } | |
376 | } | |
28752ff4 | 377 | } //end loop over cathodes |
378 | if (GetDebug()>2) | |
b8278504 | 379 | cerr<<"AliMUONDigitizer::Exec: writing the TreeD: " |
28752ff4 | 380 | <<fManager->GetTreeD()->GetName()<<endl; |
b8278504 | 381 | fManager->GetTreeD()->Write(0,TObject::kOverwrite); |
28752ff4 | 382 | delete [] fHitMap; |
383 | delete fTDList; | |
384 | ||
28752ff4 | 385 | if (fHits) fHits->Delete(); |
386 | if (fPadHits) fPadHits->Delete(); | |
28752ff4 | 387 | } |
388 | ||
389 | ||
b8278504 | 390 | //------------------------------------------------------------------------ |
28752ff4 | 391 | void AliMUONDigitizer::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr) |
392 | { | |
393 | // | |
394 | // Sort the list of tracks contributing to a given digit | |
395 | // Only the 3 most significant tracks are acctually sorted | |
396 | // | |
397 | ||
398 | // | |
399 | // Loop over signals, only 3 times | |
400 | // | |
401 | ||
402 | Int_t qmax; | |
403 | Int_t jmax; | |
404 | Int_t idx[3] = {-2,-2,-2}; | |
405 | Int_t jch[3] = {-2,-2,-2}; | |
406 | Int_t jtr[3] = {-2,-2,-2}; | |
407 | Int_t i,j,imax; | |
408 | ||
409 | if (ntr<3) imax=ntr; | |
410 | else imax=3; | |
411 | for(i=0;i<imax;i++){ | |
412 | qmax=0; | |
413 | jmax=0; | |
414 | ||
415 | for(j=0;j<ntr;j++){ | |
416 | ||
417 | if((i == 1 && j == idx[i-1]) | |
418 | ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue; | |
419 | ||
420 | if(charges[j] > qmax) { | |
421 | qmax = charges[j]; | |
422 | jmax=j; | |
423 | } | |
424 | } | |
425 | ||
426 | if(qmax > 0) { | |
427 | idx[i]=jmax; | |
428 | jch[i]=charges[jmax]; | |
429 | jtr[i]=tracks[jmax]; | |
430 | } | |
431 | ||
432 | } | |
433 | ||
434 | for(i=0;i<3;i++){ | |
435 | if (jtr[i] == -2) { | |
436 | charges[i]=0; | |
437 | tracks[i]=0; | |
438 | } else { | |
439 | charges[i]=jch[i]; | |
440 | tracks[i]=jtr[i]; | |
441 | } | |
442 | } | |
443 | } |