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