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