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