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