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