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 <TObjArray.h>
22 //#include <TDirectory.h>
24 #include "AliMUONMerger.h"
26 #include "AliMUONPadHit.h"
27 #include "AliMUONTransientDigit.h"
28 #include "AliHitMap.h"
29 //#include "AliMUONChamber.h"
30 //#include "AliMUONConstants.h"
31 //#include "AliMUONHit.h"
32 //#include "AliMUONHitMapA1.h"
36 ClassImp(AliMUONMerger)
38 //----------------------------------------------------------------------
39 AliMUONMerger::AliMUONMerger(): TObject()
41 // Default constructor
57 //----------------------------------------------------------------------
58 AliMUONMerger::AliMUONMerger(const AliMUONMerger&): TObject()
60 // Protected copy constructor
62 AliFatal("Not implemented.");
65 //------------------------------------------------------------------------
66 AliMUONMerger::~AliMUONMerger()
69 if (fTrH1) delete fTrH1;
70 if (fHitsBgr) delete fHitsBgr;
71 if (fPadHitsBgr) delete fPadHitsBgr;
72 if (fHitMap) delete [] fHitMap;
73 if (fList) delete fList;
74 if (fBgrFile) delete fBgrFile;
77 //----------------------------------------------------------------------
78 AliMUONMerger& AliMUONMerger::operator=(const AliMUONMerger& rhs)
80 // Protected assignement operator
82 if (this == &rhs) return *this;
84 AliFatal("Not implemented.");
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 AliInfo(Form("\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 !
174 // Obsolete sep 2003 Gines MARTINEZ
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;
191 // char treeName[20];
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
200 // char branchname[20];
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);
228 // // Loop over tracks
231 // /******************************************************************/
232 // TTree* treeH = pMUON->TreeH();
235 // cerr<<"AliMUONMerger::Exec: Can not get TreeH"<<endl;
238 // /******************************************************************/
242 // Int_t ntracks = (Int_t) treeH->GetEntries();
243 // treeH->SetBranchStatus("*",0); // switch off all branches
244 // treeH->SetBranchStatus("MUON*",1); // switch on only MUON
246 // for (fTrack = 0; fTrack < ntracks; fTrack++) {
247 // gAlice->ResetHits();
248 // treeH->GetEntry(fTrack,0);
251 // for(AliMUONHit* mHit = (AliMUONHit*)pMUON->FirstHit(-1);
253 // mHit = (AliMUONHit*)pMUON->NextHit())
255 // fNch = mHit->Chamber()-1; // chamber number
256 // if (fNch > AliMUONConstants::NCh()-1) continue;
257 // iChamber = &(pMUON->Chamber(fNch));
260 // // Loop over pad hits
261 // for (AliMUONPadHit* mPad =
262 // (AliMUONPadHit*)pMUON->FirstPad(mHit,pMUON->PadHits());
264 // mPad = (AliMUONPadHit*)pMUON->NextPad(pMUON->PadHits()))
266 // Int_t cathode = mPad->Cathode(); // cathode number
267 // if (cathode != (icat+1)) continue;
268 // Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
269 // // segmentation = iChamber->SegmentationModel(cathode);
270 // fDigits[0] = mPad->PadX();
271 // fDigits[1] = mPad->PadY();
272 // if (!(fHitMap[fNch]->ValidateHit(fDigits[0], fDigits[1]))) continue;
273 // fDigits[2] = icat;
274 // fDigits[3] = iqpad;
275 // fDigits[4] = iqpad;
276 // if (mHit->Particle() == kMuonPlus ||
277 // mHit->Particle() == kMuonMinus) {
278 // fDigits[5] = mPad->HitNumber();
279 // } else fDigits[5] = -1;
281 // // build the list of fired pads and update the info
283 // if (!Exists(mPad)) {
287 // } // end if pdigit
288 // } //end loop over clusters
292 // // open the file with background
296 // ntracks = (Int_t)fTrH1->GetEntries();
298 // // Loop over tracks
300 // for (fTrack = 0; fTrack < ntracks; fTrack++) {
302 // if (fHitsBgr) fHitsBgr->Clear();
303 // if (fPadHitsBgr) fPadHitsBgr->Clear();
305 // fTrH1->GetEvent(fTrack);
309 // for(Int_t i = 0; i < fHitsBgr->GetEntriesFast(); ++i)
311 // mHit = (AliMUONHit*) (*fHitsBgr)[i];
312 // fNch = mHit->Chamber()-1; // chamber number
313 // iChamber = &(pMUON->Chamber(fNch));
315 // // Loop over pad hits
316 // for (AliMUONPadHit* mPad =
317 // (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHitsBgr);
319 // mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHitsBgr))
321 // Int_t cathode = mPad->Cathode(); // cathode number
322 // Int_t ipx = mPad->PadX(); // pad number on X
323 // Int_t ipy = mPad->PadY(); // pad number on Y
324 // Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
325 // if (!(fHitMap[fNch]->ValidateHit(ipx, ipy))) continue;
327 // if (cathode != (icat+1)) continue;
330 // fDigits[2] = icat;
331 // fDigits[3] = iqpad;
335 // // build the list of fired pads and update the info
336 // if (!Exists(mPad)) {
340 // } // end if !Exists
341 // } //end loop over clusters
345 // TTree *treeK = gAlice->TreeK();
346 // TFile *file = NULL;
348 // if (treeK) file = treeK->GetCurrentFile();
352 // Int_t tracks[kMAXTRACKS];
353 // Int_t charges[kMAXTRACKS];
354 // Int_t nentries = fList->GetEntriesFast();
356 // for (Int_t nent = 0; nent < nentries; nent++) {
357 // AliMUONTransientDigit *address = (AliMUONTransientDigit*)fList->At(nent);
358 // if (address == 0) continue;
359 // Int_t ich = address->Chamber();
360 // Int_t q = address->Signal();
361 // iChamber = &(pMUON->Chamber(ich));
363 // // Digit Response (noise, threshold, saturation, ...)
364 // AliMUONResponse * response = iChamber->ResponseModel();
365 // q = response->DigitResponse(q,address);
369 // fDigits[0] = address->PadX();
370 // fDigits[1] = address->PadY();
371 // fDigits[2] = address->Cathode();
373 // fDigits[4] = address->Physics();
374 // fDigits[5] = address->Hit();
376 // Int_t nptracks = address->GetNTracks();
378 // if (nptracks > kMAXTRACKS) {
380 // printf("\n Attention - nptracks > kMAXTRACKS %d \n", nptracks);
381 // nptracks = kMAXTRACKS;
383 // if (nptracks > 2) {
385 // printf("Attention - nptracks > 2 %d \n",nptracks);
386 // printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q);
389 // for (Int_t tr = 0; tr < nptracks; tr++) {
390 // tracks[tr] = address->GetTrack(tr);
391 // charges[tr] = address->GetCharge(tr);
392 // } //end loop over list of tracks for one pad
393 // // Sort list of tracks according to charge
394 // if (nptracks > 1) {
395 // SortTracks(tracks,charges,nptracks);
397 // if (nptracks < kMAXTRACKS ) {
398 // for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
405 // pMUON->AddDigits(ich,tracks,charges,fDigits);
407 // gAlice->TreeD()->Fill();
408 // pMUON->ResetDigits();
412 // for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) {
413 // if (fHitMap[ii]) {
414 // delete fHitMap[ii];
418 // } //end loop over cathodes
419 // delete [] fHitMap;
422 // no need to delete ... and it makes a crash also
423 // if (fHitsBgr) fHitsBgr->Delete();
424 // if (fPadHitsBgr) fPadHitsBgr->Delete();
425 // gObjectTable->Print();
430 void AliMUONMerger::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr) const
433 // Sort the list of tracks contributing to a given digit
434 // Only the 3 most significant tracks are acctually sorted
438 // Loop over signals, only 3 times
443 Int_t idx[3] = {-2,-2,-2};
444 Int_t jch[3] = {-2,-2,-2};
445 Int_t jtr[3] = {-2,-2,-2};
456 if((i == 1 && j == idx[i-1])
457 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
459 if(charges[j] > qmax) {
467 jch[i]=charges[jmax];