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