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