Pedestals in OCDB + minors
[u/mrichter/AliRoot.git] / HMPID / Hshuttle.C
1 void Hshuttle(Int_t runTime=1500)
2 {
3 // this macro is to simulate the functionality of SHUTTLE.
4 // Here the list of DCS aliases is created and packed in TMap of structure "alias name" - TObjArray of AliDCSValue; AliDCSValue is a pair value-time stamp     
5 // currently simulated: freon temperature 2 per radiator (inlet,outlet)
6 //                      methane pressure 1 per chamber   
7   gSystem->Load("libTestShuttle.so");
8   
9   AliTestShuttle::SetMainCDB(TString("local://$HOME"));
10   
11   TMap        *pDcsMap = new TMap;       pDcsMap->SetOwner(1);          //DCS archive map
12
13   SimPed();
14   SimMap(pDcsMap,runTime);
15   TestShuttle(pDcsMap);  
16   TCanvas *c=new TCanvas("cc","ff",600,600);  
17   DrawInput(c,pDcsMap);
18   DrawOutput();
19 }//Hshuttle()
20 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 void SimPed()
22 {
23   ofstream out;
24   for(Int_t ddl=0;ddl<=13;ddl++){
25     out.open(Form("ped_%02i.txt",ddl));
26     out << 3 <<endl;
27     for(Int_t row=1;row<=24;row++)
28       for(Int_t dil=1;dil<=10;dil++)
29         for(Int_t adr=0;adr<=47;adr++){
30           Float_t mean  = 150+200*gRandom->Rndm();
31           Float_t sigma = 1+0.2*gRandom->Rndm();
32           Int_t inhard=((Int_t(mean))<<9)+Int_t(mean+3*sigma);
33           out << Form("%2i %2i %2i %2i %5.2f %5.2f %x\n",ddl,row,dil,adr,mean,sigma,inhard);
34         }
35
36     Printf("file ped %02i created",ddl);
37     out.close();
38   }
39 }
40 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 void SimMap(TMap *pDcsMap,Int_t runTime=1500)
42 {
43   Int_t stepTime=100; //time interval between mesuraments
44   Int_t startTime=0;
45   
46   
47   for(Int_t iCh=0;iCh<7;iCh++){//chambers loop
48     TObjArray *pP=new TObjArray;  pP->SetOwner(1);
49     TObjArray *pHV=new TObjArray; pHV->SetOwner(1); 
50     for(Int_t time=0;time<runTime;time+=stepTime)  pP->Add(new AliDCSValue((Float_t)1005.0 ,time));   //sample CH4 pressure [mBar]
51                                                    pHV->Add(new AliDCSValue((Float_t)2010.0,time));   //sample chamber HV [V]
52     pDcsMap->Add(new TObjString(Form(AliHMPIDPreprocessor::GetP(),iCh,iCh,iCh)),pP); 
53     pDcsMap->Add(new TObjString(Form(AliHMPIDPreprocessor::GetHV(),iCh,iCh,iCh)),pHV); 
54         
55     for(Int_t iRad=0;iRad<3;iRad++){//radiators loop
56       TObjArray *pT1=new TObjArray; pT1->SetOwner(1); 
57       TObjArray *pT2=new TObjArray; pT2->SetOwner(1); 
58       for (Int_t time=0;time<runTime;time+=stepTime)  pT1->Add(new AliDCSValue(13,time));  //sample inlet temperature    Nmean=1.292 @ 13 degrees
59       for (Int_t time=0;time<runTime;time+=stepTime)  pT2->Add(new AliDCSValue(13,time));  //sample outlet temperature
60       pDcsMap->Add(new TObjString(Form(AliHMPIDPreprocessor::GetT1(),iCh,iCh,iRad)) ,pT1); 
61       pDcsMap->Add(new TObjString(Form(AliHMPIDPreprocessor::GetT2(),iCh,iCh,iRad)),pT2);
62     }//radiators loop    
63   }//chambers loop
64 }//SimMap()
65 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66 void TestShuttle(TMap *pDcsMap)
67 {
68   AliTestShuttle* pShuttle = new AliTestShuttle(0,0,1000000);   
69   pShuttle->SetDCSInput(pDcsMap);                                                    //DCS map
70   for(Int_t ddl=0;ddl<=13;ddl++) pShuttle->AddInputFile(AliTestShuttle::kDAQ,"HMP","pedestals",Form("DDL%i",ddl),Form("./ped_%02i.txt",ddl));
71   AliPreprocessor* pp = new AliHMPIDPreprocessor(pShuttle);                           //actual preprocessor is created here
72   pShuttle->Process();                                                               //run SHUTTLE simulator
73   delete pp;
74 }
75 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
76 void DrawInput(TCanvas *c,TMap *pDcsMap)
77 {
78   c->Divide(3,3);
79   
80   AliDCSValue *pVal; Int_t cnt=0;
81   
82   for(Int_t iCh=0;iCh<7;iCh++){//chambers loop
83     if(iCh==6) c->cd(1);  if(iCh==5) c->cd(2);                          
84     if(iCh==4) c->cd(4);  if(iCh==3) c->cd(5);  if(iCh==2) c->cd(6);
85                           if(iCh==1) c->cd(8);  if(iCh==0) c->cd(9); 
86                           
87     TObjArray *pHV=(TObjArray*)pDcsMap->GetValue(Form(AliHMPIDPreprocessor::GetHV(),iCh,iCh,iCh,iCh)); //HV
88     TObjArray *pP =(TObjArray*)pDcsMap->GetValue(Form(AliHMPIDPreprocessor::GetP(),iCh,iCh,iCh)); //P
89     TGraph *pGr=new TGraph; pGr->SetMarkerStyle(5);
90     
91     TIter nextp(pP); cnt=0; while((pVal=(AliDCSValue*)nextp())){ pGr->SetPoint(cnt++,pVal->GetTimeStamp(),pVal->GetFloat());}//P
92
93     
94     pGr->Draw("AP");
95   }  
96 }
97 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
98 void DrawOutput()
99 {
100   AliCDBManager::Instance()->SetDefaultStorage("local://$HOME");
101   AliCDBEntry *pQthreEnt =AliCDBManager::Instance()->Get("HMPID/Calib/Qthre",0);
102   AliCDBEntry *pNmeanEnt =AliCDBManager::Instance()->Get("HMPID/Calib/Nmean",0);
103   AliCDBEntry *pSigCutEnt=AliCDBManager::Instance()->Get("HMPID/Calib/SigCut",0);
104   AliCDBEntry *pDaqSigEnt=AliCDBManager::Instance()->Get("HMPID/Calib/DaqSig",0);
105   
106   if(!pQthreEnt || ! pNmeanEnt || !pSigCutEnt || !pDaqSigEnt) return;
107   
108   TObjArray *pNmean =(TObjArray*)pNmeanEnt ->GetObject(); 
109   TObjArray *pQthre =(TObjArray*)pQthreEnt ->GetObject(); 
110   TObjArray *pSigCut=(TObjArray*)pSigCutEnt->GetObject(); 
111   TObjArray *pDaqSig=(TObjArray*)pDaqSigEnt->GetObject();
112    
113   TF1 *pRad0,*pRad1,*pRad2;  
114   TCanvas *c2=new TCanvas("c2","Nmean"); c2->Divide(3,3);
115   
116   
117   for(Int_t iCh=0;iCh<7;iCh++){//chambers loop
118     if(iCh==6) c2->cd(1);  if(iCh==5) c2->cd(2);                          
119     if(iCh==4) c2->cd(4);  if(iCh==3) c2->cd(5);  if(iCh==2) c2->cd(6);
120                            if(iCh==1) c2->cd(8);  if(iCh==0) c2->cd(9); 
121                           
122     TF1 *pRad0=(TF1*)pNmean->At(iCh*3+0); pRad0->Draw();  pRad0->GetXaxis()->SetTimeDisplay(kTRUE); pRad0->GetYaxis()->SetRangeUser(1.28,1.3);
123     TF1 *pRad1=(TF1*)pNmean->At(iCh*3+1); pRad1->Draw("same");
124     TF1 *pRad2=(TF1*)pNmean->At(iCh*3+2); pRad2->Draw("same");
125   }//chambers loop  
126 }