1 //-----------------------------------------------------//
3 // Source File : PMDDigitization.cxx, Version 00 //
5 // Date : September 20 2002 //
7 //-----------------------------------------------------//
12 #include <TGeometry.h>
13 #include <TObjArray.h>
14 #include <TClonesArray.h>
17 #include <TParticle.h>
22 #include "AliDetector.h"
23 #include "AliRunLoader.h"
24 #include "AliLoader.h"
25 #include "AliConfig.h"
27 #include "AliRunDigitizer.h"
28 #include "AliHeader.h"
30 #include "AliPMDcell.h"
31 #include "AliPMDsdigit.h"
32 #include "AliPMDdigit.h"
33 #include "AliPMDDigitizer.h"
34 #include "AliPMDClustering.h"
35 #include "AliPMDrecpoint.h"
38 ClassImp(AliPMDDigitizer)
42 AliPMDDigitizer::AliPMDDigitizer()
44 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
46 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
49 for (Int_t i = 0; i < fTotSM; i++)
51 for (Int_t j = 0; j < fNCell; j++)
53 for (Int_t k = 0; k < fNCell; k++)
61 if (!fCell) fCell = new TObjArray();
63 fZPos = 361.5; // in units of cm, This is the default position of PMD
66 AliPMDDigitizer::~AliPMDDigitizer()
75 void AliPMDDigitizer::OpengAliceFile(Char_t *file, Option_t *option)
78 fRunLoader = AliRunLoader::Open(file,AliConfig::fgkDefaultEventFolderName,
83 Error("Open","Can not open session for file %s.",file);
86 fRunLoader->LoadgAlice();
87 fRunLoader->LoadHeader();
88 fRunLoader->LoadKinematics();
90 gAlice = fRunLoader->GetAliRun();
94 printf("<AliPMDdigitizer::Open> ");
95 printf("AliRun object found on file.\n");
99 printf("<AliPMDdigitizer::Open> ");
100 printf("Could not find AliRun object.\n");
103 PMD = (AliPMD*)gAlice->GetDetector("PMD");
104 pmdloader = fRunLoader->GetLoader("PMDLoader");
105 if (pmdloader == 0x0)
107 cerr<<"Hits2Digits : Can not find PMD or PMDLoader\n";
110 const char *cHS = strstr(option,"HS");
111 const char *cHD = strstr(option,"HD");
112 const char *cSD = strstr(option,"SD");
116 pmdloader->LoadHits("READ");
117 pmdloader->LoadSDigits("recreate");
121 pmdloader->LoadHits("READ");
122 pmdloader->LoadDigits("recreate");
126 pmdloader->LoadSDigits("READ");
127 pmdloader->LoadDigits("recreate");
131 void AliPMDDigitizer::Hits2SDigits(Int_t ievt)
133 cout << " -------- Beginning of Hits2SDigits ----------- " << endl;
146 Float_t xPos, yPos, zPos;
149 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
154 printf("Event Number = %d \n",ievt);
155 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
156 printf("Number of Particles = %d \n", nparticles);
157 fRunLoader->GetEvent(ievt);
158 Particles = gAlice->Particles();
159 // ------------------------------------------------------- //
160 // Pointer to specific detector hits.
161 // Get pointers to Alice detectors and Hits containers
163 treeH = pmdloader->TreeH();
165 Int_t ntracks = (Int_t) treeH->GetEntries();
166 printf("Number of Tracks in the TreeH = %d \n", ntracks);
168 treeS = pmdloader->TreeS();
171 pmdloader->MakeTree("S");
172 treeS = pmdloader->TreeS();
174 Int_t bufsize = 16000;
175 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
177 if (PMD) PMDhits = PMD->Hits();
179 // Start loop on tracks in the hits containers
182 for (Int_t track=0; track<ntracks;track++)
185 treeH->GetEvent(track);
189 npmd = PMDhits->GetEntriesFast();
190 for (int ipmd = 0; ipmd < npmd; ipmd++)
192 pmdHit = (AliPMDhit*) PMDhits->UncheckedAt(ipmd);
193 trackno = pmdHit->GetTrack();
195 // get kinematics of the particles
197 particle = gAlice->Particle(trackno);
198 trackpid = particle->GetPdgCode();
206 TParticle* mparticle = particle;
208 while((imo = mparticle->GetFirstMother()) >= 0)
211 mparticle = gAlice->Particle(imo);
212 id_mo = mparticle->GetPdgCode();
214 vx = mparticle->Vx();
215 vy = mparticle->Vy();
216 vz = mparticle->Vz();
218 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, id_mo, vx, vy, vz);
219 //fprintf(ftest1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, id_mo, vx, vy, vz);
221 if (id_mo == kGamma && vx == 0. && vy == 0. && vz == 0.)
228 if (id_mo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
242 cellnumber = pmdHit->fVolume[1];
243 smnumber1 = pmdHit->fVolume[4];
244 edep = pmdHit->fEnergy;
246 if (smnumber1 > 3 && smnumber1 <= 6)
248 Int_t ny = (cellnumber-1)/48 + 1;
249 Int_t nx = cellnumber - (ny-1)*48;
252 Int_t ncell1 = (ny1 - 1)* 72 + nx1;
255 smnumber = Convert2RealSMNumber(smnumber1);
256 ypad = (cellnumber - 1)/fNCell + 1;
257 xpad = cellnumber - (ypad-1)*fNCell;
259 //cout << "-zpos = " << -zPos << endl;
266 else if (-zPos > fZPos)
274 fPMD[smnumber-1][xpad-1][ypad-1] += edep;
275 fPMDCounter[smnumber-1][xpad-1][ypad-1]++;
276 Int_t smn = smnumber - 1;
277 Int_t ixx = xpad - 1;
278 Int_t iyy = ypad - 1;
280 pmdcell = new AliPMDcell(mtrackno,smn,ixx,iyy,edep);
286 fCPV[smnumber-1][xpad-1][ypad-1] += edep;
287 fCPVTrackNo[smnumber-1][xpad-1][ypad-1] = mtrackno;
291 } // Track Loop ended
294 TrackAssignment2Cell();
300 Int_t count_digit = 0;
304 for (Int_t idet = 0; idet < 2; idet++)
306 for (Int_t ism = 0; ism < fTotSM; ism++)
308 for (Int_t jrow = 0; jrow < fNCell; jrow++)
310 for (Int_t kcol = 0; kcol < fNCell; kcol++)
312 cellno = jrow + kcol*fNCell;
315 deltaE = fPMD[ism][jrow][kcol];
316 trno = fPMDTrackNo[ism][jrow][kcol];
321 deltaE = fCPV[ism][jrow][kcol];
322 trno = fCPVTrackNo[ism][jrow][kcol];
328 AddSDigit(trno,detno,ism,cellno,deltaE);
336 pmdloader->WriteSDigits("OVERWRITE");
340 // cout << " -------- End of Hits2SDigit ----------- " << endl;
343 void AliPMDDigitizer::Hits2Digits(Int_t ievt)
356 Float_t xPos, yPos, zPos;
359 Float_t vx = -999.0, vy = -999.0, vz = -999.0;
364 printf("Event Number = %d \n",ievt);
366 Int_t nparticles = fRunLoader->GetHeader()->GetNtrack();
367 printf("Number of Particles = %d \n", nparticles);
368 fRunLoader->GetEvent(ievt);
369 Particles = gAlice->Particles();
370 // ------------------------------------------------------- //
371 // Pointer to specific detector hits.
372 // Get pointers to Alice detectors and Hits containers
374 PMD = (AliPMD*)gAlice->GetDetector("PMD");
375 pmdloader = fRunLoader->GetLoader("PMDLoader");
377 if (pmdloader == 0x0)
379 cerr<<"Hits2Digits method : Can not find PMD or PMDLoader\n";
381 treeH = pmdloader->TreeH();
382 Int_t ntracks = (Int_t) treeH->GetEntries();
383 printf("Number of Tracks in the TreeH = %d \n", ntracks);
384 pmdloader->LoadDigits("recreate");
385 treeD = pmdloader->TreeD();
388 pmdloader->MakeTree("D");
389 treeD = pmdloader->TreeD();
391 Int_t bufsize = 16000;
392 treeD->Branch("PMDDigit", &fDigits, bufsize);
394 if (PMD) PMDhits = PMD->Hits();
396 // Start loop on tracks in the hits containers
398 for (Int_t track=0; track<ntracks;track++)
401 treeH->GetEvent(track);
405 npmd = PMDhits->GetEntriesFast();
406 for (int ipmd = 0; ipmd < npmd; ipmd++)
408 pmdHit = (AliPMDhit*) PMDhits->UncheckedAt(ipmd);
409 trackno = pmdHit->GetTrack();
411 // get kinematics of the particles
413 particle = gAlice->Particle(trackno);
414 trackpid = particle->GetPdgCode();
422 TParticle* mparticle = particle;
424 while((imo = mparticle->GetFirstMother()) >= 0)
427 mparticle = gAlice->Particle(imo);
428 id_mo = mparticle->GetPdgCode();
430 vx = mparticle->Vx();
431 vy = mparticle->Vy();
432 vz = mparticle->Vz();
434 //printf("==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, id_mo, vx, vy, vz);
435 //fprintf(ftest1,"==> Mother ID %5d %5d %5d Vertex: %13.3f %13.3f %13.3f\n", igen, imo, id_mo, vx, vy, vz);
437 if (id_mo == kGamma && vx == 0. && vy == 0. && vz == 0.)
444 if (id_mo == kPi0 && vx == 0. && vy == 0. && vz == 0.)
458 cellnumber = pmdHit->fVolume[1];
459 smnumber1 = pmdHit->fVolume[4];
460 edep = pmdHit->fEnergy;
462 if (smnumber1 > 3 && smnumber1 <= 6)
464 Int_t ny = (cellnumber-1)/48 + 1;
465 Int_t nx = cellnumber - (ny-1)*48;
468 Int_t ncell1 = (ny1 - 1)* 72 + nx1;
472 smnumber = Convert2RealSMNumber(smnumber1);
473 ypad = (cellnumber - 1)/fNCell + 1;
474 xpad = cellnumber - (ypad-1)*fNCell;
476 //cout << "-zpos = " << -zPos << endl;
482 else if (-zPos > fZPos)
490 fCPV[smnumber-1][xpad-1][ypad-1] += edep;
492 else if (fDetNo == 0)
494 fPMD[smnumber-1][xpad-1][ypad-1] += edep;
495 fPMDCounter[smnumber-1][xpad-1][ypad-1]++;
499 } // Track Loop ended
501 TrackAssignment2Cell();
506 Int_t count_digit = 0;
510 for (Int_t idet = 0; idet < 2; idet++)
512 for (Int_t ism = 0; ism < fTotSM; ism++)
514 for (Int_t jrow = 0; jrow < fNCell; jrow++)
516 for (Int_t kcol = 0; kcol < fNCell; kcol++)
518 cellno = jrow + kcol*fNCell;
521 deltaE = fPMD[ism][jrow][kcol];
526 deltaE = fCPV[ism][jrow][kcol];
532 AddDigit(trno,detno,ism,cellno,deltaE);
536 } // supermodule loop
541 pmdloader->WriteDigits("OVERWRITE");
545 // cout << " -------- End of Hits2Digit ----------- " << endl;
549 void AliPMDDigitizer::SDigits2Digits(Int_t ievt)
551 // cout << " -------- Beginning of SDigits2Digit ----------- " << endl;
552 fRunLoader->GetEvent(ievt);
554 treeS = pmdloader->TreeS();
555 AliPMDsdigit *pmdsdigit;
556 TBranch *branch = treeS->GetBranch("PMDSDigit");
557 branch->SetAddress(&fSDigits);
559 treeD = pmdloader->TreeD();
562 pmdloader->MakeTree("D");
563 treeD = pmdloader->TreeD();
565 Int_t bufsize = 16000;
566 treeD->Branch("PMDDigit", &fDigits, bufsize);
568 Int_t trno, det, smn;
572 Int_t nmodules = (Int_t) treeS->GetEntries();
574 for (Int_t imodule = 0; imodule < nmodules; imodule++)
576 treeS->GetEntry(imodule);
577 Int_t nentries = fSDigits->GetLast();
578 //cout << " nentries = " << nentries << endl;
579 for (Int_t ient = 0; ient < nentries+1; ient++)
581 pmdsdigit = (AliPMDsdigit*)fSDigits->UncheckedAt(ient);
582 trno = pmdsdigit->GetTrackNumber();
583 det = pmdsdigit->GetDetector();
584 smn = pmdsdigit->GetSMNumber();
585 cellno = pmdsdigit->GetCellNumber();
586 edep = pmdsdigit->GetCellEdep();
590 AddDigit(trno,det,smn,cellno,adc);
595 pmdloader->WriteDigits("OVERWRITE");
596 // cout << " -------- End of SDigits2Digit ----------- " << endl;
599 void AliPMDDigitizer::TrackAssignment2Cell()
601 // To be checked again
603 // This blocks assign the cell id when there is
604 // multiple tracks in a cell according to the
616 PMDTrack = new Int_t ***[27];
617 PMDEdep = new Float_t ***[27];
618 for (i=0; i<fTotSM; i++)
620 PMDTrack[i] = new Int_t **[72];
621 PMDEdep[i] = new Float_t **[72];
624 for (i = 0; i < fTotSM; i++)
626 for (j = 0; j < fNCell; j++)
628 PMDTrack[i][j] = new Int_t *[72];
629 PMDEdep[i][j] = new Float_t *[72];
633 for (i = 0; i < fTotSM; i++)
635 for (j = 0; j < fNCell; j++)
637 for (k = 0; k < fNCell; k++)
639 Int_t nn = fPMDCounter[i][j][k];
642 PMDTrack[i][j][k] = new Int_t[nn];
643 PMDEdep[i][j][k] = new Float_t[nn];
648 PMDTrack[i][j][k] = new Int_t[nn];
649 PMDEdep[i][j][k] = new Float_t[nn];
651 fPMDCounter[i][j][k] = 0;
657 Int_t nentries = fCell->GetEntries();
659 Int_t mtrackno, ism, ixp, iyp;
662 for (i = 0; i < nentries; i++)
664 pmdcell = (AliPMDcell*)fCell->UncheckedAt(i);
666 mtrackno = pmdcell->GetTrackNumber();
667 ism = pmdcell->GetSMNumber();
668 ixp = pmdcell->GetX();
669 iyp = pmdcell->GetY();
670 edep = pmdcell->GetEdep();
672 Int_t nn = fPMDCounter[ism][ixp][iyp];
674 // cout << " nn = " << nn << endl;
676 PMDTrack[ism][ixp][iyp][nn] = (Int_t) mtrackno;
677 PMDEdep[ism][ixp][iyp][nn] = edep;
678 fPMDCounter[ism][ixp][iyp]++;
685 for (im=0; im<27; im++)
687 for (ix=0; ix<72; ix++)
689 for (iy=0; iy<72; iy++)
691 nn = fPMDCounter[im][ix][iy];
694 // This block handles if a cell is fired
695 // many times by many tracks
697 status = new Int_t[nn];
698 for (iz = 0; iz < nn; iz++)
700 status[iz] = PMDTrack[im][ix][iy][iz];
702 sort(status,status+nn);
703 Int_t track_old = -99999;
704 Int_t track, tr_count = 0;
705 for (iz = 0; iz < nn; iz++)
708 if (track_old != track)
711 vjunkTRN.push_back(track);
716 Float_t tot_edp = 0.;
717 tr_edp = new Float_t[tr_count];
718 frac_edp = new Float_t[tr_count];
719 for (il = 0; il < tr_count; il++)
722 track = vjunkTRN[il];
723 for (iz = 0; iz < nn; iz++)
725 if (track == PMDTrack[im][ix][iy][iz])
727 tr_edp[il] += PMDEdep[im][ix][iy][iz];
730 tot_edp += tr_edp[il];
734 Float_t frac_old = 0.;
736 for (il = 0; il < tr_count; il++)
738 frac_edp[il] = tr_edp[il]/tot_edp;
739 if (frac_old < frac_edp[il])
741 frac_old = frac_edp[il];
748 fPMDTrackNo[im][ix][iy] = vjunkTRN[il_old];
752 // This only handles if a cell is fired
755 fPMDTrackNo[im][ix][iy] = PMDTrack[im][ix][iy][0];
760 // This is if no cell is fired
761 fPMDTrackNo[im][ix][iy] = -999;
767 // Delete all the pointers
769 for (i = 0; i < fTotSM; i++)
771 for (j = 0; j < fNCell; j++)
773 for (k = 0; k < fNCell; k++)
775 delete [] PMDTrack[i][j][k];
776 delete [] PMDEdep[i][j][k];
781 for (i = 0; i < fTotSM; i++)
783 for (j = 0; j < fNCell; j++)
785 delete [] PMDTrack[i][j];
786 delete [] PMDEdep[i][j];
790 for (i = 0; i < fTotSM; i++)
792 delete [] PMDTrack[i];
793 delete [] PMDEdep[i];
798 // End of the cell id assignment
803 void AliPMDDigitizer::MeV2ADC(Float_t mev, Float_t & adc)
809 void AliPMDDigitizer::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
810 Int_t cellnumber, Float_t adc)
812 TClonesArray &lsdigits = *fSDigits;
813 AliPMDsdigit *newcell;
814 newcell = new AliPMDsdigit(trnumber,det,smnumber,cellnumber,adc);
815 new(lsdigits[fNsdigit++]) AliPMDsdigit(newcell);
819 void AliPMDDigitizer::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
820 Int_t cellnumber, Float_t adc)
822 TClonesArray &ldigits = *fDigits;
823 AliPMDdigit *newcell;
824 newcell = new AliPMDdigit(trnumber,det,smnumber,cellnumber,adc);
825 new(ldigits[fNdigit++]) AliPMDdigit(newcell);
829 Int_t AliPMDDigitizer::Convert2RealSMNumber(Int_t smnumber1)
831 Int_t smnumber = -999;
833 if (smnumber1==1) smnumber = 1;
834 if (smnumber1==2) smnumber = 10;
835 if (smnumber1==3) smnumber = 19;
836 if (smnumber1==4) smnumber = 1;
837 if (smnumber1==5) smnumber = 10;
838 if (smnumber1==6) smnumber = 19;
839 if (smnumber1==7) smnumber = 2;
840 if (smnumber1==8) smnumber = 3;
841 if (smnumber1==9) smnumber = 4;
842 if (smnumber1==10) smnumber = 5;
843 if (smnumber1==11) smnumber = 6;
844 if (smnumber1==12) smnumber = 7;
845 if (smnumber1==13) smnumber = 8;
846 if (smnumber1==14) smnumber = 9;
847 if (smnumber1==15) smnumber = 11;
848 if (smnumber1==16) smnumber = 12;
849 if (smnumber1==17) smnumber = 13;
850 if (smnumber1==18) smnumber = 14;
851 if (smnumber1==19) smnumber = 15;
852 if (smnumber1==20) smnumber = 16;
853 if (smnumber1==21) smnumber = 17;
854 if (smnumber1==22) smnumber = 18;
855 if (smnumber1==23) smnumber = 20;
856 if (smnumber1==24) smnumber = 21;
857 if (smnumber1==25) smnumber = 22;
858 if (smnumber1==26) smnumber = 23;
859 if (smnumber1==27) smnumber = 24;
860 if (smnumber1==28) smnumber = 25;
861 if (smnumber1==29) smnumber = 26;
862 if (smnumber1==30) smnumber = 27;
866 void AliPMDDigitizer::SetZPosition(Float_t zpos)
870 Float_t AliPMDDigitizer::GetZPosition() const
875 void AliPMDDigitizer::ResetCell()
878 for (Int_t i = 0; i < fTotSM; i++)
880 for (Int_t j = 0; j < fNCell; j++)
882 for (Int_t k = 0; k < fNCell; k++)
884 fPMDCounter[i][j][k] = 0;
889 void AliPMDDigitizer::ResetSDigit()
892 if (fSDigits) fSDigits->Clear();
894 void AliPMDDigitizer::ResetDigit()
897 if (fDigits) fDigits->Clear();
900 void AliPMDDigitizer::ResetCellADC()
902 for (Int_t i = 0; i < fTotSM; i++)
904 for (Int_t j = 0; j < fNCell; j++)
906 for (Int_t k = 0; k < fNCell; k++)
915 void AliPMDDigitizer::UnLoad(Option_t *option)
917 const char *cS = strstr(option,"S");
918 const char *cD = strstr(option,"D");
920 fRunLoader->UnloadgAlice();
921 fRunLoader->UnloadHeader();
922 fRunLoader->UnloadKinematics();
926 pmdloader->UnloadHits();
930 pmdloader->UnloadHits();
931 pmdloader->UnloadSDigits();