4 #include <TDirectory.h>
11 #include "AliMUONChamber.h"
12 #include "AliMUONConstants.h"
13 #include "AliMUONDigit.h"
14 #include "AliMUONDigitizerv1.h"
15 #include "AliMUONHit.h"
16 #include "AliMUONHitMapA1.h"
17 #include "AliMUONPadHit.h"
18 #include "AliMUONTransientDigit.h"
20 #include "AliRunDigitizer.h"
22 ClassImp(AliMUONDigitizerv1)
24 //___________________________________________
25 AliMUONDigitizerv1::AliMUONDigitizerv1() :AliDigitizer()
27 // Default ctor - don't use it
31 cerr<<"AliMUONDigitizerv1::AliMUONDigitizerv1"
32 <<"(AliRunDigitizer* manager) was processed"<<endl;
35 //___________________________________________
36 AliMUONDigitizerv1::AliMUONDigitizerv1(AliRunDigitizer* manager)
37 :AliDigitizer(manager)
39 // ctor which should be used
43 fHits = new TClonesArray("AliMUONHit",1000);
45 cerr<<"AliMUONDigitizerv1::AliMUONDigitizerv1"
46 <<"(AliRunDigitizer* manager) was processed"<<endl;
49 //------------------------------------------------------------------------
50 AliMUONDigitizerv1::~AliMUONDigitizerv1()
56 //------------------------------------------------------------------------
57 void AliMUONDigitizerv1::AddTransientDigit(AliMUONTransientDigit * mTD)
59 // Choosing the maping of the cathode plane of the chamber:
60 Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
61 fTDList->AddAtAndExpand(mTD, fTDCounter);
62 fHitMap[iNchCpl]->SetHit( mTD->PadX(), mTD->PadY(), fTDCounter);
66 //------------------------------------------------------------------------
67 Bool_t AliMUONDigitizerv1::ExistTransientDigit(AliMUONTransientDigit * mTD)
69 // Choosing the maping of the cathode plane of the chamber:
70 Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
71 return( fHitMap[iNchCpl]->TestHit(mTD->PadX(), mTD->PadY()) );
74 //------------------------------------------------------------------------
75 Bool_t AliMUONDigitizerv1::Init()
81 //------------------------------------------------------------------------
82 void AliMUONDigitizerv1::UpdateTransientDigit(Int_t track, AliMUONTransientDigit * mTD)
84 // Choosing the maping of the cathode plane of the chamber:
85 Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
86 AliMUONTransientDigit *pdigit =
87 static_cast<AliMUONTransientDigit*>(fHitMap[iNchCpl]->GetHit(mTD->PadX(),mTD->PadY()));
90 Int_t iqpad = mTD->Signal(); // charge per pad
91 pdigit->AddSignal(iqpad);
92 pdigit->AddPhysicsSignal(iqpad);
93 // update list of tracks
97 if (fSignal) charge = iqpad;
99 pdigit->UpdateTrackList(track,charge);
103 //--------------------------------------------------------------------------
104 void AliMUONDigitizerv1::MakeTransientDigit(Int_t track, Int_t iHit, AliMUONHit * mHit)
106 AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
108 cerr<<"AliMUONDigitizerv1::Digitize Error:"
109 <<" module MUON not found in the input file"<<endl;
111 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit starts"<<endl;
112 Int_t ichamber = mHit->Chamber()-1;
113 AliMUONChamber & chamber = pMUON->Chamber(ichamber);
114 Float_t xhit = mHit->X();
115 Float_t yhit = mHit->Y();
116 Float_t zhit = mHit->Z();
117 Float_t eloss= mHit->Eloss();
118 Float_t tof = mHit->Age();
119 // Variables for chamber response from AliMUONChamber::DisIntegration
120 Float_t newdigit[6][500]; // Pad information
121 Int_t nnew=0; // Number of touched Pads per hit
125 // Calls the charge disintegration method of the current chamber
126 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit calling AliMUONChamber::DisIngtegration starts"<<endl;
127 chamber.DisIntegration(eloss, tof, xhit, yhit, zhit, nnew, newdigit);
128 // Creating a new TransientDigits from hit
129 for(Int_t iTD=0; iTD<nnew; iTD++) {
130 digits[0] = Int_t(newdigit[1][iTD]); // Padx of the Digit
131 digits[1] = Int_t(newdigit[2][iTD]); // Pady of the Digit
132 digits[2] = Int_t(newdigit[5][iTD]); // Cathode plane
133 digits[3] = Int_t(newdigit[3][iTD]); // Induced charge in the Pad
134 if (fSignal) digits[4] = Int_t(newdigit[3][iTD]);
136 digits[5] = iHit+fMask; // Hit number in the list
137 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit " <<
138 "PadX "<< digits[0] << " " <<
139 "PadY "<< digits[1] << " " <<
140 "Plane " << digits[2] << " " <<
141 "Charge " << digits[3] <<" " <<
142 "Hit " << digits[5] << endl;
146 if (fSignal) charge = digits[3];
147 else charge = kBgTag;
148 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit Creating AliMUONTransientDigit"<<endl;
149 AliMUONTransientDigit * mTD = new AliMUONTransientDigit(ichamber, digits);
150 mTD->AddToTrackList(track,charge);
152 if (!ExistTransientDigit(mTD)) {
153 AddTransientDigit(mTD);
154 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit Adding TransientDigit"<<endl;
157 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit updating TransientDigit"<<endl;
158 UpdateTransientDigit(track, mTD);
163 //-----------------------------------------------------------------------
164 void AliMUONDigitizerv1::Exec(Option_t* option)
166 TString optionString = option;
167 if (optionString.Data() == "deb") {
168 cout<<"AliMUONDigitizerv1::Exec: called with option deb "<<endl;
172 AliMUONChamber* chamber;
173 AliSegmentation* c1Segmentation; //Cathode plane c1 of the chamber
174 AliSegmentation* c2Segmentation; //Cathode place c2 of the chamber
176 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::Digitize() starts"<<endl;
177 fTDList = new TObjArray;
179 // Getting Module MUON
180 AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
182 cerr<<"AliMUONDigitizerv1::Digitize Error:"
183 <<" module MUON not found in the input file"<<endl;
186 // New branch for MUON digit in the tree of digits
187 pMUON->MakeBranchInTreeD(fManager->GetTreeD());
189 // Array of pointer of the AliMUONHitMapA1:
190 // two HitMaps per chamber, or one HitMap per cahtode plane
191 fHitMap= new AliMUONHitMapA1* [2*AliMUONConstants::NCh()];
193 //Loop over chambers for the definition AliMUONHitMap
194 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
195 chamber = &(pMUON->Chamber(i));
196 c1Segmentation = chamber->SegmentationModel(1); // Cathode plane 1
197 fHitMap[i] = new AliMUONHitMapA1(c1Segmentation, fTDList);
198 c2Segmentation = chamber->SegmentationModel(2); // Cathode plane 2
199 fHitMap[i+AliMUONConstants::NCh()] = new AliMUONHitMapA1(c2Segmentation, fTDList);
202 // Loop over files to merge and to digitize
204 for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); inputFile++) {
205 // Connect MUON Hit branch
206 if (inputFile > 0 ) fSignal = kFALSE;
207 TBranch *branchHits = 0;
208 TTree *treeH = fManager->GetInputTreeH(inputFile);
210 cerr<<"AliMUONDigitizerv1::Exec inputFile is "<<inputFile<<" "<<endl;
211 cerr<<"AliMUONDigitizerv1::Exec treeH, fHits "<<treeH<<" "<<fHits<<endl;
213 if (treeH && fHits) {
214 branchHits = treeH->GetBranch("MUON");
217 branchHits->SetAddress(&fHits);
220 Error("Exec","branch MUON was not found");
222 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::Exec branchHits = "<<branchHits<<endl;
224 fMask = fManager->GetMask(inputFile);
228 Int_t ntracks = (Int_t) treeH->GetEntries();
229 for (itrack = 0; itrack < ntracks; itrack++) {
230 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::Exec itrack = "<<itrack<<endl;
232 branchHits->GetEntry(itrack);
235 Int_t ihit, ichamber;
237 for(ihit = 0; ihit < fHits->GetEntriesFast(); ihit++) {
238 mHit = static_cast<AliMUONHit*>(fHits->At(ihit));
239 ichamber = mHit->Chamber()-1; // chamber number
240 if (ichamber > AliMUONConstants::NCh()-1) {
241 cerr<<"AliMUONDigitizer: ERROR: "
242 <<"fNch > AliMUONConstants::NCh()-1, fNch, NCh(): "
243 <<ichamber<<", "<< AliMUONConstants::NCh()<<endl;
246 chamber = &(pMUON->Chamber(ichamber));
248 //Dumping Hit content:
250 cerr<<"AliMuonDigitizerv1::Exec ihit, ichamber, x, y, z, eloss " <<
252 mHit->Chamber() << " " <<
256 mHit->Eloss() << " " << endl;
259 // Inititializing Correlation
260 chamber->ChargeCorrelationInit();
261 if (ichamber < AliMUONConstants::NTrackingCh()) {
263 // Initialize hit position (cursor) in the segmentation model
264 chamber->SigGenInit(mHit->X(), mHit->Y(), mHit->Z());
268 MakeTransientDigit(itrack, ihit, mHit);
272 if (GetDebug()>2) cerr<<"AliMUONDigitizer::Exec End of hits, track and file loops"<<endl;
275 // Filling Digit List
276 Int_t tracks[kMAXTRACKS];
277 Int_t charges[kMAXTRACKS];
278 Int_t nentries = fTDList->GetEntriesFast();
280 for (Int_t nent = 0; nent < nentries; nent++) {
281 AliMUONTransientDigit *address = (AliMUONTransientDigit*)fTDList->At(nent);
282 if (address == 0) continue;
283 Int_t ich = address->Chamber();
284 Int_t q = address->Signal();
285 chamber = &(pMUON->Chamber(ich));
287 // Digit Response (noise, threshold, saturation, ...)
288 AliMUONResponse * response = chamber->ResponseModel();
289 q = response->DigitResponse(q,address);
293 digits[0] = address->PadX();
294 digits[1] = address->PadY();
295 digits[2] = address->Cathode();
297 digits[4] = address->Physics();
298 digits[5] = address->Hit();
300 Int_t nptracks = address->GetNTracks();
302 if (nptracks > kMAXTRACKS) {
304 cerr<<"AliMUONDigitizer:Exec nptracks > 10 "<<nptracks;
305 cerr<<"reset to max value "<<kMAXTRACKS<<endl;
307 nptracks = kMAXTRACKS;
309 if (nptracks > 2 && GetDebug() >2) {
310 cerr<<"AliMUONDigitizer::Exec nptracks > 2 "<<nptracks<<endl;
311 // printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,digits[0],digits[1],q);
313 for (Int_t tr = 0; tr < nptracks; tr++) {
314 tracks[tr] = address->GetTrack(tr);
315 charges[tr] = address->GetCharge(tr);
316 } //end loop over list of tracks for one pad
317 // Sort list of tracks according to charge
319 SortTracks(tracks,charges,nptracks);
321 if (nptracks < kMAXTRACKS ) {
322 for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
329 if (GetDebug()>2) cerr<<"AliMUONDigitzerv1::Exex TransientDigit to Digit"<<endl;
330 pMUON->AddDigits(ich,tracks,charges,digits);
332 fManager->GetTreeD()->Fill();
333 pMUON->ResetDigits(); //
336 for(Int_t ii = 0; ii < 2*AliMUONConstants::NCh(); ++ii) {
344 cerr<<"AliMUONDigitizer::Exec: writing the TreeD: "
345 <<fManager->GetTreeD()->GetName()<<endl;
346 fManager->GetTreeD()->Write(0,TObject::kOverwrite);
350 if (fHits) fHits->Clear();
353 //------------------------------------------------------------------------
354 void AliMUONDigitizerv1::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
357 // Sort the list of tracks contributing to a given digit
358 // Only the 3 most significant tracks are acctually sorted
362 // Loop over signals, only 3 times
367 Int_t idx[3] = {-2,-2,-2};
368 Int_t jch[3] = {-2,-2,-2};
369 Int_t jtr[3] = {-2,-2,-2};
380 if((i == 1 && j == idx[i-1])
381 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
383 if(charges[j] > qmax) {
391 jch[i]=charges[jmax];