]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSimpleClusterServer.cxx
Compilation on Windoiws/Cygwin
[u/mrichter/AliRoot.git] / MUON / AliMUONSimpleClusterServer.cxx
CommitLineData
d08b5461 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#include "AliMUONSimpleClusterServer.h"
19
9bf6860b 20#include "AliCodeTimer.h"
21#include "AliLog.h"
d08b5461 22#include "AliMUONCluster.h"
9bf6860b 23#include "AliMUONConstants.h"
d08b5461 24#include "AliMUONGeometryTransformer.h"
25#include "AliMUONPad.h"
9bf6860b 26#include "AliMUONTriggerTrackToTrackerClusters.h"
d08b5461 27#include "AliMUONVCluster.h"
28#include "AliMUONVClusterFinder.h"
29#include "AliMUONVClusterStore.h"
30#include "AliMUONVDigitStore.h"
35be7ed7 31#include "AliMUONRecoParam.h"
d08b5461 32#include "AliMpArea.h"
33#include "AliMpDEIterator.h"
34#include "AliMpDEManager.h"
35#include "AliMpExMap.h"
9bf6860b 36#include "AliMpPad.h"
d08b5461 37#include "AliMpSegmentation.h"
38#include "AliMpVSegmentation.h"
d08b5461 39#include <Riostream.h>
40#include <TClonesArray.h>
41#include <TString.h>
9bf6860b 42#include <float.h>
7deb8eb0 43
d08b5461 44/// \class AliMUONSimpleClusterServer
45///
46/// Implementation of AliMUONVClusterServer interface
47///
48///
49/// \author Laurent Aphecetche, Subatech
50
51/// \cond CLASSIMP
52ClassImp(AliMUONSimpleClusterServer)
53/// \endcond
54
55namespace
56{
57 TString AsString(const AliMpArea& area)
58 {
59 return Form("(X,Y)=(%7.3f,%7.3f) (DX,DY)=(%7.3f,%7.3f)",
60 area.Position().X(),
61 area.Position().Y(),
62 area.Dimensions().Y(),
63 area.Dimensions().Y());
64 }
65}
66
67//_____________________________________________________________________________
9bf6860b 68AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder* clusterFinder,
d08b5461 69 const AliMUONGeometryTransformer& transformer)
70: AliMUONVClusterServer(),
71 fClusterFinder(clusterFinder),
72 fTransformer(transformer),
73 fPads(),
9bf6860b 74 fTriggerTrackStore(0x0),
75 fBypass(0x0)
d08b5461 76{
77 /// Ctor
9bf6860b 78 /// Note that we take ownership of the clusterFinder
d08b5461 79
630711ed 80 fPads[0] = new AliMpExMap;
81 fPads[1] = new AliMpExMap;
7deb8eb0 82
d08b5461 83}
84
85//_____________________________________________________________________________
86AliMUONSimpleClusterServer::~AliMUONSimpleClusterServer()
87{
88 /// Dtor
9bf6860b 89 delete fClusterFinder;
d08b5461 90 delete fPads[0];
91 delete fPads[1];
9bf6860b 92 delete fBypass;
d08b5461 93}
94
95//_____________________________________________________________________________
96Int_t
97AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
98 AliMUONVClusterStore& clusterStore,
35be7ed7 99 const AliMpArea& area,
100 const AliMUONRecoParam* recoParam)
d08b5461 101{
102 /// Area is in absolute coordinate. If not valid, means clusterize all
103 /// the chamber.
104 ///
105 /// We first find out the list of DE that have a non-zero overlap with area,
106 /// and then use the clusterfinder to find clusters in those areas (and DE).
107
9bf6860b 108 AliCodeTimerAuto(Form("Chamber %d",chamberId));
109
110 if ( fTriggerTrackStore && chamberId >= 6 )
111 {
112 return fBypass->GenerateClusters(chamberId,clusterStore);
113 }
114
35be7ed7 115 if (!recoParam) {
116 AliError("Reconstruction parameters are missing: unable to clusterize");
117 return 0;
118 }
119
d08b5461 120 AliMpDEIterator it;
121
122 it.First(chamberId);
123
124 Int_t nofAddedClusters(0);
125 Int_t fNCluster = clusterStore.GetSize();
126
127 AliDebug(1,Form("chamberId = %2d NofClusters before = %d searchArea=%s",
128 chamberId,fNCluster,AsString(area).Data()));
129
130 while ( !it.IsDone() )
131 {
132 Int_t detElemId = it.CurrentDEId();
133
134 TClonesArray* pads[2] =
135 {
136 static_cast<TClonesArray*>(fPads[0]->GetValue(detElemId)),
137 static_cast<TClonesArray*>(fPads[1]->GetValue(detElemId))
138 };
139
140 if ( ( pads[0] && pads[0]->GetLast()>=0 ) ||
141 ( pads[1] && pads[1]->GetLast()>=0 ) )
142 {
143 AliMpArea deArea; // area in DE-local-coordinates
144 Bool_t ok(kTRUE);
145
146 if ( area.IsValid() )
147 {
148 ok = Overlap(detElemId,area,deArea);
149 }
150
151 if ( ok )
152 {
9bf6860b 153 if ( fClusterFinder->NeedSegmentation() )
d08b5461 154 {
155 const AliMpVSegmentation* seg[2] =
156 { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
157 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
158 };
9bf6860b 159 fClusterFinder->Prepare(detElemId,pads,deArea,seg);
d08b5461 160 }
161 else
162 {
9bf6860b 163 fClusterFinder->Prepare(detElemId,pads,deArea);
d08b5461 164 }
165
166 AliDebug(1,Form("Clusterizing DE %04d with %3d pads (cath0) and %3d pads (cath1)",
167 detElemId,
168 (pads[0] ? pads[0]->GetLast()+1 : 0),
169 (pads[1] ? pads[1]->GetLast()+1 : 0)));
170
171 AliMUONCluster* cluster;
172
9bf6860b 173 while ( ( cluster = fClusterFinder->NextCluster() ) )
d08b5461 174 {
175 // add new cluster to the store with information to build its ID
176 // increment the number of clusters into the store
35be7ed7 177 AliMUONVCluster* rawCluster = clusterStore.Add(chamberId, detElemId, fNCluster++);
d08b5461 178
179 ++nofAddedClusters;
180
181 // fill array of Id of digits attached to this cluster
182 Int_t nPad = cluster->Multiplicity();
183 if (nPad < 1) AliWarning("no pad attached to the cluster");
184
185 for (Int_t iPad=0; iPad<nPad; iPad++)
186 {
187 AliMUONPad *pad = cluster->Pad(iPad);
89b4e052 188
189 // skip virtual pads
190 if (!pad->IsReal()) continue;
191
192 rawCluster->AddDigitId(pad->GetUniqueID());
d08b5461 193 }
194
195 // fill charge and other cluster informations
196 rawCluster->SetCharge(cluster->Charge());
89b4e052 197 rawCluster->SetChi2(cluster->Chi2());
d08b5461 198
199 Double_t xg, yg, zg;
200 fTransformer.Local2Global(detElemId,
201 cluster->Position().X(), cluster->Position().Y(),
202 0, xg, yg, zg);
203 rawCluster->SetXYZ(xg, yg, zg);
35be7ed7 204 rawCluster->SetErrXY(recoParam->GetDefaultNonBendingReso(chamberId),recoParam->GetDefaultBendingReso(chamberId));
d08b5461 205
206 AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e)",
89b4e052 207 detElemId,rawCluster->GetNDigits(),rawCluster->GetCharge(),
d08b5461 208 cluster->Position().X(),cluster->Position().Y(),0.0,
209 xg,yg,zg));
210 }
211 }
212 }
213 it.Next();
214 }
215
216 AliDebug(1,Form("chamberId = %2d NofClusters after = %d",chamberId,fNCluster));
217
218 return nofAddedClusters;
219}
220
9bf6860b 221
d08b5461 222//_____________________________________________________________________________
223void
224AliMUONSimpleClusterServer::Global2Local(Int_t detElemId, const AliMpArea& globalArea,
225 AliMpArea& localArea) const
226{
227 /// Convert a global area in local area for a given DE
228
229 Double_t xl,yl,zl;
230
231 Double_t zg = AliMUONConstants::DefaultChamberZ(AliMpDEManager::GetChamberId(detElemId));
232
233 fTransformer.Global2Local(detElemId,
234 globalArea.Position().X(),globalArea.Position().Y(),zg,
235 xl,yl,zl);
236
237 localArea = AliMpArea(TVector2(xl,yl), globalArea.Dimensions());
238}
239
240//_____________________________________________________________________________
241Bool_t
242AliMUONSimpleClusterServer::Overlap(Int_t detElemId,
243 const AliMpArea& area,
244 AliMpArea& deArea) const
245{
246 /// Check whether (global) area overlaps with the given DE.
247 /// If it is, set deArea to the overlap region and convert it
248 /// in the local coordinate system of that DE.
249
250 Bool_t overlap(kFALSE);
251
9bf6860b 252 AliMpArea* globalDEArea = fTransformer.GetDEArea(detElemId);
253
254 if (!globalDEArea) return kFALSE;
d08b5461 255
256 AliMpArea overlapArea;
257
258 if ( area.Overlap(*globalDEArea) )
259 {
260 overlapArea = area.Intersect(*globalDEArea);
261 Global2Local(detElemId,overlapArea,deArea);
262 overlap = kTRUE;
263 }
264 else
265 {
266 deArea = AliMpArea();
267 }
268
269 AliDebug(1,Form("DE %04d area %s globalDEArea %s overlapArea %s deArea %s overlap=%d",
270 detElemId,
271 AsString(area).Data(),
272 AsString(*globalDEArea).Data(),
273 AsString(overlapArea).Data(),
274 AsString(deArea).Data(),
275 overlap));
276
277 return overlap;
278}
279
280//_____________________________________________________________________________
281TClonesArray*
282AliMUONSimpleClusterServer::PadArray(Int_t detElemId, Int_t cathode) const
283{
284 /// Return array for given cathode of given DE
285
286 return static_cast<TClonesArray*>(fPads[cathode]->GetValue(detElemId));
287}
288
9bf6860b 289//_____________________________________________________________________________
290Bool_t
291AliMUONSimpleClusterServer::UseTriggerTrackStore(AliMUONVTriggerTrackStore* trackStore)
292{
293 /// Tells us to use trigger track store, and thus to bypass St45 clusters
294 fTriggerTrackStore = trackStore; // not owner
295 delete fBypass;
296 fBypass = new AliMUONTriggerTrackToTrackerClusters(fTransformer,fTriggerTrackStore);
297 return kTRUE;
298}
299
d08b5461 300//_____________________________________________________________________________
301void
7deb8eb0 302AliMUONSimpleClusterServer::UseDigits(TIter& next)
d08b5461 303{
304 /// Convert digitStore into two arrays of AliMUONPads
305
7deb8eb0 306 fPads[0]->Clear();
307 fPads[1]->Clear();
d08b5461 308
d08b5461 309 AliMUONVDigit* d;
d08b5461 310 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
311 {
312 if ( ! d->Charge() > 0 ) continue; // skip void digits.
313 Int_t ix = d->PadX();
314 Int_t iy = d->PadY();
315 Int_t cathode = d->Cathode();
316 Int_t detElemId = d->DetElemId();
317 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
318 GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
319 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy));
320
321 TClonesArray* padArray = PadArray(detElemId,cathode);
322 if (!padArray)
323 {
324 padArray = new TClonesArray("AliMUONPad",100);
325 fPads[cathode]->Add(detElemId,padArray);
326 }
327
328 AliMUONPad mpad(detElemId,cathode,
329 ix,iy,pad.Position().X(),pad.Position().Y(),
330 pad.Dimensions().X(),pad.Dimensions().Y(),
331 d->Charge());
332 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
333 mpad.SetUniqueID(d->GetUniqueID());
334 new ((*padArray)[padArray->GetLast()+1]) AliMUONPad(mpad);
335 }
336}
337
338//_____________________________________________________________________________
339void
340AliMUONSimpleClusterServer::Print(Option_t*) const
341{
342 /// Printout for debug only
343
344 AliMpDEIterator it;
345
346 it.First();
347
348 while ( !it.IsDone() )
349 {
350 Int_t detElemId = it.CurrentDEId();
351
352 // printout the number of pads / de, and number of used pads / de
353
354 if ( ( PadArray(detElemId,0) && PadArray(detElemId,0)->GetLast() >= 0 ) ||
355 ( PadArray(detElemId,1) && PadArray(detElemId,1)->GetLast() >= 0 ) )
356 {
357 cout << Form("---- DE %04d",detElemId) << endl;
358
359 for ( Int_t cathode = 0; cathode < 2; ++cathode )
360 {
361 cout << Form(" -- Cathode %1d",cathode) << endl;
362
363 TClonesArray* padArray = PadArray(detElemId,cathode);
364
365 if (!padArray)
366 {
367 cout << "no pad array" << endl;
368 }
369 else if ( padArray->GetLast() < 0 )
370 {
371 cout << "no pads" << endl;
372 }
373 else
374 {
375 TIter next(padArray);
376 AliMUONPad* pad;
377 while ( ( pad = static_cast<AliMUONPad*>(next()) ) )
378 {
379 pad->Print("full");
380 }
381 }
382 }
383 }
384 it.Next();
385 }
386}
387
388