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.7 2001/11/22 11:15:41 jchudoba
19 Proper deletion of arrays (thanks to Rene Brun)
21 Revision 1.6 2001/11/02 12:55:45 jchudoba
22 cleanup of the code, add const to Get methods
24 Revision 1.4 2001/10/18 14:44:09 jchudoba
25 Define constant MAXTRACKS for maximum number of tracks associated with 1 digit
27 Revision 1.3 2001/10/04 20:01:54 jchudoba
28 changes for TTask implementation, some other small editing
30 Revision 1.2 2001/07/28 10:46:04 hristov
31 AliRunDigitizer.h included; typos corrected
33 Revision 1.1 2001/07/27 15:41:01 jchudoba
34 merging/digitization classes
38 #include <TObjArray.h>
40 #include <TDirectory.h>
43 #include "AliMUONDigitizer.h"
44 #include "AliMUONConstants.h"
45 #include "AliMUONChamber.h"
46 #include "AliMUONHitMapA1.h"
48 #include "AliMUONHit.h"
49 #include "AliMUONPadHit.h"
50 #include "AliMUONDigit.h"
51 #include "AliMUONTransientDigit.h"
54 #include "AliRunDigitizer.h"
56 ClassImp(AliMUONDigitizer)
58 //___________________________________________
59 AliMUONDigitizer::AliMUONDigitizer() :AliDigitizer()
61 // Default ctor - don't use it
68 //___________________________________________
69 AliMUONDigitizer::AliMUONDigitizer(AliRunDigitizer* manager)
70 :AliDigitizer(manager)
72 // ctor which should be used
79 cerr<<"AliMUONDigitizer::AliMUONDigitizer"
80 <<"(AliRunDigitizer* manager) was processed"<<endl;
83 //------------------------------------------------------------------------
84 AliMUONDigitizer::~AliMUONDigitizer()
87 if (fHits) delete fHits;
88 if (fPadHits) delete fPadHits;
91 //------------------------------------------------------------------------
92 Bool_t AliMUONDigitizer::Exists(const AliMUONPadHit *padhit) const
94 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
97 //------------------------------------------------------------------------
98 void AliMUONDigitizer::Update(AliMUONPadHit *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
113 track = fTrack+fMask;
119 pdigit->UpdateTrackList(track,charge);
122 //------------------------------------------------------------------------
123 void AliMUONDigitizer::CreateNew(AliMUONPadHit *padhit)
125 // Create new AliMUONTransientDigit and add it to the fTDList
127 fTDList->AddAtAndExpand(
128 new AliMUONTransientDigit(fNch,fDigits),fCounter);
129 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
130 AliMUONTransientDigit* pdigit =
131 (AliMUONTransientDigit*)fTDList->Last();
134 track = fTrack+fMask;
136 charge = padhit->QPad();
140 pdigit->AddToTrackList(track,charge);
145 //------------------------------------------------------------------------
146 Bool_t AliMUONDigitizer::Init()
150 fHits = new TClonesArray("AliMUONHit",1000);
151 fPadHits = new TClonesArray("AliMUONPadHit",1000);
156 //------------------------------------------------------------------------
157 //void AliMUONDigitizer::Digitize()
158 void AliMUONDigitizer::Exec(Option_t* option)
161 TString optionString = option;
162 if (optionString.Data() == "deb") {
163 cout<<"AliMUONDigitizer::Exec: called with option deb "<<endl;
166 AliMUONChamber* iChamber;
167 AliSegmentation* segmentation;
169 if (GetDebug()>2) cerr<<" AliMUONDigitizer::Digitize() starts"<<endl;
170 fTDList = new TObjArray;
172 AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
174 cerr<<"AliMUONDigitizer::Digitize Error:"
175 <<" module MUON not found in the input file"<<endl;
178 pMUON->MakeBranchInTreeD(fManager->GetTreeD());
179 fHitMap= new AliMUONHitMapA1* [AliMUONConstants::NCh()];
182 // loop over cathodes
185 for (int icat = 0; icat < 2; icat++) {
187 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
188 iChamber = &(pMUON->Chamber(i));
189 // if (!(iChamber->Nsec() == 1 && icat == 1)) {
190 segmentation = iChamber->SegmentationModel(icat+1);
191 fHitMap[i] = new AliMUONHitMapA1(segmentation, fTDList);
196 // Loop over files to digitize
198 for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
200 // Connect MUON branches
202 if (inputFile > 0 ) fSignal = kFALSE;
203 TBranch *branchHits = 0;
204 TBranch *branchPadHits = 0;
205 TTree *treeH = fManager->GetInputTreeH(inputFile);
207 cerr<<" inputFile , cathode = "<<inputFile<<" "
209 cerr<<" treeH, fHits "<<treeH<<" "<<fHits<<endl;
211 if (treeH && fHits) {
212 branchHits = treeH->GetBranch("MUON");
215 branchHits->SetAddress(&fHits);
218 Error("Exec","branch MUON was not found");
220 if (GetDebug()>2) cerr<<" branchHits = "<<branchHits<<endl;
222 if (treeH && fPadHits) {
223 branchPadHits = treeH->GetBranch("MUONCluster");
225 branchPadHits->SetAddress(&fPadHits);
227 Error("Exec","branch MUONCluster was not found");
229 if (GetDebug()>2) cerr<<" branchPadHits = "<<branchPadHits<<endl;
235 Int_t ntracks = (Int_t) treeH->GetEntries();
237 for (fTrack = 0; fTrack < ntracks; fTrack++) {
238 if (GetDebug()>2) cerr<<" fTrack = "<<fTrack<<endl;
241 branchHits->GetEntry(fTrack);
242 branchPadHits->GetEntry(fTrack);
248 for(Int_t i = 0; i < fHits->GetEntriesFast(); ++i) {
249 mHit = static_cast<AliMUONHit*>(fHits->At(i));
250 fNch = mHit->Chamber()-1; // chamber number
251 if (fNch > AliMUONConstants::NCh()-1) {
252 cerr<<"AliMUONDigitizer: ERROR: "
253 <<"fNch > AliMUONConstants::NCh()-1, fNch, NCh(): "
254 <<fNch<<", "<< AliMUONConstants::NCh()<<endl;
257 iChamber = &(pMUON->Chamber(fNch));
259 // Loop over pad hits
260 for (AliMUONPadHit* mPad =
261 (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHits);
263 mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHits))
265 Int_t cathode = mPad->Cathode(); // cathode number
266 Int_t ipx = mPad->PadX(); // pad number on X
267 Int_t ipy = mPad->PadY(); // pad number on Y
268 Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
269 if (cathode != (icat+1)) continue;
271 fMask = fManager->GetMask(inputFile);
276 if (inputFile == 0) {
281 if (mHit->Particle() == kMuonPlus ||
282 mHit->Particle() == kMuonMinus) {
283 fDigits[5] = (mPad->HitNumber()) + fMask;
284 } else fDigits[5] = -1;
286 // build the list of fired pads and update the info,
287 // fDigits is input for Update(mPad)
293 } // end if Exists(mPad)
294 } //end loop over clusters
298 if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl;
300 Int_t tracks[kMAXTRACKS];
301 Int_t charges[kMAXTRACKS];
302 Int_t nentries = fTDList->GetEntriesFast();
304 for (Int_t nent = 0; nent < nentries; nent++) {
305 AliMUONTransientDigit *address = (AliMUONTransientDigit*)fTDList->At(nent);
306 if (address == 0) continue;
307 Int_t ich = address->Chamber();
308 Int_t q = address->Signal();
309 iChamber = &(pMUON->Chamber(ich));
311 // Digit Response (noise, threshold, saturation, ...)
312 AliMUONResponse * response = iChamber->ResponseModel();
313 q = response->DigitResponse(q);
317 fDigits[0] = address->PadX();
318 fDigits[1] = address->PadY();
319 fDigits[2] = address->Cathode();
321 fDigits[4] = address->Physics();
322 fDigits[5] = address->Hit();
324 Int_t nptracks = address->GetNTracks();
326 if (nptracks > kMAXTRACKS) {
328 cerr<<"AliMUONDigitizer: nptracks > 10 "<<nptracks;
329 cerr<<"reset to max value "<<kMAXTRACKS<<endl;
331 nptracks = kMAXTRACKS;
333 if (nptracks > 2 && GetDebug() >2) {
334 cerr<<"AliMUONDigitizer: nptracks > 2 "<<nptracks<<endl;
335 printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q);
337 for (Int_t tr = 0; tr < nptracks; tr++) {
338 tracks[tr] = address->GetTrack(tr);
339 charges[tr] = address->GetCharge(tr);
340 } //end loop over list of tracks for one pad
341 // Sort list of tracks according to charge
343 SortTracks(tracks,charges,nptracks);
345 if (nptracks < kMAXTRACKS ) {
346 for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
353 pMUON->AddDigits(ich,tracks,charges,fDigits);
356 fManager->GetTreeD()->Fill();
358 pMUON->ResetDigits(); //
362 for(Int_t ii = 0; ii < AliMUONConstants::NCh(); ++ii) {
368 } //end loop over cathodes
370 cerr<<"AliMUONDigitizer::Exec: writing the TreeD: "
371 <<fManager->GetTreeD()->GetName()<<endl;
372 fManager->GetTreeD()->Write(0,TObject::kOverwrite);
376 if (fHits) fHits->Delete();
377 if (fPadHits) fPadHits->Delete();
381 //------------------------------------------------------------------------
382 void AliMUONDigitizer::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
385 // Sort the list of tracks contributing to a given digit
386 // Only the 3 most significant tracks are acctually sorted
390 // Loop over signals, only 3 times
395 Int_t idx[3] = {-2,-2,-2};
396 Int_t jch[3] = {-2,-2,-2};
397 Int_t jtr[3] = {-2,-2,-2};
408 if((i == 1 && j == idx[i-1])
409 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
411 if(charges[j] > qmax) {
419 jch[i]=charges[jmax];