]>
Commit | Line | Data |
---|---|---|
66f93042 | 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$ */ |
ba030c0e | 17 | |
116cbefd | 18 | #include <TObjArray.h> |
88cb7938 | 19 | #include <TFile.h> |
30178c30 | 20 | #include <TError.h> |
21 | //#include <TTree.h> | |
22 | //#include <TDirectory.h> | |
66f93042 | 23 | |
116cbefd | 24 | #include "AliMUONMerger.h" |
30178c30 | 25 | #include "AliMUON.h" |
66f93042 | 26 | #include "AliMUONPadHit.h" |
66f93042 | 27 | #include "AliMUONTransientDigit.h" |
30178c30 | 28 | #include "AliHitMap.h" |
29 | //#include "AliMUONChamber.h" | |
30 | //#include "AliMUONConstants.h" | |
31 | //#include "AliMUONHit.h" | |
32 | //#include "AliMUONHitMapA1.h" | |
33 | //#include "AliRun.h" | |
66f93042 | 34 | |
35 | ClassImp(AliMUONMerger) | |
36 | ||
11ca64ac | 37 | //---------------------------------------------------------------------- |
66f93042 | 38 | AliMUONMerger::AliMUONMerger() |
39 | { | |
40 | // Default constructor | |
41 | fEvNrSig = 0; | |
42 | fEvNrBgr = 0; | |
43 | fMerge = kDigitize; | |
44 | fFnBgr = 0; | |
45 | fHitMap = 0; | |
46 | fList = 0; | |
47 | fTrH1 = 0; | |
48 | fHitsBgr = 0; | |
49 | fPadHitsBgr = 0; | |
50 | fHitMap = 0; | |
51 | fList = 0; | |
77ccf5b0 | 52 | fBgrFile = 0; |
ba030c0e | 53 | fDebug = 0; |
66f93042 | 54 | } |
55 | ||
11ca64ac | 56 | //---------------------------------------------------------------------- |
57 | AliMUONMerger::AliMUONMerger(const AliMUONMerger&) | |
58 | { | |
59 | // Protected copy constructor | |
60 | ||
61 | Fatal("AliMUONMergerModule", "Not implemented."); | |
62 | } | |
63 | ||
66f93042 | 64 | //------------------------------------------------------------------------ |
65 | AliMUONMerger::~AliMUONMerger() | |
66 | { | |
67 | // Destructor | |
68 | if (fTrH1) delete fTrH1; | |
69 | if (fHitsBgr) delete fHitsBgr; | |
70 | if (fPadHitsBgr) delete fPadHitsBgr; | |
3ec837bb | 71 | if (fHitMap) delete [] fHitMap; |
66f93042 | 72 | if (fList) delete fList; |
77ccf5b0 | 73 | if (fBgrFile) delete fBgrFile; |
66f93042 | 74 | } |
75 | ||
11ca64ac | 76 | //---------------------------------------------------------------------- |
77 | AliMUONMerger& AliMUONMerger::operator=(const AliMUONMerger& rhs) | |
78 | { | |
79 | // Protected assignement operator | |
80 | ||
81 | if (this == &rhs) return *this; | |
82 | ||
83 | Fatal("operator=", "Not implemented."); | |
84 | ||
85 | return *this; | |
86 | } | |
87 | ||
66f93042 | 88 | //------------------------------------------------------------------------ |
c7955c78 | 89 | Bool_t AliMUONMerger::Exists(const AliMUONPadHit *padhit) const |
66f93042 | 90 | { |
3ec837bb | 91 | // test if the given padhit was already fired |
66f93042 | 92 | return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY())); |
93 | } | |
94 | ||
95 | //------------------------------------------------------------------------ | |
8f36c696 | 96 | void AliMUONMerger::Update(AliMUONPadHit *padhit) |
66f93042 | 97 | { |
3ec837bb | 98 | // add new contribution to the fired padhit |
8f36c696 | 99 | AliMUONTransientDigit *pdigit = |
100 | static_cast<AliMUONTransientDigit*>( | |
101 | fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY())); | |
66f93042 | 102 | |
66f93042 | 103 | // update charge |
104 | // | |
8f36c696 | 105 | Int_t iqpad = padhit->QPad(); // charge per pad |
106 | pdigit->AddSignal(iqpad); | |
107 | pdigit->AddPhysicsSignal(iqpad); | |
108 | ||
66f93042 | 109 | // update list of tracks |
110 | // | |
3351e14b | 111 | Int_t track, charge; |
8f36c696 | 112 | if (fSignal) { |
113 | track = fTrack; | |
114 | charge = iqpad; | |
66f93042 | 115 | } else { |
8f36c696 | 116 | track = kBgTag; |
117 | charge = kBgTag; | |
66f93042 | 118 | } |
8f36c696 | 119 | pdigit->UpdateTrackList(track,charge); |
66f93042 | 120 | } |
121 | ||
122 | //------------------------------------------------------------------------ | |
8f36c696 | 123 | void AliMUONMerger::CreateNew(AliMUONPadHit *padhit) |
66f93042 | 124 | { |
3ec837bb | 125 | // add new transient digit to the list, update hit map |
66f93042 | 126 | fList->AddAtAndExpand( |
127 | new AliMUONTransientDigit(fNch,fDigits),fCounter); | |
8f36c696 | 128 | fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter); |
129 | AliMUONTransientDigit* pdigit = | |
c7955c78 | 130 | static_cast<AliMUONTransientDigit*>(fList->Last()); |
66f93042 | 131 | // list of tracks |
8f36c696 | 132 | Int_t track, charge; |
133 | if (fSignal) { | |
134 | track = fTrack; | |
135 | charge = padhit->QPad(); | |
136 | } else { | |
137 | track = kBgTag; | |
138 | charge = kBgTag; | |
139 | } | |
140 | pdigit->AddToTrackList(track,charge); | |
141 | fCounter++; | |
66f93042 | 142 | } |
143 | ||
144 | ||
145 | //------------------------------------------------------------------------ | |
146 | void AliMUONMerger::Init() | |
147 | { | |
148 | // Initialisation | |
77ccf5b0 | 149 | // open only once the background file !! |
150 | if (fMerge && !fBgrFile) fBgrFile = InitBgr(); | |
66f93042 | 151 | } |
152 | ||
153 | ||
154 | ||
155 | //------------------------------------------------------------------------ | |
156 | TFile* AliMUONMerger::InitBgr() | |
157 | { | |
158 | // Initialise background event | |
159 | TFile *file = new TFile(fFnBgr); | |
160 | // add error checking later | |
161 | printf("\n AliMUONMerger has opened %s file with background event \n", fFnBgr); | |
162 | fHitsBgr = new TClonesArray("AliMUONHit",1000); | |
163 | fPadHitsBgr = new TClonesArray("AliMUONPadHit",1000); | |
164 | return file; | |
165 | } | |
166 | ||
167 | //------------------------------------------------------------------------ | |
168 | void AliMUONMerger::Digitise() | |
169 | { | |
170 | ||
171 | // keep galice.root for signal and name differently the file for | |
172 | // background when add! otherwise the track info for signal will be lost ! | |
ce3f5e87 | 173 | // Obsolete sep 2003 Gines MARTINEZ |
174 | // AliMUONChamber* iChamber; | |
175 | // AliSegmentation* segmentation; | |
176 | ||
177 | // fList = new TObjArray; | |
178 | ||
179 | // AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON"); | |
180 | // fHitMap= new AliHitMap* [AliMUONConstants::NCh()]; | |
181 | // if (fMerge ) { | |
182 | // fBgrFile->cd(); | |
183 | // // | |
184 | // // Get Hits Tree header from file | |
185 | // //if(fHitsBgr) fHitsBgr->Clear(); // Useless because line 327 | |
186 | // //if(fPadHitsBgr) fPadHitsBgr->Clear(); // Useless because line 328 | |
187 | // if(fTrH1) delete fTrH1; | |
188 | // fTrH1 = 0; | |
66f93042 | 189 | |
ce3f5e87 | 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); | |
195 | // } | |
196 | // // | |
197 | // // Set branch addresses | |
198 | // TBranch *branch; | |
199 | // char branchname[20]; | |
200 | // sprintf(branchname,"%s",pMUON->GetName()); | |
201 | // if (fTrH1 && fHitsBgr) { | |
202 | // branch = fTrH1->GetBranch(branchname); | |
203 | // if (branch) branch->SetAddress(&fHitsBgr); | |
204 | // } | |
205 | // if (fTrH1 && fPadHitsBgr) { | |
206 | // branch = fTrH1->GetBranch("MUONCluster"); | |
207 | // if (branch) branch->SetAddress(&fPadHitsBgr); | |
208 | // } | |
209 | // } | |
210 | // // | |
211 | // // loop over cathodes | |
212 | // // | |
213 | // fSignal = kTRUE; | |
214 | // for (int icat = 0; icat < 2; icat++) { | |
215 | // fCounter = 0; | |
216 | // for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) { | |
217 | // iChamber = &(pMUON->Chamber(i)); | |
218 | // if (iChamber->Nsec() == 1 && icat == 1) { | |
219 | // continue; | |
220 | // } else { | |
221 | // segmentation = iChamber->SegmentationModel(icat+1); | |
222 | // } | |
223 | // fHitMap[i] = new AliMUONHitMapA1(segmentation, fList); | |
224 | // } | |
225 | ||
226 | // // | |
227 | // // Loop over tracks | |
228 | // // | |
229 | ||
230 | // /******************************************************************/ | |
231 | // TTree* treeH = pMUON->TreeH(); | |
232 | // if (treeH == 0x0) | |
233 | // { | |
234 | // cerr<<"AliMUONMerger::Exec: Can not get TreeH"<<endl; | |
235 | // return; | |
236 | // } | |
237 | // /******************************************************************/ | |
88cb7938 | 238 | |
239 | ||
240 | ||
ce3f5e87 | 241 | // Int_t ntracks = (Int_t) treeH->GetEntries(); |
242 | // treeH->SetBranchStatus("*",0); // switch off all branches | |
243 | // treeH->SetBranchStatus("MUON*",1); // switch on only MUON | |
244 | ||
245 | // for (fTrack = 0; fTrack < ntracks; fTrack++) { | |
246 | // gAlice->ResetHits(); | |
247 | // treeH->GetEntry(fTrack,0); | |
248 | // // | |
249 | // // Loop over hits | |
250 | // for(AliMUONHit* mHit = (AliMUONHit*)pMUON->FirstHit(-1); | |
251 | // mHit; | |
252 | // mHit = (AliMUONHit*)pMUON->NextHit()) | |
253 | // { | |
254 | // fNch = mHit->Chamber()-1; // chamber number | |
255 | // if (fNch > AliMUONConstants::NCh()-1) continue; | |
256 | // iChamber = &(pMUON->Chamber(fNch)); | |
66f93042 | 257 | |
ce3f5e87 | 258 | // // |
259 | // // Loop over pad hits | |
260 | // for (AliMUONPadHit* mPad = | |
261 | // (AliMUONPadHit*)pMUON->FirstPad(mHit,pMUON->PadHits()); | |
262 | // mPad; | |
263 | // mPad = (AliMUONPadHit*)pMUON->NextPad(pMUON->PadHits())) | |
264 | // { | |
265 | // Int_t cathode = mPad->Cathode(); // cathode number | |
266 | // if (cathode != (icat+1)) continue; | |
267 | // Int_t iqpad = Int_t(mPad->QPad()); // charge per pad | |
268 | // // segmentation = iChamber->SegmentationModel(cathode); | |
269 | // fDigits[0] = mPad->PadX(); | |
270 | // fDigits[1] = mPad->PadY(); | |
271 | // if (!(fHitMap[fNch]->ValidateHit(fDigits[0], fDigits[1]))) continue; | |
272 | // fDigits[2] = icat; | |
273 | // fDigits[3] = iqpad; | |
274 | // fDigits[4] = iqpad; | |
275 | // if (mHit->Particle() == kMuonPlus || | |
276 | // mHit->Particle() == kMuonMinus) { | |
277 | // fDigits[5] = mPad->HitNumber(); | |
278 | // } else fDigits[5] = -1; | |
279 | ||
280 | // // build the list of fired pads and update the info | |
281 | ||
282 | // if (!Exists(mPad)) { | |
283 | // CreateNew(mPad); | |
284 | // } else { | |
285 | // Update(mPad); | |
286 | // } // end if pdigit | |
287 | // } //end loop over clusters | |
288 | // } // hit loop | |
289 | // } // track loop | |
290 | ||
291 | // // open the file with background | |
66f93042 | 292 | |
ce3f5e87 | 293 | // if (fMerge) { |
294 | // fSignal = kFALSE; | |
295 | // ntracks = (Int_t)fTrH1->GetEntries(); | |
296 | // // | |
297 | // // Loop over tracks | |
298 | // // | |
299 | // for (fTrack = 0; fTrack < ntracks; fTrack++) { | |
300 | ||
301 | // if (fHitsBgr) fHitsBgr->Clear(); | |
302 | // if (fPadHitsBgr) fPadHitsBgr->Clear(); | |
303 | ||
304 | // fTrH1->GetEvent(fTrack); | |
305 | // // | |
306 | // // Loop over hits | |
307 | // AliMUONHit* mHit; | |
308 | // for(Int_t i = 0; i < fHitsBgr->GetEntriesFast(); ++i) | |
309 | // { | |
310 | // mHit = (AliMUONHit*) (*fHitsBgr)[i]; | |
311 | // fNch = mHit->Chamber()-1; // chamber number | |
312 | // iChamber = &(pMUON->Chamber(fNch)); | |
313 | // // | |
314 | // // Loop over pad hits | |
315 | // for (AliMUONPadHit* mPad = | |
316 | // (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHitsBgr); | |
317 | // mPad; | |
318 | // mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHitsBgr)) | |
319 | // { | |
320 | // Int_t cathode = mPad->Cathode(); // cathode number | |
321 | // Int_t ipx = mPad->PadX(); // pad number on X | |
322 | // Int_t ipy = mPad->PadY(); // pad number on Y | |
323 | // Int_t iqpad = Int_t(mPad->QPad()); // charge per pad | |
324 | // if (!(fHitMap[fNch]->ValidateHit(ipx, ipy))) continue; | |
325 | ||
326 | // if (cathode != (icat+1)) continue; | |
327 | // fDigits[0] = ipx; | |
328 | // fDigits[1] = ipy; | |
329 | // fDigits[2] = icat; | |
330 | // fDigits[3] = iqpad; | |
331 | // fDigits[4] = 0; | |
332 | // fDigits[5] = -1; | |
66f93042 | 333 | |
ce3f5e87 | 334 | // // build the list of fired pads and update the info |
335 | // if (!Exists(mPad)) { | |
336 | // CreateNew(mPad); | |
337 | // } else { | |
338 | // Update(mPad); | |
339 | // } // end if !Exists | |
340 | // } //end loop over clusters | |
341 | // } // hit loop | |
342 | // } // track loop | |
343 | ||
344 | // TTree *treeK = gAlice->TreeK(); | |
345 | // TFile *file = NULL; | |
66f93042 | 346 | |
ce3f5e87 | 347 | // if (treeK) file = treeK->GetCurrentFile(); |
348 | // file->cd(); | |
349 | // } // if fMerge | |
66f93042 | 350 | |
ce3f5e87 | 351 | // Int_t tracks[kMAXTRACKS]; |
352 | // Int_t charges[kMAXTRACKS]; | |
353 | // Int_t nentries = fList->GetEntriesFast(); | |
66f93042 | 354 | |
ce3f5e87 | 355 | // for (Int_t nent = 0; nent < nentries; nent++) { |
356 | // AliMUONTransientDigit *address = (AliMUONTransientDigit*)fList->At(nent); | |
357 | // if (address == 0) continue; | |
358 | // Int_t ich = address->Chamber(); | |
359 | // Int_t q = address->Signal(); | |
360 | // iChamber = &(pMUON->Chamber(ich)); | |
361 | // // | |
362 | // // Digit Response (noise, threshold, saturation, ...) | |
363 | // AliMUONResponse * response = iChamber->ResponseModel(); | |
364 | // q = response->DigitResponse(q,address); | |
66f93042 | 365 | |
ce3f5e87 | 366 | // if (!q) continue; |
66f93042 | 367 | |
ce3f5e87 | 368 | // fDigits[0] = address->PadX(); |
369 | // fDigits[1] = address->PadY(); | |
370 | // fDigits[2] = address->Cathode(); | |
371 | // fDigits[3] = q; | |
372 | // fDigits[4] = address->Physics(); | |
373 | // fDigits[5] = address->Hit(); | |
66f93042 | 374 | |
ce3f5e87 | 375 | // Int_t nptracks = address->GetNTracks(); |
376 | ||
377 | // if (nptracks > kMAXTRACKS) { | |
378 | // if (fDebug>0) | |
379 | // printf("\n Attention - nptracks > kMAXTRACKS %d \n", nptracks); | |
380 | // nptracks = kMAXTRACKS; | |
381 | // } | |
382 | // if (nptracks > 2) { | |
383 | // if (fDebug>0) { | |
384 | // printf("Attention - nptracks > 2 %d \n",nptracks); | |
385 | // printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q); | |
386 | // } | |
387 | // } | |
388 | // for (Int_t tr = 0; tr < nptracks; tr++) { | |
389 | // tracks[tr] = address->GetTrack(tr); | |
390 | // charges[tr] = address->GetCharge(tr); | |
391 | // } //end loop over list of tracks for one pad | |
392 | // // Sort list of tracks according to charge | |
393 | // if (nptracks > 1) { | |
394 | // SortTracks(tracks,charges,nptracks); | |
395 | // } | |
396 | // if (nptracks < kMAXTRACKS ) { | |
397 | // for (Int_t i = nptracks; i < kMAXTRACKS; i++) { | |
398 | // tracks[i] = 0; | |
399 | // charges[i] = 0; | |
400 | // } | |
401 | // } | |
66f93042 | 402 | |
ce3f5e87 | 403 | // // fill digits |
404 | // pMUON->AddDigits(ich,tracks,charges,fDigits); | |
405 | // } | |
406 | // gAlice->TreeD()->Fill(); | |
407 | // pMUON->ResetDigits(); | |
408 | // fList->Delete(); | |
66f93042 | 409 | |
410 | ||
ce3f5e87 | 411 | // for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) { |
412 | // if (fHitMap[ii]) { | |
413 | // delete fHitMap[ii]; | |
414 | // fHitMap[ii] = 0; | |
415 | // } | |
416 | // } | |
417 | // } //end loop over cathodes | |
418 | // delete [] fHitMap; | |
419 | // delete fList; | |
66f93042 | 420 | |
77ccf5b0 | 421 | // no need to delete ... and it makes a crash also |
422 | // if (fHitsBgr) fHitsBgr->Delete(); | |
423 | // if (fPadHitsBgr) fPadHitsBgr->Delete(); | |
66f93042 | 424 | // gObjectTable->Print(); |
425 | } | |
426 | ||
427 | ||
428 | ||
30178c30 | 429 | void AliMUONMerger::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr) const |
a3f472a9 | 430 | { |
431 | // | |
432 | // Sort the list of tracks contributing to a given digit | |
433 | // Only the 3 most significant tracks are acctually sorted | |
434 | // | |
435 | ||
436 | // | |
437 | // Loop over signals, only 3 times | |
438 | // | |
439 | ||
440 | Int_t qmax; | |
441 | Int_t jmax; | |
442 | Int_t idx[3] = {-2,-2,-2}; | |
443 | Int_t jch[3] = {-2,-2,-2}; | |
444 | Int_t jtr[3] = {-2,-2,-2}; | |
445 | Int_t i,j,imax; | |
446 | ||
447 | if (ntr<3) imax=ntr; | |
448 | else imax=3; | |
449 | for(i=0;i<imax;i++){ | |
450 | qmax=0; | |
451 | jmax=0; | |
452 | ||
453 | for(j=0;j<ntr;j++){ | |
454 | ||
455 | if((i == 1 && j == idx[i-1]) | |
456 | ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue; | |
457 | ||
458 | if(charges[j] > qmax) { | |
459 | qmax = charges[j]; | |
460 | jmax=j; | |
461 | } | |
462 | } | |
463 | ||
464 | if(qmax > 0) { | |
465 | idx[i]=jmax; | |
466 | jch[i]=charges[jmax]; | |
467 | jtr[i]=tracks[jmax]; | |
468 | } | |
469 | ||
470 | } | |
471 | ||
472 | for(i=0;i<3;i++){ | |
473 | if (jtr[i] == -2) { | |
474 | charges[i]=0; | |
475 | tracks[i]=0; | |
476 | } else { | |
477 | charges[i]=jch[i]; | |
478 | tracks[i]=jtr[i]; | |
479 | } | |
480 | } | |
481 | } | |
482 | ||
66f93042 | 483 | |
484 |