1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONSimpleClusterServer.h"
20 #include "AliMUONConstants.h"
21 #include "AliMUONCluster.h"
22 #include "AliMUONGeometryTransformer.h"
23 #include "AliMUONPad.h"
24 #include "AliMUONVCluster.h"
25 #include "AliMUONVClusterFinder.h"
26 #include "AliMUONVClusterStore.h"
27 #include "AliMUONVDigitStore.h"
28 #include "AliMpArea.h"
29 #include "AliMpDEIterator.h"
30 #include "AliMpDEManager.h"
31 #include "AliMpExMap.h"
32 #include "AliMpSegmentation.h"
33 #include "AliMpVPadIterator.h"
34 #include "AliMpVSegmentation.h"
37 #include <Riostream.h>
38 #include <TClonesArray.h>
41 /// \class AliMUONSimpleClusterServer
43 /// Implementation of AliMUONVClusterServer interface
46 /// \author Laurent Aphecetche, Subatech
49 ClassImp(AliMUONSimpleClusterServer)
54 TString AsString(const AliMpArea& area)
56 return Form("(X,Y)=(%7.3f,%7.3f) (DX,DY)=(%7.3f,%7.3f)",
59 area.Dimensions().Y(),
60 area.Dimensions().Y());
64 //_____________________________________________________________________________
65 AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder& clusterFinder,
66 const AliMUONGeometryTransformer& transformer)
67 : AliMUONVClusterServer(),
68 fClusterFinder(clusterFinder),
69 fTransformer(transformer),
71 fDEAreas(new AliMpExMap(true))
79 /// Generate the DE areas in global coordinates
81 while ( !it.IsDone() )
83 Int_t detElemId = it.CurrentDEId();
85 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0);
89 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
91 Double_t xl(0.0), yl(0.0), zl(0.0);
92 Double_t dx(seg->Dimensions().X());
93 Double_t dy(seg->Dimensions().Y());
95 if ( stationType == AliMp::kStation1 || stationType == AliMp::kStation2 )
97 Double_t xmin(FLT_MAX);
98 Double_t xmax(-FLT_MAX);
99 Double_t ymin(FLT_MAX);
100 Double_t ymax(-FLT_MAX);
102 for ( Int_t icathode = 0; icathode < 2; ++icathode )
104 const AliMpVSegmentation* cathode
105 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::GetCathodType(icathode));
107 AliMpVPadIterator* it = cathode->CreateIterator();
111 while ( !it->IsDone() )
113 AliMpPad pad = it->CurrentItem();
114 AliMpArea a(pad.Position(),pad.Dimensions());
115 xmin = TMath::Min(xmin,a.LeftBorder());
116 xmax = TMath::Max(xmax,a.RightBorder());
117 ymin = TMath::Min(ymin,a.DownBorder());
118 ymax = TMath::Max(ymax,a.UpBorder());
125 xl = (xmin+xmax)/2.0;
126 yl = (ymin+ymax)/2.0;
127 dx = (xmax-xmin)/2.0;
128 dy = (ymax-ymin)/2.0;
130 fTransformer.Local2Global(detElemId,xl,yl,zl,xg,yg,zg);
134 fTransformer.Local2Global(detElemId,xl,yl,zl,xg,yg,zg);
137 fDEAreas->Add(detElemId,new AliMpArea(TVector2(xg,yg),TVector2(dx,dy)));
143 //_____________________________________________________________________________
144 AliMUONSimpleClusterServer::~AliMUONSimpleClusterServer()
152 //_____________________________________________________________________________
154 AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
155 AliMUONVClusterStore& clusterStore,
156 const AliMpArea& area)
158 /// Area is in absolute coordinate. If not valid, means clusterize all
161 /// We first find out the list of DE that have a non-zero overlap with area,
162 /// and then use the clusterfinder to find clusters in those areas (and DE).
168 Int_t nofAddedClusters(0);
169 Int_t fNCluster = clusterStore.GetSize();
171 AliDebug(1,Form("chamberId = %2d NofClusters before = %d searchArea=%s",
172 chamberId,fNCluster,AsString(area).Data()));
174 while ( !it.IsDone() )
176 Int_t detElemId = it.CurrentDEId();
178 TClonesArray* pads[2] =
180 static_cast<TClonesArray*>(fPads[0]->GetValue(detElemId)),
181 static_cast<TClonesArray*>(fPads[1]->GetValue(detElemId))
184 if ( ( pads[0] && pads[0]->GetLast()>=0 ) ||
185 ( pads[1] && pads[1]->GetLast()>=0 ) )
187 AliMpArea deArea; // area in DE-local-coordinates
190 if ( area.IsValid() )
192 ok = Overlap(detElemId,area,deArea);
197 if ( fClusterFinder.NeedSegmentation() )
199 const AliMpVSegmentation* seg[2] =
200 { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
201 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
203 fClusterFinder.Prepare(detElemId,pads,deArea,seg);
207 fClusterFinder.Prepare(detElemId,pads,deArea);
210 AliDebug(1,Form("Clusterizing DE %04d with %3d pads (cath0) and %3d pads (cath1)",
212 (pads[0] ? pads[0]->GetLast()+1 : 0),
213 (pads[1] ? pads[1]->GetLast()+1 : 0)));
215 AliMUONCluster* cluster;
217 while ( ( cluster = fClusterFinder.NextCluster() ) )
219 // add new cluster to the store with information to build its ID
220 // increment the number of clusters into the store
221 AliMUONVCluster* rawCluster = clusterStore.Add(AliMpDEManager::GetChamberId(detElemId), detElemId, fNCluster++);
225 // fill array of Id of digits attached to this cluster
226 Int_t nPad = cluster->Multiplicity();
227 if (nPad < 1) AliWarning("no pad attached to the cluster");
229 for (Int_t iPad=0; iPad<nPad; iPad++)
231 AliMUONPad *pad = cluster->Pad(iPad);
232 rawCluster->AddDigitId(pad->GetUniqueID());
235 // fill charge and other cluster informations
236 rawCluster->SetCharge(cluster->Charge());
239 fTransformer.Local2Global(detElemId,
240 cluster->Position().X(), cluster->Position().Y(),
242 rawCluster->SetXYZ(xg, yg, zg);
244 AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e)",
245 detElemId,nPad,cluster->Charge(),
246 cluster->Position().X(),cluster->Position().Y(),0.0,
254 AliDebug(1,Form("chamberId = %2d NofClusters after = %d",chamberId,fNCluster));
256 return nofAddedClusters;
259 //_____________________________________________________________________________
261 AliMUONSimpleClusterServer::Global2Local(Int_t detElemId, const AliMpArea& globalArea,
262 AliMpArea& localArea) const
264 /// Convert a global area in local area for a given DE
268 Double_t zg = AliMUONConstants::DefaultChamberZ(AliMpDEManager::GetChamberId(detElemId));
270 fTransformer.Global2Local(detElemId,
271 globalArea.Position().X(),globalArea.Position().Y(),zg,
274 localArea = AliMpArea(TVector2(xl,yl), globalArea.Dimensions());
277 //_____________________________________________________________________________
279 AliMUONSimpleClusterServer::Overlap(Int_t detElemId,
280 const AliMpArea& area,
281 AliMpArea& deArea) const
283 /// Check whether (global) area overlaps with the given DE.
284 /// If it is, set deArea to the overlap region and convert it
285 /// in the local coordinate system of that DE.
287 Bool_t overlap(kFALSE);
289 AliMpArea* globalDEArea = static_cast<AliMpArea*>(fDEAreas->GetValue(detElemId));
291 AliMpArea overlapArea;
293 if ( area.Overlap(*globalDEArea) )
295 overlapArea = area.Intersect(*globalDEArea);
296 Global2Local(detElemId,overlapArea,deArea);
301 deArea = AliMpArea();
304 AliDebug(1,Form("DE %04d area %s globalDEArea %s overlapArea %s deArea %s overlap=%d",
306 AsString(area).Data(),
307 AsString(*globalDEArea).Data(),
308 AsString(overlapArea).Data(),
309 AsString(deArea).Data(),
315 //_____________________________________________________________________________
317 AliMUONSimpleClusterServer::PadArray(Int_t detElemId, Int_t cathode) const
319 /// Return array for given cathode of given DE
321 return static_cast<TClonesArray*>(fPads[cathode]->GetValue(detElemId));
324 //_____________________________________________________________________________
326 AliMUONSimpleClusterServer::UseDigitStore(const AliMUONVDigitStore& digitStore)
328 /// Convert digitStore into two arrays of AliMUONPads
333 fPads[0] = new AliMpExMap(true);
334 fPads[1] = new AliMpExMap(true);
336 TIter next(digitStore.CreateIterator());
339 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
341 if ( ! d->Charge() > 0 ) continue; // skip void digits.
342 Int_t ix = d->PadX();
343 Int_t iy = d->PadY();
344 Int_t cathode = d->Cathode();
345 Int_t detElemId = d->DetElemId();
346 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
347 GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
348 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy));
350 TClonesArray* padArray = PadArray(detElemId,cathode);
353 padArray = new TClonesArray("AliMUONPad",100);
354 fPads[cathode]->Add(detElemId,padArray);
357 AliMUONPad mpad(detElemId,cathode,
358 ix,iy,pad.Position().X(),pad.Position().Y(),
359 pad.Dimensions().X(),pad.Dimensions().Y(),
361 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
362 mpad.SetUniqueID(d->GetUniqueID());
363 new ((*padArray)[padArray->GetLast()+1]) AliMUONPad(mpad);
367 //_____________________________________________________________________________
369 AliMUONSimpleClusterServer::Print(Option_t*) const
371 /// Printout for debug only
377 while ( !it.IsDone() )
379 Int_t detElemId = it.CurrentDEId();
381 // printout the number of pads / de, and number of used pads / de
383 if ( ( PadArray(detElemId,0) && PadArray(detElemId,0)->GetLast() >= 0 ) ||
384 ( PadArray(detElemId,1) && PadArray(detElemId,1)->GetLast() >= 0 ) )
386 cout << Form("---- DE %04d",detElemId) << endl;
388 for ( Int_t cathode = 0; cathode < 2; ++cathode )
390 cout << Form(" -- Cathode %1d",cathode) << endl;
392 TClonesArray* padArray = PadArray(detElemId,cathode);
396 cout << "no pad array" << endl;
398 else if ( padArray->GetLast() < 0 )
400 cout << "no pads" << endl;
404 TIter next(padArray);
406 while ( ( pad = static_cast<AliMUONPad*>(next()) ) )