]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONDigitizerv1.cxx
Renamed the motifs with lower case ID: x->x1
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizerv1.cxx
CommitLineData
8dbbc4e3 1
2
3#include <Riostream.h>
4#include <TDirectory.h>
5#include <TFile.h>
6#include <TObjArray.h>
7#include <TPDGCode.h>
8#include <TTree.h>
88cb7938 9#include <TMath.h>
8dbbc4e3 10
11#include "AliMUON.h"
12#include "AliMUONChamber.h"
13#include "AliMUONConstants.h"
14#include "AliMUONDigit.h"
15#include "AliMUONDigitizerv1.h"
16#include "AliMUONHit.h"
17#include "AliMUONHitMapA1.h"
18#include "AliMUONPadHit.h"
19#include "AliMUONTransientDigit.h"
20#include "AliRun.h"
21#include "AliRunDigitizer.h"
88cb7938 22#include "AliRunLoader.h"
23#include "AliLoader.h"
8dbbc4e3 24
25ClassImp(AliMUONDigitizerv1)
26
27//___________________________________________
28AliMUONDigitizerv1::AliMUONDigitizerv1() :AliDigitizer()
29{
30// Default ctor - don't use it
31 fHitMap = 0;
32 fTDList = 0;
33 if (GetDebug()>2)
34 cerr<<"AliMUONDigitizerv1::AliMUONDigitizerv1"
35 <<"(AliRunDigitizer* manager) was processed"<<endl;
36}
37
38//___________________________________________
39AliMUONDigitizerv1::AliMUONDigitizerv1(AliRunDigitizer* manager)
40 :AliDigitizer(manager)
41{
42// ctor which should be used
43 fHitMap = 0;
44 fTDList = 0;
45 fDebug = 0;
ce3f5e87 46 // fHits = new TClonesArray("AliMUONHit",1000);
8dbbc4e3 47 if (GetDebug()>2)
48 cerr<<"AliMUONDigitizerv1::AliMUONDigitizerv1"
49 <<"(AliRunDigitizer* manager) was processed"<<endl;
50}
51
52//------------------------------------------------------------------------
53AliMUONDigitizerv1::~AliMUONDigitizerv1()
54{
55// Destructor
ce3f5e87 56 //delete fHits;
8dbbc4e3 57}
58
59//------------------------------------------------------------------------
60void AliMUONDigitizerv1::AddTransientDigit(AliMUONTransientDigit * mTD)
61{
62 // Choosing the maping of the cathode plane of the chamber:
63 Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
64 fTDList->AddAtAndExpand(mTD, fTDCounter);
65 fHitMap[iNchCpl]->SetHit( mTD->PadX(), mTD->PadY(), fTDCounter);
66 fTDCounter++;
67}
68
69//------------------------------------------------------------------------
70Bool_t AliMUONDigitizerv1::ExistTransientDigit(AliMUONTransientDigit * mTD)
71{
72 // Choosing the maping of the cathode plane of the chamber:
73 Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
74 return( fHitMap[iNchCpl]->TestHit(mTD->PadX(), mTD->PadY()) );
75}
76
77//------------------------------------------------------------------------
78Bool_t AliMUONDigitizerv1::Init()
79{
80// Initialization
81 return kTRUE;
82}
83
84//------------------------------------------------------------------------
85void AliMUONDigitizerv1::UpdateTransientDigit(Int_t track, AliMUONTransientDigit * mTD)
86{
87 // Choosing the maping of the cathode plane of the chamber:
88 Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
89 AliMUONTransientDigit *pdigit =
90 static_cast<AliMUONTransientDigit*>(fHitMap[iNchCpl]->GetHit(mTD->PadX(),mTD->PadY()));
91 // update charge
92 //
93 Int_t iqpad = mTD->Signal(); // charge per pad
94 pdigit->AddSignal(iqpad);
95 pdigit->AddPhysicsSignal(iqpad);
96 // update list of tracks
97 //
3351e14b 98 Int_t charge;
8dbbc4e3 99 track=+ fMask;
100 if (fSignal) charge = iqpad;
3351e14b 101 //else charge = kBgTag;
102 else charge = iqpad + fMask;
103
8dbbc4e3 104 pdigit->UpdateTrackList(track,charge);
105}
106
107
108//--------------------------------------------------------------------------
109void AliMUONDigitizerv1::MakeTransientDigit(Int_t track, Int_t iHit, AliMUONHit * mHit)
110{
111 AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON");
112 if (!pMUON) {
113 cerr<<"AliMUONDigitizerv1::Digitize Error:"
114 <<" module MUON not found in the input file"<<endl;
115 }
116 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit starts"<<endl;
117 Int_t ichamber = mHit->Chamber()-1;
118 AliMUONChamber & chamber = pMUON->Chamber(ichamber);
119 Float_t xhit = mHit->X();
120 Float_t yhit = mHit->Y();
121 Float_t zhit = mHit->Z();
122 Float_t eloss= mHit->Eloss();
123 Float_t tof = mHit->Age();
124 // Variables for chamber response from AliMUONChamber::DisIntegration
125 Float_t newdigit[6][500]; // Pad information
126 Int_t nnew=0; // Number of touched Pads per hit
127 Int_t digits[6];
128
129 //
130 // Calls the charge disintegration method of the current chamber
131 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit calling AliMUONChamber::DisIngtegration starts"<<endl;
132 chamber.DisIntegration(eloss, tof, xhit, yhit, zhit, nnew, newdigit);
133 // Creating a new TransientDigits from hit
134 for(Int_t iTD=0; iTD<nnew; iTD++) {
135 digits[0] = Int_t(newdigit[1][iTD]); // Padx of the Digit
136 digits[1] = Int_t(newdigit[2][iTD]); // Pady of the Digit
137 digits[2] = Int_t(newdigit[5][iTD]); // Cathode plane
138 digits[3] = Int_t(newdigit[3][iTD]); // Induced charge in the Pad
139 if (fSignal) digits[4] = Int_t(newdigit[3][iTD]);
140 else digits[4] = 0;
141 digits[5] = iHit+fMask; // Hit number in the list
142 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit " <<
143 "PadX "<< digits[0] << " " <<
144 "PadY "<< digits[1] << " " <<
145 "Plane " << digits[2] << " " <<
146 "Charge " << digits[3] <<" " <<
147 "Hit " << digits[5] << endl;
148 // list of tracks
3351e14b 149 Int_t charge;
8dbbc4e3 150 track += fMask;
151 if (fSignal) charge = digits[3];
3351e14b 152 //else charge = kBgTag;
153 else charge = digits[3] + fMask;
154
8dbbc4e3 155 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit Creating AliMUONTransientDigit"<<endl;
156 AliMUONTransientDigit * mTD = new AliMUONTransientDigit(ichamber, digits);
157 mTD->AddToTrackList(track,charge);
8dbbc4e3 158 if (!ExistTransientDigit(mTD)) {
159 AddTransientDigit(mTD);
160 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit Adding TransientDigit"<<endl;
161 }
162 else {
163 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit updating TransientDigit"<<endl;
164 UpdateTransientDigit(track, mTD);
165 delete mTD;
166 }
167 }
168}
169//-----------------------------------------------------------------------
170void AliMUONDigitizerv1::Exec(Option_t* option)
171{
172 TString optionString = option;
173 if (optionString.Data() == "deb") {
ce3f5e87 174 Info("Digitize","Called with option deb ");
8dbbc4e3 175 fDebug = 3;
176 }
ce3f5e87 177
8dbbc4e3 178 AliMUONChamber* chamber;
179 AliSegmentation* c1Segmentation; //Cathode plane c1 of the chamber
180 AliSegmentation* c2Segmentation; //Cathode place c2 of the chamber
181
ce3f5e87 182 if (GetDebug()>2) Info("Digitize","AliMUONDigitizerv1::Digitize() starts");
8dbbc4e3 183 fTDList = new TObjArray;
184
88cb7938 185 //Loaders (We assume input0 to be the output too)
186 AliRunLoader * runloader; // Input loader
187 AliLoader * gime;
188
ce3f5e87 189 // Getting runloader
88cb7938 190 runloader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
191 if (runloader == 0x0) {
ce3f5e87 192 Error("Digitize","RunLoader is not in input file 0");
88cb7938 193 return; // RunDigitizer is not working.
194 }
ce3f5e87 195 // Getting MUONloader
196 gime = runloader->GetLoader("MUONLoader");
88cb7938 197 if (gime->TreeH()==0x0) {
ce3f5e87 198 if (GetDebug()>2) Info("Digitize","TreeH is not loaded yet. Loading...");
88cb7938 199 gime->LoadHits("READ");
ce3f5e87 200 if (GetDebug()>2) Info("Digitize","Now treeH is %#x. MUONLoader is %#x",gime->TreeH(),gime);
88cb7938 201 }
202
ce3f5e87 203 if (GetDebug()>2) Info("Digitize","Loaders ready");
88cb7938 204
ce3f5e87 205 if (runloader->GetAliRun() == 0x0) runloader->LoadgAlice();
88cb7938 206 gAlice = runloader->GetAliRun();
207
208 // Getting Module MUON
209 AliMUON *pMUON = (AliMUON *) gAlice->GetDetector("MUON");
8dbbc4e3 210 if (!pMUON) {
ce3f5e87 211 Error("Digitize","Module MUON not found in the input file");
8dbbc4e3 212 return;
ce3f5e87 213 }
214 // Getting Muon data
215 AliMUONData * muondata = pMUON->GetMUONData();
216 muondata->SetLoader(gime);
217 muondata->SetTreeAddress("H");
88cb7938 218
219 // Loading Event
220 Int_t currentevent = fManager->GetOutputEventNr();
221
222 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::Digitize() Event Number is "<<currentevent <<endl;
223 if ( (currentevent<10) ||
224 (Int_t(TMath::Log10(currentevent)) == TMath::Log10(currentevent) ) )
225 cout <<"ALiMUONDigitizerv1::Digitize() Event Number is "<< currentevent <<endl;
226
ce3f5e87 227 // Output file for digits same as hits
228 // AliRunLoader * runloaderout = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
229 //AliLoader * gimeout = runloaderout->GetLoader("MUONLoader");
88cb7938 230 // New branch per chamber for MUON digit in the tree of digits
b28974de 231 if (gime->TreeD() == 0x0) {
232 gime->MakeDigitsContainer();
233 }
ce3f5e87 234 TTree* treeD = gime->TreeD();
235 muondata->MakeBranch("D");
236 muondata->SetTreeAddress("D");
8dbbc4e3 237
238 // Array of pointer of the AliMUONHitMapA1:
239 // two HitMaps per chamber, or one HitMap per cahtode plane
240 fHitMap= new AliMUONHitMapA1* [2*AliMUONConstants::NCh()];
241
242 //Loop over chambers for the definition AliMUONHitMap
243 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
244 chamber = &(pMUON->Chamber(i));
245 c1Segmentation = chamber->SegmentationModel(1); // Cathode plane 1
246 fHitMap[i] = new AliMUONHitMapA1(c1Segmentation, fTDList);
247 c2Segmentation = chamber->SegmentationModel(2); // Cathode plane 2
248 fHitMap[i+AliMUONConstants::NCh()] = new AliMUONHitMapA1(c2Segmentation, fTDList);
249 }
250
251// Loop over files to merge and to digitize
252 fSignal = kTRUE;
253 for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); inputFile++) {
88cb7938 254 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::Digitize() Input File is "<<inputFile<<endl;
255
88cb7938 256
257 // Connect MUON Hit branch
258 if (inputFile > 0 ) {
259 fSignal = kFALSE;
260 runloader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
261 if (runloader == 0x0) {
262 cerr<<"AliMUONDigitizerv1::Digitize() RunLoader for inputFile "<<inputFile<< " not found !!! "<<endl;
263 }
264 gime = runloader->GetLoader("MUONLoader");
265 if (gime->TreeH() == 0x0) gime->LoadHits("READ");
ce3f5e87 266 muondata->SetLoader(gime);
267 muondata->SetTreeAddress("H");
88cb7938 268 }
269
ce3f5e87 270 // Setting the address
88cb7938 271 TTree *treeH = gime->TreeH();
272 if (treeH == 0x0) {
273 Error("Digitize","Can not get TreeH from input %d",inputFile);
274 Info("Digitize","Now treeH is %#x. MUONLoader is %#x",gime->TreeH(),gime);
275 return;
276 }
8dbbc4e3 277 if (GetDebug()>2) {
278 cerr<<"AliMUONDigitizerv1::Exec inputFile is "<<inputFile<<" "<<endl;
ce3f5e87 279 cerr<<"AliMUONDigitizerv1::Exec treeH" << treeH <<endl;
8dbbc4e3 280 }
ce3f5e87 281
282 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::Exec Setting tree addresses"<<endl;
88cb7938 283
8dbbc4e3 284 fMask = fManager->GetMask(inputFile);
285 //
286 // Loop over tracks
287 Int_t itrack;
288 Int_t ntracks = (Int_t) treeH->GetEntries();
289 for (itrack = 0; itrack < ntracks; itrack++) {
290 if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::Exec itrack = "<<itrack<<endl;
ce3f5e87 291 muondata->ResetHits();
88cb7938 292 treeH->GetEvent(itrack);
8dbbc4e3 293 //
294 // Loop over hits
295 Int_t ihit, ichamber;
296 AliMUONHit* mHit;
ce3f5e87 297 TClonesArray* hits = muondata->Hits();
298 for(ihit = 0; ihit < hits->GetEntriesFast(); ihit++) {
299 mHit = static_cast<AliMUONHit*>(hits->At(ihit));
8dbbc4e3 300 ichamber = mHit->Chamber()-1; // chamber number
301 if (ichamber > AliMUONConstants::NCh()-1) {
302 cerr<<"AliMUONDigitizer: ERROR: "
303 <<"fNch > AliMUONConstants::NCh()-1, fNch, NCh(): "
304 <<ichamber<<", "<< AliMUONConstants::NCh()<<endl;
305 return;
306 }
307 chamber = &(pMUON->Chamber(ichamber));
308 //
309 //Dumping Hit content:
310 if (GetDebug()>2) {
311 cerr<<"AliMuonDigitizerv1::Exec ihit, ichamber, x, y, z, eloss " <<
312 ihit << " " <<
313 mHit->Chamber() << " " <<
314 mHit->X() << " " <<
315 mHit->Y() << " " <<
316 mHit->Z() << " " <<
317 mHit->Eloss() << " " << endl;
318 }
319 //
320 // Inititializing Correlation
321 chamber->ChargeCorrelationInit();
322 if (ichamber < AliMUONConstants::NTrackingCh()) {
323 // Tracking Chamber
324 // Initialize hit position (cursor) in the segmentation model
325 chamber->SigGenInit(mHit->X(), mHit->Y(), mHit->Z());
326 } else {
327 // Trigger Chamber
328 }
329 MakeTransientDigit(itrack, ihit, mHit);
330 } // hit loop
331 } // track loop
332 } // end file loop
333 if (GetDebug()>2) cerr<<"AliMUONDigitizer::Exec End of hits, track and file loops"<<endl;
334
391cd891 335 // Loop on cathodes
336 Int_t icat;
337 for(icat=0; icat<2; icat++) {
8dbbc4e3 338 //
391cd891 339 // Filling Digit List
340 Int_t tracks[kMAXTRACKS];
341 Int_t charges[kMAXTRACKS];
342 Int_t nentries = fTDList->GetEntriesFast();
343 Int_t digits[6];
344 for (Int_t nent = 0; nent < nentries; nent++) {
345 AliMUONTransientDigit *address = (AliMUONTransientDigit*)fTDList->At(nent);
346 if (address == 0) continue;
347 Int_t ich = address->Chamber();
348 Int_t q = address->Signal();
349 chamber = &(pMUON->Chamber(ich));
350 //
351 // Digit Response (noise, threshold, saturation, ...)
352 AliMUONResponse * response = chamber->ResponseModel();
353 q = response->DigitResponse(q,address);
354
355 if (!q) continue;
356
357 digits[0] = address->PadX();
358 digits[1] = address->PadY();
359 digits[2] = address->Cathode()-1;
360 digits[3] = q;
361 digits[4] = address->Physics();
362 digits[5] = address->Hit();
363
364 Int_t nptracks = address->GetNTracks();
365
366 if (nptracks > kMAXTRACKS) {
367 if (GetDebug() >0) {
368 cerr<<"AliMUONDigitizer:Exec nptracks > 10 "<<nptracks;
369 cerr<<"reset to max value "<<kMAXTRACKS<<endl;
370 }
371 nptracks = kMAXTRACKS;
8dbbc4e3 372 }
391cd891 373 if (nptracks > 2 && GetDebug() >2) {
374 cerr<<"AliMUONDigitizer::Exec nptracks > 2 "<<nptracks<<endl;
375 // printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,digits[0],digits[1],q);
376 }
377 for (Int_t tr = 0; tr < nptracks; tr++) {
378 tracks[tr] = address->GetTrack(tr);
379 charges[tr] = address->GetCharge(tr);
380 } //end loop over list of tracks for one pad
381 // Sort list of tracks according to charge
382 if (nptracks > 1) {
383 SortTracks(tracks,charges,nptracks);
8dbbc4e3 384 }
391cd891 385 if (nptracks < kMAXTRACKS ) {
386 for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
88cb7938 387 tracks[i] = -1;
391cd891 388 charges[i] = 0;
389 }
390 }
391
ce3f5e87 392 // Add digits
88cb7938 393 if (GetDebug()>3) cerr<<"AliMUONDigitzerv1::Exex TransientDigit to Digit"<<endl;
ce3f5e87 394 if ( digits[2] == icat ) muondata->AddDigit(ich,tracks,charges,digits);
b28974de 395// printf("test rm ich %d padX %d padY %d \n",ich, digits[0], digits[1]);
8dbbc4e3 396 }
88cb7938 397 // Filling list of digits per chamber for a given cathode.
1a1cdff8 398 muondata->Fill("D");
ce3f5e87 399 muondata->ResetDigits();
391cd891 400 } // end loop cathode
401 fTDList->Delete();
8dbbc4e3 402
403 for(Int_t ii = 0; ii < 2*AliMUONConstants::NCh(); ++ii) {
404 if (fHitMap[ii]) {
405 delete fHitMap[ii];
406 fHitMap[ii] = 0;
407 }
408 }
409
410 if (GetDebug()>2)
411 cerr<<"AliMUONDigitizer::Exec: writing the TreeD: "
88cb7938 412 <<treeD->GetName()<<endl;
413
ce3f5e87 414 gime->WriteDigits("OVERWRITE");
8dbbc4e3 415 delete [] fHitMap;
416 delete fTDList;
ce3f5e87 417 muondata->ResetHits();
b28974de 418 gime->UnloadHits();
419 gime->UnloadDigits();
8dbbc4e3 420}
8dbbc4e3 421//------------------------------------------------------------------------
422void AliMUONDigitizerv1::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
423{
424 //
425 // Sort the list of tracks contributing to a given digit
426 // Only the 3 most significant tracks are acctually sorted
427 //
428
429 //
430 // Loop over signals, only 3 times
431 //
432
433 Int_t qmax;
434 Int_t jmax;
435 Int_t idx[3] = {-2,-2,-2};
436 Int_t jch[3] = {-2,-2,-2};
437 Int_t jtr[3] = {-2,-2,-2};
438 Int_t i,j,imax;
439
440 if (ntr<3) imax=ntr;
441 else imax=3;
442 for(i=0;i<imax;i++){
443 qmax=0;
444 jmax=0;
445
446 for(j=0;j<ntr;j++){
447
448 if((i == 1 && j == idx[i-1])
449 ||(i == 2 && (j == idx[i-1] || j == idx[i-2]))) continue;
450
451 if(charges[j] > qmax) {
452 qmax = charges[j];
453 jmax=j;
454 }
455 }
456
457 if(qmax > 0) {
458 idx[i]=jmax;
459 jch[i]=charges[jmax];
3351e14b 460 jtr[i]=tracks[jmax];
8dbbc4e3 461 }
462
463 }
464
465 for(i=0;i<3;i++){
466 if (jtr[i] == -2) {
467 charges[i]=0;
468 tracks[i]=0;
469 } else {
470 charges[i]=jch[i];
471 tracks[i]=jtr[i];
472 }
473 }
474}