00001 #include "ArchNPtGainTestResult.h"
00002 #include <TFile.h>
00003 #include <TKey.h>
00004 #include <TDirectory.h>
00005 #include <TSystem.h>
00006 #include <TNamed.h>
00007 #include <TObject.h>
00008 #include <TObjArray.h>
00009 #include <TString.h>
00010 #include <TObjString.h>
00011 #include <TVector.h>
00012 #include <TVectorD.h>
00013 #include <TH1.h>
00014 #include <TH2.h>
00015 #include <TCanvas.h>
00016 #include <TROOT.h>
00017 #include <is/isinfo.h>
00018 #include <iostream>
00019 #include <vector>
00020 #include "SummaryWriter/SummaryWriter.h"
00021 #include "SummaryWriter/SummaryManager.h"
00022
00023 #include "SctData/ResponseCurve.h"
00024
00025 using namespace SctData;
00026
00027
00028
00029
00030 ArchNPtGainTestResult::ArchNPtGainTestResult(): ArchTestResult() {
00031
00032
00033
00034
00035
00036 }
00037
00038
00039 ArchNPtGainTestResult::ArchNPtGainTestResult(NPtGainTestResult& NPtGtest): ArchTestResult(NPtGtest) {
00040
00041
00042
00043
00044 NChipData = NPtGtest.getNChipData();
00045 NChannelData = NPtGtest.getNChannelData();
00046
00047
00048 for (unsigned int i = 0; i<NChipData;i++) {
00049 chipData.push_back(&NPtGtest.getChipData(i));
00050
00051 }
00052
00053 for (unsigned int i = 0; i<NChannelData;i++) {
00054 channelData.push_back(&NPtGtest.getChannelData(i));
00055
00056 }
00057
00058
00059
00060 vector<const NPtGainTestResultData*>::iterator icf = chipData.begin();
00061 while( icf != chipData.end() ) {
00062 Chipfit.push_back((*icf)->rc->getFunction());
00063 ++icf;
00064 }
00065
00066
00067 vector<const NPtGainTestResultData*>::iterator icg = chipData.begin();
00068 while( icg != chipData.end() ) {
00069 ChipGraph.push_back((*icg)->graph);
00070 ++icg;
00071 }
00072
00073
00074
00075 double g[NChipData];
00076 unsigned int Ig=0;
00077 vector<const NPtGainTestResultData*>::iterator icgain = chipData.begin();
00078 while( icgain != chipData.end() ) {
00079 g[Ig] = (*icgain)->gain ;
00080 ++Ig;
00081 ++icgain;
00082 }
00083 vChipGain = new TVectorD(NChipData,g);
00084
00085
00086 double n[NChipData];
00087 unsigned int In=0;
00088 vector<const NPtGainTestResultData*>::iterator icnoise = chipData.begin();
00089 while( icnoise != chipData.end() ) {
00090 n[In] = (*icnoise)->noise ;
00091 ++In;
00092 ++icnoise;
00093 }
00094 vChipNoise = new TVectorD(NChipData,n);
00095
00096
00097 double o[NChipData];
00098 unsigned int Io=0;
00099 vector<const NPtGainTestResultData*>::iterator icoffset = chipData.begin();
00100 while( icnoise != chipData.end() ) {
00101 o[Io] = (*icoffset)->noise ;
00102 ++Io;
00103 ++icoffset;
00104 }
00105 vChipOffset = new TVectorD(NChipData,o);
00106
00107
00108
00109
00110 vector<const NPtGainTestResultData*>::iterator ichnf = channelData.begin();
00111 while( ichnf != channelData.end() ) {
00112 Channelfit.push_back((*ichnf)->rc->getFunction());
00113 ++ichnf;
00114 }
00115
00116
00117 vector<const NPtGainTestResultData*>::iterator ichng = channelData.begin();
00118 while( ichng != channelData.end() ) {
00119 ChannelGraph.push_back((*ichng)->graph);
00120 ++ichng;
00121 }
00122
00123
00124
00125
00126 double chng[NChannelData];
00127 unsigned int Ichng=0;
00128 vector<const NPtGainTestResultData*>::iterator ichngain = channelData.begin();
00129 while( ichngain != channelData.end() ) {
00130 chng[Ichng] = (*ichngain)->gain ;
00131 ++Ichng;
00132 ++ichngain;
00133 }
00134 vChannelGain = new TVectorD(NChannelData,chng);
00135
00136 double chnn[NChannelData];
00137 unsigned int Ichnn=0;
00138 vector<const NPtGainTestResultData*>::iterator ichnnoise = channelData.begin();
00139 while( ichnnoise != channelData.end() ) {
00140 chnn[Ichnn] = (*ichnnoise)->noise ;
00141 ++Ichnn;
00142 ++ichnnoise;
00143 }
00144 vChannelNoise = new TVectorD(NChannelData,chnn);
00145
00146 double chno[NChannelData];
00147 unsigned int Ichno=0;
00148 vector<const NPtGainTestResultData*>::iterator ichnoffset = channelData.begin();
00149 while( ichnnoise != channelData.end() ) {
00150 chno[Ichno] = (*ichnoffset)->noise ;
00151 ++Ichno;
00152 ++ichnoffset;
00153 }
00154 vChannelOffset = new TVectorD(NChannelData,chno);
00155
00156
00157
00158
00159
00160 try{
00161 TestSummary(NPtGtest);
00162 } catch(...) {
00163 cout<<" ERROR in retrieving Test Summary from IS" <<endl;
00164 }
00165
00166
00167
00168
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 ArchNPtGainTestResult::~ArchNPtGainTestResult() {
00180
00181
00182
00183
00184
00185 }
00186
00187
00188
00189
00190
00191 void ArchNPtGainTestResult::SaveNPtGainTestDataOnly() {
00192
00193 cout<<"Saving NPtGainTestData "<<endl;
00194
00195
00196 string filename = names->getfilename();
00197 string moduleID = names->getModuleID();
00198 string testType = names->getTestType();
00199 string runID = names->getRunID();
00200 string ChipDataID = names->getChipDataID();
00201 string vChipGainID = names->getChipGainID();
00202 string vChipNoiseID = names->getChipNoiseID();
00203 string vChipOffsetID = names->getChipOffsetID();
00204 string ChannelDataID = names->getChannelDataID();
00205 string vChannelGainID = names->getChannelGainID();
00206 string vChannelNoiseID = names->getChannelNoiseID();
00207 string vChannelOffsetID = names->getChannelOffsetID();
00208
00209
00210
00211
00212
00213
00214 TFile *storage_file = new TFile(filename.c_str(),"update");
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 TDirectory *this_run = (TDirectory*) gDirectory->Get(runID.c_str());
00228
00229
00230 if (!this_run) {
00231
00232 this_run = storage_file->mkdir(runID.c_str());
00233
00234 }
00235 storage_file->GetListOfKeys()->Print();
00236 this_run->cd();
00237
00238
00239
00240 TObject* pers_runnumber = gDirectory->FindObjectAny(runID.c_str());
00241 if (!pers_runnumber) {
00242 double frunNumber = runNumber;
00243 TVector run(1,1,frunNumber, "END");
00244 run.Write(runID.c_str());
00245 }
00246
00247
00248
00249
00250 TDirectory* this_module = (TDirectory*) gDirectory->Get(moduleID.c_str());
00251
00252 if (!this_module) {
00253
00254 this_module =gDirectory ->mkdir(moduleID.c_str());
00255 }
00256
00257
00258
00259
00260 this_module->cd();
00261 TDirectory* this_testType = (TDirectory*) gDirectory->Get(testType.c_str());
00262
00263
00264 if (!this_testType) {
00265
00266 this_testType = gDirectory->mkdir(testType.c_str());
00267 }
00268 this_testType->cd();
00269
00270
00271
00272 TDirectory* this_ChipData = (TDirectory*) this_testType->Get(ChipDataID.c_str());
00273 if (!this_ChipData) {
00274
00275 this_ChipData = this_testType->mkdir(ChipDataID.c_str());
00276 }
00277 this_ChipData->cd();
00278
00279
00280 int chipN=0;
00281 for (vector<shared_ptr<TF1> >::iterator i = Chipfit.begin(); i!=Chipfit.end(); i++) {
00282 (*i)->Write(names->getChipFitID(chipN).c_str());
00283 ++chipN;
00284 }
00285 chipN=0;
00286 for (vector<shared_ptr<TGraph> >::iterator i = ChipGraph.begin(); i!=ChipGraph.end(); i++) {
00287 (*i)->Write(names->getChipGraphID(chipN).c_str());
00288 ++chipN;
00289 }
00290
00291 vChipGain->Write(vChipGainID.c_str());
00292 vChipNoise->Write(vChipNoiseID.c_str());
00293 vChipOffset->Write(vChipOffsetID.c_str());
00294
00295
00296
00297 TDirectory* this_ChannelData = (TDirectory*) this_testType->Get(ChannelDataID.c_str());
00298 if (!this_ChannelData) {
00299
00300 this_ChannelData = this_testType->mkdir(ChannelDataID.c_str());
00301 }
00302 this_ChannelData->cd();
00303
00304
00305 int channelN=0;
00306 for (vector<shared_ptr<TF1> >::iterator i = Channelfit.begin(); i!=Channelfit.end(); i++) {
00307 (*i)->Write(names->getChannelFitID(channelN).c_str());
00308 ++channelN;
00309 }
00310 channelN=0;
00311 for (vector<shared_ptr<TGraph> >::iterator i = ChannelGraph.begin(); i!=ChannelGraph.end(); i++) {
00312 (*i)->Write(names->getChannelGraphID(channelN).c_str());
00313 ++channelN;
00314 }
00315
00316 vChannelGain->Write(vChannelGainID.c_str());
00317
00318 vChannelNoise->Write(vChannelNoiseID.c_str());
00319
00320 vChannelOffset->Write(vChannelOffsetID.c_str());
00321
00322
00323
00324 if(testSummary != NULL) {
00325 this_testType->cd();
00326
00327 TObject* pers_testSummary = gDirectory->FindObjectAny(names->getTestSummaryID().c_str());
00328 if (!pers_testSummary) {
00329 testSummary->Write(names->getTestSummaryID().c_str());
00330
00331 }
00332 }
00333
00334
00335
00336
00337
00338
00339 storage_file->Close();
00340 delete storage_file;
00341
00342
00343
00344
00345
00346
00347 }
00348
00349
00350
00351 void ArchNPtGainTestResult::SaveNPtGain() {
00352
00353 SaveTestDataOnly();
00354 SaveNPtGainTestDataOnly();
00355 SaveRawScans();
00356 SaveFitScans();
00357 AddTestToIndex();
00358
00359 }
00360
00361
00362
00363
00364
00365 void ArchNPtGainTestResult::TestSummary(NPtGainTestResult & NPtGtest) {
00366
00367 ostringstream datastream;
00368 shared_ptr<const SctData::TestSummary::SummaryWriter> writer =
00369 SctData::TestSummary::SummaryManager::instance().getWriter(NPtGtest.getClassName());
00370 writer->writeHeader(NPtGtest, datastream);
00371 writer->write(NPtGtest, datastream);
00372 string myString = datastream.str();
00373
00374
00375 testSummary = new TObjString(myString.c_str());
00376
00377
00378
00379
00380 return;
00381
00382
00383 }