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