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 **************************************************************************/
16 //====================================================================================================================================================
18 // Digitizer class for the ALICE Muon Forward Tracker
20 // Contact author: antonio.uras@cern.ch
22 //====================================================================================================================================================
25 #include "AliRunLoader.h"
26 #include "AliDigitizationInput.h"
27 #include "AliLoader.h"
29 #include "AliMFTDigitizer.h"
30 #include "AliMFTDigit.h"
32 #include "AliMFTSegmentation.h"
33 #include "TObjArray.h"
34 #include "TClonesArray.h"
35 #include "AliDigitizer.h"
37 ClassImp(AliMFTDigitizer)
39 //====================================================================================================================================================
41 AliMFTDigitizer::AliMFTDigitizer():
47 // default constructor
51 //====================================================================================================================================================
53 AliMFTDigitizer::AliMFTDigitizer(AliDigitizationInput *digInp):
61 //====================================================================================================================================================
63 void AliMFTDigitizer::Digitize(Option_t*) {
65 // This method is responsible for merging sdigits to a list of digits
67 AliDebug(1, "************************************************************************");
68 AliDebug(1, "************************ AliMFTDigitizer::Digitize *********************");
69 AliDebug(1, "************************************************************************");
72 fSegmentation = new AliMFTSegmentation("AliMFTGeometry.root");
73 fNPlanes = fSegmentation -> GetNPlanes();
76 AliDebug(1, Form("nPlanes = %d",fNPlanes));
78 AliDebug(1,Form("Start with %i input(s) for event %i", fDigInput->GetNinputs(), fDigInput->GetOutputEventNr()));
80 AliRunLoader *pInRunLoader=0;
81 AliLoader *pInMFTLoader=0;
83 TClonesArray sDigits[fNMaxPlanes];
84 for (Int_t iPlane=0; iPlane<fNMaxPlanes; iPlane++) sDigits[iPlane].SetClass("AliMFTDigit"); // tmp storage for sdigits sum up from all input files
86 // filling the arrays of sdigits...
88 for (Int_t iFile=0; iFile<fDigInput->GetNinputs(); iFile++) {
90 pInRunLoader = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(iFile));
91 pInMFTLoader = pInRunLoader->GetLoader("MFTLoader");
93 AliDebug(1,"no MFT lodader, checking in the other input \n");
97 if (!pInRunLoader->GetAliRun()) pInRunLoader->LoadgAlice();
98 AliMFT *pInMFT = (AliMFT*) pInRunLoader->GetAliRun()->GetDetector("MFT");
100 AliDebug(1, "pInMFTLoader->LoadSDigits()...");
101 pInMFTLoader->LoadSDigits();
102 AliDebug(1, "... done!");
103 AliDebug(1, " pInMFTLoader->TreeS()->GetEntry(0);");
104 pInMFTLoader->TreeS()->GetEntry(0);
105 AliDebug(1, "... done!");
107 for (Int_t iPlane=0; iPlane<pInMFT->GetSDigitsList()->GetEntries(); iPlane++) {
108 for(Int_t iSDig=0; iSDig<((TClonesArray*)pInMFT->GetSDigitsList()->At(iPlane))->GetEntries(); iSDig++) {
109 AliDebug(2, Form("Reading digit %03d of plane %02d (A)", iSDig, iPlane));
110 AliMFTDigit *pSDig = (AliMFTDigit*) ((TClonesArray*)pInMFT->GetSDigitsList()->At(iPlane))->At(iSDig);
111 AliDebug(2, Form("Reading digit %03d of plane %02d (B)", iSDig, iPlane));
112 pSDig->AddOffset2TrackID(fDigInput->GetMask(iFile)); // -> To be introduced for merging (since all inputs count tracks independently from 0)
113 AliDebug(2, Form("Reading digit %03d of plane %02d (C)", iSDig, iPlane));
114 new ((sDigits[iPlane])[sDigits[iPlane].GetEntries()]) AliMFTDigit(*pSDig);
115 AliDebug(2, Form("Reading digit %03d of plane %02d (D)", iSDig, iPlane));
119 pInMFTLoader->UnloadSDigits();
120 pInMFT->ResetSDigits();
124 AliRunLoader *pOutRunLoader = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName()); // open output stream (only 1 possible)
125 AliLoader *pOutMFTLoader = pOutRunLoader->GetLoader("MFTLoader");
126 AliRun *pAliRun = pOutRunLoader->GetAliRun();
127 AliMFT *pOutMFT = (AliMFT*) pAliRun->GetDetector("MFT");
128 pOutMFTLoader->MakeTree("D");
129 pOutMFT->MakeBranch("D");
130 pOutMFT->SetTreeAddress();
132 SDigits2Digits(sDigits, pOutMFT->GetDigitsList()); // here the sdigits are merged into digits
134 pOutMFTLoader->TreeD()->Fill(); // fill the output tree with the list of digits
135 pOutMFTLoader->WriteDigits("OVERWRITE"); // serialize them to file
137 for (Int_t iPlane=0; iPlane<fNPlanes; iPlane++) sDigits[iPlane].Clear(); // remove all tmp sdigits
138 pOutMFTLoader->UnloadDigits();
139 pOutMFT->ResetDigits();
143 //====================================================================================================================================================
145 void AliMFTDigitizer::SDigits2Digits(TClonesArray *pSDigitList, TObjArray *pDigitList) {
147 TClonesArray *myDigitList[fNMaxPlanes] = {0};
149 for (Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
150 myDigitList[iPlane] = (TClonesArray*)(*pDigitList)[iPlane];
151 if (myDigitList[iPlane]->GetEntries()!=0) AliErrorClass("Some of digits lists is not empty"); // in principle those lists should be empty
154 AliDebug(1,"starting loop over planes");
156 for (Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
158 AliMFTDigit *newDig=NULL;
159 AliMFTDigit *oldDig=NULL;
160 pSDigitList[iPlane].Sort();
162 Int_t nDetElem = fSegmentation->GetPlane(iPlane)->GetNActiveElements();
163 TClonesArray *digitsPerDetElem[fNMaxDetElemPerPlane] = {0};
164 for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) digitsPerDetElem[iDetElem] = new TClonesArray("AliMFTDigit");
166 AliDebug(1,"starting loop over sdigits to create digits");
167 AliDebug(1, Form("MFT plane #%02d has %d SDigits", iPlane, Int_t(pSDigitList[iPlane].GetEntries())));
169 for (Int_t iSDig=0; iSDig<pSDigitList[iPlane].GetEntries(); iSDig++) {
171 newDig = (AliMFTDigit*) (pSDigitList[iPlane].At(iSDig));
172 Int_t localDetElemID = fSegmentation->GetDetElemLocalID(newDig->GetDetElemID());
173 Bool_t digitExists = kFALSE;
174 Int_t nDigits = digitsPerDetElem[localDetElemID]->GetEntries();
176 for (Int_t iDig=0; iDig<nDigits; iDig++) {
177 oldDig = (AliMFTDigit*) (digitsPerDetElem[localDetElemID]->At(iDig));
178 if (newDig->GetDetElemID()==oldDig->GetDetElemID() &&
179 newDig->GetPixelX()==oldDig->GetPixelX() &&
180 newDig->GetPixelY()==oldDig->GetPixelY() &&
181 newDig->GetPixelZ()==oldDig->GetPixelZ()) {
183 MergeDigits(oldDig, newDig);
188 if (!digitExists) new ((*digitsPerDetElem[localDetElemID])[digitsPerDetElem[localDetElemID]->GetEntries()]) AliMFTDigit(*newDig);
192 // Now we merge the digit lists coming from each detection element, to have an ordered final list
194 for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) {
195 for (Int_t iSDig=0; iSDig<digitsPerDetElem[iDetElem]->GetEntries(); iSDig++) {
196 newDig = (AliMFTDigit*) (digitsPerDetElem[iDetElem]->At(iSDig));
197 new ((*myDigitList[iPlane])[myDigitList[iPlane]->GetEntries()]) AliMFTDigit(*newDig);
201 for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) delete digitsPerDetElem[iDetElem];
203 AliDebug(1, Form("MFT plane #%02d has %d Digits", iPlane, Int_t(myDigitList[iPlane]->GetEntries())));
205 // for (Int_t iDigit=0; iDigit<myDigitList[iPlane]->GetEntries(); iDigit++) {
206 // AliDebug(1, Form("Digit %03d of MFT plane %02d has pixel coordinates (%05d, %05d)",
207 // iDigit, iPlane, ((AliMFTDigit*) myDigitList[iPlane]->At(iDigit))->GetPixelX(), ((AliMFTDigit*) myDigitList[iPlane]->At(iDigit))->GetPixelY()) );
210 AliDebug(1, "ending loop over sdigits to create digits");
214 AliDebug(1,"ending loop over layers");
218 //====================================================================================================================================================
220 void AliMFTDigitizer::MergeDigits(AliMFTDigit *mainDig, AliMFTDigit *digToSum) {
222 mainDig -> SetEloss(mainDig->GetEloss() + digToSum->GetEloss());
224 Bool_t trackExists = kFALSE;
225 for (Int_t iTrack=0; iTrack<mainDig->GetNMCTracks(); iTrack++) {
226 if (digToSum->GetMCLabel(0) == mainDig->GetMCLabel(iTrack)) {
232 if (!trackExists) mainDig->AddMCLabel(digToSum->GetMCLabel(0));
236 //====================================================================================================================================================