Changes reflecting the updated track references
[u/mrichter/AliRoot.git] / ITS / AliITSDetTypeRec.cxx
CommitLineData
3b9df642 1/***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
b17dae48 5 * Conributors are mentioned in the code where appropriate. *
3b9df642 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 **************************************************************************/
15
16/*
17 $Id$
18*/
19
7d62fb64 20////////////////////////////////////////////////////////////////////////
21// This class defines the "Standard" reconstruction for the ITS //
22// detector. //
23// //
24////////////////////////////////////////////////////////////////////////
25#include "TObjArray.h"
26#include "TTree.h"
27
8ba39da9 28#include "AliCDBManager.h"
e8c4cf33 29#include "AliCDBStorage.h"
8ba39da9 30#include "AliCDBEntry.h"
7d62fb64 31#include "AliITSClusterFinder.h"
32#include "AliITSClusterFinderV2.h"
33#include "AliITSClusterFinderV2SPD.h"
34#include "AliITSClusterFinderV2SDD.h"
35#include "AliITSClusterFinderV2SSD.h"
36#include "AliITSClusterFinderSPD.h"
37#include "AliITSClusterFinderSDD.h"
38#include "AliITSClusterFinderSSD.h"
3b9df642 39#include "AliITSDetTypeRec.h"
7d62fb64 40#include "AliITSRawCluster.h"
41#include "AliITSRawClusterSPD.h"
42#include "AliITSRawClusterSDD.h"
43#include "AliITSRawClusterSSD.h"
44#include "AliITSRecPoint.h"
fcf95fc7 45#include "AliITSCalibrationSDD.h"
7d62fb64 46#include "AliITSsegmentationSPD.h"
47#include "AliITSsegmentationSDD.h"
48#include "AliITSsegmentationSSD.h"
00a7cc50 49#include "AliLog.h"
7d62fb64 50
3b9df642 51
7d62fb64 52const Int_t AliITSDetTypeRec::fgkNdettypes = 3;
8ba39da9 53const Int_t AliITSDetTypeRec::fgkDefaultNModulesSPD = 240;
54const Int_t AliITSDetTypeRec::fgkDefaultNModulesSDD = 260;
55const Int_t AliITSDetTypeRec::fgkDefaultNModulesSSD = 1698;
56
3b9df642 57ClassImp(AliITSDetTypeRec)
58
7d62fb64 59//________________________________________________________________
e56160b8 60AliITSDetTypeRec::AliITSDetTypeRec(): TObject(),
61fNMod(0),
62fReconstruction(0),
63fSegmentation(0),
64fCalibration(0),
65fPreProcess(0),
66fPostProcess(0),
67fDigits(0),
68fNdtype(0),
69fCtype(0),
70fNctype(0),
71fRecPoints(0),
72fNRecPoints(0),
73fSelectedVertexer(),
74fLoader(0),
75fRunNumber(0),
76fFirstcall(kTRUE){
3b9df642 77 // Default Constructor
78 // Inputs:
79 // none.
80 // Outputs:
81 // none.
82 // Return:
83 // A properly zero-ed AliITSDetTypeRec class.
e56160b8 84
8e50d897 85 for(Int_t i=0; i<3; i++){
86 fClusterClassName[i]=0;
87 fDigClassName[i]=0;
88 fRecPointClassName[i]=0;
89 }
e56160b8 90
8e50d897 91 SelectVertexer(" ");
e56160b8 92
8e50d897 93
94}
95//________________________________________________________________
e56160b8 96AliITSDetTypeRec::AliITSDetTypeRec(AliITSLoader *loader): TObject(),
97fNMod(0),
98fReconstruction(0),
99fSegmentation(0),
100fCalibration(0),
101fPreProcess(0),
102fPostProcess(0),
103fDigits(0),
104fNdtype(0),
105fCtype(0),
106fNctype(0),
107fRecPoints(0),
108fNRecPoints(0),
109fSelectedVertexer(),
110fLoader(loader),
111fRunNumber(0),
112fFirstcall(kTRUE){
8e50d897 113 // Standard Constructor
114 // Inputs:
115 // none.
116 // Outputs:
117 // none.
118 // Return:
119 //
7d62fb64 120
7d62fb64 121 fReconstruction = new TObjArray(fgkNdettypes);
7d62fb64 122 fDigits = new TObjArray(fgkNdettypes);
8e50d897 123 for(Int_t i=0; i<3; i++){
124 fClusterClassName[i]=0;
125 fDigClassName[i]=0;
126 fRecPointClassName[i]=0;
127 }
7d62fb64 128 fNdtype = new Int_t[fgkNdettypes];
129 fCtype = new TObjArray(fgkNdettypes);
130 fNctype = new Int_t[fgkNdettypes];
8e50d897 131 fNMod = new Int_t [fgkNdettypes];
132 fNMod[0] = fgkDefaultNModulesSPD;
133 fNMod[1] = fgkDefaultNModulesSDD;
134 fNMod[2] = fgkDefaultNModulesSSD;
00a7cc50 135 fRecPoints = new TClonesArray("AliITSRecPoint",3000);
7d62fb64 136 fNRecPoints = 0;
7d62fb64 137
138 for(Int_t i=0;i<fgkNdettypes;i++){
139 fNdtype[i]=0;
140 fNctype[i]=0;
141 }
142
e56160b8 143 SelectVertexer(" ");
8ba39da9 144 SetRunNumber();
7d62fb64 145}
7537d03c 146
7d62fb64 147//______________________________________________________________________
7537d03c 148AliITSDetTypeRec::AliITSDetTypeRec(const AliITSDetTypeRec & rec):TObject(rec),
149fNMod(rec.fNMod),
150fReconstruction(rec.fReconstruction),
151fSegmentation(rec.fSegmentation),
152fCalibration(rec.fCalibration),
153fPreProcess(rec.fPreProcess),
154fPostProcess(rec.fPostProcess),
155fDigits(rec.fDigits),
156fNdtype(rec.fNdtype),
157fCtype(rec.fCtype),
158fNctype(rec.fNctype),
159fRecPoints(rec.fRecPoints),
160fNRecPoints(rec.fNRecPoints),
161fSelectedVertexer(rec.fSelectedVertexer),
162fLoader(rec.fLoader),
163fRunNumber(rec.fRunNumber),
164fFirstcall(rec.fFirstcall)
e56160b8 165{
7d62fb64 166
e56160b8 167 // Copy constructor.
7537d03c 168
7d62fb64 169}
170//______________________________________________________________________
e56160b8 171AliITSDetTypeRec& AliITSDetTypeRec::operator=(const AliITSDetTypeRec& source){
7537d03c 172 // Assignment operator.
173 this->~AliITSDetTypeRec();
174 new(this) AliITSDetTypeRec(source);
175 return *this;
7d62fb64 176
e56160b8 177}
7537d03c 178
7d62fb64 179//_____________________________________________________________________
3b9df642 180AliITSDetTypeRec::~AliITSDetTypeRec(){
7d62fb64 181 //Destructor
fcf95fc7 182
183 if(fReconstruction){
184 fReconstruction->Delete();
185 delete fReconstruction;
186 fReconstruction = 0;
187 }
188 if(fSegmentation){
189 fSegmentation->Delete();
190 delete fSegmentation;
191 fSegmentation = 0;
192 }
b17dae48 193 if(fCalibration && fRunNumber<0){
8e50d897 194 AliITSresponse* rspd = ((AliITSCalibration*)fCalibration->At(GetITSgeom()->GetStartSPD()))->GetResponse();
195 AliITSresponse* rsdd = ((AliITSCalibration*)fCalibration->At(GetITSgeom()->GetStartSDD()))->GetResponse();
196 AliITSresponse* rssd = ((AliITSCalibration*)fCalibration->At(GetITSgeom()->GetStartSSD()))->GetResponse();
fcf95fc7 197 if(rspd) delete rspd;
198 if(rsdd) delete rsdd;
199 if(rssd) delete rssd;
200 fCalibration->Delete();
201 delete fCalibration;
202 fCalibration = 0;
203 }
7d62fb64 204 if(fPreProcess) delete fPreProcess;
205 if(fPostProcess) delete fPostProcess;
206
207 if(fDigits){
208 fDigits->Delete();
209 delete fDigits;
210 fDigits=0;
211 }
212 if(fRecPoints){
213 fRecPoints->Delete();
214 delete fRecPoints;
215 fRecPoints=0;
216 }
7d62fb64 217 if(fCtype) {
218 fCtype->Delete();
219 delete fCtype;
220 fCtype = 0;
221 }
222 delete [] fNctype;
8ba39da9 223 delete [] fNdtype;
8e50d897 224 delete [] fNMod;
5e5bc8f1 225 //if(fLoader) delete fLoader; // MvL: Loader is not owned by this class; do not delete
7d62fb64 226
227}
8e50d897 228
7d62fb64 229//___________________________________________________________________
230void AliITSDetTypeRec::SetReconstructionModel(Int_t dettype,AliITSClusterFinder *clf){
231
232 //Set reconstruction model for detector type
233
234 if(fReconstruction==0) fReconstruction = new TObjArray(fgkNdettypes);
235 if(fReconstruction->At(dettype)!=0) delete fReconstruction->At(dettype);
236 fReconstruction->AddAt(clf,dettype);
237}
238//______________________________________________________________________
239AliITSClusterFinder* AliITSDetTypeRec::GetReconstructionModel(Int_t dettype){
240
241 //Get reconstruction model for detector type
242 if(fReconstruction==0) {
243 Warning("GetReconstructionModel","fReconstruction is 0!");
244 return 0;
245 }
246 return (AliITSClusterFinder*)fReconstruction->At(dettype);
247}
248
249//______________________________________________________________________
250void AliITSDetTypeRec::SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg){
251
252 //Set segmentation model for detector type
253
254 if(fSegmentation==0) fSegmentation = new TObjArray(fgkNdettypes);
255 if(fSegmentation->At(dettype)!=0) delete fSegmentation->At(dettype);
256 fSegmentation->AddAt(seg,dettype);
257
258}
259//______________________________________________________________________
260AliITSsegmentation* AliITSDetTypeRec::GetSegmentationModel(Int_t dettype){
261
262 //Get segmentation model for detector type
263
264 if(fSegmentation==0) {
265 Warning("GetSegmentationModel","fSegmentation is 0!");
266 return 0;
267 }
268 return (AliITSsegmentation*)fSegmentation->At(dettype);
269
270}
271//_______________________________________________________________________
fcf95fc7 272void AliITSDetTypeRec::SetCalibrationModel(Int_t iMod, AliITSCalibration *cal){
8ba39da9 273
274 //Set calibration (response) for the module iMod of type dettype
275 if (fCalibration==0) {
8e50d897 276 fCalibration = new TObjArray(GetITSgeom()->GetIndexMax());
8ba39da9 277 fCalibration->SetOwner(kTRUE);
278 fCalibration->Clear();
279 }
280
281 if (fCalibration->At(iMod) != 0)
fcf95fc7 282 delete (AliITSCalibration*) fCalibration->At(iMod);
8ba39da9 283 fCalibration->AddAt(cal,iMod);
7d62fb64 284
7d62fb64 285}
286//_______________________________________________________________________
fcf95fc7 287AliITSCalibration* AliITSDetTypeRec::GetCalibrationModel(Int_t iMod){
7d62fb64 288
8ba39da9 289 //Get calibration model for module type
7d62fb64 290
291 if(fCalibration==0) {
8ba39da9 292 Warning("GetalibrationModel","fCalibration is 0!");
7d62fb64 293 return 0;
294 }
8ba39da9 295
fcf95fc7 296 return (AliITSCalibration*)fCalibration->At(iMod);
7d62fb64 297}
298
299//______________________________________________________________________
300void AliITSDetTypeRec::SetTreeAddress(){
301 // Set branch address for the Trees.
302
303 TTree *treeR = fLoader->TreeR();
304 TTree *treeD = fLoader->TreeD();
305
306 SetTreeAddressD(treeD);
307 SetTreeAddressR(treeR);
308}
309//______________________________________________________________________
310void AliITSDetTypeRec::SetTreeAddressD(TTree *treeD){
311 // Set branch address for the tree of digits.
312
313 const char *det[4] = {"SPD","SDD","SSD","ITS"};
314 TBranch *branch;
315 Char_t* digclass;
316 Int_t i;
317 char branchname[30];
318
319 if(!treeD) return;
320 if (fDigits == 0x0) fDigits = new TObjArray(fgkNdettypes);
321 for (i=0; i<fgkNdettypes; i++) {
322 digclass = GetDigitClassName(i);
323 if(!(fDigits->At(i))) {
324 fDigits->AddAt(new TClonesArray(digclass,1000),i);
325 }else{
326 ResetDigits(i);
327 }
328 if (fgkNdettypes==3) sprintf(branchname,"%sDigits%s",det[3],det[i]);
329 else sprintf(branchname,"%sDigits%d",det[3],i+1);
330 if (fDigits) {
331 branch = treeD->GetBranch(branchname);
332 if (branch) branch->SetAddress(&((*fDigits)[i]));
333 }
334 }
335}
336
337//_______________________________________________________________________
338TBranch* AliITSDetTypeRec::MakeBranchInTree(TTree *tree, const char* name,
339 const char *classname,
340 void* address,Int_t size,
341 Int_t splitlevel, const char */*file*/)
342{
343//
344// Makes branch in given tree and diverts them to a separate file
345//
346//
347//
348
349 if (tree == 0x0) {
350 Error("MakeBranchInTree","Making Branch %s Tree is NULL",name);
351 return 0x0;
352 }
353 TBranch *branch = tree->GetBranch(name);
354 if (branch) {
355 return branch;
356 }
357 if (classname){
358 branch = tree->Branch(name,classname,address,size,splitlevel);
359 }
360 else {
361 branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
362 }
363
364 return branch;
365}
366
367//____________________________________________________________________
368void AliITSDetTypeRec::SetDefaults(){
369
370 //Set defaults for segmentation and response
371
8e50d897 372 if(!GetITSgeom()){
373 Warning("SetDefaults","null pointer to AliITSgeomGeom !");
7d62fb64 374 return;
375 }
376
377 AliITSsegmentation* seg;
8ba39da9 378 if(!GetCalibration()) {AliFatal("Exit");exit(0);}
7d62fb64 379
380 for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
381 if(dettype==0){
8e50d897 382 seg = new AliITSsegmentationSPD(GetITSgeom());
7d62fb64 383 SetSegmentationModel(dettype,seg);
3a7c3e6d 384 SetDigitClassName(dettype,"AliITSdigitSPD");
385 SetClusterClassName(dettype,"AliITSRawClusterSPD");
386
7d62fb64 387 }
388 if(dettype==1){
8e50d897 389 AliITSCalibrationSDD* res=(AliITSCalibrationSDD*) GetCalibrationModel(GetITSgeom()->GetStartSDD());
390 seg = new AliITSsegmentationSDD(GetITSgeom(),res);
7d62fb64 391 SetSegmentationModel(dettype,seg);
fcf95fc7 392 const char *kopt = ((AliITSresponseSDD*)res->GetResponse())->ZeroSuppOption();
3a7c3e6d 393 if((!strstr(kopt,"2D"))&&(!strstr(kopt,"1D"))) SetDigitClassName(dettype,"AliITSdigit");
394 else SetDigitClassName(dettype,"AliITSdigitSDD");
395 SetClusterClassName(dettype,"AliITSRawClusterSDD");
396
7d62fb64 397 }
398 if(dettype==2){
8e50d897 399 AliITSsegmentationSSD* seg2 = new AliITSsegmentationSSD(GetITSgeom());
7d62fb64 400 seg2->SetAngles(0.0075,0.0275); // strip angels rad P and N side.
401 seg2->SetAnglesLay5(0.0075,0.0275); // strip angels rad P and N side.
402 seg2->SetAnglesLay6(0.0275,0.0075); // strip angels rad P and N side.
7d62fb64 403 SetSegmentationModel(dettype,seg2);
7d62fb64 404 SetDigitClassName(dettype,"AliITSdigitSSD");
405 SetClusterClassName(dettype,"AliITSRawClusterSSD");
406 }
7d62fb64 407 }
7d62fb64 408
409}
8ba39da9 410//______________________________________________________________________
411Bool_t AliITSDetTypeRec::GetCalibration() {
412 // Get Default calibration if a storage is not defined.
413
b17dae48 414 if(!fFirstcall){
415 AliITSCalibration* cal = GetCalibrationModel(0);
416 if(cal)return kTRUE;
417 }
418 else {
419 fFirstcall = kFALSE;
420 }
06232459 421
b17dae48 422 SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
423 Int_t run=GetRunNumber();
b17dae48 424
425 Bool_t origCacheStatus = AliCDBManager::Instance()->GetCacheFlag();
426 Bool_t isCacheActive = kTRUE;
427 if(GetRunNumber()<0)isCacheActive=kFALSE;
428 if (fCalibration==0) {
429 fCalibration = new TObjArray(GetITSgeom()->GetIndexMax());
430 fCalibration->SetOwner(isCacheActive);
431 fCalibration->Clear();
432 }
433
434 AliCDBManager::Instance()->SetCacheFlag(isCacheActive);
435
436 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSPD", run);
437 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD", run);
438 AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD", run);
439 AliCDBEntry *entry2SPD = AliCDBManager::Instance()->Get("ITS/Calib/RespSPD", run);
440 AliCDBEntry *entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD", run);
441 AliCDBEntry *entry2SSD = AliCDBManager::Instance()->Get("ITS/Calib/RespSSD", run);
06232459 442
fcf95fc7 443 if(!entrySPD || !entrySDD || !entrySSD || !entry2SPD || !entry2SDD || !entry2SSD){
566f73ca 444 AliFatal("Calibration object retrieval failed! ");
e8c4cf33 445 return kFALSE;
566f73ca 446 }
447
b17dae48 448 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
449 if(!isCacheActive)entrySPD->SetObject(NULL);
8ba39da9 450 entrySPD->SetOwner(kTRUE);
fcf95fc7 451
452 AliITSresponseSPD *pSPD = (AliITSresponseSPD*)entry2SPD->GetObject();
b17dae48 453 if(!isCacheActive)entry2SPD->SetObject(NULL);
fcf95fc7 454 entry2SPD->SetOwner(kTRUE);
455
b17dae48 456 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
457 if(!isCacheActive)entrySDD->SetObject(NULL);
8ba39da9 458 entrySDD->SetOwner(kTRUE);
fcf95fc7 459
460 AliITSresponseSDD *pSDD = (AliITSresponseSDD*)entry2SDD->GetObject();
b17dae48 461 if(!isCacheActive)entry2SDD->SetObject(NULL);
fcf95fc7 462 entry2SDD->SetOwner(kTRUE);
463
b17dae48 464 TObjArray *calSSD = (TObjArray *)entrySSD->GetObject();
465 if(!isCacheActive)entrySSD->SetObject(NULL);
8ba39da9 466 entrySSD->SetOwner(kTRUE);
fcf95fc7 467
468 AliITSresponseSSD *pSSD = (AliITSresponseSSD*)entry2SSD->GetObject();
b17dae48 469 if(!isCacheActive)entry2SSD->SetObject(NULL);
fcf95fc7 470 entry2SSD->SetOwner(kTRUE);
471
b17dae48 472 // DB entries are deleted. In this way metadeta objects are deleted as well
473 if(!isCacheActive){
474 delete entrySPD;
475 delete entrySDD;
476 delete entrySSD;
477 delete entry2SPD;
478 delete entry2SDD;
479 delete entry2SSD;
480 }
06232459 481
b17dae48 482 AliCDBManager::Instance()->SetCacheFlag(origCacheStatus);
fcf95fc7 483
b17dae48 484 if ((!pSPD)||(!pSDD)||(!pSSD) || (!calSPD) || (!calSDD) || (!calSSD)) {
8ba39da9 485 AliWarning("Can not get calibration from calibration database !");
486 return kFALSE;
487 }
fcf95fc7 488
b17dae48 489 fNMod[0] = calSPD->GetEntries();
490 fNMod[1] = calSDD->GetEntries();
491 fNMod[2] = calSSD->GetEntries();
8ba39da9 492 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
493 fNMod[0], fNMod[1], fNMod[2]));
b17dae48 494 AliITSCalibration* cal;
8ba39da9 495 for (Int_t i=0; i<fNMod[0]; i++) {
b17dae48 496 cal = (AliITSCalibration*) calSPD->At(i);
497 cal->SetResponse((AliITSresponse*)pSPD);
498 SetCalibrationModel(i, cal);
8ba39da9 499 }
500 for (Int_t i=0; i<fNMod[1]; i++) {
b17dae48 501 cal = (AliITSCalibration*) calSDD->At(i);
502 cal->SetResponse((AliITSresponse*)pSDD);
8ba39da9 503 Int_t iMod = i + fNMod[0];
b17dae48 504 SetCalibrationModel(iMod, cal);
8ba39da9 505 }
506 for (Int_t i=0; i<fNMod[2]; i++) {
b17dae48 507 cal = (AliITSCalibration*) calSSD->At(i);
508 cal->SetResponse((AliITSresponse*)pSSD);
8ba39da9 509 Int_t iMod = i + fNMod[0] + fNMod[1];
b17dae48 510 SetCalibrationModel(iMod, cal);
8ba39da9 511 }
512
513 return kTRUE;
514}
515
7d62fb64 516
517//________________________________________________________________
518void AliITSDetTypeRec::SetDefaultClusterFinders(){
519
520 //set defaults for standard cluster finder
521
8e50d897 522 if(!GetITSgeom()){
523 Warning("SetDefaults","null pointer to AliITSgeom!");
7d62fb64 524 return;
525 }
526
7d62fb64 527 AliITSClusterFinder *clf;
528
529 MakeTreeC();
530
3a7c3e6d 531 for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
7d62fb64 532 //SPD
533 if(dettype==0){
534 if(!GetReconstructionModel(dettype)){
7d62fb64 535 TClonesArray *dig0 = DigitsAddress(0);
536 TClonesArray *rec0 = ClustersAddress(0);
8ba39da9 537 clf = new AliITSClusterFinderSPD(this,dig0,rec0);
7d62fb64 538 SetReconstructionModel(dettype,clf);
8ba39da9 539
7d62fb64 540 }
541 }
8ba39da9 542
7d62fb64 543 //SDD
544 if(dettype==1){
545 if(!GetReconstructionModel(dettype)){
7d62fb64 546 TClonesArray *dig1 = DigitsAddress(1);
547 TClonesArray *rec1 = ClustersAddress(1);
8ba39da9 548 clf = new AliITSClusterFinderSDD(this,dig1,rec1);
7d62fb64 549 SetReconstructionModel(dettype,clf);
550 }
551
552 }
553 //SSD
554 if(dettype==2){
555 if(!GetReconstructionModel(dettype)){
7d62fb64 556 TClonesArray* dig2 = DigitsAddress(2);
8ba39da9 557 clf = new AliITSClusterFinderSSD(this,dig2);
7d62fb64 558 SetReconstructionModel(dettype,clf);
559 }
560 }
561
562 }
563
564
565}
566
567//________________________________________________________________
3a7c3e6d 568void AliITSDetTypeRec::SetDefaultClusterFindersV2(Bool_t rawdata){
7d62fb64 569
570 //Set defaults for cluster finder V2
571
8e50d897 572 if(!GetITSgeom()){
573 Warning("SetDefaults","Null pointer to AliITSgeom !");
7d62fb64 574 return;
575 }
576
7d62fb64 577 AliITSClusterFinder *clf;
578
579 MakeTreeC();
3a7c3e6d 580 for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
7d62fb64 581 //SPD
582 if(dettype==0){
583 if(!GetReconstructionModel(dettype)){
8ba39da9 584 clf = new AliITSClusterFinderV2SPD(this);
7d62fb64 585 clf->InitGeometry();
3a7c3e6d 586 if(!rawdata) clf->SetDigits(DigitsAddress(0));
7d62fb64 587 SetReconstructionModel(dettype,clf);
588
589 }
590 }
591 //SDD
592 if(dettype==1){
593 if(!GetReconstructionModel(dettype)){
8ba39da9 594 clf = new AliITSClusterFinderV2SDD(this);
595 clf->InitGeometry();
3a7c3e6d 596 if(!rawdata) clf->SetDigits(DigitsAddress(1));
7d62fb64 597 SetReconstructionModel(dettype,clf);
598 }
599
600 }
601
602 //SSD
603 if(dettype==2){
604 if(!GetReconstructionModel(dettype)){
8ba39da9 605 clf = new AliITSClusterFinderV2SSD(this);
7d62fb64 606 clf->InitGeometry();
3a7c3e6d 607 if(!rawdata) clf->SetDigits(DigitsAddress(2));
7d62fb64 608 SetReconstructionModel(dettype,clf);
609 }
610 }
611
612 }
613
614}
615//______________________________________________________________________
616void AliITSDetTypeRec::MakeBranch(Option_t* option){
617
618 //Creates branches for clusters and recpoints
619 Bool_t cR = (strstr(option,"R")!=0);
620 Bool_t cRF = (strstr(option,"RF")!=0);
7d62fb64 621
622 if(cRF)cR = kFALSE;
623
624 if(cR) MakeBranchR(0);
625 if(cRF) MakeBranchRF(0);
7d62fb64 626
627}
628
629//_____________________________________________________________
630void AliITSDetTypeRec::MakeTreeC(){
631
632 //Create a separate tree to store the clusters
633 if(!fLoader){
634 Warning("MakeTreeC","ITS loader is null!");
635 return;
636 }
637 if(fLoader->TreeC()== 0x0) fLoader->MakeTree("C");
638 MakeBranchC();
639}
640
641//______________________________________________________________
642void AliITSDetTypeRec::MakeBranchC(){
643
644 //Make branches in the tree of clusters
645
646 if(!fLoader){
647 Warning("MakeBranchC","ITS loader is null!");
648 return;
649 }
650 TTree* lTC = fLoader->TreeC();
651 if(lTC==0x0){
652 Error("MakeTreeC","Can not get TreeC from loader");
653 return;
654 }
655
656 Int_t buffersize = 4000;
657 Char_t branchname[30];
658 Char_t* cluclass;
659 const char *det[4]={"SPD","SDD","SSD","ITS"};
660
661 for(Int_t i=0;i<fgkNdettypes;i++){
662 cluclass = GetClusterClassName(i);
663 if(fCtype==0x0) fCtype = new TObjArray(fgkNdettypes);
664 if(!ClustersAddress(i)){
665 fCtype->AddAt(new TClonesArray(cluclass,1000),i);
666 }
667 if(fgkNdettypes==3) sprintf(branchname,"%sClusters%s",det[3],det[i]);
668 else sprintf(branchname,"%sClusters%d",det[3],i+1);
669 if(fCtype && lTC){
670 if(lTC->GetBranch(branchname)){
671 Warning("MakeBranchC","Branch %s already exists in TreeC",branchname);
672 } else{
673 Info("MakeBranchC","Creating branch %s in TreeC",branchname);
674 lTC->Branch(branchname,&((*fCtype)[i]),buffersize);
675 }
676 }
677
678 }
679
680}
681
682//_______________________________________________________________
683void AliITSDetTypeRec::GetTreeC(Int_t event){
684
685 //Get the clusters tree for this event and
686 //sets the branch address
687
688
689 if(!fLoader){
690 Warning("GetTreeC","ITS loader is null!");
691 return;
692 }
693
694 Char_t branchname[30];
695 const char *det[4] = {"SPD","SDD","SSD","ITS"};
696 TTree* lTC = fLoader->TreeC();
697
698 ResetClusters();
699 if(lTC) fLoader->CleanRawClusters();
700
701 TBranch* branch;
702 if(lTC){
703 Char_t* cluclass;
704 for(Int_t i=0;i<fgkNdettypes;i++){
705 cluclass = GetClusterClassName(i);
706 if(fCtype==0x0) fCtype = new TObjArray(fgkNdettypes);
707 if(!fCtype->At(i)) fCtype->AddAt(new TClonesArray(cluclass,1000),i);
708 if(fgkNdettypes==3) sprintf(branchname,"%sClusters%s",det[3],det[i]);
709 else sprintf(branchname,"%sClusters%d",det[3],i+1);
710 if(fCtype){
711 branch = lTC->GetBranch(branchname);
712 if(branch) branch->SetAddress(&((*fCtype)[i]));
713 }
714 }
715 } else{
716 Error("GetTreeC","cannot find clusters Tree for vent %d",event);
717 }
718
719}
720
721//___________________________________________________________________
722void AliITSDetTypeRec::AddCluster(Int_t id, AliITSRawCluster *c){
723
724 // Adds a raw cluster to the list
725 TClonesArray &lc = *((TClonesArray*)fCtype->At(id));
726 switch(id){
727 case 0:
728 new(lc[fNctype[id]++]) AliITSRawClusterSPD(*((AliITSRawClusterSPD*)c));
729 break;
730 case 1:
731 new(lc[fNctype[id]++]) AliITSRawClusterSDD(*((AliITSRawClusterSDD*)c));
732 break;
733 case 2:
734 new(lc[fNctype[id]++]) AliITSRawClusterSSD(*((AliITSRawClusterSSD*)c));
735 break;
736 }
737}
738//___________________________________________________________________
739void AliITSDetTypeRec::ResetDigits(){
740 // Reset number of digits and the digits array for the ITS detector.
741
742 if(!fDigits) return;
743 for(Int_t i=0;i<fgkNdettypes;i++){
744 ResetDigits(i);
745 }
746}
747//___________________________________________________________________
748void AliITSDetTypeRec::ResetDigits(Int_t branch){
749 // Reset number of digits and the digits array for this branch.
750
751 if(fDigits->At(branch)) ((TClonesArray*)fDigits->At(branch))->Clear();
752 if(fNdtype) fNdtype[branch]=0;
753
754}
755
756//__________________________________________________________________
757void AliITSDetTypeRec::ResetClusters(){
758
759 //Resets number of clusters and the cluster array
760 for(Int_t i=0;i<fgkNdettypes;i++){
761 ResetClusters(i);
762 }
763}
764
765//__________________________________________________________________
766void AliITSDetTypeRec::ResetClusters(Int_t i){
767
768 //Resets number of clusters and the cluster array for this branch
769
770 if (fCtype->At(i)) ((TClonesArray*)fCtype->At(i))->Clear();
771 if (fNctype) fNctype[i]=0;
772}
773//__________________________________________________________________
774void AliITSDetTypeRec::MakeBranchR(const char *file, Option_t *opt){
775
776 //Creates tree branches for recpoints
777 // Inputs:
778 // cont char *file File name where RecPoints branch is to be written
779 // to. If blank it write the SDigits to the same
780 // file in which the Hits were found.
781
782 if(!fLoader){
783 Warning("MakeBranchR","ITS loader is null!");
784 return;
785 }
786
787 Int_t buffsz = 4000;
788 char branchname[30];
789
790 // only one branch for rec points for all detector types
791 Bool_t oFast= (strstr(opt,"Fast")!=0);
7d62fb64 792
793 Char_t detname[10] = "ITS";
794
795
796 if(oFast){
797 sprintf(branchname,"%sRecPointsF",detname);
7d62fb64 798 } else {
799 sprintf(branchname,"%sRecPoints",detname);
800 }
801
00a7cc50 802 if(!fRecPoints)fRecPoints = new TClonesArray("AliITSRecPoint",1000);
803 if (fLoader->TreeR()) {
804 if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",
805 1000);
806 MakeBranchInTree(fLoader->TreeR(),branchname,0,&fRecPoints,buffsz,99,file);
807 } // end if
808
7d62fb64 809
810}
811//______________________________________________________________________
812void AliITSDetTypeRec::SetTreeAddressR(TTree *treeR){
813 // Set branch address for the Reconstructed points Trees.
3b9df642 814 // Inputs:
7d62fb64 815 // TTree *treeR Tree containing the RecPoints.
3b9df642 816 // Outputs:
7d62fb64 817 // none.
3b9df642 818 // Return:
7d62fb64 819
820 char branchname[30];
821 Char_t namedet[10]="ITS";
822
823 if(!treeR) return;
824 if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 825 TBranch *branch;
826 sprintf(branchname,"%sRecPoints",namedet);
827 branch = treeR->GetBranch(branchname);
828 if (branch) {
829 branch->SetAddress(&fRecPoints);
830 }else {
831 sprintf(branchname,"%sRecPointsF",namedet);
7d62fb64 832 branch = treeR->GetBranch(branchname);
833 if (branch) {
00a7cc50 834 branch->SetAddress(&fRecPoints);
7d62fb64 835 }
00a7cc50 836
7d62fb64 837 }
3b9df642 838}
7d62fb64 839//____________________________________________________________________
840void AliITSDetTypeRec::AddRecPoint(const AliITSRecPoint &r){
841 // Add a reconstructed space point to the list
842 // Inputs:
843 // const AliITSRecPoint &r RecPoint class to be added to the tree
844 // of reconstructed points TreeR.
845 // Outputs:
846 // none.
847 // Return:
848 // none.
849
850 TClonesArray &lrecp = *fRecPoints;
851 new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
852}
7d62fb64 853
854//______________________________________________________________________
855void AliITSDetTypeRec::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt, Bool_t v2){
856 // cluster finding and reconstruction of space points
857 // the condition below will disappear when the geom class will be
858 // initialized for all versions - for the moment it is only for v5 !
859 // 7 is the SDD beam test version
860 // Inputs:
861 // Int_t evNumber Event number to be processed.
862 // Int_t lastentry Offset for module when not all of the modules
863 // are processed.
864 // Option_t *opt String indicating which ITS sub-detectors should
865 // be processed. If ="All" then all of the ITS
866 // sub detectors are processed.
867
8e50d897 868 if(!GetITSgeom()){
869 Warning("DigitsToRecPoints","Null pointer to AliITSgeom !");
7d62fb64 870 return;
871 }
872 if(!fLoader){
873 Warning("DigitsToRecPoints","ITS loader is null!");
874 return;
875 }
876
877 const char *all = strstr(opt,"All");
878 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
879 strstr(opt,"SSD")};
00a7cc50 880 if(!v2) {
881 SetDefaultClusterFinders();
882 AliInfo("Original cluster finder has been selected\n");
883 }
884 else {
885 SetDefaultClusterFindersV2();
886 AliInfo("V2 cluster finder has been selected \n");
887 }
7d62fb64 888
889 TTree *treeC=fLoader->TreeC();
890 if(!treeC){
891 MakeTreeC();
7d62fb64 892 }
893 AliITSClusterFinder *rec = 0;
894 Int_t id,module,first=0;
8e50d897 895 for(module=0;module<GetITSgeom()->GetIndexMax();module++){
896 id = GetITSgeom()->GetModuleType(module);
7d62fb64 897 if (!all && !det[id]) continue;
8e50d897 898 if(det[id]) first = GetITSgeom()->GetStartDet(id);
7d62fb64 899 rec = (AliITSClusterFinder*)GetReconstructionModel(id);
900 TClonesArray *itsDigits = DigitsAddress(id);
901 if (!rec) {
902 Error("DigitsToRecPoints",
903 "The reconstruction class was not instanciated! event=%d",
904 evNumber);
905 exit(1);
906 }
5e5bc8f1 907 ResetDigits(); // MvL: Not sure we neeed this when rereading anyways
7d62fb64 908 TTree *lTD = fLoader->TreeD();
909 if (all) {
910 lTD->GetEvent(lastentry+module);
911 }else {
912 lTD->GetEvent(lastentry+(module-first));
913 }
914 Int_t ndigits = itsDigits->GetEntriesFast();
915 if(ndigits>0){
916 rec->SetDetTypeRec(this);
7d62fb64 917 rec->SetDigits(DigitsAddress(id));
918 rec->SetClusters(ClustersAddress(id));
919 rec->FindRawClusters(module);
920 } // end if
921 fLoader->TreeR()->Fill();
922 ResetRecPoints();
7d62fb64 923 treeC->Fill();
924 ResetClusters();
925 }
926
927 fLoader->WriteRecPoints("OVERWRITE");
928 fLoader->WriteRawClusters("OVERWRITE");
5e5bc8f1 929 fLoader->CleanRawClusters();
7d62fb64 930}
931//______________________________________________________________________
932void AliITSDetTypeRec::DigitsToRecPoints(AliRawReader* rawReader){
933 // cluster finding and reconstruction of space points
934 // the condition below will disappear when the geom class will be
935 // initialized for all versions - for the moment it is only for v5 !
936 // 7 is the SDD beam test version
937 // Inputs:
938 // Int_t evNumber Event number to be processed.
939 // Int_t lastentry Offset for module when not all of the modules
940 // are processed.
941 // Option_t *opt String indicating which ITS sub-detectors should
942 // be processed. If ="All" then all of the ITS
943 // sub detectors are processed.
944 // Outputs:
945 // none.
946 // Return:
947 // none.
8e50d897 948 if(!GetITSgeom()){
949 Warning("DigitsToRecPoints","Null pointer to AliITSgeom !");
7d62fb64 950 return;
951 }
952 if(!fLoader){
953 Warning("DigitsToRecPoints","ITS loader is null!");
954 return;
955 }
956
7d62fb64 957
958 AliITSClusterFinderV2 *rec = 0;
959 Int_t id=0;
960
961 if(!fLoader->TreeR()) fLoader->MakeTree("R");
962 TTree* cTree = fLoader->TreeR();
00a7cc50 963 TClonesArray *array=new TClonesArray("AliITSRecPoint",1000);
964 cTree->Branch("ITSRecPoints",&array);
7d62fb64 965 delete array;
966
8e50d897 967 TClonesArray** clusters = new TClonesArray*[GetITSgeom()->GetIndexMax()];
968 for (Int_t iModule = 0; iModule < GetITSgeom()->GetIndexMax(); iModule++) {
7d62fb64 969 clusters[iModule] = NULL;
970 }
971 for(id=0;id<3;id++){
972 rec = (AliITSClusterFinderV2*)GetReconstructionModel(id);
8ba39da9 973 rec->SetDetTypeRec(this);
c157c94e 974 if (!rec)
975 AliFatal("The reconstruction class was not instanciated");
976
7d62fb64 977 rec->RawdataToClusters(rawReader,clusters);
978 }
979 Int_t nClusters =0;
c157c94e 980 TClonesArray *emptyArray=new TClonesArray("AliITSRecPoint");
8e50d897 981 for(Int_t iModule=0;iModule<GetITSgeom()->GetIndexMax();iModule++){
7d62fb64 982 array = clusters[iModule];
983 if(!array){
c157c94e 984 AliDebug(1,Form("data for module %d missing!",iModule));
985 array = emptyArray;
7d62fb64 986 }
00a7cc50 987 cTree->SetBranchAddress("ITSRecPoints",&array);
7d62fb64 988 cTree->Fill();
989 nClusters+=array->GetEntriesFast();
5ef4644f 990
991 if (array != emptyArray) {
992 array->Delete();
993 delete array;
994 }
7d62fb64 995 }
c157c94e 996 delete emptyArray;
997
7d62fb64 998 fLoader->WriteRecPoints("OVERWRITE");
999
1000 delete[] clusters;
00a7cc50 1001 Info("DigitsToRecPoints", "total number of found recpoints in ITS: %d\n",
7d62fb64 1002 nClusters);
1003
1004}
1005
8ba39da9 1006