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"
35 ClassImp(AliMUONMerger)
37 //----------------------------------------------------------------------
38 AliMUONMerger::AliMUONMerger()
40 // Default constructor
56 //----------------------------------------------------------------------
57 AliMUONMerger::AliMUONMerger(const AliMUONMerger&)
59 // Protected copy constructor
61 Fatal("AliMUONMergerModule", "Not implemented.");
64 //------------------------------------------------------------------------
65 AliMUONMerger::~AliMUONMerger()
68 if (fTrH1) delete fTrH1;
69 if (fHitsBgr) delete fHitsBgr;
70 if (fPadHitsBgr) delete fPadHitsBgr;
71 if (fHitMap) delete [] fHitMap;
72 if (fList) delete fList;
73 if (fBgrFile) delete fBgrFile;
76 //----------------------------------------------------------------------
77 AliMUONMerger& AliMUONMerger::operator=(const AliMUONMerger& rhs)
79 // Protected assignement operator
81 if (this == &rhs) return *this;
83 Fatal("operator=", "Not implemented.");
88 //------------------------------------------------------------------------
89 Bool_t AliMUONMerger::Exists(const AliMUONPadHit *padhit) const
91 // test if the given padhit was already fired
92 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
95 //------------------------------------------------------------------------
96 void AliMUONMerger::Update(AliMUONPadHit *padhit)
98 // add new contribution to the fired padhit
99 AliMUONTransientDigit *pdigit =
100 static_cast<AliMUONTransientDigit*>(
101 fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
105 Int_t iqpad = padhit->QPad(); // charge per pad
106 pdigit->AddSignal(iqpad);
107 pdigit->AddPhysicsSignal(iqpad);
109 // update list of tracks
119 pdigit->UpdateTrackList(track,charge);
122 //------------------------------------------------------------------------
123 void AliMUONMerger::CreateNew(AliMUONPadHit *padhit)
125 // add new transient digit to the list, update hit map
126 fList->AddAtAndExpand(
127 new AliMUONTransientDigit(fNch,fDigits),fCounter);
128 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
129 AliMUONTransientDigit* pdigit =
130 static_cast<AliMUONTransientDigit*>(fList->Last());
135 charge = padhit->QPad();
140 pdigit->AddToTrackList(track,charge);
145 //------------------------------------------------------------------------
146 void AliMUONMerger::Init()
149 // open only once the background file !!
150 if (fMerge && !fBgrFile) fBgrFile = InitBgr();
155 //------------------------------------------------------------------------
156 TFile* AliMUONMerger::InitBgr()
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);
167 //------------------------------------------------------------------------
168 void AliMUONMerger::Digitise()
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 !
173 // Obsolete sep 2003 Gines MARTINEZ
174 // AliMUONChamber* iChamber;
175 // AliSegmentation* segmentation;
177 // fList = new TObjArray;
179 // AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
180 // fHitMap= new AliHitMap* [AliMUONConstants::NCh()];
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;
190 // char treeName[20];
191 // sprintf(treeName,"TreeH%d",fEvNrBgr);
192 // fTrH1 = (TTree*)gDirectory->Get(treeName);
194 // printf("ERROR: cannot find Hits Tree for event:%d\n",fEvNrBgr);
197 // // Set branch addresses
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);
205 // if (fTrH1 && fPadHitsBgr) {
206 // branch = fTrH1->GetBranch("MUONCluster");
207 // if (branch) branch->SetAddress(&fPadHitsBgr);
211 // // loop over cathodes
214 // for (int icat = 0; icat < 2; icat++) {
216 // for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
217 // iChamber = &(pMUON->Chamber(i));
218 // if (iChamber->Nsec() == 1 && icat == 1) {
221 // segmentation = iChamber->SegmentationModel(icat+1);
223 // fHitMap[i] = new AliMUONHitMapA1(segmentation, fList);
227 // // Loop over tracks
230 // /******************************************************************/
231 // TTree* treeH = pMUON->TreeH();
234 // cerr<<"AliMUONMerger::Exec: Can not get TreeH"<<endl;
237 // /******************************************************************/
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
245 // for (fTrack = 0; fTrack < ntracks; fTrack++) {
246 // gAlice->ResetHits();
247 // treeH->GetEntry(fTrack,0);
250 // for(AliMUONHit* mHit = (AliMUONHit*)pMUON->FirstHit(-1);
252 // mHit = (AliMUONHit*)pMUON->NextHit())
254 // fNch = mHit->Chamber()-1; // chamber number
255 // if (fNch > AliMUONConstants::NCh()-1) continue;
256 // iChamber = &(pMUON->Chamber(fNch));
259 // // Loop over pad hits
260 // for (AliMUONPadHit* mPad =
261 // (AliMUONPadHit*)pMUON->FirstPad(mHit,pMUON->PadHits());
263 // mPad = (AliMUONPadHit*)pMUON->NextPad(pMUON->PadHits()))
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;
280 // // build the list of fired pads and update the info
282 // if (!Exists(mPad)) {
286 // } // end if pdigit
287 // } //end loop over clusters
291 // // open the file with background
295 // ntracks = (Int_t)fTrH1->GetEntries();
297 // // Loop over tracks
299 // for (fTrack = 0; fTrack < ntracks; fTrack++) {
301 // if (fHitsBgr) fHitsBgr->Clear();
302 // if (fPadHitsBgr) fPadHitsBgr->Clear();
304 // fTrH1->GetEvent(fTrack);
308 // for(Int_t i = 0; i < fHitsBgr->GetEntriesFast(); ++i)
310 // mHit = (AliMUONHit*) (*fHitsBgr)[i];
311 // fNch = mHit->Chamber()-1; // chamber number
312 // iChamber = &(pMUON->Chamber(fNch));
314 // // Loop over pad hits
315 // for (AliMUONPadHit* mPad =
316 // (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHitsBgr);
318 // mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHitsBgr))
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;
326 // if (cathode != (icat+1)) continue;
329 // fDigits[2] = icat;
330 // fDigits[3] = iqpad;
334 // // build the list of fired pads and update the info
335 // if (!Exists(mPad)) {
339 // } // end if !Exists
340 // } //end loop over clusters
344 // TTree *treeK = gAlice->TreeK();
345 // TFile *file = NULL;
347 // if (treeK) file = treeK->GetCurrentFile();
351 // Int_t tracks[kMAXTRACKS];
352 // Int_t charges[kMAXTRACKS];
353 // Int_t nentries = fList->GetEntriesFast();
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));
362 // // Digit Response (noise, threshold, saturation, ...)
363 // AliMUONResponse * response = iChamber->ResponseModel();
364 // q = response->DigitResponse(q,address);
368 // fDigits[0] = address->PadX();
369 // fDigits[1] = address->PadY();
370 // fDigits[2] = address->Cathode();
372 // fDigits[4] = address->Physics();
373 // fDigits[5] = address->Hit();
375 // Int_t nptracks = address->GetNTracks();
377 // if (nptracks > kMAXTRACKS) {
379 // printf("\n Attention - nptracks > kMAXTRACKS %d \n", nptracks);
380 // nptracks = kMAXTRACKS;
382 // if (nptracks > 2) {
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);
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);
396 // if (nptracks < kMAXTRACKS ) {
397 // for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
404 // pMUON->AddDigits(ich,tracks,charges,fDigits);
406 // gAlice->TreeD()->Fill();
407 // pMUON->ResetDigits();
411 // for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) {
412 // if (fHitMap[ii]) {
413 // delete fHitMap[ii];
417 // } //end loop over cathodes
418 // delete [] fHitMap;
421 // no need to delete ... and it makes a crash also
422 // if (fHitsBgr) fHitsBgr->Delete();
423 // if (fPadHitsBgr) fPadHitsBgr->Delete();
424 // gObjectTable->Print();
429 void AliMUONMerger::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr) const
432 // Sort the list of tracks contributing to a given digit
433 // Only the 3 most significant tracks are acctually sorted
437 // Loop over signals, only 3 times
442 Int_t idx[3] = {-2,-2,-2};
443 Int_t jch[3] = {-2,-2,-2};
444 Int_t jtr[3] = {-2,-2,-2};
455 if((i == 1 && j == idx[i-1])
456 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
458 if(charges[j] > qmax) {
466 jch[i]=charges[jmax];