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