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