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.6 2001/11/02 12:55:45 jchudoba
19 cleanup of the code, add const to Get methods
21 Revision 1.5 2001/10/31 16:35:07 jchudoba
22 some functionality move to AliMUONTransientDigit class
24 Revision 1.4 2001/03/20 13:36:11 egangler
25 TFile memory leak and "too many files open" problem solved (?):
26 the backgroud file is open only once forever, and not once for each event.
28 Revision 1.3 2001/03/05 23:57:44 morsch
29 Writing of digit tree moved to macro.
31 Revision 1.2 2001/03/05 08:40:25 morsch
32 Method SortTracks(..) imported from AliMUON.
34 Revision 1.1 2001/02/02 14:11:53 morsch
35 AliMUONMerger prototype to be called by the merge manager.
40 #include <TObjArray.h>
42 #include <TDirectory.h>
44 #include "AliMUONMerger.h"
45 #include "AliMUONConstants.h"
46 #include "AliMUONChamber.h"
47 #include "AliHitMap.h"
48 #include "AliMUONHitMapA1.h"
50 #include "AliMUONHit.h"
51 #include "AliMUONPadHit.h"
52 #include "AliMUONDigit.h"
53 #include "AliMUONTransientDigit.h"
57 ClassImp(AliMUONMerger)
59 //___________________________________________
60 AliMUONMerger::AliMUONMerger()
62 // Default constructor
77 //------------------------------------------------------------------------
78 AliMUONMerger::~AliMUONMerger()
81 if (fTrH1) delete fTrH1;
82 if (fHitsBgr) delete fHitsBgr;
83 if (fPadHitsBgr) delete fPadHitsBgr;
84 if (fHitMap) delete [] fHitMap;
85 if (fList) delete fList;
86 if (fBgrFile) delete fBgrFile;
89 //------------------------------------------------------------------------
90 Bool_t AliMUONMerger::Exists(const AliMUONPadHit *padhit) const
92 // test if the given padhit was already fired
93 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
96 //------------------------------------------------------------------------
97 void AliMUONMerger::Update(AliMUONPadHit *padhit)
99 // add new contribution to the fired padhit
100 AliMUONTransientDigit *pdigit =
101 static_cast<AliMUONTransientDigit*>(
102 fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
106 Int_t iqpad = padhit->QPad(); // charge per pad
107 pdigit->AddSignal(iqpad);
108 pdigit->AddPhysicsSignal(iqpad);
110 // update list of tracks
120 pdigit->UpdateTrackList(track,charge);
123 //------------------------------------------------------------------------
124 void AliMUONMerger::CreateNew(AliMUONPadHit *padhit)
126 // add new transient digit to the list, update hit map
127 fList->AddAtAndExpand(
128 new AliMUONTransientDigit(fNch,fDigits),fCounter);
129 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
130 AliMUONTransientDigit* pdigit =
131 static_cast<AliMUONTransientDigit*>(fList->Last());
136 charge = padhit->QPad();
141 pdigit->AddToTrackList(track,charge);
146 //------------------------------------------------------------------------
147 void AliMUONMerger::Init()
150 // open only once the background file !!
151 if (fMerge && !fBgrFile) fBgrFile = InitBgr();
156 //------------------------------------------------------------------------
157 TFile* AliMUONMerger::InitBgr()
159 // Initialise background event
160 TFile *file = new TFile(fFnBgr);
161 // add error checking later
162 printf("\n AliMUONMerger has opened %s file with background event \n", fFnBgr);
163 fHitsBgr = new TClonesArray("AliMUONHit",1000);
164 fPadHitsBgr = new TClonesArray("AliMUONPadHit",1000);
168 //------------------------------------------------------------------------
169 void AliMUONMerger::Digitise()
172 // keep galice.root for signal and name differently the file for
173 // background when add! otherwise the track info for signal will be lost !
175 AliMUONChamber* iChamber;
176 AliSegmentation* segmentation;
178 fList = new TObjArray;
180 AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
181 fHitMap= new AliHitMap* [AliMUONConstants::NCh()];
185 // Get Hits Tree header from file
186 //if(fHitsBgr) fHitsBgr->Clear(); // Useless because line 327
187 //if(fPadHitsBgr) fPadHitsBgr->Clear(); // Useless because line 328
188 if(fTrH1) delete fTrH1;
192 sprintf(treeName,"TreeH%d",fEvNrBgr);
193 fTrH1 = (TTree*)gDirectory->Get(treeName);
195 printf("ERROR: cannot find Hits Tree for event:%d\n",fEvNrBgr);
198 // Set branch addresses
201 sprintf(branchname,"%s",pMUON->GetName());
202 if (fTrH1 && fHitsBgr) {
203 branch = fTrH1->GetBranch(branchname);
204 if (branch) branch->SetAddress(&fHitsBgr);
206 if (fTrH1 && fPadHitsBgr) {
207 branch = fTrH1->GetBranch("MUONCluster");
208 if (branch) branch->SetAddress(&fPadHitsBgr);
212 // loop over cathodes
215 for (int icat = 0; icat < 2; icat++) {
217 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
218 iChamber = &(pMUON->Chamber(i));
219 if (iChamber->Nsec() == 1 && icat == 1) {
222 segmentation = iChamber->SegmentationModel(icat+1);
224 fHitMap[i] = new AliMUONHitMapA1(segmentation, fList);
231 TTree *treeH = gAlice->TreeH();
232 Int_t ntracks = (Int_t) treeH->GetEntries();
234 for (fTrack = 0; fTrack < ntracks; fTrack++) {
236 treeH->GetEvent(fTrack);
239 for(AliMUONHit* mHit = (AliMUONHit*)pMUON->FirstHit(-1);
241 mHit = (AliMUONHit*)pMUON->NextHit())
243 fNch = mHit->Chamber()-1; // chamber number
244 if (fNch > AliMUONConstants::NCh()-1) continue;
245 iChamber = &(pMUON->Chamber(fNch));
248 // Loop over pad hits
249 for (AliMUONPadHit* mPad =
250 (AliMUONPadHit*)pMUON->FirstPad(mHit,pMUON->PadHits());
252 mPad = (AliMUONPadHit*)pMUON->NextPad(pMUON->PadHits()))
254 Int_t cathode = mPad->Cathode(); // cathode number
255 if (cathode != (icat+1)) continue;
256 Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
257 // segmentation = iChamber->SegmentationModel(cathode);
258 fDigits[0] = mPad->PadX();
259 fDigits[1] = mPad->PadY();
263 if (mHit->Particle() == kMuonPlus ||
264 mHit->Particle() == kMuonMinus) {
265 fDigits[5] = mPad->HitNumber();
266 } else fDigits[5] = -1;
268 // build the list of fired pads and update the info
275 } //end loop over clusters
279 // open the file with background
283 ntracks = (Int_t)fTrH1->GetEntries();
287 for (fTrack = 0; fTrack < ntracks; fTrack++) {
289 if (fHitsBgr) fHitsBgr->Clear();
290 if (fPadHitsBgr) fPadHitsBgr->Clear();
292 fTrH1->GetEvent(fTrack);
296 for(Int_t i = 0; i < fHitsBgr->GetEntriesFast(); ++i)
298 mHit = (AliMUONHit*) (*fHitsBgr)[i];
299 fNch = mHit->Chamber()-1; // chamber number
300 iChamber = &(pMUON->Chamber(fNch));
302 // Loop over pad hits
303 for (AliMUONPadHit* mPad =
304 (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHitsBgr);
306 mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHitsBgr))
308 Int_t cathode = mPad->Cathode(); // cathode number
309 Int_t ipx = mPad->PadX(); // pad number on X
310 Int_t ipy = mPad->PadY(); // pad number on Y
311 Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
313 if (cathode != (icat+1)) continue;
321 // build the list of fired pads and update the info
327 } //end loop over clusters
331 TTree *treeK = gAlice->TreeK();
334 if (treeK) file = treeK->GetCurrentFile();
338 Int_t tracks[kMAXTRACKS];
339 Int_t charges[kMAXTRACKS];
340 Int_t nentries = fList->GetEntriesFast();
342 for (Int_t nent = 0; nent < nentries; nent++) {
343 AliMUONTransientDigit *address = (AliMUONTransientDigit*)fList->At(nent);
344 if (address == 0) continue;
345 Int_t ich = address->Chamber();
346 Int_t q = address->Signal();
347 iChamber = &(pMUON->Chamber(ich));
349 // Digit Response (noise, threshold, saturation, ...)
350 AliMUONResponse * response = iChamber->ResponseModel();
351 q = response->DigitResponse(q);
355 fDigits[0] = address->PadX();
356 fDigits[1] = address->PadY();
357 fDigits[2] = address->Cathode();
359 fDigits[4] = address->Physics();
360 fDigits[5] = address->Hit();
362 Int_t nptracks = address->GetNTracks();
364 if (nptracks > kMAXTRACKS) {
365 printf("\n Attention - nptracks > kMAXTRACKS %d \n", nptracks);
366 nptracks = kMAXTRACKS;
369 printf("Attention - nptracks > 2 %d \n",nptracks);
370 printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q);
372 for (Int_t tr = 0; tr < nptracks; tr++) {
373 tracks[tr] = address->GetTrack(tr);
374 charges[tr] = address->GetCharge(tr);
375 } //end loop over list of tracks for one pad
376 // Sort list of tracks according to charge
378 SortTracks(tracks,charges,nptracks);
380 if (nptracks < kMAXTRACKS ) {
381 for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
388 pMUON->AddDigits(ich,tracks,charges,fDigits);
390 gAlice->TreeD()->Fill();
391 pMUON->ResetDigits();
395 for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) {
401 } //end loop over cathodes
405 // no need to delete ... and it makes a crash also
406 // if (fHitsBgr) fHitsBgr->Delete();
407 // if (fPadHitsBgr) fPadHitsBgr->Delete();
408 // gObjectTable->Print();
413 void AliMUONMerger::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
416 // Sort the list of tracks contributing to a given digit
417 // Only the 3 most significant tracks are acctually sorted
421 // Loop over signals, only 3 times
426 Int_t idx[3] = {-2,-2,-2};
427 Int_t jch[3] = {-2,-2,-2};
428 Int_t jtr[3] = {-2,-2,-2};
439 if((i == 1 && j == idx[i-1])
440 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
442 if(charges[j] > qmax) {
450 jch[i]=charges[jmax];