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