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