ffa6d63b |
1 | /************************************************************************* |
61e0abb5 |
2 | * Copyright(c) 1998-1999, 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 | /* $Id$ */ |
17 | |
18 | //_________________________________________________________________________ |
19 | // This is a TTask that makes SDigits out of Hits |
20 | // A Summable Digits is the sum of all hits originating |
ffa6d63b |
21 | // from one in one tower of the EMCAL |
61e0abb5 |
22 | // A threshold for assignment of the primary to SDigit is applied |
23 | // SDigits are written to TreeS, branch "EMCAL" |
24 | // AliEMCALSDigitizer with all current parameters is written |
25 | // to TreeS branch "AliEMCALSDigitizer". |
26 | // Both branches have the same title. If necessary one can produce |
27 | // another set of SDigits with different parameters. Two versions |
28 | // can be distunguished using titles of the branches. |
29 | // User case: |
30 | // root [0] AliEMCALSDigitizer * s = new AliEMCALSDigitizer("galice.root") |
31 | // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated |
32 | // root [1] s->ExecuteTask() |
33 | // // Makes SDigitis for all events stored in galice.root |
34 | // root [2] s->SetPedestalParameter(0.001) |
35 | // // One can change parameters of digitization |
36 | // root [3] s->SetSDigitsBranch("Redestal 0.001") |
37 | // // and write them into the new branch |
38 | // root [4] s->ExeciteTask("deb all tim") |
39 | // // available parameters: |
40 | // deb - print # of produced SDigitis |
41 | // deb all - print # and list of produced SDigits |
42 | // tim - print benchmarking information |
43 | // |
ffa6d63b |
44 | //*-- Author : Sahal Yacoob (LBL) |
45 | // based on : AliPHOSSDigitzer |
61e0abb5 |
46 | ////////////////////////////////////////////////////////////////////////////// |
47 | |
48 | |
49 | // --- ROOT system --- |
50 | #include "TFile.h" |
51 | #include "TTask.h" |
52 | #include "TTree.h" |
53 | #include "TSystem.h" |
54 | #include "TROOT.h" |
55 | #include "TFolder.h" |
56 | #include "TBenchmark.h" |
57 | // --- Standard library --- |
58 | #include <iomanip.h> |
59 | |
60 | // --- AliRoot header files --- |
61 | #include "AliRun.h" |
62 | #include "AliEMCALDigit.h" |
63 | #include "AliEMCALHit.h" |
64 | #include "AliEMCALSDigitizer.h" |
65 | #include "AliEMCALGeometry.h" |
66 | #include "AliEMCALv1.h" |
67 | |
68 | ClassImp(AliEMCALSDigitizer) |
69 | |
70 | |
71 | //____________________________________________________________________________ |
72 | AliEMCALSDigitizer::AliEMCALSDigitizer():TTask("AliEMCALSDigitizer","") |
73 | { |
74 | // ctor |
75 | fA = 0; |
76 | fB = 10000000. ; |
ffa6d63b |
77 | fPrimThreshold = 0.01 ; |
61e0abb5 |
78 | fNevents = 0 ; |
79 | fSDigits = 0 ; |
80 | fHits = 0 ; |
81 | fIsInitialized = kFALSE ; |
82 | |
83 | } |
84 | |
85 | //____________________________________________________________________________ |
86 | AliEMCALSDigitizer::AliEMCALSDigitizer(const char* headerFile, const char *sDigitsTitle):TTask("AliEMCALSDigitizer","") |
87 | { |
88 | // ctor |
89 | fA = 0; |
90 | fB = 10000000.; |
ffa6d63b |
91 | fPrimThreshold = 0.01 ; |
61e0abb5 |
92 | fNevents = 0 ; |
93 | fSDigitsTitle = sDigitsTitle ; |
94 | fHeadersFile = headerFile ; |
95 | fSDigits = new TClonesArray("AliEMCALDigit",1000); |
96 | fHits = new TClonesArray("AliEMCALHit",1000); |
97 | |
98 | TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ; |
99 | |
100 | //File was not opened yet |
101 | if(file == 0){ |
102 | if(fHeadersFile.Contains("rfio")) |
103 | file = TFile::Open(fHeadersFile,"update") ; |
104 | else |
105 | file = new TFile(fHeadersFile.Data(),"update") ; |
106 | gAlice = (AliRun *) file->Get("gAlice") ; |
107 | } |
108 | |
109 | //add Task to //root/Tasks folder |
110 | TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; |
111 | roottasks->Add(this) ; |
112 | |
113 | fIsInitialized = kTRUE ; |
114 | } |
115 | |
116 | //____________________________________________________________________________ |
117 | AliEMCALSDigitizer::~AliEMCALSDigitizer() |
118 | { |
119 | // dtor |
120 | if(fSDigits) |
121 | delete fSDigits ; |
122 | if(fHits) |
123 | delete fHits ; |
124 | } |
125 | //____________________________________________________________________________ |
126 | void AliEMCALSDigitizer::Init(){ |
127 | //Initialization can not be done in the default constructor |
128 | |
129 | if(!fIsInitialized){ |
130 | |
131 | if(fHeadersFile.IsNull()) |
132 | fHeadersFile="galice.root" ; |
133 | |
134 | TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ; |
135 | |
136 | //if file was not opened yet, read gAlice |
137 | if(file == 0){ |
138 | file = new TFile(fHeadersFile.Data(),"update") ; |
139 | gAlice = (AliRun *) file->Get("gAlice") ; |
140 | } |
141 | |
142 | fHits = new TClonesArray("AliEMCALHit",1000); |
143 | fSDigits = new TClonesArray("AliEMCALDigit",1000); |
144 | |
145 | // add Task to //root/Tasks folder |
146 | TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; |
147 | roottasks->Add(this) ; |
148 | |
149 | fIsInitialized = kTRUE ; |
150 | } |
151 | } |
152 | //____________________________________________________________________________ |
153 | void AliEMCALSDigitizer::Exec(Option_t *option) { |
154 | //Collects all hits in the same active volume into digit |
155 | |
156 | if(!fIsInitialized) |
157 | Init() ; |
158 | |
159 | if(strstr(option,"tim")) |
160 | gBenchmark->Start("EMCALSDigitizer"); |
161 | |
162 | fNevents = (Int_t) gAlice->TreeE()->GetEntries() ; |
163 | |
164 | Int_t ievent ; |
165 | for(ievent = 0; ievent < fNevents; ievent++){ |
166 | gAlice->GetEvent(ievent) ; |
167 | gAlice->SetEvent(ievent) ; |
168 | |
169 | if(gAlice->TreeH()==0){ |
170 | cout << "AliEMCALSDigitizer: There is no Hit Tree" << endl; |
171 | return ; |
172 | } |
173 | |
174 | //set address of the hits |
175 | TBranch * branch = gAlice->TreeH()->GetBranch("EMCAL"); |
176 | if (branch) |
177 | branch->SetAddress(&fHits); |
178 | else{ |
179 | cout << "ERROR in AliEMCALSDigitizer: "<< endl ; |
180 | cout << " no branch EMCAL in TreeH"<< endl ; |
181 | cout << " do nothing " << endl ; |
182 | return ; |
183 | } |
184 | |
185 | fSDigits->Clear(); |
186 | Int_t nSdigits = 0 ; |
187 | |
188 | |
189 | //Now made SDigits from hits, for EMCAL it is the same, so just copy |
190 | Int_t itrack ; |
191 | for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){ |
192 | |
193 | //=========== Get the EMCAL branch from Hits Tree for the Primary track itrack |
194 | branch->GetEntry(itrack,0); |
ffa6d63b |
195 | AliEMCALv0 * EMCAL = (AliEMCALv0 *) gAlice->GetDetector("EMCAL") ; |
61e0abb5 |
196 | AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance( EMCAL->GetGeometry()->GetName(), EMCAL->GetGeometry()->GetTitle() ); |
197 | |
198 | Int_t i; |
199 | for ( i = 0 ; i < fHits->GetEntries() ; i++ ) { |
200 | AliEMCALHit * hit = (AliEMCALHit*)fHits->At(i) ; |
ffa6d63b |
201 | AliEMCALDigit * curSDigit = 0 ; |
202 | AliEMCALDigit * sdigit ; |
203 | Bool_t newsdigit = kTRUE; |
204 | // Assign primary number only if contribution is significant |
61e0abb5 |
205 | if( hit->GetEnergy() > fPrimThreshold) |
ffa6d63b |
206 | curSDigit = new AliEMCALDigit( hit->GetPrimary(), hit->GetIparent(), (((hit->GetId()/geom->GetNPhi())%geom->GetNZ()+1 ) * (hit->GetId()%(geom->GetNPhi()+1))), Digitize( hit->GetEnergy() ) ) ; |
61e0abb5 |
207 | else |
ffa6d63b |
208 | curSDigit = new AliEMCALDigit( -1 , -1 ,(((hit->GetId()/geom->GetNPhi())%geom->GetNZ() + 1 ) * (hit->GetId()%(geom->GetNPhi()+1))), Digitize( hit->GetEnergy() ) ) ; |
209 | cout << "Hit ID = " <<hit->GetId() << endl ; |
210 | cout << "ID for detector = " << curSDigit->GetId() << endl ; |
211 | cout << hit->GetEnergy() << " - hit energy - Digit Energy - " << curSDigit->GetAmp() << endl; |
212 | for(Int_t check= 0; check < nSdigits ; check++) { |
61e0abb5 |
213 | sdigit = (AliEMCALDigit *)fSDigits->At(check); |
ffa6d63b |
214 | if( sdigit->GetId() == curSDigit->GetId()) |
215 | { cout << "SDigit - Get Amp " << sdigit->GetAmp() << endl ; |
216 | *sdigit = *sdigit + *curSDigit ; |
217 | newsdigit = kFALSE; |
218 | cout << " and after addition " << sdigit->GetAmp() << endl ; |
61e0abb5 |
219 | } |
ffa6d63b |
220 | } |
221 | if (newsdigit) |
222 | { new((*fSDigits)[nSdigits]) AliEMCALDigit(*curSDigit); |
223 | nSdigits++ ; |
224 | cout << "Detector nsdigits = " << nSdigits << endl ; } |
225 | newsdigit = kTRUE; |
226 | |
61e0abb5 |
227 | |
228 | if( hit->GetEnergy() > fPrimThreshold) |
ffa6d63b |
229 | curSDigit = new AliEMCALDigit( hit->GetPrimary(), hit->GetIparent(), ((geom->GetNZ() * geom->GetNPhi()) + ((hit->GetId()/geom->GetNPhi())%geom->GetNZ() + 1) * (hit->GetId()%(geom->GetNPhi()+1))), Digitize( hit->GetEnergy() ) ) ; |
61e0abb5 |
230 | else |
ffa6d63b |
231 | curSDigit = new AliEMCALDigit( -1 , -1 ,((geom->GetNZ() * geom->GetNPhi()) + ((hit->GetId()/geom->GetNPhi())%geom->GetNZ()+1) * (hit->GetId()%(geom->GetNPhi()+1))), Digitize( hit->GetEnergy() ) ) ; |
61e0abb5 |
232 | |
233 | if((hit->GetId()/geom->GetNPhi()) < (2*geom->GetNZ())) |
ffa6d63b |
234 | { cout << "ID for Preshower = " << curSDigit->GetId() << endl ; |
61e0abb5 |
235 | for(Int_t check= 0; check < nSdigits; check++) { |
236 | sdigit = (AliEMCALDigit *)fSDigits->At(check); |
ffa6d63b |
237 | if( sdigit->GetId() == curSDigit->GetId()) |
61e0abb5 |
238 | { |
ffa6d63b |
239 | *sdigit = *sdigit + *curSDigit ; |
240 | newsdigit = kFALSE ; |
241 | } |
61e0abb5 |
242 | } |
ffa6d63b |
243 | if (newsdigit) |
244 | { new((*fSDigits)[nSdigits]) AliEMCALDigit(*curSDigit); |
245 | nSdigits++ ; |
246 | cout << "Preshower nsdigits = " << nSdigits << endl ;} |
247 | newsdigit=kTRUE; |
61e0abb5 |
248 | } |
249 | } |
250 | } // loop over tracks |
251 | |
252 | fSDigits->Sort() ; |
253 | |
254 | nSdigits = fSDigits->GetEntriesFast() ; |
255 | fSDigits->Expand(nSdigits) ; |
256 | |
257 | Int_t i ; |
258 | for (i = 0 ; i < nSdigits ; i++) { |
259 | AliEMCALDigit * digit = (AliEMCALDigit *) fSDigits->At(i) ; |
260 | digit->SetIndexInList(i) ; |
261 | } |
262 | |
263 | if(gAlice->TreeS() == 0) |
264 | gAlice->MakeTree("S") ; |
265 | |
266 | //check, if this branch already exits? |
267 | TBranch * sdigitsBranch = 0; |
268 | TBranch * sdigitizerBranch = 0; |
269 | |
270 | TObjArray * branches = gAlice->TreeS()->GetListOfBranches() ; |
271 | Int_t ibranch; |
272 | Bool_t emcalNotFound = kTRUE ; |
273 | Bool_t sdigitizerNotFound = kTRUE ; |
274 | |
275 | for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){ |
276 | |
277 | if(emcalNotFound){ |
278 | sdigitsBranch=(TBranch *) branches->At(ibranch) ; |
279 | if( (strcmp("EMCAL",sdigitsBranch->GetName())==0 ) && |
280 | (fSDigitsTitle.CompareTo(sdigitsBranch->GetTitle()) == 0) ) |
281 | emcalNotFound = kFALSE ; |
282 | } |
283 | if(sdigitizerNotFound){ |
284 | sdigitizerBranch = (TBranch *) branches->At(ibranch) ; |
285 | if( (strcmp(sdigitizerBranch->GetName(),"AliEMCALSDigitizer") == 0)&& |
286 | (fSDigitsTitle.CompareTo(sdigitizerBranch->GetTitle()) == 0) ) |
287 | sdigitizerNotFound = kFALSE ; |
288 | } |
289 | } |
290 | |
291 | if(!(sdigitizerNotFound && emcalNotFound)){ |
292 | cout << "AliEMCALSdigitizer error:" << endl ; |
293 | cout << "Can not overwrite existing branches: do not write" << endl ; |
294 | return ; |
295 | } |
296 | |
297 | //Make (if necessary) branches |
298 | char * file =0; |
299 | if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name |
300 | file = new char[strlen(gAlice->GetBaseFile())+20] ; |
301 | sprintf(file,"%s/EMCAL.SDigits.root",gAlice->GetBaseFile()) ; |
302 | } |
303 | |
304 | TDirectory *cwd = gDirectory; |
305 | |
306 | //First list of sdigits |
307 | Int_t bufferSize = 32000 ; |
308 | sdigitsBranch = gAlice->TreeS()->Branch("EMCAL",&fSDigits,bufferSize); |
309 | sdigitsBranch->SetTitle(fSDigitsTitle.Data()); |
310 | if (file) { |
311 | sdigitsBranch->SetFile(file); |
312 | TIter next( sdigitsBranch->GetListOfBranches()); |
313 | TBranch * subbr; |
314 | while ((subbr=(TBranch*)next())) { |
315 | subbr->SetFile(file); |
316 | } |
317 | cwd->cd(); |
318 | } |
319 | |
320 | //second - SDigitizer |
321 | Int_t splitlevel = 0 ; |
322 | AliEMCALSDigitizer * sd = this ; |
323 | sdigitizerBranch = gAlice->TreeS()->Branch("AliEMCALSDigitizer","AliEMCALSDigitizer", |
324 | &sd,bufferSize,splitlevel); |
325 | sdigitizerBranch->SetTitle(fSDigitsTitle.Data()); |
326 | if (file) { |
327 | sdigitizerBranch->SetFile(file); |
328 | TIter next( sdigitizerBranch->GetListOfBranches()); |
329 | TBranch * subbr ; |
330 | while ((subbr=(TBranch*)next())) { |
331 | subbr->SetFile(file); |
332 | } |
333 | cwd->cd(); |
334 | delete file; |
335 | } |
336 | |
337 | sdigitsBranch->Fill() ; |
338 | sdigitizerBranch->Fill() ; |
339 | gAlice->TreeS()->Write(0,TObject::kOverwrite) ; |
340 | |
341 | if(strstr(option,"deb")) |
342 | PrintSDigits(option) ; |
343 | |
344 | } |
345 | |
346 | if(strstr(option,"tim")){ |
347 | gBenchmark->Stop("EMCALSDigitizer"); |
348 | cout << "AliEMCALSDigitizer:" << endl ; |
349 | cout << " took " << gBenchmark->GetCpuTime("EMCALSDigitizer") << " seconds for SDigitizing " |
350 | << gBenchmark->GetCpuTime("EMCALSDigitizer")/fNevents << " seconds per event " << endl ; |
351 | cout << endl ; |
352 | } |
353 | |
354 | |
355 | } |
356 | //__________________________________________________________________ |
357 | void AliEMCALSDigitizer::SetSDigitsBranch(const char * title ){ |
358 | //Seting title to branch SDigits |
359 | if(!fSDigitsTitle.IsNull()) |
360 | cout << "AliEMCALSdigitizer: changing SDigits file from " <<fSDigitsTitle.Data() << " to " << title << endl ; |
361 | fSDigitsTitle=title ; |
362 | } |
363 | //__________________________________________________________________ |
364 | void AliEMCALSDigitizer::Print(Option_t* option)const{ |
365 | cout << "------------------- "<< GetName() << " -------------" << endl ; |
366 | cout << " Writing SDigitis to branch with title " << fSDigitsTitle.Data() << endl ; |
367 | cout << " with digitization parameters A = " << fA << endl ; |
368 | cout << " B = " << fB << endl ; |
369 | cout << " Threshold for Primary assignment= " << fPrimThreshold << endl ; |
370 | cout << "---------------------------------------------------"<<endl ; |
371 | |
372 | } |
373 | //__________________________________________________________________ |
374 | Bool_t AliEMCALSDigitizer::operator==( AliEMCALSDigitizer const &sd )const{ |
375 | if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold)) |
376 | return kTRUE ; |
377 | else |
378 | return kFALSE ; |
379 | } |
380 | //__________________________________________________________________ |
381 | void AliEMCALSDigitizer::PrintSDigits(Option_t * option){ |
382 | //Prints list of digits produced at the current pass of AliEMCALDigitizer |
383 | |
384 | cout << "AliEMCALSDigitizer: " << endl ; |
385 | cout << " Number of entries in SDigits list " << fSDigits->GetEntriesFast() << endl ; |
386 | cout << endl ; |
387 | |
388 | if(strstr(option,"all")){// print all digits |
389 | |
390 | //loop over digits |
391 | AliEMCALDigit * digit; |
392 | cout << "SDigit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl; |
393 | Int_t index ; |
394 | for (index = 0 ; index < fSDigits->GetEntries() ; index++) { |
395 | digit = (AliEMCALDigit * ) fSDigits->At(index) ; |
396 | cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " " |
397 | << setw(6) << digit->GetIndexInList() << " " |
398 | << setw(5) << digit->GetNprimary() <<" "; |
399 | |
400 | Int_t iprimary; |
401 | for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) |
402 | cout << setw(5) << digit->GetPrimary(iprimary+1) << " "; |
403 | cout << endl; |
404 | } |
405 | |
406 | } |
407 | } |