/[PAMELA software]/PamelaLevel2/src/PamLevel2.cpp
ViewVC logotype

Diff of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by pam-fi, Thu Jan 18 08:51:16 2007 UTC revision 1.26 by pam-fi, Fri Mar 16 20:27:55 2007 UTC
# Line 100  PamLevel2::PamLevel2(){ Line 100  PamLevel2::PamLevel2(){
100  //     nd_obj    = NDLevel2::GetNDLevel2();  //     nd_obj    = NDLevel2::GetNDLevel2();
101  //     ac_obj    = AcLevel2::GetAcLevel2();  //     ac_obj    = AcLevel2::GetAcLevel2();
102  //     orb_obj   = OrbitalInfo::GetOrbitalInfo();  //     orb_obj   = OrbitalInfo::GetOrbitalInfo();
103        
104        h0_obj    = 0;
105        trk0_obj  = 0;
106    
107      trk2_obj  = 0;      trk2_obj  = 0;
108      trk1_obj  = 0;      trk1_obj  = 0;
109      trkh_obj  = 0;      trkh_obj  = 0;
# Line 118  PamLevel2::PamLevel2(){ Line 122  PamLevel2::PamLevel2(){
122      runfirstentry = 0ULL;      runfirstentry = 0ULL;
123      runlastentry = 0ULL;      runlastentry = 0ULL;
124    
125      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      l0_file = NULL;
126        l0_tree = NULL;
127        iroot   = -1;
128        dbc     = 0;
129        
130        irun = -1;
131        run_tree = NULL;
132        run_tree_clone = NULL;
133        sel_tree = NULL;
134        sel_tree_clone = NULL;
135        
136        irunentry = -1;
137        pam_tree = NULL;
138        for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
139    
140        host = "mysql://localhost/pamelaprod";
141        user = "anonymous";
142        psw = "";
143        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
144        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
145        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
146        if ( !pamdbhost ) pamdbhost = "";
147        if ( !pamdbuser ) pamdbuser = "";
148        if ( !pamdbpsw ) pamdbpsw = "";
149        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
150        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
151        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
152    
153        
154    
155  //    sorted_tracks = 0;//new TRefArray();  //    sorted_tracks = 0;//new TRefArray();
156            
157        CAL0 = false;
158      CAL1 = true;      CAL1 = true;
159      CAL2 = true;      CAL2 = true;
160      TRK2 = true;      TRK2 = true;
161      TRK1 = false;      TRK1 = false;
162      TRKh = false;      TRKh = false;
163      TRG = true;      TRKh = false;
164      TOF = true;      TRG  = true;
165      S4  = true;      TOF  = true;
166      ND  = true;      TOF0 = false;
167      AC  = true;      S4   = true;
168      ORB = true;      ND   = true;
169        AC   = true;
170        ORB  = true;
171            
172      RUN = true;      RUN  = true;
173    
174        SELLI = -1;
175    
176      tsorted=0;      tsorted=0;
177      timage=0;      timage=0;
# Line 149  void PamLevel2::Delete(){ Line 186  void PamLevel2::Delete(){
186      if(soft_obj)delete soft_obj; //Emiliano      if(soft_obj)delete soft_obj; //Emiliano
187    
188  //    cout << "void PamLevel2::Clear()"<<endl;  //    cout << "void PamLevel2::Clear()"<<endl;
189        if(h0_obj)   delete h0_obj;
190        if(trk0_obj) delete trk0_obj;      
191      if(trk1_obj) delete trk1_obj;            if(trk1_obj) delete trk1_obj;      
192      if(trk2_obj) delete trk2_obj;      if(trk2_obj) delete trk2_obj;
193      if(trkh_obj) delete trkh_obj;      if(trkh_obj) delete trkh_obj;
# Line 169  void PamLevel2::Delete(){ Line 208  void PamLevel2::Delete(){
208          timage->Delete();          timage->Delete();
209          delete timage;          delete timage;
210      }      }
211    
212        if(dbc){
213            dbc->Close();
214            delete dbc;
215        }
216        
217        if(l0_file)l0_file->Close();
218        if(pam_tree)pam_tree->Delete();;
219        if(run_tree)run_tree->Delete();;
220        if(sel_tree)sel_tree->Delete();;
221        for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
222        if(run_tree_clone)run_tree_clone->Delete();;
223        if(sel_tree_clone)sel_tree_clone->Delete();;
224        
225    
226  };  };
227    
228  /**  /**
# Line 186  void PamLevel2::Clear(){ Line 240  void PamLevel2::Clear(){
240  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
241  //    if(soft_obj) soft_obj->Clear();  //    if(soft_obj) soft_obj->Clear();
242    
243        if(h0_obj)   h0_obj->Clear();      
244        if(trk0_obj) trk0_obj->Clear();    
245      if(trk1_obj) trk1_obj->Clear();          if(trk1_obj) trk1_obj->Clear();    
246      if(trk2_obj) trk2_obj->Clear();      if(trk2_obj) trk2_obj->Clear();
247      if(trkh_obj) trkh_obj->Clear();      if(trkh_obj) trkh_obj->Clear();
# Line 498  void PamLevel2::SortTracks(TString how){ Line 554  void PamLevel2::SortTracks(TString how){
554                  use_CAL            &&                  use_CAL            &&
555                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view                  calo2_obj->npcfit[1] > 15     &&   //no. of fit planes on Y view
556                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view                  calo2_obj->varcfit[1] < 1000. &&  //fit variance on Y view
557                    cp && ci &&
558                  true){                  true){
559    
560                                    
# Line 519  void PamLevel2::SortTracks(TString how){ Line 576  void PamLevel2::SortTracks(TString how){
576                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";                  cout << "void PamLevel2::SortTracks(TString how): how= "<<how<<" but ToFLevel2 not loaded !!!";
577                  return;                  return;
578              };              };
579              if( use_TOF ){              if( use_TOF && op && oi ){
580                                    
581                  Int_t nphit_p =0;                  Int_t nphit_p =0;
582                  Int_t nphit_i =0;                  Int_t nphit_i =0;
# Line 775  TTree *PamLevel2::GetPamTree(TFile *f, T Line 832  TTree *PamLevel2::GetPamTree(TFile *f, T
832    
833  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);
834  //     else                    GetWhichTrees(f);  //     else                    GetWhichTrees(f);
835        
836        cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
837    
838      SetWhichTrees(detlist);      SetWhichTrees(detlist);
839    
840      TTree *Trout =0;      TTree *Trout =0;
# Line 782  TTree *PamLevel2::GetPamTree(TFile *f, T Line 842  TTree *PamLevel2::GetPamTree(TFile *f, T
842      TString fname = f->GetName();      TString fname = f->GetName();
843      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
844    
845      UInt_t *found=0;      //    UInt_t *found=0;    
846    
847      cout<< "GetPamTree(TFile*,TString): detector list --> ";      cout<< "GetPamTree(TFile*,TString): detector list --> ";
848      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
# Line 797  TTree *PamLevel2::GetPamTree(TFile *f, T Line 857  TTree *PamLevel2::GetPamTree(TFile *f, T
857      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
858      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
859      cout << endl;      cout << endl;
860        if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
861    
862      f->cd();      f->cd();
863    
# Line 804  TTree *PamLevel2::GetPamTree(TFile *f, T Line 865  TTree *PamLevel2::GetPamTree(TFile *f, T
865      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
866      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
867          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
868          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
869          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
870          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
871          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
872          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
873          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
874          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
875          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
876          if(!Trout)Trout=T;          if(!Trout)Trout=T;
877          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 821  TTree *PamLevel2::GetPamTree(TFile *f, T Line 882  TTree *PamLevel2::GetPamTree(TFile *f, T
882      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
883      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
884          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
885          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
886          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
887          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
888          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
889          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
890          if(!Trout)Trout=C;          if(!Trout)Trout=C;
891          else Trout->AddFriend(C);          else Trout->AddFriend(C);
# Line 892  TTree *PamLevel2::GetPamTree(TFile *f, T Line 953  TTree *PamLevel2::GetPamTree(TFile *f, T
953      }else{      }else{
954          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
955      };      };
956    
957        TTree *L = (TTree*)f->Get("SelectionList");
958        if(L && SELLI==1) {
959    //      L->SetBranchAddress("RunEntry",&irun);
960    //      cout << "SelectionList: set branch address RunEntry"<<endl;
961    //      L->SetBranchAddress("EventEntry",&irunentry);
962    //      cout << "SelectionList: set branch address EventEntry"<<endl;
963    //      if(!Trout)Trout=O;
964    //      else Trout->AddFriend("SelectionList");
965            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
966            sel_tree = 0;
967        }else{
968            cout << "SelectionList  : missing tree"<<endl;
969        };
970            
971      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
972            
# Line 963  TList*  PamLevel2::GetListOfLevel2Files( Line 1038  TList*  PamLevel2::GetListOfLevel2Files(
1038  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1039  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1040  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1041              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file));              if( file.EndsWith(".root") ){
1042              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file));
1043              delete fullpath;                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1044                    delete fullpath;
1045                }
1046  //          }else{  //          }else{
1047  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1048  //          };  //          };
# Line 1049  TChain *PamLevel2::GetPamTree(TList *fl, Line 1126  TChain *PamLevel2::GetPamTree(TList *fl,
1126      TChain *N = 0;      TChain *N = 0;
1127      TChain *A = 0;      TChain *A = 0;
1128      TChain *B = 0;      TChain *B = 0;
1129    
1130        TChain *L = 0;
1131            
1132      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1133      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1058  TChain *PamLevel2::GetPamTree(TList *fl, Line 1137  TChain *PamLevel2::GetPamTree(TList *fl,
1137      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1138      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1139      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1140    
1141         L = new TChain("SelectionList");
1142            
1143      // loop over files and create chains              // loop over files and create chains        
1144      TIter next(fl);      TIter next(fl);
# Line 1074  TChain *PamLevel2::GetPamTree(TList *fl, Line 1155  TChain *PamLevel2::GetPamTree(TList *fl,
1155              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1156              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1157              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1158                if(SELLI==1)         L->Add(name);
1159          };          };
1160      }      }
1161            
1162      cout << "done chain \n";      cout << "done chain \n";
1163    
1164      UInt_t *found=0;  //    UInt_t *found=0;
1165  // Tracker  // Tracker
1166      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1167          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1168          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1169          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1170          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1171          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1172          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1173          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1174          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1175          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1176          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1177          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
# Line 1099  TChain *PamLevel2::GetPamTree(TList *fl, Line 1181  TChain *PamLevel2::GetPamTree(TList *fl,
1181      // Calorimeter      // Calorimeter
1182      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1183          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1184          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1185          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1186          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1187          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1188          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1189          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1190          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
# Line 1163  TChain *PamLevel2::GetPamTree(TList *fl, Line 1245  TChain *PamLevel2::GetPamTree(TList *fl,
1245      }else{      }else{
1246          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1247      };      };
1248    
1249        // Selection List
1250        if(L && SELLI==1) {
1251            cout<<">>> Found selection-list <<<"<<endl;
1252            L->SetBranchAddress("RunEntry",&irun);
1253            cout << "SelectionList: set branch address RunEntry"<<endl;
1254            L->SetBranchAddress("EventEntry",&irunentry);
1255            cout << "SelectionList: set branch address EventEntry"<<endl;
1256            sel_tree = L;
1257    //      if(!Trout)Trout=O;
1258    //      else Trout->AddFriend("SelectionList");
1259        }else{
1260    //      cout << "SelectionList  : missing tree"<<endl;
1261            if(L)L->Delete();
1262        };
1263            
1264  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1265    
1266            pam_tree = Trout;
1267  //     // Tracker  
 //     if(TRK2||TRK1||TRKh){  
 //      if(!Tout)Tout=T;  
 //      else Tout->AddFriend("Tracker");  
 //     }  
 //     // Calorimeter  
 //     if(CAL2||CAL1) {          
 //      if(!Tout)Tout=C;  
 //      else Tout->AddFriend("Calorimeter");  
 //     };  
 //     // ToF      
 //     if(TOF) {  
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo");  
 //     };  
       
 //    cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;  
       
 //    if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );  
       
1268      return Trout;      return Trout;
1269  }  }
1270    
# Line 1293  void PamLevel2::SetBranchAddress(TTree * Line 1346  void PamLevel2::SetBranchAddress(TTree *
1346          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1347          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1348      };      };
1349        // SelectionList
1350        if(SELLI==1) {
1351            t->SetBranchAddress("RunEntry", &irun);
1352            cout << "SelectionList: set branch address RunEntry"<<endl;
1353            t->SetBranchAddress("EventEntry", &irunentry);
1354            cout << "SelectionList: set branch address EventEntry"<<endl;
1355        };
1356            
1357  }  }
1358  /**  /**
# Line 1366  void PamLevel2::SetBranchAddress(TChain Line 1426  void PamLevel2::SetBranchAddress(TChain
1426          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1427          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1428      };      };
1429        // SelectionList
1430        if(SELLI==1) {
1431            t->SetBranchAddress("RunEntry", &irun);
1432            cout << "SelectionList: set branch address RunEntry"<<endl;
1433            t->SetBranchAddress("EventEntry", &irunentry);
1434            cout << "SelectionList: set branch address EventEntry"<<endl;
1435        };
1436            
1437  }  }
1438    
# Line 1393  TChain *PamLevel2::GetRunTree(TList *fl) Line 1460  TChain *PamLevel2::GetRunTree(TList *fl)
1460              R->Add(name);              R->Add(name);
1461          };          };
1462      }      }
1463    
1464        if(R->GetNtrees()){
1465            
1466      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1467      cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
1468      R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1469      cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1470            }else{
1471            delete R;
1472            R=0;
1473        }
1474    
1475        run_tree = R;
1476    
1477      return R;      return R;
1478            
1479  }  }
# Line 1413  TChain *PamLevel2::GetRunTree(TList *fl) Line 1488  TChain *PamLevel2::GetRunTree(TList *fl)
1488   */   */
1489  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
1490    
1491        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1492    
1493      TTree *R = (TTree*)f->Get("Run");      TTree *R = (TTree*)f->Get("Run");
1494            
1495      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      if(R){
1496      cout << "Run         : set branch address RunInfo"<<endl;          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1497      R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          cout << "Run         : set branch address RunInfo"<<endl;
1498      cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1499                cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1500        }
1501      return R;      return R;
1502            
1503  }  }
# Line 1435  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 1512  Bool_t PamLevel2::UpdateRunInfo(TChain *
1512    //    //
1513    if ( run->GetEntries() <= 0 ) return(false);    if ( run->GetEntries() <= 0 ) return(false);
1514    //    //
1515      
1516    Int_t oldrun = irun;    Int_t oldrun = irun;
1517    if ( irun < 0 ){    // --------------------------------------
1518      irun = 0;    // if it is a full file (not preselected)
1519      run->GetEntry(0);    // --------------------------------------
1520      runfirstentry = 0ULL;    if(SELLI==0){
1521      runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;        if ( irun < 0 ){
1522    };            irun = 0;
1523    while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){            run->GetEntry(irun);
1524      //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));            runfirstentry = 0ULL;
1525      irun++;            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;
1526      run->GetEntry(irun);            return(true);
1527      runfirstentry = runlastentry+1ULL;        };      
1528      runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);  
1529          if( !GetOrbitalInfo() ){
1530              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1531              return(false);
1532          }
1533          // modificato il controllo sull'aggiornamento del run, per evitare problemi
1534          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
1535          while ( GetOrbitalInfo()->absTime > GetRunInfo()->RUNTRAILER_TIME && irun < run->GetEntries() ){
1536    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1537              //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1538              irun++;
1539              run->GetEntry(irun);
1540              runfirstentry = runlastentry+1ULL;
1541              runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1542          };
1543          
1544          //
1545          if
1546     ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1547          //
1548          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1549          //
1550          return(true);    
1551    };    };
1552    //    // ----------------------------------------------------
1553    if ( irun == oldrun || irun >= run->GetEntries() ) return(false);    // if it is a preselected file (there is SelectionList)
1554    //    // NBNB - the event tree MUST be read first
1555    //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);    // ----------------------------------------------------
1556    //    if(SELLI==1){      
1557    return(true);            sel_tree->GetEntry(iev);
1558          if(irun != oldrun){
1559              run->GetEntry(irun);
1560              return true;
1561          }
1562          return false;
1563      }
1564    
1565      return false;
1566    //    //
1567  };  };
1568  /**  /**
# Line 1477  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 1585  Bool_t PamLevel2::UpdateRunInfo(TTree *r
1585  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
1586                    
1587      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
1588            CAL0 = false;
1589          CAL1 = true;          CAL1 = true;
1590          CAL2 = true;          CAL2 = true;
1591          TRK2 = true;          TRK2 = true;
1592          TRK1 = false;          TRK1 = false;
1593          TRKh = false;          TRKh = false;
1594            TRK0 = false;
1595          TRG = true;          TRG = true;
1596          TOF = true;          TOF = true;
1597            TOF0 = false;
1598          S4  = true;          S4  = true;
1599          ND  = true;          ND  = true;
1600          AC  = true;          AC  = true;
1601          ORB = true;          ORB = true;
1602      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
1603            CAL0 = false;
1604          CAL1 = false;          CAL1 = false;
1605          CAL2 = false;          CAL2 = false;
1606          TRK2 = false;          TRK2 = false;
1607          TRK1 = false;          TRK1 = false;
1608          TRKh = false;          TRKh = false;
1609            TRK0 = false;
1610          TRG = false;          TRG = false;
1611          TOF = false;          TOF = false;
1612            TOF0 = false;
1613          S4  = false;          S4  = false;
1614          ND  = false;          ND  = false;
1615          AC  = false;          AC  = false;
# Line 1507  void PamLevel2::SetWhichTrees(TString de Line 1621  void PamLevel2::SetWhichTrees(TString de
1621          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1622          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1623      };      };
1624    
1625        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
1626            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
1627            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
1628        };
1629                    
1630      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1631          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1519  void PamLevel2::SetWhichTrees(TString de Line 1638  void PamLevel2::SetWhichTrees(TString de
1638          CAL1=false;          CAL1=false;
1639      }      }
1640  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
1641        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
1642            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
1643            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
1644        };
1645    
1646      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1647          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1648          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1547  void PamLevel2::SetWhichTrees(TString de Line 1671  void PamLevel2::SetWhichTrees(TString de
1671            
1672      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
1673      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
1674    
1675        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
1676        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
1677            
1678      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
1679      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
# Line 1581  void PamLevel2::SetWhichTrees(TString de Line 1708  void PamLevel2::SetWhichTrees(TString de
1708   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
1709   */   */
1710  void  PamLevel2::GetWhichTrees(TFile* f){  void  PamLevel2::GetWhichTrees(TFile* f){
1711                
1712    
1713    
1714        cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
1715      // -----------      // -----------
1716      // reset flags      // reset flags
1717      // -----------      // -----------
# Line 1753  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1883  Bool_t  PamLevel2::CheckLevel2File(TStri
1883            
1884      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
1885            
1886            Bool_t SELLI__ok  = false;
1887    
1888      cout << "Checking file: "<<name<<endl;      cout << "Checking file: "<<name<<endl;
1889      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
# Line 1770  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1900  Bool_t  PamLevel2::CheckLevel2File(TStri
1900    
1901      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
1902                    
1903    //      cout << key->GetName() << endl;
1904  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
1905  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
1906  //      nev_previous = nev;  //      nev_previous = nev;
# Line 1780  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1911  Bool_t  PamLevel2::CheckLevel2File(TStri
1911  //          return false;  //          return false;
1912  //      };  //      };
1913    
1914    
1915          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
1916    
1917          //=========================================================              //=========================================================    
1918            if( !strcmp(key->GetName(),"SelectionList"    ) ){
1919                SELLI__ok = true;
1920                if(SELLI==1){
1921                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
1922                    if( nev && nevt!=nev){
1923                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
1924                        return false;
1925                    }
1926                    nev=nevt;
1927                }
1928            }
1929    
1930            //=========================================================    
1931          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
1932              TRG__ok = true;              TRG__ok = true;
1933              if(TRG){              if(TRG){
# Line 1894  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2039  Bool_t  PamLevel2::CheckLevel2File(TStri
2039          };                };      
2040    
2041      };      };
2042    
2043        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
2044        if( SELLI==0 && SELLI__ok ){
2045            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
2046            return false;  
2047        }
2048        if( SELLI==1 && !SELLI__ok ){
2049            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
2050            return false;
2051        }
2052            
2053    //    cout << "SELLI "<<SELLI<<endl;
2054    
2055  //     cout<< "CheckLevel2File(TString): detector list --> ";  //     cout<< "CheckLevel2File(TString): detector list --> ";
2056  //     if(TRK1__ok)cout<<"TRK1 ";  //     if(TRK1__ok)cout<<"TRK1 ";
2057  //     if(TRK2__ok)cout<<"TRK2 ";  //     if(TRK2__ok)cout<<"TRK2 ";
# Line 2003  void PamLevel2::CreateCloneTrees0( TChai Line 2160  void PamLevel2::CreateCloneTrees0( TChai
2160      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
2161            
2162      Int_t i=0;      Int_t i=0;
2163      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
2164      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
2165      name.Append("_clone");      name.Append("_clone");
2166  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
2167      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
2168      i++;      i++;
2169    
2170      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
# Line 2017  void PamLevel2::CreateCloneTrees0( TChai Line 2174  void PamLevel2::CreateCloneTrees0( TChai
2174      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
2175  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2176  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
2177          tree_clone[i] = T_friend->GetTree()->CloneTree(0);          pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2178          tree_clone[i]->SetAutoSave(1000000);          pam_tree_clone[i]->SetAutoSave(1000000);
2179          name =  tree_clone[i]->GetName();          name =  pam_tree_clone[i]->GetName();
2180          name.Append("_clone");          name.Append("_clone");
2181  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
2182          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
2183          i++;          i++;
2184      }      }
2185            
# Line 2042  void PamLevel2::CreateCloneTrees(TFile * Line 2199  void PamLevel2::CreateCloneTrees(TFile *
2199      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2200      cout << "Create new PAMELA trees "<<endl;      cout << "Create new PAMELA trees "<<endl;
2201                    
     Int_t i=0;  
2202    
2203        run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
2204        run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
2205        cout << "Run          : branch RunInfo"<<endl;
2206        run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
2207        cout << "Run          : branch SoftInfo"<<endl;
2208                
2209    
2210    
2211        sel_tree_clone = new TTree("SelectionList","List of selected events ");
2212        sel_tree_clone->Branch("RunEntry",&irun,"runentry/I");
2213        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/I");
2214        
2215    
2216        Int_t i=0;
2217      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
2218          tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");              pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2219          if(TRK1) {          if(TRK1) {
2220              tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2221              tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
2222              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
2223                cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
2224          };          };
2225          if(TRK2) {          if(TRK2) {
2226              tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2227              cout << "Tracker      : branch TrkLevel2"<<endl;                      cout << "Tracker      : branch TrkLevel2"<<endl;        
2228          };          };
2229          if(TRKh) {          if(TRKh) {
2230              tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));              pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2231              cout << "Tracker      : branch TrkHough"<<endl;              cout << "Tracker      : branch TrkHough"<<endl;
2232          };          };
2233          i++;          i++;
# Line 2064  void PamLevel2::CreateCloneTrees(TFile * Line 2235  void PamLevel2::CreateCloneTrees(TFile *
2235    
2236      // Calorimeter      // Calorimeter
2237      if(CAL1||CAL2){      if(CAL1||CAL2){
2238          tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2239          if(CAL1) {          if(CAL1) {
2240              tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));              pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2241              cout << "Calorimeter  : branch CaloLevel1"<<endl;              cout << "Calorimeter  : branch CaloLevel1"<<endl;
2242          };          };
2243          if(CAL2) {          if(CAL2) {
2244              tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2245              cout << "Calorimeter  : branch CaloLevel2"<<endl;              cout << "Calorimeter  : branch CaloLevel2"<<endl;
2246          };          };
2247          i++;          i++;
# Line 2078  void PamLevel2::CreateCloneTrees(TFile * Line 2249  void PamLevel2::CreateCloneTrees(TFile *
2249    
2250      // ToF          // ToF    
2251      if(TOF) {      if(TOF) {
2252          tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2253          tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2254          cout << "ToF          : branch ToFLevel2"<<endl;          cout << "ToF          : branch ToFLevel2"<<endl;
2255          i++;          i++;
2256      };      };
2257      // Trigger      // Trigger
2258      if(TRG) {      if(TRG) {
2259          tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");              pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2260          tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2261          cout << "Trigger      : branch TrigLevel2"<<endl;          cout << "Trigger      : branch TrigLevel2"<<endl;
2262          i++;          i++;
2263      };      };
2264      // S4      // S4
2265      if(S4) {      if(S4) {
2266          tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");                pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
2267          tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));          pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2268          cout << "S4           : branch S4Level2"<<endl;          cout << "S4           : branch S4Level2"<<endl;
2269          i++;          i++;
2270      };      };
2271      // Neutron Detector      // Neutron Detector
2272      if(ND) {      if(ND) {
2273          tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
2274          tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));          pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2275          cout << "NeutronD     : branch NDLevel2"<<endl;          cout << "NeutronD     : branch NDLevel2"<<endl;
2276          i++;          i++;
2277      };      };
2278      // Anticounters      // Anticounters
2279      if(AC) {      if(AC) {
2280          tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");              pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
2281          tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));          pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2282          cout << "Anticounter  : branch AcLevel2"<<endl;          cout << "Anticounter  : branch AcLevel2"<<endl;
2283          i++;          i++;
2284      };      };
2285      // OrbitalInfo      // OrbitalInfo
2286      if(ORB) {      if(ORB) {
2287          tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");                pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");  
2288          tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2289          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
2290          i++;          i++;
2291      };      };
# Line 2129  void PamLevel2::CreateCloneTrees(TFile * Line 2300  void PamLevel2::CreateCloneTrees(TFile *
2300   */   */
2301  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
2302  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
2303                
2304      for(Int_t i=0; i<8; i++){  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
2305          if(tree_clone[i])tree_clone[i]->Fill();  
2306        for(Int_t i=0; i<NCLONES; i++){
2307            if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2308      }      }
2309        if(sel_tree_clone)sel_tree_clone->Fill();    
2310    
2311  }  }
2312    
2313    
2314  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
2315    
2316      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
2317          if(tree_clone[i]){          if(pam_tree_clone[i]){
2318              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
2319              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
2320          };          };
2321      }      }
2322        if(run_tree_clone){
2323            TString na = run_tree_clone->GetName();
2324            if(!name.CompareTo(na))return run_tree_clone;
2325        }
2326        if(sel_tree_clone){
2327            TString na = sel_tree_clone->GetName();
2328            if(!name.CompareTo(na))return sel_tree_clone;
2329        }
2330      return NULL;      return NULL;
2331    
2332  }  }
2333  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
2334      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2335      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
2336      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;    
2337          if(tree_clone[i]){      run_tree_clone->Write();
2338              cout << tree_clone[i]->GetName()<<endl;      cout << sel_tree_clone->GetName()<<endl;    
2339              tree_clone[i]->Write();      sel_tree_clone->Write();
2340        for(Int_t i=0; i<NCLONES; i++){    
2341            if(pam_tree_clone[i]){
2342                cout << pam_tree_clone[i]->GetName()<<endl;
2343                pam_tree_clone[i]->Write();
2344          };          };
2345      }      }
2346      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 2161  void PamLevel2::WriteCloneTrees(){ Line 2348  void PamLevel2::WriteCloneTrees(){
2348  }  }
2349    
2350  /**  /**
2351   * Create a new (empty) Pamela trees   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
2352     */
2353    Int_t PamLevel2::GetEntry(Int_t iee){
2354        
2355        if(!pam_tree){
2356            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loeaded"<<endl;
2357            return 0;
2358        }
2359        if(!run_tree ){
2360            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
2361            return 0;
2362        }
2363    
2364        Int_t ii=0;
2365        //-------------------------------
2366        ii = iee;
2367        if( !pam_tree->GetEntry(ii) ) return 0;
2368        //-------------------------------
2369        ii = iee;
2370        Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
2371        if(SELLI==0)irunentry = iee-runfirstentry;
2372        if(UPDATED && run_tree_clone)run_tree_clone->Fill();
2373    
2374    //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
2375    
2376        if( TRK0 || CAL0 || TOF0 )GetYodaEntry( );
2377    
2378        return 1;
2379    
2380    }
2381    
2382    /**
2383     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2384     * Given the run ID (...), if needed it query the DB and load the proper file.
2385     * @return Pointer to the tree
2386   */   */
 // TTree* PamLevel2::GetNewPamTree(){  
2387    
 //     if(tree_clone)return tree_clone;  
2388    
2389  //     TTree *Tout = 0;  TTree* PamLevel2::GetYodaTree( ){
2390            
2391  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
2392  //     cout << "Create new PAMELA trees "<<endl;      //===================================
2393            // check if iroot has changed
2394        //===================================
2395        if( irun<0 ){
2396            cout << "PamLevel2::GetYodaTree() -- ERROR "<<endl;
2397            cout << "In order to use this method you have to load the RunInfo tree "<<endl;
2398            cout << "with the method TChain* PamLevel2::GetRunTree(TString, TString)"<<endl;
2399    //      cout << " - read the event with PamLevel2::GetEntry(Int_t)"<<endl;
2400            return NULL;
2401        }    
2402        Int_t irootnew = run_obj->ID_ROOT_L0;
2403    //     cout << "iroot    "<<iroot<<endl;
2404    //     cout << "irootnew "<<irootnew<<endl;
2405    
2406        //===================================
2407        // load the level0 file
2408        // (if not already loaded)
2409        //===================================
2410        if( iroot != irootnew || !l0_tree){
2411            iroot = irootnew;
2412            //===================================
2413            // open the DB connection
2414            // (if not already opened)
2415            //===================================
2416            if(!dbc || (dbc && !dbc->IsConnected())){
2417                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2418                cout<<"Connecting to DB"<<endl;
2419                cout<<"HOST "<<host<<endl;
2420                cout<<"USER "<<user<<endl;
2421                cout<<"PSW  "<<psw<<endl;
2422                dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
2423                if( !dbc )return NULL;
2424                if( !dbc->IsConnected() )return NULL;    
2425    //          cout<<"...done"<<endl;
2426                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2427            }else{
2428    //          cout<<"DB already connected"<<endl;
2429            }
2430            GL_ROOT glroot = GL_ROOT();
2431            if( glroot.Query_GL_ROOT(iroot,dbc) ){
2432                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
2433                return NULL;
2434            };
2435            TString filename = glroot.PATH + glroot.NAME;
2436            if(l0_file){
2437                l0_file->Close();
2438                l0_file->Delete();
2439            }
2440            cout << "Opening LEVEL0 file: "<< filename << endl;
2441            FileStat_t t;
2442            if( gSystem->GetPathInfo(filename.Data(),t) ){
2443                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
2444                return NULL;
2445            }
2446            l0_file = new TFile(filename);
2447            if( !l0_file )return NULL;
2448            l0_tree = (TTree*)l0_file->Get("Physics");
2449            if(!h0_obj)h0_obj = new EventHeader();
2450            l0_tree->SetBranchAddress("Header" ,&h0_obj);
2451            //---------------------------------------------------
2452            // TRACKER:
2453            if(TRK0){
2454                if(!trk0_obj){
2455                    trk0_obj = new TrkLevel0();
2456                    trk0_obj->Set();
2457                };
2458                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
2459            }
2460            //---------------------------------------------------
2461            // CALORIMETER:
2462            if(CAL0){
2463                cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
2464            }
2465            //---------------------------------------------------
2466            // TOF:
2467            if(TOF0){
2468                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
2469            }
2470    
2471        };
2472    
2473        if(!dbc || (dbc && !dbc->IsConnected())){
2474            cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl;
2475        }
2476    
2477        TrkParams::SetCalib(run_obj,dbc);
2478    
2479    
2480    //    cout << l0_tree << endl;
2481            
2482  //     if(TRK1||TRK2||TRKh){      return l0_tree;
 //      TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");      
 //      if(TRK1) {  
 //          trk1_clone = new TrkLevel1();  
 //          T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);  
 //          T->BranchRef();  
 //          cout << "Tracker      : branch TrkLevel1"<<endl;  
 //      };  
 //      if(TRK2) {  
 //          trk2_clone = new TrkLevel2();  
 //          T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  
 //          cout << "Tracker      : branch TrkLevel2"<<endl;          
 //      };  
 //      if(TRKh) {  
 //          trkh_clone = new TrkHough();  
 //          T->Branch("TrkHough","TrkHough", &trkh_clone);  
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      if(!Tout)Tout=T;  
 //      else Tout->AddFriend("Tracker_clone");  
 //     }  
   
 //     // Calorimeter  
 //     if(CAL1||CAL2){  
 //      TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");      
 //      if(CAL1) {  
 //          calo1_clone = new CaloLevel1();  
 //          C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);  
 //          cout << "Calorimeter  : branch CaloLevel1"<<endl;  
 //      };  
 //      if(CAL2) {  
 //          calo2_clone = new CaloLevel2();  
 //          C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);  
 //          cout << "Calorimeter  : branch CaloLevel2"<<endl;  
 //      };  
 //      if(!Tout)Tout=C;  
 //      else Tout->AddFriend("Calorimeter_clone");  
 //     }      
   
 //     // ToF      
 //     if(TOF) {  
 //      TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data ");      
 //      tof_clone = new ToFLevel2();  
 //      O->Branch("ToFLevel2","ToFLevel2", &tof_clone);  
 //      cout << "ToF          : branch ToFLevel2"<<endl;  
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF_clone");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data ");      
 //      trig_clone = new TrigLevel2();  
 //      R->Branch("TrigLevel2","TrigLevel2", &trig_clone);  
 //      cout << "Trigger      : branch TrigLevel2"<<endl;  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger_clone");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      TTree *S = new TTree("S4_clone","PAMELA S4 level2 data ");        
 //      s4_clone = new S4Level2();  
 //      S->Branch("S4Level2","S4Level2", &s4_clone);  
 //      cout << "S4           : branch S4Level2"<<endl;  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4_clone");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      TTree *N = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");    
 //      nd_clone = new NDLevel2();  
 //      N->Branch("NDLevel2","NDLevel2", &nd_clone);  
 //      cout << "NeutronD     : branch NDLevel2"<<endl;  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD_clone");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      TTree *A = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");    
 //      ac_clone = new AcLevel2();  
 //      A->Branch("AcLevel2","AcLevel2", &ac_clone);  
 //      cout << "Anticounter  : branch AcLevel2"<<endl;  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter_clone");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      TTree *B = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");      
 //      orb_clone = new OrbitalInfo();  
 //      B->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo_clone");  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
2483    
2484  //     tree_clone = Tout;  }
 //     tree_clone->SetDirectory(0);  
2485    
2486  //     return Tout;  /**
2487  // }   * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2488  // /**   */
2489  //  * Fill a tree (created with GetNewPamTree)  Int_t PamLevel2::GetYodaEntry(){
 //  *  
 //  */  
 // //void PamLevel2::FillNewPamTree(TTree *T){  
 // void PamLevel2::FillNewPamTree(){  
           
2490    
2491  //     if(trk1_clone)  *trk1_clone = *trk1_obj;  //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
2492  //     if(trk2_clone){      if(!GetYodaTree())return 0;
2493  //      trk2_clone->Clear();      
2494  //      trk2_obj->Copy(*trk2_clone);      //  ---------------------------------
2495  // //   *trk2_clone = *trk2_obj;      //  if file is NOT a preselected file
2496  //     }      //  ---------------------------------
2497  //     if(trkh_clone)  *trkh_clone = *trkh_obj;      Int_t quellagiusta = irunentry + run_obj->EV_FROM;
2498  //     if(calo1_clone){  
2499  // //   *calo1_clone = *calo1_obj;  //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl;
2500  //      calo1_clone->Clear();  //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl;
2501  //      calo1_obj->Copy(*calo1_clone);  //     cout << " time "<< GetOrbitalInfo()->absTime << endl;
2502  //     }  //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl;
2503  //     if(calo2_clone){      
2504  // //   *calo2_clone = *calo2_obj;      if( !GetOrbitalInfo() ){
2505  //      calo2_clone->Clear();          cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
2506  //      calo2_obj->Copy(*calo2_clone);          return 0;
2507  //     }      }
2508  //     if(tof_clone)   *tof_clone  = *tof_obj;  
2509  //     if(trig_clone)  *trig_clone = *trig_obj;      // ---------------------------------------------------------------------
2510  //     if(s4_clone)    *s4_clone   = *s4_obj;      // ATTENTION!!!
2511  //     if(nd_clone)    *nd_clone   = *nd_obj;      // If data are not pre-processed with cleaner, the level0 tree may contain
2512  //     if(ac_clone)    *ac_clone   = *ac_obj;      // spurious nested physics packets.
2513  //     if(orb_clone)   *orb_clone  = *orb_obj;      // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
2514        // while level2 tree DOES NOT!!
2515  //     TTree *T = tree_clone;      // This means that "quellagiusta" in these cases is not correct.
2516        // In order to retrieve the correct level0 event, I implemented a check
2517  //     T->Fill(); //fill main tree      // of the OBT and pkt-number. In case of mismatch, the level0 entry number
2518  // //    cout<<T->IsA()->GetName()<<" "<<T->GetName()<<endl;      // is shift forward until when the packets match.
2519  //     TList *li = T->GetListOfFriends();      // ---------------------------------------------------------------------
2520  //     TIter next(li);      Int_t answer = 0;
2521  //     TFriendElement* T_friend=0;      Int_t shift =0;
2522  //     while( (T_friend = (TFriendElement*)next()) ){      do{
2523  // //   cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;          if(shift>0){
2524  //      T_friend->GetTree()->Fill();//fill friends              cout << " level0 <--> level2 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" )"<<endl;
2525  //     }          }
2526            answer = l0_tree->GetEntry(quellagiusta+shift);
2527            shift++;
2528            if( !GetEventHeader() ){
2529                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
2530                return 0;
2531            }
2532    //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
2533    //      cout << " GetOrbitalInfo()->OBT "<< GetOrbitalInfo()->OBT << endl;
2534    //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl;
2535    //      cout << " GetOrbitalInfo()->pkt_num "<< GetOrbitalInfo()->pkt_num << endl;
2536    //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl;
2537    
2538  // }      }while( ( GetOrbitalInfo()->OBT != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+shift) < GetYodaTree()->GetEntries() );
2539    
2540    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
2541    //    return GetYodaTree()->GetEntry(quellagiusta);
2542        
2543        return answer;
2544        
2545    }

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.26

  ViewVC Help
Powered by ViewVC 1.1.23