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