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