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