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);
206 size=c.fAttributes->GetSize();
207 n=c.fAttributes->GetEntries();
211 fAttributes=new TObjArray(size);
212 fAttributes->SetOwner();
213 for (Int_t ia=0; ia<n; ia++)
215 AliAttribObj* a=(AliAttribObj*)(c.fAttributes->At(ia));
216 if (a) fAttributes->Add(new AliAttribObj(*a));
223 fClusters=new TObjArray();
224 fClusters->SetOwner();
225 for (Int_t icl=1; icl<=n; icl++)
227 AliCalcluster* cl=c.GetCluster(icl);
228 if (cl) fClusters->Add(new AliCalcluster(*cl));
235 fMatrix=new AliObjMatrix();
237 fMatrix->SetSwapMode(fSwap);
238 for (Int_t im=1; im<=n; im++)
240 AliCalmodule* m=c.GetModule(im);
241 if (m) fMatrix->EnterObject(m->GetRow(),m->GetColumn(),new AliCalmodule(*m));
246 for (Int_t iv=1; iv<=n; iv++)
248 AliSignal* s=c.GetVetoSignal(iv);
249 if (s) AddVetoSignal(s);
252 ///////////////////////////////////////////////////////////////////////////
253 Int_t AliCalorimeter::GetNrows()
255 // Provide the number of rows for the calorimeter module matrix
257 if (fMatrix && !nrows) nrows=fMatrix->GetMaxRow();
260 ///////////////////////////////////////////////////////////////////////////
261 Int_t AliCalorimeter::GetNcolumns()
263 // Provide the number of columns for the calorimeter module matrix
264 Int_t ncols=fNcolumns;
265 if (fMatrix && !ncols) ncols=fMatrix->GetMaxColumn();
268 ///////////////////////////////////////////////////////////////////////////
269 void AliCalorimeter::SetSignal(Int_t row,Int_t col,Float_t sig)
271 // Set the signal for a certain calorimeter module.
273 // Check for (row,col) boundaries.
274 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
276 cout << " *AliCalorimeter::SetSignal* row,col : " << row << "," << col
277 << " out of range." << endl;
278 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
284 fMatrix=new AliObjMatrix();
286 fMatrix->SetSwapMode(fSwap);
289 AliCalmodule* m=GetModule(row,col);
290 if (!m) // initialise for a new module
292 m=new AliCalmodule();
294 if (fPositions) r=(AliPositionObj*)fPositions->GetObject(row,col);
295 if (r) m->SetPosition(*r);
299 if (row <= fAttributes->GetSize()) a=(AliAttribObj*)fAttributes->At(row-1);
302 if (a->GetGainFlag(col)) m->SetGain(a->GetGain(col));
303 if (a->GetOffsetFlag(col)) m->SetOffset(a->GetOffset(col));
304 if (a->GetDeadValue(col)) m->SetDead();
305 if (a->GetEdgeValue(col)) m->SetEdgeValue(a->GetEdgeValue(col));
308 fMatrix->EnterObject(row,col,m);
311 m->SetSignal(row,col,sig);
313 ///////////////////////////////////////////////////////////////////////////
314 void AliCalorimeter::AddSignal(Int_t row, Int_t col, Float_t sig)
316 // Add the signal to a certain calorimeter module.
318 // Check for (row,col) boundaries.
319 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
321 cout << " *AliCalorimeter::AddSignal* row,col : " << row << "," << col
322 << " out of range." << endl;
323 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
327 AliCalmodule* m=GetModule(row,col);
328 if (!m) // initialise for new modules
330 SetSignal(row,col,sig);
334 m->AddSignal(row,col,sig);
337 ///////////////////////////////////////////////////////////////////////////
338 void AliCalorimeter::AddSignal(AliCalmodule* mod)
340 // Add the signal of module mod to the current calorimeter data.
341 // This enables mixing of calorimeter data of various events.
343 // Note : The position and attributes according to the user provided data
344 // for the corresponding (row,col) location will be used.
345 // In case there is no user provided data present, the position and
346 // attributes of the first module added to the corresponding (row,col)
347 // location will be taken, except for the "edge" and "dead" indicators.
348 // The latter will then both be set to 0.
352 Int_t row=mod->GetRow();
353 Int_t col=mod->GetColumn();
354 Float_t sig=mod->GetSignal();
356 // Check for (row,col) boundaries.
357 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
359 cout << " *AliCalorimeter::AddSignal* row,col : " << row << "," << col
360 << " out of range." << endl;
361 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
367 fMatrix=new AliObjMatrix();
369 fMatrix->SetSwapMode(fSwap);
372 AliCalmodule* m=GetModule(row,col);
373 if (!m) // No module existed yet at this position
375 m=new AliCalmodule(*mod);
377 if (fPositions) r=(AliPositionObj*)fPositions->GetObject(row,col);
378 if (r) m->SetPosition(*r);
379 // Don't take the dead and edge attributes from this module,
380 // but from the calorimeter dbase, if present.
386 if (row <= fAttributes->GetSize()) a=(AliAttribObj*)fAttributes->At(row-1);
389 if (a->GetGainFlag(col)) m->SetGain(a->GetGain(col));
390 if (a->GetOffsetFlag(col)) m->SetOffset(a->GetOffset(col));
391 if (a->GetDeadValue(col)) m->SetDead();
392 if (a->GetEdgeValue(col)) m->SetEdgeValue(a->GetEdgeValue(col));
395 fMatrix->EnterObject(row,col,m);
399 m->AddSignal(row,col,sig);
402 ///////////////////////////////////////////////////////////////////////////
403 void AliCalorimeter::Reset(Int_t row,Int_t col)
405 // Reset the signal for a certain calorimeter module.
406 // Note : Module position and attributes remain unchanged.
408 // Check for (row,col) boundaries.
409 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
411 cout << " *AliCalorimeter::Reset* row,col : " << row << "," << col
412 << " out of range." << endl;
413 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
417 AliCalmodule* m=GetModule(row,col);
418 if (m) fMatrix->RemoveObject(row,col);
420 ///////////////////////////////////////////////////////////////////////////
421 void AliCalorimeter::Reset(Int_t mode)
423 // Reset the signals for the complete calorimeter.
424 // Normally this is done to prepare for the data of the next event.
426 // mode = 0 : Swap mode, module positions and attributes remain unchanged.
427 // 1 : Swap mode, module positions and attributes are cleared.
429 // The default is mode=0.
431 // Note : In the case of reading AliCalorimeter objects from a data file,
432 // one has to reset the AliCalorimeter object with mode=1
433 // (or explicitly delete it) before reading-in the next object
434 // in order to prevent memory leaks.
436 if (mode<0 || mode>1)
438 cout << " *AliCalorimeter::Reset* Wrong argument. mode = " << mode << endl;
469 if (fMatrix) fMatrix->Reset();
472 // Free memory allocated for the various arrays.
492 ///////////////////////////////////////////////////////////////////////////
493 Float_t AliCalorimeter::GetSignal(Int_t row,Int_t col,Int_t mode)
495 // Provide the signal of a certain calorimeter module.
496 // In case the module was marked dead, 0 is returned.
498 // mode = 0 : Just the module signal is returned
499 // 1 : The module signal is corrected for the gain and offset.
500 // In case the gain value was not set, gain=1 will be assumed.
501 // In case the gain value was 0, a signal value of 0 is returned.
502 // In case the offset value was not set, offset=0 will be assumed.
504 // The corrected signal (sigc) is determined as follows :
506 // sigc=(signal/gain)-offset
508 // The default is mode=0.
510 // Check for (row,col) boundaries.
511 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
513 cout << " *AliCalorimeter::GetSignal* row,col : " << row << "," << col
514 << " out of range." << endl;
515 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
522 AliCalmodule* m=GetModule(row,col);
525 Int_t dead=m->GetDeadValue();
526 if (!dead) signal=m->GetSignal();
528 if (mode==0 || dead) return signal;
530 // Correct the signal for the gain and offset
531 if (GetGainFlag(row,col))
533 gain=GetGain(row,col);
537 if (m->GetGainFlag()) gain=m->GetGain();
540 if (GetOffsetFlag(row,col))
542 offset=GetOffset(row,col);
546 if (m->GetOffsetFlag()) offset=m->GetOffset();
551 signal=(signal/gain)-offset;
560 ///////////////////////////////////////////////////////////////////////////
561 void AliCalorimeter::SetEdgeOn(Int_t row,Int_t col)
563 // Indicate a certain calorimeter module as 'edge module'.
565 // Check for (row,col) boundaries.
566 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
568 cout << " *AliCalorimeter::SetEdgeOn* row,col : " << row << "," << col
569 << " out of range." << endl;
570 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
576 fAttributes=new TObjArray(row);
577 fAttributes->SetOwner();
581 if (row > fAttributes->GetSize()) fAttributes->Expand(row);
584 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
591 a=new AliAttribObj();
593 fAttributes->AddAt(a,row-1);
596 AliCalmodule* m=GetModule(row,col);
597 if (m) m->SetEdgeOn();
599 ///////////////////////////////////////////////////////////////////////////
600 void AliCalorimeter::SetEdgeOff(Int_t row,Int_t col)
602 // Indicate a certain calorimeter module as 'non-edge module'.
604 // Check for (row,col) boundaries.
605 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
607 cout << " *AliCalorimeter::SetEdgeOff* row,col : " << row << "," << col
608 << " out of range." << endl;
609 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
613 // Only action on fAttributes in case an attribute is present at (row,col),
614 // since by default a module has edge=0 unless explicitly set otherwise.
617 if (row <= fAttributes->GetSize())
619 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
620 if (a) a->SetEdgeOff(col);
624 AliCalmodule* m=GetModule(row,col);
625 if (m) m->SetEdgeOff();
627 ///////////////////////////////////////////////////////////////////////////
628 void AliCalorimeter::SetDead(Int_t row,Int_t col)
630 // Indicate a certain calorimeter module as 'dead module'
632 // Check for (row,col) boundaries in case of a fixed size calorimeter
633 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
635 cout << " *AliCalorimeter::SetDead* row,col : " << row << "," << col
636 << " out of range." << endl;
637 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
641 // Make Attributes storage 1 row (and also 1 column) larger than needed
642 // because the 'edge value' of the (future) surrounding modules has
643 // to be updated as well.
646 fAttributes=new TObjArray(row+1);
647 fAttributes->SetOwner();
651 if (row >= fAttributes->GetSize()) fAttributes->Expand(row+1);
654 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
661 a=new AliAttribObj();
663 fAttributes->AddAt(a,row-1);
666 AliCalmodule* m=GetModule(row,col);
669 // Increase the 'edge value' of surrounding modules
675 if (rlow < 1) rlow=row;
676 if (clow < 1) clow=col;
678 for (Int_t i=rlow; i<=rup; i++)
680 for (Int_t j=clow; j<=cup; j++)
682 if (i!=row || j!=col) // No increase of edge value for the 'dead' module itself
684 AliAttribObj* a=(AliAttribObj*)fAttributes->At(i-1);
687 a->IncreaseEdgeValue(j);
691 a=new AliAttribObj();
693 fAttributes->AddAt(a,i-1);
696 AliCalmodule* m=GetModule(i,j);
697 if (m) m->IncreaseEdgeValue();
702 ///////////////////////////////////////////////////////////////////////////
703 void AliCalorimeter::SetAlive(Int_t row,Int_t col)
705 // Indicate a certain calorimeter module as 'active module'.
707 // Check for (row,col) boundaries.
708 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
710 cout << " *AliCalorimeter::SetAlive* row,col : " << row << "," << col
711 << " out of range." << endl;
712 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
716 // Only action on fAttributes in case an attribute is present at (row,col),
717 // since by default a module has dead=0 unless explicitly set otherwise.
720 if (row <= fAttributes->GetSize())
722 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
723 if (a) a->SetAlive(col);
727 AliCalmodule* m=GetModule(row,col);
728 if (m) m->SetAlive();
730 // Decrease the 'edge value' of surrounding modules
736 if (rlow < 1) rlow=row;
737 if (clow < 1) clow=col;
739 for (Int_t i=rlow; i<=rup; i++)
741 for (Int_t j=clow; j<=cup; j++)
743 if (i!=row || j!=col) // No decrease of edge value for the 'alive' module itself
745 if (i <= fAttributes->GetSize())
747 AliAttribObj* a=(AliAttribObj*)fAttributes->At(i-1);
748 if (a) a->DecreaseEdgeValue(j);
750 AliCalmodule* m=GetModule(i,j);
751 if (m) m->DecreaseEdgeValue();
756 ///////////////////////////////////////////////////////////////////////////
757 void AliCalorimeter::SetGain(Int_t row,Int_t col,Float_t gain)
759 // Set the gain value for a certain calorimeter module.
760 // See the memberfunction GetSignal() for a definition of the gain value.
762 // Check for (row,col) boundaries.
763 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
765 cout << " *AliCalorimeter::SetGain* row,col : " << row << "," << col
766 << " out of range." << endl;
767 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
773 fAttributes=new TObjArray(row);
774 fAttributes->SetOwner();
778 if (row > fAttributes->GetSize()) fAttributes->Expand(row);
781 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
784 a->SetGain(gain,col);
788 a=new AliAttribObj();
789 a->SetGain(gain,col);
790 fAttributes->AddAt(a,row-1);
793 AliCalmodule* m=GetModule(row,col);
794 if (m) m->SetGain(gain);
796 ///////////////////////////////////////////////////////////////////////////
797 void AliCalorimeter::SetOffset(Int_t row,Int_t col,Float_t offset)
799 // Set the offset value for a certain calorimeter module.
800 // See the memberfunction GetSignal() for a definition of the offset value.
802 // Check for (row,col) boundaries.
803 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
805 cout << " *AliCalorimeter::SetOffset* row,col : " << row << "," << col
806 << " out of range." << endl;
807 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
813 fAttributes=new TObjArray(row);
814 fAttributes->SetOwner();
818 if (row > fAttributes->GetSize()) fAttributes->Expand(row);
821 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
824 a->SetOffset(offset,col);
828 a=new AliAttribObj();
829 a->SetOffset(offset,col);
830 fAttributes->AddAt(a,row-1);
833 AliCalmodule* m=GetModule(row,col);
834 if (m) m->SetOffset(offset);
836 ///////////////////////////////////////////////////////////////////////////
837 void AliCalorimeter::SetPosition(Int_t row,Int_t col,Float_t* vec,TString f)
839 // Set the position in user coordinates for a certain calorimeter module
842 SetPosition(row,col,r);
844 ///////////////////////////////////////////////////////////////////////////
845 void AliCalorimeter::SetPosition(Int_t row,Int_t col,Ali3Vector& r)
847 // Set the position for a certain calorimeter module
849 // Check for (row,col) boundaries.
850 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
852 cout << " *AliCalorimeter::SetPosition* row,col : " << row << "," << col
853 << " out of range." << endl;
854 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
860 fPositions=new AliObjMatrix();
861 fPositions->SetOwner();
862 fPositions->SetSwapMode(fSwap);
865 AliPositionObj* p=(AliPositionObj*)fPositions->GetObject(row,col);
873 p=new AliPositionObj();
875 fPositions->EnterObject(row,col,p);
878 // Update the position of the calorimeter module itself as well if it exists
879 AliCalmodule* m=GetModule(row,col);
880 if (m) m->SetPosition(r);
882 ///////////////////////////////////////////////////////////////////////////
883 Int_t AliCalorimeter::GetEdgeValue(Int_t row,Int_t col)
885 // Provide the value of the edge flag of a certain module.
887 // Check for (row,col) boundaries.
888 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
890 cout << " *AliCalorimeter::GetEdgeValue* row,col : " << row << "," << col
891 << " out of range." << endl;
892 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
900 if (row <= fAttributes->GetSize())
902 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
905 if (col <= a->GetNcalflags())
907 edge=a->GetEdgeValue(col);
914 AliCalmodule* m=GetModule(row,col);
915 if (m) edge=m->GetEdgeValue();
918 ///////////////////////////////////////////////////////////////////////////
919 Int_t AliCalorimeter::GetDeadValue(Int_t row,Int_t col)
921 // Provide the value of the dead flag of a certain module
923 // Check for (row,col) boundaries.
924 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
926 cout << " *AliCalorimeter::GetDeadValue* row,col : " << row << "," << col
927 << " out of range." << endl;
928 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
936 if (row <= fAttributes->GetSize())
938 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
941 if (col <= a->GetNcalflags())
943 dead=a->GetDeadValue(col);
950 AliCalmodule* m=GetModule(row,col);
951 if (m) dead=m->GetDeadValue();
954 ///////////////////////////////////////////////////////////////////////////
955 Int_t AliCalorimeter::GetGainFlag(Int_t row,Int_t col)
957 // Provide the value of the gain flag of a certain module.
959 // Check for (row,col) boundaries.
960 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
962 cout << " *AliCalorimeter::GetGainFlag* row,col : " << row << "," << col
963 << " out of range." << endl;
964 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
972 if (row <= fAttributes->GetSize())
974 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
977 if (col <= a->GetNcalflags())
979 gf=a->GetGainFlag(col);
986 AliCalmodule* m=GetModule(row,col);
987 if (m) gf=m->GetGainFlag();
990 ///////////////////////////////////////////////////////////////////////////
991 Int_t AliCalorimeter::GetOffsetFlag(Int_t row,Int_t col)
993 // Provide the value of the offset flag of a certain module.
995 // Check for (row,col) boundaries.
996 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
998 cout << " *AliCalorimeter::GetOffsetFlag* row,col : " << row << "," << col
999 << " out of range." << endl;
1000 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1008 if (row <= fAttributes->GetSize())
1010 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
1013 if (col <= a->GetNcalflags())
1015 of=a->GetOffsetFlag(col);
1022 AliCalmodule* m=GetModule(row,col);
1023 if (m) of=m->GetOffsetFlag();
1026 ///////////////////////////////////////////////////////////////////////////
1027 Float_t AliCalorimeter::GetGain(Int_t row,Int_t col)
1029 // Provide the gain value of a certain module.
1030 // See the memberfunction GetSignal() for a definition of the gain value.
1032 // In case the gain value is unknown, the value 0 will be returned.
1034 // Check for (row,col) boundaries.
1035 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1037 cout << " *AliCalorimeter::GetGain* row,col : " << row << "," << col
1038 << " out of range." << endl;
1039 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1047 if (row <= fAttributes->GetSize())
1049 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
1052 if (col <= a->GetNcalflags())
1054 if (a->GetGainFlag(col))
1056 gain=a->GetGain(col);
1064 AliCalmodule* m=GetModule(row,col);
1067 if (m->GetGainFlag())
1074 ///////////////////////////////////////////////////////////////////////////
1075 Float_t AliCalorimeter::GetOffset(Int_t row,Int_t col)
1077 // Provide the offset value of a certain module.
1078 // See the memberfunction GetSignal() for a definition of the offset value.
1080 // In case the offset value is unknown, the value 0 will be returned.
1082 // Check for (row,col) boundaries.
1083 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1085 cout << " *AliCalorimeter::GetOffset* row,col : " << row << "," << col
1086 << " out of range." << endl;
1087 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1095 if (row <= fAttributes->GetSize())
1097 AliAttribObj* a=(AliAttribObj*)fAttributes->At(row-1);
1100 if (col <= a->GetNcalflags())
1102 if (a->GetOffsetFlag(col))
1104 offset=a->GetOffset(col);
1112 AliCalmodule* m=GetModule(row,col);
1115 if (m->GetOffsetFlag())
1117 offset=m->GetOffset();
1122 ///////////////////////////////////////////////////////////////////////////
1123 void AliCalorimeter::GetPosition(Int_t row,Int_t col,Float_t* vec,TString f)
1125 // Return the position in user coordinates for a certain calorimeter module
1130 AliPosition* p=GetPosition(row,col);
1131 if (p) p->GetVector(vec,f);
1133 ///////////////////////////////////////////////////////////////////////////
1134 AliPosition* AliCalorimeter::GetPosition(Int_t row,Int_t col)
1136 // Access to the position of a certain calorimeter module.
1138 // Check for (row,col) boundaries.
1139 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1141 cout << " *AliCalorimeter::GetPosition* row,col : " << row << "," << col
1142 << " out of range." << endl;
1143 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1147 if (!fPositions && !fMatrix) return 0;
1149 AliPositionObj* po=0;
1150 if (fPositions) po=(AliPositionObj*)fPositions->GetObject(row,col);
1153 AliCalmodule* m=GetModule(row,col);
1156 ///////////////////////////////////////////////////////////////////////////
1157 Float_t AliCalorimeter::GetClusteredSignal(Int_t row,Int_t col)
1159 // Provide the module signal after clustering.
1161 // Check for (row,col) boundaries.
1162 if (row<1 || col<1 || (fNrows && fNcolumns && (row>fNrows || col>fNcolumns)))
1164 cout << " *AliCalorimeter::GetClusteredSignal* row,col : " << row << "," << col
1165 << " out of range." << endl;
1166 if (fNrows && fNcolumns) cout << " Nrows,Ncols = " << fNrows << "," << fNcolumns << endl;
1172 AliCalmodule* m=GetModule(row,col);
1173 if (m) sig=m->GetClusteredSignal();
1177 ///////////////////////////////////////////////////////////////////////////
1178 Int_t AliCalorimeter::GetNsignals()
1180 // Provide the number of modules that contain a signal
1181 // Note : The number of modules marked 'dead' but which had a signal
1184 if (fMatrix) nsig=fMatrix->GetNobjects();
1187 ///////////////////////////////////////////////////////////////////////////
1188 void AliCalorimeter::Group(Int_t n,Int_t mode)
1190 // Group the individual modules into clusters.
1191 // Module signals of n rings around the central module will be grouped.
1192 // The grouping process will start with the module containing the highest signal
1193 // in an iterative way.
1194 // For this all fired modules are ordered w.r.t. decreasing signal.
1195 // The search mode for the module signal hierarchy can be specified by the user.
1197 // mode = 1 : Search performed via the (row,col) structure of the matrix (SortM)
1198 // 2 : Search performed via the linear array of fired modules (SortA)
1200 // See the docs of the memberfunctions SortM and SortA for additional details.
1202 // Default values : n=1 mode=1.
1204 if (mode<1 || mode>2)
1206 cout << " *AliCalorimeter::Group* Invalid mode : " << mode << endl;
1207 cout << " Default value mode=1 will be used." << endl;
1211 if (!fMatrix) return;
1213 Int_t nsignals=GetNsignals();
1214 if (nsignals > 0) // Only continue if there are fired modules
1216 if (GetNclusters() > 0) Ungroup(); // Restore unclustered situation if needed
1218 // Order the modules with decreasing signal
1219 AliCalmodule** ordered=new AliCalmodule*[nsignals]; // temp. array for ordered modules
1221 if (mode==1) SortM(ordered,nord);
1222 if (mode==2) SortA(ordered,nord);
1224 // Clustering of modules. Start with the highest signal.
1230 fClusters=new TObjArray();
1231 fClusters->SetOwner();
1236 for (Int_t i=0; i<nord; i++)
1238 row=ordered[i]->GetRow(); // row number of cluster center
1239 col=ordered[i]->GetColumn(); // column number of cluster center
1241 m=(AliCalmodule*)fMatrix->GetObject(row,col);
1244 // only use modules not yet used in a cluster
1245 if (m->GetClusteredSignal() > 0.)
1247 Int_t edge=GetEdgeValue(row,col);
1248 c=new AliCalcluster();
1249 if (!edge) c->Start(*m); // module to start the cluster if not on edge
1250 if (c->GetNmodules() > 0) // cluster started successfully (no edge)
1253 AddRing(row,col,n); // add signals of n rings around the center
1263 // Delete the temp. array
1266 for (Int_t j=0; j<nord; j++)
1274 ///////////////////////////////////////////////////////////////////////////
1275 void AliCalorimeter::SortM(AliCalmodule** ordered,Int_t& nord)
1277 // Order the modules with decreasing signal by looping over the (row,col) grid
1279 // Modules which were declared as "Dead" will be rejected.
1280 // The gain etc... corrected module signals will be used in the ordering process.
1282 // Note : This method may become slow for large, very finely granulated calorimeters.
1284 // Very specific case :
1285 // ====================
1286 // In case of various overlapping showers of which the central modules have
1287 // EXACTLY the same signal this ordering procedure may have the following
1288 // advantages and disadvantages.
1292 // * In case of multi-overlapping showers, the central shower will NOT
1293 // be "eaten-up" from both sides, resulting in a slightly more accurate
1295 // * This method produces re-producable results, irrespective of the filling
1296 // order of the matrix modules.
1300 // * In case of a very high occupancy, there might be a slight effect on the
1301 // cluster signals depending on the geometrical location in the detector matrix.
1303 Int_t nrows=fMatrix->GetMaxRow();
1304 Int_t ncols=fMatrix->GetMaxColumn();
1308 for (Int_t irow=1; irow<=nrows; irow++) // loop over all modules of the matrix
1310 for (Int_t icol=1; icol<=ncols; icol++)
1312 signal=GetSignal(irow,icol,1); // get the gain etc... corrected signal
1313 if (signal <= 0.) continue; // only take alive modules with a signal
1315 if (nord == 0) // store the first module with a signal at the first ordered position
1318 ordered[nord-1]=(AliCalmodule*)fMatrix->GetObject(irow,icol);
1322 for (Int_t j=0; j<=nord; j++) // put module in the right ordered position
1324 if (j == nord) // module has smallest signal seen so far
1327 ordered[j]=(AliCalmodule*)fMatrix->GetObject(irow,icol); // add module at the end
1328 break; // go for next matrix module
1331 if (signal < ordered[j]->GetSignal(1,1)) continue;
1334 for (Int_t k=nord-1; k>j; k--) // create empty position
1336 ordered[k]=ordered[k-1];
1338 ordered[j]=(AliCalmodule*)fMatrix->GetObject(irow,icol); // put module at empty position
1339 break; // go for next matrix module
1344 ///////////////////////////////////////////////////////////////////////////
1345 void AliCalorimeter::SortA(AliCalmodule** ordered,Int_t& nord)
1347 // Order the modules with decreasing signal by looping over the linear array
1348 // of fired modules.
1349 // Modules which were declared as "Dead" will be rejected.
1350 // The gain etc... corrected module signals will be used in the ordering process.
1352 // Note : This method is rather fast even for large, very finely granulated calorimeters.
1354 // Very specific case :
1355 // ====================
1356 // In case of various overlapping showers of which the central modules have
1357 // EXACTLY the same signal this ordering procedure may have the following
1358 // advantages and disadvantages.
1362 // * Even in case of a very high occupancy, the resulting cluster signals
1363 // will in general NOT depend on the geometrical location in the detector matrix.
1367 // * In case of multi-overlapping showers, the central shower might be
1368 // "eaten-up" from both sides, resulting in a slightly too low value
1369 // of the resulting cluster signal.
1370 // * This method might produce results depending on the filling
1371 // order of the matrix modules.
1374 if (fMatrix) nmods=fMatrix->GetNobjects();
1377 for (Int_t i=1; i<=nmods; i++) // loop over all fired modules of the matrix
1379 AliCalmodule* m=(AliCalmodule*)fMatrix->GetObject(i);
1382 if (m->GetDeadValue()) continue; // only take alive modules with a signal
1384 if (nord == 0) // store the first module with a signal at the first ordered position
1391 for (Int_t j=0; j<=nord; j++) // put module in the right ordered position
1393 if (j == nord) // module has smallest signal seen so far
1396 ordered[j]=m; // add module at the end
1397 break; // go for next matrix module
1400 if (m->GetSignal(1,1) < ordered[j]->GetSignal(1,1)) continue;
1403 for (Int_t k=nord-1; k>j; k--) // create empty position
1405 ordered[k]=ordered[k-1];
1407 ordered[j]=m; // put module at empty position
1408 break; // go for next matrix module
1412 ///////////////////////////////////////////////////////////////////////////
1413 void AliCalorimeter::AddRing(Int_t row, Int_t col, Int_t n)
1415 // Add module signals of 1 ring around (row,col) to current cluster.
1416 // The gain etc... corrected module signals will be used in this process.
1417 // The parameter n denotes the maximum number of rings around cluster center.
1418 // Note : This function is used recursively.
1420 if (!fMatrix) return;
1422 Int_t nrows=fMatrix->GetMaxRow();
1423 Int_t ncols=fMatrix->GetMaxColumn();
1425 if (n >= 1) // Check if any rings left for recursive calls
1427 Float_t signal=GetSignal(row,col,1); // Gain etc... corrected signal of (row,col) module
1429 Int_t lrow=row-1; if (lrow < 1) lrow=1; // row lowerbound for ring
1430 Int_t urow=row+1; if (urow > nrows) urow=nrows; // row upperbound for ring
1431 Int_t lcol=col-1; if (lcol < 1) lcol=1; // col lowerbound for ring
1432 Int_t ucol=col+1; if (ucol > ncols) ucol=ncols; // row upperbound for ring
1434 for (Int_t i=lrow; i<=urow; i++)
1436 for (Int_t j=lcol; j<=ucol; j++)
1438 // add module(i,j) to cluster if the signal <= signal(row,col)
1439 if (GetSignal(i,j,1) <= signal)
1441 AliCalmodule* m=(AliCalmodule*)fMatrix->GetObject(i,j);
1442 if (m) ((AliCalcluster*)fClusters->At(GetNclusters()-1))->Add(*m);
1444 AddRing(i,j,n-1); // Go for ring of modules around this (i,j) one
1449 ///////////////////////////////////////////////////////////////////////////
1450 Int_t AliCalorimeter::GetNclusters()
1452 // Provide the number of clusters
1454 if (fClusters) nclu=fClusters->GetEntries();
1457 ///////////////////////////////////////////////////////////////////////////
1458 AliCalcluster* AliCalorimeter::GetCluster(Int_t j)
1460 // Provide cluster number j
1461 // Note : j=1 denotes the first cluster
1463 if (!fClusters) return 0;
1465 if ((j >= 1) && (j <= GetNclusters()))
1467 return (AliCalcluster*)fClusters->At(j-1);
1471 cout << " *AliCalorimeter::GetCluster* cluster number : " << j
1472 << " out of range ==> 0 returned." << endl;
1476 ///////////////////////////////////////////////////////////////////////////
1477 AliCalmodule* AliCalorimeter::GetModule(Int_t j)
1479 // Provide 'fired' module number j
1480 // Note : j=1 denotes the first 'fired' module
1482 if (!fMatrix) return 0;
1484 if ((j >= 1) && (j <= GetNsignals()))
1486 return (AliCalmodule*)fMatrix->GetObject(j);
1490 cout << " *AliCalorimeter::GetModule* module number : " << j
1491 << " out of range ==> 0 returned." << endl;
1495 ///////////////////////////////////////////////////////////////////////////
1496 AliCalmodule* AliCalorimeter::GetModule(Int_t row,Int_t col)
1498 // Provide access to module (row,col).
1499 // Note : first module is at (1,1).
1502 if (fMatrix) m=(AliCalmodule*)fMatrix->GetObject(row,col);
1505 ///////////////////////////////////////////////////////////////////////////
1506 TH2F* AliCalorimeter::DrawModules(Float_t thresh,Int_t mode)
1508 // Provide a lego plot of the module signals.
1509 // The input parameter mode (default mode=0) has the same meaning as
1510 // specified in the memberfunction GetSignal(row,col,mode).
1511 // Only modules with a (corrected) signal value above the threshold
1512 // (default thresh=0) will be displayed.
1515 Int_t ncols=fNcolumns;
1517 if (fMatrix && !nrows && !ncols)
1519 nrows=fMatrix->GetMaxRow();
1520 ncols=fMatrix->GetMaxColumn();
1529 fHmodules=new TH2F("fHmodules","Module signals",
1530 ncols,0.5,float(ncols)+0.5,nrows,0.5,float(nrows)+0.5);
1532 fHmodules->SetDirectory(0); // Suppress global character of histo pointer
1535 Int_t nmods=GetNsignals();
1537 Float_t row,col,signal;
1539 for (Int_t i=1; i<=nmods; i++)
1541 AliCalmodule* m=(AliCalmodule*)fMatrix->GetObject(i);
1544 row=float(m->GetRow());
1545 col=float(m->GetColumn());
1546 dead=m->GetDeadValue();
1548 if (!dead) signal=GetSignal(row,col,mode);
1549 if (signal>thresh) fHmodules->Fill(col,row,signal);
1553 fHmodules->Draw("lego");
1556 ///////////////////////////////////////////////////////////////////////////
1557 TH2F* AliCalorimeter::DrawClusters(Float_t thresh)
1559 // Provide a lego plot of the cluster signals.
1560 // Only clusters with a signal value above the threshold (default thresh=0)
1561 // will be displayed.
1564 Int_t ncols=fNcolumns;
1566 if (fMatrix && !nrows && !ncols)
1568 nrows=fMatrix->GetMaxRow();
1569 ncols=fMatrix->GetMaxColumn();
1574 fHclusters->Reset();
1578 fHclusters=new TH2F("fHclusters","Cluster signals",
1579 ncols,0.5,float(ncols)+0.5,nrows,0.5,float(nrows)+0.5);
1581 fHclusters->SetDirectory(0); // Suppress global character of histo pointer
1585 Float_t row,col,signal;
1586 for (Int_t i=0; i<GetNclusters(); i++)
1588 c=(AliCalcluster*)fClusters->At(i);
1591 row=float(c->GetRow());
1592 col=float(c->GetColumn());
1593 signal=c->GetSignal();
1594 if (signal>thresh) fHclusters->Fill(col,row,signal);
1598 fHclusters->Draw("lego");
1601 ///////////////////////////////////////////////////////////////////////////
1602 void AliCalorimeter::Ungroup()
1604 // Set the module signals back to the non-clustered situation
1606 if (!fMatrix) return;
1608 Int_t nsig=GetNsignals();
1611 for (Int_t j=1; j<=nsig; j++)
1613 AliCalmodule* m=(AliCalmodule*)fMatrix->GetObject(j);
1616 signal=m->GetSignal();
1617 m->SetClusteredSignal(signal);
1621 ///////////////////////////////////////////////////////////////////////////
1622 void AliCalorimeter::AddVetoSignal(AliSignal& s)
1624 // Associate an (extrapolated) AliSignal as veto to the calorimeter.
1627 fVetos=new TObjArray();
1631 AliSignal* sx=new AliSignal(s);
1635 ///////////////////////////////////////////////////////////////////////////
1636 Int_t AliCalorimeter::GetNvetos()
1638 // Provide the number of veto signals associated to the calorimeter.
1640 if (fVetos) nvetos=fVetos->GetEntries();
1643 ///////////////////////////////////////////////////////////////////////////
1644 AliSignal* AliCalorimeter::GetVetoSignal(Int_t i)
1646 // Provide access to the i-th veto signal of this calorimeter
1647 // Note : The first hit corresponds to i=1
1649 if (i>0 && i<=GetNvetos())
1651 return (AliSignal*)fVetos->At(i-1);
1655 cout << " *AliCalorimeter::GetVetoSignal* Signal number " << i
1656 << " out of range ==> 0 returned." << endl;
1660 ///////////////////////////////////////////////////////////////////////////
1661 void AliCalorimeter::SetName(TString name)
1663 // Set the name of the calorimeter system.
1666 ///////////////////////////////////////////////////////////////////////////
1667 TString AliCalorimeter::GetName()
1669 // Provide the name of the calorimeter system.
1672 ///////////////////////////////////////////////////////////////////////////
1673 void AliCalorimeter::SetSwapMode(Int_t swap)
1675 // Set the swap mode for the module and position matrices.
1676 // At invokation of this memberfunction the default argument is swap=1.
1677 // For further details see the documentation of AliObjMatrix.
1678 if (swap==0 || swap==1)
1684 cout << " *AliCalorimeter::SetSwapMode* Invalid argument : swap = " << swap << endl;
1687 ///////////////////////////////////////////////////////////////////////////
1688 Int_t AliCalorimeter::GetSwapMode()
1690 // Provide the swap mode for the module and position matrices.
1691 // For further details see the documentation of AliObjMatrix.
1694 ///////////////////////////////////////////////////////////////////////////