00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "StSsdDaqMaker.h"
00029 #include "TDataSetIter.h"
00030 #include "StMessMgr.h"
00031 #include "StDAQMaker/StDAQReader.h"
00032 #include "StDAQMaker/StSSDReader.h"
00033 #include "ssdLadderMap.h"
00034 #include "tables/St_spa_strip_Table.h"
00035 #include "tables/St_ssdConfiguration_Table.h"
00036 #include "tables/St_ssdPedStrip_Table.h"
00037 #include "StSsdUtil/StSsdConfig.hh"
00038 #include "TH1.h"
00039 #include "TH2.h"
00040 #include "TFile.h"
00041 #include "TNtuple.h"
00042 ClassImp(StSsdDaqMaker)
00043
00044
00046
00053 StSsdDaqMaker::StSsdDaqMaker(const char *name):StMaker(name){
00054
00055 }
00056
00057
00058
00060
00069 StSsdDaqMaker::~StSsdDaqMaker(){
00070
00071 }
00072
00073
00074
00076 Int_t StSsdDaqMaker::Init(){
00077
00078
00079
00080
00081 LOG_INFO << "Read now Databases " << endm;
00082
00083 if (IAttr(".histos")) {
00084 occupancy_wafer = new TH2S("occupancy_wafer","occupancy per wafer",40,0,40,20,0,20);
00085 occupancy_chip = new TH2S("occupancy_chip","occupancy per chip",40,0,40,99,0,99);
00086 noise_chip = new TH2S("noise_chip","mean noise per chip",40,0,40,99,0,99);
00087 noise_wafer = new TH2S("noise_wafer","mean noise per wafer",40,0,40,20,0,20);
00088 noise_chip_P = new TH2S("noise_chip_P","mean noise per chip for the P Side ",20,0,20,96,0,96);
00089 noise_chip_N = new TH2S("noise_chip_N","mean noise per chip for the N Side",20,0,20,96,0,96);
00090 pedestal_chip = new TH2S("pedestal_chip","pedestal per chip",40,0,40,99,0,99);
00091 ped_zero_ladP = new TH2S("ped_zero_ladP","map of p-side wafers where strips have ped = 0",20,0,20,15,0,15);
00092 ped_zero_ladN = new TH2S("ped_zero_ladN","map of n-side wafers where strips have ped = 0",20,0,20,15,0,15);
00093 ped_high_ladP = new TH2S("ped_high_ladP","map of p-side wafers where strips have ped = 255",20,0,20,15,0,15);
00094 ped_high_ladN = new TH2S("ped_high_ladN","map of n-side wafers where strips have ped = 255",20,0,20,15,0,15);
00095 noise_zero_ladP = new TH2S("noise_zero_ladP","map of p-side wafers where strips have noise = 0",20,0,20,15,0,15);
00096 noise_zero_ladN = new TH2S("noise_zero_ladN","map of n-side wafers where strips have noise = 0",20,0,20,15,0,15);
00097 noise_high_ladP = new TH2S("noise_high_ladP","map of p-side wafers where strips have noise = 255",20,0,20,15,0,15);
00098 noise_high_ladN = new TH2S("noise_high_ladN","map of n-side wafers where strips have noise = 255",20,0,20,15,0,15);
00099 occupancy = new TH1F("deadStrips","number of dead strips",40,0,40);
00100 occupancy_wafer->SetXTitle("Ladder");
00101 occupancy_wafer->SetYTitle("Wafer");
00102 occupancy_chip->SetXTitle("Ladder");
00103 occupancy_chip->SetYTitle("Chip");
00104 noise_chip->SetXTitle("Ladder");
00105 noise_chip->SetYTitle("Chip");
00106 noise_chip_P->SetXTitle("Ladder");
00107 noise_chip_N->SetXTitle("Ladder");
00108 noise_chip_P->SetYTitle("Chip");
00109 noise_chip_N->SetYTitle("Chip");
00110 noise_wafer->SetXTitle("Ladder");
00111 noise_wafer->SetYTitle("Wafer");
00112 pedestal_chip->SetXTitle("Ladder");
00113 pedestal_chip->SetYTitle("Chip");
00114 occupancy->SetXTitle("Ladder");
00115 occupancy->SetYTitle("#");
00116 ped_zero_ladP->SetXTitle("Ladder");
00117 ped_zero_ladP->SetYTitle("Wafer");
00118 ped_zero_ladN->SetXTitle("Ladder");
00119 ped_zero_ladN->SetYTitle("Wafer");
00120 ped_high_ladP->SetXTitle("Ladder");
00121 ped_high_ladP->SetYTitle("Wafer");
00122 ped_high_ladN->SetXTitle("Ladder");
00123 ped_high_ladN->SetYTitle("Wafer");
00124 noise_zero_ladP->SetXTitle("Ladder");
00125 noise_zero_ladP->SetYTitle("Wafer");
00126 noise_zero_ladN->SetXTitle("Ladder");
00127 noise_zero_ladN->SetYTitle("Wafer");
00128 noise_high_ladP->SetXTitle("Ladder");
00129 noise_high_ladP->SetYTitle("Wafer");
00130 noise_high_ladN->SetXTitle("Ladder");
00131 noise_high_ladN->SetYTitle("Wafer");
00132 mPedOut = 0;
00133 if(mPedOut)
00134 {
00135 DeclareNTuple();
00136 }
00137 }
00138 LOG_INFO << "Init() - Done " << endm;
00139
00140 return StMaker::Init();
00141 }
00142
00143
00144 Int_t StSsdDaqMaker::InitRun(int runumber)
00145 {
00146 LOG_INFO <<"InitRun(int runumber) - Read now Databases"<<endm;
00147 Int_t run = (runumber/1000000)-1;
00148
00149 St_ssdConfiguration *configuration = (St_ssdConfiguration*) GetDataBase("Geometry/ssd/ssdConfiguration");
00150 if (!configuration){
00151 LOG_ERROR << "InitRun("<<runumber<<") - ERROR - ssdConfiguration==0"<<endm;
00152 return 0;
00153 }
00154 ssdConfiguration_st *config = (ssdConfiguration_st*) configuration->GetTable() ;
00155 if (!config){
00156 LOG_ERROR <<"InitRun("<<runumber<<") - ERROR - config==0"<<endm;
00157 return 0;
00158 }
00159
00160 mConfig = new StSsdConfig();
00161
00162 int totLadderPresent = 0;
00163
00164 for (int ladder = 1; ladder<=config->nMaxLadders;ladder++)
00165 {
00166 LOG_INFO<< " on sector = " << config->ladderIsPresent[ladder-1];
00167 if (config->ladderIsPresent[ladder-1] != 0)
00168 totLadderPresent++;
00169 mConfig->setLadderIsActive(ladder,config->ladderIsPresent[ladder-1]);
00170 }
00171 PrintConfiguration(run,config);
00172 mConfig->setNumberOfLadders(totLadderPresent);
00173 mConfig->setNumberOfWafers(config->nMaxWafers/config->nMaxLadders);
00174 mConfig->setNumberOfHybrids(2);
00175 mConfig->setTotalNumberOfHybrids(2*16*totLadderPresent);
00176 mConfig->setTotalNumberOfLadders(config->nMaxLadders);
00177 mConfig->setNumberOfStrips(768);
00178
00179 mConfig->setConfiguration();
00180
00181 LOG_INFO << "_____________________________" << endm;
00182 LOG_INFO << " Via Datababase......." << endm;
00183 LOG_INFO << ".......numberOfSectors = " << config->nMaxSectors << endm;
00184 LOG_INFO << ".......numberOfLadders = " << totLadderPresent << endm;
00185 LOG_INFO << " .numberOfWafersPerLadder = " << config->nMaxWafers/config->nMaxLadders << endm;
00186 LOG_INFO << "_____________________________" << endm;
00187 LOG_INFO << " InitRun() - Done "<<endm;
00188 return kStOk;
00189
00190 }
00191
00192
00193
00194 void StSsdDaqMaker::DeclareNTuple(){
00195 pFile = new TFile("PedestalFile.root","RECREATE");
00196 string varlist = "side:ladder:wafer:strip:pedestal:noise:chip:id_wafer:tot_strip";
00197 pTuple = new TNtuple("PedestalNTuple","Pedestal Ntuple",varlist.c_str());
00198 LOG_INFO << "StSsdDaqMaker::DeclareNtuple - Done - "<<endm;
00199 }
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 Int_t StSsdDaqMaker::Make(){
00211 int strip_number,id_wafer,id_side,count,my_channel=-9999;
00212 int ladderCountN[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
00213 int ladderCountP[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} ;
00214 int data,pedestal,noise,channel,newchannel,ladder; char EastWest;
00215 int maxChannel;
00216 int nStrip =0;
00217 int iLad = 0;
00218 int iWaf = 0;
00219 int chip = 0;
00220
00221
00222
00223
00224 for (Int_t i=0;i<9;i++){
00225 PedestalNTuple[i] = 0;
00226 }
00227 maxChannel=mConfig->getNumberOfStrips()*mConfig->getNumberOfWafers();
00228 TDataSet *daq = GetDataSet("StDAQReader");
00229 if (!daq) {
00230 LOG_WARN << "Make : StDAQReader Dataset not found - Skipping the event" << endm;
00231 return kStWarn;
00232 }
00233 StDAQReader *daqReader = (StDAQReader*) (daq->GetObject());
00234 if (!daqReader) {
00235 LOG_WARN << "Make : StDAQReader Object not found - Skipping the event" << endm;
00236 return kStWarn;
00237 }
00238 if (!(daqReader->SSDPresent())) {
00239 LOG_WARN << "Make : The SSD was not in the data stream - Skipping the event" << endm;
00240 return kStWarn;
00241 }
00242 StSSDReader *stssdreader = daqReader->getSSDReader();
00243 if(!stssdreader)
00244 {
00245 LOG_WARN << "Make : SSD reader not found - Skipping the event" << endm;
00246 return kStWarn;
00247 }
00248
00249 St_spa_strip *spa_strip = (St_spa_strip *) m_DataSet->Find("spa_strip");
00250 if(!spa_strip)
00251 {
00252 spa_strip = new St_spa_strip("spa_strip",100000);
00253 m_DataSet->Add(spa_strip);
00254 }
00255 St_ssdPedStrip *ssdPedStrip = (St_ssdPedStrip *) m_DataSet->Find("ssdPedStrip");
00256 if(!ssdPedStrip)
00257 {
00258 ssdPedStrip = new St_ssdPedStrip("ssdPedStrip",100000);
00259 m_DataSet->Add(ssdPedStrip);
00260 }
00261 spa_strip_st out_strip;
00262 ssdPedStrip_st out_ped_strip;
00263 count=1;
00264
00265 static const char EW[4]={'E','W','p','n'};
00266 for (id_side=0;id_side<2;id_side++)
00267 {
00268 EastWest=EW[id_side];
00269 LOG_DEBUG <<" process "<<EW[id_side+2]<<"-side ladders "<< endm;
00270 for (ladder=0;ladder<mConfig->getTotalNumberOfLadders();ladder++)
00271 {
00272 if (mConfig->getLadderIsActive(ladder+1)>0)
00273 {
00274 if ((ladder+1)== 4 || (ladder+1)== 6 || (ladder+1)==10 ||
00275 (ladder+1)==11 || (ladder+1)==13 || (ladder+1)==15 ||
00276 (ladder+1)==17 )
00277 maxChannel=mConfig->getNumberOfStrips()*mConfig->getNumberOfWafers()-1;
00278 else maxChannel=mConfig->getNumberOfStrips()*mConfig->getNumberOfWafers();
00279 for (newchannel=0;newchannel<maxChannel;newchannel++)
00280 {
00281 if ((ladder+1)== 4 || (ladder+1)== 6 || (ladder+1)==10 ||
00282 (ladder+1)==11 || (ladder+1)==13 || (ladder+1)==15 ||
00283 (ladder+1)==17 )
00284 channel= newchannel+1;
00285 else channel=newchannel;
00286 if(stssdreader->getSsdData(ladder+1,EastWest,newchannel,data,pedestal,noise)==0)
00287 {
00288
00289
00290
00291
00292
00293
00294 if (data>0) {
00295 if (id_side==1) my_channel=maxChannel-1-channel;
00296 else my_channel=channel;
00297
00298
00299 if (id_side==1) {
00300 for (int kk=0;kk<maxChannel;kk++) {
00301 if (ssd_ladder_mapN[kk]==channel) my_channel=kk;
00302 }
00303 }
00304 else {
00305 for (int kk=0;kk<maxChannel;kk++) {
00306 if (ssd_ladder_mapP[kk]==channel) my_channel=kk;
00307 }
00308 }
00309 assert(my_channel>=0);
00310 strip_number=my_channel-(my_channel/mConfig->getNumberOfStrips())*mConfig->getNumberOfStrips()+1;
00311 if (id_side==0)
00312 id_wafer=7000+100*(mConfig->getNumberOfWafers()-(my_channel/mConfig->getNumberOfStrips()))+ladder+1;
00313 else
00314 id_wafer=7000+100*((my_channel/mConfig->getNumberOfStrips())+1)+ladder+1;
00315 out_strip.id = count;
00316 out_strip.adc_count = data;
00317 out_strip.id_strip = 10000*(10*strip_number+id_side)+id_wafer;
00318 out_strip.id_mchit[0] = 0;
00319 out_strip.id_mchit[1] = 0;
00320 out_strip.id_mchit[2] = 0;
00321 out_strip.id_mchit[3] = 0;
00322 out_strip.id_mchit[4] = 0;
00323 spa_strip->AddAt(&out_strip);
00324 if (id_side ==0) ladderCountP[ladder]++;
00325 else ladderCountN[ladder]++;
00326 count++;
00327 }
00328 }
00329 else
00330 {
00331
00332
00333
00334
00335
00336
00337 if (pedestal>=0) {
00338
00339
00340
00341
00342 if (id_side==1) {
00343 for (int kk=0;kk<maxChannel;kk++) {
00344 if (ssd_ladder_mapN[kk]==channel) my_channel=kk;
00345 }
00346
00347 }
00348 else {
00349 for (int kk=0;kk<maxChannel;kk++) {
00350 if (ssd_ladder_mapP[kk]==channel) my_channel=kk;
00351 }
00352
00353 }
00354 strip_number=my_channel-(my_channel/mConfig->getNumberOfStrips())*mConfig->getNumberOfStrips()+1;
00355 if (id_side==0)
00356 id_wafer=7000+100*(mConfig->getNumberOfWafers()-(my_channel/mConfig->getNumberOfStrips()))+ladder+1;
00357 else
00358 id_wafer=7000+100*((my_channel/mConfig->getNumberOfStrips())+1)+ladder+1;
00359 out_ped_strip.id = count;
00360 out_ped_strip.id_strip = 10000*(10*strip_number+id_side)+id_wafer;
00361 out_ped_strip.noise = noise;
00362 out_ped_strip.pedestal = pedestal;
00363 nStrip=(int)(out_ped_strip.id_strip/100000.);
00364 iWaf = (int)((id_wafer - 7*1000)/100 - 1);
00365 iLad = (int)(id_wafer - 7*1000 - (iWaf+1)*100 - 1);
00366 nStrip=nStrip-1;
00367 chip=(int)((nStrip+(768*(iWaf)))/128.);
00368 ssdPedStrip->AddAt(&out_ped_strip);
00369 if (id_side ==0) {
00370 ladderCountP[ladder]++;
00371 occupancy_wafer->Fill(2*iLad,iWaf,1);
00372 occupancy_chip->Fill(2*iLad,chip,1);
00373 noise_chip->Fill(2*iLad,chip,(out_ped_strip.noise/(16.)));
00374 noise_wafer->Fill(2*iLad,iWaf,(out_ped_strip.noise/(16.)));
00375 noise_chip_P->Fill(iLad,chip,(out_ped_strip.noise/(16.)));
00376 pedestal_chip->Fill(2*iLad,chip,out_ped_strip.pedestal);
00377 if(pedestal==0)ped_zero_ladP->Fill(iLad,iWaf);
00378 if(pedestal==255)ped_high_ladP->Fill(iLad,iWaf);
00379 if(noise==0)noise_zero_ladP->Fill(iLad,iWaf);
00380 if(noise==255)noise_high_ladP->Fill(iLad,iWaf);
00381
00382
00383 if(mPedOut){
00384 PedestalNTuple[0]=0;
00385 PedestalNTuple[1]=iLad;
00386 PedestalNTuple[2]=iWaf;
00387 PedestalNTuple[3]=nStrip+1;
00388 PedestalNTuple[4]=out_ped_strip.pedestal;
00389 PedestalNTuple[5]=out_ped_strip.noise;
00390 PedestalNTuple[6]=(nStrip/128)+1;
00391 PedestalNTuple[7]=id_wafer;
00392 PedestalNTuple[8]=nStrip+(iWaf-1)*768;
00393 pTuple->Fill(PedestalNTuple);
00394 }
00395 }
00396 else {
00397 ladderCountN[ladder]++;
00398 occupancy_wafer->Fill((2*iLad)+1,iWaf,1);
00399 occupancy_chip->Fill((2*iLad)+1,chip,1);
00400 noise_chip->Fill((2*iLad)+1,chip,(out_ped_strip.noise/(16.)));
00401 noise_wafer->Fill((2*iLad)+1,iWaf,(out_ped_strip.noise/(16.)));
00402 noise_chip_N->Fill(iLad,chip,(out_ped_strip.noise/(16.)));
00403 pedestal_chip->Fill((2*iLad)+1,chip,out_ped_strip.pedestal);
00404 if(pedestal==0)ped_zero_ladN->Fill(iLad,iWaf);
00405 if(pedestal==255)ped_high_ladN->Fill(iLad,iWaf);
00406 if(noise==0)noise_zero_ladN->Fill(iLad,iWaf);
00407 if(noise==255)noise_high_ladN->Fill(iLad,iWaf);
00408 if(mPedOut){
00409 PedestalNTuple[0]=1;
00410 PedestalNTuple[1]=iLad;
00411 PedestalNTuple[2]=iWaf;
00412 PedestalNTuple[3]=nStrip-1;
00413 PedestalNTuple[4]=out_ped_strip.pedestal;
00414 PedestalNTuple[5]=out_ped_strip.noise;
00415 PedestalNTuple[6]=(nStrip/128)+1;
00416 PedestalNTuple[7]=id_wafer;
00417 PedestalNTuple[8]=nStrip+(iWaf-1)*768;
00418 pTuple->Fill(PedestalNTuple);
00419 }
00420 }
00421 count++;
00422 for (int i=0;i<20;i++)
00423 {
00424 occupancy->SetFillColor(2);
00425 occupancy->Fill((2*i),(12288-ladderCountP[i]));
00426 occupancy->Fill((2*i)+1,(12288-ladderCountN[i]));
00427 }
00428
00429 }
00430 }
00431 }
00432 }
00433 }
00434 }
00435
00436
00437 LOG_DEBUG <<"Make()/Number of raw data in the SSD ";
00438 LOG_DEBUG << "Make()/Active Ladders: ";
00439 for (int i=0;i<mConfig->getTotalNumberOfLadders();i++){
00440 if (mConfig->getLadderIsActive(i+1)>0) {
00441 LOG_DEBUG.width(5);
00442 LOG_DEBUG <<i+1<<" ";
00443 } }
00444 LOG_DEBUG <<endm;
00445 LOG_DEBUG << "Make()/Counts (p-side): ";
00446 for (int i=0;i<mConfig->getTotalNumberOfLadders();i++){
00447 if (mConfig->getLadderIsActive(i+1)>0) {
00448 LOG_DEBUG.width(5);
00449 LOG_DEBUG <<ladderCountP[i]<<" ";
00450 } }
00451 LOG_DEBUG << endm;
00452 LOG_DEBUG << "Make()/Counts (n-side): ";
00453 for (int i=0;i<mConfig->getTotalNumberOfLadders();i++){
00454 if (mConfig->getLadderIsActive(i+1)>0) {
00455 LOG_DEBUG.width(5);
00456 LOG_DEBUG <<ladderCountN[i]<<" ";
00457 } }
00458 LOG_DEBUG<<endm;
00459 if((spa_strip->GetNRows()==0)&&(ssdPedStrip && ssdPedStrip->GetNRows()!=0)){
00460 LOG_INFO << "Make()/ Read Pedestal & Noise"<< endm;
00461 LOG_INFO << "Make()/ssdPedStrip->NRows= "<<ssdPedStrip->GetNRows()<<endm;
00462 }
00463 else
00464 if((! ssdPedStrip || ssdPedStrip->GetNRows()==0) && (spa_strip->GetNRows()!=0)){
00465 LOG_INFO << "Make()/ Read Signal from Physics Run"<< endm;
00466 LOG_INFO << "Make()/ spa_strip->NRows= "<<spa_strip->GetNRows()<<endm;
00467 }
00468 return kStOK;
00469 }
00470
00471
00472 Int_t StSsdDaqMaker::Finish()
00473 {
00474 LOG_INFO << Form("Finish()") << endm;
00475 if(mPedOut){
00476 LOG_INFO << "Write Pedestal tuple"<< endm;
00477 pFile->Write();
00478 pFile->Close();
00479 }
00480 return kStOK;
00481 }
00482
00483 void StSsdDaqMaker::PrintConfiguration(Int_t runumber,ssdConfiguration_st *config)
00484 {
00485 switch(runumber){
00486 case 4 : {
00487 LOG_INFO <<"Configuration of ladders for run IV" <<endm;
00488 break;
00489 }
00490 case 5 : {
00491 LOG_INFO <<"Configuration of ladders for run V" << endm;
00492 break;
00493 }
00494 case 6 : {
00495 LOG_INFO <<"Configuration of ladders for run VI"<< endm;
00496 break;
00497 }
00498 case 7 : {
00499 LOG_INFO <<"Configuration of ladders for run VII" << endm;
00500 break;
00501 }
00502 }
00503 Int_t i =0;
00504 Int_t totladderPresent =0;
00505 LOG_INFO << "PrintLadderSummary:ladder id :";
00506 for (i=1;i<=config->nMaxLadders;i++){
00507 LOG_INFO.width(3);
00508 LOG_INFO << i;
00509 }
00510 LOG_INFO <<endm;
00511 LOG_INFO << "PrintLadderSummary:Active Ladders on sectors: ";
00512 for (i=1;i<=config->nMaxLadders;i++){
00513 LOG_INFO.width(3);
00514 LOG_INFO <<mConfig->getLadderIsActive(i);
00515 if(mConfig->getLadderIsActive(i)>0)totladderPresent++;
00516
00517 }
00518 LOG_INFO << endm;
00519 LOG_INFO << "totLadderActive = "<<totladderPresent<<endm;
00520 }