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