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