]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSRecPointContainer.cxx
New method PrepareToRead to be able of using the container without the runloader
[u/mrichter/AliRoot.git] / ITS / AliITSRecPointContainer.cxx
1 #include <TTree.h>
2 #include "AliLog.h"
3 #include "AliITSRecoParam.h"
4 #include "AliITSReconstructor.h"
5 #include "AliITSRecPointContainer.h"
6 #include "AliITSRecPoint.h"
7 #include "AliRunLoader.h"
8
9 ClassImp(AliITSRecPointContainer)
10
11 //////////////////////////////////////////////////////////////////////
12 // Class to store ITS RecPoints for the duration of                 //
13 // one event processing                                             //
14 // The container is cleared at each event and new RP                //
15 // are loaded from TTree                                            //
16 // Origin masera@to.infn.it  Nov. 12 2009                           //
17 //////////////////////////////////////////////////////////////////////
18
19 /* $Id$ */
20
21 AliITSRecPointContainer* AliITSRecPointContainer::fgInstance = 0x0;
22
23 //______________________________________________________________________
24 AliITSRecPointContainer::AliITSRecPointContainer(const AliITSRecoParam* krp):TObject(),
25 fSPDNModules(0),
26 fSDDNModules(0),
27 fSSDNModules(0),
28 fArray(),
29 fCurrentEve(-1000),
30 fNextEvent(-1000),
31 fActualSize(0),
32 fDet(""),
33 fStatusOK(kTRUE){
34   // Default constructor
35
36   if(fgkNModules != AliITSgeomTGeo::GetNModules())AliError(Form("The total number of modules is not %d, but %d",fgkNModules,AliITSgeomTGeo::GetNModules()));
37
38   Int_t modperlay[6];
39   for(Int_t i=0;i<6;i++)modperlay[i]=AliITSgeomTGeo::GetNDetectors(1+i)*AliITSgeomTGeo::GetNLadders(1+i);
40   fSPDNModules=modperlay[0]+modperlay[1];
41   fSDDNModules=modperlay[2]+modperlay[3];
42   fSSDNModules=modperlay[4]+modperlay[5];
43   //  AliInfo(Form("Total modules: %d \n SPD modules=%d , SDD modules=%d, SSD modules=%d ",fgkNModules,fSPDNModules,fSDDNModules,fSSDNModules));
44
45   // kLimits[0:5] --> low fluw; kLimits[6,11] --> High flux
46   const Int_t kLimits[12]={25,25,20,20,10,10,300,300,200,200,100,100};
47   Int_t offset=0;
48   if(!krp){
49     AliWarning("AliITSRecoParam is missing. Using defaults");
50   }
51   else {
52     if(krp->GetEventSpecie() == AliRecoParam::kHighMult)offset=6;
53   }
54   Int_t maxval[6];
55   TString values="";
56   for(Int_t i=0;i<6;i++){
57     maxval[i]=kLimits[i+offset];
58     values+=maxval[i];
59     values+=" ";
60     if(i>0)modperlay[i]+=modperlay[i-1];
61   }
62   AliInfo(Form("Container created with sizes/layer: %s",values.Data()));
63   Int_t layer=0;
64   for(Int_t i=0;i<fgkNModules;i++){
65     if(i>=modperlay[layer])++layer;
66     fArray[i]=new TClonesArray("AliITSRecPoint",maxval[layer]);
67   }
68 }
69
70
71 //______________________________________________________________________
72 AliITSRecPointContainer::~AliITSRecPointContainer(){
73   // Destructor
74   for(Int_t i=0;i<fgkNModules;i++){
75     if(fArray[i]){
76       fArray[i]->Delete();
77       delete fArray[i];
78     }
79   }
80 }
81
82 //______________________________________________________________________
83 void AliITSRecPointContainer::CookEntries(){
84   // From the number of entries in TTree R, the number of ITS subdetectors
85   // active for the present run is inferred
86   if(fActualSize == fgkNModules)fDet="ALL SPD SDD SSD ";
87   if(fActualSize == fSPDNModules) fDet = "SPD ";
88   if(fActualSize == fSDDNModules) fDet = "SDD ";
89   if(fActualSize == fSSDNModules)fDet = "SSD ";
90   if(fActualSize == (fSPDNModules+fSDDNModules)) fDet = "SPD SDD ";
91   if(fActualSize == (fSPDNModules+fSSDNModules))fDet = "SPD SSD ";
92   if(fActualSize == (fSDDNModules+fSSDNModules))fDet = "SDD SSD ";
93   if((!fDet.Contains("SPD")) && (!fDet.Contains("SDD")) &&
94      (!fDet.Contains("SSD"))){
95     AliError(Form("The number of active modules %d does not correspond to any standard configuration of the detector",fActualSize));
96     fStatusOK = kFALSE;
97   }
98 }
99 //______________________________________________________________________
100 TClonesArray* AliITSRecPointContainer::FetchClusters(Int_t mod, TTree* tR){
101   // retrieves Recpoints for module mod (offline mode: the event number is
102   // retrieved via the AliRunLoader object)
103   // The actual access to the RP TTree is done as follows:
104   // If the AliRunLoader object exists, the event number is taken from it
105   // If not, the data member fNextEvent is used. 
106   // To set fNextEvent it is necessary to call PrepareToRead in advance.
107   // if this is never done, fNextEvent will have its default negative value
108   // and an error message will be delivered.
109   AliRunLoader* rl = AliRunLoader::Instance();
110   Int_t cureve;
111   if(rl){
112     cureve = rl->GetEventNumber();
113   }
114   else if(fNextEvent>=0){
115     cureve = fNextEvent;
116   }
117   else {
118     AliError("The RunLoader is not defined, PrepareToRead was not invoked. Revise calling sequence. Nothing done");
119     return NULL;
120   }
121   return FetchClusters(mod,tR,cureve);
122 }
123 //______________________________________________________________________
124 TClonesArray* AliITSRecPointContainer::FetchClusters(Int_t mod, TTree* tR,Int_t cureve){
125   // retrieves Recpoints for module mod
126   // cureve is the current event number. If it is different w.r.t.
127   // the event number stored in fCurrentEve, the recpoints are read from
128   // the TTree. Otherwise, the RP stored in memory are used. 
129   if(cureve != fCurrentEve){
130     fCurrentEve = cureve;
131     Reset();
132     TBranch *branch = NULL;
133     branch = tR->GetBranch("ITSRecPoints");
134     if(!branch){
135       AliError("Branch ITSRecPoints not found on ITS recpoints TTree");
136       fStatusOK = kFALSE;
137       return NULL;
138     }
139
140     fActualSize = branch->GetEntries();
141     CookEntries();
142     if(fDet.IsNull())return NULL;
143
144     // it is assumed that the filling order of the tree is SPD, SDD, SSD
145     // even if one or two subdetector are missing
146     if(IsSPDActive()){
147       for(Int_t i=0;i<fSPDNModules;i++){
148         branch->SetAddress(&fArray[i]);
149         branch->GetEvent(i);
150       }
151     }
152     if(IsSDDActive()){
153       Int_t start=0;
154       if(IsSPDActive())start+=fSPDNModules;
155       Int_t counter = fSPDNModules;
156       for(Int_t i=start;i<start+fSDDNModules;i++){
157         branch->SetAddress(&fArray[counter]);
158         ++counter;
159         branch->GetEvent(i);
160       }
161     }
162     if(IsSSDActive()){
163       Int_t start=0;
164       if(IsSPDActive())start+=fSPDNModules;
165       if(IsSDDActive())start+=fSDDNModules;
166       Int_t counter = fSPDNModules+fSDDNModules;
167       for(Int_t i=start;i<start+fSSDNModules;i++){
168         branch->SetAddress(&fArray[counter]);
169         ++counter;
170         branch->GetEvent(i);
171       }
172     }
173   }
174
175   if(CheckBoundaries(mod)){
176     return fArray[mod];
177   }
178   else {
179     AliError(Form("Module %d is out of boundaries",mod));
180     return NULL;
181   }
182   
183 }
184
185 //______________________________________________________________________
186 AliITSRecPointContainer* AliITSRecPointContainer::Instance(const AliITSRecoParam* kptr){
187   // returns AliITSRecPointContainer instance (singleton)
188   if(!fgInstance){
189     if(!kptr){
190       fgInstance =  new AliITSRecPointContainer(AliITSReconstructor::GetRecoParam());
191     }
192     else {
193     fgInstance = new AliITSRecPointContainer(kptr);
194     }
195   }
196   return fgInstance;
197 }
198
199 //______________________________________________________________________
200 void AliITSRecPointContainer::Reset(){
201   // Resets the status of the object
202   for(Int_t i=0;i<fgkNModules;i++){
203     (fArray[i])->Clear();
204   }
205   fDet="";
206 }