Interference with other detectors removed: read/fill only our branches
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrackSegmentMakerv1.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 **************************************************************************/
b2a60966 15/* $Id$ */
d15a28e7 16//_________________________________________________________________________
b2a60966 17// Implementation version 1 of algorithm class to construct PHOS track segments
f035f6ce 18// Track segment for PHOS is list of
19// EMC RecPoint + (possibly) CPV RecPoint + (possibly) PPSD RecPoint
20// To find TrackSegments we do the following: for each EMC RecPoints we look at
21// CPV/PPSD RecPoints in the radious fR0. If there is such a CPV RecPoint,
22// we make "Link" it is just indexes of EMC and CPV/PPSD RecPoint and distance
23// between them in the PHOS plane. Then we sort "Links" and starting from the
24// least "Link" pointing to the unassined EMC and CPV RecPoints assing them to
25// new TrackSegment. If there is no CPV/PPSD RecPoint we make TrackSegment
26// consisting from EMC along. There is no TrackSegments without EMC RecPoint.
27//
28// In principle this class should be called from AliPHOSReconstructioner, but
29// one can use it as well in standalong mode.
30// User case:
31// root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root")
32// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
33// root [1] t->ExecuteTask()
34// root [2] t->SetMaxEmcPpsdDistance(5)
35// root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
36// root [4] t->ExecuteTask("deb all time")
37//
b2a60966 38//*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH)
39//
d15a28e7 40
41// --- ROOT system ---
2731cd1e 42#include "TROOT.h"
43#include "TFile.h"
44#include "TTree.h"
45#include "TSystem.h"
46#include "TBenchmark.h"
d15a28e7 47// --- Standard library ---
48
de9ec31b 49#include <iostream.h>
2731cd1e 50#include <iomanip.h>
d15a28e7 51
52// --- AliRoot header files ---
53
54#include "AliPHOSTrackSegmentMakerv1.h"
2731cd1e 55#include "AliPHOSClusterizerv1.h"
d15a28e7 56#include "AliPHOSTrackSegment.h"
2aca7d46 57#include "AliPHOSCpvRecPoint.h"
2731cd1e 58#include "AliPHOSPpsdRecPoint.h"
d15a28e7 59#include "AliPHOSLink.h"
60#include "AliPHOSv0.h"
61#include "AliRun.h"
62
63ClassImp( AliPHOSTrackSegmentMakerv1)
64
65
66//____________________________________________________________________________
b2a60966 67 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
d15a28e7 68{
9f616d61 69 // ctor
2731cd1e 70 SetTitle("version 1") ;
71 SetName("AliPHOSTrackSegmentMaker") ;
28c3a259 72 fR0 = 10. ;
2731cd1e 73 fEmcFirst = 0 ;
74 fEmcLast = 0 ;
75 fCpvFirst = 0 ;
76 fCpvLast = 0 ;
77 fPpsdFirst= 0 ;
78 fPpsdLast = 0 ;
79 fLinkLowArray = 0 ;
80 fLinkUpArray = 0 ;
81 fIsInitialized = kFALSE ;
d15a28e7 82}
9f616d61 83//____________________________________________________________________________
f035f6ce 84 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const char* headerFile, const char* branchTitle):
85AliPHOSTrackSegmentMaker()
2731cd1e 86{
87 // ctor
88 SetTitle("version 1") ;
89 SetName("AliPHOSTrackSegmentMaker") ;
90 fR0 = 10. ;
91 fEmcFirst = 0 ;
92 fEmcLast = 0 ;
93 fCpvFirst = 0 ;
94 fCpvLast = 0 ;
95 fPpsdFirst= 0 ;
96 fPpsdLast = 0 ;
97
98 fHeaderFileName = headerFile ;
99 fRecPointsBranchTitle = branchTitle ;
100
101 TFile * file = (TFile*) gROOT->GetFile(fHeaderFileName.Data() ) ;
102
103 if(file == 0){
104 file = new TFile(fHeaderFileName.Data(),"update") ;
105 gAlice = (AliRun *) file->Get("gAlice") ;
106 }
107
108 AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;
109 fGeom = AliPHOSGeometry::GetInstance(phos->GetGeometry()->GetName(),phos->GetGeometry()->GetTitle() );
110
111 fEmcRecPoints = new TObjArray(200) ;
112 fCpvRecPoints = new TObjArray(200) ;
113 fClusterizer = new AliPHOSClusterizerv1() ;
114
115 fTrackSegments = new TClonesArray("AliPHOSTrackSegment",200) ;
116
117 fLinkLowArray = new TClonesArray("AliPHOSLink", 1000);
118 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
119
120 fIsInitialized = kTRUE ;
b2a60966 121
2731cd1e 122}
d15a28e7 123//____________________________________________________________________________
2731cd1e 124void AliPHOSTrackSegmentMakerv1::Init(){
f035f6ce 125 //Make all memory allokations not possible in default constructor
9f616d61 126
2731cd1e 127 if(!fIsInitialized){
128 if(fHeaderFileName.IsNull())
129 fHeaderFileName = "galice.root" ;
130
131
132 TFile * file = (TFile*) gROOT->GetFile(fHeaderFileName.Data() ) ;
133
134 if(file == 0){
135 file = new TFile(fHeaderFileName.Data(),"update") ;
136 gAlice = (AliRun *) file->Get("gAlice") ;
6ad0bfa0 137 }
2731cd1e 138
139 AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;
140 fGeom = AliPHOSGeometry::GetInstance(phos->GetGeometry()->GetName(),phos->GetGeometry()->GetTitle() );
d15a28e7 141
9f616d61 142
2731cd1e 143 fEmcRecPoints = new TObjArray(200) ;
144 fCpvRecPoints = new TObjArray(200) ;
145 fClusterizer = new AliPHOSClusterizerv1() ;
98cbd830 146
2731cd1e 147
148 fTrackSegments = new TClonesArray("AliPHOSTrackSegment",200) ;
98cbd830 149
2731cd1e 150 fLinkLowArray = new TClonesArray("AliPHOSLink", 1000);
151 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
152
153 fIsInitialized = kTRUE ;
d15a28e7 154 }
2731cd1e 155}
98cbd830 156
2731cd1e 157//____________________________________________________________________________
158 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
159{
160 // dtor
161 if(fLinkLowArray) delete fLinkLowArray ;
162 if(fLinkUpArray) delete fLinkUpArray ;
d15a28e7 163}
9f616d61 164
d15a28e7 165//____________________________________________________________________________
2731cd1e 166void AliPHOSTrackSegmentMakerv1::FillOneModule()
9f616d61 167{
f035f6ce 168 // Finds first and last indexes between which
169 // clusters from one PHOS module are
9f616d61 170
2731cd1e 171
172 //First EMC clusters
173 Int_t totalEmc = fEmcRecPoints->GetEntriesFast() ;
174 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
175 (((AliPHOSRecPoint *) fEmcRecPoints->At(fEmcLast))->GetPHOSMod() == fModule );
176 fEmcLast ++) ;
177
6ad0bfa0 178
2731cd1e 179 //Now CPV clusters
180 Int_t totalCpv = fCpvRecPoints->GetEntriesFast() ;
6ad0bfa0 181
2731cd1e 182 if(fModule <= fGeom->GetNCPVModules()){ // in CPV geometry
9f616d61 183
2731cd1e 184 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
185 (((AliPHOSRecPoint *) fCpvRecPoints->At(fCpvLast))->GetPHOSMod() == fModule );
186 fCpvLast ++) ;
31aa6d6c 187
2731cd1e 188 fPpsdFirst = fCpvLast ; //To avoid scanning RecPoints between fPpsdFirst and fPpsdLast
189 fPpsdLast = fCpvLast ; //and to be ready to switch to mixed geometry
d15a28e7 190 }
2731cd1e 191 else{ //in PPSD geometry
192 fCpvLast = fPpsdLast ;
193 //Upper layer first
194 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
195 (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fCpvLast))->GetPHOSMod() == fModule ) &&
196 (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fCpvLast))->GetUp()) ;
197 fCpvLast ++) ;
198
199 fPpsdLast= fCpvLast ;
200 for(fPpsdFirst = fPpsdLast; (fPpsdLast < totalCpv) &&
201 (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fPpsdLast))->GetPHOSMod() == fModule ) &&
202 (!((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fPpsdLast))->GetUp()) ;
203 fPpsdLast ++) ;
d15a28e7 204 }
2731cd1e 205
d15a28e7 206}
207//____________________________________________________________________________
2731cd1e 208Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSRecPoint * cpvClu, Bool_t &toofar)
d15a28e7 209{
b2a60966 210 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
2731cd1e 211 //clusters are sorted in "rows" and "columns" of width 1 cm
f035f6ce 212
2731cd1e 213 Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
214 // if you change this value, change it as well in xxxRecPoint::Compare()
92862013 215 Float_t r = fR0 ;
d15a28e7 216
217 TVector3 vecEmc ;
2731cd1e 218 TVector3 vecCpv ;
219
220 emcClu->GetLocalPosition(vecEmc) ;
221 cpvClu->GetLocalPosition(vecCpv) ;
222
223 if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){
224 if(vecCpv.X() <= vecEmc.X() + fR0 + 2*delta ){
225
226 vecCpv = vecCpv - vecEmc ;
227 r = vecCpv.Mag() ;
92862013 228 toofar = kFALSE ;
2731cd1e 229
230 } // if xPpsd >= xEmc + ...
231 else
232 toofar = kTRUE ;
d15a28e7 233 }
234 else
92862013 235 toofar = kTRUE ;
7956ec10 236
237 //toofar = kFALSE ;
238
d15a28e7 239
92862013 240 return r ;
d15a28e7 241}
242
243//____________________________________________________________________________
2731cd1e 244void AliPHOSTrackSegmentMakerv1::MakeLinks()
d15a28e7 245{
f035f6ce 246 // Finds distances (links) between all EMC and PPSD clusters,
247 // which are not further apart from each other than fR0
248 // and sort them in accordance with this distance
b2a60966 249
2731cd1e 250 fLinkUpArray->Clear() ;
251 fLinkLowArray->Clear() ;
252
253 AliPHOSRecPoint * ppsd ;
254 AliPHOSRecPoint * cpv ;
92862013 255 AliPHOSEmcRecPoint * emcclu ;
28c3a259 256
d15a28e7 257 Int_t iLinkLow = 0 ;
258 Int_t iLinkUp = 0 ;
259
28c3a259 260 Int_t iEmcRP;
2731cd1e 261 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
262 emcclu = (AliPHOSEmcRecPoint *) fEmcRecPoints->At(iEmcRP) ;
263
264 Bool_t toofar ;
265 Int_t iPpsd ;
266 for(iPpsd = fPpsdFirst; iPpsd < fPpsdLast;iPpsd++ ) {
d15a28e7 267
2731cd1e 268 ppsd = (AliPHOSRecPoint *) fCpvRecPoints->At(iPpsd) ;
269 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsd, toofar) ;
270
92862013 271 if(toofar)
d15a28e7 272 break ;
2731cd1e 273 if(r < fR0)
274 new ((*fLinkLowArray)[iLinkLow++]) AliPHOSLink(r, iEmcRP, iPpsd) ;
d15a28e7 275 }
276
2731cd1e 277 Int_t iCpv = 0 ;
278 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
28c3a259 279
2731cd1e 280 cpv = (AliPHOSRecPoint *) fCpvRecPoints->At(iCpv) ;
281 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, toofar) ;
d15a28e7 282
92862013 283 if(toofar)
d15a28e7 284 break ;
83974468 285 if(r < fR0) {
2731cd1e 286 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv) ;
28c3a259 287 }
d15a28e7 288 }
28c3a259 289 }
d15a28e7 290
2731cd1e 291 fLinkLowArray->Sort() ; //first links with smallest distances
292 fLinkUpArray->Sort() ;
d15a28e7 293}
28c3a259 294
d15a28e7 295//____________________________________________________________________________
2731cd1e 296void AliPHOSTrackSegmentMakerv1::MakePairs()
6ad0bfa0 297{
f035f6ce 298 // Using the previously made list of "links", we found the smallest link - i.e.
299 // link with the least distance betwing EMC and CPV and pointing to still
300 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
301 // remove them from the list of "unassigned".
6ad0bfa0 302
2731cd1e 303 //Make arrays to mark clusters already chousen
304 Int_t * emcExist = 0;
305 if(fEmcLast > fEmcFirst)
306 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
307
308 Int_t index;
309 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
310 emcExist[index] = 1 ;
311
312 Bool_t * cpvExist = 0;
313 if(fCpvLast > fCpvFirst)
314 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
315 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
316 cpvExist[index] = kTRUE ;
317
318 Bool_t * ppsdExist = 0;
319 if(fPpsdLast > fPpsdFirst)
320 ppsdExist = new Bool_t[fPpsdLast-fPpsdFirst] ;
321 for(index = 0; index <fPpsdLast-fPpsdFirst; index ++)
322 ppsdExist[index] = kTRUE ;
323
324 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
325 TIter nextLow(fLinkLowArray) ;
326 TIter nextUp(fLinkUpArray) ;
d15a28e7 327
328 AliPHOSLink * linkLow ;
329 AliPHOSLink * linkUp ;
330
d15a28e7 331
2731cd1e 332 AliPHOSRecPoint * nullpointer = 0 ;
9f616d61 333
d15a28e7 334 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
28c3a259 335
144a844a 336 if( (emcExist[linkLow->GetEmc()-fEmcFirst]> 0) &&
337 ppsdExist[linkLow->GetPpsd()-fPpsdFirst] ){ // RecPoints not removed yet
2731cd1e 338 new ((*fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fEmcRecPoints->At(linkLow->GetEmc()),
339 nullpointer,
144a844a 340 (AliPHOSRecPoint *)fCpvRecPoints->At(linkLow->GetPpsd()) ) ;
2731cd1e 341
342 ((AliPHOSTrackSegment* )fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
28c3a259 343 //replace index of emc to negative and shifted index of TS
2731cd1e 344 emcExist[linkLow->GetEmc()-fEmcFirst] = -2 - fNTrackSegments ;
345 //mark ppsd as used
346 ppsdExist[linkLow->GetPpsd()-fPpsdFirst] = kFALSE ;
28c3a259 347 fNTrackSegments++ ;
6ad0bfa0 348 }
d15a28e7 349 }
28c3a259 350
2731cd1e 351
28c3a259 352 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
2731cd1e 353 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){ //without ppsd Up yet
d15a28e7 354
2731cd1e 355 if(cpvExist[linkUp->GetPpsd()-fCpvFirst]){ //CPV still exist
7956ec10 356
2731cd1e 357 if(emcExist[linkUp->GetEmc()-fEmcFirst] > 0){ //without ppsd Low => create new TS
7956ec10 358
2731cd1e 359 new ((* fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fEmcRecPoints->At(linkUp->GetEmc()) ,
144a844a 360 (AliPHOSRecPoint *)fCpvRecPoints->At(linkUp->GetPpsd()),
2731cd1e 361 nullpointer) ;
362 ((AliPHOSTrackSegment *) fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
7956ec10 363 fNTrackSegments++ ;
364 }
365 else{ // append ppsd Up to existing TS
2731cd1e 366 ((AliPHOSTrackSegment *)fTrackSegments->At(-2-emcExist[linkUp->GetEmc()-fEmcFirst]))->SetCpvRecPoint((AliPHOSCpvRecPoint *)fCpvRecPoints->At(linkUp->GetPpsd()));
7956ec10 367 }
368
2731cd1e 369 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
370 //mark CPV recpoint as already used
371 cpvExist[linkUp->GetPpsd()-fCpvFirst] = kFALSE ;
7956ec10 372 } //if ppsdUp still exist
28c3a259 373 }
374 }
375
2731cd1e 376 //look through emc recPoints left without CPV/PPSD
377 if(emcExist){ //if there is emc rec point
378 Int_t iEmcRP ;
379 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
380 if(emcExist[iEmcRP] > 0 ){
381 new ((*fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment((AliPHOSEmcRecPoint *)fEmcRecPoints->At(iEmcRP+fEmcFirst),
382 nullpointer,
383 nullpointer ) ;
384 ((AliPHOSTrackSegment *) fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
385 fNTrackSegments++;
386 }
d15a28e7 387 }
d15a28e7 388 }
28c3a259 389
d15a28e7 390}
391
392//____________________________________________________________________________
2731cd1e 393void AliPHOSTrackSegmentMakerv1::Exec(Option_t * option)
d15a28e7 394{
f035f6ce 395 //STEERing method
28c3a259 396
2731cd1e 397 if(! fIsInitialized) Init() ;
6ad0bfa0 398
2731cd1e 399 if(strstr(option,"tim"))
400 gBenchmark->Start("PHOSTSMaker");
d15a28e7 401
2731cd1e 402 Int_t nEvents = (Int_t) gAlice->TreeE()->GetEntries() ;
403
404 for(fEvent = 0;fEvent< nEvents; fEvent++){
405 if(!ReadRecPoints()) //reads RecPoints for event fEvent
406 return;
98cbd830 407
2731cd1e 408 for(fModule = 1; fModule <= fGeom->GetNModules() ; fModule++ ){
409
410 FillOneModule() ;
411
412 MakeLinks() ;
413
414 MakePairs() ;
415
416 }
28c3a259 417
2731cd1e 418 WriteTrackSegments() ;
419 if(strstr(option,"deb"))
420 PrintTrackSegments(option) ;
421 }
9f616d61 422
2731cd1e 423 if(strstr(option,"tim")){
424 gBenchmark->Stop("PHOSTSMaker");
425 cout << "AliPHOSTSMaker:" << endl ;
426 cout << " took " << gBenchmark->GetCpuTime("PHOSTSMaker") << " seconds for making TS "
427 << gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents << " seconds per event " << endl ;
428 cout << endl ;
429 }
9f616d61 430
9f616d61 431
d15a28e7 432}
d15a28e7 433//____________________________________________________________________________
2731cd1e 434void AliPHOSTrackSegmentMakerv1::Print(Option_t * option)const {
435 if(fIsInitialized){
436 cout << "======== AliPHOSTrackSegmentMakerv1 ========" << endl ;
437 cout << "Making Track segments "<< endl ;
f035f6ce 438 cout << " Headers file: " << fHeaderFileName.Data() << endl ;
439 cout << " RecPoints branch file name: " << fRecPointsBranchTitle.Data() << endl ;
2731cd1e 440 cout << " TrackSegments Branch file name: " << fTSBranchTitle.Data() << endl ;
441 cout << "with parameters: " << endl ;
f035f6ce 442 cout << " Maximal EMC - CPV (PPSD) distance (cm)" << fR0 << endl ;
2731cd1e 443 cout << "============================================" << endl ;
444 }
445 else
446 cout << "AliPHOSTrackSegmentMakerv1 not initialized " << endl ;
d15a28e7 447}
98cbd830 448//____________________________________________________________________________
2731cd1e 449Bool_t AliPHOSTrackSegmentMakerv1::ReadRecPoints(){
f035f6ce 450 // Reads Emc and CPV recPoints with given title (fRecPointsBranchTitle)
451 // made priveously with Clusterizer.
452
2731cd1e 453
454 //Make some initializations
455 fEmcRecPoints->Clear() ;
456 fCpvRecPoints->Clear() ;
457 fTrackSegments->Clear() ;
458 fNTrackSegments = 0 ;
459 fEmcFirst = 0 ;
460 fEmcLast = 0 ;
461 fCpvFirst = 0 ;
462 fCpvLast = 0 ;
463 fPpsdFirst= 0 ;
464 fPpsdLast = 0 ;
465
466
467 gAlice->GetEvent(fEvent) ;
468
469 // Get TreeR header from file
2731cd1e 470 if(gAlice->TreeR()==0){
f035f6ce 471 char treeName[20];
472 sprintf(treeName,"TreeR%d",fEvent);
2731cd1e 473 cout << "Error in AliPHOSTrackSegmentMakerv1 : no "<<treeName << endl ;
474 cout << " Do nothing " << endl ;
475 return kFALSE ;
476 }
98cbd830 477
2731cd1e 478
f035f6ce 479 //Find RecPoints with title fRecPointsBranchTitle
2731cd1e 480 TBranch * emcBranch = 0;
481 TBranch * cpvBranch = 0;
482 TBranch * clusterizerBranch = 0;
483
484 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
485 Int_t ibranch;
486 Bool_t emcNotFound = kTRUE ;
487 Bool_t cpvNotFound = kTRUE ;
488 Bool_t clusterizerNotFound = kTRUE ;
489
490 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
98cbd830 491
2731cd1e 492 if(emcNotFound){
493 emcBranch=(TBranch *) branches->At(ibranch) ;
494 if( fRecPointsBranchTitle.CompareTo(emcBranch->GetTitle())==0 )
f035f6ce 495 if( strcmp(emcBranch->GetName(),"PHOSEmcRP") == 0) {
2731cd1e 496 emcNotFound = kFALSE ;
497 }
2aca7d46 498 }
fad3e5b9 499
2731cd1e 500 if(cpvNotFound){
501 cpvBranch=(TBranch *) branches->At(ibranch) ;
502 if( fRecPointsBranchTitle.CompareTo(cpvBranch->GetTitle())==0 )
f035f6ce 503 if( strcmp(cpvBranch->GetName(),"PHOSCpvRP") == 0)
2731cd1e 504 cpvNotFound = kFALSE ;
505 }
69183710 506
2731cd1e 507 if(clusterizerNotFound){
508 clusterizerBranch = (TBranch *) branches->At(ibranch) ;
509 if( fRecPointsBranchTitle.CompareTo(clusterizerBranch->GetTitle()) == 0)
f035f6ce 510 if( strcmp(clusterizerBranch->GetName(),"AliPHOSClusterizer") == 0)
2731cd1e 511 clusterizerNotFound = kFALSE ;
512 }
fad3e5b9 513
98cbd830 514 }
515
2731cd1e 516 if(clusterizerNotFound || emcNotFound || cpvNotFound){
517 cout << "AliPHOSTrackSegmentMakerv1: " << endl ;
518 cout << " Can't find Branch with RecPoints or Clusterizer " ;
519 cout << " Do nothing" <<endl ;
520 return kFALSE ;
521 }
522
523 emcBranch->SetAddress(&fEmcRecPoints) ;
524 cpvBranch->SetAddress(&fCpvRecPoints) ;
525 clusterizerBranch->SetAddress(&fClusterizer) ;
761e34c0 526
527 emcBranch->GetEntry(0) ;
528 cpvBranch->GetEntry(0) ;
529 clusterizerBranch->GetEntry(0) ;
2731cd1e 530
2731cd1e 531 return kTRUE ;
532
98cbd830 533}
d15a28e7 534//____________________________________________________________________________
2731cd1e 535void AliPHOSTrackSegmentMakerv1::WriteTrackSegments(){
f035f6ce 536 // Writes found TrackSegments to TreeR. Creates branches
537 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
538 // In the former branch found TrackSegments are stored, while
539 // in the latter all parameters, with which TS were made.
540 // ROOT does not allow overwriting existing branches, therefore
541 // first we chesk, if branches with the same title alredy exist.
542 // If yes - exits without writing.
2731cd1e 543
544 //First, check, if branches already exist
545 TBranch * tsMakerBranch = 0;
546 TBranch * tsBranch = 0;
547
548 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
549 Int_t ibranch;
550 Bool_t tsMakerNotFound = kTRUE ;
551 Bool_t tsNotFound = kTRUE ;
552
553 for(ibranch = 0;(ibranch <branches->GetEntries())&&(tsMakerNotFound||tsNotFound);ibranch++){
554 if(tsMakerNotFound){
555 tsMakerBranch=(TBranch *) branches->At(ibranch) ;
556 if( (strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0) &&
557 (fTSBranchTitle.CompareTo( tsMakerBranch->GetTitle())==0 ))
558 tsMakerNotFound = kFALSE ;
559 }
560 if(tsNotFound){
561 tsBranch=(TBranch *) branches->At(ibranch) ;
562 if( (strcmp(tsBranch->GetName(),"PHOSTS") == 0) &&
563 (fTSBranchTitle.CompareTo( tsBranch->GetTitle())==0 ))
564 tsNotFound = kFALSE ;
565 }
566 }
9f616d61 567
2731cd1e 568 if(!(tsMakerNotFound && tsNotFound )){
569 cout << "AliPHOSTrackSegmentMakerv1 error:"<< endl ;
570 cout << " Branches PHOSTS and AliPHOSTrackSegementMaker " << endl ;
571 cout << " with title '"<<fTSBranchTitle.Data() << "' already exist " << endl ;
572 cout << " can not overwrite " << endl ;
d15a28e7 573 return ;
31aa6d6c 574 }
98cbd830 575
2731cd1e 576 //Make branch in TreeR for TrackSegments
577 char * filename = 0;
578 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
579 filename = new char[strlen(gAlice->GetBaseFile())+20] ;
580 sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
d15a28e7 581 }
582
2731cd1e 583 TDirectory *cwd = gDirectory;
31aa6d6c 584
2731cd1e 585 //First TS
586 Int_t bufferSize = 32000 ;
587 tsBranch = gAlice->TreeR()->Branch("PHOSTS",&fTrackSegments,bufferSize);
588 tsBranch->SetTitle(fTSBranchTitle.Data());
589 if (filename) {
590 tsBranch->SetFile(filename);
591 TIter next( tsBranch->GetListOfBranches());
761e34c0 592 TBranch * sb ;
593 while ((sb=(TBranch*)next())) {
594 sb->SetFile(filename);
2731cd1e 595 }
596 cwd->cd();
597 }
98cbd830 598
2731cd1e 599 //Second -TSMaker
600 Int_t splitlevel = 0 ;
601 AliPHOSTrackSegmentMakerv1 * ts = this ;
602 tsMakerBranch = gAlice->TreeR()->Branch("AliPHOSTrackSegmentMaker","AliPHOSTrackSegmentMakerv1",
603 &ts,bufferSize,splitlevel);
604 tsMakerBranch->SetTitle(fTSBranchTitle.Data());
605 if (filename) {
606 tsMakerBranch->SetFile(filename);
607 TIter next( tsMakerBranch->GetListOfBranches());
761e34c0 608 TBranch * sb;
609 while ((sb=(TBranch*)next())) {
610 sb->SetFile(filename);
2731cd1e 611 }
612 cwd->cd();
613 }
9f616d61 614
761e34c0 615 tsBranch->Fill() ;
616 tsMakerBranch->Fill() ;
2731cd1e 617 gAlice->TreeR()->Write(0,kOverwrite) ;
618
619}
98cbd830 620
98cbd830 621
2731cd1e 622//____________________________________________________________________________
623void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option){
f035f6ce 624 // option deb - prints # of found TrackSegments
625 // option deb all - prints as well indexed of found RecParticles assigned to the TS
626
2731cd1e 627
628 cout << "AliPHOSTrackSegmentMakerv1: " << endl ;
629 cout << " Found " << fTrackSegments->GetEntriesFast() << " trackSegments " << endl ;
630
631 if(strstr(option,"all")) { // printing found TS
632 cout << "TrackSegment # " << " EMC RP# " << " CPV RP# " << " PPSD RP#" << endl ;
633
634 Int_t index;
635 for (index = 0 ; index <fTrackSegments->GetEntriesFast() ; index++) {
636 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )fTrackSegments->At(index) ;
637 cout<<" "<< setw(4) << ts->GetIndexInList() << " "
638 <<setw(4) << ts->GetEmcIndex()<< " "
639 <<setw(4) << ts->GetCpvIndex()<< " "
640 <<setw(4) << ts->GetPpsdIndex()<< endl ;
641 }
642
643 cout << "-------------------------------------------------------"<< endl ;
d15a28e7 644 }
2731cd1e 645}