]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSDigitizer.cxx
New plots for trending injector efficiencies (Melinda)
[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 "AliITSgeomTGeo.h"
41 #include "AliITSsimulation.h"
42
43 ClassImp(AliITSDigitizer)
44
45 //______________________________________________________________________
46 AliITSDigitizer::AliITSDigitizer() : AliDigitizer(),
47 fITS(0),
48 fModActive(0),
49 fInit(kFALSE),
50 fRoif(-1),
51 fRoiifile(0),
52 fFlagFirstEv(kTRUE){
53     // Default constructor. Assign fITS since it is never written out from
54     // here. 
55     // Inputs:
56     //      Option_t * opt   Not used
57     // Outputs:
58     //      none.
59     // Return:
60     //      A blank AliITSDigitizer class.
61   fModActive = new Bool_t[AliITSgeomTGeo::GetNModules()];
62   for(Int_t i=0;i<AliITSgeomTGeo::GetNModules();i++) fModActive[i] = kTRUE;
63
64 }
65 //______________________________________________________________________
66 AliITSDigitizer::AliITSDigitizer(AliRunDigitizer *mngr) : AliDigitizer(mngr),
67 fITS(0),
68 fModActive(0),
69 fInit(kFALSE),
70 fRoif(-1),
71 fRoiifile(0),
72 fFlagFirstEv(kTRUE){
73     // Standard constructor. Assign fITS since it is never written out from
74     // here. 
75     // Inputs:
76     //      Option_t * opt   Not used
77     // Outputs:
78     //      none.
79     // Return:
80     //      An AliItSDigitizer class.
81   fModActive = new Bool_t[AliITSgeomTGeo::GetNModules()];
82   for(Int_t i=0;i<AliITSgeomTGeo::GetNModules();i++) fModActive[i] = kTRUE;
83 }
84
85
86 //______________________________________________________________________
87 AliITSDigitizer::~AliITSDigitizer(){
88     // Default destructor. 
89     // Inputs:
90     //      Option_t * opt   Not used
91     // Outputs:
92     //      none.
93     // Return:
94     //      none.
95     fITS = 0; // don't delete fITS. Done else where.
96     if(fModActive) delete[] fModActive;
97 }
98 //______________________________________________________________________
99 Bool_t AliITSDigitizer::Init(){
100     // Initialization. Set up region of interest, if switched on, and
101     // loads ITS and ITSgeom.
102     // Inputs:
103     //      none.
104     // Outputs:
105     //      none.
106     // Return:
107     //      none.
108
109     fInit = kTRUE; // Assume for now init will work.
110     if(!gAlice) {
111         fITS      = 0;
112         fRoiifile = 0;
113         fInit     = kFALSE;
114         Warning("Init","gAlice not found");
115         return fInit;
116     } // end if
117     fITS = (AliITS *)(gAlice->GetDetector("ITS"));
118     if(!fITS){
119         fRoiifile = 0;
120         fInit     = kFALSE;
121         Warning("Init","ITS not found");
122         return fInit;
123     } 
124     if(!fITS->GetITSgeom()){
125         fRoiifile = 0;
126         fInit     = kFALSE;
127         Warning("Init","ITS geometry not found");
128         return fInit;
129     } // end if
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[21] = {0,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     snprintf(name,20,"%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        delete [] fl;
189        return;
190      }
191     outRL->GetEvent(event);
192     outgime = outRL->GetLoader(loadname);
193     if ( outgime == 0x0)
194      {
195        Error("Exec","Can not get Output ITS Loader");
196        delete [] fl;
197        return;
198      }
199
200     outgime->LoadDigits("update");
201     if (outgime->TreeD() == 0x0) outgime->MakeTree("D");
202     
203     // Digitize
204     fITS->MakeBranchInTreeD(outgime->TreeD());
205     if(fRoif!=0) {
206       AliDebug(1,"Region of Interest digitization selected");
207     }
208     else {
209       AliDebug(1,"No Region of Interest selected. Digitizing everything");
210     }
211
212
213     for(ifiles=0; ifiles<nfiles; ifiles++ )
214      {
215        inRL =  AliRunLoader::GetRunLoader(fManager->GetInputFolderName(fl[ifiles]));
216        ingime = inRL->GetLoader(loadname);
217        if (ingime->TreeS() == 0x0) ingime->LoadSDigits();
218      }
219
220     for(module=0; module<size; module++ )
221      {
222        if(fRoif!=0) if(!fModActive[module]) continue;
223        id = fITS->GetITSgeom()->GetModuleType(module);
224        if(!all && !det[id]) continue;
225        sim      = (AliITSsimulation*)fITS->GetSimulationModel(id);
226        if(!sim) {
227             Error( "Exec", "The simulation class was not instanciated!" );
228             exit(1);
229         } // end if !sim
230            // Fill the module with the sum of SDigits
231         sim->InitSimulationModule(module, event);
232         //cout << "Module=" << module;
233         for(ifiles=0; ifiles<nfiles; ifiles++ )
234          {
235            if(fRoif!=0) if(!fModActive[module]) continue;
236             
237            inRL =  AliRunLoader::GetRunLoader(fManager->GetInputFolderName(fl[ifiles]));
238            ingime = inRL->GetLoader(loadname);
239            
240            TTree *treeS = ingime->TreeS();
241            fITS->SetTreeAddress();
242            
243            if( !treeS  ) continue; 
244            TBranch *brchSDigits = treeS->GetBranch( name );
245            if( brchSDigits ) 
246             {
247                 brchSDigits->SetAddress( &sdig ); 
248             } else {
249                 Error( "Exec", "branch ITS not found in TreeS, input file %d ",
250                        ifiles );
251                 delete [] fl;
252                 return;
253             } // end if brchSDigits
254             sdig->Clear();
255             mask = GetManager()->GetMask(ifiles);
256             // add summable digits to module
257             brchSDigits->GetEvent( module );
258             lmod = sim->AddSDigitsToModule(sdig,mask);
259             if(fRegionOfInterest && (ifiles==0))
260              {
261                fModActive[module] = lmod;
262              } // end if
263         } // end for ifiles
264         //cout << " end ifiles loop" << endl;
265         // Digitize current module sum(SDigits)->Digits
266         sim->FinishSDigitiseModule();
267
268         // fills all branches - wasted disk space
269         outgime->TreeD()->Fill();
270         fITS->ResetDigits();
271     } // end for module
272     
273     outgime->TreeD()->AutoSave();
274     outgime->WriteDigits("OVERWRITE");
275     outgime->UnloadDigits();
276     for(ifiles=0; ifiles<nfiles; ifiles++ )
277      {
278        inRL =  AliRunLoader::GetRunLoader(fManager->GetInputFolderName(fl[ifiles]));
279        ingime = inRL->GetLoader(loadname);
280        ingime->UnloadSDigits();
281      }
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     
288
289     return;
290 }
291 //______________________________________________________________________
292 void AliITSDigitizer::SetByRegionOfInterest(TTree *ts){
293     // Scans through the ITS branch of the SDigits tree, ts, for modules
294     // which have SDigits in them. For these modules, a flag is set to
295     // digitize only these modules. The value of fRoif determines how many
296     // neighboring modules will also be turned on. fRoif=0 will turn on only
297     // those modules with SDigits in them. fRoif=1 will turn on, in addition,
298     // those modules that are +-1 module from the one with the SDigits. And
299     // So on. This last feature is not supported yet.
300     // Inputs:
301     //      TTree *ts  The tree in which the existing SDigits will define the
302     //                 region of interest.
303     // Outputs:
304     //      none.
305     // Return:
306     //      none.
307     Int_t m,nm,i;
308
309     if(fRoif==0) return;
310     if(ts==0) return;
311     TBranch *brchSDigits = ts->GetBranch(fITS->GetName());
312     TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
313     //cout << "Region of Interest ts="<<ts<<" brchSDigits="<<brchSDigits<<" sdig="<<sdig<<endl;
314
315     if( brchSDigits ) {
316       brchSDigits->SetAddress( &sdig );
317     } else {
318       Error( "SetByRegionOfInterest","branch ITS not found in TreeS");
319       return;
320     } // end if brchSDigits
321
322     nm = fITS->GetITSgeom()->GetIndexMax();
323     for(m=0;m<nm;m++){
324       fModActive[m] = kFALSE; // Not active by default
325       sdig->Clear();
326       brchSDigits->GetEvent(m);
327       if(sdig->GetLast()>=0) for(i=0;i<sdig->GetLast();i++){
328           // activate the necessary modules
329           if(((AliITSpList*)sdig->At(m))->GetpListItem(i)->GetSignal()>0.0){ // Must have non zero signal.
330             fModActive[m] = kTRUE;
331             break;
332           } // end if
333       } // end if. end for i.
334       //cout << fModActive[m];
335       //cout << endl;
336     } // end for m
337     AliDebug(1,"Digitization by Region of Interest selected");
338     sdig->Clear();
339     delete sdig;
340     return;
341 }