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