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 : //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 "AliITSDigitizer.h"
39 : #include "AliITSgeom.h"
40 : #include "AliITSgeomTGeo.h"
41 : #include "AliITSsimulation.h"
42 :
43 116 : ClassImp(AliITSDigitizer)
44 :
45 : //______________________________________________________________________
46 0 : AliITSDigitizer::AliITSDigitizer() : AliDigitizer(),
47 0 : fITS(0),
48 0 : fModActive(0),
49 0 : fInit(kFALSE),
50 0 : fRoif(-1),
51 0 : fRoiifile(0),
52 0 : fFlagFirstEv(kTRUE){
53 : // Default constructor. Assign fITS since it is never written out from
54 : // here.
55 : // Inputs:
56 : // Option_t * opt Not used
57 : // Outputs:
58 : // none.
59 : // Return:
60 : // A blank AliITSDigitizer class.
61 0 : fModActive = new Bool_t[AliITSgeomTGeo::GetNModules()];
62 0 : for(Int_t i=0;i<AliITSgeomTGeo::GetNModules();i++) fModActive[i] = kTRUE;
63 :
64 0 : }
65 : //______________________________________________________________________
66 0 : AliITSDigitizer::AliITSDigitizer(AliDigitizationInput* digInp) : AliDigitizer(digInp),
67 0 : fITS(0),
68 0 : fModActive(0),
69 0 : fInit(kFALSE),
70 0 : fRoif(-1),
71 0 : fRoiifile(0),
72 0 : fFlagFirstEv(kTRUE){
73 : // Standard constructor. Assign fITS since it is never written out from
74 : // here.
75 : // Inputs:
76 : // Option_t * opt Not used
77 : // Outputs:
78 : // none.
79 : // Return:
80 : // An AliItSDigitizer class.
81 0 : fModActive = new Bool_t[AliITSgeomTGeo::GetNModules()];
82 0 : for(Int_t i=0;i<AliITSgeomTGeo::GetNModules();i++) fModActive[i] = kTRUE;
83 0 : }
84 :
85 :
86 : //______________________________________________________________________
87 0 : AliITSDigitizer::~AliITSDigitizer(){
88 : // Default destructor.
89 : // Inputs:
90 : // Option_t * opt Not used
91 : // Outputs:
92 : // none.
93 : // Return:
94 : // none.
95 0 : fITS = 0; // don't delete fITS. Done else where.
96 0 : if(fModActive) delete[] fModActive;
97 0 : }
98 : //______________________________________________________________________
99 : Bool_t AliITSDigitizer::Init(){
100 : // Initialization. Set up region of interest, if switched on, and
101 : // loads ITS and ITSgeom.
102 : // Inputs:
103 : // none.
104 : // Outputs:
105 : // none.
106 : // Return:
107 : // none.
108 :
109 0 : fInit = kTRUE; // Assume for now init will work.
110 0 : if(!gAlice) {
111 0 : fITS = 0;
112 0 : fRoiifile = 0;
113 0 : fInit = kFALSE;
114 0 : Warning("Init","gAlice not found");
115 0 : return fInit;
116 : } // end if
117 0 : fITS = (AliITS *)(gAlice->GetDetector("ITS"));
118 0 : if(!fITS){
119 0 : fRoiifile = 0;
120 0 : fInit = kFALSE;
121 0 : Warning("Init","ITS not found");
122 0 : return fInit;
123 : }
124 0 : if(!fITS->GetITSgeom()){
125 0 : fRoiifile = 0;
126 0 : fInit = kFALSE;
127 0 : Warning("Init","ITS geometry not found");
128 0 : return fInit;
129 : } // end if
130 0 : return fInit;
131 0 : }
132 : //______________________________________________________________________
133 : void AliITSDigitizer::Digitize(Option_t* opt){
134 : // Main digitization function.
135 : // Inputs:
136 : // Option_t * opt list of sub detector to digitize. =0 all.
137 : // Outputs:
138 : // none.
139 : // Return:
140 : // none.
141 :
142 0 : char name[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
143 : const char *all;
144 0 : const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
145 0 : strstr(opt,"SSD")};
146 0 : if( !det[0] && !det[1] && !det[2] ) all = "All";
147 : else all = 0;
148 0 : Int_t nfiles = GetDigInput()->GetNinputs();
149 0 : Int_t event = GetDigInput()->GetOutputEventNr();
150 : AliITSsimulation *sim = 0;
151 0 : if(fFlagFirstEv){
152 0 : fITS->SetDefaults();
153 0 : fITS->SetDefaultSimulation();
154 0 : fFlagFirstEv=kFALSE;
155 0 : }
156 0 : if(!fInit){
157 0 : Error("Exec","Init not successful, aborting.");
158 0 : return;
159 : } // end if
160 :
161 0 : snprintf(name,20,"%s",fITS->GetName());
162 :
163 0 : Int_t size = fITS->GetITSgeom()->GetIndexMax();
164 : Int_t module,id,ifiles,mask;
165 : Bool_t lmod;
166 0 : Int_t *fl = new Int_t[nfiles];
167 0 : fl[0] = fRoiifile;
168 : mask = 1;
169 0 : for(id=0;id<nfiles;id++)
170 0 : if(id!=fRoiifile)
171 : {
172 : // just in case fRoiifile!=0.
173 0 : fl[mask] = id;
174 0 : mask++;
175 0 : } // end for,if
176 0 : TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
177 :
178 0 : TString loadname(name);
179 0 : loadname+="Loader";
180 :
181 : AliRunLoader *inRL = 0x0, *outRL = 0x0;
182 : AliLoader *ingime = 0x0, *outgime = 0x0;
183 :
184 0 : outRL = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());
185 0 : if ( outRL == 0x0)
186 : {
187 0 : Error("Exec","Can not get Output Run Loader");
188 0 : delete [] fl;
189 0 : return;
190 : }
191 0 : outRL->GetEvent(event);
192 0 : outgime = outRL->GetLoader(loadname);
193 0 : if ( outgime == 0x0)
194 : {
195 0 : Error("Exec","Can not get Output ITS Loader");
196 0 : delete [] fl;
197 0 : return;
198 : }
199 :
200 0 : outgime->LoadDigits("update");
201 0 : if (outgime->TreeD() == 0x0) outgime->MakeTree("D");
202 :
203 : // Digitize
204 0 : fITS->MakeBranchInTreeD(outgime->TreeD());
205 0 : if(fRoif!=0) {
206 0 : AliDebug(1,"Region of Interest digitization selected");
207 : }
208 : else {
209 0 : AliDebug(1,"No Region of Interest selected. Digitizing everything");
210 : }
211 :
212 :
213 0 : for(ifiles=0; ifiles<nfiles; ifiles++ )
214 : {
215 0 : inRL = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(fl[ifiles]));
216 0 : ingime = inRL->GetLoader(loadname);
217 0 : if (ingime->TreeS() == 0x0) ingime->LoadSDigits();
218 : }
219 :
220 0 : for(module=0; module<size; module++ )
221 : {
222 0 : if(fRoif!=0) if(!fModActive[module]) continue;
223 0 : id = fITS->GetITSgeom()->GetModuleType(module);
224 0 : if(!all && !det[id]) continue;
225 0 : sim = (AliITSsimulation*)fITS->GetSimulationModel(id);
226 0 : if(!sim) {
227 0 : Error( "Exec", "The simulation class was not instanciated!" );
228 0 : exit(1);
229 : } // end if !sim
230 : // Fill the module with the sum of SDigits
231 0 : sim->InitSimulationModule(module, event);
232 : //cout << "Module=" << module;
233 0 : for(ifiles=0; ifiles<nfiles; ifiles++ )
234 : {
235 0 : if(fRoif!=0) if(!fModActive[module]) continue;
236 :
237 0 : inRL = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(fl[ifiles]));
238 0 : ingime = inRL->GetLoader(loadname);
239 :
240 0 : TTree *treeS = ingime->TreeS();
241 0 : fITS->SetTreeAddress();
242 :
243 0 : if( !treeS ) continue;
244 0 : TBranch *brchSDigits = treeS->GetBranch( name );
245 0 : if( brchSDigits )
246 : {
247 0 : brchSDigits->SetAddress( &sdig );
248 : } else {
249 0 : Error( "Exec", "branch ITS not found in TreeS, input file %d ",
250 : ifiles );
251 0 : delete [] fl;
252 0 : return;
253 : } // end if brchSDigits
254 0 : sdig->Clear();
255 0 : mask = GetDigInput()->GetMask(ifiles);
256 : // add summable digits to module
257 0 : brchSDigits->GetEvent( module );
258 0 : lmod = sim->AddSDigitsToModule(sdig,mask);
259 0 : if(GetRegionOfInterest() && (ifiles==0))
260 : {
261 0 : fModActive[module] = lmod;
262 0 : } // end if
263 0 : } // end for ifiles
264 : //cout << " end ifiles loop" << endl;
265 : // Digitize current module sum(SDigits)->Digits
266 0 : sim->FinishSDigitiseModule();
267 :
268 : // fills all branches - wasted disk space
269 0 : outgime->TreeD()->Fill();
270 0 : fITS->ResetDigits();
271 : } // end for module
272 0 : fITS->WriteFOSignals();
273 0 : outgime->TreeD()->AutoSave();
274 0 : outgime->WriteDigits("OVERWRITE");
275 0 : outgime->UnloadDigits();
276 0 : for(ifiles=0; ifiles<nfiles; ifiles++ )
277 : {
278 0 : inRL = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(fl[ifiles]));
279 0 : ingime = inRL->GetLoader(loadname);
280 0 : ingime->UnloadSDigits();
281 : }
282 :
283 0 : delete[] fl;
284 0 : sdig->Clear();
285 0 : delete sdig;
286 0 : for(Int_t i=0;i<fITS->GetITSgeom()->GetIndexMax();i++) fModActive[i] = kTRUE;
287 :
288 :
289 0 : return;
290 0 : }
291 : //______________________________________________________________________
292 : void AliITSDigitizer::SetByRegionOfInterest(TTree *ts){
293 : // Scans through the ITS branch of the SDigits tree, ts, for modules
294 : // which have SDigits in them. For these modules, a flag is set to
295 : // digitize only these modules. The value of fRoif determines how many
296 : // neighboring modules will also be turned on. fRoif=0 will turn on only
297 : // those modules with SDigits in them. fRoif=1 will turn on, in addition,
298 : // those modules that are +-1 module from the one with the SDigits. And
299 : // So on. This last feature is not supported yet.
300 : // Inputs:
301 : // TTree *ts The tree in which the existing SDigits will define the
302 : // region of interest.
303 : // Outputs:
304 : // none.
305 : // Return:
306 : // none.
307 : Int_t m,nm,i;
308 :
309 0 : if(fRoif==0) return;
310 0 : if(ts==0) return;
311 0 : TBranch *brchSDigits = ts->GetBranch(fITS->GetName());
312 0 : TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
313 : //cout << "Region of Interest ts="<<ts<<" brchSDigits="<<brchSDigits<<" sdig="<<sdig<<endl;
314 :
315 0 : if( brchSDigits ) {
316 0 : brchSDigits->SetAddress( &sdig );
317 : } else {
318 0 : Error( "SetByRegionOfInterest","branch ITS not found in TreeS");
319 0 : return;
320 : } // end if brchSDigits
321 :
322 0 : nm = fITS->GetITSgeom()->GetIndexMax();
323 0 : for(m=0;m<nm;m++){
324 0 : fModActive[m] = kFALSE; // Not active by default
325 0 : sdig->Clear();
326 0 : brchSDigits->GetEvent(m);
327 0 : if(sdig->GetLast()>=0) for(i=0;i<sdig->GetLast();i++){
328 : // activate the necessary modules
329 0 : if(((AliITSpList*)sdig->At(m))->GetpListItem(i)->GetSignal()>0.0){ // Must have non zero signal.
330 0 : fModActive[m] = kTRUE;
331 0 : break;
332 : } // end if
333 : } // end if. end for i.
334 : //cout << fModActive[m];
335 : //cout << endl;
336 : } // end for m
337 0 : AliDebug(1,"Digitization by Region of Interest selected");
338 0 : sdig->Clear();
339 0 : delete sdig;
340 0 : return;
341 0 : }
|