Changes to compile with Root6
[u/mrichter/AliRoot.git] / MFT / AliMFTDigitizer.cxx
CommitLineData
820b4d9e 1/**************************************************************************
2 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16//====================================================================================================================================================
17//
18// Digitizer class for the ALICE Muon Forward Tracker
19//
20// Contact author: antonio.uras@cern.ch
21//
22//====================================================================================================================================================
23
24#include "AliRun.h"
25#include "AliRunLoader.h"
f21fc003 26#include "AliDigitizationInput.h"
820b4d9e 27#include "AliLoader.h"
28#include "AliLog.h"
29#include "AliMFTDigitizer.h"
30#include "AliMFTDigit.h"
31#include "AliMFT.h"
32#include "AliMFTSegmentation.h"
33#include "TObjArray.h"
34#include "TClonesArray.h"
35#include "AliDigitizer.h"
36
37ClassImp(AliMFTDigitizer)
38
39//====================================================================================================================================================
40
41AliMFTDigitizer::AliMFTDigitizer():
42 AliDigitizer(),
43 fNPlanes(0),
44 fSegmentation(0)
45{
46
47 // default constructor
48
49}
50
51//====================================================================================================================================================
52
d4643a10 53AliMFTDigitizer::AliMFTDigitizer(AliDigitizationInput *digInp):
f21fc003 54 AliDigitizer(digInp),
820b4d9e 55 fNPlanes(0),
56 fSegmentation(0)
57{
58
59}
60
61//====================================================================================================================================================
62
f21fc003 63void AliMFTDigitizer::Digitize(Option_t*) {
820b4d9e 64
65 // This method is responsible for merging sdigits to a list of digits
66
67 AliDebug(1, "************************************************************************");
d4643a10 68 AliDebug(1, "************************ AliMFTDigitizer::Digitize *********************");
820b4d9e 69 AliDebug(1, "************************************************************************");
70
71 if (!fSegmentation) {
72 fSegmentation = new AliMFTSegmentation("AliMFTGeometry.root");
73 fNPlanes = fSegmentation -> GetNPlanes();
74 }
75
76 AliDebug(1, Form("nPlanes = %d",fNPlanes));
77
f21fc003 78 AliDebug(1,Form("Start with %i input(s) for event %i", fDigInput->GetNinputs(), fDigInput->GetOutputEventNr()));
820b4d9e 79
80 AliRunLoader *pInRunLoader=0;
81 AliLoader *pInMFTLoader=0;
82
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
85
86 // filling the arrays of sdigits...
87
f21fc003 88 for (Int_t iFile=0; iFile<fDigInput->GetNinputs(); iFile++) {
820b4d9e 89
f21fc003 90 pInRunLoader = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(iFile));
820b4d9e 91 pInMFTLoader = pInRunLoader->GetLoader("MFTLoader");
92 if (!pInMFTLoader) {
93 AliDebug(1,"no MFT lodader, checking in the other input \n");
94 continue;
95 }
96
97 if (!pInRunLoader->GetAliRun()) pInRunLoader->LoadgAlice();
98 AliMFT *pInMFT = (AliMFT*) pInRunLoader->GetAliRun()->GetDetector("MFT");
99
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!");
106
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));
f21fc003 112 pSDig->AddOffset2TrackID(fDigInput->GetMask(iFile)); // -> To be introduced for merging (since all inputs count tracks independently from 0)
820b4d9e 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));
116 }
117 }
118
119 pInMFTLoader->UnloadSDigits();
120 pInMFT->ResetSDigits();
121
122 }
123
f21fc003 124 AliRunLoader *pOutRunLoader = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName()); // open output stream (only 1 possible)
820b4d9e 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();
131
132 SDigits2Digits(sDigits, pOutMFT->GetDigitsList()); // here the sdigits are merged into digits
133
134 pOutMFTLoader->TreeD()->Fill(); // fill the output tree with the list of digits
135 pOutMFTLoader->WriteDigits("OVERWRITE"); // serialize them to file
136
137 for (Int_t iPlane=0; iPlane<fNPlanes; iPlane++) sDigits[iPlane].Clear(); // remove all tmp sdigits
138 pOutMFTLoader->UnloadDigits();
139 pOutMFT->ResetDigits();
140
141}
142
143//====================================================================================================================================================
144
145void AliMFTDigitizer::SDigits2Digits(TClonesArray *pSDigitList, TObjArray *pDigitList) {
146
147 TClonesArray *myDigitList[fNMaxPlanes] = {0};
148
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
152 }
153
154 AliDebug(1,"starting loop over planes");
155
156 for (Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
157
158 AliMFTDigit *newDig=NULL;
159 AliMFTDigit *oldDig=NULL;
160 pSDigitList[iPlane].Sort();
161
660cbe7c 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");
165
820b4d9e 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())));
168
169 for (Int_t iSDig=0; iSDig<pSDigitList[iPlane].GetEntries(); iSDig++) {
170
171 newDig = (AliMFTDigit*) (pSDigitList[iPlane].At(iSDig));
660cbe7c 172 Int_t localDetElemID = fSegmentation->GetDetElemLocalID(newDig->GetDetElemID());
820b4d9e 173 Bool_t digitExists = kFALSE;
660cbe7c 174 Int_t nDigits = digitsPerDetElem[localDetElemID]->GetEntries();
820b4d9e 175
176 for (Int_t iDig=0; iDig<nDigits; iDig++) {
660cbe7c 177 oldDig = (AliMFTDigit*) (digitsPerDetElem[localDetElemID]->At(iDig));
820b4d9e 178 if (newDig->GetDetElemID()==oldDig->GetDetElemID() &&
179 newDig->GetPixelX()==oldDig->GetPixelX() &&
180 newDig->GetPixelY()==oldDig->GetPixelY() &&
181 newDig->GetPixelZ()==oldDig->GetPixelZ()) {
182 digitExists = kTRUE;
183 MergeDigits(oldDig, newDig);
184 break;
185 }
186 }
660cbe7c 187
188 if (!digitExists) new ((*digitsPerDetElem[localDetElemID])[digitsPerDetElem[localDetElemID]->GetEntries()]) AliMFTDigit(*newDig);
189
190 }
820b4d9e 191
660cbe7c 192 // Now we merge the digit lists coming from each detection element, to have an ordered final list
820b4d9e 193
660cbe7c 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);
198 }
820b4d9e 199 }
660cbe7c 200
201 for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) delete digitsPerDetElem[iDetElem];
820b4d9e 202
203 AliDebug(1, Form("MFT plane #%02d has %d Digits", iPlane, Int_t(myDigitList[iPlane]->GetEntries())));
204
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()) );
208// }
209
210 AliDebug(1, "ending loop over sdigits to create digits");
211
212 }
213
214 AliDebug(1,"ending loop over layers");
215
216}
217
218//====================================================================================================================================================
219
220void AliMFTDigitizer::MergeDigits(AliMFTDigit *mainDig, AliMFTDigit *digToSum) {
221
222 mainDig -> SetEloss(mainDig->GetEloss() + digToSum->GetEloss());
223
224 Bool_t trackExists = kFALSE;
225 for (Int_t iTrack=0; iTrack<mainDig->GetNMCTracks(); iTrack++) {
226 if (digToSum->GetMCLabel(0) == mainDig->GetMCLabel(iTrack)) {
227 trackExists = kTRUE;
228 break;
229 }
230 }
231
232 if (!trackExists) mainDig->AddMCLabel(digToSum->GetMCLabel(0));
233
234}
235
236//====================================================================================================================================================
237