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