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 "AliMUONRecoParam.h"
32 #include "AliMpArea.h"
33 #include "AliMpDEIterator.h"
34 #include "AliMpDEManager.h"
35 #include "AliMpExMap.h"
37 #include "AliMpSegmentation.h"
38 #include "AliMpVSegmentation.h"
39 #include <Riostream.h>
40 #include <TClonesArray.h>
44 /// \class AliMUONSimpleClusterServer
46 /// Implementation of AliMUONVClusterServer interface
49 /// \author Laurent Aphecetche, Subatech
52 ClassImp(AliMUONSimpleClusterServer)
57 TString AsString(const AliMpArea& area)
59 return Form("(X,Y)=(%7.3f,%7.3f) (DX,DY)=(%7.3f,%7.3f)",
62 area.GetDimensionX(), /// TBCL was Y !!!
63 area.GetDimensionY());
67 //_____________________________________________________________________________
68 AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder* clusterFinder,
69 const AliMUONGeometryTransformer& transformer)
70 : AliMUONVClusterServer(),
72 fClusterFinder(clusterFinder),
73 fkTransformer(transformer),
75 fTriggerTrackStore(0x0),
79 /// Note that we take ownership of the clusterFinder
81 fPads[0] = new AliMpExMap;
82 fPads[1] = new AliMpExMap;
86 //_____________________________________________________________________________
87 AliMUONSimpleClusterServer::~AliMUONSimpleClusterServer()
90 delete fClusterFinder;
96 //_____________________________________________________________________________
98 AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
99 AliMUONVClusterStore& clusterStore,
100 const AliMpArea& area,
101 const AliMUONRecoParam* recoParam)
103 /// Area is in absolute coordinate. If not valid, means clusterize all
106 /// We first find out the list of DE that have a non-zero overlap with area,
107 /// and then use the clusterfinder to find clusters in those areas (and DE).
109 AliCodeTimerAuto(Form("Chamber %d",chamberId));
111 if ( fTriggerTrackStore && chamberId >= 6 )
113 return fBypass->GenerateClusters(chamberId,clusterStore);
117 AliError("Reconstruction parameters are missing: unable to clusterize");
125 Int_t nofAddedClusters(0);
126 Int_t fNCluster = clusterStore.GetSize();
128 AliDebug(1,Form("chamberId = %2d NofClusters before = %d searchArea=%s",
129 chamberId,fNCluster,AsString(area).Data()));
131 while ( !it.IsDone() )
133 Int_t detElemId = it.CurrentDEId();
135 TClonesArray* pads[2] =
137 static_cast<TClonesArray*>(fPads[0]->GetValue(detElemId)),
138 static_cast<TClonesArray*>(fPads[1]->GetValue(detElemId))
141 if ( ( pads[0] && pads[0]->GetLast()>=0 ) ||
142 ( pads[1] && pads[1]->GetLast()>=0 ) )
144 AliMpArea deArea; // area in DE-local-coordinates
147 if ( area.IsValid() )
149 ok = Overlap(detElemId,area,deArea);
154 const AliMpVSegmentation* seg[2] =
155 { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
156 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
158 if ( fClusterFinder->NeedSegmentation() )
160 fClusterFinder->Prepare(detElemId,pads,deArea,seg);
164 fClusterFinder->Prepare(detElemId,pads,deArea);
167 AliDebug(1,Form("Clusterizing DE %04d with %3d pads (cath0) and %3d pads (cath1)",
169 (pads[0] ? pads[0]->GetLast()+1 : 0),
170 (pads[1] ? pads[1]->GetLast()+1 : 0)));
172 AliMUONCluster* cluster;
174 while ( ( cluster = fClusterFinder->NextCluster() ) )
176 // add new cluster to the store with information to build its ID
177 // increment the number of clusters into the store
178 AliMUONVCluster* rawCluster = clusterStore.Add(chamberId, detElemId, fNCluster++);
182 // fill array of Id of digits attached to this cluster
183 Int_t nPad = cluster->Multiplicity();
184 if (nPad < 1) AliWarning("no pad attached to the cluster");
186 for (Int_t iPad=0; iPad<nPad; iPad++)
188 AliMUONPad *pad = cluster->Pad(iPad);
191 if (!pad->IsReal()) continue;
193 rawCluster->AddDigitId(pad->GetUniqueID());
196 // fill charge and other cluster informations
197 rawCluster->SetCharge(cluster->Charge());
198 rawCluster->SetChi2(cluster->Chi2());
201 fkTransformer.Local2Global(detElemId,
202 cluster->Position().X(), cluster->Position().Y(),
204 rawCluster->SetXYZ(xg, yg, zg);
205 rawCluster->SetErrXY(recoParam->GetDefaultNonBendingReso(chamberId),recoParam->GetDefaultBendingReso(chamberId));
208 if (fDigitStore && fDigitStore->HasMCInformation())
210 rawCluster->SetMCLabel(FindMCLabel(*cluster, detElemId, seg));
213 AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e) label %d",
214 detElemId,rawCluster->GetNDigits(),rawCluster->GetCharge(),
215 cluster->Position().X(),cluster->Position().Y(),0.0,
216 xg,yg,zg,rawCluster->GetMCLabel()));
223 AliDebug(1,Form("chamberId = %2d NofClusters after = %d",chamberId,fNCluster));
225 return nofAddedClusters;
229 //_____________________________________________________________________________
231 AliMUONSimpleClusterServer::Global2Local(Int_t detElemId, const AliMpArea& globalArea,
232 AliMpArea& localArea) const
234 /// Convert a global area in local area for a given DE
238 Double_t zg = AliMUONConstants::DefaultChamberZ(AliMpDEManager::GetChamberId(detElemId));
240 fkTransformer.Global2Local(detElemId,
241 globalArea.GetPositionX(),globalArea.GetPositionY(),zg,
244 localArea = AliMpArea(xl,yl, globalArea.GetDimensionX(), globalArea.GetDimensionY());
247 //_____________________________________________________________________________
249 AliMUONSimpleClusterServer::Overlap(Int_t detElemId,
250 const AliMpArea& area,
251 AliMpArea& deArea) const
253 /// Check whether (global) area overlaps with the given DE.
254 /// If it is, set deArea to the overlap region and convert it
255 /// in the local coordinate system of that DE.
257 Bool_t overlap(kFALSE);
259 AliMpArea* globalDEArea = fkTransformer.GetDEArea(detElemId);
261 if (!globalDEArea) return kFALSE;
263 AliMpArea overlapArea;
265 if ( area.Overlap(*globalDEArea) )
267 overlapArea = area.Intersect(*globalDEArea);
268 Global2Local(detElemId,overlapArea,deArea);
273 deArea = AliMpArea();
276 AliDebug(1,Form("DE %04d area %s globalDEArea %s overlapArea %s deArea %s overlap=%d",
278 AsString(area).Data(),
279 AsString(*globalDEArea).Data(),
280 AsString(overlapArea).Data(),
281 AsString(deArea).Data(),
287 //_____________________________________________________________________________
289 AliMUONSimpleClusterServer::PadArray(Int_t detElemId, Int_t cathode) const
291 /// Return array for given cathode of given DE
293 return static_cast<TClonesArray*>(fPads[cathode]->GetValue(detElemId));
296 //_____________________________________________________________________________
298 AliMUONSimpleClusterServer::UseTriggerTrackStore(AliMUONVTriggerTrackStore* trackStore)
300 /// Tells us to use trigger track store, and thus to bypass St45 clusters
301 fTriggerTrackStore = trackStore; // not owner
303 fBypass = new AliMUONTriggerTrackToTrackerClusters(fkTransformer,fTriggerTrackStore);
307 //_____________________________________________________________________________
309 AliMUONSimpleClusterServer::UseDigits(TIter& next, AliMUONVDigitStore* digitStore)
311 /// Convert digitStore into two arrays of AliMUONPads
313 fDigitStore = digitStore;
319 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
321 if ( ! d->Charge() > 0 ) continue; // skip void digits.
322 Int_t ix = d->PadX();
323 Int_t iy = d->PadY();
324 Int_t cathode = d->Cathode();
325 Int_t detElemId = d->DetElemId();
326 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
327 GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
328 AliMpPad pad = seg->PadByIndices(ix,iy);
330 TClonesArray* padArray = PadArray(detElemId,cathode);
333 padArray = new TClonesArray("AliMUONPad",100);
334 fPads[cathode]->Add(detElemId,padArray);
337 AliMUONPad mpad(detElemId,cathode,
338 ix,iy,pad.GetPositionX(),pad.GetPositionY(),
339 pad.GetDimensionX(),pad.GetDimensionY(),
341 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
342 mpad.SetUniqueID(d->GetUniqueID());
343 new ((*padArray)[padArray->GetLast()+1]) AliMUONPad(mpad);
347 //_____________________________________________________________________________
349 AliMUONSimpleClusterServer::FindMCLabel(const AliMUONCluster& cluster, Int_t detElemId, const AliMpVSegmentation* seg[2]) const
351 /// Find the label of the most contributing MC track (-1 in case of failure)
352 /// The data member fDigitStore must be set
354 // --- get the digit (if any) located at the cluster position on both cathods ---
355 Int_t nTracks[2] = {0, 0};
356 AliMUONVDigit* digit[2] = {0x0, 0x0};
357 for (Int_t iCath = 0; iCath < 2; iCath++) {
359 = seg[AliMp::GetCathodType(iCath)]->PadByPosition(cluster.Position().X(), cluster.Position().Y(),kFALSE);
361 digit[iCath] = fDigitStore->FindObject(detElemId, pad.GetManuId(), pad.GetManuChannel(), iCath);
362 if (digit[iCath]) nTracks[iCath] = digit[iCath]->Ntracks();
366 if (nTracks[0] + nTracks[1] == 0) return -1;
368 // --- build the list of contributing tracks and of the associated charge ---
369 Int_t* trackId = new Int_t[nTracks[0] + nTracks[1]];
370 Float_t* trackCharge = new Float_t[nTracks[0] + nTracks[1]];
371 Int_t nTracksTot = 0;
373 // fill with contributing tracks on first cathod
374 for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
375 trackId[iTrack1] = digit[0]->Track(iTrack1);
376 trackCharge[iTrack1] = digit[0]->TrackCharge(iTrack1);
378 nTracksTot = nTracks[0];
380 // complement with contributing tracks on second cathod
381 for (Int_t iTrack2 = 0; iTrack2 < nTracks[1]; iTrack2++) {
382 Int_t trackId2 = digit[1]->Track(iTrack2);
383 // check if track exist
384 Bool_t trackExist = kFALSE;
385 for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
386 if (trackId2 == trackId[iTrack1]) {
387 // complement existing track
388 trackCharge[iTrack1] += digit[1]->TrackCharge(iTrack2);
395 trackId[nTracksTot] = trackId2;
396 trackCharge[nTracksTot] = digit[1]->TrackCharge(iTrack2);
401 // --- Find the most contributing track ---
402 Int_t mainTrackId = -1;
403 Float_t maxCharge = 0.;
404 for (Int_t iTrack = 0; iTrack < nTracksTot; iTrack++) {
405 if (trackCharge[iTrack] > maxCharge) {
406 mainTrackId = trackId[iTrack];
407 maxCharge = trackCharge[iTrack];
412 delete[] trackCharge;
417 //_____________________________________________________________________________
419 AliMUONSimpleClusterServer::Print(Option_t*) const
421 /// Printout for debug only
427 while ( !it.IsDone() )
429 Int_t detElemId = it.CurrentDEId();
431 // printout the number of pads / de, and number of used pads / de
433 if ( ( PadArray(detElemId,0) && PadArray(detElemId,0)->GetLast() >= 0 ) ||
434 ( PadArray(detElemId,1) && PadArray(detElemId,1)->GetLast() >= 0 ) )
436 cout << Form("---- DE %04d",detElemId) << endl;
438 for ( Int_t cathode = 0; cathode < 2; ++cathode )
440 cout << Form(" -- Cathode %1d",cathode) << endl;
442 TClonesArray* padArray = PadArray(detElemId,cathode);
446 cout << "no pad array" << endl;
448 else if ( padArray->GetLast() < 0 )
450 cout << "no pads" << endl;
454 TIter next(padArray);
456 while ( ( pad = static_cast<AliMUONPad*>(next()) ) )