Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

CalDisplay.cxx

Go to the documentation of this file.
00001 
00002 #include "bfemDisplay/CalDisplay.h"
00003 #include "bfemDisplay/Enum.h"
00004 
00005 #include "reconRootData/ReconHeader.h"
00006 
00007 
00008 ClassImp(CalDisplay)
00009 
00010 CalDisplay::CalDisplay( TNode *parent, TObjArray *peds ) {
00011 
00012   m_peds = peds;
00013 
00014   m_Gammas = 0;
00015 
00016   // !Note: All measurements in cm.  Numbers are half what they are in reality.  
00017   // !This is to accomadate the fact that TBrik accept half lengths as input variables
00018   // !Coordinate system centere in the center of the tower frame.
00019 
00020   m_CalTkrdistance  = 8.61;
00021   m_CalHeightOffset = -21.68;
00022   m_CalWidth        = 15.525 ; 
00023   m_CalHeight       = 13.07;
00024   m_LogWidth        = 1.513;
00025   m_LogHeight       = 1.307;
00026   m_LogLength       = 15.13;
00027   m_NumCalLayers    = 8;
00028   m_CalHitLength    = 1.5;
00029 
00030 
00032 
00033   m_CalNodeList = 0;
00034   m_CalHitList = 0;
00035 
00036 
00037   // !Create representation for the CAL.
00038 
00039   parent->cd();
00040 
00041   TBRIK* calFrame = new TBRIK( "calFrame", "calFrame", "void", m_CalWidth, m_CalWidth, m_CalHeight );
00042 
00043   calFrame->SetLineColor( 1 );
00044 
00045   m_calFrameNode  = new TNode( "calFrameNode", "calFrameNode", "calFrame", 0.0, 0.0, m_CalHeightOffset );
00046 
00047   m_calFrameNode->cd();
00048 
00049   // Top-level node for hits on logs parallel to Y-axis ( measured coordinate is X ).
00050   m_AllHitsX = new TNode( "AllHitsX", "AllHitsX", "calFrame" );
00051   m_AllHitsX->SetParent( m_calFrameNode );
00052 
00053   // Top-level node for hits on logs parallel to X-axis ( measured coordinate is Y ).
00054   m_calFrameNode->cd();
00055   m_AllHitsY = new TNode( "AllHitsY", "AllHitsY", "calFrame" );
00056   m_AllHitsY->SetParent( m_calFrameNode );
00057 
00058 
00059 }
00060 
00061 void CalDisplay::DrawEvents( DigiEvent *event, Recon *recon, Bool_t isRealData  ) {
00062 
00064 
00065   TNNode *newnode;
00066   THits *calLog;
00067 
00068   m_event = event;
00069   m_recon = recon;
00070 
00071 
00072   // !Draw displays the current event
00073 
00074   // !Delete the old hit node and hit arrays.
00075 
00076   if ( m_CalNodeList ) m_CalNodeList->Delete();
00077   m_CalNodeList = new TObjArray();
00078 
00079   if ( m_CalHitList ) m_CalHitList->Delete();
00080   m_CalHitList = new TObjArray();
00081 
00082  
00083   Char_t* hit_name=0; // name of elements in CalHitList
00084 
00085   Char_t* cal_name=0; // name of elements in CalShapeList 
00086 
00087 
00088   Char_t* view;
00089 
00090   Int_t nhit = 0;
00091 
00092   Int_t nCAL = m_event->getCalDigi()->GetEntries();
00093 
00094   for (Int_t ihit=0; ihit < nCAL; ihit++) {
00095 
00096     CalLog *hit = (CalLog*)m_event->getCalDigi()->At(ihit);
00097 
00098     LogId *log = (LogId*)hit->getLogId();
00099 
00100     //    Int_t id = log->getId(); // Log's ID. now from 0 to 39 (before 0 - 79)
00101 
00102     Float_t eTotal, e0, e1;
00103 
00104     Int_t layer = log->getLayer();
00105 
00106     Int_t column = log->getColumn();
00107 
00108     Int_t xyDir = log->getXY(); 
00109 
00110     Int_t iped = layer*10+column;
00111 
00112     cal_name = getCalName(iped);
00113 
00114     hit_name = cal_name;
00115 
00116 
00117     //printf(" id %i -- iped %i layer %i column %i XY %i\n",id,iped,layer,column,xyDir);
00118 
00119 
00120     e0 = getLogEnergy( hit, iped, 0, isRealData );
00121 
00122     e1 = getLogEnergy( hit, iped, 1, isRealData );
00123 
00124 
00125     if (e1<0 || e0<0) continue;
00126 
00127     eTotal = (e0 + e1)/2.0;
00128 
00129     // Cut on Total Energy: Display if Et>1.3 MeV (~0.1 MIP)
00130 
00131     if (eTotal > m_cal_lev1) {
00132 
00133 
00134 
00135       // !Figure out position of Log      
00136 
00137 
00138       Float_t position = -(e1 - e0)/(e1 + e0) * m_LogLength;
00139 
00140       Float_t off = (m_CalTkrdistance + m_LogHeight) + m_CalHeightOffset;
00141 
00142       Float_t z = -off - 2*(Float_t)layer*m_LogHeight;
00143 
00144       //Float_t m_Log = m_LogWidth*eTotal*100.;
00145       
00146       //if (eTotal > 0.01) m_Log = m_LogWidth; //from 100 MeV on the size of the square rapresenting 
00147                                              //the energy in the log is fixed and equal to the log width
00148       //
00149 
00150       Float_t x, y;
00151 
00152       if (xyDir == 0){ // Coord. system according to doc: BalloonTestV12_20010415.ps pag.9
00153 
00154         view = "Y"; // xyDir = 0 measures Y
00155 
00156         y = -m_CalWidth + (1.0 + 2.0*(Float_t)column)*m_LogWidth;
00157 
00158         x = position;
00159 
00160         calLog = new THits(cal_name,cal_name,"CsI",m_CalHitLength,m_LogWidth,m_LogHeight);
00161 
00162         SetLogColor( calLog, eTotal );
00163 
00164         m_AllHitsY->cd();
00165 
00166         newnode = new TNNode(cal_name,cal_name,cal_name,x,y,z);
00167 
00168         newnode->setObject( calLog );
00169         newnode->SetParent( m_AllHitsY );
00170         m_CalNodeList->Add( newnode );
00171 
00172       }
00173 
00174       else {
00175 
00176         view = "X"; // xyDir = 1 measures X
00177 
00178         x = -m_CalWidth + (1.0 + 2.0*(Float_t)column)*m_LogWidth;
00179 
00180         y = position;
00181 
00182         calLog = new THits(cal_name,cal_name,"CsI",m_LogWidth,m_CalHitLength,m_LogHeight);
00183 
00184         SetLogColor( calLog, eTotal );
00185 
00186         m_AllHitsX->cd();
00187 
00188         newnode = new TNNode(cal_name,cal_name,cal_name,x,y,z);
00189 
00190         newnode->setObject( calLog );
00191         newnode->SetParent( m_AllHitsX );
00192         m_CalNodeList->Add( newnode );
00193 
00194       }
00195 
00196 
00197       // !Build-up list of CAL Hits
00198 
00199       calLog->SetX(x);
00200 
00201       calLog->SetY(y);
00202 
00203       calLog->SetZ(z+m_CalHeightOffset);
00204 
00205       calLog->SetEn(eTotal*1000);
00206 
00207       calLog->SetLayer(layer);
00208 
00209       calLog->SetView(view);
00210 
00211       calLog->SetElement(column);
00212 
00213       m_CalHitList->Add( calLog );
00214 
00215 
00216 
00217       // printf("log %i calname %s, layer %i column %i energy %f\n",id,cal_name,layer,column,eTotal);
00218 
00219 
00220       nhit++;
00221 
00222     }
00223 
00224   }
00225   
00226   if ( m_recon ) drawCalRecon();
00227 
00228 }
00229 
00230 void CalDisplay::SetLogColor( THits *calLog, Float_t eTotal ) {
00231       
00232 
00233   // Define colour of logs based on the deposited energy
00234 
00235   if ( eTotal > ( Float_t )m_cal_lev4 )  calLog->SetLineColor(5);
00236 
00237   if ( eTotal > ( Float_t )m_cal_lev3 && eTotal < ( Float_t )m_cal_lev4 ) calLog->SetLineColor(2);
00238 
00239   if ( eTotal > ( Float_t )m_cal_lev2 && eTotal < ( Float_t )m_cal_lev3 ) calLog->SetLineColor(4); 
00240 
00241   if ( eTotal > ( Float_t )m_cal_lev1 && eTotal < ( Float_t )m_cal_lev2 ) calLog->SetLineColor(3); 
00242 
00243  
00244 }
00245 
00246 
00247 void CalDisplay::setVisibility( Int_t vis ) {
00248 
00249   // Set visibility of tracker planes and hits.
00250   // Note: -2 = "node not drawn, sons not drawn", 2 = "node not drawn, sons drawn".
00251 
00252   switch( vis ) {
00253 
00254   case( kHideX ):
00255     m_AllHitsX->SetVisibility( -2 );
00256     m_AllHitsY->SetVisibility( 2 );
00257     break;
00258 
00259   case( kHideY ):
00260     m_AllHitsX->SetVisibility( 2 );
00261     m_AllHitsY->SetVisibility( -2 );
00262     break;
00263 
00264   case( kHideAll ):
00265     m_AllHitsX->SetVisibility( -2 );
00266     m_AllHitsY->SetVisibility( -2 );
00267     break;
00268 
00269   case( kHideNone ):
00270     m_AllHitsX->SetVisibility( 2 );
00271     m_AllHitsY->SetVisibility( 2 );
00272     break;
00273 
00274   }
00275 
00276 }
00277 
00278 
00279 void CalDisplay::setThresholds( Float_t thresh[ 4 ] ) {
00280 
00281   m_cal_lev1 = thresh[ 0 ];
00282   m_cal_lev2 = thresh[ 1 ];
00283   m_cal_lev3 = thresh[ 2 ];
00284   m_cal_lev4 = thresh[ 3 ];
00285 
00286 }
00287 
00288 
00290 
00291 Float_t CalDisplay::getLogEnergy( CalLog* hit, Int_t id, Int_t end, Bool_t isRealData ){
00292 
00293     Float_t eMax = -1000.; Int_t bestRange = -1; Int_t index;
00294 
00295     //Float_t gain[4] = {0.000065, 0.00022, 0.0037, 0.022};     //Berrie's gain (in Gev)
00296     Float_t gain[4] = {0.075, 0.3, 4.3, 25};       //Eric's gain Sept. 11 2001  - in MeV
00297 
00298     Int_t hitADC;                                        
00299 
00300     for (Int_t adc = 0; adc <= 1; adc++) {
00301 
00302        if (!end) hitADC = 4095 - hit->getAdc(hit->POS,adc);
00303        else hitADC = 4095 - hit->getAdc(hit->NEG,adc);
00304 
00305         if (hitADC > 3900) continue;
00306 
00307         if (hitADC > eMax) {
00308 
00309             eMax = hitADC;
00310 
00311             bestRange = adc;
00312 
00313         }       
00314 
00315     }
00316 
00317     if(!end) index = 2 * bestRange;
00318 
00319     else index = 2 * bestRange + 1;
00320 
00321     // Correct for unexpected ordering in ROOT ped file (Berrie's peds.)
00322     //if ( !end && bestRange==1 ) index = 1;
00323     //if ( end && !bestRange ) index = 2;
00324 
00325     TVector *vv;
00326 
00327     Float_t eHit;
00328 
00329     if ( bestRange > -1 ) { 
00330       
00331       if( isRealData ) { // raw real data !!!! 
00332         
00333         if ( eMax && m_peds ) {
00334           
00335           vv = (TVector *)m_peds->At(index);
00336           
00337           eHit = eMax-vv->operator()(id);
00338           
00339         }
00340         
00341         else eHit = 0;
00342       }
00343       
00344       else eHit = eMax; // MC data !!!
00345       
00346       //      return eHit*gain[ bestRange ];
00347 
00348       return eHit*gain[ bestRange ]/ 13.; //( Energy in MIP!!!)
00349 
00350     }
00351     
00352     return 0.0;
00353     
00354 }
00355 
00356 
00357 
00359 
00360 Char_t *CalDisplay::getCalName(Int_t ihit){
00361 
00362   Char_t cs[40];
00363 
00364    TString *CalName = new TString("CAL_log");
00365 
00366    sprintf(cs,"%d",ihit);
00367 
00368    CalName->Append(cs);   
00369 
00370    return (Char_t*)CalName->Data();
00371 
00372 }
00373 
00374 
00375 
00376 void CalDisplay::drawCalRecon() {
00377 
00378   Double_t x, y, z, anglex, angley,anglez;
00379 
00380   //  ReconHeader* recHeader;
00381 
00382   //  m_recon->Dump();
00383 
00384   //  recHeader = m_recon->getReconFlags(); //check way when switch back from analysis to display 
00385   //  if uncommented this line gives bad pointer to class recHeader.
00386 
00387   // Indeed this is a problem!  recHeader part re-commented by Nick, 28-09-2001 for compiled version.
00388 
00389 //    if  ( recHeader->HasCalNoEnergyRecon()) {
00390 //      cout << " ===> No energy reconstruction in CAL !! " << endl;
00391 //      return;
00392 //    }
00393  
00394 //    m_Gammas = 0;
00395 
00396 //    if ( recHeader->HasGamma() ) {
00397 //      cout << "\n*********** GAMMA!!! ************\n";
00398 //      m_Gammas = 1;
00399 //    }
00400   
00401   CalRecon* calRecon = m_recon->getCalRecon();
00402 
00403 
00404   TObjArray *m_CalClusterList = calRecon->getCalClusters();
00405   
00406   Int_t numClus = m_CalClusterList->GetEntries();
00407   
00408  
00409   
00410  // Create a new list of reconstructed hits.
00411 
00412   //if ( m_CalReconHitList != 0 ) delete m_CalReconHitList;
00413   
00414   //m_CalReconHitList = new TObjArray();
00415 
00416   cout << " Num. of clusters in CAL: " << numClus << endl; 
00417 
00418   for ( Int_t iclus=0; iclus<numClus; ++iclus ) {
00419    
00420    // Loop over all clusters for this event.
00421 
00422    CalCluster *cluster = (CalCluster*) m_CalClusterList->At(iclus);
00423 
00424    m_eTot = (cluster->getEsum())*pow(10,-9);
00425 
00426    m_eCorr = (cluster->getEcorr())*pow(10,-9);
00427 
00428    m_eLeak = (cluster->getEleak())*pow(10,-9);
00429   
00430    cout << "Etot:" << m_eLeak << endl;
00431    
00432    const TArrayF* m_eneLayer = &cluster->getEneLayer();
00433 
00434    Int_t nHitsE = m_eneLayer->GetSize();
00435    
00436    const TArrayF* m_xposLayer = &cluster->getXLayer();
00437 
00438    //Int_t nhitsX = m_xposLayer->GetSize();
00439    
00440    const TArrayF* m_yposLayer = &cluster->getYLayer();
00441 
00442    //Int_t nhitsY = m_yposLayer->GetSize();
00443 
00444 
00445    for ( Int_t ihit=0; ihit<nHitsE; ++ihit ) {
00446    
00447      Float_t xpos = m_xposLayer->At(ihit);
00448      Float_t ypos = m_yposLayer->At(ihit);
00449      Float_t energy = m_eneLayer->At(ihit);
00450      printf( " lay: %d -- X: %f   Y: %f  Energy: %f \n",ihit,xpos,ypos,energy);
00451 
00452    }
00453    TVector3* position = cluster->getPosition();
00454 
00455       x = position->X();
00456 
00457       y = position->Y();
00458 
00459       z = position->Z();
00460 
00461    TVector3* direction = cluster->getDirection();
00462    
00463 
00464       anglex = direction->X();
00465 
00466       angley = direction->Y();
00467 
00468       anglez = direction->Z();
00469       
00470       cout << " X:" << x << " anglex: " << anglex << "  Y:" << y << " angley:" 
00471            << angley << " Z:" << z << " anglez; " << anglez << endl; 
00472   }
00473 
00474 }
00475 
00476 
00477 
00478 

Generated at Wed Nov 14 20:41:42 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000