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.4 2001/10/18 14:44:09 jchudoba
22 Define constant MAXTRACKS for maximum number of tracks associated with 1 digit
24 Revision 1.3 2001/10/04 20:01:54 jchudoba
25 changes for TTask implementation, some other small editing
27 Revision 1.2 2001/07/28 10:46:04 hristov
28 AliRunDigitizer.h included; typos corrected
30 Revision 1.1 2001/07/27 15:41:01 jchudoba
31 merging/digitization classes
35 #include <TObjArray.h>
37 #include <TDirectory.h>
40 #include "AliMUONDigitizer.h"
41 #include "AliMUONConstants.h"
42 #include "AliMUONChamber.h"
43 #include "AliMUONHitMapA1.h"
45 #include "AliMUONHit.h"
46 #include "AliMUONPadHit.h"
47 #include "AliMUONDigit.h"
48 #include "AliMUONTransientDigit.h"
51 #include "AliRunDigitizer.h"
53 ClassImp(AliMUONDigitizer)
55 //___________________________________________
56 AliMUONDigitizer::AliMUONDigitizer() :AliDigitizer()
58 // Default ctor - don't use it
65 //___________________________________________
66 AliMUONDigitizer::AliMUONDigitizer(AliRunDigitizer* manager)
67 :AliDigitizer(manager)
69 // ctor which should be used
76 cerr<<"AliMUONDigitizer::AliMUONDigitizer"
77 <<"(AliRunDigitizer* manager) was processed"<<endl;
80 //------------------------------------------------------------------------
81 AliMUONDigitizer::~AliMUONDigitizer()
84 if (fHits) delete fHits;
85 if (fPadHits) delete fPadHits;
86 if (fHitMap) delete [] fHitMap;
87 if (fTDList) delete fTDList;
90 //------------------------------------------------------------------------
91 Bool_t AliMUONDigitizer::Exists(const AliMUONPadHit *padhit) const
93 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
96 //------------------------------------------------------------------------
97 void AliMUONDigitizer::Update(AliMUONPadHit *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
112 track = fTrack+fMask;
118 pdigit->UpdateTrackList(track,charge);
121 //------------------------------------------------------------------------
122 void AliMUONDigitizer::CreateNew(AliMUONPadHit *padhit)
124 // Create new AliMUONTransientDigit and add it to the fTDList
126 fTDList->AddAtAndExpand(
127 new AliMUONTransientDigit(fNch,fDigits),fCounter);
128 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
129 AliMUONTransientDigit* pdigit =
130 (AliMUONTransientDigit*)fTDList->Last();
133 track = fTrack+fMask;
135 charge = padhit->QPad();
139 pdigit->AddToTrackList(track,charge);
144 //------------------------------------------------------------------------
145 Bool_t AliMUONDigitizer::Init()
149 fHits = new TClonesArray("AliMUONHit",1000);
150 fPadHits = new TClonesArray("AliMUONPadHit",1000);
155 //------------------------------------------------------------------------
156 //void AliMUONDigitizer::Digitize()
157 void AliMUONDigitizer::Exec(Option_t* option)
160 TString optionString = option;
161 if (optionString.Data() == "deb") {
162 cout<<"AliMUONDigitizer::Exec: called with option deb "<<endl;
165 AliMUONChamber* iChamber;
166 AliSegmentation* segmentation;
168 if (GetDebug()>2) cerr<<" AliMUONDigitizer::Digitize() starts"<<endl;
169 fTDList = new TObjArray;
171 AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
173 cerr<<"AliMUONDigitizer::Digitize Error:"
174 <<" module MUON not found in the input file"<<endl;
177 pMUON->MakeBranchInTreeD(fManager->GetTreeD());
178 fHitMap= new AliMUONHitMapA1* [AliMUONConstants::NCh()];
181 // loop over cathodes
184 for (int icat = 0; icat < 2; icat++) {
186 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
187 iChamber = &(pMUON->Chamber(i));
188 // if (!(iChamber->Nsec() == 1 && icat == 1)) {
189 segmentation = iChamber->SegmentationModel(icat+1);
190 fHitMap[i] = new AliMUONHitMapA1(segmentation, fTDList);
195 // Loop over files to digitize
197 for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
199 // Connect MUON branches
201 if (inputFile > 0 ) fSignal = kFALSE;
202 TBranch *branchHits = 0;
203 TBranch *branchPadHits = 0;
204 TTree *treeH = fManager->GetInputTreeH(inputFile);
206 cerr<<" inputFile , cathode = "<<inputFile<<" "
208 cerr<<" treeH, fHits "<<treeH<<" "<<fHits<<endl;
210 if (treeH && fHits) {
211 branchHits = treeH->GetBranch("MUON");
214 branchHits->SetAddress(&fHits);
217 Error("Exec","branch MUON was not found");
219 if (GetDebug()>2) cerr<<" branchHits = "<<branchHits<<endl;
221 if (treeH && fPadHits) {
222 branchPadHits = treeH->GetBranch("MUONCluster");
224 branchPadHits->SetAddress(&fPadHits);
226 Error("Exec","branch MUONCluster was not found");
228 if (GetDebug()>2) cerr<<" branchPadHits = "<<branchPadHits<<endl;
234 Int_t ntracks = (Int_t) treeH->GetEntries();
236 for (fTrack = 0; fTrack < ntracks; fTrack++) {
237 if (GetDebug()>2) cerr<<" fTrack = "<<fTrack<<endl;
240 branchHits->GetEntry(fTrack);
241 branchPadHits->GetEntry(fTrack);
247 for(Int_t i = 0; i < fHits->GetEntriesFast(); ++i) {
248 mHit = static_cast<AliMUONHit*>(fHits->At(i));
249 fNch = mHit->Chamber()-1; // chamber number
250 if (fNch > AliMUONConstants::NCh()-1) {
251 cerr<<"AliMUONDigitizer: ERROR: "
252 <<"fNch > AliMUONConstants::NCh()-1, fNch, NCh(): "
253 <<fNch<<", "<< AliMUONConstants::NCh()<<endl;
256 iChamber = &(pMUON->Chamber(fNch));
258 // Loop over pad hits
259 for (AliMUONPadHit* mPad =
260 (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHits);
262 mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHits))
264 Int_t cathode = mPad->Cathode(); // cathode number
265 Int_t ipx = mPad->PadX(); // pad number on X
266 Int_t ipy = mPad->PadY(); // pad number on Y
267 Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
268 if (cathode != (icat+1)) continue;
270 fMask = fManager->GetMask(inputFile);
275 if (inputFile == 0) {
280 if (mHit->Particle() == kMuonPlus ||
281 mHit->Particle() == kMuonMinus) {
282 fDigits[5] = (mPad->HitNumber()) + fMask;
283 } else fDigits[5] = -1;
285 // build the list of fired pads and update the info,
286 // fDigits is input for Update(mPad)
292 } // end if Exists(mPad)
293 } //end loop over clusters
297 if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl;
299 Int_t tracks[kMAXTRACKS];
300 Int_t charges[kMAXTRACKS];
301 Int_t nentries = fTDList->GetEntriesFast();
303 for (Int_t nent = 0; nent < nentries; nent++) {
304 AliMUONTransientDigit *address = (AliMUONTransientDigit*)fTDList->At(nent);
305 if (address == 0) continue;
306 Int_t ich = address->Chamber();
307 Int_t q = address->Signal();
308 iChamber = &(pMUON->Chamber(ich));
310 // Digit Response (noise, threshold, saturation, ...)
311 AliMUONResponse * response = iChamber->ResponseModel();
312 q = response->DigitResponse(q);
316 fDigits[0] = address->PadX();
317 fDigits[1] = address->PadY();
318 fDigits[2] = address->Cathode();
320 fDigits[4] = address->Physics();
321 fDigits[5] = address->Hit();
323 Int_t nptracks = address->GetNTracks();
325 if (nptracks > kMAXTRACKS) {
327 cerr<<"AliMUONDigitizer: nptracks > 10 "<<nptracks;
328 cerr<<"reset to max value "<<kMAXTRACKS<<endl;
330 nptracks = kMAXTRACKS;
332 if (nptracks > 2 && GetDebug() >2) {
333 cerr<<"AliMUONDigitizer: nptracks > 2 "<<nptracks<<endl;
334 printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q);
336 for (Int_t tr = 0; tr < nptracks; tr++) {
337 tracks[tr] = address->GetTrack(tr);
338 charges[tr] = address->GetCharge(tr);
339 } //end loop over list of tracks for one pad
340 // Sort list of tracks according to charge
342 SortTracks(tracks,charges,nptracks);
344 if (nptracks < kMAXTRACKS ) {
345 for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
352 pMUON->AddDigits(ich,tracks,charges,fDigits);
355 fManager->GetTreeD()->Fill();
357 pMUON->ResetDigits(); //
361 for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) {
367 } //end loop over cathodes
369 cerr<<"AliMUONDigitizer::Exec: writing the TreeD: "
370 <<fManager->GetTreeD()->GetName()<<endl;
371 fManager->GetTreeD()->Write(0,TObject::kOverwrite);
375 if (fHits) fHits->Delete();
376 if (fPadHits) fPadHits->Delete();
380 //------------------------------------------------------------------------
381 void AliMUONDigitizer::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
384 // Sort the list of tracks contributing to a given digit
385 // Only the 3 most significant tracks are acctually sorted
389 // Loop over signals, only 3 times
394 Int_t idx[3] = {-2,-2,-2};
395 Int_t jch[3] = {-2,-2,-2};
396 Int_t jtr[3] = {-2,-2,-2};
407 if((i == 1 && j == idx[i-1])
408 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
410 if(charges[j] > qmax) {
418 jch[i]=charges[jmax];