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 ///////////////////////////////////////////////////////////////////////////
19 // Class AliCalorimeter
20 // Description of a modular calorimeter system.
21 // A generic 2D geometry is used in which a module is identified by (row,col).
22 // Obviously this geometry can be a matrix, but also any other regular
23 // structure is supported, provided the user has adopted a proper convention
24 // to uniquely address a module via the (row,col) indices.
25 // Note : First module is identified as (1,1).
27 // This is the way to define and enter signals into a calorimeter :
29 // AliCalorimeter cal;
31 // cal.AddSignal(5,7,85.4);
32 // cal.AddSignal(5,7,25.9);
33 // cal.AddSignal(3,5,1000);
34 // cal.SetSignal(5,7,10.3);
35 // cal.Reset(3,5); // Reset module (3,5) as being 'not fired'
36 // // All module data are re-initialised.
37 // cal.SetEdgeOn(1,1); // Declare module (1,1) as an 'edge module'
39 // cal.SetGain(2,8,3.2);
41 // Float_t vec[3]={6,1,20};
42 // cal.SetPosition(2,8,vec,"car");
45 // Float_t loc[3]={-1,12,3};
46 // s.SetPosition(loc,"car");
48 // cal.AddVetoSignal(s); // Associate (extrapolated) signal as a veto
50 // cal.Group(2); // Group 'fired' modules into clusters
51 // // Perform grouping over 2 rings around the center
52 // cal.Reset(); // Reset the complete calorimeter
53 // // Normally to prepare for the next event data
54 // // Note : Module gain, offset, edge and dead flags remain
56 //--- Author: Nick van Eijndhoven 13-jun-1997 UU-SAP Utrecht
57 //- Modified: NvE $Date$ UU-SAP Utrecht
58 ///////////////////////////////////////////////////////////////////////////
60 #include "AliCalorimeter.h"
61 #include "Riostream.h"
63 ClassImp(AliCalorimeter) // Class implementation to enable ROOT I/O
65 AliCalorimeter::AliCalorimeter() : TObject()
67 // Default constructor, all parameters set to 0.
68 // Create a calorimeter module matrix with fixed row and column size.
69 // Note : Due to the dynamic size extension when signals are set,
70 // the "edge modules" can NOT be marked automatically.
71 // This has to be done manually by the user via the SetEdgeOn()
83 fName="Unspecified AliCalorimeter";
85 ///////////////////////////////////////////////////////////////////////////
86 AliCalorimeter::~AliCalorimeter()
88 // Destructor to delete memory allocated to the various arrays and matrices
125 ///////////////////////////////////////////////////////////////////////////
126 AliCalorimeter::AliCalorimeter(Int_t nrow,Int_t ncol) : TObject()
128 // Create a calorimeter module matrix with fixed row and column size.
129 // The modules at the edges are automatically marked as "edge modules".
138 fAttributes=new TObjArray(nrow);
139 fAttributes->SetOwner();
141 // Mark the edge modules
142 for (Int_t row=1; row<=nrow; row++)
144 AliAttribObj* a=new AliAttribObj();
145 if (row==1 || row==nrow)
147 for (Int_t col=1; col<=ncol; col++)
165 fName="Unspecified AliCalorimeter";
167 ///////////////////////////////////////////////////////////////////////////
168 AliCalorimeter::AliCalorimeter(AliCalorimeter& c) : TObject(c)
183 fNcolumns=c.fNcolumns;
190 Int_t nrows=(c.fPositions)->GetMaxRow();
191 Int_t ncols=(c.fPositions)->GetMaxColumn();
192 for (Int_t irow=1; irow<=nrows; irow++)
194 for (Int_t icol=1; icol<=ncols; icol++)
196 AliPosition* p=c.GetPosition(irow,icol);
197 if (p) SetPosition(irow,icol,*p);
203 if (c.fAttributes) size=c.fAttributes->GetSize();
206 fAttributes=new TObjArray(size);
207 fAttributes->SetOwner();
208 for (Int_t ia=0; ia<size; ia++)
210 AliAttribObj* a=(AliAttribObj*)(c.fAttributes->At(ia));
211 if (a) fAttributes->AddAt(new AliAttribObj(*a),ia);
219 fClusters=new TObjArray();
220 fClusters->SetOwner();
221 for (Int_t icl=1; icl<=n; icl++)
223 AliCalcluster* cl=c.GetCluster(icl);
224 if (cl) fClusters->Add(new AliCalcluster(*cl));
231 fMatrix=new AliObjMatrix();
233 fMatrix->SetSwapMode(fSwap);
234 for (Int_t im=1; im<=n; im++)
236 AliCalmodule* m=c.GetModule(im);
237 if (m) fMatrix->EnterObject(m->GetRow(),m->GetColumn(),new AliCalmodule(*m));
242 for (Int_t iv=1; iv<=n; iv++)
244 AliSignal* s=c.GetVetoSignal(iv);
245 if (s) AddVetoSignal(s);
248 ///////////////////////////////////////////////////////////////////////////
249 Int_t AliCalorimeter::GetNrows()
251 // Provide the number of rows for the calorimeter module matrix
253 if (fMatrix && !nrows) nrows=fMatrix->GetMaxRow();
256 ///////////////////////////////////////////////////////////////////////////
257 Int_t AliCalorimeter::GetNcolumns()
259 // Provide the number of columns for the calorimeter module matrix
260 Int_t ncols=fNcolumns;
261 if (fMatrix && !ncols) ncols=fMatrix->GetMaxColumn();
264 ///////////////////////////////////////////////////////////////////////////
265 void AliCalorimeter::SetSignal(Int_t row,Int_t col,Float_t sig)
267 // Set the signal for a certain calorimeter module.
269 // Check for (row,col) boundaries.
270 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
272 cout << " *AliCalorimeter::SetSignal* row,col : " << row << "," << col
273 << " out of range." << endl;
274 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
280 fMatrix=new AliObjMatrix();
282 fMatrix->SetSwapMode(fSwap);
285 AliCalmodule* m=GetModule(row,col);
286 if (!m) // initialise for a new module
288 m=new AliCalmodule();
290 if (fPositions) r=(AliPositionObj*)fPositions->GetObject(row,col);
291 if (r) m->SetPosition(*r);
295 if (row <= fAttributes->GetSize()) a=(AliAttribObj*)fAttributes->At(row-1);
298 if (a->GetGainFlag(col)) m->SetGain(a->GetGain(col));
299 if (a->GetOffsetFlag(col)) m->SetOffset(a->GetOffset(col));
300 if (a->GetDeadValue(col)) m->SetDead();
301 if (a->GetEdgeValue(col)) m->SetEdgeValue(a->GetEdgeValue(col));
304 fMatrix->EnterObject(row,col,m);
307 m->SetSignal(row,col,sig);
309 ///////////////////////////////////////////////////////////////////////////
310 void AliCalorimeter::AddSignal(Int_t row, Int_t col, Float_t sig)
312 // Add the signal to a certain calorimeter module.
314 // Check for (row,col) boundaries.
315 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
317 cout << " *AliCalorimeter::AddSignal* row,col : " << row << "," << col
318 << " out of range." << endl;
319 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
323 AliCalmodule* m=GetModule(row,col);
324 if (!m) // initialise for new modules
326 SetSignal(row,col,sig);
330 m->AddSignal(row,col,sig);
333 ///////////////////////////////////////////////////////////////////////////
334 void AliCalorimeter::AddSignal(AliCalmodule* mod)
336 // Add the signal of module mod to the current calorimeter data.
337 // This enables mixing of calorimeter data of various events.
339 // Note : The position and attributes according to the user provided data
340 // for the corresponding (row,col) location will be used.
341 // In case there is no user provided data present, the position and
342 // attributes of the first module added to the corresponding (row,col)
343 // location will be taken, except for the "edge" and "dead" indicators.
344 // The latter will then both be set to 0.
348 Int_t row=mod->GetRow();
349 Int_t col=mod->GetColumn();
350 Float_t sig=mod->GetSignal();
352 // Check for (row,col) boundaries.
353 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
355 cout << " *AliCalorimeter::AddSignal* row,col : " << row << "," << col
356 << " out of range." << endl;
357 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
363 fMatrix=new AliObjMatrix();
365 fMatrix->SetSwapMode(fSwap);
368 AliCalmodule* m=GetModule(row,col);
369 if (!m) // No module existed yet at this position
371 m=new AliCalmodule(*mod);
373 if (fPositions) r=(AliPositionObj*)fPositions->GetObject(row,col);
374 if (r) m->SetPosition(*r);
375 // Don't take the dead and edge attributes from this module,
376 // but from the calorimeter dbase, if present.
382 if (row <= fAttributes->GetSize()) a=(AliAttribObj*)fAttributes->At(row-1);
385 if (a->GetGainFlag(col)) m->SetGain(a->GetGain(col));
386 if (a->GetOffsetFlag(col)) m->SetOffset(a->GetOffset(col));
387 if (a->GetDeadValue(col)) m->SetDead();
388 if (a->GetEdgeValue(col)) m->SetEdgeValue(a->GetEdgeValue(col));
391 fMatrix->EnterObject(row,col,m);
395 m->AddSignal(row,col,sig);
398 ///////////////////////////////////////////////////////////////////////////
399 void AliCalorimeter::Reset(Int_t row,Int_t col)
401 // Reset the signal for a certain calorimeter module.
402 // Note : Module position and attributes remain unchanged.
404 // Check for (row,col) boundaries.
405 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
407 cout << " *AliCalorimeter::Reset* row,col : " << row << "," << col
408 << " out of range." << endl;
409 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
413 AliCalmodule* m=GetModule(row,col);
414 if (m) fMatrix->RemoveObject(row,col);
416 ///////////////////////////////////////////////////////////////////////////
417 void AliCalorimeter::Reset(Int_t mode)
419 // Reset the signals for the complete calorimeter.
420 // Normally this is done to prepare for the data of the next event.
422 // mode = 0 : Swap mode, module positions and attributes remain unchanged.
423 // 1 : Swap mode, module positions and attributes are cleared.
425 // The default is mode=0.
427 // Note : In the case of reading AliCalorimeter objects from a data file,
428 // one has to reset the AliCalorimeter object with mode=1
429 // (or explicitly delete it) before reading-in the next object
430 // in order to prevent memory leaks.
432 if (mode<0 || mode>1)
434 cout << " *AliCalorimeter::Reset* Wrong argument. mode = " << mode << endl;
465 if (fMatrix) fMatrix->Reset();
468 // Free memory allocated for the various arrays.
488 ///////////////////////////////////////////////////////////////////////////
489 Float_t AliCalorimeter::GetSignal(Int_t row,Int_t col,Int_t mode)
491 // Provide the signal of a certain calorimeter module.
492 // In case the module was marked dead, 0 is returned.
494 // mode = 0 : Just the module signal is returned
495 // 1 : The module signal is corrected for the gain and offset.
496 // In case the gain value was not set, gain=1 will be assumed.
497 // In case the gain value was 0, a signal value of 0 is returned.
498 // In case the offset value was not set, offset=0 will be assumed.
500 // The corrected signal (sigc) is determined as follows :
502 // sigc=(signal/gain)-offset
504 // The default is mode=0.
506 // Check for (row,col) boundaries.
507 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
509 cout << " *AliCalorimeter::GetSignal* row,col : " << row << "," << col
510 << " out of range." << endl;
511 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
518 AliCalmodule* m=GetModule(row,col);
521 Int_t dead=m->GetDeadValue();
522 if (!dead) signal=m->GetSignal();
524 if (mode==0 || dead) return signal;
526 // Correct the signal for the gain and offset
527 if (GetGainFlag(row,col))
529 gain=GetGain(row,col);
533 if (m->GetGainFlag()) gain=m->GetGain();
536 if (GetOffsetFlag(row,col))
538 offset=GetOffset(row,col);
542 if (m->GetOffsetFlag()) offset=m->GetOffset();
547 signal=(signal/gain)-offset;
556 ///////////////////////////////////////////////////////////////////////////
557 void AliCalorimeter::SetEdgeOn(Int_t row,Int_t col)
559 // Indicate a certain calorimeter module as 'edge module'.
561 // Check for (row,col) boundaries.
562 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
564 cout << " *AliCalorimeter::SetEdgeOn* row,col : " << row << "," << col
565 << " out of range." << endl;
566 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
572 fAttributes=new TObjArray(row);
573 fAttributes->SetOwner();
577 if (row > fAttributes->GetSize()) fAttributes->Expand(row);
580 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
587 a=new AliAttribObj();
589 fAttributes->AddAt(a,row-1);
592 AliCalmodule* m=GetModule(row,col);
593 if (m) m->SetEdgeOn();
595 ///////////////////////////////////////////////////////////////////////////
596 void AliCalorimeter::SetEdgeOff(Int_t row,Int_t col)
598 // Indicate a certain calorimeter module as 'non-edge module'.
600 // Check for (row,col) boundaries.
601 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
603 cout << " *AliCalorimeter::SetEdgeOff* row,col : " << row << "," << col
604 << " out of range." << endl;
605 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
609 // Only action on fAttributes in case an attribute is present at (row,col),
610 // since by default a module has edge=0 unless explicitly set otherwise.
613 if (row <= fAttributes->GetSize())
615 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
616 if (a) a->SetEdgeOff(col);
620 AliCalmodule* m=GetModule(row,col);
621 if (m) m->SetEdgeOff();
623 ///////////////////////////////////////////////////////////////////////////
624 void AliCalorimeter::SetDead(Int_t row,Int_t col)
626 // Indicate a certain calorimeter module as 'dead module'
628 // Check for (row,col) boundaries in case of a fixed size calorimeter
629 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
631 cout << " *AliCalorimeter::SetDead* row,col : " << row << "," << col
632 << " out of range." << endl;
633 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
637 // Make Attributes storage 1 row (and also 1 column) larger than needed
638 // because the 'edge value' of the (future) surrounding modules has
639 // to be updated as well.
642 fAttributes=new TObjArray(row+1);
643 fAttributes->SetOwner();
647 if (row >= fAttributes->GetSize()) fAttributes->Expand(row+1);
650 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
657 a=new AliAttribObj();
659 fAttributes->AddAt(a,row-1);
662 AliCalmodule* m=GetModule(row,col);
665 // Increase the 'edge value' of surrounding modules
671 if (rlow < 1) rlow=row;
672 if (clow < 1) clow=col;
674 for (Int_t i=rlow; i<=rup; i++)
676 for (Int_t j=clow; j<=cup; j++)
678 if (i!=row || j!=col) // No increase of edge value for the 'dead' module itself
680 AliAttribObj* a=(AliAttribObj*)fAttributes->At(i-1);
683 a->IncreaseEdgeValue(j);
687 a=new AliAttribObj();
689 fAttributes->AddAt(a,i-1);
692 AliCalmodule* m=GetModule(i,j);
693 if (m) m->IncreaseEdgeValue();
698 ///////////////////////////////////////////////////////////////////////////
699 void AliCalorimeter::SetAlive(Int_t row,Int_t col)
701 // Indicate a certain calorimeter module as 'active module'.
703 // Check for (row,col) boundaries.
704 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
706 cout << " *AliCalorimeter::SetAlive* row,col : " << row << "," << col
707 << " out of range." << endl;
708 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
712 // Only action on fAttributes in case an attribute is present at (row,col),
713 // since by default a module has dead=0 unless explicitly set otherwise.
716 if (row <= fAttributes->GetSize())
718 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
719 if (a) a->SetAlive(col);
723 AliCalmodule* m=GetModule(row,col);
724 if (m) m->SetAlive();
726 // Decrease the 'edge value' of surrounding modules
732 if (rlow < 1) rlow=row;
733 if (clow < 1) clow=col;
735 for (Int_t i=rlow; i<=rup; i++)
737 for (Int_t j=clow; j<=cup; j++)
739 if (i!=row || j!=col) // No decrease of edge value for the 'alive' module itself
741 if (i <= fAttributes->GetSize())
743 AliAttribObj* a=(AliAttribObj*)fAttributes->At(i-1);
744 if (a) a->DecreaseEdgeValue(j);
746 AliCalmodule* m=GetModule(i,j);
747 if (m) m->DecreaseEdgeValue();
752 ///////////////////////////////////////////////////////////////////////////
753 void AliCalorimeter::SetGain(Int_t row,Int_t col,Float_t gain)
755 // Set the gain value for a certain calorimeter module.
756 // See the memberfunction GetSignal() for a definition of the gain value.
758 // Check for (row,col) boundaries.
759 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
761 cout << " *AliCalorimeter::SetGain* row,col : " << row << "," << col
762 << " out of range." << endl;
763 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
769 fAttributes=new TObjArray(row);
770 fAttributes->SetOwner();
774 if (row > fAttributes->GetSize()) fAttributes->Expand(row);
777 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
780 a->SetGain(gain,col);
784 a=new AliAttribObj();
785 a->SetGain(gain,col);
786 fAttributes->AddAt(a,row-1);
789 AliCalmodule* m=GetModule(row,col);
790 if (m) m->SetGain(gain);
792 ///////////////////////////////////////////////////////////////////////////
793 void AliCalorimeter::SetOffset(Int_t row,Int_t col,Float_t offset)
795 // Set the offset value for a certain calorimeter module.
796 // See the memberfunction GetSignal() for a definition of the offset value.
798 // Check for (row,col) boundaries.
799 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
801 cout << " *AliCalorimeter::SetOffset* row,col : " << row << "," << col
802 << " out of range." << endl;
803 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
809 fAttributes=new TObjArray(row);
810 fAttributes->SetOwner();
814 if (row > fAttributes->GetSize()) fAttributes->Expand(row);
817 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
820 a->SetOffset(offset,col);
824 a=new AliAttribObj();
825 a->SetOffset(offset,col);
826 fAttributes->AddAt(a,row-1);
829 AliCalmodule* m=GetModule(row,col);
830 if (m) m->SetOffset(offset);
832 ///////////////////////////////////////////////////////////////////////////
833 void AliCalorimeter::SetPosition(Int_t row,Int_t col,Float_t* vec,TString f)
835 // Set the position in user coordinates for a certain calorimeter module
838 SetPosition(row,col,r);
840 ///////////////////////////////////////////////////////////////////////////
841 void AliCalorimeter::SetPosition(Int_t row,Int_t col,Ali3Vector& r)
843 // Set the position for a certain calorimeter module
845 // Check for (row,col) boundaries.
846 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
848 cout << " *AliCalorimeter::SetPosition* row,col : " << row << "," << col
849 << " out of range." << endl;
850 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
856 fPositions=new AliObjMatrix();
857 fPositions->SetOwner();
858 fPositions->SetSwapMode(fSwap);
861 AliPositionObj* p=(AliPositionObj*)fPositions->GetObject(row,col);
869 p=new AliPositionObj();
871 fPositions->EnterObject(row,col,p);
874 // Update the position of the calorimeter module itself as well if it exists
875 AliCalmodule* m=GetModule(row,col);
876 if (m) m->SetPosition(r);
878 ///////////////////////////////////////////////////////////////////////////
879 Int_t AliCalorimeter::GetEdgeValue(Int_t row,Int_t col)
881 // Provide the value of the edge flag of a certain module.
883 // Check for (row,col) boundaries.
884 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
886 cout << " *AliCalorimeter::GetEdgeValue* row,col : " << row << "," << col
887 << " out of range." << endl;
888 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
896 if (row <= fAttributes->GetSize())
898 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
901 if (col <= a->GetNcalflags())
903 edge=a->GetEdgeValue(col);
910 AliCalmodule* m=GetModule(row,col);
911 if (m) edge=m->GetEdgeValue();
914 ///////////////////////////////////////////////////////////////////////////
915 Int_t AliCalorimeter::GetDeadValue(Int_t row,Int_t col)
917 // Provide the value of the dead flag of a certain module
919 // Check for (row,col) boundaries.
920 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
922 cout << " *AliCalorimeter::GetDeadValue* row,col : " << row << "," << col
923 << " out of range." << endl;
924 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
932 if (row <= fAttributes->GetSize())
934 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
937 if (col <= a->GetNcalflags())
939 dead=a->GetDeadValue(col);
946 AliCalmodule* m=GetModule(row,col);
947 if (m) dead=m->GetDeadValue();
950 ///////////////////////////////////////////////////////////////////////////
951 Int_t AliCalorimeter::GetGainFlag(Int_t row,Int_t col)
953 // Provide the value of the gain flag of a certain module.
955 // Check for (row,col) boundaries.
956 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
958 cout << " *AliCalorimeter::GetGainFlag* row,col : " << row << "," << col
959 << " out of range." << endl;
960 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
968 if (row <= fAttributes->GetSize())
970 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
973 if (col <= a->GetNcalflags())
975 gf=a->GetGainFlag(col);
982 AliCalmodule* m=GetModule(row,col);
983 if (m) gf=m->GetGainFlag();
986 ///////////////////////////////////////////////////////////////////////////
987 Int_t AliCalorimeter::GetOffsetFlag(Int_t row,Int_t col)
989 // Provide the value of the offset flag of a certain module.
991 // Check for (row,col) boundaries.
992 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
994 cout << " *AliCalorimeter::GetOffsetFlag* row,col : " << row << "," << col
995 << " out of range." << endl;
996 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1004 if (row <= fAttributes->GetSize())
1006 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
1009 if (col <= a->GetNcalflags())
1011 of=a->GetOffsetFlag(col);
1018 AliCalmodule* m=GetModule(row,col);
1019 if (m) of=m->GetOffsetFlag();
1022 ///////////////////////////////////////////////////////////////////////////
1023 Float_t AliCalorimeter::GetGain(Int_t row,Int_t col)
1025 // Provide the gain value of a certain module.
1026 // See the memberfunction GetSignal() for a definition of the gain value.
1028 // In case the gain value is unknown, the value 0 will be returned.
1030 // Check for (row,col) boundaries.
1031 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1033 cout << " *AliCalorimeter::GetGain* row,col : " << row << "," << col
1034 << " out of range." << endl;
1035 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1043 if (row <= fAttributes->GetSize())
1045 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
1048 if (col <= a->GetNcalflags())
1050 if (a->GetGainFlag(col))
1052 gain=a->GetGain(col);
1060 AliCalmodule* m=GetModule(row,col);
1063 if (m->GetGainFlag())
1070 ///////////////////////////////////////////////////////////////////////////
1071 Float_t AliCalorimeter::GetOffset(Int_t row,Int_t col)
1073 // Provide the offset value of a certain module.
1074 // See the memberfunction GetSignal() for a definition of the offset value.
1076 // In case the offset value is unknown, the value 0 will be returned.
1078 // Check for (row,col) boundaries.
1079 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1081 cout << " *AliCalorimeter::GetOffset* row,col : " << row << "," << col
1082 << " out of range." << endl;
1083 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1091 if (row <= fAttributes->GetSize())
1093 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
1096 if (col <= a->GetNcalflags())
1098 if (a->GetOffsetFlag(col))
1100 offset=a->GetOffset(col);
1108 AliCalmodule* m=GetModule(row,col);
1111 if (m->GetOffsetFlag())
1113 offset=m->GetOffset();
1118 ///////////////////////////////////////////////////////////////////////////
1119 void AliCalorimeter::GetPosition(Int_t row,Int_t col,Float_t* vec,TString f)
1121 // Return the position in user coordinates for a certain calorimeter module
1126 AliPosition* p=GetPosition(row,col);
1127 if (p) p->GetVector(vec,f);
1129 ///////////////////////////////////////////////////////////////////////////
1130 AliPosition* AliCalorimeter::GetPosition(Int_t row,Int_t col)
1132 // Access to the position of a certain calorimeter module.
1134 // Check for (row,col) boundaries.
1135 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1137 cout << " *AliCalorimeter::GetPosition* row,col : " << row << "," << col
1138 << " out of range." << endl;
1139 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1143 if (!fPositions && !fMatrix) return 0;
1145 AliPositionObj* po=0;
1146 if (fPositions) po=(AliPositionObj*)fPositions->GetObject(row,col);
1149 AliCalmodule* m=GetModule(row,col);
1152 ///////////////////////////////////////////////////////////////////////////
1153 Float_t AliCalorimeter::GetClusteredSignal(Int_t row,Int_t col)
1155 // Provide the module signal after clustering.
1157 // Check for (row,col) boundaries.
1158 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1160 cout << " *AliCalorimeter::GetClusteredSignal* row,col : " << row << "," << col
1161 << " out of range." << endl;
1162 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1168 AliCalmodule* m=GetModule(row,col);
1169 if (m) sig=m->GetClusteredSignal();
1173 ///////////////////////////////////////////////////////////////////////////
1174 Int_t AliCalorimeter::GetNsignals()
1176 // Provide the number of modules that contain a signal
1177 // Note : The number of modules marked 'dead' but which had a signal
1180 if (fMatrix) nsig=fMatrix->GetNobjects();
1183 ///////////////////////////////////////////////////////////////////////////
1184 void AliCalorimeter::Group(Int_t n,Int_t mode)
1186 // Group the individual modules into clusters.
1187 // Module signals of n rings around the central module will be grouped.
1188 // The grouping process will start with the module containing the highest signal
1189 // in an iterative way.
1190 // For this all fired modules are ordered w.r.t. decreasing signal.
1191 // The search mode for the module signal hierarchy can be specified by the user.
1193 // mode = 1 : Search performed via the (row,col) structure of the matrix (SortM)
1194 // 2 : Search performed via the linear array of fired modules (SortA)
1196 // See the docs of the memberfunctions SortM and SortA for additional details.
1198 // Default values : n=1 mode=1.
1200 if (mode<1 || mode>2)
1202 cout << " *AliCalorimeter::Group* Invalid mode : " << mode << endl;
1203 cout << " Default value mode=1 will be used." << endl;
1207 if (!fMatrix) return;
1209 Int_t nsignals=GetNsignals();
1210 if (nsignals > 0) // Only continue if there are fired modules
1212 if (GetNclusters() > 0) Ungroup(); // Restore unclustered situation if needed
1214 // Order the modules with decreasing signal
1215 AliCalmodule** ordered=new AliCalmodule*[nsignals]; // temp. array for ordered modules
1217 if (mode==1) SortM(ordered,nord);
1218 if (mode==2) SortA(ordered,nord);
1220 // Clustering of modules. Start with the highest signal.
1226 fClusters=new TObjArray();
1227 fClusters->SetOwner();
1232 for (Int_t i=0; i<nord; i++)
1234 row=ordered[i]->GetRow(); // row number of cluster center
1235 col=ordered[i]->GetColumn(); // column number of cluster center
1237 m=(AliCalmodule*)fMatrix->GetObject(row,col);
1240 // only use modules not yet used in a cluster
1241 if (m->GetClusteredSignal() > 0.)
1243 Int_t edge=GetEdgeValue(row,col);
1244 c=new AliCalcluster();
1245 if (!edge) c->Start(*m); // module to start the cluster if not on edge
1246 if (c->GetNmodules() > 0) // cluster started successfully (no edge)
1249 AddRing(row,col,n); // add signals of n rings around the center
1259 // Delete the temp. array
1262 for (Int_t j=0; j<nord; j++)
1270 ///////////////////////////////////////////////////////////////////////////
1271 void AliCalorimeter::SortM(AliCalmodule** ordered,Int_t& nord)
1273 // Order the modules with decreasing signal by looping over the (row,col) grid
1275 // Modules which were declared as "Dead" will be rejected.
1276 // The gain etc... corrected module signals will be used in the ordering process.
1278 // Note : This method may become slow for large, very finely granulated calorimeters.
1280 // Very specific case :
1281 // ====================
1282 // In case of various overlapping showers of which the central modules have
1283 // EXACTLY the same signal this ordering procedure may have the following
1284 // advantages and disadvantages.
1288 // * In case of multi-overlapping showers, the central shower will NOT
1289 // be "eaten-up" from both sides, resulting in a slightly more accurate
1291 // * This method produces re-producable results, irrespective of the filling
1292 // order of the matrix modules.
1296 // * In case of a very high occupancy, there might be a slight effect on the
1297 // cluster signals depending on the geometrical location in the detector matrix.
1299 Int_t nrows=fMatrix->GetMaxRow();
1300 Int_t ncols=fMatrix->GetMaxColumn();
1304 for (Int_t irow=1; irow<=nrows; irow++) // loop over all modules of the matrix
1306 for (Int_t icol=1; icol<=ncols; icol++)
1308 signal=GetSignal(irow,icol,1); // get the gain etc... corrected signal
1309 if (signal <= 0.) continue; // only take alive modules with a signal
1311 if (nord == 0) // store the first module with a signal at the first ordered position
1314 ordered[nord-1]=(AliCalmodule*)fMatrix->GetObject(irow,icol);
1318 for (Int_t j=0; j<=nord; j++) // put module in the right ordered position
1320 if (j == nord) // module has smallest signal seen so far
1323 ordered[j]=(AliCalmodule*)fMatrix->GetObject(irow,icol); // add module at the end
1324 break; // go for next matrix module
1327 if (signal < ordered[j]->GetSignal(1,1)) continue;
1330 for (Int_t k=nord-1; k>j; k--) // create empty position
1332 ordered[k]=ordered[k-1];
1334 ordered[j]=(AliCalmodule*)fMatrix->GetObject(irow,icol); // put module at empty position
1335 break; // go for next matrix module
1340 ///////////////////////////////////////////////////////////////////////////
1341 void AliCalorimeter::SortA(AliCalmodule** ordered,Int_t& nord)
1343 // Order the modules with decreasing signal by looping over the linear array
1344 // of fired modules.
1345 // Modules which were declared as "Dead" will be rejected.
1346 // The gain etc... corrected module signals will be used in the ordering process.
1348 // Note : This method is rather fast even for large, very finely granulated calorimeters.
1350 // Very specific case :
1351 // ====================
1352 // In case of various overlapping showers of which the central modules have
1353 // EXACTLY the same signal this ordering procedure may have the following
1354 // advantages and disadvantages.
1358 // * Even in case of a very high occupancy, the resulting cluster signals
1359 // will in general NOT depend on the geometrical location in the detector matrix.
1363 // * In case of multi-overlapping showers, the central shower might be
1364 // "eaten-up" from both sides, resulting in a slightly too low value
1365 // of the resulting cluster signal.
1366 // * This method might produce results depending on the filling
1367 // order of the matrix modules.
1370 if (fMatrix) nmods=fMatrix->GetNobjects();
1373 for (Int_t i=1; i<=nmods; i++) // loop over all fired modules of the matrix
1375 AliCalmodule* m=(AliCalmodule*)fMatrix->GetObject(i);
1378 if (m->GetDeadValue()) continue; // only take alive modules with a signal
1380 if (nord == 0) // store the first module with a signal at the first ordered position
1387 for (Int_t j=0; j<=nord; j++) // put module in the right ordered position
1389 if (j == nord) // module has smallest signal seen so far
1392 ordered[j]=m; // add module at the end
1393 break; // go for next matrix module
1396 if (m->GetSignal(1,1) < ordered[j]->GetSignal(1,1)) continue;
1399 for (Int_t k=nord-1; k>j; k--) // create empty position
1401 ordered[k]=ordered[k-1];
1403 ordered[j]=m; // put module at empty position
1404 break; // go for next matrix module
1408 ///////////////////////////////////////////////////////////////////////////
1409 void AliCalorimeter::AddRing(Int_t row, Int_t col, Int_t n)
1411 // Add module signals of 1 ring around (row,col) to current cluster.
1412 // The gain etc... corrected module signals will be used in this process.
1413 // The parameter n denotes the maximum number of rings around cluster center.
1414 // Note : This function is used recursively.
1416 if (!fMatrix) return;
1418 Int_t nrows=fMatrix->GetMaxRow();
1419 Int_t ncols=fMatrix->GetMaxColumn();
1421 if (n >= 1) // Check if any rings left for recursive calls
1423 Float_t signal=GetSignal(row,col,1); // Gain etc... corrected signal of (row,col) module
1425 Int_t lrow=row-1; if (lrow < 1) lrow=1; // row lowerbound for ring
1426 Int_t urow=row+1; if (urow > nrows) urow=nrows; // row upperbound for ring
1427 Int_t lcol=col-1; if (lcol < 1) lcol=1; // col lowerbound for ring
1428 Int_t ucol=col+1; if (ucol > ncols) ucol=ncols; // row upperbound for ring
1430 for (Int_t i=lrow; i<=urow; i++)
1432 for (Int_t j=lcol; j<=ucol; j++)
1434 // add module(i,j) to cluster if the signal <= signal(row,col)
1435 if (GetSignal(i,j,1) <= signal)
1437 AliCalmodule* m=(AliCalmodule*)fMatrix->GetObject(i,j);
1438 if (m) ((AliCalcluster*)fClusters->At(GetNclusters()-1))->Add(*m);
1440 AddRing(i,j,n-1); // Go for ring of modules around this (i,j) one
1445 ///////////////////////////////////////////////////////////////////////////
1446 Int_t AliCalorimeter::GetNclusters()
1448 // Provide the number of clusters
1450 if (fClusters) nclu=fClusters->GetEntries();
1453 ///////////////////////////////////////////////////////////////////////////
1454 AliCalcluster* AliCalorimeter::GetCluster(Int_t j)
1456 // Provide cluster number j
1457 // Note : j=1 denotes the first cluster
1459 if (!fClusters) return 0;
1461 if ((j >= 1) && (j <= GetNclusters()))
1463 return (AliCalcluster*)fClusters->At(j-1);
1467 cout << " *AliCalorimeter::GetCluster* cluster number : " << j
1468 << " out of range ==> 0 returned." << endl;
1472 ///////////////////////////////////////////////////////////////////////////
1473 AliCalmodule* AliCalorimeter::GetModule(Int_t j)
1475 // Provide 'fired' module number j
1476 // Note : j=1 denotes the first 'fired' module
1478 if (!fMatrix) return 0;
1480 if ((j >= 1) && (j <= GetNsignals()))
1482 return (AliCalmodule*)fMatrix->GetObject(j);
1486 cout << " *AliCalorimeter::GetModule* module number : " << j
1487 << " out of range ==> 0 returned." << endl;
1491 ///////////////////////////////////////////////////////////////////////////
1492 AliCalmodule* AliCalorimeter::GetModule(Int_t row,Int_t col)
1494 // Provide access to module (row,col).
1495 // Note : first module is at (1,1).
1498 if (fMatrix) m=(AliCalmodule*)fMatrix->GetObject(row,col);
1501 ///////////////////////////////////////////////////////////////////////////
1502 TH2F* AliCalorimeter::DrawModules(Float_t thresh,Int_t mode)
1504 // Provide a lego plot of the module signals.
1505 // The input parameter mode (default mode=0) has the same meaning as
1506 // specified in the memberfunction GetSignal(row,col,mode).
1507 // Only modules with a (corrected) signal value above the threshold
1508 // (default thresh=0) will be displayed.
1511 Int_t ncols=fNcolumns;
1513 if (fMatrix && !nrows && !ncols)
1515 nrows=fMatrix->GetMaxRow();
1516 ncols=fMatrix->GetMaxColumn();
1525 fHmodules=new TH2F("fHmodules","Module signals",
1526 ncols,0.5,float(ncols)+0.5,nrows,0.5,float(nrows)+0.5);
1528 fHmodules->SetDirectory(0); // Suppress global character of histo pointer
1531 Int_t nmods=GetNsignals();
1533 Float_t row,col,signal;
1535 for (Int_t i=1; i<=nmods; i++)
1537 AliCalmodule* m=(AliCalmodule*)fMatrix->GetObject(i);
1540 row=float(m->GetRow());
1541 col=float(m->GetColumn());
1542 dead=m->GetDeadValue();
1544 if (!dead) signal=GetSignal(row,col,mode);
1545 if (signal>thresh) fHmodules->Fill(col,row,signal);
1549 fHmodules->Draw("lego");
1552 ///////////////////////////////////////////////////////////////////////////
1553 TH2F* AliCalorimeter::DrawClusters(Float_t thresh)
1555 // Provide a lego plot of the cluster signals.
1556 // Only clusters with a signal value above the threshold (default thresh=0)
1557 // will be displayed.
1560 Int_t ncols=fNcolumns;
1562 if (fMatrix && !nrows && !ncols)
1564 nrows=fMatrix->GetMaxRow();
1565 ncols=fMatrix->GetMaxColumn();
1570 fHclusters->Reset();
1574 fHclusters=new TH2F("fHclusters","Cluster signals",
1575 ncols,0.5,float(ncols)+0.5,nrows,0.5,float(nrows)+0.5);
1577 fHclusters->SetDirectory(0); // Suppress global character of histo pointer
1581 Float_t row,col,signal;
1582 for (Int_t i=0; i<GetNclusters(); i++)
1584 c=(AliCalcluster*)fClusters->At(i);
1587 row=float(c->GetRow());
1588 col=float(c->GetColumn());
1589 signal=c->GetSignal();
1590 if (signal>thresh) fHclusters->Fill(col,row,signal);
1594 fHclusters->Draw("lego");
1597 ///////////////////////////////////////////////////////////////////////////
1598 void AliCalorimeter::Ungroup()
1600 // Set the module signals back to the non-clustered situation
1602 if (!fMatrix) return;
1604 Int_t nsig=GetNsignals();
1607 for (Int_t j=1; j<=nsig; j++)
1609 AliCalmodule* m=(AliCalmodule*)fMatrix->GetObject(j);
1612 signal=m->GetSignal();
1613 m->SetClusteredSignal(signal);
1617 ///////////////////////////////////////////////////////////////////////////
1618 void AliCalorimeter::AddVetoSignal(AliSignal& s)
1620 // Associate an (extrapolated) AliSignal as veto to the calorimeter.
1623 fVetos=new TObjArray();
1627 AliSignal* sx=new AliSignal(s);
1631 ///////////////////////////////////////////////////////////////////////////
1632 Int_t AliCalorimeter::GetNvetos()
1634 // Provide the number of veto signals associated to the calorimeter.
1636 if (fVetos) nvetos=fVetos->GetEntries();
1639 ///////////////////////////////////////////////////////////////////////////
1640 AliSignal* AliCalorimeter::GetVetoSignal(Int_t i)
1642 // Provide access to the i-th veto signal of this calorimeter
1643 // Note : The first hit corresponds to i=1
1645 if (i>0 && i<=GetNvetos())
1647 return (AliSignal*)fVetos->At(i-1);
1651 cout << " *AliCalorimeter::GetVetoSignal* Signal number " << i
1652 << " out of range ==> 0 returned." << endl;
1656 ///////////////////////////////////////////////////////////////////////////
1657 void AliCalorimeter::SetName(TString name)
1659 // Set the name of the calorimeter system.
1662 ///////////////////////////////////////////////////////////////////////////
1663 TString AliCalorimeter::GetName()
1665 // Provide the name of the calorimeter system.
1668 ///////////////////////////////////////////////////////////////////////////
1669 void AliCalorimeter::SetSwapMode(Int_t swap)
1671 // Set the swap mode for the module and position matrices.
1672 // At invokation of this memberfunction the default argument is swap=1.
1673 // For further details see the documentation of AliObjMatrix.
1674 if (swap==0 || swap==1)
1680 cout << " *AliCalorimeter::SetSwapMode* Invalid argument : swap = " << swap << endl;
1683 ///////////////////////////////////////////////////////////////////////////
1684 Int_t AliCalorimeter::GetSwapMode()
1686 // Provide the swap mode for the module and position matrices.
1687 // For further details see the documentation of AliObjMatrix.
1690 ///////////////////////////////////////////////////////////////////////////
1691 AliCalorimeter* AliCalorimeter::MakeCopy(AliCalorimeter& c)
1693 // Make a deep copy of the input object and provide the pointer to the copy.
1694 // This memberfunction enables automatic creation of new objects of the
1695 // correct type depending on the argument type, a feature which may be very useful
1696 // for containers like AliEvent when adding objects in case the
1697 // container owns the objects.
1699 AliCalorimeter* cal=new AliCalorimeter(c);
1702 ///////////////////////////////////////////////////////////////////////////