]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSupgradeDigitizer.cxx
Added version tailored for pp (AliTrackletTaskMultipp) with additional
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSupgradeDigitizer.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2000, 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
17 /* $Id$ */
18
19 #include <AliRun.h>
20 #include <AliRunLoader.h>
21 #include "AliRunDigitizer.h"
22 #include <AliLoader.h>
23 #include <AliLog.h>
24 #include "AliITSupgradeDigitizer.h"
25 #include "AliITSDigitUpgrade.h"
26 #include "AliITSupgrade.h"
27 #include "AliITSsegmentationUpgrade.h"
28 #include <TObjArray.h>
29 #include <TClonesArray.h>
30
31 extern TRandom *gRandom;
32
33 ClassImp(AliITSupgradeDigitizer)
34     
35   void AliITSupgradeDigitizer::SetConfiguration(TArrayD xcell, TArrayD zcell)
36 {
37   
38   if(xcell.GetSize()!=zcell.GetSize()) AliError(" !! The # of X cells and Z cells differ !!");
39   
40   fNlayers = xcell.GetSize();
41   
42   if(fNlayers > 9) {
43     AliError("*  Only 9 layers can be be filled  ...Exiting!!! *");
44     return;
45   }
46   
47   fNxCells.Set(fNlayers);
48   fNzCells.Set(fNlayers);
49   for(Int_t i=0; i<fNlayers; i++){
50     fNxCells.AddAt(xcell.At(i),i);
51     fNzCells.AddAt(zcell.At(i),i); 
52   }  
53 }   
54 //______________________________________________________________________________      
55 void AliITSupgradeDigitizer::Exec(Option_t*)
56 {
57   // This method is responsible for merging sdigits to a list of digits
58   //  Disintegration leeds to the fact that one hit affects several neighbouring pads, 
59   // which means that the same pad might be affected by few hits.     
60   
61   AliDebug(1,Form("Start with %i input(s) for event %i",fManager->GetNinputs(),fManager->GetOutputEventNr()));
62   
63   
64   AliITSsegmentationUpgrade *s = new AliITSsegmentationUpgrade();
65   SetConfiguration(s->GetFullCellSizeX(),s->GetFullCellSizeZ());
66   delete s;
67   //First we read all sdigits from all inputs  
68   AliRunLoader *pInRunLoader=0;//in and out Run loaders
69   AliLoader    *pITSLoader=0;//in and out ITS loaders  
70   
71   TClonesArray sdigits[10];
72   for(Int_t i=0; i<fNlayers; i++) sdigits[i].SetClass("AliITSDigitUpgrade");//tmp storage for sdigits sum up from all input files
73   
74   
75   Int_t total[10]={0,0,0,0,0,0,0,0,0,0};
76   for(Int_t inFileN=0;inFileN<fManager->GetNinputs();inFileN++){//files loop
77     
78     pInRunLoader  = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inFileN));          //get run loader from current input 
79     pITSLoader = pInRunLoader->GetLoader("ITSLoader"); 
80     if(pITSLoader==0) {
81       continue;       //no ITS in this input, check the next input
82       AliDebug(1,"no ITS lodader, checking in the other input \n"); 
83     }
84     
85     if (!pInRunLoader->GetAliRun()) pInRunLoader->LoadgAlice();
86     AliITSupgrade* pITS=(AliITSupgrade*)pInRunLoader->GetAliRun()->GetDetector("ITS"); 
87     
88     pITSLoader->LoadSDigits();  
89     
90     pITSLoader->TreeS()->GetEntry(0);                          //take list of ITS sdigits from current input 
91     
92     for(Int_t is=0;is<pITS->SDigitsList()->GetEntries();is++){      
93       
94       //collect sdigits from current input
95       for(Int_t ientr =0; ientr < ((TClonesArray*)pITS->SDigitsList()->At(is))->GetEntries(); ientr++){
96         AliITSDigitUpgrade *pSDig=(AliITSDigitUpgrade*)((TClonesArray*)pITS->SDigitsList()->At(is))->At(ientr);
97         pSDig->AddTidOffset(fManager->GetMask(inFileN)); // -> To be introduced for merging (apply TID shift since all inputs count tracks independently starting from 0)
98         new((sdigits[is])[total[is]++]) AliITSDigitUpgrade(*pSDig);  
99       }
100     }
101     
102     pITSLoader->UnloadSDigits();   
103     pITS->SDigitsReset(); //close current input and reset 
104   }//files loop  
105   
106   AliRunLoader *pOutRunLoader  = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());  //open output stream (only 1 possible)
107   AliLoader    *pOutITSLoader = pOutRunLoader->GetLoader("ITSLoader");                        
108   AliRun *pArun = pOutRunLoader->GetAliRun();
109   AliITSupgrade      *pOutITS       = (AliITSupgrade*)pArun->GetDetector("ITS");      
110   pOutITSLoader->MakeTree("D");   pOutITS->MakeBranch("D");                                    //create TreeD in output stream
111   pOutITS->SetTreeAddress();
112   
113   Sdigits2Digits(sdigits,pOutITS->DigitsList());
114   
115   pOutITSLoader->TreeD()->Fill();              //fill the output tree with the list of digits
116   pOutITSLoader->WriteDigits("OVERWRITE");     //serialize them to file
117   
118   for(Int_t i=0; i< fNlayers; i++) sdigits[i].Clear();                      //remove all tmp sdigits
119   pOutITSLoader->UnloadDigits();   
120   pOutITS->DigitsReset(); 
121 }//Exec()
122 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123 void AliITSupgradeDigitizer::Sdigits2Digits(TClonesArray *pSDigitList,TObjArray *pDigitList)
124 {   
125   TClonesArray *pLst[100]; Int_t iCnt[100];
126  
127   for(Int_t i=0;i<fNlayers;i++){ 
128     pLst[i]=(TClonesArray*)(*pDigitList)[i];
129     iCnt[i]=0; if(pLst[i]->GetEntries()!=0) AliErrorClass("Some of digits lists is not empty");  //in principle those lists should be empty 
130   }
131    
132   //AliInfo("starting loop over gli sdigits to create the digits");
133   Double_t eloss =0.;
134   Double_t nele = 0.;
135   ULong_t  pixid = 999;
136   Int_t tids[3]={-1,-1,-1};
137   
138   Float_t elossID[3]={-1.,-1.,-1.};
139   //AliInfo("starting layers");
140   AliDebug(1,"starting loop over layers");
141    
142   for(Int_t ilay=0;ilay<fNlayers;ilay++){ 
143      
144     AliITSDigitUpgrade *tmpdig=0x0;
145     pSDigitList[ilay].Sort();
146     Int_t module=999; 
147     Int_t iNdigPart=0; 
148     AliDebug(1,"starting loop over sdigits to create digits");
149     for(Int_t isdigentr=0; isdigentr<pSDigitList[ilay].GetEntries(); isdigentr++){
150       tmpdig = (AliITSDigitUpgrade*)(pSDigitList[ilay].At(isdigentr) )  ;
151      if(tmpdig->GetPixId()==pixid && tmpdig->GetModule()==module) {
152         iNdigPart++; 
153         if(iNdigPart<=3) {
154           tids[iNdigPart-1] = tmpdig->GetTrack(0);
155           elossID[iNdigPart-1] = tmpdig->GetSignal();
156         }     
157         eloss+=tmpdig->GetSignal();
158         nele+=tmpdig->GetNelectrons();
159         continue;
160       }
161       AliITSDigitUpgrade digit(pixid,eloss);
162       
163       digit.SetNelectrons(nele); 
164       digit.SetLayer(ilay);
165       digit.SetModule(module);
166       digit.SetTids(tids);
167       digit.SetSignalID(elossID);       
168       if(isdigentr!=0) new((*pLst[ilay])[iCnt[ilay]++]) AliITSDigitUpgrade(digit);
169       eloss = tmpdig->GetSignal();
170       nele = tmpdig->GetNelectrons();
171       pixid=tmpdig->GetPixId(); 
172       tids[0]=tmpdig->GetTrack(0);
173       tids[1]=tids[2]=-1;      
174       elossID[0]=tmpdig->GetSignal();
175       elossID[1]=elossID[2]=-1;
176       module=tmpdig->GetModule();   
177     }
178      
179     if(!tmpdig) AliDebug(1,"\n \n---------> tmpdig is null...break is expected ! \n");
180     else AliDebug(1," tmpdig exists \n");
181      
182     if(tmpdig){
183       tmpdig->SetSignal(eloss);  
184       tmpdig->SetPixId(pixid); 
185       tmpdig->SetTids(tids); 
186       tmpdig->SetSignalID(elossID);
187       tmpdig->SetNelectrons(nele);  
188       tmpdig->SetLayer(ilay); 
189       tmpdig->SetModule(module);
190       //cout<<" tmpdigit : pixid "<< pixid<< "  tids "<< tids << " nele " << nele << " ilay "<<ilay<<endl;     
191       new((*pLst[ilay])[iCnt[ilay]++]) AliITSDigitUpgrade(*tmpdig);
192     }     
193     AliDebug(1,"ending loop over sdigits to create digits");
194
195   }
196   AliDebug(1,"ending loop over layers");  
197
198 }
199