]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSDigitizer.cxx
Including stdlib.h (HP)
[u/mrichter/AliRoot.git] / ITS / AliITSDigitizer.cxx
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  
16 /*
17 $Log$
18 Revision 1.8  2003/03/03 17:00:30  masera
19 Corrections to comply with coding conventions
20
21 Revision 1.7  2002/10/25 18:54:22  barbera
22 Various improvements and updates from B.S.Nilsen and T. Virgili
23
24 Revision 1.6  2002/10/22 14:45:34  alibrary
25 Introducing Riostream.h
26
27 Revision 1.5  2002/10/14 14:57:00  hristov
28 Merging the VirtualMC branch to the main development branch (HEAD)
29
30 Revision 1.3.4.1  2002/06/10 17:51:14  hristov
31 Merged with v3-08-02
32
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).
36
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.
40
41 Revision 1.2  2002/03/15 17:26:40  nilsen
42 New SDigit version of ITS Digitizer.
43
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.
51
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
55 */
56 //
57 //  Class used to steer
58 //  the digitization for ITS
59 //
60 //
61 #include <stdlib.h>
62 #include <Riostream.h>
63 #include <TClonesArray.h> 
64 #include <TTree.h>
65 #include <TBranch.h>
66
67 #include <AliRun.h>
68 #include <AliRunDigitizer.h>
69
70 #include "AliITSDigitizer.h"
71 #include "AliITSgeom.h"
72 #include "AliITSpList.h"
73 #include "AliITSsimulation.h"
74 #include "AliITSDetType.h"
75
76
77 ClassImp(AliITSDigitizer)
78
79 //______________________________________________________________________
80 AliITSDigitizer::AliITSDigitizer() : AliDigitizer(){
81     // Default constructor. Assign fITS since it is never written out from
82     // here. 
83     // Inputs:
84     //      Option_t * opt   Not used
85     // Outputs:
86     //      none.
87     // Return:
88     //      A blank AliITSDigitizer class.
89
90     fITS      = 0;
91     fModActive   = 0;
92     fRoif     = -1;
93     fRoiifile = 0;
94     fInit     = kFALSE;
95 }
96 //______________________________________________________________________
97 AliITSDigitizer::AliITSDigitizer(AliRunDigitizer *mngr) : AliDigitizer(mngr){
98     // Standard constructor. Assign fITS since it is never written out from
99     // here. 
100     // Inputs:
101     //      Option_t * opt   Not used
102     // Outputs:
103     //      none.
104     // Return:
105     //      An AliItSDigitizer class.
106
107     fITS      = 0;
108     fModActive   = 0;
109     fRoif     = -1;
110     fRoiifile = 0;
111     fInit     = kFALSE;
112 }
113 //______________________________________________________________________
114 AliITSDigitizer::~AliITSDigitizer(){
115     // Default destructor. 
116     // Inputs:
117     //      Option_t * opt   Not used
118     // Outputs:
119     //      none.
120     // Return:
121     //      none.
122
123     fITS = 0; // don't delete fITS. Done else where.
124     if(fModActive) delete[] fModActive;
125 }
126 //______________________________________________________________________
127 Bool_t AliITSDigitizer::Init(){
128     // Initialization. Set up region of interest, if switched on, and
129     // loads ITS and ITSgeom.
130     // Inputs:
131     //      none.
132     // Outputs:
133     //      none.
134     // Return:
135     //      none.
136
137     fInit = kTRUE; // Assume for now init will work.
138     if(!gAlice) {
139         fITS      = 0;
140         fRoiifile = 0;
141         fInit     = kFALSE;
142         Warning("Init","gAlice not found");
143         return fInit;
144     } // end if
145     fITS = (AliITS *)(gAlice->GetDetector("ITS"));
146     if(!fITS){
147         fRoiifile = 0;
148         fInit     = kFALSE;
149         Warning("Init","ITS not found");
150         return fInit;
151     } else if(fITS->GetITSgeom()){
152         //cout << "fRoif,fRoiifile="<<fRoif<<" "<<fRoiifile<<endl;
153         fModActive = new Bool_t[fITS->GetITSgeom()->GetIndexMax()];
154     } else{
155         fRoiifile = 0;
156         fInit     = kFALSE;
157         Warning("Init","ITS geometry not found");
158         return fInit;
159     } // end if
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.
163     TTree *ts;
164     if(fRoif>=0 && fRoiifile>=0 && fRoiifile<GetManager()->GetNinputs()){
165         ts = GetManager()->GetInputTreeS(fRoiifile);
166         if(!ts){
167             if(!gAlice) ts = gAlice->TreeS();
168             if(!ts){
169                 cout <<"The TTree TreeS needed to set by region not found."
170                     " No region of interest cut will be applied."<< endl;
171                 return fInit;
172             } // end if
173         } // end if
174         cout << "calling SetByReionOfInterest ts="<< ts <<endl;
175         SetByRegionOfInterest(ts);
176     } // end if
177 */
178     return fInit;
179 }
180 //______________________________________________________________________
181 void AliITSDigitizer::Exec(Option_t* opt){
182     // Main digitization function. 
183     // Inputs:
184     //      Option_t * opt   list of sub detector to digitize. =0 all.
185     // Outputs:
186     //      none.
187     // Return:
188     //      none.
189
190     char name[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
191     char *all;
192     const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
193                           strstr(opt,"SSD")};
194     if( !det[0] && !det[1] && !det[2] ) all = "All";
195     else all = 0;
196     AliITSsimulation *sim      = 0;
197     AliITSDetType    *iDetType = 0;
198     static Bool_t    setDef    = kTRUE;
199
200     if(!fInit){
201         Error("Exec","Init not succesfull, aborting.");
202         return;
203     } // end if
204
205     if( setDef ) fITS->SetDefaultSimulation();
206     setDef = kFALSE;
207     sprintf(name,"%s",fITS->GetName());
208
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;
213     Bool_t lmod;
214     Int_t *fl = new Int_t[nfiles];
215     fl[0] = fRoiifile;
216     mask = 1;
217     for(id=0;id<nfiles;id++) if(id!=fRoiifile){
218         // just in case fRoiifile!=0.
219         fl[mask] = id;
220         mask++;
221     } // end for,if
222     TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
223     
224     // Digitize
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;
231
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();
238         if(!sim) {
239             Error( "Exec", "The simulation class was not instanciated!" );
240             exit(1);
241         } // end if !sim
242
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 );
252             if( brchSDigits ) {
253                 brchSDigits->SetAddress( &sdig ); 
254             } else {
255                 Error( "Exec", "branch ITS not found in TreeS, input file %d ",
256                        ifiles );
257                 return;
258             } // end if brchSDigits
259             sdig->Clear();
260             mask = GetManager()->GetMask(ifiles);
261             // add summable digits to module
262             brchSDigits->GetEvent( module );
263             lmod = sim->AddSDigitsToModule(sdig,mask);
264             if(ifiles==0){
265                 fModActive[module] = lmod;
266             } // end if
267             //cout << " fModActive["<<module<<"]=";
268             //if(fModActive[module]) cout << "kTRUE";
269             //else cout << "kFALSE";
270         } // end for ifiles
271         //cout << " end ifiles loop" << endl;
272         // Digitize current module sum(SDigits)->Digits
273         sim->FinishSDigitiseModule();
274
275         // fills all branches - wasted disk space
276         GetManager()->GetTreeD()->Fill();
277         fITS->ResetDigits();
278     } // end for module
279     //cout << "end modules loop"<<endl;
280
281     GetManager()->GetTreeD()->AutoSave();
282
283     delete[] fl;
284     sdig->Clear();
285     delete sdig;
286     for(Int_t i=0;i<fITS->GetITSgeom()->GetIndexMax();i++) fModActive[i] = kTRUE;
287     return;
288 }
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.
298     // Inputs:
299     //      TTree *ts  The tree in which the existing SDigits will define the
300     //                 region of interest.
301     // Outputs:
302     //      none.
303     // Return:
304     //      none.
305     Int_t m,nm,i;
306
307     if(fRoif==0) return;
308     if(ts==0) return;
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;
312
313     if( brchSDigits ) {
314         brchSDigits->SetAddress( &sdig );
315     } else {
316         Error( "SetByRegionOfInterest","branch ITS not found in TreeS");
317         return;
318     } // end if brchSDigits
319
320     nm = fITS->GetITSgeom()->GetIndexMax();
321     for(m=0;m<nm;m++){
322         //cout << " fModActive["<<m<<"]=";
323         fModActive[m] = kFALSE; // Not active by default
324         sdig->Clear();
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;
330                 break;
331             } // end if
332         } // end if. end for i.
333         //cout << fModActive[m];
334         //cout << endl;
335     } // end for m
336     Info("AliITSDigitizer","Digitization by Region of Interest selected");
337     sdig->Clear();
338     delete sdig;
339     return;
340 }