1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.2 2002/03/15 17:26:40 nilsen
19 New SDigit version of ITS Digitizer.
21 Revision 1.1 2001/11/27 16:27:28 nilsen
22 Adding AliITSDigitizer class to do merging and digitization . Based on the
23 TTask method. AliITSDigitizer class added to the Makefile and ITSLinkDef.h
24 file. The following files required minor changes. AliITS, added functions
25 SetHitsAddressBranch, MakeBranchInTreeD and modified MakeBranchD.
26 AliITSsimulationSDD.cxx needed a Tree independent way of returning back to
27 the original Root Directory in function Compress1D. Now it uses gDirectory.
29 Revision 1.2 2002/03/01 E. Lopez
30 Digitization changed to start from SDigits instead of Hits.
31 The SDigits are reading as TClonesArray of AliITSpListItem
36 #include <TObjArray.h>
42 #include <AliRunDigitizer.h>
44 #include "AliITSDigitizer.h"
45 #include "AliITShit.h"
46 #include "AliITSmodule.h"
47 #include "AliITSsimulation.h"
48 #include "AliITSDetType.h"
49 #include "AliITSgeom.h"
51 ClassImp(AliITSDigitizer)
53 //______________________________________________________________________
54 AliITSDigitizer::AliITSDigitizer() : AliDigitizer(){
55 // Default constructor. Assign fITS since it is never written out from
58 // Option_t * opt Not used
62 // A blank AliITSDigitizer class.
69 //______________________________________________________________________
70 AliITSDigitizer::AliITSDigitizer(AliRunDigitizer *mngr) : AliDigitizer(mngr){
71 // Standard constructor. Assign fITS since it is never written out from
74 // Option_t * opt Not used
78 // An AliItSDigitizer class.
87 fITS = (AliITS *)(gAlice->GetDetector("ITS"));
93 } else if(fITS->GetITSgeom()){
94 fActive = new Bool_t[fITS->GetITSgeom()->GetIndexMax()];
103 // fActive needs to be set to a default all kTRUE value
104 for(Int_t i=0;i<fITS->GetITSgeom()->GetIndexMax();i++) fActive[i] = kTRUE;
106 //______________________________________________________________________
107 AliITSDigitizer::~AliITSDigitizer(){
108 // Default destructor.
110 // Option_t * opt Not used
116 fITS = 0; // don't delete fITS. Done else where.
117 if(fActive) delete[] fActive;
119 //______________________________________________________________________
120 Bool_t AliITSDigitizer::Init(const char *filename){
129 // TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
130 // if (file) {file->Close(); delete file;}
131 TFile *file = new TFile(filename);
132 if (!file->IsOpen()) {
133 Error("Init","Can't open %s!",filename);
136 if (gAlice) delete gAlice;
137 gAlice = (AliRun*)file->Get("gAlice");
139 Error("Init","AliRun object not found on file");
148 //______________________________________________________________________
149 Bool_t AliITSDigitizer::Init(){
165 // cout << "init !gAlice"<<endl;
168 fITS = (AliITS *)(gAlice->GetDetector("ITS"));
173 // cout << "init !fITS"<<endl;
175 } else if(fITS->GetITSgeom()){
176 fActive = new Bool_t[fITS->GetITSgeom()->GetIndexMax()];
181 // cout << "init !fITS-GetITSgeom()"<<endl;
184 // fActive needs to be set to a default all kTRUE value
185 for(Int_t i=0;i<fITS->GetITSgeom()->GetIndexMax();i++) fActive[i] = kTRUE;
187 if(fRoif>=0 && fRoiifile>=0 && fRoiifile<GetManager()->GetNinputs()){
188 ts = GetManager()->GetInputTreeS(fRoiifile);
189 cout << "calling SetByReionOfInterest"<<endl;
190 SetByRegionOfInterest(ts);
195 //______________________________________________________________________
196 void AliITSDigitizer::Exec(Option_t* opt){
197 // Main digitization function.
199 // Option_t * opt list of sub detector to digitize. =0 all.
205 char name[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
207 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
209 if( !det[0] && !det[1] && !det[2] ) all = "All";
211 AliITSsimulation *sim = 0;
212 AliITSDetType *iDetType = 0;
213 static Bool_t setDef = kTRUE;
215 if(!fITS) fITS = (AliITS*)(gAlice->GetDetector("ITS"));
217 Error("Exec","The ITS not found. aborting.");
220 if( !(fITS->GetITSgeom()) ) {
221 Warning( "Exec", "Need ITS geometry to be properly defined first." );
222 return; // need transformations to do digitization.
223 } // end if !GetITSgeom()
225 if( setDef ) fITS->SetDefaultSimulation();
227 sprintf( name, "%s", fITS->GetName() );
229 Int_t nfiles = GetManager()->GetNinputs();
230 Int_t event = GetManager()->GetOutputEventNr();
231 Int_t size = fITS->GetITSgeom()->GetIndexMax();
232 TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
235 fITS->MakeBranchInTreeD( GetManager()->GetTreeD() );
236 if(fRoif!=-1)SetByRegionOfInterest(GetManager()->GetInputTreeS(fRoiifile));
238 for( Int_t module=0; module<size; module++ ){
239 if(fActive && fRoif!=-1) if(!fActive[module]) continue;
240 Int_t id = fITS->GetITSgeom()->GetModuleType( module );
241 if( !all && !det[id] ) continue;
242 iDetType = fITS->DetType( id );
243 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
245 Error( "Exec", "The simulation class was not instanciated!" );
249 // Fill the module with the sum of SDigits
250 sim->InitSimulationModule( module, event );
251 // cout << "Module=" << module;
252 for( Int_t ifiles=0; ifiles<nfiles; ifiles++ ){
253 // cout <<" ifiles=" << ifiles;
254 TTree *treeS = GetManager()->GetInputTreeS(ifiles);
255 if( !(treeS && fITS->GetSDigits()) ) continue;
256 TBranch *brchSDigits = treeS->GetBranch( name );
258 brchSDigits->SetAddress( &sdig );
260 Error( "Exec", "branch ITS not found in TreeS, input file %d ",
262 } // end if brchSDigits
264 Int_t mask = GetManager()->GetMask( ifiles );
266 // add summable digits to module
267 brchSDigits->GetEvent( module );
268 sim->AddSDigitsToModule( sdig, mask );
270 // cout << " end ifiles loop" << endl;
271 // Digitize current module sum(SDigits)->Digits
272 sim->FinishSDigitiseModule();
274 // fills all branches - wasted disk space
275 GetManager()->GetTreeD()->Fill();
278 // cout << "end modules loop"<<endl;
280 GetManager()->GetTreeD()->GetEntries();
281 GetManager()->GetTreeD()->Write( 0, TObject::kOverwrite );
283 GetManager()->GetTreeD()->Reset();
288 //______________________________________________________________________
289 void AliITSDigitizer::SetByRegionOfInterest(TTree *ts){
290 // Scans through the ITS branch of the SDigits tree, ts, for modules
291 // which have SDigits in them. For these modules, a flag is set to
292 // digitize only these modules. The value of fRoif determines how many
293 // neighboring modules will also be turned on. fRoif=0 will turn on only
294 // those modules with SDigits in them. fRoif=1 will turn on, in addition,
295 // those modules that are +-1 module from the one with the SDigits. And
296 // So on. This last feature is not supported yet.
298 // TTree *ts The tree in which the existing SDigits will define the
299 // region of interest.
305 if(gAlice==0 && ts==0) return;
306 if(ts==0) ts = gAlice->TreeS();
307 TBranch *brchSDigits = ts->GetBranch(fITS->GetName());
308 TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
309 // cout << "Region of Interest ts="<<ts<<" brchSDigits="<<brchSDigits<<" sdig="<<sdig<<endl;
312 brchSDigits->SetAddress( &sdig );
314 Error( "SetByRegionOfInterest","branch ITS not found in TreeS");
316 } // end if brchSDigits
318 nm = fITS->GetITSgeom()->GetIndexMax();
320 // cout << " fActive["<<m<<"]=";
321 fActive[m] = kFALSE; // Not active by default
323 brchSDigits->GetEvent(m);
324 if(sdig->GetLast()>=0){ // activate the necessary modules