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