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