/////////////////////////////////////////////////////////////////////////////// // $Id: L3CalCalib.cpp, v 0.0, Mrinmoy Bhattacharjee$ // // Created: October 21st. 1998 Mrinmoy Bhattacharjee // Purpose: Implementation file for Calorimeter Calibration data // processing package // /////////////////////////////////////////////////////////////////////////////// /////////////////////////////// Include files ///////////////////////////////// #include "L3CalCalib/L3CalCalib.hpp" #include "framework/Registry.hpp" #include "framework/Result.hpp" #include "framework/utilities/Utils.hpp" #include "edm/Event.hpp" #include "edm/IDSelector.hpp" #include "edm/TKey.hpp" #include "edm/THandle.hpp" #include #include #include #include #include #include #include #include "l3base/L3Crate.hpp" #include "l3base/L3CrateSimulator.hpp" #include "l3base/L3MPMSimulator.hpp" #include "l3base/L3CrateModuleAdaptor.hpp" #include "l3base/L3CrateModule.hpp" #include "l3base/RawDataChunk.hpp" #include "l3base/RawDataChunkSimulator.hpp" #ifdef ROOT_HIST #include "HepTuple/HepRootFileManager.h" #include "HepTuple/HepHist1D.h" #include "HepTuple/HepHist2D.h" #include "HepTuple/HepNtuple.h" #else #include "HepTuple/HepHBookFileManager.h" #include "HepTuple/HepHBook.h" #include "HepTuple/HepHBookNtuple.h" #endif using namespace edm; using namespace std; using fwk::Context; using fwk::Package; using fwk::Process; using fwk::JobSummary; using fwk::Result; ///////////////////////// Registry & Global decl ///////////////////////////// FWK_REGISTRY_IMPL(L3CalCalib, "$Name: $") int truncate1,truncate8; int which_crate,which_card,BLS,Nsig; ofstream calib_out("calib_test.result"); //////////////////////// Constructor & Destructor ///////////////////////////// L3CalCalib::L3CalCalib(Context* context): Package(context), Process(context), JobSummary(context) { RCP rcp=packageRCP(); BLS =rcp.getInt("BLS"); Nsig =rcp.getInt("Nsig"); truncate1=rcp.getInt("truncate1"); truncate8=rcp.getInt("truncate8"); which_crate=rcp.getInt("which_crate"); which_card =rcp.getInt("which_card"); cout << "=====================================" << endl; cout << "Initializing L3 Calib Package" << endl; // Construct ADC Crates // if( rcp.getBool("one_crate_operation")){ CalCalib_AdcCrate Crate(rcp.getInt("Crate_ID"),rcp.getInt("Crate_Siz"), rcp.getString("input_buffer")); _Crate_in_this_node.push_back(Crate); cout << endl << "1 Crate Operation" << endl; } else if( rcp.getBool("two_crate_operation")){ CalCalib_AdcCrate Crate1(rcp.getInt("Crate_ID1"),rcp.getInt("Crate_Siz"), rcp.getString("input_buffer")); _Crate_in_this_node.push_back(Crate1); CalCalib_AdcCrate Crate2(rcp.getInt("Crate_ID2"),rcp.getInt("Crate_Siz"), rcp.getString("input_buffer")); _Crate_in_this_node.push_back(Crate2); cout << endl << "2 Crate Operation" << endl; } _RunN = 0; _eventCount = 0; // Histogram stuff // #ifdef ROOT_HIST _hbkMgr= new HepRootFileManager((rcp.getString("hbk_file")).c_str()); #else _hbkMgr= new HepHBookFileManager((rcp.getString("hbk_file")).c_str()); #endif char hname[100]; for( int j=0; j<12; j++ ){ sprintf(hname,"Mean %d",j+1); _mean[j]=&_hbkMgr->hist1D(hname,501, 0.0, 500.0); sprintf(hname,"Sigma %d",j+61); _sigma[j]=&_hbkMgr->hist1D(hname,100, 0.0, 1.0); } #ifdef ROOT_HIST #else #endif cout << endl << "Performing a " << _Crate_in_this_node[0].getRunName() << " run" << endl; cout << "=====================================" << endl; } L3CalCalib::~L3CalCalib(){delete _hbkMgr;} /////////////////////////////// Process Event ///////////////////////////////// Result L3CalCalib::processEvent(Event &event) { _RunCalib(event); _eventCount++; return Result::success; } ////////////////////////////// Run Calibration //////////////////////////////// void L3CalCalib::_RunCalib(Event &event) { using namespace edm; using namespace std; using namespace fwk; unsigned int pkdchn; // Find a Raw Data Chunk in the event // const TKey rawKey; THandle rawchunk = rawKey.find(event); if( rawchunk.isValid() ){} if( !rawchunk.isValid() ){cout << "ERROR: No RawDataChunk" << endl; return;} // Get a Pointer to the Raw Data Chunk // l3base::RawDataChunk* rawptr=rawchunk.ptr(); int ncr = rawptr->number_of_crates(); // Loop & get the ADC Crate from the RawDataChunk // for( int icr=1; icr<13; ++icr ){ if( rawptr->crate_id_exists(64+icr) && 64+icr == _Crate_in_this_node[0].getCrtId() ){ const L3Crate &l3crate = rawptr->get_crate(64+icr); // Get ADC Cards in ADC Crate (RAW & L3Calib) // l3base::L3CrateModuleAdaptor crate_module(l3crate); l3vector& crdvec=_Crate_in_this_node[0].getCardS(); // Loop over Cards in RAW Crate // for( int icard=1; icard& chnvec=crdvec[icard-1].getChannelS(); const l3base::L3CrateModule &module = crate_module[icard]; l3base::L3CrateModule::const_iterator imod; // Check if ADC Card has data & loop over channels// if( module.size()>0 ){ for (imod=module.begin(); imod!=module.end(); imod++){ pkdchn = *imod; int mychn = ((pkdchn & 0x7fc0000)>>18); chnvec[mychn].adtoMean(float((pkdchn & 0xFFFF)-truncate1), float((pkdchn & 0xFFFF)-truncate8)); chnvec[mychn].adtoSigma(float((pkdchn & 0xFFFF)-truncate1), float((pkdchn & 0xFFFF)-truncate8)); chnvec[mychn].updtEvtCnt(); } //end loop RAW data channels } //end check ADC data } // loop over cards } //end check valid crate } //end loop RAW data crates } ///////////////////////////////// Run Summary ///////////////////////////////// Result L3CalCalib::jobSummary(){ clock_t start_time1 = clock(); cout << endl << endl <<"Now performing job summary ... "; l3vector& crdvec=_Crate_in_this_node[0].getCardS(); int crtsize=_Crate_in_this_node[0].getCrtSiz(); // Calculate Mean & Sigma // for( int i=0; i& chnvec=crdvec[i].getChannelS(); int crdsiz=crdvec[i].getCrdSiz(); for( int j=0; jaccumulate(chnvec[j].getMean1() ); _sigma[i]->accumulate(chnvec[j].getSigma1()); } } // Print to screen OR file // if( which_crate == _Crate_in_this_node[0].getCrtId() ){ l3vector& chnvec=crdvec[which_card].getChannelS(); int crdsiz=crdvec[which_card].getCrdSiz(); for( int i=0; i=BLS*64 && i<(BLS+1)*64 ){ calib_out << "Crate info (" << which_crate << "," << which_card << "," << i << ") BLS-Twr-Dpth (" << chnvec[i].getBLS() << "," << chnvec[i].getTWR() << "," << chnvec[i].getDPTH() << ") Mu-Sig (" << chnvec[i].getMean1() << ", " << chnvec[i].getSigma1() << ")"<< endl;} } } cout << "done" << endl; cout << endl; cout << endl; cout << "Finished Running L3CalCalib with: " << endl; cout << _eventCount <<" events processed"<> 16 ); // scale: bit 17 (Gain 1 or 8) // return ( (w & 0x20000) >> 17 ); // depth: bits 18 - 21 (Depth) // return ( (w & 0x3C0000) >> 18 ); // tower: bits 22 - 23 (Tower) // return ( (w & 0xC00000) >> 22 ); // BLS: bits 24 - 26 (BLS) // return ( (w & 0x7000000) >> 24 ); // ADC Card ID: bits 27-30 // return ( (w & 0x78000000) >> 27 ); // Channel ID: bits 18-26 // return ( (w & 0x7fc0000) >> 18 ); // if( module.size()>0 ){ // for (imod = module.begin(); imod != module.end(); imod++) { // w = *imod; // calib_out << " crate: " << l3crate.get_id() // << " card: " << ( (w & 0x78000000) >> 27 ) // << " bls: " << ( (w & 0x7000000) >> 24 ) // << " tow: " << ( (w & 0xC00000) >> 22 ) // << " dep: " << ( (w & 0x3C0000) >> 18 ) // << " channel: " << ( (w & 0x7fc0000) >> 18 ) // << " ADC Counts: " << ( w & 0xFFFF ) // << endl; // } // loop over channels in card // } // if Card has data