polishing
[u/mrichter/AliRoot.git] / PHOS / AliPHOSReconstructioner.cxx
CommitLineData
d15a28e7 1/**************************************************************************
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
b2a60966 16/* $Id$ */
17
d15a28e7 18//_________________________________________________________________________
a3dfe79c 19//*--
7acf6008 20//*-- Author: Gines Martinez & Yves Schutz (SUBATECH)
21//*-- Complitely redisigned by Dmitri Peressounko (SUBATECH & RRC KI) March 2001
22/////////////////////////////////////////////////////////////////////////////////////
9a6ec61a 23// Wrapping class for reconstruction. Allows to produce reconstruction from
24// different steps: from previously produced hits,sdigits, etc. Each new reconstruction
25// flow (e.g. gigits, made from them RecPoints, made from them TrackSegments, made from
26// them RecParticles) are distinguished by the title of created branches. One can
27// use this title as a comment, see user case below. Thanks to getters, one can set
28// parameters to reconstruction bricks. The full set of parameters is saved in the
29// correspoinding branch: e.g. parameters of clusterizer are stored in branch
30// TreeR::AliPHOSClusterizer with the same title as the branch contaning RecPoints
31// themself. TTree does not support overwriting, therefore one can not produce several
32// branches with the same names and titles - use different titles.
33//
34// User case:
7acf6008 35//
36// root [0] AliPHOSReconstructioner * r = new AliPHOSReconstructioner("galice.root")
37// // Set the header file
38// root [1] r->ExecuteTask()
9a6ec61a 39// // Make full cheine of reconstruction
7acf6008 40//
41// // One can specify the title for each branch
42// root [2] r->SetBranchFileName("RecPoints","RecPoints1") ;
7acf6008 43//
9a6ec61a 44// // One can change parameters of reconstruction algorithms
45// root [3] r->GetClusterizer()->SetEmcLocalMaxCut(0.02)
46//
47// // One can specify the starting point of the reconstruction and title of all
48// // branches produced in this pass
49// root [4] r->StartFrom("AliPHOSClusterizer","Local max cut 0.02")
50// // means that will use already generated Digits and produce only RecPoints,
51// // TS and RecParticles
7acf6008 52//
53// // And finally one can call ExecuteTask() with the following options
9a6ec61a 54// root [5] r->ExecuteTask("debug all timing")
7acf6008 55// // deb - prints the numbers of produced SDigits, Digits etc.
56// // deb all - prints in addition list of made SDigits, digits etc.
57// // timing - prints benchmarking results
9a6ec61a 58///////////////////////////////////////////////////////////////////////////////////////////////////
d15a28e7 59
60// --- ROOT system ---
61
62#include "TClonesArray.h"
7acf6008 63#include "TROOT.h"
64#include "TTree.h"
d15a28e7 65
66// --- Standard library ---
7acf6008 67#include <iostream.h>
364de5c6 68
d15a28e7 69// --- AliRoot header files ---
7acf6008 70#include "AliRun.h"
d15a28e7 71#include "AliPHOSReconstructioner.h"
7acf6008 72#include "AliPHOSClusterizerv1.h"
73#include "AliPHOSDigitizer.h"
74#include "AliPHOSSDigitizer.h"
75#include "AliPHOSTrackSegmentMakerv1.h"
76#include "AliPHOSPIDv1.h"
9ec91567 77#include "AliPHOSFastRecParticle.h"
0b06c60d 78#include "AliPHOSCpvRecPoint.h"
d15a28e7 79
80ClassImp(AliPHOSReconstructioner)
81
d15a28e7 82//____________________________________________________________________________
7acf6008 83 AliPHOSReconstructioner::AliPHOSReconstructioner():TTask("AliPHOSReconstructioner","")
d15a28e7 84{
b2a60966 85 // ctor
7acf6008 86 fDigitizer = 0 ;
87 fClusterizer = 0 ;
88 fTSMaker = 0 ;
89 fPID = 0 ;
90 fSDigitizer = 0 ;
d15a28e7 91
7acf6008 92 fIsInitialized = kFALSE ;
d15a28e7 93
6ad0bfa0 94}
95
6ad0bfa0 96//____________________________________________________________________________
7acf6008 97AliPHOSReconstructioner::AliPHOSReconstructioner(const char* headerFile):TTask("AliPHOSReconstructioner","")
d15a28e7 98{
7acf6008 99 // ctor
100
101 fHeaderFileName = headerFile ;
102
103 fSDigitsBranch="" ;
104 fSDigitizer = new AliPHOSSDigitizer(fHeaderFileName.Data(),fSDigitsBranch.Data()) ;
105 Add(fSDigitizer) ;
106
107 fDigitsBranch="" ;
108 fDigitizer = new AliPHOSDigitizer(fHeaderFileName.Data(),fDigitsBranch.Data()) ;
109 Add(fDigitizer) ;
110
111
112 fRecPointBranch="" ;
113 fClusterizer = new AliPHOSClusterizerv1(fHeaderFileName.Data(),fRecPointBranch.Data()) ;
114 Add(fClusterizer) ;
2131115b 115
b73f246d 116
7acf6008 117 fTSBranch="" ;
118 fTSMaker = new AliPHOSTrackSegmentMakerv1(fHeaderFileName.Data(),fTSBranch.Data()) ;
119 Add(fTSMaker) ;
120
121
122 fRecPartBranch="" ;
123 fPID = new AliPHOSPIDv1(fHeaderFileName.Data(),fRecPartBranch.Data()) ;
124 Add(fPID) ;
125
126 fIsInitialized = kTRUE ;
127
128}
129//____________________________________________________________________________
130void AliPHOSReconstructioner::Exec(Option_t *option){
131 //chesk, if the names of branches, which should be made conicide with already
132 //existing
133 if(!fIsInitialized)
134 Init() ;
135
136 gAlice->GetEvent(0) ;
137
138 if(fSDigitizer->IsActive()&& gAlice->TreeS()){ //Will produce SDigits
139
140 TBranch * sdigitsBranch = 0;
141 TBranch * sdigitizerBranch = 0;
142
143 TObjArray * branches = gAlice->TreeS()->GetListOfBranches() ;
144 Int_t ibranch;
145 Bool_t phosNotFound = kTRUE ;
146 Bool_t sdigitizerNotFound = kTRUE ;
147
148 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
149 if(phosNotFound){
150 sdigitsBranch=(TBranch *) branches->At(ibranch) ;
151 if(( strcmp("PHOS",sdigitsBranch->GetName())==0 ) &&
152 (fSDigitsBranch.CompareTo(sdigitsBranch->GetTitle())== 0 ))
153 phosNotFound = kFALSE ;
154 }
155 if(sdigitizerNotFound){
156 sdigitizerBranch = (TBranch *) branches->At(ibranch) ;
157 if(( strcmp(sdigitizerBranch->GetName(),"AliPHOSSDigitizer") == 0) &&
158 (fSDigitsBranch.CompareTo(sdigitizerBranch->GetTitle())== 0 ) )
159 sdigitizerNotFound = kFALSE ;
160 }
161 }
162
163 if(!(sdigitizerNotFound && phosNotFound)){
164 cout << "AliPHOSReconstructioner error: "<< endl ;
165 cout << " Branches ''PHOS'' or ''AliPHOSSDigitizer'' with title ``" << fSDigitsBranch.Data() << "''" << endl ;
166 cout << " already exist in TreeS. ROOT does not allow updating/overwriting." << endl ;
167 cout << " Specify another title for branches or use ''StartFrom()'' method" << endl ;
168
169 //mark all tasks as inactive
170 TIter next(fTasks);
171 TTask *task;
172 while((task=(TTask*)next()))
173 task->SetActive(kFALSE) ;
174
175 return ;
176 }
2131115b 177 }
59cd4405 178
7acf6008 179 if(fDigitizer->IsActive() && gAlice->TreeD()){ //Will produce Digits
180 TBranch * digitsBranch = 0;
181 TBranch * digitizerBranch = 0;
182
183 TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ;
184 Int_t ibranch;
185 Bool_t phosNotFound = kTRUE ;
186 Bool_t digitizerNotFound = kTRUE ;
187
188 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
189 if(phosNotFound){
190 digitsBranch=(TBranch *) branches->At(ibranch) ;
191 if(( strcmp("PHOS",digitsBranch->GetName())==0 ) &&
192 (fDigitsBranch.CompareTo(digitsBranch->GetTitle())== 0 ))
193 phosNotFound = kFALSE ;
194 }
195 if(digitizerNotFound){
196 digitizerBranch = (TBranch *) branches->At(ibranch) ;
197 if(( strcmp(digitizerBranch->GetName(),"AliPHOSDigitizer") == 0) &&
198 (fDigitsBranch.CompareTo(digitizerBranch->GetTitle())== 0 ) )
199 digitizerNotFound = kFALSE ;
200 }
364de5c6 201 }
2aad621e 202
7acf6008 203 if(!(digitizerNotFound && phosNotFound)){
204 cout << "AliPHOSReconstructioner error: "<< endl ;
205 cout << " Branches ''PHOS'' or ''AliPHOSDigitizer'' with title ``" << fDigitsBranch.Data() << "''" << endl ;
206 cout << " already exist in TreeD. ROOT does not allow updating/overwriting." << endl ;
207 cout << " Specify another title for branches or use ''StartFrom()'' method" << endl ;
208
209 //mark all tasks as inactive
210 TIter next(fTasks);
211 TTask *task;
212 while((task=(TTask*)next()))
213 task->SetActive(kFALSE) ;
214
215 return ;
216 }
2aad621e 217 }
364de5c6 218
7acf6008 219 if(fClusterizer->IsActive() && gAlice->TreeR()){ //Will produce RecPoints
220 TBranch * emcBranch = 0;
221 TBranch * cpvBranch = 0;
222 TBranch * clusterizerBranch = 0;
223
224 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
225 Int_t ibranch;
226 Bool_t emcNotFound = kTRUE ;
227 Bool_t cpvNotFound = kTRUE ;
228 Bool_t clusterizerNotFound = kTRUE ;
229
230 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
231
232 if(emcNotFound){
233 emcBranch=(TBranch *) branches->At(ibranch) ;
234 if(fRecPointBranch.CompareTo(emcBranch->GetTitle())==0 )
235 if( strcmp(emcBranch->GetName(),"PHOSEmcRP") == 0)
236 emcNotFound = kFALSE ;
237 }
238 if(cpvNotFound){
239 cpvBranch=(TBranch *) branches->At(ibranch) ;
240 if(fRecPointBranch.CompareTo(cpvBranch->GetTitle())==0 )
241 if( strcmp(cpvBranch->GetName(),"PHOSCpvRP") == 0)
242 cpvNotFound = kFALSE ;
243 }
244 if(clusterizerNotFound){
245 clusterizerBranch = (TBranch *) branches->At(ibranch) ;
246 if( fRecPointBranch.CompareTo(clusterizerBranch->GetTitle()) == 0)
247 if( strcmp(clusterizerBranch->GetName(),"AliPHOSClusterizer") == 0)
248 clusterizerNotFound = kFALSE ;
249 }
250 }
6ad0bfa0 251
7acf6008 252 if(!(clusterizerNotFound && emcNotFound && cpvNotFound)){
253 cout << "AliPHOSReconstructioner error: "<< endl ;
254 cout << " Branches ''PHOSEmcRP'', ''PHOSCpvRP'' or ''AliPHOSClusterizer'' with title ``"
255 << fRecPointBranch.Data() << "''" << endl ;
256 cout << " already exist in TreeR. ROOT does not allow updating/overwriting." << endl ;
257 cout << " Specify another title for branches or use ''StartFrom()'' method" << endl ;
258
259 //mark all tasks as inactive
260 TIter next(fTasks);
261 TTask *task;
262 while((task=(TTask*)next()))
263 task->SetActive(kFALSE) ;
264 return ;
265 }
031f0861 266 }
2aad621e 267
7acf6008 268 if(fTSMaker->IsActive() && gAlice->TreeR()){ //Produce TrackSegments
269
270 TBranch * tsMakerBranch = 0;
271 TBranch * tsBranch = 0;
272
273 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
274 Int_t ibranch;
275 Bool_t tsMakerNotFound = kTRUE ;
276 Bool_t tsNotFound = kTRUE ;
277
278 for(ibranch = 0;(ibranch <branches->GetEntries())&&(tsMakerNotFound||tsNotFound);ibranch++){
279 if(tsMakerNotFound){
280 tsMakerBranch=(TBranch *) branches->At(ibranch) ;
281 if( fTSBranch.CompareTo(tsMakerBranch->GetTitle())==0 )
282 if( strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0)
283 tsMakerNotFound = kFALSE ;
284 }
285 if(tsNotFound){
286 tsBranch=(TBranch *) branches->At(ibranch) ;
287 if( fTSBranch.CompareTo(tsBranch->GetTitle())==0 )
288 if( strcmp(tsBranch->GetName(),"PHOSTS") == 0)
289 tsNotFound = kFALSE ;
290 }
51926850 291 }
7acf6008 292
293 if(!(tsMakerNotFound &&tsNotFound) ){
294 cout << "AliPHOSReconstructioner error: "<< endl ;
295 cout << " Branches ''PHOSTS'' or ''AliPHOSTrackSegmentMaker'' with title ``"
296 << fTSBranch.Data() << "''" << endl ;
297 cout << " already exist in TreeR. ROOT does not allow updating/overwriting." << endl ;
298 cout << " Specify another title for branches or use ''StartFrom()'' method" << endl ;
299
300 //mark all tasks as inactive
301 TIter next(fTasks);
302 TTask *task;
303 while((task=(TTask*)next()))
304 task->SetActive(kFALSE) ;
305 return ;
2aad621e 306
51926850 307 }
7acf6008 308
83974468 309 }
7acf6008 310
311 if(fPID->IsActive() && gAlice->TreeR()){ //Produce RecParticles
312 TBranch * pidBranch = 0;
313 TBranch * rpBranch = 0;
2aad621e 314
7acf6008 315 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
316 Int_t ibranch;
317 Bool_t pidNotFound = kTRUE ;
318 Bool_t rpNotFound = kTRUE ;
319
320 for(ibranch = 0;(ibranch <branches->GetEntries()) && pidNotFound && rpNotFound ;ibranch++){
321 if(pidNotFound){
322 pidBranch=(TBranch *) branches->At(ibranch) ;
323 if( (strcmp(fRecPartBranch,pidBranch->GetTitle())==0 ) &&
324 (strcmp(pidBranch->GetName(),"AliPHOSPID") == 0) )
325 pidNotFound = kFALSE ;
326 }
327 if(rpNotFound){
328 rpBranch=(TBranch *) branches->At(ibranch) ;
329 if( (strcmp(fRecPartBranch,rpBranch->GetTitle())==0 ) &&
330 (strcmp(rpBranch->GetName(),"PHOSRP") == 0) )
331 rpNotFound = kFALSE ;
332 }
333 }
334
335 if(!pidNotFound || !rpNotFound ){
336 cout << "AliPHOSReconstructioner error: "<< endl ;
337 cout << " Branches ''PHOSRP'' or ''AliPHOSPID'' with title ``"
338 << fRecPartBranch.Data() << "''" << endl ;
339 cout << " already exist in TreeR. ROOT does not allow updating/overwriting." << endl ;
340 cout << " Specify another title for branches." << endl ;
341
342 //mark all tasks as inactive
343 TIter next(fTasks);
344 TTask *task;
345 while((task=(TTask*)next()))
346 task->SetActive(kFALSE) ;
347 return ;
2aad621e 348 }
349
031f0861 350 }
7acf6008 351}
352//____________________________________________________________________________
353 void AliPHOSReconstructioner::Init()
354{
355 //initiase Reconstructioner if necessary: we can not do this in default constructor
356
357 if(!fIsInitialized){
358 // Initialisation
359
360 fSDigitsBranch="" ;
361 fSDigitizer = new AliPHOSSDigitizer(fHeaderFileName.Data(),fSDigitsBranch.Data()) ;
362 Add(fSDigitizer) ;
363
364 fDigitsBranch="" ;
365 fDigitizer = new AliPHOSDigitizer(fHeaderFileName.Data(),fDigitsBranch.Data()) ;
366 Add(fDigitizer) ;
367
368 fRecPointBranch="" ;
369 fClusterizer = new AliPHOSClusterizerv1(fHeaderFileName.Data(),fRecPointBranch.Data()) ;
370 Add(fClusterizer) ;
371
372 fTSBranch="" ;
373 fTSMaker = new AliPHOSTrackSegmentMakerv1(fHeaderFileName.Data(),fTSBranch.Data()) ;
374 Add(fTSMaker) ;
375
376
377 fRecPartBranch="" ;
378 fPID = new AliPHOSPIDv1(fHeaderFileName.Data(),fRecPartBranch.Data()) ;
379 Add(fPID) ;
380
381 fIsInitialized = kTRUE ;
382 }
383}
384//____________________________________________________________________________
385AliPHOSReconstructioner::~AliPHOSReconstructioner()
386{
fad3e5b9 387
7acf6008 388 if(fSDigitizer)
389 delete fSDigitizer ;
83974468 390
7acf6008 391 if(fDigitizer)
392 delete fDigitizer ;
393
394 if(fClusterizer)
395 delete fClusterizer ;
396
397 if(fTSMaker)
398 delete fTSMaker ;
399
400 if(fPID)
401 delete fPID ;
402}
403//____________________________________________________________________________
404void AliPHOSReconstructioner::SetBranchTitle(const char* branch, const char * title){
405 //Diverge correcpoinding branch to the file "title"
406
407 if(strcmp(branch,"SDigits") == 0){
408 fSDigitizer->SetSDigitsBranch(title) ;
409 fDigitizer->SetSDigitsBranch(title) ;
410 fSDigitsBranch = title ;
411 return ;
2aad621e 412 }
7acf6008 413
414 if(strcmp(branch,"Digits") == 0){
415 fDigitizer->SetDigitsBranch(title) ;
416 fClusterizer->SetDigitsBranch(title) ;
417 fDigitsBranch = title ;
418 return ;
419 }
420
421 if(strcmp(branch,"RecPoints") == 0){
422 fClusterizer->SetRecPointsBranch(title) ;
423 fTSMaker->SetRecPointsBranch(title) ;
424 fRecPointBranch = title ;
425 return ;
426 }
427
428 if(strcmp(branch,"TrackSegments") == 0){
429 fTSMaker->SetTrackSegmentsBranch(title) ;
430 fPID->SetTrackSegmentsBranch(title) ;
431 fTSBranch = title ;
432 return ;
433 }
434
435 if(strcmp(branch,"RecParticles") == 0){
436 fPID->SetRecParticlesBranch(title) ;
437 fRecPartBranch = title ;
438 return ;
439 }
440
441 cout << "There is no branch " << branch << "!"<< endl ;
442 cout << "Available branches `SDigits', `Digits', `RecPoints', `TrackSegments' and `RecParticles' " << endl ;
443
444}
445//____________________________________________________________________________
9a6ec61a 446void AliPHOSReconstructioner::StartFrom(char * module,char* title){
447 // in the next pass of reconstruction (call ExecuteTask()) reconstruction will
448 // start from the module "module", and in the case of nonsero title all
449 // pruduced branches will have title "title". Recognize the following "modules"
450 // "SD" - AliPHOSSDigitizer,
451 // "D" - AliPHOSDigitizer
452 // "C" - AliPHOSClusterizer
453 // "TS" - AliPHOSTrackSegmentMaker
454 // "RP" - AliPHOSPID
7acf6008 455
456 if(!fIsInitialized)
9a6ec61a 457 Init() ;
458
459 char * moduleName = new char[30];
460 if(strstr(module,"SD"))
461 sprintf(moduleName,"AliPHOSSDigitizer") ;
462 else
463 if(strstr(module,"D") )
464 sprintf(moduleName,"AliPHOSDigitizer") ;
465 else
466 if(strstr(module,"C") || strstr(module,"RecPoint") )
467 sprintf(moduleName,"AliPHOSClusterizer") ;
468 else
469 if(strstr(module,"TS") || strstr(module,"Track") )
470 sprintf(moduleName,"AliPHOSTrackSegmentMaker") ;
471 else
472 if(strstr(module,"PID") || strstr(module,"Particle") || strstr(module,"RP") )
473 sprintf(moduleName,"AliPHOSPID") ;
474 else{
475 cout << "Do not know such a module / Rec Object " << endl;
476 return ;
477 }
478
7acf6008 479 TIter next(fTasks);
480 TTask *task;
481 Bool_t active = kFALSE ;
482 while((task=(TTask*)next())){
9a6ec61a 483 if (strcmp(moduleName,task->GetName())==0)
7acf6008 484 active = kTRUE;
485 task->SetActive(active) ;
9a6ec61a 486 if(active && title){ // set title to branches
487 switch(strlen(task->GetName()) ) {
488 case 17: // "AliPHOSSDigitizer"
489 fSDigitizer->SetSDigitsBranch(title) ;
490 fDigitizer->SetSDigitsBranch(title) ;
491 fSDigitsBranch = title ;
492 break ;
493 case 16: //"AliPHOSDigitizer"
494 fDigitizer->SetDigitsBranch(title) ;
495 fClusterizer->SetDigitsBranch(title) ;
496 fDigitsBranch = title ;
497 break ;
498 case 18: //"AliPHOSClusterizer"
499 fClusterizer->SetRecPointsBranch(title) ;
500 fTSMaker->SetRecPointsBranch(title) ;
501 fRecPointBranch = title ;
502 break ;
503 case 24: //"AliPHOSTrackSegmentMaker"
504 fTSMaker->SetTrackSegmentsBranch(title) ;
505 fPID->SetTrackSegmentsBranch(title) ;
506 fTSBranch = title ;
507 break ;
508 case 10: // "AliPHOSPID"
509 fPID->SetRecParticlesBranch(title) ;
510 fRecPartBranch = title ;
511 break ;
512 }
513
514 }
7acf6008 515 }
9a6ec61a 516
517 delete moduleName;
7acf6008 518}
7acf6008 519//____________________________________________________________________________
520void AliPHOSReconstructioner::Print(Option_t * option)const {
521
522 cout << "-----------------AliPHOSReconstructioner---------------" << endl ;
523 cout << " Reconstruction of the header file " <<fHeaderFileName.Data() << endl ;
524 cout << " with the following modules: " << endl ;
525
526 if(fSDigitizer->IsActive()){
527 cout << " (+) " << fSDigitizer->GetName() << " to branch : " << fSDigitsBranch.Data() << endl ;
528 cout << endl ;
529 }
530 if(fDigitizer->IsActive()){
531 cout << " (+) " << fDigitizer->GetName() << " to branch : " << fDigitsBranch.Data() << endl ;
532 cout << endl ;
533 }
534
535 if(fClusterizer->IsActive()){
536 cout << " (+) " <<fClusterizer->GetName() << " to branch : " <<fRecPointBranch.Data() << endl ;
537 cout << endl ;
538 }
539
540 if(fTSMaker->IsActive()){
541 cout << " (+) " << fTSMaker->GetName() << " to branch : " << fTSBranch.Data() << endl ;
542 cout << endl ;
543 }
544
545
546 if(fPID->IsActive()){
547 cout << " (+) " << fPID->GetName() << " to branch : " <<fRecPartBranch.Data() << endl ;
548 cout << endl ;
549 }
550
2aad621e 551
51926850 552}