1 /**************************************************************************
2 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.10 2003/01/14 10:50:19 alibrary
19 Cleanup of STEER coding conventions
21 Revision 1.9 2002/03/13 07:04:11 jchudoba
22 Connect only MUON branches when reading the event to speed up digitisation.
24 Revision 1.8 2002/02/22 12:14:21 morsch
25 Validate pad hit before digitization.
27 Revision 1.7 2001/11/22 11:15:41 jchudoba
28 Proper deletion of arrays (thanks to Rene Brun)
30 Revision 1.6 2001/11/02 12:55:45 jchudoba
31 cleanup of the code, add const to Get methods
33 Revision 1.5 2001/10/31 16:35:07 jchudoba
34 some functionality move to AliMUONTransientDigit class
36 Revision 1.4 2001/03/20 13:36:11 egangler
37 TFile memory leak and "too many files open" problem solved (?):
38 the backgroud file is open only once forever, and not once for each event.
40 Revision 1.3 2001/03/05 23:57:44 morsch
41 Writing of digit tree moved to macro.
43 Revision 1.2 2001/03/05 08:40:25 morsch
44 Method SortTracks(..) imported from AliMUON.
46 Revision 1.1 2001/02/02 14:11:53 morsch
47 AliMUONMerger prototype to be called by the merge manager.
51 #include <TDirectory.h>
53 #include <TObjArray.h>
57 #include "AliHitMap.h"
59 #include "AliMUONChamber.h"
60 #include "AliMUONConstants.h"
61 #include "AliMUONDigit.h"
62 #include "AliMUONHit.h"
63 #include "AliMUONHitMapA1.h"
64 #include "AliMUONMerger.h"
65 #include "AliMUONPadHit.h"
66 #include "AliMUONTransientDigit.h"
69 ClassImp(AliMUONMerger)
71 //___________________________________________
72 AliMUONMerger::AliMUONMerger()
74 // Default constructor
90 //------------------------------------------------------------------------
91 AliMUONMerger::~AliMUONMerger()
94 if (fTrH1) delete fTrH1;
95 if (fHitsBgr) delete fHitsBgr;
96 if (fPadHitsBgr) delete fPadHitsBgr;
97 if (fHitMap) delete [] fHitMap;
98 if (fList) delete fList;
99 if (fBgrFile) delete fBgrFile;
102 //------------------------------------------------------------------------
103 Bool_t AliMUONMerger::Exists(const AliMUONPadHit *padhit) const
105 // test if the given padhit was already fired
106 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
109 //------------------------------------------------------------------------
110 void AliMUONMerger::Update(AliMUONPadHit *padhit)
112 // add new contribution to the fired padhit
113 AliMUONTransientDigit *pdigit =
114 static_cast<AliMUONTransientDigit*>(
115 fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
119 Int_t iqpad = padhit->QPad(); // charge per pad
120 pdigit->AddSignal(iqpad);
121 pdigit->AddPhysicsSignal(iqpad);
123 // update list of tracks
133 pdigit->UpdateTrackList(track,charge);
136 //------------------------------------------------------------------------
137 void AliMUONMerger::CreateNew(AliMUONPadHit *padhit)
139 // add new transient digit to the list, update hit map
140 fList->AddAtAndExpand(
141 new AliMUONTransientDigit(fNch,fDigits),fCounter);
142 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
143 AliMUONTransientDigit* pdigit =
144 static_cast<AliMUONTransientDigit*>(fList->Last());
149 charge = padhit->QPad();
154 pdigit->AddToTrackList(track,charge);
159 //------------------------------------------------------------------------
160 void AliMUONMerger::Init()
163 // open only once the background file !!
164 if (fMerge && !fBgrFile) fBgrFile = InitBgr();
169 //------------------------------------------------------------------------
170 TFile* AliMUONMerger::InitBgr()
172 // Initialise background event
173 TFile *file = new TFile(fFnBgr);
174 // add error checking later
175 printf("\n AliMUONMerger has opened %s file with background event \n", fFnBgr);
176 fHitsBgr = new TClonesArray("AliMUONHit",1000);
177 fPadHitsBgr = new TClonesArray("AliMUONPadHit",1000);
181 //------------------------------------------------------------------------
182 void AliMUONMerger::Digitise()
185 // keep galice.root for signal and name differently the file for
186 // background when add! otherwise the track info for signal will be lost !
188 AliMUONChamber* iChamber;
189 AliSegmentation* segmentation;
191 fList = new TObjArray;
193 AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
194 fHitMap= new AliHitMap* [AliMUONConstants::NCh()];
198 // Get Hits Tree header from file
199 //if(fHitsBgr) fHitsBgr->Clear(); // Useless because line 327
200 //if(fPadHitsBgr) fPadHitsBgr->Clear(); // Useless because line 328
201 if(fTrH1) delete fTrH1;
205 sprintf(treeName,"TreeH%d",fEvNrBgr);
206 fTrH1 = (TTree*)gDirectory->Get(treeName);
208 printf("ERROR: cannot find Hits Tree for event:%d\n",fEvNrBgr);
211 // Set branch addresses
214 sprintf(branchname,"%s",pMUON->GetName());
215 if (fTrH1 && fHitsBgr) {
216 branch = fTrH1->GetBranch(branchname);
217 if (branch) branch->SetAddress(&fHitsBgr);
219 if (fTrH1 && fPadHitsBgr) {
220 branch = fTrH1->GetBranch("MUONCluster");
221 if (branch) branch->SetAddress(&fPadHitsBgr);
225 // loop over cathodes
228 for (int icat = 0; icat < 2; icat++) {
230 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
231 iChamber = &(pMUON->Chamber(i));
232 if (iChamber->Nsec() == 1 && icat == 1) {
235 segmentation = iChamber->SegmentationModel(icat+1);
237 fHitMap[i] = new AliMUONHitMapA1(segmentation, fList);
244 TTree *treeH = gAlice->TreeH();
245 Int_t ntracks = (Int_t) treeH->GetEntries();
246 treeH->SetBranchStatus("*",0); // switch off all branches
247 treeH->SetBranchStatus("MUON*",1); // switch on only MUON
249 for (fTrack = 0; fTrack < ntracks; fTrack++) {
251 treeH->GetEntry(fTrack,0);
254 for(AliMUONHit* mHit = (AliMUONHit*)pMUON->FirstHit(-1);
256 mHit = (AliMUONHit*)pMUON->NextHit())
258 fNch = mHit->Chamber()-1; // chamber number
259 if (fNch > AliMUONConstants::NCh()-1) continue;
260 iChamber = &(pMUON->Chamber(fNch));
263 // Loop over pad hits
264 for (AliMUONPadHit* mPad =
265 (AliMUONPadHit*)pMUON->FirstPad(mHit,pMUON->PadHits());
267 mPad = (AliMUONPadHit*)pMUON->NextPad(pMUON->PadHits()))
269 Int_t cathode = mPad->Cathode(); // cathode number
270 if (cathode != (icat+1)) continue;
271 Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
272 // segmentation = iChamber->SegmentationModel(cathode);
273 fDigits[0] = mPad->PadX();
274 fDigits[1] = mPad->PadY();
275 if (!(fHitMap[fNch]->ValidateHit(fDigits[0], fDigits[1]))) continue;
279 if (mHit->Particle() == kMuonPlus ||
280 mHit->Particle() == kMuonMinus) {
281 fDigits[5] = mPad->HitNumber();
282 } else fDigits[5] = -1;
284 // build the list of fired pads and update the info
291 } //end loop over clusters
295 // open the file with background
299 ntracks = (Int_t)fTrH1->GetEntries();
303 for (fTrack = 0; fTrack < ntracks; fTrack++) {
305 if (fHitsBgr) fHitsBgr->Clear();
306 if (fPadHitsBgr) fPadHitsBgr->Clear();
308 fTrH1->GetEvent(fTrack);
312 for(Int_t i = 0; i < fHitsBgr->GetEntriesFast(); ++i)
314 mHit = (AliMUONHit*) (*fHitsBgr)[i];
315 fNch = mHit->Chamber()-1; // chamber number
316 iChamber = &(pMUON->Chamber(fNch));
318 // Loop over pad hits
319 for (AliMUONPadHit* mPad =
320 (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHitsBgr);
322 mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHitsBgr))
324 Int_t cathode = mPad->Cathode(); // cathode number
325 Int_t ipx = mPad->PadX(); // pad number on X
326 Int_t ipy = mPad->PadY(); // pad number on Y
327 Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
328 if (!(fHitMap[fNch]->ValidateHit(ipx, ipy))) continue;
330 if (cathode != (icat+1)) continue;
338 // build the list of fired pads and update the info
344 } //end loop over clusters
348 TTree *treeK = gAlice->TreeK();
351 if (treeK) file = treeK->GetCurrentFile();
355 Int_t tracks[kMAXTRACKS];
356 Int_t charges[kMAXTRACKS];
357 Int_t nentries = fList->GetEntriesFast();
359 for (Int_t nent = 0; nent < nentries; nent++) {
360 AliMUONTransientDigit *address = (AliMUONTransientDigit*)fList->At(nent);
361 if (address == 0) continue;
362 Int_t ich = address->Chamber();
363 Int_t q = address->Signal();
364 iChamber = &(pMUON->Chamber(ich));
366 // Digit Response (noise, threshold, saturation, ...)
367 AliMUONResponse * response = iChamber->ResponseModel();
368 q = response->DigitResponse(q,address);
372 fDigits[0] = address->PadX();
373 fDigits[1] = address->PadY();
374 fDigits[2] = address->Cathode();
376 fDigits[4] = address->Physics();
377 fDigits[5] = address->Hit();
379 Int_t nptracks = address->GetNTracks();
381 if (nptracks > kMAXTRACKS) {
383 printf("\n Attention - nptracks > kMAXTRACKS %d \n", nptracks);
384 nptracks = kMAXTRACKS;
388 printf("Attention - nptracks > 2 %d \n",nptracks);
389 printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q);
392 for (Int_t tr = 0; tr < nptracks; tr++) {
393 tracks[tr] = address->GetTrack(tr);
394 charges[tr] = address->GetCharge(tr);
395 } //end loop over list of tracks for one pad
396 // Sort list of tracks according to charge
398 SortTracks(tracks,charges,nptracks);
400 if (nptracks < kMAXTRACKS ) {
401 for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
408 pMUON->AddDigits(ich,tracks,charges,fDigits);
410 gAlice->TreeD()->Fill();
411 pMUON->ResetDigits();
415 for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) {
421 } //end loop over cathodes
425 // no need to delete ... and it makes a crash also
426 // if (fHitsBgr) fHitsBgr->Delete();
427 // if (fPadHitsBgr) fPadHitsBgr->Delete();
428 // gObjectTable->Print();
433 void AliMUONMerger::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
436 // Sort the list of tracks contributing to a given digit
437 // Only the 3 most significant tracks are acctually sorted
441 // Loop over signals, only 3 times
446 Int_t idx[3] = {-2,-2,-2};
447 Int_t jch[3] = {-2,-2,-2};
448 Int_t jtr[3] = {-2,-2,-2};
459 if((i == 1 && j == idx[i-1])
460 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
462 if(charges[j] > qmax) {
470 jch[i]=charges[jmax];