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 #include <Riostream.h>
20 #include <TObjArray.h>
22 #include <TDirectory.h>
25 #include "AliHitMap.h"
27 #include "AliMUONChamber.h"
28 #include "AliMUONConstants.h"
29 #include "AliMUONDigit.h"
30 #include "AliMUONHit.h"
31 #include "AliMUONHitMapA1.h"
32 #include "AliMUONMerger.h"
33 #include "AliMUONPadHit.h"
34 #include "AliMUONTransientDigit.h"
37 ClassImp(AliMUONMerger)
39 //----------------------------------------------------------------------
40 AliMUONMerger::AliMUONMerger()
42 // Default constructor
58 //----------------------------------------------------------------------
59 AliMUONMerger::AliMUONMerger(const AliMUONMerger&)
61 // Protected copy constructor
63 Fatal("AliMUONMergerModule", "Not implemented.");
66 //------------------------------------------------------------------------
67 AliMUONMerger::~AliMUONMerger()
70 if (fTrH1) delete fTrH1;
71 if (fHitsBgr) delete fHitsBgr;
72 if (fPadHitsBgr) delete fPadHitsBgr;
73 if (fHitMap) delete [] fHitMap;
74 if (fList) delete fList;
75 if (fBgrFile) delete fBgrFile;
78 //----------------------------------------------------------------------
79 AliMUONMerger& AliMUONMerger::operator=(const AliMUONMerger& rhs)
81 // Protected assignement operator
83 if (this == &rhs) return *this;
85 Fatal("operator=", "Not implemented.");
90 //------------------------------------------------------------------------
91 Bool_t AliMUONMerger::Exists(const AliMUONPadHit *padhit) const
93 // test if the given padhit was already fired
94 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
97 //------------------------------------------------------------------------
98 void AliMUONMerger::Update(AliMUONPadHit *padhit)
100 // add new contribution to the fired padhit
101 AliMUONTransientDigit *pdigit =
102 static_cast<AliMUONTransientDigit*>(
103 fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
107 Int_t iqpad = padhit->QPad(); // charge per pad
108 pdigit->AddSignal(iqpad);
109 pdigit->AddPhysicsSignal(iqpad);
111 // update list of tracks
121 pdigit->UpdateTrackList(track,charge);
124 //------------------------------------------------------------------------
125 void AliMUONMerger::CreateNew(AliMUONPadHit *padhit)
127 // add new transient digit to the list, update hit map
128 fList->AddAtAndExpand(
129 new AliMUONTransientDigit(fNch,fDigits),fCounter);
130 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
131 AliMUONTransientDigit* pdigit =
132 static_cast<AliMUONTransientDigit*>(fList->Last());
137 charge = padhit->QPad();
142 pdigit->AddToTrackList(track,charge);
147 //------------------------------------------------------------------------
148 void AliMUONMerger::Init()
151 // open only once the background file !!
152 if (fMerge && !fBgrFile) fBgrFile = InitBgr();
157 //------------------------------------------------------------------------
158 TFile* AliMUONMerger::InitBgr()
160 // Initialise background event
161 TFile *file = new TFile(fFnBgr);
162 // add error checking later
163 printf("\n AliMUONMerger has opened %s file with background event \n", fFnBgr);
164 fHitsBgr = new TClonesArray("AliMUONHit",1000);
165 fPadHitsBgr = new TClonesArray("AliMUONPadHit",1000);
169 //------------------------------------------------------------------------
170 void AliMUONMerger::Digitise()
173 // keep galice.root for signal and name differently the file for
174 // background when add! otherwise the track info for signal will be lost !
175 // Obsolete sep 2003 Gines MARTINEZ
176 // AliMUONChamber* iChamber;
177 // AliSegmentation* segmentation;
179 // fList = new TObjArray;
181 // AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
182 // fHitMap= new AliHitMap* [AliMUONConstants::NCh()];
186 // // Get Hits Tree header from file
187 // //if(fHitsBgr) fHitsBgr->Clear(); // Useless because line 327
188 // //if(fPadHitsBgr) fPadHitsBgr->Clear(); // Useless because line 328
189 // if(fTrH1) delete fTrH1;
192 // char treeName[20];
193 // sprintf(treeName,"TreeH%d",fEvNrBgr);
194 // fTrH1 = (TTree*)gDirectory->Get(treeName);
196 // printf("ERROR: cannot find Hits Tree for event:%d\n",fEvNrBgr);
199 // // Set branch addresses
201 // char branchname[20];
202 // sprintf(branchname,"%s",pMUON->GetName());
203 // if (fTrH1 && fHitsBgr) {
204 // branch = fTrH1->GetBranch(branchname);
205 // if (branch) branch->SetAddress(&fHitsBgr);
207 // if (fTrH1 && fPadHitsBgr) {
208 // branch = fTrH1->GetBranch("MUONCluster");
209 // if (branch) branch->SetAddress(&fPadHitsBgr);
213 // // loop over cathodes
216 // for (int icat = 0; icat < 2; icat++) {
218 // for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
219 // iChamber = &(pMUON->Chamber(i));
220 // if (iChamber->Nsec() == 1 && icat == 1) {
223 // segmentation = iChamber->SegmentationModel(icat+1);
225 // fHitMap[i] = new AliMUONHitMapA1(segmentation, fList);
229 // // Loop over tracks
232 // /******************************************************************/
233 // TTree* treeH = pMUON->TreeH();
236 // cerr<<"AliMUONMerger::Exec: Can not get TreeH"<<endl;
239 // /******************************************************************/
243 // Int_t ntracks = (Int_t) treeH->GetEntries();
244 // treeH->SetBranchStatus("*",0); // switch off all branches
245 // treeH->SetBranchStatus("MUON*",1); // switch on only MUON
247 // for (fTrack = 0; fTrack < ntracks; fTrack++) {
248 // gAlice->ResetHits();
249 // treeH->GetEntry(fTrack,0);
252 // for(AliMUONHit* mHit = (AliMUONHit*)pMUON->FirstHit(-1);
254 // mHit = (AliMUONHit*)pMUON->NextHit())
256 // fNch = mHit->Chamber()-1; // chamber number
257 // if (fNch > AliMUONConstants::NCh()-1) continue;
258 // iChamber = &(pMUON->Chamber(fNch));
261 // // Loop over pad hits
262 // for (AliMUONPadHit* mPad =
263 // (AliMUONPadHit*)pMUON->FirstPad(mHit,pMUON->PadHits());
265 // mPad = (AliMUONPadHit*)pMUON->NextPad(pMUON->PadHits()))
267 // Int_t cathode = mPad->Cathode(); // cathode number
268 // if (cathode != (icat+1)) continue;
269 // Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
270 // // segmentation = iChamber->SegmentationModel(cathode);
271 // fDigits[0] = mPad->PadX();
272 // fDigits[1] = mPad->PadY();
273 // if (!(fHitMap[fNch]->ValidateHit(fDigits[0], fDigits[1]))) continue;
274 // fDigits[2] = icat;
275 // fDigits[3] = iqpad;
276 // fDigits[4] = iqpad;
277 // if (mHit->Particle() == kMuonPlus ||
278 // mHit->Particle() == kMuonMinus) {
279 // fDigits[5] = mPad->HitNumber();
280 // } else fDigits[5] = -1;
282 // // build the list of fired pads and update the info
284 // if (!Exists(mPad)) {
288 // } // end if pdigit
289 // } //end loop over clusters
293 // // open the file with background
297 // ntracks = (Int_t)fTrH1->GetEntries();
299 // // Loop over tracks
301 // for (fTrack = 0; fTrack < ntracks; fTrack++) {
303 // if (fHitsBgr) fHitsBgr->Clear();
304 // if (fPadHitsBgr) fPadHitsBgr->Clear();
306 // fTrH1->GetEvent(fTrack);
310 // for(Int_t i = 0; i < fHitsBgr->GetEntriesFast(); ++i)
312 // mHit = (AliMUONHit*) (*fHitsBgr)[i];
313 // fNch = mHit->Chamber()-1; // chamber number
314 // iChamber = &(pMUON->Chamber(fNch));
316 // // Loop over pad hits
317 // for (AliMUONPadHit* mPad =
318 // (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHitsBgr);
320 // mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHitsBgr))
322 // Int_t cathode = mPad->Cathode(); // cathode number
323 // Int_t ipx = mPad->PadX(); // pad number on X
324 // Int_t ipy = mPad->PadY(); // pad number on Y
325 // Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
326 // if (!(fHitMap[fNch]->ValidateHit(ipx, ipy))) continue;
328 // if (cathode != (icat+1)) continue;
331 // fDigits[2] = icat;
332 // fDigits[3] = iqpad;
336 // // build the list of fired pads and update the info
337 // if (!Exists(mPad)) {
341 // } // end if !Exists
342 // } //end loop over clusters
346 // TTree *treeK = gAlice->TreeK();
347 // TFile *file = NULL;
349 // if (treeK) file = treeK->GetCurrentFile();
353 // Int_t tracks[kMAXTRACKS];
354 // Int_t charges[kMAXTRACKS];
355 // Int_t nentries = fList->GetEntriesFast();
357 // for (Int_t nent = 0; nent < nentries; nent++) {
358 // AliMUONTransientDigit *address = (AliMUONTransientDigit*)fList->At(nent);
359 // if (address == 0) continue;
360 // Int_t ich = address->Chamber();
361 // Int_t q = address->Signal();
362 // iChamber = &(pMUON->Chamber(ich));
364 // // Digit Response (noise, threshold, saturation, ...)
365 // AliMUONResponse * response = iChamber->ResponseModel();
366 // q = response->DigitResponse(q,address);
370 // fDigits[0] = address->PadX();
371 // fDigits[1] = address->PadY();
372 // fDigits[2] = address->Cathode();
374 // fDigits[4] = address->Physics();
375 // fDigits[5] = address->Hit();
377 // Int_t nptracks = address->GetNTracks();
379 // if (nptracks > kMAXTRACKS) {
381 // printf("\n Attention - nptracks > kMAXTRACKS %d \n", nptracks);
382 // nptracks = kMAXTRACKS;
384 // if (nptracks > 2) {
386 // printf("Attention - nptracks > 2 %d \n",nptracks);
387 // printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q);
390 // for (Int_t tr = 0; tr < nptracks; tr++) {
391 // tracks[tr] = address->GetTrack(tr);
392 // charges[tr] = address->GetCharge(tr);
393 // } //end loop over list of tracks for one pad
394 // // Sort list of tracks according to charge
395 // if (nptracks > 1) {
396 // SortTracks(tracks,charges,nptracks);
398 // if (nptracks < kMAXTRACKS ) {
399 // for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
406 // pMUON->AddDigits(ich,tracks,charges,fDigits);
408 // gAlice->TreeD()->Fill();
409 // pMUON->ResetDigits();
413 // for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) {
414 // if (fHitMap[ii]) {
415 // delete fHitMap[ii];
419 // } //end loop over cathodes
420 // delete [] fHitMap;
423 // no need to delete ... and it makes a crash also
424 // if (fHitsBgr) fHitsBgr->Delete();
425 // if (fPadHitsBgr) fPadHitsBgr->Delete();
426 // gObjectTable->Print();
431 void AliMUONMerger::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
434 // Sort the list of tracks contributing to a given digit
435 // Only the 3 most significant tracks are acctually sorted
439 // Loop over signals, only 3 times
444 Int_t idx[3] = {-2,-2,-2};
445 Int_t jch[3] = {-2,-2,-2};
446 Int_t jtr[3] = {-2,-2,-2};
457 if((i == 1 && j == idx[i-1])
458 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
460 if(charges[j] > qmax) {
468 jch[i]=charges[jmax];