LCOV - code coverage report
Current view: top level - ITS/ITSsim - AliITS.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 252 667 37.8 %
Date: 2016-06-14 17:26:59 Functions: 24 43 55.8 %

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

Generated by: LCOV version 1.11