]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSTrackSegmentMakerv1.cxx
Write header with vertex position.
[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 ;
eabde521 185 SetEventRange(0,-1) ;
8d0f3f77 186}
187
188
d15a28e7 189//____________________________________________________________________________
baef0810 190void AliPHOSTrackSegmentMakerv1::MakeLinks()const
d15a28e7 191{
f035f6ce 192 // Finds distances (links) between all EMC and PPSD clusters,
fbf811ec 193 // which are not further apart from each other than fRcpv
f035f6ce 194 // and sort them in accordance with this distance
9688c1dd 195
88cb7938 196 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
fbf811ec 197 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
198 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
7b7c1533 199
2731cd1e 200 fLinkUpArray->Clear() ;
2731cd1e 201
2731cd1e 202 AliPHOSRecPoint * cpv ;
92862013 203 AliPHOSEmcRecPoint * emcclu ;
28c3a259 204
d15a28e7 205 Int_t iLinkUp = 0 ;
206
28c3a259 207 Int_t iEmcRP;
2731cd1e 208 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
29b077b5 209 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
2731cd1e 210
9688c1dd 211 Bool_t toofar ;
2731cd1e 212 Int_t iCpv = 0 ;
213 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
28c3a259 214
29b077b5 215 cpv = dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(iCpv)) ;
2731cd1e 216 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, toofar) ;
d15a28e7 217
92862013 218 if(toofar)
88cb7938 219 break ;
fbf811ec 220 if(r < fRcpv) {
88cb7938 221 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv) ;
28c3a259 222 }
d15a28e7 223 }
28c3a259 224 }
d15a28e7 225
9688c1dd 226 fLinkUpArray->Sort() ; //first links with smallest distances
d15a28e7 227}
28c3a259 228
d15a28e7 229//____________________________________________________________________________
2731cd1e 230void AliPHOSTrackSegmentMakerv1::MakePairs()
6ad0bfa0 231{
f035f6ce 232 // Using the previously made list of "links", we found the smallest link - i.e.
a4e98857 233 // link with the least distance between EMC and CPV and pointing to still
f035f6ce 234 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
235 // remove them from the list of "unassigned".
88cb7938 236
237 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
238
fbf811ec 239 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
240 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
88cb7938 241 TClonesArray * trackSegments = gime->TrackSegments();
9688c1dd 242
01a599c9 243 //Make arrays to mark clusters already chosen
2731cd1e 244 Int_t * emcExist = 0;
245 if(fEmcLast > fEmcFirst)
246 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
247
248 Int_t index;
249 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
250 emcExist[index] = 1 ;
251
252 Bool_t * cpvExist = 0;
253 if(fCpvLast > fCpvFirst)
254 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
255 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
256 cpvExist[index] = kTRUE ;
257
2731cd1e 258
259 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
2731cd1e 260 TIter nextUp(fLinkUpArray) ;
d15a28e7 261
d15a28e7 262 AliPHOSLink * linkUp ;
9688c1dd 263
2731cd1e 264 AliPHOSRecPoint * nullpointer = 0 ;
9688c1dd 265
29b077b5 266 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
9688c1dd 267
2731cd1e 268 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){ //without ppsd Up yet
d15a28e7 269
2731cd1e 270 if(cpvExist[linkUp->GetPpsd()-fCpvFirst]){ //CPV still exist
88cb7938 271
272 new ((* trackSegments)[fNTrackSegments])
273 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) ,
274 dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(linkUp->GetPpsd()))) ;
275 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
276 fNTrackSegments++ ;
277
278 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
279 //mark CPV recpoint as already used
280 cpvExist[linkUp->GetPpsd()-fCpvFirst] = kFALSE ;
7956ec10 281 } //if ppsdUp still exist
28c3a259 282 }
88cb7938 283 }
28c3a259 284
2731cd1e 285 //look through emc recPoints left without CPV/PPSD
286 if(emcExist){ //if there is emc rec point
287 Int_t iEmcRP ;
288 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
289 if(emcExist[iEmcRP] > 0 ){
88cb7938 290 new ((*trackSegments)[fNTrackSegments])
291 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)),
292 nullpointer) ;
293 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
294 fNTrackSegments++;
2731cd1e 295 }
d15a28e7 296 }
d15a28e7 297 }
780a31c1 298 delete [] emcExist ;
299 delete [] cpvExist ;
d15a28e7 300}
301
302//____________________________________________________________________________
eabde521 303void AliPHOSTrackSegmentMakerv1::Exec(Option_t *option)
d15a28e7 304{
eabde521 305 // Steering method to perform track segment construction for events
306 // in the range from fFirstEvent to fLastEvent.
307 // This range is optionally set by SetEventRange().
308 // if fLastEvent=-1 (by default), then process events until the end.
88cb7938 309
2731cd1e 310 if(strstr(option,"tim"))
b3f97575 311 gBenchmark->Start("PHOSTSMaker");
7b7c1533 312
313 if(strstr(option,"print")) {
88cb7938 314 Print() ;
7b7c1533 315 return ;
316 }
88cb7938 317
fb43ada4 318 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
319
55ea5766 320 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
7b7c1533 321
eabde521 322 if (fLastEvent == -1) fLastEvent = gime->MaxEvent() - 1 ;
fb43ada4 323 else fLastEvent = TMath::Min(fFirstEvent,gime->MaxEvent());
eabde521 324 Int_t nEvents = fLastEvent - fFirstEvent + 1;
01a599c9 325
fb43ada4 326 Int_t ievent ;
327 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
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"),
eabde521 360 gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents) ;
88cb7938 361 }
362 Unload();
363}
364
365//____________________________________________________________________________
366void AliPHOSTrackSegmentMakerv1::Unload()
367{
e957fea8 368 // Unloads the task from the folder
88cb7938 369 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
370 gime->PhosLoader()->UnloadRecPoints() ;
371 gime->PhosLoader()->UnloadTracks() ;
d15a28e7 372}
7b7c1533 373
d15a28e7 374//____________________________________________________________________________
88cb7938 375void AliPHOSTrackSegmentMakerv1::Print()const
a4e98857 376{
baef0810 377 // Print TrackSegmentMaker parameters
378
21cd0c07 379 TString message("") ;
7b7c1533 380 if( strcmp(GetName(), "") != 0 ) {
21cd0c07 381 message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ;
382 message += "Making Track segments\n" ;
383 message += "with parameters:\n" ;
384 message += " Maximal EMC - CPV (PPSD) distance (cm) %f\n" ;
385 message += "============================================\n" ;
386 Info("Print", message.Data(),fRcpv) ;
2731cd1e 387 }
388 else
21cd0c07 389 Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
d15a28e7 390}
7b7c1533 391
d15a28e7 392//____________________________________________________________________________
90cceaf6 393void AliPHOSTrackSegmentMakerv1::WriteTrackSegments()
a4e98857 394{
f035f6ce 395 // Writes found TrackSegments to TreeR. Creates branches
396 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
397 // In the former branch found TrackSegments are stored, while
398 // in the latter all parameters, with which TS were made.
399 // ROOT does not allow overwriting existing branches, therefore
a4e98857 400 // first we check, if branches with the same title already exist.
f035f6ce 401 // If yes - exits without writing.
88cb7938 402
403 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
55ea5766 404
fbf811ec 405 TClonesArray * trackSegments = gime->TrackSegments() ;
55ea5766 406 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
8d0f3f77 407
88cb7938 408 TTree * treeT = gime->TreeT();
409
410 //First TS
411 Int_t bufferSize = 32000 ;
412 TBranch * tsBranch = treeT->Branch("PHOSTS",&trackSegments,bufferSize);
761e34c0 413 tsBranch->Fill() ;
eec3ac52 414
88cb7938 415 gime->WriteTracks("OVERWRITE");
416 gime->WriteTrackSegmentMaker("OVERWRITE");
2731cd1e 417}
98cbd830 418
98cbd830 419
2731cd1e 420//____________________________________________________________________________
a4e98857 421void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
422{
f035f6ce 423 // option deb - prints # of found TrackSegments
424 // option deb all - prints as well indexed of found RecParticles assigned to the TS
9688c1dd 425
88cb7938 426 TClonesArray * trackSegments = AliPHOSGetter::Instance()->TrackSegments() ;
21cd0c07 427
88cb7938 428 Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ;
429 printf("nevent: %d\n", gAlice->GetEvNumber()) ;
430 printf(" Found %d TrackSegments\n", trackSegments->GetEntriesFast() );
431
2731cd1e 432 if(strstr(option,"all")) { // printing found TS
88cb7938 433 printf("TrackSegment # EMC RP# CPV RP#\n") ;
2731cd1e 434 Int_t index;
7b7c1533 435 for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
436 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ;
88cb7938 437 printf(" %d %d %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ;
2731cd1e 438 }
d15a28e7 439 }
2731cd1e 440}