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