/[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.24 by pam-fi, Thu Mar 15 12:18:51 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 775  TTree *PamLevel2::GetPamTree(TFile *f, T Line 831  TTree *PamLevel2::GetPamTree(TFile *f, T
831    
832  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);
833  //     else                    GetWhichTrees(f);  //     else                    GetWhichTrees(f);
834        
835        cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
836    
837      SetWhichTrees(detlist);      SetWhichTrees(detlist);
838    
839      TTree *Trout =0;      TTree *Trout =0;
# Line 782  TTree *PamLevel2::GetPamTree(TFile *f, T Line 841  TTree *PamLevel2::GetPamTree(TFile *f, T
841      TString fname = f->GetName();      TString fname = f->GetName();
842      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
843    
844      UInt_t *found=0;      //    UInt_t *found=0;    
845    
846      cout<< "GetPamTree(TFile*,TString): detector list --> ";      cout<< "GetPamTree(TFile*,TString): detector list --> ";
847      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
# Line 797  TTree *PamLevel2::GetPamTree(TFile *f, T Line 856  TTree *PamLevel2::GetPamTree(TFile *f, T
856      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
857      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
858      cout << endl;      cout << endl;
859        if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
860    
861      f->cd();      f->cd();
862    
# Line 804  TTree *PamLevel2::GetPamTree(TFile *f, T Line 864  TTree *PamLevel2::GetPamTree(TFile *f, T
864      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
865      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
866          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
867          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
868          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
869          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
870          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
871          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
872          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
873          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
874          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
875          if(!Trout)Trout=T;          if(!Trout)Trout=T;
876          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 821  TTree *PamLevel2::GetPamTree(TFile *f, T Line 881  TTree *PamLevel2::GetPamTree(TFile *f, T
881      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
882      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
883          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
884          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
885          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
886          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
887          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
888          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
889          if(!Trout)Trout=C;          if(!Trout)Trout=C;
890          else Trout->AddFriend(C);          else Trout->AddFriend(C);
# Line 892  TTree *PamLevel2::GetPamTree(TFile *f, T Line 952  TTree *PamLevel2::GetPamTree(TFile *f, T
952      }else{      }else{
953          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
954      };      };
955    
956        TTree *L = (TTree*)f->Get("SelectionList");
957        if(L && SELLI==1) {
958    //      L->SetBranchAddress("RunEntry",&irun);
959    //      cout << "SelectionList: set branch address RunEntry"<<endl;
960    //      L->SetBranchAddress("EventEntry",&irunentry);
961    //      cout << "SelectionList: set branch address EventEntry"<<endl;
962    //      if(!Trout)Trout=O;
963    //      else Trout->AddFriend("SelectionList");
964            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
965            sel_tree = 0;
966        }else{
967            cout << "SelectionList  : missing tree"<<endl;
968        };
969            
970      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
971            
972        pam_tree = (TChain*)Trout;
973    
974      return Trout;      return Trout;
975            
976  }  }
# Line 963  TList*  PamLevel2::GetListOfLevel2Files( Line 1039  TList*  PamLevel2::GetListOfLevel2Files(
1039  //          cout <<"(2) " << file << endl;  //          cout <<"(2) " << file << endl;
1040  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){  //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){
1041  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){  //          if( (fullpath = gSystem->FindFile(ddir,file)) ){
1042              char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file));              if( file.EndsWith(".root") ){
1043              contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list                  char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(file));
1044              delete fullpath;                  contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list
1045                    delete fullpath;
1046                }
1047  //          }else{  //          }else{
1048  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;  //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl;
1049  //          };  //          };
# Line 1049  TChain *PamLevel2::GetPamTree(TList *fl, Line 1127  TChain *PamLevel2::GetPamTree(TList *fl,
1127      TChain *N = 0;      TChain *N = 0;
1128      TChain *A = 0;      TChain *A = 0;
1129      TChain *B = 0;      TChain *B = 0;
1130    
1131        TChain *L = 0;
1132            
1133      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1134      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1058  TChain *PamLevel2::GetPamTree(TList *fl, Line 1138  TChain *PamLevel2::GetPamTree(TList *fl,
1138      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1139      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1140      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1141    
1142         L = new TChain("SelectionList");
1143            
1144      // loop over files and create chains              // loop over files and create chains        
1145      TIter next(fl);      TIter next(fl);
# Line 1074  TChain *PamLevel2::GetPamTree(TList *fl, Line 1156  TChain *PamLevel2::GetPamTree(TList *fl,
1156              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1157              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1158              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1159                if(SELLI==1)         L->Add(name);
1160          };          };
1161      }      }
1162            
1163      cout << "done chain \n";      cout << "done chain \n";
1164    
1165      UInt_t *found=0;  //    UInt_t *found=0;
1166  // Tracker  // Tracker
1167      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1168          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1169          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1170          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1171          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1172          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1173          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1174          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1175          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1176          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1177          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1178          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
# Line 1099  TChain *PamLevel2::GetPamTree(TList *fl, Line 1182  TChain *PamLevel2::GetPamTree(TList *fl,
1182      // Calorimeter      // Calorimeter
1183      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1184          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1185          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1186          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1187          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1188          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1189          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1190          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1191          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
# Line 1163  TChain *PamLevel2::GetPamTree(TList *fl, Line 1246  TChain *PamLevel2::GetPamTree(TList *fl,
1246      }else{      }else{
1247          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1248      };      };
1249    
1250        // Selection List
1251        if(L && SELLI==1) {
1252            cout<<">>> Found selection-list <<<"<<endl;
1253            L->SetBranchAddress("RunEntry",&irun);
1254            cout << "SelectionList: set branch address RunEntry"<<endl;
1255            L->SetBranchAddress("EventEntry",&irunentry);
1256            cout << "SelectionList: set branch address EventEntry"<<endl;
1257            sel_tree = L;
1258    //      if(!Trout)Trout=O;
1259    //      else Trout->AddFriend("SelectionList");
1260        }else{
1261    //      cout << "SelectionList  : missing tree"<<endl;
1262            if(L)L->Delete();
1263        };
1264            
1265  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1266    
1267            pam_tree = Trout;
1268  //     // 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 );  
       
1269      return Trout;      return Trout;
1270  }  }
1271    
# Line 1293  void PamLevel2::SetBranchAddress(TTree * Line 1347  void PamLevel2::SetBranchAddress(TTree *
1347          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1348          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1349      };      };
1350        // SelectionList
1351        if(SELLI==1) {
1352            t->SetBranchAddress("RunEntry", &irun);
1353            cout << "SelectionList: set branch address RunEntry"<<endl;
1354            t->SetBranchAddress("EventEntry", &irunentry);
1355            cout << "SelectionList: set branch address EventEntry"<<endl;
1356        };
1357            
1358  }  }
1359  /**  /**
# Line 1366  void PamLevel2::SetBranchAddress(TChain Line 1427  void PamLevel2::SetBranchAddress(TChain
1427          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1428          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1429      };      };
1430        // SelectionList
1431        if(SELLI==1) {
1432            t->SetBranchAddress("RunEntry", &irun);
1433            cout << "SelectionList: set branch address RunEntry"<<endl;
1434            t->SetBranchAddress("EventEntry", &irunentry);
1435            cout << "SelectionList: set branch address EventEntry"<<endl;
1436        };
1437            
1438  }  }
1439    
# Line 1393  TChain *PamLevel2::GetRunTree(TList *fl) Line 1461  TChain *PamLevel2::GetRunTree(TList *fl)
1461              R->Add(name);              R->Add(name);
1462          };          };
1463      }      }
1464    
1465        if(R->GetNtrees()){
1466            
1467      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1468      cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
1469      R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1470      cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1471            }else{
1472            delete R;
1473            R=0;
1474        }
1475    
1476        run_tree = R;
1477    
1478      return R;      return R;
1479            
1480  }  }
# Line 1413  TChain *PamLevel2::GetRunTree(TList *fl) Line 1489  TChain *PamLevel2::GetRunTree(TList *fl)
1489   */   */
1490  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
1491    
1492        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1493    
1494      TTree *R = (TTree*)f->Get("Run");      TTree *R = (TTree*)f->Get("Run");
1495            
1496      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      if(R){
1497      cout << "Run         : set branch address RunInfo"<<endl;          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1498      R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          cout << "Run         : set branch address RunInfo"<<endl;
1499      cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1500                cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1501        }
1502    
1503        run_tree = (TChain*)R;
1504    
1505      return R;      return R;
1506            
1507  }  }
# Line 1435  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 1516  Bool_t PamLevel2::UpdateRunInfo(TChain *
1516    //    //
1517    if ( run->GetEntries() <= 0 ) return(false);    if ( run->GetEntries() <= 0 ) return(false);
1518    //    //
1519      
1520    Int_t oldrun = irun;    Int_t oldrun = irun;
1521    if ( irun < 0 ){    // --------------------------------------
1522      irun = 0;    // if it is a full file (not preselected)
1523      run->GetEntry(0);    // --------------------------------------
1524      runfirstentry = 0ULL;    if(SELLI==0){
1525      runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;        if ( irun < 0 ){
1526    };            irun = 0;
1527    while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){            run->GetEntry(0);
1528      //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));            runfirstentry = 0ULL;
1529      irun++;            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;
1530      run->GetEntry(irun);        };      
1531      runfirstentry = runlastentry+1ULL;  
1532      runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);        if( !GetOrbitalInfo() ){
1533              cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl;
1534              return(false);
1535          }
1536          // modificato il controllo sull'aggiornamento del run, per evitare problemi
1537          // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!)
1538          while ( GetOrbitalInfo()->absTime > GetRunInfo()->RUNTRAILER_TIME && irun < run->GetEntries() ){
1539    //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1540              //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1541              irun++;
1542              run->GetEntry(irun);
1543              runfirstentry = runlastentry+1ULL;
1544              runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1545          };
1546          
1547          //
1548          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1549          //
1550          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1551          //
1552          return(true);    
1553    };    };
1554    //    // ----------------------------------------------------
1555    if ( irun == oldrun || irun >= run->GetEntries() ) return(false);    // if it is a preselected file (there is SelectionList)
1556    //    // NBNB - the event tree MUST be read first
1557    //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);    // ----------------------------------------------------
1558    //    if(SELLI==1){      
1559    return(true);            sel_tree->GetEntry(iev);
1560          if(irun != oldrun){
1561              run->GetEntry(irun);
1562              return true;
1563          }
1564          return false;
1565      }
1566    
1567      return false;
1568    //    //
1569  };  };
1570  /**  /**
# Line 1477  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 1587  Bool_t PamLevel2::UpdateRunInfo(TTree *r
1587  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
1588                    
1589      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
1590            CAL0 = false;
1591          CAL1 = true;          CAL1 = true;
1592          CAL2 = true;          CAL2 = true;
1593          TRK2 = true;          TRK2 = true;
1594          TRK1 = false;          TRK1 = false;
1595          TRKh = false;          TRKh = false;
1596            TRK0 = false;
1597          TRG = true;          TRG = true;
1598          TOF = true;          TOF = true;
1599            TOF0 = false;
1600          S4  = true;          S4  = true;
1601          ND  = true;          ND  = true;
1602          AC  = true;          AC  = true;
1603          ORB = true;          ORB = true;
1604      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
1605            CAL0 = false;
1606          CAL1 = false;          CAL1 = false;
1607          CAL2 = false;          CAL2 = false;
1608          TRK2 = false;          TRK2 = false;
1609          TRK1 = false;          TRK1 = false;
1610          TRKh = false;          TRKh = false;
1611            TRK0 = false;
1612          TRG = false;          TRG = false;
1613          TOF = false;          TOF = false;
1614            TOF0 = false;
1615          S4  = false;          S4  = false;
1616          ND  = false;          ND  = false;
1617          AC  = false;          AC  = false;
# Line 1507  void PamLevel2::SetWhichTrees(TString de Line 1623  void PamLevel2::SetWhichTrees(TString de
1623          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1624          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1625      };      };
1626    
1627        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
1628            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
1629            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
1630        };
1631                    
1632      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1633          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1519  void PamLevel2::SetWhichTrees(TString de Line 1640  void PamLevel2::SetWhichTrees(TString de
1640          CAL1=false;          CAL1=false;
1641      }      }
1642  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
1643        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
1644            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
1645            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
1646        };
1647    
1648      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1649          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1650          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1547  void PamLevel2::SetWhichTrees(TString de Line 1673  void PamLevel2::SetWhichTrees(TString de
1673            
1674      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
1675      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
1676    
1677        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
1678        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
1679            
1680      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
1681      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 1710  void PamLevel2::SetWhichTrees(TString de
1710   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
1711   */   */
1712  void  PamLevel2::GetWhichTrees(TFile* f){  void  PamLevel2::GetWhichTrees(TFile* f){
1713                
1714    
1715    
1716        cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
1717      // -----------      // -----------
1718      // reset flags      // reset flags
1719      // -----------      // -----------
# Line 1753  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1885  Bool_t  PamLevel2::CheckLevel2File(TStri
1885            
1886      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
1887            
1888            Bool_t SELLI__ok  = false;
1889    
1890      cout << "Checking file: "<<name<<endl;      cout << "Checking file: "<<name<<endl;
1891      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
# Line 1770  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1902  Bool_t  PamLevel2::CheckLevel2File(TStri
1902    
1903      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
1904                    
1905    //      cout << key->GetName() << endl;
1906  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
1907  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
1908  //      nev_previous = nev;  //      nev_previous = nev;
# Line 1780  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1913  Bool_t  PamLevel2::CheckLevel2File(TStri
1913  //          return false;  //          return false;
1914  //      };  //      };
1915    
1916    
1917          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
1918    
1919          //=========================================================              //=========================================================    
1920            if( !strcmp(key->GetName(),"SelectionList"    ) ){
1921                SELLI__ok = true;
1922                if(SELLI==1){
1923                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
1924                    if( nev && nevt!=nev){
1925                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
1926                        return false;
1927                    }
1928                    nev=nevt;
1929                }
1930            }
1931    
1932            //=========================================================    
1933          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
1934              TRG__ok = true;              TRG__ok = true;
1935              if(TRG){              if(TRG){
# Line 1894  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2041  Bool_t  PamLevel2::CheckLevel2File(TStri
2041          };                };      
2042    
2043      };      };
2044    
2045        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
2046        if( SELLI==0 && SELLI__ok ){
2047            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
2048            return false;  
2049        }
2050        if( SELLI==1 && !SELLI__ok ){
2051            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
2052            return false;
2053        }
2054            
2055    //    cout << "SELLI "<<SELLI<<endl;
2056    
2057  //     cout<< "CheckLevel2File(TString): detector list --> ";  //     cout<< "CheckLevel2File(TString): detector list --> ";
2058  //     if(TRK1__ok)cout<<"TRK1 ";  //     if(TRK1__ok)cout<<"TRK1 ";
2059  //     if(TRK2__ok)cout<<"TRK2 ";  //     if(TRK2__ok)cout<<"TRK2 ";
# Line 2003  void PamLevel2::CreateCloneTrees0( TChai Line 2162  void PamLevel2::CreateCloneTrees0( TChai
2162      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
2163            
2164      Int_t i=0;      Int_t i=0;
2165      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
2166      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
2167      name.Append("_clone");      name.Append("_clone");
2168  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
2169      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
2170      i++;      i++;
2171    
2172      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
# Line 2017  void PamLevel2::CreateCloneTrees0( TChai Line 2176  void PamLevel2::CreateCloneTrees0( TChai
2176      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
2177  //      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;
2178  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
2179          tree_clone[i] = T_friend->GetTree()->CloneTree(0);          pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2180          tree_clone[i]->SetAutoSave(1000000);          pam_tree_clone[i]->SetAutoSave(1000000);
2181          name =  tree_clone[i]->GetName();          name =  pam_tree_clone[i]->GetName();
2182          name.Append("_clone");          name.Append("_clone");
2183  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
2184          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
2185          i++;          i++;
2186      }      }
2187            
# Line 2042  void PamLevel2::CreateCloneTrees(TFile * Line 2201  void PamLevel2::CreateCloneTrees(TFile *
2201      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2202      cout << "Create new PAMELA trees "<<endl;      cout << "Create new PAMELA trees "<<endl;
2203                    
     Int_t i=0;  
2204    
2205        run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
2206        run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
2207        cout << "Run          : branch RunInfo"<<endl;
2208        run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
2209        cout << "Run          : branch SoftInfo"<<endl;
2210                
2211    
2212    
2213        sel_tree_clone = new TTree("SelectionList","List of selected events ");
2214        sel_tree_clone->Branch("RunEntry",&irun,"runentry/I");
2215        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/I");
2216        
2217    
2218        Int_t i=0;
2219      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
2220          tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");              pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2221          if(TRK1) {          if(TRK1) {
2222              tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2223              tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
2224              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
2225                cout << "CreateCloneTrees " << GetTrkLevel1()<<endl;
2226          };          };
2227          if(TRK2) {          if(TRK2) {
2228              tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2229              cout << "Tracker      : branch TrkLevel2"<<endl;                      cout << "Tracker      : branch TrkLevel2"<<endl;        
2230          };          };
2231          if(TRKh) {          if(TRKh) {
2232              tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));              pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2233              cout << "Tracker      : branch TrkHough"<<endl;              cout << "Tracker      : branch TrkHough"<<endl;
2234          };          };
2235          i++;          i++;
# Line 2064  void PamLevel2::CreateCloneTrees(TFile * Line 2237  void PamLevel2::CreateCloneTrees(TFile *
2237    
2238      // Calorimeter      // Calorimeter
2239      if(CAL1||CAL2){      if(CAL1||CAL2){
2240          tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2241          if(CAL1) {          if(CAL1) {
2242              tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));              pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2243              cout << "Calorimeter  : branch CaloLevel1"<<endl;              cout << "Calorimeter  : branch CaloLevel1"<<endl;
2244          };          };
2245          if(CAL2) {          if(CAL2) {
2246              tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2247              cout << "Calorimeter  : branch CaloLevel2"<<endl;              cout << "Calorimeter  : branch CaloLevel2"<<endl;
2248          };          };
2249          i++;          i++;
# Line 2078  void PamLevel2::CreateCloneTrees(TFile * Line 2251  void PamLevel2::CreateCloneTrees(TFile *
2251    
2252      // ToF          // ToF    
2253      if(TOF) {      if(TOF) {
2254          tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2255          tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2256          cout << "ToF          : branch ToFLevel2"<<endl;          cout << "ToF          : branch ToFLevel2"<<endl;
2257          i++;          i++;
2258      };      };
2259      // Trigger      // Trigger
2260      if(TRG) {      if(TRG) {
2261          tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");              pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2262          tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2263          cout << "Trigger      : branch TrigLevel2"<<endl;          cout << "Trigger      : branch TrigLevel2"<<endl;
2264          i++;          i++;
2265      };      };
2266      // S4      // S4
2267      if(S4) {      if(S4) {
2268          tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");                pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
2269          tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));          pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2270          cout << "S4           : branch S4Level2"<<endl;          cout << "S4           : branch S4Level2"<<endl;
2271          i++;          i++;
2272      };      };
2273      // Neutron Detector      // Neutron Detector
2274      if(ND) {      if(ND) {
2275          tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
2276          tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));          pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2277          cout << "NeutronD     : branch NDLevel2"<<endl;          cout << "NeutronD     : branch NDLevel2"<<endl;
2278          i++;          i++;
2279      };      };
2280      // Anticounters      // Anticounters
2281      if(AC) {      if(AC) {
2282          tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");              pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
2283          tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));          pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2284          cout << "Anticounter  : branch AcLevel2"<<endl;          cout << "Anticounter  : branch AcLevel2"<<endl;
2285          i++;          i++;
2286      };      };
2287      // OrbitalInfo      // OrbitalInfo
2288      if(ORB) {      if(ORB) {
2289          tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");                pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");  
2290          tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2291          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
2292          i++;          i++;
2293      };      };
# Line 2129  void PamLevel2::CreateCloneTrees(TFile * Line 2302  void PamLevel2::CreateCloneTrees(TFile *
2302   */   */
2303  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
2304  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
2305                
2306      for(Int_t i=0; i<8; i++){  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
2307          if(tree_clone[i])tree_clone[i]->Fill();  
2308        for(Int_t i=0; i<NCLONES; i++){
2309            if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2310      }      }
2311        if(sel_tree_clone)sel_tree_clone->Fill();    
2312    
2313  }  }
2314    
2315    
2316  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
2317    
2318      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
2319          if(tree_clone[i]){          if(pam_tree_clone[i]){
2320              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
2321              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
2322          };          };
2323      }      }
2324        if(run_tree_clone){
2325            TString na = run_tree_clone->GetName();
2326            if(!name.CompareTo(na))return run_tree_clone;
2327        }
2328        if(sel_tree_clone){
2329            TString na = sel_tree_clone->GetName();
2330            if(!name.CompareTo(na))return sel_tree_clone;
2331        }
2332      return NULL;      return NULL;
2333    
2334  }  }
2335  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
2336      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2337      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
2338      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;    
2339          if(tree_clone[i]){      run_tree_clone->Write();
2340              cout << tree_clone[i]->GetName()<<endl;      cout << sel_tree_clone->GetName()<<endl;    
2341              tree_clone[i]->Write();      sel_tree_clone->Write();
2342        for(Int_t i=0; i<NCLONES; i++){    
2343            if(pam_tree_clone[i]){
2344                cout << pam_tree_clone[i]->GetName()<<endl;
2345                pam_tree_clone[i]->Write();
2346          };          };
2347      }      }
2348      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 2161  void PamLevel2::WriteCloneTrees(){ Line 2350  void PamLevel2::WriteCloneTrees(){
2350  }  }
2351    
2352  /**  /**
2353   * Create a new (empty) Pamela trees   * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry.
2354   */   */
2355  // TTree* PamLevel2::GetNewPamTree(){  Int_t PamLevel2::GetEntry(Int_t iee){
2356        
2357        if(!pam_tree){
2358            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl;
2359            return 0;
2360        }
2361    
2362  //     if(tree_clone)return tree_clone;      Int_t ii=0;
2363        //-------------------------------
2364        ii = iee;
2365        if( !pam_tree->GetEntry(ii) ) return 0;
2366        //-------------------------------
2367    
2368        if(!run_tree ){
2369            cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl;
2370            return 0;
2371        }
2372    
2373  //     TTree *Tout = 0;      ii = iee;
2374            Bool_t UPDATED = UpdateRunInfo(run_tree,ii);
2375  //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      if(SELLI==0)irunentry = iee-runfirstentry;
2376  //     cout << "Create new PAMELA trees "<<endl;      if(UPDATED && run_tree_clone)run_tree_clone->Fill();
2377        
2378    //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
2379    
2380        if( TRK0 || CAL0 || TOF0 )GetYodaEntry( );
2381    
2382        return 1;
2383    
2384    }
2385    
2386    /**
2387     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2388     * Given the run ID (...), if needed it query the DB and load the proper file.
2389     * @return Pointer to the tree
2390     */
2391    
2392    
2393    TTree* PamLevel2::GetYodaTree( ){
2394        
2395    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
2396        //===================================
2397        // check if iroot has changed
2398        //===================================
2399        if( irun<0 ){
2400            cout << "PamLevel2::GetYodaTree() -- ERROR "<<endl;
2401            cout << "In order to use this method you have to load the RunInfo tree "<<endl;
2402            cout << "with the method TChain* PamLevel2::GetRunTree(TString, TString)"<<endl;
2403    //      cout << " - read the event with PamLevel2::GetEntry(Int_t)"<<endl;
2404            return NULL;
2405        }    
2406        Int_t irootnew = run_obj->ID_ROOT_L0;
2407    //     cout << "iroot    "<<iroot<<endl;
2408    //     cout << "irootnew "<<irootnew<<endl;
2409    
2410        //===================================
2411        // load the level0 file
2412        // (if not already loaded)
2413        //===================================
2414        if( iroot != irootnew || !l0_tree){
2415            iroot = irootnew;
2416            //===================================
2417            // open the DB connection
2418            // (if not already opened)
2419            //===================================
2420            if(!dbc || (dbc && !dbc->IsConnected())){
2421                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2422                cout<<"Connecting to DB"<<endl;
2423                cout<<"HOST "<<host<<endl;
2424                cout<<"USER "<<user<<endl;
2425                cout<<"PSW  "<<psw<<endl;
2426                dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
2427                if( !dbc )return NULL;
2428                if( !dbc->IsConnected() )return NULL;    
2429    //          cout<<"...done"<<endl;
2430                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2431            }else{
2432    //          cout<<"DB already connected"<<endl;
2433            }
2434            GL_ROOT glroot = GL_ROOT();
2435            if( glroot.Query_GL_ROOT(iroot,dbc) ){
2436                cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl;
2437                return NULL;
2438            };
2439            TString filename = glroot.PATH + glroot.NAME;
2440            if(l0_file){
2441                l0_file->Close();
2442                l0_file->Delete();
2443            }
2444            cout << "Opening LEVEL0 file: "<< filename << endl;
2445            FileStat_t t;
2446            if( gSystem->GetPathInfo(filename.Data(),t) ){
2447                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
2448                return NULL;
2449            }
2450            l0_file = new TFile(filename);
2451            if( !l0_file )return NULL;
2452            l0_tree = (TTree*)l0_file->Get("Physics");
2453            if(!h0_obj)h0_obj = new EventHeader();
2454            l0_tree->SetBranchAddress("Header" ,&h0_obj);
2455            //---------------------------------------------------
2456            // TRACKER:
2457            if(TRK0){
2458                if(!trk0_obj){
2459                    trk0_obj = new TrkLevel0();
2460                    trk0_obj->Set();
2461                };
2462                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
2463                TrkParams::SetCalib(run_obj,dbc);
2464            }
2465            //---------------------------------------------------
2466            // CALORIMETER:
2467            if(CAL0){
2468                cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
2469            }
2470            //---------------------------------------------------
2471            // TOF:
2472            if(TOF0){
2473                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
2474            }
2475    
2476        };
2477    
2478    //    cout << l0_tree << endl;
2479            
2480  //     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;  
2481    
2482  //     tree_clone = Tout;  }
 //     tree_clone->SetDirectory(0);  
2483    
2484  //     return Tout;  /**
2485  // }   * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2486  // /**   */
2487  //  * Fill a tree (created with GetNewPamTree)  Int_t PamLevel2::GetYodaEntry(){
 //  *  
 //  */  
 // //void PamLevel2::FillNewPamTree(TTree *T){  
 // void PamLevel2::FillNewPamTree(){  
           
2488    
2489  //     if(trk1_clone)  *trk1_clone = *trk1_obj;  //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
2490  //     if(trk2_clone){      if(!GetYodaTree())return 0;
2491  //      trk2_clone->Clear();      
2492  //      trk2_obj->Copy(*trk2_clone);      //  ---------------------------------
2493  // //   *trk2_clone = *trk2_obj;      //  if file is NOT a preselected file
2494  //     }      //  ---------------------------------
2495  //     if(trkh_clone)  *trkh_clone = *trkh_obj;      Int_t quellagiusta = irunentry + run_obj->EV_FROM;
 //     if(calo1_clone){  
 // //   *calo1_clone = *calo1_obj;  
 //      calo1_clone->Clear();  
 //      calo1_obj->Copy(*calo1_clone);  
 //     }  
 //     if(calo2_clone){  
 // //   *calo2_clone = *calo2_obj;  
 //      calo2_clone->Clear();  
 //      calo2_obj->Copy(*calo2_clone);  
 //     }  
 //     if(tof_clone)   *tof_clone  = *tof_obj;  
 //     if(trig_clone)  *trig_clone = *trig_obj;  
 //     if(s4_clone)    *s4_clone   = *s4_obj;  
 //     if(nd_clone)    *nd_clone   = *nd_obj;  
 //     if(ac_clone)    *ac_clone   = *ac_obj;  
 //     if(orb_clone)   *orb_clone  = *orb_obj;  
   
 //     TTree *T = tree_clone;  
   
 //     T->Fill(); //fill main tree  
 // //    cout<<T->IsA()->GetName()<<" "<<T->GetName()<<endl;  
 //     TList *li = T->GetListOfFriends();  
 //     TIter next(li);  
 //     TFriendElement* T_friend=0;  
 //     while( (T_friend = (TFriendElement*)next()) ){  
 // //   cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  
 //      T_friend->GetTree()->Fill();//fill friends  
 //     }  
2496    
2497  // }      if( !GetOrbitalInfo() ){
2498            cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl;
2499            return 0;
2500        }
2501    
2502        // ---------------------------------------------------------------------
2503        // ATTENTION!!!
2504        // If data are not pre-processed with cleaner, the level0 tree may contain
2505        // spurious nested physics packets.
2506        // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries
2507        // while level2 tree DOES NOT!!
2508        // This means that "quellagiusta" in these cases is not correct.
2509        // In order to retrieve the correct level0 event, I implemented a check
2510        // of the OBT and pkt-number. In case of mismatch, the level0 entry number
2511        // is shift forward until when the packets match.
2512        // ---------------------------------------------------------------------
2513        Int_t answer = 0;
2514        Int_t shift =0;
2515        do{
2516    //      if(shift>0){
2517    //          cout << " level0 <--> level2 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" )"<<endl;
2518    //      }
2519            answer = GetYodaTree()->GetEntry(quellagiusta+shift);
2520            shift++;
2521            if( !GetEventHeader() ){
2522                cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl;
2523                return 0;
2524            }
2525    //      if( (quellagiusta+shift) == GetYodaTree()->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl;
2526        }while( ( (UInt_t)(GetOrbitalInfo()->OBT) != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || GetOrbitalInfo()->pkt_num != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta+shift) < (UInt_t)(GetYodaTree()->GetEntries()) );
2527    
2528    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
2529    //    return GetYodaTree()->GetEntry(quellagiusta);
2530        
2531        return answer;
2532        
2533    }

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

  ViewVC Help
Powered by ViewVC 1.1.23