00001 #include "../interface/CocoaDaqReaderRoot.h" 00002 #include "TFile.h" 00003 #include "Alignment/CocoaDaq/interface/CocoaDaqRootEvent.h" 00004 00005 #include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurements.h" 00006 00007 #include <iostream> 00008 00009 #include "TClonesArray.h" 00010 00011 00012 //---------------------------------------------------------------------- 00013 CocoaDaqReaderRoot::CocoaDaqReaderRoot(const std::string& m_inFileName ) 00014 { 00015 00016 // Open root file 00017 theFile = new TFile(m_inFileName.c_str()); 00018 00019 // Read TTree named "CocoaDaq" in memory. !! SHOULD BE CALLED Alignment_Cocoa 00020 theTree = (TTree*)theFile->Get("CocoaDaq"); 00021 00022 nev = theTree->GetEntries(); // number of entries in Tree 00023 //if ( ALIUtils::debug >= 2) std::cout << "CocoaDaqReaderRoot::CocoaDaqReaderRoot: number of entries in Tree " << nev << std::endl; 00024 00025 nextEvent = 0; 00026 00027 // Event object must be created before setting the branch address 00028 theEvent = new CocoaDaqRootEvent(); 00029 00030 // link pointer to Tree branch 00031 theTree->SetBranchAddress("CocoaDaq", &theEvent); // !! SHOULD BE CALLED Alignment_Cocoa 00032 00033 CocoaDaqReader::SetDaqReader( this ); 00034 00035 } 00036 00037 //---------------------------------------------------------------------- 00038 CocoaDaqReaderRoot::~CocoaDaqReaderRoot() 00039 { 00040 theFile->Close(); 00041 } 00042 00043 //---------------------------------------------------------------------- 00044 bool CocoaDaqReaderRoot::ReadNextEvent() 00045 { 00046 return ReadEvent( nextEvent ); 00047 } 00048 00049 00050 //---------------------------------------------------------------------- 00051 bool CocoaDaqReaderRoot::ReadEvent( int nev ) 00052 { 00053 std::vector<OpticalAlignMeasurementInfo> measList; 00054 00055 int nb = 0; // dummy, number of bytes 00056 // Loop over all events 00057 nb = theTree->GetEntry(nev); // read in entire event 00058 00059 //if ( ALIUtils::debug >= 2) std::cout << "CocoaDaqReaderRoot reading event " << nev << " " << nb << std::endl; 00060 if( nb == 0 ) return 0; //end of file reached?? 00061 00062 // Every n events, dump one to screen 00063 if(nev%1 == 0) theEvent->DumpIt(); 00064 00065 //if ( ALIUtils::debug >= 2) std::cout<<" CocoaDaqReaderRoot::ReadEvent "<< nev <<std::endl; 00066 00067 //if ( ALIUtils::debug >= 2) std::cout<<" CocoaDaqReaderRoot::ReadEvent npos2D "<< theEvent->GetNumPos2D() << " nCOPS " << theEvent->GetNumPosCOPS() << std::endl; 00068 00069 for(int ii=0; ii<theEvent->GetNumPos2D(); ii++) { 00070 AliDaqPosition2D* pos2D = (AliDaqPosition2D*) theEvent->GetArray_Position2D()->At(ii); 00071 // std::cout<<"2D sensor "<<ii<<" has ID = "<<pos2D->GetID() 00072 // <<" and (x,y) = ("<<pos2D->GetX()<<","<<pos2D->GetY()<<")"<<std::endl; 00073 measList.push_back( GetMeasFromPosition2D( pos2D ) ); 00074 } 00075 for(int ii=0; ii<theEvent->GetNumPosCOPS(); ii++) { 00076 AliDaqPositionCOPS* posCOPS = (AliDaqPositionCOPS*) theEvent->GetArray_PositionCOPS()->At(ii); 00077 measList.push_back( GetMeasFromPositionCOPS( posCOPS ) ); 00078 //if ( ALIUtils::debug >= 2) std::cout<<"COPS sensor "<<ii<<" has ID = "<<posCOPS->GetID()<< std::endl; 00079 posCOPS->DumpIt("COPS"); 00080 } 00081 for(int ii=0; ii<theEvent->GetNumTilt(); ii++) { 00082 AliDaqTilt* tilt = (AliDaqTilt*) theEvent->GetArray_Tilt()->At(ii); 00083 measList.push_back( GetMeasFromTilt( tilt ) ); 00084 } 00085 for(int ii=0; ii<theEvent->GetNumDist(); ii++) { 00086 AliDaqDistance* dist = (AliDaqDistance*) theEvent->GetArray_Dist()->At(ii); 00087 measList.push_back( GetMeasFromDist( dist ) ); 00088 } 00089 00090 nextEvent = nev + 1; 00091 00092 BuildMeasurementsFromOptAlign( measList ); 00093 00094 return 1; 00095 00096 } 00097 00098 //---------------------------------------------------------------------- 00099 OpticalAlignMeasurementInfo CocoaDaqReaderRoot::GetMeasFromPosition2D( AliDaqPosition2D* pos2D ) 00100 { 00101 OpticalAlignMeasurementInfo meas; 00102 00103 meas.type_ = "SENSOR2D"; 00104 meas.name_ = pos2D->GetID(); 00105 //- std::vector<std::string> measObjectNames_; 00106 std::vector<bool> isSimu; 00107 for( size_t jj = 0; jj < 2; jj++ ){ 00108 isSimu.push_back(false); 00109 } 00110 meas.isSimulatedValue_ = isSimu; 00111 std::vector<OpticalAlignParam> paramList; 00112 OpticalAlignParam oaParam1; 00113 oaParam1.name_ = "H:"; 00114 oaParam1.value_ = pos2D->GetX(); 00115 oaParam1.error_ = pos2D->GetXerror(); 00116 paramList.push_back(oaParam1); 00117 00118 OpticalAlignParam oaParam2; 00119 oaParam2.name_ = "V:"; 00120 oaParam2.value_ = pos2D->GetY(); 00121 oaParam2.error_ = pos2D->GetYerror(); 00122 paramList.push_back(oaParam2); 00123 00124 meas.values_ = paramList; 00125 00126 return meas; 00127 } 00128 00129 00130 //---------------------------------------------------------------------- 00131 OpticalAlignMeasurementInfo CocoaDaqReaderRoot::GetMeasFromPositionCOPS( AliDaqPositionCOPS* posCOPS ) 00132 { 00133 OpticalAlignMeasurementInfo meas; 00134 00135 meas.type_ = "COPS"; 00136 meas.name_ = posCOPS->GetID(); 00137 //- std::vector<std::string> measObjectNames_; 00138 std::vector<bool> isSimu; 00139 for( size_t jj = 0; jj < 4; jj++ ){ 00140 isSimu.push_back(false); 00141 } 00142 meas.isSimulatedValue_ = isSimu; 00143 00144 std::vector<OpticalAlignParam> paramList; 00145 OpticalAlignParam oaParam1; 00146 oaParam1.name_ = "U:"; 00147 oaParam1.value_ = posCOPS->GetUp(); 00148 oaParam1.error_ = posCOPS->GetUpError(); 00149 paramList.push_back(oaParam1); 00150 00151 OpticalAlignParam oaParam2; 00152 oaParam2.name_ = "U:"; 00153 oaParam2.value_ = posCOPS->GetDown(); 00154 oaParam2.error_ = posCOPS->GetDownError(); 00155 paramList.push_back(oaParam2); 00156 00157 OpticalAlignParam oaParam3; 00158 oaParam3.name_ = "U:"; 00159 oaParam3.value_ = posCOPS->GetRight(); 00160 oaParam3.error_ = posCOPS->GetRightError(); 00161 paramList.push_back(oaParam3); 00162 00163 OpticalAlignParam oaParam4; 00164 oaParam4.name_ = "U:"; 00165 oaParam4.value_ = posCOPS->GetLeft(); 00166 oaParam4.error_ = posCOPS->GetLeftError(); 00167 paramList.push_back(oaParam4); 00168 00169 meas.values_ = paramList; 00170 00171 return meas; 00172 00173 } 00174 00175 //---------------------------------------------------------------------- 00176 OpticalAlignMeasurementInfo CocoaDaqReaderRoot::GetMeasFromTilt( AliDaqTilt* tilt ) 00177 { 00178 OpticalAlignMeasurementInfo meas; 00179 00180 meas.type_ = "SENSOR2D"; 00181 meas.name_ = tilt->GetID(); 00182 //- std::vector<std::string> measObjectNames_; 00183 std::vector<bool> isSimu; 00184 for( size_t jj = 0; jj < 2; jj++ ){ 00185 isSimu.push_back(false); 00186 } 00187 meas.isSimulatedValue_ = isSimu; 00188 std::vector<OpticalAlignParam> paramList; 00189 OpticalAlignParam oaParam; 00190 oaParam.name_ = "T:"; 00191 oaParam.value_ = tilt->GetTilt(); 00192 oaParam.error_ = tilt->GetTiltError(); 00193 paramList.push_back(oaParam); 00194 00195 meas.values_ = paramList; 00196 00197 00198 return meas; 00199 00200 } 00201 00202 00203 //---------------------------------------------------------------------- 00204 OpticalAlignMeasurementInfo CocoaDaqReaderRoot::GetMeasFromDist( AliDaqDistance* dist ) 00205 { 00206 OpticalAlignMeasurementInfo meas; 00207 00208 meas.type_ = "SENSOR2D"; 00209 meas.name_ = dist->GetID(); 00210 //- std::vector<std::string> measObjectNames_; 00211 std::vector<bool> isSimu; 00212 for( size_t jj = 0; jj < 2; jj++ ){ 00213 isSimu.push_back(false); 00214 } 00215 meas.isSimulatedValue_ = isSimu; 00216 std::vector<OpticalAlignParam> paramList; 00217 OpticalAlignParam oaParam; 00218 oaParam.name_ = "D:"; 00219 oaParam.value_ = dist->GetDistance(); 00220 oaParam.error_ = dist->GetDistanceError(); 00221 paramList.push_back(oaParam); 00222 00223 meas.values_ = paramList; 00224 00225 return meas; 00226 00227 } 00228 00229 void CocoaDaqReaderRoot::BuildMeasurementsFromOptAlign( std::vector<OpticalAlignMeasurementInfo>& measList ) 00230 { 00231 00232 }