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>
19 #include <TDirectory.h>
22 #include "AliRunLoader.h"
23 #include "AliLoader.h"
24 #include <Riostream.h>
26 #include "AliMUONDigitizer.h"
27 #include "AliMUONConstants.h"
28 #include "AliMUONChamber.h"
29 #include "AliMUONHitMapA1.h"
31 #include "AliMUONChamber.h"
32 #include "AliMUONConstants.h"
33 #include "AliMUONDigit.h"
34 #include "AliMUONDigitizer.h"
35 #include "AliMUONHit.h"
36 #include "AliMUONHitMapA1.h"
37 #include "AliMUONPadHit.h"
38 #include "AliMUONTransientDigit.h"
40 #include "AliRunDigitizer.h"
42 ClassImp(AliMUONDigitizer)
44 //___________________________________________
45 AliMUONDigitizer::AliMUONDigitizer() :AliDigitizer()
47 // Default ctor - don't use it
54 //___________________________________________
55 AliMUONDigitizer::AliMUONDigitizer(AliRunDigitizer* manager)
56 :AliDigitizer(manager)
58 // ctor which should be used
65 cerr<<"AliMUONDigitizer::AliMUONDigitizer"
66 <<"(AliRunDigitizer* manager) was processed"<<endl;
69 //------------------------------------------------------------------------
70 AliMUONDigitizer::~AliMUONDigitizer()
73 if (fHits) delete fHits;
74 if (fPadHits) delete fPadHits;
77 //------------------------------------------------------------------------
78 Bool_t AliMUONDigitizer::Exists(const AliMUONPadHit *padhit) const
80 return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
83 //------------------------------------------------------------------------
84 void AliMUONDigitizer::Update(AliMUONPadHit *padhit)
86 AliMUONTransientDigit *pdigit =
87 static_cast<AliMUONTransientDigit*>(
88 fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
92 Int_t iqpad = padhit->QPad(); // charge per pad
93 pdigit->AddSignal(iqpad);
94 pdigit->AddPhysicsSignal(iqpad);
96 // update list of tracks
105 pdigit->UpdateTrackList(track,charge);
108 //------------------------------------------------------------------------
109 void AliMUONDigitizer::CreateNew(AliMUONPadHit *padhit)
111 // Create new AliMUONTransientDigit and add it to the fTDList
113 fTDList->AddAtAndExpand(
114 new AliMUONTransientDigit(fNch,fDigits),fCounter);
115 fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
116 AliMUONTransientDigit* pdigit =
117 (AliMUONTransientDigit*)fTDList->Last();
120 track = fTrack+fMask;
122 charge = padhit->QPad();
126 pdigit->AddToTrackList(track,charge);
131 //------------------------------------------------------------------------
132 Bool_t AliMUONDigitizer::Init()
136 fHits = new TClonesArray("AliMUONHit",1000);
137 fPadHits = new TClonesArray("AliMUONPadHit",1000);
142 //------------------------------------------------------------------------
143 //void AliMUONDigitizer::Digitize()
144 void AliMUONDigitizer::Exec(Option_t* option)
147 TString optionString = option;
148 if (optionString.Data() == "deb") {
149 cout<<"AliMUONDigitizer::Exec: called with option deb "<<endl;
152 AliMUONChamber* iChamber;
153 AliSegmentation* segmentation;
155 if (GetDebug()>2) cerr<<" AliMUONDigitizer::Digitize() starts"<<endl;
156 fTDList = new TObjArray;
158 AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
160 cerr<<"AliMUONDigitizer::Digitize Error:"
161 <<" module MUON not found in the input file"<<endl;
165 AliRunLoader *rl, *orl;
166 AliLoader *gime, *ogime;
167 orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
168 ogime = orl->GetLoader("MUONLoader");
170 pMUON->MakeBranchInTreeD(ogime->TreeD());
172 fHitMap= new AliMUONHitMapA1* [AliMUONConstants::NCh()];
175 // loop over cathodes
178 for (int icat = 0; icat < 2; icat++) {
180 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
181 iChamber = &(pMUON->Chamber(i));
182 // if (!(iChamber->Nsec() == 1 && icat == 1)) {
183 segmentation = iChamber->SegmentationModel(icat+1);
184 fHitMap[i] = new AliMUONHitMapA1(segmentation, fTDList);
189 // Loop over files to digitize
191 for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
193 // Connect MUON branches
195 if (inputFile > 0 ) fSignal = kFALSE;
196 TBranch *branchHits = 0;
197 TBranch *branchPadHits = 0;
199 rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
200 gime = rl->GetLoader("MUONLoader");
203 TTree *treeH = gime->TreeH();
205 cerr<<" inputFile , cathode = "<<inputFile<<" "
207 cerr<<" treeH, fHits "<<treeH<<" "<<fHits<<endl;
209 if (treeH && fHits) {
210 branchHits = treeH->GetBranch("MUON");
213 branchHits->SetAddress(&fHits);
216 Error("Exec","branch MUON was not found");
218 if (GetDebug()>2) cerr<<" branchHits = "<<branchHits<<endl;
220 if (treeH && fPadHits) {
221 branchPadHits = treeH->GetBranch("MUONCluster");
223 branchPadHits->SetAddress(&fPadHits);
225 Error("Exec","branch MUONCluster was not found");
227 if (GetDebug()>2) cerr<<" branchPadHits = "<<branchPadHits<<endl;
233 Int_t ntracks = (Int_t) treeH->GetEntries();
235 for (fTrack = 0; fTrack < ntracks; fTrack++) {
236 if (GetDebug()>2) cerr<<" fTrack = "<<fTrack<<endl;
239 branchHits->GetEntry(fTrack);
240 branchPadHits->GetEntry(fTrack);
246 for(Int_t i = 0; i < fHits->GetEntriesFast(); ++i) {
247 mHit = static_cast<AliMUONHit*>(fHits->At(i));
248 fNch = mHit->Chamber()-1; // chamber number
249 if (fNch > AliMUONConstants::NCh()-1) {
250 cerr<<"AliMUONDigitizer: ERROR: "
251 <<"fNch > AliMUONConstants::NCh()-1, fNch, NCh(): "
252 <<fNch<<", "<< AliMUONConstants::NCh()<<endl;
255 iChamber = &(pMUON->Chamber(fNch));
257 // Loop over pad hits
258 for (AliMUONPadHit* mPad =
259 (AliMUONPadHit*)pMUON->FirstPad(mHit,fPadHits);
261 mPad = (AliMUONPadHit*)pMUON->NextPad(fPadHits))
263 Int_t cathode = mPad->Cathode(); // cathode number
264 Int_t ipx = mPad->PadX(); // pad number on X
265 Int_t ipy = mPad->PadY(); // pad number on Y
266 Int_t iqpad = Int_t(mPad->QPad()); // charge per pad
267 if (cathode != (icat+1)) continue;
269 fMask = fManager->GetMask(inputFile);
274 if (inputFile == 0) {
279 if (mHit->Particle() == kMuonPlus ||
280 mHit->Particle() == kMuonMinus) {
281 fDigits[5] = (mPad->HitNumber()) + fMask;
282 } else fDigits[5] = -1;
284 // build the list of fired pads and update the info,
285 // fDigits is input for Update(mPad)
291 } // end if Exists(mPad)
292 } //end loop over clusters
296 if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl;
298 Int_t tracks[kMAXTRACKS];
299 Int_t charges[kMAXTRACKS];
300 Int_t nentries = fTDList->GetEntriesFast();
302 for (Int_t nent = 0; nent < nentries; nent++) {
303 AliMUONTransientDigit *address = (AliMUONTransientDigit*)fTDList->At(nent);
304 if (address == 0) continue;
305 Int_t ich = address->Chamber();
306 Int_t q = address->Signal();
307 iChamber = &(pMUON->Chamber(ich));
309 // Digit Response (noise, threshold, saturation, ...)
310 AliMUONResponse * response = iChamber->ResponseModel();
311 q = response->DigitResponse(q,address);
315 fDigits[0] = address->PadX();
316 fDigits[1] = address->PadY();
317 fDigits[2] = address->Cathode();
319 fDigits[4] = address->Physics();
320 fDigits[5] = address->Hit();
322 Int_t nptracks = address->GetNTracks();
324 if (nptracks > kMAXTRACKS) {
326 cerr<<"AliMUONDigitizer: nptracks > 10 "<<nptracks;
327 cerr<<"reset to max value "<<kMAXTRACKS<<endl;
329 nptracks = kMAXTRACKS;
331 if (nptracks > 2 && GetDebug() >2) {
332 cerr<<"AliMUONDigitizer: nptracks > 2 "<<nptracks<<endl;
333 printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q);
335 for (Int_t tr = 0; tr < nptracks; tr++) {
336 tracks[tr] = address->GetTrack(tr);
337 charges[tr] = address->GetCharge(tr);
338 } //end loop over list of tracks for one pad
339 // Sort list of tracks according to charge
341 SortTracks(tracks,charges,nptracks);
343 if (nptracks < kMAXTRACKS ) {
344 for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
351 pMUON->AddDigits(ich,tracks,charges,fDigits);
354 // fManager->GetTreeD()->Fill();
355 ogime->TreeD()->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 << ogime->TreeD()->GetName()<<endl;
373 ogime->WriteDigits("OVERWRITE");
378 if (fHits) fHits->Delete();
379 if (fPadHits) fPadHits->Delete();
383 //------------------------------------------------------------------------
384 void AliMUONDigitizer::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
387 // Sort the list of tracks contributing to a given digit
388 // Only the 3 most significant tracks are acctually sorted
392 // Loop over signals, only 3 times
397 Int_t idx[3] = {-2,-2,-2};
398 Int_t jch[3] = {-2,-2,-2};
399 Int_t jtr[3] = {-2,-2,-2};
410 if((i == 1 && j == idx[i-1])
411 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
413 if(charges[j] > qmax) {
421 jch[i]=charges[jmax];