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 **************************************************************************/
16 /* $Id: AliITSUDigitizer.cxx 52261 2011-10-23 15:46:57Z hristov $ */
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 //
23 // Class used to steer //
24 // the digitization for ITS //
26 ///////////////////////////////////////////////////////////////////////////
29 #include <TClonesArray.h>
34 #include "AliRunLoader.h"
35 #include "AliLoader.h"
37 #include "AliDigitizationInput.h"
38 #include "AliITSUDigitizer.h"
39 #include "AliITSUGeomTGeo.h"
40 #include "AliITSUSimulation.h"
41 #include "AliITSUSDigit.h"
43 ClassImp(AliITSUDigitizer)
45 //______________________________________________________________________
46 AliITSUDigitizer::AliITSUDigitizer()
54 // Default constructor.
57 //______________________________________________________________________
58 AliITSUDigitizer::AliITSUDigitizer(AliDigitizationInput* digInp)
67 // Standard constructor.
70 //______________________________________________________________________
71 AliITSUDigitizer::~AliITSUDigitizer()
74 fITS = 0; // don't delete fITS. Done else where.
78 //______________________________________________________________________
79 Bool_t AliITSUDigitizer::Init()
81 // Initialization. Set up region of interest, if switched on, and loads ITS and ITSgeom.
83 if (fInit) return kTRUE;
85 fInit = kTRUE; // Assume for now init will work.
91 AliFatal("gAlice not found");
94 fITS = (AliITSU *)(gAlice->GetDetector("ITS"));
98 AliFatal("ITS not found");
100 int nm = fITS->GetITSGeomTGeo()->GetNModules();
101 fModActive = new Bool_t[nm];
102 for (Int_t i=nm;i--;) fModActive[i] = kTRUE;
107 //______________________________________________________________________
108 void AliITSUDigitizer::Digitize(Option_t* opt)
110 // Main digitization function.
112 if (!fInit) AliFatal("Init not successful, aborting.");
114 Int_t nfiles = GetDigInput()->GetNinputs();
115 Int_t event = GetDigInput()->GetOutputEventNr();
117 TString loadname = Form("%sLoader",fITS->GetName());
119 AliITSUGeomTGeo* geom = fITS->GetITSGeomTGeo();
120 Int_t nModules = geom->GetNModules();
122 Int_t *fl = new Int_t[nfiles];
125 for (int id=0;id<nfiles;id++) if(id!=fRoiifile) fl[mask++] = id;
127 TClonesArray * sdig = new TClonesArray( "AliITSUSDigit",1000 );
129 AliRunLoader *inRL = 0x0, *outRL = 0x0;
130 AliLoader *ingime = 0x0, *outgime = 0x0;
132 outRL = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());
133 if (!outRL) AliFatal("Can not get Output Run Loader");
135 outRL->GetEvent(event);
136 outgime = outRL->GetLoader(loadname);
137 if ( outgime == 0x0) AliFatal("Can not get Output ITS Loader");
139 outgime->LoadDigits("update");
140 if (outgime->TreeD() == 0x0) outgime->MakeTree("D");
143 fITS->MakeBranchInTreeD(outgime->TreeD());
144 if(fRoif!=0) AliDebug(1,"Region of Interest digitization selected");
145 else AliDebug(1,"No Region of Interest selected. Digitizing everything");
147 for (int ifiles=0; ifiles<nfiles; ifiles++ ) {
148 inRL = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(fl[ifiles]));
149 ingime = inRL->GetLoader(loadname);
150 if (ingime->TreeS() == 0x0) ingime->LoadSDigits();
153 for (int module=0; module<nModules; module++ ) {
155 if (!fRoif && !fModActive[module]) continue;
156 int id = geom->GetModuleDetTypeID(module);
157 AliITSUSimulation *sim = fITS->GetSimulationModel(id);
158 if (!sim) AliFatal(Form("The simulation model %d is not available",id));
160 // Fill the module with the sum of SDigits
161 sim->InitSimulationModule(module, event, fITS->GetSegmentation(id));
163 for (int ifiles=0; ifiles<nfiles; ifiles++ ) {
165 if (!fRoif && !fModActive[module]) continue;
166 inRL = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(fl[ifiles]));
167 ingime = inRL->GetLoader(loadname);
169 TTree *treeS = ingime->TreeS();
170 fITS->SetTreeAddress();
172 if( !treeS ) continue;
173 TBranch *brchSDigits = treeS->GetBranch( fITS->GetName() );
174 if( brchSDigits ) brchSDigits->SetAddress( &sdig );
176 AliError(Form("branch ITS not found in TreeS, input file %d ", ifiles));
182 mask = GetDigInput()->GetMask(ifiles);
183 brchSDigits->GetEvent( module );
184 lmod = sim->AddSDigitsToModule(sdig,mask);
185 if(GetRegionOfInterest() && !ifiles) fModActive[module] = lmod;
188 // Digitize current module sum(SDigits)->Digits
189 sim->FinishSDigitiseModule();
191 outgime->TreeD()->Fill(); // fills all branches - wasted disk space
195 // fITS->WriteFOSignals();
196 outgime->TreeD()->AutoSave();
197 outgime->WriteDigits("OVERWRITE");
198 outgime->UnloadDigits();
199 for(int ifiles=0; ifiles<nfiles; ifiles++ ) {
200 inRL = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(fl[ifiles]));
201 ingime = inRL->GetLoader(loadname);
202 ingime->UnloadSDigits();
208 for (Int_t i=nModules;i--;) fModActive[i] = kTRUE;
213 //______________________________________________________________________
214 void AliITSUDigitizer::SetByRegionOfInterest(TTree *ts)
216 // Scans through the ITS branch of the SDigits tree, ts, for modules
217 // which have SDigits in them. For these modules, a flag is set to
218 // digitize only these modules. The value of fRoif determines how many
219 // neighboring modules will also be turned on. fRoif=0 will turn on only
220 // those modules with SDigits in them. fRoif=1 will turn on, in addition,
221 // those modules that are +-1 module from the one with the SDigits. And
222 // So on. This last feature is not supported yet.
224 // TTree *ts The tree in which the existing SDigits will define the
225 // region of interest.
226 if (fRoif==0) return;
228 TBranch *brchSDigits = ts->GetBranch(fITS->GetName());
229 TClonesArray * sdig = new TClonesArray( "AliITSUSDigit",1000 );
231 if( brchSDigits ) brchSDigits->SetAddress( &sdig );
232 else {AliError("Branch ITS not found in TreeS"); return;}
234 int nm = fITS->GetITSGeomTGeo()->GetNModules();
235 for (int m=0;m<nm;m++) {
236 fModActive[m] = kFALSE; // Not active by default
238 brchSDigits->GetEvent(m);
239 int ndig = sdig->GetEntries();
240 for(int i=0;i<ndig;i++) {
241 // activate the necessary modules
242 if ( ((AliITSUSDigit*)sdig->At(m))->GetSumSignal()>0.0 ) { // Must have non zero signal.
243 fModActive[m] = kTRUE;
246 } // end if. end for i.
248 AliDebug(1,"Digitization by Region of Interest selected");