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