1 #if !defined(__CINT__) || defined(__MAKECINT__)
3 #include <TAlienFile.h>
6 #include <TGridResult.h>
13 #include <TPluginManager.h>
17 #include <TGeoGlobalMagField.h>
19 #include "AliRawReader.h"
20 #include "AliRawReaderRoot.h"
21 #include "AliRawReaderDate.h"
22 #include "AliITSQADataMakerRec.h"
23 #include "AliITSQASDDDataMakerRec.h"
24 #include "AliITSQAChecker.h"
25 #include "AliQAChecker.h"
26 #include "AliITSQASDDChecker.h"
27 #include "AliReconstructor.h"
28 #include "AliCDBManager.h"
31 #include "AliGeomManager.h"
32 #include "AliITSInitGeometry.h"
33 #include "AliITSgeom.h"
34 #include "AliRecoParam.h"
35 #include "AliCDBPath.h"
36 #include "AliCDBEntry.h"
37 #include "AliRecoParam.h"
38 #include "AliDetectorRecoParam.h"
39 #include "AliITSReconstructor.h"
40 #include "AliITSRecPointContainer.h"
42 #include "AliGRPObject.h"
43 #include "AliRunInfo.h"
45 void ITSQArecoparam(char *iFile, Int_t runNb=150000, Int_t idet=2, Int_t FirstEvt=0, Int_t MaxEvts=1000000)
47 TString namefile(iFile);
48 if(namefile.Contains("alien"))
50 TGrid::Connect("alien://");
52 printf("gGrid not found! exit macro\n");
56 gStyle->SetPalette(1);
58 AliRawReader *rd=NULL;
59 if(strstr(iFile,".root")!=0){rd = new AliRawReaderRoot(iFile,FirstEvt);}
60 else{rd=new AliRawReaderDate(iFile,FirstEvt);}
61 //Int_t runNumber = rd->GetRunNumber();
62 cout << "ITS Quality Assurance Prototype for run "<< runNb << endl;
64 //TString namefile(iFile);
66 AliCDBManager* man = AliCDBManager::Instance();
67 if (!man->IsDefaultStorageSet()) {
68 printf("Setting a local default storage and run number \n");
69 // if(namefile.Contains("alien")){
70 man->SetDefaultStorage("alien://folder=/alice/data/2011/OCDB");
72 //else{man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");}
74 AliQAv1::SetQARefStorage("local://$ALICE_ROOT/QARef") ;
76 AliCDBManager::Instance()->GetAll(Form("ITS/Calib/*"));
79 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
81 AliGRPObject *fGRPData=NULL;
83 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
86 printf("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
88 fGRPData = new AliGRPObject();
89 fGRPData->ReadValuesFromMap(m);
93 printf("Found an AliGRPObject in GRP/GRP/Data, reading it");
94 fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
100 printf("Error No GRP entry found in OCDB!");
105 TString lhcState = fGRPData->GetLHCState();
106 if (lhcState==AliGRPObject::GetInvalidString()) {
107 printf("Error GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
108 lhcState = "UNKNOWN";
111 TString beamType = fGRPData->GetBeamType();
112 if (beamType==AliGRPObject::GetInvalidString()) {
113 printf("Error GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
114 beamType = "UNKNOWN";
117 Float_t beamEnergy = fGRPData->GetBeamEnergy();
118 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
119 printf("Error GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
123 TString runType = fGRPData->GetRunType();
124 if (runType==AliGRPObject::GetInvalidString()) {
125 printf("Error GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
129 Int_t activeDetectors = fGRPData->GetDetectorMask();
130 if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
131 printf("Error GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
132 activeDetectors = 1074790399;
135 AliRunInfo *fRunInfo = new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
138 if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
139 if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
140 printf("ExpertMode!!! GRP information will be ignored !");
141 printf("ExpertMode!!! Running with the externally locked B field !");
144 printf("Destroying existing B field instance!");
145 delete TGeoGlobalMagField::Instance();
148 if ( !TGeoGlobalMagField::Instance()->IsLocked() ) {
149 // Construct the field map out of the information retrieved from GRP.
152 Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
153 if (l3Current == AliGRPObject::GetInvalidFloat()) {
154 printf("Error : GRP/GRP/Data entry: missing value for the L3 current !");
158 Char_t l3Polarity = fGRPData->GetL3Polarity();
159 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
160 printf("Error: GRP/GRP/Data entry: missing value for the L3 polarity !");
165 Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
166 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
167 printf("Error GRP/GRP/Data entry: missing value for the dipole current !");
171 Char_t diPolarity = fGRPData->GetDipolePolarity();
172 if (diPolarity == AliGRPObject::GetInvalidChar()) {
173 printf("Error GRP/GRP/Data entry: missing value for the dipole polarity !");
178 Int_t polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
179 Bool_t uniformB = fGRPData->IsUniformBMap();
182 AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1),
183 TMath::Abs(diCurrent) * (diPolarity ? -1:1),
184 polConvention,uniformB,beamEnergy, beamType.Data());
186 TGeoGlobalMagField::Instance()->SetField( fld );
187 TGeoGlobalMagField::Instance()->Lock();
188 printf("Running with the B field constructed out of GRP !");
190 else printf("Fatal Failed to create a B field map !");
192 else printf("Fatal B field is neither set nor constructed from GRP ! Exitig...");
198 AliITSQADataMakerRec *itsQAdm = new AliITSQADataMakerRec(kTRUE,idet,0); //online kTRUE
199 itsQAdm->SetWriteExpert() ;
200 itsQAdm->SetRunNumber(runNb);
201 //________________________For the RecPoints____________________________________
202 /************************************************/
203 TPluginManager* pluginManager=NULL;
204 TPluginHandler* pluginHandler=NULL;
205 AliReconstructor* reconstructor = NULL;
206 AliITSRecPointContainer* rpcont=NULL;
207 AliGeomManager::LoadGeometry("geometry.root");
208 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
209 // ITS initializations
211 AliITSInitGeometry initgeom;
212 AliITSgeom *geom = initgeom.CreateAliITSgeom();
213 printf("Geometry name: %s\n",(initgeom.GetGeometryName()).Data());
215 printf("Loading reconstruction parameter objects for detector ITS\n");
216 AliRecoParam fRecoParam;
217 AliCDBPath path("ITS","Calib","RecoParam");
218 AliCDBEntry *entry2=AliCDBManager::Instance()->Get(path.GetPath());
219 Bool_t cacheStatus = AliCDBManager::Instance()->GetCacheFlag();
220 if(!entry2){printf("Couldn't find RecoParam entry in OCDB for detector ITS");entry2=NULL;}
222 TObject *recoParamObj = entry2->GetObject();
223 if (dynamic_cast<TObjArray*>(recoParamObj)) {
224 printf("RecoParam TObjArray\n");
225 fRecoParam.AddDetRecoParamArray(0,dynamic_cast<TObjArray*>(recoParamObj));
227 else if (dynamic_cast<AliDetectorRecoParam*>(recoParamObj)) {
228 printf("RecoParam AliDetectorRecoParam\n");
229 printf("Single set of reconstruction parameters found for detector ITS");
230 (dynamic_cast<AliDetectorRecoParam*>(recoParamObj))->SetAsDefault();
231 fRecoParam.AddDetRecoParam(0,(dynamic_cast<AliDetectorRecoParam*>(recoParamObj)));
233 else {printf("Error: No valid RecoParam object found in the OCDB for detector ITS");}
236 if(!cacheStatus)entry2->SetObject(NULL);
237 if(!cacheStatus){ delete entry2;}
239 // load the reconstructor object
240 pluginManager = gROOT->GetPluginManager();
241 TString detName = "ITS";
242 TString recName = "Ali" + detName + "Reconstructor";
244 pluginHandler = pluginManager->FindHandler("AliReconstructor", "ITS");
245 // if not, add a plugin for it
246 if (!pluginHandler) {
247 printf("defining plugin for ITS\n");
248 TString libs = gSystem->GetLibraries();
249 if (libs.Contains("lib" + detName + "base.so") ||
250 (gSystem->Load("lib" + detName + "base.so") >= 0)) {pluginManager->AddHandler("AliReconstructor", detName,recName, detName + "rec", recName + "()");}
251 else {pluginManager->AddHandler("AliReconstructor", detName,recName, detName, recName + "()");}
252 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
254 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);}
255 if (fRecoParam.GetDetRecoParamArray(0) && !AliReconstructor::GetRecoParam(0)) {
256 const AliDetectorRecoParam *par = fRecoParam.GetDetRecoParam(0);
257 reconstructor->Init();
258 reconstructor->SetRecoParam(par);
261 /*AliITSRecPointContainer**/ rpcont=AliITSRecPointContainer::Instance();
262 rpcont->PrepareToRead();
264 Int_t cycleLength = 5;
265 //cout << "Processing Run " << runNumber << endl;
266 cout << "Init: " << AliQAv1::kRAWS << endl;
268 TObjArray **objArray= itsQAdm->Init(AliQAv1::kRAWS, cycleLength);
269 cout<<"raw tobjarray :"<<objArray<<"\n"<<endl;
270 for(Int_t spec = 0 ; spec < 5 ; spec++){
272 itsQAdm->SetEventSpecie(AliRecoParam::kCosmic);
273 AliQAv1::Instance()->SetEventSpecie(AliRecoParam::kCosmic);
278 itsQAdm->StartOfCycle(AliQAv1::kRAWS,runNb,kFALSE);
279 /*********************************************************************/
281 cout << "Init: " << AliQAv1::kRECPOINTS << endl;
282 TObjArray **objArray1= itsQAdm->Init(AliQAv1::kRECPOINTS, cycleLength);
283 cout<<"recpoint tobjarray :"<<objArray1<<"\n"<<endl;
284 for(Int_t spec = 0 ; spec < 5 ; spec++){
286 itsQAdm->SetEventSpecie(AliRecoParam::kCosmic);
287 AliQAv1::Instance()->SetEventSpecie(AliRecoParam::kCosmic);
288 itsQAdm->InitRecPoints();
292 itsQAdm->StartOfCycle(AliQAv1::kRECPOINTS,runNb,kTRUE);
294 /*********************************************************************/
296 while(rd->NextEvent() && iev < MaxEvts ) {
297 cout<<">>>>>>> Processing event number: "<<++iev<<endl;
298 /*******************************************************/
299 if(itsQAdm->IsCycleDone()) {
300 cout << "end of cycle" << endl;
301 AliQAChecker::Instance()->SetRunNumber(AliCDBManager::Instance()->GetRun());
302 itsQAdm->EndOfCycle(AliQAv1::kRAWS);
303 itsQAdm->StartOfCycle(AliQAv1::kRAWS,ic++,kFALSE);
305 /******************************************************/
306 /*************************************************/
308 if(itsQAdm->IsCycleDone()) {
309 cout << "end of cycle" << endl;
310 AliQAChecker::Instance()->SetRunNumber(AliCDBManager::Instance()->GetRun());
311 itsQAdm->EndOfCycle(AliQAv1::kRECPOINTS);
312 itsQAdm->StartOfCycle(AliQAv1::kRECPOINTS,ic,kTRUE);
315 /*************************************************/
316 cout<<"Beginning Exec"<<endl;
317 cout<<"AliQAv1::kRAWS "<<AliQAv1::kRAWS<<endl;
318 itsQAdm->SetEventSpecie(AliRecoParam::kCosmic);
319 AliQAv1::Instance()->SetEventSpecie(AliRecoParam::kCosmic);
320 itsQAdm->Exec(AliQAv1::kRAWS,rd);
321 /***************************************************/
323 cout<<"AliQAv1::kRECPOINTS "<<AliQAv1::kRECPOINTS<<endl;
324 cout << "DigitsToRecPoints" << endl;
325 TTree* fTreeR = new TTree("TreeR", "Reconstructed Points Container"); //make a tree
328 if(idet==0)sprintf(option,"ALL");
329 else if(idet==1)sprintf(option,"SPD");
330 else if(idet==2)sprintf(option,"SDD");
331 else if(idet==3)sprintf(option,"SSD");
332 printf("\t\t===========>option is %s\n",option);
334 rpcont->PrepareToRead();
335 reconstructor->Reconstruct(rd,fTreeR);
337 itsQAdm->SetEventSpecie(AliRecoParam::kCosmic);
338 AliQAv1::Instance()->SetEventSpecie(AliRecoParam::kCosmic) ;
339 itsQAdm->Exec(AliQAv1::kRECPOINTS,fTreeR);
340 cout<<"Finishing Exec"<<endl;
342 ((AliITSReconstructor*)reconstructor)->ResetRecPoints();
345 /*****************************************************/
348 cout << "end RAWS cycle: " << AliQAv1::kRAWS << endl;
349 cout << "refStorage: " << AliQAv1::GetQARefStorage() << endl;
350 cout << "end of cycle 2" << endl;
351 AliQAChecker::Instance()->SetRunNumber(AliCDBManager::Instance()->GetRun());
352 itsQAdm->EndOfCycle(AliQAv1::kRAWS);
353 cout << "Raws QA completed for " << iev << " events" << endl;
354 /*******************************************************************/
356 AliQAChecker::Instance()->SetRunNumber(AliCDBManager::Instance()->GetRun());
357 itsQAdm->EndOfCycle(AliQAv1::kRECPOINTS);
358 cout << "RecPoints QA completed for " << iev << " events" << endl;
360 /*******************************************************************/
361 itsQAdm->Finish(); // write to the output File
363 cout << "Call AliITSQASDDDataMakerRec destructor" << endl;
369 void ITSQArecoparam(Int_t runNb=150000,Int_t year=2011,Char_t period[10]="LHC11a",Int_t idet=2,Int_t FirstEvt=0, Int_t MaxEvts=1000000)
371 //TString namefile(iFile);
372 //if(namefile.Contains("alien"))
374 TGrid::Connect("alien://");
376 printf("gGrid not found! exit macro\n");
381 gSystem->AddIncludePath("-I. -I$ALICE_ROOT/include");
385 sprintf(path2,"/alice/data/");
386 printf("path %s\n",path2);
387 char rawfilename[200];
388 sprintf(rawfilename,"%04i/%s/%09i/raw/%02i%09i*.*.root",year,period,runNb,year-2000,runNb);
393 TGridResult *gr = gGrid->Query(path2,rawfilename);
394 if (gr->GetEntries() < 1) {
395 printf("In this run there are not raws files: Exit macro\n");
398 //if(gr->GetEntries() > 10) number=3;
400 Bool_t chunkok=kFALSE;
401 TString filenamedef; //= gr->GetKey(number,"turl");
402 //printf("-> FILE %s \n",filename);
403 while(chunkok==kFALSE || number<gr->GetEntries())
405 const char* filename = gr->GetKey(number,"turl");
406 printf("-> FILE %s \n",filename);
407 TString namefile(filename);
408 if(namefile.Contains(".10.root")==kFALSE){chunkok=kTRUE; filenamedef.Form("%s",filename); break;}
413 if(number==gr->GetEntries()-1) {chunkok=kTRUE; filenamedef.Form("%s",filename); break;}
416 char *filetouse=(char*)filenamedef.Data();//=filenamedef.Data(); //=NULL;
417 //sprintf(filetouse,"%s",(char*)filenamedef.Data());
419 printf("File to use = %s\n\n",filetouse);
423 printf("Run: %d \n",runn);
425 ITSQArecoparam(filetouse,runn,idet,FirstEvt,MaxEvts);