New RecPoint container class. Access to RP through this class implemented for vertexe...
[u/mrichter/AliRoot.git] / ITS / AliITSRecPointContainer.cxx
CommitLineData
b21c1af0 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
9ClassImp(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
21AliITSRecPointContainer* AliITSRecPointContainer::fgInstance = 0x0;
22
23//______________________________________________________________________
24AliITSRecPointContainer::AliITSRecPointContainer(const AliITSRecoParam* krp):TObject(),
25fSPDNModules(0),
26fSDDNModules(0),
27fSSDNModules(0),
28fArray(),
29fCurrentEve(-1000),
30fActualSize(0),
31fDet(""){
32 // Default constructor
33
34 if(fgkNModules != AliITSgeomTGeo::GetNModules())AliError(Form("The total number of modules is not %d, but %d",fgkNModules,AliITSgeomTGeo::GetNModules()));
35
36 Int_t modperlay[6];
37 for(Int_t i=0;i<6;i++)modperlay[i]=AliITSgeomTGeo::GetNDetectors(1+i)*AliITSgeomTGeo::GetNLadders(1+i);
38 fSPDNModules=modperlay[0]+modperlay[1];
39 fSDDNModules=modperlay[2]+modperlay[3];
40 fSSDNModules=modperlay[4]+modperlay[5];
41 // AliInfo(Form("Total modules: %d \n SPD modules=%d , SDD modules=%d, SSD modules=%d ",fgkNModules,fSPDNModules,fSDDNModules,fSSDNModules));
42
43 // kLimits[0:5] --> low fluw; kLimits[6,11] --> High flux
44 const Int_t kLimits[12]={25,25,20,20,10,10,300,300,200,200,100,100};
45 Int_t offset=0;
46 if(!krp){
47 AliWarning("AliITSRecoPoint is missing. Using defaults");
48 }
49 else {
50 if(krp->GetEventSpecie() == AliRecoParam::kHighMult)offset=6;
51 }
52 Int_t maxval[6];
53 TString values="";
54 for(Int_t i=0;i<6;i++){
55 maxval[i]=kLimits[i+offset];
56 values+=maxval[i];
57 values+=" ";
58 if(i>0)modperlay[i]+=modperlay[i-1];
59 }
60 AliInfo(Form("Container created with sizes/layer: %s",values.Data()));
61 Int_t layer=0;
62 for(Int_t i=0;i<fgkNModules;i++){
63 if(i>=modperlay[layer])++layer;
64 fArray[i]=new TClonesArray("AliITSRecPoint",maxval[layer]);
65 }
66}
67
68
69//______________________________________________________________________
70AliITSRecPointContainer::~AliITSRecPointContainer(){
71 // Destructor
72 for(Int_t i=0;i<fgkNModules;i++){
73 if(fArray[i]){
74 fArray[i]->Delete();
75 delete fArray[i];
76 }
77 }
78}
79
80//______________________________________________________________________
81void AliITSRecPointContainer::CookEntries(){
82 // From the number of entries in TTree R, the number of ITS subdetectors
83 // active for the present run is inferred
84 if(fActualSize == fgkNModules)fDet="ALL SPD SDD SSD ";
85 if(fActualSize == fSPDNModules) fDet = "SPD ";
86 if(fActualSize == fSDDNModules) fDet = "SDD ";
87 if(fActualSize == fSSDNModules)fDet = "SSD ";
88 if(fActualSize == (fSPDNModules+fSDDNModules)) fDet = "SPD SDD ";
89 if(fActualSize == (fSPDNModules+fSSDNModules))fDet = "SPD SSD ";
90 if(fActualSize == (fSDDNModules+fSSDNModules))fDet = "SDD SSD ";
91 if((!fDet.Contains("SPD")) && (!fDet.Contains("SDD")) &&
92 (!fDet.Contains("SSD")))AliError(Form("The number of active modules %d does not correspond to any standard configuration of the detector",fActualSize));
93}
94//______________________________________________________________________
95TClonesArray* AliITSRecPointContainer::FetchClusters(Int_t mod, TTree* tR){
96 // retrieves Recpoints for module mod
97 Int_t cureve=AliRunLoader::Instance()->GetEventNumber();
98 if(cureve != fCurrentEve){
99 fCurrentEve = cureve;
100 Reset();
101 TBranch *branch = NULL;
102 branch = tR->GetBranch("ITSRecPoints");
103 if(!branch){
104 AliError("Branch ITSRecPoints not found on ITS recpoints TTree");
105 return NULL;
106 }
107
108 fActualSize = branch->GetEntries();
109 CookEntries();
110 if(fDet.IsNull())return NULL;
111
112 // it is assumed that the filling order of the tree is SPD, SDD, SSD
113 // even if one or two subdetector are missing
114 if(IsSPDActive()){
115 for(Int_t i=0;i<fSPDNModules;i++){
116 branch->SetAddress(&fArray[i]);
117 branch->GetEvent(i);
118 }
119 }
120 if(IsSDDActive()){
121 Int_t start=0;
122 if(IsSPDActive())start+=fSPDNModules;
123 Int_t counter = fSPDNModules;
124 for(Int_t i=start;i<start+fSDDNModules;i++){
125 branch->SetAddress(&fArray[counter]);
126 ++counter;
127 branch->GetEvent(i);
128 }
129 }
130 if(IsSSDActive()){
131 Int_t start=0;
132 if(IsSPDActive())start+=fSPDNModules;
133 if(IsSDDActive())start+=fSDDNModules;
134 Int_t counter = fSPDNModules+fSDDNModules;
135 for(Int_t i=start;i<start+fSSDNModules;i++){
136 branch->SetAddress(&fArray[counter]);
137 ++counter;
138 branch->GetEvent(i);
139 }
140 }
141 }
142
143 if(CheckBoundaries(mod)){
144 return fArray[mod];
145 }
146 else {
147 AliError(Form("Module %d is out of boundaries",mod));
148 return NULL;
149 }
150
151}
152
153//______________________________________________________________________
154AliITSRecPointContainer* AliITSRecPointContainer::Instance(const AliITSRecoParam* kptr){
155 // returns AliITSRecPointContainer instance (singleton)
156 if(!fgInstance){
157 if(!kptr){
158 fgInstance = new AliITSRecPointContainer(AliITSReconstructor::GetRecoParam());
159 }
160 else {
161 fgInstance = new AliITSRecPointContainer(kptr);
162 }
163 }
164 return fgInstance;
165}
166
167//______________________________________________________________________
168void AliITSRecPointContainer::Reset(){
169 // Resets the status of the object
170 for(Int_t i=0;i<fgkNModules;i++){
171 (fArray[i])->Clear();
172 }
173 fDet="";
174}