]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSTrackSegmentMakerv1.cxx
Coding rule violations corrected.
[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
fbf811ec 22// CPV/PPSD RecPoints in the radious fRcpv.
a4e98857 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.
21cd0c07 31//// In principle this class should be called from AliPHOSReconstructioner, but
a4e98857 32// one can use it as well in standalone mode.
33// Use case:
fc12304f 34// root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
a4e98857 35// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
fc12304f 36// // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
37// // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")
a4e98857 38// root [1] t->ExecuteTask()
39// root [2] t->SetMaxEmcPpsdDistance(5)
40// root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
41// root [4] t->ExecuteTask("deb all time")
f035f6ce 42//
fc12304f 43//*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
b2a60966 44//
d15a28e7 45
46// --- ROOT system ---
2731cd1e 47#include "TROOT.h"
48#include "TFile.h"
88cb7938 49#include "TFolder.h"
2731cd1e 50#include "TTree.h"
88cb7938 51#include "TSystem.h"
2731cd1e 52#include "TBenchmark.h"
d15a28e7 53
21cd0c07 54// --- Standard library ---
d15a28e7 55
56// --- AliRoot header files ---
57
58#include "AliPHOSTrackSegmentMakerv1.h"
88cb7938 59#include "AliPHOSClusterizerv1.h"
d15a28e7 60#include "AliPHOSTrackSegment.h"
88cb7938 61#include "AliPHOSCpvRecPoint.h"
d15a28e7 62#include "AliPHOSLink.h"
7b7c1533 63#include "AliPHOSGetter.h"
88cb7938 64#include "AliPHOS.h"
d15a28e7 65
66ClassImp( AliPHOSTrackSegmentMakerv1)
67
68
69//____________________________________________________________________________
2bd5457f 70 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
d15a28e7 71{
7b7c1533 72 // default ctor (to be used mainly by Streamer)
73
8d0f3f77 74 InitParameters() ;
92f521a9 75 fDefaultInit = kTRUE ;
d15a28e7 76}
7b7c1533 77
9f616d61 78//____________________________________________________________________________
88cb7938 79 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const TString alirunFileName, const TString eventFolderName)
80 :AliPHOSTrackSegmentMaker(alirunFileName, eventFolderName)
2731cd1e 81{
82 // ctor
2731cd1e 83
8d0f3f77 84 InitParameters() ;
7b7c1533 85 Init() ;
92f521a9 86 fDefaultInit = kFALSE ;
2731cd1e 87}
98cbd830 88
2731cd1e 89//____________________________________________________________________________
90 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
91{
92 // dtor
92f521a9 93 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
88cb7938 94 if (!fDefaultInit)
95 delete fLinkUpArray ;
d15a28e7 96}
9f616d61 97
8d0f3f77 98
fc12304f 99//____________________________________________________________________________
100const TString AliPHOSTrackSegmentMakerv1::BranchName() const
101{
88cb7938 102
103 return GetName() ;
fc12304f 104}
105
d15a28e7 106//____________________________________________________________________________
2731cd1e 107void AliPHOSTrackSegmentMakerv1::FillOneModule()
9f616d61 108{
f035f6ce 109 // Finds first and last indexes between which
110 // clusters from one PHOS module are
88cb7938 111
112 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
fc12304f 113
fbf811ec 114 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
115 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
9688c1dd 116
2731cd1e 117 //First EMC clusters
7b7c1533 118 Int_t totalEmc = emcRecPoints->GetEntriesFast() ;
2731cd1e 119 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
29b077b5 120 ((dynamic_cast<AliPHOSRecPoint *>(emcRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
2731cd1e 121 fEmcLast ++) ;
122
2731cd1e 123 //Now CPV clusters
7b7c1533 124 Int_t totalCpv = cpvRecPoints->GetEntriesFast() ;
6ad0bfa0 125
2731cd1e 126 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
88cb7938 127 ((dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
128 fCpvLast ++) ;
9688c1dd 129
d15a28e7 130}
7b7c1533 131
d15a28e7 132//____________________________________________________________________________
baef0810 133Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSRecPoint * cpvClu, Bool_t &toofar)const
d15a28e7 134{
b2a60966 135 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
a4e98857 136 // Clusters are sorted in "rows" and "columns" of width 1 cm
f035f6ce 137
2731cd1e 138 Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
139 // if you change this value, change it as well in xxxRecPoint::Compare()
fbf811ec 140 Float_t r = fRcpv ;
d15a28e7 141
142 TVector3 vecEmc ;
2731cd1e 143 TVector3 vecCpv ;
144
145 emcClu->GetLocalPosition(vecEmc) ;
146 cpvClu->GetLocalPosition(vecCpv) ;
147
148 if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){
fbf811ec 149 if(vecCpv.X() <= vecEmc.X() + fRcpv + 2*delta ){
2731cd1e 150
151 vecCpv = vecCpv - vecEmc ;
152 r = vecCpv.Mag() ;
92862013 153 toofar = kFALSE ;
2731cd1e 154
155 } // if xPpsd >= xEmc + ...
156 else
157 toofar = kTRUE ;
d15a28e7 158 }
159 else
92862013 160 toofar = kTRUE ;
7956ec10 161
162 //toofar = kFALSE ;
163
d15a28e7 164
92862013 165 return r ;
d15a28e7 166}
167
7b7c1533 168//____________________________________________________________________________
169void AliPHOSTrackSegmentMakerv1::Init()
170{
171 // Make all memory allocations that are not possible in default constructor
172
88cb7938 173 AliPHOSGetter* gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
fbf811ec 174
7b7c1533 175 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
88cb7938 176 if ( !gime->TrackSegmentMaker() ) {
177 gime->PostTrackSegmentMaker(this);
178 }
7b7c1533 179}
180
8d0f3f77 181//____________________________________________________________________________
182void AliPHOSTrackSegmentMakerv1::InitParameters()
183{
fbf811ec 184 fRcpv = 10. ;
8d0f3f77 185 fEmcFirst = 0 ;
186 fEmcLast = 0 ;
187 fCpvFirst = 0 ;
188 fCpvLast = 0 ;
189 fLinkUpArray = 0 ;
88cb7938 190 fTrackSegmentsInRun = 0 ;
8d0f3f77 191}
192
193
d15a28e7 194//____________________________________________________________________________
baef0810 195void AliPHOSTrackSegmentMakerv1::MakeLinks()const
d15a28e7 196{
f035f6ce 197 // Finds distances (links) between all EMC and PPSD clusters,
fbf811ec 198 // which are not further apart from each other than fRcpv
f035f6ce 199 // and sort them in accordance with this distance
9688c1dd 200
88cb7938 201 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
fbf811ec 202 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
203 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
7b7c1533 204
2731cd1e 205 fLinkUpArray->Clear() ;
2731cd1e 206
2731cd1e 207 AliPHOSRecPoint * cpv ;
92862013 208 AliPHOSEmcRecPoint * emcclu ;
28c3a259 209
d15a28e7 210 Int_t iLinkUp = 0 ;
211
28c3a259 212 Int_t iEmcRP;
2731cd1e 213 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
29b077b5 214 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
2731cd1e 215
9688c1dd 216 Bool_t toofar ;
2731cd1e 217 Int_t iCpv = 0 ;
218 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
28c3a259 219
29b077b5 220 cpv = dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(iCpv)) ;
2731cd1e 221 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, toofar) ;
d15a28e7 222
92862013 223 if(toofar)
88cb7938 224 break ;
fbf811ec 225 if(r < fRcpv) {
88cb7938 226 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv) ;
28c3a259 227 }
d15a28e7 228 }
28c3a259 229 }
d15a28e7 230
9688c1dd 231 fLinkUpArray->Sort() ; //first links with smallest distances
d15a28e7 232}
28c3a259 233
d15a28e7 234//____________________________________________________________________________
2731cd1e 235void AliPHOSTrackSegmentMakerv1::MakePairs()
6ad0bfa0 236{
f035f6ce 237 // Using the previously made list of "links", we found the smallest link - i.e.
a4e98857 238 // link with the least distance between EMC and CPV and pointing to still
f035f6ce 239 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
240 // remove them from the list of "unassigned".
88cb7938 241
242 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
243
fbf811ec 244 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
245 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
88cb7938 246 TClonesArray * trackSegments = gime->TrackSegments();
9688c1dd 247
01a599c9 248 //Make arrays to mark clusters already chosen
2731cd1e 249 Int_t * emcExist = 0;
250 if(fEmcLast > fEmcFirst)
251 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
252
253 Int_t index;
254 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
255 emcExist[index] = 1 ;
256
257 Bool_t * cpvExist = 0;
258 if(fCpvLast > fCpvFirst)
259 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
260 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
261 cpvExist[index] = kTRUE ;
262
2731cd1e 263
264 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
2731cd1e 265 TIter nextUp(fLinkUpArray) ;
d15a28e7 266
d15a28e7 267 AliPHOSLink * linkUp ;
9688c1dd 268
2731cd1e 269 AliPHOSRecPoint * nullpointer = 0 ;
9688c1dd 270
29b077b5 271 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
9688c1dd 272
2731cd1e 273 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){ //without ppsd Up yet
d15a28e7 274
2731cd1e 275 if(cpvExist[linkUp->GetPpsd()-fCpvFirst]){ //CPV still exist
88cb7938 276
277 new ((* trackSegments)[fNTrackSegments])
278 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) ,
279 dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(linkUp->GetPpsd()))) ;
280 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
281 fNTrackSegments++ ;
282
283 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
284 //mark CPV recpoint as already used
285 cpvExist[linkUp->GetPpsd()-fCpvFirst] = kFALSE ;
7956ec10 286 } //if ppsdUp still exist
28c3a259 287 }
88cb7938 288 }
28c3a259 289
2731cd1e 290 //look through emc recPoints left without CPV/PPSD
291 if(emcExist){ //if there is emc rec point
292 Int_t iEmcRP ;
293 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
294 if(emcExist[iEmcRP] > 0 ){
88cb7938 295 new ((*trackSegments)[fNTrackSegments])
296 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)),
297 nullpointer) ;
298 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
299 fNTrackSegments++;
2731cd1e 300 }
d15a28e7 301 }
d15a28e7 302 }
780a31c1 303 delete [] emcExist ;
304 delete [] cpvExist ;
d15a28e7 305}
306
307//____________________________________________________________________________
2731cd1e 308void AliPHOSTrackSegmentMakerv1::Exec(Option_t * option)
d15a28e7 309{
a4e98857 310 // STEERing method
88cb7938 311
2731cd1e 312 if(strstr(option,"tim"))
b3f97575 313 gBenchmark->Start("PHOSTSMaker");
7b7c1533 314
315 if(strstr(option,"print")) {
88cb7938 316 Print() ;
7b7c1533 317 return ;
318 }
88cb7938 319
320 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
321
55ea5766 322 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
7b7c1533 323
88cb7938 324 Int_t nevents = gime->MaxEvent() ;
325 Int_t ievent ;
01a599c9 326
88cb7938 327 for(ievent = 0; ievent < nevents; ievent++) {
55ea5766 328 gime->Event(ievent,"R") ;
55ea5766 329 //Make some initializations
330 fNTrackSegments = 0 ;
331 fEmcFirst = 0 ;
332 fEmcLast = 0 ;
333 fCpvFirst = 0 ;
334 fCpvLast = 0 ;
88cb7938 335
336 gime->TrackSegments()->Clear();
55ea5766 337
9688c1dd 338 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
339
88cb7938 340 for(fModule = 1; fModule <= geom->GetNModules() ; fModule++ ) {
2731cd1e 341 FillOneModule() ;
2731cd1e 342 MakeLinks() ;
2731cd1e 343 MakePairs() ;
2731cd1e 344 }
28c3a259 345
90cceaf6 346 WriteTrackSegments() ;
7b7c1533 347
2731cd1e 348 if(strstr(option,"deb"))
88cb7938 349 PrintTrackSegments(option);
94de8339 350
351 //increment the total number of track segments per run
88cb7938 352 fTrackSegmentsInRun += gime->TrackSegments()->GetEntriesFast() ;
7b7c1533 353
2731cd1e 354 }
88cb7938 355
2731cd1e 356 if(strstr(option,"tim")){
357 gBenchmark->Stop("PHOSTSMaker");
21cd0c07 358 Info("Exec", "took %f seconds for making TS %f seconds per event",
88cb7938 359 gBenchmark->GetCpuTime("PHOSTSMaker"),
360 gBenchmark->GetCpuTime("PHOSTSMaker")/nevents) ;
361 }
362 Unload();
363}
364
365//____________________________________________________________________________
366void AliPHOSTrackSegmentMakerv1::Unload()
367{
368 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
369 gime->PhosLoader()->UnloadRecPoints() ;
370 gime->PhosLoader()->UnloadTracks() ;
d15a28e7 371}
7b7c1533 372
d15a28e7 373//____________________________________________________________________________
88cb7938 374void AliPHOSTrackSegmentMakerv1::Print()const
a4e98857 375{
baef0810 376 // Print TrackSegmentMaker parameters
377
21cd0c07 378 TString message("") ;
7b7c1533 379 if( strcmp(GetName(), "") != 0 ) {
21cd0c07 380 message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ;
381 message += "Making Track segments\n" ;
382 message += "with parameters:\n" ;
383 message += " Maximal EMC - CPV (PPSD) distance (cm) %f\n" ;
384 message += "============================================\n" ;
385 Info("Print", message.Data(),fRcpv) ;
2731cd1e 386 }
387 else
21cd0c07 388 Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
d15a28e7 389}
7b7c1533 390
d15a28e7 391//____________________________________________________________________________
90cceaf6 392void AliPHOSTrackSegmentMakerv1::WriteTrackSegments()
a4e98857 393{
f035f6ce 394 // Writes found TrackSegments to TreeR. Creates branches
395 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
396 // In the former branch found TrackSegments are stored, while
397 // in the latter all parameters, with which TS were made.
398 // ROOT does not allow overwriting existing branches, therefore
a4e98857 399 // first we check, if branches with the same title already exist.
f035f6ce 400 // If yes - exits without writing.
88cb7938 401
402 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
55ea5766 403
fbf811ec 404 TClonesArray * trackSegments = gime->TrackSegments() ;
55ea5766 405 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
8d0f3f77 406
88cb7938 407 TTree * treeT = gime->TreeT();
408
409 //First TS
410 Int_t bufferSize = 32000 ;
411 TBranch * tsBranch = treeT->Branch("PHOSTS",&trackSegments,bufferSize);
761e34c0 412 tsBranch->Fill() ;
eec3ac52 413
88cb7938 414 gime->WriteTracks("OVERWRITE");
415 gime->WriteTrackSegmentMaker("OVERWRITE");
2731cd1e 416}
98cbd830 417
98cbd830 418
2731cd1e 419//____________________________________________________________________________
a4e98857 420void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
421{
f035f6ce 422 // option deb - prints # of found TrackSegments
423 // option deb all - prints as well indexed of found RecParticles assigned to the TS
9688c1dd 424
88cb7938 425 TClonesArray * trackSegments = AliPHOSGetter::Instance()->TrackSegments() ;
21cd0c07 426
88cb7938 427 Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ;
428 printf("nevent: %d\n", gAlice->GetEvNumber()) ;
429 printf(" Found %d TrackSegments\n", trackSegments->GetEntriesFast() );
430
2731cd1e 431 if(strstr(option,"all")) { // printing found TS
88cb7938 432 printf("TrackSegment # EMC RP# CPV RP#\n") ;
2731cd1e 433 Int_t index;
7b7c1533 434 for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
435 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ;
88cb7938 436 printf(" %d %d %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ;
2731cd1e 437 }
d15a28e7 438 }
2731cd1e 439}