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.8 2003/03/03 17:00:30 masera
19 Corrections to comply with coding conventions
21 Revision 1.7 2002/10/25 18:54:22 barbera
22 Various improvements and updates from B.S.Nilsen and T. Virgili
24 Revision 1.6 2002/10/22 14:45:34 alibrary
25 Introducing Riostream.h
27 Revision 1.5 2002/10/14 14:57:00 hristov
28 Merging the VirtualMC branch to the main development branch (HEAD)
30 Revision 1.3.4.1 2002/06/10 17:51:14 hristov
33 Revision 1.4 2002/04/24 22:08:12 nilsen
34 New ITS Digitizer/merger with two macros. One to make SDigits (old way) and
35 one to run the merger (modified for Jiri).
37 Revision 1.3 2002/03/25 10:48:55 nilsen
38 New ITS SDigit merging with region of interest cut. Update for changes in
39 AliDigitizer. Additional optimization should be done.
41 Revision 1.2 2002/03/15 17:26:40 nilsen
42 New SDigit version of ITS Digitizer.
44 Revision 1.1 2001/11/27 16:27:28 nilsen
45 Adding AliITSDigitizer class to do merging and digitization . Based on the
46 TTask method. AliITSDigitizer class added to the Makefile and ITSLinkDef.h
47 file. The following files required minor changes. AliITS, added functions
48 SetHitsAddressBranch, MakeBranchInTreeD and modified MakeBranchD.
49 AliITSsimulationSDD.cxx needed a Tree independent way of returning back to
50 the original Root Directory in function Compress1D. Now it uses gDirectory.
52 Revision 1.2 2002/03/01 E. Lopez
53 Digitization changed to start from SDigits instead of Hits.
54 The SDigits are reading as TClonesArray of AliITSpListItem
57 // Class used to steer
58 // the digitization for ITS
62 #include <Riostream.h>
63 #include <TClonesArray.h>
68 #include <AliRunDigitizer.h>
70 #include "AliITSDigitizer.h"
71 #include "AliITSgeom.h"
72 #include "AliITSpList.h"
73 #include "AliITSsimulation.h"
74 #include "AliITSDetType.h"
77 ClassImp(AliITSDigitizer)
79 //______________________________________________________________________
80 AliITSDigitizer::AliITSDigitizer() : AliDigitizer(){
81 // Default constructor. Assign fITS since it is never written out from
84 // Option_t * opt Not used
88 // A blank AliITSDigitizer class.
96 //______________________________________________________________________
97 AliITSDigitizer::AliITSDigitizer(AliRunDigitizer *mngr) : AliDigitizer(mngr){
98 // Standard constructor. Assign fITS since it is never written out from
101 // Option_t * opt Not used
105 // An AliItSDigitizer class.
113 //______________________________________________________________________
114 AliITSDigitizer::~AliITSDigitizer(){
115 // Default destructor.
117 // Option_t * opt Not used
123 fITS = 0; // don't delete fITS. Done else where.
124 if(fModActive) delete[] fModActive;
126 //______________________________________________________________________
127 Bool_t AliITSDigitizer::Init(){
128 // Initialization. Set up region of interest, if switched on, and
129 // loads ITS and ITSgeom.
137 fInit = kTRUE; // Assume for now init will work.
142 Warning("Init","gAlice not found");
145 fITS = (AliITS *)(gAlice->GetDetector("ITS"));
149 Warning("Init","ITS not found");
151 } else if(fITS->GetITSgeom()){
152 //cout << "fRoif,fRoiifile="<<fRoif<<" "<<fRoiifile<<endl;
153 fModActive = new Bool_t[fITS->GetITSgeom()->GetIndexMax()];
157 Warning("Init","ITS geometry not found");
160 // fModActive needs to be set to a default all kTRUE value
161 for(Int_t i=0;i<fITS->GetITSgeom()->GetIndexMax();i++) fModActive[i] = kTRUE;
162 /* This will not work from Init. ts is aways returned as zero.
164 if(fRoif>=0 && fRoiifile>=0 && fRoiifile<GetManager()->GetNinputs()){
165 ts = GetManager()->GetInputTreeS(fRoiifile);
167 if(!gAlice) ts = gAlice->TreeS();
169 cout <<"The TTree TreeS needed to set by region not found."
170 " No region of interest cut will be applied."<< endl;
174 cout << "calling SetByReionOfInterest ts="<< ts <<endl;
175 SetByRegionOfInterest(ts);
180 //______________________________________________________________________
181 void AliITSDigitizer::Exec(Option_t* opt){
182 // Main digitization function.
184 // Option_t * opt list of sub detector to digitize. =0 all.
190 char name[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
192 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
194 if( !det[0] && !det[1] && !det[2] ) all = "All";
196 AliITSsimulation *sim = 0;
197 AliITSDetType *iDetType = 0;
198 static Bool_t setDef = kTRUE;
201 Error("Exec","Init not succesfull, aborting.");
205 if( setDef ) fITS->SetDefaultSimulation();
207 sprintf(name,"%s",fITS->GetName());
209 Int_t nfiles = GetManager()->GetNinputs();
210 Int_t event = GetManager()->GetOutputEventNr();
211 Int_t size = fITS->GetITSgeom()->GetIndexMax();
212 Int_t module,id,ifiles,mask;
214 Int_t *fl = new Int_t[nfiles];
217 for(id=0;id<nfiles;id++) if(id!=fRoiifile){
218 // just in case fRoiifile!=0.
222 TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
225 fITS->MakeBranchInTreeD(GetManager()->GetTreeD());
226 if(fRoif!=0) Info("AliITSDigitizer","Region of Interest digitization selected");
227 else Info("AliITSDigitizer","No Region of Interest selected. Digitizing everything");
228 //cout <<"fModActive="<<fModActive<<" fRoif="<<fRoif;
229 if(fModActive==0) fRoif = 0; // fModActive array must be define for RIO cuts.
230 //cout <<" fRoif="<<fRoif<<endl;
232 for(module=0; module<size; module++ ){
233 if(fRoif!=0) if(!fModActive[module]) continue;
234 id = fITS->GetITSgeom()->GetModuleType(module);
235 if(!all && !det[id]) continue;
236 iDetType = fITS->DetType( id );
237 sim = (AliITSsimulation*)iDetType->GetSimulationModel();
239 Error( "Exec", "The simulation class was not instanciated!" );
243 // Fill the module with the sum of SDigits
244 sim->InitSimulationModule(module, event);
245 //cout << "Module=" << module;
246 for(ifiles=0; ifiles<nfiles; ifiles++ ){
247 if(fRoif!=0) if(!fModActive[module]) continue;
248 //cout <<" fl[ifiles=" << ifiles << "]=" << fl[ifiles];
249 TTree *treeS = GetManager()->GetInputTreeS(fl[ifiles]);
250 if( !(treeS && fITS->GetSDigits()) ) continue;
251 TBranch *brchSDigits = treeS->GetBranch( name );
253 brchSDigits->SetAddress( &sdig );
255 Error( "Exec", "branch ITS not found in TreeS, input file %d ",
258 } // end if brchSDigits
260 mask = GetManager()->GetMask(ifiles);
261 // add summable digits to module
262 brchSDigits->GetEvent( module );
263 lmod = sim->AddSDigitsToModule(sdig,mask);
265 fModActive[module] = lmod;
267 //cout << " fModActive["<<module<<"]=";
268 //if(fModActive[module]) cout << "kTRUE";
269 //else cout << "kFALSE";
271 //cout << " end ifiles loop" << endl;
272 // Digitize current module sum(SDigits)->Digits
273 sim->FinishSDigitiseModule();
275 // fills all branches - wasted disk space
276 GetManager()->GetTreeD()->Fill();
279 //cout << "end modules loop"<<endl;
281 GetManager()->GetTreeD()->AutoSave();
286 for(Int_t i=0;i<fITS->GetITSgeom()->GetIndexMax();i++) fModActive[i] = kTRUE;
289 //______________________________________________________________________
290 void AliITSDigitizer::SetByRegionOfInterest(TTree *ts){
291 // Scans through the ITS branch of the SDigits tree, ts, for modules
292 // which have SDigits in them. For these modules, a flag is set to
293 // digitize only these modules. The value of fRoif determines how many
294 // neighboring modules will also be turned on. fRoif=0 will turn on only
295 // those modules with SDigits in them. fRoif=1 will turn on, in addition,
296 // those modules that are +-1 module from the one with the SDigits. And
297 // So on. This last feature is not supported yet.
299 // TTree *ts The tree in which the existing SDigits will define the
300 // region of interest.
309 TBranch *brchSDigits = ts->GetBranch(fITS->GetName());
310 TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
311 //cout << "Region of Interest ts="<<ts<<" brchSDigits="<<brchSDigits<<" sdig="<<sdig<<endl;
314 brchSDigits->SetAddress( &sdig );
316 Error( "SetByRegionOfInterest","branch ITS not found in TreeS");
318 } // end if brchSDigits
320 nm = fITS->GetITSgeom()->GetIndexMax();
322 //cout << " fModActive["<<m<<"]=";
323 fModActive[m] = kFALSE; // Not active by default
325 brchSDigits->GetEvent(m);
326 if(sdig->GetLast()>=0) for(i=0;i<sdig->GetLast();i++){
327 // activate the necessary modules
328 if(((AliITSpList*)sdig->At(m))->GetpListItem(i)->GetSignal()>0.0){ // Must have non zero signal.
329 fModActive[m] = kTRUE;
332 } // end if. end for i.
333 //cout << fModActive[m];
336 Info("AliITSDigitizer","Digitization by Region of Interest selected");