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

mMuiBLTEmulator.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // Utility class: mMuiBLTEmulator:
00004 // Author: chun zhang
00005 // Date: 12/03/03
00006 // Description: BLT emulator 
00007 //              
00009 
00010 // MUIOO/MUTOO headers
00011 //
00012 #include <mMuiBLTEmulator.h>
00013 #include <mMuiBLTEmulatorPar.h>
00014 #include <TMutNode.h>
00015 #include <PHException.h>
00016 #include <MUTOO.h>
00017 #include <PHTimer.h>
00018 #include <TMuiHitMapO.h>
00019 #include <TMuiMCHitMapO.h>
00020 #include <TMuiPseudoBLTMapO.h>
00021 
00022 // PHENIX db headers.
00023 //
00024 #include "RunToTimeObjy.hh"
00025 #include "PdbBankManager.hh"
00026 #include "PdbApplication.hh"
00027 #include "PdbObjyBankManager.hh"
00028 #include "PdbBankID.hh"
00029 #include "PdbMuiTriggerMLU.hh"
00030 #include "PdbCalBank.hh"
00031 // MUID Geometry header.
00032 //
00033 #include <mMuiInitModule.h>
00034 #include <PHCompositeNode.h>
00035 #include <TMuiReadoutID.hh>
00036 #include <TMuiAddressTable.hh>
00037 
00038 
00039 // PHENIX RECO headers
00040 //
00041 #include "recoConsts.h" 
00042 
00045 // STL/BOOST
00046 //
00047 #include <iostream>
00048 #include <string>
00049 #include <list>
00050 #include <boost/array.hpp>
00051 
00052 mMuiBLTEmulator::mMuiBLTEmulator() : _timer("mMuiBLTEmulator")
00053 {
00054   name = "mMuiBLTEmulator";
00055   MUTOO::TRACE("initializing module " + std::string(name.getString()));    
00056   init_done = 0;
00057   _non_used_plane = 4;
00058 }
00059 
00060 // Destructor
00061 
00062 mMuiBLTEmulator::~mMuiBLTEmulator() { }
00063 
00064 // Event method.
00065 
00066 PHBoolean mMuiBLTEmulator::event(PHCompositeNode* top_node)
00067 {
00068 
00069   _timer.restart(); 
00070   
00071   try { 
00072 
00073     // Reset IOC pointers
00074     //
00075     set_interface_ptrs(top_node);
00076     // do the initialization for first event.
00077     //
00078     // if(!init_done) initialize();
00079 
00080     // collects all the raw hits/hits information.
00081     //
00082     if(_mod_par->get_mode()==mMuiBLTEmulatorPar::FROMPRDF) get_raw_data();
00083     if(_mod_par->get_mode()==mMuiBLTEmulatorPar::FROMDST) get_hits();
00084     // transfer the hit to trigger primary format.
00085     //
00086     raw_to_trigpattern();
00087     // Fill trigger decisions into pseudo-trigger map.
00088     //
00089     fill_map();
00090     // check blt emualtor according to the hit information.
00091     //
00092     if(_mod_par->get_debug_flag()==1) check_blt();
00093   } catch(std::exception& e) {
00094     MUTOO::TRACE(e.what());
00095     return False;
00096   }  
00097 
00098   // Timer
00099   //
00100   _timer.print(); 
00101   return True;
00102 }
00103 
00104 void 
00105 mMuiBLTEmulator::get_raw_data() {
00106   // get raw data from event_node. then store it into 
00107   // arry word[arm][orientation][iword].
00108   // Tatally there are 120 words per orientation, and the low 16 bits
00109   // in each word represents 16 twopacks. 
00110   //
00111   Packet* p;  
00112   static const int id_base[max_arm] = {12001, 12003}; // for South and North
00113 
00114   for(int iarm = 0; iarm < MUIOO::NumberOfArms; iarm++) {
00115     for(int iorient = 0; iorient < MUIOO::MAX_ORIENTATION; iorient++) {
00116       int pack_id = id_base[iarm] + iorient;
00117       if((p=_event->getPacket(pack_id))!=0) {
00118         for(int iword = 0; iword < MUIOO::kWordsPerFEM; iword++) {
00119           word[iarm][iorient][iword] = p->iValue(iword);
00120         }
00121         delete p;
00122       }
00123     }
00124   }
00125 }
00126 
00127 void mMuiBLTEmulator::get_hits(){
00128   // Loop through mui hit map, fill word array 
00129   // muioo hit is organized by (arm, plane, panel, orientation, twopack),
00130   // but word array is organized by FEM address and every word uses its
00131   // low 16 bits to store 16 twopacks, we need to map muioo hit into 
00132   // low 16 bits of each word in word array. This transform is taken care by
00133   // TMuiChannelId and TMuiAddressTable::Table()->HardwareAddress(TMuiChannelId).
00134   // Here I just call them.
00135   //
00136 
00137   // clear word array for each event.
00138   //
00139   for(int iarm = 0; iarm < MUIOO::NumberOfArms; iarm++){
00140     for(int iorient = 0; iorient < MUIOO::MAX_ORIENTATION; iorient++) {
00141       for(int iword = 0; iword < MUIOO::kWordsPerFEM; iword++) {
00142         word[iarm][iorient][iword] = 0;
00143       }
00144     }
00145   }
00146 
00147   TMuiHitMapO::const_iterator hit_iter = _hit_map->range();
00148   while(TMuiHitMapO::const_pointer hit_ptr = hit_iter.next()){
00149     EOrient_t orientation = kVERT;
00150     if(hit_ptr->get()->get_orientation()==0) orientation = kHORIZ;
00151     
00152     TMuiChannelId muichannel(hit_ptr->get()->get_arm(),
00153                              hit_ptr->get()->get_plane(),
00154                              hit_ptr->get()->get_panel(),
00155                              orientation,
00156                              hit_ptr->get()->get_twopack());
00157     TMuiReadoutID hardware = TMuiAddressTable::Table()->HardwareAddress(muichannel);
00158     int iword = hardware.ROC()*MUIOO::kWordsPerROC+hardware.Word();
00159     int ibit  = hardware.Channel();
00160 
00161     word[hit_ptr->get()->get_arm()][hit_ptr->get()->get_orientation()][iword] |= (0x01<<ibit);  
00162   }
00163 }
00164 
00165 void mMuiBLTEmulator::raw_to_trigpattern() {
00166 
00167   // This whole piece is taken directly from Hiroki's code without any changes. Except for
00168   // using three/four dimension array to handle two arm at the same time. I was very careful about 
00169   // this little change.
00170   //
00171 
00172   // convert FEM word[iarm(0-1)][ifem(0-1)][word 0-119](0-0xffff) to trig_pattern[iarm(0-1)][quad(0-3)][plane(0-3)](0-15)
00173 
00174   const int max_sector = 8;
00175   int trig_bit[MUIOO::NumberOfArms][MUIOO::MAX_ORIENTATION][MUIOO::MAX_PLANE-1][max_sector];
00176   for(int iarm = 0; iarm < MUIOO::NumberOfArms; iarm++) {
00177     for ( int iorient = 0; iorient<MUIOO::MAX_ORIENTATION; iorient++ ) {
00178       for ( int iplane = 0; iplane<MUIOO::MAX_PLANE-1; iplane++ ){
00179         for ( int k = 0; k<max_sector; k++ ) {
00180           trig_bit[iarm][iorient][iplane][k] = 0;
00181         }
00182       }
00183     }
00184   }
00185 
00186   // use lower 16 bits of each word
00187   for(int iarm = 0; iarm < MUIOO::NumberOfArms; iarm++) {
00188     for( int iorient = 0; iorient<MUIOO::MAX_ORIENTATION; iorient++ ) {
00189       for ( int iword = 0; iword<MUIOO::kWordsPerFEM; iword++ ) {
00190         word[iarm][iorient][iword] = word[iarm][iorient][iword] & 0xffff;
00191       }
00192     }
00193   }
00194   // word -> trig_bit
00195 
00196   for(int iarm = 0; iarm < MUIOO::NumberOfArms; iarm++) {
00197     int plane_new = 0;
00198     for ( int plane = 0; plane<MUIOO::MAX_PLANE; plane++ ) {
00199       // There are 5 planes int word[][][], but only 4 planes in trig_bit[][][]
00200       if ( plane != get_non_used_plane()) { 
00201         for ( int sector = 0; sector<max_sector; sector++ ) {
00202           if ( sector % 2 == 0 ) {
00203             trig_bit[iarm][ 0 ][ plane_new ][ sector ] = 
00204             word[iarm][ 0 ][ plane*24 + sector*3  + 0 ]
00205             + word[iarm][ 0 ][ plane*24 + sector*3 + 1 ] 
00206             + word[iarm][ 0 ][ plane*24 + sector*3 + 2 ] 
00207             + word[iarm][ 0 ][ plane*24 + sector*3 + 3 ] ;
00208           }
00209           else {
00210             trig_bit[iarm][ 0 ][ plane_new ][ sector ] = 
00211               word[iarm][ 0 ][ plane*24 + (sector-1)*3 + 2 ]
00212               + word[iarm][ 0 ][ plane*24 + (sector-1)*3 + 3 ]
00213               + word[iarm][ 0 ][ plane*24 + (sector-1)*3 + 4 ]
00214               + word[iarm][ 0 ][ plane*24 + (sector-1)*3 + 5 ];
00215           }
00216           for ( int iword = 0; iword<3; iword++ ) {
00217             trig_bit[iarm][ 1 ][ plane_new ][ sector ]
00218               += word[iarm][ 1 ][ plane*24 + sector*3 + iword ]; 
00219           }
00220         }
00221         plane_new++;
00222       }
00223     }
00224   }
00225   // take "OR"
00226   for(int iarm = 0; iarm < MUIOO::NumberOfArms; iarm++) {
00227     for ( int iorient = 0; iorient < MUIOO::MAX_ORIENTATION; iorient++){ // orientation
00228       for ( int iplane = 0; iplane < MUIOO::MAX_PLANE-1; iplane++ ){ // plane
00229         for ( int k = 0; k<max_sector; k++ ) { //sector
00230           if ( trig_bit[iarm][iorient][iplane][k] != 0 ) { 
00231             trig_bit[iarm][iorient][iplane][k] = 1;
00232           }
00233         }
00234       }
00235     }
00236   }
00237   // trig_bit -> trig_pattern
00238   for(int iarm = 0; iarm < MUIOO::NumberOfArms; iarm++) {
00239     for ( int iquad = 0; iquad<max_quad; iquad++ ) {
00240       for ( int iplane = 0; iplane < MUIOO::MAX_PLANE-1; iplane++ ){ // plane
00241         trig_pattern[iarm][iquad][iplane] = 0;
00242       }
00243     }
00244   }
00245  
00246   // Chun :: horizental and vertial planes have different sector configuration.
00247   //         horizental :: sector    6 4 2 0   quadrant 3   1 
00248   //
00249   //
00250   //                                 7 5 3 1            4   2
00251   //
00252   //         vertical   :: sector    1     0   quadrant 3   1
00253   //                                 3     2
00254   //                                 5     4
00255   //                                 7     6            4   2
00256   //
00257   for(int iarm = 0; iarm < MUIOO::NumberOfArms; iarm++) {
00258     for( int plane = 0; plane<MUIOO::MAX_PLANE-1; plane++ ){
00259       trig_pattern[iarm][0][plane] 
00260         += trig_bit[iarm][0][plane][0] * (int)pow( 2.0, 1 )
00261         + trig_bit[iarm][0][plane][2] * (int)pow( 2.0, 0 ) 
00262         + trig_bit[iarm][1][plane][0] * (int)pow( 2.0, 3 )
00263         + trig_bit[iarm][1][plane][2] * (int)pow( 2.0, 2 );
00264       trig_pattern[iarm][1][plane] 
00265         += trig_bit[iarm][0][plane][1] * (int)pow( 2.0, 1 )
00266         + trig_bit[iarm][0][plane][3] * (int)pow( 2.0, 0 ) 
00267         + trig_bit[iarm][1][plane][4] * (int)pow( 2.0, 2 )
00268         + trig_bit[iarm][1][plane][6] * (int)pow( 2.0, 3 );
00269       trig_pattern[iarm][2][plane] 
00270         += trig_bit[iarm][0][plane][4] * (int)pow( 2.0, 0 )
00271         + trig_bit[iarm][0][plane][6] * (int)pow( 2.0, 1 ) 
00272         + trig_bit[iarm][1][plane][1] * (int)pow( 2.0, 3 )
00273         + trig_bit[iarm][1][plane][3] * (int)pow( 2.0, 2 );
00274       trig_pattern[iarm][3][plane] 
00275         += trig_bit[iarm][0][plane][5] * (int)pow( 2.0, 0 )
00276         + trig_bit[iarm][0][plane][7] * (int)pow( 2.0, 1 ) 
00277         + trig_bit[iarm][1][plane][5] * (int)pow( 2.0, 2 )
00278         + trig_bit[iarm][1][plane][7] * (int)pow( 2.0, 3 );
00279     }
00280   }
00281 }
00282 
00283 int 
00284 mMuiBLTEmulator::decision_event(int arm) {
00285   
00286   // Copy of Hiroki's code, modification I made is
00287   // having arm as an input to handle both arm 
00288   
00289   int trig_pattern_arm[max_quad][MUIOO::MAX_PLANE-1];
00290   
00291   for(int iquad = 0; iquad < max_quad; iquad++) {
00292     for(int iplane = 0; iplane < MUIOO::MAX_PLANE-1; iplane++) {
00293       trig_pattern_arm[iquad][iplane] = trig_pattern[arm][iquad][iplane];
00294     }
00295   }
00296 
00297   for( int quad = 0; quad<max_quad; quad++ ){
00298     trig_accept[arm][quad] = 0;
00299   }
00300   
00301   for ( int quad = 0; quad<max_quad; quad++ ) {
00302     if ( quad_fire( trig_pattern_arm[quad], mlu_data_d ) == 1 ) {
00303       trig_accept[arm][quad] = DEEP_ROAD;
00304     }
00305     else if ( quad_fire( trig_pattern_arm[quad], mlu_data_s ) == 1 ) {
00306       trig_accept[arm][quad] = SHALLOW_ROAD;
00307     }
00308   } 
00309   return decision_mlu(arm);
00310 }
00311 
00312 int mMuiBLTEmulator::quad_fire(int quad_trig_pattern[max_plane], int mlu_data[ mlu_address_max ]  )
00313 {
00314   // copy from Hiroki's code, take out 'cout'
00315   //
00316   int fired = 0;
00317   int address = 0;
00318   int data_bit = 0;
00319   for ( int plane = 0; plane<max_plane - 1; plane++ ) {
00320     for ( int bit = 0; bit<4; bit++ ) {
00321       if ( ( ( quad_trig_pattern[plane] & (1<<bit) ) >> bit ) == 1 ) { 
00322         address += (int)pow( 2.0, bit + plane * 4 );  
00323       }
00324     }
00325   }
00326   data_bit = quad_trig_pattern[3];
00327   
00328   //  int scan_data;
00329   if ( ( ( mlu_data[address] & (1<<data_bit) ) >> data_bit ) == 1 ) {
00330     fired++;
00331   }
00332   if ( fired > 0 ) {
00333     return 1;
00334   }
00335   else{
00336     return 0;
00337   }
00338 }
00339 
00340 
00341 int mMuiBLTEmulator::decision_mlu( int arm) {
00342 
00343   // copy from hiroki's code, just take out 'cout'
00344   //
00345 
00346   short shallow = 0;
00347   short deep = 0;
00348 
00349   int exclusive_switch = 0;
00350   // if this is 1, all five bits are excusive.
00351 
00352   for( int quad = 0; quad<max_quad; quad++ ) {
00353     if ( trig_accept[arm][quad] > 0 ) {
00354       if ( trig_accept[arm][quad] == DEEP_ROAD ) {
00355         deep++;
00356       } else if ( trig_accept[arm][quad] == SHALLOW_ROAD ) {
00357         shallow++;
00358       }
00359     }
00360   }
00361      
00362   if ( deep >= 2 ) {
00363     if( exclusive_switch == 1 ) {
00364       return DEEP_DEEP;
00365     }
00366     else {
00367       return DEEP_DEEP + DEEP_SHALLOW + SHALLOW_SHALLOW +
00368         SINGLE_DEEP + SINGLE_SHALLOW;
00369     }
00370   } else if ( deep == 1 && shallow >= 1 ) {
00371     if( exclusive_switch == 1 ) {
00372       return DEEP_SHALLOW;
00373     } else {
00374       return DEEP_SHALLOW + SHALLOW_SHALLOW + SINGLE_DEEP + SINGLE_SHALLOW;
00375     }
00376   } else if ( deep == 1 ) {
00377     if( exclusive_switch == 1 ) {
00378       return SINGLE_DEEP;
00379     } else {
00380       return SINGLE_DEEP + SINGLE_SHALLOW;
00381     }
00382   }
00383   else if ( shallow >= 2 ) {
00384     if( exclusive_switch == 1 ) {
00385       return SHALLOW_SHALLOW;
00386     } else {
00387       return SHALLOW_SHALLOW + SINGLE_SHALLOW;
00388     }
00389   }
00390   else if ( shallow == 1 ) {
00391     return SINGLE_SHALLOW;
00392   } else {
00393     return 0;
00394   } 
00395 }
00396 
00397 void 
00398 mMuiBLTEmulator::fill_map() {
00399   
00400   // Take the output from emulator, fill pseudo-BLT map.
00401   //
00402   for(int iarm = 0; iarm < MUIOO::NumberOfArms; iarm++) {
00403     TMuiPseudoBLTMapO::iterator blt_iter = _blt_map->insert_new(iarm);
00404     int pseudoblt_bit = decision_event(iarm);
00405     if( (pseudoblt_bit & DEEP_DEEP) != 0 ) blt_iter->get()->fire_2D();
00406     if( (pseudoblt_bit & DEEP_SHALLOW) != 0 ) blt_iter->get()->fire_1D1S();
00407     for(int iquad = 0; iquad < max_quad; iquad++) {
00408       if(trig_accept[iarm][iquad]==DEEP_ROAD) {
00409         blt_iter->get()->fire_1D(iquad);
00410         blt_iter->get()->fire_1S(iquad);
00411       } else if(trig_accept[iarm][iquad]==SHALLOW_ROAD) {
00412         blt_iter->get()->fire_1S(iquad);
00413       }
00414     }
00415     if(is_reco_2D(iarm)) blt_iter->get()->fire_reco_2D();
00416     if(is_reco_1D1S(iarm)) blt_iter->get()->fire_reco_1D1S();
00417     for(int iquad = 0; iquad < max_quad; iquad++) {
00418       if(is_reco_1D(iarm,iquad)) blt_iter->get()->fire_reco_1D(iquad);
00419       if(is_reco_1S(iarm,iquad)) blt_iter->get()->fire_reco_1S(iquad);
00420     }
00421   }
00422 }
00423 
00425 void 
00426 mMuiBLTEmulator::set_interface_ptrs(PHCompositeNode* top_node){  
00427   // module runtime parameters
00428   //
00429   _mod_par    = TMutNode<mMuiBLTEmulatorPar>::find_node(top_node,"mMuiBLTEmulatorPar");
00430   // interface map 
00431   //
00432   _blt_map    = TMutNode<TMuiPseudoBLTMapO>::find_node(top_node,"TMuiPseudoBLTMapO");
00433 
00434   if(_mod_par->get_mode()==mMuiBLTEmulatorPar::FROMPRDF){
00435     _event = TMutNode<Event>::find_node(top_node,"PRDF");
00436     _hit_map = 0;
00437   }
00438   if(_mod_par->get_mode()==mMuiBLTEmulatorPar::FROMDST){
00439     _event = 0;
00440     _hit_map    = TMutNode<TMuiHitMapO>::find_node(top_node,"TMuiHitMapO");
00441   }
00442 } 
00443 
00444 void mMuiBLTEmulator::initialize(int runNumber){
00445 
00446   // initialize of non_used_plane
00447   const int nup_max = 3; // non_used_plane
00448   int nup_begin[nup_max];
00449   int nup_end[nup_max];
00450   int nup[nup_max];
00451   
00452   int init_done = 0;
00453 
00454   nup_begin[0] = 35758;
00455   nup[0] = 1;
00456   nup_end[0] = 40655; // end of Run-2
00457   nup_begin[1] = 40656; // It is not certain when it changed?
00458   nup[1] = 2;
00459   nup_end[1] = 71869;  
00460   nup_begin[2] = 71870;  // Nobu
00461   nup[2] = 4;
00462   nup_end[2] = 9999999; // current configuration
00463 
00464   //  int runNumber= 0;
00465   //if(_event) {
00466   //  runNumber = _event->getRunNumber();
00467   //} else {
00468   //  recoConsts* rc = recoConsts::instance();
00469   //  runNumber = rc->get_IntFlag("RUNNUMBER",80312);
00470   //  cout << " mMuiBLTEmulator :: the runNumber we get from this analysis is " << runNumber << endl; 
00471   // }
00472 
00473   int nup_found = 0;
00474   for ( int nup_set = 0; nup_set < nup_max; nup_set++ ) {
00475     if ( runNumber >= nup_begin[nup_set] && 
00476          runNumber <= nup_end[nup_set] ) {
00477       set_non_used_plane(nup[nup_set]);
00478       nup_found = 1;
00479       cout << " mMuiPsedoTrigger Non_Used_Plane was set to "
00480            << get_non_used_plane() << endl;
00481     }
00482   }
00483   if( !nup_found ) {
00484     cout << " mMuiPsedoTrigger Non_Used_Plane was not found for Run "
00485          << runNumber  << endl;
00486     cout << "   Default value " << get_non_used_plane() << " will be used " << endl;
00487   }
00488 
00489   //Let's see if the database contains a time stamp for this run number,
00490   // if so we'll try to get the map from the database.
00491   init_done = -1;
00492   bool db_init_done = false;
00493   RunToTimeObjy runTime;
00494   PHTimeStamp *beginTime = runTime.getBeginTime(runNumber);
00495   if (beginTime)
00496   {
00497     PdbBankManager *bankManager = PdbObjyBankManager::instance();
00498     PdbApplication *application = bankManager->getApplication();  
00499     if (application->startRead()) {
00500       PdbMuiTriggerMLU *achan;
00501       PdbBankID shortbankID("*.calib.mui.muitriggermlu");
00502       shortbankID.setInternalValue(0);  //Shallow MLU will be 0
00503       PdbCalBank* shortBank =
00504         bankManager->fetchBank("PdbMuiTriggerMLUBank",shortbankID,"calib.mui.muitriggermlu",runNumber);
00505        //We are good to go!
00506           //First the shallow
00507       if(shortBank > 0)
00508       {
00509         shortBank->print();
00510           PdbMuiTriggerMLU *achan;
00511           if(shortBank->getLength()<=mlu_address_max){
00512             for(unsigned int wordid = 0; wordid < shortBank->getLength(); wordid++)
00513             {
00514               achan = (PdbMuiTriggerMLU*)&(shortBank->getEntry(wordid));
00515               mlu_data_s[wordid]=achan->MLUword();
00516             }
00517             db_init_done = true;
00518           }
00519           else
00520           {
00521             cout << PHWHERE << "More data in database than expected."<<endl;
00522             db_init_done = false;
00523           }
00524           delete shortBank;
00525       }
00526       else
00527       {
00528         cout << PHWHERE << "Map wasn't found in database."<<endl;
00529       }
00530       PdbBankID deepbankID("*.calib.mui.muitriggermlu");
00531       deepbankID.setInternalValue(1);  //Deep MLU will be 1
00532       PdbCalBank* deepBank =
00533         bankManager->fetchBank("PdbMuiTriggerMLUBank",deepbankID,"calib.mui.muitriggermlu",runNumber);
00534       if(deepBank > 0)
00535       {
00536         deepBank->print();
00537         //Now the deep
00538         if(deepBank->getLength()<=mlu_address_max){
00539           for(unsigned int wordid = 0; wordid < deepBank->getLength(); wordid++)
00540           {
00541             achan = (PdbMuiTriggerMLU*)&(deepBank->getEntry(wordid));
00542             mlu_data_d[wordid]=achan->MLUword();
00543           }
00544           db_init_done = true;
00545           delete deepBank;
00546         }
00547         else
00548         {
00549           cout << PHWHERE << "More data in database than expected."<<endl;
00550           db_init_done = false;
00551         }
00552       }
00553       else
00554       {
00555         cout << PHWHERE << "Map wasn't found in database."<< endl;
00556       }
00557 
00558       application->commit();
00559     }
00560     else
00561     {
00562       cout << PHWHERE << "Failed to start application for update" << endl;
00563     }
00564      delete beginTime;
00565   }
00566   if(db_init_done)
00567   {
00568     init_done = 1;
00569     return ;
00570   }
00571   else
00572   {
00573     cout<< PHWHERE << "Map not found in database will try local files."<< endl;
00574   }
00575 
00576   int map_select = _mod_par->get_mlu_map();
00577   char* mlu_file_d;
00578   char* mlu_file_d1 = "mui_pseudotrigmap_deep_mh1.dat";
00579   char* mlu_file_d2 = "mui_pseudotrigmap_deep_mh2.dat";
00580   // MLU data file for deep roads
00581   char* mlu_file_s = "mui_pseudotrigmap_shallow.dat";
00582   int run_pp_begin = 35758;
00583   int run_change_deep = 38189;
00584   int run_pp_end = 40655;
00585   
00586   if( map_select == 1 || map_select == 0 && ( (runNumber >= run_pp_begin) && (runNumber < run_change_deep) ) )  {
00587     mlu_file_d = mlu_file_d1;
00588   }
00589   else if( (map_select == 2 ) || map_select == 0 && ( (runNumber >= run_change_deep) && (runNumber <= run_pp_end) ) ) {
00590     mlu_file_d = mlu_file_d2;
00591   }
00592   else { 
00593     cout << " mMuiPseudoTrigger: This is not pp Run2 or simulation" << endl;
00594     cout << "   No MLU map was read" << endl;
00595     return;
00596   }
00597 
00598   if( read_mlu_data( mlu_data_d, mlu_file_d ) ) {
00599       cout << "mMuiPsedoTrigger; MLU data for deep roads " 
00600            << mlu_file_d << " was read" << endl;    
00601   }
00602   else {
00603     return;
00604   }
00605 
00606   if( read_mlu_data( mlu_data_s, mlu_file_s ) ) {
00607       cout << "mMuiPsedoTrigger; MLU data for shallow roads " 
00608            << mlu_file_s << " was read" << endl;    
00609   }
00610   else {
00611     return;
00612   } 
00613 
00614    init_done = 1;
00615 }
00616 
00617 bool mMuiBLTEmulator::read_mlu_data( int* mlu_word, char* mlu_data_file = "deep.dat"){
00618 
00619   for ( int i = 0; i<mlu_address_max; i++ ) {
00620     mlu_word[i] = 0;
00621   }
00622 
00623   FILE* fp;
00624   if ( !( fp = fopen( mlu_data_file, "r" ))) {
00625     printf(" mMuiPseudoTrigger: Input file '%s' can not be opened\n",mlu_data_file);
00626    return False;
00627   }
00628   int scan_data;
00629   for ( int i = 0; i<mlu_address_max; i++ ) {
00630     if ( fscanf( fp, "%x\n", &scan_data ) != EOF ) {
00631       mlu_word[i] = scan_data;
00632     }
00633     else {
00634       printf(" mMuiPseudoTrigger: unable to read %d th line of '%s'\n", i, mlu_data_file);
00635       return False;
00636     }
00637   }
00638   fclose( fp );
00639 
00640   return True;
00641 
00642 }
00643 
00644 bool mMuiBLTEmulator::is_reco_2D(int arm) {
00645 
00646   for(int iquad1 = 0; iquad1 < 4; iquad1++) {
00647     if(is_reco_1D(arm, iquad1)) {
00648       for(int iquad2=0; iquad2<4; iquad2++) {
00649         if(iquad2==iquad1) continue;
00650         if(is_reco_1D(arm,iquad2)) return true;
00651       }
00652     }
00653   }
00654   return false;
00655 }
00656 
00657 bool mMuiBLTEmulator::is_reco_1D1S(int arm) {
00658   for(int iquad1 = 0; iquad1 < 4; iquad1++) {
00659     if(is_reco_1D(arm, iquad1)) {
00660       for(int iquad2=0; iquad2<4; iquad2++) {
00661         if(iquad2==iquad1) continue;
00662         if(is_reco_1D(arm,iquad2) || is_reco_1S(arm,iquad2)) return true;
00663       }
00664     }
00665   }
00666   return false;
00667 }
00668 
00669 bool mMuiBLTEmulator::is_reco_1D(int arm, int quad) {
00670 
00671   int nhit_quad = 0;
00672   
00673   for(int iplane = 0; iplane < MUIOO::MAX_PLANE-1; iplane++) {
00674     for(int iorient = 0; iorient < MUIOO::MAX_ORIENTATION; iorient++){
00675       int find_flag = 0;
00676       for(int ipanel = 0; ipanel < MUIOO::MAX_PANEL; ipanel++) {
00677         TMuiHitMapO::const_iterator mui_hit_iter = _hit_map->get(arm,iplane,ipanel,iorient);
00678         while(TMuiHitMapO::const_pointer mui_hit_ptr = mui_hit_iter.next()){
00679           TMuiMCHitMapO::const_key_iterator mc_hit_iter = mui_hit_ptr->get()->get_associated<TMuiMCHitO>();
00680           while(TMuiMCHitMapO::const_pointer mc_hit_ptr = mc_hit_iter.next()) {
00681             // if the hit is in big panel( 0, 2, 3, 5) we can decide it's quadrant directly,
00682             // if the hit is in small panel(1, 4) and on horizental plane, it contributes to
00683             // both left and right quadrants, if the hit is in small panel and verticle plane,
00684             // we have to relay on mchit x/y position to decide the quadrant.
00685             //
00686             int iquad = -1;
00687 
00688             if(ipanel == 3 ||(ipanel == 4 && iorient == 0) ) {
00689               iquad = 0;
00690               if(quad==iquad) find_flag = 1;
00691             }
00692             if(ipanel == 5 ||(ipanel == 4 && iorient == 0)) {
00693               iquad = 1;
00694               if(quad==iquad) find_flag = 1;
00695             }
00696             if(ipanel == 2 ||(ipanel == 1 && iorient == 0)) {
00697               iquad = 2;
00698               if(quad==iquad) find_flag = 1;
00699             }
00700             if(ipanel == 0 ||(ipanel == 1 && iorient == 0)) {
00701               iquad = 3;
00702               if(quad==iquad) find_flag = 1;
00703             }
00704             if(iorient == 1 && (ipanel==4||ipanel==1)){
00705               iquad = get_quad(mc_hit_ptr->get()->get_x(),
00706                                mc_hit_ptr->get()->get_y(), 
00707                                mc_hit_ptr->get()->get_z());
00708               if(quad==iquad) find_flag = 1; 
00709             }
00710           }
00711         }
00712       }
00713       if(find_flag) nhit_quad++;
00714     }
00715   }
00716   if(nhit_quad >=7 ) return true;
00717   
00718   return false;
00719 }
00720 
00721 bool mMuiBLTEmulator::is_reco_1S(int arm, int quad) {
00722 
00723   int nhit_quad = 0;
00724   
00725   for(int iplane = 0; iplane < MUIOO::MAX_PLANE-3; iplane++) {
00726     for(int iorient = 0; iorient < MUIOO::MAX_ORIENTATION; iorient++){
00727       int find_flag = 0;
00728       for(int ipanel = 0; ipanel < MUIOO::MAX_PANEL; ipanel++) {
00729         TMuiHitMapO::const_iterator mui_hit_iter = _hit_map->get(arm,iplane,ipanel,iorient);
00730         while(TMuiHitMapO::const_pointer mui_hit_ptr = mui_hit_iter.next()){
00731           TMuiMCHitMapO::const_key_iterator mc_hit_iter = mui_hit_ptr->get()->get_associated<TMuiMCHitO>();
00732           while(TMuiMCHitMapO::const_pointer mc_hit_ptr = mc_hit_iter.next()) {
00733             // if the hit is in big panel( 0, 2, 3, 5) we can decide it's quadrant directly,
00734             // if the hit is in small panel(1, 4) and on horizental plane, it contributes to
00735             // both left and right quadrants, if the hit is in small panel and verticle plane,
00736             // we have to relay on mchit x/y position to decide the quadrant.
00737             //
00738             int iquad = -1;
00739             if(ipanel == 3 ||(ipanel == 4 && iorient == 0) ) {
00740               iquad = 0;
00741               if(quad==iquad) find_flag = 1;
00742             } 
00743             if(ipanel == 5 ||(ipanel == 4 && iorient == 0)) {
00744               iquad = 1;
00745               if(quad==iquad) find_flag = 1;
00746             }
00747             if(ipanel == 2 ||(ipanel == 1 && iorient == 0)) {
00748               iquad = 2;
00749               if(quad==iquad) find_flag = 1;
00750             }
00751             if(ipanel == 0 ||(ipanel == 1 && iorient == 0)) {
00752               iquad = 3;
00753               if(quad==iquad) find_flag = 1;
00754             }
00755             if(iorient == 1 && (ipanel==4||ipanel==1)) {
00756               iquad = get_quad(mc_hit_ptr->get()->get_x(),
00757                                mc_hit_ptr->get()->get_y(), 
00758                                mc_hit_ptr->get()->get_z());
00759               if(quad==iquad) find_flag = 1; 
00760             }
00761           }
00762         }
00763       }
00764       if(find_flag) nhit_quad++;
00765     }
00766   }
00767 
00768   if(nhit_quad >=3 ) return true;
00769   
00770   return false;
00771 }
00772 
00773     
00774 int mMuiBLTEmulator::get_quad(float x, float y, float z) {
00775   
00776   if( x>= 0 && y >= 0 ) return 3;
00777   if( x>= 0 && y <= 0 ) return 1;
00778   if( x<= 0 && y >= 0 ) return 2;
00779   if( x<= 0 && y <= 0 ) return 0;
00780   
00781   // not reached
00782   return -1;
00783 }
00784 
00785 void mMuiBLTEmulator::check_blt() {
00786   
00787   // define a flag for debug.
00788   //
00789   int check_flag = 0;
00790   for(int iarm = 0; iarm < MUIOO::NumberOfArms; iarm++) {
00791     TMuiPseudoBLTMapO::const_iterator blt_iter = _blt_map->get(iarm);
00792     while(TMuiPseudoBLTMapO::const_pointer blt_ptr = blt_iter.next()){
00793       if(blt_ptr->get()->is_2D_fired()!=is_reco_2D(iarm)) {
00794         check_flag = 1;
00795         std::cout << " 2D trigger shows inconsistent " << std::endl;
00796         dump_reco_blt(iarm);
00797         blt_ptr->get()->print();
00798         _hit_map->print();
00799       } else if(blt_ptr->get()->is_1D1S_fired()!=is_reco_1D1S(iarm)) {
00800         check_flag = 1;
00801         std::cout << " 1D1S trigger shows inconsistent " << std::endl;
00802         dump_reco_blt(iarm);
00803         blt_ptr->get()->print();
00804         _hit_map->print();
00805       } 
00806     }
00807   }
00808 }
00809 
00810 void mMuiBLTEmulator::dump_reco_blt(int arm) {
00811 
00812   std::cout << " check on arm : " << arm << " :: " <<std::endl;
00813   std::cout << " reco trigger check from mMuiBLTEmulator " << std::endl;
00814   std::cout << " is_reco_2D::                            " << is_reco_2D(arm) << std::endl;
00815   std::cout << " is_reco_1D1S::                          " << is_reco_1D1S(arm) << std::endl;
00816   std::cout << " is_reco_1D quad0::                      " << is_reco_1D(arm, 0) << std::endl;  
00817   std::cout << " is_reco_1D quad1::                      " << is_reco_1D(arm, 1) << std::endl;  
00818   std::cout << " is_reco_1D quad2::                      " << is_reco_1D(arm, 2) << std::endl;  
00819   std::cout << " is_reco_1D quad3::                      " << is_reco_1D(arm, 3) << std::endl;  
00820   std::cout << " is_reco_1S quad0::                      " << is_reco_1S(arm, 0) << std::endl;  
00821   std::cout << " is_reco_1S quad1::                      " << is_reco_1S(arm, 1) << std::endl;  
00822   std::cout << " is_reco_1S quad2::                      " << is_reco_1S(arm, 2) << std::endl;  
00823   std::cout << " is_reco_1S quad3::                      " << is_reco_1S(arm, 3) << std::endl;  
00824 }
00825 
00826 

MUIOO: PHENIX Muon Identifier Analysis Framework. Documentation by doxygen
Last modified: