emcCalibratedDataObject.C

Go to the documentation of this file.
00001 // $Id: emcCalibratedDataObject.C,v 1.23 2004/07/23 14:52:51 aphecetc Exp $
00002 //-------------------------------------------------------------------------
00003 //
00004 // Package: Calib
00005 // 
00006 // Copyright (C) PHENIX collaboration, 1999-2001
00007 //
00008 // Implementation of class : emcCalibratedDataObject
00009 //
00010 //-------------------------------------------------------------------------
00011 
00012 #include "emcCalibratedDataObject.h"
00013 #include <iomanip>
00014 #include <cassert>
00015 #include "TMath.h"
00016 #include "EmcIndexer.h"
00017 
00018 ClassImp(emcCalibratedDataObject)
00019 
00020   using namespace std;
00021 
00022 //_____________________________________________________________________________
00023 emcCalibratedDataObject::emcCalibratedDataObject() : PHObject()
00024 {
00025   fEnergy = 0 ;
00026   fETotal = 0 ;
00027   fTime = 0 ;
00028   fTowerId = 0 ;
00029   fSoftwareKey = 0;
00030   fDeadNeighbours = 0 ;
00031   fEnergyCalibrated = fTimeCalibrated = fZeroSuppressed = false ; 
00032   fSize = fMaxSize = 0 ;
00033   fReadOnly = false ;
00034 
00035   // MV 2001/12/08
00036   fWarnNeighbours=0;
00037 }
00038 
00039 //_____________________________________________________________________________
00040 emcCalibratedDataObject::emcCalibratedDataObject(const emcCalibratedDataObject& cdo) : PHObject()
00041 {
00042   cdo.copyTo(*this) ;
00043 }
00044 
00045 //_____________________________________________________________________________
00046 emcCalibratedDataObject&
00047 emcCalibratedDataObject::operator=(const emcCalibratedDataObject& cdo)
00048 {
00049   if ( &cdo != this )
00050     {
00051       delete[] cdo.fEnergy;
00052       delete[] cdo.fTime;
00053       delete[] cdo.fTowerId;
00054       delete[] cdo.fDeadNeighbours;
00055       delete[] cdo.fWarnNeighbours;
00056       delete[] cdo.fSoftwareKey;
00057       cdo.copyTo(*this);
00058     }
00059   return *this;
00060 }
00061 //_____________________________________________________________________________
00062 void emcCalibratedDataObject::copyTo(emcCalibratedDataObject& cdo) const
00063 {
00064   // Copy this into cdo
00065 
00066   //  TObject::Copy(cdo) ;
00067 
00068   cdo.fMaxSize = fMaxSize ;
00069   cdo.fSize = fSize ;
00070   cdo.fEnergyCalibrated = fEnergyCalibrated ;
00071   cdo.fTimeCalibrated = fTimeCalibrated ;
00072   cdo.fZeroSuppressed = fZeroSuppressed ;
00073 
00074   Int_t i ;
00075 
00076   cdo.fEnergy = new Float_t[fMaxSize] ;
00077   cdo.fTime = new Float_t[fMaxSize] ;
00078   cdo.fTowerId = new Int_t[fMaxSize] ;
00079   cdo.fDeadNeighbours = new Int_t[fMaxSize] ;
00080   cdo.fWarnNeighbours = new Int_t[fMaxSize] ;
00081   cdo.fSoftwareKey = new long[fMaxSize] ;
00082 
00083   for ( i = 0 ; i < fSize ; i++ ) {
00084     cdo.fEnergy[i] = fEnergy[i] ;
00085     cdo.fTime[i] = fTime[i] ;
00086     cdo.fTowerId[i] = fTowerId[i] ;
00087     cdo.fDeadNeighbours[i] = fDeadNeighbours[i] ;
00088 
00089     // MV 2001/12/08
00090     cdo.fWarnNeighbours[i]=fWarnNeighbours[i];
00091   }
00092 
00093   // (re-)build index map and Software Key -
00094   cdo.fIndexMap.clear() ;
00095   for ( i = 0 ; i < fSize ; i++ ) {
00096     cdo.fIndexMap[ cdo.fTowerId[i] ] = i ;
00097     cdo.fSoftwareKey[i] = GenerateSoftwareKey( cdo.fTowerId[i] ) ;
00098   }
00099 
00100   cdo.ComputeTotalEnergy() ;
00101 }
00102 
00103 //_____________________________________________________________________________
00104 emcCalibratedDataObject::~emcCalibratedDataObject()
00105 {
00106   delete[] fEnergy ;
00107   delete[] fTime ;
00108   delete[] fTowerId ; 
00109   delete[] fSoftwareKey ;
00110   delete[] fDeadNeighbours ;
00111 
00112   // MV 2001/12/08
00113   delete [] fWarnNeighbours;
00114 }
00115 
00116 //_____________________________________________________________________________
00117 emcCalibratedDataObject& emcCalibratedDataObject::operator += (const emcCalibratedDataObject& obj)
00118 {
00119   /* To be able to add obj to this, we assume that both objects have
00120      the same fMaxSize, and that they have the same Zero-Suppression 
00121      status */
00122   
00123   if ( fZeroSuppressed != obj.fZeroSuppressed ) {
00124     cerr << "<W> emcCalibratedDataObject::operator+= : "
00125          << " different fZeroSuppressed !"
00126          << " Operation aborted (object unchanged)" 
00127          << endl ;
00128     return *this ; // do nothing
00129 
00130   }
00131 
00132   // Save the ReadOnly flag
00133   bool ro = fReadOnly ;
00134 
00135   // Allow this object to be modified whatever 
00136   // its actual ReadOnly flag is.
00137   fReadOnly = false ;
00138 
00139   Int_t i ; 
00140   Int_t loop = obj.GetSize() ;
00141   Int_t twrIndex = 0 ;
00142   Int_t index = 0 ;
00143   float energy = 0.;
00144   float thetime = 0.;
00145   int neighbour = 0 ;
00146   int neighbourWarn = 0; 
00147   long softkey = 0;
00148   int towerid = 0 ;
00149 
00150   for ( i = 0 ; i < loop ; i++ ) {
00151 
00152     twrIndex = obj.GetTowerId(i) ;
00153     index = GetIndexFromTowerId(twrIndex) ;
00154     
00155     if (index==-1) {
00156       // new tower
00157       Set(fSize,obj.GetTowerId(i),obj.GetSoftwareKey(i),0,
00158           obj.GetEnergy(i),obj.GetTime(i),obj.GetDead(i), obj.GetWarn(i)) ;
00159     }
00160     else {
00161       // merge 2 signals into one tower
00162       energy = obj.fEnergy[i] + fEnergy[index] ;
00163       // we take the minimum of the TOFs as the overlap time tower.
00164       // *Coarse* approx. for Run-2 LED mode. 
00165       // *Wrong* approx. for Run-1 CDF mode (min. TOF was somewhat shifted towards the later TOF)
00166       thetime = TMath::Min(obj.fTime[i],fTime[index]) ;
00167       neighbour = ( obj.GetDead(i) | GetDead(index) ) ;
00168       neighbourWarn = (obj.GetWarn(i) | GetWarn(index));
00169 
00170       // those 2 guys should be equal but in the case one of the cdo's does not have all data members set
00171       // this shouldn't happen though ...
00172       softkey = (GetSoftwareKey(index)) ? GetSoftwareKey(index) : obj.GetSoftwareKey(i); 
00173       towerid = (GetTowerId(index)) ? (GetTowerId(index)) : obj.GetTowerId(i);
00174 
00175       // if both cdo's do not have all data members set.
00176       // this shouldn't happen though ...
00177       if (!softkey)  softkey = GenerateSoftwareKey(index);
00178 
00179       Set(index,towerid,softkey,0,energy,thetime,neighbour,neighbourWarn) ;
00180     }
00181   }
00182 
00183   // (re-)build index map and Software Key -
00184   Update();
00185 
00186   // Restore the ReadOnly flag.
00187   fReadOnly = ro ;
00188 
00189   return *this ;
00190 }
00191 
00192 //_____________________________________________________________________________
00193 // emcCalibratedDataObject emcCalibratedDataObject::operator + (const emcCalibratedDataObject& obj) const
00194 // { 
00195 //   (*this)+= obj; 
00196 //   return *this ;
00197 // }
00198 
00199 //_____________________________________________________________________________
00200 Int_t emcCalibratedDataObject::CountHits(Float_t twrEThreshold) const
00201 {
00202   int hits  = 0 ;
00203   if (fEnergyCalibrated) {
00204     int i ;
00205     for ( i = 0 ; i < fSize ; i++ ) hits += ( fEnergy[i] > twrEThreshold ) ;
00206   }
00207   return hits ;
00208 }
00209 
00210 //_____________________________________________________________________________
00211 Float_t emcCalibratedDataObject::ComputeTotalEnergy()  
00212 {
00213   fETotal = 0 ;
00214   if (fEnergyCalibrated) {
00215     fETotal = 0 ;
00216     int i ;
00217     for ( i = 0 ; i < fSize ; i++) fETotal += fEnergy[i] ;
00218     return fETotal;
00219   } else { return 0.;}   
00220 }
00221 
00222 //_____________________________________________________________________________
00223 void emcCalibratedDataObject::DecodeKey(long key, Int_t& arm, Int_t& sector, Int_t& yrow, Int_t& zrow) const
00224 {
00225   arm    = key / 100000 ; 
00226   sector = ( key - arm * 100000 ) / 10000 ; 
00227   yrow   = ( key - arm * 100000 - sector * 10000 ) / 100 ; 
00228   zrow   = key - arm * 100000 - sector * 10000 - yrow * 100 ; 
00229 }
00230 
00231 //_____________________________________________________________________________
00232 long emcCalibratedDataObject::GenerateSoftwareKey(Int_t ItemId) const
00233 {
00234 
00235   int iS ;   // sector number (0-7)
00236   int iSMT ; // tower_index number within Sector
00237   int iarm ; // arm:0=West, 1=East;
00238   int iy ;   // row number of the tower_index within a sector (bottom=>row=0)
00239   int iz ;   /* column number of the tower_index within a sector. column=0 for
00240                 lower bottom left tower_index, when sector is viewed from back 
00241                 (i.e. you are looking at the electronics).
00242               */
00243   int swkey ; /* software key = 
00244                  100000 * iarm +
00245                   10000 * iS +
00246                     100 * iy +
00247                           iz
00248                */
00249 
00250   EmcIndexer::iPXiSiST(ItemId,iS,iSMT) ; 
00251 
00252   iarm = ((iS<4)?0:1) ;
00253   if (iS<6) {
00254     iy = iSMT/72 ;
00255     iz = iSMT%72 ;
00256   }
00257   else {
00258     iy = iSMT/96 ;
00259     iz = iSMT%96 ; 
00260   }
00261   
00262   if(iS>=4){
00263     // change sector numbers to comply with PHENIX geography
00264     iS = ((iS -=6)<0)? iS+4 : iS;
00265   }
00266   swkey = 100000*iarm + 10000*iS + 100*iy + iz ;
00267        
00268   return swkey ;
00269 }
00270 
00271 
00272 //_____________________________________________________________________________
00273 void emcCalibratedDataObject::Get (Int_t index, 
00274                                    Float_t& energy, Float_t& tof) const
00275 {
00276   /* Get energy, tof using internal indexing.
00277      If index is not valid, energy=tof=-1
00278   */
00279   if ( ValidIndex(index) ) {
00280     tof        = fTime[index] ;
00281     energy     = fEnergy[index] ;
00282   }
00283   else {
00284     energy = tof = 0 ;
00285   }
00286 }
00287 
00288 //_____________________________________________________________________________
00289 void emcCalibratedDataObject::Get( Int_t index, 
00290                                    Int_t& TowerId, long & softwareKey, 
00291                                    Int_t & dummy, 
00292                                    Float_t& energy, Float_t& tof ) const
00293 {
00294   /* Get energy, tof and all Tower primitives using internal indexing.
00295      If index is not valid, energy=tof=-1
00296   */ 
00297   if ( ValidIndex(index) ) {
00298     energy        = fEnergy[index] ;
00299     tof           = fTime[index] ;
00300     TowerId       = fTowerId[index] ; 
00301     softwareKey   = fSoftwareKey[index] ;
00302     dummy = 0 ;
00303   }
00304   else {
00305     energy = tof = 0 ;
00306   }
00307 }
00308 
00309 //_____________________________________________________________________________
00310 void emcCalibratedDataObject::GetByTowerId( Int_t TowerId,  
00311                                           Float_t& energy, Float_t& tof ) const
00312 {
00313   // Returns energy for a given tower or -1 if towerindex is not valid.
00314   Int_t index = GetIndexFromTowerId(TowerId) ;
00315   if (index>=0) {
00316     energy =  fEnergy[index] ; 
00317     tof    =  fTime[index];
00318   } else {
00319     energy = 0.;
00320     tof    = 0.;
00321   }
00322 }
00323 
00324 //_____________________________________________________________________________
00325 Int_t emcCalibratedDataObject::GetDead(Int_t index) const
00326 {
00327   Int_t dead = 0 ;
00328 
00329   if ( ValidIndex(index) ) dead = fDeadNeighbours[index] ;
00330 
00331   return dead ;
00332 }
00333 
00334 //_____________________________________________________________________________
00335 Int_t emcCalibratedDataObject::GetWarn(Int_t index) const
00336 {
00337   // MV 2001/12/08
00338 
00339   Int_t warn=0;
00340 
00341   if(ValidIndex(index)) warn=fWarnNeighbours[index] ;
00342 
00343   return warn;
00344 }
00345 
00346 //_____________________________________________________________________________
00347 Int_t emcCalibratedDataObject::GetDeadByTowerId(Int_t TowerId) const
00348 {
00349   // Returns energy for a given tower or 0 if towerindex is not valid.
00350   Int_t index = GetIndexFromTowerId(TowerId) ;
00351 
00352   if (index>=0) {
00353     return fDeadNeighbours[index] ; 
00354   }
00355   else {
00356     return 0 ; 
00357   }
00358 }
00359 
00360 //____________________________________________________________________________
00361 Int_t emcCalibratedDataObject::GetWarnByTowerId(Int_t TowerId) const
00362 {
00363   // MV 2001/12/08
00364 
00365   Int_t index = GetIndexFromTowerId(TowerId) ;
00366 
00367   if (index>=0) {
00368     return fWarnNeighbours[index] ; 
00369   }
00370   else {
00371     return 0 ; 
00372   }
00373 }
00374 
00375 //_____________________________________________________________________________
00376 Float_t emcCalibratedDataObject::GetEnergy(Int_t index) const
00377 {
00378   Float_t energy = 0 ;
00379 
00380   if (ValidIndex(index)) energy = fEnergy[index] ;
00381 
00382   return energy ;
00383 }
00384 
00385 //_____________________________________________________________________________
00386 Float_t emcCalibratedDataObject::GetEnergyByTowerId(Int_t TowerId) const 
00387 {
00388   // Returns energy for a given tower or 0 if towerindex is not valid.
00389   Int_t index = GetIndexFromTowerId(TowerId) ;
00390 
00391   if (index>=0) {
00392     return fEnergy[index] ; 
00393   }
00394   else {
00395     return 0.; 
00396   }
00397 } 
00398 
00399 //_____________________________________________________________________________
00400 Int_t emcCalibratedDataObject::GetIndexFromTowerId(Int_t TowerId) const
00401 {
00402   // Returns the index (of fADC, fTDC, etc.. arrays) from towerindex.
00403   map<int,int>::const_iterator p = fIndexMap.find(TowerId) ;
00404   if (p!=fIndexMap.end()) {
00405     return p->second ;
00406   }
00407   else {
00408     return -1;
00409   }
00410 }
00411 
00412 //_____________________________________________________________________________
00413 void emcCalibratedDataObject::GetPointers(float*& ENERGY, float*& TOF) 
00414 {
00415   // WARNING. USE THIS METHOD IS STRONGLY DISCOURAGED. USE AT YOUR OWN RISK !
00416   ENERGY = fEnergy ;
00417   TOF = fTime ;
00418 }
00419 
00420 
00421 //_____________________________________________________________________________
00422 void emcCalibratedDataObject::GetSectorEnergies(Float_t * e)
00423 {
00424   // Loop over towers
00425   int i ;
00426   for (i=0;i<8;i++) e[i]=0;
00427   for (int index = 0; index < GetSize(); index++ ) {
00428     int is = 4*(fSoftwareKey[index]/100000) +  
00429       (fSoftwareKey[index]%100000)/10000 ;
00430     e[is] += fEnergy[index];
00431   }
00432 }
00433 
00434 //_____________________________________________________________________________
00435 void emcCalibratedDataObject::GetSMEnergies(Float_t* e)
00436 {
00437   int i ;
00438   for (i=0;i<GetMaxSize()/144;i++) e[i]=0;
00439   int towerid ;
00440   int sector ;
00441   int sm144,sm144sector ;
00442   int st ;
00443   int sm144t ;
00444 
00445   for ( i = 0 ; i < GetSize() ; i++) {
00446     
00447     towerid = fTowerId[i] ;
00448 
00450     EmcIndexer::iPXiSiST(towerid,sector,st) ;
00451 
00453     EmcIndexer::iSiSTiSMiSMT(sector,st,sm144sector,sm144t) ;
00454 
00456     sm144 = EmcIndexer::iSiSM144_PXSM144(sector , sm144sector);
00457 
00458     e[sm144] += fEnergy[i] ;
00459   }
00460 }
00461 
00462 //_____________________________________________________________________________
00463 long emcCalibratedDataObject::GetSoftwareKey(Int_t index) const
00464 {
00465   long softkey = 0 ;
00466 
00467   if (ValidIndex(index)) softkey = fSoftwareKey[index] ;
00468 
00469   return softkey ;
00470 }
00471 
00472 //_____________________________________________________________________________
00473 Float_t emcCalibratedDataObject::GetTime(Int_t index) const
00474 {
00475   Float_t t = 0 ;
00476   
00477   if (ValidIndex(index)) t = fTime[index] ;
00478 
00479   return t ;
00480 }
00481 
00482 //_____________________________________________________________________________
00483 Float_t emcCalibratedDataObject::GetTimeByTowerId(Int_t TowerId) const 
00484 {
00485   // Get tof value or -1 if towerindex is not valid.
00486   Int_t index = GetIndexFromTowerId(TowerId) ;
00487  
00488   if (index>=0) {
00489     return fTime[index] ; 
00490   }
00491   else {
00492     return 0.; 
00493   }
00494 } 
00495 
00496 //_____________________________________________________________________________
00497 Int_t emcCalibratedDataObject::GetTowerId(Int_t index) const
00498 {
00499   Int_t towerId = 0 ;
00500 
00501   if (ValidIndex(index)) towerId = fTowerId[index] ;
00502 
00503   return towerId ;
00504 }
00505 
00506 //_____________________________________________________________________________
00507 void emcCalibratedDataObject::identify(ostream& out) const
00508 {
00509   out << "I am an emcCalibratedDataObject" << endl ;
00510 }
00511 
00512 //_____________________________________________________________________________
00513 Bool_t emcCalibratedDataObject::IsCalibrated(TString what) const 
00514 {
00515   if ( what == "energy" )
00516     return fEnergyCalibrated ;
00517   else if ( what == "time" )
00518     return fTimeCalibrated ;
00519   else {
00520     cout << "emcRawDataCalibrator::IsCalibrated > " << what << " is a wrong option" << endl ;
00521     return kFALSE ;
00522   }  
00523 }
00524 
00525 //_____________________________________________________________________________
00526 void emcCalibratedDataObject::Set(int index, int TowerId, long softwareKey, 
00527                                   int /*dummy*/, float energy, float time,
00528                                   Int_t deadNeighbours, Int_t warnNeighbours)
00529 {
00530   // MV 2001/12/08 added warnNeighbours
00531 
00532   if (fReadOnly) {
00533     cerr << "<W> emcCalibratedDataObject::Set(all stuff) : Object is read-only" << endl ;
00534   }
00535   else {
00536 
00537     if (index>=fMaxSize) {
00538       assert(fSize==fMaxSize) ;
00539       if (!fMaxSize) {
00540         // Very first allocation
00541         fMaxSize = 1000 ;
00542         fEnergy = new Float_t[fMaxSize] ;
00543         fTime = new Float_t[fMaxSize] ;
00544         fTowerId = new Int_t[fMaxSize] ;
00545         fSoftwareKey = new long[fMaxSize] ;
00546         fDeadNeighbours = new Int_t[fMaxSize] ;
00547 
00548         // MV 2001/12/08
00549         fWarnNeighbours=new Int_t[fMaxSize];
00550 
00551         int i ;
00552         for (i=0;i<fMaxSize;i++) {
00553           fEnergy[i]=fTime[i]=0;
00554           fTowerId[i]=fDeadNeighbours[i]=0;
00555           fSoftwareKey[i]=0;
00556         }
00557       }
00558       else {
00559         int verymaxsize = 25000 ;
00560         int oldsize = fMaxSize ; 
00561         // Double allocation, up to verymaxsize.
00562         fMaxSize = TMath::Min(verymaxsize,fMaxSize*2) ;
00563         
00564         Float_t* newEnergy = new Float_t[fMaxSize] ;
00565         Float_t* newTime = new Float_t[fMaxSize] ;
00566         Int_t* newTowerId = new Int_t[fMaxSize] ;
00567         long* newSoftwareKey = new long[fMaxSize] ;
00568         Int_t* newDeadNeighbours = new Int_t[fMaxSize] ;
00569 
00570         // MV 2001/12/08
00571         Int_t* newWarnNeighbours=new Int_t[fMaxSize];
00572         
00573         int i ;
00574         for (i=0;i<oldsize;i++) {
00575           newEnergy[i] = fEnergy[i] ;
00576           newTime[i] = fTime[i] ;
00577           newTowerId[i] = fTowerId[i] ;
00578           newSoftwareKey[i] = fSoftwareKey[i] ;
00579           newDeadNeighbours[i] = fDeadNeighbours[i] ;
00580 
00581           // MV 2001/12/08
00582           newWarnNeighbours[i]=fWarnNeighbours[i];
00583 
00584         }
00585         
00586         delete[] fEnergy ;
00587         delete[] fTime ;
00588         delete[] fTowerId ;
00589         delete[] fSoftwareKey ;
00590         delete[] fDeadNeighbours ;
00591 
00592         // MV 2001/12/08
00593         delete [] fWarnNeighbours;
00594         
00595         fEnergy = newEnergy ;
00596         fTime = newTime ;
00597         fTowerId = newTowerId ;
00598         fSoftwareKey = newSoftwareKey ;
00599         fDeadNeighbours = newDeadNeighbours ;
00600 
00601         // MV 2001/12/08
00602         fWarnNeighbours=newWarnNeighbours;
00603 
00604       }
00605     }
00606 
00607     fSize = TMath::Max(fSize,index+1) ;
00608 
00609     fIndexMap[TowerId] = index ;
00610     fTowerId[index] = TowerId ;
00611     fSoftwareKey[index] = softwareKey ;
00612     fEnergy[index] = energy ;
00613     fTime[index] = time ;
00614     fDeadNeighbours[index] = deadNeighbours ;
00615 
00616     // MV 2001/12/08
00617     fWarnNeighbours[index]=warnNeighbours;
00618 
00619   }
00620 }
00621 
00622 //_____________________________________________________________________________
00623 void emcCalibratedDataObject::SetMaxSize(Int_t thesize)
00624 {
00625   Reset();
00626   if (!fMaxSize) {
00627     // Very first allocation only
00628     fMaxSize = thesize ;
00629     fEnergy = new Float_t[fMaxSize] ;
00630     fTime = new Float_t[fMaxSize] ;
00631     fTowerId = new Int_t[fMaxSize] ;
00632     fSoftwareKey = new long[fMaxSize] ;
00633     fDeadNeighbours = new Int_t[fMaxSize] ;
00634     fWarnNeighbours = new Int_t[fMaxSize];
00635 
00636     int i ;
00637     for (i=0;i<fMaxSize;i++) {
00638       fEnergy[i]=fTime[i]=0;
00639       fTowerId[i]=fDeadNeighbours[i]=0;
00640       fSoftwareKey[i]=0;
00641     }
00642   }
00643 }
00644 
00645 
00646 //_____________________________________________________________________________
00647 void emcCalibratedDataObject::Reset(void)
00648 {
00649   fSize=0;
00650   fIndexMap.clear() ;
00651   fEnergyCalibrated=fTimeCalibrated=false ;
00652 }
00653 
00654 //*************************************************************************
00655 
00656 void emcCalibratedDataObject::resetByIndex(int index)
00657 {
00658   if (index<fSize) {
00659       fEnergy[index]        = 0.;
00660       fTime[index]          = 0.;  
00661   }
00662 }
00663 
00664 //*************************************************************************
00665 
00666 void emcCalibratedDataObject::resetByTowerId(int TowerId)
00667 {
00668   Int_t index = GetIndexFromTowerId(TowerId) ;
00669   if(index>=0){
00670     fEnergy[index]        = 0.;
00671     fTime[index]          = 0.; 
00672   } 
00673 }
00674 
00675 //_____________________________________________________________________________
00676 TString emcCalibratedDataObject::Status() 
00677 {
00678   TString status ; 
00679   TString blank = "     " ; 
00680   status = "emcCalibratedDataObject status : \n" ;
00681   status += blank ; 
00682 
00683   if ( IsCalibrated("energy") )
00684     status += "Energy calibration have been applied\n" ; 
00685   else
00686     status += "Energy calibration have NOT been applied\n" ; 
00687 
00688   status += blank ; 
00689 
00690   if ( IsCalibrated("time") ) 
00691     status += "Time calibration have been applied\n" ; 
00692   else
00693     status += "Time calibration have NOT been applied\n" ; 
00694 
00695   status += blank ; 
00696   if ( IsZeroSuppressed()  ) 
00697     status += "Zero suppression has been applied\n" ; 
00698   else
00699     status += "Zero suppression has not been applied\n" ; 
00700 
00701   return status ; 
00702 }
00703 
00704 //_____________________________________________________________________________
00705 void emcCalibratedDataObject::Streamer(TBuffer &R__b)
00706 {
00707   // Stream an object of class emcCalibratedDataObject.
00708   
00709   // MV 2001/12/12 Incremented class version 2 -> 3
00710   
00711   if (R__b.IsReading()) {
00712     
00713     Version_t R__v = R__b.ReadVersion();
00714     
00715     if (R__v==1) { cerr << "CDO Streamer : Cannot read anylonger this version of CDO!" << endl;}
00716     
00717     TObject::Streamer(R__b) ;
00718     
00719     R__b >> fSize ;
00720     
00721     if ( fSize > fMaxSize) {
00722 
00723       // Change allocation
00724       delete[] fEnergy ;
00725       delete[] fTime ;
00726       delete[] fTowerId ;
00727       delete[] fSoftwareKey;
00728       delete[] fDeadNeighbours ;
00729       
00730       // MV 2001/12/08
00731       delete [] fWarnNeighbours;
00732       
00733       fMaxSize = fSize ;
00734       
00735       fEnergy = new Float_t[fMaxSize] ;
00736       fTime = new Float_t[fMaxSize] ;
00737       fTowerId = new Int_t  [fMaxSize] ;
00738       fSoftwareKey = new long [fMaxSize] ;
00739       fDeadNeighbours   = new Int_t  [fMaxSize] ;
00740       
00741       // MV 2001/12/08
00742       fWarnNeighbours=new Int_t[fMaxSize];
00743       
00744     }
00745     
00746     R__b >> fEnergyCalibrated;
00747     R__b >> fTimeCalibrated;
00748     R__b >> fZeroSuppressed;
00749     
00750     R__b.ReadFastArray(fEnergy, fSize);
00751     R__b.ReadFastArray(fTime, fSize);
00752     R__b.ReadFastArray(fTowerId, fSize);
00753     R__b.ReadFastArray(fDeadNeighbours, fSize);
00754     
00755     // MV 2001/12/08
00756     if(R__v>2){
00757 
00758       R__b.ReadFastArray(fWarnNeighbours, fSize);
00759 
00760     } else{
00761 
00762       memset((void*)fWarnNeighbours, 0, fSize*sizeof(Int_t));
00763 
00764     }
00765     
00766     // we rebuild the IndexMap (which is only used for speeding up 
00767     // accessing in the Get... methods) and the fSoftwareKey array.
00768     int i ;
00769     fIndexMap.clear() ;
00770     for ( i = 0 ; i < fSize ; i++ ) {
00771       fIndexMap[ fTowerId[i] ] = i ; 
00772       fSoftwareKey[i] = GenerateSoftwareKey( fTowerId[i] ) ;
00773     }
00774     
00775     for ( i = fSize ; i < fMaxSize ; i++ ) {
00776       fEnergy[i] = fTime[i] = 0 ;
00777       fTowerId[i] = 0 ;
00778       fSoftwareKey[i] = 0 ;
00779       fDeadNeighbours[i] = 0 ;
00780       
00781       // MV 2001/12/08
00782       fWarnNeighbours[i]=0;
00783       
00784     }
00785     
00786     ComputeTotalEnergy() ;
00787     
00788     fReadOnly = true ;
00789     
00790   } else {
00791     
00792     R__b.WriteVersion(emcCalibratedDataObject::IsA());
00793     TObject::Streamer(R__b);
00794     
00795     R__b << fSize ;
00796     
00797     R__b << fEnergyCalibrated ; 
00798     R__b << fTimeCalibrated ; 
00799     R__b << fZeroSuppressed ; 
00800     
00801     // we write only non-zero towers
00802     R__b.WriteFastArray(fEnergy, fSize) ;
00803     R__b.WriteFastArray(fTime, fSize) ;
00804     R__b.WriteFastArray(fTowerId, fSize);
00805     R__b.WriteFastArray(fDeadNeighbours, fSize);
00806     
00807     // MV 2001/12/08
00808     R__b.WriteFastArray(fWarnNeighbours, fSize);
00809     
00810   }
00811 }
00812 
00813 //_____________________________________________________________________________
00814 void emcCalibratedDataObject::Update(void)
00815 {
00816   Int_t i;
00817 
00818   fIndexMap.clear() ;
00819   for ( i = 0 ; i < fSize ; i++ ) {
00820     fIndexMap[ fTowerId[i] ] = i ;
00821     fSoftwareKey[i] = GenerateSoftwareKey( fTowerId[i] ) ;
00822   }
00823   ComputeTotalEnergy() ;
00824 }
00825 
00826 //_____________________________________________________________________________
00827 ostream& operator << (ostream& out, const emcCalibratedDataObject& cdo) 
00828 {
00829   if (cdo.fTowerId) {
00830     int i ;
00831 
00832     // MV 2001/12/08 added warnings for neighbors
00833     char* head = " Tower :      arm    sector yrow   zrow   GeV     ns   DeadNeighbours   WarnNeighbours";
00834     out << head << endl ;
00835     out << dec ;
00836     Int_t arm, sector, yrow, zrow ; 
00837     TString ans ; 
00838     for (i = 0; i < cdo.GetSize(); i++) {
00839    
00840       if ( (i+1) % 1000 == 0 ) {
00841         cout << "S(top) or C(ontinue) ?  " ;
00842         cin >> ans ; 
00843         cout << endl ; 
00844         if ( ans == "s" || ans == "S" ) 
00845           break ; 
00846         out << head << endl ;
00847       }
00848 
00849       cdo.DecodeKey(  cdo.GetSoftwareKey(i), arm,sector, yrow, zrow) ; 
00850       out << "#" << cdo.GetTowerId(i)  << " : "
00851           << arm 
00852           << sector 
00853           << yrow 
00854           << setprecision(2)
00855           << zrow
00856           << " " 
00857           << setprecision(8) << cdo.fEnergy[i] 
00858           << " "
00859           << setprecision(8) << cdo.fTime[i]
00860           << ") " 
00861           << " D" << cdo.GetDead(i)
00862  
00863         // MV 2001/12/08
00864           << " W" << cdo.GetWarn(i)
00865           << endl ;
00866     }
00867   }
00868   return out ;
00869 }