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