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