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