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

Generated at Mon Nov 26 18:20:06 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000