]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUDigitizer.cxx
1) Added classes for digitization
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUDigitizer.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: AliITSUDigitizer.cxx 52261 2011-10-23 15:46:57Z hristov $ */
17 ///////////////////////////////////////////////////////////////////////////
18 //Piotr.Skowronski@cern.ch :                                             //
19 //Corrections applied in order to compile (only)                         // 
20 //   with new I/O and folder structure                                   //
21 //To be implemented correctly by responsible                             //
22 //                                                                       //
23 //  Class used to steer                                                  //
24 //  the digitization for ITS                                             //
25 //                                                                       //
26 ///////////////////////////////////////////////////////////////////////////
27
28 #include <stdlib.h>
29 #include <TClonesArray.h>
30 #include <TTree.h>
31 #include <TBranch.h>
32
33 #include "AliRun.h"
34 #include "AliRunLoader.h"
35 #include "AliLoader.h"
36 #include "AliLog.h"
37 #include "AliDigitizationInput.h"
38 #include "AliITSUDigitizer.h"
39 #include "AliITSUGeomTGeo.h"
40 #include "AliITSUSimulation.h"
41 #include "AliITSUSDigit.h"
42
43 ClassImp(AliITSUDigitizer)
44
45 //______________________________________________________________________
46 AliITSUDigitizer::AliITSUDigitizer() 
47 :  fITS(0)
48   ,fModActive(0)
49   ,fInit(kFALSE)
50   ,fRoif(-1)
51   ,fRoiifile(0)
52   ,fFlagFirstEv(kTRUE)
53 {
54   // Default constructor.
55 }
56
57 //______________________________________________________________________
58 AliITSUDigitizer::AliITSUDigitizer(AliDigitizationInput* digInp) 
59   :AliDigitizer(digInp)
60   ,fITS(0)
61   ,fModActive(0)
62   ,fInit(kFALSE)
63   ,fRoif(-1)
64   ,fRoiifile(0)
65   ,fFlagFirstEv(kTRUE)
66 {
67   // Standard constructor.
68 }
69
70 //______________________________________________________________________
71 AliITSUDigitizer::~AliITSUDigitizer()
72 {
73   // destructor. 
74   fITS = 0; // don't delete fITS. Done else where.
75   delete[] fModActive;
76 }
77
78 //______________________________________________________________________
79 Bool_t AliITSUDigitizer::Init()
80 {
81   // Initialization. Set up region of interest, if switched on, and loads ITS and ITSgeom.
82   //
83   if (fInit) return kTRUE;
84   //
85   fInit = kTRUE; // Assume for now init will work.
86   //
87   if(!gAlice) {
88     fITS      = 0;
89     fRoiifile = 0;
90     fInit     = kFALSE;
91     AliFatal("gAlice not found");
92   } // end if
93   //
94   fITS = (AliITSU *)(gAlice->GetDetector("ITS"));
95   if(!fITS){
96     fRoiifile = 0;
97     fInit     = kFALSE;
98     AliFatal("ITS not found");
99   } 
100   int nm = fITS->GetITSGeomTGeo()->GetNModules();
101   fModActive = new Bool_t[nm];
102   for (Int_t i=nm;i--;) fModActive[i] = kTRUE;
103
104   return fInit;
105 }
106
107 //______________________________________________________________________
108 void AliITSUDigitizer::Digitize(Option_t* opt)
109 {
110   // Main digitization function. 
111   //
112   if (!fInit) AliFatal("Init not successful, aborting.");
113   //
114   Int_t nfiles = GetDigInput()->GetNinputs();
115   Int_t event  = GetDigInput()->GetOutputEventNr();
116   //
117   TString loadname = Form("%sLoader",fITS->GetName());
118   //
119   AliITSUGeomTGeo* geom = fITS->GetITSGeomTGeo();
120   Int_t nModules  = geom->GetNModules();
121   Bool_t lmod;
122   Int_t *fl = new Int_t[nfiles];
123   fl[0] = fRoiifile;
124   int mask = 1;
125   for (int id=0;id<nfiles;id++) if(id!=fRoiifile) fl[mask++] = id;
126   //
127   TClonesArray * sdig = new TClonesArray( "AliITSUSDigit",1000 );
128   //
129   AliRunLoader *inRL = 0x0, *outRL = 0x0;
130   AliLoader *ingime = 0x0, *outgime = 0x0;    
131   //
132   outRL = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());    
133   if (!outRL) AliFatal("Can not get Output Run Loader");
134   //
135   outRL->GetEvent(event);
136   outgime = outRL->GetLoader(loadname);
137   if ( outgime == 0x0) AliFatal("Can not get Output ITS Loader");
138   //
139   outgime->LoadDigits("update");
140   if (outgime->TreeD() == 0x0) outgime->MakeTree("D");
141   //
142   // Digitize
143   fITS->MakeBranchInTreeD(outgime->TreeD());
144   if(fRoif!=0) AliDebug(1,"Region of Interest digitization selected");
145   else         AliDebug(1,"No Region of Interest selected. Digitizing everything");
146   //
147   for (int ifiles=0; ifiles<nfiles; ifiles++ ) {
148     inRL =  AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(fl[ifiles]));
149     ingime = inRL->GetLoader(loadname);
150     if (ingime->TreeS() == 0x0) ingime->LoadSDigits();
151   }
152   //
153   for (int module=0; module<nModules; module++ ) {
154     //
155     if (!fRoif && !fModActive[module]) continue;
156     int id = geom->GetModuleDetTypeID(module);
157     AliITSUSimulation *sim = fITS->GetSimulationModel(id);
158     if (!sim) AliFatal(Form("The simulation model %d is not available",id));
159     //
160     // Fill the module with the sum of SDigits
161     sim->InitSimulationModule(module, event, fITS->GetSegmentation(id));
162     //
163     for (int ifiles=0; ifiles<nfiles; ifiles++ ) {
164       //
165       if (!fRoif && !fModActive[module]) continue;
166       inRL =  AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(fl[ifiles]));
167       ingime = inRL->GetLoader(loadname);
168       //
169       TTree *treeS = ingime->TreeS();
170       fITS->SetTreeAddress();
171       //
172       if( !treeS  ) continue; 
173       TBranch *brchSDigits = treeS->GetBranch( fITS->GetName() );
174       if( brchSDigits ) brchSDigits->SetAddress( &sdig ); 
175       else {
176         AliError(Form("branch ITS not found in TreeS, input file %d ", ifiles));
177         delete [] fl;
178         return;
179       } 
180       //
181       sdig->Clear();
182       mask = GetDigInput()->GetMask(ifiles);
183       brchSDigits->GetEvent( module );
184       lmod = sim->AddSDigitsToModule(sdig,mask);
185       if(GetRegionOfInterest() && !ifiles) fModActive[module] = lmod;
186       //
187     } 
188     // Digitize current module sum(SDigits)->Digits
189     sim->FinishSDigitiseModule();
190     //
191     outgime->TreeD()->Fill();       // fills all branches - wasted disk space
192     fITS->ResetDigits();
193   } // end for module
194   //
195   //  fITS->WriteFOSignals(); 
196   outgime->TreeD()->AutoSave();
197   outgime->WriteDigits("OVERWRITE");
198   outgime->UnloadDigits();
199   for(int ifiles=0; ifiles<nfiles; ifiles++ ) {
200     inRL =  AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(fl[ifiles]));
201     ingime = inRL->GetLoader(loadname);
202     ingime->UnloadSDigits();
203   }
204   //
205   delete[] fl;
206   sdig->Clear();
207   delete sdig;
208   for (Int_t i=nModules;i--;) fModActive[i] = kTRUE;
209   //
210   return;
211 }
212
213 //______________________________________________________________________
214 void AliITSUDigitizer::SetByRegionOfInterest(TTree *ts)
215 {
216   // Scans through the ITS branch of the SDigits tree, ts, for modules
217   // which have SDigits in them. For these modules, a flag is set to
218   // digitize only these modules. The value of fRoif determines how many
219   // neighboring modules will also be turned on. fRoif=0 will turn on only
220   // those modules with SDigits in them. fRoif=1 will turn on, in addition,
221   // those modules that are +-1 module from the one with the SDigits. And
222   // So on. This last feature is not supported yet.
223   // Inputs:
224   //      TTree *ts  The tree in which the existing SDigits will define the
225   //                 region of interest.
226   if (fRoif==0) return;
227   if (ts==0)    return;
228   TBranch *brchSDigits = ts->GetBranch(fITS->GetName());
229   TClonesArray * sdig = new TClonesArray( "AliITSUSDigit",1000 );
230   //
231   if( brchSDigits ) brchSDigits->SetAddress( &sdig );
232   else  {AliError("Branch ITS not found in TreeS"); return;}
233   //
234   int nm = fITS->GetITSGeomTGeo()->GetNModules();
235   for (int m=0;m<nm;m++) {
236     fModActive[m] = kFALSE; // Not active by default
237     sdig->Clear();
238     brchSDigits->GetEvent(m);
239     int ndig = sdig->GetEntries();
240     for(int i=0;i<ndig;i++) {
241       // activate the necessary modules
242       if ( ((AliITSUSDigit*)sdig->At(m))->GetSumSignal()>0.0 ) { // Must have non zero signal.
243         fModActive[m] = kTRUE;
244         break;
245       } // end if
246     } // end if. end for i.
247   } // end for m
248   AliDebug(1,"Digitization by Region of Interest selected");
249   sdig->Clear();
250   delete sdig;
251   return;
252 }