]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSDetTypeRec.cxx
TEveJetCone moved to root/eve (piggyback on sync with ROOT trunk).
[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/*
140e5249 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"
7d62fb64 32#include "AliITSClusterFinderV2SPD.h"
33#include "AliITSClusterFinderV2SDD.h"
34#include "AliITSClusterFinderV2SSD.h"
3b9df642 35#include "AliITSDetTypeRec.h"
6cae184e 36#include "AliITSgeom.h"
7d62fb64 37#include "AliITSRecPoint.h"
ed446fa3 38#include "AliITSReconstructor.h"
39#include "AliITSRecoParam.h"
fcf95fc7 40#include "AliITSCalibrationSDD.h"
028a3709 41#include "AliITSMapSDD.h"
18da6e54 42#include "AliITSDriftSpeedArraySDD.h"
140e5249 43#include "AliITSDriftSpeedSDD.h"
2f8ed7ab 44#include "AliITSHLTforSDD.h"
fb4dfab9 45#include "AliITSCalibrationSSD.h"
88128115 46#include "AliITSNoiseSSDv2.h"
47#include "AliITSGainSSDv2.h"
48#include "AliITSBadChannelsSSDv2.h"
fb4dfab9 49#include "AliITSNoiseSSD.h"
50#include "AliITSGainSSD.h"
51#include "AliITSBadChannelsSSD.h"
7d62fb64 52#include "AliITSsegmentationSPD.h"
53#include "AliITSsegmentationSDD.h"
54#include "AliITSsegmentationSSD.h"
00a7cc50 55#include "AliLog.h"
7d62fb64 56
3b9df642 57
7d62fb64 58const Int_t AliITSDetTypeRec::fgkNdettypes = 3;
8ba39da9 59const Int_t AliITSDetTypeRec::fgkDefaultNModulesSPD = 240;
60const Int_t AliITSDetTypeRec::fgkDefaultNModulesSDD = 260;
61const Int_t AliITSDetTypeRec::fgkDefaultNModulesSSD = 1698;
62
3b9df642 63ClassImp(AliITSDetTypeRec)
64
7d62fb64 65//________________________________________________________________
e56160b8 66AliITSDetTypeRec::AliITSDetTypeRec(): TObject(),
67fNMod(0),
6cae184e 68fITSgeom(0),
e56160b8 69fReconstruction(0),
70fSegmentation(0),
71fCalibration(0),
ced4d9bc 72fSSDCalibration(0),
23197852 73fSPDDead(0),
b457135f 74fSPDFastOr(0),
e56160b8 75fPreProcess(0),
76fPostProcess(0),
77fDigits(0),
979b5a5f 78fDDLMapSDD(0),
253e68a0 79fRespSDD(0),
75065a60 80fAveGainSDD(0),
2f8ed7ab 81fIsHLTmodeC(0),
e56160b8 82fNdtype(0),
83fCtype(0),
84fNctype(0),
85fRecPoints(0),
86fNRecPoints(0),
87fSelectedVertexer(),
62b93da7 88fFirstcall(kTRUE),
ff44c37c 89fLoadOnlySPDCalib(0),
90fFastOrFiredMap(1200){
8e50d897 91 // Standard Constructor
92 // Inputs:
93 // none.
94 // Outputs:
95 // none.
96 // Return:
97 //
7d62fb64 98
7d62fb64 99 fReconstruction = new TObjArray(fgkNdettypes);
7d62fb64 100 fDigits = new TObjArray(fgkNdettypes);
8e50d897 101 for(Int_t i=0; i<3; i++){
8e50d897 102 fDigClassName[i]=0;
8e50d897 103 }
ced4d9bc 104 fSSDCalibration=new AliITSCalibrationSSD();
7d62fb64 105 fNdtype = new Int_t[fgkNdettypes];
106 fCtype = new TObjArray(fgkNdettypes);
107 fNctype = new Int_t[fgkNdettypes];
8e50d897 108 fNMod = new Int_t [fgkNdettypes];
109 fNMod[0] = fgkDefaultNModulesSPD;
110 fNMod[1] = fgkDefaultNModulesSDD;
111 fNMod[2] = fgkDefaultNModulesSSD;
00a7cc50 112 fRecPoints = new TClonesArray("AliITSRecPoint",3000);
7d62fb64 113 fNRecPoints = 0;
7d62fb64 114
115 for(Int_t i=0;i<fgkNdettypes;i++){
116 fNdtype[i]=0;
117 fNctype[i]=0;
118 }
119
e56160b8 120 SelectVertexer(" ");
7d62fb64 121}
7537d03c 122
7d62fb64 123//______________________________________________________________________
7537d03c 124AliITSDetTypeRec::AliITSDetTypeRec(const AliITSDetTypeRec & rec):TObject(rec),
125fNMod(rec.fNMod),
6cae184e 126fITSgeom(rec.fITSgeom),
7537d03c 127fReconstruction(rec.fReconstruction),
128fSegmentation(rec.fSegmentation),
129fCalibration(rec.fCalibration),
ced4d9bc 130fSSDCalibration(rec.fSSDCalibration),
23197852 131fSPDDead(rec.fSPDDead),
b457135f 132fSPDFastOr(rec.fSPDFastOr),
7537d03c 133fPreProcess(rec.fPreProcess),
134fPostProcess(rec.fPostProcess),
135fDigits(rec.fDigits),
979b5a5f 136fDDLMapSDD(rec.fDDLMapSDD),
253e68a0 137fRespSDD(rec.fRespSDD),
75065a60 138fAveGainSDD(rec.fAveGainSDD),
2f8ed7ab 139fIsHLTmodeC(rec.fIsHLTmodeC),
7537d03c 140fNdtype(rec.fNdtype),
141fCtype(rec.fCtype),
142fNctype(rec.fNctype),
143fRecPoints(rec.fRecPoints),
144fNRecPoints(rec.fNRecPoints),
145fSelectedVertexer(rec.fSelectedVertexer),
62b93da7 146fFirstcall(rec.fFirstcall),
ff44c37c 147fLoadOnlySPDCalib(rec.fLoadOnlySPDCalib),
148fFastOrFiredMap(rec.fFastOrFiredMap){
7d62fb64 149
e56160b8 150 // Copy constructor.
7537d03c 151
7d62fb64 152}
153//______________________________________________________________________
e56160b8 154AliITSDetTypeRec& AliITSDetTypeRec::operator=(const AliITSDetTypeRec& source){
7537d03c 155 // Assignment operator.
156 this->~AliITSDetTypeRec();
157 new(this) AliITSDetTypeRec(source);
158 return *this;
7d62fb64 159
e56160b8 160}
7537d03c 161
7d62fb64 162//_____________________________________________________________________
3b9df642 163AliITSDetTypeRec::~AliITSDetTypeRec(){
7d62fb64 164 //Destructor
6cae184e 165
fcf95fc7 166 if(fReconstruction){
167 fReconstruction->Delete();
168 delete fReconstruction;
169 fReconstruction = 0;
170 }
171 if(fSegmentation){
172 fSegmentation->Delete();
173 delete fSegmentation;
174 fSegmentation = 0;
175 }
6cae184e 176 if(fCalibration){
7032f6a2 177 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
7032f6a2 178 fCalibration->Delete();
179 delete fCalibration;
180 fCalibration = 0;
253e68a0 181 if(fRespSDD) delete fRespSDD;
182 if(fDDLMapSDD) delete fDDLMapSDD;
183 }
fcf95fc7 184 }
ced4d9bc 185 if(fSSDCalibration) delete fSSDCalibration;
186 if(fSPDDead){
23197852 187 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
188 fSPDDead->Delete();
189 delete fSPDDead;
190 fSPDDead = 0;
191 }
192 }
7d62fb64 193 if(fPreProcess) delete fPreProcess;
194 if(fPostProcess) delete fPostProcess;
7d62fb64 195 if(fDigits){
196 fDigits->Delete();
197 delete fDigits;
198 fDigits=0;
199 }
200 if(fRecPoints){
201 fRecPoints->Delete();
202 delete fRecPoints;
203 fRecPoints=0;
204 }
7d62fb64 205 if(fCtype) {
206 fCtype->Delete();
207 delete fCtype;
208 fCtype = 0;
209 }
210 delete [] fNctype;
8ba39da9 211 delete [] fNdtype;
8e50d897 212 delete [] fNMod;
7d62fb64 213
6cae184e 214 if (fITSgeom) delete fITSgeom;
215
7d62fb64 216}
8e50d897 217
7d62fb64 218//___________________________________________________________________
219void AliITSDetTypeRec::SetReconstructionModel(Int_t dettype,AliITSClusterFinder *clf){
220
221 //Set reconstruction model for detector type
222
223 if(fReconstruction==0) fReconstruction = new TObjArray(fgkNdettypes);
224 if(fReconstruction->At(dettype)!=0) delete fReconstruction->At(dettype);
225 fReconstruction->AddAt(clf,dettype);
226}
227//______________________________________________________________________
228AliITSClusterFinder* AliITSDetTypeRec::GetReconstructionModel(Int_t dettype){
229
230 //Get reconstruction model for detector type
231 if(fReconstruction==0) {
232 Warning("GetReconstructionModel","fReconstruction is 0!");
233 return 0;
234 }
235 return (AliITSClusterFinder*)fReconstruction->At(dettype);
236}
237
238//______________________________________________________________________
239void AliITSDetTypeRec::SetSegmentationModel(Int_t dettype,AliITSsegmentation *seg){
240
241 //Set segmentation model for detector type
242
243 if(fSegmentation==0) fSegmentation = new TObjArray(fgkNdettypes);
244 if(fSegmentation->At(dettype)!=0) delete fSegmentation->At(dettype);
245 fSegmentation->AddAt(seg,dettype);
246
247}
248//______________________________________________________________________
249AliITSsegmentation* AliITSDetTypeRec::GetSegmentationModel(Int_t dettype){
250
251 //Get segmentation model for detector type
252
253 if(fSegmentation==0) {
254 Warning("GetSegmentationModel","fSegmentation is 0!");
255 return 0;
256 }
257 return (AliITSsegmentation*)fSegmentation->At(dettype);
258
259}
260//_______________________________________________________________________
fcf95fc7 261void AliITSDetTypeRec::SetCalibrationModel(Int_t iMod, AliITSCalibration *cal){
8ba39da9 262
263 //Set calibration (response) for the module iMod of type dettype
264 if (fCalibration==0) {
8e50d897 265 fCalibration = new TObjArray(GetITSgeom()->GetIndexMax());
8ba39da9 266 fCalibration->SetOwner(kTRUE);
267 fCalibration->Clear();
268 }
269
270 if (fCalibration->At(iMod) != 0)
fcf95fc7 271 delete (AliITSCalibration*) fCalibration->At(iMod);
8ba39da9 272 fCalibration->AddAt(cal,iMod);
7d62fb64 273
7d62fb64 274}
275//_______________________________________________________________________
23197852 276void AliITSDetTypeRec::SetSPDDeadModel(Int_t iMod, AliITSCalibration *cal){
277
278 //Set dead pixel info for the SPD module iMod
279 if (fSPDDead==0) {
280 fSPDDead = new TObjArray(fgkDefaultNModulesSPD);
281 fSPDDead->SetOwner(kTRUE);
282 fSPDDead->Clear();
283 }
284
285 if (fSPDDead->At(iMod) != 0)
286 delete (AliITSCalibration*) fSPDDead->At(iMod);
287 fSPDDead->AddAt(cal,iMod);
288}
289//_______________________________________________________________________
fcf95fc7 290AliITSCalibration* AliITSDetTypeRec::GetCalibrationModel(Int_t iMod){
7d62fb64 291
8ba39da9 292 //Get calibration model for module type
7d62fb64 293
294 if(fCalibration==0) {
8ba39da9 295 Warning("GetalibrationModel","fCalibration is 0!");
7d62fb64 296 return 0;
297 }
8ba39da9 298
ced4d9bc 299 if(iMod<fgkDefaultNModulesSPD+fgkDefaultNModulesSDD){
300 return (AliITSCalibration*)fCalibration->At(iMod);
301 }else{
302 Int_t i=iMod-(fgkDefaultNModulesSPD+fgkDefaultNModulesSDD);
303 fSSDCalibration->SetModule(i);
304 return (AliITSCalibration*)fSSDCalibration;
305 }
306
7d62fb64 307}
23197852 308//_______________________________________________________________________
309AliITSCalibration* AliITSDetTypeRec::GetSPDDeadModel(Int_t iMod){
310
311 //Get SPD dead for module iMod
312
313 if(fSPDDead==0) {
314 AliWarning("fSPDDead is 0!");
315 return 0;
316 }
317
318 return (AliITSCalibration*)fSPDDead->At(iMod);
319}
7d62fb64 320
7d62fb64 321//______________________________________________________________________
322void AliITSDetTypeRec::SetTreeAddressD(TTree *treeD){
323 // Set branch address for the tree of digits.
324
325 const char *det[4] = {"SPD","SDD","SSD","ITS"};
326 TBranch *branch;
a6e0ebfe 327 const Char_t* digclass;
7d62fb64 328 Int_t i;
329 char branchname[30];
330
331 if(!treeD) return;
332 if (fDigits == 0x0) fDigits = new TObjArray(fgkNdettypes);
333 for (i=0; i<fgkNdettypes; i++) {
334 digclass = GetDigitClassName(i);
335 if(!(fDigits->At(i))) {
336 fDigits->AddAt(new TClonesArray(digclass,1000),i);
337 }else{
338 ResetDigits(i);
339 }
340 if (fgkNdettypes==3) sprintf(branchname,"%sDigits%s",det[3],det[i]);
341 else sprintf(branchname,"%sDigits%d",det[3],i+1);
342 if (fDigits) {
343 branch = treeD->GetBranch(branchname);
344 if (branch) branch->SetAddress(&((*fDigits)[i]));
345 }
346 }
347}
348
349//_______________________________________________________________________
350TBranch* AliITSDetTypeRec::MakeBranchInTree(TTree *tree, const char* name,
351 const char *classname,
352 void* address,Int_t size,
6cae184e 353 Int_t splitlevel)
7d62fb64 354{
355//
356// Makes branch in given tree and diverts them to a separate file
357//
358//
359//
360
361 if (tree == 0x0) {
362 Error("MakeBranchInTree","Making Branch %s Tree is NULL",name);
363 return 0x0;
364 }
365 TBranch *branch = tree->GetBranch(name);
366 if (branch) {
367 return branch;
368 }
369 if (classname){
370 branch = tree->Branch(name,classname,address,size,splitlevel);
371 }
372 else {
373 branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
374 }
375
376 return branch;
377}
378
379//____________________________________________________________________
380void AliITSDetTypeRec::SetDefaults(){
381
382 //Set defaults for segmentation and response
383
8e50d897 384 if(!GetITSgeom()){
385 Warning("SetDefaults","null pointer to AliITSgeomGeom !");
7d62fb64 386 return;
387 }
388
389 AliITSsegmentation* seg;
8ba39da9 390 if(!GetCalibration()) {AliFatal("Exit");exit(0);}
7d62fb64 391
392 for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
393 if(dettype==0){
d24bc9d6 394 seg = new AliITSsegmentationSPD();
7d62fb64 395 SetSegmentationModel(dettype,seg);
3a7c3e6d 396 SetDigitClassName(dettype,"AliITSdigitSPD");
7d62fb64 397 }
62b93da7 398 if(fLoadOnlySPDCalib==kFALSE){
399 if(dettype==1){
400 seg = new AliITSsegmentationSDD();
401 AliITSCalibrationSDD* cal=(AliITSCalibrationSDD*)GetCalibrationModel(fgkDefaultNModulesSPD+1);
402 if(cal->IsAMAt20MHz()){
403 seg->SetPadSize(seg->Dpz(0),20.);
404 seg->SetNPads(seg->Npz()/2,128);
405 }
406 SetSegmentationModel(dettype,seg);
407 SetDigitClassName(dettype,"AliITSdigitSDD");
b27af87f 408 }
7d62fb64 409 }
410 if(dettype==2){
d24bc9d6 411 AliITSsegmentationSSD* seg2 = new AliITSsegmentationSSD();
7d62fb64 412 SetSegmentationModel(dettype,seg2);
7d62fb64 413 SetDigitClassName(dettype,"AliITSdigitSSD");
7d62fb64 414 }
7d62fb64 415 }
7d62fb64 416}
8ba39da9 417//______________________________________________________________________
418Bool_t AliITSDetTypeRec::GetCalibration() {
419 // Get Default calibration if a storage is not defined.
420
b17dae48 421 if(!fFirstcall){
422 AliITSCalibration* cal = GetCalibrationModel(0);
423 if(cal)return kTRUE;
62b93da7 424 }else {
b17dae48 425 fFirstcall = kFALSE;
426 }
06232459 427
6cae184e 428 // SetRunNumber((Int_t)AliCDBManager::Instance()->GetRun());
429 // Int_t run=GetRunNumber();
b17dae48 430
6cae184e 431 Bool_t cacheStatus = AliCDBManager::Instance()->GetCacheFlag();
b17dae48 432 if (fCalibration==0) {
433 fCalibration = new TObjArray(GetITSgeom()->GetIndexMax());
6cae184e 434 fCalibration->SetOwner(!cacheStatus);
b17dae48 435 fCalibration->Clear();
436 }
75065a60 437
438 Bool_t retCode=GetCalibrationSPD(cacheStatus);
439 if(retCode==kFALSE) return kFALSE;
440
441 if(fLoadOnlySPDCalib==kFALSE){
442 retCode=GetCalibrationSDD(cacheStatus);
443 if(retCode==kFALSE) return kFALSE;
444 retCode=GetCalibrationSSD(cacheStatus);
445 if(retCode==kFALSE) return kFALSE;
446 }
447
448 AliInfo(Form("%i SPD, %i SDD and %i SSD in calibration database",
449 fNMod[0], fNMod[1], fNMod[2]));
450 return kTRUE;
451}
452//______________________________________________________________________
453Bool_t AliITSDetTypeRec::GetCalibrationSPD(Bool_t cacheStatus) {
454 // Get SPD calibration objects from OCDB
8d37cc87 455 // dead pixel are not used for local reconstruction
75065a60 456
8d37cc87 457 AliCDBEntry *entrySPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDNoisy");
23197852 458 AliCDBEntry *deadSPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead");
b457135f 459 AliCDBEntry *fastOrSPD = AliCDBManager::Instance()->Get("ITS/Calib/SPDFastOr");
460 if(!entrySPD || !deadSPD || !fastOrSPD ){
62b93da7 461 AliFatal("SPD Calibration object retrieval failed! ");
462 return kFALSE;
463 }
75065a60 464
62b93da7 465 TObjArray *calSPD = (TObjArray *)entrySPD->GetObject();
466 if(!cacheStatus)entrySPD->SetObject(NULL);
467 entrySPD->SetOwner(kTRUE);
fb4dfab9 468
62b93da7 469 TObjArray *caldeadSPD = (TObjArray *)deadSPD->GetObject();
470 if(!cacheStatus)deadSPD->SetObject(NULL);
471 deadSPD->SetOwner(kTRUE);
472
b457135f 473 AliITSFastOrCalibrationSPD *calfastOrSPD = (AliITSFastOrCalibrationSPD *)fastOrSPD->GetObject();
474 if(!cacheStatus)fastOrSPD->SetObject(NULL);
475 fastOrSPD->SetOwner(kTRUE);
476
62b93da7 477 if(!cacheStatus){
478 delete entrySPD;
479 delete deadSPD;
b457135f 480 delete fastOrSPD;
62b93da7 481 }
b457135f 482 if ((!calSPD) || (!caldeadSPD) || (!calfastOrSPD)){
62b93da7 483 AliWarning("Can not get SPD calibration from calibration database !");
484 return kFALSE;
485 }
486
487 fNMod[0] = calSPD->GetEntries();
488
489 AliITSCalibration* cal;
490 for (Int_t i=0; i<fNMod[0]; i++) {
491 cal = (AliITSCalibration*) calSPD->At(i);
492 SetCalibrationModel(i, cal);
493 cal = (AliITSCalibration*) caldeadSPD->At(i);
494 SetSPDDeadModel(i, cal);
495 }
b457135f 496 fSPDFastOr = calfastOrSPD;
62b93da7 497
62b93da7 498 return kTRUE;
499}
75065a60 500
62b93da7 501//______________________________________________________________________
75065a60 502Bool_t AliITSDetTypeRec::GetCalibrationSDD(Bool_t cacheStatus) {
503 // Get SDD calibration objects from OCDB
504
62b93da7 505 AliCDBEntry *entrySDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD");
6cae184e 506 AliCDBEntry *entry2SDD = AliCDBManager::Instance()->Get("ITS/Calib/RespSDD");
18da6e54 507 AliCDBEntry *drSpSDD = AliCDBManager::Instance()->Get("ITS/Calib/DriftSpeedSDD");
979b5a5f 508 AliCDBEntry *ddlMapSDD = AliCDBManager::Instance()->Get("ITS/Calib/DDLMapSDD");
2f8ed7ab 509 AliCDBEntry *hltforSDD = AliCDBManager::Instance()->Get("ITS/Calib/HLTforSDD");
62b93da7 510 // AliCDBEntry *mapASDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsAnodeSDD");
028a3709 511 AliCDBEntry *mapTSDD = AliCDBManager::Instance()->Get("ITS/Calib/MapsTimeSDD");
06232459 512
75065a60 513 if(!entrySDD || !entry2SDD || !drSpSDD || !ddlMapSDD || !hltforSDD || !mapTSDD ){
514 AliFatal("SDD Calibration object retrieval failed! ");
e8c4cf33 515 return kFALSE;
566f73ca 516 }
517
23197852 518
fcf95fc7 519
b17dae48 520 TObjArray *calSDD = (TObjArray *)entrySDD->GetObject();
6cae184e 521 if(!cacheStatus)entrySDD->SetObject(NULL);
8ba39da9 522 entrySDD->SetOwner(kTRUE);
fcf95fc7 523
524 AliITSresponseSDD *pSDD = (AliITSresponseSDD*)entry2SDD->GetObject();
6cae184e 525 if(!cacheStatus)entry2SDD->SetObject(NULL);
fcf95fc7 526 entry2SDD->SetOwner(kTRUE);
527
18da6e54 528 TObjArray *drSp = (TObjArray *)drSpSDD->GetObject();
529 if(!cacheStatus)drSpSDD->SetObject(NULL);
530 drSpSDD->SetOwner(kTRUE);
531
979b5a5f 532 AliITSDDLModuleMapSDD *ddlsdd=(AliITSDDLModuleMapSDD*)ddlMapSDD->GetObject();
533 if(!cacheStatus)ddlMapSDD->SetObject(NULL);
534 ddlMapSDD->SetOwner(kTRUE);
535
2f8ed7ab 536 AliITSHLTforSDD* hltsdd=(AliITSHLTforSDD*)hltforSDD->GetObject();
537 if(!cacheStatus)hltforSDD->SetObject(NULL);
538 hltforSDD->SetOwner(kTRUE);
539
2ebd5518 540// TObjArray *mapAn = (TObjArray *)mapASDD->GetObject();
541// if(!cacheStatus)mapASDD->SetObject(NULL);
542// mapASDD->SetOwner(kTRUE);
028a3709 543
544 TObjArray *mapT = (TObjArray *)mapTSDD->GetObject();
545 if(!cacheStatus)mapTSDD->SetObject(NULL);
546 mapTSDD->SetOwner(kTRUE);
547
75065a60 548
549 // DB entries are deleted. In this way metadeta objects are deleted as well
550 if(!cacheStatus){
551 delete entrySDD;
552 delete entry2SDD;
553 //delete mapASDD;
554 delete hltforSDD;
555 delete mapTSDD;
556 delete drSpSDD;
557 delete ddlMapSDD;
558 }
559
560 if ((!pSDD)||(!calSDD) || (!drSp) || (!ddlsdd) || (!hltsdd) || (!mapT) ){
561 AliWarning("Can not get SDD calibration from calibration database !");
562 return kFALSE;
563 }
564
565 fNMod[1] = calSDD->GetEntries();
566
567 fDDLMapSDD=ddlsdd;
568 fRespSDD=pSDD;
569 fIsHLTmodeC=hltsdd->IsHLTmodeC();
570 AliITSCalibration* cal;
571 Float_t avegain=0.;
572 Float_t nGdAnodes=0;
573 for(Int_t iddl=0; iddl<AliITSDDLModuleMapSDD::GetNDDLs(); iddl++){
574 for(Int_t icar=0; icar<AliITSDDLModuleMapSDD::GetNModPerDDL();icar++){
575 Int_t iMod=fDDLMapSDD->GetModuleNumber(iddl,icar);
576 if(iMod==-1) continue;
577 Int_t i=iMod - fgkDefaultNModulesSPD;
578 cal = (AliITSCalibration*) calSDD->At(i);
579 Int_t i0=2*i;
580 Int_t i1=1+2*i;
581 for(Int_t iAnode=0;iAnode< ((AliITSCalibrationSDD*)cal)->NOfAnodes(); iAnode++){
582 if(((AliITSCalibrationSDD*)cal)->IsBadChannel(iAnode)) continue;
583 avegain+= ((AliITSCalibrationSDD*)cal)->GetChannelGain(iAnode);
584 nGdAnodes++;
585 }
586 AliITSDriftSpeedArraySDD* arr0 = (AliITSDriftSpeedArraySDD*) drSp->At(i0);
587 // AliITSMapSDD* ma0 = (AliITSMapSDD*)mapAn->At(i0);
588 AliITSMapSDD* mt0 = (AliITSMapSDD*)mapT->At(i0);
589 AliITSDriftSpeedArraySDD* arr1 = (AliITSDriftSpeedArraySDD*) drSp->At(i1);
590 // AliITSMapSDD* ma1 = (AliITSMapSDD*)mapAn->At(i1);
591 AliITSMapSDD* mt1 = (AliITSMapSDD*)mapT->At(i1);
592 cal->SetDriftSpeed(0,arr0);
593 cal->SetDriftSpeed(1,arr1);
594// cal->SetMapA(0,ma0);
595// cal->SetMapA(1,ma1);
596 cal->SetMapT(0,mt0);
597 cal->SetMapT(1,mt1);
598 SetCalibrationModel(iMod, cal);
599 }
600 }
601 if(nGdAnodes) fAveGainSDD=avegain/nGdAnodes;
602 return kTRUE;
603}
604
605
606//______________________________________________________________________
607Bool_t AliITSDetTypeRec::GetCalibrationSSD(Bool_t cacheStatus) {
608 // Get SSD calibration objects from OCDB
609 // AliCDBEntry *entrySSD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSSD");
610
611 AliCDBEntry *entryNoiseSSD = AliCDBManager::Instance()->Get("ITS/Calib/NoiseSSD");
612 AliCDBEntry *entryGainSSD = AliCDBManager::Instance()->Get("ITS/Calib/GainSSD");
613 AliCDBEntry *entryBadChannelsSSD = AliCDBManager::Instance()->Get("ITS/Calib/BadChannelsSSD");
614
615 if(!entryNoiseSSD || !entryGainSSD || !entryBadChannelsSSD){
616 AliFatal("SSD Calibration object retrieval failed! ");
617 return kFALSE;
618 }
619
88128115 620 TObject *emptyssd = 0; TString ssdobjectname = 0;
621 AliITSNoiseSSDv2 *noiseSSD = new AliITSNoiseSSDv2();
622 emptyssd = (TObject *)entryNoiseSSD->GetObject();
623 ssdobjectname = emptyssd->GetName();
624 if(ssdobjectname=="TObjArray") {
625 TObjArray *noiseSSDOld = (TObjArray *)entryNoiseSSD->GetObject();
626 ReadOldSSDNoise(noiseSSDOld, noiseSSD);
627 }
628 else if(ssdobjectname=="AliITSNoiseSSDv2")
629 noiseSSD = (AliITSNoiseSSDv2 *)entryNoiseSSD->GetObject();
fb4dfab9 630 if(!cacheStatus)entryNoiseSSD->SetObject(NULL);
631 entryNoiseSSD->SetOwner(kTRUE);
632
88128115 633 AliITSGainSSDv2 *gainSSD = new AliITSGainSSDv2();
634 emptyssd = (TObject *)entryGainSSD->GetObject();
635 ssdobjectname = emptyssd->GetName();
636 if(ssdobjectname=="Gain") {
637 TObjArray *gainSSDOld = (TObjArray *)entryGainSSD->GetObject();
638 ReadOldSSDGain(gainSSDOld, gainSSD);
639 }
640 else if(ssdobjectname=="AliITSGainSSDv2")
641 gainSSD = (AliITSGainSSDv2 *)entryGainSSD->GetObject();
fb4dfab9 642 if(!cacheStatus)entryGainSSD->SetObject(NULL);
643 entryGainSSD->SetOwner(kTRUE);
644
88128115 645 AliITSBadChannelsSSDv2 *badChannelsSSD = new AliITSBadChannelsSSDv2();
646 emptyssd = (TObject *)entryBadChannelsSSD->GetObject();
647 ssdobjectname = emptyssd->GetName();
648 if(ssdobjectname=="TObjArray") {
649 TObjArray *badChannelsSSDOld = (TObjArray *)entryBadChannelsSSD->GetObject();
650 ReadOldSSDBadChannels(badChannelsSSDOld, badChannelsSSD);
651 }
652 else if(ssdobjectname=="AliITSBadChannelsSSDv2")
653 badChannelsSSD = (AliITSBadChannelsSSDv2*)entryBadChannelsSSD->GetObject();
fb4dfab9 654 if(!cacheStatus)entryBadChannelsSSD->SetObject(NULL);
655 entryBadChannelsSSD->SetOwner(kTRUE);
fcf95fc7 656
b17dae48 657 // DB entries are deleted. In this way metadeta objects are deleted as well
6cae184e 658 if(!cacheStatus){
fb4dfab9 659 delete entryNoiseSSD;
660 delete entryGainSSD;
661 delete entryBadChannelsSSD;
b17dae48 662 }
06232459 663
75065a60 664 if ((!noiseSSD)|| (!gainSSD)|| (!badChannelsSSD)) {
665 AliWarning("Can not get SSD calibration from calibration database !");
8ba39da9 666 return kFALSE;
667 }
fcf95fc7 668
ced4d9bc 669 fSSDCalibration->SetNoise(noiseSSD);
ced4d9bc 670 fSSDCalibration->SetGain(gainSSD);
88128115 671 fSSDCalibration->SetBadChannels(badChannelsSSD);
ced4d9bc 672 //fSSDCalibration->FillBadChipMap();
673
8ba39da9 674 return kTRUE;
675}
676
7d62fb64 677//________________________________________________________________
3a7c3e6d 678void AliITSDetTypeRec::SetDefaultClusterFindersV2(Bool_t rawdata){
7d62fb64 679
680 //Set defaults for cluster finder V2
681
8e50d897 682 if(!GetITSgeom()){
683 Warning("SetDefaults","Null pointer to AliITSgeom !");
7d62fb64 684 return;
685 }
686
7d62fb64 687 AliITSClusterFinder *clf;
688
3a7c3e6d 689 for(Int_t dettype=0;dettype<fgkNdettypes;dettype++){
7d62fb64 690 //SPD
691 if(dettype==0){
692 if(!GetReconstructionModel(dettype)){
8ba39da9 693 clf = new AliITSClusterFinderV2SPD(this);
7d62fb64 694 clf->InitGeometry();
3a7c3e6d 695 if(!rawdata) clf->SetDigits(DigitsAddress(0));
7d62fb64 696 SetReconstructionModel(dettype,clf);
697
698 }
699 }
700 //SDD
701 if(dettype==1){
702 if(!GetReconstructionModel(dettype)){
8ba39da9 703 clf = new AliITSClusterFinderV2SDD(this);
704 clf->InitGeometry();
3a7c3e6d 705 if(!rawdata) clf->SetDigits(DigitsAddress(1));
7d62fb64 706 SetReconstructionModel(dettype,clf);
707 }
708
709 }
710
711 //SSD
712 if(dettype==2){
713 if(!GetReconstructionModel(dettype)){
8ba39da9 714 clf = new AliITSClusterFinderV2SSD(this);
7d62fb64 715 clf->InitGeometry();
3a7c3e6d 716 if(!rawdata) clf->SetDigits(DigitsAddress(2));
7d62fb64 717 SetReconstructionModel(dettype,clf);
718 }
719 }
720
721 }
722
723}
724//______________________________________________________________________
6cae184e 725void AliITSDetTypeRec::MakeBranch(TTree* tree, Option_t* option){
7d62fb64 726
727 //Creates branches for clusters and recpoints
728 Bool_t cR = (strstr(option,"R")!=0);
729 Bool_t cRF = (strstr(option,"RF")!=0);
7d62fb64 730
731 if(cRF)cR = kFALSE;
732
6cae184e 733 if(cR) MakeBranchR(tree);
734 if(cRF) MakeBranchRF(tree);
7d62fb64 735
736}
737
7d62fb64 738//___________________________________________________________________
739void AliITSDetTypeRec::ResetDigits(){
740 // Reset number of digits and the digits array for the ITS detector.
741
742 if(!fDigits) return;
743 for(Int_t i=0;i<fgkNdettypes;i++){
744 ResetDigits(i);
745 }
746}
747//___________________________________________________________________
748void AliITSDetTypeRec::ResetDigits(Int_t branch){
749 // Reset number of digits and the digits array for this branch.
750
751 if(fDigits->At(branch)) ((TClonesArray*)fDigits->At(branch))->Clear();
752 if(fNdtype) fNdtype[branch]=0;
753
754}
755
756//__________________________________________________________________
757void AliITSDetTypeRec::ResetClusters(){
758
759 //Resets number of clusters and the cluster array
760 for(Int_t i=0;i<fgkNdettypes;i++){
761 ResetClusters(i);
762 }
763}
764
765//__________________________________________________________________
766void AliITSDetTypeRec::ResetClusters(Int_t i){
767
768 //Resets number of clusters and the cluster array for this branch
769
770 if (fCtype->At(i)) ((TClonesArray*)fCtype->At(i))->Clear();
771 if (fNctype) fNctype[i]=0;
772}
773//__________________________________________________________________
6cae184e 774void AliITSDetTypeRec::MakeBranchR(TTree *treeR, Option_t *opt){
7d62fb64 775
776 //Creates tree branches for recpoints
777 // Inputs:
778 // cont char *file File name where RecPoints branch is to be written
779 // to. If blank it write the SDigits to the same
780 // file in which the Hits were found.
781
7d62fb64 782 Int_t buffsz = 4000;
783 char branchname[30];
784
785 // only one branch for rec points for all detector types
786 Bool_t oFast= (strstr(opt,"Fast")!=0);
7d62fb64 787
788 Char_t detname[10] = "ITS";
789
790
791 if(oFast){
792 sprintf(branchname,"%sRecPointsF",detname);
7d62fb64 793 } else {
794 sprintf(branchname,"%sRecPoints",detname);
795 }
796
00a7cc50 797 if(!fRecPoints)fRecPoints = new TClonesArray("AliITSRecPoint",1000);
6cae184e 798 if (treeR)
799 MakeBranchInTree(treeR,branchname,0,&fRecPoints,buffsz,99);
7d62fb64 800}
801//______________________________________________________________________
802void AliITSDetTypeRec::SetTreeAddressR(TTree *treeR){
803 // Set branch address for the Reconstructed points Trees.
3b9df642 804 // Inputs:
7d62fb64 805 // TTree *treeR Tree containing the RecPoints.
3b9df642 806 // Outputs:
7d62fb64 807 // none.
3b9df642 808 // Return:
7d62fb64 809
810 char branchname[30];
811 Char_t namedet[10]="ITS";
812
813 if(!treeR) return;
814 if(fRecPoints==0x0) fRecPoints = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 815 TBranch *branch;
816 sprintf(branchname,"%sRecPoints",namedet);
817 branch = treeR->GetBranch(branchname);
818 if (branch) {
819 branch->SetAddress(&fRecPoints);
820 }else {
821 sprintf(branchname,"%sRecPointsF",namedet);
7d62fb64 822 branch = treeR->GetBranch(branchname);
823 if (branch) {
00a7cc50 824 branch->SetAddress(&fRecPoints);
7d62fb64 825 }
00a7cc50 826
7d62fb64 827 }
3b9df642 828}
7d62fb64 829//____________________________________________________________________
830void AliITSDetTypeRec::AddRecPoint(const AliITSRecPoint &r){
831 // Add a reconstructed space point to the list
832 // Inputs:
833 // const AliITSRecPoint &r RecPoint class to be added to the tree
834 // of reconstructed points TreeR.
835 // Outputs:
836 // none.
837 // Return:
838 // none.
839
840 TClonesArray &lrecp = *fRecPoints;
841 new(lrecp[fNRecPoints++]) AliITSRecPoint(r);
842}
7d62fb64 843
844//______________________________________________________________________
5d2c2f86 845void AliITSDetTypeRec::DigitsToRecPoints(TTree *treeD,TTree *treeR,Int_t lastentry,Option_t *opt, Int_t optCluFind){
7d62fb64 846 // cluster finding and reconstruction of space points
847 // the condition below will disappear when the geom class will be
848 // initialized for all versions - for the moment it is only for v5 !
849 // 7 is the SDD beam test version
850 // Inputs:
6cae184e 851 // TTree *treeD Digits tree
852 // TTree *treeR Clusters tree
7d62fb64 853 // Int_t lastentry Offset for module when not all of the modules
854 // are processed.
855 // Option_t *opt String indicating which ITS sub-detectors should
856 // be processed. If ="All" then all of the ITS
857 // sub detectors are processed.
858
7d62fb64 859 const char *all = strstr(opt,"All");
860 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
861 strstr(opt,"SSD")};
5d2c2f86 862 if(optCluFind==0){
00a7cc50 863 SetDefaultClusterFindersV2();
864 AliInfo("V2 cluster finder has been selected \n");
5d2c2f86 865 }else{
866 SetDefaultClusterFindersV2();
867 AliInfo("Cluster Finder Option not implemented, V2 cluster finder will be udes \n");
00a7cc50 868 }
7d62fb64 869
7d62fb64 870 AliITSClusterFinder *rec = 0;
871 Int_t id,module,first=0;
8e50d897 872 for(module=0;module<GetITSgeom()->GetIndexMax();module++){
873 id = GetITSgeom()->GetModuleType(module);
7d62fb64 874 if (!all && !det[id]) continue;
8e50d897 875 if(det[id]) first = GetITSgeom()->GetStartDet(id);
7d62fb64 876 rec = (AliITSClusterFinder*)GetReconstructionModel(id);
877 TClonesArray *itsDigits = DigitsAddress(id);
6cae184e 878 if (!rec)
879 AliFatal("The reconstruction class was not instanciated!");
5e5bc8f1 880 ResetDigits(); // MvL: Not sure we neeed this when rereading anyways
7d62fb64 881 if (all) {
6cae184e 882 treeD->GetEvent(lastentry+module);
7d62fb64 883 }else {
6cae184e 884 treeD->GetEvent(lastentry+(module-first));
7d62fb64 885 }
886 Int_t ndigits = itsDigits->GetEntriesFast();
887 if(ndigits>0){
888 rec->SetDetTypeRec(this);
7d62fb64 889 rec->SetDigits(DigitsAddress(id));
6cae184e 890 // rec->SetClusters(ClustersAddress(id));
7d62fb64 891 rec->FindRawClusters(module);
892 } // end if
6cae184e 893 treeR->Fill();
7d62fb64 894 ResetRecPoints();
7d62fb64 895 ResetClusters();
896 }
7d62fb64 897}
898//______________________________________________________________________
8484b32d 899void AliITSDetTypeRec::DigitsToRecPoints(AliRawReader* rawReader,TTree *treeR,Option_t *opt){
7d62fb64 900 // cluster finding and reconstruction of space points
901 // the condition below will disappear when the geom class will be
902 // initialized for all versions - for the moment it is only for v5 !
903 // 7 is the SDD beam test version
904 // Inputs:
6cae184e 905 // AliRawReader *rawReader Pointer to the raw-data reader
906 // TTree *treeR Clusters tree
7d62fb64 907 // Outputs:
908 // none.
909 // Return:
910 // none.
8484b32d 911 const char *all = strstr(opt,"All");
912 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
913 strstr(opt,"SSD")};
5d2c2f86 914 AliITSClusterFinder *rec = 0;
7d62fb64 915 Int_t id=0;
916
00a7cc50 917 TClonesArray *array=new TClonesArray("AliITSRecPoint",1000);
6cae184e 918 TBranch *branch = treeR->Branch("ITSRecPoints",&array);
7d62fb64 919 delete array;
920
8e50d897 921 TClonesArray** clusters = new TClonesArray*[GetITSgeom()->GetIndexMax()];
922 for (Int_t iModule = 0; iModule < GetITSgeom()->GetIndexMax(); iModule++) {
7d62fb64 923 clusters[iModule] = NULL;
924 }
925 for(id=0;id<3;id++){
8484b32d 926 if (!all && !det[id]) continue;
5d2c2f86 927 rec = (AliITSClusterFinder*)GetReconstructionModel(id);
c157c94e 928 if (!rec)
ff44c37c 929 AliFatal("The reconstruction class was not instantiated");
6cae184e 930 rec->SetDetTypeRec(this);
7d62fb64 931 rec->RawdataToClusters(rawReader,clusters);
932 }
933 Int_t nClusters =0;
c157c94e 934 TClonesArray *emptyArray=new TClonesArray("AliITSRecPoint");
8e50d897 935 for(Int_t iModule=0;iModule<GetITSgeom()->GetIndexMax();iModule++){
8484b32d 936 id = GetITSgeom()->GetModuleType(iModule);
937 if (!all && !det[id]) continue;
7d62fb64 938 array = clusters[iModule];
939 if(!array){
c157c94e 940 AliDebug(1,Form("data for module %d missing!",iModule));
941 array = emptyArray;
7d62fb64 942 }
6cae184e 943 branch->SetAddress(&array);
944 treeR->Fill();
7d62fb64 945 nClusters+=array->GetEntriesFast();
5ef4644f 946
947 if (array != emptyArray) {
948 array->Delete();
949 delete array;
950 }
7d62fb64 951 }
c157c94e 952 delete emptyArray;
953
7d62fb64 954 delete[] clusters;
00a7cc50 955 Info("DigitsToRecPoints", "total number of found recpoints in ITS: %d\n",
7d62fb64 956 nClusters);
957
958}
959
88128115 960//______________________________________________________________________
961void AliITSDetTypeRec::ReadOldSSDNoise(TObjArray *array,
962 AliITSNoiseSSDv2 *noiseSSD) {
963 //Reads the old SSD calibration object and converts it to the new format
964 const Int_t fgkSSDSTRIPSPERMODULE = 1536;
965 const Int_t fgkSSDPSIDESTRIPSPERMODULE = 768;
966
3dd31ed2 967 Int_t gNMod = array->GetEntries();
88128115 968 cout<<"Converting old calibration object for noise..."<<endl;
969
970 //NOISE
971 Double_t noise = 0.0;
3dd31ed2 972 for (Int_t iModule = 0; iModule < gNMod; iModule++) {
88128115 973 AliITSNoiseSSD *noiseModule = (AliITSNoiseSSD*) (array->At(iModule));
974 for(Int_t iStrip = 0; iStrip < fgkSSDSTRIPSPERMODULE; iStrip++) {
975 noise = (iStrip < fgkSSDPSIDESTRIPSPERMODULE) ? noiseModule->GetNoiseP(iStrip) : noiseModule->GetNoiseN(1535 - iStrip);
976 if(iStrip < fgkSSDPSIDESTRIPSPERMODULE)
977 noiseSSD->AddNoiseP(iModule,iStrip,noise);
978 if(iStrip >= fgkSSDPSIDESTRIPSPERMODULE)
979 noiseSSD->AddNoiseN(iModule,1535 - iStrip,noise);
980 }//loop over strips
981 }//loop over modules
982}
983
984//______________________________________________________________________
985void AliITSDetTypeRec::ReadOldSSDBadChannels(TObjArray *array,
986 AliITSBadChannelsSSDv2 *badChannelsSSD) {
987 //Reads the old SSD calibration object and converts it to the new format
3dd31ed2 988 Int_t gNMod = array->GetEntries();
88128115 989 cout<<"Converting old calibration object for bad channels..."<<endl;
3dd31ed2 990 for (Int_t iModule = 0; iModule < gNMod; iModule++) {
88128115 991 //for (Int_t iModule = 0; iModule < 1; iModule++) {
992 AliITSBadChannelsSSD *bad = (AliITSBadChannelsSSD*) (array->At(iModule));
993 TArrayI arrayPSide = bad->GetBadPChannelsList();
994 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
995 badChannelsSSD->AddBadChannelP(iModule,
996 iPCounter,
997 (Char_t)arrayPSide.At(iPCounter));
998
999 TArrayI arrayNSide = bad->GetBadNChannelsList();
1000 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
1001 badChannelsSSD->AddBadChannelN(iModule,
1002 iNCounter,
1003 (Char_t)arrayNSide.At(iNCounter));
1004
1005 }//loop over modules
1006}
1007
1008//______________________________________________________________________
1009void AliITSDetTypeRec::ReadOldSSDGain(TObjArray *array,
1010 AliITSGainSSDv2 *gainSSD) {
1011 //Reads the old SSD calibration object and converts it to the new format
1012
3dd31ed2 1013 Int_t gNMod = array->GetEntries();
88128115 1014 cout<<"Converting old calibration object for gain..."<<endl;
1015
1016 //GAIN
3dd31ed2 1017 for (Int_t iModule = 0; iModule < gNMod; iModule++) {
88128115 1018 AliITSGainSSD *gainModule = (AliITSGainSSD*) (array->At(iModule));
1019 TArrayF arrayPSide = gainModule->GetGainP();
1020 for(Int_t iPCounter = 0; iPCounter < arrayPSide.GetSize(); iPCounter++)
1021 gainSSD->AddGainP(iModule,
1022 iPCounter,
1023 arrayPSide.At(iPCounter));
1024 TArrayF arrayNSide = gainModule->GetGainN();
1025 for(Int_t iNCounter = 0; iNCounter < arrayNSide.GetSize(); iNCounter++)
1026 gainSSD->AddGainN(iModule,
1027 iNCounter,
1028 arrayNSide.At(iNCounter));
1029 }//loop over modules
1030}
1031
8ba39da9 1032