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 "AliCodeTimer.h"
22 #include "AliMUONCluster.h"
23 #include "AliMUONConstants.h"
24 #include "AliMUONGeometryTransformer.h"
25 #include "AliMUONPad.h"
26 #include "AliMUONTriggerTrackToTrackerClusters.h"
27 #include "AliMUONVCluster.h"
28 #include "AliMUONVClusterFinder.h"
29 #include "AliMUONVClusterStore.h"
30 #include "AliMUONVDigitStore.h"
31 #include "AliMpArea.h"
32 #include "AliMpDEIterator.h"
33 #include "AliMpDEManager.h"
34 #include "AliMpExMap.h"
36 #include "AliMpSegmentation.h"
37 #include "AliMpVSegmentation.h"
38 #include <Riostream.h>
39 #include <TClonesArray.h>
43 /// \class AliMUONSimpleClusterServer
45 /// Implementation of AliMUONVClusterServer interface
48 /// \author Laurent Aphecetche, Subatech
51 ClassImp(AliMUONSimpleClusterServer)
56 TString AsString(const AliMpArea& area)
58 return Form("(X,Y)=(%7.3f,%7.3f) (DX,DY)=(%7.3f,%7.3f)",
61 area.Dimensions().Y(),
62 area.Dimensions().Y());
66 //_____________________________________________________________________________
67 AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder* clusterFinder,
68 const AliMUONGeometryTransformer& transformer)
69 : AliMUONVClusterServer(),
70 fClusterFinder(clusterFinder),
71 fTransformer(transformer),
73 fTriggerTrackStore(0x0),
77 /// Note that we take ownership of the clusterFinder
79 fPads[0] = new AliMpExMap(true);
80 fPads[1] = new AliMpExMap(true);
84 //_____________________________________________________________________________
85 AliMUONSimpleClusterServer::~AliMUONSimpleClusterServer()
88 delete fClusterFinder;
94 //_____________________________________________________________________________
96 AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
97 AliMUONVClusterStore& clusterStore,
98 const AliMpArea& area)
100 /// Area is in absolute coordinate. If not valid, means clusterize all
103 /// We first find out the list of DE that have a non-zero overlap with area,
104 /// and then use the clusterfinder to find clusters in those areas (and DE).
106 AliCodeTimerAuto(Form("Chamber %d",chamberId));
108 if ( fTriggerTrackStore && chamberId >= 6 )
110 return fBypass->GenerateClusters(chamberId,clusterStore);
117 Int_t nofAddedClusters(0);
118 Int_t fNCluster = clusterStore.GetSize();
120 AliDebug(1,Form("chamberId = %2d NofClusters before = %d searchArea=%s",
121 chamberId,fNCluster,AsString(area).Data()));
123 while ( !it.IsDone() )
125 Int_t detElemId = it.CurrentDEId();
127 TClonesArray* pads[2] =
129 static_cast<TClonesArray*>(fPads[0]->GetValue(detElemId)),
130 static_cast<TClonesArray*>(fPads[1]->GetValue(detElemId))
133 if ( ( pads[0] && pads[0]->GetLast()>=0 ) ||
134 ( pads[1] && pads[1]->GetLast()>=0 ) )
136 AliMpArea deArea; // area in DE-local-coordinates
139 if ( area.IsValid() )
141 ok = Overlap(detElemId,area,deArea);
146 if ( fClusterFinder->NeedSegmentation() )
148 const AliMpVSegmentation* seg[2] =
149 { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
150 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
152 fClusterFinder->Prepare(detElemId,pads,deArea,seg);
156 fClusterFinder->Prepare(detElemId,pads,deArea);
159 AliDebug(1,Form("Clusterizing DE %04d with %3d pads (cath0) and %3d pads (cath1)",
161 (pads[0] ? pads[0]->GetLast()+1 : 0),
162 (pads[1] ? pads[1]->GetLast()+1 : 0)));
164 AliMUONCluster* cluster;
166 while ( ( cluster = fClusterFinder->NextCluster() ) )
168 // add new cluster to the store with information to build its ID
169 // increment the number of clusters into the store
170 AliMUONVCluster* rawCluster = clusterStore.Add(AliMpDEManager::GetChamberId(detElemId), detElemId, fNCluster++);
174 // fill array of Id of digits attached to this cluster
175 Int_t nPad = cluster->Multiplicity();
176 if (nPad < 1) AliWarning("no pad attached to the cluster");
178 for (Int_t iPad=0; iPad<nPad; iPad++)
180 AliMUONPad *pad = cluster->Pad(iPad);
183 if (!pad->IsReal()) continue;
185 rawCluster->AddDigitId(pad->GetUniqueID());
188 // fill charge and other cluster informations
189 rawCluster->SetCharge(cluster->Charge());
190 rawCluster->SetChi2(cluster->Chi2());
193 fTransformer.Local2Global(detElemId,
194 cluster->Position().X(), cluster->Position().Y(),
196 rawCluster->SetXYZ(xg, yg, zg);
198 AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e)",
199 detElemId,rawCluster->GetNDigits(),rawCluster->GetCharge(),
200 cluster->Position().X(),cluster->Position().Y(),0.0,
208 AliDebug(1,Form("chamberId = %2d NofClusters after = %d",chamberId,fNCluster));
210 return nofAddedClusters;
214 //_____________________________________________________________________________
216 AliMUONSimpleClusterServer::Global2Local(Int_t detElemId, const AliMpArea& globalArea,
217 AliMpArea& localArea) const
219 /// Convert a global area in local area for a given DE
223 Double_t zg = AliMUONConstants::DefaultChamberZ(AliMpDEManager::GetChamberId(detElemId));
225 fTransformer.Global2Local(detElemId,
226 globalArea.Position().X(),globalArea.Position().Y(),zg,
229 localArea = AliMpArea(TVector2(xl,yl), globalArea.Dimensions());
232 //_____________________________________________________________________________
234 AliMUONSimpleClusterServer::Overlap(Int_t detElemId,
235 const AliMpArea& area,
236 AliMpArea& deArea) const
238 /// Check whether (global) area overlaps with the given DE.
239 /// If it is, set deArea to the overlap region and convert it
240 /// in the local coordinate system of that DE.
242 Bool_t overlap(kFALSE);
244 AliMpArea* globalDEArea = fTransformer.GetDEArea(detElemId);
246 if (!globalDEArea) return kFALSE;
248 AliMpArea overlapArea;
250 if ( area.Overlap(*globalDEArea) )
252 overlapArea = area.Intersect(*globalDEArea);
253 Global2Local(detElemId,overlapArea,deArea);
258 deArea = AliMpArea();
261 AliDebug(1,Form("DE %04d area %s globalDEArea %s overlapArea %s deArea %s overlap=%d",
263 AsString(area).Data(),
264 AsString(*globalDEArea).Data(),
265 AsString(overlapArea).Data(),
266 AsString(deArea).Data(),
272 //_____________________________________________________________________________
274 AliMUONSimpleClusterServer::PadArray(Int_t detElemId, Int_t cathode) const
276 /// Return array for given cathode of given DE
278 return static_cast<TClonesArray*>(fPads[cathode]->GetValue(detElemId));
281 //_____________________________________________________________________________
283 AliMUONSimpleClusterServer::UseTriggerTrackStore(AliMUONVTriggerTrackStore* trackStore)
285 /// Tells us to use trigger track store, and thus to bypass St45 clusters
286 fTriggerTrackStore = trackStore; // not owner
288 fBypass = new AliMUONTriggerTrackToTrackerClusters(fTransformer,fTriggerTrackStore);
292 //_____________________________________________________________________________
294 AliMUONSimpleClusterServer::UseDigits(TIter& next)
296 /// Convert digitStore into two arrays of AliMUONPads
302 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
304 if ( ! d->Charge() > 0 ) continue; // skip void digits.
305 Int_t ix = d->PadX();
306 Int_t iy = d->PadY();
307 Int_t cathode = d->Cathode();
308 Int_t detElemId = d->DetElemId();
309 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
310 GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
311 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy));
313 TClonesArray* padArray = PadArray(detElemId,cathode);
316 padArray = new TClonesArray("AliMUONPad",100);
317 fPads[cathode]->Add(detElemId,padArray);
320 AliMUONPad mpad(detElemId,cathode,
321 ix,iy,pad.Position().X(),pad.Position().Y(),
322 pad.Dimensions().X(),pad.Dimensions().Y(),
324 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
325 mpad.SetUniqueID(d->GetUniqueID());
326 new ((*padArray)[padArray->GetLast()+1]) AliMUONPad(mpad);
330 //_____________________________________________________________________________
332 AliMUONSimpleClusterServer::Print(Option_t*) const
334 /// Printout for debug only
340 while ( !it.IsDone() )
342 Int_t detElemId = it.CurrentDEId();
344 // printout the number of pads / de, and number of used pads / de
346 if ( ( PadArray(detElemId,0) && PadArray(detElemId,0)->GetLast() >= 0 ) ||
347 ( PadArray(detElemId,1) && PadArray(detElemId,1)->GetLast() >= 0 ) )
349 cout << Form("---- DE %04d",detElemId) << endl;
351 for ( Int_t cathode = 0; cathode < 2; ++cathode )
353 cout << Form(" -- Cathode %1d",cathode) << endl;
355 TClonesArray* padArray = PadArray(detElemId,cathode);
359 cout << "no pad array" << endl;
361 else if ( padArray->GetLast() < 0 )
363 cout << "no pads" << endl;
367 TIter next(padArray);
369 while ( ( pad = static_cast<AliMUONPad*>(next()) ) )