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