]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITS.cxx
Memory leak in Raw2SDigits - Savannah bug 70587
[u/mrichter/AliRoot.git] / ITS / AliITS.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors 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 /* $Id$ */
17
18
19 ///////////////////////////////////////////////////////////////////////////////
20 //                                                                           //
21 //      An overview of the basic philosophy of the ITS code development      //
22 // and analysis is show in the figure below.                                 //
23 //Begin_Html                                                                 //
24 /*                                               
25 <img src="picts/ITS/ITS_Analysis_schema.gif">
26 </pre>
27 <br clear=left>
28 <font size=+2 color=red>
29 <p>Roberto Barbera is in charge of the ITS Offline code (1999).
30 <a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
31 </font>
32 <pre>
33 */
34 //End_Html
35 //
36 //  AliITS. Inner Traking System base class.
37 //  This class contains the base procedures for the Inner Tracking System
38 //
39 //Begin_Html
40 /*
41 <img src="picts/ITS/AliITS_Class_Diagram.gif">
42 </pre>
43 <br clear=left>
44 <font size=+2 color=red>
45 <p>This show the class diagram of the different elements that are part of
46 the AliITS class.
47 </font>
48 <pre>
49 */
50 //End_Html
51 //
52 // Version: 0
53 // Written by Rene Brun, Federico Carminati, and Roberto Barbera
54 //
55 // Version: 1
56 // Modified and documented by Bjorn S. Nilsen
57 // July 11 1999
58 //
59 // Version: 2
60 // Modified and documented by A. Bologna
61 // October 18 1999
62 //
63 // AliITS is the general base class for the ITS. Also see AliDetector for
64 // futher information.
65 //
66 ///////////////////////////////////////////////////////////////////////////////
67
68 #include <stdlib.h>
69 #include <TClonesArray.h>
70 #include <TFile.h>
71 #include <TParticle.h>
72 #include <TString.h>
73 #include <TTree.h>
74 #include <TVirtualMC.h>
75 #include "AliDetector.h"
76 #include "AliITS.h"
77 #include "AliITSDetTypeSim.h"
78 #include "AliITSDDLRawData.h"
79 #include "AliITSLoader.h"
80 #include "AliITShit.h"
81 #include "AliITSmodule.h"
82 #include "AliITSpListItem.h"
83 #include "AliITSsimulation.h"
84 #include "AliITSsimulationFastPoints.h"
85 #include "AliMC.h"
86 #include "AliITSDigitizer.h"
87 #include "AliITSRecPoint.h"
88 #include "AliITSsegmentationSPD.h"
89 #include "AliITSsegmentationSDD.h"
90 #include "AliITSsimulationSDD.h"
91 #include "AliITSCalibrationSDD.h"
92 #include "AliITSCalibrationSSD.h"
93 #include "AliITSsegmentationSSD.h"
94 #include "AliITSRawStreamSPD.h"
95 #include "AliITSRawStreamSSD.h"
96 #include "AliITSRawStreamSDD.h"
97 #include "AliRawReader.h"
98 #include "AliRun.h"
99 #include "AliLog.h"
100 #include "AliITSInitGeometry.h"
101 #include "AliITSFOSignalsSPD.h"
102
103 ClassImp(AliITS)
104
105 //______________________________________________________________________
106 AliITS::AliITS() : AliDetector(),
107 fDetTypeSim(0),
108 fEuclidOut(0),
109 fOpt("All"),
110 fIdN(0),
111 fIdSens(0),
112 fIdName(0),
113 fITSmodules(0),
114 fTiming(kFALSE),
115 fSimuParam(0),
116 fModA(0),
117 fpSDigits(0)
118 {
119   // Default initializer for ITS
120   //      The default constructor of the AliITS class. In addition to
121   // creating the AliITS class it zeros the variables fIshunt (a member
122   // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
123   // fIdSens, and fIdName. The AliDetector default constructor
124   // is also called.
125   
126 //    SetDetectors(); // default to fOpt="All". This variable not written out.
127 //PH    SetMarkerColor(kRed);
128 }
129 //______________________________________________________________________
130 AliITS::AliITS(const Char_t *title):
131   AliDetector("ITS",title),
132   fDetTypeSim(0),
133   fEuclidOut(0),
134   fOpt("All"),
135   fIdN(0),
136   fIdSens(0),
137   fIdName(0),
138   fITSmodules(0),
139   fTiming(kFALSE),
140   fSimuParam(0),
141   fModA(0),
142   fpSDigits(0)
143 {
144     //     The standard Constructor for the ITS class. 
145     // It also zeros the variables
146     // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
147     // the pointers fIdSens and fIdName. To help in displaying hits via the
148     // ROOT macro display.C AliITS also sets the marker color to red. The
149     // variables passes with this constructor, const char *name and *title,
150     // are used by the constructor of AliDetector class. See AliDetector
151     // class for a description of these parameters and its constructor
152     // functions.
153     // Inputs:
154     //   Char_t *title  Simulation title for the ITS
155     // Outputs:
156     //   none.
157     // Return:
158     //   none.
159   
160     fHits = new TClonesArray("AliITShit",1560); // from AliDetector
161     if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
162     //fNhits=0;  //done in AliDetector(name,title)
163     SetDetectors(); // default to fOpt="All". This variable not written out.
164     fDetTypeSim   = new AliITSDetTypeSim();
165     //PH  SetMarkerColor(kRed);
166     if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
167     fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
168 }
169 //______________________________________________________________________
170 AliITS::AliITS(const char *name, const char *title):
171   AliDetector(name,title),
172   fDetTypeSim(0),
173   fEuclidOut(0),
174   fOpt("All"),
175   fIdN(0),
176   fIdSens(0),
177   fIdName(0),
178   fITSmodules(0),
179   fTiming(kFALSE),
180   fSimuParam(0),
181   fModA(0),
182   fpSDigits(0)
183 {
184   //     The standard Constructor for the ITS class. 
185   // It also zeros the variables
186   // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
187   // the pointers fIdSens and fIdName. To help in displaying hits via the
188   // ROOT macro display.C AliITS also sets the marker color to red. The
189   // variables passes with this constructor, const char *name and *title,
190   // are used by the constructor of AliDetector class. See AliDetector
191   // class for a description of these parameters and its constructor
192   // functions.
193   
194   fHits = new TClonesArray("AliITShit",1560);
195   if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
196   //fNhits=0;  //done in AliDetector(name,title)
197
198   SetDetectors(); // default to fOpt="All". This variable not written out.
199     
200   fDetTypeSim   = new AliITSDetTypeSim();
201   //PH  SetMarkerColor(kRed);
202   if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
203   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
204
205 }
206 //______________________________________________________________________
207 AliITS::~AliITS(){
208     // Default destructor for ITS.
209     //     The default destructor of the AliITS class. In addition to deleting
210     // the AliITS class it deletes the memory pointed to by 
211     // fIdSens, fIdName, fDetTypeSim and it's contents.
212     // Inputs:
213     //      none.
214     // Outputs:
215     //      none.
216     // Return:
217     //      none.
218
219     if (fHits) {
220       fHits->Delete();
221       delete fHits;
222       fHits=0;
223     }
224     if(fITSmodules) {
225         this->ClearModules();
226         delete fITSmodules;
227         fITSmodules = 0;
228     }// end if fITSmodules!=0
229
230     delete[] fIdName;  // Array of TStrings
231     delete[] fIdSens;
232     Int_t size   = 0;
233     if (fDetTypeSim){
234       size = GetITSgeom()->GetIndexMax();
235       delete fDetTypeSim;
236       fDetTypeSim = 0;
237     }
238     if(fSimuParam){
239       delete fSimuParam;
240       fSimuParam=0;
241     }
242     if(fModA){
243       if(size>0){
244         for(Int_t j=0; j<size; j++){
245           fModA[j]->Delete();
246           delete fModA[j];
247         }
248       }
249       delete []fModA;
250     }
251     if(fpSDigits){
252       fpSDigits->Delete();
253       delete fpSDigits;
254     }
255 }
256 //______________________________________________________________________
257 AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
258     // Creates the AliITSDigitizer in a standard way for use via AliModule.
259     // This function can not be included in the .h file because of problems
260     // with the order of inclusion (recursive).
261     // Inputs:
262     //    AliRunDigitizer *manager  The Manger class for Digitization
263     // Output:
264     //    none.
265     // Return:
266     //    A new AliITSRunDigitizer (cast as a AliDigitizer).
267
268      return new AliITSDigitizer(manager);
269 }
270 //______________________________________________________________________
271 void AliITS::Init(){
272     // Initializer ITS after it has been built
273     //     This routine initializes the AliITS class. It is intended to be
274     // called from the Init function in AliITSv?. Besides displaying a banner
275     // indicating that it has been called it initializes the array fIdSens
276     // and sets the default segmentation, response, digit and raw cluster
277     // classes therefore it should be called after a call to CreateGeometry.
278     // Inputs:
279     //      none.
280     // Outputs:
281     //      none.
282     // Return:
283     //      none.
284     Int_t i;
285     // Array of TStrings
286     if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
287  
288 }
289 //______________________________________________________________________
290 void AliITS::SetDefaults(){
291     // sets the default segmentation, response, digit and raw cluster classes.
292     // Inputs:
293     //      none.
294     // Outputs:
295     //      none.
296     // Return:
297     //      none.
298     AliInfoClass("AliITS::Setting Defaults");
299     if(!fDetTypeSim) { 
300      Error("SetDefaults()","fDetTypeSim is 0!"); 
301      return;
302     }
303
304     fDetTypeSim->SetDefaults();
305     if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
306
307 }
308 //______________________________________________________________________
309 void AliITS::SetDefaultSimulation(){
310     // sets the default simulation.
311     // Inputs:
312     //      none.
313     // Outputs:
314     //      none.
315     // Return:
316     //      none.
317     if(!fDetTypeSim) { 
318      Error("SetDefaultSimulation()","fDetTypeSim is 0!"); 
319      return;
320     }
321
322     fDetTypeSim->SetDefaultSimulation();
323     if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
324
325 }
326
327
328 //______________________________________________________________________
329 void AliITS::MakeBranch(Option_t* option){
330     // Creates Tree branches for the ITS.
331     // Inputs:
332     //      Option_t *option    String of Tree types S,D, and/or R.
333     //      const char *file    String of the file name where these branches
334     //                          are to be stored. If blank then these branches
335     //                          are written to the same tree as the Hits were
336     //                          read from.
337     // Outputs:
338     //      none.
339     // Return:
340     //      none.
341   if(!fDetTypeSim) {
342     Error("MakeBranch","fDetTypeSim is 0!");
343     return;
344   }
345
346   Bool_t cH = (strstr(option,"H")!=0);
347   Bool_t cS = (strstr(option,"S")!=0);
348   Bool_t cD = (strstr(option,"D")!=0);
349   
350   if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
351   AliDetector::MakeBranch(option);
352   
353   if(cS) MakeBranchS(0);
354   if(cD) MakeBranchD(0);
355
356
357 }
358 //___________________________________________________________________
359 void AliITS::MakeBranchS(const char* fl){
360
361   // Creates Tree Branch for the ITS summable digits.
362   // Inputs:
363   //      cont char *fl  File name where SDigits branch is to be written
364   //                     to. If blank it write the SDigits to the same
365   //                     file in which the Hits were found.
366
367   
368   if(!fDetTypeSim){
369     Error("MakeBranchS","fDetTypeSim is 0!");
370   }
371   Int_t buffersize = 4000;
372   char branchname[30];
373
374   // only one branch for SDigits.
375   sprintf(branchname,"%s",GetName());
376
377   if(fLoader->TreeS()){
378     TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
379     MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
380   } 
381 }
382 //______________________________________________________________________
383 void AliITS::MakeBranchD(const char* file){
384
385   //Make branch for digits
386   if(!fDetTypeSim) {
387     Warning("MakeBranchD","fDetTypeSim is 0!");
388     return;
389   }
390   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
391   if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
392   MakeBranchInTreeD(fLoader->TreeD(),file);
393 }
394
395 //___________________________________________________________________
396 void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
397   // Creates Tree branches for the ITS.
398
399   if(!fDetTypeSim){
400     Error("MakeBranchS","fDetTypeSim is 0!");
401   }
402   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
403   if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
404
405   const Char_t *det[3] = {"SPD","SDD","SSD"};
406   const Char_t* digclass;
407   Int_t buffersize = 4000;
408   Char_t branchname[30];
409   
410   if(!fDetTypeSim->GetDigits()){
411     fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
412   }
413   for(Int_t i=0;i<fgkNTYPES;i++){
414     digclass = fDetTypeSim->GetDigitClassName(i);
415     TString classn = digclass;
416     if(!((fDetTypeSim->GetDigits())->At(i))){
417       (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
418     }
419     else ResetDigits(i);  
420     if(fgkNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
421     else sprintf(branchname,"%sDigits%d",GetName(),i+1);
422     TObjArray* dig = DigitsAddress(i);
423     if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
424   }
425
426 }
427 //______________________________________________________________________
428 void AliITS::SetTreeAddress(){
429     // Set branch address for the Trees.
430     // Inputs:
431     //      none.
432     // Outputs:
433     //      none.
434     // Return:
435     //      none.
436     
437   if(!fDetTypeSim) {
438     Error("SetTreeAddress","fDetTypeSim is 0!");
439     return;
440   }
441
442   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
443   if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
444
445   TTree *treeS = fLoader->TreeS();
446   TTree *treeD = fLoader->TreeD();
447   if (fLoader->TreeH() && (fHits == 0x0)) {
448       fHits = new TClonesArray("AliITShit", 1560);
449   }
450   AliDetector::SetTreeAddress();
451
452   fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
453   fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
454 }
455 //______________________________________________________________________
456 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
457     // Add an ITS hit
458     //     The function to add information to the AliITShit class. See the
459     // AliITShit class for a full description. This function allocates the
460     // necessary new space for the hit information and passes the variable
461     // track, and the pointers *vol and *hits to the AliITShit constructor
462     // function.
463     // Inputs:
464     //      Int_t   track   Track number which produced this hit.
465     //      Int_t   *vol    Array of Integer Hit information. See AliITShit.h
466     //      Float_t *hits   Array of Floating Hit information.  see AliITShit.h
467     // Outputs:
468     //      none.
469     // Return:
470     //      none.
471   TClonesArray &lhits = *fHits;
472   new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
473 }
474
475 //______________________________________________________________________
476 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
477                          Option_t *option, const char *filename){
478   // fill the modules with the sorted by module hits; add hits from
479   // background if option=Add.
480
481   static TTree *trH1;                 //Tree with background hits
482   static Bool_t first=kTRUE;
483   static TFile *file;
484   const char *addBgr = strstr(option,"Add");
485   
486   evnt = nmodules; // Dummy use of variables to remove warnings
487   if (addBgr ) {
488     if(first) {
489       file=new TFile(filename);
490     } // end if first
491     first=kFALSE;
492     file->cd();
493     file->ls();
494     // Get Hits Tree header from file
495     if(trH1) delete trH1;
496     trH1=0;
497     
498     char treeName[20];
499     sprintf(treeName,"TreeH%d",bgrev);
500     trH1 = (TTree*)gDirectory->Get(treeName);
501     if (!trH1) {
502       Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
503     } // end if !trH1
504     // Set branch addresses
505   } // end if addBgr
506   
507   FillModules(fLoader->TreeH(),0); // fill from this file's tree.
508     
509   if (addBgr ) {
510     FillModules(trH1,10000000); // Default mask 10M.
511     TTree *fAli=fLoader->GetRunLoader()->TreeK();
512     TFile *fileAli=0;
513     if (fAli) fileAli =fAli->GetCurrentFile();
514     fileAli->cd();
515   } // end if add
516   
517   
518 }
519 //______________________________________________________________________
520 void AliITS::FillModules(TTree *treeH, Int_t mask) {
521     // fill the modules with the sorted by module hits; 
522     // can be called many times to do a merging
523     // Inputs:
524     //      TTree *treeH  The tree containing the hits to be copied into
525     //                    the modules.
526     //      Int_t mask    The track number mask to indecate which file
527     //                    this hits came from.
528     // Outputs:
529     //      none.
530     // Return:
531     //      none.
532
533     if (treeH == 0x0)
534      {
535        Error("FillModules","Tree is NULL");
536      }
537     Int_t lay,lad,det,index;
538     AliITShit *itsHit=0;
539     AliITSmodule *mod=0;
540     char branchname[20];
541     sprintf(branchname,"%s",GetName());
542     TBranch *branch = treeH->GetBranch(branchname);
543     if (!branch) {
544         Error("FillModules","%s branch in TreeH not found",branchname);
545         return;
546     } // end if !branch
547     branch->SetAddress(&fHits);
548     Int_t nTracks =(Int_t) treeH->GetEntries();
549     Int_t iPrimTrack,h;
550     for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
551         ResetHits();
552         Int_t nBytes = treeH->GetEvent(iPrimTrack);
553         if (nBytes <= 0) continue;
554         Int_t nHits = fHits->GetEntriesFast();
555         for(h=0; h<nHits; h++){
556             itsHit = (AliITShit *)fHits->UncheckedAt(h);
557             itsHit->GetDetectorID(lay,lad,det);
558             if (GetITSgeom()) {
559                 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
560             } else {
561                 index=det-1; // This should not be used.
562             } // end if [You must have fITSgeom for this to work!]
563             mod = GetModule(index);
564             itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
565             mod->AddHit(itsHit,iPrimTrack,h);
566         } // end loop over hits 
567     } // end loop over tracks
568 }
569
570 //______________________________________________________________________
571 Bool_t AliITS::InitModules(Int_t size,Int_t &nmodules){
572     // Initialize the modules array.
573     // Inputs:
574     //      Int_t size  Size of array of the number of modules to be
575     //                  created. If size <=0 then the number of modules
576     //                  is gotten from AliITSgeom class kept in fITSgeom.
577     // Outputs:
578     //      Int_t &nmodules The number of modules existing.
579     // Return:
580     //      none.
581
582     if(fITSmodules){ 
583         fITSmodules->Delete();
584         delete fITSmodules;
585     } // end fir fITSmoudles
586
587     if(!fDetTypeSim) {
588       Error("InitModules","fDetTypeSim is null!");
589       return kFALSE;
590     }
591     if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
592
593     Int_t nl,indexMAX,index;
594
595     if(size<=0){ // default to using data stored in AliITSgeom
596         if(fDetTypeSim->GetITSgeom()==0) {
597             Error("InitModules","fITSgeom not defined");
598             return kFALSE;
599         } // end if fITSgeom==0
600         nl = fDetTypeSim->GetITSgeom()->GetNlayers();
601         indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
602         nmodules = indexMAX;
603         fITSmodules = new TObjArray(indexMAX);
604         for(index=0;index<indexMAX;index++){
605             fITSmodules->AddAt( new AliITSmodule(index),index);
606         } // end for index
607     }else{
608         fITSmodules = new TObjArray(size);
609         for(index=0;index<size;index++) {
610             fITSmodules->AddAt( new AliITSmodule(index),index);
611         } // end for index
612
613         nmodules = size;
614     } // end i size<=0
615     return kTRUE;
616 }
617 //______________________________________________________________________
618 void AliITS::Hits2SDigits(){
619     // Standard Hits to summable Digits function.
620     // Inputs:
621     //      none.
622     // Outputs:
623     //      none.
624   
625
626    if(!fDetTypeSim) {
627      Error("Hits2SDigits","fDetTypeSim is null!");
628      return; 
629   } 
630      
631   SetDefaults();
632   fLoader->LoadHits("read");
633   fLoader->LoadSDigits("recreate");
634   AliRunLoader* rl = fLoader->GetRunLoader(); 
635   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
636   if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
637
638   for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
639         // Do the Hits to Digits operation. Use Standard input values.
640         // Event number from file, no background hit merging , use size from
641         // AliITSgeom class, option="All", input from this file only.
642     rl->GetEvent(iEvent);
643     if (!fLoader->TreeS()) fLoader->MakeTree("S");
644     MakeBranch("S");
645     SetTreeAddress();
646     HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
647   } // end for iEvent
648     
649   fLoader->UnloadHits();
650   fLoader->UnloadSDigits();
651   
652 }
653 //______________________________________________________________________
654 void AliITS::Hits2Digits(){
655
656   //Conversion from hits to digits
657   if(!fDetTypeSim) {
658     Error("Hits2SDigits","fDetTypeSim is 0!");
659     return;
660   }
661    
662   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
663   if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
664   SetDefaults();
665
666   fLoader->LoadHits("read");
667   fLoader->LoadDigits("recreate");
668   AliRunLoader* rl = fLoader->GetRunLoader(); 
669   for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
670     rl->GetEvent(iEvent);
671     if (!fLoader->TreeD()) fLoader->MakeTree("D");
672     MakeBranch("D");
673     SetTreeAddress();   
674     HitsToDigits(iEvent,0,-1," ",fOpt," ");
675   } 
676   
677   fLoader->UnloadHits();
678   fLoader->UnloadDigits();
679   
680 }
681
682 //______________________________________________________________________
683 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
684                           Option_t *option,Option_t *opt,
685                           const char *filename){
686     //   Keep galice.root for signal and name differently the file for 
687     // background when add! otherwise the track info for signal will be lost !
688     // the condition below will disappear when the geom class will be
689     // initialized for all versions - for the moment it is only for v5 !
690     // 7 is the SDD beam test version.
691     // Inputs:
692     //      Int_t evnt       Event to be processed.
693     //      Int_t bgrev      Background Hit tree number.
694     //      Int_t nmodules   Not used.
695     //      Option_t *option String indicating if merging hits or not. To
696     //                       merge hits set equal to "Add". Otherwise no
697     //                       background hits are considered.
698     //      Test_t *filename File name containing the background hits..
699     // Outputs:
700     //      none.
701     // Return:
702     //      none.
703
704   if(!fDetTypeSim) {
705     Error("HitsToDigits","fDetTypeSim is null!");
706     return;
707   }
708   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
709   if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
710   if(!GetITSgeom()) return; // need transformations to do digitization.
711   AliITSgeom *geom = GetITSgeom();
712
713   const char *all = strstr(opt,"All");
714   const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
715                         strstr(opt,"SSD")};
716   static Bool_t setDef=kTRUE;
717   if (setDef) SetDefaultSimulation();
718   setDef=kFALSE;
719   
720   Int_t nmodules;
721   InitModules(size,nmodules);
722   FillModules(evNumber,bgrev,nmodules,option,filename);
723  
724   // Reset Fast-OR signals for this event
725   fDetTypeSim->ResetFOSignals();
726
727   AliITSsimulation *sim      = 0;
728   AliITSmodule     *mod      = 0;
729   Int_t id;
730   for(Int_t module=0;module<geom->GetIndexMax();module++){
731     id       = geom->GetModuleType(module);
732     if (!all && !det[id]) continue;
733     sim      = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
734     if (!sim) {
735       Error("HitsToDigits","The simulation class was not "
736             "instanciated for module %d type %s!",module,
737             geom->GetModuleTypeName(module));
738       exit(1);
739     } // end if !sim
740     mod      = (AliITSmodule *)fITSmodules->At(module);
741     sim->DigitiseModule(mod,module,evNumber);
742     // fills all branches - wasted disk space
743     fLoader->TreeD()->Fill(); 
744     ResetDigits();
745   } // end for module
746   
747   ClearModules();
748  
749   // Add random noise to FO signals
750   if (all || det[0]) { // SPD present
751     fDetTypeSim->ProcessNoiseForFastOr();
752   }
753
754   // Add Fast-OR signals to event (only one object per event)
755   if (all || det[0]) { // SPD present
756     fDetTypeSim->WriteFOSignals();
757   }
758
759   
760   fLoader->TreeD()->GetEntries();
761   fLoader->TreeD()->AutoSave();
762   // reset tree
763   fLoader->TreeD()->Reset();
764 }
765 //_____________________________________________________________________
766 void AliITS::Hits2PreDigits(){ 
767   // Turn hits into SDigits
768
769   if(!fDetTypeSim) {
770     Error("Hits2SDigits","fDetTypeSim is 0!");
771     return;
772   }
773    
774   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
775   if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
776   SetDefaults();
777   
778   HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
779                   0,-1," ",fOpt," ");
780 }
781
782 //______________________________________________________________________
783 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
784                              Option_t *option,Option_t *opt,
785                              const char *filename){
786     //   Keep galice.root for signal and name differently the file for 
787     // background when add! otherwise the track info for signal will be lost !
788     // the condition below will disappear when the geom class will be
789     // initialized for all versions - for the moment it is only for v5 !
790     // 7 is the SDD beam test version.
791     // Inputs:
792     //      Int_t evnt       Event to be processed.
793     //      Int_t bgrev      Background Hit tree number.
794     //      Int_t nmodules   Not used.
795     //      Option_t *option String indicating if merging hits or not. To
796     //                       merge hits set equal to "Add". Otherwise no
797     //                       background hits are considered.
798     //      Test_t *filename File name containing the background hits..
799     // Outputs:
800     //      none.
801     // Return:
802     //      none.
803
804  
805   if(!fDetTypeSim) {
806     Error("HitsToPreDigits","fDetTypeSim is null!");
807     return;
808   }
809   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
810   if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
811
812   if(!GetITSgeom()){
813     Error("HitsToPreDigits","fGeom is null!");
814     return; // need transformations to do digitization.
815   }
816   AliITSgeom *geom = GetITSgeom();
817
818   const char *all = strstr(opt,"All");
819   const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
820                         strstr(opt,"SSD")};
821   static Bool_t setDef=kTRUE;
822   if (setDef) SetDefaultSimulation();
823   setDef=kFALSE;
824   
825   Int_t nmodules;
826   InitModules(size,nmodules);
827   FillModules(evNumber,bgrev,nmodules,option,filename);
828   
829
830   AliITSsimulation *sim      = 0;
831   AliITSmodule     *mod      = 0;
832   Int_t id,module;
833   for(module=0;module<geom->GetIndexMax();module++){
834     id       = geom->GetModuleType(module);
835     if (!all && !det[id]) continue;
836     sim      = (AliITSsimulation*)GetSimulationModel(id);
837     if (!sim) {
838       Error("HitsToPreDigits","The simulation class was not "
839             "instanciated for module %d type %s!",module,
840             geom->GetModuleTypeName(module));
841       exit(1);
842     } // end if !sim
843     mod      = (AliITSmodule *)fITSmodules->At(module);
844     sim->SDigitiseModule(mod,module,evNumber);
845     // fills all branches - wasted disk space
846     fLoader->TreeS()->Fill(); 
847     fDetTypeSim->ResetSDigits();
848   } // end for module
849
850   ClearModules();
851
852   
853   fLoader->TreeS()->GetEntries();
854   fLoader->TreeS()->AutoSave();
855   fLoader->WriteSDigits("OVERWRITE");
856   // reset tree
857   fLoader->TreeS()->Reset();
858 }
859
860 //_____________________________________________________________________
861 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
862                                   Option_t *opt0,Option_t *opt1,
863                                  const char *flnm){
864     // keep galice.root for signal and name differently the file for 
865     // background when add! otherwise the track info for signal will be lost !
866     // the condition below will disappear when the geom class will be
867     // initialized for all versions - for the moment it is only for v5 !
868     // Inputs:
869     //      Int_t evnt       Event to be processed.
870     //      Int_t bgrev      Background Hit tree number.
871     //      Int_t size       Size used by InitModules. See InitModules.
872     //      Option_t *opt0   Option passed to FillModules. See FillModules.
873     //      Option_t *opt1   String indicating if merging hits or not. To
874     //                       merge hits set equal to "Add". Otherwise no
875     //                       background hits are considered.
876     //      Test_t *flnm     File name containing the background hits..
877     // Outputs:
878     //      none.
879     // Return:
880     //      none.
881
882
883
884   if(!GetITSgeom()){
885     Error("HitsToPreDigits","fGeom is null!");
886     return; // need transformations to do digitization.
887   }
888   AliITSgeom *geom = GetITSgeom();
889
890   AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
891
892   const char *all = strstr(opt1,"All");
893   const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
894                        strstr(opt1,"SSD")};
895   Int_t nmodules;
896   InitModules(size,nmodules);
897   FillModules(evNumber,bgrev,nmodules,opt0,flnm);
898
899   AliITSsimulation *sim      = 0;
900   AliITSmodule     *mod      = 0;
901   Int_t id,module;
902
903   TTree *lTR = pITSloader->TreeR();
904   if(!lTR) {
905     pITSloader->MakeTree("R");
906     lTR = pITSloader->TreeR();
907   }
908   
909   TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
910   TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
911   branch->SetAddress(&ptarray);
912   //m.b. : this change is nothing but a nice way to make sure
913   //the CPU goes up !    
914   for(module=0;module<geom->GetIndexMax();module++){
915     id       = geom->GetModuleType(module);
916     if (!all && !det[id]) continue;
917     sim      = (AliITSsimulation*)GetSimulationModel(id);
918     if (!sim) {
919       Error("HitsToFastPoints","The simulation class was not "
920             "instantiated for module %d type %s!",module,
921             geom->GetModuleTypeName(module));
922       exit(1);
923     } // end if !sim
924     mod      = (AliITSmodule *)fITSmodules->At(module);
925     sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
926     lTR->Fill();
927     ptarray->Clear();
928   } // end for module
929
930   ClearModules();
931   fLoader->WriteRecPoints("OVERWRITE");
932   delete ptarray;
933 }
934 //_____________________________________________________________________
935 Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
936   //------------------------------------------------------------
937   // This function creates ITS clusters
938   //------------------------------------------------------------
939   if(!GetITSgeom()){
940     Error("HitsToPreDigits","fGeom is null!");
941     return 1; // need transformations to do digitization.
942   }
943   AliITSgeom *geom=GetITSgeom();
944   Int_t mmax=geom->GetIndexMax();
945
946   InitModules(-1,mmax);
947   FillModules(hTree,0);
948
949   TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
950   TBranch *branch=cTree->GetBranch("ITSRecPoints");
951   if (!branch) cTree->Branch("ITSRecPoints",&points);
952   else branch->SetAddress(&points);
953
954   AliITSsimulationFastPoints sim;
955   Int_t ncl=0;
956   for (Int_t m=0; m<mmax; m++) {
957     AliITSmodule *mod=GetModule(m);      
958     sim.CreateFastRecPoints(mod,m,gRandom,points);      
959     ncl+=points->GetEntriesFast();
960     cTree->Fill();
961     points->Clear();
962   }
963
964   AliDebug(1,Form("Number of found fast clusters : %d",ncl));
965
966   //cTree->Write();
967
968   delete points;
969   return 0;
970 }
971
972 //_____________________________________________________________________
973 void AliITS::CheckLabels(Int_t lab[3]) const {
974   //------------------------------------------------------------
975   // Tries to find mother's labels
976   //------------------------------------------------------------
977
978   if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
979
980   Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
981   for (Int_t i=0;i<3;i++){
982     Int_t label = lab[i];
983     if (label>=0 && label<ntracks) {
984       TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
985       if (part->P() < 0.005) {
986         Int_t m=part->GetFirstMother();
987         if (m<0) {      
988           continue;
989         }
990         if (part->GetStatusCode()>0) {
991           continue;
992         }
993         lab[i]=m;       
994       }
995     }    
996   }
997   
998 }
999
1000 //______________________________________________________________________
1001 void AliITS::SDigitsToDigits(Option_t *opt){
1002   // Standard Summable digits to Digits function.
1003   // Inputs:
1004   //      none.
1005   // Outputs:
1006   //      none.
1007   if (!fDetTypeSim) {
1008     AliError("fDetTypeSim is 0!");
1009     return;
1010   }
1011
1012   const char *all = strstr(opt,"All");
1013   const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1014                        strstr(opt,"SSD")};
1015
1016   // Reset Fast-OR signals for this event
1017   fDetTypeSim->ResetFOSignals();
1018
1019   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1020   SetDefaults();
1021   if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1022   fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1023
1024   // Add random noise to FO signals
1025   if (all || det[0]) { // SPD present
1026     fDetTypeSim->ProcessNoiseForFastOr();
1027   }
1028   // Add Fast-OR signals to event (only one object per event)
1029   if (all || det[0]) { // SPD present
1030     fDetTypeSim->WriteFOSignals();
1031   }
1032 }
1033
1034 //______________________________________________________________________
1035 void AliITS::ResetDigits(){
1036     // Reset number of digits and the digits array for the ITS detector.
1037     // Inputs:
1038     //      none.
1039     // Outputs:
1040     //      none.
1041     if(!fDetTypeSim) {
1042       Error("ResetDigits","fDetTypeSim is 0!");
1043       return;
1044     }
1045    
1046     fDetTypeSim->ResetDigits();
1047
1048
1049 }
1050 //______________________________________________________________________
1051 void AliITS::ResetDigits(Int_t branch){
1052     // Reset number of digits and the digits array for this branch.
1053     // Inputs:
1054     //      none.
1055     // Outputs:
1056     //      none.
1057
1058     if(!fDetTypeSim) {
1059       Error("ResetDigits","fDetTypeSim is 0!");
1060       return;
1061     }
1062    
1063     fDetTypeSim->ResetDigits(branch);
1064
1065 }
1066 //______________________________________________________________________
1067 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1068     // Adds the a module full of summable digits to the summable digits tree.
1069     // Inputs:
1070     //      AliITSpListItem &sdig   SDigit to be added to SDigits tree.
1071     // Outputs:
1072     //      none.
1073     // Return:
1074     //      none.
1075
1076     if(!fDetTypeSim) {
1077       Error("AddSumDigit","fDetTypeSim is 0!");
1078       return;
1079     }
1080     fDetTypeSim->AddSumDigit(sdig);
1081     
1082 }
1083 //______________________________________________________________________
1084 void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
1085     //    Add a simulated digit.
1086     // Inputs:
1087     //      Int_t id        Detector type number.
1088     //      AliITSdigit *d  Digit to be added to the Digits Tree. See 
1089     //                      AliITSdigit.h
1090     // Outputs:
1091     //      none.
1092     // Return:
1093     //      none.
1094
1095     if(!fDetTypeSim) {
1096       Error("AddSimDigit","fDetTypeSim is 0!");
1097       return;
1098     }
1099     fDetTypeSim->AddSimDigit(branch,d);
1100
1101 }
1102 //______________________________________________________________________
1103 void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
1104                          Int_t *hits,Float_t *charges, Int_t sigexpanded){
1105   //   Add a simulated digit to the list.
1106   // Inputs:
1107   //      Int_t id        Detector type number.
1108   //      Float_t phys    Physics indicator. See AliITSdigits.h
1109   //      Int_t *digits   Integer array containing the digits info. See 
1110   //                      AliITSdigit.h
1111   //      Int_t *tracks   Integer array [AliITSdigitS?D::GetNTracks()] 
1112   //                      containing the track numbers that contributed to
1113   //                      this digit.
1114   //      Int_t *hits     Integer array [AliITSdigitS?D::GetNTracks()]
1115   //                      containing the hit numbers, from AliITSmodule, that
1116   //                      contributed to this digit.
1117   //      Float_t *charge Floating point array of the signals contributed
1118   //                      to this digit by each track.
1119   // Outputs:
1120   //      none.
1121   // Return:
1122   //      none.
1123
1124     if(!fDetTypeSim) {
1125       Error("AddSimDigit","fDetTypeSim is 0!");
1126       return;
1127     }
1128     fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
1129
1130 }
1131 //______________________________________________________________________
1132 void AliITS::Digits2Raw(){
1133     // convert digits of the current event to raw data
1134
1135   if(!fDetTypeSim) {
1136     Error("Digits2Raw","fDetTypeSim is 0!");
1137     return;
1138   }
1139   fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1140   SetDefaults();
1141   if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1142   fDetTypeSim->GetLoader()->LoadDigits();
1143   TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1144   if (!digits) {
1145       Error("Digits2Raw", "no digits tree");
1146       return;
1147   }
1148   fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1149   
1150    // Get the FO signals for this event
1151   AliITSFOSignalsSPD* foSignals = NULL;
1152   AliRunLoader* runLoader = AliRunLoader::Instance();
1153   AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1154   if (!itsLoader) {
1155     AliError("ITS loader is NULL.");
1156   }
1157    else {
1158       if(!itsLoader->TreeD()) AliError("   !!! No TreeD available !!!");
1159       foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1160       if(!foSignals) AliError("FO signals not retrieved");
1161      }
1162  
1163   Bool_t deleteFOsignalsLater = kFALSE;
1164   if (!foSignals) {
1165     AliError("FO signals not available. No FO bits will be written.");
1166     foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1167     deleteFOsignalsLater = kTRUE;
1168   }
1169   
1170   
1171   AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
1172   Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
1173   AliITSDDLRawData rawWriter;
1174   
1175   rawWriter.SetSDDRawFormat(rawSDD);
1176   //Verbose level
1177   // 0: Silent
1178   // 1: cout messages
1179   // 2: txt files with digits 
1180   //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1181   //it is highly suggested to use this mode only for debugging digits files
1182   //reasonably small, because otherwise the size of the txt files can reach
1183   //quickly several MB wasting time and disk space.
1184   rawWriter.SetVerbose(0);
1185     
1186   //SILICON PIXEL DETECTOR
1187   AliDebug(1,"Formatting raw data for SPD");
1188   rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1189   if(deleteFOsignalsLater) delete foSignals;
1190     
1191   //SILICON DRIFT DETECTOR
1192   AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
1193   rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
1194     
1195   //SILICON STRIP DETECTOR
1196   AliDebug(1,"Formatting raw data for SSD");
1197   rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1198
1199   fLoader->UnloadDigits();
1200 }
1201 //______________________________________________________________________
1202 AliLoader* AliITS::MakeLoader(const char* topfoldername){ 
1203     //builds ITSgetter (AliLoader type)
1204     //if detector wants to use castomized getter, it must overload this method
1205
1206     AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1207          topfoldername));
1208     fLoader = new AliITSLoader(GetName(),topfoldername);
1209     return fLoader;
1210 }
1211 //______________________________________________________________________
1212 Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1213 {
1214   //
1215   // Converts RAW data to SDigits
1216   //
1217   // Get TreeS
1218   //
1219   Int_t last   = -1;
1220   Int_t size   = GetITSgeom()->GetIndexMax();
1221   if(!fModA) {
1222     fModA = new TClonesArray*[size];
1223     for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1224   }
1225   AliLoader* loader =  (AliRunLoader::Instance())->GetLoader("ITSLoader");
1226   if (!loader){
1227     Error("Open","Can not get ITS loader from Run Loader");
1228     return kFALSE;
1229   }
1230
1231   TTree* tree = 0;
1232   tree = loader->TreeS();
1233   if (!tree){
1234     loader->MakeTree("S");
1235     tree = loader->TreeS();
1236   }
1237   //
1238   // Array for SDigits
1239   // 
1240   if(!fpSDigits){
1241     fpSDigits = new TClonesArray("AliITSpListItem",10000);
1242   }
1243   TClonesArray& aSDigits = *fpSDigits;
1244   Int_t bufsize = 32000;
1245   tree->Branch("ITS", &fpSDigits, bufsize);
1246   Int_t npx = 0;
1247   //
1248   // SPD
1249   //
1250   AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1251   if(!segSPD){
1252     AliWarning("Set AliITS defaults");
1253     SetDefaults();
1254     segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1255   }
1256   npx = segSPD->Npx();
1257   Double_t thr, sigma; 
1258     
1259   AliITSRawStreamSPD inputSPD(rawReader);
1260   while(1){
1261     Bool_t next  = inputSPD.Next();
1262     if (!next) break;
1263
1264     Int_t module = inputSPD.GetModuleID();
1265     Int_t column = inputSPD.GetColumn();
1266     Int_t row    = inputSPD.GetRow();
1267     Int_t index  = npx * column + row;
1268
1269     if (module >= size) continue;
1270  
1271     last = (fModA[module])->GetEntries();
1272     TClonesArray& dum = *fModA[module];
1273     fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1274     thr += 1.;
1275     new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1276   }
1277   rawReader->Reset();
1278
1279   //
1280   // SDD
1281   // 
1282   AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1283   npx = segSDD->Npx();
1284   Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1285   Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1286   Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1287
1288   AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1289   for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1290     AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1291     Bool_t isZeroSupp=cal->GetZeroSupp();
1292     if(isZeroSupp){ 
1293       for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1294     }else{
1295       for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
1296     }
1297   }
1298
1299   AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1300   inputSDD->SetDDLModuleMap(ddlmap);
1301   while(inputSDD->Next()){
1302     if(inputSDD->IsCompletedModule()==kFALSE && 
1303        inputSDD->IsCompletedDDL()==kFALSE){
1304
1305       Int_t module = inputSDD->GetModuleID();
1306       Int_t anode  = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1307       Int_t time   = inputSDD->GetCoord2();
1308       Int_t signal10 = inputSDD->GetSignal();
1309       Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1310
1311       if (module >= size) continue;
1312       last = fModA[module]->GetEntries();
1313       TClonesArray& dum = *fModA[module];
1314       new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1315       ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
1316     }
1317   }
1318   delete inputSDD;
1319   rawReader->Reset();
1320     
1321   //
1322   // SSD
1323   // 
1324   AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1325   npx = segSSD->Npx();
1326   AliITSRawStreamSSD inputSSD(rawReader);
1327   while(1){
1328     Bool_t next  = inputSSD.Next();
1329     if (!next) break;
1330
1331     Int_t module  = inputSSD.GetModuleID();
1332     Int_t side    = inputSSD.GetSideFlag();
1333     Int_t strip   = inputSSD.GetStrip();
1334     Int_t signal  = inputSSD.GetSignal();
1335     Int_t index  = npx * side + strip;
1336
1337     if (module >= size) continue;
1338         
1339     last = fModA[module]->GetEntries();
1340     TClonesArray& dum = *fModA[module];
1341     new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1342   }
1343   rawReader->Reset();
1344   AliITSpListItem* sdig = 0;
1345     
1346   Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1347   Double_t adcToEv = 1.;
1348   for (Int_t mod = 0; mod < size; mod++)
1349     {
1350       if(mod>=firstssd) {
1351         AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1352         adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1353       }
1354       Int_t nsdig =  fModA[mod]->GetEntries();
1355       for (Int_t ie = 0; ie < nsdig; ie++) {
1356         sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
1357         Int_t digsig = sdig->GetSignal();
1358         if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
1359         new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
1360         Float_t sig = sdig->GetSignalAfterElect();
1361         if(mod>=firstssd) sig*=adcToEv;
1362         if (sig > 0.) {
1363           sdig = (AliITSpListItem*)aSDigits[ie];
1364           sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1365         }
1366       }
1367         
1368       tree->Fill();
1369       aSDigits.Clear();
1370       fModA[mod]->Clear();
1371     }
1372   loader->WriteSDigits("OVERWRITE");    
1373   return kTRUE;
1374 }
1375
1376 //______________________________________________________________________
1377 void AliITS::UpdateInternalGeometry(){
1378   //reads new geometry from TGeo 
1379 //   AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1380
1381   AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1382   Int_t minor = 0;
1383   if(version==kvPPRasymmFMD) minor=2;  // default minor version for this geom.
1384   AliITSInitGeometry initgeom;
1385   AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
1386   SetITSgeom(geom);
1387 }
1388 //______________________________________________________________________
1389 AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1390   // create an AliITSTrigger object (and set trigger conditions as input)
1391   return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
1392 }